File indexing completed on 2025-01-18 09:15:44
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 int 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(int 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 void Event::SetVov(double v){
0132 Vov=v;
0133 }
0134
0135 void Event::SetVop(double v){
0136 Vop=v;
0137 }
0138 void Event::SetBeamPosX(double x){
0139 BeamPosX=x;
0140 }
0141 void Event::SetBeamPosY(double y){
0142 BeamPosY=y;
0143 }
0144 void Event::SetBeginRunTime(TTimeStamp t){
0145 BeginRun=t;
0146 }
0147
0148 bool Event::InspectIfLocalMuonTrigg( int currTileID,
0149 double averageScale,
0150 double minThrSc = 0.9,
0151 double maxThrSc = 3
0152 ){
0153
0154 double trPrim = ((Caen*)GetTileFromID(currTileID))->GetLocalTriggerPrimitive();
0155
0156 if (trPrim > averageScale*minThrSc && trPrim < maxThrSc*averageScale)
0157 return true;
0158 else
0159 return false;
0160
0161 }
0162
0163 bool Event::InspectIfNoiseTrigg( int currTileID,
0164 double averageScale,
0165 double minThrSc = 0.9
0166 ){
0167 double trPrim = ((Caen*)GetTileFromID(currTileID))->GetLocalTriggerPrimitive();
0168
0169 if (trPrim < averageScale*minThrSc )
0170 return true;
0171 else
0172 return false;
0173
0174 }
0175
0176 double Event::CalculateLocalMuonTrigg( Calib calib,
0177 TRandom3* rand,
0178 int currTileID,
0179 int nTiles = 4,
0180 double avLGHG = 10.
0181 ){
0182
0183
0184 Setup* setup = Setup::GetInstance();
0185 long ids[6] = {-1, -1, -1, -1, -1, -1};
0186 int layer = setup->GetLayer(currTileID);
0187 int row = setup->GetRow(currTileID);
0188 int col = setup->GetColumn(currTileID);
0189 int mod = setup->GetModule(currTileID);
0190 if (nTiles == 4){
0191 if (layer == 0){
0192 ids[0] = setup->GetCellID(row, col, layer+1,mod);
0193 ids[1] = setup->GetCellID(row, col, layer+2,mod);
0194 ids[2] = setup->GetCellID(row, col, layer+3,mod);
0195 ids[3] = setup->GetCellID(row, col, layer+4,mod);
0196 }else if (layer == 1){
0197 ids[0] = setup->GetCellID(row, col, layer-1,mod);
0198 ids[1] = setup->GetCellID(row, col, layer+1,mod);
0199 ids[2] = setup->GetCellID(row, col, layer+2,mod);
0200 ids[3] = setup->GetCellID(row, col, layer+3,mod);
0201 } else if (layer == setup->GetNMaxLayer()-1){
0202 ids[0] = setup->GetCellID(row, col, layer-3,mod);
0203 ids[1] = setup->GetCellID(row, col, layer-2,mod);
0204 ids[2] = setup->GetCellID(row, col, layer-1,mod);
0205 ids[3] = setup->GetCellID(row, col, layer+1,mod);
0206 } else if (layer == setup->GetNMaxLayer()){
0207 ids[0] = setup->GetCellID(row, col, layer-4,mod);
0208 ids[1] = setup->GetCellID(row, col, layer-3,mod);
0209 ids[2] = setup->GetCellID(row, col, layer-2,mod);
0210 ids[3] = setup->GetCellID(row, col, layer-1,mod);
0211 } else {
0212 ids[0] = setup->GetCellID(row, col, layer-2,mod);
0213 ids[1] = setup->GetCellID(row, col, layer-1,mod);
0214 ids[2] = setup->GetCellID(row, col, layer+1,mod);
0215 ids[3] = setup->GetCellID(row, col, layer+2,mod);
0216 }
0217 } else if (nTiles == 6){
0218 if (layer == 0){
0219 ids[0] = setup->GetCellID(row, col, layer+1,mod);
0220 ids[1] = setup->GetCellID(row, col, layer+2,mod);
0221 ids[2] = setup->GetCellID(row, col, layer+3,mod);
0222 ids[3] = setup->GetCellID(row, col, layer+4,mod);
0223 ids[4] = setup->GetCellID(row, col, layer+5,mod);
0224 ids[5] = setup->GetCellID(row, col, layer+6,mod);
0225 }else if (layer == 1){
0226 ids[0] = setup->GetCellID(row, col, layer-1,mod);
0227 ids[1] = setup->GetCellID(row, col, layer+1,mod);
0228 ids[2] = setup->GetCellID(row, col, layer+2,mod);
0229 ids[3] = setup->GetCellID(row, col, layer+3,mod);
0230 ids[4] = setup->GetCellID(row, col, layer+4,mod);
0231 ids[5] = setup->GetCellID(row, col, layer+5,mod);
0232 }else if (layer == 2){
0233 ids[0] = setup->GetCellID(row, col, layer-2,mod);
0234 ids[1] = setup->GetCellID(row, col, layer-1,mod);
0235 ids[2] = setup->GetCellID(row, col, layer+1,mod);
0236 ids[3] = setup->GetCellID(row, col, layer+2,mod);
0237 ids[4] = setup->GetCellID(row, col, layer+3,mod);
0238 ids[5] = setup->GetCellID(row, col, layer+4,mod);
0239 } else if (layer == setup->GetNMaxLayer()-2){
0240 ids[0] = setup->GetCellID(row, col, layer-4,mod);
0241 ids[1] = setup->GetCellID(row, col, layer-3,mod);
0242 ids[2] = setup->GetCellID(row, col, layer-2,mod);
0243 ids[3] = setup->GetCellID(row, col, layer-1,mod);
0244 ids[4] = setup->GetCellID(row, col, layer+1,mod);
0245 ids[5] = setup->GetCellID(row, col, layer+2,mod);
0246 } else if (layer == setup->GetNMaxLayer()-1){
0247 ids[0] = setup->GetCellID(row, col, layer-5,mod);
0248 ids[1] = setup->GetCellID(row, col, layer-4,mod);
0249 ids[2] = setup->GetCellID(row, col, layer-3,mod);
0250 ids[3] = setup->GetCellID(row, col, layer-2,mod);
0251 ids[4] = setup->GetCellID(row, col, layer-1,mod);
0252 ids[5] = setup->GetCellID(row, col, layer+1,mod);
0253 } else if (layer == setup->GetNMaxLayer()){
0254 ids[0] = setup->GetCellID(row, col, layer-6,mod);
0255 ids[1] = setup->GetCellID(row, col, layer-5,mod);
0256 ids[2] = setup->GetCellID(row, col, layer-4,mod);
0257 ids[3] = setup->GetCellID(row, col, layer-3,mod);
0258 ids[4] = setup->GetCellID(row, col, layer-2,mod);
0259 ids[5] = setup->GetCellID(row, col, layer-1,mod);
0260 } else {
0261 ids[0] = setup->GetCellID(row, col, layer-3,mod);
0262 ids[1] = setup->GetCellID(row, col, layer-2,mod);
0263 ids[2] = setup->GetCellID(row, col, layer-1,mod);
0264 ids[3] = setup->GetCellID(row, col, layer+1,mod);
0265 ids[4] = setup->GetCellID(row, col, layer+2,mod);
0266 ids[5] = setup->GetCellID(row, col, layer+3,mod);
0267 }
0268
0269 } else if (nTiles == 2){
0270 if (layer == 0){
0271 ids[0] = setup->GetCellID(row, col, layer+1,mod);
0272 ids[1] = setup->GetCellID(row, col, layer+2,mod);
0273 } else if (layer == setup->GetNMaxLayer()){
0274 ids[0] = setup->GetCellID(row, col, layer-2,mod);
0275 ids[1] = setup->GetCellID(row, col, layer-1,mod);
0276 } else {
0277 ids[0] = setup->GetCellID(row, col, layer-1,mod);
0278 ids[1] = setup->GetCellID(row, col, layer+1,mod);
0279 }
0280 }
0281
0282 double avsurr = 0;
0283 Int_t activeTiles = nTiles;
0284 for (Int_t t = 0; t < nTiles; t++){
0285 if ((Caen*)GetTileFromID(ids[t]) == nullptr){
0286 activeTiles--;
0287 continue;
0288 }
0289 if (calib.GetBCCalib()){
0290 if (calib.GetBadChannel(ids[t]) != -64 && calib.GetBadChannel(ids[t]) < 3){
0291 activeTiles--;
0292 continue;
0293 }
0294 }
0295 double tmpGain = 0;
0296 double scale = (calib.GetScaleLGHGCorr(ids[t]) == -64.) ? avLGHG : calib.GetScaleLGHGCorr(ids[t]);
0297
0298 if (((Caen*)GetTileFromID(ids[t]))->GetADCHigh() < 3800)
0299 tmpGain = ((Caen*)GetTileFromID(ids[t]))->GetADCHigh()-calib.GetPedestalMeanH(ids[t]);
0300 else
0301 tmpGain = (((Caen*)GetTileFromID(ids[t]))->GetADCLow()-calib.GetPedestalMeanL(ids[t]))*scale + rand->Rndm()*scale;
0302
0303 if (tmpGain > 3*calib.GetPedestalSigH(ids[t]))
0304 avsurr +=tmpGain;
0305 }
0306 if (activeTiles > 1)
0307 avsurr = avsurr/activeTiles;
0308 return avsurr;
0309 }
0310