/************************************************************************************* * getKS: Searches through the histograms in the plotter output, adds the MC together * for each field, and compares the MC with the Data histogram using a KS test * input: the main() arguments array * output: writes to stdout the (human-readable) KS statistics of pairs of histograms * * Structure-wise: this is fine, can be implemented into class easily. ***********************************/ void getKS(const char* argv[]) { //open the input TFile TFile *f = new TFile(argv[2]); f->cd(); //get the filesystem information from the file TList *alokDirs = (TList*) f->GetListOfKeys(); //loop through the directories in the input file for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) { TDirectory *cDir = (TDirectory*) f->Get(alokDirs->At(idir)->GetName()); TList *alokHistos = (TList*) cDir->GetListOfKeys(); // create the MC histogram and start collecting relevant MC histograms // from the current directory TList *aloh = new TList; // loop through keys (histograms) in current directory for(int ihisto=0; alokHistos->At(ihisto) != alokHistos->Last(); ihisto++) { if(TString(alokHistos->At(ihisto)->GetName()).Contains("MC8TeV")) { TH1F *cHisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName()); aloh->Add(cHisto); } } //merge the data histograms into one histogram TH1F *MCHisto = (TH1F*) (aloh->Last())->Clone(TString(cDir->GetName()) + TString("MCHisto")); aloh->RemoveLast(); MCHisto->Merge(aloh); cout<<"-------------------- "<<cDir->GetName()<<" -----------------------"<<endl; //now create the data histogram and run the KS test TH1F *DataHisto = (TH1F*) cDir->Get(alokHistos->Last()->GetName()); cout<<" ---> KS Test: "<<cDir->GetName()<<" has probability "<<MCHisto->KolmogorovTest(DataHisto, "D")<<"\n"<<endl; } }
UInt_t GetListOfJobs( TFile* file, TList& jobdirs) { // get a list of all jobs in all method directories // based on ideas by Peter and Joerg found in macro deviations.C TIter next(file->GetListOfKeys()); TKey *key(0); while ((key = (TKey*)next())) { if (TString(key->GetName()).BeginsWith("Method_")) { if (gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) { TDirectory* mDir = (TDirectory*)key->ReadObj(); TIter keyIt(mDir->GetListOfKeys()); TKey *jobkey; while ((jobkey = (TKey*)keyIt())) { if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom("TDirectory")) continue; TDirectory *jobDir = (TDirectory *)jobkey->ReadObj(); cout << "jobdir name " << jobDir->GetName() << endl; jobdirs.Add(jobDir); } } } } return jobdirs.GetSize(); }
// input: - Input file (result from TMVA), // - use of TMVA plotting TStyle void network( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); Network_GFile = file; TKey* mkey = TMVAGlob::FindMethod("MLP"); if (mkey==0) { cout << "Could not locate directory MLP in file " << fin << endl; return; } TDirectory *dir = (TDirectory *)mkey->ReadObj(); dir->cd(); TList titles; UInt_t ni = TMVAGlob::GetListOfTitles( dir, titles ); if (ni==0) { cout << "No titles found for Method_MLP" << endl; return; } TIter nextTitle(&titles); TKey *titkey; TDirectory *titDir; while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) { titDir = (TDirectory *)titkey->ReadObj(); cout << "Drawing title: " << titDir->GetName() << endl; draw_network(titDir); } }
// ----------------------------------------------------------------------------- // TH1* getHisto( std::string nameFile, std::string nameHist, std::string Dirname, int rebin ) { std::string name = nameFile; TFile* file = new TFile(name.c_str()); if (file) { std::cout << "Opened file: " << file->GetName() << std::endl; } else { std::cout << "Could not find file: " << name << std::endl; return 0; } TDirectory* dir = (TDirectory*)file->Get(Dirname.c_str()); if (dir) { std::cout << "Opened dir: " << dir->GetName() << std::endl; } else { std::cout << "Could not find dir: " << Dirname << std::endl; return 0; } int low = 375; TH1* hist = 0; if ( false || nameHist.find("HtMultiplicity_HT375") == std::string::npos ) { hist = (TH1*)dir->Get(nameHist.c_str()); } else { for ( uint ii = low; ii <= 975; ii+=100 ) { std::stringstream tmp; tmp << "HtMultiplicity_HT" << ii << nameHist.substr(20); if ( !hist ) { dir->cd(); TH1D* temp = (TH1D*)dir->Get( "HtMultiplicity_HT375_aT0" ); //TH1D* temp = (TH1D*)file->Get( tmp.str().c_str() ); if (temp) { hist = (TH1D*)temp->Clone(); } else { std::cout << "1 Unable to retrieve histo with name " << tmp.str() << std::endl; } } else { dir->cd(); TH1D* temp = (TH1D*)dir->Get( tmp.str().c_str() ); if (temp) { hist->Add( (TH1D*)temp ); } else { std::cout << "2 Unable to retrieve histo with name " << tmp.str() << std::endl; } } } } if (hist) { std::cout << "Opened histo: " << hist->GetName() << std::endl; } else { std::cout << "Could not find histo: " << nameHist << std::endl; return 0; } hist->SetLineWidth(3); if ( rebin > 0 ) { hist->Rebin(rebin); } hist->GetXaxis()->SetTitleSize(0.055); hist->GetYaxis()->SetTitleSize(0.055); hist->GetXaxis()->SetLabelSize(0.05); hist->GetYaxis()->SetLabelSize(0.05); hist->SetStats(kFALSE); return hist; }
void make(TDirectory & out, TObject * o) { TDirectory * dir; TH1F * th1f; TH1D * th1d; TH2F * th2f; TH2D * th2d; out.cd(); if((dir = dynamic_cast<TDirectory*>(o)) != 0) { TDirectory * outDir = out.mkdir(dir->GetName(), dir->GetTitle()); TIter next(dir->GetListOfKeys()); TKey *key; while( (key = dynamic_cast<TKey*>(next())) ) { string className(key->GetClassName()); string name(key->GetName()); TObject * obj = dir->Get(name.c_str()); if(obj == 0) { cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl; exit(-1); } make(*outDir, obj); } } else if((th1f = dynamic_cast<TH1F*>(o)) != 0) { TH1F *h = (TH1F*) th1f->Clone(); h->Reset(); h->Sumw2(); h->SetDirectory(&out); } else if((th1d = dynamic_cast<TH1D*>(o)) != 0) { TH1D *h = (TH1D*) th1d->Clone(); h->Reset(); h->Sumw2(); h->SetDirectory(&out); } else if((th2f = dynamic_cast<TH2F*>(o)) != 0) { TH2F *h = (TH2F*) th2f->Clone(); h->Reset(); h->Sumw2(); h->SetDirectory(&out); } else if((th2d = dynamic_cast<TH2D*>(o)) != 0) { TH2D *h = (TH2D*) th2d->Clone(); h->Reset(); h->Sumw2(); h->SetDirectory(&out); } }
void fill(TDirectory & out, TObject * o, double w) { TDirectory * dir; TH1F * th1f; TH1D * th1d; TH2F * th2f; TH2D * th2d; if((dir = dynamic_cast<TDirectory*>(o)) != 0) { const char * name = dir->GetName(); TDirectory * outDir = dynamic_cast<TDirectory*>(out.Get(name)); if(outDir == 0) { cerr << "can't find directory " << name << " in output file" << endl; exit(-1); } TIter next(dir->GetListOfKeys()); TKey *key; while( (key = dynamic_cast<TKey*>(next())) ) { string className(key->GetClassName()); string name(key->GetName()); TObject * obj = dir->Get(name.c_str()); if(obj == 0) { cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl; exit(-1); } fill(*outDir, obj, w); } } else if((th1f = dynamic_cast<TH1F*>(o)) != 0) { const char * name = th1f->GetName(); TH1F * outTh1f = dynamic_cast<TH1F*>(out.Get(name)); if(outTh1f == 0) { cerr <<"error: histogram TH1F" << name << " not found in directory " << out.GetName() << endl; exit(-1); } outTh1f->Add(th1f, w); } else if((th1d = dynamic_cast<TH1D*>(o)) != 0) { const char * name = th1d->GetName(); TH1D * outTh1d = dynamic_cast<TH1D*>(out.Get(name)); if(outTh1d == 0) { cerr <<"error: histogram TH1D" << name << " not found in directory " << out.GetName() << endl; exit(-1); } outTh1d->Add(th1d, w); } else if((th2f = dynamic_cast<TH2F*>(o)) != 0) { const char * name = th2f->GetName(); TH2F * outTh2f = dynamic_cast<TH2F*>(out.Get(name)); if(outTh2f == 0) { cerr <<"error: histogram TH2F" << name << " not found in directory " << out.GetName() << endl; exit(-1); } outTh2f->Add(th2f, w); } else if((th2d = dynamic_cast<TH2D*>(o)) != 0) { const char * name = th2d->GetName(); TH2D * outTh2d = dynamic_cast<TH2D*>(out.Get(name)); if(outTh2d == 0) { cerr <<"error: histogram TH2D" << name << " not found in directory " << out.GetName() << endl; exit(-1); } outTh2d->Add(th2d, w); } }
// helper function to add and weight all plots in the subsamples void addDir(const std::string& path, const std::vector< std::pair< TFile*, double > >& files, TFile *target, int verbose) { // loop all objects in the file std::vector< std::pair< TFile*, double > >::const_iterator first=files.begin(); first->first->cd(path.c_str()); TIter nextkey(gDirectory->GetListOfKeys()); TKey *key=0; while ( (key = (TKey*)nextkey())) { // read object from first source file first->first->cd(path.c_str()); TObject *obj = key->ReadObj(); if ( obj->IsA()->InheritsFrom( "TH1" ) ) { // if descendant of TH1 -> mergeit TH1 *h1 = (TH1*)obj; h1->Sumw2(); h1->Scale(first->second); // loop over all source files and add the content of the // corresponding histogram to the one pointed to by "h1" for(std::vector< std::pair< TFile*, double > >::const_iterator file=first+1; file!=files.end(); ++file) { // make sure we are at the correct directory level by cd'ing to path file->first->cd(path.c_str()); TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() ); if ( h2 ) { h2->Sumw2(); h1->Add(h2,file->second); delete h2; // don't know if this is necessary, i.e. if // h2 is created by the call to gDirectory above. } } } else if (obj->IsA()->InheritsFrom( "TDirectory" ) ) { // for a subdirectory if(verbose>1) std::cout << "Found subdirectory " << obj->GetName() << std::endl; // create a new subdir of same name and title in the target file target->cd(); TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() ); // newdir is now the starting point of another round of merging // newdir still knows its depth within the target file via // GetPath(), so we can still figure out where we are in the recursion addDir(newdir->GetName(),files,target, verbose); } if ( obj ) { target->cd(path.c_str()); obj->Write( key->GetName() ); } delete obj; } target->Write(); delete key; }
//Clone the file excluding the histogram (code stolen from Rene Brun) void copyDir(TDirectory *source,std::string iSkipHist,bool iFirst=true) { //copy all objects and subdirs of directory source as a subdir of the current directory TDirectory *savdir = gDirectory; TDirectory *adir = savdir; if(!iFirst) adir = savdir->mkdir(source->GetName()); if(!iFirst) adir->cd(); //loop on all entries of this directory TKey *key; TIter nextkey(source->GetListOfKeys()); while ((key = (TKey*)nextkey())) { const char *classname = key->GetClassName(); TClass *cl = gROOT->GetClass(classname); if (!cl) continue; if (cl->InheritsFrom(TDirectory::Class())) { source->cd(key->GetName()); TDirectory *subdir = gDirectory; adir->cd(); copyDir(subdir,iSkipHist,false); adir->cd(); } else { source->cd(); TObject *obj = key->ReadObj(); std::string pFullName = std::string(adir->GetName())+"/"+std::string(obj->GetName()); std::string iSkipHist2 = iSkipHist; std::string fine_binning = "_fine_binning"; iSkipHist2.replace(iSkipHist2.find(fine_binning), fine_binning.length(),""); if(pFullName.find(iSkipHist) != std::string::npos || pFullName.find(iSkipHist2) != std::string::npos) { continue; } adir->cd(); obj->Write(); delete obj; } } adir->SaveSelf(kTRUE); savdir->cd(); }
void DoComparison(TString newFileName, TString oldFileName, vector<TString> newHistName, vector<TString> oldHistName) { TFile newF(newFileName,"read"); TDirectory *newDir = newF.GetDirectory("Merged"); TFile old(oldFileName); TFile output("Comparison.root","update"); assert(newHistName.size() == oldHistName.size()); vector<TH1D*> newHists; vector<TH1D*> oldHists; for(UInt_t i = 0; i < newHistName.size(); i++) { TH1D *newH = (TH1D*)newDir->Get(newHistName[i]); if(!newH) { cout<<"Could not find "<<newHistName[i]<< " in "<<newDir->GetName()<<endl; return; } TH1D *oldH = (TH1D*)old.Get(oldHistName[i]); if(!oldH) { cout<<"Could not find "<<oldHistName[i]<< " in "<<old.GetName()<<endl; return; } newHists.push_back(newH); oldHists.push_back(oldH); } for(UInt_t i = 0; i < newHists.size(); i++) { // Make ratio TH1D *ratio = (TH1D*)newHists[i]->Clone(); ratio->Divide(oldHists[i]); ratio->SetDirectory(0); TString newName = newHists[i]->GetName(); newName += "Ratio"; ratio->SetName(newName); ratio->SetTitle(newName); ratio->SetMarkerStyle(20); output.cd(); ratio->Write(newName, TObject::kOverwrite); cout<<"Wrote "<<newName<<" to "<< output.GetName()<<endl; // Make difference TH1D *difference = (TH1D*)newHists[i]->Clone(); difference->Add(oldHists[i],-1.); difference->SetDirectory(0); newName = newHists[i]->GetName(); newName += "Difference"; difference->SetName(newName); difference->SetTitle(newName); difference->SetMarkerStyle(20); output.cd(); difference->Write(newName, TObject::kOverwrite); cout<<"Wrote "<<newName<<" to "<< output.GetName()<<endl; // Make side by side plot TString canName = "Canvas"; canName += newHists[i]->GetName(); canName += "Comparison"; TCanvas *can = new TCanvas(canName, canName); newHists[i]->SetLineColor(kBlack); newHists[i]->SetMarkerStyle(20); newHists[i]->SetMarkerColor(kBlack); oldHists[i]->SetLineColor(kRed); oldHists[i]->SetMarkerStyle(20); oldHists[i]->SetMarkerColor(kRed); oldHists[i]->Draw(); newHists[i]->Draw("same"); can->Write(canName, TObject::kOverwrite); delete can; can = NULL; } }
void plotauto(TString infilename) { TString plname = infilename+".ps"; TCanvas* cc = new TCanvas("validate","validate",500,370); cc->Print(plname+"["); TText tt; tt.SetTextColor(2); tt.SetTextSize(0.02); gStyle->SetMarkerSize(0.1); gStyle->SetTitleSize(0.15,"ff"); gStyle->SetTitleTextColor(4); std::vector < TString > vnames; vnames.push_back("Sim_HitEn"); vnames.push_back("Sim_HitTime"); vnames.push_back("Sim_posXY"); vnames.push_back("Sim_posXZ"); vnames.push_back("Sim_posYZ"); vnames.push_back("Sim_posRZ"); std::vector <TString> exts; exts.push_back(""); exts.push_back("_posZ"); exts.push_back("_negZ"); TH1F* h; TH2F* hh; TKey *key; TIter next; TKey *key2; TIter next2; TFile* infile = new TFile(infilename, "read"); // overall geometry TDirectory* td = (TDirectory*) infile->Get("ALLCollections"); cc->Clear(); cc->Divide(3,3); cc->cd(1); hh = (TH2F*) td->Get("ALLCollections_overallhitZR"); hh->Draw("box"); cc->cd(2); int icol=1; bool first=true; TLegend* tl = new TLegend(0., 0., 1, 1); next = td->GetListOfKeys(); while ((key = (TKey*)next())) { TClass *cll = gROOT->GetClass(key->GetClassName()); if (cll->InheritsFrom("TH2F")) { hh = (TH2F*)key->ReadObj(); TString hn = hh->GetName(); if ( hn.Contains("ALL") ) continue; if ( hn.Contains("_Log") ) continue; hh->SetLineColor(icol); if ( first ) {hh->Draw("box"); first=false;} else hh->Draw("same;box"); icol++; if (icol==10) icol=1; TString ss = hn.ReplaceAll( "_overallhitZR", ""); tl->AddEntry(hh, ss , "l"); } } // the legend cc->cd(3); tl->Draw(); cc->cd(4); hh = (TH2F*) td->Get("ALLCollections_Log_overallhitZR"); hh->Draw("box"); cc->cd(5); icol=1; first=true; next = td->GetListOfKeys(); while ((key = (TKey*)next())) { TClass *cll = gROOT->GetClass(key->GetClassName()); if (cll->InheritsFrom("TH2F")) { hh = (TH2F*)key->ReadObj(); TString hn = hh->GetName(); if ( hn.Contains("ALL" ) ) continue; if ( ! hn.Contains("_Log_") ) continue; hh->SetLineColor(icol); if ( first ) {hh->Draw("box"); first=false;} else hh->Draw("same;box"); icol++; if (icol==10) icol=1; } } cc->cd(7); hh = (TH2F*) td->Get("ALLCollections_LogLog_overallhitZR"); hh->Draw("box"); cc->cd(8); icol=1; first=true; next = td->GetListOfKeys(); while ((key = (TKey*)next())) { TClass *cll = gROOT->GetClass(key->GetClassName()); if (cll->InheritsFrom("TH2F")) { hh = (TH2F*)key->ReadObj(); TString hn = hh->GetName(); if ( hn.Contains("ALL" ) ) continue; if ( ! hn.Contains("_LogLog_") ) continue; hh->SetLineColor(icol); if ( first ) {hh->Draw("box"); first=false;} else hh->Draw("same;box"); icol++; if (icol==10) icol=1; } } cc->Print(plname); // now collection-by-collection next = infile->GetListOfKeys(); while ((key = (TKey*)next())) { TClass *cll = gROOT->GetClass(key->GetClassName()); if (cll->InheritsFrom("TDirectory")) { td = (TDirectory*)key->ReadObj(); TString dirname = td->GetName(); if ( dirname=="ALLCollections" ) continue; // is it an endcap collection? bool isEndcap = td->Get(dirname+"_hitXY_posZ"); // first overall geometry cc->Clear(); cc->Divide(3,2); cc->cd(1); ( (TH2F*) td->Get(dirname+"_hitEn"))->Draw("box"); cc->cd(4)->SetLogy(); ( (TH2F*) td->Get(dirname+"_hitTime"))->Draw("box"); if ( isEndcap ) { cc->cd(2); ( (TH2F*) td->Get(dirname+"_hitXY_posZ"))->Draw("box"); cc->cd(3); ( (TH2F*) td->Get(dirname+"_hitXY_negZ"))->Draw("box"); cc->cd(5); ((TH2F*) td->Get(dirname+"_hitZR_posZ"))->Draw("box"); cc->cd(6); ((TH2F*) td->Get(dirname+"_hitZR_negZ"))->Draw("box"); } else { cc->cd(2); ( (TH2F*) td->Get(dirname+"_hitXY"))->Draw("box"); cc->cd(3); ( (TH2F*) td->Get(dirname+"_hitZR"))->Draw("box"); } cc->Print(plname); // then the cell indices // work out how many indices/variables we're dealing with std::vector < TString > indices; std::vector < TString > variables; next2 = td->GetListOfKeys(); while ((key2 = (TKey*)next2())) { cll = gROOT->GetClass(key2->GetClassName()); if (cll->InheritsFrom("TH2F")) { hh = (TH2F*) key2->ReadObj(); TString hn = hh->GetName(); if ( hn.Contains("Indx") ) { TString ss = hn.ReplaceAll(dirname+"_", ""); TString asas = ((TObjString*) (ss.Tokenize("_") -> At(0)))->GetString(); if ( find( indices.begin(), indices.end(), asas )==indices.end() ) indices.push_back(asas); asas = ((TObjString*) (ss.Tokenize("_") -> At(1)))->GetString(); if ( find( variables.begin(), variables.end(), asas )==variables.end() ) variables.push_back(asas); } } } if ( indices.size()==0 || variables.size()==0 ) continue; for (int inp=0; inp<2; inp++) { if ( !isEndcap && inp==1 ) continue; cc->Clear(); cc->Divide(indices.size(), variables.size()); int ic=1; next2 = td->GetListOfKeys(); while ((key2 = (TKey*)next2())) { cll = gROOT->GetClass(key2->GetClassName()); if (cll->InheritsFrom("TH2F")) { hh = (TH2F*) key2->ReadObj(); TString hn = hh->GetName(); if ( isEndcap ) { if ( inp==0 && ! hn.Contains("posZ") ) continue; else if ( inp==1 && ! hn.Contains("negZ") ) continue; } if ( hn.Contains("Indx") ) { TString asas = ((TObjString*) (hn.Tokenize("_") -> At(1)))->GetString(); asas = asas(4,asas.Length()); cc->cd(ic++); hh->Draw("box"); } } } cc->cd(); for ( size_t k=0; k<variables.size(); k++) { tt.DrawTextNDC( 0.0, 0.9 - (1.0*k)/(variables.size()), variables[k] ); } for ( size_t k=0; k<indices.size(); k++) { tt.DrawTextNDC( 0.05 + (1.0*k)/(indices.size()), 0.02, indices[k].ReplaceAll("Indx","Indx_") ); } tt.DrawTextNDC( 0.1, 0.99, dirname); if ( isEndcap ) { if (inp==0 ) tt.DrawTextNDC( 0.35, 0.99, "posZ"); else tt.DrawTextNDC( 0.35, 0.99, "negZ"); } cc->Print(plname); } } } infile->Close(); cc->Print(plname+"]"); }
void trigger() { gStyle->SetOptStat(1111111); std::vector<std::string> trig; trig.push_back("HLT_HT150_v2"); trig.push_back("HLT_HT150_AlphaT0p60_v1"); std::vector<std::string> his; his.push_back("ge2"); his.push_back("eq2"); his.push_back("eq3"); his.push_back("ge4"); TFile* f = new TFile(std::string("../Trigger_HT_Run2011A_PromptReco_v1.root").c_str(),"READ"); if ( f && !f->IsZombie() ) { std::cout << "Opened file: " << f->GetName() << std::endl; } else { std::cout << "Could not find file " << std::endl; //return; } TDirectory* d = (f==0?0:(TDirectory*)f->Get("Triggers")); if (d) { std::cout << "Opened dir: " << d->GetName() << std::endl; } else { std::cout << "Could not find dir " << std::endl; //return; } TCanvas* c1 = new TCanvas(std::string("trigger").c_str(), std::string("trigger").c_str(), 600,600); c1->Divide(1,2); TLegend* legend = new TLegend( 0.7, 0.6, 0.85, 0.7, NULL, "brNDC" ); std::vector<TH1D*> h(trig.size(),0); std::vector<TH1D*> i(trig.size(),0); for ( int ii = 0; ii < trig.size(); ++ii ) { std::string str; str = trig[ii]+"_all"; // if ( his[jj] == "eq2" ) { str = trig[ii]+"_2"; } // else if ( his[jj] == "eq3" ) { str = trig[ii]+"_3"; } // else if ( his[jj] == "ge4" ) { str = trig[ii]+"_4"; } // else { str = trig[ii]+"_all"; } h[ii] = (d==0?0:(TH1D*)d->Get(str.c_str())); if (h[ii]) { std::cout << "Opened histo: " << h[ii]->GetName() << std::endl; } else { std::cout << "Could not find histo " << std::endl; //continue; } i[ii] = (h[ii]==0?0:(TH1D*)h[ii]->Clone()); if (i[ii]) calcIntegral(i[ii],true); legend->AddEntry( h[ii], trig[ii].c_str(), "pl" ); } // TGraphAsymmErrors* gr1 = new TGraphAsymmErrors(); // if ( h[0] && h[1] ) gr1->BayesDivide(h[0],h[1]); // TGraphAsymmErrors* gr2 = new TGraphAsymmErrors(); // if ( i[0] && i[1] ) gr2->BayesDivide(i[0],i[1]); c1->cd(1); if ( h[0] && h[1] ) { h[0]->GetXaxis()->SetTitle("#alpha_{T}"); h[0]->SetLineColor(kRed); h[0]->SetFillColor(kRed-10); h[0]->GetXaxis()->SetRangeUser(0.,1.); h[0]->Draw(""); h[1]->GetXaxis()->SetTitle("#alpha_{T}"); h[1]->GetXaxis()->SetRangeUser(0.,1.); h[1]->Draw("sameP"); legend->SetTextSize(0.035); //legend->SetFillColor(0); //legend->SetLineColor(0); //legend->SetShadowColor(0); legend->Draw("same"); } c1->cd(2); if ( i[0] && i[1] ) { i[0]->GetXaxis()->SetTitle("#alpha_{T} > cut value"); i[0]->GetXaxis()->SetRangeUser(0.,1.); i[0]->SetLineColor(kRed); i[0]->SetFillColor(kRed-10); i[0]->Draw("LF2"); i[1]->GetXaxis()->SetTitle("#alpha_{T} > cut value"); i[1]->GetXaxis()->SetRangeUser(0.,1.); i[1]->Draw("sameP"); legend->SetTextSize(0.035); legend->SetFillColor(0); legend->SetLineColor(0); legend->SetShadowColor(0); legend->Draw("same"); } // c1->cd(3); // if ( h[0] && h[1] ) { // gr1->GetXaxis()->SetTitle("#alpha_{T}"); // gr1->GetYaxis()->SetTitle("Differential Efficiency"); // gr1->GetXaxis()->SetRangeUser(0.,1.); // gr1->Draw("alp"); // } // c1->cd(4); // if ( i[0] && i[1] ) { // gr2->GetXaxis()->SetTitle("#alpha_{T} > cut value"); // gr2->GetYaxis()->SetTitle("Cumulative Efficiency"); // gr2->GetXaxis()->SetRangeUser(0.4,1.0); // gr2->GetYaxis()->SetRangeUser(0.9,1.); // gr2->Draw("alp"); // } //c1->Update(); c1->SaveAs(std::string("trigger.pdf").c_str()); }
void recurseFile(TDirectory *indir, TDirectory *outdir, double etawid, double etamid) { TDirectory *curdir = gDirectory; // Automatically go through the list of keys (directories) TList *keys = indir->GetListOfKeys(); TListIter itkey(keys); TObject *key, *obj; TDirectory *dir; while ( (key = itkey.Next()) ) { if (_debug) cout << key->GetName() << endl << flush; obj = ((TKey*)key)->ReadObj(); assert(obj); dir = indir; // Found a subdirectory: copy it to output and go deeper if (obj->InheritsFrom("TDirectory")) { //assert(outdir->mkdir(obj->GetName())); outdir->mkdir(obj->GetName()); assert(outdir->cd(obj->GetName())); TDirectory *outdir2 = outdir->GetDirectory(obj->GetName()); assert(outdir2); outdir2->cd(); assert(indir->cd(obj->GetName())); TDirectory *indir2 = indir->GetDirectory(obj->GetName()); indir2->cd(); // Check if directory name contains information on eta bin width float etamin, etamax; if ( (sscanf(indir->GetName(),"Eta_%f-%f",&etamin,&etamax)==2) && (etamax>etamin) ) { etawid = 2.*(etamax-etamin); etamid = 0.5*(etamax+etamin); //cout << "Eta bin width: " << etawid << flush << endl; } recurseFile(indir2, outdir2, etawid, etamid); //outdir2->Write(); // does this speedup or slow down? } // inherits from TDirectory // Found a plot: normalize if hpt, then copy to output if (obj->InheritsFrom("TH1")) { outdir->cd(); TObject *obj2 = obj->Clone(obj->GetName()); // Normalize hpt and hselpt histograms // Same for hbpt if (string(obj2->GetName())=="hpt" || string(obj2->GetName())=="hpt_evt" || string(obj2->GetName())=="hpt_jet" || string(obj2->GetName())=="hpt_pre" || string(obj2->GetName())=="hpt0" || string(obj2->GetName())=="hpt1" || string(obj2->GetName())=="hpt2" || string(obj2->GetName())=="hpt3" || string(obj2->GetName())=="hpt_jk1" || string(obj2->GetName())=="hpt_jk2" || string(obj2->GetName())=="hpt_jk3" || string(obj2->GetName())=="hpt_jk4" || string(obj2->GetName())=="hpt_jk5" || string(obj2->GetName())=="hpt_jk6" || string(obj2->GetName())=="hpt_jk7" || string(obj2->GetName())=="hpt_jk8" || string(obj2->GetName())=="hpt_jk9" || string(obj2->GetName())=="hpt_jk10" || string(obj2->GetName())=="hpt_l1off" || string(obj2->GetName())=="hpt_l1fast" || string(obj2->GetName())=="hpt_plus" || string(obj2->GetName())=="hpt_minus" || string(obj2->GetName())=="hpt0_plus" || string(obj2->GetName())=="hpt0_minus" || string(obj2->GetName())=="hpt_noid" || string(obj2->GetName())=="hpt_noevtid" || string(obj2->GetName())=="hpt_nojetid" || string(obj2->GetName())=="hpt_ak5calo" || string(obj2->GetName())=="hpt_ak5pf" || string(obj2->GetName())=="hpt_evt_ak5pf" || string(obj2->GetName())=="hpt_jet_ak5pf" || string(obj2->GetName())=="hselpt" || string(obj2->GetName())=="hpt_r" || string(obj2->GetName())=="hpt_g" || string(obj2->GetName())=="hpt_gg" || string(obj2->GetName())=="hpt_g0" || string(obj2->GetName())=="hpt_g0tw" || string(obj2->GetName())=="hdjmass" || string(obj2->GetName())=="hdjmass0" || string(obj2->GetName())=="hdjmass0_hgg") { cout << "." << flush; TH1D *hpt = (TH1D*)obj2; bool isgen = TString(obj2->GetName()).Contains("pt_g"); bool isoth = (TString(obj2->GetName()).Contains("pt_no") || TString(obj2->GetName()).Contains("djmass") || TString(obj2->GetName()).Contains("hpt0") || TString(obj2->GetName()).Contains("l1off") || TString(obj2->GetName()).Contains("l1fast")); bool iscalo = (TString(obj2->GetName()).Contains("_ak5calo")); bool ispf5 = (TString(obj2->GetName()).Contains("_ak5pf")); bool ispre = (TString(obj2->GetName()).Contains("_pre")); bool isjk = (TString(obj2->GetName()).Contains("hpt_jk")); bool isjet = (TString(obj2->GetName()).Contains("hpt_jet")); TProfile *peff = (TProfile*)dir->Get("peff"); assert(peff); TH1D *hlumi = (TH1D*)dir->Get("hlumi"); assert(hlumi); TH1D *hlumi0 = (TH1D*)dir->Get("../jt450/hlumi"); assert(hlumi0); if (_jp_usetriglumi) { TH1D *hlumi_orig = (TH1D*)outdir->FindObject("hlumi_orig"); if (!hlumi_orig) hlumi_orig = (TH1D*)hlumi->Clone("hlumi_orig"); // regular prescaled luminosity TH1D *hlumi_new = (TH1D*)outdir->FindObject("hlumi"); if (hlumi_new) hlumi = hlumi_new; string strg = dir->GetName(); double lumi = triglumi[strg]; for (int i = 1; i != hlumi->GetNbinsX()+1; ++i) { hlumi->SetBinContent(i, lumi); } // unprescaled luminosity double lumi0 = triglumi["jt450"]; for (int i = 1; i != hlumi0->GetNbinsX()+1; ++i) { hlumi0->SetBinContent(i, lumi0); } } // _jp_usetriglumi // Test MC-based normalization for trigger efficiency bool dotrigeff = ((string(obj2->GetName())=="hpt") || isjk || isjet); TH1D *htrigeff = (TH1D*)outdir->FindObject("htrigeff"); TH1D *htrigeffmc = (TH1D*)outdir->FindObject("htrigeffmc"); TH1D *htrigeffsf = (TH1D*)outdir->FindObject("htrigeffsf"); TH1D *hpt_notrigeff = 0; if (!htrigeff && _jp_dotrigeff) { TFile *fmc = new TFile("output-MC-1.root","READ"); assert(fmc && !fmc->IsZombie()); assert(fmc->cd("Standard")); fmc->cd("Standard"); TDirectory *dmc0 = fmc->GetDirectory("Standard"); //assert(gDirectory->cd(Form("Eta_%1.1f-%1.1f", // etamid-0.25*etawid,etamid+0.25*etawid))); //TDirectory *dmc = gDirectory; TDirectory *dmc = dmc0->GetDirectory(Form("Eta_%1.1f-%1.1f", etamid-0.25*etawid,etamid+0.25*etawid)); assert(dmc); dmc->cd(); // Add MC truth based trigger efficiency if(!htrigeffmc && dmc->cd(dir->GetName())) { TDirectory *dir1 = dmc->GetDirectory(dir->GetName()); assert(dir1); TH1D *hpty = (TH1D*)dir1->Get("hpt"); assert(hpty); assert(dmc->cd("mc")); dmc->cd("mc"); TDirectory *dir2 = dmc->GetDirectory("mc"); assert(dir2); TH1D *hptx = (TH1D*)dir2->Get(Form("hpt_%s",dir->GetName())); outdir->cd(); if (hpty && hptx) htrigeffmc = (TH1D*)hpty->Clone("htrigeffmc"); if (hpty && hptx) htrigeffmc->Divide(hpty,hptx,1,1,"B"); } // Add data/MC scale factor for trigger efficiency if (_nh_dt && !htrigeffsf) { assert(dmc->cd(dir->GetName())); dmc->cd(dir->GetName()); TDirectory *dirmc = dmc->GetDirectory(dir->GetName()); assert(dirmc); TProfile *pm = (TProfile*)dirmc->Get("ptrigefftp"); TProfile *pd = (TProfile*)dir->Get("ptrigefftp"); outdir->cd(); if (pm && pd) htrigeffsf = pm->ProjectionX("htrigeffsf"); if (pm && pd) htrigeffsf->Divide(pd,pm,1); } // Combine MC trigger efficiency and scalefactor if (htrigeffmc) { // not available for 'mc' directory outdir->cd(); htrigeff = (TH1D*)htrigeffmc->Clone("htrigeff"); assert(!_nh_dt || htrigeffsf); if (_nh_dt) htrigeff->Multiply(htrigeffsf); TH1D *h = (TH1D*)dir->Get("hpt"); assert(outdir->FindObject("hpt_notrigeff")==0); outdir->cd(); hpt_notrigeff = (TH1D*)h->Clone("hpt_notrigeff"); } fmc->Close(); } // dotrigeff // Scale data to account for time dependence bool dotimedep = ((string(obj2->GetName())=="hpt") || isjk || isjet); TH1D *htimedep = (TH1D*)outdir->FindObject("htimedep"); TH1D *htimefit = (TH1D*)outdir->FindObject("htimefit"); TH1D *hpt_notimedep = 0, *hpt_withtimedep = 0; double ktime = 1.; if (!htimedep) { TH1D *h = (TH1D*)dir->Get("hpt"); TH1D *hsel = (TH1D*)dir->Get("hselpt"); TH1D *hpre = (TH1D*)dir->Get("hpt_pre"); //TH1D *hlumi0 = (TH1D*)dir->Get("../jt450/hlumi"); // Fix luminosity for unprescaled trigger //string strg = dir->GetName(); //double lum0 = triglumi["jt450"]; //for (int i = 1; i != hlumi0->GetNbinsX()+1; ++i) { //hlumi0->SetBinContent(i, lum0); //} outdir->cd(); if (h) hpt_notimedep = (TH1D*)h->Clone("hpt_notimedep"); if (hpre && h) htimedep = (TH1D*)hpre->Clone("htimedep"); if (hpre && h) htimedep->Divide(hpre,h);//,1,1,"B"); // Figure out trigger luminosities double lumi = 0; if (hlumi) lumi = hlumi->GetBinContent(1); double lumi0 = 0; if (hlumi0) lumi0 = hlumi0->GetBinContent(1); if (htimedep && lumi && lumi0) { htimedep->Scale(lumi / lumi0); } // Find proper pT range and fit double minpt = 0.; double maxpt = 6500.; if (hsel) { for (int i = 1; i != hsel->GetNbinsX()+1; ++i) { if (hsel->GetBinContent(i)!=0 && hsel->GetBinLowEdge(i)>=_jp_xmin57) { if (minpt<20) minpt = hsel->GetBinLowEdge(i); maxpt = hsel->GetBinLowEdge(i+1); } } } TF1 *ftmp = new TF1("ftmp","[0]",minpt,maxpt); ftmp->SetParameter(0,1); if (htimedep && htimedep->Integral()>0) htimedep->Fit(ftmp,"QRN"); if (htimedep && ftmp->GetParameter(0)>0) ktime = 1./ftmp->GetParameter(0); if (htimedep) { outdir->cd(); htimefit = (TH1D*)hsel->Clone("htimefit"); hpt_withtimedep = (TH1D*)h->Clone("hpt_withtimedep"); for (int i = 1; i != htimefit->GetNbinsX()+1; ++i) { if (hsel->GetBinContent(i)!=0) { htimefit->SetBinContent(i, ftmp->GetParameter(0)); htimefit->SetBinError(i, ftmp->GetParError(0)); } // Calculate with time dependence here to add ktime fit error hpt_withtimedep->SetBinContent(i, hpt_notimedep->GetBinContent(i) * htimefit->GetBinContent(i)); double err1 = hpt_notimedep->GetBinError(i) / hpt_notimedep->GetBinContent(i); double err2 = htimefit->GetBinError(i) / htimefit->GetBinContent(i); hpt_withtimedep->SetBinError(i, hpt_notimedep->GetBinContent(i) * sqrt(pow(err1,2) + pow(err2,2))); } } } // dotimedep if (!(hpt->GetNbinsX()==peff->GetNbinsX() || isoth || isgen) || !(hpt->GetNbinsX()==hlumi->GetNbinsX() || isoth || isgen)) { cerr << "Hist " << hpt->GetName() << " " << dir->GetName() << " Nbins=" << hpt->GetNbinsX() << endl << flush; assert(hpt->GetNbinsX()==peff->GetNbinsX() || isoth); assert(hpt->GetNbinsX()==hlumi->GetNbinsX() || isoth); } for (int i = 1; i != hpt->GetNbinsX()+1; ++i) { // Normalization for bin width in y, pT double norm = hpt->GetBinWidth(i) * etawid; double trigeff = 1.; double pt = hpt->GetBinCenter(i); // Normalization for all the common efficiencies if (peff->GetBinContent(i)!=0 && !isgen) norm *= peff->GetBinContent(i); // Test MC-based normalization for trigger efficiency if (dotrigeff && htrigeff && _jp_dotrigeff) { if (htrigeff->GetBinContent(i)!=0) { trigeff = min(1.,max(0.,htrigeff->GetBinContent(i))); if (_jp_dotrigefflowptonly && pt>=114) trigeff = 1; norm *= trigeff; } } // Normalization for luminosity if (hlumi->GetBinContent(i)!=0 && !isoth && !isgen && !ispre) norm *= hlumi->GetBinContent(i); if (hlumi->GetBinContent(1)!=0 && isoth && !isgen && !ispre) norm *= hlumi->GetBinContent(1); if (hlumi0->GetBinContent(1)!=0 && !isoth && !isgen && ispre) norm *= hlumi0->GetBinContent(1); // Fix luminosity from .csv VTX to lumiCalc vdM if (!_nh_mc) norm *= _lumiscale; // Scale normalization for jackknife if (isjk) norm *= 0.9; if (_nh_mc && _jp_pthatbins) norm *= 1.; if (_nh_mc && !_jp_pthatbins) { norm /= 2500.; //(xsecw / (sumw * adhocw) ); // equals 2551.; } // Correct data for time-dependence double norm_notime = norm; if (dotimedep && htimedep && _jp_dotimedep) { norm *= ktime; } if (!(peff->GetBinContent(i)!=0||hpt->GetBinContent(i)==0 || isgen || iscalo || ispf5 || isoth || hpt->GetBinCenter(i)<_jp_recopt || hpt->GetBinCenter(i)*cosh(etamid)>3500.)) { cerr << "Hist " << hpt->GetName() << " " << dir->GetName() << " pt=" << hpt->GetBinCenter(i) << " etamid = " << etamid << endl << flush; assert(peff->GetBinContent(i)!=0||hpt->GetBinContent(i)==0||isgen|| hpt->GetBinCenter(i)<_jp_recopt); } /* if (!(hlumi->GetBinContent(i)!=0 || hpt->GetBinContent(i)==0 || isoth || isgen || hpt->GetBinCenter(i)<_jp_recopt)) { cerr << "Hist " << hpt->GetName() << " " << dir->GetName() << " pt=" << hpt->GetBinCenter(i) << endl << flush; assert(hlumi->GetBinContent(i)!=0 || hpt->GetBinContent(i)==0 || isoth || hpt->GetBinCenter(i)<_jp_recopt); } */ assert(norm!=0); hpt->SetBinContent(i, hpt->GetBinContent(i) / norm); hpt->SetBinError(i, hpt->GetBinError(i) / norm); if (hpt_notrigeff) { hpt_notrigeff->SetBinContent(i, hpt_notrigeff->GetBinContent(i) / norm * trigeff); hpt_notrigeff->SetBinError(i, hpt_notrigeff->GetBinError(i) / norm * trigeff); } if (hpt_notimedep) { hpt_notimedep->SetBinContent(i, hpt_notimedep->GetBinContent(i) / norm_notime); hpt_notimedep->SetBinError(i, hpt_notimedep->GetBinError(i) / norm_notime); } if (hpt_withtimedep) { // ktime already applied => use norm_notime hpt_withtimedep->SetBinContent(i, hpt_withtimedep->GetBinContent(i) / norm_notime); hpt_withtimedep->SetBinError(i, hpt_withtimedep->GetBinError(i) / norm_notime); } } // for i } // hpt dir->cd(); } // inherits from TH1 } // while key curdir->cd(); } // recurseFile
// input: - Input file (result from TMVA) // - use of TMVA plotting TStyle void deviations( TString fin = "TMVAReg.root", HistType htype = MVAType, Bool_t showTarget, Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); gStyle->SetNumberContours(999); // switches const Bool_t Save_Images = kTRUE; // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); // define Canvas layout here! Int_t xPad = 1; // no of plots in x Int_t yPad = 1; // no of plots in y Int_t noPad = xPad * yPad ; const Int_t width = 650; // size of canvas // this defines how many canvases we need TCanvas* c[100]; // counter variables Int_t countCanvas = 0; // search for the right histograms in full list of keys // TList* methods = new TMap(); TIter next(file->GetListOfKeys()); TKey *key(0); while ((key = (TKey*)next())) { if (!TString(key->GetName()).BeginsWith("Method_")) continue; if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue; TString methodName; TMVAGlob::GetMethodName(methodName,key); cout << "--- Plotting deviation for method: " << methodName << endl; TObjString *mN = new TObjString( methodName ); TDirectory* mDir = (TDirectory*)key->ReadObj(); TList* jobNames = new TList(); TIter keyIt(mDir->GetListOfKeys()); TKey *titkey; while ((titkey = (TKey*)keyIt())) { if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue; TDirectory *titDir = (TDirectory *)titkey->ReadObj(); TObjString *jN = new TObjString( titDir->GetName() ); if (!jobNames->Contains( jN )) jobNames->Add( jN ); else delete jN; TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); TString hname = "MVA_" + methodTitle; TIter dirKeyIt( titDir->GetListOfKeys() ); TKey* dirKey; Int_t countPlots = 0; while ((dirKey = (TKey*)dirKeyIt())){ if (dirKey->ReadObj()->InheritsFrom("TH2F")) { TString s(dirKey->ReadObj()->GetName()); if (s.Contains("_reg_") && ( (showTarget && s.Contains("_tgt")) || (!showTarget && !s.Contains("_tgt")) ) && s.Contains( (htype == CompareType ? "train" : "test" ))) { c[countCanvas] = new TCanvas( Form("canvas%d", countCanvas+1), Form( "Regression output deviation versus %s for method: %s", (showTarget ? "target" : "input variables"), methodName.Data() ), countCanvas*50+100, (countCanvas+1)*20, width, (Int_t)width*0.72 ); c[countCanvas]->SetRightMargin(0.10); // leave space for border TH1* h = (TH1*)dirKey->ReadObj(); h->SetTitle( Form("Output deviation for method: %s (%s sample)", hname.Data(), (htype == CompareType ? "training" : "test" )) ); // methodName.Data(), (htype == CompareType ? "training" : "test" )) ); h->Draw("colz"); TLine* l = new TLine( h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0 ); l->SetLineStyle(2); l->Draw(); // update and print cout << "plotting logo" << endl; TMVAGlob::plot_logo(1.058); c[countCanvas]->Update(); TString fname = Form( "plots/deviation_%s_%s_%s_c%i", methodName.Data(), (showTarget ? "target" : "vars"), (htype == CompareType ? "training" : "test" ), countPlots ); TMVAGlob::imgconv( c[countCanvas], fname ); countPlots++; countCanvas++; } } } } } }
void CombineCFsInDataDir(TDirectory *f, vector<TString> dataSetNames) { TString cfDirName = "CF"; TString countDirName = "Count"; vector<TDirectory*> cfDirs = GetDirectories(f, dataSetNames, cfDirName); vector<TDirectory*> countDirs = GetDirectories(f, dataSetNames, countDirName); TDirectory *mergeDir = (TDirectory*)f->GetDirectory("Merged"); if(!mergeDir) { mergeDir = f->mkdir("Merged"); } UInt_t nDirs = cfDirs.size(); // Merge each centrality one at a time // Load the cfs and counts into vectors for that centrality // Find all the cfs and counts that match the name of the CF // in the first directory TIter iter(cfDirs[0]->GetListOfKeys()); TObject *obj = NULL; while ( (obj = iter()) ) { TKey *key = dynamic_cast<TKey*>(obj); TH1D *cf = dynamic_cast<TH1D*>(key->ReadObj()); if(!cf) { cout<<"Could not find a CF hist"<<endl; return; } //Figure out which CF we are trying to grab TString cfName = cf->GetName(); TString countName = cfName; countName.ReplaceAll("CF","Count"); //Grab the corresponding CFs and counts vector<TH1D*> cfs; vector<Double_t> counts; Double_t totalCounts = 0; for(UInt_t iDir = 0; iDir < nDirs; iDir++) { TH1D *thisCF = (TH1D*) cfDirs[iDir]->Get(cfName); if(!thisCF) { cout<<"Could not find CF matching "<<cfName <<" in "<<cfDirs[iDir]->GetName()<<endl; } // TVectorD *count = dynamic_cast<TVectorD*>(countDirs[iDir]->Get(countName)); TVectorD *count = (TVectorD*)countDirs[iDir]->Get(countName); // cout<<count->ClassName()<<endl; Double_t myCount = count[0](0); cfs.push_back(thisCF); counts.push_back(myCount); totalCounts += myCount; } // Finally, combine the CFs TH1D *combinedCF = CombineCFs(cfs, counts); if (!combinedCF) { cout << "Combine CF returned nothing. Continuing loop." <<endl; continue; } TVectorD finalCount(1); finalCount[0] = totalCounts; cout<<"Writing combined CF "<<combinedCF->GetName() <<" to "<<mergeDir->GetName()<<endl; combinedCF->SetDirectory(0); mergeDir->cd(); combinedCF->Write(combinedCF->GetName(), TObject::kOverwrite); finalCount.Write(countName, TObject::kOverwrite); } }
void CombineLLAAForDirectory(TDirectory *dataDir) { // Run after merging centralities vector<TString> centBins = {"010", "1030", "3050"}; vector<TString> pairTypes = {"LamLam", "ALamALam"}; TString finalPairType = "LLAA"; // Get merge dir TDirectory *mergeDir = dataDir->GetDirectory("Merged"); if(!mergeDir) { cout<<"Merge directory does not exist. Cannot merge."<<endl; return; } for(UInt_t iCent = 0; iCent < centBins.size(); iCent++) { vector<TH1D*> cfs; vector<Double_t> counts; Double_t totalCounts = 0; for(UInt_t iType = 0; iType < pairTypes.size(); iType++) { TString cfName = "CF" + pairTypes[iType] + centBins[iCent]; TH1D *cf = (TH1D*)mergeDir->Get(cfName); if(!cf) { cout<<"Could not find CF named "<<cfName<<" in "<<mergeDir->GetName()<<endl; return; } cfs.push_back(cf); TString countName = "Count" + pairTypes[iType] + centBins[iCent]; TVectorD *count = (TVectorD*) mergeDir->Get(countName); totalCounts += count[0](0); counts.push_back(count[0](0)); } // Finally, combine the CFs TH1D *combinedCF = CombineCFs(cfs, counts); if (!combinedCF) { cout << "Combine CF returned nothing. Continuing loop." <<endl; continue; } TVectorD finalCount(1); finalCount[0] = totalCounts; // Set names TString combinedCFName = "CF" + finalPairType + centBins[iCent]; TString combinedCountName = "Count" + finalPairType + centBins[iCent]; combinedCF->SetName(combinedCFName); combinedCF->SetTitle(combinedCFName); // Set axis ranges combinedCF->SetAxisRange(0.9, 1.1, "Y"); combinedCF->SetAxisRange(0., 1., "X"); cout<<"Writing combined CF "<<combinedCF->GetName() <<" to "<<mergeDir->GetName()<<endl; combinedCF->SetDirectory(0); mergeDir->cd(); combinedCF->Write(combinedCF->GetName(), TObject::kOverwrite); finalCount.Write(combinedCountName, TObject::kOverwrite); } }
void CombineCentralitiesForDirectory(TString pairType, TDirectory *dataDir) { // Gather the cfs and counts to combine centrality bins vector<TString> centBins010 = {"05", "510"}; vector<TString> centBins1030 = {"1015", "1520", "2025", "2530"}; vector<TString> centBins3050 = {"3035", "3540", "4045", "4550"}; vector<TString> finalCentBins = {"010", "1030", "3050"}; vector<vector<TString> > centBins; centBins.push_back(centBins010); centBins.push_back(centBins1030); centBins.push_back(centBins3050); TDirectory *mergeDir = dataDir->GetDirectory("Merged"); if(!mergeDir) { cout<<"Merge directory does not exist. Cannot merge."<<endl; return; } //For each merge group, get the necessary CFs and counts for(UInt_t iMerge = 0; iMerge < centBins.size(); iMerge++) { vector<TH1D*> cfs; vector<Double_t> counts; Double_t totalCounts = 0; for(UInt_t iCF = 0; iCF < centBins[iMerge].size(); iCF++) { TString cfName = "CF" + pairType + centBins[iMerge][iCF]; TH1D *cf = (TH1D*)mergeDir->Get(cfName); if(!cf) { cout<<"Could not find CF named "<<cfName<<" in "<<mergeDir->GetName()<<endl; return; } cfs.push_back(cf); TString countName = "Count" + pairType + centBins[iMerge][iCF]; TVectorD *count = (TVectorD*) mergeDir->Get(countName); totalCounts += count[0](0); counts.push_back(count[0](0)); } // Finally, combine the CFs TH1D *combinedCF = CombineCFs(cfs, counts); if (!combinedCF) { cout << "Combine CF returned nothing. Continuing loop." <<endl; continue; } TVectorD finalCount(1); finalCount[0] = totalCounts; // Set names TString combinedCFName = "CF" + pairType + finalCentBins[iMerge]; TString combinedCountName = "Count" + pairType + finalCentBins[iMerge]; combinedCF->SetName(combinedCFName); combinedCF->SetTitle(combinedCFName); // Set axis ranges combinedCF->SetAxisRange(0.9, 1.1, "Y"); combinedCF->SetAxisRange(0., .5, "X"); combinedCF->SetLabelSize(0.05, "X"); combinedCF->SetLabelSize(0.05, "Y"); combinedCF->SetTitleSize(0.05, "X"); combinedCF->SetNdivisions(505, "X"); combinedCF->SetNdivisions(505, "Y"); cout<<"Writing combined CF "<<combinedCF->GetName() <<" to "<<mergeDir->GetName()<<endl; combinedCF->SetDirectory(0); mergeDir->cd(); combinedCF->Write(combinedCF->GetName(), TObject::kOverwrite); finalCount.Write(combinedCountName, TObject::kOverwrite); } }
TString* get_var_names( Int_t nVars ) { const TString directories[6] = { "InputVariables_NoTransform", "InputVariables_DecorrTransform", "InputVariables_PCATransform", "InputVariables_Id", "InputVariables_Norm", "InputVariables_Deco"}; TDirectory* dir = 0; for (Int_t i=0; i<6; i++) { dir = (TDirectory*)Network_GFile->Get( directories[i] ); if (dir != 0) break; } if (dir==0) { cout << "*** Big troubles in macro \"network.C\": could not find directory for input variables, " << "and hence could not determine variable names --> abort" << endl; return 0; } cout << "--> go into directory: " << dir->GetName() << endl; dir->cd(); TString* vars = new TString[nVars]; Int_t ivar = 0; // loop over all objects in directory TIter next(dir->GetListOfKeys()); TKey* key = 0; while ((key = (TKey*)next())) { if (key->GetCycle() != 1) continue; if(!TString(key->GetName()).Contains("__S") && !TString(key->GetName()).Contains("__r")) continue; // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; TH1 *sig = (TH1*)key->ReadObj(); TString hname = sig->GetTitle(); vars[ivar] = hname; ivar++; if (ivar > nVars-1) break; } if (ivar != nVars-1) { // bias layer is also in nVars counts cout << "*** Troubles in \"network.C\": did not reproduce correct number of " << "input variables: " << ivar << " != " << nVars << endl; } return vars; // ------------- old way (not good) ------------- // TString fname = "weights/TMVAnalysis_MLP.weights.txt"; // ifstream fin( fname ); // if (!fin.good( )) { // file not found --> Error // cout << "Error opening " << fname << endl; // exit(1); // } // Int_t idummy; // Float_t fdummy; // TString dummy = ""; // // file header with name // while (!dummy.Contains("#VAR")) fin >> dummy; // fin >> dummy >> dummy >> dummy; // the rest of header line // // number of variables // fin >> dummy >> idummy; // // at this point, we should have idummy == nVars // // variable mins and maxes // TString* vars = new TString[nVars]; // for (Int_t i = 0; i < idummy; i++) fin >> vars[i] >> dummy >> dummy >> dummy; // fin.close(); // return vars; }
void stackPlotter::plot(TString histname, TString legpos_string) { std::vector<int> colors; //colors.push_back(kAzure+3); //colors.push_back(kOrange+3); //colors.push_back(kSpring-7); //colors.push_back(kOrange-3); //colors.push_back(kCyan-5); //colors.push_back(kPink-6); //colors.push_back(kViolet+6); //colors.push_back(kYellow-9); colors.push_back(kCyan-6); colors.push_back(kYellow-9); colors.push_back(kMagenta-8); colors.push_back(kRed-7); colors.push_back(kAzure-4); colors.push_back(kOrange-3); colors.push_back(kSpring+5); colors.push_back(kMagenta-10); colors.push_back(kGray); colors.push_back(kMagenta-2); colors.push_back(kGreen-8); colors.push_back(kYellow-7); // set legpos: legendposition legpos; if(legpos_string == "t") legpos = lp_top; if(legpos_string == "l") legpos = lp_left; if(legpos_string == "r") legpos = lp_right; if(debug) std::cout << "stackPlotter::plot" << std::endl; TH1::AddDirectory(kFALSE); TDirectory::AddDirectory(kFALSE); gROOT->SetBatch(true); TFile *fIn = new TFile(infile_,"READ"); fIn->cd(); if(debug) std::cout << "stackPlotter::plot || input file '" << infile_ << "' is being read..." << std::endl; TIter dirIter(fIn->GetListOfKeys()); TObject *cDirObj; TKey *key; // iterate over directories and get all stacks int count = 0; while((key = (TKey *) dirIter())) { cDirObj=fIn->Get(key->GetName()); if(!cDirObj->InheritsFrom(TDirectory::Class())) continue; TDirectory* cDir = (TDirectory*) cDirObj; if(debug) std::cout << "stackPlotter::plot || Moving histograms from directory " << cDir->GetName() << " to relevant maps." << std::endl; moveDirHistsToStacks(cDir, histname, colors.at(count)); count++; } if(debug) std::cout << "stackPlotter::plot || input file '" << infile_ << "' has been read. Closing..." << std::endl; // intermediate cleanup fIn->Close(); delete fIn; if(debug) std::cout << "stackPlotter::plot || Closed. Saving output..." << std::endl; // create the outfile if need be if(savecanvases_) { if(debug) std::cout << "stackPlotter::plot || Opening output ROOT file" << std::endl; TString writeOption = rewriteoutfile_ ? "RECREATE" : "UPDATE"; outfile_ = new TFile(outdir_+"/plotter.root",writeOption); } // plot all the stacks & save appropriately if(debug) std::cout << "stackPlotter::plot || Plotting all the canvases" << std::endl; for(const auto& it : stacksLegEntries_) { plotStack(it.first, legpos); } // close, save, and cleanup if(savecanvases_ && outfile_) { if(debug) std::cout << "stackPlotter::plot || Closing the outfile" << std::endl; outfile_->Close(); } if(debug) std::cout << "stackPlotter::plot || Done!" << std::endl; }
TH1* GetCentK(TDirectory* top, Double_t c1, Double_t c2, Int_t s, TLegend* l) { TString dname; dname.Form("cent%06.2f_%06.2f", c1, c2); dname.ReplaceAll(".", "d"); TDirectory* d = top->GetDirectory(dname); if (!d) { Warning("GetCetnK", "Directory %s not found in %s", dname.Data(), top->GetName()); return; } TDirectory* det = d->GetDirectory("details"); if (!det) { Warning("GetCetnK", "Directory details not found in %s", d->GetName()); d->ls(); return; } TObject* o = det->Get("scalar"); if (!o) { Warning("GetCetnK", "Object scalar not found in %s", det->GetName()); return; } if (!o->IsA()->InheritsFrom(TH1::Class())) { Warning("GetCetnK", "Object %s is not a TH1, but a %s", o->GetName(), o->ClassName()); return; } TH1* h = static_cast<TH1*>(o->Clone()); Color_t col = cc[(s-1)%10]; h->SetLineColor(col); h->SetMarkerColor(col); h->SetFillColor(col); h->SetFillStyle(1001); // h->SetTitle(Form("%5.2f-%5.2f%% #times %d", c1, c2, s)); h->SetTitle(Form("%2.0f-%2.0f%% + %d", c1, c2, s-1)); TF1* f = new TF1("", "[0]",-2.2,2.2); f->SetParameter(0,s-1); f->SetLineColor(col); f->SetLineStyle(7); f->SetLineWidth(1); // h->Scale(s); h->Add(f); h->GetListOfFunctions()->Add(f); f->SetParameter(0,s); for (Int_t i = 1; i <= h->GetNbinsX(); i++) { if (TMath::Abs(h->GetBinCenter(i)) > 2) { h->SetBinContent(i,0); h->SetBinError(i,0); } } TLegendEntry* e = l->AddEntry(h, h->GetTitle(), "f"); e->SetFillColor(col); e->SetFillStyle(1001); e->SetLineColor(col); return h; }
/// /// Process a directory recursively. /// void html_a_directory(TDirectory *f, TString path, TEnv *params) { TCanvas *c_h1 = 0; if (c_h1 == 0) { int x = params->GetValue("H1.XSize", 150); int y = params->GetValue("H1.YSize", 100); c_h1 = new TCanvas ("c_h1", "1d plots", x, y); } /// /// Check how to make gif plots /// char command[512]; sprintf(command, "which pstoimg &> /dev/null"); bool UsePstoimg = ! system(command); /// /// Generate the output directory /// gSystem->MakeDirectory (path); /// /// Get the html started /// ofstream html (path + "/index.html"); html << "<html><head><title>" << f->GetName() << "</title></head>" << endl; html << "<body>" << endl; html << "<h1>" << f->GetName() << "</h1>" << endl; cout << "Processing directory " << f->GetName() << endl; /// /// Now loop over all the keys in the directory /// f->cd(); TList *objlist = f->GetListOfKeys(); objlist->Sort(); // order alphabetically, instead of order in which they were written TIterator *itr = objlist->MakeIterator(); TKey *key; while ((key = static_cast<TKey*>(itr->Next())) != 0) { TObject *obj = key->ReadObj(); if (obj->IsA()->InheritsFrom("TDirectory")) { TDirectory *d = static_cast<TDirectory*>(obj); html << "<br><a href=\"" << d->GetName() << "/\">" << d->GetName() << "</a>" << endl; html_a_directory(d, path + "/" + d->GetName(), params); } else if (obj->IsA()->InheritsFrom("TObjString")) { TObjString *s = static_cast<TObjString*>(obj); html << "<p><h2>" << key->GetName() << "</h2>" << endl; //html << "<blockquote><pre>" << static_cast<char*>(s->GetString()) // << "</pre></blockquote></p>" // << endl; html << "<blockquote><pre>" << (s->GetString()).Data() << "</pre></blockquote></p>"<< endl; } // else if (obj->IsA()->InheritsFrom("CutFlowTable")) { // CutFlowTable *c = static_cast<CutFlowTable*> (obj); // // html << "<p><h2>" << key->GetName() << "</h2>" << endl; // // CFTPrinterHTML txt (html); // f->cd(); // c->PrintGlobal (txt, "All Events", ""); // html << "</p>" << endl; // } else if (obj->IsA()->InheritsFrom("TCanvas")) { TCanvas *cnv = static_cast<TCanvas*>(obj); cnv->Draw(); cnv->SaveAs(path + "/" + key->GetName() + ".eps"); if (UsePstoimg) { sprintf(command, "pstoimg -type=gif %s &> /dev/null",(path + "/" + key->GetName() + ".eps").Data()); if (system(command) != 0) { cout<<"Could not convert to gif: "<<path + "/" + key->GetName() + ".eps"<<endl; abort(); } } else cnv->SaveAs(path + "/" + key->GetName() + ".gif"); cnv->Close(); html << "<p><a href=\"" << key->GetName() << ".eps\">"; html << "<img src=\"" << key->GetName() << ".gif\">"; html << "</a> <br> " << key->GetName() << ".gif </p>" << endl; } else if (obj->IsA()->InheritsFrom("TH1") && !(obj->IsA()->InheritsFrom("TH2"))) { TH1 *h = static_cast<TH1*> (obj); c_h1->cd(); h->Draw(); c_h1->SaveAs(path + "/" + key->GetName() + ".eps"); if (UsePstoimg) { sprintf(command, "pstoimg -type=gif %s &> /dev/null",(path + "/" + key->GetName() + ".eps").Data()); if (system(command) != 0) { cout<<"Could not convert to gif: "<<path + "/" + key->GetName() + ".eps"<<endl; abort(); } } else c_h1->SaveAs(path + "/" + key->GetName() + ".gif"); html << "<p><a href=\"" << key->GetName() << ".eps\">"; html << "<img src=\"" << key->GetName() << ".gif\">"; html << "</a> <br> " << key->GetName() << ".gif </p>" << endl; } f->cd(); } /// /// Done! /// html << "</body></html>" << endl; html.close(); }
/* * this script takes 2 TStrings as root filenames as a parameters * basic functionality: * loop through all directories (the mass bins) in the root file * -> create difference plots * -> create global plots * -> create 2D diff vs mass plots * -> etc... */ void plotGlobalWeightedEvts_Kpipi(TString input_filename, TString output_filename) { setupBookies(); gROOT->SetStyle("Plain"); gStyle->SetTitleFont(10*13+2,"xyz"); gStyle->SetTitleSize(0.06, "xyz"); gStyle->SetTitleOffset(1.3,"y"); gStyle->SetTitleOffset(1.3,"z"); gStyle->SetLabelFont(10*13+2,"xyz"); gStyle->SetLabelSize(0.06,"xyz"); gStyle->SetLabelOffset(0.009,"xyz"); gStyle->SetPadBottomMargin(0.16); gStyle->SetPadTopMargin(0.16); gStyle->SetPadLeftMargin(0.16); gStyle->SetPadRightMargin(0.16); gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gROOT->ForceStyle(); gStyle->SetFrameFillColor(0); gStyle->SetFrameFillStyle(0); TGaxis::SetMaxDigits(3); //IsPhDStyle = true; int massbins =0; double mass= 0.0, massstart =1000.0, massend=0.0; std::map<std::string, std::pair<double, std::pair<double, double> > > diffbounds; TFile* infile = TFile::Open(input_filename, "READ"); TFile* outfile = new TFile(output_filename, "RECREATE"); outfile->mkdir("global"); TList *dirlist = infile->GetListOfKeys(); massbins = dirlist->GetSize(); infile->cd(); TIter diriter(dirlist); TDirectory *dir; std::cout<< "scanning directories and creating overview canvases..." <<std::endl; while ((dir = (TDirectory *)diriter())) { std::string dirname = dir->GetName(); // check if directory is mass bin dir unsigned int pointpos = dirname.find("."); if(pointpos == 0 || pointpos == dirname.size()) continue; std::string masslow = dirname.substr(0, pointpos+1); std::string masshigh = dirname.substr(pointpos+1); double massstarttemp = atof(masslow.c_str())/1000; double massendtemp = atof(masshigh.c_str())/1000; if((int)(massendtemp - massstarttemp) != massbinwidth) massbinwidth = (int)(massendtemp - massstarttemp); mass = (massstarttemp + massendtemp)/2; if(massstart > massstarttemp) massstart = massstarttemp; if(massend < massendtemp) massend = massendtemp; outfile->cd(); outfile->mkdir(dir->GetName()); infile->cd(dir->GetName()); // make list of MC Histograms TList mclist; TList *histlist = gDirectory->GetListOfKeys(); TIter histiter(histlist); TObject *obj; while ((obj = histiter())) { TString s(obj->GetName()); if(s.EndsWith("MC")) mclist.Add(obj); else if(s.Contains("MC_")) mclist.Add(obj); } make1DOverviewCanvas(infile, outfile, &mclist, dirname); histiter = TIter(&mclist); TH1D *diffhist, *mchist; while ((mchist = (TH1D*)histiter())) { // generate difference histograms std::string hnamemc(mchist->GetName()); // create new string with MC exchanged for Diff std::string hnamediff(hnamemc); int pos = hnamemc.find("MC"); hnamediff.erase(pos, 2); hnamediff.insert(pos, "Diff"); infile->GetObject((std::string(dir->GetName())+"/"+hnamediff).c_str(), diffhist); if (diffhist) { // get diff min max values std::pair<double, std::pair<double, double> > p; bool change =false; double maxdiff = diffhist->GetMaximum(); double maxdifftemp = diffhist->GetMinimum(); if(abs(maxdifftemp) > maxdiff) maxdiff = maxdifftemp; double diffmintemp = diffhist->GetXaxis()->GetXmin(); double diffmaxtemp = diffhist->GetXaxis()->GetXmax(); std::map<std::string, std::pair<double, std::pair<double, double> > >::iterator iter = diffbounds.find( diffhist->GetName()); if (iter != diffbounds.end()) { p.first = iter->second.first; p.second.first = iter->second.second.first; p.second.second = iter->second.second.second; if (iter->second.first < maxdiff) { change = true; p.first = maxdiff; } if (iter->second.second.first > diffmintemp) { change = true; p.second.first = diffmintemp; } if (iter->second.second.second < diffmaxtemp) { change = true; p.second.second = diffmaxtemp; } if (change) { diffbounds[diffhist->GetName()] = p; } } else { p.first = maxdiff; p.second.first = diffmintemp; p.second.second = diffmaxtemp; diffbounds.insert(std::pair<std::string, std::pair<double, std::pair<double, double> > >(diffhist->GetName(), p)); } } } histiter = TIter(&mclist); TH2D *reldiffhist2d, *diffhist2d, *mchist2d, *datahist2d; while ((mchist2d = (TH2D*) histiter())) { // generate difference histograms std::string hnamemc(mchist2d->GetName()); // create new string with MC exchanged for Diff std::string hnamediff(hnamemc); int pos = hnamemc.find("MC"); hnamediff.erase(pos, 2); hnamediff.insert(pos, "Diff"); // create new string with MC exchanged for RelDiff std::string hnamereldiff(hnamemc); hnamereldiff.erase(pos, 2); hnamereldiff.insert(pos, "RelDiff"); // create new string with MC exchanged for Data std::string hnamedata(hnamemc); hnamedata.erase(pos, 2); hnamedata.insert(pos, "Data"); infile->GetObject((std::string(dir->GetName()) + "/" + hnamereldiff).c_str(), reldiffhist2d); infile->GetObject((std::string(dir->GetName()) + "/" + hnamediff).c_str(), diffhist2d); infile->GetObject((std::string(dir->GetName()) + "/" + hnamedata).c_str(), datahist2d); infile->GetObject((std::string(dir->GetName()) + "/" + hnamemc).c_str(), mchist2d); outfile->cd(dir->GetName()); make2DOverviewCanvas(mchist2d, datahist2d, diffhist2d, reldiffhist2d, mass); } } dirlist = infile->GetListOfKeys(); infile->cd(); diriter = TIter(dirlist); std::cout << "creating global histograms and 2D diff vs mass plots..." << std::endl; while ((dir = (TDirectory *) diriter())) { std::string dirname = dir->GetName(); // check if directory is mass bin dir unsigned int pointpos = dirname.find("."); if (pointpos == 0 || pointpos == dirname.size()) continue; infile->cd(dir->GetName()); // make list of MC Histograms TList mclist; TList *histlist = gDirectory->GetListOfKeys(); TIter histiter(histlist); TObject *obj; while ((obj = histiter())) { TString s(obj->GetName()); if (s.EndsWith("MC")) mclist.Add(obj); else if (s.Contains("MC_")) mclist.Add(obj); } histiter = TIter(&mclist); TH1D *hist; TH1D *diffhist, *mchist, *datahist; while ((hist = (TH1D*) histiter())) { // generate difference histograms std::string hnamemc(hist->GetName()); // create new string with MC exchanged for Diff std::string hname(hnamemc); int pos = hnamemc.find("MC"); hname.erase(pos, 2); hname.insert(pos, "Diff"); // create new string with MC exchanged for Data std::string hnamedata(hnamemc); hnamedata.erase(pos, 2); hnamedata.insert(pos, "Data"); // create new string for MC Global Histogram std::string hnamemcglob(hnamemc); hnamemcglob.insert(pos + 2, "Global"); // create new string for MC Global Histogram std::string hnamedataglob(hnamemc); hnamedataglob.erase(pos, 2); hnamedataglob.insert(pos, "DataGlobal"); infile->GetObject((std::string(dir->GetName()) + "/" + hname + ";1").c_str(), diffhist); infile->GetObject((std::string(dir->GetName()) + "/" + hnamedata + ";1").c_str(), datahist); infile->GetObject((std::string(dir->GetName()) + "/" + hnamemc + ";1").c_str(), mchist); if (datahist) { // make global histograms in global folder outfile->cd("global"); TH1D* hmcglob = (TH1D*) outfile->Get(std::string("global/"+hnamemcglob).c_str()); if (hmcglob == NULL) hmcglob = new TH1D(hnamemcglob.c_str(), mchist->GetTitle(), mchist->GetNbinsX(), mchist->GetXaxis()->GetXmin(), mchist->GetXaxis()->GetXmax()); hmcglob->Add(mchist); TH1D* hdataglob = (TH1D*) outfile->Get(std::string("global/"+hnamedataglob).c_str()); if (hdataglob == NULL) hdataglob = new TH1D(hnamedataglob.c_str(), datahist->GetTitle(), datahist->GetNbinsX(), datahist->GetXaxis()->GetXmin(), datahist->GetXaxis()->GetXmax()); hdataglob->Add(datahist); // make diff vs. mass plots fillDiffvsMassPlot(diffhist, dir->GetName(), massbins, massstart, massend, diffbounds, outfile); } } histiter = TIter(&mclist); TH2D *mchist2d, *datahist2d; while ((mchist2d = (TH2D*) histiter())) { // generate difference histograms std::string hnamemc(mchist2d->GetName()); // create new string with MC exchanged for Diff std::string hnamediff(hnamemc); int pos = hnamemc.find("MC"); hnamediff.erase(pos, 2); hnamediff.insert(pos, "Diff"); // create new string with MC exchanged for Data std::string hnamedata(hnamemc); hnamedata.erase(pos, 2); hnamedata.insert(pos, "Data"); // create new string for MC Global Histogram std::string hnamemcglob(hnamemc); hnamemcglob.insert(pos + 2, "Global"); // create new string for MC Global Histogram std::string hnamedataglob(hnamemc); hnamedataglob.erase(pos, 2); hnamedataglob.insert(pos, "DataGlobal"); infile->GetObject((std::string(dir->GetName()) + "/" + hnamedata + ";1").c_str(), datahist2d); infile->GetObject((std::string(dir->GetName()) + "/" + hnamemc + ";1").c_str(), mchist2d); if (datahist2d) { // make global histograms in global folder outfile->cd("global"); TH2D* hmcglob = (TH2D*) outfile->Get(std::string("global/" + hnamemcglob).c_str()); if (hmcglob == NULL) { hmcglob = new TH2D(hnamemcglob.c_str(), mchist2d->GetTitle(), mchist->GetNbinsX(), mchist2d->GetXaxis()->GetXmin(), mchist2d->GetXaxis()->GetXmax(), mchist2d->GetNbinsY(), mchist2d->GetYaxis()->GetXmin(), mchist2d->GetYaxis()->GetXmax()); hmcglob->SetXTitle(mchist2d->GetXaxis()->GetTitle()); hmcglob->SetYTitle(mchist2d->GetYaxis()->GetTitle()); } hmcglob->Add(mchist2d); TH2D* hdataglob = (TH2D*) outfile->Get(std::string("global/" + hnamedataglob).c_str()); if (hdataglob == NULL) { hdataglob = new TH2D(hnamedataglob.c_str(), datahist2d->GetTitle(), datahist2d->GetNbinsX(), datahist2d->GetXaxis()->GetXmin(), datahist2d->GetXaxis()->GetXmax(), datahist2d->GetNbinsY(), datahist2d->GetYaxis()->GetXmin(), datahist2d->GetYaxis()->GetXmax()); hdataglob->SetXTitle(datahist2d->GetXaxis()->GetTitle()); hdataglob->SetYTitle(datahist2d->GetYaxis()->GetTitle()); } hdataglob->Add(datahist2d); } } } makeBookies(); std::cout<< "saving to disk..." <<std::endl; outfile->Write(); std::cout<< "done!" <<std::endl; /*// ok lets make a canvas and plug some plots into it -> add to booky TCanvas* c = new TCanvas("KineValidate" + massbin, "Weighted Events", 10, 10, 600, 800); c->Divide(4, 4); // first column contains neutral isobar histograms c->cd(1); double totMC = GJHB_neutral_isobar.isobar_mass[0]->Integral(); double totDATA = GJHB_neutral_isobar.isobar_mass[1]->Integral(); if (totMC != 0) GJHB_neutral_isobar.isobar_mass[0]->Scale(totDATA / totMC); GJHB_neutral_isobar.isobar_mass[0]->SetLineColor(kRed); GJHB_neutral_isobar.isobar_mass[0]->SetFillColor(kRed); GJHB_neutral_isobar.isobar_mass[0]->Draw("E4"); TH1D* hDiffMIsobar = new TH1D(*GJHB_neutral_isobar.isobar_mass[0]); hDiffMIsobar->Add(GJHB_neutral_isobar.isobar_mass[1], -1.); GJHB_neutral_isobar.isobar_mass[1]->Draw("same"); hDiffMIsobar->SetLineColor(kOrange - 3); hDiffMIsobar->Draw("same"); GJHB_neutral_isobar.isobar_mass[0]->GetYaxis()->SetRangeUser(hDiffMIsobar->GetMinimum() * 1.5, GJHB_neutral_isobar.isobar_mass[0]->GetMaximum() * 1.2); gPad->Update(); c->cd(5); totMC = GJHB_neutral_isobar.costheta_GJF[0]->Integral(); totDATA = GJHB_neutral_isobar.costheta_GJF[1]->Integral(); if (totMC != 0) GJHB_neutral_isobar.costheta_GJF[0]->Scale(totDATA / totMC); GJHB_neutral_isobar.costheta_GJF[0]->SetLineColor(kRed); GJHB_neutral_isobar.costheta_GJF[0]->SetFillColor(kRed); GJHB_neutral_isobar.costheta_GJF[0]->Draw("E4"); GJHB_neutral_isobar.costheta_GJF[1]->Draw("same E"); totMC = GJHB_neutral_isobar.costheta_GJF_MC_raw->Integral(); GJHB_neutral_isobar.costheta_GJF_MC_raw->Scale(totDATA / totMC); GJHB_neutral_isobar.costheta_GJF_MC_raw->Draw("same"); GJHB_neutral_isobar.costheta_GJF[0]->GetYaxis()->SetRangeUser(0, GJHB_neutral_isobar.costheta_GJF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(9); totMC = GJHB_neutral_isobar.phi_GJF[0]->Integral(); totDATA = GJHB_neutral_isobar.phi_GJF[1]->Integral(); GJHB_neutral_isobar.phi_GJF[0]->Sumw2(); if (totMC != 0) GJHB_neutral_isobar.phi_GJF[0]->Scale(totDATA / totMC); GJHB_neutral_isobar.phi_GJF[0]->SetLineColor(kRed); GJHB_neutral_isobar.phi_GJF[0]->SetFillColor(kRed); GJHB_neutral_isobar.phi_GJF[0]->Draw("E4"); GJHB_neutral_isobar.phi_GJF[1]->Draw("same E"); GJHB_neutral_isobar.phi_GJF[0]->GetYaxis()->SetRangeUser(0, GJHB_neutral_isobar.phi_GJF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(13); totMC = HHB_neutral_isobar.costheta_HF[0]->Integral(); totDATA = HHB_neutral_isobar.costheta_HF[1]->Integral(); HHB_neutral_isobar.costheta_HF[0]->Sumw2(); if (totMC != 0) HHB_neutral_isobar.costheta_HF[0]->Scale(totDATA / totMC); HHB_neutral_isobar.costheta_HF[0]->SetLineColor(kRed); HHB_neutral_isobar.costheta_HF[0]->SetFillColor(kRed); HHB_neutral_isobar.costheta_HF[0]->Draw("E4"); HHB_neutral_isobar.costheta_HF[1]->Draw("same E"); HHB_neutral_isobar.costheta_HF[0]->GetYaxis()->SetRangeUser(0, HHB_neutral_isobar.costheta_HF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(15); totMC = HHB_neutral_isobar.phi_HF[0]->Integral(); totDATA = HHB_neutral_isobar.phi_HF[1]->Integral(); HHB_neutral_isobar.phi_HF[0]->Sumw2(); if (totMC != 0) HHB_neutral_isobar.phi_HF[0]->Scale(totDATA / totMC); HHB_neutral_isobar.phi_HF[0]->SetLineColor(kRed); HHB_neutral_isobar.phi_HF[0]->SetFillColor(kRed); HHB_neutral_isobar.phi_HF[0]->Draw("E4"); HHB_neutral_isobar.phi_HF[1]->Draw("same E"); HHB_neutral_isobar.phi_HF[0]->GetYaxis()->SetRangeUser(0, HHB_neutral_isobar.phi_HF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(2); totMC = GJHB_charged_isobar.isobar_mass[0]->Integral(); totDATA = GJHB_charged_isobar.isobar_mass[1]->Integral(); if (totMC != 0) GJHB_charged_isobar.isobar_mass[0]->Scale(totDATA / totMC); GJHB_charged_isobar.isobar_mass[0]->SetLineColor(kRed); GJHB_charged_isobar.isobar_mass[0]->SetFillColor(kRed); GJHB_charged_isobar.isobar_mass[0]->Draw("E4"); TH1D* hDiffMIsobar2 = new TH1D(*GJHB_charged_isobar.isobar_mass[0]); hDiffMIsobar2->Add(GJHB_charged_isobar.isobar_mass[1], -1.); GJHB_charged_isobar.isobar_mass[1]->Draw("same"); hDiffMIsobar2->SetLineColor(kOrange - 3); hDiffMIsobar2->Draw("same"); GJHB_charged_isobar.isobar_mass[0]->GetYaxis()->SetRangeUser(hDiffMIsobar->GetMinimum() * 1.5, GJHB_charged_isobar.isobar_mass[0]->GetMaximum() * 1.2); gPad->Update(); c->cd(6); totMC = GJHB_charged_isobar.costheta_GJF[0]->Integral(); totDATA = GJHB_charged_isobar.costheta_GJF[1]->Integral(); //hGJ[0]->Sumw2(); if (totMC != 0) GJHB_charged_isobar.costheta_GJF[0]->Scale(totDATA / totMC); GJHB_charged_isobar.costheta_GJF[0]->SetLineColor(kRed); GJHB_charged_isobar.costheta_GJF[0]->SetFillColor(kRed); GJHB_charged_isobar.costheta_GJF[0]->Draw("E4"); GJHB_charged_isobar.costheta_GJF[1]->Draw("same E"); totMC = GJHB_charged_isobar.costheta_GJF_MC_raw->Integral(); GJHB_charged_isobar.costheta_GJF_MC_raw->Scale(totDATA / totMC); GJHB_charged_isobar.costheta_GJF_MC_raw->Draw("same"); GJHB_charged_isobar.costheta_GJF[0]->GetYaxis()->SetRangeUser(0, GJHB_charged_isobar.costheta_GJF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(10); totMC = GJHB_charged_isobar.phi_GJF[0]->Integral(); totDATA = GJHB_charged_isobar.phi_GJF[1]->Integral(); GJHB_charged_isobar.phi_GJF[0]->Sumw2(); if (totMC != 0) GJHB_charged_isobar.phi_GJF[0]->Scale(totDATA / totMC); GJHB_charged_isobar.phi_GJF[0]->SetLineColor(kRed); GJHB_charged_isobar.phi_GJF[0]->SetFillColor(kRed); GJHB_charged_isobar.phi_GJF[0]->Draw("E4"); GJHB_charged_isobar.phi_GJF[1]->Draw("same E"); GJHB_charged_isobar.phi_GJF[0]->GetYaxis()->SetRangeUser(0, GJHB_charged_isobar.phi_GJF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(14); totMC = HHB_charged_isobar.costheta_HF[0]->Integral(); totDATA = HHB_charged_isobar.costheta_HF[1]->Integral(); HHB_charged_isobar.costheta_HF[0]->Sumw2(); if (totMC != 0) HHB_charged_isobar.costheta_HF[0]->Scale(totDATA / totMC); HHB_charged_isobar.costheta_HF[0]->SetLineColor(kRed); HHB_charged_isobar.costheta_HF[0]->SetFillColor(kRed); HHB_charged_isobar.costheta_HF[0]->Draw("E4"); HHB_charged_isobar.costheta_HF[1]->Draw("same E"); HHB_charged_isobar.costheta_HF[0]->GetYaxis()->SetRangeUser(0, HHB_charged_isobar.costheta_HF[0]->GetMaximum() * 1.5); gPad->Update(); c->cd(16); totMC = HHB_charged_isobar.phi_HF[0]->Integral(); totDATA = HHB_charged_isobar.phi_HF[1]->Integral(); HHB_charged_isobar.phi_HF[0]->Sumw2(); if (totMC != 0) HHB_charged_isobar.phi_HF[0]->Scale(totDATA / totMC); HHB_charged_isobar.phi_HF[0]->SetLineColor(kRed); HHB_charged_isobar.phi_HF[0]->SetFillColor(kRed); HHB_charged_isobar.phi_HF[0]->Draw("E4"); HHB_charged_isobar.phi_HF[1]->Draw("same E"); HHB_charged_isobar.phi_HF[0]->GetYaxis()->SetRangeUser(0, HHB_charged_isobar.phi_HF[0]->GetMaximum() * 1.5); gPad->Update(); // add global diagrams c->cd(1); TLatex* Label = new TLatex(); Label->PaintLatex(2, GJHB_neutral_isobar.isobar_mass[0]->GetMaximum() * 0.8, 0, 0.1, massbin.Data()); c->Update(); TList* Hlist = gDirectory->GetList(); Hlist->Remove(mctr); Hlist->Remove(datatr); //Hlist->Remove("hWeights"); TFile* outfile = TFile::Open(outfilename, "UPDATE"); TString psFileName = outfilename; psFileName.ReplaceAll(".root", massbin); psFileName.Append(".ps"); if (totMC != 0) { // get mass-integrated plots (or create them if not there) // neutral isobar TH1D* hMIsobarMCGlob = (TH1D*) outfile->Get("hMIsobarMCGlob"); if (hMIsobarMCGlob == NULL) hMIsobarMCGlob = new TH1D("hMIsobarMCGlob", "2#pi neutral Isobar Mass (MC)", nbninsm, 0.2, 2.5); hMIsobarMCGlob->Add(GJHB_neutral_isobar.isobar_mass[0]); hMIsobarMCGlob->Write(); TH1D* hMIsobarDataGlob = (TH1D*) outfile->Get("hMIsobarDataGlob"); if (hMIsobarDataGlob == NULL) hMIsobarDataGlob = new TH1D("hMIsobarDataGlob", "2#pi neutral Isobar Mass (DATA)", nbninsm, 0.2, 2.5); hMIsobarDataGlob->Add(GJHB_neutral_isobar.isobar_mass[1]); hMIsobarDataGlob->Write(); TH1D* hGJMCGlob = (TH1D*) outfile->Get("hGJMCGlob"); if (hGJMCGlob == NULL) hGJMCGlob = new TH1D("hGJMCGlob", "Gottfried-Jackson Theta (MC)", nbinsang, -1, 1); hGJMCGlob->Add(GJHB_neutral_isobar.costheta_GJF[0]); hGJMCGlob->Write(); TH1D* hGJDataGlob = (TH1D*) outfile->Get("hGJDataGlob"); if (hGJDataGlob == NULL) hGJDataGlob = new TH1D("hGJDataGlob", "Gottfried-Jackson Theta (Data)", nbinsang, -1, 1); hGJDataGlob->Add(GJHB_neutral_isobar.costheta_GJF[1]); hGJDataGlob->Write(); TH1D* hTYMCGlob = (TH1D*) outfile->Get("hTYMCGlob"); if (hTYMCGlob == NULL) hTYMCGlob = new TH1D("hTYMCGlob", "Treiman-Yang Phi (MC)", nbinsang, -TMath::Pi(),TMath::Pi()); hTYMCGlob->Add(GJHB_neutral_isobar.phi_GJF[0]); hTYMCGlob->Write(); TH1D* hTYDataGlob = (TH1D*) outfile->Get("hTYDataGlob"); if (hTYDataGlob == NULL) hTYDataGlob = new TH1D("hTYDataGlob", "Treiman-Yang Phi (Data)", nbinsang, -TMath::Pi(),TMath::Pi()); hTYDataGlob->Add(GJHB_neutral_isobar.phi_GJF[1]); hTYDataGlob->Write(); c->cd(3); hMIsobarMCGlob->SetLineColor(kRed); hMIsobarMCGlob->SetFillColor(kRed); hMIsobarMCGlob->Draw("E4"); hMIsobarDataGlob->Draw("E SAME"); c->cd(7); hGJMCGlob->SetLineColor(kRed); hGJMCGlob->SetFillColor(kRed); hGJMCGlob->Draw("E4"); hGJDataGlob->Draw("E SAME"); c->cd(11); hTYMCGlob->SetLineColor(kRed); hTYMCGlob->SetFillColor(kRed); hTYMCGlob->Draw("E4"); hTYDataGlob->Draw("E SAME"); // charged isobar TH1D* hMIsobarMCGlob2 = (TH1D*) outfile->Get("hMIsobarMCGlob2"); if (hMIsobarMCGlob2 == NULL) hMIsobarMCGlob2 = new TH1D("hMIsobarMCGlob2", "2#pi charged Isobar Mass (MC)", nbninsm, 0.2, 2.5); hMIsobarMCGlob2->Add(GJHB_charged_isobar.isobar_mass[0]); hMIsobarMCGlob2->Write(); TH1D* hMIsobarDataGlob2 = (TH1D*) outfile->Get("hMIsobarDataGlob2"); if (hMIsobarDataGlob2 == NULL) hMIsobarDataGlob2 = new TH1D("hMIsobarDataGlob2", "2#pi charged Isobar mass (DATA)", nbninsm, 0.2, 2.5); hMIsobarDataGlob2->Add(GJHB_charged_isobar.isobar_mass[1]); hMIsobarDataGlob2->Write(); TH1D* hGJMCGlob2 = (TH1D*) outfile->Get("hGJMCGlob2"); if (hGJMCGlob2 == NULL) hGJMCGlob2 = new TH1D("hGJMCGlob2", "Gottfried-Jackson Theta (MC)", nbinsang, -1, 1); hGJMCGlob2->Add(GJHB_charged_isobar.costheta_GJF[0]); hGJMCGlob2->Write(); TH1D* hGJDataGlob2 = (TH1D*) outfile->Get("hGJDataGlob2"); if (hGJDataGlob2 == NULL) hGJDataGlob2 = new TH1D("hGJDataGlob2", "Gottfried-Jackson Theta (Data)", nbinsang, -1, 1); hGJDataGlob2->Add(GJHB_charged_isobar.costheta_GJF[1]); hGJDataGlob2->Write(); TH1D* hTYMCGlob2 = (TH1D*) outfile->Get("hTYMCGlob2"); if (hTYMCGlob2 == NULL) hTYMCGlob2 = new TH1D("hTYMCGlob2", "Treiman-Yang Phi (MC)", nbinsang, -TMath::Pi(),TMath::Pi()); hTYMCGlob2->Add(GJHB_charged_isobar.phi_GJF[0]); hTYMCGlob2->Write(); TH1D* hTYDataGlob2 = (TH1D*) outfile->Get("hTYDataGlob2"); if (hTYDataGlob2 == NULL) hTYDataGlob2 = new TH1D("hTYDataGlob2", "Treiman-Yang Phi (Data)", nbinsang, -TMath::Pi(),TMath::Pi()); hTYDataGlob2->Add(GJHB_charged_isobar.phi_GJF[1]); hTYDataGlob2->Write(); c->cd(4); hMIsobarMCGlob2->SetLineColor(kRed); hMIsobarMCGlob2->SetFillColor(kRed); hMIsobarMCGlob2->Draw("E4"); hMIsobarDataGlob2->Draw("E SAME"); c->cd(8); hGJMCGlob2->SetLineColor(kRed); hGJMCGlob2->SetFillColor(kRed); hGJMCGlob2->Draw("E4"); hGJDataGlob2->Draw("E SAME"); c->cd(12); hTYMCGlob2->SetLineColor(kRed); hTYMCGlob2->SetFillColor(kRed); hTYMCGlob2->Draw("E4"); hTYDataGlob2->Draw("E SAME"); } c->Write(); TCanvas dummyCanv("dummy", "dummy"); c->Print((psFileName));*/ }