• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/cosy-jan12/go4/STS/TSTSTopology.cxx (r4864/r3122)

Go to the documentation of this file.
00001 #include "TSTSTopology.h"
00002 #include "stdlib.h"
00003 
00004 
00005 
00006 TSTSTopology::~TSTSTopology()
00007 {
00008     for( UInt_t iDet = 0; iDet < fMappings.size(); ++iDet ) {
00009         for( UInt_t iSide = 0; iSide < fMappings.at( iDet ).size(); ++iSide ) {
00010             for( UInt_t iConn = 0; iConn < fMappings.at( iDet).at( iSide ).size(); ++iConn ) {
00011                 TF1 * & f = fMappings.at( iDet).at( iSide ).at( iConn );
00012                 if( f ) {
00013                     delete f;
00014                     f = 0;
00015                 }
00016             }
00017         }
00018     }
00019 }
00020 
00021 
00022 
00023 void TSTSTopology::SetConnection( UInt_t roc, UInt_t nx, UInt_t det, ESTSSide side, UInt_t conn )
00024 {
00025     if( roc >= fRocNxConnections.size() ) {
00026         fRocNxConnections.resize( roc + 1 );
00027     }
00028     if( nx >= fRocNxConnections.at( roc ).size() ) {
00029         fRocNxConnections.at( roc ).resize( nx + 1 );
00030     }
00031     fRocNxConnections.at( roc ).at( nx ).fDet = det;
00032     fRocNxConnections.at( roc ).at( nx ).fSide = side;
00033     fRocNxConnections.at( roc ).at( nx ).fConn = conn;
00034     fRocNxConnections.at( roc ).at( nx ).fSet = kTRUE;
00035 }
00036 
00037 
00038 
00039 void TSTSTopology::SetMapping( UInt_t det, UInt_t side, UInt_t conn, const Char_t * mapping )
00040 {
00041     if( side >= kNSides ) {
00042         printf( "Error in TSTSTopology::SetMapping: side is expected to be < 2, received %d\n", side );
00043         return;
00044     }
00045     if( det >= fMappings.size() ) {
00046         fMappings.resize( det + 1 );
00047     }
00048     if( side >= fMappings.at( det ).size() ) {
00049         fMappings.at( det ).resize( side + 1 );
00050     }
00051     if( conn >= fMappings.at( det ).at( side ).size() ) {
00052         fMappings.at( det ).at( side ).resize( conn + 1 );
00053     }
00054     fMappings.at( det ).at( side ).at( conn ) = new TF1( Form("mapping_det%d_side%d_conn%d", det, side, conn), mapping, 0, GetNNxCh() - 1 );
00055 }
00056 
00057 
00058 
00059 UInt_t TSTSTopology::GetRocArrSize() const
00060 {
00061     for( UInt_t iRoc = fRocNxConnections.size() - 1; iRoc >=0 ; --iRoc ) {
00062         for( UInt_t iNx = 0; iNx < fRocNxConnections.at(iRoc).size(); ++iNx ) {
00063             if( fRocNxConnections.at( iRoc ).at( iNx ).fSet ) {
00064                 return iRoc + 1;
00065             }
00066         }
00067     }
00068     return 0;
00069 }
00070 
00071 
00072 
00073 UInt_t TSTSTopology::GetNxArrSize() const
00074 {
00075     UInt_t nxArrSize = 0;
00076     for( UInt_t iRoc = 0; iRoc < fRocNxConnections.size(); ++iRoc ) {
00077         nxArrSize= TMath::Max( nxArrSize, GetNxArrSize( iRoc ) );
00078     }
00079     return nxArrSize;
00080 }
00081 
00082 
00083 
00084 UInt_t TSTSTopology::GetNxArrSize( UInt_t roc ) const
00085 {
00086     for( UInt_t iNx = fRocNxConnections.at( roc ).size() - 1; iNx >= 0; --iNx ) {
00087         if( fRocNxConnections.at( roc ).at( iNx ).fSet ) return iNx + 1;
00088     }
00089     return 0;
00090 }
00091 
00092 
00093 
00094 UInt_t TSTSTopology::GetDetArrSize() const
00095 {
00096     UInt_t detArrSize = 0;
00097     for( UInt_t iRoc = 0; iRoc < fRocNxConnections.size(); ++iRoc ) {
00098         for( UInt_t iNx = 0; iNx < fRocNxConnections.at( iRoc ).size(); ++iNx ) {
00099             detArrSize = TMath::Max( fRocNxConnections.at( iRoc ).at( iNx ).fDet + 1, detArrSize );
00100         }
00101     }
00102     return detArrSize;
00103 }
00104 
00105 
00106 
00107 UInt_t TSTSTopology::GetDetector( UInt_t roc, UInt_t nx ) const
00108 {
00109     return fRocNxConnections.at( roc ).at( nx ).fDet;
00110 }
00111 
00112 
00113 
00114 TSTSTopology::ESTSSide TSTSTopology::GetSide( UInt_t roc, UInt_t nx ) const
00115 {
00116     return fRocNxConnections.at( roc ).at( nx ).fSide;
00117 }
00118 
00119 
00120 
00121 UInt_t TSTSTopology::GetConnector( UInt_t roc, UInt_t nx ) const
00122 {
00123     return fRocNxConnections.at( roc ).at( nx ).fConn;
00124 }
00125 
00126 
00127 
00128 Double_t TSTSTopology::GetStripNoCheck( UInt_t det, UInt_t side, UInt_t conn, UInt_t ch ) const
00129 {
00130     return fMappings.at( det ).at( side ).at( conn )->Eval( ch );
00131 }
00132 
00133 
00134 
00135 UInt_t TSTSTopology::GetStripCheckNegative( UInt_t det, UInt_t side, UInt_t conn, UInt_t ch ) const
00136 {
00137     Double_t strip = GetStripNoCheck( det, side, conn, ch );
00138     if( strip < 0 ) {
00139         printf( "Error in TSTSTopology::GetStripCheckNegative: det=%d side=%c conn=%d ch=%d is mapped to negative strip %f\n", det, GetSideName( side ), conn, ch, strip );
00140         return 0;
00141     }
00142     return static_cast< UInt_t >( strip );
00143 }
00144 
00145 
00146 
00147 UInt_t TSTSTopology::GetStrip( UInt_t det, UInt_t side, UInt_t conn, UInt_t ch ) const
00148 {
00149     return static_cast< UInt_t >( GetStripNoCheck( det, side, conn, ch ) );
00150 }
00151 
00152 
00153 
00154 UInt_t TSTSTopology::GetStrip( UInt_t roc, UInt_t nx, UInt_t ch ) const
00155 {
00156     UInt_t det = GetDetector( roc, nx );
00157     ESTSSide side = GetSide( roc, nx );
00158     UInt_t conn = GetConnector( roc, nx );
00159     return GetStrip( det, side, conn, ch );
00160 }
00161 
00162 
00163 
00164 UInt_t TSTSTopology::GetStripArrSize( UInt_t det, UInt_t side ) const
00165 {
00166     UInt_t stripArrSize = 0;
00167     for( UInt_t iConn = 0; iConn < fMappings.at( det ).at( side ).size(); ++iConn ) {
00168         if( ! IsMappingSet( det, side, iConn ) ) {
00169             continue;
00170         }
00171         for( UInt_t iCh = 0; iCh < GetNNxCh(); ++iCh ) {
00172             stripArrSize = TMath::Max( stripArrSize, GetStrip( det, side, iConn, iCh ) + 1 );
00173         }
00174     }
00175     return stripArrSize;
00176 }
00177 
00178 
00179 /*
00180  * True if at connection from this roc to at least one nX is specified.
00181  */
00182 Bool_t TSTSTopology::IsValidRoc( UInt_t roc ) const
00183 {
00184     if( roc > fRocNxConnections.size() || roc < 0 ) {
00185         return kFALSE;
00186     }
00187     for( UInt_t iNx = 0; iNx < fRocNxConnections.at( roc ).size(); ++iNx ) {
00188         if( fRocNxConnections.at( roc ).at( iNx ).fSet ) {
00189             return kTRUE;
00190         }
00191     }
00192     return kFALSE;
00193 }
00194 
00195 
00196 
00197 Bool_t TSTSTopology::IsValidNx( UInt_t roc, UInt_t nx ) const
00198 {
00199     if( roc > fRocNxConnections.size() || roc < 0 ) {
00200         return kFALSE;
00201     }
00202     if( nx > fRocNxConnections.at( roc ).size() || nx < 0 ) {
00203         return kFALSE;
00204     }
00205     return fRocNxConnections.at( roc ).at( nx ).fSet;
00206 }
00207 
00208 
00209 
00210 Bool_t TSTSTopology::IsValidCh( UInt_t ch ) const
00211 {
00212     return ch < GetNNxCh() ;
00213 }
00214 
00215 
00216 
00217 Bool_t TSTSTopology::IsMappingSet( UInt_t det, UInt_t side, UInt_t conn ) const
00218 {
00219     if( det >= fMappings.size() ) {
00220         return kFALSE;
00221     }
00222     if( side >= fMappings.at( det ).size() ) {
00223         return kFALSE;
00224     }
00225     if( conn >= fMappings.at( det ).at( side ).size() ) {
00226         return kFALSE;
00227     }
00228     return fMappings.at( det ).at( side ).at( conn ) != 0;
00229 }
00230 
00231 
00232 
00233 void TSTSTopology::TestMapping( Bool_t doPrint ) const
00234 {
00235     std::vector< std::vector < std::vector< TRocNxChConn > > > mapping;
00236     const UInt_t detArrSize = GetDetArrSize();
00237     mapping.resize( detArrSize );
00238     for( UInt_t iDet = 0; iDet < detArrSize; ++iDet ) {
00239         mapping.at( iDet ).resize( kNSides );
00240         for( UInt_t iSide = 0; iSide < kNSides; iSide++ ) {
00241             mapping.at( iDet ).at( iSide ).resize( GetStripArrSize( iDet, iSide ) );
00242         }
00243     }
00244 
00245     UInt_t rocArrSize = GetRocArrSize();
00246     for( UInt_t iRoc = 0; iRoc < rocArrSize; ++iRoc ) {
00247         if( IsValidRoc( iRoc ) ) {
00248             UInt_t nxArrSize = GetNxArrSize( iRoc );
00249             for( UInt_t iNx = 0; iNx < nxArrSize; ++iNx ) {
00250                 if( IsValidNx( iRoc, iNx ) ) {
00251                     for( UInt_t iCh = 0; iCh < GetNNxCh(); ++iCh ) {
00252                         UInt_t det = GetDetector( iRoc, iNx );
00253                         UInt_t side = GetSide( iRoc, iNx );
00254                         UInt_t conn = GetConnector( iRoc, iNx );
00255                         UInt_t strip = GetStripCheckNegative( det, side, conn, iCh );
00256                         if( ! mapping.at( det ).at( side ).at( strip ).fSet ) {
00257                             mapping.at( det ).at( side ).at( strip ).fRoc = iRoc;
00258                             mapping.at( det ).at( side ).at( strip ).fNx  = iNx;
00259                             mapping.at( det ).at( side ).at( strip ).fCh  = iCh;
00260                             mapping.at( det ).at( side ).at( strip ).fConn= conn;
00261                             mapping.at( det ).at( side ).at( strip ).fSet = kTRUE;
00262                         }
00263                         else {
00264                             UInt_t oldRoc = mapping.at( det ).at( side ).at( strip ).fRoc;
00265                             UInt_t oldNx  = mapping.at( det ).at( side ).at( strip ).fNx;
00266                             UInt_t oldCh  = mapping.at( det ).at( side ).at( strip ).fCh;
00267                             UInt_t oldConn= mapping.at( det ).at( side ).at( strip ).fConn;
00268                             printf( "Error in TSTSTopology::TestMapping: ");
00269                             printf( "Two readout channels map to strip %d on %c-side of detector %d: ", strip, GetSideName( side ), det );
00270                             printf( " roc %d, nx %d, ch%d (connector %d) and ", oldRoc, oldNx, oldCh, oldConn );
00271                             printf( " roc %d, nx %d, ch%d (connector %d)\n", iRoc, iNx, iCh, conn );
00272                         }
00273                     }
00274                 }
00275             }
00276         }
00277     }
00278 
00279     if( doPrint ) {
00280         UInt_t nNotConnectedStrips = 0;
00281         printf( "======================= Printing STS topology =================================\n");
00282         for( UInt_t iDet = 0; iDet < mapping.size(); ++iDet ) {
00283             for( UInt_t iSide = 0; iSide < mapping.at( iDet ).size(); ++iSide ) {
00284                 for( UInt_t iStrip = 0; iStrip < mapping.at( iDet ).at( iSide ).size(); ++iStrip ) {
00285                     printf( "Det=%2d  side=%c  strip=%4d   <--   ", iDet, GetSideName( iSide ), iStrip );
00286                     const TRocNxChConn & rocNxChConn = mapping.at( iDet ).at( iSide ).at( iStrip );
00287                     if( rocNxChConn.fSet ) {
00288                         printf( "Roc=%2d  Nx=%2d  Ch=%3d  (Conn=%2d)\n", rocNxChConn.fRoc, rocNxChConn.fNx, rocNxChConn.fCh, rocNxChConn.fConn );
00289                     }
00290                     else {
00291                         printf( "not connected\n");
00292                         ++nNotConnectedStrips;
00293                     }
00294                 }
00295             }
00296         }
00297         for( UInt_t iDet = 0; iDet < mapping.size(); ++iDet ) {
00298             for( UInt_t iSide = 0; iSide < mapping.at( iDet ).size(); ++iSide ) {
00299                 UInt_t maxStrip = GetStripArrSize( iDet, iSide ) - 1;
00300                 printf( "Max strip on %c-side of det %d is %d", GetSideName( iSide ), iDet, maxStrip );
00301                 if( maxStrip != 255 && maxStrip != 1023 ) {
00302                     printf( " <-- WARNING!!!" );
00303                 }
00304                 printf("\n");
00305             }
00306         }
00307         if( nNotConnectedStrips ) {
00308             printf( "WARNING: %d strips are not connected!!!\n", nNotConnectedStrips );
00309         }
00310         printf("\n");
00311     }
00312 
00313 }
00314 
00315 
00316 
00317 

Generated on Tue Dec 10 2013 04:52:18 for ROCsoft by  doxygen 1.7.1