void beffAnalysis(const char* input, const char* output) { // input TFile* inputFile = TFile::Open(input); TTree* btagEff = (TTree*)inputFile->Get("btagEff"); // output TFile* outputFile = TFile::Open(output,"RECREATE"); // histogram with proper binning... cloned later on Double_t binning[23] = {20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,120,140,160,180,200,1000}; TH1F* ptSpectrum = new TH1F("PtSpectrum","PtSpectrum",22,binning); ptSpectrum->Sumw2(); // produce the ratio plot for the 12 combinations of (CSVL,CSVM,CSVT),(Barrel,Endcap),(b,c,l) TClonesArray algorithms("TCut",3); new(algorithms[0]) TCut("CSVL","csv>0.244"); new(algorithms[1]) TCut("CSVM","csv>0.679"); new(algorithms[2]) TCut("CSVT","csv>0.898"); TClonesArray etaRegions("TCut",2); new(etaRegions[0]) TCut("Barrel","abs(eta)<=1.2"); new(etaRegions[1]) TCut("Endcaps","abs(eta)>1.2"); TClonesArray flavor("TCut",3); new(flavor[0]) TCut("l","abs(flavor)!=4 && abs(flavor)!=5"); new(flavor[1]) TCut("c","abs(flavor)==4"); new(flavor[2]) TCut("b","abs(flavor)==5"); for(int i=0; i< algorithms.GetEntries() ; ++i) { outputFile->mkdir(((TCut*)algorithms.At(i))->GetName()); outputFile->cd(((TCut*)algorithms.At(i))->GetName()); for(int j=0; j< etaRegions.GetEntries() ; ++j) { for(int k=0; k< flavor.GetEntries() ; ++k) { // histogram before tagging TH1F* pretag = ptSpectrum->Clone("pretag"); btagEff->Draw("pt>>pretag",((*(TCut*)etaRegions.At(j))&&(*(TCut*)flavor.At(k)))*"eventWeight"); // histogram after tagging TH1F* posttag = ptSpectrum->Clone("posttag"); btagEff->Draw("pt>>posttag",((*(TCut*)algorithms.At(i))&&(*(TCut*)etaRegions.At(j))&&(*(TCut*)flavor.At(k)))*"eventWeight"); // ratio TH1F* ratio = posttag->Clone(Form("h_eff_bTagOverGoodJet_pt%s_%s",((TCut*)flavor.At(k))->GetName(), ((TCut*)etaRegions.At(j))->GetName())); ratio->Divide(pretag); // cleanup delete pretag; delete posttag; } } } // cleanup algorithms.Delete(); etaRegions.Delete(); flavor.Delete(); ptSpectrum->SetDirectory(0); outputFile->Write(); outputFile->Close(); inputFile->Close(); }
void applyEfficiencyToTauMuons() { TFile* _fPtSm = new TFile("smearedMuonPtFromTau.07.09.2013.root","read"); TFile* _fEff = new TFile("mcWEffForTauMuonStudy_07_08_2013.root","read"); TFile* _fPtSmEff = new TFile("smearedEffAppliedMuonPtFromTau.root","recreate"); _fPtSm->cd(); TH1F* hPtSm = (TH1F*)_fPtSm->Get("hSmearedMuonPt"); _fEff->cd(); TGraphAsymmErrors* grEff = (TGraphAsymmErrors*)_fEff->Get("pEffWAccCuts"); double* yEff = grEff->GetY(); TH1F* hnew = (TH1F*)hPtSm->Clone("hnew"); ///Apply efficiency bin by bin for(int igr=0; igr<grEff->GetN(); ++igr) { double ptNominal = hPtSm->GetBinContent(igr+1); std::cout << "pt nominal " << ptNominal << " eff " << yEff[igr] << " = " << yEff[igr]*ptNominal << std::endl; hnew->SetBinContent(igr+1,yEff[igr]*ptNominal); } _fPtSmEff->cd(); hnew->Write(); _fPtSmEff->Write(); _fPtSmEff->Close(); }
void draw_lumi(){ TString filenameData = "lumi_effData.root"; TString filenameMC = "lumi_effMC.root"; TString fileMC = "../newDoubleMuonTree/tnpZ_theTreeCleanedMC.root"; //TString fileData = "doubleMuonTrees/tnpZ_theTreeCleaned.root"; TString fileData = "/afs/cern.ch/user/q/quwang/work/Trigger/CMSSW_7_6_3_patch2/src/MuonAnalysis/TagAndProbe/test/zmumu/tnpZ_Data.root";//"doubleMuonTrees/tnpZ_theTreeCleaned.root"; //TString fileMC = "newDoubleMuonTree/TnPtreeMC.root"; //TString fileData = "doubleMuonTrees/tnpZ_Data_25ns_run2015D_doubleMuon.root"; Eff( fileData, filenameData, "data_lumi"); //Eff( fileMC, filenameMC, "MC_lumi"); TFile * hData = new TFile("lumi_effData.root"); TH1F * histD = (TH1F *)hData->Get("hlumi_eff"); TFile * hMC = new TFile("lumi_effMC.root"); TH1F * histM = (TH1F *)hMC->Get("hlumi_eff"); TH1F * hlumi_DM = (TH1F *)histD->Clone("hlumi_DM"); hlumi_DM->Sumw2(); hlumi_DM->SetMinimum(0); hlumi_DM->Divide(histD, histM, 1, 1, "b"); hlumi_DM->SetTitle("dZ eff Data/MC"); hlumi_DM->GetXaxis()->SetTitle("lumi"); hlumi_DM->GetYaxis()->SetTitle("eff Data/MC"); TCanvas * C2 = new TCanvas(); C2->Draw(); hlumi_DM->Draw("colz"); //C2->SaveAs("dZ_lumi_DM.pdf"); }
//-------------------------------------------------------------------------------------------------- // make fake rate histogram from numerator and denominators //-------------------------------------------------------------------------------------------------- TH1F* createFakeRatePtHist(vector<string> datasetFiles, vector<string> datasetNames, int faketype, string histName) { string numeratorHistName = ""; string denominatorHistName = ""; string dirName = ""; if (faketype == 11) { dirName = "ComputeElectronFakeRateMod"; numeratorHistName = "hElectronNumeratorEt"; denominatorHistName = "hElectronDenominatorEt"; } else if (faketype == 13) { dirName = "ComputeMuonFakeRateMod"; numeratorHistName = "hMuonNumeratorPt"; denominatorHistName = "hMuonDenominatorPt"; } else { cerr << "Error: faketype = " << faketype << " is not recognized." << endl; return 0; } TH1F *denominator = addAllSamples(datasetFiles, datasetNames, dirName, denominatorHistName); TH1F *numerator = addAllSamples(datasetFiles, datasetNames, dirName, numeratorHistName); //create fake rate hist from denominator binning TH1F *fakeRateHist = (TH1F*)numerator->Clone(histName.c_str()); fakeRateHist->GetYaxis()->SetTitle("Fake Rate"); //divide by the denominator to get fake rate; fakeRateHist->Divide(denominator); return fakeRateHist; }
void HighlightZoom(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb) { TH1F *h = (TH1F *)obj; if(!h) return; TCanvas *c2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("c2"); static TH1 *hz = 0; if (!h->IsHighlight()) { // after highlight disabled if (c2) delete c2; if (hz) { delete hz; hz = 0; } return; } if (!c2) { c2 = new TCanvas("c2", "c2", 605, 0, 400, 400); c2->SetGrid(); if (hz) hz->Draw(); // after reopen this canvas } if (!hz) { hz = (TH1 *)h->Clone("hz"); hz->SetTitle(TString::Format("%s (zoomed)", hz->GetTitle())); hz->SetStats(kFALSE); hz->Draw(); c2->Update(); hz->SetHighlight(kFALSE); } Int_t zf = hz->GetNbinsX()*0.05; // zoom factor hz->GetXaxis()->SetRange(xhb-zf, xhb+zf); c2->Modified(); c2->Update(); }
void TAGH_doubles_E() { TDirectory *dir = (TDirectory*)gDirectory->FindObjectAny("TAGH_doubles"); if(dir) dir->cd(); TH1F *doubles =(TH1F*)gDirectory->Get("BeforeMergingDoubles/BM2_Energy"); TH1F *total =(TH1F*)gDirectory->Get("BeforeMergingDoubles/BM1_Energy"); TH1F *f_doubles = (TH1F*)doubles->Clone(); f_doubles->Sumw2(); f_doubles->Divide(doubles, total); if(gPad == NULL) { TCanvas *c1 = new TCanvas("c1","TAGH double-hit fraction",150,10,990,660); c1->cd(0); c1->Draw(); c1->Update(); } if(!gPad) return; TCanvas* c1 = gPad->GetCanvas(); gStyle->SetOptStat(""); f_doubles->SetTitle("TAGH double-hit fraction vs. energy"); f_doubles->SetTitleSize(0.045, "XY"); f_doubles->GetXaxis()->SetTitle("TAGH energy [GeV]"); f_doubles->GetYaxis()->SetTitle("double-hit fraction"); f_doubles->SetAxisRange(0.0,1.0,"Y"); f_doubles->Draw(); }
/* plotContainer* makeRatio (plotContainer& pcOS, plotContainer& pcSS, vector<pair <TString, TCut> >& selections, vector<string>& variablesList, vector <string>& samples, vector <float>& isoThr1, vector <float>& isoThr2 ) */ TH1F* makeRatio (plotContainer& pcOS, plotContainer& pcSS, pair <TString, TCut>& selection, string& varName, string& sampleName, float thr1, float thr2 ) { TString OS_selName = Form("OSaiso_%f_%f_", thr1, thr2); TString SS_selName = Form("SSaiso_%f_%f_", thr1, thr2); OS_selName = OS_selName + selection.first; SS_selName = SS_selName + selection.first; TH1F* hOS = pcOS.getHisto (varName, string(OS_selName.Data()), sampleName); TH1F* hSS = pcSS.getHisto (varName, string(SS_selName.Data()), sampleName); TString newName = "ratio_" + varName + "_" + selection.first + Form("_%f_%f", thr1, thr2) ; TH1F* hratio = (TH1F*)hOS->Clone(newName); hratio -> Divide (hSS); hratio -> SetMinimum(0.80); hratio -> SetMaximum(1.30); hratio -> GetYaxis()->SetTitle("OS/SS"); return hratio; }
TH1F* dist(TTree* treeElEl, TTree* treeMuMu, TTree* treeMuEl, const TString &variable, int nBin, float * bins, TCut precut, TCut precut_em, TCut fcut, const TString & name, const TString & tagName, int color, const TString & xtitle){ TCut dencut_em = precut_em + fcut; TCut dencut = precut + fcut; TH1F* h_eff = new TH1F(Form("h_eff_%s",name.Data()),"h_eff",nBin,bins); TH1F* hden = new TH1F(Form("hden_%s",name.Data()),"hden",nBin,bins); TH1F* hden_ee = new TH1F(Form("hden_%s_ee",name.Data()),"hden_ee",nBin,bins); TH1F* hden_mm = new TH1F(Form("hden_%s_mm",name.Data()),"hden_mm",nBin,bins); TH1F* hden_em = new TH1F(Form("hden_%s_em",name.Data()),"hden_em",nBin,bins); treeElEl->Project(Form("hden_%s_ee",name.Data()),Form("%s",variable.Data()),dencut,""); treeMuMu->Project(Form("hden_%s_mm",name.Data()),Form("%s",variable.Data()),dencut,""); treeMuEl->Project(Form("hden_%s_em",name.Data()),Form("%s",variable.Data()),dencut_em,""); hden->Add(hden_ee,1); hden->Add(hden_mm,1); hden->Add(hden_em,1); //TCanvas* tag_eff = new TCanvas(Form("eff_%s",name.Data()),Form("eff_%s",name.Data()),500,500); TH1F* h_effint = hden->Clone(); h_effint->Scale(1/h_effint->Integral()); h_effint->SetTitle(xtitle); h_effint->SetLineColor(color); h_effint->GetXaxis()->SetTitle(xtitle); h_effint->GetYaxis()->SetTitle("Normalized Entries"); return h_effint; }
void compnclusts(Int_t run) { TFile* f = new TFile(Form("hodtest_%d.root",run)); cout << "hcana root file " << Form("hodtest_%d.root",run) << endl; TH1F* h = nclust; TFile* f1 = new TFile(Form("%d_hbk.root",run)); cout << "Engine root file " << Form("%d_hbk.root",run) << endl; TH1F* h1; switch (run) { case 50017 : // h1 = h212; //A+ break; default : h1 = h412; //hnclusters } TCanvas *c1 = new TCanvas("c1", "Shower Cluster Map", 1000, 667); gPad->SetLogy(); h1->SetFillColor(kGreen); h1->SetLineColor(kGreen); h1->SetFillStyle(1111); h1->Draw(); h->SetFillColor(kBlue); h->SetLineWidth(2); h->SetFillStyle(0); h->Draw("same"); TLatex l; l.SetTextSize(0.04); Float_t maxy = h1->GetBinContent(h1->GetMaximumBin()); Float_t xmin = h1->GetXaxis()->GetXmin(); Float_t xmax = h1->GetXaxis()->GetXmax(); Float_t xt = xmin + 0.67*(xmax-xmin); l.SetTextColor(kGreen); l.DrawLatex(xt,0.095*maxy,"Engine"); l.SetTextColor(kBlue); l.DrawLatex(xt,0.045*maxy,"hcana"); // Difference between the histograms. TCanvas *c2 = new TCanvas("c2", "Cluster differences", 1000, 667); TH1F* dif = h->Clone(); dif->Add(h,h1,1.,-1.); dif->SetTitle("Difference"); dif->SetFillColor(kRed); dif->SetLineColor(kRed); dif->SetLineWidth(1); dif->SetFillStyle(1111); dif->Draw(); }
//_____________________________________________________________________________ Int_t ProofSimple::GetHistosFromFC(TCanvas *cv) { // Check for the histograms in the files of a possible TFileCollection TIter nxo(fOutput); TFileCollection *fc = 0; Bool_t fc_found = kFALSE, hs_found = kFALSE; while ((fc = (TFileCollection *) nxo())) { if (strcmp(fc->ClassName(), "TFileCollection")) continue; fc_found = kTRUE; if (!fHist) { fHist = new TH1F*[fNhist]; for (Int_t i = 0; i < fNhist; i++) { fHist[i] = 0; } } else { for (Int_t i = 0; i < fNhist; i++) { SafeDelete(fHist[i]); } } // Go through the list of files TIter nxf(fc->GetList()); TFileInfo *fi = 0; while ((fi = (TFileInfo *) nxf())) { TFile *f = TFile::Open(fi->GetCurrentUrl()->GetUrl()); if (f) { for (Int_t i = 0; i < fNhist; i++) { TString hn = TString::Format("h%d", i); TH1F *h = (TH1F *) f->Get(hn); if (h) { hs_found = kTRUE; if (!fHist[i]) { fHist[i] = (TH1F *) h->Clone(); fHist[i]->SetDirectory(0); } else { fHist[i]->Add(h); } } else { Error("GetHistosFromFC", "histo '%s' not found in file '%s'", hn.Data(), fi->GetCurrentUrl()->GetUrl()); } } f->Close(); } else { Error("GetHistosFromFC", "file '%s' could not be open", fi->GetCurrentUrl()->GetUrl()); } } if (hs_found) break; } if (!fc_found) return -1; if (!hs_found) return -1; for (Int_t i = 0; i < fNhist; i++) { cv->cd(i+1); if (fHist[i]) { fHist[i]->DrawCopy(); } } Info("GetHistosFromFC", "histograms read from %d files in TFileCollection '%s'", fc->GetList()->GetSize(), fc->GetName()); // Done return 0; }
void peaks(Int_t np=10) { npeaks = TMath::Abs(np); TH1F *h = new TH1F("h","test",500,0,1000); //generate n peaks at random Double_t par[3000]; par[0] = 0.8; par[1] = -0.6/1000; Int_t p; for (p=0;p<npeaks;p++) { par[3*p+2] = 1; par[3*p+3] = 10+gRandom->Rndm()*980; par[3*p+4] = 3+2*gRandom->Rndm(); } TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks); f->SetNpx(1000); f->SetParameters(par); TCanvas *c1 = new TCanvas("c1","c1",10,10,1000,900); c1->Divide(1,2); c1->cd(1); h->FillRandom("f",200000); h->Draw(); TH1F *h2 = (TH1F*)h->Clone("h2"); //Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(2*npeaks); Int_t nfound = s->Search(h,2,"",0.10); printf("Found %d candidate peaks to fit\n",nfound); //Estimate background using TSpectrum::Background TH1 *hb = s->Background(h,20,"same"); if (hb) c1->Update(); if (np <0) return; //estimate linear background using a fitting method c1->cd(2); TF1 *fline = new TF1("fline","pol1",0,1000); h->Fit("fline","qn"); //Loop on all found peaks. Eliminate peaks at the background level par[0] = fline->GetParameter(0); par[1] = fline->GetParameter(1); npeaks = 0; Double_t *xpeaks = s->GetPositionX(); for (p=0;p<nfound;p++) { Double_t xp = xpeaks[p]; Int_t bin = h->GetXaxis()->FindBin(xp); Double_t yp = h->GetBinContent(bin); if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue; par[3*npeaks+2] = yp; par[3*npeaks+3] = xp; par[3*npeaks+4] = 3; npeaks++; } printf("Found %d useful peaks to fit\n",npeaks); printf("Now fitting: Be patient\n"); TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks); //we may have more than the default 25 parameters TVirtualFitter::Fitter(h2,10+3*npeaks); fit->SetParameters(par); fit->SetNpx(1000); h2->Fit("fit"); }
//-------------------------------------------------------------------------------------------------- // make fake rate histogram from numerator and denominators //-------------------------------------------------------------------------------------------------- // TGraphAsymmErrors* createFakeRatePtHist(vector<string> datasetFiles, vector<string> datasetNames, // int denominatortype, int faketype, int chargetype, // int eventType, string histName) { TH1F* createFakeRatePtHist(vector<string> datasetFiles, vector<string> datasetNames, int denominatortype, int faketype, int chargetype, int eventType, string histName) { string numeratorHistName = ""; string denominatorHistName = ""; string dirName = ""; string chargeTypeName = ""; if (chargetype == -1) chargeTypeName = "Minus"; else if (chargetype == 1) chargeTypeName = "Plus"; string eventTypeName = ""; if (eventType == -1) eventTypeName = "MinusW"; else if (eventType == 1) eventTypeName = "PlusW"; string denominatorTypeName = ""; if (denominatortype == 1) denominatorTypeName = "Track"; if (faketype == 11) { dirName = "ComputeElectronFakeRateMod"; numeratorHistName = "h" + chargeTypeName + "Electron" + eventTypeName + "NumeratorPt"; denominatorHistName = "h" + chargeTypeName + "Electron" + eventTypeName + denominatorTypeName + "DenominatorPt"; } else if (faketype == 13) { dirName = "ComputeMuonFakeRateMod"; numeratorHistName = "h" + chargeTypeName + "Muon" + eventTypeName + "NumeratorPt"; denominatorHistName = "h" + chargeTypeName + "Muon" + eventTypeName + denominatorTypeName + "DenominatorPt"; } else { cerr << "Error in createFakeRatePtHist: faketype = " << faketype << " is not recognized." << endl; assert(false); } TH1F *denominator = addAllSamples(datasetFiles, datasetNames, dirName, denominatorHistName); TH1F *numerator = addAllSamples(datasetFiles, datasetNames, dirName, numeratorHistName); //create fake rate hist from denominator binning TH1F *fakeRateHist = (TH1F*)numerator->Clone(histName.c_str()); fakeRateHist->GetYaxis()->SetTitle("Fake Rate"); //divide by the denominator to get fake rate; fakeRateHist->Divide(denominator); //TGraphAsymmErrors* fakeRate = (numerator, denominator); //for (int i=1 ; i <= fakeRateHist->GetXaxis()->GetNbins(); i++) { //cout << i << " : " << fakeRateHist->GetXaxis()->GetBinCenter(i) << " " << fakeRateHist->GetBinContent(i) << " +- " << fakeRateHist->GetBinError(i) << endl; //if (fakeRateHist->GetBinContent(i) > 0 && fakeRateHist->GetBinError(i) < 0.01) { //fakeRateHist->SetBinError(i,0.01); //} //} return fakeRateHist; }
void JetTagBin::inputData( TFile * file ) { TH1F * tempDataHist = (TH1F*)file->Get(("Data_"+jtBinName_).c_str()); if ( verbose ) cout << "Loaded Data_" << jtBinName_ << " from the file." << endl; jtDataHist_ = (TH1F*) tempDataHist->Clone(); //include check on binning with respect to other histograms if ( jtData_ ) delete jtData_; jtData_ = new RooDataHist(("Data_"+jtBinName_).c_str(),("Data_"+jtBinName_).c_str(),*jtBinVar_,Import(*jtDataHist_)); }
void displaySingleChannelWaveforms(TString fdat, int board, int channel) { gStyle->SetOptStat(0); TFile *f = new TFile(fdat); if (f->IsZombie()){ cout << "Cannot open file: " << fdat << endl; return; } TBEvent *event = new TBEvent(); TTree *t1041 = (TTree*)f->Get("t1041"); TBranch *bevent = t1041->GetBranch("tbevent"); bevent->SetAddress(&event); TCanvas * canv = new TCanvas("canv", "canv", 2000, 2000); canv->cd(); TH1F * dummy = new TH1F("dummy", "dummy", 120, 0, 120); dummy->GetYaxis()->SetRangeUser(0, 2500); dummy->Draw(); vector<TH1F*> waves; TH1F * wave = new TH1F("wave", "wave", 120, 0, 120); int nplots = 0; for (Int_t i = 0; i < t1041->GetEntries(); i++) { t1041->GetEntry(i); for (int j = 0; j < event->NPadeChan(); j++){ PadeChannel pch = event->GetPadeChan(j); if((int)pch.GetBoardID() != board || (int)pch.GetChannelID() != channel) continue; pch.GetHist(wave); nplots++; TH1F * wavecopy = (TH1F*)wave->Clone("wave_"+TString(Form("%d", nplots))); waves.push_back(wavecopy); } } int nBigPeaks = 0; for(unsigned int ui = 0; ui < waves.size(); ui++) { if(waves[ui]->GetMaximum() > 400) { waves[ui]->SetLineColor(nBigPeaks+2); nBigPeaks++; } waves[ui]->Draw("same"); } }
//---------- Retrieve data histo ----------------- TH1F* GetData(TFile* fin, string region, string varname) { string cname = CHANNEL_NAME+string("/")+region+"/"+varname; TCanvas* c = (TCanvas*) fin->Get(cname.c_str()); TList* l = c->GetListOfPrimitives(); TPad* pad = (TPad*) l->At(0); string hname = "v:"+varname+"|r:"+region+string("|c:")+CHANNEL_NAME+string("|t:1DSumData"); TH1F* h = (TH1F*) pad->GetPrimitive(hname.c_str()); return (TH1F*) h->Clone(); }
//================================================ void DeltaZVsPt(const Int_t save = 0) { THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType])); TH2F *hTrkDzVsPt = (TH2F*)hn->Projection(1,0); c = draw2D(hTrkDzVsPt,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_vs_pt_%s.pdf",run_type,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_vs_pt_%s.png",run_type,trigName[kTrigType])); } Double_t pt_cut = 1; hTrkDzVsPt->GetXaxis()->SetRangeUser(pt_cut+0.1,100); TH1F *hMthDz = (TH1F*)hTrkDzVsPt->ProjectionY(Form("hTrkDzVsPt_%s_proj",trigName[kTrigType])); hMthDz->SetTitle(Form("%s: #Deltaz of matched track-hit pairs (p_{T}>%1.1f GeV/c);#Deltaz (cm)",trigName[kTrigType],pt_cut)); TH1F *hClone = (TH1F*)hMthDz->Clone(Form("%s_clone",hMthDz->GetName())); c = draw1D(hClone,"",kFALSE,kFALSE); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_%s.pdf",run_type,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_%s.png",run_type,trigName[kTrigType])); } Double_t range = 50; TF1 *func = new TF1("func","gaus(0)+gaus(3)",-1*range,range); func->SetParameters(10000,0,10,1000,0,40); c = FitDeltaZ(hMthDz,func,range,20.); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%s.pdf",run_type,pt_cut,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%s.png",run_type,pt_cut,trigName[kTrigType])); } // pt dependence Double_t pt_cuts[5] = {1,2,3,5,20}; for(Int_t i=0; i<4; i++) { hTrkDzVsPt->GetXaxis()->SetRangeUser(pt_cuts[i]+0.1,pt_cuts[i+1]-0.1); TH1F *htmp = (TH1F*)hTrkDzVsPt->ProjectionY(Form("hTrkDz_pt%1.0f-%1.0f_%s",pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); htmp->SetTitle(Form("%s: #Deltaz of matched track-hit pairs (%1.0f < p_{T} < %1.0f GeV/c);#Deltaz (cm)",trigName[kTrigType],pt_cuts[i],pt_cuts[i+1])); TF1 *func = new TF1(Form("func_pt%1.0f-%1.0f",pt_cuts[i],pt_cuts[i+1]),"gaus(0)+gaus(3)",-1*range,range); if(i==0) func->SetParameters(100,0,100,1000,0,10); if(i==1) func->SetParameters(1000,0,15,1000,0,60); if(i==2) func->SetParameters(1000,0,15,1000,0,60); if(i==3) func->SetParameters(1000,0,60,1000,0,15); c = FitDeltaZ(htmp,func,range,20.); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%1.0f_%s.pdf",run_type,pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%1.0f_%s.png",run_type,pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); } } }
void PoissonianMagic() { TFile file_PUnum("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/DataPUFile_22Jan2013ReReco_Run2012.root", "read"); TFile file_PUden("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/S10MC_PUFile.root", "read"); TH1F *data = (TH1F*)file_PUnum.Get("analyzeHiMassTau/NVertices_0"); data->Scale(1/data->Integral(0,-1)); TH1F *MC = (TH1F*)file_PUden.Get("analyzeHiMassTau/NVertices_0"); MC->Scale(1/MC->Integral(0,-1)); //define empty histograms for the smeared versions TH1F *num = (TH1F*)data->Clone("ratio"); for(int i=0; i<num->GetNbinsX(); i++) num->SetBinContent(i+1,0); TH1F *den = (TH1F*)data->Clone("MC"); for(int i=0; i<den->GetNbinsX(); i++) den->SetBinContent(i+1,0); //generate the poissonian distributions for(unsigned int i=0; i<data->GetNbinsX(); i++){ TF1 *Pd = new TF1("Pd", "TMath::PoissonI(x,[0])",0,100); Pd->SetParameter(0,data->GetBinLowEdge(i+1)); std::cout<<data->GetBinLowEdge(i+1)<<std::endl; TF1 *Pm = new TF1("Pm", "TMath::PoissonI(x,[0])",0,100); Pm->SetParameter(0,MC->GetBinLowEdge(i+1)); //add up the poissonians for(unsigned int j=0; j<data->GetNbinsX(); j++){ num->SetBinContent(j+1,num->GetBinContent(j+1)+Pd->Eval(j)/Pd->Integral(0,100)*data->GetBinContent(i+1)); den->SetBinContent(j+1,den->GetBinContent(j+1)+Pm->Eval(j)/Pm->Integral(0,100)*MC->GetBinContent(i+1)); } } //make the ratio and save the result num->Divide(den); TFile *f=new TFile("PUreweightHistogram.root","RECREATE"); num->Write(); den->Write(); f->Close(); file_PUnum.Close(); file_PUden.Close(); }
void closureTesterFSR(void) { TString REGIME = ""; //_corr //2D case TFile* g = new TFile("../Inputs/unfold/unfoldData_HLT_Double_2D_NoTRM.root"); g->cd(); TH1F* unfolded = (TH1F*)gDirectory->Get("hunfolded"); //FSR correction TFile* gg = new TFile("../Inputs/FSR/BinByBin.root"); gg->cd(); TH1F* FSRcorr_num = (TH1F*)gDirectory->Get("hpostFSR2"); TH1F* FSRcorr_den = (TH1F*)gDirectory->Get("hpreFSR2"); TH1F* FSRcorr = (TH1F*)FSRcorr_num->Clone(); FSRcorr->Divide(FSRcorr_num,FSRcorr_den); for (int i = 0; i < 132; i++) { unfolded->SetBinContent(i+1,unfolded->GetBinContent(i+1)*FSRcorr->GetBinContent(i+1)); } unfolded->SetMarkerStyle(22); unfolded->GetXaxis()->SetTitle("Bin number"); unfolded->GetYaxis()->SetTitle("Events"); unfolded->Draw("hist"); TH1D* other = (TH1D*)unfolded->Clone(); other->SetMarkerStyle(22); other->SetMarkerColor(kRed); other->SetLineColor(kRed); other->Draw("Psame"); TCanvas* c = new TCanvas(); c->cd(); TH1D* ratio = (TH1D*)unfolded->Clone(); ratio->Divide(other,unfolded); ratio->SetMarkerStyle(22); ratio->GetXaxis()->SetTitle("N_{unfolded}/N_{preunfolded}"); ratio->GetXaxis()->SetTitle("Bin number"); ratio->Draw("P"); }
JetTagBin::JetTagBin(TFile & file, string jtBinName, vector<Sample> theSamples): jtBinName_(jtBinName) { jtBinVar_= new RooRealVar(jtBinName.c_str(), jtBinName.c_str(), 50, 600); int nbins_def = 0; for(unsigned int i=0;i<theSamples.size();++i) { string name = theSamples[i].name()+jtBinName; string histname = ""; if ( theSamples[i].sampName()=="" ) histname = name; else histname = theSamples[i].sampName()+jtBinName; if ( verbose ) cout << "Opening histogram " << histname << endl; TH1F * tempHisto = (TH1F*)file.Get(histname.c_str()); TH1F * tempHisto2; if(tempHisto==0) { cout << "Template " << name << " does not exist" << endl; assert(0); // maybe we don't assert but rather break/continue so we can easily work with different jtbin names } else { tempHisto2 = (TH1F*) tempHisto->Clone(); // delete tempHisto; } // We set the binning, assuming all samples have the same binning int nbins = tempHisto2->GetNbinsX(); if(i==0) { nbins_def = nbins; int xlo = tempHisto2->GetBinLowEdge(1); int xhi = tempHisto2->GetBinLowEdge(nbins + 1); RooUniformBinning jtBinning(xlo,xhi,nbins_def); jtBinVar_->setBinning(jtBinning); } else { if (nbins!=nbins_def) { cout << "something here " << endl; assert(0); } } Template * temp = new Template(*tempHisto2, name, *jtBinVar_, theSamples[i]); jtTemplates_.push_back( temp ); delete tempHisto2; } if ( verbose ) cout << "Making combined pdf" << endl; RooArgList TemplateList; for(unsigned int i=0;i<jtTemplates_.size();++i) { TemplateList.add(*(jtTemplates_[i]->epdf())); } jtPdf_ = new RooAddPdf((jtBinName_+"_pdf").c_str(),(jtBinName_+"_pdf").c_str(),TemplateList); jtData_ = 0; jtNll_ = 0; }
void EflowCASTOR() { NCanvas(1,2,"data"); TH1F * HDat; TH1F * HZ2; // TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root"); TFile *fzee = new TFile("ZDiffOutputfile.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_DATA"); HZ2 = (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_Z2PY6"); data->cd(1); NHSetMarker(HDat,2,20,0.8); HDat->SetMinimum(10); HDat->Draw(); NStat(HDat,0); NSetTitle(HDat,"CASTOR Modules", "Entries"); HDat->SetTitle("CASTOR Module Energy 2010"); HZ2->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.06); legend->SetBorderSize(0); legend->AddEntry(HDat,"Data2010","p"); legend->AddEntry(HZ2,"Z2","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDat->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); NHSetMarker(Hra,4,20,0.8); Hra->SetMinimum(1); Hra->Divide(HZ2); NLogAxis(0,0); data->cd(2); Hra->Draw(); Hra->SetTitle("Ratio DATA/MC"); Hra->Fit("pol0"); NSetTitle(Hra,"CASTOR Modules", "Ratio"); NLogAxis(0,1); }
TH1F *giveEfficiency(TString nomPlot, TString variable, float *theBins, int nbBins){ TH1F *denom = new TH1F("denom", "", nbBins, theBins); TH1F *num = new TH1F("num", "", nbBins, theBins); TString baseCut = "abs(T_Gen_Muon_PDGid)==13&&T_Gen_Muon_Pt>7&&abs(T_Gen_Muon_Eta)<2.4"; chain->Draw(variable+">>denom",baseCut); chain->Draw(variable+">>num",baseCut+"&&T_Gen_Muon_L2crudeMaching==1"); TH1F *efficiency = (TH1F*) denom->Clone(nomPlot); efficiency->Sumw2(); efficiency->Divide(num, denom, 1,1); delete denom; delete num; return efficiency; }
//loads single track pT efficiency from root file TH1F *GetEfficiencyPt(TString effLoc){ TFile *fIn = 0; TH1F *hEffPt = 0; if(!fIn)fIn = TFile::Open(effLoc.Data()); if(!fIn)Printf("%s%d no input data",(char*)__FILE__,__LINE__); if(!hEffPt)hEffPt = (TH1F*)fIn->Get("hSingleTrackEffPt"); if(!hEffPt)Printf("%s%d no single track efficiency spectrum available",(char*)__FILE__,__LINE__); gROOT->cd(); TH1F *hEffPtClone = (TH1F*)hEffPt->Clone(hEffPt->GetName()); fIn->Close(); return hEffPtClone; }
//________________________________________________________________________________ TH1F* makeEffSyst(TString dir , TString ctr , TString acc){ TFile* f_unf = getFile("files/unfold_outputs/" + dir + "/unf_MC31_partfull_HF0_" + ctr + "_INEL_" + acc + ".root"); TH1F* eff_ctr_gen = getHist<TH1F>(*f_unf , "eff_centrSel"); TH1F* eff_trg_gen = getHist<TH1F>(*f_unf , "eff_evtSel"); TH1F* unfoldedPtr = getHist<TH1F>(*f_unf , "nch_unfoldedPtr"); TFile* f_mc = getFile("files/outputs_full/" + dir + "/effs_MC31_ferncTr_E_7_5000000_allEffs.root"); TH1F* eff_trg_reco_mc = getHist<TH1F>(*f_mc , "eff_evtSel_RECO_HF0_" + ctr + "_RECO_" + acc); TFile* f_0b = getFile("files/outputs_full/" + dir + "/effs_zerobias_ferncTr_E_7_482270.root"); TH1F* eff_trg_reco_0b = getHist<TH1F>(*f_0b , "eff_evtSel_RECO_HF0_" + ctr + "_RECO_" + acc); TH1F* eff_syst = (TH1F*) eff_trg_gen->Clone("eff_syst"); for(int i = 1 ; i <= unfoldedPtr->GetNbinsX() ; ++i){ Double_t bin = eff_trg_gen->GetBinContent(i) + eff_trg_reco_0b->GetBinContent(i) - eff_trg_reco_mc->GetBinContent(i); if(bin>1) eff_syst->SetBinContent(i,1.); else if(bin<0) eff_syst->SetBinContent(i,0.); else eff_syst->SetBinContent(i,bin); } TH1F* eff_tot = (TH1F*) eff_trg_gen->Clone("eff_tot"); eff_tot->Multiply(eff_ctr_gen,eff_syst,1,1); TH1F* nch_data_corrected = (TH1F*) unfoldedPtr->Clone("nch_data_corrected"); nch_data_corrected->Divide(nch_data_corrected , eff_tot , 1 , 1); delete f_unf ; delete eff_ctr_gen ; delete eff_trg_gen ; delete unfoldedPtr ; delete f_mc; delete eff_trg_reco_mc; delete f_0b; delete eff_trg_reco_0b; delete eff_syst; delete eff_tot; return nch_data_corrected; }
int load_spe(char *filename,TH1F* histo) { int idim1,idim2,j,rl; int swap = -1; char cbuf[128]; FILE *infile; char namesp[8]; //int numch; infile = fopen(filename,"r"); rl = get_file_rec(infile,cbuf,128,0); strncpy(namesp,cbuf,8); memcpy(&idim1,cbuf+8,4); memcpy(&idim2,cbuf+12,4); const int numch = idim1 * idim2; float sp[numch]; TH1F *temp = new TH1F("temp",filename,numch,0,numch); //histo->SetName(filename); //histo->GetXaxis()->SetTitle("Energy"); //histo->SetBinsLength(numch); //histo->SetAxisRange(0,numch,"X"); //histo->SetMinium(0); //histo->SetMaxium(numch); rl = get_file_rec(infile,sp,4*numch,swap); fclose(infile); for(j=0;j<numch;j++) { //if(sp[j]>0){cout << j << "\t" << sp[j] << endl; } //histo->SetBinContent(j,sp[j]); temp->Fill(j,sp[j]); } *histo = (TH1F*)temp->Clone(); histo->SetName(filename); cout << "loaded\n"; return 0; }
void plotweight(int isub){ TFile *f = TFile::Open("/phenix/u/xuq/xuq/taxi/Run15pAu200FVTXClusAna503/8845/data/435527_0.root"); int ivz = 0; TH1F* h = (TH1F*)f->Get(Form("phiweight_0_0_0_%d_0_%d",ivz,isub)); TH1F* hc = (TH1F*)h->Clone("hc"); h->Rebin(4); hc->Rebin(4); for(int ibin=0;ibin<=h->GetNbinsX();ibin++){ if(h->GetBinContent(ibin)!=0) hc->SetBinContent(ibin,h->Integral()/h->GetNbinsX()/h->GetBinContent(ibin)); else hc->SetBinContent(ibin,1.); } TCanvas *c1 = new TCanvas("c1"); hc->Draw(); TCanvas *c2 = new TCanvas("c2"); h->Draw(); }
TH1F* GetHisto(TFile* fin, string region, string process, string varname, float& norm, bool do_norm, float input_norm) { string cname = CHANNEL_NAME+string("/")+region+"/"+varname; TCanvas* c = (TCanvas*) fin->Get(cname.c_str()); string hname = "v:"+varname+"|p:"+process+"|r:"+region+string("|c:")+CHANNEL_NAME+string("|t:1DEntries"); TH1F* h = 0; if(VERBOSE>0){ cerr<<"cname :"<<cname<<endl; cerr<<"histo name: "<<hname<<endl; cerr<<"pointer: "<<c<<endl; } TList* l = c->GetListOfPrimitives(); TPad* pad = (TPad*) l->At(0); THStack* stack = (THStack*) pad->GetPrimitive(""); h = (TH1F*) stack->GetHists()->FindObject(hname.c_str()); if(do_norm) h->Scale(input_norm/h->Integral()); norm = h->Integral(); return (TH1F*) h->Clone(); }
void pseudodata() { TString var_y = "eta_lj"; TFile *f = new TFile("histos/lqeta.root"); TFile *fo = new TFile("histos/pseudo_data.root","RECREATE"); fo->cd(); vector<TString> names; vector<Float_t> scales; vector<Float_t> uncs; vector<TH1F*> histos; read_fitres(names,scales,uncs); Int_t nbkgs = names.size()-1; TH1::SetDefaultSumw2(true); TH1F *hsignal = (TH1F*)f->Get(var_y+"__tchan"); hsignal->Scale(scales[0]); // Artificially enhance signal fraction // FIXME //hsignal->Scale(2); hsignal->Write(); TH1F *added = (TH1F*)hsignal->Clone(var_y+"__DATA"); // Read in background histograms for(int i = 0; i < nbkgs ; i++) { TString name = names.at(i+1); TH1F *histo = (TH1F*)f->Get(var_y+"__"+name); // Scale histos histo->Scale(scales[i+1]); added->Add(histo); histo->Write(); } cout << added->Integral() << endl; fo->cd(); added->Write(); fo->Close(); }
// Called just after the main event loop // Can be used to write things out, dump a summary etc // Return non-zero to indicate a problem int IslandAmplitude::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){ // Print extra info if we're debugging this module: if(Debug()){ cout<<"-----IslandAmplitude::AfterLastEntry(): I'm debugging!"<<endl; } double run_norm = fAmpNorm->Integral(0,-1); for(mapSH_t::iterator it = fAmpHist.begin(); it != fAmpHist.end(); ++it) { TH1F* h = it->second; TObject* obj = h->Clone((std::string(h->GetName()) + "_RunNorm").c_str()); TH1* hn = static_cast<TH1*>(obj); hn->SetTitle((std::string(h->GetTitle()) + " (run normalized)").c_str()); hn->Scale(1.0/run_norm); } for(mapSH_t::iterator it = fAmpHistNorm.begin(); it != fAmpHistNorm.end(); ++it) it->second->Scale(1.0/fNProcessed); return 0; }
void plotweight(int isub){ TFile *f = TFile::Open("/phenix/plhf/xuq/taxi/Run15pAl200MBPro104/10241/data/438026_0.root"); //TFile *f = TFile::Open("/phenix/u/xuq/xuq/phenix/flow/PP/work/Run15pp200MinBias/output_fvtxclus.root"); int ivz = 0; if(isub!=4){ TH1F* h = (TH1F*)f->Get(Form("phiweight_0_0_0_%d_0_%d",ivz,isub)); //TH1F* h = (TH1F*)f->Get(Form("fvtxphi_%d_%d",ivz,isub)); TH1F* hc = (TH1F*)h->Clone("hc"); for(int ibin=0;ibin<=h->GetNbinsX();ibin++){ if(h->GetBinContent(ibin)!=0) hc->SetBinContent(ibin,h->Integral()/h->GetNbinsX()/h->GetBinContent(ibin)); else hc->SetBinContent(ibin,1.); } } else{ TProfile* h = (TProfile*)f->Get(Form("phiweightbbc_0_0_0_%d_0_%d",ivz,isub)); TProfile* hc = (TProfile*)h->Clone("hc"); } TCanvas *c1 = new TCanvas("c1"); hc->GetYaxis()->SetRangeUser(0,2); hc->Draw(); TLine *l1 = new TLine(-3.14,0.8,3.14,0.8); l1->SetLineStyle(2); l1->SetLineColor(2); // l1->Draw(); TLine *l2 = new TLine(-3.14,1.2,3.14,1.2); l2->SetLineStyle(2); l2->SetLineColor(2); // l2->Draw(); if(isub!=4) c1->Print(Form("FVTXweight%d.png",isub)); TCanvas *c2 = new TCanvas("c2"); h->GetXaxis()->SetRangeUser(0,64); h->GetYaxis()->SetRangeUser(0.5,3); h->Draw(); if(isub==4) c2->Print(Form("BBCweight%d.png",isub)); }
void PileUpMaker() { // Access data file TFile *file = TFile::Open("ZmumuGammaNtuple_Full2012_MuCorr.root"); TTree *Datatree = (TTree*)file->Get("ZmumuGammaEvent"); // Set up histogram for data pile up TH1F *pileupraw = new TH1F("pileup","",40,0,80); // Fill pile up distribution Int_t nentries = Datatree->GetEntriesFast(); Int_t nbytes = 0; for (Int_t i=0; i<nentries;i++) { nbytes += Datatree->GetEvent(i); UInt_t NVertices; Datatree->SetBranchAddress("NVertices",&NVertices); pileupraw->Fill(float(NVertices)/0.7); } // Normalize the distribution TH1F* PU = (TH1F*)pileupraw->Clone("pileup"); PU->Scale(1./PU->Integral()); // Plot both the normalized and unnormalized pile up TCanvas *cv = 0; cv= new TCanvas("cv","cv",800, 600); pileupraw->Draw(""); cv->SaveAs("DataPU.pdf"); cv= new TCanvas("cv","cv",800,600); PU->Draw(""); cv->SaveAs("DataPU_normalized.pdf"); // Save the normalized distribution to a root file for weighting MC TFile *file = TFile::Open("2012_PhosphorData_PileUp.root","UPDATE"); file->cd(); file->WriteTObject(PU,PU->GetName(),"WriteDelete"); file->Close(); delete file; }