File indexing completed on 2025-08-05 08:14:39
0001 #ifndef __HCALUTIL_H__
0002 #define __HCALUTIL_H__
0003
0004 #include <list>
0005 #include <algorithm>
0006
0007 #include <TROOT.h>
0008 #include <TFile.h>
0009 #include <TTree.h>
0010 #include <TGMsgBox.h>
0011 #include <TCanvas.h>
0012 #include <TGraph.h>
0013 #include <TString.h>
0014 #include <TText.h>
0015 #include <TApplication.h>
0016 #include <TStyle.h>
0017 #include <TSystem.h>
0018 #include <TGClient.h>
0019 #include <TGWindow.h>
0020 #include <TH1.h>
0021 #include <TH1F.h>
0022 #include <TH1D.h>
0023 #include <TProfile.h>
0024 #include <TF1.h>
0025 #include <TH2.h>
0026 #include <TH3.h>
0027 #include <TMath.h>
0028 #include <TSpectrum.h>
0029 #include "TVirtualFitter.h"
0030 #include <TSystemDirectory.h>
0031 #include <TSystemFile.h>
0032
0033 class hcalUtil;
0034 class hLabHelper;
0035 class hcalHelper;
0036 class hcalTree;
0037 class tileHelper;
0038 class tileTree;
0039 class hcal;
0040 class stack;
0041 class tower;
0042
0043
0044 #include <hcalControls.h>
0045
0046
0047
0048 extern "C" Double_t erfunc(Double_t *x, Double_t * par);
0049 extern "C" Double_t erf_g(Double_t *x, Double_t * par);
0050 extern "C" Double_t powerFun(Double_t *x, Double_t * par);
0051 extern "C" Double_t power_g(Double_t *x, Double_t * par);
0052 extern "C" Double_t ps( Double_t *adc, Double_t *par);
0053 extern "C" Double_t sipmPeaks(Double_t *x, Double_t *par);
0054 extern "C" Int_t sipmCalib(TString & hName, int mode=0);
0055 extern "C" Double_t AsymToX(Double_t asym);
0056
0057 extern "C" Double_t signalShape(Double_t *x, Double_t * par);
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 struct rootfile{
0070 rootfile(TString n, Int_t rn, TString rid) : name(n) ,runnumber(rn), runid(rid) {;}
0071 rootfile(const rootfile & last){
0072 this->name = last.name;
0073 this->runnumber = last.runnumber;
0074 this->runid = last.runid;
0075 }
0076 void print(){
0077 cout<<"<rootfile> "<<name<<" Run # "<<runnumber<<" RunId "<<runid<<endl;
0078 }
0079 TString name;
0080 Int_t runnumber;
0081 TString runid;
0082
0083 };
0084
0085
0086
0087 struct prdffile{
0088 prdffile(TString n, Int_t rn, TString rid) : name(n) ,runnumber(rn), runid(rid) {;}
0089 prdffile(const prdffile & last){
0090 this->name = last.name;
0091 this->runnumber = last.runnumber;
0092 this->runid = last.runid;
0093 }
0094 void print(){
0095 cout<<"<prdffile> "<<name<<" Run # "<<runnumber<<" RunId "<<runid<<endl;
0096 }
0097 TString name;
0098 Int_t runnumber;
0099 TString runid;
0100 };
0101
0102
0103
0104
0105 class hLabHelper{
0106
0107 protected:
0108 hLabHelper();
0109 virtual ~hLabHelper(){;}
0110 static hLabHelper * single;
0111
0112
0113 public:
0114 static hLabHelper * getInstance(){if(!single) single = new hLabHelper(); return single;}
0115 static void deleteInstance(){if(single) delete single;}
0116
0117 bool evDisplay(Int_t run);
0118
0119 void getFileLists();
0120 void decoderun(TString & fname, Int_t & rn, TString & rid);
0121 TFile * attachrootrun(Int_t rn);
0122 void setRunKind(TString rK = "beam");
0123 Bool_t setPRDFRun(int run, Bool_t bookH = kTRUE);
0124 Bool_t setROOTRun(int run = 0);
0125 Int_t runToRootFile(Int_t run = 0);
0126 Int_t runToPRDFFile(Int_t run = 0);
0127 void renameAndCloseRF();
0128 void makeCanvasDirectory();
0129 void updateMap();
0130 void updateCalibration();
0131 void initPRDFRun(Bool_t bookH = kTRUE);
0132 void fitShape(int chan, Double_t & peakVal, Int_t & peakPos, Int_t mode);
0133 void getDetectorTiming();
0134 void displaySumEvent();
0135 void dofixes();
0136 void collect(Bool_t fitshape = kFALSE);
0137 Bool_t reject();
0138
0139 Int_t runnumber;
0140 TString runKind;
0141 Int_t rfiles;
0142 TString host;
0143 TString rootTempFileName;
0144 TString rootfName;
0145 TString prdfName;
0146 TString rootdirname;
0147 TString cDirectory;
0148 list<rootfile> roots;
0149 Int_t pfiles;
0150 TString prdfdirname;
0151 list<prdffile> prdfs;
0152 Int_t eventseq;
0153 Int_t eventsread;
0154
0155 Int_t * active;
0156 Float_t ** adc;
0157 Float_t * pedestal;
0158 Float_t * rawPeak, * rawTime;
0159
0160 Double_t ** fitResults;
0161 Float_t * fitPeak, * fitTime, * fitInt, * fitChi2;
0162 Float_t * fitPeakRMS, * fitTimeRMS;
0163
0164 Float_t * calibPeak;
0165
0166 Double_t ** shapeD;
0167
0168 TF1 ** shapes;
0169 TF1 ** sigFit;
0170 TF1 ** rvsc, **fmsc;
0171 TGraph ** gpulse;
0172 TH1 ** ft, ** fm, ** fw, ** fint, ** fpd, **fchi2;
0173 TH1 *** fitPar;
0174 TH1 ** rpeak, ** rtm;
0175 TH2 * rdata;
0176
0177
0178 Double_t * evtadcsum[2];
0179 Double_t * evtfitpar[2];
0180 Double_t evtpedestal[2];
0181 Double_t evttime[2];
0182 Double_t evtpeak[2];
0183 Double_t tChi2[2];
0184 TF1 * evtShape[2], * evtSignal[2];
0185 TGraph * evtGraph[2];
0186
0187 TFile * fhcl;
0188 TTree * thcl;
0189
0190 };
0191
0192
0193
0194 class hcalHelper{
0195 protected:
0196 hcalHelper();
0197 static hcalHelper * single;
0198 virtual ~hcalHelper(){ ; }
0199
0200 public:
0201 static hcalHelper * getInstance(){if(!single) single = new hcalHelper(); return single;}
0202 static void deleteInstance(){if(single) delete single;}
0203
0204
0205 hcal * t1044;
0206
0207 void setCTriggerOn(Bool_t ON = kTRUE);
0208 void setCTriggerGRange(Int_t gain = 1);
0209 void setDisplayMode(Int_t mode = 3);
0210 void setRunKind(TString rK = "beam");
0211 Int_t evLoop(int run, int evToProcess=0, int fToProcess=1);
0212 Int_t collectRaw();
0213 void updateCalibration();
0214 void hcalTrigger();
0215 void hcalPattern(Int_t nx, Int_t ny, Int_t run, Int_t mod = 0);
0216 void hcalImpact();
0217 void fitHCalSignal();
0218 void hcalDisplay();
0219 void dofixes();
0220 Int_t reject();
0221
0222 Double_t trThresholdBin;
0223 Double_t twrThreshold;
0224 Double_t stckSumThreshold;
0225
0226 Int_t runnumber;
0227 Int_t eventseq;
0228 Int_t eventsread;
0229 Int_t displayMode;
0230 Int_t triggerOn;
0231 Int_t triggerGain;
0232 Int_t rejectRaw;
0233 Int_t eventReject;
0234 Int_t eventTrigger;
0235 Int_t channels;
0236 Int_t samples;
0237 Int_t parameters;
0238
0239 Double_t uSum, cSum;
0240 Double_t YF, YU, YC, XU, XC;
0241 Double_t sumFU, sumFC;
0242 Double_t muxU, muxC, muxFU, muxFC;
0243 Int_t muxUCh, muxCCh, muxUFiber, muxCFiber;
0244
0245 Int_t ** adc;
0246 Int_t * activeCh;
0247
0248 TH2 * rdata;
0249 };
0250
0251
0252
0253
0254 class hcal{
0255 hcal();
0256 ~hcal();
0257 friend class hcalHelper;
0258 public:
0259
0260 Int_t rejectEvent;
0261 Bool_t readyForEvent;
0262 Int_t maxStacks;
0263 Int_t activeStacks;
0264 Int_t activeCalStacks;
0265 Bool_t * alive;
0266 Int_t * kinds;
0267
0268 stack ** stacks;
0269 void setCalibration();
0270 Int_t getStackTiming();
0271 Int_t update(Int_t displayMode = 3, Bool_t fitShapes=kFALSE);
0272 Int_t collectTrPrimitives();
0273 void displayRaw(Int_t mode = 0);
0274 void displaySummary(Int_t mode = 0);
0275 void clean();
0276
0277 Double_t amplTotal;
0278 Double_t eTotal;
0279 Double_t calLCG;
0280 Double_t scintLCG;
0281 TH1 * totalamp, * totale, * totallcg, * scintlcg;
0282 };
0283
0284
0285
0286 class stack{
0287 friend class hcal;
0288 friend class hcalHelper;
0289
0290 public:
0291
0292 stack();
0293
0294 stack(const Int_t kind, const Int_t chnls, const Int_t xch, const Int_t ych);
0295 ~stack();
0296 void displayEvent(Int_t mode = 0);
0297 void displayADCSum();
0298 void displayTowerSummary(Int_t mode = 3);
0299 void displayStackSummary(Int_t mode = 3);
0300 void print();
0301 void updateMap(Int_t stckloc);
0302 Int_t update(Bool_t fitShapes = kFALSE);
0303 Int_t getStackTime();
0304 Int_t getStackImpact();
0305 Int_t getStackTrack();
0306 Int_t getTrigger();
0307 void clean();
0308
0309 Int_t reject;
0310
0311
0312
0313 Double_t stackECalib;
0314 Int_t triggerFlag;
0315 Int_t triggerHits;
0316 Int_t triggerSum;
0317 Int_t eventsSeen;
0318
0319 Int_t stackId;
0320 Int_t stackKind;
0321 Int_t gains;
0322 Int_t twrsInStack;
0323 Int_t stackLoc;
0324 Int_t nTwrsX;
0325 Int_t nTwrsY;
0326 Int_t key;
0327 Bool_t mapUpdated;
0328 Double_t totPed;
0329 Double_t totAmpl;
0330 Double_t totCorAmpl;
0331 Double_t avTwrTime;
0332 Double_t rmsTwrTime;
0333 Double_t E;
0334 Double_t xImpact;
0335 Double_t yImpact;
0336 tower ** towers;
0337
0338
0339 Int_t gainToUse;
0340 Int_t twrsUsed[2];
0341 Double_t * adcsum[2];
0342 Double_t * fitPar[2];
0343 Double_t fitPed[2];
0344
0345 Double_t fitTime[2];
0346 Double_t fitPeak[2];
0347 Double_t fitChi2[2];
0348 TF1 * shape[2], * signal[2];
0349 TGraph * graph[2];
0350
0351
0352 Int_t stackHits;
0353 Int_t trackHits;
0354 Double_t crossing, slope, trchi2, trackAmpl;
0355
0356 TH1 * stFGR;
0357 TH1 * stFPed, * stFAmpl, * stFTime, * stChi2;
0358 TH1 * stSPed, * stSAmpl, * stSE, * stAvT, * stTRMS;
0359
0360 TH2 * hitCG;
0361
0362 TH1 * trAmp, * trChi2, * trCr, * trSl;
0363 TH2 * trAmpCh2, * trAstH,* trASl, * trATwr;
0364
0365
0366 TH1 * satProb[2];
0367
0368 };
0369
0370
0371
0372
0373
0374
0375 class tower{
0376 friend class hcalHelper;
0377 public:
0378 tower(){;}
0379 ~tower(){;}
0380 tower(Int_t stack, Int_t stkLoc, Int_t xSt, Int_t ySt);
0381 void setChannel(Int_t channel, Int_t gain);
0382 Int_t update(Bool_t fitShape=kFALSE);
0383 void clean();
0384 void print();
0385 void display();
0386
0387 Int_t reject;
0388 Double_t twrECalib;
0389 Double_t twrEScale;
0390 Int_t stackId;
0391 Int_t index;
0392 Int_t key;
0393 Int_t x;
0394 Int_t y;
0395 Int_t gains;
0396 Int_t gainToUse;
0397 Int_t adcChannel[2];
0398 Int_t satFlag[2];
0399 Double_t rawPed[2];
0400 Double_t rawAmpl[2], rawTime[2];
0401 Bool_t attached;
0402
0403 Double_t rped, rampl, rtime;
0404 Double_t cped, campl, ctime;
0405 Double_t E;
0406 TF1 * shape[2], * signal[2];
0407 TGraph * graph[2];
0408
0409 TH1 * twrPed, * twrAmpl, * twrTime, * twrE;
0410
0411
0412
0413
0414 };
0415
0416
0417
0418 class hcalTree
0419 {
0420
0421 protected:
0422 hcalTree();
0423 virtual ~hcalTree(){;}
0424 static hcalTree * single;
0425
0426
0427 public:
0428 static hcalTree * getInstance(){if(!single) single = new hcalTree(); return single;}
0429 static void deleteInstance(){if(single) delete single;}
0430
0431
0432
0433
0434 void updateRootFile();
0435
0436 int runnumber;
0437 int eventseq;
0438 int eventsread;
0439 int channels;
0440 int samples;
0441
0442
0443
0444
0445
0446
0447
0448 int rejectCode;
0449
0450 };
0451
0452
0453
0454
0455 class tileHelper{
0456 protected:
0457 tileHelper();
0458 static tileHelper * single;
0459 virtual ~tileHelper(){
0460 delete [] tileCalib;
0461 delete [] tileCalPeak;
0462 }
0463
0464
0465 public:
0466 static tileHelper * getInstance(){if(!single) single = new tileHelper(); return single;}
0467 static void deleteInstance(){if(single) delete single;}
0468
0469
0470
0471
0472 struct eventtilesummary{
0473 eventtilesummary(){
0474 evtGraph = new TGraph(NSAMPLES);
0475 TString fitName = "det adc sum";
0476 evtShape = new TF1(fitName, &signalShape, 0., (Double_t)NSAMPLES, NPARAMETERS);
0477 fitName = "det signal";
0478 evtSignal = new TF1(fitName, &signalShape, 0., (Double_t)NSAMPLES, NPARAMETERS);
0479 }
0480 Double_t times[TILECHANNELS];
0481 Double_t chi2[TILECHANNELS];
0482 Double_t evtadcsum[NSAMPLES];
0483 Double_t evtfitpar[NPARAMETERS];
0484 Double_t evtpedestal;
0485 Double_t evttime;
0486 Double_t evtpeak;
0487 Double_t tChi2;
0488 Double_t evtpc;
0489 Int_t hitfiber;
0490 Double_t hitfiberpc;
0491 Double_t hitfibertd;
0492 Double_t yChi2;
0493 Double_t ySigma;
0494 TGraph * evtGraph;
0495 TF1 * evtShape;
0496 TF1 * evtSignal;
0497 Int_t rejectCode;
0498
0499 void reset(){
0500 for (int is = 0; is < NSAMPLES; is++) evtadcsum[is] = 0.;
0501 for (int tch = 0; tch < TILECHANNELS; tch++) times[tch] = 0.;
0502 evttime = 0.;
0503 rejectCode = 0;
0504 }
0505 };
0506
0507
0508
0509
0510 struct runtilesummary{
0511 runtilesummary();
0512
0513
0514
0515 TH2 * rmax;
0516 TH2 * rfsum;
0517 TH2 * rtsum;
0518 TH2 * rfasym;
0519 TH1 * rtasym;
0520 TH1 * rx;
0521 TH1 * ry;
0522 TH2 * rimp;
0523 TH2 * cdata;
0524 TH2 * cmax;
0525 TH2 * cfsum;
0526 TH2 * ctsum;
0527 TH2 * cfasym;
0528 TH1 * ctasym;
0529 TH1 * cx;
0530 TH1 * cy;
0531 TH1 * fy;
0532 TH2 * cimp;
0533 TH2 * cx_pc;
0534 TH2 * cy_pc;
0535 TH2 * fy_pc;
0536 TH2 * cimpW;
0537
0538
0539 TH1 * trhits;
0540 TH2 * hits_tpc;
0541
0542
0543
0544 TH3 * treff;
0545 TH3 * pc_imp;
0546 TH2 * pc_pat;
0547 TH3 * pc_fimp;
0548 TH2 * pc_fpat;
0549
0550
0551
0552 TH2 * XvsSl, * XY;
0553 TH1 * Y0, * Y1, * Y2;
0554 TH2 * y_yChi2, * s_y_Chi2;
0555 TH2 * y_ys, * yc_rcode;
0556 TH1 * yCleaned, * yKept;
0557 TH1 * trcode;
0558
0559
0560
0561 TH2 * td_r_l;
0562 TH3 * td_t_tw;
0563
0564
0565 };
0566
0567
0568
0569
0570 Int_t evLoop(Int_t run, Int_t evToProcess, Int_t fToProcess);
0571 void status();
0572 void updateMap();
0573 void updateCalibration();
0574 void evreset();
0575 void tileTrigger();
0576 void tileTiming();
0577 void tileDisplay();
0578 void tileTriggerDisplay();
0579 void tilePattern(Int_t nx, Int_t ny, Int_t run, Int_t mod = 0);
0580 void collectTileSummary();
0581 Double_t getYFit();
0582 void tileImpact();
0583 void fitTileSignal();
0584 Int_t reject();
0585 eventtilesummary evtsum;
0586 runtilesummary runsum;
0587
0588 Int_t channels;
0589 Int_t samples;
0590 Int_t fibers;
0591 Int_t xdivisions, ydivisions;
0592 Int_t parameters;
0593
0594 Double_t uSum, cSum, luSum, lcSum, ruSum, rcSum;
0595 Double_t YF, YU, YC, XU, XC;
0596 Double_t sumFU, sumFC;
0597 Double_t muxU, muxC, muxFU, muxFC;
0598 int muxUCh, muxCCh, muxUFiber, muxCFiber;
0599 Double_t ras, cas, rtas, ctas;
0600 Double_t * fiberY;
0601 Double_t * fiberLY;
0602 Double_t * tileCalib;
0603 Double_t * tileCalPeak;
0604 int hitcnt[CHANNELTHRESHOLDS];
0605
0606 TCanvas * fiberDisplay;
0607 TCanvas * triggerDisplay;
0608 TCanvas * impactDisplay;
0609 TCanvas * lyPattern, * lyFits;
0610 TF1 * yFit;
0611 TGraph * fLY;
0612
0613 };
0614
0615
0616
0617
0618 class tileLightYield{
0619 tileLightYield();
0620 void setrootfile(rootfile & rf){
0621
0622 rfile = new rootfile(rf);
0623 }
0624 void setdivisions(Int_t nx, Int_t ny){
0625 xdivisions = nx;
0626 ydivisions = ny;
0627 lightyield = new Double_t * [ny];
0628 for(int iy =0; iy<ny; iy++) lightyield[iy] = new Double_t [nx];
0629
0630 }
0631 rootfile * rfile;
0632 Int_t xdivisions, ydivisions;
0633 Double_t ** lightyield;
0634 };
0635
0636
0637 class tileTree
0638 {
0639
0640 protected:
0641 tileTree();
0642 virtual ~tileTree(){;}
0643 static tileTree * single;
0644
0645
0646 public:
0647 static tileTree * getInstance(){if(!single) single = new tileTree(); return single;}
0648 static void deleteInstance(){if(single) delete single;}
0649
0650
0651
0652
0653 void updateRootFile();
0654
0655
0656
0657
0658
0659
0660
0661
0662 int rejectCode;
0663 };
0664
0665
0666
0667 class hcalUtil{
0668 protected:
0669 hcalUtil ();
0670 virtual ~hcalUtil(){;}
0671 static hcalUtil * single;
0672
0673 public:
0674 static hcalUtil * getInstance(){if(!single) single=new hcalUtil(); return single;}
0675 static void deleteInstance(){if(single) delete single;}
0676
0677 Float_t xPeak(TF1* f, Float_t x1, Float_t x2);
0678
0679
0680 Float_t width(TF1* f, Float_t x1, Float_t x2, Float_t peak);
0681
0682 bool shapeFit(TH1D * proj, Double_t * pE, Float_t & maxE, Double_t * pG, bool fine, bool MIP);
0683
0684 bool emcFit(TH1D * proj, bool fine, bool sing, Double_t * pE, Float_t & maxE, Double_t * pG, bool MIP);
0685 bool emcFit(TH1D * proj, bool sing, Double_t * pE, Float_t & maxE, Double_t * pG);
0686 bool emcFit(TH1D * proj, bool sing, Double_t * pE, Float_t & maxE, Double_t * pG, Float_t minx, Float_t maxx);
0687 bool twrMipFit(TH1D * proj, Double_t * pE, Float_t & maxE, Double_t * pG);
0688 bool twrTimeFit(TH1D * proj, Double_t * pE, Float_t & maxE, Double_t * pG);
0689
0690 };
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702 #endif
0703