Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:15:49

0001 
0002 #ifndef TBPARSINGSIMPLE
0003 #define TBPARSINGSIMPLE
0004 
0005 
0006   //__________________________________________________________________________________________________________
0007   //__________________________________________________________________________________________________________
0008   //__________________________________________________________________________________________________________
0009   void SetBranchAddressesTree(TTree* inputTree){
0010       //**********************************
0011       //format
0012       //**********************************
0013 
0014       //     *Tree    :tree      :                                                        *
0015       //     ******************************************************************************
0016       //     *Br    0 :t_stamp   : t_stamp/D                                              *
0017       //     *Br    1 :trgid     : trgid/L                                                *
0018       //     *Br    2 :board     : board[64]/L                                            *
0019       //     *Br    3 :channel   : channel[64]/L                                          *
0020       //     *Br    4 :LG        : LG[64]/L                                               *
0021       //     *Br    5 :HG        : HG[64]/L                                               *
0022       //******************************************************************************
0023     
0024     
0025       if (inputTree->GetBranchStatus("t_stamp") ){
0026         inputTree->SetBranchAddress("trgid",          &gTrID);
0027         inputTree->SetBranchAddress("t_stamp",          &gTRtimeStamp);
0028         inputTree->SetBranchAddress("board",            gBoard);
0029         inputTree->SetBranchAddress("channel",                 gChannel);
0030         inputTree->SetBranchAddress("LG",               gLG);
0031         inputTree->SetBranchAddress("HG",               gHG);
0032       }
0033   }
0034 
0035   //__________________________________________________________________________________________________________
0036   //_________________________ Determine neighbors in layer
0037   //__________________________________________________________________________________________________________
0038   void GetNeighborWithinBoard(Int_t chBoard, Int_t &nNeighbors, Int_t* neighbors){
0039     nNeighbors = 0;
0040     // reset neighbors array
0041     for (Int_t i = 0; i < 5; i++) neighbors[i]= -1;
0042     if (chBoard == 1){
0043         neighbors[0] = 2;
0044         neighbors[1] = 8;
0045         neighbors[2] = 7;
0046     } else if (chBoard == 2){
0047         neighbors[0] = 1;
0048         neighbors[1] = 3;
0049         neighbors[2] = 7;
0050         neighbors[3] = 6;
0051         neighbors[4] = 8;
0052     } else if (chBoard == 3){
0053         neighbors[0] = 2;
0054         neighbors[1] = 4;
0055         neighbors[2] = 6;
0056         neighbors[3] = 5;
0057         neighbors[4] = 7;
0058     } else if (chBoard == 4){
0059         neighbors[0] = 3;
0060         neighbors[1] = 5;
0061         neighbors[2] = 6;
0062     } else if (chBoard == 5){
0063         neighbors[0] = 6;
0064         neighbors[1] = 4;
0065         neighbors[2] = 3;
0066     } else if (chBoard == 6){
0067         neighbors[0] = 7;
0068         neighbors[1] = 5;
0069         neighbors[2] = 3;
0070         neighbors[3] = 4;
0071         neighbors[4] = 2;
0072     } else if (chBoard == 7){
0073         neighbors[0] = 8;
0074         neighbors[1] = 6;
0075         neighbors[2] = 2;
0076         neighbors[3] = 3;
0077         neighbors[4] = 1;
0078     } else if (chBoard == 8){  
0079         neighbors[0] = 7;
0080         neighbors[1] = 1;
0081         neighbors[2] = 2;
0082     }
0083     for (Int_t i = 0; i < 5; i++){
0084       if (neighbors[i] != -1) nNeighbors++;
0085     }
0086     return;
0087   }
0088 
0089 
0090   //__________________________________________________________________________________________________________
0091   // find bin with largest content
0092   //__________________________________________________________________________________________________________
0093   Double_t FindLargestBin1DHist(TH1* hist, Double_t minX = -10000, Double_t maxX = -10000 ){
0094     Double_t largestContent     = 0;
0095     if (!hist){
0096         std::cout << "histogram pointer was empty, skipping!" << std::endl;
0097         return 0.;
0098     }
0099     Int_t minBin = 1;
0100     Int_t maxBin = hist->GetNbinsX()+1;
0101     if (minX != -10000) minBin = hist->GetXaxis()->FindBin(minX);
0102     if (maxX != -10000) maxBin = hist->GetXaxis()->FindBin(maxX)+0.0001;
0103     for (Int_t i= minBin; i < maxBin; i++){
0104         if (largestContent < hist->GetBinContent(i)){
0105             largestContent = hist->GetBinContent(i);
0106         }
0107     }
0108     return largestContent;
0109   }
0110   //__________________________________________________________________________________________________________
0111   // find bin with largest content
0112   //__________________________________________________________________________________________________________
0113   Double_t FindBinWithLargestBin1DHist(TH1* hist, Double_t minX = -10000, Double_t maxX = -10000 ){
0114     Double_t largestContent     = 0;
0115     Int_t minBin = 1;
0116     Int_t maxBin = hist->GetNbinsX()+1;
0117     if (minX != -10000) minBin = hist->GetXaxis()->FindBin(minX);
0118     if (maxX != -10000) maxBin = hist->GetXaxis()->FindBin(maxX)+0.0001;
0119     Int_t largestBin = minBin;
0120     for (Int_t i= minBin; i < maxBin; i++){
0121       if (largestContent < hist->GetBinContent(i)){
0122         largestContent = hist->GetBinContent(i);
0123         largestBin = i;
0124       }
0125     }
0126     return largestContent;
0127   }
0128 
0129   //__________________________________________________________________________________________________________
0130   // find bin with smallest content
0131   //__________________________________________________________________________________________________________
0132   Double_t FindSmallestBin1DHist(TH1* hist, Double_t maxStart = 1e6 ){
0133     Double_t smallesContent     = maxStart;
0134     for (Int_t i= 0; i < hist->GetNbinsX(); i++){
0135       if (hist->GetBinContent(i) != 0 && smallesContent > hist->GetBinContent(i)){
0136         smallesContent = hist->GetBinContent(i);
0137       }
0138     }
0139     return smallesContent;
0140   }
0141 
0142   //__________________________________________________________________________________________________________
0143   // Cleanup results graphs
0144   //  - removes entries from TGraphErrors if their entry & error is 0 (default) or another setable y value and error 0
0145   //__________________________________________________________________________________________________________
0146   void CleanUpResultsGraph(TGraphErrors* graph, TString nameUpdate,  Double_t yClean = 0 ){
0147     for (Int_t i= 0; i < graph->GetN(); i++){
0148       if (graph->GetY()[i] == yClean && graph->GetEY()[i] == 0){
0149         graph->RemovePoint(i);
0150         i--;
0151       }
0152     }
0153     graph->SetName(nameUpdate.Data());
0154   }
0155   
0156 
0157   //__________________________________________________________________________________________________________
0158   // Creates TGraphErrors from TH1 and cleans up unwanted values
0159   //  - creates graph
0160   //  - sets name
0161   //  - sets axis lables according to histo labels
0162   //  - removes entries from TGraphErrors if their entry & error is 0 (default) or another setable y value and error 0
0163   //__________________________________________________________________________________________________________
0164   TGraphErrors* CreateGraphFromHistAndCleanup(TH1* hist, TString nameUpdate,  Double_t yClean = 0, Bool_t cleanSThan = kFALSE ){
0165     TGraphErrors* graph = new TGraphErrors(hist);
0166     graph->SetName(nameUpdate.Data());
0167     graph->GetXaxis()->SetTitle(hist->GetXaxis()->GetTitle());
0168     graph->GetYaxis()->SetTitle(hist->GetYaxis()->GetTitle());
0169     for (Int_t i= 0; i < graph->GetN(); i++){
0170       if (cleanSThan){
0171         if (graph->GetY()[i] < yClean){
0172           graph->RemovePoint(i);
0173           i--;
0174         }
0175       } else {
0176         if (graph->GetY()[i] == yClean && graph->GetEY()[i] == 0){
0177           graph->RemovePoint(i);
0178           i--;
0179         }
0180       }
0181     }
0182     return graph;
0183   }
0184   
0185 
0186 
0187   //__________________________________________________________________________________________________________
0188   // Plot noise nicely
0189   //__________________________________________________________________________________________________________
0190   void PlotNoiseSingle (TCanvas* canvas, TH1D* histo, TF1* fit, 
0191                         Double_t mean, Double_t meanErr, Double_t sigma, Double_t sigmaErr, 
0192                         Int_t cb, Int_t cc, Int_t sl, Int_t sc, 
0193                         TString baseNameOut, runInfo currRunInfo,  Double_t textSizeRel = 0.04){
0194     canvas->cd();
0195       SetStyleHistoTH1ForGraphs(  histo,  histo->GetXaxis()->GetTitle(),  histo->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0196       SetMarkerDefaults( histo, 20, 0.8, kBlue+1,kBlue+1);
0197       SetStyleFit(fit , 0, 120, 7, 7, kBlack);
0198       histo->GetXaxis()->SetRangeUser(0,200);
0199       histo->Draw("pe");
0200       fit->Draw("same");
0201 
0202       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0203       
0204       TLegend* legend = GetAndSetLegend2( 0.58, 0.76-textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 1, Form("CAEN B %d, C %d, Stack L %d, C%d",cb, cc, sl, sc), 42,0.2);
0205       legend->AddEntry(fit, "Gauss noise fit", "l");
0206       legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",mean, meanErr ) , " ");
0207       legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",sigma, sigmaErr ) , " ");
0208       legend->Draw();
0209     canvas->SaveAs(Form("%s_B%d_C%02d.pdf", baseNameOut.Data(), cb,cc));
0210     return;
0211   }
0212 
0213   //__________________________________________________________________________________________________________
0214   // Plot noise nicely
0215   //__________________________________________________________________________________________________________
0216   void PlotMIPSingle (TCanvas* canvas, TH1D* histo, TF1* fit, 
0217                         double chi2, int ndf, double maxLG, double fwhm,
0218                         Int_t sl, Int_t sc, 
0219                         TString baseNameOut, runInfo currRunInfo, Double_t textSizeRel = 0.04){
0220     
0221     if (!histo || histo->GetEntries() == 0) return;
0222     canvas->cd();
0223     canvas->SetLogy(0);
0224       histo->GetYaxis()->SetRangeUser(0,FindLargestBin1DHist(histo,150,2200)*1.1);
0225       SetStyleHistoTH1ForGraphs(  histo,  histo->GetXaxis()->GetTitle(),  histo->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0226       SetMarkerDefaults( histo, 20, 0.2, kBlue+1,kBlue+1);
0227       SetStyleFit(fit , 0, 2200, 7, 7, kBlack);
0228       histo->GetXaxis()->SetRangeUser(0,2200);
0229       histo->Draw("hist,pe");
0230       fit->Draw("same");
0231       
0232       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0233       
0234       TLegend* legend = GetAndSetLegend2( 0.63, 0.69-textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 1, Form("Stack L %d, C%d",sl, sc), 42,0.12);
0235       legend->AddEntry(fit, "Landau-Gauss fit", "l");
0236       legend->AddEntry((TObject*)0, Form("#chi^{2}/ndf = %2.2f",(Double_t)(chi2/ndf) ) , " ");
0237       legend->AddEntry((TObject*)0, Form("MPV = %2.2f #pm %2.2f",(Double_t)(fit->GetParameter(1)), (Double_t)(fit->GetParError(1))  ) , " ");
0238       legend->AddEntry((TObject*)0, Form("Max = %2.2f",(Double_t)(maxLG) ) , " ");
0239       legend->AddEntry((TObject*)0, Form("FWHM = %2.2f",(Double_t)(fwhm) ) , " ");
0240       legend->Draw();
0241     canvas->SaveAs(Form("%s_L%d_C%02d.pdf", baseNameOut.Data(), sl,sc));
0242     
0243     canvas->SetLogy(1);
0244       histo->GetYaxis()->SetRangeUser(1,FindLargestBin1DHist(histo,150,2200)*3);
0245       histo->Draw("pe");
0246       fit->Draw("same");
0247       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0248       legend->Draw();
0249 
0250     canvas->SaveAs(Form("%s_L%d_C%02d_logY.pdf", baseNameOut.Data(), sl,sc));
0251     return;
0252   }
0253 
0254   //__________________________________________________________________________________________________________
0255   // Plot overlay of different triggers
0256   //__________________________________________________________________________________________________________
0257   void PlotOverlayDiffTriggers( TCanvas* canvas, TH1D* hAll, TH1D* hTriggC, TH1D* hTriggN, TF1* fitN,
0258                                 Double_t minPX, Double_t maxPX, TString baseNameOut,
0259                                 Int_t cb, Int_t cc, Int_t sl, Int_t sc, runInfo currRunInfo,
0260                                 Float_t textSizeRel = 0.04 ){
0261     if (!hAll || hAll->GetEntries() == 0) return;
0262     canvas->cd();
0263       SetStyleHistoTH1ForGraphs( hAll, hAll->GetXaxis()->GetTitle(), hAll->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0264       SetMarkerDefaults( hAll, 20, 0.8, kBlue+1,kBlue+1);
0265       
0266       hAll->GetXaxis()->SetRangeUser(minPX,maxPX);
0267       hAll->Draw("pe");
0268       if (hTriggN){
0269   //                   SetMarkerDefaults( hTriggN, 24, 0.8, kBlack,kBlack);
0270           SetLineDefaults( hTriggN,kBlack, 2, 1);
0271           hTriggN->Draw("hist,same");
0272       }
0273       if (hTriggC){
0274   //                   SetMarkerDefaults( hTriggC, 20, 0.8, kRed+1,kRed+1);
0275           SetLineDefaults( hTriggC,kRed+1, 3, 1);
0276           hTriggC->Draw("hist,same");
0277       }
0278       if (fitN){
0279         SetStyleFit(fitN, 0, 120, 7, 7, kGray+1);
0280         fitN->Draw("same");
0281         DrawLines(fitN->GetParameter(1),fitN->GetParameter(1), hAll->GetMinimum(), hAll->GetMaximum()*0.3, 3, kGray+2, 3, 1);
0282       }
0283       
0284       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0285       
0286       TLegend* legend = GetAndSetLegend2( 0.61, 0.75-textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 1, Form("CAEN B %d, C %d, Stack L %d, C%d",cb, cc, sl, sc), 42,0.2);
0287       legend->AddEntry(hAll, "All triggers", "p");
0288       if (hTriggC)legend->AddEntry(hTriggC, "Straight line trigg", "l");
0289       if (hTriggN)legend->AddEntry(hTriggN, "noise trigg", "l");
0290       if (fitN)legend->AddEntry(fitN, "noise fit", "l");
0291       legend->Draw();
0292     canvas->SaveAs(Form("%s_B%d_C%02d.pdf", baseNameOut.Data(), cb,cc));
0293     canvas->SaveAs(Form("%s_L%d_C%02d.pdf", baseNameOut.Data(), sl, sc));
0294     return;
0295   }
0296 
0297 //__________________________________________________________________________________________________________
0298   // Plot overlay of different triggers
0299   //__________________________________________________________________________________________________________
0300   void PlotOverlaySinglePhoton( TCanvas* canvas, TH1D* hAll, TH1D* hBGEstimate, TH1D* hSub, TF1* fitN,
0301                                 Double_t minPX, Double_t maxPX, TString baseNameOut,
0302                                 Int_t cb, Int_t cc, Int_t sl, Int_t sc, runInfo currRunInfo,
0303                                 Float_t textSizeRel = 0.04 ){
0304     if (!hAll || hAll->GetEntries() == 0) return;
0305     canvas->cd();
0306       SetStyleHistoTH1ForGraphs( hAll, hAll->GetXaxis()->GetTitle(), hAll->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0307       SetMarkerDefaults( hAll, 20, 0.8, kBlue+1,kBlue+1);
0308       
0309       hAll->GetXaxis()->SetRangeUser(minPX,maxPX);
0310       hAll->Draw("pe");
0311       if (hSub){
0312           SetLineDefaults( hSub,kRed+1, 4, 1);
0313           hSub->Draw("hist,same");
0314       }
0315       if (hBGEstimate){
0316           SetLineDefaults( hBGEstimate,kGray+1, 2, 1);
0317           hBGEstimate->Draw("hist,same");
0318       }
0319       if (fitN){
0320         SetStyleFit(fitN, 0, 4000, 7, 7, kGray+1);
0321         fitN->Draw("same");
0322       }
0323       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0324       
0325       TLegend* legend = GetAndSetLegend2( 0.61, 0.75-textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 1, Form("CAEN B %d, C %d, Stack L %d, C%d",cb, cc, sl, sc), 42,0.2);
0326       legend->AddEntry(hAll, "spectrum", "p");
0327       if (hBGEstimate)legend->AddEntry(hBGEstimate, "BG estimate", "l");
0328       if (hSub)legend->AddEntry(hSub, "sub. spectrum", "l");
0329       if (fitN)legend->AddEntry(fitN, "SPE fit", "l");
0330       legend->Draw();
0331     canvas->SaveAs(Form("%s_B%d_C%02d.pdf", baseNameOut.Data(), cb,cc));
0332     canvas->SaveAs(Form("%s_L%d_C%02d.pdf", baseNameOut.Data(), sl, sc));
0333     return;
0334   }
0335 
0336   
0337   
0338   //__________________________________________________________________________________________________________
0339   // Plot overlay of different channels within one readout board
0340   //__________________________________________________________________________________________________________
0341   void PlotChannelOverlaySameLayer( TCanvas* canvas, TH1D** histos, Int_t minC, Int_t maxC,
0342                                   Double_t minPX, Double_t maxPX, Double_t minPY,  TString baseNameOut,
0343                                   Int_t sl, runInfo currRunInfo,
0344                                   Float_t textSizeRel = 0.04, TString plotStyle = "p,e" ){
0345     canvas->cd();
0346       Int_t maxCount = 0;
0347       TLegend* legend = GetAndSetLegend2( 0.58, 0.93-4*textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 4, Form("Layer %d, channel:",sl), 42,0.2);
0348       for (Int_t c = minC; c < maxC; c++){
0349         if (!histos[c]) continue;
0350         if (maxCount < FindLargestBin1DHist(histos[c],minPX, maxPX)) maxCount = FindLargestBin1DHist(histos[c],minPX, maxPX);
0351       }
0352       for (Int_t c = minC; c < maxC; c++){
0353         if (!histos[c]) continue;
0354         SetStyleHistoTH1ForGraphs( histos[c], histos[c]->GetXaxis()->GetTitle(), histos[c]->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0355         SetMarkerDefaults( histos[c], markerReadBoard[c-1], 0.8, colorReadBoard[c-1],colorReadBoard[c-1]);
0356         if (plotStyle.Contains("hist")) histos[c]->SetLineWidth(3);
0357         histos[c]->GetXaxis()->SetRangeUser(minPX,maxPX);
0358         histos[c]->GetYaxis()->SetRangeUser(0.7*minPY,maxCount*1.1);      
0359         if (c == minC) histos[c]->Draw(plotStyle.Data());
0360         else histos[c]->Draw(Form("%s,same",plotStyle.Data()));
0361         if (c == maxC-1) histos[minC]->Draw("same,axis");
0362         if (plotStyle.Contains("p")) legend->AddEntry(histos[c], Form("%d",c), "p");
0363         else legend->AddEntry(histos[c], Form("%d",c), "l");
0364       }
0365       
0366       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0367 
0368       legend->Draw();
0369     canvas->SaveAs(Form("%s_L%d.pdf", baseNameOut.Data(), sl));
0370     return;
0371   }
0372 
0373   //__________________________________________________________________________________________________________
0374   // Plot overlay of different channels within one readout board with fitsBG
0375   //__________________________________________________________________________________________________________
0376   void PlotChannelOverlaySameLayerWithFitsBG( TCanvas* canvas, TH1D** histos, TF1** fits,  Int_t minC, Int_t maxC,
0377                                               Double_t minPX, Double_t maxPX, Double_t minPY,  TString baseNameOut,
0378                                               Int_t sl, runInfo currRunInfo,
0379                                               Float_t textSizeRel = 0.04, TString plotStyle = "p,e" ){
0380     canvas->cd();
0381       Int_t maxCount = 0;
0382       TLegend* legend = GetAndSetLegend2( 0.58, 0.93-4*textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 4, Form("Layer %d, channel:",sl), 42,0.2);
0383       TLegend* legendFits = GetAndSetLegend2( 0.58, 0.93-7*textSizeRel, 0.95, 0.93-4*textSizeRel,textSizeRel, 4, "Noise means", 42,0.2);
0384       for (Int_t c = minC; c < maxC; c++){
0385         if (!histos[c]) continue;
0386         if (maxCount < FindLargestBin1DHist(histos[c],minPX, maxPX)) maxCount = FindLargestBin1DHist(histos[c],minPX, maxPX);
0387       }
0388       for (Int_t c = minC; c < maxC; c++){
0389         if (!histos[c]) continue;
0390         SetStyleHistoTH1ForGraphs( histos[c], histos[c]->GetXaxis()->GetTitle(), histos[c]->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0391         SetMarkerDefaults( histos[c], markerReadBoard[c-1], 0.8, colorReadBoard[c-1],colorReadBoard[c-1]);
0392         if (plotStyle.Contains("hist")) histos[c]->SetLineWidth(3);
0393         histos[c]->GetXaxis()->SetRangeUser(minPX,maxPX);
0394         histos[c]->GetYaxis()->SetRangeUser(0.7*minPY,maxCount*1.1);      
0395         if (c == minC) histos[c]->Draw(plotStyle.Data());
0396         else histos[c]->Draw(Form("%s,same",plotStyle.Data()));
0397         
0398         if (fits && fits[c]){
0399           SetStyleFit(fits[c] , 0, 120, 7, 7, colorReadBoard[c-1]);
0400           fits[c]->Draw("same,l");
0401           legendFits->AddEntry(fits[c], Form("%0.1f",fits[c]->GetParameter(1)), "l");
0402         }
0403         
0404         if (c == maxC-1) histos[minC]->Draw("same,axis");
0405         if (plotStyle.Contains("p")) legend->AddEntry(histos[c], Form("%d",c), "p");
0406         else legend->AddEntry(histos[c], Form("%d",c), "l");
0407       }
0408       
0409       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0410 
0411       legend->Draw();
0412       legendFits->Draw();
0413     canvas->SaveAs(Form("%s_L%d.pdf", baseNameOut.Data(), sl));
0414     return;
0415   }  
0416   //__________________________________________________________________________________________________________
0417   // Plot overlay of different channels within one readout board
0418   //__________________________________________________________________________________________________________
0419   void PlotChannelOverlaySameReadoutChannel( TCanvas* canvas, TH1D* histos[gMaxLayers][9], Bool_t* bLayer, Int_t minL, Int_t maxL,
0420                                             Double_t minPX, Double_t maxPX, Double_t minPY,  TString baseNameOut,
0421                                             Int_t sc, runInfo currRunInfo,
0422                                             Float_t textSizeRel = 0.04, TString plotStyle = "p,e" ){
0423     canvas->cd();
0424       Int_t maxCount = 0;
0425       TLegend* legend = GetAndSetLegend2( 0.58, 0.93-4*textSizeRel, 0.95, 0.93-textSizeRel,textSizeRel, 4, Form("Read-out channel %d, layer:",sc), 42,0.2);
0426       for (Int_t l = minL; l < maxL; l++){
0427         if (!bLayer[l]) continue;
0428         if (!histos[l][sc]) continue;
0429         if (maxCount < FindLargestBin1DHist(histos[l][sc],minPX, maxPX)) maxCount = FindLargestBin1DHist(histos[l][sc],minPX, maxPX);
0430       }
0431       for (Int_t l = minL; l < maxL; l++){
0432         if (!bLayer[l]) continue;
0433         if (!histos[l][sc]) continue;
0434         SetStyleHistoTH1ForGraphs( histos[l][sc], histos[l][sc]->GetXaxis()->GetTitle(), histos[l][sc]->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0435         SetMarkerDefaults( histos[l][sc], markerLayer[l], 0.8, colorLayer[l],colorLayer[l]);
0436         if (plotStyle.Contains("hist")) histos[l][sc]->SetLineWidth(3);
0437         histos[l][sc]->GetXaxis()->SetRangeUser(minPX,maxPX);
0438         histos[l][sc]->GetYaxis()->SetRangeUser(0.7*minPY,maxCount*1.1);      
0439         if (l == minL) histos[l][sc]->Draw(plotStyle.Data());
0440         else histos[l][sc]->Draw(Form("%s,same",plotStyle.Data()));
0441         histos[minL][sc]->Draw("same,axis");
0442         if (plotStyle.Contains("p")) legend->AddEntry(histos[l][sc], Form("%d",l), "p");
0443         else legend->AddEntry(histos[l][sc], Form("%d",l), "l");
0444       }
0445       
0446       DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0447 
0448       legend->Draw();
0449     canvas->SaveAs(Form("%s_RB%d.pdf", baseNameOut.Data(), sc));
0450     return;
0451   }
0452 
0453   //__________________________________________________________________________________________________________
0454   // Plot Noise with Fits for Full layer
0455   //__________________________________________________________________________________________________________
0456   void PlotNoiseWithFitsFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0457                                   TH1D** hists, TF1** fits,
0458                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, Int_t layer, TString nameOutput, runInfo currRunInfo){
0459                                   
0460     Double_t maxY = 0;
0461     for (Int_t p = 0; p < 8; p++){
0462       if (maxY < FindLargestBin1DHist(hists[p+1], xPMin , xPMax)) maxY = FindLargestBin1DHist(hists[p+1], xPMin , xPMax);
0463     }
0464     
0465     for (Int_t p = 0; p < 8; p++){
0466       canvas8Panel->cd();
0467       pads[p]->Draw();
0468       pads[p]->cd();
0469       pads[p]->SetLogy();
0470       SetStyleHistoTH1ForGraphs( hists[p+1], hists[p+1]->GetXaxis()->GetTitle(), hists[p+1]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0471       SetMarkerDefaults(hists[p+1], 20, 1, kBlue+1, kBlue+1, kFALSE);   
0472       hists[p+1]->GetXaxis()->SetRangeUser(xPMin,xPMax);
0473       hists[p+1]->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0474       
0475       hists[p+1]->Draw("pe");
0476       
0477       TString label = Form("RB ch. %d", p+1);
0478       if (p == 4) label = Form("layer %d, RB ch. %d", layer, p+1);
0479       TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0480       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0481 
0482       if (fits){
0483         if (fits[p+1]){
0484           SetStyleFit(fits[p+1] , 0, 120, 7, 7, kBlack);
0485           fits[p+1]->Draw("same");
0486           TLegend* legend = GetAndSetLegend2( topRCornerX[p]-8*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.2);
0487           legend->AddEntry(fits[p+1], "Gauss noise fit", "l");
0488           legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fits[p+1]->GetParameter(1), fits[p+1]->GetParError(1) ) , " ");
0489           legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fits[p+1]->GetParameter(2), fits[p+1]->GetParError(2) ) , " ");
0490           legend->Draw();
0491 
0492         } else {
0493           labelChannel->Draw();
0494         }
0495       } else {
0496         labelChannel->Draw();
0497       }
0498       if (p ==4 ){
0499         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);
0500         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);
0501       }
0502     }
0503     canvas8Panel->SaveAs(nameOutput.Data());
0504   }
0505 
0506   //__________________________________________________________________________________________________________
0507   // Plot Noise with Fits for Full layer
0508   //__________________________________________________________________________________________________________
0509   void PlotDiffTriggersFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0510                                   TH1D** histsAll,  TH1D** hTriggC, TH1D** hTriggN, TF1** fits,
0511                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, Int_t layer, TString nameOutput, runInfo currRunInfo){
0512                                   
0513     Double_t maxY = 0;
0514     for (Int_t p = 0; p < 8; p++){
0515       if (!histsAll[p+1]) continue;
0516       if (maxY < FindLargestBin1DHist(histsAll[p+1], xPMin , xPMax)) maxY = FindLargestBin1DHist(histsAll[p+1], xPMin , xPMax);
0517     }
0518     
0519     for (Int_t p = 0; p < 8; p++){
0520       canvas8Panel->cd();
0521       pads[p]->Draw();
0522       pads[p]->cd();
0523       pads[p]->SetLogy();
0524       if (!histsAll[p+1]) continue;
0525       SetStyleHistoTH1ForGraphs( histsAll[p+1], histsAll[p+1]->GetXaxis()->GetTitle(), histsAll[p+1]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0526       SetMarkerDefaults(histsAll[p+1], 20, 1, kBlue+1, kBlue+1, kFALSE);
0527       histsAll[p+1]->GetXaxis()->SetRangeUser(xPMin,xPMax);
0528       histsAll[p+1]->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0529       histsAll[p+1]->Draw("pe");
0530       if (hTriggN){
0531         if (hTriggN[p+1]){
0532             SetLineDefaults( hTriggN[p+1],kBlack, 2, 1);
0533             hTriggN[p+1]->Draw("hist,same");
0534         }
0535       }
0536       if (hTriggC){
0537         if (hTriggC[p+1]){
0538           SetLineDefaults( hTriggC[p+1],kRed+1, 3, 1);
0539           hTriggC[p+1]->Draw("hist,same");
0540         }
0541       }
0542       if (fits){
0543         if (fits[p+1]){
0544           SetStyleFit(fits[p+1] , 0, 120, 7, 7, kGray+1);
0545           fits[p+1]->Draw("same");
0546         }
0547       } 
0548       if (p == 4){
0549         TLegend* legend = GetAndSetLegend2( topRCornerX[p]-8*relSize8P[p], topRCornerY[p]-5*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-1.6*relSize8P[p],0.85*textSizePixel, 1, "", 43,0.2);
0550         legend->AddEntry(histsAll[p+1], "All triggers", "p");
0551         if (hTriggC && hTriggC[p+1])legend->AddEntry(hTriggC[p+1], "Straight line trigg", "l");
0552         if (hTriggN && hTriggN[p+1])legend->AddEntry(hTriggN[p+1], "noise trigg", "l");
0553         if (fits){
0554           if (fits[p+1])legend->AddEntry(fits[p+1], "noise fit", "l");
0555         }
0556         legend->Draw();
0557       } else if (p == 3){
0558         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0559         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42); 
0560       }
0561       histsAll[p+1]->Draw("axis,same");
0562       
0563       TString label = Form("RB ch. %d", p+1);
0564       if (p == 4) label = Form("layer %d, RB ch. %d", layer, p+1);
0565       TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0566       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0567       labelChannel->Draw();
0568     }
0569     canvas8Panel->SaveAs(nameOutput.Data());
0570   }
0571 
0572   //__________________________________________________________________________________________________________
0573   // Plot data with fits for for Full layer
0574   //__________________________________________________________________________________________________________
0575   void PlotSPEFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0576                           TH1D** histsAll,  TH1D** hSub, TH1D** hBGEstimate, TF1** fits,
0577                           Double_t xPMin, Double_t xPMax, Double_t scaleYMax, Int_t layer, TString nameOutput, runInfo currRunInfo){
0578                                   
0579     Double_t maxY = 0;
0580     for (Int_t p = 0; p < 8; p++){
0581       if (maxY < FindLargestBin1DHist(histsAll[p+1], xPMin , xPMax)) maxY = FindLargestBin1DHist(histsAll[p+1], xPMin , xPMax);
0582     }
0583     
0584     for (Int_t p = 0; p < 8; p++){
0585       canvas8Panel->cd();
0586       pads[p]->Draw();
0587       pads[p]->cd();
0588       pads[p]->SetLogy();
0589       SetStyleHistoTH1ForGraphs( histsAll[p+1], histsAll[p+1]->GetXaxis()->GetTitle(), histsAll[p+1]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0590       SetMarkerDefaults(histsAll[p+1], 20, 1, kBlue+1, kBlue+1, kFALSE);
0591       histsAll[p+1]->GetXaxis()->SetRangeUser(xPMin,xPMax);
0592       histsAll[p+1]->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0593       histsAll[p+1]->Draw("pe");
0594       if (hBGEstimate){
0595         if (hBGEstimate[p+1]){
0596             SetLineDefaults( hBGEstimate[p+1],kGray+1, 2, 1);
0597             hBGEstimate[p+1]->Draw("hist,same");
0598         }
0599       }
0600       if (hSub){
0601         if (hSub[p+1]){
0602           SetLineDefaults( hSub[p+1],kRed+1, 3, 1);
0603           hSub[p+1]->Draw("hist,same");
0604         }
0605       }
0606       if (fits){
0607         if (fits[p+1]){
0608           SetStyleFit(fits[p+1] , 0, 2000, 7, 7, kGray+1);
0609           fits[p+1]->Draw("same");
0610         }
0611       } 
0612       if (p == 4){
0613         TLegend* legend = GetAndSetLegend2( topRCornerX[p]-8*relSize8P[p], topRCornerY[p]-5*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-1.6*relSize8P[p],0.85*textSizePixel, 1, "", 43,0.2);
0614         legend->AddEntry(histsAll[p+1], "All triggers", "p");
0615         if (hBGEstimate && hBGEstimate[p+1])legend->AddEntry(hBGEstimate[p+1], "BG estimate", "l");
0616         if (hSub && hSub[p+1])legend->AddEntry(hSub[p+1], "sub. spectrum", "l");
0617         if (fits){
0618           if (fits[p+1])legend->AddEntry(fits[p+1], "SPE fit", "l");
0619         }
0620         legend->Draw();
0621       } else if (p == 3){
0622         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0623         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42); 
0624       }
0625       histsAll[p+1]->Draw("axis,same");
0626       
0627       TString label = Form("RB ch. %d", p+1);
0628       if (p == 4) label = Form("layer %d, RB ch. %d", layer, p+1);
0629       TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0630       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0631       labelChannel->Draw();
0632     }
0633     canvas8Panel->SaveAs(nameOutput.Data());
0634   }
0635   
0636   
0637  //__________________________________________________________________________________________________________
0638   void PlotStraigtLineTriggAndFitFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0639                                             TH1D** hTriggC, TF1** fits, Double_t maxVals[9],
0640                                             Double_t xAMin, Double_t xAMax, Double_t xPMin, Double_t xPMax, Double_t scaleYMax, Int_t layer, TString nameOutput, runInfo currRunInfo){
0641                                   
0642     Double_t maxY = 0;
0643     for (Int_t p = 0; p < 8; p++){
0644       if (maxY < FindLargestBin1DHist(hTriggC[p+1], xAMin , xAMax)) maxY = FindLargestBin1DHist(hTriggC[p+1], xAMin , xAMax);
0645     }
0646     
0647     for (Int_t p = 0; p < 8; p++){
0648       canvas8Panel->cd();
0649       pads[p]->Draw();
0650       pads[p]->cd();
0651       pads[p]->SetLogy();
0652       SetStyleHistoTH1ForGraphs( hTriggC[p+1], hTriggC[p+1]->GetXaxis()->GetTitle(), hTriggC[p+1]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 505, 510, 43, 63);  
0653       SetMarkerDefaults(hTriggC[p+1], 20, 1, kBlue+1, kBlue+1, kFALSE);
0654       hTriggC[p+1]->GetXaxis()->SetRangeUser(xPMin,xPMax);
0655       hTriggC[p+1]->GetYaxis()->SetRangeUser(0.2,scaleYMax*maxY);
0656       hTriggC[p+1]->Draw("hist");
0657       
0658       if (fits){
0659         if (fits[p+1]){
0660           TBox* fitErrBox = CreateBox(kRed-8, fits[p+1]->GetParameter(1)-fits[p+1]->GetParError(1), 0.2, fits[p+1]->GetParameter(1)+fits[p+1]->GetParError(1), 0.7*scaleYMax*2, 1001 ) ;
0661           fitErrBox->Draw();
0662           hTriggC[p+1]->Draw("hist,same");
0663           DrawLines(fits[p+1]->GetParameter(1), fits[p+1]->GetParameter(1), 0.2, 0.7*scaleYMax*2, 3, kRed+2, 4,1);
0664           DrawLines(maxVals[p+1], maxVals[p+1], 0.2, 0.7*scaleYMax*4, 3, kGray+1, 4,1);
0665           SetStyleFit(fits[p+1] , xPMin, xPMax, 7, 7, kBlack);
0666           fits[p+1]->Draw("same");
0667         }
0668         
0669       } 
0670       
0671       if (p == 4){
0672         TLegend* legend = GetAndSetLegend2( topRCornerX[p]-9*relSize8P[p], topRCornerY[p]-5*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-1.6*relSize8P[p],0.85*textSizePixel, 1, "", 43,0.2);
0673         legend->AddEntry(hTriggC[p+1], "Straight line trigg", "p");
0674         if (fits){
0675           if (fits[p+1]){
0676             legend->AddEntry(fits[p+1], "Landau-Gauss fit", "l");
0677             TLine* dummyL = new TLine();
0678             dummyL->SetLineWidth(3);
0679             dummyL->SetLineColor(kRed+2);
0680             dummyL->SetLineStyle(4);
0681             TLine* dummyL2 = new TLine();
0682             dummyL2->SetLineWidth(3);
0683             dummyL2->SetLineColor(kGray+1);
0684             dummyL2->SetLineStyle(4);
0685             legend->AddEntry(dummyL, "MP Landau", "l");
0686             legend->AddEntry(dummyL2, "Max Landau-Gauss", "l");
0687 
0688           }
0689         }
0690         legend->Draw();
0691       } else if (p == 3){
0692         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0693         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42); 
0694       }
0695       hTriggC[p+1]->Draw("axis,same");
0696       
0697       TString label = Form("RB ch. %d", p+1);
0698       if (p == 4) label = Form("layer %d, RB ch. %d", layer, p+1);
0699       TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0700       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0701       labelChannel->Draw();
0702 
0703     }
0704     canvas8Panel->SaveAs(nameOutput.Data());
0705   }  
0706 
0707  //__________________________________________________________________________________________________________
0708   void PlotStraigtLineTriggAndFitFullLayerLin (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0709                                             TH1D** hTriggC, TF1** fits, Double_t maxVals[9],
0710                                             Double_t xAMin, Double_t xAMax, Double_t xPMin, Double_t xPMax, Double_t scaleYMax, Int_t layer, TString nameOutput, runInfo currRunInfo){
0711                                   
0712     Double_t maxY = 0;
0713     for (Int_t p = 0; p < 8; p++){
0714       if (maxY < FindLargestBin1DHist(hTriggC[p+1], xAMin , xAMax)) maxY = FindLargestBin1DHist(hTriggC[p+1], xAMin , xAMax);
0715     }
0716     
0717     for (Int_t p = 0; p < 8; p++){
0718       canvas8Panel->cd();
0719       pads[p]->Draw();
0720       pads[p]->cd();
0721       pads[p]->SetLogy(0);
0722       SetStyleHistoTH1ForGraphs( hTriggC[p+1], hTriggC[p+1]->GetXaxis()->GetTitle(), hTriggC[p+1]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 505, 510, 43, 63);  
0723       SetMarkerDefaults(hTriggC[p+1], 20, 1, kBlue+1, kBlue+1, kFALSE);
0724       hTriggC[p+1]->GetXaxis()->SetRangeUser(xPMin,xPMax);
0725       hTriggC[p+1]->GetYaxis()->SetRangeUser(0.,scaleYMax*maxY);
0726       hTriggC[p+1]->Draw("hist");
0727       
0728       if (fits){
0729         if (fits[p+1]){
0730           TBox* fitErrBox = CreateBox(kRed-8, fits[p+1]->GetParameter(1)-fits[p+1]->GetParError(1), 0., fits[p+1]->GetParameter(1)+fits[p+1]->GetParError(1), maxY/10., 1001 ) ;
0731           fitErrBox->Draw();
0732           hTriggC[p+1]->Draw("hist,same");
0733           DrawLines(fits[p+1]->GetParameter(1), fits[p+1]->GetParameter(1), 0., maxY/10., 3, kRed+2, 4,1);
0734           DrawLines(maxVals[p+1], maxVals[p+1], 0., maxY/10., 3, kGray+1, 4,1);
0735           SetStyleFit(fits[p+1] , xPMin, xPMax, 7, 7, kBlack);
0736           fits[p+1]->Draw("same");
0737         }
0738         
0739       } 
0740       
0741       if (p == 4){
0742         TLegend* legend = GetAndSetLegend2( topRCornerX[p]-9*relSize8P[p], topRCornerY[p]-5*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-1.6*relSize8P[p],0.85*textSizePixel, 1, "", 43,0.2);
0743         legend->AddEntry(hTriggC[p+1], "Straight line trigg", "p");
0744         if (fits){
0745           if (fits[p+1]){
0746             legend->AddEntry(fits[p+1], "Landau-Gauss fit", "l");
0747             TLine* dummyL = new TLine();
0748             dummyL->SetLineWidth(3);
0749             dummyL->SetLineColor(kRed+2);
0750             dummyL->SetLineStyle(4);
0751             TLine* dummyL2 = new TLine();
0752             dummyL2->SetLineWidth(3);
0753             dummyL2->SetLineColor(kGray+1);
0754             dummyL2->SetLineStyle(4);
0755           legend->AddEntry(dummyL, "MP Landau", "l");
0756           legend->AddEntry(dummyL2, "Max Landau-Gauss", "l");
0757           }
0758         }
0759         legend->Draw();
0760       } else if (p == 3){
0761         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0762         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42); 
0763       }
0764       hTriggC[p+1]->Draw("axis,same");
0765       
0766       TString label = Form("RB ch. %d", p+1);
0767       if (p == 4) label = Form("layer %d, RB ch. %d", layer, p+1);
0768       TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0769       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0770       labelChannel->Draw();
0771 
0772     }
0773     canvas8Panel->SaveAs(nameOutput.Data());
0774   }  
0775   
0776   //__________________________________________________________________________________________________________
0777   // Plot Noise with Fits for Full layer
0778   //__________________________________________________________________________________________________________
0779   void PlotOverlayFullLayer ( TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel, 
0780                               TH1D* hists[gMaxLayers][9], Bool_t* bLayer, Int_t minL, Int_t maxL,
0781                               Double_t xRMin, Double_t xRMax, Double_t xPMin, Double_t xPMax, Double_t scaleYMax, TString nameOutput, runInfo currRunInfo, TString plotStyle = "pe"){
0782                                   
0783     Double_t maxY = 0;
0784     Double_t minY = 1;
0785     for (Int_t l = 0; l < maxL; l++){
0786       if (!bLayer[l]) continue;
0787       for (Int_t p = 0; p < 8; p++){
0788         if (maxY < FindLargestBin1DHist(hists[l][p+1], xRMin , xRMax)) maxY = FindLargestBin1DHist(hists[l][p+1],xRMin, xRMax);
0789         if (minY > FindSmallestBin1DHist(hists[l][p+1])) minY = FindSmallestBin1DHist(hists[l][p+1]);
0790         
0791       }
0792     }
0793     
0794     TLegend* legend;
0795     for (Int_t p = 0; p < 8; p++){
0796       canvas8Panel->cd();
0797       pads[p]->Draw();
0798       pads[p]->cd();
0799       pads[p]->SetLogy();
0800       
0801       if (p == 4) legend = GetAndSetLegend2( 0.04, topRCornerY[p]-3*0.85*relSize8P[p]-0.6*relSize8P[p], 0.5, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 4, "layer", 43,0.3);
0802 
0803       for (Int_t l = minL; l < maxL; l++){
0804         if (!bLayer[l]) continue;
0805         SetStyleHistoTH1ForGraphs( hists[l][p+1], hists[l][p+1]->GetXaxis()->GetTitle(), hists[l][p+1]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 505, 510, 43, 63);  
0806         SetMarkerDefaults(hists[l][p+1], markerLayer[l], 0.8, colorLayer[l],colorLayer[l], kFALSE);
0807         if (plotStyle.Contains("hist")) hists[l][p+1]->SetLineWidth(2);
0808         hists[l][p+1]->GetXaxis()->SetRangeUser(xPMin,xPMax);
0809         hists[l][p+1]->GetYaxis()->SetRangeUser(0.7*minY,scaleYMax*maxY);
0810         if(l==minL)hists[l][p+1]->Draw(plotStyle.Data());
0811         else hists[l][p+1]->Draw(Form("%s,same",plotStyle.Data()));
0812         hists[minL][p+1]->Draw("same,axis");
0813         if (p == 4){
0814           if (plotStyle.Contains("p")) legend->AddEntry(hists[l][p+1], Form("%d",l), "p");
0815           else legend->AddEntry(hists[l][p+1], Form("%d",l), "l");
0816         }
0817       }
0818       if (p == 4) legend->Draw();
0819       else if (p == 3){
0820         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
0821         DrawLatex(topRCornerX[p]-0.04, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42); 
0822       }
0823       TString label = Form("RB ch. %d", p+1);
0824       TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
0825       SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0826       labelChannel->Draw();
0827     }
0828     canvas8Panel->SaveAs(nameOutput.Data());
0829   }
0830 
0831   //__________________________________________________________________________________________________________
0832   // Plot 2D fit variables overview
0833   //__________________________________________________________________________________________________________  
0834   void PlotSimpleMultiLayer2D( TCanvas* canvas2D, TH2* hist, Int_t maxl, Int_t maxCh, Float_t textSizeRel, TString nameOutput, runInfo currRunInfo, Bool_t hasNeg = kFALSE ){
0835       canvas2D->cd();
0836       SetStyleHistoTH2ForGraphs( hist, hist->GetXaxis()->GetTitle(), hist->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 0.9);  
0837       hist->GetYaxis()->SetRangeUser(-0.5,maxl+1.5);
0838       hist->GetXaxis()->SetRangeUser(0.5,maxCh+1.5);
0839       if (!hasNeg)
0840         hist->GetZaxis()->SetRangeUser(hist->GetMinimum(0),hist->GetMaximum());
0841       else 
0842         hist->GetZaxis()->SetRangeUser(hist->GetMinimum(),hist->GetMaximum());
0843       hist->Draw("colz,text");
0844       
0845       DrawLatex(0.85, 0.92, GetStringFromRunInfo(currRunInfo,1), true, textSizeRel, 42);
0846 
0847     canvas2D->SaveAs(nameOutput.Data());
0848   }
0849   
0850   //__________________________________________________________________________________________________________
0851   // Write histo if there's content
0852   //__________________________________________________________________________________________________________
0853   void WriteOnlyIfFilled(TH2* hist){
0854     if(hist){
0855       if (hist->GetEntries() > 0)
0856         hist->Write();
0857     }
0858     return;
0859   }
0860   //__________________________________________________________________________________________________________
0861   // Write histo if there's content
0862   //__________________________________________________________________________________________________________
0863   void WriteOnlyIfFilled(TH1* hist){
0864     if(hist){
0865       if (hist->GetEntries() > 0)
0866         hist->Write();
0867     }
0868     return;
0869   }
0870   
0871 #endif