Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:55:55

0001 #include "Event.h"
0002 
0003 int Event::GetRunNumber(void) const{
0004   return RunNumber;
0005 }
0006 
0007 int Event::GetEventID(void) const{
0008   return EventID;
0009 }
0010 
0011 int Event::GetTimeStamp(void) const{
0012   return TimeStamp;
0013 }
0014 
0015 ReadOut::Type Event::GetROtype(void) const{
0016   return ROtype;
0017 }
0018 
0019 void Event::SetRunNumber(int r){
0020   RunNumber=r;
0021 }
0022 
0023 void Event::SetEventID(int ev){
0024   EventID=ev;
0025 }
0026 
0027 void Event::SetTimeStamp(int t){
0028   TimeStamp=t;
0029 }
0030 
0031 void Event::SetROtype(ReadOut::Type ro){
0032   ROtype=ro;
0033 }
0034 
0035 TString Event::GetBeamName(void)const{
0036   return BeamName;
0037 }
0038 
0039 int Event::GetBeamID(void) const{
0040   return BeamID;
0041 }
0042 
0043 double Event::GetBeamEnergy(void) const{
0044   return BeamEnergy;
0045 }
0046 
0047 void Event::SetBeamName(TString n){
0048   BeamName=n;
0049 }
0050 
0051 void Event::SetBeamID(int id){
0052   BeamID=id;
0053 }
0054 
0055 void Event::SetBeamEnergy(double e){
0056   BeamEnergy=e;
0057 }
0058 
0059 void Event::AddTile(Tile* t){
0060   int id=t->GetCellID();
0061   std::map<int, Tile*>::iterator it=Tiles.find(id);
0062   if(it!=Tiles.end()){
0063     delete it->second;
0064     it->second=t;
0065     // std::cerr<<"What the hell am I doing here?, Or did I ClearTiles before ?"<<std::endl;
0066   }
0067   else{
0068     Tiles[id]=t;
0069     TileIDs.push_back(id);
0070   }
0071 }
0072 
0073 void Event::RemoveTile(Tile* t){
0074   int id=t->GetCellID();
0075   std::map<int, Tile*>::iterator it=Tiles.find(id);
0076   if(it!=Tiles.end()){
0077     delete it->second;
0078     Tiles.erase(it);
0079     TileIDs.erase(std::find(TileIDs.begin(),TileIDs.end(),id));
0080   }
0081   else{
0082     std::cerr<<"Tile does not belong to the stack in this event, dunno what went wrong"<<std::endl;
0083   }
0084 }
0085 
0086 Tile* Event::GetTile(int index){
0087   int tempID = TileIDs.at(index);
0088   return GetTileFromID(tempID);
0089 }
0090 
0091 Tile* Event::GetTileFromID(int id){
0092   std::map<int, Tile*>::iterator it=Tiles.find(id);
0093   if(it!=Tiles.end()) return it->second;
0094   else return nullptr;
0095 }
0096 
0097 int Event::GetNTiles(void)const{
0098   return (int)Tiles.size();
0099 }
0100 
0101 void Event::ClearTiles(void){
0102   std::map<int, Tile*>::iterator it;
0103   for(it=Tiles.begin(); it!=Tiles.end(); ++it){
0104     delete it->second;
0105     it->second=NULL;
0106   }
0107   Tiles.clear();
0108   TileIDs.clear();
0109 }
0110 
0111 double Event::GetVov() const{
0112   return Vov;
0113 }
0114 
0115 double Event::GetVop()const{
0116   return Vop;
0117 }
0118 
0119 double Event::GetBeamPosX(void) {
0120   return BeamPosX;
0121 }
0122 
0123 double Event::GetBeamPosY(void){
0124   return BeamPosY;
0125 }
0126 
0127 const TTimeStamp* Event::GetBeginRunTime(void) const{
0128   return &BeginRun;
0129 }
0130 
0131 TTimeStamp Event::GetBeginRunTimeAlt(void){
0132   return BeginRun;
0133 }
0134 
0135 void Event::SetVov(double v){
0136   Vov=v;
0137 }
0138 
0139 void Event::SetVop(double v){
0140   Vop=v;
0141 }
0142 void Event::SetBeamPosX(double x){
0143   BeamPosX=x;
0144 }
0145 void Event::SetBeamPosY(double y){
0146   BeamPosY=y;
0147 }
0148 void Event::SetBeginRunTime(TTimeStamp t){
0149   BeginRun=t;
0150 }
0151 
0152 bool Event::InspectIfLocalMuonTrigg( int currTileID, 
0153                                      double averageScale,
0154                                      double minThrSc = 0.9, 
0155                                      double maxThrSc = 3
0156                                     ){
0157   
0158   double trPrim = ((Caen*)GetTileFromID(currTileID))->GetLocalTriggerPrimitive();
0159   // evaluate stored trigger primitive
0160   if (trPrim >  averageScale*minThrSc && trPrim < maxThrSc*averageScale)
0161     return true;
0162   else 
0163     return false;
0164     
0165 }
0166 
0167 bool Event::InspectIfNoiseTrigg( int currTileID, 
0168                                 double averageScale,
0169                                 double minThrSc = 0.9
0170                               ){
0171   double trPrim = ((Caen*)GetTileFromID(currTileID))->GetLocalTriggerPrimitive();
0172   // evaluate stored trigger primitive
0173   if (trPrim < averageScale*minThrSc )
0174     return true;
0175   else 
0176     return false;
0177     
0178 }
0179 
0180 double Event::CalculateLocalMuonTrigg(  Calib calib, 
0181                                         TRandom3* rand,
0182                                         int currTileID, 
0183                                         int nTiles = 4,
0184                                         double avLGHG = 10.
0185                                       ){
0186   
0187   // figure out surrounding tiles for local mip selection
0188   Setup* setup = Setup::GetInstance();
0189   long ids[6]  = {-1, -1, -1, -1, -1, -1};
0190   int layer     = setup->GetLayer(currTileID);
0191   int row       = setup->GetRow(currTileID);
0192   int col       = setup->GetColumn(currTileID);
0193   int mod       = setup->GetModule(currTileID);
0194   if (nTiles == 4){
0195     if (layer == 0){
0196       ids[0] = setup->GetCellID(row, col, layer+1,mod);
0197       ids[1] = setup->GetCellID(row, col, layer+2,mod);
0198       ids[2] = setup->GetCellID(row, col, layer+3,mod);
0199       ids[3] = setup->GetCellID(row, col, layer+4,mod);
0200     }else if (layer == 1){
0201       ids[0] = setup->GetCellID(row, col, layer-1,mod);
0202       ids[1] = setup->GetCellID(row, col, layer+1,mod);
0203       ids[2] = setup->GetCellID(row, col, layer+2,mod);
0204       ids[3] = setup->GetCellID(row, col, layer+3,mod);
0205     } else if (layer == setup->GetNMaxLayer()-1){
0206       ids[0] = setup->GetCellID(row, col, layer-3,mod);
0207       ids[1] = setup->GetCellID(row, col, layer-2,mod);
0208       ids[2] = setup->GetCellID(row, col, layer-1,mod);
0209       ids[3] = setup->GetCellID(row, col, layer+1,mod);      
0210     } else if (layer == setup->GetNMaxLayer()){
0211       ids[0] = setup->GetCellID(row, col, layer-4,mod);
0212       ids[1] = setup->GetCellID(row, col, layer-3,mod);
0213       ids[2] = setup->GetCellID(row, col, layer-2,mod);
0214       ids[3] = setup->GetCellID(row, col, layer-1,mod);      
0215     } else {
0216       ids[0] = setup->GetCellID(row, col, layer-2,mod);
0217       ids[1] = setup->GetCellID(row, col, layer-1,mod);
0218       ids[2] = setup->GetCellID(row, col, layer+1,mod);
0219       ids[3] = setup->GetCellID(row, col, layer+2,mod);
0220     }
0221   } else if (nTiles == 6){  
0222     if (layer == 0){
0223       ids[0] = setup->GetCellID(row, col, layer+1,mod);
0224       ids[1] = setup->GetCellID(row, col, layer+2,mod);
0225       ids[2] = setup->GetCellID(row, col, layer+3,mod);
0226       ids[3] = setup->GetCellID(row, col, layer+4,mod);
0227       ids[4] = setup->GetCellID(row, col, layer+5,mod);
0228       ids[5] = setup->GetCellID(row, col, layer+6,mod);
0229     }else if (layer == 1){
0230       ids[0] = setup->GetCellID(row, col, layer-1,mod);
0231       ids[1] = setup->GetCellID(row, col, layer+1,mod);
0232       ids[2] = setup->GetCellID(row, col, layer+2,mod);
0233       ids[3] = setup->GetCellID(row, col, layer+3,mod);
0234       ids[4] = setup->GetCellID(row, col, layer+4,mod);
0235       ids[5] = setup->GetCellID(row, col, layer+5,mod);
0236     }else if (layer == 2){
0237       ids[0] = setup->GetCellID(row, col, layer-2,mod);
0238       ids[1] = setup->GetCellID(row, col, layer-1,mod);
0239       ids[2] = setup->GetCellID(row, col, layer+1,mod);
0240       ids[3] = setup->GetCellID(row, col, layer+2,mod);
0241       ids[4] = setup->GetCellID(row, col, layer+3,mod);
0242       ids[5] = setup->GetCellID(row, col, layer+4,mod);
0243     } else if (layer == setup->GetNMaxLayer()-2){
0244       ids[0] = setup->GetCellID(row, col, layer-4,mod);
0245       ids[1] = setup->GetCellID(row, col, layer-3,mod);
0246       ids[2] = setup->GetCellID(row, col, layer-2,mod);
0247       ids[3] = setup->GetCellID(row, col, layer-1,mod);
0248       ids[4] = setup->GetCellID(row, col, layer+1,mod);
0249       ids[5] = setup->GetCellID(row, col, layer+2,mod);      
0250     } else if (layer == setup->GetNMaxLayer()-1){
0251       ids[0] = setup->GetCellID(row, col, layer-5,mod);
0252       ids[1] = setup->GetCellID(row, col, layer-4,mod);
0253       ids[2] = setup->GetCellID(row, col, layer-3,mod);
0254       ids[3] = setup->GetCellID(row, col, layer-2,mod);
0255       ids[4] = setup->GetCellID(row, col, layer-1,mod);
0256       ids[5] = setup->GetCellID(row, col, layer+1,mod);      
0257     } else if (layer == setup->GetNMaxLayer()){
0258       ids[0] = setup->GetCellID(row, col, layer-6,mod);
0259       ids[1] = setup->GetCellID(row, col, layer-5,mod);
0260       ids[2] = setup->GetCellID(row, col, layer-4,mod);
0261       ids[3] = setup->GetCellID(row, col, layer-3,mod);
0262       ids[4] = setup->GetCellID(row, col, layer-2,mod);
0263       ids[5] = setup->GetCellID(row, col, layer-1,mod);      
0264     } else {
0265       ids[0] = setup->GetCellID(row, col, layer-3,mod);
0266       ids[1] = setup->GetCellID(row, col, layer-2,mod);
0267       ids[2] = setup->GetCellID(row, col, layer-1,mod);
0268       ids[3] = setup->GetCellID(row, col, layer+1,mod);
0269       ids[4] = setup->GetCellID(row, col, layer+2,mod);
0270       ids[5] = setup->GetCellID(row, col, layer+3,mod);
0271     }
0272     
0273   } else if (nTiles == 2){
0274     if (layer == 0){
0275       ids[0] = setup->GetCellID(row, col, layer+1,mod);
0276       ids[1] = setup->GetCellID(row, col, layer+2,mod);            
0277     } else if (layer == setup->GetNMaxLayer()){
0278       ids[0] = setup->GetCellID(row, col, layer-2,mod);
0279       ids[1] = setup->GetCellID(row, col, layer-1,mod);          
0280     } else {
0281       ids[0] = setup->GetCellID(row, col, layer-1,mod);
0282       ids[1] = setup->GetCellID(row, col, layer+1,mod);      
0283     }
0284   }
0285   // calculate average sum of surrounding tiles (nominally 2 in the front + 2 in the back)
0286   double avsurr = 0;
0287   Int_t activeTiles = nTiles;
0288   for (Int_t t = 0; t < nTiles; t++){
0289     if ((Caen*)GetTileFromID(ids[t]) == nullptr){
0290       activeTiles--;
0291       continue;
0292     }
0293     if (calib.GetBCCalib()){
0294       if (calib.GetBadChannel(ids[t]) != -64  && calib.GetBadChannel(ids[t]) < 3){
0295         activeTiles--;
0296         continue;
0297       }
0298     }
0299     double tmpGain  = 0;
0300     double scale    = (calib.GetLGHGCorr(ids[t]) == -64.) ? avLGHG : calib.GetLGHGCorr(ids[t]);     // only use LG-HG corr factor if fit succeeded, otherwise use average
0301     // calculating combined gain
0302     if (((Caen*)GetTileFromID(ids[t]))->GetADCHigh() < 3800)
0303       tmpGain = ((Caen*)GetTileFromID(ids[t]))->GetADCHigh()-calib.GetPedestalMeanH(ids[t]); 
0304     else 
0305       tmpGain = (((Caen*)GetTileFromID(ids[t]))->GetADCLow()-calib.GetPedestalMeanL(ids[t]))*scale + rand->Rndm()*scale;
0306       
0307     if (tmpGain > 3*calib.GetPedestalSigH(ids[t]))
0308       avsurr +=tmpGain;
0309   }
0310   if (activeTiles > 1)
0311     avsurr        = avsurr/activeTiles;
0312   return avsurr;
0313 }
0314