Skip to content

Commit

Permalink
Merge pull request #23782 from cedricpri/add-overflow
Browse files Browse the repository at this point in the history
Added overflow bin to all the plots (muon validation)
  • Loading branch information
cmsbuild committed Jul 18, 2018
2 parents 6538201 + 8ec219a commit 9125b19
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
64 changes: 52 additions & 12 deletions Validation/RecoMuon/test/macro/new_PlotHelpers.C
Expand Up @@ -17,8 +17,10 @@ void NormalizeHistogramsToFirst(TH1* h1, TH1* h2);
void NormalizeHistogramsToOne(TH1* h1, TH1* h2);
void NormalizeHistogramsAsDensity(TH1* h1, TH1* h2);
TH1* PlotRatiosHistograms(TH1* h1, TH1* h2);
TH1* AddOverflow(TH1* h);

int ratioCounter = 0;
int overflowCounter = 0;

// debugging printouts
bool DEBUGP = false;
Expand Down Expand Up @@ -269,8 +271,10 @@ void PlotNHistograms(const TString& pdfFile,
cerr << " + Plotting histograms for " << canvasTitle << endl;
}

TH1* rh = 0;
TH1* sh = 0;
TH1* rh_raw = 0;
TH1* rh = 0;
TH1* sh_raw = 0;
TH1* sh = 0;

TCanvas* canvas = 0;
if (nhistos >4)
Expand All @@ -297,45 +301,48 @@ void PlotNHistograms(const TString& pdfFile,

if (DEBUGP) cout << " Getting object for reference sample " << (rcollname + "/" + hnames[i]) << endl;

rdir->GetObject(rcollname + "/" + hnames[i], rh);
if (! rh) {
rdir->GetObject(rcollname + "/" + hnames[i], rh_raw);
if (! rh_raw) {
cout << "WARNING: Could not find a reference histogram or profile named " << hnames[i]
<< " in " << rdir->GetName() << endl;
cout << " Skipping" << endl;
continue;
}

//If it is a 2D project it in Y... is this what we always want?
if (TString(rh->IsA()->GetName()) == "TH2F") {
if (TString(rh_raw->IsA()->GetName()) == "TH2F") {

if (DEBUGP) cout << " It is a TH2F object... project in Y!" << endl;

TH1* proj = ((TH2F*) rh)->ProjectionY();
rh = proj;
TH1* proj = ((TH2F*) rh_raw)->ProjectionY();
rh_raw = proj;
}

// + New release
sdir->cd(scollname);

if (DEBUGP) cout << " Getting object for target sample " << (scollname + "/" + hnames[i]) << endl;

sdir->GetObject(scollname + "/" + hnames[i], sh);
if (! sh) {
sdir->GetObject(scollname + "/" + hnames[i], sh_raw);
if (! sh_raw) {
cout << "WARNING: Could not find a signal histogram or profile named " << hnames[i]
<< " in " << sdir->GetName() << endl;
cout << " Skipping" << endl;
continue;
}

//If it is a 2D project it in Y... is this what we always want?
if (TString(sh->IsA()->GetName()) == "TH2F") {
if (TString(sh_raw->IsA()->GetName()) == "TH2F") {

if (DEBUGP) cout << hnames[i] << " is a TH2F object... project in Y!" << endl;

TH1* proj = ((TH2F*) sh)->ProjectionY();
sh = proj;
TH1* proj = ((TH2F*) sh_raw)->ProjectionY();
sh_raw = proj;
}

rh = AddOverflow(rh_raw);
sh = AddOverflow(sh_raw);

// Set styles

if (DEBUGP) cout << " Setting style..." << endl;
Expand Down Expand Up @@ -741,3 +748,36 @@ TH1* PlotRatiosHistograms(TH1* h1, TH1* h2){

return h_ratio;
}

TH1* AddOverflow(TH1* h) {

++overflowCounter;

TString name = h->GetName();
Int_t nx = h->GetNbinsX()+1;
Double_t bw = h->GetBinWidth(nx);
Double_t x1 = h->GetBinLowEdge(1);
Double_t x2 = h->GetBinLowEdge(nx) + bw;

// Book a new histogram having an extra bin for overflows
TH1F* htmp = new TH1F(Form(name + "_overflow_%d", overflowCounter), "", nx, x1, x2);

// Fill the new histogram including the extra bin for overflows
for (Int_t i=1; i<=nx; i++) {
htmp->Fill(htmp->GetBinCenter(i), h->GetBinContent(i));
htmp->SetBinError(i, h->GetBinError(i));
}

// Fill the underflow
htmp->Fill(x1-1, h->GetBinContent(0));

// Restore the number of entries
htmp->SetEntries(h->GetEntries());

// Cosmetics
htmp->SetLineColor(h->GetLineColor());
htmp->SetLineWidth(h->GetLineWidth());
htmp->GetXaxis()->SetTitleOffset(1.5);

return htmp;
}
4 changes: 2 additions & 2 deletions Validation/RecoMuon/test/macro/new_TrackValHistoPublisher.C
Expand Up @@ -293,15 +293,15 @@ void new_TrackValHistoPublisher(const char* newFile="NEW_FILE",const char* refFi

//===== normalized chi2, chi2 probability, ave. norm. chi2 vs eta; ave. pt bias vs eta
plotOptReset(logx,logy,doKolmo,norm,minx,maxx,miny,maxy,drawopt,plots,titles);
plots[0]="chi2" ; titles[0]="Track normalized #chi^{2}";
plots[0]="chi2" ; titles[0]="Track #chi^{2}";
plots[1]="chi2prob" ; titles[1]="Probability of track #chi^{2}";
plots[2]="chi2_vs_eta_prof" ; titles[2]="Mean normalized #chi^{2} vs #eta" ;

drawopt[0]="hist";
drawopt[1]="hist";
drawopt[2]="";

norm[0]= 2.;
norm[0]= -1.;
norm[1]= 2.;
norm[2]= -1.;

Expand Down

0 comments on commit 9125b19

Please sign in to comment.