TH1D* plot (std::string num, std::string den,std::vector<TFile*>& tfiles,std::vector<double>& weights) { double weightTot = 0.0; for ( int i = 0; i<weights.size(); i++) { weightTot+=weights[i]; } std::string name = num; name+="NEW"; TH1D* hNum = (TH1D*)tfiles[0]->Get(num.c_str()); TH1D* HNum = (TH1D*)hNum->Clone(name.c_str()); HNum->Sumw2(); name=den; name+="NEW"; TH1D* hDen = (TH1D*)tfiles[0]->Get(den.c_str()); TH1D* HDen = (TH1D*)hDen->Clone(name.c_str()); HDen->Sumw2(); for (int i=1; i<tfiles.size(); i++) { TH1D* htempNum = (TH1D*)tfiles[i]->Get(num.c_str()); TH1D* htempDen = (TH1D*)tfiles[i]->Get(den.c_str()); HNum->Add(htempNum,weights[i]/weightTot); HDen->Add(htempDen,weights[i]/weightTot); } name = num; name+="Div"; TH1D* hDiv = (TH1D*)HNum->Clone(name.c_str()); //hDiv->Sumw2(); hDiv->Divide(HDen); return hDiv; }
TH1D *haddHistos(TFile *fileName,TString histoName,vector<TString> ST,vector<TString> HT) { TH1::SetDefaultSumw2(); TH1D *hInit = (TH1D*)fileName->Get("ANplots"+ST[0]+"_NOLPsecondD"+HT[0]+"/"+histoName); hInit->SetName(histoName); // ---- loop over all the STbins for (int iST=0; iST<ST.size(); iST++) { if (ST.size()>1) { TH1D *hTempST = (TH1D*)fileName->Get("ANplots"+ST[iST]+"_NOLPsecondD"+HT[iHT]+"/"+histoName); hInit->Add(hInit,hTempST,1.,1.); } // ---- loop over all the STbins for (int iHT=0; iHT<HT.size(); iHT++) { if (HT.size()>1) { TH1D *hTempHT = (TH1D*)fileName->Get("ANplots"+ST[iST]+"_NOLPsecondD"+HT[iHT]+"/"+histoName); hInit->Add(hInit,hTempHT,1.,1.); } } // --- end of looping over HTbins } // --- end of looping over STbins return hInit; }
TH1D* CutFlow::allMChisto(AllSamples samples, Variable variable){ TH1D *allMC = (TH1D*)samples.ttbar->histo->Clone("all mc"); allMC->Add(samples.qcd->histo); allMC->Add(samples.vjets->histo); allMC->Add(samples.single_t->histo); return allMC; }
// Merge same modes int dmMerge(TObject *a1, TObject *b1,TList *keys) { TDecayMode *a=(TDecayMode*)a1; TDecayMode *b=(TDecayMode*)b1; TIter nexthist(keys); TKey *key_hist=0; while(key_hist=(TKey*)nexthist()) { int cycle=-10; if(strcmp(key_hist->GetClassName(),"TH1D")==0) { TH1D *h=0; int cycleh=key_hist->GetCycle(); if(cycleh<cycle) { cout<<"Skipping..."<<endl; continue; } if(cycle<cycleh) cycle=cycleh; h=(TH1D*)key_hist->ReadObj(); if(!h) { cout<<"Cannot read: "<<key_hist->GetName()<<endl; exit(-2); } TH1D *eh = (TH1D*) a->histograms->FindObject(h->GetName()); if(!eh) continue; if(eh->GetNbinsX()!=h->GetNbinsX() || eh->GetXaxis()->GetXmax()!=h->GetXaxis()->GetXmax()) return -1; eh->Add(h); } } a->SetNEntries(a->GetNEntries()+b->GetNEntries()); a->SetSumw(a->GetSumw()+b->GetSumw()); a->SetSumw2(a->GetSumw2()+b->GetSumw2()); return 0; }
TH1D *CombineCFs(vector<TH1D*> cfs, vector<Double_t> counts) { // Take in a vector of cfs and a vector of counts, and use them to // make an averaged correlation function UInt_t nCFs = cfs.size(); if(nCFs == 0) { cout << "No CFs found in collection. Cannot combine" << endl; return NULL; } else if (nCFs == 1) { cout<<"Only one cf found in collection."<<endl <<"Cannot combine."<<endl <<"Returning the found CF."<<endl;; return cfs[0]; } assert(nCFs == counts.size()); TH1D *combinedCF = (TH1D*)cfs[0]->Clone(); combinedCF->Scale(counts[0]); Double_t totalCounts = counts[0]; // Add together weighted cfs for(UInt_t i = 1; i < nCFs; i++) { TH1D *copyCF = (TH1D*) cfs[i]->Clone(); Double_t thisCount = counts[i]; copyCF->Scale(thisCount); combinedCF->Add(copyCF); totalCounts += thisCount; delete copyCF; copyCF = NULL; } // Now get average combinedCF->Scale(1./totalCounts); return combinedCF; }
void calculateBayesErrors(int BgID){ TH1D *hist; for(int k=0; k<2; k++){ //###sum over A B C D regions for(int i=0; i<2; i++){ for(int j=0; j<2; j++){ if(i==0 && j==0) hist = (TH1D*)histRaw[BgID-1][k][0][i][j]->Clone(); else hist->Add(Form("Hist.hist%d%d",i,j),1); } } double scale_factor = L*pb2fb*X_bg[BgID-1]; //###calculate Bayesian Errors for(int i=0; i<2; i++){ for(int j=0; j<2; j++){ for(int s=0; s<5; s++){//spectrum graph[BgID-1][k][s][i][j] = new TGraphAsymmErrors(Nbins); graph[BgID-1][k][s][i][j] -> BayesDivide(histRaw[BgID-1][k][s][i][j],hist); for(int bin=0; bin<graph[BgID-1][k][s][i][j]->GetN(); bin++){ double x,y,err; graph[BgID-1][k][s][i][j]->GetPoint(bin,x,y); histYield[BgID-1][k][s][i][j]->SetBinContent(bin,y*scale_factor); err = sqrt( pow(Err_X_bg[BgID-1]/X_bgi[BgID-1],2) + pow(graph[BgID-1][k][s][i][j]->GetErrorYlow(bin)/y,2) ); YieldErrors[BgID-1][k][s][i][j][bin][0] = err*(y*scale_factor); err = sqrt( pow(Err_X_bg[BgID-1]/X_bgi[BgID-1],2) + pow(graph[BgID-1][k][s][i][j]->GetErrorYhigh(bin)/y,2) ); YieldErrors[BgID-1][k][s][i][j][bin][1] = err*(y*scale_factor); } } } } }//end of k }
// Convert plots to paper format - no title, bigger fonts etc void combineHists( TFile* fSig, TFile* fBg, TFile* fBg2, std::string histName, std::string plotOpt, std::string outputName, std::vector<double> scalingFactors, std::string label, std::string yTitle="DEFAULT"){ TH1::SetDefaultSumw2(); // for 3 hists - sig and 2 bg TCanvas c1; TH1D* hSig = fSig->Get(histName.c_str()); hSig->SetLineColor(kRed); hSig->SetMarkerSize(0); doSignalHist(hSig); // Make combined BG hist // Need to rescale carefully std::vector<TFile*> files; files.push_back(fBg); files.push_back(fBg2); // TH1D* hBg = combine(files, histName, scalingFactors); TH1D* hBgA = fBg->Get(histName.c_str()); TH1D* hBgB = fBg2->Get(histName.c_str()); TH1D* hBg = (TH1D*) hBgA->Clone(); double total = scalingFactors[0]+scalingFactors[1]; hBg->Scale(scalingFactors[0]/total); hBg->Add(hBgB, scalingFactors[1]/total); hBg->SetMarkerSize(0); doAltBGHist(hBg); THStack st("h",""); st.Add(hSig); st.Add(hBg); st.Draw((plotOpt+"NOSTACK").c_str()); st.GetXaxis()->SetTitle(hSig->GetXaxis()->GetTitle()); if (yTitle == "DEFAULT") { st.GetYaxis()->SetTitle(hSig->GetYaxis()->GetTitle()); } else { st.GetYaxis()->SetTitle(yTitle.c_str()); } setAltTitleLabelSizes(&st.GetHistogram()); st.SetTitle(""); st.Draw((plotOpt+"NOSTACK").c_str()); TLegend* l_all = new TLegend(0.65,0.6,0.89,0.89); l_all->AddEntry(hBg,"Gen. level QCD MC","lp"); l_all->AddEntry((TObject*)0,"(b#bar{b} + q-g scatter,",""); //null pointers for blank entries l_all->AddEntry((TObject*)0,"q = b, #bar{b}, c, #bar{c})",""); l_all->AddEntry(hSig, "Signal MC", "lp"); l_all->AddEntry((TObject*)0,"m_{#phi} = 8 GeV", ""); doStandardLegend(l_all); l_all->Draw(); TPaveText t(0.15, 0.75, 0.5, 0.85, "NDC"); t.AddText(label.c_str()); doStandardText(&t); if (label != "") { t.Draw(); } c1.SaveAs(outputName.c_str()); if (!hSig) delete hSig; if (!hBg) delete hBg; }
// 1 file argument -> add e+m from same files e.g. mc // this is considered to be MC -> added to sum histo TH1D* get(const TString& File){ // TFile file(path+File); TH1D* mH = (TH1D*)file.Get(mName); TH1D* eH = (TH1D*)file.Get(eName); gROOT->cd(); TH1D* H = mH->Clone();// Sumw2() is copied as well H->Add(eH); return H; }
// 2 file arguments -> add e+m from different files e.g. data // this is considered to be data not added to sum histo TH1D* get(const TString& eFile, const TString& mFile){ TFile mfile(path+mFile); TFile efile(path+eFile); TH1D* mH = (TH1D*)mfile.Get(mName); TH1D* eH = (TH1D*)efile.Get(eName); gROOT->cd(); TH1D* H = mH->Clone(); H->Add(eH); return H; }
int main(){ TFile * data = TFile::Open("TreesMu_Data_plots.root"); TH1D * dataMtop = (TH1D*)data->Get("antiEtaFwDTrue_allW/antiEtaFwDTrue_allWcosTheta"); TFile * tt = TFile::Open("TreesMu_TTBar_RW.root"); TH1D * ttMtop = (TH1D*)tt->Get("MtopOutWindowTrue_allW/MtopOutWindowTrue_allWcosTheta"); TH2D * ttMtop2D = (TH2D*)tt->Get("MtopOutWindowTrue_allW/MtopOutWindowTrue_allWcosTheta2D"); std::pair<TF1, WeightFunctionCreator*> WeightFuncUD(WeightFunctionCreator::getWeightFunction("WeightFuncUDF", F0, FL)); std::pair<TF1, WeightFunctionCreator*> WeightFuncDU(WeightFunctionCreator::getWeightFunction("WeightFuncDUF", F0, FL)); cout<<F0 + F0Sys<<"\t"<<FL - FLSys<<endl; WeightFuncUD.first.SetParameters(F0 + F0Sys, FL - FLSys); WeightFuncDU.first.SetParameters(F0 - F0Sys, FL + FLSys); TH1D * ttUD = myReweightor(ttMtop2D,WeightFuncUD,"WeightFuncUD_"); cout<<"ratio: "<<ttMtop2D->Integral()/ttUD->Integral()<<endl; ttUD->Scale(ttMtop2D->Integral()/ttUD->Integral()); ttUD->Add(ttMtop); TH1D * wUD = (TH1D*)ttUD->Clone("wUD"); wUD->Scale(-1.); wUD->Add(dataMtop); TH1D * ttDU = myReweightor(ttMtop2D,WeightFuncDU,"WeightFuncDU_"); cout<<"ratio: "<<ttMtop2D->Integral()/ttDU->Integral()<<endl; ttDU->Scale(ttMtop2D->Integral()/ttDU->Integral()); ttDU->Add(ttMtop); TH1D * wDU = (TH1D*)ttDU->Clone("wDU"); wDU->Scale(-1.); wDU->Add(dataMtop); TFile * out = new TFile("file.root","recreate"); out->cd(); WeightFuncUD.first.Write(); WeightFuncDU.first.Write(); ttUD->Write(); ttDU->Write(); wUD->Write(); wDU->Write(); out->Close(); return 1; }
TH1D* ratioCalculator(TH1D* passTH1, TH1D* failTH1) { passTH1->Sumw2(); TH1D *sum = (TH1D*)passTH1->Clone(); failTH1->Sumw2(); sum->Add(failTH1); passTH1->Divide(passTH1,sum,1,1,"B"); return passTH1; }
/* Returns full reconstructed thetaC histogram where each MCP has been shifted such that the mean of the gaussian aligns with the expected value */ TH1D* ThetaCorr( TTree *&tree, bool prot = 1, TString pidcut = "PID>1000", double *&shifts, TString corrtitle = "theta", int bins = 120 ) { double angleP = 0.8168; // assume 7 GeV for now double anglePi = 0.8249; double angle; if(prot) angle = angleP; else angle = anglePi; const int nMCP = 15; TH1D *mcpHist[nMCP]; TH1D *thetaCorr = new TH1D(corrtitle,corrtitle,bins,0.6,1); TF1 *mcpfit = new TF1("mcpfit","gaus"); mcpfit->SetParameters(100,angle,0.007); double diffpeak = DiffPeak(tree,pidcut); pidcut += Form(" && abs(diff-%f)<1",diffpeak); // loop over mcps for(int mcpid = 0; mcpid < nMCP; mcpid++) { // get timing peak for MCP=mcpid TString cut = pidcut + Form(" && mcp==%d",mcpid); //cut += Form(" && mcp==%d",mcpid); //double diffpeak = DiffPeak(tree,cut); //cout << "MCP " << mcpid << " time shift\t" << diffpeak << endl; // project from tree // using PID cut and time cut //cut += Form(" && abs(diff-%f)<1",diffpeak); TString mcpname = Form("mcp%d",mcpid); mcpHist[mcpid] = new TH1D(mcpname,mcpname,bins,0.6,1); tree->Project(mcpname,"theta",cut); mcpHist[mcpid]->GetXaxis()->SetRangeUser(angle-0.04,angle+0.04); double max = mcpHist[mcpid]->GetXaxis()->GetBinCenter(mcpHist[mcpid]->GetMaximumBin()); //cout << "max\t" << max << endl; mcpHist[mcpid]->Fit(mcpfit,"lq","",max-0.03,max+0.03); mcpHist[mcpid]->GetXaxis()->UnZoom(); double shift = angle - mcpfit->GetParameter(1); shifts[mcpid] = shift; //cout << "shift\t" << shift << endl; tree->Project(mcpname,Form("theta+%f",shift),cut); thetaCorr->Add(mcpHist[mcpid]); } return thetaCorr; }
TH1D* addScale(std::vector<TH1D*> plots, std::vector<double> scalingFactors) { TH1::SetDefaultSumw2(); TH1D* h = (TH1D*)plots[0]->Clone(plots[0]->GetName()); h->Scale(scalingFactors[0]); for (unsigned i = 1; i < plots.size(); i++) { // TH1D* hTmp = (TH1D*)plots[i]->Rebin(nBinsX, plots[0]->GetTitle(), &massBins[0]); h->Add(plots[i], scalingFactors[i]); } return h; }
TH1D* combine(std::vector<TFile*> files, std::string histName, std::vector<double> scalingFactors) { TH1::SetDefaultSumw2(); // Get 1st hist in list TH1D* h = (TH1D*)files[0]->Get(histName.c_str())->Clone(files[0]->Get(histName.c_str())->GetName()); h->Scale(scalingFactors[0]); for (unsigned i = 1; i < files.size(); i++) { TH1D* hTmp = (TH1D*) (files[i]->Get(histName.c_str())); h->Add(hTmp, scalingFactors[i]); } return h; }
/* Get a fake estimate from the given histogram, i.e. return Data - MC. * * Subtract all background MCs from data but the one specified with * "notremove". Under- and overflows are ignored in computation. * * @param hname Histogram name from which to compute estimate * @return Histogram of fakes */ TH1D * get_fakes_1d(const char * hname) { // get number of single fakes from data histogram plot(hname); legend(); TH1D * hData = dataHisto(); if (hData == 0) { THROW("get_fakes() needs a data histogram"); } // data double N = hData->Integral(); INFO("Data events: " << N); TH1D * hBack = 0; for (unsigned int i = 0; i < sizeof(removeNames)/sizeof(void *); i++) { TH1D * hSub = backgroundHisto(removeNames[i]); if (hSub == 0) { THROW(string("get_fakes() problem getting background ")+removeNames[i]); } // add backgrounds together if (hBack == 0) { hBack = hSub; } else { hBack->Add(hSub); delete hSub; } } N = hBack->Integral(); INFO("Background events : " << N); // subtract hData->Add(hBack, -1.); // temporarily needed for function call delete hBack; return hData; }
double getQCD(TString Variable, TString Obj, int rebinFact, double *errorRef) { TString dir = "rootFilesV4/central/"; TFile* file = new TFile(dir + "SingleMu_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root"); TFile* tt_file = new TFile(dir + "TTJet_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root"); TFile* vjets_file = new TFile(dir + "VJets_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root"); TFile* stop_file = new TFile(dir + "SingleTop_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root"); cout << "TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets ge3j/"+Obj+"0btag" << endl; TString IsoFolder; if(Variable == "HT") { IsoFolder = "QCD mu+jets PFRelIso"; } else { IsoFolder = "QCD non iso mu+jets ge3j"; } TH1D* plot = (TH1D*) file->Get("TTbar_plus_X_analysis/MuPlusJets/"+IsoFolder+"/"+Obj+"0btag"); plot->Sumw2(); TH1D* tt_plot = (TH1D*) tt_file->Get("TTbar_plus_X_analysis/MuPlusJets/"+IsoFolder+"/"+Obj+"0btag"); TH1D* vjets_plot = (TH1D*) vjets_file->Get("TTbar_plus_X_analysis/MuPlusJets/"+IsoFolder+"/"+Obj+"0btag"); TH1D* stop_plot = (TH1D*) stop_file->Get("TTbar_plus_X_analysis/MuPlusJets/"+IsoFolder+"/"+Obj+"0btag"); TH1D* allMC = (TH1D*)tt_plot->Clone("allMC"); allMC->Add(vjets_plot); allMC->Add(stop_plot); plot->Add(allMC, -1); *errorRef = sqrt(plot->Integral() + pow(0.5*allMC->Integral(),2)); return plot->Integral(); }
TH1D* combineRebin10bins(std::vector<TFile*> files, std::string histName, std::vector<double> scalingFactors) { TH1::SetDefaultSumw2(); std::vector<double> massBins = generate10Bins(); int nBinsX = massBins.size()-1; // Get 1st hist in list TH1D* h = (TH1D*)files[0]->Get(histName.c_str())->Clone(files[0]->Get(histName.c_str())->GetName()); h->Scale(scalingFactors[0]); for (unsigned i = 1; i < files.size(); i++) { TH1D* hTmp = (TH1D*) (files[i]->Get(histName.c_str())); h->Add(hTmp, scalingFactors[i]); } // /files[0]->Get(histName.c_str())->GetTitle() TH1D* hNew = h->Rebin(nBinsX, files[0]->Get(histName.c_str())->GetTitle(), &massBins[0]); return hNew; }
/** * Combine various hists according to their weights * @param hists [description] * @param scalingFactors [description] * @return [description] */ TH1D* combineScale(std::vector<TH1D*> hists, std::vector<double> scalingFactors) { TH1::SetDefaultSumw2(); // get total double total = 0; for (int i = 0; i < scalingFactors.size(); i++) { total += scalingFactors[i]; } TH1D* h = (TH1D*) hists[0]->Clone(hists[0]->GetName()); h->Scale(scalingFactors[0]/total); for (i = 1; i < scalingFactors.size(); i++) { h->Add(hists[i], scalingFactors[i]/total); } return h; }
/*=========================================================*/ Float_t AGX(Char_t *matn,Float_t peak,Float_t width=0.0) { Axis_t aymax=aymin+numchy; setcanvas(2); TH1D *hist; hist=(TH1D*)gROOT->FindObject("ytemp"); if(hist!=NULL)hist->Delete(); hist=new TH1D("ytemp","ytemp",NCHY,0,DIMY); hist->Add(histy,1.0); Float_t a=GX(matn,peak,width); histy->Add(hist,1.0); c1->cd(2); histy->SetAxisRange(aymin,aymax); histy->SetLineColor(3); histy->Draw(); return a; }
/*=========================================================*/ Float_t AGY(Char_t *matn,Float_t peak,Float_t width=0.0) { Axis_t axmax=axmin+numchx; setcanvas(2); TH1D *hist; hist=(TH1D*)gROOT->FindObject("xtemp"); if(hist!=NULL)hist->Delete(); hist=new TH1D("xtemp","xtemp",NCHX,0,DIMX); hist->Add(histx,1.0); Float_t a=GY(matn,peak,width); histx->Add(hist,1.0); c1->cd(2); histx->SetAxisRange(axmin,axmax); histx->SetLineColor(3); histx->Draw(); return a; }
TH1D* GetDiff(TH1D* hEM,TH1D* hME,double xmin, double xmax) { TH1D* diff = (TH1D*)hEM->Clone("diff"); diff->Add(hME,-1); diff->GetYaxis()->SetTitle("Diff"); diff->GetYaxis()->SetTitleSize(0.1); diff->GetYaxis()->SetTitleOffset(0.3); diff->GetYaxis()->CenterTitle(); diff->GetXaxis()->SetRangeUser(xmin,xmax); diff->SetLineColor(kBlack); diff->GetYaxis()->SetLabelSize(0.08); diff->SetLineWidth(2); diff->SetMarkerStyle(8); diff->SetMarkerSize(0.7); diff->SetMarkerColor(kBlack); diff->GetXaxis()->SetTitle("M_{coll} (GeV)"); diff->GetXaxis()->SetTitleSize(0.15); diff->GetXaxis()->SetTitleOffset(0.8); diff->GetXaxis()->SetLabelOffset(); diff->GetXaxis()->SetLabelSize(0.1); return diff; }
void addPolarizationHists(){ TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/results_5_19/5_19Full.root"); TH1D* polHist = new TH1D("polHist","polHist",25,0,1); for (int i=0; i<5; i++) { for (int j=0; j<32; j++) { char name[50]; sprintf(name, "hPolOfBin_Ptbin_%d_phiSRbin_%d",i,j); cout << name << endl; TH1D* tempHist = infile->Get(name); cout << tempHist->GetEntries() << endl; polHist->Add(tempHist, 1); } } polHist->Draw(); }
//// This version needs thought void SiCalibrator::FindPeaks() { Load(); int iterate = 25; int nbins; TSpectrum* spec = new TSpectrum(10); avesigma = 0; int nsigma = 0; for (int src=0; src < CalData.size(); src++) { if (CalData[src].hSource != 0) { for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) { TH1D* hbi = CalData[src].hSource->ProjectionY("hb",ch+1,ch+1); nbins = hbi->GetNbinsX(); TH1D* hbk1 = (TH1D*) spec->Background(hbi,iterate); hbi->Add(hbk1,-1); //Estimate parameters double lim = 5; double max = 0; double peak = 0; int i = nbins - 1; while (hbi->GetBinContent(i) < lim && i > 0) { max = i; i--; } double sigma = (max/CalibSource::sourcelist[src].betas.back().E)*2; //2 keV if (sigma > 1) { avesigma += sigma; nsigma++; } gErrorIgnoreLevel = kError; int npeaks = spec->Search(hbi,sigma,"nodraw ",0.001); float* adc = spec->GetPositionX(); float* amp = spec->GetPositionY(); for (int i=0; i<npeaks; i++) { CalData[src].sourcedata[ch].ADC.push_back(adc[i]); CalData[src].sourcedata[ch].Amp.push_back(amp[i]); } } } } avesigma = avesigma/nsigma; }
TH1D *haddHistos(TFile *fileName,TString histoName,TString ST,vector<TString> HT) { TH1::SetDefaultSumw2(); fileName->ls(); TH1D *hInit = (TH1D*)fileName->Get("ANplots"+ST+"_NOLPsecondD"+HT[0]+"/"+histoName); hInit->SetName(histoName); cout << "IN-1" << "\n"; // ---- loop over all the STbins for (int iHT=0; iHT<HT.size(); iHT++) { cout << "iHT " << iHT << "\n"; if ((HT.size()>1) && (iHT>0)) { TH1D *hTempHT = (TH1D*)fileName->Get("ANplots"+ST+"_NOLPsecondD"+HT[iHT]+"/"+histoName); hInit->Add(hInit,hTempHT,1.,1.); } } // --- end of looping over HTbins return hInit; }
TH1D* Plot1D (std::string var,std::vector<TFile*>& tfiles,std::vector<double>& weights) { double weightTot = 0.0; for ( int i = 0; i<weights.size(); i++) { weightTot+=weights[i]; } std::string name = var; name+="NEW"; TH1D* hVar = (TH1D*)tfiles[0]->Get(var.c_str()); TH1D* HVar = (TH1D*)hVar->Clone(name.c_str()); HVar->Sumw2(); for (int i=1; i<tfiles.size(); i++) { TH1D* htempVar = (TH1D*)tfiles[i]->Get(var.c_str()); HVar->Add(htempVar,weights[i]/weightTot); } return HVar; }
TH1D * getSpectrum(TFile * f, char * type, int minCent, int maxCent, double etaMin, double etaMax ) { TH3F *h = (TH3F*) f->Get(Form("%s",type)); h->GetZaxis()->SetRangeUser( minCent+0.001, maxCent-0.001); TH2F * ch = (TH2F*) h->Project3D("yxe"); TH1D* hPt; TH1D* hPtN; Int_t etabin10m=ch->GetXaxis()->FindBin(etaMin+0.01); Int_t etabin10p=ch->GetXaxis()->FindBin(etaMax-0.01); Int_t Netabin10p=ch->GetXaxis()->FindBin(-etaMin-0.01); Int_t Netabin10m=ch->GetXaxis()->FindBin(-etaMax+0.01); hPt = (TH1D*) ch->ProjectionY(Form("hPt_%d",rand()),etabin10m,etabin10p,"e"); hPtN = (TH1D*) ch->ProjectionY("hPtN",Netabin10m,Netabin10p,"e"); hPt->Add( hPtN, 1.0); delete h; delete ch; delete hPtN; return hPt; }
void plotter::draw_rec(TH1D* data_, TH1D* sig_, TH1D* bgr_, TString file_name){ TH1D* data = (TH1D*) data_->Clone("data"); TH1D* sig = (TH1D*) sig_->Clone("sig"); TH1D* bgr = (TH1D*) bgr_->Clone("bgr"); TCanvas *c= new TCanvas("c","",1200,600); gPad->SetLeftMargin(0.15); sig->Add(bgr, 1.); sig->SetTitle(" "); sig->GetYaxis()->SetRangeUser(0., 250); sig->GetXaxis()->SetTitle("detector binning"); sig->GetYaxis()->SetTitle("events"); sig->GetYaxis()->SetTitleOffset(1.5); sig->GetYaxis()->SetNdivisions(505); sig->SetFillColor(810); sig->SetLineColor(810); sig->Draw("HIST"); bgr->SetFillColor(kGray); bgr->SetLineColor(kBlack); bgr->SetFillStyle(1001); bgr->Draw("HIST SAME"); data->SetLineColor(kBlack); data->SetLineColor(kBlack); data->SetLineStyle(1); data->SetMarkerColor(kBlack); data->SetMarkerStyle(20); data->Draw("E SAME"); TLegend *l=new TLegend(0.2,0.7,0.4,0.88); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(data,"Data","pl"); l->AddEntry(sig,"t#bar{t}","f"); l->AddEntry(bgr,"Background","f"); l->Draw(); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void Getvn(int iangle1, int iangle2, bool usingCNTEP=0){ TString str; int nrun = GetTotalRun(); std::cout<<"Totally we have "<<nrun<<" runs/segments!"<<std::endl; FillGoodRun(); std::cout<<"Filling Good run finished!"<<std::endl; if(nrun<0) exit(1); ofstream fout, foutraw, fout1, fout2; int iharE=0; if(nhar==1) iharE=1; TFile *fin; cout<<"iangle1 = "<<iangle1<<" iangle2 = "<<iangle2<<endl; for(int icent=0;icent<ncent;icent++){ for(int ihar=0;ihar<nhar;ihar++){ for(int isub=0;isub<nsub;isub++){ int n = ihar+1.0+iharE; str = choosesub(isub); TString UseCNTEP; if(str=="ABORT") continue; if(usingCNTEP) UseCNTEP = "UseCNTEP"; else UseCNTEP = "NoUseCNTEP"; std::cout<<UseCNTEP<<std::endl; std::cout<<"starting doing "<<str<<" v"<<n<<" analysis!"<<std::endl; fout1.open(Form("Result/%s/res_%d%d_%d_%d_%s.dat",UseCNTEP.Data(),iangle1,iangle2,n,icent,str.Data())); //using str as event plane detector fout2.open(Form("Result/%s/psi_%d%d_%d_%d_%s.dat",UseCNTEP.Data(),iangle1,iangle2,n,icent,str.Data())); //using str as event plane detector float reso = GetReso(iangle1, iangle2, icent,ihar,isub,usingCNTEP); fout1<<reso<<std::endl; if(reso<=0) {std::cout<<"resolution is wrong!"<<std::endl; reso = 1.0;} for(int irun=0;irun<nrun;irun++){ fout2<<GetRun(irun)<<" "<<GoodRunFit[icent][ihar][isub][irun]<<std::endl; } TH1D* hvobsall = new TH1D(Form("hvobsall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobsall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6); TH1D* hvobsallsq = new TH1D(Form("hvobsallsq_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobsallsq_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6); TH1D* hvobs2all = new TH1D(Form("hvobs2all_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobs2all_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6); for(int iphi=0;iphi<nphi+1;iphi++){ TH1D* hvobs = new TH1D(Form("hvobs_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobs_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6); TH1D* hvobssq = new TH1D(Form("hvobssq_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobssq_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6); TH1D* hvobs2 = new TH1D(Form("hvobs2_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobs2_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6); string phistr = (iphi==0)?"_east":"_west"; if(iphi==nphi) phistr = ""; cout<<"open v2 file"<<endl; fout.open(Form("Result/%s/v%d_%d%d_%d%s_%s.dat",UseCNTEP.Data(),n,iangle1,iangle2,icent,phistr.c_str(),str.Data())); //using str as event plane detector cout<<"open v2raw file"<<endl; foutraw.open(Form("Result/%s/v%draw_%d%d_%d%s_%s.dat",UseCNTEP.Data(),n,iangle1,iangle2,icent,phistr.c_str(),str.Data())); //using str as event plane detector if(iphi<nphi){ for(int irun=0;irun<nrun;irun++){ //std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<" "<<phistr<<std::endl; fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s.root",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data())); if(!(GoodRunFit[icent][ihar][isub][irun]>0.2 && GoodRunFit[icent][ihar][isub][irun]<3.0)){ std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<std::endl; fin->Close(); continue; } TProfile* hvobstemp = (TProfile*)fin->Get(Form("vobs%s_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi)); TProfile* hvobssqtemp = (TProfile*)fin->Get(Form("vobs%ssq_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi)); TH1D* hvobssumtemp = (TH1D*)hvobstemp->ProjectionX(Form("vobssum%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"W"); TH1D* hvobssqsumtemp = (TH1D*)hvobssqtemp->ProjectionX(Form("vobssqsum%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"W"); //Add weighted v2 TH1D* hvobssum2temp = (TH1D*)hvobstemp->ProjectionX(Form("vobssum2%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"B");//Add Entries hvobs->Add(hvobssumtemp); hvobssq->Add(hvobssqsumtemp); hvobs2->Add(hvobssum2temp); fin->Close(); } } hvobsall->Add(hvobs); hvobsallsq->Add(hvobssq); hvobs2all->Add(hvobs2); if(iphi==nphi){ hvobs = hvobsall; hvobssq = hvobsallsq; hvobs2 = hvobs2all; } for(int ipt=0;ipt<npt-1;ipt++){ int xbinmin = hvobs->GetXaxis()->FindBin(ptbin[ipt]+eps); int xbinmax = hvobs->GetXaxis()->FindBin(ptbin[ipt+1]-eps); // std::cout<<xbinmin<<" "<<xbinmax<<std::endl; // std::cout<<ptbin[ipt]<<" "<<ptbin[ipt+1]<<std::endl; // TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),xbinmin,xbinmax); // TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),xbinmin,xbinmax); float Ntracks = hvobs2->Integral(xbinmin,xbinmax); float vobs = hvobs->Integral(xbinmin,xbinmax)/Ntracks; float vobssq = hvobssq->Integral(xbinmin,xbinmax)/Ntracks; // float vobssq = hvobssqProj->GetMean(); float v = vobs/reso; // float verr = hvobsProj->GetRMS()/reso/sqrt(Ntracks); float verr = sqrt(vobssq-vobs*vobs)/reso/sqrt(Ntracks); TH1D* hvobsclone = (TH1D*)hvobs2->Clone("hvobsclone"); hvobsclone->GetXaxis()->SetRangeUser(ptbin[ipt],ptbin[ipt+1]); float pt = hvobsclone->GetMean(); fout<<pt<<" "<<v<<" "<<verr<<" "<<std::endl; foutraw<<pt<<" "<<vobs<<" "<<verr*reso<<" "<<std::endl; } fout.close(); foutraw.close(); } fout1.close(); fout2.close(); } } } }
void doPlotsBtag_Log(bool logPlot){ setTDRStyle(); double lumi = 5800; //stuff to choose //bool logPlot = false; //true for log plot int rebinFact = 1; //isolation selection //TString Isolation = "QCD No Iso/"; TString Isolation = "Ref selection/"; //TString Isolation = "QCD mu+jets PFRelIso/"; //TString Isolation = "QCD non iso mu+jets/"; TString Systematic = "central"; // number of btags TString Nbtags = "2btags"; //standard "2btags" , qcd "0btag" //choose object TString Obj = ""; //TString Obj = "MET/"; //muon variables const int N = 2; TString Variable; TString Variables[N] = {"N_BJets", "N_BJets_reweighted"}; double MinXs[N] = {-0.5,-0.5}; double MaxXs[N] = {7.5,7.5}; TString XTitles[N] = {"B-tag Multiplicity", "B-tag Multiplicity"}; //loop over variables for(int i = 0; i<2; i++){ double MinX = MinXs[i]; double MaxX = MaxXs[i]; Variable = Variables[i]; TString Xtitle = XTitles[i]; //Data TH1D* data = getSample("SingleMu", 1, Obj, Variable, Isolation, rebinFact, "central"); //MC TH1D* tt = getSample("TTJet", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* wjets = getSample("W1Jet", lumi*37509/57708550, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5", lumi*34679.3/8500505, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5", lumi*2.87e8 * 0.0065/8486893, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5", lumi*6.609e7 * 0.0122/8928999, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5", lumi*8082000.0 * 0.0218/7256011, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5", lumi*1024000.0 * 0.0395/9030624, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5", lumi*0.774 * 0.1097/3807263, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, Obj, Variable, Isolation, rebinFact, Systematic); TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, Obj, Variable, Isolation, rebinFact, Systematic); //make combined top and single top template TH1D* sing_top = (TH1D*)top_t->Clone("top"); sing_top->Add(top_tw);sing_top->Add(top_s); sing_top->Add(tbar_t); sing_top->Add(tbar_tw);sing_top->Add(tbar_s); zjets->Add(z2jets); zjets->Add(z3jets); zjets->Add(z4jets); wjets->Add(w2jets); wjets->Add(w3jets); wjets->Add(w4jets); //make combined top and single top template TH1D* qcd_all = (TH1D*)qcd->Clone("qcd_all"); qcd_all->Add(qcd2); qcd_all->Add(qcd3); qcd_all->Add(qcd4); qcd_all->Add(qcd5); qcd_all->Add(qcd6); qcd_all->Add(qcd7); qcd_all->Add(qcd8); qcd_all->Add(qcd9); qcd_all->Add(qcd10); qcd_all->Add(qcd11); THStack *hs = new THStack("hs","test"); qcd_all->SetLineColor(kBlack); zjets->SetLineColor(kBlack); wjets->SetLineColor(kBlack); sing_top->SetLineColor(kBlack); tt->SetLineColor(kBlack); hs->Add(qcd_all); hs->Add(zjets); hs->Add(wjets); hs->Add(sing_top); hs->Add(tt); //draw histos to files TCanvas *c1 = new TCanvas("Plot","Plot",900, 600); hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.2); hs->SetMinimum(1.); hs->Draw(); data->Draw("E same"); data->SetMarkerStyle(20); //events: cout << "ttbar: " << tt->Integral() << endl; cout << "data: " << data->Integral() << endl; if(logPlot == true){ hs->GetXaxis()->SetLimits(MinX, MaxX); }else{ hs->GetXaxis()->SetLimits(MinX, 4.5); } hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05); TLegend *tleg2; tleg2 = new TLegend(0.7,0.7,0.8,0.9); tleg2->SetTextSize(0.04); tleg2->SetBorderSize(0); tleg2->SetFillColor(10); tleg2->AddEntry(data , "2012 data", "lpe"); tleg2->AddEntry(tt , "t#bar{t}", "f"); tleg2->AddEntry(sing_top, "single top", "f"); tleg2->AddEntry(wjets , "w+jets", "f"); tleg2->AddEntry(zjets , "z+jets", "f"); tleg2->AddEntry(qcd_all , "QCD", "f"); //tleg2->AddEntry(singtEff, "single-t" , "l"); //tleg2->AddEntry(singtwEff, "single-tW" , "l"); tleg2->Draw("same"); if(logPlot == true){ TText* textPrelim = doPrelim(0.12,0.96, "#geq 0 btags"); textPrelim->Draw(); }else{ TText* textPrelim = doPrelim(0.2,0.96, ""); textPrelim->Draw(); } if(logPlot ==true){ c1->SetLogy(); } TString plotName("Plots/TTbarPlusVarAnalysis/Nbtags/"); if(logPlot ==true){ plotName += Variable+"_Log"; }else{ plotName += Variable; } c1->SaveAs(plotName+".pdf"); c1->SaveAs(plotName+".png"); delete c1; } }
void AxEffSyst(TString modOCDBOutputPath, TString stdOCDBOutputPath){ gStyle->SetOptStat(0); TFile *axEffModOCDBFile = new TFile(modOCDBOutputPath.Data(),"READONLY"); TFile *axEffStdOCDBFile = new TFile(stdOCDBOutputPath.Data(),"READONLY"); TH1D *axEffModOCDBHisto = 0x0; axEffModOCDBFile->GetObject("ratio1", axEffModOCDBHisto); axEffModOCDBHisto->SetLineColor(kBlue); axEffModOCDBHisto->SetLineWidth(2); axEffModOCDBHisto->SetTitle("A#times#epsilon"); axEffModOCDBHisto->GetXaxis()->SetTitle("Rapidity"); axEffModOCDBHisto->GetYaxis()->SetTitle("A#times#epsilon"); TH1D *axEffStdOCDBHisto = 0x0; axEffStdOCDBFile->GetObject("ratio1", axEffStdOCDBHisto); axEffStdOCDBHisto->SetLineColor(kRed); axEffStdOCDBHisto->SetTitle("A#times#epsilon Std OCDB"); axEffStdOCDBHisto->GetXaxis()->SetTitle("Rapidity"); axEffStdOCDBHisto->GetYaxis()->SetTitle("A#times#epsilon"); axEffModOCDBHisto->Sumw2(kTRUE); axEffStdOCDBHisto->Sumw2(kTRUE); TH1D *ratio = (TH1D*)axEffStdOCDBHisto->Clone(); ratio->Sumw2(kTRUE); ratio->SetLineWidth(1); ratio->Add(axEffModOCDBHisto, -1.); ratio->Divide(axEffStdOCDBHisto); ratio->SetLineColor(kBlack); ratio->SetTitle("#frac{A#times#epsilon_{Std OCDB}-A#times#epsilon_{Mod OCDB}}{A#times#epsilon_{Std OCDB}}"); ratio->GetXaxis()->SetTitle("Rapidity"); ratio->GetYaxis()->SetTitle("Ratio (%)"); for (Int_t iBinsRatio = 0; iBinsRatio <= ratio->GetNbinsX()+1; iBinsRatio++) { Double_t binContent = ratio->GetBinContent(iBinsRatio); cout<<binContent<<"->"; if ( binContent<0. ) ratio->SetBinContent(iBinsRatio, -binContent*100.); else ratio->SetBinContent(iBinsRatio, binContent*100.); binContent = ratio->GetBinContent(iBinsRatio); cout<<binContent<<endl; } TCanvas *canv = new TCanvas("canv"); canv->Divide(2,1); canv->cd(1); axEffModOCDBHisto->SetDirectory(0); axEffModOCDBHisto->Draw("E"); axEffStdOCDBHisto->SetDirectory(0); axEffStdOCDBHisto->Draw("SAME E"); canv->cd(2); ratio->GetYaxis()->SetRangeUser(-0.5,ratio->GetMaximum()*2); ratio->SetDirectory(0); ratio->Draw("E"); axEffModOCDBFile->Close(); axEffStdOCDBFile->Close(); }