File indexing completed on 2025-01-18 09:15:45
0001 #ifndef PLOTTHELPER_H
0002 #define PLOTTHELPER_H
0003
0004 #include "TLegend.h"
0005 #include "TAxis.h"
0006 #include "TColor.h"
0007 #include "TCanvas.h"
0008 #include "TLine.h"
0009 #include "TBox.h"
0010 #include "TPad.h"
0011 #include "TFrame.h"
0012 #include "TLatex.h"
0013 #include "TGraph.h"
0014 #include "TGraphErrors.h"
0015 #include "TGraphAsymmErrors.h"
0016 #include "TGaxis.h"
0017 #include "TSystem.h"
0018 #include "TStyle.h"
0019 #include "TileSpectra.h"
0020 #include "CommonHelperFunctions.h"
0021
0022
0023
0024 TString ReturnDateStr(){
0025 TDatime today;
0026 int iDate = today.GetDate();
0027 int iYear = iDate/10000;
0028 int iMonth = (iDate%10000)/100;
0029 int iDay = iDate%100;
0030 return Form("%i_%02d_%02d",iYear, iMonth, iDay);
0031 }
0032
0033
0034
0035
0036
0037 Double_t FindLargestBin1DHist(TH1* hist, Double_t minX = -10000, Double_t maxX = -10000 ){
0038 Double_t largestContent = 0;
0039 if (!hist){
0040 std::cout << "histogram pointer was empty, skipping!" << std::endl;
0041 return 0.;
0042 }
0043 Int_t minBin = 1;
0044 Int_t maxBin = hist->GetNbinsX()+1;
0045 if (minX != -10000) minBin = hist->GetXaxis()->FindBin(minX);
0046 if (maxX != -10000) maxBin = hist->GetXaxis()->FindBin(maxX)+0.0001;
0047 for (Int_t i= minBin; i < maxBin; i++){
0048 if (largestContent < hist->GetBinContent(i)){
0049 largestContent = hist->GetBinContent(i);
0050 }
0051 }
0052 return largestContent;
0053 }
0054
0055
0056
0057 Double_t FindSmallestBin1DHist(TH1* hist, Double_t maxStart = 1e6 ){
0058 Double_t smallesContent = maxStart;
0059 for (Int_t i= 0; i < hist->GetNbinsX(); i++){
0060 if (hist->GetBinContent(i) != 0 && smallesContent > hist->GetBinContent(i)){
0061 smallesContent = hist->GetBinContent(i);
0062 }
0063 }
0064 return smallesContent;
0065 }
0066
0067
0068
0069
0070 void StyleSettingsBasics( TString format = ""){
0071
0072 gStyle->SetOptDate(0);
0073 gStyle->SetOptStat(0);
0074 gStyle->SetPalette(1,0);
0075 gStyle->SetFrameBorderMode(0);
0076 gStyle->SetFrameFillColor(0);
0077 gStyle->SetTitleFillColor(0);
0078 gStyle->SetTextSize(0.5);
0079 gStyle->SetLabelSize(0.03,"xyz");
0080 gStyle->SetLabelOffset(0.006,"xyz");
0081 gStyle->SetTitleFontSize(0.04);
0082 gStyle->SetTitleOffset(1,"y");
0083 gStyle->SetTitleOffset(0.7,"x");
0084 gStyle->SetCanvasColor(0);
0085 gStyle->SetPadTickX(1);
0086 gStyle->SetPadTickY(1);
0087 gStyle->SetLineWidth(1);
0088 gStyle->SetPaintTextFormat(".3f");
0089
0090 gStyle->SetPadTopMargin(0.03);
0091 gStyle->SetPadBottomMargin(0.09);
0092 gStyle->SetPadRightMargin(0.03);
0093 gStyle->SetPadLeftMargin(0.13);
0094
0095
0096 TGaxis::SetMaxDigits(4);
0097 gErrorIgnoreLevel=kError;
0098
0099 if (format.CompareTo("eps") == 0 ||format.CompareTo("pdf") == 0 ) gStyle->SetLineScalePS(1);
0100 }
0101
0102
0103 void SetPlotStyle() {
0104
0105 const Int_t nRGBs = 5;
0106 const Int_t nCont = 255;
0107
0108 Double_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0109 Double_t red[nRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
0110 Double_t green[nRGBs] = { 0.31, 0.81, 1.00, 0.20, 0.00 };
0111 Double_t blue[nRGBs] = { 0.51, 1., 0.12, 0.00, 0.00};
0112
0113 TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, nCont);
0114 gStyle->SetNumberContours(nCont);
0115 }
0116
0117
0118 void SetPlotStyleNConts( Int_t nCont = 255) {
0119 const Int_t nRGBs = 5;
0120 Double_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0121 Double_t red[nRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
0122 Double_t green[nRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
0123 Double_t blue[nRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
0124 TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, nCont);
0125 gStyle->SetNumberContours(nCont);
0126 }
0127
0128
0129 void DrawCanvasSettings( TCanvas* c1,
0130 Double_t leftMargin,
0131 Double_t rightMargin,
0132 Double_t topMargin,
0133 Double_t bottomMargin){
0134
0135 c1->SetTickx();
0136 c1->SetTicky();
0137 c1->SetGridx(0);
0138 c1->SetGridy(0);
0139 c1->SetLogy(0);
0140 c1->SetLeftMargin(leftMargin);
0141 c1->SetRightMargin(rightMargin);
0142 c1->SetTopMargin(topMargin);
0143 c1->SetBottomMargin(bottomMargin);
0144 c1->SetFillColor(0);
0145 }
0146
0147
0148 TCanvas *GetAndSetCanvas( TString name,
0149 Double_t leftmargin = 0.11,
0150 Double_t bottommargin = 0.1,
0151 Double_t x = 1400,
0152 Double_t y = 1000){
0153
0154 TCanvas *canvas = new TCanvas(name,name,x,y);
0155 canvas->SetLeftMargin(leftmargin);
0156 canvas->SetRightMargin(0.015);
0157 canvas->SetTopMargin(0.03);
0158 canvas->SetBottomMargin(bottommargin);
0159 canvas->SetFillColor(0);
0160
0161 return canvas;
0162
0163 }
0164
0165
0166 TLegend *GetAndSetLegend( Double_t positionX,
0167 Double_t positionY,
0168 Double_t entries,
0169 Int_t Columns = 1,
0170 TString header =""){
0171
0172 if(header.CompareTo("") != 0) entries++;
0173 Double_t positionYPlus = 0.04*1.1*(Double_t)entries;
0174 TLegend *legend = new TLegend(positionX,positionY,positionX+(0.25*Columns),positionY+positionYPlus);
0175 legend->SetNColumns(Columns);
0176 legend->SetLineColor(0);
0177 legend->SetLineWidth(0);
0178 legend->SetFillColor(0);
0179 legend->SetFillStyle(0);
0180 legend->SetLineStyle(0);
0181 legend->SetTextSize(0.04);
0182 legend->SetTextFont(42);
0183 if(header.CompareTo("") != 0)legend->SetHeader(header);
0184 return legend;
0185 }
0186
0187
0188 TLegend *GetAndSetLegend2( Double_t positionX,
0189 Double_t positionY,
0190 Double_t positionXRight,
0191 Double_t positionYUp,
0192 Size_t textSize,
0193 Int_t columns = 1,
0194 TString header = "",
0195 Font_t textFont = 43,
0196 Double_t margin = 0
0197 ){
0198
0199 TLegend *legend = new TLegend(positionX,positionY,positionXRight,positionYUp);
0200 legend->SetNColumns(columns);
0201 legend->SetLineColor(0);
0202 legend->SetLineWidth(0);
0203 legend->SetFillColor(0);
0204 legend->SetFillStyle(0);
0205 legend->SetLineStyle(0);
0206 legend->SetBorderSize(0);
0207 legend->SetTextFont(textFont);
0208 legend->SetTextSize(textSize);
0209 if (margin != 0) legend->SetMargin(margin);
0210 if (header.CompareTo("")!= 0) legend->SetHeader(header);
0211 return legend;
0212 }
0213
0214
0215 void SetHistogramm( TH1 *hist,
0216 TString xLabel,
0217 TString yLabel,
0218 Double_t rangeYlow = -99.,
0219 Double_t rangeYhigh = -99.,
0220 Double_t xOffset = 1.0,
0221 Double_t yOffset = 1.15,
0222 Font_t font = 42
0223 ){
0224
0225 Double_t scale = 1./gPad->GetAbsHNDC();
0226
0227 if(rangeYlow != -99.) hist->GetYaxis()->SetRangeUser(rangeYlow,rangeYhigh);
0228 hist->SetTitle("");
0229 hist->SetXTitle(xLabel);
0230 hist->SetYTitle(yLabel);
0231 hist->GetYaxis()->SetDecimals();
0232 hist->GetYaxis()->SetTitleOffset(yOffset/scale);
0233 hist->GetXaxis()->SetTitleOffset(xOffset);
0234 hist->GetXaxis()->SetTitleSize(0.04*scale);
0235 hist->GetYaxis()->SetTitleSize(0.04*scale);
0236 hist->GetXaxis()->SetLabelSize(0.035*scale);
0237 hist->GetYaxis()->SetLabelSize(0.035*scale);
0238 hist->GetXaxis()->SetLabelFont(font);
0239 hist->GetYaxis()->SetLabelFont(font);
0240 hist->SetMarkerSize(1.);
0241 hist->SetMarkerStyle(20);
0242 }
0243
0244
0245 void SetGraph( TGraph *graph,
0246 TString xLabel,
0247 TString yLabel,
0248 Double_t rangeYlow = -99.,
0249 Double_t rangeYhigh = -99.,
0250 Double_t xOffset = 1.0,
0251 Double_t yOffset = 1.15){
0252
0253 Double_t scale = 1./gPad->GetAbsHNDC();
0254
0255 if(rangeYlow != -99.) graph->GetYaxis()->SetRangeUser(rangeYlow,rangeYhigh);
0256 graph->GetXaxis()->SetTitle(xLabel);
0257 graph->GetYaxis()->SetTitle(yLabel);
0258 graph->GetYaxis()->SetDecimals();
0259 graph->GetYaxis()->SetTitleOffset(yOffset/scale);
0260 graph->GetXaxis()->SetTitleOffset(xOffset);
0261 graph->GetXaxis()->SetTitleSize(0.04*scale);
0262 graph->GetYaxis()->SetTitleSize(0.04*scale);
0263 graph->GetXaxis()->SetLabelSize(0.035*scale);
0264 graph->GetYaxis()->SetLabelSize(0.035*scale);
0265 graph->GetXaxis()->SetLabelFont(42);
0266 graph->GetYaxis()->SetLabelFont(42);
0267 graph->SetMarkerSize(1.);
0268 graph->SetMarkerStyle(20);
0269 }
0270
0271
0272 void SetMarkerDefaults( TH1* histo1,
0273 Style_t markerStyle,
0274 Size_t markerSize,
0275 Color_t markerColor,
0276 Color_t lineColor,
0277 Bool_t setFont = kTRUE) {
0278 histo1->SetMarkerStyle(markerStyle);
0279 histo1->SetMarkerSize(markerSize);
0280 histo1->SetMarkerColor(markerColor);
0281 histo1->SetLineColor(lineColor);
0282 if (setFont){
0283 histo1->GetYaxis()->SetLabelFont(42);
0284 histo1->GetXaxis()->SetLabelFont(42);
0285 histo1->GetYaxis()->SetTitleFont(62);
0286 histo1->GetXaxis()->SetTitleFont(62);
0287 }
0288 }
0289
0290 void SetMarkerDefaults( TH1* histo1,
0291 TString xtitle = "",
0292 TString ytitle = "",
0293 Style_t markerStyle = 20,
0294 Size_t markerSize = 1,
0295 Color_t markerColor = kBlack,
0296 Color_t lineColor = kBlack,
0297 double textsize = 0.045,
0298 double labelsize = 0.045,
0299 double xoffset = 1.,
0300 double yoffset = 1. ) {
0301 histo1->SetTitle("");
0302 histo1->SetStats(0);
0303 histo1->SetMarkerStyle(markerStyle);
0304 histo1->SetMarkerSize(markerSize);
0305 histo1->SetMarkerColor(markerColor);
0306 histo1->SetLineColor(lineColor);
0307 histo1->GetYaxis()->SetLabelFont(42);
0308 histo1->GetXaxis()->SetLabelFont(42);
0309 histo1->GetYaxis()->SetLabelSize(labelsize);
0310 histo1->GetXaxis()->SetLabelSize(labelsize);
0311 histo1->GetYaxis()->SetTitleFont(62);
0312 histo1->GetXaxis()->SetTitleFont(62);
0313 histo1->GetYaxis()->SetTitleSize(textsize);
0314 histo1->GetXaxis()->SetTitleSize(textsize);
0315 if(!xtitle.EqualTo("")) histo1->GetXaxis()->SetTitle(xtitle);
0316 if(!ytitle.EqualTo("")) histo1->GetYaxis()->SetTitle(ytitle);
0317 histo1->GetXaxis()->SetTitleOffset(xoffset);
0318 histo1->GetYaxis()->SetTitleOffset(yoffset);
0319 }
0320
0321 void SetMarkerDefaultsProfile( TProfile* prof,
0322 Style_t markerStyle,
0323 Size_t markerSize,
0324 Color_t markerColor,
0325 Color_t lineColor ) {
0326 prof->SetMarkerStyle(markerStyle);
0327 prof->SetMarkerSize(markerSize);
0328 prof->SetMarkerColor(markerColor);
0329 prof->SetLineColor(lineColor);
0330 prof->GetYaxis()->SetLabelFont(42);
0331 prof->GetXaxis()->SetLabelFont(42);
0332 prof->GetYaxis()->SetTitleFont(62);
0333 prof->GetXaxis()->SetTitleFont(62);
0334 }
0335
0336
0337 void SetLineDefaults( TH1* histo1,
0338 Int_t LineColor,
0339 Int_t LineWidth,
0340 Int_t LineStyle ) {
0341 histo1->SetLineColor(LineColor);
0342 histo1->SetLineWidth(LineWidth);
0343 histo1->SetLineStyle(LineStyle);
0344 }
0345
0346
0347 void SetLineDefaultsTF1( TF1* Fit1,
0348 Int_t LineColor,
0349 Int_t LineWidth,
0350 Int_t LineStyle ) {
0351 Fit1->SetLineColor(LineColor);
0352 Fit1->SetLineWidth(LineWidth);
0353 Fit1->SetLineStyle(LineStyle);
0354 }
0355
0356
0357
0358 void DefaultCancasSettings( TCanvas* c1,
0359 Double_t leftMargin,
0360 Double_t rightMargin,
0361 Double_t topMargin,
0362 Double_t bottomMargin){
0363 c1->SetTickx();
0364 c1->SetTicky();
0365 c1->SetGridx(0);
0366 c1->SetGridy(0);
0367 c1->SetLogy(0);
0368 c1->SetLeftMargin(leftMargin);
0369 c1->SetRightMargin(rightMargin);
0370 c1->SetTopMargin(topMargin);
0371 c1->SetBottomMargin(bottomMargin);
0372 c1->SetFillColor(0);
0373 }
0374
0375
0376 void DefaultPadSettings( TPad* pad1,
0377 Double_t leftMargin,
0378 Double_t rightMargin,
0379 Double_t topMargin,
0380 Double_t bottomMargin){
0381 pad1->SetFillColor(0);
0382 pad1->GetFrame()->SetFillColor(0);
0383 pad1->SetBorderMode(0);
0384 pad1->SetLeftMargin(leftMargin);
0385 pad1->SetBottomMargin(bottomMargin);
0386 pad1->SetRightMargin(rightMargin);
0387 pad1->SetTopMargin(topMargin);
0388 pad1->SetTickx();
0389 pad1->SetTicky();
0390 }
0391
0392
0393 void SetMarkerDefaultsTGraph( TGraph* graph,
0394 Style_t markerStyle,
0395 Size_t markerSize,
0396 Color_t markerColor,
0397 Color_t lineColor,
0398 Width_t lineWidth = 1,
0399 Style_t lineStyle = 1,
0400 Bool_t boxes = kFALSE,
0401 Color_t fillColor = 0,
0402 Bool_t isHollow = kFALSE
0403 ) {
0404 graph->SetMarkerStyle(markerStyle);
0405 graph->SetMarkerSize(markerSize);
0406 graph->SetMarkerColor(markerColor);
0407 graph->SetLineColor(lineColor);
0408 graph->SetLineWidth(lineWidth);
0409 graph->SetLineWidth(lineStyle);
0410 if (boxes){
0411 graph->SetFillColor(fillColor);
0412 if (fillColor!=0){
0413 if (!isHollow){
0414 graph->SetFillStyle(1001);
0415 } else {
0416 graph->SetFillStyle(0);
0417 }
0418 } else {
0419 graph->SetFillStyle(0);
0420 }
0421 }
0422 }
0423
0424
0425 void SetMarkerDefaultsTGraphErr( TGraphErrors* graph,
0426 Style_t markerStyle,
0427 Size_t markerSize,
0428 Color_t markerColor,
0429 Color_t lineColor,
0430 Width_t lineWidth = 1,
0431 Bool_t boxes = kFALSE,
0432 Color_t fillColor = 0,
0433 Bool_t isHollow = kFALSE) {
0434 graph->SetMarkerStyle(markerStyle);
0435 graph->SetMarkerSize(markerSize);
0436 graph->SetMarkerColor(markerColor);
0437 graph->SetLineColor(lineColor);
0438 graph->SetLineWidth(lineWidth);
0439 if (boxes){
0440 graph->SetFillColor(fillColor);
0441 if (fillColor!=0){
0442 if (!isHollow){
0443 graph->SetFillStyle(1001);
0444 } else {
0445 graph->SetFillStyle(0);
0446 }
0447 } else {
0448 graph->SetFillStyle(0);
0449 }
0450 }
0451 }
0452
0453
0454 void SetMarkerDefaultsTGraphAsym( TGraphAsymmErrors* graph,
0455 Style_t markerStyle,
0456 Size_t markerSize,
0457 Color_t markerColor,
0458 Color_t lineColor,
0459 Width_t lineWidth =1,
0460 Bool_t boxes = kFALSE,
0461 Color_t fillColor = 0,
0462 Bool_t isHollow = kFALSE
0463 ) {
0464 if (!graph) return;
0465 graph->SetMarkerStyle(markerStyle);
0466 graph->SetMarkerSize(markerSize);
0467 graph->SetMarkerColor(markerColor);
0468 graph->SetLineColor(lineColor);
0469 graph->SetLineWidth(lineWidth);
0470 if (boxes){
0471 graph->SetFillColor(fillColor);
0472 if (fillColor!=0){
0473 if (!isHollow){
0474 graph->SetFillStyle(1001);
0475 } else {
0476 graph->SetFillStyle(0);
0477 }
0478 } else {
0479 graph->SetFillStyle(0);
0480 }
0481 }
0482 }
0483
0484
0485 void SetMarkerDefaultsTF1( TF1* fit1,
0486 Style_t lineStyle,
0487 Size_t lineWidth,
0488 Color_t lineColor ) {
0489 if (!fit1) return;
0490 fit1->SetLineColor(lineColor);
0491 fit1->SetLineStyle(lineStyle);
0492 fit1->SetLineWidth(lineWidth);
0493 }
0494
0495
0496 void SetStyleTLatex( TLatex* text,
0497 Size_t textSize,
0498 Width_t lineWidth,
0499 Color_t textColor = 1,
0500 Font_t textFont = 42,
0501 Bool_t kNDC = kTRUE,
0502 Short_t align = 11
0503 ){
0504 if (kNDC) {text->SetNDC();}
0505 text->SetTextFont(textFont);
0506 text->SetTextColor(textColor);
0507 text->SetTextSize(textSize);
0508 text->SetLineWidth(lineWidth);
0509 text->SetTextAlign(align);
0510 }
0511
0512
0513 void DrawLatex(const double PosX = 0.5, const double PosY = 0.5, TString text = "", const bool alignRight = false, const double TextSize = 0.044, const int font = 42, const double dDist = 0.05, const int color = 1){
0514
0515 std::vector<TString> Latex;
0516
0517 TObjArray *textStr = text.Tokenize(";");
0518 for(Int_t i = 0; i<textStr->GetEntries() ; i++){
0519 TObjString* tempObj = (TObjString*) textStr->At(i);
0520 Latex.push_back( tempObj->GetString());
0521 }
0522 for(unsigned int i = 0; i < Latex.size(); ++i){
0523 TLatex l(PosX, PosY - i*dDist, Latex[i]);
0524 l.SetNDC();
0525 l.SetTextFont(font);
0526 l.SetTextColor(color);
0527 l.SetTextSize(TextSize);
0528 if(alignRight) l.SetTextAlign(31);
0529 l.DrawClone("same");
0530 }
0531 }
0532
0533
0534 void SetStyleHisto( TH1* histo,
0535 Width_t lineWidth,
0536 Style_t lineStyle,
0537 Color_t lineColor) {
0538 if (!histo) return;
0539 histo->SetLineWidth(lineWidth);
0540 histo->SetLineStyle(lineStyle);
0541 histo->SetLineColor(lineColor);
0542 }
0543
0544
0545 void SetStyleFit( TF1* fit,
0546 Double_t xRangeStart,
0547 Double_t xRangeEnd,
0548 Width_t lineWidth,
0549 Style_t lineStyle,
0550 Color_t lineColor) {
0551 if (!fit) return;
0552 fit->SetRange(xRangeStart,xRangeEnd);
0553 fit->SetLineWidth(lineWidth);
0554 fit->SetLineStyle(lineStyle);
0555 fit->SetLineColor(lineColor);
0556 }
0557
0558
0559 void SetStyleHistoTH2ForGraphs( TH2* histo,
0560 TString XTitle,
0561 TString YTitle,
0562 Size_t xLableSize,
0563 Size_t xTitleSize,
0564 Size_t yLableSize,
0565 Size_t yTitleSize,
0566 Float_t xTitleOffset = 1,
0567 Float_t yTitleOffset = 1,
0568 Int_t xNDivisions = 510,
0569 Int_t yNDivisions = 510,
0570 Font_t textFontLabel = 42,
0571 Font_t textFontTitle = 62
0572 ){
0573 histo->SetXTitle(XTitle);
0574 histo->SetYTitle(YTitle);
0575 histo->SetTitle("");
0576 histo->SetStats(0);
0577
0578 histo->GetXaxis()->SetLabelFont(textFontLabel);
0579 histo->GetYaxis()->SetLabelFont(textFontLabel);
0580 histo->GetXaxis()->SetTitleFont(textFontTitle);
0581 histo->GetYaxis()->SetTitleFont(textFontTitle);
0582
0583 histo->GetXaxis()->SetLabelSize(xLableSize);
0584 histo->GetXaxis()->SetTitleSize(xTitleSize);
0585 histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0586 histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0587
0588 histo->GetYaxis()->SetDecimals();
0589 histo->GetYaxis()->SetLabelSize(yLableSize);
0590 histo->GetYaxis()->SetTitleSize(yTitleSize);
0591 histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0592 histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0593 }
0594
0595
0596 void SetStyleHistoTH1ForGraphs( TH1* histo,
0597 TString XTitle,
0598 TString YTitle,
0599 Size_t xLableSize,
0600 Size_t xTitleSize,
0601 Size_t yLableSize,
0602 Size_t yTitleSize,
0603 Float_t xTitleOffset = 1,
0604 Float_t yTitleOffset = 1,
0605 Int_t xNDivisions = 510,
0606 Int_t yNDivisions = 510,
0607 Font_t textFontLabel = 42,
0608 Font_t textFontTitle = 62
0609 ){
0610 histo->SetXTitle(XTitle);
0611 histo->SetYTitle(YTitle);
0612 histo->SetTitle("");
0613
0614 histo->GetYaxis()->SetLabelFont(textFontLabel);
0615 histo->GetXaxis()->SetLabelFont(textFontLabel);
0616 histo->GetYaxis()->SetTitleFont(textFontTitle);
0617 histo->GetXaxis()->SetTitleFont(textFontTitle);
0618
0619 histo->GetXaxis()->SetLabelSize(xLableSize);
0620 histo->GetXaxis()->SetTitleSize(xTitleSize);
0621 histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0622 histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0623
0624 histo->GetYaxis()->SetDecimals();
0625 histo->GetYaxis()->SetLabelSize(yLableSize);
0626 histo->GetYaxis()->SetTitleSize(yTitleSize);
0627 histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0628 histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0629 }
0630
0631
0632
0633 void SetStyleTProfile( TH1* histo,
0634 TString XTitle,
0635 TString YTitle,
0636 Size_t xLableSize,
0637 Size_t xTitleSize,
0638 Size_t yLableSize,
0639 Size_t yTitleSize,
0640 Float_t xTitleOffset = 1,
0641 Float_t yTitleOffset = 1,
0642 Int_t xNDivisions = 510,
0643 Int_t yNDivisions = 510,
0644 Font_t textFontLabel = 42,
0645 Font_t textFontTitle = 62
0646 ){
0647 histo->SetXTitle(XTitle);
0648 histo->SetYTitle(YTitle);
0649 histo->SetTitle("");
0650
0651 histo->GetYaxis()->SetLabelFont(textFontLabel);
0652 histo->GetXaxis()->SetLabelFont(textFontLabel);
0653 histo->GetYaxis()->SetTitleFont(textFontTitle);
0654 histo->GetXaxis()->SetTitleFont(textFontTitle);
0655
0656 histo->GetXaxis()->SetLabelSize(xLableSize);
0657 histo->GetXaxis()->SetTitleSize(xTitleSize);
0658 histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0659 histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0660
0661 histo->GetYaxis()->SetDecimals();
0662 histo->GetYaxis()->SetLabelSize(yLableSize);
0663 histo->GetYaxis()->SetTitleSize(yTitleSize);
0664 histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0665 histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0666 }
0667
0668
0669
0670
0671
0672
0673
0674
0675 void DrawLines(Float_t startX, Float_t endX,
0676 Float_t startY, Float_t endY,
0677 Float_t linew, Float_t lineColor = 4, Style_t lineStyle = 1, Float_t opacity = 1.){
0678 TLine * l1 = new TLine (startX,startY,endX,endY);
0679 l1->SetLineColor(lineColor);
0680 l1->SetLineWidth(linew);
0681 l1->SetLineStyle(lineStyle);
0682 if (opacity != 1.)
0683 l1->SetLineColorAlpha(lineColor,opacity);
0684
0685 l1->Draw("same");
0686 }
0687
0688
0689
0690
0691 TBox* CreateBox(Color_t colorBox, Double_t xStart, Double_t yStart, Double_t xEnd, Double_t yEnd, Style_t fillStyle = 1001 ) {
0692 TBox* box = new TBox(xStart ,yStart , xEnd, yEnd);
0693 box->SetLineColor(colorBox);
0694 box->SetFillColor(colorBox);
0695 box->SetFillStyle(fillStyle);
0696 return box;
0697 }
0698
0699
0700
0701
0702
0703
0704 TString GetStringFromRunInfo(RunInfo currRunInfo, Int_t option = 1){
0705 if (option == 1){
0706 if (currRunInfo.species.Contains("cosmics")){
0707 return Form("cosmics, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop );
0708 } else if (currRunInfo.species.CompareTo("g") == 0){
0709 return Form("LED, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop );
0710 } else {
0711 TString beam = currRunInfo.species.Data();
0712 if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0713 return Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV, Run %d, #it{V}_{#it{op}} = %1.1f V", beam.Data(), currRunInfo.energy, currRunInfo.runNr, currRunInfo.vop );
0714 }
0715 } else if (option == 2){
0716 if (currRunInfo.species.CompareTo("cosmics") == 0){
0717 return "cosmics";
0718 } else if (currRunInfo.species.CompareTo("g") == 0){
0719 return "LED";
0720 } else {
0721 TString beam = currRunInfo.species.Data();
0722 if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0723 return Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV", beam.Data(), currRunInfo.energy);
0724 }
0725 } else if (option == 3){
0726 return Form("Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop ) ;
0727 } else if (option == 4){
0728 if (currRunInfo.species.CompareTo("cosmics") == 0){
0729 return Form("cosmics, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0730 } else if (currRunInfo.species.CompareTo("g") == 0){
0731 return Form("LED, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0732 } else{
0733 TString beam = currRunInfo.species.Data();
0734 if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0735
0736 return Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", beam.Data(), currRunInfo.energy, currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0737 }
0738 } else if (option == 5){
0739 return Form("pedestal, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop ) ;
0740 }
0741
0742 return "";
0743 }
0744
0745
0746
0747
0748
0749
0750 void PlotSimple2D( TCanvas* canvas2D,
0751 TH2* hist, Int_t maxy, Int_t maxx,
0752 Float_t textSizeRel, TString nameOutput, RunInfo currRunInfo,
0753 int labelOpt = 1, Bool_t hasNeg = kFALSE, TString drwOpt ="colz",
0754 bool blegAbove = false, TString additionalLabel = ""
0755 ){
0756 canvas2D->cd();
0757 SetStyleHistoTH2ForGraphs( hist, hist->GetXaxis()->GetTitle(), hist->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 1.05);
0758 hist->GetZaxis()->SetLabelSize(0.85*textSizeRel);
0759 hist->GetZaxis()->SetTitleOffset(1.06);
0760 hist->GetZaxis()->SetTitleSize(textSizeRel);
0761
0762
0763 if (maxy > -10000)hist->GetYaxis()->SetRangeUser(-0.5,maxy+0.1);
0764 if (maxx > -10000)hist->GetXaxis()->SetRangeUser(0.5,maxx+0.1);
0765 if (!hasNeg)
0766 hist->GetZaxis()->SetRangeUser(hist->GetMinimum(0),hist->GetMaximum());
0767 else
0768 hist->GetZaxis()->SetRangeUser(hist->GetMinimum(),hist->GetMaximum());
0769
0770 if (((TString)hist->GetZaxis()->GetTitle()).Contains("counts")){
0771 gStyle->SetPaintTextFormat(".0f");
0772 std::cout << "entered counts case" << std::endl;
0773 } else {
0774 gStyle->SetPaintTextFormat(".3f");
0775 }
0776 hist->Draw(drwOpt.Data());
0777
0778 if (!blegAbove)
0779 DrawLatex(0.85, 0.92, GetStringFromRunInfo(currRunInfo,labelOpt), true, 0.85*textSizeRel, 42);
0780 else
0781 DrawLatex(0.92, 0.97, GetStringFromRunInfo(currRunInfo,labelOpt), true, 0.85*textSizeRel, 42);
0782
0783 if (additionalLabel.CompareTo("") != 0){
0784 if (!blegAbove)
0785 DrawLatex(0.11, 0.92, additionalLabel, false, 0.85*textSizeRel, 42);
0786 else
0787 DrawLatex(0.08, 0.97, additionalLabel, false, 0.85*textSizeRel, 42);
0788 }
0789 canvas2D->SaveAs(nameOutput.Data());
0790 }
0791
0792
0793
0794
0795
0796 void PlotSimple1D( TCanvas* canvas2D,
0797 TH1* hist, Int_t maxy, Int_t maxx,
0798 Float_t textSizeRel, TString nameOutput, RunInfo currRunInfo,
0799 int labelOpt = 1,
0800 TString additionalLabel = ""
0801 ){
0802 canvas2D->cd();
0803 SetStyleHistoTH1ForGraphs( hist, hist->GetXaxis()->GetTitle(), hist->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 1.05);
0804
0805 SetMarkerDefaults(hist, 20, 1, kBlue+1, kBlue+1, kFALSE);
0806
0807
0808 if (maxy > -10000)hist->GetYaxis()->SetRangeUser(-0.5,maxy+0.1);
0809 if (maxx > -10000)hist->GetXaxis()->SetRangeUser(0.5,maxx+0.1);
0810
0811 hist->Draw("p,e");
0812
0813 DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,labelOpt), true, 0.85*textSizeRel, 42);
0814 if (additionalLabel.CompareTo("") != 0){
0815 DrawLatex(0.95, 0.92-textSizeRel, additionalLabel, true, 0.85*textSizeRel, 42);
0816 }
0817 canvas2D->SaveAs(nameOutput.Data());
0818 }
0819
0820
0821
0822
0823 void PlotContamination1D( TCanvas* canvas2D,
0824 TH1* histAll, TH1* histMuon, TH1* histPrim, Int_t maxy, Int_t maxx,
0825 Float_t textSizeRel, TString nameOutput, RunInfo currRunInfo,
0826 int labelOpt = 1,
0827 TString additionalLabel = ""
0828 ){
0829 canvas2D->cd();
0830 SetStyleHistoTH1ForGraphs( histAll, histAll->GetXaxis()->GetTitle(), histAll->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 1.05);
0831
0832 SetMarkerDefaults(histAll, 20, 1, kBlue+1, kBlue+1, kFALSE);
0833
0834
0835 if (maxy > -10000)histAll->GetYaxis()->SetRangeUser(-0.5,maxy+0.1);
0836 if (maxx > -10000)histAll->GetXaxis()->SetRangeUser(0.5,maxx+0.1);
0837
0838 histAll->Draw("p,e");
0839 SetMarkerDefaults(histMuon, 25, 1, kGray+1, kGray+1, kFALSE);
0840 histMuon->Draw("p,e,same");
0841 SetMarkerDefaults(histPrim, 24, 1, kRed+1, kRed+1, kFALSE);
0842 histPrim->Draw("p,e,same");
0843
0844
0845 DrawLatex(0.95, 0.92, GetStringFromRunInfo(currRunInfo,labelOpt), true, 0.85*textSizeRel, 42);
0846 if (additionalLabel.CompareTo("") != 0){
0847 DrawLatex(0.95, 0.92-textSizeRel, additionalLabel, true, 0.85*textSizeRel, 42);
0848 }
0849
0850 TLegend* legend = GetAndSetLegend2( 0.11, 0.95-3*textSizeRel, 0.4, 0.95,0.85*textSizeRel, 1, "", 42,0.2);
0851 legend->AddEntry(histAll, "no evt. selection", "p");
0852 legend->AddEntry(histMuon, "muon events", "p");
0853 legend->AddEntry(histPrim, "remaining events", "p");
0854 legend->Draw();
0855
0856 canvas2D->SaveAs(nameOutput.Data());
0857 }
0858
0859
0860
0861
0862
0863 void PlotSimple2DZRange( TCanvas* canvas2D,
0864 TH2* hist, Int_t maxy, Int_t maxx, double minZ, double maxZ,
0865 Float_t textSizeRel, TString nameOutput, RunInfo currRunInfo,
0866 int labelOpt = 1, TString drwOpt ="colz",
0867 bool blegAbove = false, TString additionalLabel = ""
0868 ){
0869 canvas2D->cd();
0870 SetStyleHistoTH2ForGraphs( hist, hist->GetXaxis()->GetTitle(), hist->GetYaxis()->GetTitle(), 0.85*textSizeRel, textSizeRel, 0.85*textSizeRel, textSizeRel,0.9, 1.05);
0871 hist->GetZaxis()->SetLabelSize(0.85*textSizeRel);
0872 hist->GetZaxis()->SetTitleOffset(1.06);
0873 hist->GetZaxis()->SetTitleSize(textSizeRel);
0874
0875
0876 if (maxy > -10000)hist->GetYaxis()->SetRangeUser(-0.5,maxy+0.1);
0877 if (maxx > -10000)hist->GetXaxis()->SetRangeUser(0.5,maxx+0.1);
0878 hist->GetZaxis()->SetRangeUser(minZ,maxZ);
0879
0880 if (((TString)hist->GetZaxis()->GetTitle()).Contains("counts")){
0881 gStyle->SetPaintTextFormat(".0f");
0882 std::cout << "entered counts case" << std::endl;
0883 } else {
0884 gStyle->SetPaintTextFormat(".3f");
0885 }
0886 hist->Draw(drwOpt.Data());
0887
0888 if (!blegAbove)
0889 DrawLatex(0.85, 0.92, GetStringFromRunInfo(currRunInfo,labelOpt), true, 0.85*textSizeRel, 42);
0890 else
0891 DrawLatex(0.92, 0.97, GetStringFromRunInfo(currRunInfo,labelOpt), true, 0.85*textSizeRel, 42);
0892
0893 if (additionalLabel.CompareTo("") != 0){
0894 if (!blegAbove)
0895 DrawLatex(0.11, 0.92, additionalLabel, false, 0.85*textSizeRel, 42);
0896 else
0897 DrawLatex(0.08, 0.97, additionalLabel, false, 0.85*textSizeRel, 42);
0898 }
0899 canvas2D->SaveAs(nameOutput.Data());
0900 }
0901
0902
0903
0904 void ReturnCorrectValuesForCanvasScaling( Int_t sizeX,
0905 Int_t sizeY,
0906 Int_t nCols,
0907 Int_t nRows,
0908 Double_t leftMargin,
0909 Double_t rightMargin,
0910 Double_t upperMargin,
0911 Double_t lowerMargin,
0912 Double_t* arrayBoundariesX,
0913 Double_t* arrayBoundariesY,
0914 Double_t* relativeMarginsX,
0915 Double_t* relativeMarginsY,
0916 Bool_t verbose = kTRUE){
0917 Int_t realsizeX = sizeX- (Int_t)(sizeX*leftMargin)- (Int_t)(sizeX*rightMargin);
0918 Int_t realsizeY = sizeY- (Int_t)(sizeY*upperMargin)- (Int_t)(sizeY*lowerMargin);
0919
0920 Int_t nPixelsLeftColumn = (Int_t)(sizeX*leftMargin);
0921 Int_t nPixelsRightColumn = (Int_t)(sizeX*rightMargin);
0922 Int_t nPixelsUpperColumn = (Int_t)(sizeY*upperMargin);
0923 Int_t nPixelsLowerColumn = (Int_t)(sizeY*lowerMargin);
0924
0925 Int_t nPixelsSinglePlotX = (Int_t) (realsizeX/nCols);
0926 Int_t nPixelsSinglePlotY = (Int_t) (realsizeY/nRows);
0927 if(verbose){
0928 std::cout << realsizeX << "\t" << nPixelsSinglePlotX << std::endl;
0929 std::cout << realsizeY << "\t" << nPixelsSinglePlotY << std::endl;
0930 std::cout << nPixelsLeftColumn << "\t" << nPixelsRightColumn << "\t" << nPixelsLowerColumn << "\t" << nPixelsUpperColumn << std::endl;
0931 }
0932 Int_t pixel = 0;
0933 if(verbose)std::cout << "boundaries X" << std::endl;
0934 for (Int_t i = 0; i < nCols+1; i++){
0935 if (i == 0){
0936 arrayBoundariesX[i] = 0.;
0937 pixel = pixel+nPixelsLeftColumn+nPixelsSinglePlotX;
0938 } else if (i == nCols){
0939 arrayBoundariesX[i] = 1.;
0940 pixel = pixel+nPixelsRightColumn;
0941 } else {
0942 arrayBoundariesX[i] = (Double_t)pixel/sizeX;
0943 pixel = pixel+nPixelsSinglePlotX;
0944 }
0945 if(verbose)std::cout << "arrayBoundariesX: " << i << "\t" << arrayBoundariesX[i] << "\t" << pixel<<std::endl;
0946 }
0947
0948 if(verbose)std::cout << "boundaries Y" << std::endl;
0949 pixel = sizeY;
0950 for (Int_t i = 0; i < nRows+1; i++){
0951 if (i == 0){
0952 arrayBoundariesY[i] = 1.;
0953 pixel = pixel-nPixelsUpperColumn-nPixelsSinglePlotY;
0954 } else if (i == nRows){
0955 arrayBoundariesY[i] = 0.;
0956 pixel = pixel-nPixelsLowerColumn;
0957 } else {
0958 arrayBoundariesY[i] = (Double_t)pixel/sizeY;
0959 pixel = pixel-nPixelsSinglePlotY;
0960 }
0961 if(verbose)std::cout << i << "\t" << arrayBoundariesY[i] <<"\t" << pixel<<std::endl;
0962 }
0963
0964 relativeMarginsX[0] = (Double_t)nPixelsLeftColumn/(nPixelsLeftColumn+nPixelsSinglePlotX);
0965 relativeMarginsX[1] = 0;
0966 relativeMarginsX[2] = (Double_t)nPixelsRightColumn/(nPixelsRightColumn+nPixelsSinglePlotX);;
0967
0968 relativeMarginsY[0] = (Double_t)nPixelsUpperColumn/(nPixelsUpperColumn+nPixelsSinglePlotY);
0969 relativeMarginsY[1] = 0;
0970 relativeMarginsY[2] = (Double_t)nPixelsLowerColumn/(nPixelsLowerColumn+nPixelsSinglePlotY);;
0971
0972 return;
0973 }
0974
0975
0976 void ReturnCorrectValuesTextSize( TPad * pad,
0977 Double_t &textsizeLabels,
0978 Double_t &textsizeFac,
0979 Int_t textSizeLabelsPixel,
0980 Double_t dummyWUP){
0981 if(dummyWUP){}
0982
0983 textsizeLabels = 0;
0984 textsizeFac = 0;
0985 if (pad->XtoPixel(pad->GetX2()) < pad->YtoPixel(pad->GetY1())){
0986 textsizeLabels = (Double_t)textSizeLabelsPixel/pad->XtoPixel(pad->GetX2()) ;
0987 textsizeFac = (Double_t)1./pad->XtoPixel(pad->GetX2()) ;
0988 } else {
0989 textsizeLabels = (Double_t)textSizeLabelsPixel/pad->YtoPixel(pad->GetY1());
0990 textsizeFac = (Double_t)1./pad->YtoPixel(pad->GetY1());
0991 }
0992 std::cout << textsizeLabels << std::endl;
0993 std::cout << textsizeFac << std::endl;
0994
0995 return;
0996
0997 }
0998
0999
1000
1001
1002 void CreateCanvasAndPadsFor8PannelTBPlot(TCanvas* &canvas, TPad* pads[8], Double_t* topRCornerX, Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel = 30, Double_t marginLeft = 0.03, TString add = "", bool rightCorner = true){
1003 Double_t arrayBoundsXIndMeasRatio[5];
1004 Double_t arrayBoundsYIndMeasRatio[3];
1005 Double_t relativeMarginsIndMeasRatioX[3];
1006 Double_t relativeMarginsIndMeasRatioY[3];
1007 ReturnCorrectValuesForCanvasScaling(2200,1200, 4, 2,marginLeft, 0.005, 0.005,0.05,arrayBoundsXIndMeasRatio,arrayBoundsYIndMeasRatio,relativeMarginsIndMeasRatioX,relativeMarginsIndMeasRatioY);
1008
1009 canvas = new TCanvas(Form("canvas8Panel%s", add.Data()),"",0,0,2200,1200);
1010 canvas->cd();
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023 pads[0] = new TPad(Form("pad8Pane%sl_0", add.Data()), "", arrayBoundsXIndMeasRatio[0], arrayBoundsYIndMeasRatio[2], arrayBoundsXIndMeasRatio[1], arrayBoundsYIndMeasRatio[1],-1, -1, -2);
1024 pads[1] = new TPad(Form("pad8Pane%sl_1", add.Data()), "", arrayBoundsXIndMeasRatio[1], arrayBoundsYIndMeasRatio[2], arrayBoundsXIndMeasRatio[2], arrayBoundsYIndMeasRatio[1],-1, -1, -2);
1025 pads[2] = new TPad(Form("pad8Pane%sl_2", add.Data()), "", arrayBoundsXIndMeasRatio[2], arrayBoundsYIndMeasRatio[2], arrayBoundsXIndMeasRatio[3], arrayBoundsYIndMeasRatio[1],-1, -1, -2);
1026 pads[3] = new TPad(Form("pad8Pane%sl_3", add.Data()), "", arrayBoundsXIndMeasRatio[3], arrayBoundsYIndMeasRatio[2], arrayBoundsXIndMeasRatio[4], arrayBoundsYIndMeasRatio[1],-1, -1, -2);
1027 pads[4] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundsXIndMeasRatio[0], arrayBoundsYIndMeasRatio[1],arrayBoundsXIndMeasRatio[1], arrayBoundsYIndMeasRatio[0],-1, -1, -2);
1028 pads[5] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundsXIndMeasRatio[1], arrayBoundsYIndMeasRatio[1],arrayBoundsXIndMeasRatio[2], arrayBoundsYIndMeasRatio[0],-1, -1, -2);
1029 pads[6] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundsXIndMeasRatio[2], arrayBoundsYIndMeasRatio[1],arrayBoundsXIndMeasRatio[3], arrayBoundsYIndMeasRatio[0],-1, -1, -2);
1030 pads[7] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundsXIndMeasRatio[3], arrayBoundsYIndMeasRatio[1],arrayBoundsXIndMeasRatio[4], arrayBoundsYIndMeasRatio[0],-1, -1, -2);
1031
1032 DefaultPadSettings( pads[4], relativeMarginsIndMeasRatioX[0], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioY[0], relativeMarginsIndMeasRatioY[1]);
1033 DefaultPadSettings( pads[5], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioY[0], relativeMarginsIndMeasRatioY[1]);
1034 DefaultPadSettings( pads[6], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioY[0], relativeMarginsIndMeasRatioY[1]);
1035 DefaultPadSettings( pads[7], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioX[2], relativeMarginsIndMeasRatioY[0], relativeMarginsIndMeasRatioY[1]);
1036 DefaultPadSettings( pads[0], relativeMarginsIndMeasRatioX[0], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioY[1], relativeMarginsIndMeasRatioY[2]);
1037 DefaultPadSettings( pads[1], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioY[1], relativeMarginsIndMeasRatioY[2]);
1038 DefaultPadSettings( pads[2], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioY[1], relativeMarginsIndMeasRatioY[2]);
1039 DefaultPadSettings( pads[3], relativeMarginsIndMeasRatioX[1], relativeMarginsIndMeasRatioX[2], relativeMarginsIndMeasRatioY[1], relativeMarginsIndMeasRatioY[2]);
1040
1041 topRCornerY[0] = 1-relativeMarginsIndMeasRatioY[1];
1042 topRCornerY[1] = 1-relativeMarginsIndMeasRatioY[1];
1043 topRCornerY[2] = 1-relativeMarginsIndMeasRatioY[1];
1044 topRCornerY[3] = 1-relativeMarginsIndMeasRatioY[1];
1045 topRCornerY[4] = 1-relativeMarginsIndMeasRatioY[0];
1046 topRCornerY[5] = 1-relativeMarginsIndMeasRatioY[0];
1047 topRCornerY[6] = 1-relativeMarginsIndMeasRatioY[0];
1048 topRCornerY[7] = 1-relativeMarginsIndMeasRatioY[0];
1049 if (rightCorner){
1050 topRCornerX[0] = 1-relativeMarginsIndMeasRatioX[1];
1051 topRCornerX[1] = 1-relativeMarginsIndMeasRatioX[1];
1052 topRCornerX[2] = 1-relativeMarginsIndMeasRatioX[1];
1053 topRCornerX[3] = 1-relativeMarginsIndMeasRatioX[2];
1054 topRCornerX[4] = 1-relativeMarginsIndMeasRatioX[1];
1055 topRCornerX[5] = 1-relativeMarginsIndMeasRatioX[1];
1056 topRCornerX[6] = 1-relativeMarginsIndMeasRatioX[1];
1057 topRCornerX[7] = 1-relativeMarginsIndMeasRatioX[2];
1058 } else {
1059 topRCornerX[0] = relativeMarginsIndMeasRatioX[0];
1060 topRCornerX[1] = relativeMarginsIndMeasRatioX[1];
1061 topRCornerX[2] = relativeMarginsIndMeasRatioX[1];
1062 topRCornerX[3] = relativeMarginsIndMeasRatioX[1];
1063 topRCornerX[4] = relativeMarginsIndMeasRatioX[0];
1064 topRCornerX[5] = relativeMarginsIndMeasRatioX[1];
1065 topRCornerX[6] = relativeMarginsIndMeasRatioX[1];
1066 topRCornerX[7] = relativeMarginsIndMeasRatioX[0];
1067 }
1068
1069 for (Int_t p = 0; p < 8; p++){
1070 if (pads[p]->XtoPixel(pads[p]->GetX2()) < pads[p]->YtoPixel(pads[p]->GetY1())){
1071 relSize8P[p] = (Double_t)textSizePixel/pads[p]->XtoPixel(pads[p]->GetX2()) ;
1072 } else {
1073 relSize8P[p] = (Double_t)textSizePixel/pads[p]->YtoPixel(pads[p]->GetY1());
1074 }
1075 std::cout << p << "\t" << topRCornerX[p]<< "\t" << topRCornerY[p] << "\t" << relSize8P[p] << std::endl;
1076 }
1077 return;
1078 }
1079
1080
1081
1082
1083
1084 void PlotNoiseWithFitsFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX, Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel,
1085 std::map<int,TileSpectra> spectra, Setup* setupT, bool isHG,
1086 Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod, TString nameOutput, RunInfo currRunInfo){
1087
1088 Double_t maxY = 0;
1089 std::map<int, TileSpectra>::iterator ithSpectra;
1090
1091 int nRow = setupT->GetNMaxRow()+1;
1092 int nCol = setupT->GetNMaxColumn()+1;
1093 int skipped = 0;
1094 for (int r = 0; r < nRow; r++){
1095 for (int c = 0; c < nCol; c++){
1096 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1097 ithSpectra=spectra.find(tempCellID);
1098 if(ithSpectra==spectra.end()){
1099 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1100 skipped++;
1101 continue;
1102 }
1103 TH1D* tempHist = nullptr;
1104 if (isHG){
1105 tempHist = ithSpectra->second.GetHG();
1106 } else {
1107 tempHist = ithSpectra->second.GetLG();
1108 }
1109 if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
1110 }
1111 }
1112
1113 for (int r = 0; r < nRow; r++){
1114 for (int c = 0; c < nCol; c++){
1115 canvas8Panel->cd();
1116 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1117 int p = setupT->GetChannelInLayer(tempCellID);
1118 pads[p]->Draw();
1119 pads[p]->cd();
1120 pads[p]->SetLogy();
1121 ithSpectra=spectra.find(tempCellID);
1122 if(ithSpectra==spectra.end()){
1123 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1124 pads[p]->Clear();
1125 pads[p]->Draw();
1126 if (p ==7 ){
1127 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);
1128 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);
1129 }
1130 continue;
1131 }
1132 TH1D* tempHist = nullptr;
1133 if (isHG){
1134 tempHist = ithSpectra->second.GetHG();
1135 } else {
1136 tempHist = ithSpectra->second.GetLG();
1137 }
1138 SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);
1139 SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);
1140 tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
1141 tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
1142
1143 tempHist->Draw("pe");
1144 short bctemp = ithSpectra->second.GetCalib()->BadChannel;
1145 if (bctemp != -64 && bctemp < 3){
1146 Color_t boxCol = kGray;
1147 if (bctemp == 1)
1148 boxCol = kGray+1;
1149 else if (bctemp == 0)
1150 boxCol = kGray+2;
1151 TBox* badChannelArea = CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
1152 badChannelArea->Draw();
1153 tempHist->Draw("same,axis");
1154 tempHist->Draw("same,pe");
1155 }
1156
1157 TString label = Form("row %d col %d", r, c);
1158 if (p == 7){
1159 label = Form("row %d col %d layer %d", r, c, layer);
1160 }
1161 TLatex *labelChannel = new TLatex(topRCornerX[p]-0.04,topRCornerY[p]-1.2*relSize8P[p],label);
1162 SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
1163
1164
1165 TF1* fit = nullptr;
1166 if (isHG){
1167 fit = ithSpectra->second.GetBackModel(1);
1168 } else {
1169 fit = ithSpectra->second.GetBackModel(0);
1170 }
1171 if (fit){
1172 SetStyleFit(fit , xPMin, xPMax, 7, 7, kBlack);
1173 fit->Draw("same");
1174 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);
1175 legend->AddEntry(fit, "Gauss noise fit", "l");
1176 legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
1177 legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
1178 legend->Draw();
1179
1180 } else {
1181 labelChannel->Draw();
1182 }
1183
1184 if (p ==7 ){
1185 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);
1186 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);
1187 }
1188 }
1189 }
1190 if (skipped < 6)
1191 canvas8Panel->SaveAs(nameOutput.Data());
1192 }
1193
1194
1195
1196
1197
1198 void PlotNoiseAdvWithFitsFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX, Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel,
1199 std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, Setup* setupT, bool isHG,
1200 Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod, TString nameOutput, RunInfo currRunInfo){
1201
1202 Double_t maxY = 0;
1203 std::map<int, TileSpectra>::iterator ithSpectra;
1204 std::map<int, TileSpectra>::iterator ithSpectraTrigg;
1205
1206 int nRow = setupT->GetNMaxRow()+1;
1207 int nCol = setupT->GetNMaxColumn()+1;
1208 int skipped = 0;
1209 for (int r = 0; r < nRow; r++){
1210 for (int c = 0; c < nCol; c++){
1211 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1212 ithSpectra=spectra.find(tempCellID);
1213 if(ithSpectra==spectra.end()){
1214 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1215 continue;
1216 }
1217 TH1D* tempHist = nullptr;
1218 if (isHG){
1219 tempHist = ithSpectra->second.GetHG();
1220 } else {
1221 tempHist = ithSpectra->second.GetLG();
1222 }
1223 if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
1224 }
1225 }
1226 for (int r = 0; r < nRow; r++){
1227 for (int c = 0; c < nCol; c++){
1228 canvas8Panel->cd();
1229 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1230 int p = setupT->GetChannelInLayer(tempCellID);
1231 pads[p]->Draw();
1232 pads[p]->cd();
1233 pads[p]->SetLogy();
1234 ithSpectra=spectra.find(tempCellID);
1235 if(ithSpectra==spectra.end()){
1236 skipped++;
1237 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1238 pads[p]->Clear();
1239 pads[p]->Draw();
1240 if (p ==7 ){
1241 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1242 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1243 }
1244 continue;
1245 }
1246 ithSpectraTrigg=spectraTrigg.find(tempCellID);
1247 TH1D* tempHist = nullptr;
1248 if (isHG){
1249 tempHist = ithSpectra->second.GetHG();
1250 } else {
1251 tempHist = ithSpectra->second.GetLG();
1252 }
1253 SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);
1254 SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);
1255 tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
1256 tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
1257
1258 tempHist->Draw("pe");
1259 short bctemp = ithSpectra->second.GetCalib()->BadChannel;
1260 if (bctemp != -64 && bctemp < 3){
1261 Color_t boxCol = kGray;
1262 if (bctemp == 1)
1263 boxCol = kGray+1;
1264 else if (bctemp == 0)
1265 boxCol = kGray+2;
1266 TBox* badChannelArea = CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
1267 badChannelArea->Draw();
1268 tempHist->Draw("same,axis");
1269 tempHist->Draw("same,pe");
1270 }
1271
1272 TH1D* tempHistT = nullptr;
1273 if (isHG){
1274 tempHistT = ithSpectraTrigg->second.GetHG();
1275 } else {
1276 tempHistT = ithSpectraTrigg->second.GetLG();
1277 }
1278 SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);
1279 tempHistT->Draw("same,pe");
1280
1281 TString label = Form("row %d col %d", r, c);
1282 if (p == 7){
1283 label = Form("row %d col %d layer %d", r, c, layer);
1284 }
1285 TLatex *labelChannel = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
1286 SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
1287
1288
1289 TF1* fit = nullptr;
1290 bool isTrigFit = false;
1291 if (isHG){
1292 fit = ithSpectraTrigg->second.GetBackModel(1);
1293 if (!fit){
1294 fit = ithSpectra->second.GetBackModel(1);
1295
1296 } else {
1297 isTrigFit = true;
1298 }
1299 } else {
1300 fit = ithSpectraTrigg->second.GetBackModel(0);
1301 if (!fit){
1302 fit = ithSpectra->second.GetBackModel(0);
1303 } else {
1304 isTrigFit = true;
1305 }
1306 }
1307 if (fit){
1308 if (isTrigFit)
1309 SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
1310 else
1311 SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);
1312 fit->Draw("same");
1313 TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSize8P[p], topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
1314 if (isTrigFit)
1315 legend->AddEntry(fit, "Gauss noise fit, trigg.", "l");
1316 else
1317 legend->AddEntry(fit, "Gauss noise fit", "l");
1318 legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
1319 legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
1320 legend->Draw();
1321 } else {
1322 labelChannel->Draw();
1323 }
1324
1325 if (p ==7 ){
1326 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1327 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1328 }
1329 }
1330 }
1331 if (skipped < 6)
1332 canvas8Panel->SaveAs(nameOutput.Data());
1333 }
1334
1335
1336
1337
1338
1339 void PlotMipWithFitsFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX, Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel,
1340 std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, Setup* setupT, bool isHG,
1341 Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod, TString nameOutput, RunInfo currRunInfo){
1342
1343 Double_t maxY = 0;
1344 std::map<int, TileSpectra>::iterator ithSpectra;
1345 std::map<int, TileSpectra>::iterator ithSpectraTrigg;
1346
1347 int nRow = setupT->GetNMaxRow()+1;
1348 int nCol = setupT->GetNMaxColumn()+1;
1349 int skipped = 0;
1350 for (int r = 0; r < nRow; r++){
1351 for (int c = 0; c < nCol; c++){
1352 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1353 ithSpectra=spectra.find(tempCellID);
1354 if(ithSpectra==spectra.end()){
1355 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1356 continue;
1357 }
1358 TH1D* tempHist = nullptr;
1359 if (isHG){
1360 tempHist = ithSpectra->second.GetHG();
1361 } else {
1362 tempHist = ithSpectra->second.GetLG();
1363 }
1364 if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
1365 }
1366 }
1367
1368 for (int r = 0; r < nRow; r++){
1369 for (int c = 0; c < nCol; c++){
1370 canvas8Panel->cd();
1371 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1372 int p = setupT->GetChannelInLayer(tempCellID);
1373 pads[p]->Draw();
1374 pads[p]->cd();
1375 pads[p]->SetLogy();
1376 ithSpectra=spectra.find(tempCellID);
1377 if(ithSpectra==spectra.end()){
1378 skipped++;
1379 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1380 pads[p]->Clear();
1381 pads[p]->Draw();
1382 if (p ==7 ){
1383 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1384 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1385 }
1386 continue;
1387 }
1388 ithSpectraTrigg=spectraTrigg.find(tempCellID);
1389 TH1D* tempHist = nullptr;
1390 double noiseWidth = 0;
1391 if (isHG){
1392 tempHist = ithSpectra->second.GetHG();
1393 noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
1394 } else {
1395 tempHist = ithSpectra->second.GetLG();
1396 noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
1397 }
1398 SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);
1399 SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);
1400 tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
1401 tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
1402
1403 tempHist->Draw("pe");
1404 short bctemp = ithSpectra->second.GetCalib()->BadChannel;
1405 if (bctemp != -64 && bctemp < 3){
1406 Color_t boxCol = kGray;
1407 if (bctemp == 1)
1408 boxCol = kGray+1;
1409 else if (bctemp == 0)
1410 boxCol = kGray+2;
1411 TBox* badChannelArea = CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
1412 badChannelArea->Draw();
1413 tempHist->Draw("same,axis");
1414 tempHist->Draw("same,pe");
1415 }
1416
1417 TH1D* tempHistT = nullptr;
1418
1419 if (isHG){
1420 tempHistT = ithSpectraTrigg->second.GetHG();
1421 } else {
1422 tempHistT = ithSpectraTrigg->second.GetLG();
1423 }
1424 SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);
1425 tempHistT->Draw("same,pe");
1426
1427 TString label = Form("row %d col %d", r, c);
1428 if (p == 7){
1429 label = Form("row %d col %d layer %d", r, c, layer);
1430 }
1431 TLatex *labelChannel = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
1432 SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
1433
1434
1435 TF1* fit = nullptr;
1436 bool isTrigFit = false;
1437 double maxFit = 0;
1438 if (isHG){
1439 fit = ithSpectraTrigg->second.GetSignalModel(1);
1440 if (!fit){
1441 fit = ithSpectra->second.GetSignalModel(1);
1442 if (fit){
1443 maxFit = ithSpectra->second.GetCalib()->ScaleH;
1444 }
1445 } else {
1446 isTrigFit = true;
1447 maxFit = ithSpectraTrigg->second.GetCalib()->ScaleH;
1448 }
1449 } else {
1450 fit = ithSpectraTrigg->second.GetSignalModel(0);
1451 if (!fit){
1452 fit = ithSpectra->second.GetSignalModel(0);
1453 if (fit){
1454 maxFit = ithSpectra->second.GetCalib()->ScaleL;
1455 }
1456 } else {
1457 isTrigFit = true;
1458 maxFit = ithSpectraTrigg->second.GetCalib()->ScaleL;
1459 }
1460 }
1461 if (fit){
1462 if (isTrigFit)
1463 SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
1464 else
1465 SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);
1466 fit->Draw("same");
1467 TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSize8P[p], topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
1468 if (isTrigFit)
1469 legend->AddEntry(fit, "Landau-Gauss fit, trigg.", "l");
1470 else
1471 legend->AddEntry(fit, "Landau-Gauss fit", "l");
1472 legend->AddEntry((TObject*)0, Form("#scale[0.8]{L MPV = %2.2f #pm %2.2f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
1473 legend->AddEntry((TObject*)0, Form("#scale[0.8]{Max = %2.2f}", maxFit ) , " ");
1474 legend->Draw();
1475 DrawLines(maxFit, maxFit,0.7, scaleYMax*maxY/10, 5, kRed+3, 7);
1476 } else {
1477 labelChannel->Draw();
1478 }
1479
1480 DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);
1481 DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);
1482
1483 if (p ==7 ){
1484 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1485 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1486 }
1487 }
1488 }
1489 if (skipped < 6)
1490 canvas8Panel->SaveAs(nameOutput.Data());
1491 }
1492
1493
1494
1495
1496
1497 void PlotCorrWithFitsFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX, Double_t* topRCornerY, Double_t* relSize8P, Int_t textSizePixel,
1498 std::map<int,TileSpectra> spectra, Setup* setupT, bool isHG,
1499 Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod, TString nameOutput, RunInfo currRunInfo){
1500
1501 Double_t maxY = 3900;
1502 if (isHG) maxY = 340;
1503 std::map<int, TileSpectra>::iterator ithSpectra;
1504 int nRow = setupT->GetNMaxRow()+1;
1505 int nCol = setupT->GetNMaxColumn()+1;
1506 int skipped = 0;
1507
1508 for (int r = 0; r < nRow; r++){
1509 for (int c = 0; c < nCol; c++){
1510 canvas8Panel->cd();
1511 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1512 int p = setupT->GetChannelInLayer(tempCellID);
1513 pads[p]->Draw();
1514 pads[p]->SetLogy(0);
1515 pads[p]->cd();
1516
1517 ithSpectra=spectra.find(tempCellID);
1518 if(ithSpectra==spectra.end()){
1519 skipped++;
1520 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1521 pads[p]->Clear();
1522 pads[p]->Draw();
1523 if (p ==7 ){
1524 DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSize8P[p], 42);
1525 DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSize8P[p], 42);
1526 }
1527 continue;
1528 }
1529 TProfile* tempProfile = nullptr;
1530 if (isHG){
1531 tempProfile = ithSpectra->second.GetHGLGcorr();
1532 } else {
1533 tempProfile = ithSpectra->second.GetLGHGcorr();
1534 }
1535 if (!tempProfile) continue;
1536 TH1D* dummyhist = new TH1D("dummyhist", "", tempProfile->GetNbinsX(), tempProfile->GetXaxis()->GetXmin(), tempProfile->GetXaxis()->GetXmax());
1537 SetStyleHistoTH1ForGraphs( dummyhist, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);
1538
1539
1540
1541 SetMarkerDefaultsProfile(tempProfile, 20, 1, kBlue+1, kBlue+1);
1542 Int_t maxX = 3900;
1543 if (!isHG)
1544 maxX = 340;
1545 dummyhist->GetXaxis()->SetRangeUser(0,maxX);
1546 dummyhist->GetYaxis()->SetRangeUser(0,maxY);
1547 dummyhist->Draw("axis");
1548
1549 short bctemp = ithSpectra->second.GetCalib()->BadChannel;
1550 if (bctemp != -64 && bctemp < 3){
1551 Color_t boxCol = kGray;
1552 if (bctemp == 1)
1553 boxCol = kGray+1;
1554 else if (bctemp == 0)
1555 boxCol = kGray+2;
1556 TBox* badChannelArea = CreateBox(boxCol, 0, 0, maxX,maxY, 1001 );
1557 badChannelArea->Draw();
1558 dummyhist->Draw("axis,same");
1559 }
1560
1561 tempProfile->Draw("pe, same");
1562
1563 TString label = Form("row %d col %d", r, c);
1564 if (p == 7){
1565 label = Form("row %d col %d layer %d", r, c, layer);
1566 }
1567 TLatex *labelChannel = new TLatex(topRCornerX[p]+0.045,topRCornerY[p]-1.2*relSize8P[p],label);
1568 SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,11);
1569
1570
1571 TF1* fit = nullptr;
1572 if (isHG){
1573 fit = ithSpectra->second.GetCorrModel(1);
1574 } else {
1575 fit = ithSpectra->second.GetCorrModel(0);
1576 }
1577 if (fit){
1578 Double_t rangeFit[2] = {0,0};
1579 fit->GetRange(rangeFit[0], rangeFit[1]);
1580 SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
1581 fit->Draw("same");
1582 TLegend* legend = GetAndSetLegend2( topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-0.4*relSize8P[p], topRCornerX[p]+6*relSize8P[p], topRCornerY[p]-0.6*relSize8P[p],0.85*textSizePixel, 1, label, 43,0.1);
1583 legend->AddEntry(fit, "linear fit, trigg.", "l");
1584 legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.2f #pm %2.2f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
1585 legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.2f #pm %2.2f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
1586 legend->Draw();
1587 } else {
1588 labelChannel->Draw();
1589 }
1590
1591 if (p ==7 ){
1592 DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-1.4*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSize8P[p], 42);
1593 DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSize8P[p]-2.2*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSize8P[p], 42);
1594 }
1595 }
1596 }
1597 if (skipped < 6)
1598 canvas8Panel->SaveAs(nameOutput.Data());
1599 }
1600
1601
1602
1603
1604
1605 void PlotTriggerPrimWithFitsFullLayer (TCanvas* canvas8Panel, TPad* pads[8], Double_t* topRCornerX, Double_t* topRCornerY,
1606 Double_t* relSize8P, Int_t textSizePixel,
1607 std::map<int,TileSpectra> spectra, Setup* setupT,
1608 double avMip, double facLow, double facHigh,
1609 Double_t xPMin, Double_t xPMax, Double_t scaleYMax,
1610 int layer, int mod, TString nameOutput, RunInfo currRunInfo){
1611
1612 Double_t maxY = 0;
1613 std::map<int, TileSpectra>::iterator ithSpectra;
1614 std::map<int, TileSpectra>::iterator ithSpectraTrigg;
1615
1616 int nRow = setupT->GetNMaxRow()+1;
1617 int nCol = setupT->GetNMaxColumn()+1;
1618 int skipped = 0;
1619 for (int r = 0; r < nRow; r++){
1620 for (int c = 0; c < nCol; c++){
1621 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1622 ithSpectra=spectra.find(tempCellID);
1623 if(ithSpectra==spectra.end()){
1624 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1625 continue;
1626 }
1627 TH1D* tempHist = ithSpectra->second.GetTriggPrim();
1628 if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
1629 }
1630 }
1631
1632 for (int r = 0; r < nRow; r++){
1633 for (int c = 0; c < nCol; c++){
1634 canvas8Panel->cd();
1635 int tempCellID = setupT->GetCellID(r,c, layer, mod);
1636 int p = setupT->GetChannelInLayer(tempCellID);
1637 pads[p]->Draw();
1638 pads[p]->cd();
1639 pads[p]->SetLogy();
1640 ithSpectra=spectra.find(tempCellID);
1641 if(ithSpectra==spectra.end()){
1642 skipped++;
1643 std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
1644 pads[p]->Clear();
1645 pads[p]->Draw();
1646 if (p ==7 ){
1647 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1648 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1649 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSize8P[p], "Trigger primitives", true, 0.85*relSize8P[p], 42);
1650 }
1651 continue;
1652 }
1653 TH1D* tempHist = ithSpectra->second.GetTriggPrim();
1654 SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);
1655 SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);
1656 tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
1657 tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
1658
1659 tempHist->Draw("pe");
1660 short bctemp = ithSpectra->second.GetCalib()->BadChannel;
1661 if (bctemp != -64 && bctemp < 3){
1662 Color_t boxCol = kGray;
1663 if (bctemp == 1)
1664 boxCol = kGray+1;
1665 else if (bctemp == 0)
1666 boxCol = kGray+2;
1667 TBox* badChannelArea = CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
1668 badChannelArea->Draw();
1669 tempHist->Draw("same,axis");
1670 tempHist->Draw("same,pe");
1671 }
1672
1673 TString label = Form("row %d col %d", r, c);
1674 if (p == 7){
1675 label = Form("row %d col %d layer %d", r, c, layer);
1676 }
1677 TLatex *labelChannel = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSize8P[p],label);
1678 SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
1679 labelChannel->Draw();
1680
1681 TBox* triggArea = CreateBox(kBlue-8, avMip*facLow, 0.7, avMip*facHigh,scaleYMax*maxY, 1001 );
1682 triggArea->Draw();
1683
1684 DrawLines(avMip*facLow, avMip*facLow,0.7, scaleYMax*maxY, 1, 1, 7);
1685 DrawLines(avMip*facHigh, avMip*facHigh,0.7, scaleYMax*maxY, 1, 1, 7);
1686 tempHist->Draw("same,axis");
1687 tempHist->Draw("same,pe");
1688
1689 if (p ==7 ){
1690 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSize8P[p], 42);
1691 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSize8P[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSize8P[p], 42);
1692 DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSize8P[p], "Trigger primitives", true, 0.85*relSize8P[p], 42);
1693 }
1694 }
1695 }
1696 if (skipped < 6)
1697 canvas8Panel->SaveAs(nameOutput.Data());
1698 }
1699
1700 #endif