/** * @brief Write all TObjects from a given TCollection into a certain directory structure in the file * * @param col pointer to a TCollection-based container * @param dirname name of a directory inside the output file to which the objects should be written * @param subdirname optional name of a subdirectory inside dirname to which the objects should be written * * This method whites all TObject-based objects contained in the TCollection-based container (see ROOT documentation) * into a directory whose name is given by dirname inside the output file. If dirname does not exist * in the output file, it will be created. Otherwise, contents of the col collection will be appended to an existing * directory. * * If the optional subdirectory name is specified (subdirname parameter, defaults to empty string) then the * contents of the collection will be written to "dirname/subdirname". If the "subdirname" directory does not * exist inside the "dirname" directory, it will be created. * */ void JPetWriter::writeCollection(const TCollection* col, const char* dirname, const char* subdirname) { TDirectory* current = fFile->GetDirectory(dirname); if (!current) { current = fFile->mkdir(dirname); } assert(current); // use a subdirectory if requested by user if (!std::string(subdirname).empty()) { if (current->GetDirectory(subdirname)) { current = current->GetDirectory(subdirname); } else { current = current->mkdir(subdirname); } } assert(current); current->cd(); TIterator* it = col->MakeIterator(); TObject* obj; while ((obj = it->Next())) { obj->Write(); } fFile->cd(); }
void store(){ if (!TClass::GetDict("NBD")) { gROOT->ProcessLine(".L /afs/cern.ch/user/q/qixu/CMSSW_6_2_5/src/Centrality/NBD_Glauber_fit/NBD/NBDclass.C+"); } TH1::AddDirectory(kFALSE); int Gth=atoi(getenv("GTH")); int sth=atoi(getenv("STH")); NBD *l; struct para1 var; if(sth==0){TString dirname = "std"; var = var1; if(Gth<nGlau) l = new NBD(datafile,stdGlaulist[Gth],histoname);else l = new NBD(datafile,stdGlaulist[0],histoname);} else if(sth==1){TString dirname ="Gri055"; var = var2; if(Gth<nGlau) l = new NBD(datafile,Gri055Glaulist[Gth],histoname);else l = new NBD(datafile,Gri055Glaulist[0],histoname);} else {TString dirname ="Gri101"; var = var3; if(Gth<nGlau) l = new NBD(datafile,Gri101Glaulist[Gth],histoname);else l = new NBD(datafile,Gri101Glaulist[0],histoname);} l->initmu(var.mumin,var.mumax,var.mustep); l->initk(var.kmin,var.kmax,var.kstep); if(Gth<nGlau) l->initx(var.xmin,var.xmax); else if(Gth-nGlau==0) l->initx(var.xmin-binshift,var.xmax); else l->initx(var.xmin+binshift,var.xmax); // l->fit(); if(sth==0) l->assign(bestlist1[Gth].mubest,bestlist1[Gth].kbest); else if(sth==1) l->assign(bestlist2[Gth].mubest,bestlist2[Gth].kbest); else l->assign(bestlist3[Gth].mubest,bestlist3[Gth].kbest); l->initN(bin,N,method); l->calcvar(); TFile *outfile = new TFile(outG,"Update"); if(Gth==0 && sth==0){ l->dataname.Write("dataname",TObject::kOverwrite); l->histoname.Write("histoname",TObject::kOverwrite); } TDirectory *dir = outfile->GetDirectory(dirname); if (!dir) {outfile->mkdir(dirname); TDirectory *dir = outfile->GetDirectory(dirname);} dir->cd(); TString name; if(Gth==0) name = "G0"; else if(Gth<nGlau) name = Form("Glau_%d",Gth); else name = Form("bin_%d",Gth-nGlau+1); TDirectory *subdir = dir->GetDirectory(name); if(!subdir) {dir->mkdir(name); TDirectory *subdir = dir->GetDirectory(name);} subdir->cd(); l->method.Write("method",TObject::kOverwrite); l->Glaubername.Write("Glaubername",TObject::kOverwrite); l->xmin.Write("xmin",TObject::kOverwrite);l->xmax.Write("xmax",TObject::kOverwrite); l->mubest.Write("mubest",TObject::kOverwrite);l->kbest.Write("kbest",TObject::kOverwrite); l->chis.Write("chis",TObject::kOverwrite);l->Ndf.Write("Ndf",TObject::kOverwrite); l->NcollAver.Write("NcollAver",TObject::kOverwrite);l->NpartAver.Write("NpartAver",TObject::kOverwrite);l->BAver.Write("BAver",TObject::kOverwrite); l->centbin.Write("centbin",TObject::kOverwrite); l->kpoint.Write("kpoint",TObject::kOverwrite); l->centbin_.Write("centbin_",TObject::kOverwrite); l->kpoint_.Write("kpoint_",TObject::kOverwrite); l->Npartdis->Write(); l->Grgrid->Write("Grgrid",TObject::kOverwrite); outfile->Close(); }
LjmetEventContent::~LjmetEventContent(){ // save tree mpTree->Write(); // save histograms std::map<std::string,std::map<std::string,LjmetEventContent::HistMetadata> >::iterator iMod; std::map<std::string,LjmetEventContent::HistMetadata>::iterator iHist; TDirectory * rootDir = mpTree->GetDirectory(); for (iMod=mDoubleHist.begin();iMod!=mDoubleHist.end();++iMod){ TDirectory * _dir = 0; _dir = rootDir->mkdir( iMod->first.c_str() ); if (!_dir) rootDir->GetDirectory( iMod->first.c_str() ); for (iHist=iMod->second.begin();iHist!=iMod->second.end();++iHist){ std::cout << mLegend << "Saving " << iMod->first << "/" << iHist->second.GetName() << std::endl; _dir->cd(); iHist->second.GetHist( )->SetDirectory(_dir); iHist->second.GetHist( )->Print(); iHist->second.GetHist( )->Write(); } } }
void store(int type, int sth=0, int Gth=0){ TH1::AddDirectory(kFALSE); NBD *l; struct para1 var; TString dirname; double sss=0.1; if(sth==0){ dirname = "std"; if(Gth<nGlau) l = new NBD(datafile,stdGlaulist[Gth],histoname); else l = new NBD(datafile,stdGlaulist[0],histoname); var = var1[Gth]; l->initmu(bestlist1[Gth].mubest-sss,bestlist1[Gth].mubest+sss,sss/5); l->initk(bestlist1[Gth].kbest-sss,bestlist1[Gth].kbest+sss,sss/5); l->initf(bestlist1[Gth].fbest-sss,bestlist1[Gth].fbest+sss,sss/5); } else if(sth==1){ dirname ="Gri055"; if(Gth<nGlau) l = new NBD(datafile,Gri055Glaulist[Gth],histoname); else l = new NBD(datafile,Gri055Glaulist[0],histoname); var = var2[Gth]; l->initmu(bestlist2[Gth].mubest-sss,bestlist2[Gth].mubest+sss,sss/5); l->initk(bestlist2[Gth].kbest-sss,bestlist2[Gth].kbest+sss,sss/5); l->initf(bestlist2[Gth].fbest-sss,bestlist2[Gth].fbest+sss,sss/5); } else { dirname ="Gri101"; if(Gth<nGlau) l = new NBD(datafile,Gri101Glaulist[Gth],histoname); else l = new NBD(datafile,Gri101Glaulist[0],histoname); var = var3[Gth]; l->initmu(bestlist3[Gth].mubest-sss,bestlist3[Gth].mubest+sss,sss/5); l->initk(bestlist3[Gth].kbest-sss,bestlist3[Gth].kbest+sss,sss/5); l->initf(bestlist3[Gth].fbest-sss,bestlist3[Gth].fbest+sss,sss/5); } //l->initmu(var.mumin,var.mumax,var.mustep); //l->initk(var.kmin,var.kmax,var.kstep); //l->initf(var.fmin,var.fmax,var.fstep); if(Gth<nGlau) l->initx(var.xmin,var.xmax); else if(Gth-nGlau==0) l->initx(var.xmin-binshift,var.xmax); else l->initx(var.xmin+binshift,var.xmax); if(type==0) l->fit(); if(type==1){ if(sth==0) l->assign(bestlist1[Gth].mubest,bestlist1[Gth].kbest,bestlist1[Gth].fbest); else if(sth==1) l->assign(bestlist2[Gth].mubest,bestlist2[Gth].kbest,bestlist2[Gth].fbest); else l->assign(bestlist3[Gth].mubest,bestlist3[Gth].kbest,bestlist3[Gth].fbest); l->initN(bin,N,method); l->calcvar(); TFile *outfile = new TFile(outG,"Update"); if(Gth==0 && sth==0){ l->dataname.Write("dataname",TObject::kOverwrite); l->histoname.Write("histoname",TObject::kOverwrite); } TDirectory *dir = (TDirectory*)outfile->GetDirectory(dirname); if (!dir) {outfile->mkdir(dirname); dir = (TDirectory*)outfile->GetDirectory(dirname);} dir->cd(); TString name; if(Gth==0) name = "G0"; else if(Gth<nGlau) name = Form("Glau_%d",Gth); else name = Form("bin_%d",Gth-nGlau+1); TDirectory *subdir = (TDirectory*)dir->GetDirectory(name); if(!subdir) {dir->mkdir(name); subdir = (TDirectory*)dir->GetDirectory(name);} subdir->cd(); l->method.Write("method",TObject::kOverwrite); l->Glaubername.Write("Glaubername",TObject::kOverwrite); l->xmin.Write("xmin",TObject::kOverwrite);l->xmax.Write("xmax",TObject::kOverwrite); l->mubest.Write("mubest",TObject::kOverwrite);l->kbest.Write("kbest",TObject::kOverwrite);l->fbest.Write("fbest",TObject::kOverwrite); l->chis.Write("chis",TObject::kOverwrite);l->Ndf.Write("Ndf",TObject::kOverwrite); l->NcollAver.Write("NcollAver",TObject::kOverwrite);l->NpartAver.Write("NpartAver",TObject::kOverwrite);l->BAver.Write("BAver",TObject::kOverwrite); l->centbin.Write("centbin",TObject::kOverwrite); l->kpoint.Write("kpoint",TObject::kOverwrite); l->centbin_.Write("centbin_",TObject::kOverwrite); l->kpoint_.Write("kpoint_",TObject::kOverwrite); l->Npartdis->Write("Npartdis",TObject::kSingleKey | TObject::kOverwrite); l->Grgrid->Write("Grgrid",TObject::kOverwrite); outfile->Close(); } }
void SubtractBgndRuns(TDirectory *fbg, TDirectory *fprod, const Char_t *foutname="", const std::string& bl_list="") { std::set<UInt_t> blacklist = GetBlackedChannels(bl_list); string basename = FindBaseName(fprod->GetName()); vector<TH1*> histbg = ROOTUtils::GetAllTH1InDirectory(fbg); ROOTUtils::EnforceProperOrdering(histbg); //GetAllHists(*fbg, false); FilterOutTDC(histbg); vector<TH1*> histprod = ROOTUtils::GetAllTH1InDirectory(fprod, Form("^((%s[0-9]+_shifted_norm_vclk)|(%s[0-9]+_norm_vclk_shifted))$",basename.data(),basename.data())); ROOTUtils::EnforceProperOrdering(histprod); //GetAllHists(*fprod, true); // for_each(histprod.begin(), histprod.end(), InspectSingleHistErrors); FilterOutTDC(histprod); EnforceAxisRangeConsistency(histbg, histprod); TDirectory *fout=0; string foname = foutname; if (foname.length()>0) { fout = TFile::Open(foname.data(),"UPDATE"); } else { TDirectory *basedir = GetBaseDir(fprod); if (dynamic_cast<TDirectoryFile*>(basedir)==0) { std::cerr << "Cannot identify the file" << std::endl; return; } string dname = FormOutputSubDirName(fprod->GetName()); fout = basedir->GetDirectory(dname.data()); if (fout==0) fout = basedir->mkdir(dname.data()); } TH1 *hbg=0, *h=0, *h_cl=0; for (UInt_t i=0; i<min(histbg.size(), histprod.size()); i++) { hbg = histbg.at(i); h = histprod.at(i); h_cl = static_cast<TH1*>(h->Clone(Form("normed_bgsubbed_%s%i",basename.data(), i))); if (blacklist.find(i)==blacklist.end()) { cout << histbg.at(i)->GetName() << " subbed from " << histprod.at(i)->GetName() << endl; h_cl->SetTitle(Form("Overnight Bgnd Subtracted ADC%i",i)); h_cl->Add(hbg,-1.0); // The next line is only valid if Sumw2 is not turned on // CalcErrors(h_cl, hbg, h); } else { cout << histbg.at(i)->GetName() << " blacklisted ... no subtraction" << endl; h_cl->SetTitle(Form("ADC%i Without Subtraction",i)); } fout->cd(); h_cl->Write("",TObject::kOverwrite); } std::cout << "Results saved in " << fout->GetName() << std::endl; if (foname.length()>0) fout->Close(); }
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; }
int InputForLimits(){ TH1::SetDefaultSumw2(true); if(pcp)cout<<"going to set inputs"<<endl; Int_t NBR = 3; Float_t BR[] = { 1., 0.75, 0.5}; TFile* bkgFile = new TFile( "../../BkgPrediction/BkgPrediction.root", "READ"); TTree* bkgTree; bkgFile->GetObject( "ElAndMu", bkgTree); Float_t bkg = 0.; Float_t bkgTotUnc = 0.; Float_t obs = 0.; bkgTree->SetBranchAddress( "srData", &obs); bkgTree->SetBranchAddress( "srAllBkgCorr", &bkg); bkgTree->SetBranchAddress( "TotUnc", &bkgTotUnc); TFile* sigFile = new TFile( "../../SignalSystematics/SignalSys.root", "READ"); std::vector<std::vector<TString> > sysColl; std::vector<TString> sys; sys.push_back(TString("JES_Up")); sys.push_back(TString("JES_Down")); sysColl.push_back(sys); sys.clear(); sys.push_back(TString("BTagReweight_UpBC")); sys.push_back(TString("BTagReweight_DownBC")); sysColl.push_back(sys); sys.clear(); sys.push_back(TString("BTagReweight_UpLight")); sys.push_back(TString("BTagReweight_DownLight")); sysColl.push_back(sys); std::vector<TString> decayMode; decayMode.push_back(TString("tt")); decayMode.push_back(TString("tb")); decayMode.push_back(TString("bb")); Systematics* systematics[3]; TString dirname; TString histoname; TDirectory* srDir; TDirectory* histoDir; TFile* outFile = new TFile( "InputForLimits.root", "RECREATE"); TDirectory* outBRDir; TDirectory* outSRDir; TH1F* datah = new TH1F( "data", "data", 1, 0., 1.); TH1F* bkgh = new TH1F( "bkg", "bkg", 1, 0., 1.); TH2F* sigh; TH2F* sig_toth; TH2F* effh; TH2F* sigLh; TH2F* effLh; TH2F* sigRh; TH2F* effRh; TH2F* jesh; TH2F* btagBCh; TH2F* btagLighth; TH2F* btagh; TH2F* sysh; TH2F* unch; TH2F* jesPercenth; TH2F* btagBCPercenth; TH2F* btagLightPercenth; TH2F* btagPercenth; TH2F* sysPercenth; TH2F* uncPercenth; Float_t sig = 0.; Float_t stat = 0.; Float_t jes = 0.; Float_t bc = 0.; Float_t light = 0.; Float_t unc = 0.; int N = bkgTree->GetEntries(); for ( int ibr = 0; ibr < NBR; ibr++){ dirname = ""; dirname += BR[ibr]; outFile->mkdir(dirname); outBRDir = outFile->GetDirectory(dirname); for ( int iSR = 0; iSR < 9; iSR++){ bkgTree->GetEntry(iSR); datah->SetBinContent( 1, obs); bkgh->SetBinContent( 1, bkg); bkgh->SetBinError( 1, bkgTotUnc); dirname = ""; dirname += iSR; outBRDir->mkdir(dirname); outSRDir = outBRDir->GetDirectory(dirname); dirname = ""; dirname += iSR; dirname += ".root"; srDir = sigFile->GetDirectory( dirname); for ( int isys = 0; isys < (int) sysColl.size(); isys++){ systematics[isys] = new Systematics(); systematics[isys]->BR = BR[ibr]; histoDir = srDir->GetDirectory( "NoSystematic"); for ( int idecay = 0; idecay < (int) decayMode.size(); idecay++){ histoDir->GetObject( decayMode.at(idecay), systematics[isys]->h[idecay]); histoDir->GetObject( decayMode.at(idecay) + "l", systematics[isys]->Lh); histoDir->GetObject( decayMode.at(idecay) + "r", systematics[isys]->Rh); } histoDir->GetObject( decayMode.at(0) + "l", systematics[isys]->Lh); histoDir->GetObject( decayMode.at(0) + "r", systematics[isys]->Rh); histoDir->GetObject( "sig_tot", systematics[isys]->sig_toth); for ( int ishift = 0; ishift < 2; ishift++){ histoDir = srDir->GetDirectory(sysColl.at(isys).at(ishift)); for ( int idecay = 0; idecay < (int) decayMode.size(); idecay++){ histoDir->GetObject( decayMode.at(idecay), systematics[isys]->shifth[ishift][idecay]); } } systematics[isys]->Calc(); } sig_toth = new TH2F( *systematics[0]->sig_toth); sig_toth->SetName("sig_tot"); sig_toth->SetTitle("sig_tot"); sigh = new TH2F( *systematics[0]->sigh); sigh->SetName("sig"); sigh->SetTitle("sig"); effh = new TH2F( *systematics[0]->effh); effh->SetName("eff"); effh->SetTitle("eff"); sigLh = new TH2F( *systematics[0]->sigRh); sigLh->SetName("sigL"); sigLh->SetTitle("sigL"); effLh = new TH2F( *systematics[0]->effLh); effLh->SetName("effL"); effLh->SetTitle("effL"); sigRh = new TH2F( *systematics[0]->sigRh); sigRh->SetName("sigR"); sigRh->SetTitle("sigR"); effRh = new TH2F( *systematics[0]->effRh); effRh->SetName("effR"); effRh->SetTitle("effR"); jesh = new TH2F( *systematics[0]->sysh); jesh->SetName("jes"); jesh->SetTitle("jes"); btagBCh = new TH2F( *systematics[1]->sysh); btagBCh->SetName("btagBC"); btagBCh->SetTitle("btagBC"); btagLighth = new TH2F( *systematics[2]->sysh); btagLighth->SetName("btagLight"); btagLighth->SetTitle("btagLight"); btagh = new TH2F( *btagBCh); btagh->Reset(); btagh->SetName("btag"); btagh->SetTitle("btag"); sysh = new TH2F( *jesh); sysh->Reset(); sysh->SetName("sys"); sysh->SetTitle("sys"); unch = new TH2F( *jesh); unch->Reset(); unch->SetName("unc"); unch->SetTitle("unc"); jesPercenth = new TH2F( *systematics[0]->sysh); jesPercenth->SetName("jesPercent"); jesPercenth->SetTitle("jesPercent"); jesPercenth->Divide( sigh); jesPercenth->Scale( 100.); btagBCPercenth = new TH2F( *systematics[1]->sysh); btagBCPercenth->SetName("btagBCPercent"); btagBCPercenth->SetTitle("btagBCPercent"); btagBCPercenth->Divide( sigh); btagBCPercenth->Scale( 100.); btagLightPercenth = new TH2F( *systematics[2]->sysh); btagLightPercenth->SetName("btagLightPercent"); btagLightPercenth->SetTitle("btagLightPercent"); btagLightPercenth->Divide( sigh); btagLightPercenth->Scale( 100.); btagPercenth = new TH2F( *btagBCh); btagPercenth->Reset(); btagPercenth->SetName("btagPercent"); btagPercenth->SetTitle("btagPercent"); sysPercenth = new TH2F( *jesh); sysPercenth->Reset(); sysPercenth->SetName("sysPercent"); sysPercenth->SetTitle("sysPercent"); uncPercenth = new TH2F( *jesh); uncPercenth->Reset(); uncPercenth->SetName("uncPercent"); uncPercenth->SetTitle("uncPercent"); for (int ibin = 0; ibin < sigh->GetSize(); ibin++){ sig = sigh->GetBinContent( ibin); stat = sigh->GetBinError( ibin); jes = jesh->GetBinContent(ibin); bc = btagBCh->GetBinContent(ibin); light = btagLighth->GetBinContent(ibin); unc = sqrt( bc * bc + light * light); btagh->SetBinContent( ibin, unc); btagPercenth->SetBinContent( ibin, unc / sig * 100.); unc = sqrt( jes * jes + bc * bc + light * light + sig * sig * (0.044 * 0.044 + // Lumi 0.03 * 0.03 + // Trigger 0.05 * 0.05 // Lep Id ) ); sysh->SetBinContent( ibin, unc); sysPercenth->SetBinContent( ibin, unc / sig * 100.); unc = sqrt( jes * jes + bc * bc + light * light + stat * stat + sig * sig * (0.044 * 0.044 + // Lumi 0.03 * 0.03 + // Trigger 0.05 * 0.05 // Lep Id ) ); unch->SetBinContent( ibin, unc); uncPercenth->SetBinContent( ibin, unc / sig * 100.); } outSRDir->cd(); datah->Write(); bkgh->Write(); sig_toth->Write(); sigh->Write(); effh->Write(); sigLh->Write(); effLh->Write(); sigRh->Write(); effRh->Write(); jesh->Write(); btagBCh->Write(); btagLighth->Write(); btagh->Write(); sysh->Write(); unch->Write(); jesPercenth->Write(); btagBCPercenth->Write(); btagLightPercenth->Write(); btagPercenth->Write(); sysPercenth->Write(); uncPercenth->Write(); } } delete systematics[0]; delete systematics[1]; delete systematics[2]; outFile->Close(); sigFile->Close(); bkgFile->Close(); return 0; }
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
int MakeHistos(int iSample = 0, int iSR = 6){ TH1::SetDefaultSumw2(true); if(pcp)cout<<"going to set inputs"<<endl; TString mainDir = "/home/fcostanz/Bonsai/ControlPlots/"; TFile* cutFile = new TFile( "Optimization-2Step.root", "READ"); TTree* cutTree; cutFile->GetObject( "Optimization", cutTree); Float_t mtCut = 0.; Float_t nJetCut = 0.; Float_t topnessCut = 0.; Float_t mt2wCut = 0.; Float_t yCut = 0.; Float_t dphiCut = 0.; Float_t drlblCut = 0.; Float_t drlbgCut = 0.; Float_t chi2Cut = 0.; Float_t metCut = 0.; Float_t m3Cut = 0.; Float_t centralityCut = 0.; Float_t mlbCut = 0.; cutTree->SetBranchAddress( "mtCut", &mtCut); cutTree->SetBranchAddress( "njetCut", &nJetCut); cutTree->SetBranchAddress( "topnessCut", &topnessCut); cutTree->SetBranchAddress( "mt2wCut", &mt2wCut); cutTree->SetBranchAddress( "yCut", &yCut); cutTree->SetBranchAddress( "dphiCut", &dphiCut); cutTree->SetBranchAddress( "drlblCut", &drlblCut); cutTree->SetBranchAddress( "drlbgCut", &drlbgCut); cutTree->SetBranchAddress( "chi2Cut", &chi2Cut); cutTree->SetBranchAddress( "metCut", &metCut); cutTree->SetBranchAddress( "m3Cut", &m3Cut); cutTree->SetBranchAddress( "centralityCut", ¢ralityCut); cutTree->SetBranchAddress( "mlbCut", &mlbCut); cutTree->GetEntry(iSR); /* mtCut = 120.; nJetCut = 3; topnessCut = -20; mt2wCut = 200; yCut = 0.; dphiCut = 1.; drlblCut = 5.; drlbgCut = 0.; chi2Cut = 9999999999.; metCut = 250.; m3Cut = 0.; centralityCut = 0.6; mlbCut =9999999999. ;*/ cout<<"mtCut = "<<mtCut<<endl; cout<<"nJetCut = "<<nJetCut<<endl; cout<<"topnessCut = "<<topnessCut<<endl; cout<<"mt2wCut = "<<mt2wCut<<endl; cout<<"yCut = "<<yCut<<endl; cout<<"dphiCut = "<<dphiCut<<endl; cout<<"drlblCut = "<<drlblCut<<endl; cout<<"drlbgCut = "<<drlbgCut<<endl; cout<<"chi2Cut = "<<chi2Cut<<endl; cout<<"metCut = "<<metCut<<endl; cout<<"m3Cut = "<<m3Cut<<endl; cout<<"centralityCut = "<<centralityCut<<endl; cout<<"mlbCut = "<<mlbCut<<endl; const int NSamples = 11; const int NSignals = 4; const int NControlRegions = 6; const int NLeps = 3; const int NDirs = NControlRegions * NLeps; TString sample[NSamples]; sample[0] = "Data"; sample[1] = "DiLep"; sample[2] = "OneLep"; sample[3] = "WJets"; sample[4] = "Rare"; sample[5] = "QCD"; sample[6] = "DrellYan"; sample[7] = "T2tb-mStop175mLSP50"; sample[8] = "T2tb-mStop200mLSP25"; sample[9] = "T2tb-mStop325mLSP100"; sample[10] = "T2tb-mStop550mLSP1"; double lumi=19500.; double weight = 1.; bool lepFlag; TString lep[NLeps]; lep[0] = "El"; lep[1] = "Mu"; lep[2] = "ElAndMu"; TString controlRegion[NControlRegions]; controlRegion[0] = "Preselection"; controlRegion[1] = "SearchRegionPreIsoTrackVeto"; controlRegion[2] = "SearchRegionPostIsoTrackVeto"; controlRegion[3] = "CR1"; controlRegion[4] = "CR4"; controlRegion[5] = "CR5"; bool flag[NDirs]; TString controlDirName[NDirs]; TDirectory* controlDir[NDirs]; for (int ilep = 0; ilep < NLeps; ilep++){ for ( int iControlRegion = 0; iControlRegion < NControlRegions; iControlRegion++){ controlDirName[ilep * NControlRegions + iControlRegion ] = lep[ilep]; controlDirName[ilep * NControlRegions + iControlRegion ] += "-"; controlDirName[ilep * NControlRegions + iControlRegion ] += controlRegion[iControlRegion]; } } ///////////////////////////////////////////////////// // Input Definition ///////////////////////////////////////////////////// std::cout<<"Running over Sample "<<sample[iSample]<<std::endl; TString inFileName = mainDir; inFileName += sample[iSample]; inFileName +=".root"; TFile* inFile = new TFile(inFileName,"READ"); if (!inFile->IsOpen()){ std::cout<<"not open"<<std::endl; } ///////////////////////////////////////////////////// // Tree Definition ///////////////////////////////////////////////////// TTree* tree; tree= (TTree*)inFile->Get("NoSystematic/bonsai"); int N = tree->GetEntries(); cout<<"THERE ARE "<<N<<" EVENTS IN "<<inFileName<<endl; Float_t globalWeight = 0.; Float_t triggerWeight = 0.; Float_t npv = 0.; Float_t ngoodpv = 0.; Float_t puWeight = 0.; Float_t isrWeight = 0.; Float_t topPtWeight = 0.; Float_t lepFromTop = 0.; Float_t charginos = 0.; Float_t njets = 0.; Float_t jet1 = 0.; Float_t jet2 = 0.; Float_t jet3 = 0.; Float_t jet4 = 0.; Float_t nbjets = 0.; Float_t bjet1 = 0.; Float_t bjetHighestDisc = 0.; Float_t bdiscH = 0.; Float_t lPt = 0.; Float_t lEta = 0.; Float_t lRelIso = 0.; Float_t isoTrack = 0.; Float_t tauVeto = 0.; Float_t rawmet = 0.; Float_t typeImet = 0.; Float_t phiCorrMet = 0.; Float_t ht = 0.; Float_t ht3 = 0.; Float_t ht4 = 0.; Float_t ht5 = 0.; Float_t htRatio = 0.; Float_t meff = 0.; Float_t y = 0.; Float_t mt = 0.; Float_t mlb1 = 0.; Float_t mlb = 0.; Float_t m3b = 0.; Float_t m3 = 0.; Float_t centrality = 0.; Float_t mt2w = 0.; Float_t hadChi2 = 0.; Float_t topness = 0.; Float_t dphimin = 0.; Float_t drlb1 = 0.; Float_t drlbmin = 0.; Int_t pdgIdLep1 = 0; Int_t pdgIdLep2 = 0; Char_t kinRegion = false; Char_t searchRegionPre = false; Char_t searchRegionPost = false; Char_t CR1 = false; Char_t CR4 = false; Char_t CR5 = false; tree->SetBranchAddress( "GlobalWeight", &globalWeight); tree->SetBranchAddress( "TriggerWeight", &triggerWeight); tree->SetBranchAddress( "NPV", &npv); tree->SetBranchAddress( "NgoodPV", &ngoodpv); tree->SetBranchAddress( "PUWeight", &puWeight); tree->SetBranchAddress( "isrWeight", &isrWeight); tree->SetBranchAddress( "topPtWeight", &topPtWeight); tree->SetBranchAddress( "LepFromTop", &lepFromTop); tree->SetBranchAddress( "Charginos", &charginos); tree->SetBranchAddress( "njets", &njets); tree->SetBranchAddress( "jet1", &jet1); tree->SetBranchAddress( "jet2", &jet2); tree->SetBranchAddress( "jet3", &jet3); tree->SetBranchAddress( "jet4", &jet4); tree->SetBranchAddress( "nbjets", &nbjets); tree->SetBranchAddress( "bjet1", &bjet1); tree->SetBranchAddress( "bjetHighestDisc", &bjetHighestDisc); tree->SetBranchAddress( "discH", &bdiscH); tree->SetBranchAddress( "lPt", &lPt); tree->SetBranchAddress( "lEta", &lEta); tree->SetBranchAddress( "lRelIso", &lRelIso); tree->SetBranchAddress( "phiCorrMet", &phiCorrMet); tree->SetBranchAddress( "ht", &ht); tree->SetBranchAddress( "ht3", &ht3); tree->SetBranchAddress( "ht4", &ht4); tree->SetBranchAddress( "ht5", &ht5); tree->SetBranchAddress( "htRatio", &htRatio); tree->SetBranchAddress( "meff", &meff); tree->SetBranchAddress( "y", &y); tree->SetBranchAddress( "mt", &mt); tree->SetBranchAddress( "mlb1", &mlb1); tree->SetBranchAddress( "mlb", &mlb); tree->SetBranchAddress( "m3b", &m3b); tree->SetBranchAddress( "m3", &m3); tree->SetBranchAddress( "centrality", ¢rality); tree->SetBranchAddress( "mt2w", &mt2w); tree->SetBranchAddress( "hadChi2", &hadChi2); tree->SetBranchAddress( "topness", &topness); tree->SetBranchAddress( "dphimin", &dphimin); tree->SetBranchAddress( "drlb1", &drlb1); tree->SetBranchAddress( "drlbmin", &drlbmin); tree->SetBranchAddress("pdgIdLep1",&pdgIdLep1); tree->SetBranchAddress("pdgIdLep2",&pdgIdLep2); tree->SetBranchAddress("kinRegion",&kinRegion); tree->SetBranchAddress("searchRegionPre",&searchRegionPre); tree->SetBranchAddress("searchRegionPost",&searchRegionPost); tree->SetBranchAddress("CR1",&CR1); tree->SetBranchAddress("CR4",&CR4); tree->SetBranchAddress("CR5",&CR5); ///////////////////////////////////////////////////// // Output Definition ///////////////////////////////////////////////////// //Branching Ratio TFile* outFile = new TFile( "./MakeHistos/"+sample[iSample]+".root", "Update"); outFile->cd(); TH1D* npvh[NDirs]; TH1D* ngoodpvh[NDirs]; TH1D* lpth[NDirs]; TH1D* letah[NDirs]; TH1D* lrelisoh[NDirs]; TH1D* njetsh[NDirs]; TH1D* jet1h[NDirs]; TH1D* jet2h[NDirs]; TH1D* jet3h[NDirs]; TH1D* jet4h[NDirs]; TH1D* nbjetsh[NDirs]; TH1D* bjet1h[NDirs]; TH1D* bjetHighDh[NDirs]; TH1D* bdiscHh[NDirs]; TH1D* hth[NDirs]; TH1D* ht3h[NDirs]; TH1D* ht4h[NDirs]; TH1D* ht5h[NDirs]; TH1D* htratioh[NDirs]; TH1D* meth[NDirs]; TH1D* meffh[NDirs]; TH1D* yh[NDirs]; TH1D* mth[NDirs]; TH1D* mlb1h[NDirs]; TH1D* mlbh[NDirs]; TH1D* m3bh[NDirs]; TH1D* m3h[NDirs]; TH1D* centralityh[NDirs]; TH1D* mt2wh[NDirs]; TH1D* hadchi2h[NDirs]; TH1D* topnessh[NDirs]; TH1D* dphiminh[NDirs]; TH1D* drlb1h[NDirs]; TH1D* drlbminh[NDirs]; TString dirName = ""; dirName += iSR; if (outFile->GetDirectory(dirName)) outFile->Delete(dirName + ";*"); outFile->mkdir( dirName); TDirectory* SRDir = outFile->GetDirectory( dirName); SRDir->cd(); for ( int iDir = 0; iDir < NDirs; iDir++){ SRDir->mkdir( controlDirName[iDir]); controlDir[iDir] = SRDir->GetDirectory( controlDirName[iDir]); controlDir[iDir]->cd(); npvh[iDir] = new TH1D( "npv", "NPV", 51, -0.5, 50.5); ngoodpvh[iDir] = new TH1D( "ngoodpv", "NgoodPV", 51, -0.5, 50.5); lpth[iDir] = new TH1D( "lpt", "lep p_{T} [GeV]", 12, 25., 500.); letah[iDir] = new TH1D( "leta", "lep #Eta", 30, -3., 3.); lrelisoh[iDir] = new TH1D( "lRelIso", "lep RelIso", 30, 0., 1.); njetsh[iDir] = new TH1D( "njets", "jets multiplicity", 10, -0.5, 9.5); jet1h[iDir] = new TH1D( "jet1", "1st jet p_{T} [GeV]", 25, 0., 500.); jet2h[iDir] = new TH1D( "jet2", "2nd jet p_{T} [GeV]", 25, 0., 500.); jet3h[iDir] = new TH1D( "jet3", "3rd jet p_{T} [GeV]", 25, 0., 500.); jet4h[iDir] = new TH1D( "jet4", "4th jet p_{T} [GeV]", 25, 0., 500.); nbjetsh[iDir] = new TH1D( "nbjets", "b jets multiplicity", 6, -0.5, 5.5); bjet1h[iDir] = new TH1D( "bjet1", "Leading b jet p_{T} [GeV]", 25, 0., 500.); bjetHighDh[iDir] = new TH1D( "bjetHighD", "p_{T} of the highest b disc jet [GeV]", 12, 0., 500.); bdiscHh[iDir] = new TH1D( "bdisc", "bdisc", 20, 0., 1.); meth[iDir] = new TH1D( "MET", "MET [GeV]", 12, 0., 400.); hth[iDir] = new TH1D( "Ht", "Ht [GeV]", 20, 0., 1000.); ht3h[iDir] = new TH1D( "Ht3", "Ht3 [GeV]", 20, 0., 1000.); ht4h[iDir] = new TH1D( "Ht4", "Ht4 [GeV]", 20, 0., 1000.); ht5h[iDir] = new TH1D( "Ht5", "Ht5 [GeV]", 20, 0., 1000.); htratioh[iDir] = new TH1D( "HtRatio", "HtRatio", 20, 0., 1.); meffh[iDir] = new TH1D( "Meff", "Meff [GeV]", 40, 0., 1000.); yh[iDir] = new TH1D( "Y", "Y [GeV^{1/2}]", 15, 0., 30.); mth[iDir] = new TH1D( "Mt", "Mt [GeV]", 30, 0., 300.); mlb1h[iDir] = new TH1D( "mlb1", "Mlb1 [GeV]", 10, 0., 500.); mlbh[iDir] = new TH1D( "mlb", "Mlb [GeV]", 10, 0., 500.); m3bh[iDir] = new TH1D( "m3b", "M3b [GeV]", 15, 0., 500.); m3h[iDir] = new TH1D( "m3", "M3 [GeV]", 15, 0., 500.); centralityh[iDir] = new TH1D( "centrality", "centrality", 10, 0., 1.); mt2wh[iDir] = new TH1D( "mt2w", "MT2W [GeV]", 15, 0., 500.); hadchi2h[iDir] = new TH1D( "hadChi2", "hadChi2 [GeV]", 20, 0., 10.); topnessh[iDir] = new TH1D( "topness", "topness [GeV]", 30, -15., 15.); dphiminh[iDir] = new TH1D( "dphimin", "min dPhi (MET, jet1/2)", 17, 0., TMath::Pi() * 17./16.); drlb1h[iDir] = new TH1D( "drlb1", "dR(lep, bjet1)", 20, 0., 5.); drlbminh[iDir] = new TH1D( "drlbmin", "min dR(lep, bjet)", 20, 0., 5.); } outFile->cd(); for (int ievt=0;ievt<N;++ievt){ tree->GetEntry(ievt); //if (ievt%13453 == 0) cout<<"Event number "<<ievt<<"\r"<<flush; if (iSample == 0) weight = 1.; else weight = globalWeight * triggerWeight * puWeight * topPtWeight * lumi; if ( (iSample - NSamples + NSignals) > -0.01 ) weight *= isrWeight; if (lRelIso > 0.1) continue; for (int ilep = 0; ilep < NLeps; ilep++){ lepFlag = true; if (ilep == 0) lepFlag = (abs(pdgIdLep1) == 11); if (ilep == 1) lepFlag = (abs(pdgIdLep1) == 13); flag[ilep * NControlRegions + 0] = (searchRegionPost || CR1) && lepFlag; flag[ilep * NControlRegions + 1] = searchRegionPre && lepFlag; flag[ilep * NControlRegions + 2] = searchRegionPost && lepFlag; flag[ilep * NControlRegions + 3] = CR1 && lepFlag; flag[ilep * NControlRegions + 4] = CR4 && lepFlag; flag[ilep * NControlRegions + 5] = CR5 && lepFlag; } for ( int iDir = 0; iDir < NDirs; iDir++){ if (!flag[iDir]) continue; ///////////////////////////////////////////////////// // Histo Filling ///////////////////////////////////////////////////// bool allCuts = (njets - nJetCut) > -0.0001 && mt2w > mt2wCut && y > yCut && dphimin > dphiCut && drlb1 < drlblCut && phiCorrMet > metCut && m3 > m3Cut; bool allButMt2w = (njets - nJetCut) > -0.0001 && y > yCut && dphimin > dphiCut && drlb1 < drlblCut && phiCorrMet > metCut && m3 > m3Cut; bool allButY = (njets - nJetCut) > -0.0001 && mt2w > mt2wCut && dphimin > dphiCut && drlb1 < drlblCut && phiCorrMet > metCut && m3 > m3Cut; bool allButDphi = (njets - nJetCut) > -0.0001 && mt2w > mt2wCut && y > yCut && drlb1 < drlblCut && phiCorrMet > metCut && m3 > m3Cut; bool allButDrlb = (njets - nJetCut) > -0.0001 && mt2w > mt2wCut && y > yCut && dphimin > dphiCut && phiCorrMet > metCut && m3 > m3Cut; bool allButMet = (njets - nJetCut) > -0.0001 && mt2w > mt2wCut && y > yCut && dphimin > dphiCut && drlb1 < drlblCut && m3 > m3Cut; bool allButM3 = (njets - nJetCut) > -0.0001 && mt2w > mt2wCut && y > yCut && dphimin > dphiCut && drlb1 < drlblCut && phiCorrMet > metCut ; bool allButCentrality = allCuts && mlb1 < mlbCut; bool allButMlb = allCuts && centrality > centralityCut; allCuts &= centrality > centralityCut && mlb1 < mlbCut; allButMt2w &= centrality > centralityCut && mlb1 < mlbCut; allButY &= centrality > centralityCut && mlb1 < mlbCut; allButDphi &= centrality > centralityCut && mlb1 < mlbCut; allButDrlb &= centrality > centralityCut && mlb1 < mlbCut; allButMet &= centrality > centralityCut && mlb1 < mlbCut; allButM3 &= centrality > centralityCut && mlb1 < mlbCut; if (iDir%NControlRegions == 0 || iDir%NControlRegions == 1 || iDir%NControlRegions == 2 ){ if ( mt > 80.){ if (iSample != 0 && allCuts) mth[iDir]->Fill( mt, weight); continue; } if (mt < 50.) { if (allCuts) mth[iDir]->Fill( mt, weight); continue; } } if (allButMt2w) mt2wh[iDir]->Fill( mt2w, weight); if (allButY) yh[iDir]->Fill( y, weight); if (allButDphi) dphiminh[iDir]->Fill( dphimin, weight); if (allButDrlb) drlb1h[iDir]->Fill( drlb1, weight); if (allButMet) meth[iDir]->Fill( phiCorrMet, weight); if (allButM3) m3h[iDir]->Fill( m3, weight); if (allButCentrality) centralityh[iDir]->Fill( centrality, weight); if (allButMlb) mlb1h[iDir]->Fill( mlb1, weight); if (allCuts) { npvh[iDir]->Fill( npv, weight); ngoodpvh[iDir]->Fill( ngoodpv, weight); lpth[iDir]->Fill( lPt, weight); letah[iDir]->Fill( lEta, weight); lrelisoh[iDir]->Fill( lRelIso, weight); njetsh[iDir]->Fill( njets, weight); jet1h[iDir]->Fill( jet1, weight); jet2h[iDir]->Fill( jet2, weight); jet3h[iDir]->Fill( jet3, weight); jet4h[iDir]->Fill( jet4, weight); nbjetsh[iDir]->Fill( nbjets, weight); bjet1h[iDir]->Fill( bjet1, weight); bjetHighDh[iDir]->Fill( bjetHighestDisc, weight); bdiscHh[iDir]->Fill( bdiscH, weight); hth[iDir]->Fill( ht, weight); ht3h[iDir]->Fill( ht3, weight); ht4h[iDir]->Fill( ht4, weight); ht5h[iDir]->Fill( ht5, weight); htratioh[iDir]->Fill( htRatio, weight); meffh[iDir]->Fill( meff, weight); mth[iDir]->Fill( mt, weight); mlb1h[iDir]->Fill( mlb1, weight); m3bh[iDir]->Fill( m3b, weight); hadchi2h[iDir]->Fill( hadChi2, weight); topnessh[iDir]->Fill( topness, weight); drlbminh[iDir]->Fill( drlbmin, weight); } } } outFile->Write(); outFile->Close(); inFile->Close(); return 0; }
int main(int ac, char *av[]) { try { double fMin, fMax; string ext; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("include-path,I", po::value< vector<string> >(), "include path") ("input-file", po::value< vector<string> >(), "input file") ("min,m", po::value<double>(&fMin)->default_value(60), "minimum value for fit range") ("max,M", po::value<double>(&fMax)->default_value(120), "maximum value for fit range") ("convbwintgamg", "fit to the convolution of a breit-wigner plus interference term and gamma propagator and a gaussian") ("convexpbwintgamg", "fit to the convolution of the product between an exponential and a breit-wigner plus interference term and gamma propagator with a gaussian") ("convbwintgam2gf", "fit to the convolution of the breit-wigner plus interference term and gamma propagator with a linear combination of fixed gaussians") ("output-file,O", po::value<string>(&ext)->default_value(".ps"), "output file format") ; po::positional_options_description p; p.add("input-file", -1); po::variables_map vm; po::store(po::command_line_parser(ac, av). options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { cout << "Usage: options_description [options]\n"; cout << desc; return 0; } if (vm.count("include-path")) { cout << "Include paths are: " << vm["include-path"].as< vector<string> >() << "\n"; } vector<string> v_file; vector<TH1D*> v_ZMassHistos; vector<string> v_eps; if (vm.count("input-file")) { cout << "Input files are: " << vm["input-file"].as< vector<string> >() << "\n"; v_file = vm["input-file"].as< vector<string> >(); for(vector<string>::const_iterator it = v_file.begin(); it != v_file.end(); ++it) { TFile * root_file = new TFile(it->c_str(),"read"); TDirectory *Histos = (TDirectory*) root_file->GetDirectory("ZHisto"); TDirectory *RecoHistos = (TDirectory*) Histos->GetDirectory("ZRecoHisto"); TH1D * zMass = (TH1D*) RecoHistos->Get("ZMass"); zMass->Rebin(4); //remember... zMass->GetXaxis()->SetTitle("#mu #mu invariant mass (GeV/c^{2})"); v_ZMassHistos.push_back(zMass); gROOT->SetStyle("Plain"); //gStyle->SetOptFit(1111); string f_string = *it; replace(f_string.begin(), f_string.end(), '.', '_'); string eps_string = f_string + ext; v_eps.push_back(eps_string); cout << ">>> histogram loaded\n"; } cout << v_file.size() << ", " << v_ZMassHistos.size() << ", " << v_eps.size() << endl; cout <<">>> Input files loaded\n"; } IntegratorConv integratorConv(1.e-5); //Values for Z mass and width funct::Parameter mass("Mass", 91.364); funct::Parameter gamma("Gamma", 4.11); //Parameters for Z Line Shape funct::Parameter f_gamma("Photon factor", 0.838); funct::Parameter f_int("Interference factor", -0.00197); //Parameters for fits with gaussians funct::Parameter yield("Yield", 283000); funct::Parameter alpha("Alpha", 0.771); //the first gaussian is narrow funct::Parameter mean("Mean", 0); //0.229 funct::Parameter sigma1("Sigma 1", 0.76); funct::Parameter sigma2("Sigma 2", 2.94); //Parameter for exponential funct::Parameter lambda("Lambda", 0); if (vm.count("convbwintgamg")) { cout << "Fitting histograms in input files to the convolution of the Breit-Wigner plus Z/photon interference and photon propagator with a Gaussian\n"; cout << ">>> set pars: " << endl; cout << yield << endl; cout << mass << endl; cout << gamma << endl; cout << f_gamma << endl; cout << f_int << endl; cout << mean << endl; cout << sigma1 << endl; for(unsigned int i = 0; i < v_ZMassHistos.size(); ++i) { TH1D * zMass = v_ZMassHistos[i]; funct::ZLineShape zls(mass, gamma, f_gamma, f_int); funct::Gaussian gauss(mean, sigma1); double range = 3 * sigma1.value(); funct::Convolution<funct::ZLineShape, funct::Gaussian, IntegratorConv>::type czg(zls, gauss, -range , range, integratorConv); funct::Constant c(yield); typedef funct::Product<funct::Constant, funct::Convolution<funct::ZLineShape, funct::Gaussian, IntegratorConv>::type >::type FitFunction; FitFunction f = c * czg; cout << "set functions" << endl; typedef fit::HistoChiSquare<FitFunction> ChiSquared; ChiSquared chi2(f, zMass, fMin, fMax); int fullBins = chi2.numberOfBins(); cout << "N. deg. of freedom: " << fullBins << endl; fit::RootMinuit<ChiSquared> minuit(chi2, true); minuit.addParameter(yield, 10, 100, 10000000); minuit.addParameter(mass, .1, 70., 110); minuit.addParameter(gamma, 1, 1, 10); minuit.addParameter(f_gamma, 0.1, -100, 1000); minuit.addParameter(f_int, .0001, -1000000, 1000000); minuit.addParameter(mean, 0.001, -0.5, 0.5); minuit.fixParameter(mean.name()); minuit.addParameter(sigma1, 0.1, -5., 5.); minuit.minimize(); minuit.printFitResults(); vector<shared_ptr<double> > pars; pars.push_back(yield.ptr()); pars.push_back(mass.ptr()); pars.push_back(gamma.ptr()); pars.push_back(f_gamma.ptr()); pars.push_back(f_int.ptr()); pars.push_back(mean.ptr()); pars.push_back(sigma1.ptr()); TF1 fun = root::tf1("fun", f, fMin, fMax, pars); fun.SetParNames(yield.name().c_str(), mass.name().c_str(), gamma.name().c_str(), f_gamma.name().c_str(), f_int.name().c_str(), mean.name().c_str(), sigma1.name().c_str()); fun.SetLineColor(kRed); fun.SetNpx(100000); TCanvas *canvas = new TCanvas("canvas"); zMass->Draw("e"); fun.Draw("same"); string epsFilename = "ZMassFitCoBwInGaG_" + v_eps[i]; canvas->SaveAs(epsFilename.c_str()); canvas->SetLogy(); string epsLogFilename = "ZMassFitCoBwInGaG_Log_" + v_eps[i]; canvas->SaveAs(epsLogFilename.c_str()); } } if (vm.count("convexpbwintgamg")) { cout << "Fitting histograms in input files to the convolution of the product between an exponential and a breit-wigner plus interference term and gamma propagator with a gaussian" << endl; cout << ">>> set pars: " << endl; cout << yield << endl; cout << lambda << endl; cout << mass << endl; cout << gamma << endl; cout << f_gamma << endl; cout << f_int << endl; cout << mean << endl; cout << sigma1 << endl; for(unsigned int i = 0; i < v_ZMassHistos.size(); ++i) { TH1D * zMass = v_ZMassHistos[i]; funct::Exponential expo(lambda); funct::ZLineShape zls(mass, gamma, f_gamma, f_int); funct::Gaussian gauss(mean, sigma1); typedef funct::Product<funct::Exponential, funct::ZLineShape>::type ExpZLS; ExpZLS expz = expo * zls; double range = 3 * sigma1.value(); funct::Convolution<ExpZLS, funct::Gaussian, IntegratorConv>::type cezg(expz, gauss, -range , range, integratorConv); funct::Constant c(yield); typedef funct::Product<funct::Constant, funct::Convolution<ExpZLS, funct::Gaussian, IntegratorConv>::type >::type FitFunction; FitFunction f = c * cezg; cout << "set functions" << endl; typedef fit::HistoChiSquare<FitFunction> ChiSquared; ChiSquared chi2(f, zMass, fMin, fMax); int fullBins = chi2.numberOfBins(); cout << "N. deg. of freedom: " << fullBins << endl; fit::RootMinuit<ChiSquared> minuit(chi2, true); minuit.addParameter(yield, 10, 100, 10000000); minuit.addParameter(lambda, 0.1, -100, 100); minuit.fixParameter(lambda.name()); minuit.addParameter(mass, .1, 70., 110); minuit.addParameter(gamma, 1, 1, 10); minuit.addParameter(f_gamma, 0.1, -100, 1000); minuit.addParameter(f_int, .0001, -1000000, 1000000); minuit.addParameter(mean, 0.001, -0.5, 0.5); minuit.fixParameter(mean.name()); minuit.addParameter(sigma1, 0.1, -5., 5.); minuit.minimize(); minuit.printFitResults(); minuit.releaseParameter(lambda.name()); minuit.minimize(); minuit.printFitResults(); vector<shared_ptr<double> > pars; pars.push_back(yield.ptr()); pars.push_back(lambda.ptr()); pars.push_back(mass.ptr()); pars.push_back(gamma.ptr()); pars.push_back(f_gamma.ptr()); pars.push_back(f_int.ptr()); pars.push_back(mean.ptr()); pars.push_back(sigma1.ptr()); TF1 fun = root::tf1("fun", f, fMin, fMax, pars); fun.SetParNames(yield.name().c_str(), lambda.name().c_str(), mass.name().c_str(), gamma.name().c_str(), f_gamma.name().c_str(), f_int.name().c_str(), mean.name().c_str(), sigma1.name().c_str()); fun.SetLineColor(kRed); fun.SetNpx(100000); TCanvas *canvas = new TCanvas("canvas"); zMass->Draw("e"); fun.Draw("same"); string epsFilename = "ZMassFitCoExBwInGaG_" + v_eps[i]; canvas->SaveAs(epsFilename.c_str()); canvas->SetLogy(); string epsLogFilename = "ZMassFitCoExBwInGaG_Log_" + v_eps[i]; canvas->SaveAs(epsLogFilename.c_str()); } } if (vm.count("convbwintgam2gf")) { cout << "Fitting histograms in input files to the convolution of the Breit-Wigner plus Z/photon interference and photon propagator with a linear combination of fixed Gaussians\n"; cout << ">>> set pars: " << endl; cout << yield << endl; cout << alpha << endl; cout << mass << endl; cout << gamma << endl; cout << f_gamma << endl; cout << f_int << endl; cout << mean << endl; cout << sigma1 << endl; cout << sigma2 << endl; for(unsigned int i = 0; i < v_ZMassHistos.size(); ++i) { TH1D * zMass = v_ZMassHistos[i]; funct::ZLineShape zls(mass, gamma, f_gamma, f_int); funct::Gaussian gaus1(mean, sigma1); funct::Gaussian gaus2(mean, sigma2); funct::Number _1(1); typedef funct::Product<funct::Constant, funct::Gaussian>::type G1; typedef funct::Product<funct::Difference<funct::Number, funct::Constant>::type, funct::Gaussian>::type G2; typedef funct::Product<funct::Constant, funct::Sum<G1, G2>::type>::type GaussComb; funct::Constant c_alpha(alpha), c_yield(yield); GaussComb gc = c_yield*(c_alpha*gaus1 + (_1 - c_alpha)*gaus2); typedef funct::Convolution<funct::ZLineShape, GaussComb, IntegratorConv>::type FitFunction; double range = 3 * max(sigma1.value(), sigma2.value()); FitFunction f(zls, gc, -range , range, integratorConv); cout << "set functions" << endl; typedef fit::HistoChiSquare<FitFunction> ChiSquared; ChiSquared chi2(f, zMass, fMin, fMax); int fullBins = chi2.numberOfBins(); cout << "N. deg. of freedom: " << fullBins << endl; fit::RootMinuit<ChiSquared> minuit(chi2, true); minuit.addParameter(yield, 10, 100, 10000000); minuit.addParameter(alpha, 0.1, -1., 1.); minuit.addParameter(mass, .1, 70., 110); minuit.addParameter(gamma, 1, 1, 10); minuit.addParameter(f_gamma, 0.1, -100, 1000); minuit.addParameter(f_int, .0001, -1000000, 1000000); minuit.addParameter(mean, 0.001, -0.5, 0.5); minuit.fixParameter(mean.name()); minuit.addParameter(sigma1, 0.1, -5., 5.); minuit.addParameter(sigma2, 0.1, -5., 5.); minuit.minimize(); minuit.printFitResults(); vector<shared_ptr<double> > pars; pars.push_back(yield.ptr()); pars.push_back(alpha.ptr()); pars.push_back(mass.ptr()); pars.push_back(gamma.ptr()); pars.push_back(f_gamma.ptr()); pars.push_back(f_int.ptr()); pars.push_back(mean.ptr()); pars.push_back(sigma1.ptr()); pars.push_back(sigma2.ptr()); TF1 fun = root::tf1("fun", f, fMin, fMax, pars); fun.SetParNames(yield.name().c_str(), alpha.name().c_str(), mass.name().c_str(), gamma.name().c_str(), f_gamma.name().c_str(), f_int.name().c_str(), mean.name().c_str(), sigma1.name().c_str(), sigma2.name().c_str()); fun.SetLineColor(kRed); TCanvas *canvas = new TCanvas("canvas"); zMass->Draw("e"); fun.Draw("same"); string epsFilename = "ZMassFitCoBwInGaGGf_" + v_eps[i]; canvas->SaveAs(epsFilename.c_str()); canvas->SetLogy(); string epsLogFilename = "ZMassFitCoBwInGaGGf_Log_" + v_eps[i]; canvas->SaveAs(epsLogFilename.c_str()); } } cout << "It works!\n"; } catch(std::exception& e) { cerr << "error: " << e.what() << "\n"; return 1; } catch(...) { cerr << "Exception of unknown type!\n"; } return 0; }