Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:03:53

0001 #ifndef PLOTHELPER_MEDIUMTBLFHCAL_H
0002 #define PLOTHELPER_MEDIUMTBLFHCAL_H
0003 
0004   //*****************************************************************
0005   // Medium TB geom sorted by LFHCal layer geom in addtion
0006   //===========================================================
0007     //*****************************************************************
0008     // Test beam geometry (beam coming from viewer)
0009     //          =================================================================================================================
0010     //   row 0  ||    8 (40)   ||    7 (41)  ||    6 (42)  ||    5 (43)  || 8 (44)   ||    7 (45)  ||    6 (46)  ||    5 (47)  ||   row 0
0011     // mod 4    =================================================================================================================           mod 5
0012     //   row 1  ||    1 (32)   ||    2 (33)  ||    3 (34)  ||    4 (35)  || 1 (36)   ||    2 (37)  ||    3 (38)  ||    4 (39)  ||   row 1
0013     //          =================================================================================================================
0014     //   row 0  ||    8 (24)   ||    7 (25)  ||    6 (26)  ||    5 (27)  || 8 (28)   ||    7 (29)  ||    6 (30)  ||    5 (31)  ||   row 0
0015     // mod 2    =================================================================================================================           mod 3
0016     //   row 1  ||    1 (16)   ||    2 (17)  ||    3 (18)  ||    4 (19)  || 1 (20)    ||   2 (21)  ||    3 (22)  ||    4 (23)  ||   row 1
0017     //          =================================================================================================================
0018     //   row 0  ||    8 (8)    ||    7 (9)   ||    6 (10)   ||   5 (11)  || 8 (12)   ||    7 (13)  ||    6 (14)  ||    5 (15)  ||   row 0
0019     //mod 0     =================================================================================================================           mod 1
0020     //   row 1  ||    1 (0)    ||    2 (1)   ||    3 (2)   ||    4 (3)   || 1 (4)    ||    2 (5)   ||    3 (6)  ||    4 (7)    ||   row 1
0021     //          ================================================================================================================= 
0022     //                col 0          col 1        col 2         col  3       col 0          col 1        col 2         col  3
0023     // rebuild pad geom in similar way (numbering -1)
0024     //*****************************************************************
0025     
0026   //__________________________________________________________________________________________________________
0027   // Plot Trigger Primitive with Fits for MediumTB
0028   //__________________________________________________________________________________________________________
0029   inline void PlotTriggerPrimMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, 
0030                                          Double_t* relSize8P, Int_t textSizePixel, 
0031                                          std::map<int,TileSpectra> spectra, 
0032                                          double avMip, double facLow, double facHigh,
0033                                          Double_t xMin, Double_t xMax, Double_t scaleYMax, 
0034                                          int layer, TString nameOutput, RunInfo currRunInfo){
0035                                   
0036     Double_t maxY = 0;
0037     Setup* setupT = Setup::GetInstance();
0038     std::map<int, TileSpectra>::iterator ithSpectra;
0039     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0040     
0041     int nRow = setupT->GetNMaxRow()+1;
0042     int nCol = setupT->GetNMaxColumn()+1;
0043     int nMod = setupT->GetNMaxModule()+1;
0044     int skipped = 0;
0045     for (int r = 0; r < nRow; r++){
0046       for (int c = 0; c < nCol; c++){
0047         for (int m = 0; m < nMod; m++){
0048           int tempCellID = setupT->GetCellID(r,c, layer, m);
0049           ithSpectra=spectra.find(tempCellID);
0050           if(ithSpectra==spectra.end()){
0051             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0052             continue;
0053           } 
0054           TH1D* tempHist = ithSpectra->second.GetTriggPrim();
0055           if (maxY < FindLargestBin1DHist(tempHist, xMin , xMax)) maxY = FindLargestBin1DHist(tempHist, xMin , xMax);
0056         }
0057       }  
0058     }
0059 
0060     for (int r = 0; r < nRow; r++){
0061       for (int c = 0; c < nCol; c++){
0062         for (int m = 0; m < nMod; m++){
0063           canvas->cd();
0064           int tempCellID = setupT->GetCellID(r,c, layer, m);
0065           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0066           pads[p]->Draw();
0067           pads[p]->cd();
0068           pads[p]->SetLogy();
0069           ithSpectra=spectra.find(tempCellID);
0070           if(ithSpectra==spectra.end()){
0071             skipped++;
0072             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0073             pads[p]->Clear();
0074             pads[p]->Draw();
0075             if (p ==47 ){
0076               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0077               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0078               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSize8P[p], "Trigger primitives", true, 0.85*relSize8P[p], 42);
0079             }
0080             continue;
0081           } 
0082           TH1D* tempHist = ithSpectra->second.GetTriggPrim();
0083           SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0084           SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0085           tempHist->GetXaxis()->SetRangeUser(xMin,xMax);
0086           tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0087           
0088           tempHist->Draw("pe");
0089           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
0090           tempHist->Draw("same,axis");
0091           tempHist->Draw("same,pe");
0092 
0093           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0094           if (p == 47){
0095             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
0096           }
0097           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
0098           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0099           labelChannel->Draw();  
0100                   
0101           TBox* triggArea =  CreateBox(kBlue-8, avMip*facLow, 0.7, avMip*facHigh,scaleYMax*maxY, 1001 );
0102           triggArea->Draw();
0103           DrawLines(avMip*facLow, avMip*facLow,0.7, scaleYMax*maxY, 1, 1, 7);
0104           DrawLines(avMip*facHigh, avMip*facHigh,0.7, scaleYMax*maxY, 1, 1, 7);
0105           tempHist->Draw("same,axis");
0106           tempHist->Draw("same,pe");
0107           
0108           if (p == 47 ){
0109             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0110             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0111             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSize8P[p], "Trigger primitives", true, 0.85*relSize8P[p], 42);
0112           }
0113         }
0114       }
0115     }
0116     if (skipped < 48)
0117       canvas->SaveAs(nameOutput.Data());
0118   }
0119   
0120   //__________________________________________________________________________________________________________
0121   // Plot Noise with Fits for MediumTBLayer
0122   //__________________________________________________________________________________________________________
0123   inline void PlotNoiseWithFitsMediumTBLayer (TCanvas* canvas, TPad** pads, 
0124                                  Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0125                                  std::map<int,TileSpectra> spectra, int option, 
0126                                  Double_t xMin, Double_t xMax, Double_t scaleYMax, int layer, TString nameOutput, RunInfo currRunInfo){
0127                                   
0128     Double_t maxY = 0;
0129     std::map<int, TileSpectra>::iterator ithSpectra;
0130     Setup* setupT = Setup::GetInstance();
0131     
0132     int nRow = setupT->GetNMaxRow()+1;
0133     int nCol = setupT->GetNMaxColumn()+1;
0134     int nMod = setupT->GetNMaxModule()+1;
0135     int skipped = 0;
0136     for (int r = 0; r < nRow; r++){
0137       for (int c = 0; c < nCol; c++){
0138         for (int m = 0; m < nMod; m++){
0139           int tempCellID = setupT->GetCellID(r,c, layer, m);
0140           ithSpectra=spectra.find(tempCellID);
0141           if(ithSpectra==spectra.end()){
0142             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m<< std::endl;
0143             skipped++;
0144             continue;
0145           } 
0146           TH1D* tempHist = nullptr;
0147           if (option == 0){
0148               tempHist = ithSpectra->second.GetHG();
0149           } else if (option ==1){
0150               tempHist = ithSpectra->second.GetLG();
0151           } else if (option ==2){
0152               tempHist = ithSpectra->second.GetTOA();
0153           } else if (option ==3){
0154               tempHist = ithSpectra->second.GetTOT();
0155           }
0156           if (maxY < FindLargestBin1DHist(tempHist, xMin , xMax)) maxY = FindLargestBin1DHist(tempHist, xMin , xMax);
0157         }
0158       }  
0159     }
0160     
0161     for (int r = 0; r < nRow; r++){
0162       for (int c = 0; c < nCol; c++){
0163         for (int m = 0; m < nMod; m++){
0164           canvas->cd();
0165           int tempCellID = setupT->GetCellID(r,c, layer, m);
0166           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0167           pads[p]->Draw();
0168           pads[p]->cd();
0169           pads[p]->SetLogy();
0170           ithSpectra=spectra.find(tempCellID);
0171           if(ithSpectra==spectra.end()){
0172             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0173             pads[p]->Clear();
0174             pads[p]->Draw();
0175             if (p ==47 ){
0176               DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0177               DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0178             }
0179             continue;
0180           } 
0181           TH1D* tempHist = nullptr;
0182           if (option == 0){
0183               tempHist = ithSpectra->second.GetHG();
0184           } else if (option ==1){
0185               tempHist = ithSpectra->second.GetLG();
0186           } else if (option ==2){
0187               tempHist = ithSpectra->second.GetTOA();
0188           } else if (option ==3){
0189               tempHist = ithSpectra->second.GetTOT();
0190           }
0191           SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0192           SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0193           tempHist->GetXaxis()->SetRangeUser(xMin,xMax);
0194           tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0195           
0196           tempHist->Draw("pe");
0197           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
0198           tempHist->Draw("same,axis");
0199           tempHist->Draw("same,pe");
0200           
0201           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0202           if (p == 47){
0203             label = Form("r:%d c:%d m:%d layer:%d", r, c, m, layer);
0204           }
0205           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0206           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0207 
0208           
0209           TF1* fit = nullptr;
0210           if (option == 0){
0211             fit = ithSpectra->second.GetBackModel(1);
0212           } else  if (option ==1){
0213             fit = ithSpectra->second.GetBackModel(0);  
0214           }
0215           if (fit){
0216             SetStyleFit(fit , xMin, xMax, 7, 7, kBlack);
0217             fit->Draw("same");
0218             TLegend* legend = GetAndSetLegend2( topRCornerX[p]-0.52, topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.08, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.2);
0219             legend->AddEntry(fit, "Gauss fit", "l");
0220             legend->AddEntry((TObject*)0, Form("#mu = %2.1f#pm%2.1f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0221             legend->AddEntry((TObject*)0, Form("#sigma = %2.1f#pm%2.1f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
0222             legend->Draw();
0223               
0224           } else {
0225             labelChannel->Draw();  
0226           }
0227         
0228           if (xMin < -5) DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0229         
0230           if (p ==47 ){
0231             DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0232             DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0233           }
0234         }
0235       }
0236     }
0237     if (skipped < 48)
0238       canvas->SaveAs(nameOutput.Data());
0239   }
0240   
0241   
0242   //__________________________________________________________________________________________________________
0243   // Plot Noise extracted from collision data
0244   //__________________________________________________________________________________________________________
0245   inline void PlotNoiseAdvWithFitsMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0246                                       std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, bool opt, 
0247                                       Double_t xMin, Double_t xMax, Double_t scaleYMax, int layer, TString nameOutput, RunInfo currRunInfo){
0248                                   
0249     Double_t maxY = 0;
0250     std::map<int, TileSpectra>::iterator ithSpectra;
0251     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0252     
0253     Setup* setupT = Setup::GetInstance();
0254     int nRow = setupT->GetNMaxRow()+1;
0255     int nCol = setupT->GetNMaxColumn()+1;
0256     int nMod = setupT->GetNMaxModule()+1;
0257     int skipped = 0;
0258     for (int r = 0; r < nRow; r++){
0259       for (int c = 0; c < nCol; c++){
0260         for (int m = 0; m < nMod; m++){
0261           int tempCellID = setupT->GetCellID(r,c, layer, m);
0262           ithSpectra=spectra.find(tempCellID);
0263           if(ithSpectra==spectra.end()){
0264             std::cout << "WARNING: PlotNoiseAdvWithFitsMediumTBLayer skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0265             continue;
0266           } 
0267           TH1D* tempHist = nullptr;
0268           if (opt == 1){ // HG
0269             tempHist = ithSpectra->second.GetHG();
0270           } else {
0271             tempHist = ithSpectra->second.GetLG();
0272           }
0273           if (maxY < FindLargestBin1DHist(tempHist, xMin , xMax)) maxY = FindLargestBin1DHist(tempHist, xMin , xMax);
0274         }
0275       }  
0276     }
0277     for (int r = 0; r < nRow; r++){
0278       for (int c = 0; c < nCol; c++){
0279         for (int m = 0; m < nMod; m++){
0280           canvas->cd();
0281           int tempCellID = setupT->GetCellID(r,c, layer, m);
0282           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0283           pads[p]->Draw();
0284           pads[p]->cd();
0285           pads[p]->SetLogy();
0286           ithSpectra=spectra.find(tempCellID);
0287           if(ithSpectra==spectra.end()){
0288             skipped++;
0289             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0290             pads[p]->Clear();
0291             pads[p]->Draw();
0292             if (p == 47 ){
0293               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0294               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0295             }
0296             continue;
0297           } 
0298           ithSpectraTrigg=spectraTrigg.find(tempCellID);
0299           TH1D* tempHist = nullptr;
0300           if (opt == 1){ // HG
0301               tempHist = ithSpectra->second.GetHG();
0302           } else {
0303               tempHist = ithSpectra->second.GetLG();
0304           }
0305           if (!tempHist) continue;
0306           SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0307           SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0308           tempHist->GetXaxis()->SetRangeUser(xMin,xMax);
0309           tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0310           
0311           tempHist->Draw("pe");
0312           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
0313           tempHist->Draw("same,axis");
0314           tempHist->Draw("same,pe");
0315           
0316           TH1D* tempHistT = nullptr;
0317           if (opt == 1){ // HG
0318               tempHistT = ithSpectraTrigg->second.GetHG();
0319           } else {
0320               tempHistT = ithSpectraTrigg->second.GetLG();
0321           }
0322           if (tempHistT){
0323             SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);   
0324             tempHistT->Draw("same,pe");
0325           }
0326           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0327           if (p ==47){
0328             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
0329           }
0330           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
0331           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0332 
0333           
0334           TF1* fit            = nullptr;
0335           bool isTrigFit      = false;
0336           if (opt == 1){ // HG
0337             fit = ithSpectraTrigg->second.GetBackModel(1);
0338             if (!fit){
0339                 fit = ithSpectra->second.GetBackModel(1);
0340                 
0341             } else {
0342                 isTrigFit = true;
0343             }
0344           } else {
0345             fit = ithSpectraTrigg->second.GetBackModel(0);
0346             if (!fit){
0347                 fit = ithSpectra->second.GetBackModel(0);
0348             } else {
0349                 isTrigFit = true;
0350             }  
0351           }
0352           if (fit){
0353             if (isTrigFit)
0354               SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
0355             else 
0356               SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);  
0357             fit->Draw("same");
0358             TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSize8P[p], topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
0359             if (isTrigFit)
0360               legend->AddEntry(fit, "Gauss noise fit, trigg.", "l");
0361             else 
0362               legend->AddEntry(fit, "Gauss noise fit", "l");  
0363             legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0364             legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
0365             legend->Draw();
0366           } else {
0367             labelChannel->Draw();  
0368           }
0369         
0370           DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0371           if (p == 47 ){
0372             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0373             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0374           }
0375         
0376         }
0377       }
0378     }
0379     if (skipped < 48)
0380       canvas->SaveAs(nameOutput.Data());
0381   }  
0382 
0383   //__________________________________________________________________________________________________________
0384   // Plot Noise extracted from collision data
0385   //__________________________________________________________________________________________________________
0386   inline void Plot3SpectraOverlayMediumTBLayer (TCanvas* canvas, TPad** pads, 
0387                                             Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0388                                             std::map<int,TileSpectra> spectra,
0389                                             std::map<int,TileSpectra> spectraTrigg,
0390                                             std::map<int,TileSpectra> spectraNoise,
0391                                             bool opt, Double_t xMin, Double_t xMax, Double_t scaleYMax, 
0392                                             int layer, TString nameOutput, RunInfo currRunInfo){
0393                                   
0394     Double_t maxY = 0;
0395     std::map<int, TileSpectra>::iterator ithSpectra;
0396     std::map<int, TileSpectra>::iterator ithSpectraNoise;
0397     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0398     
0399     Setup* setupT = Setup::GetInstance();
0400     int nRow = setupT->GetNMaxRow()+1;
0401     int nCol = setupT->GetNMaxColumn()+1;
0402     int nMod = setupT->GetNMaxModule()+1;
0403     int skipped = 0;
0404     for (int r = 0; r < nRow; r++){
0405       for (int c = 0; c < nCol; c++){
0406         for (int m = 0; m < nMod; m++){
0407           int tempCellID = setupT->GetCellID(r,c, layer, m);
0408           ithSpectra=spectra.find(tempCellID);
0409           if(ithSpectra==spectra.end()){
0410             std::cout << "WARNING: Plot3SpectraOverlayMediumTBLayer skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0411             continue;
0412           } 
0413           TH1D* tempHist = nullptr;
0414           if (opt == 1){ // HG
0415             tempHist = ithSpectra->second.GetHG();
0416           } else {
0417             tempHist = ithSpectra->second.GetLG();
0418           }
0419           if (maxY < FindLargestBin1DHist(tempHist, xMin , xMax)) maxY = FindLargestBin1DHist(tempHist, xMin , xMax);
0420         }
0421       }  
0422     }
0423     for (int r = 0; r < nRow; r++){
0424       for (int c = 0; c < nCol; c++){
0425         for (int m = 0; m < nMod; m++){
0426           canvas->cd();
0427           int tempCellID = setupT->GetCellID(r,c, layer, m);
0428           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0429           pads[p]->Draw();
0430           pads[p]->cd();
0431           pads[p]->SetLogy();
0432           ithSpectra=spectra.find(tempCellID);
0433           if(ithSpectra==spectra.end()){
0434             skipped++;
0435             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0436             pads[p]->Clear();
0437             pads[p]->Draw();
0438             if (p == 47 ){
0439               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0440               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0441             }
0442             continue;
0443           } 
0444           ithSpectraTrigg=spectraTrigg.find(tempCellID);
0445           ithSpectraNoise=spectraNoise.find(tempCellID);
0446           TH1D* tempHist = nullptr;
0447           if (opt == 1){ // HG
0448               tempHist = ithSpectra->second.GetHG();
0449           } else {
0450               tempHist = ithSpectra->second.GetLG();
0451           }
0452           if (!tempHist) continue;
0453           SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0454           SetMarkerDefaults(tempHist, 24, 1, kGray+1, kGray+1, kFALSE);   
0455           tempHist->GetXaxis()->SetRangeUser(xMin,xMax);
0456           tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0457           
0458           tempHist->Draw("pe");
0459           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
0460           tempHist->Draw("same,axis");
0461           tempHist->Draw("same,pe");
0462           
0463           TH1D* tempHistT = nullptr;
0464           if (opt == 1){ // HG
0465               tempHistT = ithSpectraTrigg->second.GetHG();
0466           } else {
0467               tempHistT = ithSpectraTrigg->second.GetLG();
0468           }
0469           if (tempHistT){
0470             SetMarkerDefaults(tempHistT, 20, 1, kRed+1, kRed+1, kFALSE);   
0471             tempHistT->Draw("same,pe");
0472           }
0473           TH1D* tempHistN = nullptr;
0474           if (opt == 1){ // HG
0475               tempHistN = ithSpectraNoise->second.GetHG();
0476           } else {
0477               tempHistN = ithSpectraNoise->second.GetLG();
0478           }
0479           if (tempHistN){
0480             SetMarkerDefaults(tempHistN, 24, 1, kBlue+1, kBlue+1, kFALSE);   
0481             tempHistN->Draw("same,pe");
0482           }
0483           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0484           if (p == 40){
0485             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
0486           }
0487           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
0488           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0489           labelChannel->Draw();  
0490         
0491           DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0492           if (p == 47 ){
0493             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0494             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0495           }
0496         }
0497       }
0498     }
0499     if (skipped < 48)
0500       canvas->SaveAs(nameOutput.Data());
0501   }  
0502   
0503   
0504   //__________________________________________________________________________________________________________
0505   // Plot Spectra with Fits for Full layer
0506   //__________________________________________________________________________________________________________
0507   inline void PlotSpectraMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0508                                   std::map<int,TileSpectra> spectra, int option, 
0509                                   Double_t xMin, Double_t xMax, Double_t scaleYMax, int layer, TString nameOutput, RunInfo currRunInfo){
0510                                   
0511     Double_t maxY = 0;
0512     std::map<int, TileSpectra>::iterator ithSpectra;
0513     Setup* setupT = Setup::GetInstance();
0514     
0515     int nRow = setupT->GetNMaxRow()+1;
0516     int nCol = setupT->GetNMaxColumn()+1;
0517     int nMod = setupT->GetNMaxModule()+1;
0518     int skipped = 0;
0519     for (int r = 0; r < nRow; r++){
0520       for (int c = 0; c < nCol; c++){
0521         for (int m = 0; m < nMod; m++){
0522           int tempCellID = setupT->GetCellID(r,c, layer, m);
0523           ithSpectra=spectra.find(tempCellID);
0524           if(ithSpectra==spectra.end()){
0525             std::cout << "WARNING: PlotSpectraMediumTBLayer skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0526             continue;
0527           } 
0528           TH1D* tempHist = nullptr;
0529           if (option == 0){
0530             tempHist = ithSpectra->second.GetHG();
0531           } else if (option == 1){
0532             tempHist = ithSpectra->second.GetLG();
0533           } else if (option == 2){
0534             tempHist = ithSpectra->second.GetComb();
0535           } else if (option == 3){
0536             tempHist = ithSpectra->second.GetTOA();
0537           } else if (option == 4){
0538             tempHist = ithSpectra->second.GetTOT();
0539           }
0540           if (maxY < FindLargestBin1DHist(tempHist, xMin , xMax)) maxY = FindLargestBin1DHist(tempHist, xMin , xMax);
0541         }
0542       }  
0543     }
0544     
0545     for (int r = 0; r < nRow; r++){
0546       for (int c = 0; c < nCol; c++){
0547         for (int m = 0; m < nMod; m++){
0548           canvas->cd();
0549           int tempCellID = setupT->GetCellID(r,c, layer, m);
0550           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0551           pads[p]->Draw();
0552           pads[p]->cd();
0553           pads[p]->SetLogy();
0554           ithSpectra=spectra.find(tempCellID);
0555           if(ithSpectra==spectra.end()){
0556             skipped++;
0557             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0558             pads[p]->Clear();
0559             pads[p]->Draw();
0560             if (p == 47 ){
0561               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0562               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0563             }          
0564             continue;
0565           } 
0566           TH1D* tempHist = nullptr;
0567           double noiseWidth = 0;
0568           if (option == 0){
0569               tempHist = ithSpectra->second.GetHG();
0570               noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
0571           } else if (option == 1){
0572               tempHist = ithSpectra->second.GetLG();
0573               noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
0574           } else if (option == 2){
0575               tempHist = ithSpectra->second.GetComb();
0576           } else if (option == 3){
0577             tempHist = ithSpectra->second.GetTOA();
0578           } else if (option == 4){
0579             tempHist = ithSpectra->second.GetTOT();
0580           }
0581           SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0582           SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0583           tempHist->GetXaxis()->SetRangeUser(xMin,xMax);
0584           tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0585           
0586           tempHist->Draw("pe");
0587           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
0588           tempHist->Draw("same,axis");
0589           tempHist->Draw("same,pe");
0590                   
0591           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0592           if (p == 47){
0593             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
0594           }
0595           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
0596           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0597           labelChannel->Draw();  
0598         
0599           if (option < 2){
0600             DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0601             DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);  
0602           } else if (option == 3){
0603             DrawLines(0.3, 0.3, 0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0604           }
0605           if (p == 47 ){
0606             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0607             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0608           }
0609         }
0610       }
0611     }
0612     if (skipped < 48)
0613       canvas->SaveAs(nameOutput.Data());
0614   }
0615     
0616  //__________________________________________________________________________________________________________
0617   // Plot Corr with Fits for Full layer
0618   //__________________________________________________________________________________________________________
0619   inline void PlotCorrWithFitsMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0620                                   std::map<int,TileSpectra> spectra, int option, 
0621                                   Double_t xMin, Double_t xMax, Double_t maxY, int layer, TString nameOutput, RunInfo currRunInfo){
0622                                   
0623     Setup* setupT = Setup::GetInstance();
0624     
0625     std::map<int, TileSpectra>::iterator ithSpectra;    
0626     int nRow = setupT->GetNMaxRow()+1;
0627     int nCol = setupT->GetNMaxColumn()+1;
0628     int nMod = setupT->GetNMaxModule()+1;
0629     int skipped = 0;
0630     
0631     for (int r = 0; r < nRow; r++){
0632       for (int c = 0; c < nCol; c++){
0633         for (int m = 0; m < nMod; m++){
0634           canvas->cd();
0635           int tempCellID = setupT->GetCellID(r,c, layer, m);
0636           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0637           pads[p]->Draw();
0638           pads[p]->SetLogy(0);
0639           pads[p]->cd();
0640           
0641           ithSpectra=spectra.find(tempCellID);
0642           if(ithSpectra==spectra.end()){
0643             skipped++;
0644             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
0645             pads[p]->Clear();
0646             pads[p]->Draw();
0647             if (p == 47 ){
0648               DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSize8P[p], 42);
0649               DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSize8P[p], 42);
0650             }
0651           continue;
0652           } 
0653           TProfile* tempProfile = nullptr;
0654           if (option == 1 || option == 2){
0655               tempProfile = ithSpectra->second.GetHGLGcorr();
0656           } else {
0657               tempProfile = ithSpectra->second.GetLGHGcorr();
0658           }
0659           if (!tempProfile) continue;
0660           TH1D* dummyhist = new TH1D("dummyhist", "", tempProfile->GetNbinsX(), tempProfile->GetXaxis()->GetXmin(), tempProfile->GetXaxis()->GetXmax());
0661           SetStyleHistoTH1ForGraphs( dummyhist, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0662 
0663 
0664           // SetStyleTProfile( tempProfile, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0665           SetMarkerDefaultsProfile(tempProfile, 20, 1, kBlue+1, kBlue+1);   
0666           Int_t maxX = 3900;        
0667           if (option == 0 || option == 2 )
0668             maxX = 340;
0669           if (option == 2){
0670             dummyhist->GetYaxis()->SetRangeUser(-maxY,maxY);
0671             dummyhist->GetXaxis()->SetRangeUser(xMin,maxX);
0672           } else {
0673             dummyhist->GetYaxis()->SetRangeUser(0,maxY);
0674             dummyhist->GetXaxis()->SetRangeUser(0,maxX);
0675           }
0676           
0677           dummyhist->Draw("axis");
0678           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
0679           tempProfile->Draw("pe, same");
0680                   
0681           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0682           if (p == 47){
0683             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
0684           }
0685           TLatex *labelChannel    = new TLatex(topRCornerX[p]+0.045,topRCornerY[p]-1.2*relSize8P[p],label);
0686           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,11);
0687 
0688           
0689           TF1* fit            = nullptr;
0690           if (option == 1 ){
0691             fit = ithSpectra->second.GetCorrModel(1);
0692           } else if (option == 0 ){
0693             fit = ithSpectra->second.GetCorrModel(0);
0694           }
0695           if (fit){
0696             Double_t rangeFit[2] = {0,0};
0697             fit->GetRange(rangeFit[0], rangeFit[1]);
0698             SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
0699             fit->Draw("same");
0700             TLegend* legend = GetAndSetLegend2( topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]+6*relSize8P[p], topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
0701             legend->AddEntry(fit, "linear fit, trigg.", "l");
0702             legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
0703             legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0704             legend->Draw();
0705           } else {
0706             labelChannel->Draw();  
0707           }
0708         
0709           if (option == 2){
0710           DrawLines(xMin,maxX,0, 0, 2, kGray+1, 10);   
0711           }
0712           if (p == 47 ){
0713             DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSize8P[p], 42);
0714             DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSize8P[p], 42);
0715           }
0716         }
0717       }
0718     }
0719     if (skipped < 48)
0720       canvas->SaveAs(nameOutput.Data());
0721   } 
0722 
0723   //__________________________________________________________________________________________________________
0724   // Plot Corr with Fits for Full layer 2D
0725   //__________________________________________________________________________________________________________
0726   inline void PlotCorr2DMediumTBLayer (TCanvas* canvas, TPad** pads, 
0727                           Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0728                           std::map<int,TileSpectra> spectra, int option,
0729                           Double_t xMin, Double_t xMax, Double_t minY, Double_t maxY, int layer, TString nameOutput, RunInfo currRunInfo, bool noCalib = 0, int triggCh = -1 ){
0730                                   
0731     Setup* setupT = Setup::GetInstance();
0732     
0733     std::map<int, TileSpectra>::iterator ithSpectra;    
0734     int nRow = setupT->GetNMaxRow()+1;
0735     int nCol = setupT->GetNMaxColumn()+1;
0736     int nMod = setupT->GetNMaxModule()+1;
0737     int skipped = 0;
0738     ReadOut::Type rotype = ReadOut::Type::Undef;
0739     
0740     bool isTriggCh = false;
0741     if (triggCh != -1)
0742       isTriggCh = true;
0743     
0744     for (int r = 0; r < nRow; r++){
0745       for (int c = 0; c < nCol; c++){
0746         for (int m = 0; m < nMod; m++){
0747           canvas->cd();
0748           int tempCellID = setupT->GetCellID(r,c, layer, m);
0749           int p     = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0750           int roCh  = setupT->GetROchannel(tempCellID);
0751           if (roCh == triggCh){
0752             std::cout << (setupT->DecodeCellID(tempCellID)).Data() << std::endl;
0753           }
0754           pads[p]->Draw();
0755           pads[p]->SetLogy(0);
0756           pads[p]->SetLogz(1);
0757           pads[p]->cd();
0758           
0759           ithSpectra=spectra.find(tempCellID);
0760           if(ithSpectra==spectra.end()){
0761             skipped++;
0762             std::cout << "WARNING: PlotCorr2D2ModLayer skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << "ro ch asic " << roCh << std::endl;
0763             pads[p]->Clear();
0764             pads[p]->Draw();
0765             if (p ==47 ){
0766               DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-1*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0767               DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-1*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0768             }
0769             continue;
0770           } else {
0771             rotype = ithSpectra->second.GetROType();
0772           }
0773           
0774           TProfile* tempProfile = nullptr;
0775           TH2D* temp2D          = nullptr;        
0776           // LG-HG correlation CAEN
0777           if (option == 0){
0778             tempProfile     = ithSpectra->second.GetLGHGcorr();
0779             temp2D          = ithSpectra->second.GetCorr();
0780           // HGCROC waveform
0781           } else if (option == 1){
0782             // tempProfile     = ithSpectra->second.GetWave1D();
0783             temp2D          = ithSpectra->second.GetCorr();          
0784           // HGCROC TOA-ADC correlation
0785           } else if (option == 2){
0786             tempProfile     = ithSpectra->second.GetTOAADC();
0787             temp2D          = ithSpectra->second.GetCorrTOAADC();                    
0788           } else if (option == 3){
0789             temp2D          = ithSpectra->second.GetCorrTOASample();
0790           } else if (option == 4){
0791             temp2D          = ithSpectra->second.GetCorrADCTOT();
0792             tempProfile     = ithSpectra->second.GetADCTOT();
0793           } else if (option == 5){
0794             tempProfile     = ithSpectra->second.GetTOTProfile();
0795           } else if (option == 6){
0796             tempProfile     = ithSpectra->second.GetTOAProfile();
0797           }
0798           
0799           if (!temp2D && option != 4) continue;
0800           
0801           if (temp2D){
0802             SetStyleHistoTH2ForGraphs( temp2D, temp2D->GetXaxis()->GetTitle(), temp2D->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0803             temp2D->GetYaxis()->SetRangeUser(minY,maxY);
0804             temp2D->GetXaxis()->SetRangeUser(xMin,xMax);
0805             temp2D->Draw("col");
0806 
0807             if( !noCalib ){
0808               DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, minY, xMax, maxY);
0809               temp2D->Draw("axis,same");
0810             }
0811             if (isTriggCh && triggCh == roCh){
0812               std::cout << "entered highlighting" << std::endl;
0813               DrawHighlightTrigg(xMin, minY, xMax, maxY);
0814               temp2D->Draw("axis,same");
0815             }
0816           } else {
0817             if (!tempProfile) continue;
0818             TH1D* dummyhist = new TH1D("dummyhist", "", tempProfile->GetNbinsX(), tempProfile->GetXaxis()->GetXmin(), tempProfile->GetXaxis()->GetXmax());
0819             SetStyleHistoTH1ForGraphs( dummyhist, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0820             dummyhist->GetXaxis()->SetRangeUser(xMin,xMax);
0821             dummyhist->GetYaxis()->SetRangeUser(minY,maxY);
0822             dummyhist->Draw("axis");
0823             if( !noCalib ){
0824               DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, minY, xMax, maxY);
0825               dummyhist->Draw("axis,same");
0826             }                              
0827             if (isTriggCh && triggCh == roCh){
0828               std::cout << "entered highlighting" << std::endl;
0829               DrawHighlightTrigg(xMin, minY, xMax, maxY);
0830               dummyhist->Draw("axis,same");
0831             }
0832           }
0833           
0834           if (tempProfile ){
0835             if (option == 2)
0836               SetMarkerDefaultsProfile(tempProfile, 24, 0.7, kBlue+1, kBlue+1);           
0837             else 
0838               SetMarkerDefaultsProfile(tempProfile, 24, 0.7, kRed+2, kRed+2);           
0839             tempProfile->Draw("pe, same");
0840           }
0841             
0842           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0843           if (p == 47){
0844             label = Form("r:%d c:%d m:%d layer:%d", r, c, m, layer);
0845           }
0846           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0847           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0848 
0849           TF1* fit            = ithSpectra->second.GetCorrModel(0);
0850           if (rotype == ReadOut::Type::Hgcroc && option != 4)
0851             fit            = ithSpectra->second.GetCorrModel(2);
0852           int nlinesTot = 1;
0853           if(option == 2 || option == 3){ 
0854             if (ithSpectra->second.GetCalib()->HGLGCorrOff != -1000.){
0855               DrawLines(ithSpectra->second.GetCalib()->HGLGCorrOff, ithSpectra->second.GetCalib()->HGLGCorrOff,0, 0.7*maxY, 1, 1, 7);
0856             }
0857             
0858           }
0859           if (fit){
0860             Double_t rangeFit[2] = {0,0};
0861             fit->GetRange(rangeFit[0], rangeFit[1]);
0862             SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
0863             fit->Draw("same");
0864             TLegend* legend = nullptr;
0865             if (rotype == ReadOut::Type::Caen){
0866               legend = GetAndSetLegend2( topRCornerX[p]-0.5, topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]+0.045, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
0867               legend->AddEntry(fit, "linear fit, trigg.", "l");
0868               legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
0869               legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0870               nlinesTot = 4;
0871             } else {
0872               legend = GetAndSetLegend2( topRCornerX[p]-0.4, topRCornerY[p]-3*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]+0.045, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
0873               legend->AddEntry(fit, "const fit", "l");
0874               legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.1f #pm %2.1f}",fit->GetParameter(0), fit->GetParError(0) ) , " "); 
0875               nlinesTot = 3;
0876             }
0877             legend->Draw();
0878           } else {
0879             labelChannel->Draw();  
0880           }
0881         
0882           if (p ==47 ){
0883             DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-nlinesTot*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0884             DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-nlinesTot*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
0885           }
0886         }
0887       }
0888     }
0889     if (skipped < 48)
0890       canvas->SaveAs(nameOutput.Data());
0891   }
0892   
0893   //__________________________________________________________________________________________________________
0894   // Plot Corr with Fits for Full layer
0895   //__________________________________________________________________________________________________________
0896   inline void PlotTrendingMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0897                               std::map<int,TileTrend> trending, int optionTrend, 
0898                               Double_t xMin, Double_t xMax, Double_t minY, Double_t maxY, bool isSameVoltage, double commonVoltage, 
0899                               int layer, TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t  detailedPlot = 1){
0900                                   
0901     Setup* setupT = Setup::GetInstance();
0902     
0903     std::map<int, TileTrend>::iterator ithTrend;    
0904     int nRow = setupT->GetNMaxRow()+1;
0905     int nCol = setupT->GetNMaxColumn()+1;
0906     int nMod = setupT->GetNMaxModule()+1;
0907     int skipped = 0;
0908     
0909     
0910     // prep for log scale
0911     if (optionTrend == 6){ 
0912       if (minY ==0 ) minY = 1;
0913       else minY = minY/5.;
0914       maxY= maxY*5.;
0915     } else if (optionTrend == 17 || optionTrend == 18 ){ 
0916       minY = 1.1*minY;
0917       maxY = 2*maxY;      
0918     } else {
0919       minY = 0.9*minY;
0920       maxY = 1.1*maxY;      
0921     }
0922     for (int r = 0; r < nRow; r++){
0923       for (int c = 0; c < nCol; c++){
0924         for (int m = 0; m < nMod; m++){
0925           canvas->cd();
0926           int tempCellID = setupT->GetCellID(r,c, layer, m);
0927           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
0928 
0929           TString label           = Form("r:%d c:%d m:%d", r, c, m);
0930           TString label2          = Form("Common V_{op} = %2.1f V", commonVoltage);
0931           if (p == 47){
0932             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
0933           }
0934 
0935           pads[p]->Draw();
0936           
0937           if (optionTrend == 6){ 
0938             pads[p]->SetLogy(1);
0939           } else {
0940             pads[p]->SetLogy(0);          
0941           }
0942 
0943           pads[p]->cd();
0944           ithTrend=trending.find(tempCellID);
0945           if(ithTrend==trending.end()){
0946             skipped++;
0947             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m<< std::endl;
0948             pads[p]->Clear();
0949             pads[p]->Draw();
0950             if (p == 40 ){
0951               TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
0952               TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
0953               TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
0954               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], lab1, true, 0.85*textSizePixel, 43);
0955               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-2*0.85*relSize8P[p], lab2, true, 0.85*textSizePixel, 43);
0956               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-3*0.85*relSize8P[p], lab3, true, 0.85*textSizePixel, 43);
0957             }
0958             continue;
0959           } 
0960           TGraphErrors* tempGraph = nullptr;
0961           if (optionTrend == 0)       tempGraph = ithTrend->second.GetHGped();
0962           else if (optionTrend == 1)  tempGraph = ithTrend->second.GetLGped();
0963           else if (optionTrend == 2)  tempGraph = ithTrend->second.GetHGScale();            
0964           else if (optionTrend == 3)  tempGraph = ithTrend->second.GetLGScale();
0965           else if (optionTrend == 4)  tempGraph = ithTrend->second.GetLGHGcorr();
0966           else if (optionTrend == 5)  tempGraph = ithTrend->second.GetHGLGcorr();
0967           else if (optionTrend == 6)  tempGraph = ithTrend->second.GetTrigger();
0968           else if (optionTrend == 7)  tempGraph = ithTrend->second.GetSBSignal();
0969           else if (optionTrend == 8)  tempGraph = ithTrend->second.GetSBNoise();
0970           else if (optionTrend == 9)  tempGraph = ithTrend->second.GetHGLMPV();
0971           else if (optionTrend == 10) tempGraph = ithTrend->second.GetLGLMPV();
0972           else if (optionTrend == 11) tempGraph = ithTrend->second.GetHGLSigma();
0973           else if (optionTrend == 12) tempGraph = ithTrend->second.GetLGLSigma();
0974           else if (optionTrend == 13) tempGraph = ithTrend->second.GetHGGSigma();
0975           else if (optionTrend == 14) tempGraph = ithTrend->second.GetLGGSigma();
0976           else if (optionTrend == 15) tempGraph = ithTrend->second.GetHGpedwidth();
0977           else if (optionTrend == 16) tempGraph = ithTrend->second.GetLGpedwidth();
0978           else if (optionTrend == 17) tempGraph = ithTrend->second.GetLGHGOff();
0979           else if (optionTrend == 18) tempGraph = ithTrend->second.GetHGLGOff();
0980           if (!tempGraph) continue;
0981           TH1D* dummyhist = new TH1D("dummyhist", "", 100, xMin, xMax);
0982           SetStyleHistoTH1ForGraphs( dummyhist, tempGraph->GetXaxis()->GetTitle(), tempGraph->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0983           // if (optionTrend == 6)std::cout << "\t" << tempGraph->GetXaxis()->GetTitle() << "\t" << tempGraph->GetYaxis()->GetTitle() << std::endl;
0984           SetMarkerDefaultsTGraphErr(tempGraph, 20, 1, kBlue+1, kBlue+1);   
0985           dummyhist->GetYaxis()->SetRangeUser(minY,maxY);
0986           dummyhist->Draw("axis");
0987           tempGraph->Draw("pe, same");
0988                   
0989           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p], label, true, 0.85*textSizePixel, 43);
0990           if (isSameVoltage && p == 15){
0991             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], label2, true, 0.85*textSizePixel, 43);
0992           }
0993           if (p == 40 ){
0994             TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
0995             TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
0996             TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
0997             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], lab1, true, 0.85*textSizePixel, 43);
0998             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-2*0.85*relSize8P[p], lab2, true, 0.85*textSizePixel, 43);
0999             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-3*0.85*relSize8P[p], lab3, true, 0.85*textSizePixel, 43);
1000           }
1001         }
1002       }
1003     }
1004     if (skipped < 48){
1005       if(detailedPlot) canvas->SaveAs(nameOutput.Data());
1006       if (layer == 0) canvas->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1007       canvas->Print(Form("%s.pdf",nameOutputSummary.Data()));
1008       if (layer == setupT->GetNMaxLayer()) canvas->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1009     }
1010   } // end PlotTrending2ModLayer()
1011   
1012   //__________________________________________________________________________________________________________
1013   // Plot Run overlay for all 48 tiles for all runs available
1014   //__________________________________________________________________________________________________________
1015   inline void PlotRunOverlayMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
1016                               std::map<int,TileTrend> trending, int nruns, int optionTrend, 
1017                               Double_t xMin, Double_t xMax, int layer, TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t detailedPlot = 1){
1018                                   
1019     Setup* setupT = Setup::GetInstance();
1020     
1021     std::map<int, TileTrend>::iterator ithTrend;    
1022     int nRow = setupT->GetNMaxRow()+1;
1023     int nCol = setupT->GetNMaxColumn()+1;
1024     int nMod = setupT->GetNMaxModule()+1;
1025     int skipped = 0;
1026     
1027     Double_t maxY         = 0.;
1028     Double_t minY         = 9999.;
1029     bool isSameVoltage    = true;
1030     double commonVoltage  = 0;
1031     for (int r = 0; r < nRow; r++){
1032       for (int c = 0; c < nCol; c++){
1033         for (int m = 0; m < nMod; m++){
1034           int tempCellID = setupT->GetCellID(r,c, layer, m);
1035           ithTrend=trending.find(tempCellID);
1036           if (optionTrend == 0){      // HG
1037             if(maxY<ithTrend->second.GetMaxHGSpec()) maxY=ithTrend->second.GetMaxHGSpec();
1038             if(minY>ithTrend->second.GetMinHGSpec()) minY=ithTrend->second.GetMinHGSpec();
1039           } else if (optionTrend == 1){   //LG
1040             if(maxY<ithTrend->second.GetMaxLGSpec()) maxY=ithTrend->second.GetMaxLGSpec();
1041             if(minY>ithTrend->second.GetMinLGSpec()) minY=ithTrend->second.GetMinLGSpec();
1042           } 
1043           
1044           for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1045             if (r == 0 && c == 0){
1046               if (rc == 0){
1047                 commonVoltage = ithTrend->second.GetVoltage(rc);
1048               } else {
1049                 if (commonVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
1050               }
1051             }
1052           }
1053         }
1054       }
1055     }
1056     if (maxY == 0 && minY == 9999.){
1057       std::cout <<"Something went wrong! No ranges set for layer " <<  layer << " \t trend plotting option: " << optionTrend << "\t ABORTING!" << std::endl;
1058       return;
1059     }
1060     maxY = 3*maxY;
1061     TH1D* histos[30];
1062 
1063     double lineBottom  = (1.4+6);
1064     if (nruns < 6) lineBottom = (1.4+1);
1065     else if (nruns < 11) lineBottom = (1.4+2);
1066     else if (nruns < 16) lineBottom = (1.4+3);
1067     else if (nruns < 21) lineBottom = (1.4+4);
1068     else if (nruns < 26) lineBottom = (1.4+5);
1069     TLegend* legend = nullptr;
1070     
1071     for (int r = 0; r < nRow; r++){
1072       for (int c = 0; c < nCol; c++){
1073         for (int m = 0; m < nMod; m++){
1074           canvas->cd();
1075           int tempCellID = setupT->GetCellID(r,c, layer, m);
1076           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
1077           pads[p]->Draw();
1078           pads[p]->cd();
1079           pads[p]->SetLogy(1);
1080           ithTrend=trending.find(tempCellID);
1081 
1082           TString label           = Form("r:%d c:%d m:%d", r, c, m);
1083           TString label2          = Form("Common V_{op} = %2.1f V", commonVoltage);
1084           if (p == 47){
1085             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
1086           }
1087           if(ithTrend==trending.end()){
1088             skipped++;
1089             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
1090             pads[p]->Clear();
1091             pads[p]->Draw();
1092             if (p == 12 ){
1093               TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1094               TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1095               TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1096               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], lab1, true, 0.85*textSizePixel, 43);
1097               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-2*0.85*relSize8P[p], lab2, true, 0.85*textSizePixel, 43);
1098               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-3*0.85*relSize8P[p], lab3, true, 0.85*textSizePixel, 43);
1099             }
1100             
1101             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p], label, true, 0.85*textSizePixel, 43);
1102             continue;
1103           } 
1104 
1105           if (p == 47 ){
1106             double startLegY  = topRCornerY[p]-lineBottom*relSize8P[p];
1107             double endLegY    = topRCornerY[p]-1.4*relSize8P[p];
1108             legend = GetAndSetLegend2(  0.3, startLegY, topRCornerX[p]-0.045/2, endLegY,
1109                                         0.85*textSizePixel, 5, "",43,0.25);
1110           }
1111           
1112           for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1113             int tmpRunNr = ithTrend->second.GetRunNr(rc);
1114             histos[rc] = nullptr;
1115             if (tmpRunNr != -1) {
1116               if (optionTrend == 0){      // HG
1117                 histos[rc] = ithTrend->second.GetHGTriggRun(ithTrend->second.GetRunNr(rc));
1118               } else if (optionTrend == 1){      // LG
1119                 histos[rc] = ithTrend->second.GetLGTriggRun(ithTrend->second.GetRunNr(rc));
1120               }
1121             }
1122             if (histos[rc]){
1123               SetStyleHistoTH1ForGraphs( histos[rc], histos[rc]->GetXaxis()->GetTitle(), histos[rc]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.95, 1.3,  510, 510, 43, 63);  
1124               SetLineDefaults(histos[rc], GetColorLayer(rc), 2, GetLineStyleLayer(rc));   
1125               if(rc == 0){
1126                 histos[rc]->GetXaxis()->SetRangeUser(xMin,xMax);
1127                 histos[rc]->GetYaxis()->SetRangeUser(minY,maxY);
1128                 histos[rc]->Draw("hist");
1129               } else {
1130                 histos[rc]->Draw("same,hist");
1131               }
1132               if(p == 47) legend->AddEntry(histos[rc],Form("%d",tmpRunNr),"l");
1133             }
1134           }
1135           if (histos[0]) histos[0]->Draw("axis,same");                
1136           
1137           // labeling inside the panels & legend drawing 
1138           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p], label, true, 0.85*textSizePixel, 43);
1139           if (isSameVoltage && p == 15){
1140             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-(lineBottom+0.5)*relSize8P[p], label2, true, 0.85*textSizePixel, 43);
1141           }
1142           
1143           if (p == 47) legend->Draw();
1144           if (p == 40 ){
1145             TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1146             TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1147             TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1148             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], lab1, true, 0.85*textSizePixel, 43);
1149             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-2*0.85*relSize8P[p], lab2, true, 0.85*textSizePixel, 43);
1150             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSize8P[p]-3*0.85*relSize8P[p], lab3, true, 0.85*textSizePixel, 43);
1151           }
1152         }
1153       }
1154     }
1155     if (skipped < 48){
1156       if(detailedPlot) canvas->SaveAs(nameOutput.Data());
1157       if (layer == 0) canvas->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1158       canvas->Print(Form("%s.pdf",nameOutputSummary.Data()));
1159       if (layer == setupT->GetNMaxLayer()) canvas->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1160     }
1161   }
1162 
1163 
1164   //__________________________________________________________________________________________________________
1165   // Plot Run overlay for all 16 tiles for all runs available
1166   //__________________________________________________________________________________________________________
1167   inline void PlotRunOverlayProfileMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
1168                                       std::map<int,TileTrend> trending, int nruns, int option,
1169                                       Double_t xMin, Double_t xMax, Double_t yPMin, Double_t yPMax,  int layer, TString nameOutput, TString nameOutputSummary, 
1170                                       RunInfo currRunInfo, Int_t detailedPlot = 1, bool scaleInt = false){
1171                                   
1172     Setup* setupT = Setup::GetInstance();
1173     
1174     std::map<int, TileTrend>::iterator ithTrend;    
1175     int nRow = setupT->GetNMaxRow()+1;
1176     int nCol = setupT->GetNMaxColumn()+1;
1177     int nMod = setupT->GetNMaxModule()+1;
1178     int skipped = 0;
1179     
1180     Int_t nSameSettings = 0;
1181     if (currRunInfo.rf > -1) nSameSettings++;
1182     if (currRunInfo.cf > -1) nSameSettings++;
1183     if (currRunInfo.cfcomp > -1) nSameSettings++;
1184     if (currRunInfo.cc > -1) nSameSettings++;
1185     if (currRunInfo.vop > -1) nSameSettings++;
1186     
1187     TProfile* profs[30];
1188     double lineBottom  = (1.4+5);
1189     if (nruns < 6) lineBottom = (1.4);
1190     else if (nruns < 11) lineBottom = (1.4+1);
1191     else if (nruns < 16) lineBottom = (1.4+2);
1192     else if (nruns < 21) lineBottom = (1.4+3);
1193     else if (nruns < 26) lineBottom = (1.4+4);
1194     TLegend* legend = nullptr;
1195     
1196     if (nSameSettings == 4) lineBottom++;
1197     std::cout << "number of same settings: "  << nSameSettings << std::endl;
1198     
1199     for (int r = 0; r < nRow; r++){
1200       for (int c = 0; c < nCol; c++){
1201         for (int m = 0; m < nMod; m++){
1202           canvas->cd();
1203           int tempCellID = setupT->GetCellID(r,c, layer, m);
1204           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
1205           pads[p]->Draw();
1206           pads[p]->cd();
1207           pads[p]->SetLogy(0);
1208           ithTrend=trending.find(tempCellID);
1209 
1210           TString label           = Form("r:%d c:%d m:%d", r, c, m);
1211           TString label2          = Form("V_{op}=%2.1fV", currRunInfo.vop);
1212           TString label3          = GetLabelHGCROCSettings(currRunInfo);
1213 
1214           if(ithTrend==trending.end()){
1215             skipped++;
1216             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
1217             pads[p]->Clear();
1218             pads[p]->Draw();
1219             if (p == 40 ){
1220               TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1221               TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1222               TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1223               DrawLatex(topRCornerX[p]-0.8, topRCornerY[p]-1.2*relSize8P[p]-0*0.85*relSize8P[p], lab1, false, 0.85*textSizePixel, 43);
1224               DrawLatex(topRCornerX[p]-0.8, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], lab2, false, 0.85*textSizePixel, 43);
1225               DrawLatex(topRCornerX[p]-0.8, topRCornerY[p]-1.2*relSize8P[p]-2*0.85*relSize8P[p], lab3, false, 0.85*textSizePixel, 43);
1226             }
1227             
1228             DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-1.2*relSize8P[p], label, true, 0.85*textSizePixel, 43);
1229             continue;
1230           } 
1231 
1232           if (p == 47 ){
1233             double startLegY  = topRCornerY[p]-(lineBottom-1)*relSize8P[p];
1234             double endLegY    = topRCornerY[p]-0.04;
1235             TString header    = "";
1236             double width      = 0.5;
1237             if (nSameSettings == 4){
1238                 width = 0.9;
1239                 std::cout <<  currRunInfo.rf << "\t" << currRunInfo.cf << "\t" << currRunInfo.cfcomp << "\t" << currRunInfo.cc << "\t" << currRunInfo.vop << std::endl;
1240                 if (currRunInfo.rf < 0)
1241                   header = "RF (k#Omega)";
1242                 if (currRunInfo.cf < 0) header = "CF (fF)";
1243                 if (currRunInfo.cfcomp < 0) header = "CF_{comp} (fF)";
1244                 if (currRunInfo.cc < 0)  header = "CC";
1245                 if (currRunInfo.vop < 0)  header = "V_{op} (V)";
1246             }
1247             legend = GetAndSetLegend2(  0.05, startLegY, width, endLegY,
1248                                         0.85*textSizePixel, 5, header,43,0.25);
1249           }
1250           
1251           TH1D* dummyhist;
1252           for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1253             int tmpRunNr = ithTrend->second.GetRunNr(rc);
1254             profs[rc] = nullptr;
1255             if (tmpRunNr != -1) {
1256               if (option == 0)
1257                 profs[rc] = ithTrend->second.GetLGHGTriggRun(ithTrend->second.GetRunNr(rc));
1258               else if (option == 1)
1259                 profs[rc] = ithTrend->second.GetWave1DRun(ithTrend->second.GetRunNr(rc));
1260               else if (option == 2)
1261                 profs[rc] = ithTrend->second.GetTOARun(ithTrend->second.GetRunNr(rc));
1262               else if (option == 3)  
1263                 profs[rc] = ithTrend->second.GetTOTRun(ithTrend->second.GetRunNr(rc));
1264               if (scaleInt && profs[rc] != nullptr) profs[rc]->Scale(1/profs[rc]->Integral());
1265             }
1266             if (profs[rc]){
1267               if (rc == 0){
1268                 TString yTitle = profs[rc]->GetYaxis()->GetTitle();
1269                 if (scaleInt) yTitle = Form("%s/ integral", yTitle.Data());
1270 
1271                 dummyhist = new TH1D("dummyhist", "", profs[rc]->GetNbinsX(), profs[rc]->GetXaxis()->GetXmin(), profs[rc]->GetXaxis()->GetXmax());
1272                 SetStyleHistoTH1ForGraphs( dummyhist, profs[rc]->GetXaxis()->GetTitle(), yTitle, 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
1273                 dummyhist->GetXaxis()->SetRangeUser(xMin,xMax);
1274                 dummyhist->GetYaxis()->SetRangeUser(yPMin,yPMax);
1275                 dummyhist->Draw("axis");
1276               }
1277 
1278               SetLineDefaults(profs[rc], GetColorLayer(rc), 2, GetLineStyleLayer(rc));   
1279               profs[rc]->SetMarkerStyle(GetMarkerLayer(rc));
1280               profs[rc]->Draw("same,pe");
1281               if(p == 47){
1282                 TString labelLegend = Form("%d",tmpRunNr);
1283                 if (nSameSettings == 4){
1284                   if (currRunInfo.vop < 0) labelLegend = Form("%.1f",(double)ithTrend->second.GetVoltage(rc));
1285                   if (currRunInfo.rf < 0) labelLegend = Form("%.1f",ReturnRFValue(ithTrend->second.GetRF(rc)));
1286                   if (currRunInfo.cf < 0) labelLegend = Form("%.0f",ReturnCFValue(ithTrend->second.GetCF(rc)));
1287                   if (currRunInfo.cfcomp < 0) labelLegend = Form("%.0f",ReturnCFCompValue(ithTrend->second.GetCFComp(rc)));
1288                   if (currRunInfo.cc < 0)  labelLegend = Form("%.0f",ReturnCCValue(ithTrend->second.GetCC(rc)));
1289                 }
1290                 legend->AddEntry(profs[rc],labelLegend.Data(),"p");
1291               }
1292             }
1293           }
1294           if (dummyhist) dummyhist->Draw("axis,same");                
1295           
1296           // labeling inside the panels & legend drawing 
1297           DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-1.2*relSize8P[p], label, true, 0.85*textSizePixel, 43);
1298           if ( nSameSettings > 0  && p == 13){
1299             DrawLatex(0.04, topRCornerY[p]-1.2*relSize8P[p], label2, false, 0.85*textSizePixel, 43);
1300             DrawLatex(0.04, topRCornerY[p]-1.2*relSize8P[p]-0.85*relSize8P[p], label3, false, 0.85*textSizePixel, 43);
1301             
1302           }
1303           
1304           if (p == 47) legend->Draw();
1305           if (p == 40 ){
1306             TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1307             TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1308             TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1309             DrawLatex(topRCornerX[p]-0.8, topRCornerY[p]-1.2*relSize8P[p]-0*0.85*relSize8P[p], lab1, false, 0.85*textSizePixel, 43);
1310             DrawLatex(topRCornerX[p]-0.8, topRCornerY[p]-1.2*relSize8P[p]-1*0.85*relSize8P[p], lab2, false, 0.85*textSizePixel, 43);
1311             DrawLatex(topRCornerX[p]-0.8, topRCornerY[p]-1.2*relSize8P[p]-2*0.85*relSize8P[p], lab3, false, 0.85*textSizePixel, 43);
1312           }
1313         }
1314       }
1315     }
1316     if (skipped < 48){
1317       if(detailedPlot) canvas->SaveAs(nameOutput.Data());
1318       if (layer == 0) canvas->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1319       canvas->Print(Form("%s.pdf",nameOutputSummary.Data()));
1320       if (layer == setupT->GetNMaxLayer()) canvas->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1321     }
1322   }
1323  
1324    //__________________________________________________________________________________________________________
1325   // Plot Mip with Fits for Full layer
1326   //__________________________________________________________________________________________________________
1327   inline void PlotMipWithFitsMediumTBLayer (TCanvas* canvas, TPad** pads, Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
1328                                   std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, int opt, 
1329                                   Double_t xMin, Double_t xMax, Double_t scaleYMax, int layer, TString nameOutput, RunInfo currRunInfo){
1330                                   
1331     Double_t maxY = 0;
1332     std::map<int, TileSpectra>::iterator ithSpectra;
1333     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
1334     Setup* setupT = Setup::GetInstance();
1335     
1336     int nRow = setupT->GetNMaxRow()+1;
1337     int nCol = setupT->GetNMaxColumn()+1;
1338     int nMod = setupT->GetNMaxModule()+1;
1339     int skipped = 0;
1340     for (int r = 0; r < nRow; r++){
1341       for (int c = 0; c < nCol; c++){
1342         for (int m = 0; m < nMod; m++){
1343           int tempCellID = setupT->GetCellID(r,c, layer, m);
1344           ithSpectra=spectra.find(tempCellID);
1345           if(ithSpectra==spectra.end()){
1346             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
1347             continue;
1348           } 
1349           TH1D* tempHist = nullptr;
1350           if (opt == 1){
1351             tempHist = ithSpectra->second.GetHG();
1352           } else {
1353             tempHist = ithSpectra->second.GetLG();
1354           }
1355           if (maxY < FindLargestBin1DHist(tempHist, xMin , xMax)) maxY = FindLargestBin1DHist(tempHist, xMin , xMax);
1356         }
1357       }  
1358     }
1359     
1360     for (int r = 0; r < nRow; r++){
1361       for (int c = 0; c < nCol; c++){
1362         for (int m = 0; m < nMod; m++){
1363           canvas->cd();
1364           int tempCellID = setupT->GetCellID(r,c, layer, m);
1365           int p = setupT->GetChannelInLayerFull(tempCellID, DetConf::Type::MediumTB);
1366           pads[p]->Draw();
1367           pads[p]->cd();
1368           pads[p]->SetLogy();
1369           ithSpectra=spectra.find(tempCellID);
1370           if(ithSpectra==spectra.end()){
1371             skipped++;
1372             std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << m << std::endl;
1373             pads[p]->Clear();
1374             pads[p]->Draw();
1375             if (p ==47 ){
1376               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1377               DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1378             }          
1379             continue;
1380           } 
1381           ithSpectraTrigg=spectraTrigg.find(tempCellID);
1382           TH1D* tempHist = nullptr;
1383           double noiseWidth = 0;
1384           if (opt == 1){
1385             tempHist = ithSpectra->second.GetHG();
1386             noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
1387           } else {
1388             tempHist = ithSpectra->second.GetLG();
1389             noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
1390           }
1391           SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
1392           SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
1393           tempHist->GetXaxis()->SetRangeUser(xMin,xMax);
1394           tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
1395           
1396           tempHist->Draw("pe");
1397           DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xMin, 0, xMax, maxY);
1398           tempHist->Draw("same,axis");
1399           tempHist->Draw("same,pe");
1400           
1401           TH1D* tempHistT = nullptr;
1402           
1403           if (opt == 1){
1404             tempHistT = ithSpectraTrigg->second.GetHG();
1405           } else {
1406             tempHistT = ithSpectraTrigg->second.GetLG();
1407           }
1408           SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);   
1409           tempHistT->Draw("same,pe");
1410           
1411           TString label           = Form("r:%d c:%d m:%d", r, c, m);
1412           if (p == 47){
1413             label = Form("r:%d c:%d m:%d layer %d", r, c, m, layer);
1414           }
1415           TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
1416           SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
1417 
1418           
1419           TF1* fit            = nullptr;
1420           bool isTrigFit      = false;
1421           double maxFit       = 0;
1422           double SNR                = 0; // signal to noise ratio -EP   
1423           double maxBin       = 0; 
1424           if (ithSpectra->second.GetROType() == ReadOut::Type::Caen) { // from Analyses.cc -EP
1425             maxBin = 3800;
1426           } else {
1427             maxBin = 1024;
1428           }
1429           if (opt == 1){
1430             Int_t binNLow = ithSpectra->second.GetHG()->FindBin(-1*noiseWidth); // for SNR -EP
1431             Int_t binNHigh = ithSpectra->second.GetHG()->FindBin(3*noiseWidth); 
1432             Int_t binSHigh = ithSpectra->second.GetHG()->FindBin(maxBin); 
1433             fit = ithSpectraTrigg->second.GetSignalModel(1);
1434             if (!fit){
1435                 fit = ithSpectra->second.GetSignalModel(1);
1436                 if (fit){
1437                   maxFit = ithSpectra->second.GetCalib()->ScaleH;
1438                   double noiseInt = ithSpectra->second.GetHG()->Integral(binNLow, binNHigh); 
1439                   double sigInt = ithSpectra->second.GetHG()->Integral(binNHigh, binSHigh);
1440                   SNR = (noiseInt != 0) ? sigInt/noiseInt : 0; // if noise = 0, SNR = 0 -EP
1441                 }
1442             } else {
1443                 isTrigFit = true;
1444                 maxFit = ithSpectraTrigg->second.GetCalib()->ScaleH;
1445                 double noiseInt = ithSpectraTrigg->second.GetHG()->Integral(binNLow, binNHigh); 
1446                 double sigInt = ithSpectraTrigg->second.GetHG()->Integral(binNHigh, binSHigh);
1447                 SNR = (noiseInt != 0) ? sigInt/noiseInt : 0; // if noise = 0, SNR = 0 -EP
1448             }
1449           } // end if (opt == 1) 
1450           else {
1451             fit = ithSpectraTrigg->second.GetSignalModel(0);
1452             if (!fit){
1453                 fit = ithSpectra->second.GetSignalModel(0);
1454                 if (fit){
1455                   maxFit = ithSpectra->second.GetCalib()->ScaleL;
1456                 }
1457             } else {
1458                 isTrigFit = true;
1459                 maxFit = ithSpectraTrigg->second.GetCalib()->ScaleL;
1460             }  
1461           }
1462           if (fit){
1463             if (isTrigFit)
1464               SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
1465             else 
1466               SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);  
1467             fit->Draw("same");
1468             TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSize8P[p], topRCornerY[p]-6*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
1469             if (opt == 1)
1470               legend->AddEntry((TObject*)0, Form("Total events: %i", (int)ithSpectra->second.GetHG()->Integral()), "");
1471             if (isTrigFit)
1472               legend->AddEntry(fit, "Landau-Gauss fit, trigg.", "l");
1473             else 
1474               legend->AddEntry(fit, "Landau-Gauss fit", "l");  
1475             // estimate uncertainty on max position
1476             double rel_err_L_MPV = fit->GetParError(1)/fit->GetParameter(1); // relative uncertainty on MPV
1477             double sigma_Max = rel_err_L_MPV * maxFit;
1478             legend->AddEntry((TObject*)0, Form("#scale[0.8]{L MPV = %2.2f #pm %2.2f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
1479             legend->AddEntry((TObject*)0, Form("#scale[0.8]{Max = %2.2f #pm %2.2f}", maxFit, sigma_Max ) , " ");
1480             legend->AddEntry((TObject*)0, Form("#scale[0.8]{#chi^{2}/ndf = %2.2f}", fit->GetChisquare()/fit->GetNDF()), " ");
1481             // add SNR to legend
1482             if (opt == 1){
1483               legend->AddEntry((TObject*)0, Form("#scale[0.8]{SNR = %2.2f}", SNR), " ");
1484             }
1485             legend->Draw();
1486             DrawLines(maxFit, maxFit,0.7, scaleYMax*maxY/10, 5, kRed+3, 7);  
1487           } else {
1488             labelChannel->Draw();  
1489           }
1490         
1491           DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
1492           DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);  
1493         
1494           if (p == 47 ){
1495             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-6*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1496             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-6*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1497           }
1498         }
1499       }
1500     }
1501     if (skipped < 48)
1502       canvas->SaveAs(nameOutput.Data());
1503   }
1504   
1505 #endif
1506