Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 08:25:54

0001 #ifndef TILETREND_H
0002 #define TILETREND_H
0003 
0004 #include "TObject.h"
0005 #include "TString.h"
0006 #include "TH1D.h"
0007 #include "TH2D.h"
0008 #include "TProfile.h"
0009 #include "TGraphErrors.h"
0010 #include "TF1.h"
0011 #include "TPad.h" 
0012 #include "TCanvas.h"
0013 #include "TLegend.h"
0014 #include "TFile.h"
0015 #include "Calib.h"
0016 #include "Setup.h"
0017 #include "Tile.h"
0018 #include "CommonHelperFunctions.h"
0019 
0020 /**
0021  * Container for per-cell trending data and plotting metadata.
0022  *
0023  * TileTrend stores a set of ROOT TGraphErrors objects for pedestal, gain,
0024  * correlation, trigger and other calibration trends associated with one
0025  * logical cell. It acts as a small data holder and plotting helper for the
0026  * analysis code that assembles run-by-run trend plots.
0027  */
0028 class TileTrend: public TObject{
0029 
0030  public:
0031  TileTrend():TObject(){}
0032  TileTrend(int id, int deb=0, int ext=0):TObject()
0033     {
0034     CellID         = id;
0035     debug          = deb;
0036     extended       = ext;
0037      
0038     // full filling for calib monitoring
0039     if (ext < 3){
0040       InitTrendGraph(gTrendLGped, Form("TrendLGpedCellID%d",CellID), "#mu_{PED, LG} (arb. units)", kRed);
0041       InitTrendGraph(gTrendHGped, Form("TrendHGpedCellID%d",CellID), "#mu_{PED, HG} (arb. units)", kRed);
0042       InitTrendGraph(gTrendLGpedwidth, Form("TrendLGpedwidthCellID%d",CellID), "#sigma_{PED, LG} (arb. units)", kRed);
0043       InitTrendGraph(gTrendHGpedwidth, Form("TrendHGpedwidthCellID%d",CellID), "#sigma_{PED, HG} (arb. units)", kRed);
0044       InitTrendGraph(gTrendLGscale, Form("TrendLGscaleCellID%d",CellID), "Max_{LG} (arb. units)", kRed);
0045       InitTrendGraph(gTrendHGscale, Form("TrendHGscaleCellID%d",CellID), "Max_{HG} (arb. units)", kRed);
0046       InitTrendGraph(gTrendHGLGcorr, Form("TrendHGLGcorrCellID%d",CellID), "a_{HG-LG} (arb. units)", kRed);
0047       InitTrendGraph(gTrendLGHGcorr, Form("TrendLGHGcorrCellID%d",CellID), "a_{LG-HG} (arb. units)", kRed);
0048       InitTrendGraph(gTrendHGLGOffset, Form("TrendHGLGOffsetCellID%d",CellID), "b_{HG,LG} (arb. units)", kRed);
0049       InitTrendGraph(gTrendLGHGOffset, Form("TrendLGHGOffsetCellID%d",CellID), "b_{LG,HG} (arb. units)", kRed);
0050       InitTrendGraph(gTrendTOT, Form("TrendTOTCellID%d",CellID), "TOT (arb. units)", kRed);
0051     }
0052     
0053     
0054     // also monitoring triggers
0055     if (ext == 1 || ext == 2){
0056       InitTrendGraph(gTrendTrigger, Form("TrendTriggerCellID%d",CellID), "#mu triggers", kRed);
0057       InitTrendGraph(gTrendSBNoise, Form("TrendSBNoiseCellID%d",CellID), "S/B noise region", kRed);
0058       InitTrendGraph(gTrendSBSignal, Form("TrendSBSignalCellID%d",CellID), "S/B signal region", kRed);
0059     }
0060     // monitor extended trending
0061     if (ext == 1){
0062       InitTrendGraph(gTrendHGLMPV, Form("TrendHGLMPVCellID%d",CellID), "MPV_{HG} (arb. units)", kRed);
0063       InitTrendGraph(gTrendHGLSigma, Form("TrendHGLSigmaCellID%d",CellID), "#sigma_{L,HG} (arb. units)", kRed);
0064       InitTrendGraph(gTrendHGGSigma, Form("TrendHGGSigmaCellID%d",CellID), "#sigma_{G,HG} (arb. units)", kRed);
0065       InitTrendGraph(gTrendLGLMPV, Form("TrendLGLMPVCellID%d",CellID), "MPV_{LG} (arb. units)", kRed);
0066       InitTrendGraph(gTrendLGLSigma, Form("TrendLGLSigmaCellID%d",CellID), "#sigma_{L,LG} (arb. units)", kRed);
0067       InitTrendGraph(gTrendLGGSigma, Form("TrendLGGSigmaCellID%d",CellID), "#sigma_{G,LG} (arb. units)", kRed);
0068     }
0069     // mode for injection plotting
0070     if (ext == 3){
0071       InitTrendGraph(gTrendHGped, Form("TrendHGpedCellID%d",CellID), "#mu_{PED, 0^{th} sample} (arb. units)", kRed);
0072       InitTrendGraph(gTrendHGpedwidth, Form("TrendHGpedwidthCellID%d",CellID), "#sigma_{PED, 0^{th} sample} (arb. units)", kRed);
0073     }
0074     // mode for injection dac plotting
0075     if (ext == 4){
0076       InitTrendGraph(gTrendHGped, Form("TrendHGpedCellID%d",CellID), "#mu_{PED, 0^{th} sample} (arb. units)", kRed);
0077       InitTrendGraph(gTrendHGpedwidth, Form("TrendHGpedwidthCellID%d",CellID), "#sigma_{PED, 0^{th} sample} (arb. units)", kRed);
0078       InitTrendGraph(gTrendADCMax, Form("TrendADCMaxCellID%d",CellID), "ADC_{max} (arb. units)", kRed);
0079       InitTrendGraph(gTrendADCSaturated, Form("TrendADCSaturatedCellID%d",CellID), "# samples ADC_{sat}", kRed);
0080       InitTrendGraph(gTrendTOA, Form("TrendTOACellID%d",CellID), "TOA (arb. units)", kRed);
0081       InitTrendGraph(gTrendNSampTOA, Form("TrendNSampleTOACellID%d",CellID), "# sample TOA fired", kRed);
0082       InitTrendGraph(gTrendNTOA, Form("TrendNTOACellID%d",CellID), "# TOA fired", kRed);
0083       InitTrendGraph(gTrendTOT, Form("TrendTOTCellID%d",CellID), "TOT (arb. units)", kRed);
0084       InitTrendGraph(gTrendTOTSaturated, Form("TrendTOTSaturatedCellID%d",CellID), "# samples TOT_{sat}", kRed);
0085     }
0086     
0087   }
0088   ~TileTrend(){}
0089 
0090   // Fill objects 
0091   bool Fill           (double, const TileCalib&, int, double, int, double, double, double, double);
0092   bool FillExtended   (double, int, int, TH1D*, TH1D*, TProfile*, TProfile* wave = nullptr);
0093   void FillMPV        (double, double, double, double, double);
0094   void FillLSigma     (double, double, double, double, double);
0095   void FillGSigma     (double, double, double, double, double);
0096   void FillSB         (double, double, double);
0097   void FillCorrOffset (double, double, double, double, double);  
0098   void FillHGCROCSetting (double val_rf = -1., double val_cf= -1., double val_cfcomp= -1., double val_cc= -1., double val_inj = -1.);  
0099   
0100   bool FillInjection  ( double x, double ped, int runNr, 
0101                         TProfile* wave, TProfile* toa, TProfile* tot, 
0102                         double val_rf = -1., double val_cf= -1., double val_cfcomp= -1., double val_cc= -1., double val_inj = -1.);
0103 
0104   bool FillInjectionDACVal  ( double x, double ped, double adc, double toa, double tot, int adcSatN = 0, int totSatN = 0, int nTOA = 0, int nSampToA = 0) ;
0105   bool FillHGCROCVals (double x, double tot);
0106   
0107   
0108   // Drawing functions for graphs
0109   bool DrawLGped      (TString);
0110   bool DrawHGped      (TString);
0111   bool DrawLGpedwidth (TString);
0112   bool DrawHGpedwidth (TString);
0113   bool DrawLGscale    (TString);
0114   bool DrawHGscale    (TString);
0115   bool DrawHGLGcorr   (TString);
0116   bool DrawLGHGcorr   (TString);
0117   bool DrawTrigger    (TString);
0118   bool DrawSBNoise    (TString);
0119   bool DrawSBSignal   (TString);
0120   bool DrawHGLMPV     (TString);
0121   bool DrawLGLMPV     (TString);
0122   bool DrawHGLSigma   (TString);
0123   bool DrawLGLSigma   (TString);
0124   bool DrawHGGSigma   (TString);
0125   bool DrawLGGSigma   (TString);
0126   bool DrawHGLGOffset (TString);
0127   bool DrawLGHGOffset (TString);
0128   bool DrawADCmax     (TString);
0129   bool DrawADCsat     (TString);
0130   bool DrawTOT        (TString);
0131   bool DrawTOTsat     (TString);
0132   bool DrawTOA        (TString);
0133   bool DrawNSampTOA   (TString);
0134   bool DrawNTOA       (TString);
0135   TString GetLabelLegend(RunInfo , int, int );
0136   
0137   // Set default drawing options for all graphs
0138   bool SetLineColor   (uint);
0139   bool SetMarkerColor (uint);
0140   bool SetMarkerStyle (uint);
0141   bool SetXAxisTitle  (TString);
0142   void SetLabelPerRun (TString);
0143   
0144   // Sort graph according to voltage or run number
0145   void Sort          ();
0146   // Write graphs to file
0147   bool Write          (TFile*);
0148   bool Write          ();
0149   void PrintMinMaxRanges ();
0150   
0151   inline double GetExtOpt()       {return extended;};
0152 
0153   // Get minima and maxima for different graphs
0154   inline double GetMinLGped() const     {return MinLGped;};
0155   inline double GetMaxLGped() const     {return MaxLGped;};
0156   inline double GetMinHGped() const     {return MinHGped;};
0157   inline double GetMaxHGped() const     {return MaxHGped;};
0158   inline double GetMinLGpedwidth() const {return MinLGpedwidth;};
0159   inline double GetMaxLGpedwidth() const {return MaxLGpedwidth;};
0160   inline double GetMinHGpedwidth() const {return MinHGpedwidth;};
0161   inline double GetMaxHGpedwidth() const {return MaxHGpedwidth;};
0162   inline double GetMinLGscale() const   {return MinLGscale;};
0163   inline double GetMaxLGscale() const   {return MaxLGscale;};
0164   inline double GetMinHGscale() const   {return MinHGscale;};
0165   inline double GetMaxHGscale() const   {return MaxHGscale;};
0166   inline double GetMinHGLGcorr() const  {return MinHGLGcorr;};
0167   inline double GetMaxHGLGcorr() const  {return MaxHGLGcorr;};
0168   inline double GetMinLGHGcorr() const  {return MinLGHGcorr;};
0169   inline double GetMaxLGHGcorr() const  {return MaxLGHGcorr;};
0170 
0171    
0172   // Get minima and maxima for different graphs extended graphs
0173   inline double GetMinTrigg() const     {return MinTrigg;};
0174   inline double GetMaxTrigg() const     {return MaxTrigg;};
0175   inline double GetMinHGSpec() const    {return MinHGSpec;};
0176   inline double GetMaxHGSpec() const    {return MaxHGSpec;};
0177   inline double GetMinLGSpec() const    {return MinLGSpec;};
0178   inline double GetMaxLGSpec() const    {return MaxLGSpec;};
0179   inline double GetMinLGMPV() const     {return MinLGMPV;};
0180   inline double GetMaxLGMPV() const     {return MaxLGMPV;};
0181   inline double GetMinHGMPV() const     {return MinHGMPV;};
0182   inline double GetMaxHGMPV() const     {return MaxHGMPV;};
0183   inline double GetMinHGLSigma() const  {return MinHGLSigma;};
0184   inline double GetMaxHGLSigma() const  {return MaxHGLSigma;};
0185   inline double GetMinLGLSigma() const  {return MinLGLSigma;};
0186   inline double GetMaxLGLSigma() const  {return MaxLGLSigma;};
0187   inline double GetMinHGGSigma() const  {return MinHGGSigma;};
0188   inline double GetMaxHGGSigma() const  {return MaxHGGSigma;};
0189   inline double GetMinLGGSigma() const  {return MinLGGSigma;};
0190   inline double GetMaxLGGSigma() const  {return MaxLGGSigma;};
0191   inline double GetMinSBSignal() const  {return MinSBSignal;};
0192   inline double GetMaxSBSignal() const  {return MaxSBSignal;};
0193   inline double GetMinSBNoise() const   {return MinSBNoise;};
0194   inline double GetMaxSBNoise() const   {return MaxSBNoise;};
0195   inline double GetMinLGHGOffset() const {return MinLGHGOff;};
0196   inline double GetMaxLGHGOffset() const {return MaxLGHGOff;};
0197   inline double GetMaxHGLGOffset() const {return MaxHGLGOff;};
0198   inline double GetMinHGLGOffset() const {return MinHGLGOff;};
0199    
0200    
0201   // Get minima and maxima for different graphs injection related
0202   inline double GetMaxADCmax() const    {return MaxADCmax;};
0203   inline double GetMaxADCsat() const    {return MaxADCsat;};
0204   inline double GetMaxTOT() const       {return MaxTOT;};
0205   inline double GetMaxTOTsat() const    {return MaxTOTsat;};
0206   inline double GetMaxTOA() const       {return MaxTOA;};
0207   inline double GetMaxNSampTOA() const  {return MaxNSampTOA;};
0208   inline double GetMaxNTOA() const      {return MaxNTOA;};
0209   inline double GetMinADCmax() const    {return MinADCmax;};
0210   inline double GetMinADCsat() const    {return MinADCsat;};
0211   inline double GetMinTOT() const       {return MinTOT;};
0212   inline double GetMinTOTsat() const    {return MinTOTsat;};
0213   inline double GetMinTOA() const       {return MinTOA;};
0214   inline double GetMinNSampTOA() const  {return MinNSampTOA;};
0215   inline double GetMinNTOA() const      {return MinNTOA;};
0216    
0217   inline double GetMaxInjADC() const {return MaxInjADC;};
0218   inline double GetMaxInjTOT() const {return MaxInjTOT;};
0219    
0220    
0221   inline int GetNRuns() const           {return (int)runNrs.size();};
0222   inline int GetFirstRun() const        {if (runNrs.size()> 0) return runNrs[0]; else return -1;};
0223   inline int GetLastRun() const         {if (runNrs.size()> 0) return runNrs[runNrs.size()-1]; else return -1;};
0224   inline int GetRunNr(int i) const      {if (runNrs.size()> 0 && i < (int)runNrs.size()) return runNrs[i]; else return -1;}
0225   inline TString GetLabel(int i) const      {if (labels.size()> 0 && i < (int)labels.size()) return labels[i]; else return "";} 
0226   inline int GetPdg(int i)        {if (pdgs.size()> 0 && i < (int)pdgs.size()) return pdgs[i]; else return -1;}
0227   inline int GetVoltage(int i)    {if (voltages.size()> 0 && i < (int)voltages.size()) return voltages[i]; else return -1;}
0228   inline int GetRF(int i)         {if (rf.size()> 0 && i < (int)rf.size()) return rf[i]; else return -1;}
0229   inline int GetCF(int i)         {if (cf.size()> 0 && i < (int)cf.size()) return cf[i]; else return -1;}
0230   inline int GetCFComp(int i)     {if (cfcomp.size()> 0 && i < (int)cfcomp.size()) return cfcomp[i]; else return -1;}
0231   inline int GetCC(int i)         {if (cc.size()> 0 && i < (int)cc.size()) return cc[i]; else return -1;}
0232   inline double GetInj(int i)     {if (inj.size()> 0 && i < (int)inj.size()) return inj[i]; else return -1;}
0233   inline double GetEnergy(int i)  {if (energy.size()> 0 && i < (int)energy.size()) return energy[i]; else return -1;}
0234   inline double GetTemp(int i)  {if (temp.size()> 0 && i < (int)temp.size()) return temp[i]; else return -1;}
0235   
0236   // Getters for graphs
0237   inline TGraphErrors* GetHGped()    {return &gTrendHGped;};
0238   inline TGraphErrors* GetLGped()    {return &gTrendLGped;};
0239   inline TGraphErrors* GetHGpedwidth() {return &gTrendHGpedwidth;};
0240   inline TGraphErrors* GetLGpedwidth() {return &gTrendLGpedwidth;};
0241   inline TGraphErrors* GetHGScale()   {return &gTrendHGscale;};
0242   inline TGraphErrors* GetLGScale()   {return &gTrendLGscale;};
0243   inline TGraphErrors* GetLGHGcorr()  {return &gTrendLGHGcorr;};
0244   inline TGraphErrors* GetHGLGcorr()  {return &gTrendHGLGcorr;};
0245   // Getters for extended graphs
0246   inline TGraphErrors* GetTrigger()   {return &gTrendTrigger;};
0247   inline TGraphErrors* GetSBNoise()   {return &gTrendSBNoise;};
0248   inline TGraphErrors* GetSBSignal()  {return &gTrendSBSignal;};
0249   inline TGraphErrors* GetHGLMPV()    {return &gTrendHGLMPV;};
0250   inline TGraphErrors* GetLGLMPV()    {return &gTrendLGLMPV;};
0251   inline TGraphErrors* GetHGLSigma()  {return &gTrendHGLSigma;};
0252   inline TGraphErrors* GetLGLSigma()  {return &gTrendLGLSigma;};
0253   inline TGraphErrors* GetHGGSigma()  {return &gTrendHGGSigma;};
0254   inline TGraphErrors* GetLGGSigma()  {return &gTrendLGGSigma;};
0255   inline TGraphErrors* GetLGHGOff()   {return &gTrendLGHGOffset;};
0256   inline TGraphErrors* GetHGLGOff()   {return &gTrendHGLGOffset;};
0257   inline TGraphErrors* GetADCmax()    {return &gTrendADCMax;};
0258   inline TGraphErrors* GetADCsat()    {return &gTrendADCSaturated;};
0259   inline TGraphErrors* GetTOT()       {return &gTrendTOT;};
0260   inline TGraphErrors* GetTOTsat()    {return &gTrendTOTSaturated;};
0261   inline TGraphErrors* GetTOA()       {return &gTrendTOA;};
0262   inline TGraphErrors* GetNSampTOA()  {return &gTrendNSampTOA;};
0263   inline TGraphErrors* GetNTOA()      {return &gTrendNTOA;};
0264    
0265   // trending options dependencies
0266   TGraphErrors* GetTrendingBasedOnOption(int option);
0267   void GetMinMaxBasedOnOptionAndCompare(int, Double_t &, Double_t &);
0268    
0269   /**
0270   * Initialize a TGraphErrors instance with a consistent style.
0271   *
0272   * This keeps the repeated trend-graph setup in one place and avoids
0273   * repeating the same ROOT style calls for each per-cell trend.
0274   */
0275   static void InitTrendGraph(TGraphErrors& graph, const char* name, const char* yTitle, Color_t color)
0276   {
0277    graph = TGraphErrors();
0278    graph.SetName(name);
0279    graph.GetYaxis()->SetTitle(yTitle);
0280    graph.SetLineColor(color);
0281    graph.SetMarkerColor(color);
0282    graph.SetMarkerStyle(kFullCircle);
0283   }
0284    
0285   // Getters for individual graph histgrams
0286   TH1D* GetHGTriggRun(int);
0287   TH1D* GetLGTriggRun(int);
0288   TProfile* GetLGHGTriggRun(int);
0289   TProfile* GetWave1DRun(int);
0290   TProfile* GetTOTRun(int);
0291   TProfile* GetTOARun(int);
0292   
0293  protected:
0294   int CellID;
0295   int debug;
0296   int extended;
0297   TGraphErrors gTrendLGped    ;
0298   TGraphErrors gTrendHGped    ;
0299   TGraphErrors gTrendLGpedwidth ;
0300   TGraphErrors gTrendHGpedwidth ;
0301   TGraphErrors gTrendLGscale  ;
0302   TGraphErrors gTrendHGscale  ;
0303   TGraphErrors gTrendHGLGcorr ;
0304   TGraphErrors gTrendLGHGcorr ;
0305   TGraphErrors gTrendTrigger  ;
0306 
0307   TGraphErrors gTrendSBNoise  ;
0308   TGraphErrors gTrendSBSignal ;
0309   TGraphErrors gTrendHGLMPV   ;
0310   TGraphErrors gTrendHGLSigma ;
0311   TGraphErrors gTrendHGGSigma ;
0312   TGraphErrors gTrendLGLMPV   ;
0313   TGraphErrors gTrendLGLSigma ;
0314   TGraphErrors gTrendLGGSigma ;
0315   
0316   TGraphErrors gTrendLGHGOffset ;
0317   TGraphErrors gTrendHGLGOffset ;
0318 
0319   TGraphErrors gTrendADCMax;
0320   TGraphErrors gTrendADCSaturated;
0321   TGraphErrors gTrendTOA;
0322   TGraphErrors gTrendNSampTOA;
0323   TGraphErrors gTrendNTOA;
0324   TGraphErrors gTrendTOT;
0325   TGraphErrors gTrendTOTSaturated;
0326   
0327   double MaxLGped    =0.;
0328   double MaxHGped    =0.;
0329   double MaxLGpedwidth =0.;
0330   double MaxHGpedwidth =0.;
0331   double MaxLGscale  =0.;
0332   double MaxHGscale  =0.;
0333   double MaxHGLGcorr =0.;
0334   double MaxLGHGcorr =0.;
0335   double MaxTrigg    =0.;
0336   double MaxHGSpec   =0.;
0337   double MaxLGSpec   =0.;
0338   double MaxHGMPV    =0.;
0339   double MaxLGMPV    =0.;
0340   double MaxHGLSigma =0.;
0341   double MaxLGLSigma =0.;
0342   double MaxHGGSigma =0.;
0343   double MaxLGGSigma =0.;
0344   double MaxSBNoise  =0.;
0345   double MaxSBSignal =0.;
0346   double MaxLGHGOff   =-10000.;
0347   double MaxHGLGOff   =-10000.;
0348   double MaxInjADC    =-10000.;
0349   double MaxInjTOT    =-10000.;
0350   double MaxADCmax    =0.;
0351   double MaxADCsat    =0.;
0352   double MaxTOT       =0.;
0353   double MaxTOTsat    =0.;
0354   double MaxTOA       =0.;
0355   double MaxNSampTOA  =0.;
0356   double MaxNTOA      =0.;
0357 
0358   double MinLGped    =9999.;
0359   double MinHGped    =9999.;
0360   double MinLGpedwidth =9999.;
0361   double MinHGpedwidth =9999.;
0362   double MinLGscale  =9999.;
0363   double MinHGscale  =9999.;
0364   double MinHGLGcorr =9999.;
0365   double MinLGHGcorr =9999.;
0366   double MinTrigg    =9999.;
0367   double MinHGSpec   =9999.;
0368   double MinLGSpec   =9999.;
0369   double MinHGMPV    =9999.;
0370   double MinLGMPV    =9999.;
0371   double MinHGLSigma =9999.;
0372   double MinLGLSigma =9999.;
0373   double MinHGGSigma =9999.;
0374   double MinLGGSigma =9999.;
0375   double MinSBNoise  =9999.;
0376   double MinSBSignal =9999.;
0377   double MinLGHGOff  =9999.;
0378   double MinHGLGOff  =9999.;
0379   double MinADCmax    =9999.;
0380   double MinADCsat    =9999.;
0381   double MinTOT       =9999.;
0382   double MinTOTsat    =9999.;
0383   double MinTOA       =9999.;
0384   double MinNSampTOA  =9999.;
0385   double MinNTOA      =9999.;
0386   
0387   std::vector<TString> labels;
0388   std::vector<int> runNrs;
0389   std::vector<int> pdgs;
0390   std::vector<double> voltages;
0391   std::vector<double> rf;
0392   std::vector<double> cf;
0393   std::vector<double> cfcomp;
0394   std::vector<double> cc;
0395   std::vector<double> inj;
0396   std::vector<double> energy;
0397   std::vector<double> temp;
0398   std::map<int, TH1D> HGTriggRuns;
0399   std::map<int, TH1D> LGTriggRuns;
0400   std::map<int, TProfile> LGHGTriggRuns;
0401   std::map<int, TProfile> Wave1DProf;
0402   std::map<int, TProfile> TOAProf;
0403   std::map<int, TProfile> TOTProf;
0404   
0405   ClassDef(TileTrend,12);
0406 };
0407 
0408 #endif