Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:28:20

0001 #ifndef PLOTTHELPER_2MLAYER_H
0002 #define PLOTTHELPER_2MLAYER_H
0003 
0004   // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0005   // dedicated class for all 8M layer plotting functions
0006   // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0007 
0008 //   //__________________________________________________________________________________________________________
0009 //   // Plot Trigger Primitive with Fits for Full layer
0010 //   //__________________________________________________________________________________________________________
0011 //   void PlotTriggerPrimWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, 
0012 //                                          Double_t* relSizeP, Int_t textSizePixel, 
0013 //                                          std::map<int,TileSpectra> spectra, Setup* setupT, 
0014 //                                          double avMip, double facLow, double facHigh,
0015 //                                          Double_t xPMin, Double_t xPMax, Double_t scaleYMax, 
0016 //                                          int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0017 //                                   
0018 //     Double_t maxY = 0;
0019 //     std::map<int, TileSpectra>::iterator ithSpectra;
0020 //     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0021 //     
0022 //     int nRow = setupT->GetNMaxRow()+1;
0023 //     int nCol = setupT->GetNMaxColumn()+1;
0024 //     int skipped = 0;
0025 //     for (int r = 0; r < nRow; r++){
0026 //       for (int c = 0; c < nCol; c++){
0027 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0028 //         ithSpectra=spectra.find(tempCellID);
0029 //         if(ithSpectra==spectra.end()){
0030 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0031 //           continue;
0032 //         } 
0033 //         TH1D* tempHist = ithSpectra->second.GetTriggPrim();
0034 //         if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0035 //       }  
0036 //     }
0037 // 
0038 //     for (int r = 0; r < nRow; r++){
0039 //       for (int c = 0; c < nCol; c++){
0040 //         canvas2Panel->cd();
0041 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0042 //         int p = setupT->GetChannelInLayer(tempCellID);
0043 //         pads[p]->Draw();
0044 //         pads[p]->cd();
0045 //         pads[p]->SetLogy();
0046 //         ithSpectra=spectra.find(tempCellID);
0047 //         if(ithSpectra==spectra.end()){
0048 //           skipped++;
0049 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0050 //           pads[p]->Clear();
0051 //           pads[p]->Draw();
0052 //           if (p ==7 ){
0053 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0054 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0055 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSizeP[p], "Trigger primitives", true, 0.85*relSizeP[p], 42);
0056 //           }
0057 //           continue;
0058 //         } 
0059 //         TH1D* tempHist = ithSpectra->second.GetTriggPrim();
0060 //         SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0061 //         SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0062 //         tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0063 //         tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0064 //         
0065 //         tempHist->Draw("pe");
0066 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0067 //         if (bctemp != -64 && bctemp < 3){
0068 //           Color_t boxCol = kGray;
0069 //           if (bctemp == 1)
0070 //             boxCol = kGray+1;
0071 //           else if (bctemp == 0)
0072 //             boxCol = kGray+2;
0073 //           TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0074 //           badChannelArea->Draw();
0075 //           tempHist->Draw("same,axis");
0076 //           tempHist->Draw("same,pe");
0077 //         }
0078 // 
0079 //         TString label           = Form("row %d col %d", r, c);
0080 //         if (p == 7){
0081 //           label = Form("row %d col %d layer %d", r, c, layer);
0082 //         }
0083 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0084 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0085 //         labelChannel->Draw();  
0086 //       
0087 //         TBox* triggArea =  CreateBox(kBlue-8, avMip*facLow, 0.7, avMip*facHigh,scaleYMax*maxY, 1001 );
0088 //         triggArea->Draw();
0089 //         
0090 //         DrawLines(avMip*facLow, avMip*facLow,0.7, scaleYMax*maxY, 1, 1, 7);
0091 //         DrawLines(avMip*facHigh, avMip*facHigh,0.7, scaleYMax*maxY, 1, 1, 7);
0092 //         tempHist->Draw("same,axis");
0093 //         tempHist->Draw("same,pe");
0094 //         
0095 //         if (p ==7 ){
0096 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0097 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0098 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSizeP[p], "Trigger primitives", true, 0.85*relSizeP[p], 42);
0099 //         }
0100 //       }
0101 //     }
0102 //     if (skipped < 6)
0103 //       canvas2Panel->SaveAs(nameOutput.Data());
0104 //   }
0105 //     
0106   //__________________________________________________________________________________________________________
0107   // Plot Noise with Fits for Full layer
0108   //__________________________________________________________________________________________________________
0109   void PlotNoiseWithFits2MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0110                                   std::map<int,TileSpectra> spectra, bool option, 
0111                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0112                                   
0113     Double_t maxY = 0;
0114     std::map<int, TileSpectra>::iterator ithSpectra;
0115     Setup* setupT = Setup::GetInstance();
0116     
0117     int nCol = setupT->GetNMaxColumn()+1;
0118     int skipped = 0;
0119     for (int c = 0; c < nCol; c++){
0120       int tempCellID = setupT->GetCellID(0,c, layer, mod);
0121       ithSpectra=spectra.find(tempCellID);
0122       if(ithSpectra==spectra.end()){
0123         std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << 0 << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0124         skipped++;
0125         continue;
0126       } 
0127       TH1D* tempHist = nullptr;
0128       if (option == 0){
0129           tempHist = ithSpectra->second.GetHG();
0130       } else if (option ==1){
0131           tempHist = ithSpectra->second.GetLG();
0132       } else if (option ==2){
0133           tempHist = ithSpectra->second.GetTOA();
0134       } else if (option ==3){
0135           tempHist = ithSpectra->second.GetTOT();
0136       }
0137       if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0138     }  
0139     
0140     for (int c = 0; c < nCol; c++){
0141       canvas2Panel->cd();
0142       int tempCellID = setupT->GetCellID(0,c, layer, mod);
0143       pads[c]->Draw();
0144       pads[c]->cd();
0145       pads[c]->SetLogy();
0146       ithSpectra=spectra.find(tempCellID);
0147       if(ithSpectra==spectra.end()){
0148         std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << 0 << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0149         pads[c]->Clear();
0150         pads[c]->Draw();
0151         if (c ==1 ){
0152           DrawLatex(topRCornerX[c]-0.04, topRCornerY[c]-4*0.85*relSizeP[c]-1.4*relSizeP[c], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[c], 42);
0153           DrawLatex(topRCornerX[c]-0.04, topRCornerY[c]-4*0.85*relSizeP[c]-2.2*relSizeP[c], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[c], 42);
0154         }
0155         continue;
0156       } 
0157       TH1D* tempHist = nullptr;
0158       if (option == 0){
0159           tempHist = ithSpectra->second.GetHG();
0160       } else if (option ==1){
0161           tempHist = ithSpectra->second.GetLG();
0162       } else if (option ==2){
0163           tempHist = ithSpectra->second.GetTOA();
0164       } else if (option ==3){
0165           tempHist = ithSpectra->second.GetTOT();
0166       }
0167       SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0168       SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0169       tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0170       tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0171       
0172       tempHist->Draw("pe");
0173       short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0174       if (bctemp != -64 && bctemp < 3){
0175         Color_t boxCol = kGray;
0176         if (bctemp == 1)
0177           boxCol = kGray+1;
0178         else if (bctemp == 0)
0179           boxCol = kGray+2;
0180         TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0181         badChannelArea->SetFillColorAlpha(boxCol, 0.35);
0182         badChannelArea->Draw();
0183         tempHist->Draw("same,axis");
0184         tempHist->Draw("same,pe");
0185       }
0186       
0187       TString label           = Form("col %d", c);
0188       if (c == 1){
0189         label = Form("col %d layer %d", c, layer);
0190       }
0191       TLatex *labelChannel    = new TLatex(topRCornerX[c]-0.04,topRCornerY[c]-1.2*relSizeP[c],label);
0192       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0193 
0194       
0195       TF1* fit = nullptr;
0196       if (option == 0){
0197         fit = ithSpectra->second.GetBackModel(1);
0198       } else if (option == 1){
0199         fit = ithSpectra->second.GetBackModel(0);  
0200       }
0201       if (fit){
0202         SetStyleFit(fit , xPMin, xPMax, 7, 7, kBlack);
0203         fit->Draw("same");
0204         TLegend* legend = GetAndSetLegend2( topRCornerX[c]-8*relSizeP[c], topRCornerY[c]-4*0.85*relSizeP[c]-0.4*relSizeP[c], topRCornerX[c]-0.04, topRCornerY[c]-0.6*relSizeP[c],0.85*textSizePixel, 1, label, 43,0.2);
0205         legend->AddEntry(fit, "Gauss noise fit", "l");
0206         legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0207         legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
0208         legend->Draw();
0209           
0210       } else {
0211         labelChannel->Draw();  
0212       }
0213     
0214       if (xPMin < -5) DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0215     
0216       if (c ==1 ){
0217         DrawLatex(topRCornerX[c]-0.04, topRCornerY[c]-4*0.85*relSizeP[c]-1.4*relSizeP[c], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[c], 42);
0218         DrawLatex(topRCornerX[c]-0.04, topRCornerY[c]-4*0.85*relSizeP[c]-2.2*relSizeP[c], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[c], 42);
0219       }
0220     }
0221     if (skipped < 2)
0222       canvas2Panel->SaveAs(nameOutput.Data());
0223   }
0224 //   
0225 //   
0226 //   //__________________________________________________________________________________________________________
0227 //   // Plot Noise extracted from collision data
0228 //   //__________________________________________________________________________________________________________
0229 //   void PlotNoiseAdvWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0230 //                                       std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, bool isHG, 
0231 //                                       Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0232 //                                   
0233 //     Double_t maxY = 0;
0234 //     std::map<int, TileSpectra>::iterator ithSpectra;
0235 //     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0236 //     
0237 //     Setup* setupT = Setup::GetInstance();
0238 //     int nRow = setupT->GetNMaxRow()+1;
0239 //     int nCol = setupT->GetNMaxColumn()+1;
0240 //     int skipped = 0;
0241 //     for (int r = 0; r < nRow; r++){
0242 //       for (int c = 0; c < nCol; c++){
0243 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0244 //         ithSpectra=spectra.find(tempCellID);
0245 //         if(ithSpectra==spectra.end()){
0246 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0247 //           continue;
0248 //         } 
0249 //         TH1D* tempHist = nullptr;
0250 //         if (isHG){
0251 //           tempHist = ithSpectra->second.GetHG();
0252 //         } else {
0253 //           tempHist = ithSpectra->second.GetLG();
0254 //         }
0255 //         if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0256 //       }  
0257 //     }
0258 //     for (int r = 0; r < nRow; r++){
0259 //       for (int c = 0; c < nCol; c++){
0260 //         canvas2Panel->cd();
0261 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0262 //         int p = setupT->GetChannelInLayer(tempCellID);
0263 //         pads[p]->Draw();
0264 //         pads[p]->cd();
0265 //         pads[p]->SetLogy();
0266 //         ithSpectra=spectra.find(tempCellID);
0267 //         if(ithSpectra==spectra.end()){
0268 //           skipped++;
0269 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0270 //           pads[p]->Clear();
0271 //           pads[p]->Draw();
0272 //           if (p ==7 ){
0273 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0274 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0275 //           }
0276 //           continue;
0277 //         } 
0278 //         ithSpectraTrigg=spectraTrigg.find(tempCellID);
0279 //         TH1D* tempHist = nullptr;
0280 //         if (isHG){
0281 //             tempHist = ithSpectra->second.GetHG();
0282 //         } else {
0283 //             tempHist = ithSpectra->second.GetLG();
0284 //         }
0285 //         SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0286 //         SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0287 //         tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0288 //         tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0289 //         
0290 //         tempHist->Draw("pe");
0291 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0292 //         if (bctemp != -64 && bctemp < 3){
0293 //           Color_t boxCol = kGray;
0294 //           if (bctemp == 1)
0295 //             boxCol = kGray+1;
0296 //           else if (bctemp == 0)
0297 //             boxCol = kGray+2;
0298 //           TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0299 //           badChannelArea->Draw();
0300 //           tempHist->Draw("same,axis");
0301 //           tempHist->Draw("same,pe");
0302 //         }
0303 //         
0304 //         TH1D* tempHistT = nullptr;
0305 //         if (isHG){
0306 //             tempHistT = ithSpectraTrigg->second.GetHG();
0307 //         } else {
0308 //             tempHistT = ithSpectraTrigg->second.GetLG();
0309 //         }
0310 //         SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);   
0311 //         tempHistT->Draw("same,pe");
0312 //         
0313 //         TString label           = Form("row %d col %d", r, c);
0314 //         if (p == 7){
0315 //           label = Form("row %d col %d layer %d", r, c, layer);
0316 //         }
0317 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0318 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0319 // 
0320 //         
0321 //         TF1* fit            = nullptr;
0322 //         bool isTrigFit      = false;
0323 //         if (isHG){
0324 //           fit = ithSpectraTrigg->second.GetBackModel(1);
0325 //           if (!fit){
0326 //               fit = ithSpectra->second.GetBackModel(1);
0327 //               
0328 //           } else {
0329 //               isTrigFit = true;
0330 //           }
0331 //         } else {
0332 //           fit = ithSpectraTrigg->second.GetBackModel(0);
0333 //           if (!fit){
0334 //               fit = ithSpectra->second.GetBackModel(0);
0335 //           } else {
0336 //               isTrigFit = true;
0337 //           }  
0338 //         }
0339 //         if (fit){
0340 //           if (isTrigFit)
0341 //             SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
0342 //           else 
0343 //             SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);  
0344 //           fit->Draw("same");
0345 //           TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSizeP[p], topRCornerY[p]-4*0.85*relSizeP[p]-0.4*relSizeP[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSizeP[p],0.85*textSizePixel, 1, label, 43,0.1);
0346 //           if (isTrigFit)
0347 //             legend->AddEntry(fit, "Gauss noise fit, trigg.", "l");
0348 //           else 
0349 //             legend->AddEntry(fit, "Gauss noise fit", "l");  
0350 //           legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0351 //           legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
0352 //           legend->Draw();
0353 //         } else {
0354 //           labelChannel->Draw();  
0355 //         }
0356 //       
0357 //         DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0358 //         if (p ==7 ){
0359 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0360 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0361 //         }
0362 //       
0363 //       }
0364 //     }
0365 //     if (skipped < 6)
0366 //       canvas2Panel->SaveAs(nameOutput.Data());
0367 //   }  
0368 //   
0369 //   //__________________________________________________________________________________________________________
0370 //   // Plot Mip with Fits for Full layer
0371 //   //__________________________________________________________________________________________________________
0372 //   void PlotMipWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0373 //                                   std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, Setup* setupT, bool isHG, 
0374 //                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0375 //                                   
0376 //     Double_t maxY = 0;
0377 //     std::map<int, TileSpectra>::iterator ithSpectra;
0378 //     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0379 //     
0380 //     int nRow = setupT->GetNMaxRow()+1;
0381 //     int nCol = setupT->GetNMaxColumn()+1;
0382 //     int skipped = 0;
0383 //     for (int r = 0; r < nRow; r++){
0384 //       for (int c = 0; c < nCol; c++){
0385 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0386 //         ithSpectra=spectra.find(tempCellID);
0387 //         if(ithSpectra==spectra.end()){
0388 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0389 //           continue;
0390 //         } 
0391 //         TH1D* tempHist = nullptr;
0392 //         if (isHG){
0393 //           tempHist = ithSpectra->second.GetHG();
0394 //         } else {
0395 //           tempHist = ithSpectra->second.GetLG();
0396 //         }
0397 //         if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0398 //       }  
0399 //     }
0400 //     
0401 //     for (int r = 0; r < nRow; r++){
0402 //       for (int c = 0; c < nCol; c++){
0403 //         canvas2Panel->cd();
0404 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0405 //         int p = setupT->GetChannelInLayer(tempCellID);
0406 //         pads[p]->Draw();
0407 //         pads[p]->cd();
0408 //         pads[p]->SetLogy();
0409 //         ithSpectra=spectra.find(tempCellID);
0410 //         if(ithSpectra==spectra.end()){
0411 //           skipped++;
0412 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0413 //           pads[p]->Clear();
0414 //           pads[p]->Draw();
0415 //           if (p ==7 ){
0416 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0417 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0418 //           }          
0419 //           continue;
0420 //         } 
0421 //         ithSpectraTrigg=spectraTrigg.find(tempCellID);
0422 //         TH1D* tempHist = nullptr;
0423 //         double noiseWidth = 0;
0424 //         if (isHG){
0425 //             tempHist = ithSpectra->second.GetHG();
0426 //             noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
0427 //         } else {
0428 //             tempHist = ithSpectra->second.GetLG();
0429 //             noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
0430 //         }
0431 //         SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0432 //         SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0433 //         tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0434 //         tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0435 //         
0436 //         tempHist->Draw("pe");
0437 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0438 //         if (bctemp != -64 && bctemp < 3){
0439 //           Color_t boxCol = kGray;
0440 //           if (bctemp == 1)
0441 //             boxCol = kGray+1;
0442 //           else if (bctemp == 0)
0443 //             boxCol = kGray+2;
0444 //           TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0445 //           badChannelArea->Draw();
0446 //           tempHist->Draw("same,axis");
0447 //           tempHist->Draw("same,pe");
0448 //         }
0449 //         
0450 //         TH1D* tempHistT = nullptr;
0451 //         
0452 //         if (isHG){
0453 //             tempHistT = ithSpectraTrigg->second.GetHG();
0454 //         } else {
0455 //             tempHistT = ithSpectraTrigg->second.GetLG();
0456 //         }
0457 //         SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);   
0458 //         tempHistT->Draw("same,pe");
0459 //         
0460 //         TString label           = Form("row %d col %d", r, c);
0461 //         if (p == 7){
0462 //           label = Form("row %d col %d layer %d", r, c, layer);
0463 //         }
0464 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0465 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0466 // 
0467 //         
0468 //         TF1* fit            = nullptr;
0469 //         bool isTrigFit      = false;
0470 //         double maxFit       = 0;
0471 //         if (isHG){
0472 //           fit = ithSpectraTrigg->second.GetSignalModel(1);
0473 //           if (!fit){
0474 //               fit = ithSpectra->second.GetSignalModel(1);
0475 //               if (fit){
0476 //                 maxFit = ithSpectra->second.GetCalib()->ScaleH;
0477 //               }
0478 //           } else {
0479 //               isTrigFit = true;
0480 //               maxFit = ithSpectraTrigg->second.GetCalib()->ScaleH;
0481 //           }
0482 //         } else {
0483 //           fit = ithSpectraTrigg->second.GetSignalModel(0);
0484 //           if (!fit){
0485 //               fit = ithSpectra->second.GetSignalModel(0);
0486 //               if (fit){
0487 //                 maxFit = ithSpectra->second.GetCalib()->ScaleL;
0488 //               }
0489 //           } else {
0490 //               isTrigFit = true;
0491 //               maxFit = ithSpectraTrigg->second.GetCalib()->ScaleL;
0492 //           }  
0493 //         }
0494 //         if (fit){
0495 //           if (isTrigFit)
0496 //             SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
0497 //           else 
0498 //             SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);  
0499 //           fit->Draw("same");
0500 //           TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSizeP[p], topRCornerY[p]-4*0.85*relSizeP[p]-0.4*relSizeP[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSizeP[p],0.85*textSizePixel, 1, label, 43,0.1);
0501 //           if (isTrigFit)
0502 //             legend->AddEntry(fit, "Landau-Gauss fit, trigg.", "l");
0503 //           else 
0504 //             legend->AddEntry(fit, "Landau-Gauss fit", "l");  
0505 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{L MPV = %2.2f #pm %2.2f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0506 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{Max = %2.2f}", maxFit ) , " ");
0507 //           legend->Draw();
0508 //           DrawLines(maxFit, maxFit,0.7, scaleYMax*maxY/10, 5, kRed+3, 7);  
0509 //         } else {
0510 //           labelChannel->Draw();  
0511 //         }
0512 //       
0513 //         DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0514 //         DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);  
0515 //       
0516 //         if (p ==7 ){
0517 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0518 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0519 //         }
0520 //       }
0521 //     }
0522 //     if (skipped < 6)
0523 //       canvas2Panel->SaveAs(nameOutput.Data());
0524 //   }
0525 // 
0526   //__________________________________________________________________________________________________________
0527   // Plot Spectra with Fits for Full layer
0528   //__________________________________________________________________________________________________________
0529   void PlotSpectra2MLayer (TCanvas* canvas2Panel, TPad* pads[2], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0530                                   std::map<int,TileSpectra> spectra, int option, 
0531                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0532                                   
0533     Double_t maxY = 0;
0534     std::map<int, TileSpectra>::iterator ithSpectra;
0535     Setup* setupT = Setup::GetInstance();
0536     
0537     int nCol = setupT->GetNMaxColumn()+1;
0538     int skipped = 0;
0539     for (int c = 0; c < nCol; c++){
0540       int tempCellID = setupT->GetCellID(0,c, layer, mod);
0541       ithSpectra=spectra.find(tempCellID);
0542       if(ithSpectra==spectra.end()){
0543         std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0544         continue;
0545       } 
0546       TH1D* tempHist = nullptr;
0547       if (option == 0){
0548         tempHist = ithSpectra->second.GetHG();
0549       } else if (option == 1){
0550         tempHist = ithSpectra->second.GetLG();
0551       } else if (option == 2){
0552         tempHist = ithSpectra->second.GetComb();
0553       } else if (option == 3){
0554         tempHist = ithSpectra->second.GetTOA();
0555       } else if (option == 4){
0556         tempHist = ithSpectra->second.GetTOT();
0557       }
0558       if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0559     }  
0560     
0561     for (int c = 0; c < nCol; c++){
0562       canvas2Panel->cd();
0563       int tempCellID = setupT->GetCellID(0,c, layer, mod);
0564       pads[c]->Draw();
0565       pads[c]->cd();
0566       pads[c]->SetLogy();
0567       ithSpectra=spectra.find(tempCellID);
0568       if(ithSpectra==spectra.end()){
0569         skipped++;
0570         std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0571         pads[c]->Clear();
0572         pads[c]->Draw();
0573         if (c ==1 ){
0574           DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-4*0.85*relSizeP[c]-1.4*relSizeP[c], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[c], 42);
0575           DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-4*0.85*relSizeP[c]-2.2*relSizeP[c], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[c], 42);
0576         }          
0577         continue;
0578       } 
0579       TH1D* tempHist = nullptr;
0580       double noiseWidth = 0;
0581       if (option == 0){
0582           tempHist = ithSpectra->second.GetHG();
0583           noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
0584       } else if (option == 1){
0585           tempHist = ithSpectra->second.GetLG();
0586           noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
0587       } else if (option == 2){
0588           tempHist = ithSpectra->second.GetComb();
0589       } else if (option == 3){
0590         tempHist = ithSpectra->second.GetTOA();
0591       } else if (option == 4){
0592         tempHist = ithSpectra->second.GetTOT();
0593       }
0594       SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0595       SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0596       tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0597       tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0598       
0599       tempHist->Draw("pe");
0600       short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0601       if (bctemp != -64 && bctemp < 3){
0602         Color_t boxCol = kGray;
0603         if (bctemp == 1)
0604           boxCol = kGray+1;
0605         else if (bctemp == 0)
0606           boxCol = kGray+2;
0607         TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0608         badChannelArea->Draw();
0609         tempHist->Draw("same,axis");
0610         tempHist->Draw("same,pe");
0611       }
0612               
0613       TString label           = Form("col %d", c);
0614       if (c == 1){
0615         label = Form("col %d layer %d", c, layer);
0616       }
0617       TLatex *labelChannel    = new TLatex(topRCornerX[c]-0.045,topRCornerY[c]-1.2*relSizeP[c],label);
0618       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0619       labelChannel->Draw();  
0620     
0621       if (option < 2){
0622         DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0623         DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);  
0624       } else if (option == 3){
0625         DrawLines(0.3, 0.3, 0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0626       }
0627       if (c == 1 ){
0628         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-4*0.85*relSizeP[c]-1.4*relSizeP[c], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[c], 42);
0629         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-4*0.85*relSizeP[c]-2.2*relSizeP[c], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[c], 42);
0630       }
0631     }
0632     if (skipped < 2)
0633       canvas2Panel->SaveAs(nameOutput.Data());
0634   }
0635   
0636 //   //__________________________________________________________________________________________________________
0637 //   // Plot Corr with Fits for Full layer
0638 //   //__________________________________________________________________________________________________________
0639 //   void PlotCorrWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0640 //                                   std::map<int,TileSpectra> spectra, int option, 
0641 //                                   Double_t xPMin, Double_t xPMax, Double_t maxY, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0642 //                                   
0643 //     Setup* setupT = Setup::GetInstance();
0644 //     
0645 //     std::map<int, TileSpectra>::iterator ithSpectra;    
0646 //     int nRow = setupT->GetNMaxRow()+1;
0647 //     int nCol = setupT->GetNMaxColumn()+1;
0648 //     int skipped = 0;
0649 //     
0650 //     for (int r = 0; r < nRow; r++){
0651 //       for (int c = 0; c < nCol; c++){
0652 //         canvas2Panel->cd();
0653 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0654 //         int p = setupT->GetChannelInLayer(tempCellID);
0655 //         pads[p]->Draw();
0656 //         pads[p]->SetLogy(0);
0657 //         pads[p]->cd();
0658 //         
0659 //         ithSpectra=spectra.find(tempCellID);
0660 //         if(ithSpectra==spectra.end()){
0661 //           skipped++;
0662 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0663 //           pads[p]->Clear();
0664 //           pads[p]->Draw();
0665 //           if (p ==7 ){
0666 //             DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP[p], 42);
0667 //             DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP[p], 42);
0668 //           }
0669 //         continue;
0670 //         } 
0671 //         TProfile* tempProfile = nullptr;
0672 //         if (option == 1 || option == 2){
0673 //             tempProfile = ithSpectra->second.GetHGLGcorr();
0674 //         } else {
0675 //             tempProfile = ithSpectra->second.GetLGHGcorr();
0676 //         }
0677 //         if (!tempProfile) continue;
0678 //         TH1D* dummyhist = new TH1D("dummyhist", "", tempProfile->GetNbinsX(), tempProfile->GetXaxis()->GetXmin(), tempProfile->GetXaxis()->GetXmax());
0679 //         SetStyleHistoTH1ForGraphs( dummyhist, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0680 // 
0681 // 
0682 //         // SetStyleTProfile( tempProfile, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0683 //         SetMarkerDefaultsProfile(tempProfile, 20, 1, kBlue+1, kBlue+1);   
0684 //         Int_t maxX = 3900;        
0685 //         if (option == 0 || option == 2 )
0686 //           maxX = 340;
0687 //         if (option == 2){
0688 //           dummyhist->GetYaxis()->SetRangeUser(-maxY,maxY);
0689 //           dummyhist->GetXaxis()->SetRangeUser(xPMin,maxX);
0690 //         } else {
0691 //           dummyhist->GetYaxis()->SetRangeUser(0,maxY);
0692 //           dummyhist->GetXaxis()->SetRangeUser(0,maxX);
0693 //         }
0694 //         
0695 //         
0696 //         dummyhist->Draw("axis");
0697 // 
0698 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0699 //         if (bctemp != -64 && bctemp < 3){
0700 //           Color_t boxCol = kGray;
0701 //           if (bctemp == 1)
0702 //             boxCol = kGray+1;
0703 //           else if (bctemp == 0)
0704 //             boxCol = kGray+2;
0705 //           TBox* badChannelArea =  CreateBox(boxCol, 0, 0, maxX,maxY, 1001 );
0706 //           badChannelArea->Draw();
0707 //           dummyhist->Draw("axis,same");
0708 //         }
0709 // 
0710 //         tempProfile->Draw("pe, same");
0711 //                 
0712 //         TString label           = Form("row %d col %d", r, c);
0713 //         if (p == 7){
0714 //           label = Form("row %d col %d layer %d", r, c, layer);
0715 //         }
0716 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]+0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0717 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,11);
0718 // 
0719 //         
0720 //         TF1* fit            = nullptr;
0721 //         if (option == 1 ){
0722 //           fit = ithSpectra->second.GetCorrModel(1);
0723 //         } else if (option == 0 ){
0724 //           fit = ithSpectra->second.GetCorrModel(0);
0725 //         }
0726 //         if (fit){
0727 //           Double_t rangeFit[2] = {0,0};
0728 //           fit->GetRange(rangeFit[0], rangeFit[1]);
0729 //           SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
0730 //           fit->Draw("same");
0731 //           TLegend* legend = GetAndSetLegend2( topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-0.4*relSizeP[p], topRCornerX[p]+6*relSizeP[p], topRCornerY[p]-0.6*relSizeP[p],0.85*textSizePixel, 1, label, 43,0.1);
0732 //           legend->AddEntry(fit, "linear fit, trigg.", "l");
0733 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
0734 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0735 //           legend->Draw();
0736 //         } else {
0737 //           labelChannel->Draw();  
0738 //         }
0739 //       
0740 //         if (option == 2){
0741 //          DrawLines(xPMin,maxX,0, 0, 2, kGray+1, 10);   
0742 //         }
0743 //         if (p ==7 ){
0744 //           DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP[p], 42);
0745 //           DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP[p], 42);
0746 //         }
0747 //       }
0748 //     }
0749 //     if (skipped < 6)
0750 //       canvas2Panel->SaveAs(nameOutput.Data());
0751 //   }
0752 // 
0753   //__________________________________________________________________________________________________________
0754   // Plot Corr with Fits for Full layer 2D
0755   //__________________________________________________________________________________________________________
0756   void PlotCorr2D2MLayer (TCanvas* canvas2Panel, TPad* pads[2], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0757                                   std::map<int,TileSpectra> spectra, 
0758                                   Double_t xPMin, Double_t xPMax, Double_t maxY, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0759                                   
0760     Setup* setupT = Setup::GetInstance();
0761     
0762     std::map<int, TileSpectra>::iterator ithSpectra;    
0763     int nCol = setupT->GetNMaxColumn()+1;
0764     int skipped = 0;
0765     ReadOut::Type rotype = ReadOut::Type::Undef;
0766     
0767     for (int c = 0; c < nCol; c++){
0768       canvas2Panel->cd();
0769       int tempCellID = setupT->GetCellID(0,c, layer, mod);
0770       pads[c]->Draw();
0771       pads[c]->SetLogy(0);
0772       pads[c]->SetLogz(1);
0773       pads[c]->cd();
0774       
0775       Int_t offset = 1;
0776       
0777       ithSpectra=spectra.find(tempCellID);
0778       if(ithSpectra==spectra.end()){
0779         skipped++;
0780         std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << 0 << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0781         pads[c]->Clear();
0782         pads[c]->Draw();
0783         if (c == 1 ){
0784           DrawLatex(topRCornerX[c]+0.045, topRCornerY[c]-offset*0.85*relSizeP[c]-1.4*relSizeP[c], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP[c], 42);
0785           DrawLatex(topRCornerX[c]+0.045, topRCornerY[c]-offset*0.85*relSizeP[c]-2.2*relSizeP[c], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP[c], 42);
0786         }
0787         continue;
0788       } else {
0789         rotype = ithSpectra->second.GetROType();
0790       }
0791       TProfile* tempProfile = ithSpectra->second.GetLGHGcorr();
0792       TH2D* temp2D          = ithSpectra->second.GetCorr();
0793       if (!tempProfile) continue;
0794       SetStyleHistoTH2ForGraphs( temp2D, temp2D->GetXaxis()->GetTitle(), temp2D->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0795       SetMarkerDefaultsProfile(tempProfile, 24, 0.7, kRed+2, kRed+2);   
0796       
0797       temp2D->GetYaxis()->SetRangeUser(-10,maxY);
0798       temp2D->GetXaxis()->SetRangeUser(0,xPMax);
0799       temp2D->Draw("col");
0800 
0801       short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0802       if (bctemp != -64 && bctemp < 3){
0803         Color_t boxCol = kGray;
0804         if (bctemp == 1)
0805           boxCol = kGray+1;
0806         else if (bctemp == 0)
0807           boxCol = kGray+2;
0808         TBox* badChannelArea =  CreateBox(boxCol, 0, 0, xPMax,maxY, 1001 );
0809         badChannelArea->Draw();
0810         temp2D->Draw("axis,same");
0811       }
0812 
0813       TString xTit = temp2D->GetXaxis()->GetTitle();
0814       if (xTit.Contains("ample") != 0){
0815         tempProfile->Draw("pe, same");
0816       } 
0817         
0818       TString label           = Form("col %d", c);
0819       if (c == 1){
0820         label = Form("col %d layer %d", c, layer);
0821       }
0822       TLatex *labelChannel    = new TLatex(topRCornerX[c]+0.045,topRCornerY[c]-1.2*relSizeP[c],label);
0823       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,11);
0824 
0825       TF1* fit            = ithSpectra->second.GetCorrModel(0);
0826       if (rotype == ReadOut::Type::Hgcroc)
0827         fit            = ithSpectra->second.GetCorrModel(2);
0828       if (fit){
0829         offset=4;
0830         Double_t rangeFit[2] = {0,0};
0831         fit->GetRange(rangeFit[0], rangeFit[1]);
0832         SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
0833         fit->Draw("same");
0834         TLegend* legend = nullptr;
0835         if (rotype == ReadOut::Type::Caen){
0836           legend = GetAndSetLegend2( topRCornerX[c]+0.045, topRCornerY[c]-4*0.85*relSizeP[c]-0.4*relSizeP[c], topRCornerX[c]+6*relSizeP[c], topRCornerY[c]-0.6*relSizeP[c],0.85*textSizePixel, 1, label, 43,0.1);
0837           legend->AddEntry(fit, "linear fit, trigg.", "l");
0838           legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
0839           legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0840         } else {
0841           legend = GetAndSetLegend2( topRCornerX[c]+0.045, topRCornerY[c]-3*0.85*relSizeP[c]-0.4*relSizeP[c], topRCornerX[c]+6*relSizeP[c], topRCornerY[c]-0.6*relSizeP[c],0.85*textSizePixel, 1, label, 43,0.1);
0842           legend->AddEntry(fit, "const fit", "l");
0843           legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");   
0844         }
0845         legend->Draw();
0846       } else {
0847         labelChannel->Draw();  
0848       }
0849     
0850       if (c ==1 ){
0851         DrawLatex(topRCornerX[c]+0.045, topRCornerY[c]-offset*0.85*relSizeP[c]-1.4*relSizeP[c], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP[c], 42);
0852         DrawLatex(topRCornerX[c]+0.045, topRCornerY[c]-offset*0.85*relSizeP[c]-2.2*relSizeP[c], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP[c], 42);
0853       }
0854     }
0855     if (skipped < 2)
0856       canvas2Panel->SaveAs(nameOutput.Data());
0857   }
0858 //   
0859 //   //__________________________________________________________________________________________________________
0860 //   // Plot Corr with Fits for Full layer
0861 //   //__________________________________________________________________________________________________________
0862 //   void PlotTrending8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0863 //                               std::map<int,TileTrend> trending, int optionTrend, 
0864 //                               Double_t xPMin, Double_t xPMax, int layer, int mod,  TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t  detailedPlot = 1){
0865 //                                   
0866 //     Setup* setupT = Setup::GetInstance();
0867 //     
0868 //     std::map<int, TileTrend>::iterator ithTrend;    
0869 //     int nRow = setupT->GetNMaxRow()+1;
0870 //     int nCol = setupT->GetNMaxColumn()+1;
0871 //     int skipped = 0;
0872 //     bool isSameVoltage    = true;
0873 //     double commanVoltage  = 0;
0874 //     
0875 //     Double_t minY = 9999;
0876 //     Double_t maxY = 0.;
0877 //     
0878 //     for (int r = 0; r < nRow; r++){
0879 //       for (int c = 0; c < nCol; c++){
0880 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0881 //         ithTrend=trending.find(tempCellID);
0882 //         if (optionTrend == 0){
0883 //           if(minY>ithTrend->second.GetMinHGped()) minY=ithTrend->second.GetMinHGped();
0884 //           if(maxY<ithTrend->second.GetMaxHGped()) maxY=ithTrend->second.GetMaxHGped();
0885 //         } else if (optionTrend == 1){
0886 //           if(minY>ithTrend->second.GetMinLGped()) minY=ithTrend->second.GetMinLGped();
0887 //           if(maxY<ithTrend->second.GetMaxLGped()) maxY=ithTrend->second.GetMaxLGped();
0888 //         } else if (optionTrend == 2){
0889 //           if(minY>ithTrend->second.GetMinHGscale()) minY=ithTrend->second.GetMinHGscale();
0890 //           if(maxY<ithTrend->second.GetMaxHGscale()) maxY=ithTrend->second.GetMaxHGscale();
0891 //         } else if (optionTrend == 3){
0892 //           if(minY>ithTrend->second.GetMinLGscale()) minY=ithTrend->second.GetMinLGscale();
0893 //           if(maxY<ithTrend->second.GetMaxLGscale()) maxY=ithTrend->second.GetMaxLGscale();
0894 //         } else if (optionTrend == 4){
0895 //           if(minY>ithTrend->second.GetMinLGHGcorr()) minY=ithTrend->second.GetMinLGHGcorr();
0896 //           if(maxY<ithTrend->second.GetMaxLGHGcorr()) maxY=ithTrend->second.GetMaxLGHGcorr();
0897 //         } else if (optionTrend == 5){
0898 //           if(minY>ithTrend->second.GetMinHGLGcorr()) minY=ithTrend->second.GetMinHGLGcorr();
0899 //           if(maxY<ithTrend->second.GetMaxHGLGcorr()) maxY=ithTrend->second.GetMaxHGLGcorr();          
0900 //         } else if (optionTrend == 6){
0901 //           if(minY>ithTrend->second.GetMinTrigg()) minY=ithTrend->second.GetMinTrigg();
0902 //           if(maxY<ithTrend->second.GetMaxTrigg()) maxY=ithTrend->second.GetMaxTrigg();          
0903 //         } else if (optionTrend == 7){
0904 //           if(minY>ithTrend->second.GetMinSBSignal()) minY=ithTrend->second.GetMinSBSignal();
0905 //           if(maxY<ithTrend->second.GetMaxSBSignal()) maxY=ithTrend->second.GetMaxSBSignal();          
0906 //         } else if (optionTrend == 8){
0907 //           if(minY>ithTrend->second.GetMinSBNoise()) minY=ithTrend->second.GetMinSBNoise();
0908 //           if(maxY<ithTrend->second.GetMaxSBNoise()) maxY=ithTrend->second.GetMaxSBNoise();          
0909 //         } else if (optionTrend == 9){
0910 //           if(minY>ithTrend->second.GetMinHGMPV()) minY=ithTrend->second.GetMinHGMPV();
0911 //           if(maxY<ithTrend->second.GetMaxHGMPV()) maxY=ithTrend->second.GetMaxHGMPV();          
0912 //         } else if (optionTrend == 10){
0913 //           if(minY>ithTrend->second.GetMinLGMPV()) minY=ithTrend->second.GetMinLGMPV();
0914 //           if(maxY<ithTrend->second.GetMaxLGMPV()) maxY=ithTrend->second.GetMaxLGMPV();          
0915 //         } else if (optionTrend == 11){
0916 //           if(minY>ithTrend->second.GetMinHGLSigma()) minY=ithTrend->second.GetMinHGLSigma();
0917 //           if(maxY<ithTrend->second.GetMaxHGLSigma()) maxY=ithTrend->second.GetMaxHGLSigma();          
0918 //         } else if (optionTrend == 12){
0919 //           if(minY>ithTrend->second.GetMinLGLSigma()) minY=ithTrend->second.GetMinLGLSigma();
0920 //           if(maxY<ithTrend->second.GetMaxLGLSigma()) maxY=ithTrend->second.GetMaxLGLSigma();          
0921 //         } else if (optionTrend == 13){
0922 //           if(minY>ithTrend->second.GetMinHGGSigma()) minY=ithTrend->second.GetMinHGGSigma();
0923 //           if(maxY<ithTrend->second.GetMaxHGGSigma()) maxY=ithTrend->second.GetMaxHGGSigma();          
0924 //         } else if (optionTrend == 14){
0925 //           if(minY>ithTrend->second.GetMinLGGSigma()) minY=ithTrend->second.GetMinLGGSigma();
0926 //           if(maxY<ithTrend->second.GetMaxLGGSigma()) maxY=ithTrend->second.GetMaxLGGSigma();          
0927 //         } else if (optionTrend == 15){
0928 //           if(minY>ithTrend->second.GetMinHGpedwidth()) minY=ithTrend->second.GetMinHGpedwidth();
0929 //           if(maxY<ithTrend->second.GetMaxHGpedwidth()) maxY=ithTrend->second.GetMaxHGpedwidth();          
0930 //         } else if (optionTrend == 16){
0931 //           if(minY>ithTrend->second.GetMinLGpedwidth()) minY=ithTrend->second.GetMinLGpedwidth();
0932 //           if(maxY<ithTrend->second.GetMaxLGpedwidth()) maxY=ithTrend->second.GetMaxLGpedwidth();          
0933 //         } else if (optionTrend == 17){
0934 //           if(minY>ithTrend->second.GetMinLGHGOffset()) minY=ithTrend->second.GetMinLGHGOffset();
0935 //           if(maxY<ithTrend->second.GetMaxLGHGOffset()) maxY=ithTrend->second.GetMaxLGHGOffset();          
0936 //         } else if (optionTrend == 18){
0937 //           if(minY>ithTrend->second.GetMinHGLGOffset()) minY=ithTrend->second.GetMinHGLGOffset();
0938 //           if(maxY<ithTrend->second.GetMaxHGLGOffset()) maxY=ithTrend->second.GetMaxHGLGOffset();          
0939 //         }
0940 //         for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
0941 //           if (r == 0 && c == 0){
0942 //             if (rc == 0){
0943 //               commanVoltage = ithTrend->second.GetVoltage(rc);
0944 //             } else {
0945 //               if (commanVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
0946 //             }
0947 //           }
0948 //         }
0949 //       }
0950 //     }
0951 //     if (minY == 9999 && maxY == 0.){
0952 //       std::cout <<"Something went wrong! No ranges set for layer " <<  layer << " \t trend plotting option: " << optionTrend << "\t ABORTING!" << std::endl;
0953 //       return;
0954 //     }
0955 //     // prep for log scale
0956 //     if (optionTrend == 6){ 
0957 //       if (minY ==0 ) minY = 1;
0958 //       else minY = minY/5.;
0959 //       maxY= maxY*5.;
0960 //     } else if (optionTrend == 17 || optionTrend == 18 ){ 
0961 //       minY = 1.1*minY;
0962 //       maxY = 2*maxY;      
0963 //     } else {
0964 //       minY = 0.9*minY;
0965 //       maxY = 1.1*maxY;      
0966 //     }
0967 //     for (int r = 0; r < nRow; r++){
0968 //       for (int c = 0; c < nCol; c++){
0969 //         
0970 //         canvas2Panel->cd();
0971 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0972 //         int p = setupT->GetChannelInLayer(tempCellID);
0973 // 
0974 //         TString label           = Form("row %d col %d", r, c);
0975 //         TString label2          = Form("Common V_{op} = %2.1f V", commanVoltage);
0976 //         if (p == 7){
0977 //           label = Form("row %d col %d layer %d", r, c, layer);
0978 //         }
0979 // 
0980 //         pads[p]->Draw();
0981 //         
0982 //         if (optionTrend == 6){ 
0983 //           pads[p]->SetLogy(1);
0984 //         } else {
0985 //           pads[p]->SetLogy(0);          
0986 //         }
0987 // 
0988 //         pads[p]->cd();
0989 //         ithTrend=trending.find(tempCellID);
0990 //         if(ithTrend==trending.end()){
0991 //           skipped++;
0992 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0993 //           pads[p]->Clear();
0994 //           pads[p]->Draw();
0995 //           if (p ==4 ){
0996 //             TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
0997 //             TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
0998 //             TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
0999 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-1*0.85*relSizeP[p], lab1, true, 0.85*textSizePixel, 43);
1000 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-2*0.85*relSizeP[p], lab2, true, 0.85*textSizePixel, 43);
1001 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-3*0.85*relSizeP[p], lab3, true, 0.85*textSizePixel, 43);
1002 //           }
1003 //           continue;
1004 //         } 
1005 //         TGraphErrors* tempGraph = nullptr;
1006 //         if (optionTrend == 0)       tempGraph = ithTrend->second.GetHGped();
1007 //         else if (optionTrend == 1)  tempGraph = ithTrend->second.GetLGped();
1008 //         else if (optionTrend == 2)  tempGraph = ithTrend->second.GetHGScale();            
1009 //         else if (optionTrend == 3)  tempGraph = ithTrend->second.GetLGScale();
1010 //         else if (optionTrend == 4)  tempGraph = ithTrend->second.GetLGHGcorr();
1011 //         else if (optionTrend == 5)  tempGraph = ithTrend->second.GetHGLGcorr();
1012 //         else if (optionTrend == 6)  tempGraph = ithTrend->second.GetTrigger();
1013 //         else if (optionTrend == 7)  tempGraph = ithTrend->second.GetSBSignal();
1014 //         else if (optionTrend == 8)  tempGraph = ithTrend->second.GetSBNoise();
1015 //         else if (optionTrend == 9)  tempGraph = ithTrend->second.GetHGLMPV();
1016 //         else if (optionTrend == 10) tempGraph = ithTrend->second.GetLGLMPV();
1017 //         else if (optionTrend == 11) tempGraph = ithTrend->second.GetHGLSigma();
1018 //         else if (optionTrend == 12) tempGraph = ithTrend->second.GetLGLSigma();
1019 //         else if (optionTrend == 13) tempGraph = ithTrend->second.GetHGGSigma();
1020 //         else if (optionTrend == 14) tempGraph = ithTrend->second.GetLGGSigma();
1021 //         else if (optionTrend == 15) tempGraph = ithTrend->second.GetHGpedwidth();
1022 //         else if (optionTrend == 16) tempGraph = ithTrend->second.GetLGpedwidth();
1023 //         else if (optionTrend == 17) tempGraph = ithTrend->second.GetLGHGOff();
1024 //         else if (optionTrend == 18) tempGraph = ithTrend->second.GetHGLGOff();
1025 //         if (!tempGraph) continue;
1026 //         TH1D* dummyhist = new TH1D("dummyhist", "", 100, xPMin, xPMax);
1027 //         SetStyleHistoTH1ForGraphs( dummyhist, tempGraph->GetXaxis()->GetTitle(), tempGraph->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
1028 //         // if (optionTrend == 6)std::cout << "\t" << tempGraph->GetXaxis()->GetTitle() << "\t" << tempGraph->GetYaxis()->GetTitle() << std::endl;
1029 //         SetMarkerDefaultsTGraphErr(tempGraph, 20, 1, kBlue+1, kBlue+1);   
1030 //         dummyhist->GetYaxis()->SetRangeUser(minY,maxY);
1031 //         dummyhist->Draw("axis");
1032 //         tempGraph->Draw("pe, same");
1033 //                 
1034 //         DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p], label, true, 0.85*textSizePixel, 43);
1035 //         if (isSameVoltage && p == 7){
1036 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-1*0.85*relSizeP[p], label2, true, 0.85*textSizePixel, 43);
1037 //         }
1038 //         if (p ==4 ){
1039 //           TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1040 //           TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1041 //           TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1042 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-1*0.85*relSizeP[p], lab1, true, 0.85*textSizePixel, 43);
1043 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-2*0.85*relSizeP[p], lab2, true, 0.85*textSizePixel, 43);
1044 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-3*0.85*relSizeP[p], lab3, true, 0.85*textSizePixel, 43);
1045 //         }
1046 //       }
1047 //     }
1048 //     if (skipped < 8){
1049 //       if(detailedPlot) canvas2Panel->SaveAs(nameOutput.Data());
1050 //       if (layer == 0) canvas2Panel->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1051 //       canvas2Panel->Print(Form("%s.pdf",nameOutputSummary.Data()));
1052 //       if (layer == setupT->GetNMaxLayer()) canvas2Panel->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1053 //     }
1054 //   }
1055 //   
1056 //   //__________________________________________________________________________________________________________
1057 //   // Plot Run overlay for all 8 tiles for all runs available
1058 //   //__________________________________________________________________________________________________________
1059   void PlotRunOverlay2MLayer (TCanvas* canvas2Panel, TPad* pads[2], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
1060                               std::map<int,TileTrend> trending, int nruns, int optionTrend, 
1061                               Double_t xPMin, Double_t xPMax, int layer, int mod,  TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t detailedPlot = 1){
1062                                   
1063     Setup* setupT = Setup::GetInstance();
1064     
1065     std::map<int, TileTrend>::iterator ithTrend;    
1066     int nCol = setupT->GetNMaxColumn()+1;
1067     int skipped = 0;
1068     
1069     Double_t maxY         = 0.;
1070     Double_t minY         = 9999.;
1071     bool isSameVoltage    = true;
1072     double commanVoltage  = 0;
1073     for (int c = 0; c < nCol; c++){
1074       int tempCellID = setupT->GetCellID(0,c, layer, mod);
1075       ithTrend=trending.find(tempCellID);
1076       if (optionTrend == 0){      // HG
1077         if(maxY<ithTrend->second.GetMaxHGSpec()) maxY=ithTrend->second.GetMaxHGSpec();
1078         if(minY>ithTrend->second.GetMinHGSpec()) minY=ithTrend->second.GetMinHGSpec();
1079       } else if (optionTrend == 1){   //LG
1080         if(maxY<ithTrend->second.GetMaxLGSpec()) maxY=ithTrend->second.GetMaxLGSpec();
1081         if(minY>ithTrend->second.GetMinLGSpec()) minY=ithTrend->second.GetMinLGSpec();
1082       } 
1083       
1084       for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1085         if (c == 0){
1086           if (rc == 0){
1087             commanVoltage = ithTrend->second.GetVoltage(rc);
1088           } else {
1089             if (commanVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
1090           }
1091         }
1092       }
1093     }
1094     if (maxY == 0 && minY == 9999.){
1095       std::cout <<"Something went wrong! No ranges set for layer " <<  layer << " \t trend plotting option: " << optionTrend << "\t ABORTING!" << std::endl;
1096       return;
1097     }
1098     maxY = 3*maxY;
1099     TH1D* histos[30];
1100 
1101     double lineBottom  = (1.4+6);
1102     if (nruns < 6) lineBottom = (1.4+1);
1103     else if (nruns < 11) lineBottom = (1.4+2);
1104     else if (nruns < 16) lineBottom = (1.4+3);
1105     else if (nruns < 21) lineBottom = (1.4+4);
1106     else if (nruns < 26) lineBottom = (1.4+5);
1107     TLegend* legend = nullptr;
1108   
1109     for (int c = 0; c < nCol; c++){
1110       canvas2Panel->cd();
1111       int tempCellID = setupT->GetCellID(0,c, layer, mod);
1112       pads[c]->Draw();
1113       pads[c]->cd();
1114       pads[c]->SetLogy(1);
1115       ithTrend=trending.find(tempCellID);
1116 
1117       TString label           = Form("col %d", c);
1118       TString label2          = Form("Common V_{op} = %2.1f V", commanVoltage);
1119       if ( c == 1 ){
1120         label = Form("col %d layer %d", c, layer);
1121       }
1122       if(ithTrend==trending.end()){
1123         skipped++;
1124         std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1125         pads[c]->Clear();
1126         pads[c]->Draw();
1127         if (c == 0 ){
1128           TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1129           TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1130           TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1131           DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c]-1*0.85*relSizeP[c], lab1, true, 0.85*textSizePixel, 43);
1132           DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c]-2*0.85*relSizeP[c], lab2, true, 0.85*textSizePixel, 43);
1133           DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c]-3*0.85*relSizeP[c], lab3, true, 0.85*textSizePixel, 43);
1134         }
1135         
1136         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c], label, true, 0.85*textSizePixel, 43);
1137         continue;
1138       } 
1139 
1140       if ( c == 1 ){
1141         double startLegY  = topRCornerY[c]-lineBottom*relSizeP[c];
1142         double endLegY    = topRCornerY[c]-1.4*relSizeP[c];
1143         legend = GetAndSetLegend2(  0.3, startLegY, topRCornerX[c]-0.045/2, endLegY,
1144                                     0.85*textSizePixel, 5, "",43,0.25);
1145       }
1146       
1147       for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1148         int tmpRunNr = ithTrend->second.GetRunNr(rc);
1149         histos[rc] = nullptr;
1150         if (tmpRunNr != -1) {
1151           if (optionTrend == 0){      // HG
1152             histos[rc] = ithTrend->second.GetHGTriggRun(ithTrend->second.GetRunNr(rc));
1153           } else if (optionTrend == 1){      // LG
1154             histos[rc] = ithTrend->second.GetLGTriggRun(ithTrend->second.GetRunNr(rc));
1155           }
1156         }
1157         if (histos[rc]){
1158           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);  
1159           SetLineDefaults(histos[rc], GetColorLayer(rc), 2, GetLineStyleLayer(rc));   
1160           if(rc == 0){
1161             histos[rc]->GetXaxis()->SetRangeUser(xPMin,xPMax);
1162             histos[rc]->GetYaxis()->SetRangeUser(minY,maxY);
1163             histos[rc]->Draw("hist");
1164           } else {
1165             histos[rc]->Draw("same,hist");
1166           }
1167           if(c == 1) legend->AddEntry(histos[rc],Form("%d",tmpRunNr),"l");
1168         }
1169       }
1170       if (histos[0]) histos[0]->Draw("axis,same");                
1171       
1172       // labeling inside the panels & legend drawing 
1173       DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c], label, true, 0.85*textSizePixel, 43);
1174       if (isSameVoltage && c == 1){
1175         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-(lineBottom+0.5)*relSizeP[c], label2, true, 0.85*textSizePixel, 43);
1176       }
1177       
1178       if (c == 1) legend->Draw();
1179       if (c == 0 ){
1180         TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1181         TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1182         TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1183         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c]-1*0.85*relSizeP[c], lab1, true, 0.85*textSizePixel, 43);
1184         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c]-2*0.85*relSizeP[c], lab2, true, 0.85*textSizePixel, 43);
1185         DrawLatex(topRCornerX[c]-0.045, topRCornerY[c]-1.2*relSizeP[c]-3*0.85*relSizeP[c], lab3, true, 0.85*textSizePixel, 43);
1186       }
1187     }
1188     if (skipped < 2){
1189       if(detailedPlot) canvas2Panel->SaveAs(nameOutput.Data());
1190       if (layer == 0) canvas2Panel->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1191       canvas2Panel->Print(Form("%s.pdf",nameOutputSummary.Data()));
1192       if (layer == setupT->GetNMaxLayer()) canvas2Panel->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1193     }
1194   }
1195 
1196   //__________________________________________________________________________________________________________
1197   // Plot Run overlay for all 8 tiles for all runs available
1198   //__________________________________________________________________________________________________________
1199   void PlotRunOverlayProfile2MLayer (TCanvas* canvas2Panel, TPad* pads[2], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
1200                                       std::map<int,TileTrend> trending, int nruns,
1201                                       Double_t xPMin, Double_t xPMax, Double_t yPMin, Double_t yPMax,  int layer, int mod,  TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t detailedPlot = 1){
1202                                   
1203     Setup* setupT = Setup::GetInstance();
1204     
1205     std::map<int, TileTrend>::iterator ithTrend;    
1206     int nRow = setupT->GetNMaxRow()+1;
1207     int nCol = setupT->GetNMaxColumn()+1;
1208     int skipped = 0;
1209     
1210     bool isSameVoltage    = true;
1211     double commanVoltage  = 0;
1212     for (int c = 0; c < nCol; c++){
1213       int tempCellID = setupT->GetCellID(0,c, layer, mod);
1214       ithTrend=trending.find(tempCellID);
1215       for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1216         if (c == 0){
1217           if (rc == 0){
1218             commanVoltage = ithTrend->second.GetVoltage(rc);
1219           } else {
1220             if (commanVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
1221           }
1222         }
1223       }
1224     }
1225     TProfile* profs[30];
1226 
1227     double lineBottom  = (1.4+6);
1228     if (nruns < 6) lineBottom = (1.4+1);
1229     else if (nruns < 11) lineBottom = (1.4+2);
1230     else if (nruns < 16) lineBottom = (1.4+3);
1231     else if (nruns < 21) lineBottom = (1.4+4);
1232     else if (nruns < 26) lineBottom = (1.4+5);
1233     TLegend* legend = nullptr;
1234     
1235     for (int c = 0; c < nCol; c++){
1236       canvas2Panel->cd();
1237       int tempCellID = setupT->GetCellID(0,c, layer, mod);
1238       pads[c]->Draw();
1239       pads[c]->cd();
1240       pads[c]->SetLogy(0);
1241       ithTrend=trending.find(tempCellID);
1242 
1243       TString label           = Form("col %d", c);
1244       TString label2          = Form("Common V_{op} = %2.1f V", commanVoltage);
1245       if (c == 1){
1246         label = Form(" col %d layer %d", c, layer);
1247       }
1248       
1249       // Double_t yPosStart = topRCornerY[c]-1.2*relSizeP[c];
1250       Double_t yPosStart = topRCornerY[c];
1251       if(ithTrend==trending.end()){
1252         skipped++;
1253         std::cout << "WARNING: skipping cell ID: " << tempCellID  << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1254         pads[c]->Clear();
1255         pads[c]->Draw();
1256         if (c == 0 ){
1257           TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1258           TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1259           TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1260           DrawLatex(topRCornerX[c]+0.045, yPosStart-1*0.85*relSizeP[c], lab1, false, 0.85*textSizePixel, 43);
1261           DrawLatex(topRCornerX[c]+0.045, yPosStart-2*0.85*relSizeP[c], lab2, false, 0.85*textSizePixel, 43);
1262           DrawLatex(topRCornerX[c]+0.045, yPosStart-3*0.85*relSizeP[c], lab3, false, 0.85*textSizePixel, 43);
1263         }
1264         
1265         DrawLatex(topRCornerX[c]+0.045, yPosStart, label, false, 0.85*textSizePixel, 43);
1266         continue;
1267       } 
1268 
1269       if (c == 1 ){
1270         double startLegY  = yPosStart+1.2*relSizeP[c] -lineBottom*relSizeP[c];
1271         double endLegY    = yPosStart+1.2*relSizeP[c] -1.4*relSizeP[c];
1272         legend = GetAndSetLegend2(  topRCornerX[c]+0.045/2, startLegY, 0.7, endLegY,
1273                                     0.85*textSizePixel, 5, "",43,0.25);
1274       }
1275       
1276       TH1D* dummyhist;
1277       for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1278         int tmpRunNr = ithTrend->second.GetRunNr(rc);
1279         profs[rc] = nullptr;
1280         if (tmpRunNr != -1) {
1281           profs[rc] = ithTrend->second.GetLGHGTriggRun(ithTrend->second.GetRunNr(rc));
1282           std::cout << profs[rc] << std::endl;
1283         }
1284         if (profs[rc]){
1285           if (rc == 0){
1286             dummyhist = new TH1D("dummyhist", "", profs[rc]->GetNbinsX(), profs[rc]->GetXaxis()->GetXmin(), profs[rc]->GetXaxis()->GetXmax());
1287             SetStyleHistoTH1ForGraphs( dummyhist, profs[rc]->GetXaxis()->GetTitle(), profs[rc]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
1288             dummyhist->GetXaxis()->SetRangeUser(xPMin,xPMax);
1289             dummyhist->GetYaxis()->SetRangeUser(yPMin,yPMax);
1290             dummyhist->Draw("axis");
1291           }
1292 
1293           SetLineDefaults(profs[rc], GetColorLayer(rc), 2, GetLineStyleLayer(rc));   
1294           profs[rc]->SetMarkerStyle(24);
1295           profs[rc]->Draw("same,pe");
1296           if(c == 1) legend->AddEntry(profs[rc],Form("%d",tmpRunNr),"p");
1297         }
1298       }
1299       if (dummyhist) dummyhist->Draw("axis,same");                
1300       
1301       // labeling inside the panels & legend drawing 
1302       DrawLatex(topRCornerX[c]+0.045, yPosStart, label, false, 0.85*textSizePixel, 43);
1303       if (isSameVoltage && c == 1){
1304         DrawLatex(topRCornerX[c]+0.045, yPosStart+1.2*relSizeP[c]-(lineBottom+0.5)*relSizeP[c], label2, false, 0.85*textSizePixel, 43);
1305       }
1306       
1307       if (c == 1 ) legend->Draw();
1308       if (c == 0 ){
1309         TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
1310         TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1311         TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1312         DrawLatex(topRCornerX[c]+0.045, yPosStart-1*0.85*relSizeP[c], lab1, false, 0.85*textSizePixel, 43);
1313         DrawLatex(topRCornerX[c]+0.045, yPosStart-2*0.85*relSizeP[c], lab2, false, 0.85*textSizePixel, 43);
1314         DrawLatex(topRCornerX[c]+0.045, yPosStart-3*0.85*relSizeP[c], lab3, false, 0.85*textSizePixel, 43);
1315       }
1316     }
1317     
1318     if (skipped < 2){
1319       if(detailedPlot) canvas2Panel->SaveAs(nameOutput.Data());
1320       if (layer == 0) canvas2Panel->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1321       canvas2Panel->Print(Form("%s.pdf",nameOutputSummary.Data()));
1322       if (layer == setupT->GetNMaxLayer()) canvas2Panel->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1323     }
1324   }
1325   
1326 #endif
1327