Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:15:46

0001 #include "Setup.h"
0002 #include "RootSetupWrapper.h"
0003 #include <iostream>
0004 #include <fstream>
0005 
0006 //Setup* Setup::instancePtr = nullptr; // Add for use on Mac OS
0007 
0008 ClassImp(Setup);
0009 
0010 bool Setup::Initialize(TString file, int debug){
0011   if(isInit){
0012     std::cout<<"Already initialized, bailing out without action"<<std::endl;
0013     return true;
0014   }
0015   std::fstream input;
0016   input.open(file.Data(),std::ios::in);
0017   if(!input.is_open()){
0018     std::cout<<"Could not open "<<file<<std::endl;
0019     std::cout<<"Leaving uninitialized"<<std::endl;
0020     return false;
0021   }
0022   nMaxLayer   = -1;
0023   nMaxRow     = -1;
0024   nMaxColumn  = -1;
0025   nMaxModule  = -1;
0026   nMaxROUnit  = -1;
0027   maxCellID   = -1;
0028   int AROunit,AROchannel,Alayer,AROlayer,Arow,Acolumn,Amod;
0029   TString Anassembly;
0030   int Akey;
0031   while(!input.eof()){
0032     input>>AROunit>>AROchannel>>Alayer>>Anassembly>>AROlayer>>Arow>>Acolumn >> Amod;
0033     if(!input.good())break;
0034     Akey=(Amod<<9)+(Arow<<8)+(Acolumn<<6)+(Alayer);
0035     assemblyID[Akey] = Anassembly;
0036     ROunit    [Akey] = AROunit;
0037     ROchannel [Akey] = AROchannel;
0038     Board     [Akey] = AROlayer;
0039     CellIDfromRO[std::make_pair(AROunit,AROchannel)]=Akey;
0040     if (nMaxLayer < Alayer)   nMaxLayer   = Alayer;
0041     if (nMaxRow < Arow)       nMaxRow     = Arow;
0042     if (nMaxColumn < Acolumn) nMaxColumn  = Acolumn;
0043     if (nMaxModule < Amod)    nMaxModule  = Amod;
0044     if (nMaxROUnit < AROunit) nMaxROUnit  = AROunit;
0045     if (maxCellID < Akey)     maxCellID   = Akey;
0046     if (debug > 10)std::cout <<AROunit<< "\t" << AROchannel << "\t"<< Alayer << "\t"<< Anassembly << "\t"<< AROlayer << "\t"<< Arow << "\t"<< Acolumn << "\t"<< Amod << std::endl;
0047     if (debug > 1)std::cout << "registered cell: " << DecodeCellID(Akey).Data() << std::endl;
0048   }
0049   input.close();
0050   isInit=true;
0051   return isInit;
0052 }
0053 
0054 bool Setup::Initialize(RootSetupWrapper& rsw){
0055   std::cout<<rsw.isInit<<"\t"<<rsw.assemblyID.size()<<std::endl;
0056   isInit          =rsw.isInit;
0057   assemblyID      =rsw.assemblyID;
0058   ROunit          =rsw.ROunit;
0059   ROchannel       =rsw.ROchannel;
0060   Board           =rsw.Board;
0061   CellIDfromRO    =rsw.CellIDfromRO;
0062   nMaxLayer       =rsw.nMaxLayer;
0063   nMaxRow         =rsw.nMaxRow;
0064   nMaxColumn      =rsw.nMaxColumn;
0065   nMaxModule      =rsw.nMaxModule;
0066   nMaxROUnit      =rsw.nMaxROUnit;
0067   maxCellID       =rsw.maxCellID;
0068   return isInit;
0069 }
0070 
0071 bool Setup::IsInit() const{
0072   return isInit;
0073 }
0074 
0075 TString Setup::GetAssemblyID(int cellID) const{
0076   std::map<int, TString>::const_iterator it=assemblyID.find(cellID);
0077   if(it!=assemblyID.end()) return it->second;
0078   else return "";
0079 }
0080 
0081 TString Setup::GetAssemblyID(int row, int col, int lay, int mod=0) const{
0082   return GetAssemblyID((mod<<9)+(row<<8)+(col<<6)+lay);
0083 }
0084 
0085 int Setup::GetCellID(int roboard, int roch) const{
0086   std::map<std::pair<int,int>,int>::const_iterator it=CellIDfromRO.find(std::make_pair(roboard,roch));
0087   if(it!=CellIDfromRO.cend()) return it->second;
0088   else return -1;
0089 }
0090 
0091 int Setup::GetCellID(int row, int col, int lay, int mod=0)const {
0092   return (mod<<9)+(row<<8)+(col<<6)+lay;
0093 }
0094 
0095 int Setup::GetColumn(int cellID) const{
0096   return (cellID&(3<<6))>>6;
0097 }
0098 
0099 int Setup::GetLayer(int cellID) const{
0100   return (cellID&((1<<6)-1));
0101 }
0102 
0103 int Setup::GetModule(int cellID) const{
0104   return cellID>>9;
0105 }
0106 
0107 int Setup::GetROchannel(int cellID) const{
0108   std::map<int, int>::const_iterator it=ROchannel.find(cellID);
0109   if(it!=ROchannel.end()) return it->second;
0110   else return -999;
0111 }
0112 
0113 int Setup::GetROchannel(int row, int col, int lay, int mod=0) const{
0114   return GetROchannel((mod<<9)+(row<<8)+(col<<6)+lay);
0115 }
0116 
0117 int Setup::GetROunit(int cellID) const{
0118   std::map<int,int>::const_iterator it=ROunit.find(cellID);
0119   if(it!=ROunit.end()) return it->second;
0120   else return -999;
0121 }
0122 
0123 int Setup::GetROunit(int row, int col, int lay, int mod=0) const{
0124   return GetROunit((mod<<9)+(row<<8)+(col<<6)+lay);
0125 }
0126 
0127 int Setup::GetRow(int cellID) const{
0128   return (cellID&(1<<8))>>8;
0129 }
0130 
0131 double Setup::GetModuleX(int mod=0)const {
0132   return 0.;
0133 }
0134 
0135 double Setup::GetModuleY(int mod=0)const {
0136   return 0.;
0137 }
0138 
0139 int Setup::GetTotalNbChannels(void) const {
0140   return (int) ROunit.size();
0141 }
0142 
0143 double Setup::GetX(int cellID) const{
0144   int col=GetColumn(cellID);
0145   return -7.5/*cm*/+col*5./*cm*/ /*+GetModuleX()*/;
0146 }
0147 
0148 double Setup::GetY(int cellID) const{
0149   int row=GetRow(cellID);
0150   return (2*row-1)*2.5/*cm*/ /* +GetModuleY()*/;
0151 }
0152 
0153 double Setup::GetZ(int cellID) const{
0154   int lay=GetLayer(cellID);
0155   return lay*2.0/*cm*/;
0156 }
0157 
0158 TString Setup::DecodeCellID(int cellID) const{
0159   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));
0160   return out;
0161 }
0162 
0163 
0164 int Setup::GetNMaxLayer() const{
0165   return nMaxLayer;
0166 }
0167 
0168 int Setup::GetNMaxRow() const{
0169   return nMaxRow;
0170 }
0171 
0172 int Setup::GetNMaxColumn() const{
0173   return nMaxColumn;
0174 }
0175 
0176 int Setup::GetNMaxModule() const{
0177   return nMaxModule;
0178 }
0179 
0180 int Setup::GetNMaxROUnit() const{
0181   return nMaxROUnit;
0182 }
0183 
0184 int Setup::GetMaxCellID() const{
0185   return maxCellID;
0186 }
0187 
0188 int Setup::GetChannelInLayer(int cellID) const{
0189   int row     = GetRow(cellID);
0190   int column  = GetColumn(cellID);
0191   int absChL  = row*(nMaxColumn+1)+column;
0192   return absChL;
0193 }