File indexing completed on 2025-10-28 07:58:05
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 double 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(double 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
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 = ((Tile*)GetTileFromID(currTileID))->GetLocalTriggerPrimitive();
0159
0160
0161 if (trPrim > averageScale*minThrSc && trPrim < maxThrSc*averageScale)
0162 return true;
0163 else
0164 return false;
0165
0166 }
0167
0168 bool Event::InspectIfNoiseTrigg( int currTileID,
0169 double averageScale,
0170 double minThrSc = 0.9
0171 ){
0172 double trPrim = ((Tile*)GetTileFromID(currTileID))->GetLocalTriggerPrimitive();
0173
0174 if (trPrim < averageScale*minThrSc )
0175 return true;
0176 else
0177 return false;
0178
0179 }
0180
0181 double Event::CalculateLocalMuonTrigg( Calib calib,
0182 TRandom3* rand,
0183 int currTileID,
0184 int nTiles = 4,
0185 double avLGHG = 10.
0186 ){
0187
0188
0189 Setup* setup = Setup::GetInstance();
0190 long ids[6] = {-1, -1, -1, -1, -1, -1};
0191 int layer = setup->GetLayer(currTileID);
0192 int row = setup->GetRow(currTileID);
0193 int col = setup->GetColumn(currTileID);
0194 int mod = setup->GetModule(currTileID);
0195 if (nTiles == 4){
0196 if (layer == 0){
0197 ids[0] = setup->GetCellID(row, col, layer+1,mod);
0198 ids[1] = setup->GetCellID(row, col, layer+2,mod);
0199 ids[2] = setup->GetCellID(row, col, layer+3,mod);
0200 ids[3] = setup->GetCellID(row, col, layer+4,mod);
0201 }else if (layer == 1){
0202 ids[0] = setup->GetCellID(row, col, layer-1,mod);
0203 ids[1] = setup->GetCellID(row, col, layer+1,mod);
0204 ids[2] = setup->GetCellID(row, col, layer+2,mod);
0205 ids[3] = setup->GetCellID(row, col, layer+3,mod);
0206 } else if (layer == setup->GetNMaxLayer()-1){
0207 ids[0] = setup->GetCellID(row, col, layer-3,mod);
0208 ids[1] = setup->GetCellID(row, col, layer-2,mod);
0209 ids[2] = setup->GetCellID(row, col, layer-1,mod);
0210 ids[3] = setup->GetCellID(row, col, layer+1,mod);
0211 } else if (layer == setup->GetNMaxLayer()){
0212 ids[0] = setup->GetCellID(row, col, layer-4,mod);
0213 ids[1] = setup->GetCellID(row, col, layer-3,mod);
0214 ids[2] = setup->GetCellID(row, col, layer-2,mod);
0215 ids[3] = setup->GetCellID(row, col, layer-1,mod);
0216 } else {
0217 ids[0] = setup->GetCellID(row, col, layer-2,mod);
0218 ids[1] = setup->GetCellID(row, col, layer-1,mod);
0219 ids[2] = setup->GetCellID(row, col, layer+1,mod);
0220 ids[3] = setup->GetCellID(row, col, layer+2,mod);
0221 }
0222 } else if (nTiles == 6){
0223 if (layer == 0){
0224 ids[0] = setup->GetCellID(row, col, layer+1,mod);
0225 ids[1] = setup->GetCellID(row, col, layer+2,mod);
0226 ids[2] = setup->GetCellID(row, col, layer+3,mod);
0227 ids[3] = setup->GetCellID(row, col, layer+4,mod);
0228 ids[4] = setup->GetCellID(row, col, layer+5,mod);
0229 ids[5] = setup->GetCellID(row, col, layer+6,mod);
0230 }else if (layer == 1){
0231 ids[0] = setup->GetCellID(row, col, layer-1,mod);
0232 ids[1] = setup->GetCellID(row, col, layer+1,mod);
0233 ids[2] = setup->GetCellID(row, col, layer+2,mod);
0234 ids[3] = setup->GetCellID(row, col, layer+3,mod);
0235 ids[4] = setup->GetCellID(row, col, layer+4,mod);
0236 ids[5] = setup->GetCellID(row, col, layer+5,mod);
0237 }else if (layer == 2){
0238 ids[0] = setup->GetCellID(row, col, layer-2,mod);
0239 ids[1] = setup->GetCellID(row, col, layer-1,mod);
0240 ids[2] = setup->GetCellID(row, col, layer+1,mod);
0241 ids[3] = setup->GetCellID(row, col, layer+2,mod);
0242 ids[4] = setup->GetCellID(row, col, layer+3,mod);
0243 ids[5] = setup->GetCellID(row, col, layer+4,mod);
0244 } else if (layer == setup->GetNMaxLayer()-2){
0245 ids[0] = setup->GetCellID(row, col, layer-4,mod);
0246 ids[1] = setup->GetCellID(row, col, layer-3,mod);
0247 ids[2] = setup->GetCellID(row, col, layer-2,mod);
0248 ids[3] = setup->GetCellID(row, col, layer-1,mod);
0249 ids[4] = setup->GetCellID(row, col, layer+1,mod);
0250 ids[5] = setup->GetCellID(row, col, layer+2,mod);
0251 } else if (layer == setup->GetNMaxLayer()-1){
0252 ids[0] = setup->GetCellID(row, col, layer-5,mod);
0253 ids[1] = setup->GetCellID(row, col, layer-4,mod);
0254 ids[2] = setup->GetCellID(row, col, layer-3,mod);
0255 ids[3] = setup->GetCellID(row, col, layer-2,mod);
0256 ids[4] = setup->GetCellID(row, col, layer-1,mod);
0257 ids[5] = setup->GetCellID(row, col, layer+1,mod);
0258 } else if (layer == setup->GetNMaxLayer()){
0259 ids[0] = setup->GetCellID(row, col, layer-6,mod);
0260 ids[1] = setup->GetCellID(row, col, layer-5,mod);
0261 ids[2] = setup->GetCellID(row, col, layer-4,mod);
0262 ids[3] = setup->GetCellID(row, col, layer-3,mod);
0263 ids[4] = setup->GetCellID(row, col, layer-2,mod);
0264 ids[5] = setup->GetCellID(row, col, layer-1,mod);
0265 } else {
0266 ids[0] = setup->GetCellID(row, col, layer-3,mod);
0267 ids[1] = setup->GetCellID(row, col, layer-2,mod);
0268 ids[2] = setup->GetCellID(row, col, layer-1,mod);
0269 ids[3] = setup->GetCellID(row, col, layer+1,mod);
0270 ids[4] = setup->GetCellID(row, col, layer+2,mod);
0271 ids[5] = setup->GetCellID(row, col, layer+3,mod);
0272 }
0273
0274 } else if (nTiles == 2){
0275 if (layer == 0){
0276 ids[0] = setup->GetCellID(row, col, layer+1,mod);
0277 ids[1] = setup->GetCellID(row, col, layer+2,mod);
0278 } else if (layer == setup->GetNMaxLayer()){
0279 ids[0] = setup->GetCellID(row, col, layer-2,mod);
0280 ids[1] = setup->GetCellID(row, col, layer-1,mod);
0281 } else {
0282 ids[0] = setup->GetCellID(row, col, layer-1,mod);
0283 ids[1] = setup->GetCellID(row, col, layer+1,mod);
0284 }
0285 }
0286
0287 double avsurr = 0;
0288 Int_t activeTiles = nTiles;
0289 Int_t tilesWTOA = 0;
0290 for (Int_t t = 0; t < nTiles; t++){
0291 if ((Tile*)GetTileFromID(ids[t]) == nullptr){
0292 activeTiles--;
0293 continue;
0294 }
0295 if (calib.GetBCCalib()){
0296 if (calib.GetBadChannel(ids[t]) != -64 && calib.GetBadChannel(ids[t]) < 3){
0297 activeTiles--;
0298 continue;
0299 }
0300 }
0301 double tmpGain = 0;
0302 double scale = (calib.GetLGHGCorr(ids[t]) == -64.) ? avLGHG : calib.GetLGHGCorr(ids[t]);
0303
0304 if (GetROtype() == ReadOut::Type::Caen){
0305
0306 if (((Caen*)GetTileFromID(ids[t]))->GetADCHigh() < 3800)
0307 tmpGain = ((Caen*)GetTileFromID(ids[t]))->GetADCHigh()-calib.GetPedestalMeanH(ids[t]);
0308 else
0309 tmpGain = (((Caen*)GetTileFromID(ids[t]))->GetADCLow()-calib.GetPedestalMeanL(ids[t]))*scale + rand->Rndm()*scale;
0310
0311 if (tmpGain > 3*calib.GetPedestalSigH(ids[t]))
0312 avsurr +=tmpGain;
0313 } else {
0314
0315
0316 if (((Hgcroc*)GetTileFromID(ids[t]))->GetTOT() >= 1)
0317 tmpGain = 1000;
0318 else
0319 tmpGain = ((Hgcroc*)GetTileFromID(ids[t]))->GetIntegratedADC();
0320
0321 if (((Hgcroc*)GetTileFromID(ids[t]))->GetTOA() > 0){
0322 avsurr +=tmpGain;
0323 tilesWTOA++;
0324 }
0325 }
0326 }
0327 if (activeTiles > 1)
0328 avsurr = avsurr/activeTiles;
0329
0330 if (GetROtype() == ReadOut::Type::Hgcroc){
0331 if (tilesWTOA < 0.6*activeTiles){
0332 avsurr = (-1.)*avsurr;
0333 }
0334 }
0335 return avsurr;
0336 }
0337