File indexing completed on 2025-08-05 08:15:11
0001 #include "groot.h"
0002
0003
0004 #include "ATrace.h"
0005 #include "ABlob.h"
0006 #include "ATrack.h"
0007 #include "AZigzag.h"
0008
0009 #include "Event.h"
0010 #include "Quiver.h"
0011 #include "TFile.h"
0012 #include "TH1.h"
0013
0014 #include <iostream>
0015 #include <fstream>
0016 #include <string>
0017 #include <cstdlib> // Used to read $MYCALIB environment variable...
0018
0019 #include <boost/algorithm/string.hpp>
0020
0021 using namespace std;
0022 using namespace boost;
0023 groot* groot::__instance=0;
0024
0025 groot::groot()
0026 {
0027 cout << "I am GROOT!";
0028 cout << endl;
0029
0030
0031 for(int i=0; i<4; i++)
0032 {
0033 theTraces.push_back(new ATrace());
0034 }
0035
0036
0037 for (int i=0; i<Nsrs; i++)
0038 {
0039 ZigzagMap[i]=0;
0040 ZWaveMap[i]=0;
0041 }
0042
0043
0044 for (int i=0; i<Nr; i++)
0045 {
0046 for (int j=0; j<Nphi; j++)
0047 {
0048 ZigzagMap2[i][j]=0;
0049 }
0050 }
0051
0052
0053 for (int i = 0; i < CHhybrid; i++)
0054 {
0055 int channel = 32 * ( i % 4 ) + 8 * ( i >> 2) - 31 * ( i >> 4);
0056 demapper[channel]=i;
0057 remapper[i]=channel;
0058 }
0059
0060 CreateZigzags();
0061 FindNeighbors();
0062 ClearTheDetector();
0063
0064 AZigzag::ReadCalibration();
0065 }
0066
0067
0068 groot::~groot()
0069 {
0070 for( unsigned int i=0; i<theTraces.size(); i++ ) { delete theTraces[i]; }
0071
0072 for( unsigned int i=0; i< theTracks.size(); i++ ) { delete theTracks[i]; }
0073
0074 for( unsigned int i=0; i< theZigzags.size(); i++ ) { delete theZigzags[i]; }
0075
0076 for( unsigned int i=0; i<Nr; i++ )
0077 {
0078 for ( unsigned int j=0; i< theBlobs[i].size(); j++ ) { delete (theBlobs[i])[j]; }
0079
0080 theBlobs[i].clear();
0081 }
0082 }
0083
0084
0085 void groot::Report()
0086 {
0087 cout << "I am groot!" << endl;
0088
0089 cout << "TRACES -------------------------------------------------------" << endl;
0090 for (unsigned int i=0; i< theTraces.size(); i++)
0091 {
0092 cout << " Trace " << i;
0093 cout << " Maximum: " << theTraces[i]->FindMaximum(1) << " " <<endl;
0094 }
0095
0096 cout << "ZIGZAGS -------------------------------------------------------" << endl;
0097 int totalHit=0;
0098 for (unsigned int i=0; i< theZigzags.size(); i++)
0099 {
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 }
0114
0115 cout << " BLOBS --------------------------------------------------------------" << endl;
0116 for(int i=0; i<Nr; i++)
0117 {
0118 cout << "*** ROW: " << i+1 << endl;
0119 for (int j=0; j<theBlobs[i].size(); j++)
0120 {
0121 theBlobs[i][j]->Report();
0122 }
0123 }
0124 }
0125
0126
0127 void groot::ClearTheDetector()
0128 {
0129
0130 for (int i=0; i<4; i++)
0131 {
0132 theTraces[i]->voltage.clear();
0133 }
0134
0135
0136 for (int i=0; i<Nsrs; i++)
0137 {
0138 AZigzag::Raw[i].clear();
0139 AZigzag::Cal[i].clear();
0140 }
0141
0142
0143 for(unsigned int i=0; i<Nr; i++)
0144 {
0145 for ( unsigned int j=0; j< theBlobs[i].size(); j++ )
0146 {
0147 delete (theBlobs[i])[j];
0148 }
0149 theBlobs[i].clear();
0150 }
0151
0152
0153 for ( unsigned int i=0; i< theTracks.size(); i++ )
0154 {
0155 delete theTracks[i];
0156 }
0157 theTracks.clear();
0158 }
0159
0160
0161 void groot::FindNeighbors()
0162 {
0163 cout << "waveform neighbors" << endl;
0164
0165 for (int j=0; j<Nhybrid; j++)
0166 {
0167 for (int k=0; k<CHhybrid; k++)
0168 {
0169 int i = CHhybrid*j + k;
0170 if (ZWaveMap[i] !=0)
0171 {
0172 if (k>0) ZWaveMap[i]->PreWaveform = ZWaveMap[i-1];
0173 if (k<CHhybrid-1) ZWaveMap[i]->PostWaveform = ZWaveMap[i+1];
0174 }
0175 }
0176 }
0177
0178 cout << "logical neighbors" << endl;
0179
0180 for (int j=0; j<Nr; j++)
0181 {
0182 for (int k=0; k<Nphi; k++)
0183 {
0184 if (ZigzagMap2[j][k] !=0)
0185 {
0186 if (k>0) ZigzagMap2[j][k]->PreLogical = ZigzagMap2[j][k-1];
0187 if (k<Nphi-1) ZigzagMap2[j][k]->PostLogical = ZigzagMap2[j][k+1];
0188 }
0189 }
0190 }
0191 }
0192
0193
0194 void groot::FillZigzagMaps()
0195 {
0196 cout << "Filling the Zigzag Maps..." << endl;
0197
0198 string dir( getenv("MYCALIB") );
0199 string file("PadMap.txt");
0200 string result = dir + file;
0201 cout << "Looking for PadMap.txt in " << result << endl;
0202 ifstream fin(result.c_str());
0203
0204 if (!fin.is_open())
0205 {
0206 cout << "Groot could not open the file PadMap.txt." << endl;
0207 cout << "Please initialize the variable $MYCALIB in your .login." << endl;
0208 cout << "Then move the PadMap.txt file from the groot source to there." << endl;
0209 cout << "Only after that will you be allowed to continue analysis." << endl;
0210 return;
0211 }
0212 cout << "FOUND!" << endl;
0213
0214 string line;
0215 while (!fin.eof())
0216 {
0217 fin >> line;
0218
0219 vector<string> items;
0220 boost::split(items, line, [](char c){return c == ',';});
0221
0222 Padplane_NameToConnector[items[0]] = items[1];
0223 Padplane_NameToSamPin[items[0]] = items[2];
0224 }
0225 fin.close();
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235 dir = getenv("MYCALIB");
0236 file = "PanSamMap.txt";
0237 result = dir + file;
0238 cout << "Looking for PadMap.txt in " << result << endl;
0239 fin.open(result.c_str());
0240
0241 if (!fin.is_open())
0242 {
0243 cout << "You could not open the file PanSamMap.txt." << endl;
0244 cout << "Please initialize the variable $MYCALIB in your .login." << endl;
0245 cout << "Then move the PanSamMap.txt file from the groot source to there." << endl;
0246 cout << "Only after that will you be allowed to continue analysis." << endl;
0247 return;
0248 }
0249 cout << "FOUND!" << endl;
0250
0251 while (!fin.eof())
0252 {
0253 fin >> line;
0254
0255 vector<string> items;
0256 boost::split(items, line, [](char c){return c == ',';});
0257
0258 PanSam_SamPinToPanPin[items[0]] = atoi(items[1].c_str());
0259 }
0260 fin.close();
0261
0262
0263
0264
0265
0266
0267
0268
0269 }
0270
0271
0272 int groot::PanPinToChannel(int PanPin)
0273 {
0274 if (PanPin%2 == 0)
0275 {
0276 return 132-PanPin-2;
0277 }
0278 else
0279 {
0280 return 130-PanPin-2;
0281 }
0282 }
0283
0284
0285 int groot::ConnectorToHybrid(string Conn)
0286 {
0287
0288 string ConnNumber = Conn.substr(2);
0289 int Number = atoi(ConnNumber.c_str());
0290
0291 int hybrid;
0292 if (Number%2 == 0)
0293 {
0294 hybrid = Number-2;
0295 }
0296 else
0297 {
0298 hybrid = Number;
0299 }
0300
0301
0302
0303
0304
0305
0306
0307 return hybrid;
0308 }
0309
0310
0311 void groot::CreateZigzags()
0312 {
0313 FillZigzagMaps();
0314
0315 string dir( getenv("MYCALIB") );
0316 string file("OUTPUT_trim.XML");
0317 string result = dir + file;
0318 cout << "Looking for OUTPUT_trim.XML in " << result << endl;
0319 ifstream fin(result.c_str());
0320
0321 if (!fin.is_open())
0322 {
0323 cout << "You could not open the file OUTPUT_trim.XML." << endl;
0324 cout << "Please initialize the variable $MYCALIB in your .login." << endl;
0325 cout << "Then move the OUTPUT_trim.XML file from the groot source to there." << endl;
0326 cout << "Only after that will you be allowed to continue analysis." << endl;
0327 return;
0328 }
0329 cout << "FOUND!" << endl;
0330
0331 double tmp;
0332 CheveronPad_t thispad;
0333
0334 for(;;)
0335 {
0336 fin >> tmp;
0337 if(!fin.good()) break;
0338 if(tmp==99999)
0339 {
0340 fin >> thispad.fName;
0341 fin >> thispad.fPolyWidth;
0342 fin >> thispad.fPolyLayer;
0343 for(;;)
0344 {
0345 fin >> tmp;
0346 if(tmp==999999) break;
0347 thispad.fX.push_back(tmp);
0348 double x = tmp;
0349 fin >> tmp;
0350 thispad.fY.push_back(tmp);
0351 double y = tmp;
0352 double R = TMath::Sqrt(x*x+y*y);
0353 double Phi = TMath::Pi()+TMath::ATan2(-y,-x);
0354 thispad.r.push_back( R );
0355 thispad.phi.push_back( Phi );
0356 }
0357
0358
0359 fin >> tmp; thispad.fVia.push_back( tmp );
0360 fin >> tmp; thispad.fVia.push_back( tmp );
0361 fin >> tmp; thispad.fVia.push_back( tmp );
0362 fin >> tmp; thispad.fVia.push_back( tmp );
0363 fin >> tmp; thispad.fVia.push_back( tmp );
0364 fin >> tmp; thispad.fVia.push_back( tmp );
0365 fin >> tmp; thispad.fVia.push_back( tmp );
0366 fin >> tmp; thispad.fVia.push_back( tmp );
0367
0368 fin >> tmp; thispad.fWire.push_back( tmp );
0369 fin >> tmp; thispad.fWire.push_back( tmp );
0370 fin >> tmp; thispad.fWire.push_back( tmp );
0371 fin >> tmp; thispad.fWire.push_back( tmp );
0372 fin >> tmp; thispad.fWire.push_back( tmp );
0373 fin >> tmp; thispad.fWire.push_back( tmp );
0374
0375 int hybrid = ConnectorToHybrid(Padplane_NameToConnector[thispad.fName]);
0376 int channel = PanPinToChannel(PanSam_SamPinToPanPin[Padplane_NameToSamPin[thispad.fName]]);
0377 int index = CHhybrid*hybrid + channel;
0378
0379
0380 if (hybrid >= Nhybrid) continue;
0381
0382
0383
0384 AZigzag* thisZigzag = new AZigzag(thispad);
0385 thisZigzag->SetMyID(index);
0386 thisZigzag->MyHybrid = hybrid;
0387 thisZigzag->MyChannel= channel;
0388 thisZigzag->MyWaveIndex = demapper[channel];
0389 theZigzags.push_back( thisZigzag );
0390
0391
0392 vector<string> items;
0393 split(items, thispad.fName, [](char c){return c == '.';});
0394 int ir = atoi(items[1].c_str());
0395 int iphi = atoi(items[2].c_str());
0396 thisZigzag->iR = ir;
0397 thisZigzag->iPhi = iphi;
0398 ZigzagMap [index] = thisZigzag;
0399 ZigzagMap2[ir][iphi] = thisZigzag;
0400 ZWaveMap[hybrid*128+demapper[channel]] = thisZigzag;
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415 }
0416 thispad.fX.clear();
0417 thispad.fY.clear();
0418 thispad.fVia.clear();
0419 thispad.fWire.clear();
0420 thispad.r.clear();
0421 thispad.phi.clear();
0422 }
0423 fin.close();
0424 }
0425
0426 void groot::SaveTheHistograms(string filename)
0427 {
0428 TFile *theFile = new TFile(filename.c_str(),"RECREATE");
0429
0430 for (int i=0; i<theHistograms.size(); i++)
0431 {
0432 theHistograms[i]->Write();
0433 }
0434
0435 theFile->Close();
0436 }
0437
0438 void groot::FillAccessBlobs()
0439 {
0440
0441 for (int i=0; i<Nr; i++)
0442 {
0443 for (int j=0; j<10; j++)
0444 {
0445 AccessBlobs[i][j] = 0;
0446 }
0447 }
0448
0449
0450 for (int i=0; i<Nr; i++)
0451 {
0452 BlobCount[i] = theBlobs[i].size();
0453 int MAX = (( theBlobs[i].size() < 10) ? theBlobs[i].size() : 10);
0454 for (int j=0; j<MAX; j++)
0455 {
0456 AccessBlobs[i][j] = theBlobs[i][j];
0457 }
0458 }
0459
0460 }