Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-26 09:30:38

0001 /**
0002  * @file Setup.cc
0003  * @brief Implementation of the Setup singleton geometry and mapping logic.
0004  *
0005  * The Setup class is responsible for loading/initializing the detector map and
0006  * providing accessors for geometry and readout mappings used throughout the
0007  * LFHCal analysis software.
0008  */
0009 
0010 #include "Setup.h"
0011 #include "RootSetupWrapper.h"
0012 #include <iostream>
0013 #include <fstream>
0014 #include "TObjArray.h"
0015 #include "TObjString.h"
0016 #include "utility"
0017 
0018 Setup* Setup::instancePtr = nullptr;
0019 
0020 ClassImp(Setup);
0021 
0022 /**
0023  * @brief Initialize the setup from a text-based detector mapping file.
0024  *
0025  * This routine reads a geometry definition file, fills the lookup maps for cell IDs,
0026  * row/column/layer/module information, and stores the maximum geometry limits.
0027  *
0028  * @param file Path to the mapping file.
0029  * @param debug Verbosity level for diagnostic output.
0030  * @return true if initialization succeeds, false if the file cannot be opened.
0031  */
0032 bool Setup::Initialize(TString file, int debug){
0033 
0034   std::cout << "entered setup initialize" << std::endl;
0035   if(isInit){
0036     std::cout<<"Already initialized, bailing out without action"<<std::endl;
0037     return true;
0038   }
0039   std::fstream input;
0040   input.open(file.Data(),std::ios::in);
0041   if(!input.is_open()){
0042     std::cout<<"Could not open "<<file<<std::endl;
0043     std::cout<<"Leaving uninitialized"<<std::endl;
0044     return false;
0045   }
0046   nMaxLayer   = -1;
0047   nMaxRow     = -1;
0048   nMaxColumn  = -1;
0049   nMaxModule  = -1;
0050   nMaxROUnit  = -1;
0051   maxCellID   = -1;
0052   int AROunit,AROchannel,Alayer,AROlayer,Arow,Acolumn,Amod,segSize;
0053   TString Anassembly;
0054   int Akey;
0055   
0056   for( TString tempLine; tempLine.ReadLine(input, kTRUE); ) {
0057         // check if line should be considered
0058     if (tempLine.BeginsWith("%") || tempLine.BeginsWith("#")){
0059         continue;
0060     }
0061     if (debug > 10) std::cout << tempLine.Data() << std::endl;
0062     TObjArray *tempArr  = tempLine.Tokenize("\t");
0063     if(tempArr->GetEntries()<1){
0064         if (debug > 1) std::cout << "nothing to be done" << std::endl;
0065         delete tempArr;
0066         continue;
0067     } else if (tempArr->GetEntries() == 1 ){
0068         // Separate the string according to space
0069         tempArr       = tempLine.Tokenize(" ");
0070         if(tempArr->GetEntries()<1){
0071             if (debug > 1) std::cout << "nothing to be done" << std::endl;
0072             delete tempArr;
0073             continue;
0074         } else if (tempArr->GetEntries() == 1  ) {
0075             if (debug > 1) std::cout << ((TString)((TObjString*)tempArr->At(0))->GetString()).Data() << " no correct format detected" << std::endl;
0076             delete tempArr;
0077             continue;
0078         }
0079     }
0080 
0081     if (tempLine.BeginsWith("sumOpt")){
0082       sumOpt  = ((TString)((TObjString*)tempArr->At(1))->GetString()).Atoi();
0083       std::cout << "read " << sumOpt << std::endl;
0084       delete tempArr;
0085       continue;
0086     }
0087     if (tempLine.BeginsWith("detector")){
0088       TString tempS = ((TString)((TObjString*)tempArr->At(1))->GetString());
0089       std::cout << tempS.Data() << std::endl;
0090       if ( tempS.Contains("Focal") || tempS.Contains("FoCal") || tempS.Contains("FOCAL")){
0091         detector  = 1;
0092         std::cout << "setting detector to FoCal" << std::endl;
0093       }
0094       delete tempArr;
0095       continue;
0096     }
0097     
0098     if (tempArr->GetEntries()<10){
0099       if (debug > 1) std::cout << "line not conform with mapping format, skipping" << std::endl;
0100       delete tempArr;
0101       continue;
0102     }
0103    
0104     AROunit     = ((TString)((TObjString*)tempArr->At(0))->GetString()).Atoi();
0105     AROchannel  = ((TString)((TObjString*)tempArr->At(1))->GetString()).Atoi();
0106     Alayer      = ((TString)((TObjString*)tempArr->At(2))->GetString()).Atoi();
0107     Anassembly  = ((TString)((TObjString*)tempArr->At(3))->GetString());
0108     AROlayer    = ((TString)((TObjString*)tempArr->At(4))->GetString()).Atoi();
0109     Arow        = ((TString)((TObjString*)tempArr->At(5))->GetString()).Atoi();
0110     Acolumn     = ((TString)((TObjString*)tempArr->At(6))->GetString()).Atoi();
0111     Amod        = ((TString)((TObjString*)tempArr->At(7))->GetString()).Atoi();
0112     float AmodX = ((TString)((TObjString*)tempArr->At(8))->GetString()).Atof();
0113     float AmodY = ((TString)((TObjString*)tempArr->At(9))->GetString()).Atof(); 
0114     segSize     = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atoi();    
0115 
0116 
0117         // Try to set map for mod pos
0118     ModPos[Amod]=std::make_pair(AmodX,AmodY);
0119     //std::cerr<< "modnr: "<< Amod <<std::endl;
0120 
0121     //set segment size per representative layer
0122     SegmentSum[Alayer] = segSize;
0123     if (detector == 0)        // single unit: maxColumns = 4, maxRows = 2
0124       Akey=(Amod<<9)+(Arow<<8)+(Acolumn<<6)+(Alayer);
0125     else if (detector == 1)   // single unit: maxColumns = 8, maxRows = 4, reuse Alayer as X module nr. & Amod as Y module nr.
0126       Akey=(Amod<<5)+(Arow<<3)+(Acolumn); //   column (3bit), row (2bit), mod rest
0127     assemblyID[Akey] = Anassembly;
0128     ROunit    [Akey] = AROunit;
0129     ROchannel [Akey] = AROchannel;
0130     Board     [Akey] = AROlayer;
0131     CellIDfromRO[std::make_pair(AROunit,AROchannel)]=Akey;
0132     if (nMaxLayer < Alayer)   nMaxLayer   = Alayer;
0133     if (nMaxRow < Arow)       nMaxRow     = Arow;
0134     if (nMaxColumn < Acolumn) nMaxColumn  = Acolumn;
0135     if (nMaxModule < Amod)    nMaxModule  = Amod;
0136     if (nMaxROUnit < AROunit) nMaxROUnit  = AROunit;
0137     if (maxCellID < Akey)     maxCellID   = Akey;
0138     if (debug > 10)std::cout <<AROunit<< "\t" << AROchannel << "\t"<< Alayer << "\t"<< Anassembly << "\t"<< AROlayer << "\t row: "<< Arow << "\t col: "<< Acolumn << "\t mod: "<< Amod << "\t"<< AmodX<< "\t"<< AmodY<< "\t"<< segSize<< std::endl;
0139     if (debug > 1)std::cout << "registered cell: " << DecodeCellID(Akey).Data() << std::endl;
0140   }
0141     
0142   input.close();
0143   isInit=true;
0144   return isInit;
0145 }
0146 
0147 bool Setup::Initialize(RootSetupWrapper& rsw){
0148   std::cout<<rsw.isInit<<"\t"<<rsw.assemblyID.size()<<std::endl;
0149   isInit          =rsw.isInit;
0150   assemblyID      =rsw.assemblyID;
0151   ROunit          =rsw.ROunit;
0152   ROchannel       =rsw.ROchannel;
0153   Board           =rsw.Board;
0154   CellIDfromRO    =rsw.CellIDfromRO;
0155   nMaxLayer       =rsw.nMaxLayer;
0156   nMaxRow         =rsw.nMaxRow;
0157   nMaxColumn      =rsw.nMaxColumn;
0158   nMaxModule      =rsw.nMaxModule;
0159   nMaxROUnit      =rsw.nMaxROUnit;
0160   maxCellID       =rsw.maxCellID;
0161   ModPos          =rsw.ModPos;
0162   SegmentSum      =rsw.SegmentSum;
0163   sumOpt          =rsw.sumOpt;
0164   detector        =rsw.detector;
0165   return isInit;
0166 }
0167 
0168 bool Setup::IsInit() const{
0169   return isInit;
0170 }
0171 
0172 TString Setup::GetAssemblyID(int cellID) const{
0173   std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0174   if(it!=assemblyID.end()) return it->second;
0175   else return "";
0176 }
0177 
0178 TString Setup::GetAssemblyID(int row, int col, int lay, int mod=0) const{
0179   if (detector == 1)
0180     return GetAssemblyID((mod<<5)+(row<<3)+col);
0181   else 
0182     return GetAssemblyID((mod<<9)+(row<<8)+(col<<6)+lay);
0183   return -1;
0184 }
0185 
0186 int Setup::GetCellID(int roboard, int roch) const{
0187   std::map<std::pair<int,int>,int>::const_iterator it=CellIDfromRO.find(std::make_pair(roboard,roch));
0188   if(it!=CellIDfromRO.cend()) return it->second;
0189   else return -1;
0190 }
0191 
0192 int Setup::GetCellID(int row, int col, int lay, int mod=0)const {
0193   if (detector == 1)
0194     return (mod<<5)+(row<<3)+col;
0195   else 
0196     return (mod<<9)+(row<<8)+(col<<6)+lay;
0197   return -1;
0198 }
0199 
0200 int Setup::GetColumn(int cellID) const{
0201   if (detector == 1)
0202     return cellID & 0x7;          // FoCal FEB uses a 3-bit column field in the low bits.
0203   else 
0204     return (cellID&(3<<6))>>6;    // return bits 6-7 (2 bits, max value 3)
0205     
0206   return -1;
0207 }
0208 
0209 int Setup::GetLayer(int cellID) const{
0210   if (detector == 1)
0211     return 0;                     // FoCal FEB uses a single-board layout with no layer index.
0212   else 
0213     return (cellID&((1<<6)-1));   // Bits 0-5 (6 bits, mask: 63)
0214   return -1;
0215 }
0216 
0217 int Setup::GetModule(int cellID) const{
0218   if (detector == 1)
0219     return (cellID >> 5);         // FoCal bit packing stores the module index in bits 5..8.
0220   return cellID>>9;               // bit 9 and above module nr. for LFHCal, index module Y for FoCal
0221 }
0222 
0223 int Setup::GetROchannel(int cellID) const{
0224   std::map<int, int>::const_iterator it=ROchannel.find(cellID);
0225   if(it!=ROchannel.end()) return it->second;
0226   else return -999;
0227 }
0228 
0229 int Setup::GetROchannel(int row, int col, int lay, int mod=0) const{
0230   if (detector == 1)
0231     return GetROchannel((mod<<5)+(row<<3)+col);
0232   return GetROchannel((mod<<9)+(row<<8)+(col<<6)+lay);
0233 }
0234 
0235 int Setup::GetROunit(int cellID) const{
0236   std::map<int,int>::const_iterator it=ROunit.find(cellID);
0237   if(it!=ROunit.end()) return it->second;
0238   else return -999;
0239 }
0240 
0241 int Setup::GetROunit(int row, int col, int lay, int mod=0) const{
0242   if (detector == 1)
0243     return GetROunit((mod<<5)+(row<<3)+col);
0244   return GetROunit((mod<<9)+(row<<8)+(col<<6)+lay);
0245 }
0246 
0247 int Setup::GetRow(int cellID) const{
0248   if (detector == 0)
0249     return (cellID&(1<<8))>>8;            //  Bit 8 (1 bit, max value 1)
0250   else if (detector == 1)
0251     return (cellID >> 3) & 0x3;           // FoCal FEB encodes the row in bits 3-4, not bit 8.
0252   return -1;
0253 }
0254 
0255 double Setup::GetModuleX(int mod)const {
0256   auto it = ModPos.find(mod);
0257   if (it != ModPos.end()) {
0258 //      std::cerr<< "My value: " << it->second.first << std::endl;
0259       return static_cast<double>(it->second.first);
0260   }
0261   else {
0262     std::cerr << "Warning: Module " << mod << " not found in ModPos\n";
0263     return -999.0;
0264   }
0265 }
0266 
0267 double Setup::GetModuleY(int mod)const {
0268   auto it = ModPos.find(mod);
0269   if (it != ModPos.end()) {
0270       return static_cast<double>(it->second.second);
0271   }
0272   else {
0273     std::cerr << "Warning: Module " << mod << " not found in ModPos\n";
0274     return -999.0;
0275   }
0276 }
0277 
0278 int Setup::GetTotalNbChannels(void) const {
0279   return (int) ROunit.size();
0280 }
0281 
0282 double Setup::GetX(int cellID) const{
0283   int col=GetColumn(cellID);
0284   return -7.5/*cm*/+col*cellW/*cm*/ + GetModuleX(GetModule(cellID));
0285 }
0286 
0287 double Setup::GetY(int cellID) const{
0288   int row=GetRow(cellID);
0289   return -2.5/*cm*/+row*cellH/*cm*/ + GetModuleY(GetModule(cellID));
0290 }
0291 
0292 double Setup::GetZ(int cellID) const{
0293   int lay=GetLayer(cellID);
0294   if (sumOpt == 0){
0295     return cellD/2 + lay*cellD/*cm*/;
0296   } else {
0297     double tempZ = 0;
0298     int row = GetRow(cellID);
0299     int col = GetColumn(cellID);
0300     int mod = GetModule(cellID);
0301     for (int l = 0; l < lay; l++){
0302       long tempCellID = GetCellID(row, col,l, mod);
0303       tempZ = tempZ+GetSegmentDepth(tempCellID);
0304     }  
0305     tempZ = tempZ+GetSegmentDepth(cellID)/2.;
0306     return tempZ;
0307   } 
0308 }
0309 
0310 int Setup::GetLayersInSegmentFromLayer(int layerNr) const{
0311   auto it = SegmentSum.find(layerNr);
0312   if (it != SegmentSum.end())
0313     return it->second;
0314   return 1;
0315 }
0316 
0317 int Setup::GetLayersInSegment(int cellID) const{
0318   int lay=GetLayer(cellID);
0319   auto it = SegmentSum.find(lay);
0320   if (it != SegmentSum.end())
0321     return it->second;
0322   return 1;
0323 }
0324 
0325 double Setup::GetSegmentDepth(int cellID) const{
0326   int lay=GetLayer(cellID);
0327   auto it = SegmentSum.find(lay);
0328   if (it != SegmentSum.end())
0329     return it->second*cellD;
0330   return cellD;
0331 }
0332 
0333 bool Setup::HasSameSegmentDepth() const{
0334   const int& firstVal = SegmentSum.begin()->second;
0335   for (const auto& [key, val] : SegmentSum) {
0336     if (val != firstVal) {
0337       return false;
0338     }
0339   }
0340   return true;
0341 }
0342 
0343 TString Setup::DecodeCellID(int cellID) const{
0344   TString out = Form("cell ID: %d ==> RO unit %d RO channel %d  module %d  layer %d  column %d row %d", cellID, GetROunit(cellID), GetROchannel(cellID), GetModule(cellID), GetLayer(cellID), GetColumn(cellID), GetRow(cellID));
0345   return out;
0346 }
0347 
0348 
0349 int Setup::GetNMaxLayer() const{
0350   return nMaxLayer;
0351 }
0352 
0353 int Setup::GetNMaxRow() const{
0354   return nMaxRow;
0355 }
0356 
0357 int Setup::GetNMaxColumn() const{
0358   return nMaxColumn;
0359 }
0360 
0361 int Setup::GetNMaxModule() const{
0362   return nMaxModule;
0363 }
0364 
0365 int Setup::GetNMaxROUnit() const{
0366   return nMaxROUnit;
0367 }
0368 
0369 int Setup::GetNMaxKCUs() const{
0370   return (int)(nMaxROUnit/2+1);
0371 }
0372 
0373 int Setup::GetMaxCellID() const{
0374   return maxCellID;
0375 }
0376 
0377 int Setup::GetMaxChannelInLayerFull() const{
0378   int maxChInLayer  = (nMaxColumn+1)*(nMaxRow+1)*(nMaxModule+1);
0379   return maxChInLayer;
0380 }
0381 
0382 
0383 int Setup::GetChannelInLayer(int cellID) const{
0384   int row     = GetRow(cellID);
0385   int column  = GetColumn(cellID);
0386   int absChL  = row*(nMaxColumn+1)+column;
0387   return absChL;
0388 }
0389 
0390 int Setup::GetChannelInLayerFull(int cellID, DetConf::Type type) const{
0391   int row     = GetRow(cellID);
0392   int column  = GetColumn(cellID);
0393   int mod     = GetModule(cellID);
0394   int absChL  = -1;
0395   
0396   if (type == DetConf::Type::Unset){
0397     type = GetDetectorConfig();
0398   }
0399   // Dual 8M
0400   if ( type == DetConf::Type::Dual8M){
0401     absChL    = mod*((nMaxColumn+1)*(nMaxRow+1))+row*(nMaxColumn+1)+column;
0402   // Medium TB
0403   } else if ( type == DetConf::Type::MediumTB){
0404     if (mod%2 == 0){
0405       absChL = mod%2*((nMaxColumn+1) *(nMaxRow+1))+row*(nMaxColumn+1)*2+column+(int)mod/2*16;
0406     } else {
0407       absChL = (mod%2-1)*((nMaxColumn+1) *(nMaxRow+1))+row*(nMaxColumn+1)*2+column+(int)(mod-1)/2*16 + (nMaxColumn+1);
0408     }
0409   // Single 8M module
0410   } else if ( type == DetConf::Type::Single8M){
0411     absChL = row*(nMaxColumn+1)+column;
0412   // Focal or Asic geom
0413   } else if ( type == DetConf::Type::FocalH || type == DetConf::Type::Asic){
0414     absChL = mod*((nMaxColumn+1)*(nMaxRow+1))+row*(nMaxColumn+1)+column;
0415   }
0416   return absChL;
0417 }
0418 
0419 int Setup::GetAbsRow(int cellID, DetConf::Type type) const{
0420   int row     = GetRow(cellID);
0421   int mod     = GetModule(cellID);
0422   int absRow  = row;
0423   
0424   if (type == DetConf::Type::Unset){
0425     type = GetDetectorConfig();
0426   }
0427   // Dual 8M
0428   if ( type == DetConf::Type::Dual8M){
0429     absRow    = mod * (nMaxRow+1) + row;
0430     
0431   // Medium TB
0432   } else if ( type == DetConf::Type::MediumTB){
0433     if (mod%2 == 0){
0434       absRow = int(mod/2) * (nMaxRow+1) + row;
0435     } else {
0436       absRow = int((mod-1)/2)* (nMaxRow+1) + row;
0437     }
0438   // Single 8M module
0439   } else if ( type == DetConf::Type::Single8M){
0440     absRow = row;
0441   // Focal or Asic geom
0442   } else if ( type == DetConf::Type::FocalH || type == DetConf::Type::Asic){
0443     absRow = row;
0444   }
0445   return absRow;
0446 }
0447 
0448 int Setup::GetAbsColumn(int cellID, DetConf::Type type) const{
0449   int col     = GetColumn(cellID);
0450   int mod     = GetModule(cellID);
0451   int absCol  = col;
0452   
0453   if (type == DetConf::Type::Unset){
0454     type = GetDetectorConfig();
0455   }
0456   // Dual 8M
0457   if ( type == DetConf::Type::Dual8M){
0458     absCol    = col;
0459   // Medium TB
0460   } else if ( type == DetConf::Type::MediumTB){
0461     
0462     absCol = mod%2 * (nMaxColumn+1) + col;
0463     
0464   // Single 8M module
0465   } else if ( type == DetConf::Type::Single8M){
0466     absCol = col;
0467   // Focal or Asic geom
0468   } else if ( type == DetConf::Type::FocalH || type == DetConf::Type::Asic){
0469     absCol = col;
0470   }
0471   return absCol;
0472 }
0473 
0474 
0475 
0476 int Setup::GetAbsNMaxROChannel() const{
0477   int max = -1;
0478   std::map<int, int>::const_iterator it;
0479   for(it=ROchannel.begin(); it!=ROchannel.end(); ++it){
0480     if( it->second > max ) max = it->second;
0481   }
0482   return max; 
0483 }
0484 
0485 float Setup::GetMinX() const{
0486   float min = 1e6;
0487   std::map<int, TString>::const_iterator it;
0488   for(it=assemblyID.begin(); it!=assemblyID.end(); ++it){
0489     int cellID = it->first;
0490     if( GetX(cellID) < min ) min = GetX(cellID);
0491   }
0492   return min-(cellW/2);/*to get to the center of the tile*/
0493 }
0494 
0495 float Setup::GetMaxX() const{
0496   float max = -1e6;
0497   std::map<int, TString>::const_iterator it;
0498   for(it=assemblyID.begin(); it!=assemblyID.end(); ++it){
0499     int cellID = it->first;
0500     if( GetX(cellID) > max ) max = GetX(cellID);
0501   }
0502   return max+(cellW/2);/*to get to the center of the tile*/
0503 }
0504 
0505 float Setup::GetMinY() const{
0506   float min = 1e6;
0507   std::map<int, TString>::const_iterator it;
0508   for(it=assemblyID.begin(); it!=assemblyID.end(); ++it){
0509     int cellID = it->first;
0510     if( GetY(cellID) < min ) min = GetY(cellID);
0511   }
0512   return min-(cellH/2);/*to get to the center of the tile*/
0513 }
0514 
0515 float Setup::GetMaxY() const{
0516   float max = -1e6;
0517   std::map<int, TString>::const_iterator it;
0518   for(it=assemblyID.begin(); it!=assemblyID.end(); ++it){
0519     int cellID = it->first;
0520     if( GetY(cellID) > max ) max = GetY(cellID);
0521   }
0522   return max+(cellH/2);/*to get to the center of the tile*/
0523 }
0524 
0525 float Setup::GetMinZ() const{
0526   float min = 1e6;
0527   std::map<int, TString>::const_iterator it;
0528   for(it=assemblyID.begin(); it!=assemblyID.end(); ++it){
0529     int cellID = it->first;
0530     if( GetZ(cellID) < min ) min = GetZ(cellID)-(GetSegmentDepth(cellID)/2);
0531   }
0532   return min;/*to get to the beginning of tile*/
0533 }
0534 
0535 float Setup::GetMaxZ() const{
0536   float max = -1e6;
0537   std::map<int, TString>::const_iterator it;
0538   for(it=assemblyID.begin(); it!=assemblyID.end(); ++it){
0539     int cellID = it->first;
0540     if( GetZ(cellID) > max ) max = GetZ(cellID)+(GetSegmentDepth(cellID)/2);
0541   }
0542   return max;/*to get to the end of tile*/
0543 }
0544 
0545 std::vector<double> Setup::GetZBinEdges() const{  // for summing
0546   std::vector<double> edges;
0547   double z = GetMinZ();
0548   edges.push_back(z);
0549   for (int lay = 0; lay <= nMaxLayer; lay++){
0550     z += GetLayersInSegmentFromLayer(lay) * cellD;
0551     edges.push_back(z);
0552   }
0553   return edges;
0554 }
0555 
0556 bool Setup::IsLayerOn(int layer, int mod) const{
0557   bool isOn = false;
0558   for (int r = 0; r< GetNMaxRow(); r++){
0559     for (int c = 0; c < GetNMaxColumn(); c++){
0560       if (mod == -1){
0561         for (int m = 0; m < GetNMaxModule(); m++){
0562           int cellID = GetCellID(r, c, layer, m);
0563           std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0564           if (it != assemblyID.end()){
0565             isOn = true;
0566             break;
0567           }
0568         }
0569       } else {
0570         int cellID = GetCellID(r, c, layer, mod);
0571         std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0572         if (it != assemblyID.end()){
0573           isOn = true;
0574           break;
0575         }
0576       }
0577     }
0578   }
0579   return isOn;
0580 }
0581 
0582 // to check FoCal FEB
0583 bool Setup::IsModuleOn(int mod) const{
0584   bool isOn = false;
0585   for (int r = 0; r< GetNMaxRow(); r++){
0586     for (int c = 0; c < GetNMaxColumn(); c++){
0587       int cellID = GetCellID(r, c, 0, mod);     // for FoCal FEB, layer is always 0
0588       std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0589       if (it != assemblyID.end()){
0590         isOn = true;
0591         break;        
0592       }
0593     }
0594   }
0595   return isOn;
0596 }
0597 
0598 bool Setup::IsAsicOn(int asic) const{
0599   bool isOn = false;
0600   for (int ch = 0; ch< 76; ch++){
0601     int cellID = GetCellID(asic, ch);
0602     std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0603     if (it != assemblyID.end()){
0604       isOn = true;
0605       break;
0606     }    
0607   }
0608   return isOn;
0609 }
0610 
0611 
0612 int Setup::GetNActiveLayers() const{
0613   int nActLayer = 0;
0614   for (Int_t l = 0; l < GetNMaxLayer()+1; l++){
0615     if (IsLayerOn(l,-1)) nActLayer++;
0616   }
0617   return nActLayer;
0618 }
0619 
0620 int Setup::GetNActiveCells() const{
0621   int nActCells = assemblyID.size();
0622   return nActCells;
0623 }
0624 
0625 float Setup::GetCellWidth() const{
0626   return cellW;
0627 }
0628 
0629 float Setup::GetCellHeight() const{
0630   return cellH;
0631 }
0632 
0633 float Setup::GetCellDepth() const{
0634   return cellD;
0635 }
0636 
0637 DetConf::Type Setup::GetDetectorConfig() const{
0638   DetConf::Type type;
0639   std::cout << "Detector: " << GetDetector() << std::endl;
0640   if (GetDetector() == 1){
0641     type = DetConf::Type::FocalH;
0642   } else {
0643     if (GetNMaxModule()+1 == 2){
0644       if (GetNMaxRow()+1 == 2 && GetNMaxColumn()+1 == 4)
0645         type = DetConf::Type::Dual8M;
0646       else 
0647         type = DetConf::Type::Undef;
0648     } else if (GetNMaxModule()+1 == 8){
0649       if(GetNMaxRow()+1 == 2 && GetNMaxColumn()+1 == 4)
0650         type = DetConf::Type::LargeTB;
0651       else 
0652         type = DetConf::Type::Undef;
0653     } else if (GetNMaxModule()+1 == 6){
0654       if(GetNMaxRow()+1 == 2 && GetNMaxColumn()+1 == 4)
0655         type = DetConf::Type::MediumTB;
0656       else 
0657         type = DetConf::Type::Undef;
0658     } else if (GetNMaxModule()+1 == 1){
0659       if (GetNMaxRow()+1 == 2 && GetNMaxColumn()+1 == 4)
0660         type = DetConf::Type::Single8M;
0661       else if (GetNMaxRow()+1 == 2 && GetNMaxColumn()+1 == 2)
0662         type = DetConf::Type::Single4M;
0663       else if (GetNMaxRow()+1 == 1 && GetNMaxColumn()+1 == 2)
0664         type = DetConf::Type::Single2MH;
0665       else if (GetNMaxRow()+1 == 2 && GetNMaxColumn()+1 == 1)
0666         type = DetConf::Type::Single2MV;
0667       else if (GetNMaxRow()+1 == 1 && GetNMaxColumn()+1 == 1)
0668         type = DetConf::Type::SingleTile;
0669       else 
0670         type = DetConf::Type::Undef;
0671     } else {
0672       type = DetConf::Type::Undef;
0673     }
0674   }
0675   return type;
0676 }
0677 
0678 int Setup::GetAbsMaxColumnsSetup( DetConf::Type type){
0679   int maxCol = nMaxColumn+1;
0680   // Dual 8M
0681   if ( type == DetConf::Type::Dual8M){
0682     maxCol = nMaxColumn+1;
0683   // Medium TB
0684   } else if ( type == DetConf::Type::MediumTB){
0685     maxCol = (nMaxColumn+1)*2;
0686   // Single 8M module
0687   } else if ( type == DetConf::Type::Single8M){
0688     maxCol = nMaxColumn+1;
0689   // Focal or Asic geom
0690   } else if ( type == DetConf::Type::FocalH || type == DetConf::Type::Asic){
0691     maxCol = 8;   // fixed number
0692   }
0693   return maxCol;
0694 }
0695 
0696 int Setup::GetAbsMaxRowsSetup( DetConf::Type type){
0697   int maxRow = nMaxRow+1;
0698   // Dual 8M
0699   if ( type == DetConf::Type::Dual8M){
0700     maxRow = (nMaxRow+1)*2;
0701   // Medium TB
0702   } else if ( type == DetConf::Type::MediumTB){
0703     maxRow = (nMaxRow+1)*3;
0704   // Single 8M module
0705   } else if ( type == DetConf::Type::Single8M){
0706     maxRow = nMaxRow+1;
0707   // Focal or Asic geom
0708   } else if ( type == DetConf::Type::FocalH || type == DetConf::Type::Asic){
0709     maxRow = 8;   // fixed number
0710   }
0711   return maxRow;
0712 }
0713 
0714 
0715 bool Setup::ContainedInSetup(int cellID) const{
0716   std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0717   if(it!=assemblyID.end()) return true;
0718   else return false;
0719 }
0720