#include // //PURPOSE // Stacks histograms of default, tight, loose electron variables in order to check cuts are being applied correctly // Produces a ps file containing every 1D histogram in the ElectronBlock sub-directories default/tight/loose // //CAVEAT // Assumes you have used ele_cand.C to analyse a Stntuple with TopEventModule information // For Stntuples from other sources, switch off tight/loose electron plots // //INSTRUCTIONS // User can just run it with .x Stntuple/top/ele_display.C // // User can specify a file name as an argument .x Stntuple/top/ele_display.C("myfile.hbk") // User can switch off tight/loose electron plots .x Stntuple/top/ele_display.C("myfile.hbk",0) // User can switch off log scale plots with .x Stntuple/top/ele_display.C("myfile.hbk",1,0) // //ADVICE // Open area is for default electrons // Hatched area is for loose electrons (but my version of ghostview doesn't like this...) // Solid area is for tight electrons // // Log scale plots: each histogram is displayed twice: // LHS pad has linear y scale, RHS pad has logarithmic y scale // // Start root with option -b if you just want to make the postscript file // and not have to wait impatiently for the screen to update // //HOW // Done by iterating over list of keys of histograms void ele_display(Char_t* filename="ele_cand.root", Int_t TopEvent=1, Int_t logPlotToo=1 ){ //Set up the style gROOT->SetStyle("Plain"); gStyle->SetTitleFont(32); //Title box font (32=italic times bold) gStyle->SetTitleX(0.1); //Title box x position (top left-hand corner) gStyle->SetTitleY(0.995); //Title box y position (default value) gStyle->SetTitleW(0.6); //Title box width as fraction of pad size gStyle->SetTitleH(0.08); //Title box height as fraction of pad size gStyle->SetOptStat(1111111); //Integral, Overflow, Underflow, RMS, Mean, Nent, Name gStyle->SetTickLength(-0.03,"X"); gStyle->SetTickLength(-0.03,"Y"); gROOT->ForceStyle(); //Open the file TFile* f=new TFile(filename); f->ls(); //Complicated - draw all histograms in a general way! // // //Open a canvas TCanvas* myc = new TCanvas("Electrons","Electrons all/tight/loose",500,600); myc->Clear(); myc->Divide(2,4); //Even number of pads, please! myc->cd(1); //Open a postscript file printf("My Linux ghostview does not like SetFillStyle, use gs instead! fcdfsgi2 version was ok"); TPostScript *ps = new TPostScript("electron.ps",111); ps->NewPage(); //Get pointers to subdirectories f->cd("ElectronBlock/default"); TDirectory* dirD = gDirectory; f->cd("ElectronBlock/tight"); TDirectory* dirT = gDirectory; f->cd("ElectronBlock/loose"); TDirectory* dirL = gDirectory; //You could also access each histogram by name like this //const char* histName = "ncem_Et"; //TH1F* hD = (TH1F*)dirD->Get(histName); //TH1F* hT = (TH1F*)dirT->Get(histName); //TH1F* hL = (TH1F*)dirL->Get(histName); // mydraw1D(hD,hT,hL); //Keys method //Get iterators to list of histograms in each directory TIter nextD(dirD->GetListOfKeys()); TIter nextT(dirT->GetListOfKeys()); TIter nextL(dirL->GetListOfKeys()); TKey* keyD; TKey* keyT; TKey* keyL; int ipad =1; //while next keys all exist while ( (keyD=(TKey*)nextD()) && (keyT=(TKey*)nextT()) && (keyL=(TKey*)nextL()) ) { printf("\n key: %s points to an object of class: %s at %d", keyD->GetName(), keyD->GetClassName(),keyD->GetSeekKey() ); if(strcmp(keyD->GetClassName(),"TH1F")==0){ //Check it is a 1D histogram! TH1F* hD = (TH1F*)dirD->Get(keyD->GetName()); TH1F* hT = (TH1F*)dirT->Get(keyT->GetName()); TH1F* hL = (TH1F*)dirL->Get(keyL->GetName()); myc->cd(ipad++); mydraw1D(hD,hT,hL,TopEvent); //Linear y scale if(logPlotToo==1){ //command line switch myc->cd(ipad++); mydraw1D(hD,hT,hL,TopEvent,1); //Logarithmic y scale } } if(ipad==9){//update then clear canvas and go to next page in ps file myc->Update(); myc->Clear(); //Clearing canvas makes a new page in postscript file myc->Divide(2,4); ipad=1; } } ps->Close(); return; } //Stack 3 histograms //hD is all //hT is tight //hL is loose, both is tight+loose void mydraw1D(TH1F* hD, TH1F* hT, TH1F* hL, Int_t TopEvent=1, Int_t opt=0){ //log or linear scales? if(opt==0){ gPad->SetLogy(0); //Linear y scale }else{ gPad->SetLogy(1); //Logarithmic y scale hD->SetMinimum(0.8); hT->SetMinimum(0.8); hL->SetMinimum(0.8); } if(TopEvent==1){ //make a histogram with tight and loose electrons TH1F* both = (TH1F*) hL->Clone(); both->SetName("both"); both->Add(hT); //set fill colours and styles both->SetFillColor(4); //both->SetFillStyle(3004); hT->SetFillColor(5); //Draw them! Check there is at least one entry in histogram to avoid log scale complaints hD->Draw(); if(both->GetEntries() >0) both->Draw("same"); if(hT->GetEntries() >0) hT->Draw("same"); //Add a legend leg =new TLegend(0.55,0.75,0.75,0.9,""); leg->SetFillColor(0); leg->AddEntry(hD,"Default"); leg->AddEntry(both,"Loose","F"); leg->AddEntry(hT,"Tight","F"); leg->Draw(); }else{ //just draw default histogram hD->Draw(); } return; }