int countEntries(TH1D* inComing, double ptMin, double ptMax, int fileNum) { if(fileNum < 0 || fileNum > 4) { cout << "number not in the cut range" << endl; return; } TFile *myFile = TFile::Open("GammaCalo_MC_LHC15g2_60.root"); TList *myL = (TList*)myFile->Get("GammaCalo;1"); TString cutString[5]; cutString[0] = "00000113_1111121063032220000_0163103100000050"; cutString[1] = "00000013_1111121063032220000_0163103100000050"; cutString[2] = "00052013_1111121063032220000_0163103100000050"; cutString[3] = "00083013_1111121063032220000_0163103100000050"; cutString[4] = "00085013_1111121063032220000_0163103100000050"; //cout << "Cut selection: " << cutString[fileNum] << endl; TString folderString = "Cut Number " + cutString[fileNum]; TList* cut_folder = (TList*)myL->FindObject(folderString); TString esdString = cutString[fileNum] + " ESD histograms"; TList* esdHists = (TList*)cut_folder->FindObject(esdString); TH2F* hist = (TH2F*)esdHists->FindObject("ESD_Mother_InvMass_Pt"); TH1D* pi0WBg = hist->ProjectionX("pi0WBg",ptBinMin,ptBinMax,""); int entries = pi0WBg->GetEntries(); cout << "Num entries: " << entries << endl; return entries; }
void AliITSLegoPlot(Float_t nchtheta, Float_t nchphi, const char *inFile = "galice.root") { // macro to visualize the lego plots generated by gAlive->RunLego gROOT->Reset(); TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile); if (!file->IsOpen()) { cerr<<"Can't open "<<inFile<<" !" << endl; return 1; } // end if !file Float_t theta = 10; Float_t phi = 170; Int_t ncont = 50; TCanvas *cradl = new TCanvas("cradl","radl",10,10,800,600); cradl->SetTheta(theta); cradl->SetPhi(phi); TH2F *hradl = (TH2F*)file->Get("hradl"); hradl->SetStats(kFALSE); hradl->GetXaxis()->SetTitle("Phi (degrees)"); hradl->GetYaxis()->SetTitle("Theta (degrees)"); hradl->SetFillColor(2); hradl->SetContour(ncont); hradl->Draw("colz"); TCanvas *cradlx = new TCanvas("cradl1","radl",50,50,800,600); hradl->ProjectionX(); hradl_px->SetStats(kFALSE); // hradl_px->SetOptLogY(); // hradl_px->SetMinimum(0.001); // hradl_px->SetMaximum(1); hradl_px->Scale(1./nchtheta); hradl_px->GetXaxis()->SetTitle("Phi (degrees)"); hradl_px->GetYaxis()->SetTitle("X/X0"); hradl_px->Draw(); // cout << "Average over Phi: " << hradl_px->GetSumOfWeights()/nchphi << " X/X0" << endl; TCanvas *cradly = new TCanvas("cradl2","radl",100,100,800,600); hradl->ProjectionY(); hradl_py->SetStats(kFALSE); // hradl_py->SetOptLogY(); // hradl_py->SetMinimum(0.001); // hradl_py->SetMaximum(1); hradl_py->Scale(1./nchphi); hradl_py->GetXaxis()->SetTitle("Theta (degrees)"); hradl_py->GetYaxis()->SetTitle("X/X0"); hradl_py->Draw(); // cout << "Average over Theta: " << hradl_py->GetSumOfWeights()/nchtheta << " X/X0" << endl; cout << "Average: " << hradl_py->GetSumOfWeights()/nchtheta << " X/X0" << endl; }
void Drawbbc(){ TFile *f = new TFile("merged.root"); TH1D* hbbcs; TH1D* hbbcn; TCanvas *c1; TCanvas *c2; TLegend *leg = new TLegend(0.5,0.7,0.7,0.85); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetTextSize(0.048); TH2F* bbcsbbcn = (TH2F*)f->Get(Form("bbcsbbcn_0")); for(int xcent=1; xcent < 6; xcent++){ TH1F* bbcsbbcndis_t = (TH1F*)f->Get(Form("bbcsbbcn_%d",xcent)); bbcsbbcn->Add(bbcsbbcndis_t); } hbbcs = (TH1D*)bbcsbbcn->ProjectionX("bbcs",0,-1); hbbcn = (TH1D*)bbcsbbcn->ProjectionY("bbcn",0,-1); hbbcs->Rebin(4); hbbcn->Rebin(4); c1= new TCanvas(); c1->cd(); c1->SetLogy(); SetTitle(*hbbcs,"bbc charge","# of events",""); SetRange(*hbbcs,0,1e-1,100,hbbcn->GetMaximum()*5); SetStyle(*hbbcs,1.2,1,20,0,0); SetStyle(*hbbcn,1.2,2,24,0,0); hbbcs->Draw("P"); hbbcn->Draw("Psame"); leg->AddEntry(hbbcs,"bbc south"); leg->AddEntry(hbbcn,"bbc north"); leg->Draw("same"); c1->Print(Form("bbcdis.png")); c2= new TCanvas(); c2->cd(); c2->SetLogy(); hbbcs_norm = (TH1D*)hbbcs->Clone("hbbcs_norm"); hbbcn_norm = (TH1D*)hbbcn->Clone("hbbcn_norm"); hbbcs_norm->Scale(1./hbbcs_norm->Integral()); hbbcn_norm->Scale(1./hbbcn_norm->Integral()); SetRange(*hbbcs_norm,0,1e-9,100,1); hbbcs_norm->Draw("P"); hbbcn_norm->Draw("Psame"); leg->Draw("same"); c2->Print(Form("bbcdis_norm.png")); c3= new TCanvas(); c3->cd(); c3->SetLogz(); SetTitle(*bbcsbbcn,"bbc charge south","bbc charge north","# of events"); SetRange(*bbcsbbcn,0,0,100,100); bbcsbbcn->Draw("colz"); c3->Print("bbcsbbcn.png"); }
TH1D* Template::getProjected1DTemplate(unsigned int axis) /*****************************************************************/ { if(axis>=numberOfDimensions()) { stringstream error; error << "Template::getProjected1DTemplate(): Projection requested on axis "<<axis<<" for "<<numberOfDimensions()<<"D template '"<<m_name<<"'\n"; throw runtime_error(error.str()); } unsigned int nbins1 = 0; unsigned int nbins2 = 0; if(axis==0) { nbins1 = m_template->GetNbinsY(); nbins2 = m_template->GetNbinsZ(); } else if(axis==1) { nbins1 = m_template->GetNbinsX(); nbins2 = m_template->GetNbinsZ(); } else if(axis==2) { nbins1 = m_template->GetNbinsX(); nbins2 = m_template->GetNbinsY(); } stringstream projName; projName << m_template->GetName() << "_projFromTmp"<< axis; TH1D* projectedTemplate = NULL; if(numberOfDimensions()==2) { TH2F* tmp = dynamic_cast<TH2F*>(m_template); if(axis==0) projectedTemplate = tmp->ProjectionX(projName.str().c_str(), 1, nbins1, "e"); else if(axis==1) projectedTemplate = tmp->ProjectionY(projName.str().c_str(), 1, nbins1, "e"); } if(numberOfDimensions()==3) { TH3F* tmp = dynamic_cast<TH3F*>(m_template); if(axis==0) projectedTemplate = tmp->ProjectionX(projName.str().c_str(), 1, nbins1, 1, nbins2, "e"); else if(axis==1) projectedTemplate = tmp->ProjectionY(projName.str().c_str(), 1, nbins1, 1, nbins2, "e"); else if(axis==2) projectedTemplate = tmp->ProjectionZ(projName.str().c_str(), 1, nbins1, 1, nbins2, "e"); } return projectedTemplate; }
void PlotERes(string FilterSet){ stringstream name; name<<FilterSet<<"_vsEnergy"; TH2F* thePlot = (TH2F*)gDirectory->Get(name.str().c_str()); if (thePlot==NULL){ cout<<"No plot"<<endl; return; } int numYBins = thePlot->GetNbinsY(); TF1 * myFunc = new TF1("myFunc","gaus",-0.3,0.3); double * x = (double*)malloc(numYBins*sizeof(double)); double * y = (double*)malloc(numYBins*sizeof(double)); double * ey = (double*)malloc(numYBins*sizeof(double)); for (int i=0;i<numYBins;i++){ TH1D* proj=thePlot->ProjectionX("_px",i,numYBins-1); if (proj->GetEntries()>40){ TFitResultPtr result = proj->Fit("myFunc","RQS"); Int_t status = result; if (status==0){ cout<<result->Value(2)*2.35*4<<endl; x[i]=i; y[i]=result->Value(2)*2.35*4; ey[i]=result->UpperError(2)*2.35*4; } } } TGraphErrors * graph = new TGraphErrors(numYBins,x,y,0,ey); graph->GetHistogram()->SetMarkerStyle(5); graph->Draw("AP"); }
//************************************************************************************************* //Main part of the macro //************************************************************************************************* void NormalizeElectronNtuple(const string InputFilename, const string datasetName, const string OutputFilename, Int_t sampleType, const string normalizationFile = "") { Double_t normalizationWeight = 0; Bool_t useReweightFactor = kFALSE; TH2F *PtEtaReweightFactor = 0; Double_t overallWJetsNormalizationFactor = 0; //For Normalizing each sample individually if (sampleType == 0 || sampleType >= 10) { TTree* electronTree = getTreeFromFile(InputFilename.c_str()); assert(electronTree); MitNtupleElectron ele(electronTree); normalizationWeight = getNormalizationWeight(InputFilename, datasetName); //************************************************************************************************* //Create new normalized tree //************************************************************************************************* TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE"); outputFile->cd(); TTree *normalizedTree = electronTree->CloneTree(0); for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); if (sampleType == 10) { if (ele.electron_branch_passedSelectionCut == 1) { if (datasetName == "s09-wwll10-mc3" || datasetName == "s09-ttbar-mc3") { //for mu-e there should be only 1 electron candidate ele.electron_branch_weight = normalizationWeight; normalizedTree->Fill(); } else if (datasetName == "s09-we-mc3" || datasetName == "s09-wm-mc3" || datasetName == "s09-wt-mc3") { //For the W->enu sample, fill only the fake electron candidates. ele.electron_branch_weight = normalizationWeight; if (ele.electron_branch_electronType < 100) { normalizedTree->Fill(); } } else { cout << "Warning: The specified dataset " << datasetName << " is not recognized to be one of the selection cut samples.\n"; } } } else { //For regular samples just fill all electrons ele.electron_branch_weight = normalizationWeight; normalizedTree->Fill(); } } normalizedTree->Write(); cout << "Original Tree Entries: " << electronTree->GetEntries() << " Normalized Tree Entries: " << normalizedTree->GetEntries() << endl; outputFile->Close(); } //For Normalization of Background sample else if (sampleType == 1) { TTree* electronTree = getTreeFromFile(InputFilename.c_str(), kFALSE); assert(electronTree); MitNtupleElectron ele(electronTree); //************************************************************************************************* //Create new reweighted tree //************************************************************************************************* TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE"); TTree *reweightedTree = electronTree->CloneTree(0); if (normalizationFile == "") { //normalize according to total number of electrons expected in W+Jets/W+gamma bkg Double_t totalWeight = 0; for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); totalWeight += ele.electron_branch_weight; } cout << "Input Bkg Ntuple Total Weight = " << totalWeight << endl; normalizationWeight = 1126.5 / totalWeight; } else { //do pt/eta Reweighting TFile *reweightInputFile = new TFile(normalizationFile.c_str(), "READ"); assert(reweightInputFile); TH2F *WJetsFakeElectronPtEta = (TH2F*)reweightInputFile->Get("hWJetsFakeElectronPtEta"); assert(WJetsFakeElectronPtEta); WJetsFakeElectronPtEta = (TH2F*)(WJetsFakeElectronPtEta->Clone()); WJetsFakeElectronPtEta->SetDirectory(0); reweightInputFile->Close(); //Create histogram for reweighting factor PtEtaReweightFactor = (TH2F*)WJetsFakeElectronPtEta->Clone(); PtEtaReweightFactor->SetName("PtEtaReweightFactor"); PtEtaReweightFactor->SetDirectory(0); TH2F *BkgFakeElectronPtEta = new TH2F("BkgFakeElectronPtEta", ";Pt [GeV/c];#eta;" , WJetsFakeElectronPtEta->GetXaxis()->GetNbins(), WJetsFakeElectronPtEta->GetXaxis()->GetBinLowEdge(1), WJetsFakeElectronPtEta->GetXaxis()->GetBinUpEdge(WJetsFakeElectronPtEta->GetXaxis()->GetNbins()), WJetsFakeElectronPtEta->GetYaxis()->GetNbins(), WJetsFakeElectronPtEta->GetYaxis()->GetBinLowEdge(1), WJetsFakeElectronPtEta->GetYaxis()->GetBinUpEdge(WJetsFakeElectronPtEta->GetYaxis()->GetNbins())); BkgFakeElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); BkgFakeElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } PtEtaReweightFactor->Divide(WJetsFakeElectronPtEta, BkgFakeElectronPtEta, 1.0,1.0,"B"); useReweightFactor = kTRUE; } cout << "Reweighting Background Ntuple\n"; outputFile->cd(); //check Reweighting TH2F *ReweightedBkgFakeElectronPtEta = new TH2F("BkgFakeElectronPtEta", ";Pt [GeV/c];#eta;" , 200, 0, 200, 200, -3.0, 3.0); ReweightedBkgFakeElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { if (n%250000 == 0) cout << "Entry " << n << endl; ele.GetEntry(n); if (useReweightFactor) { Double_t reweightFactor = PtEtaReweightFactor->GetBinContent(PtEtaReweightFactor->GetXaxis()->FindFixBin(ele.electron_branch_pt),PtEtaReweightFactor->GetYaxis()->FindFixBin(ele.electron_branch_eta)); ele.electron_branch_weight = ele.electron_branch_weight*reweightFactor;//*overallWJetsNormalizationFactor; } else { ele.electron_branch_weight = normalizationWeight; } reweightedTree->Fill(); ReweightedBkgFakeElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } reweightedTree->Write(); cout << "Original Tree Entries: " << electronTree->GetEntries() << " Normalized Tree Entries: " << reweightedTree->GetEntries() << endl; outputFile->Close(); TCanvas *cv = new TCanvas("BkgReweightedFakeElectronPtEta", "BkgReweightedFakeElectronPtEta", 0,0,800,600); ReweightedBkgFakeElectronPtEta->ProjectionX()->DrawCopy("E1"); cv->SaveAs("BkgReweightedFakeElectronPt.gif"); ReweightedBkgFakeElectronPtEta->ProjectionY()->DrawCopy("E1"); cv->SaveAs("BkgReweightedFakeElectronEta.gif"); } //For Normalization of Signal sample else if (sampleType == 2) { TTree* electronTree = getTreeFromFile(InputFilename.c_str(), kFALSE); assert(electronTree); MitNtupleElectron ele(electronTree); //************************************************************************************************* //Create new reweighted tree //************************************************************************************************* TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE"); TTree *reweightedTree = electronTree->CloneTree(0); if (normalizationFile == "") { //normalize according to total number of electrons expected in WW -> ee nunu signal Double_t totalWeight = 0; for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); totalWeight += ele.electron_branch_weight; } cout << "Input Bkg Ntuple Total Weight = " << totalWeight << endl; normalizationWeight = 1126.5 / totalWeight; } else { //do pt/eta Reweighting TFile *reweightInputFile = new TFile(normalizationFile.c_str(), "READ"); assert(reweightInputFile); TH2F *WWSigElectronPtEta = (TH2F*)reweightInputFile->Get("hWWRealElectronPtEta"); assert(WWSigElectronPtEta); WWSigElectronPtEta = (TH2F*)(WWSigElectronPtEta->Clone()); WWSigElectronPtEta->SetDirectory(0); reweightInputFile->Close(); //Create histogram for reweighting factor PtEtaReweightFactor = (TH2F*)WWSigElectronPtEta->Clone(); PtEtaReweightFactor->SetName("PtEtaReweightFactor"); PtEtaReweightFactor->SetDirectory(0); TH2F *SigSampleElectronPtEta = new TH2F("SigSampleElectronPtEta", ";Pt [GeV/c];#eta;" , WWSigElectronPtEta->GetXaxis()->GetNbins(), WWSigElectronPtEta->GetXaxis()->GetBinLowEdge(1), WWSigElectronPtEta->GetXaxis()->GetBinUpEdge(WWSigElectronPtEta->GetXaxis()->GetNbins()), WWSigElectronPtEta->GetYaxis()->GetNbins(), WWSigElectronPtEta->GetYaxis()->GetBinLowEdge(1), WWSigElectronPtEta->GetYaxis()->GetBinUpEdge(WWSigElectronPtEta->GetYaxis()->GetNbins())); SigSampleElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { ele.GetEntry(n); SigSampleElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } PtEtaReweightFactor->Divide(WWSigElectronPtEta, SigSampleElectronPtEta, 1.0,1.0,"B"); useReweightFactor = kTRUE; } cout << "Reweighting Signal Ntuple\n"; outputFile->cd(); //check Reweighting TH2F *ReweightedSigRealElectronPtEta = new TH2F("ReweightedSigRealElectronPtEta", ";Pt [GeV/c];#eta;" , 200, 0, 200, 200, -3.0, 3.0); ReweightedSigRealElectronPtEta->SetDirectory(0); for (int n=0;n<electronTree->GetEntries();n++) { if (n%250000 == 0) cout << "Entry " << n << endl; ele.GetEntry(n); if (useReweightFactor) { Double_t reweightFactor = PtEtaReweightFactor->GetBinContent(PtEtaReweightFactor->GetXaxis()->FindFixBin(ele.electron_branch_pt),PtEtaReweightFactor->GetYaxis()->FindFixBin(ele.electron_branch_eta)); ele.electron_branch_weight = ele.electron_branch_weight*reweightFactor;//*overallWJetsNormalizationFactor; } else { ele.electron_branch_weight = normalizationWeight; } reweightedTree->Fill(); ReweightedSigRealElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight); } reweightedTree->Write(); cout << "Original Tree Entries: " << electronTree->GetEntries() << " Normalized Tree Entries: " << reweightedTree->GetEntries() << endl; outputFile->Close(); TCanvas *cv = new TCanvas("BkgReweightedFakeElectronPtEta", "BkgReweightedFakeElectronPtEta", 0,0,800,600); ReweightedSigRealElectronPtEta->ProjectionX()->DrawCopy("E1"); cv->SaveAs("SigReweightedRealElectronPt.gif"); ReweightedSigRealElectronPtEta->ProjectionY()->DrawCopy("E1"); cv->SaveAs("SigReweightedRealElectronEta.gif"); } else { cout << "Warning: Specified sampleType " << sampleType << " is not recognized.\n"; } }
void toffit(){ gStyle->SetErrorX(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); TFile *f = TFile::Open("mergedFull.root"); TString charge; ofstream fout("Run15tofdphidzcalib.dat"); ofstream fouttmp("Run15tofdphidzcalibtmp.dat"); for(int iarm=0; iarm<2; iarm++){ for(int ich=0; ich<2; ich++){ if(iarm==0) TH2F *tofdphidz = (TH2F*)f->Get(Form("tofdphidz_%d",ich)); else TH2F *tofdphidz = (TH2F*)f->Get(Form("tofwdphidz_%d",ich)); if(tofdphidz->Integral()==0) continue; TH1F* tofdphi = (TH1F*)tofdphidz->ProjectionX(Form("tofdphi_%d_%d",iarm,ich),0,-1); TH1F* tofdz = (TH1F*)tofdphidz->ProjectionY(Form("tofdz_%d_%d",iarm,ich),0,-1); //tofdphi->Rebin(4); tofdz->Rebin(5); tofdphi->Scale(1./tofdphi->Integral()); tofdz->Scale(1./tofdz->Integral()); TF1 *fphi = new TF1("fphi","gaus(0)+gaus(3)",-0.1,0.1); fphi->SetNpx(10000); //TF1 *fphi = new TF1("fphi","[0]*([1]*exp(-(x-[2])**2/[3]/[3])+(1-[1])*exp(-(x-[4])**2/[5]/[5]))",-0.1,0.1); fphi->SetParameters(1e-1,0,1e-3,1e-3,0,1e-2); //fphi->SetParameters(4.79253e-02,9.25529e-01,-8.56488e-05,-7.46701e-03,-5.37828e-04,5.99178e-0); SetStyle(*tofdphi,1.2,1,20,0,0); tofdphi->Fit("fphi","RQ"); double par[6]; fphi->GetParameters(par); TF1 *fphi1 = new TF1("fphi1","gaus",-0.1,0.1); fphi1->SetNpx(10000); fphi1->SetParameters(par); TF1 *fphi2 = new TF1("fphi2","gaus",-0.1,0.1); fphi2->SetNpx(10000); fphi2->SetParameters(&par[3]); fphi1->SetLineColor(4); //fphi1->Draw("same"); fphi2->SetLineColor(6); //fphi2->Draw("same"); fout<<par[1]<<","; if(par[1]>1) cout<<"dphi "<<iarm<<"\t"<<ich<<"\t"<<ipt<<endl; TF1 *fz = new TF1("fz","gaus(0)+gaus(3)",-10,10); //fz->SetParameters(3.02349e+07,8.32462e-01,2.39187e+00,2.17631e+07,6.35460e-01,8.09821e+00); fz->SetParameters(1e-1,0,2,1e-3,0,8); SetStyle(*tofdz,1.2,1,20,0,0); tofdz->Fit("fz","RQ"); fz->GetParameters(par); TF1 *fz1 = new TF1("fz1","gaus",-10,10); fz1->SetNpx(10000); fz1->SetParameters(par); TF1 *fz2 = new TF1("fz2","gaus",-10,10); fz2->SetNpx(10000); fz2->SetParameters(&par[3]); fz1->SetLineColor(4); //fz1->Draw("same"); fz2->SetLineColor(6); //fz2->Draw("same"); if(par[1]>10) cout<<"dz"<<iarm<<"\t"<<ich<<"\t"<<ipt<<endl; fouttmp<<par[1]<<","; } fout<<endl; fouttmp<<endl; } }
void packTemplatesMass(const int iMass) { // This Root macro is for the purpose of providing input for expected limit computation // It packs predicted background and a set of signal samples into a root file per Higgs mass // TH1::SetDefaultSumw2(); TH2::SetDefaultSumw2(); canvas = new TCanvas ("cg1","PadX",10,10,800,600); gStyle->SetPadColor(0); canvas->SetFillColor(0); // const int nbtag = 4; const int nbtag = 1; //const std::string sbtag[nbtag] = { "TCHPT", "TCHP6", "CSVT", "SSVHPT" }; const std::string sbtag[nbtag] = { "CSVT" }; const int nfc=3; const int ncateg=3; string sfc[nfc] = { "q", "c", "b" }; // this is for the combination of triggers in real data int nTCombData = 4; std::string tCombData[] = {"Trig0", "Trig1", "Trig2", "Trig3"}; std::string L1L2Mode("Weight"); std::string signalMode("PU_WEIGHTED-NEW"); // std::string L1L2Mode("Cut"); // std::string signalMode("CUT_BASED"); //std::string scenario("LowMass2011"); //std::string scenario("MediumMass2011"); std::string scenario; bool useTemplateError; bool useNP; if ( getHbbCfg(scenario,useTemplateError,useNP) != 0 ) return; string IgorVersion("V6"); #include "Analysis/Utilities/interface/HbbMass.h" if (iMass >= nSignal) { std::cout << "Bad iMass=" << iMass << std::endl; return; } // const int nSignal=7; // int signalMass[nSignal] = { 90, 100, 120, 140, 180, 250, 350 }; // int signalMass[nSignal] = { 90, 100, 120, 130, 140, 160, 180, 200, 250, 350 } // there are also : 450, 500, 600, 700, 800, 900, 1000 // double efficiency[nSignal] = { 0.0022081, 0.00324694, 0.00600146, 0.00918135, // 0.0138382, 0.0189684, 0.0206572 }; double efficiency[nSignal][nbtag]; double intLumi = 0; string IgorScen(""); string spacer(""); string SashaPath(""); string IgorPath("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/SignalTemplates-Production"); if (IgorVersion == "V4") { IgorPath.assign("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-4"); } else if (IgorVersion == "V6") { IgorPath.assign("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/SignalTemplates-Production2"); } if (scenario == "LowMass2011") { //intLumi = 2.66794; // in fb-1 intLumi = 2.692643; // with new method IgorScen.assign("low"); spacer.assign(""); //SashaPath.assign("Data-Run2011AB"); SashaPath.assign("Data-Run2011AB/TripleBtagAnalysis_CR3_SF7"); } else if (scenario == "MediumMass2011") { //intLumi = 3.99983; // in fb-1 intLumi = 4.040802; IgorScen.assign("medium"); spacer.assign("/MEDIUM"); //SashaPath.assign("Data-Run2011AB-Medium"); SashaPath.assign("Data-Run2011AB/TripleBtagAnalysis_CR3_SF7_med"); } else if (scenario == "MediumMass2012") { //intLumi = 3.99983; // in fb-1 intLumi = 2.663; IgorScen.assign("medium"); spacer.assign("/MEDIUM"); //SashaPath.assign("Data-Run2011AB-Medium"); SashaPath.assign(""); } else { std::cout << "Bad scenario in packing" << std::endl; return; } string signalHistPattern("massEvBtag/mjjEvBTag_%s"); if (L1L2Mode == "Weight") { signalHistPattern.assign("massEvBtagTW/mjjEvBTagTW_%s"); } double fScal[nSignal][nbtag]; // systematics // const int nSyst = 3; // std::string systName[nSyst] = { "JES", "SFbc", "SFudsg" }; // bool realDataNuisance[nSyst] = { false, true, true }; // indicate if relevant for real data string bbPurity("DataDriven"); // "MC", "DataDrivenR", "None" //string bbPurity("None"); // "MC", "DataDrivenR", "None" bool onlineBtagCorr = true; int nSyst = 4; std::string systName[] = { "JES", "SFbc", "SFudsg", "JER" }; bool realDataNuisance[] = { false, true, true, false }; // indicate if relevant for real data const int nUpDown = 2; std::string signalFile = ""; bool dosignal=true; #if defined(MEDIUM2012) dosignal=false; nTCombData=1; ///only one trigger //nSyst=0; /// no syst templates #endif // signal templates if (IgorVersion != "V3") { std::cout << "Using signal files " << IgorVersion << std::endl; signalFile.assign( Form("%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/SF/job_1/TripleBtagAnalysisM-%d_%s.root",IgorPath.c_str(),signalMass[iMass],spacer.c_str(),signalMass[iMass],IgorScen.c_str() ) ); } else { std::cout << "Using V3 signal files" << std::endl; signalFile.assign( Form("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-3/%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/SF/job_1/TripleBtagAnalysisM-%d_%s.root",signalMode.c_str(),signalMass[iMass],spacer.c_str(),signalMass[iMass],IgorScen.c_str() ) ); } std::string signalSystFiles[nSyst][nUpDown]; //bool activeNuisance[nSyst] = { true, true, true }; std::string upDownName[nUpDown] = { "Up", "Down" }; TH2F* hSignalSyst[nSyst][nUpDown][nbtag]; // output file TFile* hout = new TFile(Form("packedTemplates-M-%d.root",signalMass[iMass]),"recreate"); hout->cd(); TH2::AddDirectory(true); TFile* fSig = new TFile( signalFile.c_str() ); if ( fSig == NULL ) { std::cout << "Could not open signal central file " << signalFile.c_str() << std::endl; return; } else { std::cout << "Open signal file " << signalFile.c_str() << std::endl; } TH2F* hSignalCentral[nbtag]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { hSignalCentral[ibtag] = mergeSignal(fSig,Form(signalHistPattern.c_str(),sbtag[ibtag].c_str()), Form("bbH_%s",sbtag[ibtag].c_str())); // read the efficiency TH1F* histEffMerged = (TH1F*) fSig->Get(Form("TrigEff/EffMerged%s",sbtag[ibtag].c_str())); if ( histEffMerged == NULL) { std::cout << "Efficiency histo not found" << std::endl; return; } double newEff = histEffMerged->GetBinContent(1); std::cout << "Mass= " << signalMass[iMass] << " btag= " << sbtag[ibtag] << " Efficiency = " << newEff << std::endl; efficiency[iMass][ibtag] = newEff; double normShould = 1000 * intLumi * efficiency[iMass][ibtag]; double normIs = hSignalCentral[ibtag]->GetSumOfWeights(); std::cout << hSignalCentral[ibtag]->GetName() << " TotalContents=" << hSignalCentral[ibtag]->GetSumOfWeights() << std::endl; fScal[iMass][ibtag] = normShould / normIs; std::cout << "normShould = " << normShould << " normIs " << normIs << " rescale by " << fScal[iMass][ibtag] << std::endl; hSignalCentral[ibtag]->Scale( fScal[iMass][ibtag] ); hout->cd(); hSignalCentral[ibtag]->Write(); histEffMerged->Write(); // create empty file just as marker ofstream markerFile; markerFile.open(Form("pack-%s-%s.txt",sbtag[ibtag].c_str(),scenario.c_str()),ios::app); markerFile << "Template for mass " << signalMass[iMass] << std::endl; markerFile.close(); } // read the nominal cross section TH1F* histXSect = (TH1F*) fSig->Get("xsection/xsect"); if ( histXSect == NULL) { std::cout << "xsection/xsect" << " not found" << std::endl; return; } histXSect->Write(); for (int iSyst=0; iSyst<nSyst; ++iSyst) { for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { if (IgorVersion != "V3") { signalSystFiles[iSyst][iUpDown] = Form( "%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/%s_Sys%s/job_1/TripleBtagAnalysisM-%d_%s.root", IgorPath.c_str(),signalMass[iMass],spacer.c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),signalMass[iMass],IgorScen.c_str()); } else { signalSystFiles[iSyst][iUpDown] = Form( "/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-3/%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/%s_Sys%s/job_1/TripleBtagAnalysisM-%d_%s.root", signalMode.c_str(),signalMass[iMass],spacer.c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),signalMass[iMass],IgorScen.c_str()); } std::cout << "Signal systematics file " << signalSystFiles[iSyst][iUpDown] << std::endl; TFile* fSigSys = new TFile( signalSystFiles[iSyst][iUpDown].c_str() ); if ( fSigSys == NULL ) { std::cout << "Could not open signal syst file " << signalSystFiles[iSyst][iUpDown].c_str() << std::endl; return; } for (int ibtag=0; ibtag<nbtag; ++ibtag) { hSignalSyst[iSyst][iUpDown][ibtag] = mergeSignal(fSigSys,Form(signalHistPattern.c_str(),sbtag[ibtag].c_str()), Form("bbH_%s_%s_%s",systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str())); std::cout << "The merged hist has name " << hSignalSyst[iSyst][iUpDown][ibtag]->GetName() << std::endl; std::cout << hSignalSyst[iSyst][iUpDown][ibtag]->GetName() << " TotalContents=" << hSignalSyst[iSyst][iUpDown][ibtag]->GetSumOfWeights() << std::endl; hSignalSyst[iSyst][iUpDown][ibtag]->Scale( fScal[iMass][ibtag] ); hout->cd(); hSignalSyst[iSyst][iUpDown][ibtag]->Write(); } fSigSys->Close(); } } // real data std::string backgroundFile( Form("/afs/naf.desy.de/user/r/rmankel/scratch/HbbPat/CMSSW_4_2_4_patch1/src/Analysis/HbbMSSMAnalysis/test/results/v1/%s/TripleBtagAnalysis_SF/TripleBtagAnalysis.root",SashaPath.c_str()) ); #if defined(MEDIUM2012) //bool dosignal=true; //backgroundFile = std::string("/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/MVA-production-selection-trees/TripleBtagAnalysis.root"); backgroundFile = std::string("/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/Blind-test-BG-only-Fit/MEDIUM/TripleBtagAnalysis_SF/TripleBtagAnalysis.root"); #endif std::cout << "Background central file : " << backgroundFile << std::endl; TFile* fBac = new TFile( backgroundFile.c_str() ); if ( fBac == NULL ) { std::cout << "Could not open background central file " << signalFile.c_str() << std::endl; return; } // hist-to-be-fitted TH2F* mjjEbtdata[nbtag]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { mjjEbtdata[ibtag] = getTrigsAndMerge(fBac,Form("massEvBtag/mjjEvBTag_%s",sbtag[ibtag].c_str()),nTCombData,tCombData); if (mjjEbtdata[ibtag] == NULL) { std::cout << "Histogram not found: " << Form("massEvBtag/mjjEvBTag_%s",sbtag[ibtag].c_str()) << std::endl; return; } // rename mjjEbtdata[ibtag]->SetName( Form("Data_%s",sbtag[ibtag].c_str() ) ); hout->cd(); mjjEbtdata[ibtag]->Write(); } TH2F* hBackgroundCentral[nbtag][ncateg][nfc]; TH2F* hBackgroundCentralError[nbtag][ncateg][nfc]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { int theTpat; if (onlineBtagCorr) { theTpat = 3; } else { theTpat = icateg; } for (int ifc=0; ifc<nfc; ++ifc) { string templateCore("massBTagTemplatesCld/MassBTagTemplateCld"); if (bbPurity == "None") { templateCore.assign("massBTagTemplatesCld/MassBTagTemplateUncld"); } string hbSystName( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundCentral[ibtag][icateg][ifc] = getTrigsAndMerge(fBac,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundCentral[ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystName << std::endl; return; } // rename templateId tName(ifc,icateg); hBackgroundCentral[ibtag][icateg][ifc]->SetName( Form("%s_%s",tName.name().c_str(),sbtag[ibtag].c_str()) ); // read the template errors templateCore.assign("errorMassBTagTemplates/ErrorMassBTagTemplate"); string hbSystNameError( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundCentralError[ibtag][icateg][ifc] = getTrigsAndMerge(fBac,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundCentralError[ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystNameError << std::endl; return; } if (useTemplateError) { // add the template error std::cout << " ==== Adding Btag Errors ==== " << hBackgroundCentral[ibtag][icateg][ifc]->GetName() << std::endl; for (int ibinx=1; ibinx<= (hBackgroundCentral[ibtag][icateg][ifc]->GetXaxis()->GetNbins()); ++ibinx) { for (int ibiny=1; ibiny<= (hBackgroundCentral[ibtag][icateg][ifc]->GetYaxis()->GetNbins()); ++ibiny) { float oldError = hBackgroundCentral[ibtag][icateg][ifc]->GetBinError(ibinx,ibiny); float addError = hBackgroundCentralError[ibtag][icateg][ifc]->GetBinContent(ibinx,ibiny); float newError = sqrt( oldError * oldError + addError * addError ); hBackgroundCentral[ibtag][icateg][ifc]->SetBinError(ibinx,ibiny,newError); } } } hout->cd(); hBackgroundCentral[ibtag][icateg][ifc]->Write(); } } } std::string backgroundSystFiles[nSyst][nUpDown]; std::string systNameSasha[] = { "JES", "SFbc", "SFq" }; std::string upDownNameSasha[nUpDown] = { "plus2", "minus2" }; TH2F* hBackgroundSyst[nSyst][nUpDown][nbtag][ncateg][nfc]; TH2F* hBackgroundSystError[nSyst][nUpDown][nbtag][ncateg][nfc]; //#if !defined(MEDIUM2012) // for nuisances like JEC, the up/down templates are just copies of the central templates for (int iSyst=0; iSyst<nSyst; ++iSyst) { if (! realDataNuisance[iSyst]) { std::cout << "Non-real data relevant nuisance: " << systName[iSyst].c_str() << std::endl; for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { for (int ifc=0; ifc<nfc; ++ifc) { hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] = new TH2F( *hBackgroundCentral[ibtag][icateg][ifc] ); // rename templateId tName(ifc,icateg); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] ->SetName( Form("%s_%s_%s_%s", tName.name().c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str()) ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); } } } } } } //#endif fBac->Close(); for (int iSyst=0; iSyst<nSyst; ++iSyst) { if (realDataNuisance[iSyst]) { std::cout << "Real data relevant nuisance: " << systName[iSyst].c_str() << std::endl; for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { // backgroundSystFiles[iSyst][iUpDown] = Form( "/afs/naf.desy.de/user/r/rmankel/scratch/HbbPat/CMSSW_4_2_4_patch1/src/Analysis/HbbMSSMAnalysis/test/results/v1/%s/TripleBtagAnalysis_%s%s/TripleBtagAnalysis.root",SashaPath.c_str(),systNameSasha[iSyst].c_str(),upDownNameSasha[iUpDown].c_str() ); backgroundSystFiles[iSyst][iUpDown] = Form( "/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/Blind-test-BG-only-Fit/MEDIUM/TripleBtagAnalysis_%s%s/TripleBtagAnalysis.root",systNameSasha[iSyst].c_str(),upDownNameSasha[iUpDown].c_str() ); TFile* fBacSys = new TFile( backgroundSystFiles[iSyst][iUpDown].c_str() ); std::cout << "Background systematics file " << backgroundSystFiles[iSyst][iUpDown] << std::endl; if ( fBacSys == NULL ) { std::cout << "Could not open background syst file " << backgroundSystFiles[iSyst][iUpDown] << std::endl; return; } for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { int theTpat; if (onlineBtagCorr) { theTpat = 3; } else { theTpat = icateg; } for (int ifc=0; ifc<nfc; ++ifc) { string templateCore("massBTagTemplatesCld/MassBTagTemplateCld"); if (bbPurity == "None") { templateCore.assign("massBTagTemplatesCld/MassBTagTemplateUncld"); } string hbSystName( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] = getTrigsAndMerge(fBacSys,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystName << std::endl; return; } // rename templateId tName(ifc,icateg); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] ->SetName( Form("%s_%s_%s_%s", tName.name().c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str()) ); // read template errors templateCore.assign("errorMassBTagTemplates/ErrorMassBTagTemplate"); string hbSystNameError( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc] = getTrigsAndMerge(fBacSys,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystNameError << std::endl; return; } if (useTemplateError) { // add the template error std::cout << " ==== ErrorAdd ==== " << hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName() << std::endl; for (int ibinx=1; ibinx<= (hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetXaxis()->GetNbins()); ++ibinx) { for (int ibiny=1; ibiny<= (hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetYaxis()->GetNbins()); ++ibiny) { float oldError = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetBinError(ibinx,ibiny); float addError = hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc]->GetBinContent(ibinx,ibiny); float newError = sqrt( oldError * oldError + addError * addError ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->SetBinError(ibinx,ibiny,newError); } } } hout->cd(); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); } } } fBacSys->Close(); } } } std::cout << "Everything done " << std::endl; #ifdef PROJECTIONS TFile * projections_out=TFile::Open("projections.root","RECREATE"); // loop over background templates //TH1D* bgProX[nbtag][ncateg][nfc]; TH1D* bgSystProX[nSyst][nUpDown][nbtag][ncateg][nfc]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { for (int ifc=0; ifc<nfc; ++ifc) { TH2F* theTemp = hBackgroundCentral[ibtag][icateg][ifc]; TH1D* theTempProX = theTemp->ProjectionX(Form("%sProX",theTemp->GetName()),0,-1,"e"); theTempProX->SetName( Form("%sProX",theTemp->GetName()) ); TH1D* theTempProY = theTemp->ProjectionY(Form("%sProY",theTemp->GetName()),0,-1,"e"); std::cout << "Made projection " << theTempProX->GetName() << std::endl; if ( (icateg == 0) && (ifc == 0) ) { for (int ibinx=1; ibinx<= theTempProX->GetXaxis()->GetNbins(); ++ibinx) { std::cout << ibinx << " content " << theTempProX->GetBinContent(ibinx) << " error " << theTempProX->GetBinError(ibinx) << std::endl; } } theTempProX->SetMarkerStyle(20); theTempProX->SetMarkerColor(1); theTempProX->SetLineColor(1); theTempProX->SetMarkerSize(1); std::cout << "Draw" << std::endl; theTempProX->Draw("EP"); theTempProX->Write(); //theTempProX->Draw("LP,SAME"); // draw the SFbc systematics int colSyst[3] = {1, 2, 4}; int lstyleUpDown[2] = {1, 1}; for (int iSyst=1; iSyst<nSyst; ++iSyst) { for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc] = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->ProjectionX(Form("%sProXX",hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName()),0,-1,"e"); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->SetName( Form("%sProXX",hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName()) ); std::cout << "Made projection " << bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->GetName() << std::endl; bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->SetLineColor( colSyst[iSyst] ); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->Draw("HIST,SAME"); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); // TH2F* theTemp = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]; // TH1D* theTempProX = theTemp->ProjectionX(Form("%sProX",theTemp->GetName()),0,-1,"e"); // theTempProX->SetLineColor( colSyst[iSyst] ); // TH1D* theTempProY = theTemp->ProjectionY(Form("%sProY",theTemp->GetName()),0,-1,"e"); // theTempProY->SetLineColor( colSyst[iSyst] ); // //theTempProX->Draw("HIST"); } } canvas->Print(Form("Template_%s_%s_Cat%d_ProX.png",sbtag[ibtag].c_str(),sfc[ifc].c_str(),icateg)); theTempProY->SetMarkerStyle(20); theTempProY->SetMarkerColor(1); theTempProY->SetLineColor(1); theTempProY->SetMarkerSize(1); std::cout << "Draw" << std::endl; theTempProY->Draw("EP"); theTempProY->Write(); } } } projections_out->Write(); projections_out->Close(); #endif hout->Write(); hout->Close(); // close the signal central file fSig->Close(); return; }
void plot2d(int hid) { gStyle->SetOptStat(0); char c[50]; c1->Clear(); if(hid!=2 && hid!=4){ c1->Divide(2,3); for(int disc=0; disc<kFgtNumDiscs; disc++){ TPad *pad = c1->cd(disc+1); pad->SetLogz(1); pad->SetTopMargin(0.01); pad->SetBottomMargin(0.02); sprintf(c,"Disc%1d%s",disc+1,c2dHist[hid]); //printf("Getting %s\n",c); TH2F *h = hist2[disc][hid] = (TH2F*)file->Get(c); h->Draw("COLZ"); } }else if(hid==2){ // special case for timing per APVboard gStyle->SetOptTitle(0); gStyle->SetOptFit(0); c1->Divide(2,1); char txt[100]; //int disc=3; char name[100]="MaxAdc"; int disc=4; char name[100]="LandauMPV"; //int disc=5; char name[100]="LandauMPV-3Sing"; TVirtualPad *pad2 = c1->cd(1); pad2->Divide(1,2); TVirtualPad *pad3=pad2->cd(1); pad3->SetLogz(1); pad2->SetLogz(0); sprintf(c,"Disc%1d%s",disc,c2dHist[hid]); TH2F *h = hist2[disc][hid] = (TH2F*)file->Get(c); h->Draw("COLZ"); TText *tt1= new TText(0.05,0.1,"(RDO-1)*12+ARM*2+GRP"); tt1->SetTextAngle(90); tt1->SetNDC(); tt1->Draw(); sprintf(txt,"Tbin for %s",name); TText *tt2= new TText(0.3,0,txt); tt2->SetNDC(); tt2->Draw(); TVirtualPad* pad4 = c1->cd(2); pad4->SetTopMargin(0.01); pad4->SetBottomMargin(0.1); int maxid=0; float off,max=0; TH1D *h1[24]; float mean[24]; for(int i=0; i<24; i++){ char ccc[10]; sprintf(ccc,"_%d_%d",disc,i); h1[i] = h->ProjectionX(ccc,i+1,i+1); if(h1[i]->GetMaximum() > max && i!=0) {max=h1[i]->GetMaximum(); maxid=i; } } off=max/4.0; printf("max=%f off=%f\n",max,off); for(int i=0; i<24; i++){ h1[i]->GetXaxis()->SetRangeUser(2,11); int res = h1[i]->Fit("gaus","0Q"); TF1* f=h1[i]->GetFunction("gaus"); if(h1[i]->GetMaximum()>max/3 && res==0){ mean[i] = f->GetParameter(1); //mean[i]=h1[i]->GetMean(); }else{mean[i]=0;}; //printf("%d mean=%f\n",i,mean[i]); } //h1[maxid]->SetLineColor(maxid+1); h1[maxid]->SetLineWidth(2); h1[maxid]->Draw("PL"); for(int rdo=1; rdo<=2; rdo++){ for(int arm=0; arm<6; arm++){ for(int grp=0; grp<2; grp++){ i=(rdo-1)*12+arm*2+grp; int nb=h1[i]->GetNbinsX(); for(int t=0; t<nb; t++){ h1[i]->AddBinContent(t+1,off*i); } h1[i]->SetLineColor(i%6+1); h1[i]->SetLineWidth(3); if(i==0) { h1[i]->SetMinimum(0); h1[i]->SetMaximum(max*6.5); h1[i]->Draw("PL"); } else {h1[i]->Draw("PL same");} char name[100]; sprintf(name,"Rdo%1dArm%1dGrp%1d",rdo,arm,grp); TText *tx = new TText(8.5,(max/4.0)*(i+0.2),name); tx->SetTextColor(i%6+1); tx->SetTextSize(0.03); tx->Draw(); } } } // TText *tt3= new TText(0.95,0.1,"offsets added by (RDO-1)*12+ARM*2+GRP"); tt3->SetTextAngle(90); tt3->SetNDC(); tt3->Draw(); TText *tt4= new TText(0.4,0,txt); tt4->SetNDC(); tt4->Draw(); //correlation float t2[24]={-8.47, -5.16, -0.21, -2.23, 1.11, -4.09, -3.13, -9.08, -5.88, -7.01, -6.22, -9.79, 0.75, -8.91, 0.16, 1.12, -0.99, -4.56, 7.57, -3.68, 7.12, -6.54, -4.08, -8.21}; TGraph *g= new TGraph(1); int j=0; for(int i=0; i<24; i++){ if(mean[i]>0) {g->SetPoint(j,(mean[i]-6.0)*27,t2[i]); j++;} } TVirtualPad* pad5=pad2->cd(2); g->SetMarkerStyle(20+i/6); g->SetMarkerSize(1); g->Draw("ap"); for(int i=0; i<24; i++){ TGraph *g2= new TGraph(1); if(mean[i]>0) {g2->SetPoint(j,(mean[i]-6.0)*27,t2[i]); j++;} g2->SetMarkerStyle(20+i/6); g2->SetMarkerSize(2); g2->SetMarkerColor(i%6+1); g2->Draw("p"); } TText *tt5= new TText(0.05,0.1,"(VPHASE_ADC-1.2V)/0.95V*27nsec/2"); tt5->SetTextAngle(90); tt5->SetNDC(); tt5->Draw(); TText *tt6= new TText(0.5,0,"(Tbin-6)*27nsec"); tt6->SetNDC(); tt6->Draw(); }else{ // special case for timing per APVboard gStyle->SetOptTitle(0); gStyle->SetOptFit(0); c1->Divide(4,6); char txt[100]; //int disc=3; char name[100]="MaxAdc"; int disc=4; char name[100]="LandauMPV"; //int disc=5; char name[100]="LandauMPV-3Sing"; sprintf(c,"Disc%1d%s",disc,c2dHist[2]); TH2F *h = hist2[disc][2] = (TH2F*)file->Get(c); TH1D *h1[24]; float mean[24]; for(int rdo=1; rdo<=2; rdo++){ for(int arm=0; arm<6; arm++){ for(int grp=0; grp<2; grp++){ int i=(rdo-1)*12+arm*2+grp; TVirtualPad *pad2 = c1->cd(i+1); pad2->SetTopMargin(0.01); pad2->SetBottomMargin(0.1); char ccc[10]; sprintf(ccc,"_%d_%d",disc,i); h1[i]=h->ProjectionX(ccc,i+1,i+1); h1[i]->GetXaxis()->SetRangeUser(2,12); h1[i]->SetFillColor(4); h1[i]->GetXaxis()->SetLabelSize(0.1); h1[i]->GetYaxis()->SetLabelSize(0.1); h1[i]->Draw(); int res = h1[i]->Fit("gaus","Q"); TF1* f=h1[i]->GetFunction("gaus"); f->SetLineColor(2); f->SetLineWidth(2); if(res==0){ mean[i] = f->GetParameter(1); }else{mean[i]=0;}; char name[100]; sprintf(name,"Rdo%1dArm%1d-%1d",rdo,arm,grp); TText *tx = new TText(0.5,0.85,name); tx->SetTextSize(0.1); tx->SetNDC(); tx->Draw(); if(mean[i]>0){ sprintf(name,"peak=%4.1f",mean[i]); TText *tx2 = new TText(0.55,0.75,name); tx2->SetTextSize(0.12); tx2->SetNDC(); tx2->Draw(); } } } } } c1->Update(); save(c2dHist[hid]); }
void HistPdfTest(void) { using namespace RooFit; TFile *fin = TFile::Open("./stobg_high.root"); TTree *tin = (TTree*)fin->Get("stobg_data"); TCut Cut_SC = "eta < 0 && charge < 0"; TCut Cut_DCA = "Rpc1dca < 100 && Rpc3dca < 100"; TCut Cut_FVTX = "((fvtx_dr * fvtx_dtheta) < 150) && (TMath::Abs(fvtx_dphi) < 1.5)"; TCut Cut_Comb = (Cut_SC + Cut_DCA + Cut_FVTX); TH2F *TestH = new TH2F("DCA_r_chi2", "", 100, 0, 30, 100, 0, 20); tin->Project(TestH->GetName(), "chi2:DCA_r", Cut_Comb); RooRealVar DCA_r("DCA_r", "DCA_r", 0, 30.0); RooRealVar chi2 ("chi2", "chi2", 0, 20.0); RooArgSet *ASX = new RooArgSet(DCA_r); RooArgSet *ASY = new RooArgSet(chi2); RooArgSet *ASXY = new RooArgSet(DCA_r, chi2); //Projected into each direction RooDataHist *D1x = new RooDataHist("D1x", "", *ASX, TestH->ProjectionX()); RooDataHist *D1y = new RooDataHist("D1y", "", *ASY, TestH->ProjectionY()); RooHistPdf *P1x = new RooHistPdf ("P1x", "", *ASX, *D1x); RooHistPdf *P1y = new RooHistPdf ("P1y", "", *ASY, *D1y); RooAbsPdf *AP1 = new RooProdPdf ("AP1", "", RooArgSet(*P1x, *P1y)); //Whole 2D histogram RooDataHist *D2 = new RooDataHist("D2", "", *ASXY, TestH); RooHistPdf *P2 = new RooHistPdf ("P2", "", *ASXY, *D2); RooAbsPdf *AP2 = new RooProdPdf ("AP2", "", RooArgSet(*P2)); //! ------------------------------------------------------------------ //Draw RooPlot *f1_x = DCA_r.frame(); RooPlot *f1_y = chi2.frame(); AP1->plotOn(f1_x); AP1->plotOn(f1_y); RooPlot *f2_x = DCA_r.frame(); RooPlot *f2_y = chi2.frame(); //D2 ->plotOn(f2_x, LineColor(2), LineWidth(2)); //D2 ->plotOn(f2_y, LineColor(2), LineWidth(2)); AP2->plotOn(f2_x, LineColor(4), LineWidth(2)); AP2->plotOn(f2_y, LineColor(4), LineWidth(2)); //! ------------------------------------------------------------------ TCanvas *c1 = new TCanvas("c1", "", 1280, 800); c1->Divide(2, 2); c1->cd(1); f1_x->Draw(); c1->cd(2); f1_y->Draw(); c1->cd(3); f2_x->Draw(); c1->cd(4); f2_y->Draw(); DCA_r = 4.10000; double Val1 = AP1->getVal(DCA_r); double Val2 = AP2->getVal(DCA_r); cout <<endl <<Val1 <<" " <<Val2 <<endl; return; }
//================================================ void DeltaZVsPos(const Int_t save = 0) { THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType])); TList *list = new TList; // dz vs BL TH2F *hTrkDzVsBL = (TH2F*)hn->Projection(1,3); c = draw2D(hTrkDzVsBL,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_BL_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_BL_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } list->Clear(); TString legName[30]; TH1F *hTrkDzInBL[30]; Int_t counter = 0; for(Int_t i=0; i<30; i++) { hTrkDzInBL[i] = (TH1F*)hTrkDzVsBL->ProjectionY(Form("hDeltaZ_BL%d",i+1),i+1,i+1); if(hTrkDzInBL[i]->GetEntries()>0) { legName[counter] = Form("Module %d",i+1); hTrkDzInBL[i]->SetLineColor(color[counter]); list->Add(hTrkDzInBL[i]); counter ++; } } c = drawHistos(list,"TrkDzInBL",Form("%s: #Deltaz of matched track-hit pairs in backleg;#Deltaz (cm)",trigName[kTrigType]),kTRUE,-100,100,kTRUE,0,1.2*hTrkDzInBL[1]->GetMaximum(),kFALSE,kTRUE,legName,kTRUE,"",0.15,0.25,0.2,0.88,kFALSE,0.04,0.04,kFALSE,1,kTRUE,kFALSE); TLine *line = GetLine(0,0,0,1.1*hTrkDzInBL[1]->GetMaximum(),1); line->Draw(); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_BL_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_BL_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } // dz vs Mod TH2F *hTrkDzVsMod = (TH2F*)hn->Projection(1,4); c = draw2D(hTrkDzVsMod,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_Mod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_Mod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } TH1F *hMthMod = (TH1F*)hTrkDzVsMod->ProjectionX("hMthMod"); hMthMod->Sumw2(); hMthMod->Scale(1./hMthMod->Integral()); TH2F *hMtdHitMap = (TH2F*)f->Get(Form("mhMtdHitMap_%s",trigName[kTrigType])); TH1F *htmp = (TH1F*)hMtdHitMap->ProjectionY("hHitMod_finebin"); htmp->Rebin(12); TH1F *hMtdHitMod = new TH1F(Form("hMtdHitMod_%s",trigName[kTrigType]),"# of MTD hits per module;module",5,1,6); for(int i=0; i<hMtdHitMod->GetNbinsX(); i++) { hMtdHitMod->SetBinContent(i+1,htmp->GetBinContent(i+1)); hMtdHitMod->SetBinError(i+1,htmp->GetBinError(i+1)); } hMtdHitMod->Scale(1./hMtdHitMod->Integral()); list->Clear(); list->Add(hMthMod); list->Add(hMtdHitMod); TString legName3[2] = {"Matched good hits","All good hits"}; c = drawHistos(list,"MtdHitMod",Form("%s: MTD hits per module;module;probability",trigName[kTrigType]),kFALSE,0,5,kTRUE,0,0.5,kFALSE,kTRUE,legName3,kTRUE,"",0.15,0.25,0.6,0.88,kTRUE); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sCompMtdHitMod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sCompMtdHitMod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } list->Clear(); TString legName2[5]; TH1F *hTrkDzInMod[5]; for(Int_t i=0; i<5; i++) { hTrkDzInMod[i] = (TH1F*)hTrkDzVsMod->ProjectionY(Form("hDeltaZ_Mod%d",i+1),i+1,i+1); legName2[i] = Form("Module %d",i+1); list->Add(hTrkDzInMod[i]); } c = drawHistos(list,"TrkDzInMod",Form("%s: #Deltaz of matched track-hit pairs in module;#Deltaz (cm)",trigName[kTrigType]),kTRUE,-100,100,kTRUE,0,1.2*hTrkDzInMod[3]->GetMaximum(),kFALSE,kTRUE,legName2,kTRUE,"",0.15,0.25,0.6,0.88,kTRUE); TLine *line = GetLine(0,0,0,hTrkDzInMod[3]->GetMaximum()*1.05,1); line->Draw(); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_Mod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_Mod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType])); } }
void plotHistHi() { gStyle->SetOptStat(0); set_plot_style(); TFile *f = new TFile("./../root_files/hists.root"); // sim-to-reco hists TH2F *hSim = (TH2F*) f->Get("hitrkEffAnalyzer/hsim"); hSim->GetYaxis()->SetRangeUser(0,10); TH2F *hAcc = (TH2F*) f->Get("hitrkEffAnalyzer/hacc"); hAcc->GetYaxis()->SetRangeUser(0,10); TH2F *hEff = (TH2F*) f->Get("hitrkEffAnalyzer/heff"); hEff->GetYaxis()->SetRangeUser(0,10); TH2F *hMul = (TH2F*) f->Get("hitrkEffAnalyzer/hmul"); hMul->GetYaxis()->SetRangeUser(0,10); // reco-to-sim hists TH2F *hRec = (TH2F*) f->Get("hitrkEffAnalyzer/hrec"); hRec->GetYaxis()->SetRangeUser(0,10); TH2F *hFak = (TH2F*) f->Get("hitrkEffAnalyzer/hfak"); hFak->GetYaxis()->SetRangeUser(0,10); TH2F *hSec = (TH2F*) f->Get("hitrkEffAnalyzer/hsec"); hSec->GetYaxis()->SetRangeUser(0,10); // ratio histograms TH2F *rAcc = (TH2F*) hAcc->Clone("rAcc"); TH2F *rEff = (TH2F*) hEff->Clone("rEff"); TH2F *rMul = (TH2F*) hMul->Clone("rMul"); TH2F *rFak = (TH2F*) hFak->Clone("rFak"); TH2F *rSec = (TH2F*) hSec->Clone("rSec"); //TH2F *rDec = (TH2F*) hDec->Clone("rDec"); //--------------------------------------------- // acceptance fraction TCanvas *c1 = new TCanvas("c1","Acceptance Fraction",600,500); gPad->SetRightMargin(0.15); rAcc->Divide(hAcc,hSim,1,1,"B"); rAcc->SetStats(0); rAcc->SetMaximum(1.0); rAcc->SetMinimum(0.0); rAcc->SetTitle("Geometrical Acceptance"); rAcc->Draw("colz"); // reco efficiency fraction TCanvas *c2 = new TCanvas("c2","Reco Efficiency Fraction",600,500); gPad->SetRightMargin(0.15); rEff->Divide(hEff,hAcc,1,1,"B"); rEff->SetStats(0); rEff->SetMaximum(1.0); rEff->SetMinimum(0.0); rEff->SetTitle("Algorithmic Efficiency"); rEff->Draw("colz"); // multiple reco fraction TCanvas *c3 = new TCanvas("c3","Multiple Reco Fraction",600,500); gPad->SetRightMargin(0.15); rMul->Divide(hMul,hAcc,1,1,"B"); rMul->SetStats(0); rMul->SetMaximum(0.00049); rMul->SetMinimum(0.0); rMul->SetTitle("Multiple Reconstruction Fraction"); rMul->Draw("colz"); // fake reco fraction TCanvas *c4 = new TCanvas("c4","Fake Reco Fraction",600,500); gPad->SetRightMargin(0.15); rFak->Divide(hFak,hRec,1,1,"B"); rFak->SetStats(0); rFak->SetMaximum(0.1); rFak->SetMinimum(0.0); rFak->SetTitle("Fake Reconstruction Fraction"); rFak->Draw("colz"); // secondary reco fraction TCanvas *c5 = new TCanvas("c5","Secondary Fraction",600,500); gPad->SetRightMargin(0.15); rSec->Divide(hSec,hRec,1,1,"B"); rSec->SetStats(0); rSec->SetMaximum(0.05); rSec->SetMinimum(0.0); rSec->SetTitle("Non-Primary Reconstruction Fraction"); rSec->Draw("colz"); //--------------------------------------------- // find bins corresponding to projections for below Int_t ptbin04=hSim->GetYaxis()->FindBin(0.91); Int_t ptbin20=hSim->GetYaxis()->FindBin(2.01); Int_t ptbins=hSim->GetYaxis()->GetNbins(); Int_t etabin24m=hSim->GetXaxis()->FindBin(-2.39); Int_t etabin24p=hSim->GetXaxis()->FindBin(2.39); Int_t etabin10m=hSim->GetXaxis()->FindBin(-0.99); Int_t etabin10p=hSim->GetXaxis()->FindBin(0.99); cout << "etabin10m: " << etabin10m << " etabin10p: " << etabin10p << endl; cout << "etabin10m: " << etabin24m << " etabin10p: " << etabin24p << endl; // projected hists: pt > 0.9 GeV/c TH1D* hSimEta = (TH1D*) hSim->ProjectionX("hSimEta",ptbin04,ptbins,"e"); TH1D* hAccEta = (TH1D*) hAcc->ProjectionX("hAccEta",ptbin04,ptbins,"e"); TH1D* hEffEta = (TH1D*) hEff->ProjectionX("hEffEta",ptbin04,ptbins,"e"); TH1D* hMulEta = (TH1D*) hMul->ProjectionX("hMulEta",ptbin04,ptbins,"e"); TH1D* hRecEta = (TH1D*) hRec->ProjectionX("hRecEta",ptbin04,ptbins,"e"); TH1D* hFakEta = (TH1D*) hFak->ProjectionX("hFakEta",ptbin04,ptbins,"e"); TH1D* hSecEta = (TH1D*) hSec->ProjectionX("hSecEta",ptbin04,ptbins,"e"); // projected hists: pt > 2.0 GeV/c TH1D* hSimEta2 = (TH1D*) hSim->ProjectionX("hSimEta2",ptbin20,ptbins,"e"); TH1D* hAccEta2 = (TH1D*) hAcc->ProjectionX("hAccEta2",ptbin20,ptbins,"e"); TH1D* hEffEta2 = (TH1D*) hEff->ProjectionX("hEffEta2",ptbin20,ptbins,"e"); TH1D* hMulEta2 = (TH1D*) hMul->ProjectionX("hMulEta2",ptbin20,ptbins,"e"); TH1D* hRecEta2 = (TH1D*) hRec->ProjectionX("hRecEta2",ptbin20,ptbins,"e"); TH1D* hFakEta2 = (TH1D*) hFak->ProjectionX("hFakEta2",ptbin20,ptbins,"e"); TH1D* hSecEta2 = (TH1D*) hSec->ProjectionX("hSecEta2",ptbin20,ptbins,"e"); TH1D* hDumEta = new TH1D("hDumEta",";#eta",60,-2.4,2.4); hDumEta->SetMaximum(1.0); hDumEta->GetXaxis()->CenterTitle(); hDumEta->GetYaxis()->SetTitleOffset(1.8); TH1D* hDumEta2 = (TH1D*) hDumEta->Clone("hDumEta2"); hDumEta2->SetMaximum(0.1); TH1D* hDumEta3 = (TH1D*) hDumEta->Clone("hDumEta3"); hDumEta3->SetMaximum(0.00049); // projected hists: abs(eta) < 1.0 TH1D* hSimPt = (TH1D*) hSim->ProjectionY("hSimPt",etabin10m,etabin10p,"e"); TH1D* hAccPt = (TH1D*) hAcc->ProjectionY("hAccPt",etabin10m,etabin10p,"e"); TH1D* hEffPt = (TH1D*) hEff->ProjectionY("hEffPt",etabin10m,etabin10p,"e"); TH1D* hMulPt = (TH1D*) hMul->ProjectionY("hMulPt",etabin10m,etabin10p,"e"); TH1D* hRecPt = (TH1D*) hRec->ProjectionY("hRecPt",etabin10m,etabin10p,"e"); TH1D* hFakPt = (TH1D*) hFak->ProjectionY("hFakPt",etabin10m,etabin10p,"e"); TH1D* hSecPt = (TH1D*) hSec->ProjectionY("hSecPt",etabin10m,etabin10p,"e"); // projected hists: abs(eta) < 2.4 TH1D* hSimPt2 = (TH1D*) hSim->ProjectionY("hSimPt2",etabin24m,etabin24p,"e"); TH1D* hAccPt2 = (TH1D*) hAcc->ProjectionY("hAccPt2",etabin24m,etabin24p,"e"); TH1D* hEffPt2 = (TH1D*) hEff->ProjectionY("hEffPt2",etabin24m,etabin24p,"e"); TH1D* hMulPt2 = (TH1D*) hMul->ProjectionY("hMulPt2",etabin24m,etabin24p,"e"); TH1D* hRecPt2 = (TH1D*) hRec->ProjectionY("hRecPt2",etabin24m,etabin24p,"e"); TH1D* hFakPt2 = (TH1D*) hFak->ProjectionY("hFakPt2",etabin24m,etabin24p,"e"); TH1D* hSecPt2 = (TH1D*) hSec->ProjectionY("hSecPt2",etabin24m,etabin24p,"e"); TH1D* hDumPt = new TH1D("hDumPt",";p_{T} [GeV/c]",80,0.0,10.0); hDumPt->SetMaximum(1.0); hDumPt->GetXaxis()->CenterTitle(); hDumPt->GetYaxis()->SetTitleOffset(1.8); TH1D* hDumPt2 = (TH1D*) hDumPt->Clone("hDumPt2"); hDumPt2->SetMaximum(0.1); TH1D* hDumPt3 = (TH1D*) hDumPt->Clone("hDumPt3"); hDumPt3->SetMaximum(0.00049); // Acceptance TGraphAsymmErrors *gAccEta = new TGraphAsymmErrors(); gAccEta->SetName("gAccEta"); gAccEta->BayesDivide(hAccEta,hSimEta); gAccEta->SetMarkerStyle(25); gAccEta->SetLineStyle(2); gAccEta->SetLineColor(2); gAccEta->SetMarkerColor(2); TGraphAsymmErrors *gAccPt = new TGraphAsymmErrors(); gAccPt->SetName("gAccPt"); gAccPt->BayesDivide(hAccPt,hSimPt); gAccPt->SetMarkerStyle(24); gAccPt->SetLineColor(4); gAccPt->SetMarkerColor(4); TGraphAsymmErrors *gAccEta2 = new TGraphAsymmErrors(); gAccEta2->SetName("gAccEta2"); gAccEta2->BayesDivide(hAccEta2,hSimEta2); gAccEta2->SetMarkerStyle(24); gAccEta2->SetLineColor(4); gAccEta2->SetMarkerColor(4); TGraphAsymmErrors *gAccPt2 = new TGraphAsymmErrors(); gAccPt2->SetName("gAccPt2"); gAccPt2->BayesDivide(hAccPt2,hSimPt2); gAccPt2->SetMarkerStyle(25); gAccPt2->SetLineStyle(2); gAccPt2->SetLineColor(2); gAccPt2->SetMarkerColor(2); TLegend *legEta = new TLegend(0.35,0.3,0.65,0.5); legEta->SetFillColor(0); legEta->SetBorderSize(0); legEta->AddEntry(gAccEta,"p_{T} > 0.9 GeV/c","lp"); legEta->AddEntry(gAccEta2,"p_{T} > 2.0 GeV/c","lp"); TLegend *legPt = new TLegend(0.4,0.3,0.6,0.5); legPt->SetFillColor(0); legPt->SetBorderSize(0); legPt->AddEntry(gAccPt2,"|#eta| < 2.4","lp"); legPt->AddEntry(gAccPt,"|#eta| < 1.0","lp"); TCanvas *c6 = new TCanvas("c6","Acceptance Fraction",900,500); c6->Divide(2,1); hDumEtaAcc=(TH1F*) hDumEta->Clone("hDumEtaAcc"); hDumEtaAcc->GetYaxis()->SetTitle("Geometrical acceptance"); hDumPtAcc=(TH1F*) hDumPt->Clone("hDumPtAcc"); hDumPtAcc->GetYaxis()->SetTitle("Geometrical acceptance"); c6->cd(1); hDumEtaAcc->Draw(); gAccEta->Draw("pc"); gAccEta2->Draw("pc"); legEta->Draw(); c6->cd(2); hDumPtAcc->Draw(); gAccPt->Draw("pc"); gAccPt2->Draw("pc"); legPt->Draw(); // Efficiency TGraphAsymmErrors *gEffEta = new TGraphAsymmErrors(); gEffEta->SetName("gEffEta"); gEffEta->BayesDivide(hEffEta,hAccEta); gEffEta->SetMarkerStyle(25); gEffEta->SetLineStyle(2); gEffEta->SetLineColor(2); gEffEta->SetMarkerColor(2); TGraphAsymmErrors *gEffPt = new TGraphAsymmErrors(); gEffPt->SetName("gEffPt"); gEffPt->BayesDivide(hEffPt,hAccPt); gEffPt->SetMarkerStyle(24); gEffPt->SetLineColor(4); gEffPt->SetMarkerColor(4); TGraphAsymmErrors *gEffEta2 = new TGraphAsymmErrors(); gEffEta2->SetName("gEffEta2"); gEffEta2->BayesDivide(hEffEta2,hAccEta2); gEffEta2->SetMarkerStyle(24); gEffEta2->SetLineColor(4); gEffEta2->SetMarkerColor(4); TGraphAsymmErrors *gEffPt2 = new TGraphAsymmErrors(); gEffPt2->SetName("gEffPt2"); gEffPt2->BayesDivide(hEffPt2,hAccPt2); gEffPt2->SetMarkerStyle(25); gEffPt2->SetLineStyle(2); gEffPt2->SetLineColor(2); gEffPt2->SetMarkerColor(2); TCanvas *c7 = new TCanvas("c7","Efficiency Fraction",900,500); c7->Divide(2,1); hDumEtaEff=(TH1F*) hDumEta->Clone("hDumEtaEff"); hDumEtaEff->GetYaxis()->SetTitle("Algorithmic efficiency"); hDumPtEff=(TH1F*) hDumPt->Clone("hDumPtEff"); hDumPtEff->GetYaxis()->SetTitle("Algorithmic efficiency"); c7->cd(1); hDumEtaEff->Draw(); gEffEta->Draw("pc"); gEffEta2->Draw("pc"); legEta->Draw(); c7->cd(2); hDumPtEff->Draw(); gEffPt->Draw("pc"); gEffPt2->Draw("pc"); legPt->Draw(); // Multiple Reco TGraphAsymmErrors *gMulEta = new TGraphAsymmErrors(); gMulEta->SetName("gMulEta"); gMulEta->BayesDivide(hMulEta,hAccEta); gMulEta->SetMarkerStyle(25); gMulEta->SetLineStyle(2); gMulEta->SetLineColor(2); gMulEta->SetMarkerColor(2); TGraphAsymmErrors *gMulPt = new TGraphAsymmErrors(); gMulPt->SetName("gMulPt"); gMulPt->BayesDivide(hMulPt,hAccPt); gMulPt->SetMarkerStyle(24); gMulPt->SetLineColor(4); gMulPt->SetMarkerColor(4); TGraphAsymmErrors *gMulEta2 = new TGraphAsymmErrors(); gMulEta2->SetName("gMulEta2"); gMulEta2->BayesDivide(hMulEta2,hAccEta2); gMulEta2->SetMarkerStyle(24); gMulEta2->SetLineColor(4); gMulEta2->SetMarkerColor(4); TGraphAsymmErrors *gMulPt2 = new TGraphAsymmErrors(); gMulPt2->SetName("gMulPt2"); gMulPt2->BayesDivide(hMulPt2,hAccPt2); gMulPt2->SetMarkerStyle(25); gMulPt2->SetLineStyle(2); gMulPt2->SetLineColor(2); gMulPt2->SetMarkerColor(2); TCanvas *c8 = new TCanvas("c8","Multiple Fraction",900,500); c8->Divide(2,1); hDumEtaMul=(TH1F*) hDumEta3->Clone("hDumEtaMul"); hDumEtaMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction"); hDumPtMul=(TH1F*) hDumPt3->Clone("hDumPtMul"); hDumPtMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction"); legEta2 = (TLegend*) legEta->Clone(); legEta2->SetY1(0.65); legEta2->SetY2(0.85); legPt2 = (TLegend*) legPt->Clone(); legPt2->SetY1(0.65); legPt2->SetY2(0.85); c8->cd(1); hDumEtaMul->Draw(); gMulEta->Draw("pc"); gMulEta2->Draw("pc"); legEta2->Draw(); c8->cd(2); hDumPtMul->Draw(); gMulPt->Draw("pc"); gMulPt2->Draw("pc"); legPt2->Draw(); // Fakes TGraphAsymmErrors *gFakEta = new TGraphAsymmErrors(); gFakEta->SetName("gFakEta"); gFakEta->BayesDivide(hFakEta,hRecEta); gFakEta->SetMarkerStyle(25); gFakEta->SetLineStyle(2); gFakEta->SetLineColor(2); gFakEta->SetMarkerColor(2); TGraphAsymmErrors *gFakPt = new TGraphAsymmErrors(); gFakPt->SetName("gFakPt"); gFakPt->BayesDivide(hFakPt,hRecPt); gFakPt->SetMarkerStyle(24); gFakPt->SetLineColor(4); gFakPt->SetMarkerColor(4); TGraphAsymmErrors *gFakEta2 = new TGraphAsymmErrors(); gFakEta2->SetName("gFakEta2"); gFakEta2->BayesDivide(hFakEta2,hRecEta2); gFakEta2->SetMarkerStyle(24); gFakEta2->SetLineColor(4); gFakEta2->SetMarkerColor(4); TGraphAsymmErrors *gFakPt2 = new TGraphAsymmErrors(); gFakPt2->SetName("gFakPt2"); gFakPt2->BayesDivide(hFakPt2,hRecPt2); gFakPt2->SetMarkerStyle(25); gFakPt2->SetLineStyle(2); gFakPt2->SetLineColor(2); gFakPt2->SetMarkerColor(2); TCanvas *c9 = new TCanvas("c9","Fake Fraction",900,500); c9->Divide(2,1); hDumEtaFak=(TH1F*) hDumEta2->Clone("hDumEtaMul"); hDumEtaFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction"); hDumPtFak=(TH1F*) hDumPt2->Clone("hDumPtMul"); hDumPtFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction"); c9->cd(1); hDumEtaFak->Draw(); gFakEta->Draw("pc"); gFakEta2->Draw("pc"); legEta2->Draw(); c9->cd(2); hDumPtFak->Draw(); gFakPt->Draw("pc"); gFakPt2->Draw("pc"); legPt2->Draw(); // Secondaries TGraphAsymmErrors *gSecEta = new TGraphAsymmErrors(); gSecEta->SetName("gSecEta"); gSecEta->BayesDivide(hSecEta,hRecEta); gSecEta->SetMarkerStyle(25); gSecEta->SetLineStyle(2); gSecEta->SetLineColor(2); gSecEta->SetMarkerColor(2); TGraphAsymmErrors *gSecPt = new TGraphAsymmErrors(); gSecPt->SetName("gSecPt"); gSecPt->BayesDivide(hSecPt,hRecPt); gSecPt->SetMarkerStyle(24); gSecPt->SetLineColor(4); gSecPt->SetMarkerColor(4); TGraphAsymmErrors *gSecEta2 = new TGraphAsymmErrors(); gSecEta2->SetName("gSecEta2"); gSecEta2->BayesDivide(hSecEta2,hRecEta2); gSecEta2->SetMarkerStyle(24); gSecEta2->SetLineColor(4); gSecEta2->SetMarkerColor(4); TGraphAsymmErrors *gSecPt2 = new TGraphAsymmErrors(); gSecPt2->SetName("gSecPt2"); gSecPt2->BayesDivide(hSecPt2,hRecPt2); gSecPt2->SetMarkerStyle(25); gSecPt2->SetLineStyle(2); gSecPt2->SetLineColor(2); gSecPt2->SetMarkerColor(2); TCanvas *c10 = new TCanvas("c10","Secondary Fraction",900,500); c10->Divide(2,1); hDumEtaSec=(TH1F*) hDumEta2->Clone("hDumEtaMul"); hDumEtaSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction"); hDumPtSec=(TH1F*) hDumPt2->Clone("hDumPtMul"); hDumPtSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction"); c10->cd(1); hDumEtaSec->Draw(); gSecEta->Draw("pc"); gSecEta2->Draw("pc"); legEta2->Draw(); c10->cd(2); hDumPtSec->Draw(); gSecPt->Draw("pc"); gSecPt2->Draw("pc"); legPt2->Draw(); /* printCanvases(c1,"hitrk_can1",0,1); printCanvases(c2,"hitrk_can2",0,1); printCanvases(c3,"hitrk_can3",0,1); printCanvases(c4,"hitrk_can4",0,1); printCanvases(c5,"hitrk_can5",0,1); printCanvases(c6,"hitrk_can6",0,1); printCanvases(c7,"hitrk_can7",0,1); printCanvases(c8,"hitrk_can8",0,1); printCanvases(c9,"hitrk_can9",0,1); printCanvases(c10,"hitrk_can10",0,1); */ /* TFile *f = new TFile("trkEffPY8.root","RECREATE"); gAccPt->Write(); gAccPt2->Write(); gAccEta->Write(); gAccEta2->Write(); gEffPt->Write(); gEffPt2->Write(); gEffEta->Write(); gEffEta2->Write(); gMulPt->Write(); gMulPt2->Write(); gMulEta->Write(); gMulEta2->Write(); gFakPt->Write(); gFakPt2->Write(); gFakEta->Write(); gFakEta2->Write(); gSecPt->Write(); gSecPt2->Write(); gSecEta->Write(); gSecEta2->Write(); f->Close(); */ }
/*//////////////////////////////////////////////////////////////////// Opens the files, takes the appropriate Pt slice for the mass based on the ptMin and ptMax. Rebins if specified by comining rebin numbr of bins, and returns the background subtracated invariant mass historgam ////////////////////////////////////////////////////////////////////*/ TH1D* makePtHist(TH1D* inComing, double ptMin, double ptMax, int rebin, int fileNum) { if(fileNum < 0 || fileNum > 4) { cout << "number not in the cut range" << endl; return; } TFile *myFile = TFile::Open("GammaCalo_MC_LHC15g2_60.root"); TList *myL = (TList*)myFile->Get("GammaCalo;1"); TString cutString[5]; cutString[0] = "00000113_1111121063032220000_0163103100000050"; cutString[1] = "00000013_1111121063032220000_0163103100000050"; cutString[2] = "00052013_1111121063032220000_0163103100000050"; cutString[3] = "00083013_1111121063032220000_0163103100000050"; cutString[4] = "00085013_1111121063032220000_0163103100000050"; cout << "Cut selection: " << cutString[fileNum] << endl; TString folderString = "Cut Number " + cutString[fileNum]; TList* cut_folder = (TList*)myL->FindObject(folderString); TString esdString = cutString[fileNum] + " ESD histograms"; TList* esdHists = (TList*)cut_folder->FindObject(esdString); TH2F* hist = (TH2F*)esdHists->FindObject("ESD_Mother_InvMass_Pt"); hist->GetXaxis()->SetTitle("M_{} (GeV/c^2)"); hist->GetYaxis()->SetTitle("Pt (GeV/c)"); //TCanvas* c1 = new TCanvas(); //hist->Draw("colz"); int ptBinMin = static_cast<int>(ptMin*10); int ptBinMax = static_cast<int>(ptMax*10); TH1D* pi0 = inComing; //gStyle->SetTitleFontSize(0.7); pi0->GetXaxis()->SetTitle("M_{#gamma#gamma} (GeV/c^{2})"); pi0->GetXaxis()->SetTitleSize(0.05); //gStyle->SetTitleFontSize(0.5); pi0->GetYaxis()->SetTitle("dN_{#gamma#gamma}/dM_{#gamma#gamma}"); pi0->GetYaxis()->SetTitleSize(0.05); pi0->SetMarkerStyle(33); char buffer[150]; sprintf(buffer, "%.02f < p_{T} < %.02f GeV/c", ptMin, ptMax); pi0->SetTitle(buffer); //cout << "Title Size for" << buffer << "\t" << pi0->GetTitleSize() << endl; //pi0->SetTitleSize(0.3); gStyle->SetTitleFontSize(0.055); //cout << "Title Size for" << buffer << "\t" << pi0->GetTitleSize() << endl; TH1D* pi0WBg = hist->ProjectionX("pi0WBg",ptBinMin,ptBinMax,""); pi0WBg->GetYaxis()->SetTitle("dN_{#gamma#gamma}/dM_{#gamma#gamma}"); pi0WBg->GetYaxis()->SetTitleSize(0.05); pi0WBg->GetXaxis()->SetTitleSize(0.05); pi0WBg->GetXaxis()->SetTitle("M_{#gamma#gamma} (GeV/c^{2})"); totEntries += pi0WBg->GetEntries(); cout << "Num entries: " << pi0WBg->GetEntries() << "\tcummulative: " << totEntries << endl; if(rebin) { pi0WBg->Rebin(rebin); pi0->Rebin(rebin); } pi0WBg->SetTitle("#pi^0 peak from invariant mass"); //TCanvas* c2 = new TCanvas(); //pi0WBg->GetXaxis()->SetRangeUser(0,0.3); //pi0WBg->Draw("E1"); pi0WBg->Fit("pol1", "Q0"); double p0 = pi0WBg->GetFunction("pol1")->GetParameter(0); double p1 = pi0WBg->GetFunction("pol1")->GetParameter(1); //cout << "p0: "<< p0 << "\t" << "p1: " << p1 << endl; int binContents[800] = {0}; int totBins = pi0WBg->GetNbinsX(); for(int i = 0; i < totBins; i++) { binContents[i] = pi0WBg->GetBinContent(i+1); //if(i%100 == 0) //cout << i+1 << "\t" << pi0Wbg->GetBinContent(i+1) << endl; } //making changes in the new hsitogram for(int i = 0; i < totBins; i++) { double y, x, binVal; x = y = binVal = 0; x = pi0WBg->GetBinCenter(i+1); y = p0 + p1*x; binVal = pi0WBg->GetBinContent(i+1); if(binVal) binVal = pi0WBg->GetBinContent(i+1) - y;; pi0->SetBinContent(i+1,binVal); //cout << i+1 << "\t" << binContents[i] << "\t" << pi0WBg->GetBinContent(i+1) << "\t" << pi0->GetBinContent(i+1) << endl; } //TCanvas* c3 = new TCanvas(); //pi0->Draw();//*/ return pi0; }
void findcent() { const int color[10] = {2,3,4,5,6,7,8,4,3,2}; const double centbin[] = {0,0.005,0.01,0.05,0.1,0.2,0.3,0.4,0.6,1.0}; //const double centbin[] = {0,0.001,0.005,0.01,0.05,0.1,0.2,0.4,0.6,1.0}; //double centbin[101]; //for(int i=0;i<101;i++){ // centbin[i]=i*0.01; //} const double erf = 1e-5; int ncent = (int)sizeof(centbin)/sizeof(double); //TFile *f = TFile::Open("merged_AnapAlfvtxor.root"); //TFile *f = TFile::Open("merged_AnapAlfvtxand.root"); //TFile *f = TFile::Open("merged_AnapAlfvtxsouth.root"); TFile *f = TFile::Open("merged_AnaMWGppmb.root"); // TH2F* pc1hitsbbcdis = (TH2F*)f->Get("pc1hitsbbcdis"); // TH1F* pc1hitsdis = (TH1F*)f->Get("pc1hitsdis"); // TH2F* hbbcntrk = (TH2F*)f->Get("hbbcnbbc"); TH2F* hbbcntrk = (TH2F*)f->Get("hnfvtxtrkbbc"); // hbbcntrk->RebinX(3); // TH1F* bbcsouthdis = (TH1F*)pc1hitsbbcdis->ProjectionX(0,-1); TH1F* bbcsouthdis = (TH1F*)hbbcntrk->ProjectionX(0,-1); // TH2F* bbcsouthdis = (TH2F*)hbbcntrk->Clone("bbcsouthdis"); bbcsouthdis->SetTitle("BBC charge distribution"); bbcsouthdis->GetXaxis()->SetTitle("BBC charge"); bbcsouthdis->GetYaxis()->SetTitle("# of Events"); // pc1hitsdis->SetTitle("PC1 hits distribution"); // pc1hitsdis->GetXaxis()->SetTitle("PC1 hits"); // pc1hitsdis->GetYaxis()->SetTitle("# of Events"); ofstream fstr("centbin_bbcmb.txt"); // fstr<<"centbin"<<"\t"<<"bbcsouth"<<"\t"<<"pc1hits"<<"\t"<<"bbc ratio"<<"\t"<<"pc1hits ratio"<<endl; fstr<<"centbin"<<"\t"<<"bbc"<<"\t"<<"bbc ratio"<<endl; vector<double> bbcs; // vector<double> pc1hs; for(int icent = 0; icent < ncent; icent++){ double bbcskp = findpoint(bbcsouthdis,centbin[icent]); // double pc1hskp = findpoint(pc1hitsdis,centbin[icent]); if(bbcskp<0) bbcskp = 0; // if(pc1hskp<0) pc1hskp = 0; bbcs.push_back(bbcskp); cout<<bbcskp<<","; // pc1hs.push_back(pc1hskp); } for(int icent = 0; icent < ncent; icent++){ // fstr<<centbin[icent]<<"\t"<<bbcs[icent]<<"\t"<<pc1hs[icent]<<"\t"<<bbcsouthdis->Integral(bbcsouthdis->FindBin(bbcs[icent]+erf),bbcsouthdis->FindBin(bbcs[0]-erf))/bbcsouthdis->Integral(bbcsouthdis->FindBin(bbcs[ncent-1]-erf),bbcsouthdis->FindBin(bbcs[0]+erf))<<"\t"<<pc1hitsdis->Integral(pc1hitsdis->FindBin(pc1hs[icent]+erf),pc1hitsdis->FindBin(pc1hs[0]-erf))/pc1hitsdis->Integral(pc1hitsdis->FindBin(pc1hs[ncent-1]-erf),pc1hitsdis->FindBin(pc1hs[0]+erf))<<endl; fstr<<centbin[icent]<<"\t"<<bbcs[icent]<<"\t"<<bbcsouthdis->Integral(bbcsouthdis->FindBin(bbcs[icent]+erf),bbcsouthdis->FindBin(bbcs[0]-erf))/bbcsouthdis->Integral(bbcsouthdis->FindBin(bbcs[ncent-1]-erf),bbcsouthdis->FindBin(bbcs[0]+erf))<<endl; //fstr<<centbin[icent]<<"\t"<<bbcs[icent]<<"\t"<<bbcsouthdis->Integral(bbcsouthdis->GetXaxis()->FindBin(bbcs[icent]+erf),bbcsouthdis->GetXaxis()->FindBin(bbcs[0]-erf),bbcsouthdis->GetYaxis()->FindBin(bbcs[icent]+erf),bbcsouthdis->GetYaxis()->FindBin(bbcs[0]-erf))/bbcsouthdis->Integral(bbcsouthdis->FindBin(bbcs[ncent-1]-erf,bbcs[ncent-1]-erf),bbcsouthdis->FindBin(bbcs[0]+erf,bbcs[0]+erf))<<endl; } TCanvas *c1 = new TCanvas(); //c1->SetLogx(); c1->SetLogy(); // c1->SetLogz(); bbcsouthdis->GetXaxis()->SetRangeUser(0,500); // bbcsouthdis->GetYaxis()->SetRangeUser(0,100); bbcsouthdis->Draw(); for(int icent = 0; icent < ncent; icent++){ TH1F* bbcs_t = (TH1F*)bbcsouthdis->Clone(Form("bbcs_%d",icent)); bbcs_t->GetXaxis()->SetRangeUser(bbcs[icent+1]-erf,bbcs[icent]+erf); //bbcs_t->GetYaxis()->SetRangeUser(bbcs[icent+1]-erf,bbcs[icent]+erf); bbcs_t->SetFillColor(color[icent]); bbcs_t->Draw("HIST same"); } c1->Print("bbcaddcent.png"); /* TCanvas *c2 = new TCanvas(); c2->SetLogy(); pc1hitsdis->Draw(); for(int icent = 0; icent < ncent; icent++){ TH1F* pc1hs_t = (TH1F*)pc1hitsdis->Clone(Form("pc1hs_%d",icent)); pc1hs_t->GetXaxis()->SetRangeUser(pc1hs[icent+1]-erf,pc1hs[icent]+erf); pc1hs_t->SetFillColor(color[icent]); pc1hs_t->Draw("HIST same"); } c2->Print("pc1hits.png"); */ }
void CalcFakeRate(string infile, bool useData=true, bool doSystematics=false){ cout<<" UseData="<<useData<<" dosystematics="<<doSystematics<<endl; TFile *f = TFile::Open(infile.c_str(), "read"); assert(f); TH2F* hFakeRateNum = NULL; TH2F* hFakeRateAll = NULL; gStyle->SetOptStat(0); gStyle->SetPalette(1); gStyle->SetTextFont(132); gStyle->SetTextSize(1.2); //gROOT->ForceStyle(); bool useElectrons = infile.find("Muon") == string::npos; bool doWLep = infile.find("-TT") == string::npos; vector<string> allsamples; if(!useData){ allsamples.push_back("WJetsToLNu"); if(!doSystematics){ allsamples.push_back("TTJets"); allsamples.push_back("ZZ"); allsamples.push_back("GVJets"); allsamples.push_back("WWTo2L2Nu"); allsamples.push_back("WZJetsTo3LNu"); allsamples.push_back("DYJetsToLL"); } }else{ allsamples.push_back("data"); } float offset = 0.01; float eta[] = {0., 1.5, 2.5}; int neta = 3; if(!useElectrons){ eta[1] = 2.4; neta = 2;//eta[2] = 2.4; } //float pt [] = {0., 20., 40., 1000}; const int npt = 4; //float pt [] = {0., 10., 20., 30., 1000}; const int npt = 5; //float pt [] = {0., 10., 15., 25., 1000}; const int npt = 5; //float pt [] = {0., 10., 15., 20., 30., 1000}; const int npt = 6; float pt [] = {10., 15., 20., 30., 40., 100}; const int npt = 6; //float pt [] = {0., 20., 25., 30., 50., 1000}; const int npt = 6; hFakeRateNum = new TH2F("hFakeRateNum", "hFakeRateNum;p_{T} (GeV);#eta", npt-1, pt, neta-1, eta); hFakeRateAll = new TH2F("hFakeRateAll", "hFakeRateAll;p_{T} (GeV);#eta", npt-1, pt, neta-1, eta); string title = useElectrons ? "Electron Fake Rate" : "Muon Fake Rate"; title += useData ? " from Data" : " from MC"; title += !useData && doSystematics ? " Systematics" : ""; title += " using W+Jets method"; title += doWLep ? " on W lepton" : " on Z lepton"; hFakeRateNum->SetTitle(title.c_str()); /////////This is for eta, pt agnotistic Fake Rate Calc float in_tot(0), out_tot(0); for(unsigned i=0; i<allsamples.size(); ++i){ string hist_name = allsamples[i] + "/hNumEvts"; TH1F* hist = (TH1F*) f->Get(hist_name.c_str()); assert(hist); int lastbin = hist->GetNbinsX(); float in(0), out(0); in = hist->GetBinContent(lastbin); out = hist->GetBinContent(lastbin-1); in_tot += in; out_tot += out; //cout<<"Sample: "<<allsamples[i]<<" = "<<in/out<<" = pass/total = "<<in<<"/"<<out<<endl; printf(" Sample: %s = %.2f%% : pass/total = %.2f / %.2f \n",allsamples[i].c_str(), in/out*100, in, out); } float eff = in_tot/out_tot; float deff = TMath::Sqrt(eff * (1-eff)/out_tot); //cout<<"Total: "<<eff*100<<"% +/- "<<deff*100<<"% = in_tot/out_tot*100% = "<<in_tot<<"/"<<out_tot<<"*100%\n"; printf("Total: %.2f%% +/- %.2f%% = in_tot/out_tot*100%% = %.2f/%.2f\n", eff*100, deff*100, in_tot, out_tot); /////////This is for 2D Fake Rate Calc for(unsigned i=0; i<allsamples.size(); ++i){ string hist_name = allsamples[i] + "/hNumEvts"; TH1F* hist = (TH1F*) f->Get(hist_name.c_str()); assert(hist); int lastbin = hist->GetNbinsX(); float in(0), out(0); string binNameNum = hist->GetXaxis()->GetBinLabel(lastbin); string binNameDenom = hist->GetXaxis()->GetBinLabel(lastbin-1); string hist_nameNum = allsamples[i] + "/hEtaVsPt_" + binNameNum; TH2F* histNum = (TH2F*) f->Get(hist_nameNum.c_str()); assert(histNum); string hist_nameDenom = allsamples[i] + "/hEtaVsPt_" + binNameDenom; TH2F* histDenom = (TH2F*) f->Get(hist_nameDenom.c_str()); assert(histDenom); /* cout<<" Total from 2D Plot is "<<histNum->Integral()<<" / "<<histDenom->Integral()<<endl; //By default, integral doesn't count over/underflow cout<<" Total from 2D Plot is "<<histNum->GetEntries()<<" / "<<histDenom->GetEntries()<<endl; float sUnder(0), sOver(0); for(int ybin = 0; ybin<= histDenom->GetYaxis()->GetNbins() + 1; ++ybin){ for(int xbin = 0; xbin<= histDenom->GetXaxis()->GetNbins() +1; ++xbin){ int bin = histDenom->GetBin(xbin, ybin); if(histDenom->IsBinOverflow(bin)) sOver += histDenom->GetBinContent(bin); if(histDenom->IsBinUnderflow(bin)) sUnder += histDenom->GetBinContent(bin); } } printf("Total overflow, underflow in denom histo is %.2f , %.2f\n", sOver, sUnder); */ for(int ieta=0; ieta<neta-1; ++ieta){ float ymin = eta[ieta]; float ymax = eta[ieta+1]-offset; for(int ipt=0; ipt<npt-1; ++ipt){ float xmin = pt[ipt]; float xmax = pt[ipt+1]; int xminbin,xmaxbin,yminbin,ymaxbin; xminbin = histNum->GetXaxis()->FindBin(xmin); //+ (ipt!=0);//Avoid overlap except for first bin xmaxbin = histNum->GetXaxis()->FindBin(xmax)-1 + (ipt == npt-1-1); yminbin = histNum->GetYaxis()->FindBin(ymin); ymaxbin = histNum->GetYaxis()->FindBin(ymax); /* cout<<"("<<pt[ipt]<<", "<<eta[ieta]<<")\t" <<xmin<<"-"<<xmax<<":" <<ymin<<"-"<<ymax<<":" <<"\t"; cout<<"("<<ipt<<", "<<ieta<<")\t" <<xminbin<<"-"<<xmaxbin<<":" <<yminbin<<"-"<<ymaxbin <<endl; */ in = histNum ->Integral(xminbin, xmaxbin, yminbin, ymaxbin); out = histDenom->Integral(xminbin, xmaxbin, yminbin, ymaxbin); //Cory: Deal with negative eta (Y axis) yminbin = histNum->GetYaxis()->FindBin(-1*ymax); ymaxbin = histNum->GetYaxis()->FindBin(-1*ymin)-1;//avoid overlap /* cout<<"("<<pt[ipt]<<", "<<eta[ieta]<<")\t" <<xmin<<"-"<<xmax<<":" <<ymin<<"-"<<ymax<<":" <<"\t"; cout<<"("<<ipt<<", "<<ieta<<")\t" <<xminbin<<"-"<<xmaxbin<<":" <<yminbin<<"-"<<ymaxbin <<endl; */ in += histNum ->Integral(xminbin, xmaxbin, yminbin, ymaxbin); out += histDenom->Integral(xminbin, xmaxbin, yminbin, ymaxbin); //cout<<"("<<pt[ipt]<<","<<eta[ieta]<<") "<<in<<"/"<<out<<endl; //cout<<"("<<(pt[ipt]+pt[ipt+1])/2<<","<<(eta[ieta]+eta[ieta+1])/2<<") "<<in<<"/"<<out<<endl; hFakeRateNum ->Fill( (pt[ipt]+pt[ipt+1])/2, (eta[ieta]+eta[ieta+1])/2, in); hFakeRateAll->Fill( (pt[ipt]+pt[ipt+1])/2, (eta[ieta]+eta[ieta+1])/2, out); } } } if(hFakeRateNum){ //TGraphAsymmErrors* hFakeRateEff = new TGraphAsymmErrors(hFakeRateNum->GetArray(), hFakeRateAll->GetArray(), ""); //TGraphAsymmErrors* hFakeRateEff = new TGraphAsymmErrors(hFakeRateNum, hFakeRateAll, ""); TH2F* hFakeRate = (TH2F*) hFakeRateNum->Clone("hFakeRate"); //hFakeRate->Divide(hFakeRateAll); //hFakeRate->Scale(100.); //make is a percent TCanvas c1; c1.SetLogx(1); //gStyle->SetTextFont(132); //gStyle->SetTextSize(1.2); hFakeRate->SetMarkerSize(3); //gStyle->SetPaintTextFormat("3.0f m"); gStyle->SetPaintTextFormat("4.0f"); hFakeRate->Draw("colz"); TLatex latexLabel; latexLabel.SetNDC(); latexLabel.SetTextSize(0.04); latexLabel.SetTextFont(42); latexLabel.SetTextAngle(90); latexLabel.SetTextAlign(22); for(int ybin = 1; ybin<= hFakeRate->GetYaxis()->GetNbins(); ++ybin){ int nx = hFakeRate->GetXaxis()->GetNbins(); TGraphAsymmErrors* gFakeRatePt = new TGraphAsymmErrors(nx); gFakeRatePt->SetMaximum(1.1); gFakeRatePt->SetMinimum(0.); gFakeRatePt->SetTitle((title + ";p_{T} (GeV);Rate").c_str()); for(int xbin = nx; xbin >= 1; --xbin){ float xcen = hFakeRate->GetXaxis()->GetBinCenter(xbin); float ycen = hFakeRate->GetYaxis()->GetBinCenter(ybin); double xpos, ypos; GetNDC(c1, xcen, ycen, xpos, ypos); int bin = hFakeRate->GetBin(xbin, ybin); float pass = hFakeRateNum->GetBinContent(bin); float tot = hFakeRateAll->GetBinContent(bin); float mean = tot>0 ? pass / tot : 0.; float errUp = TEfficiency::ClopperPearson(tot, pass, 0.68, true) - mean;//hFakeRateEff->GetErrorYhigh(bin-1); float errDown = mean - TEfficiency::ClopperPearson(tot, pass, 0.68, false);//hFakeRateEff->GetErrorYlow(bin-1); errDown = max(errDown, (float) 0.); hFakeRate->SetBinContent(bin, mean); //hFakeRate->SetBinError(bin, err); float err = (errUp + errDown)/2; printf("if(pt > %.0f) return Value(%.4f, %.4f); //pt %3.0f eta %.1f, bin %2i, (mean, err)= (%.4f, %.4f) (%.2f / %.2f) +%.4f -%.4f\n", hFakeRate->GetXaxis()->GetBinLowEdge(xbin), mean, err, hFakeRate->GetXaxis()->GetBinLowEdge(xbin), hFakeRate->GetYaxis()->GetBinLowEdge(ybin), bin, mean, err, pass, tot, errUp, errDown); if(xbin != 1) latexLabel.DrawLatex(xpos, ypos, Form("%.0f^{+%.0f}_{-%.0f}%% (%.0f/%.0f)(%.f-%.f)GeV",mean*100, errUp*100, errDown*100, pass, tot, pt[xbin-1],pt[xbin])); gFakeRatePt->SetPoint (xbin-1, xcen, mean); gFakeRatePt->SetPointEYhigh(xbin-1, errUp); gFakeRatePt->SetPointEYlow (xbin-1, errDown); gFakeRatePt->SetPointEXhigh(xbin-1, hFakeRate->GetXaxis()->GetBinLowEdge(xbin+1) - xcen); gFakeRatePt->SetPointEXlow (xbin-1, xcen - hFakeRate->GetXaxis()->GetBinLowEdge(xbin)); }//pt loop c1.Clear(); c1.SetLogx(1); //c1.SetGrid(); gFakeRatePt->Draw("ap*"); string outName = Form("WJetsFakeRatePt-Eta%.1fto%.1f-", hFakeRate->GetYaxis()->GetBinLowEdge(ybin), hFakeRate->GetYaxis()->GetBinLowEdge(ybin+1)); replace(outName.begin(), outName.end(), '.', 'p'); outName += useElectrons ? "Elec" : "Muon"; outName += useData ? "Data" : "MC"; outName += !useData && doSystematics ? "Sys" : ""; outName += doWLep ? "WLep" : "ZLep"; outName += ".pdf"; c1.Print(outName.c_str()); }//eta loop c1.Clear(); c1.SetLogx(1); string outName = "FakeRate"; outName += useElectrons ? "Elec" : "Muon"; outName += useData ? "Data" : "MC"; outName += !useData && doSystematics ? "Sys" : ""; outName += doWLep ? "WLep" : "ZLep"; outName += ".pdf"; c1.Print(outName.c_str()); //Now make profiles c1.Clear(); c1.SetLogx(0); //c1.SetGrid(); TH1D* hFakeRateNumEta = hFakeRateNum->ProjectionY("hFakeRateNumEta", 0, -1, "e"); TH1D* hFakeRateAllEta = hFakeRateAll->ProjectionY("hFakeRateAllEta", 0, -1, "e"); //TH1D* hFakeRateEta = (TH1D*) hFakeRateNumEta->Clone("hFakeRateEta"); int n = hFakeRateAllEta->GetXaxis()->GetNbins(); TGraphAsymmErrors* hFakeRateEta = new TGraphAsymmErrors(n);//hFakeRateNumEta, hFakeRateAllEta); hFakeRateEta->SetMaximum(1.); hFakeRateEta->SetMinimum(0.); hFakeRateEta->SetTitle((title + ";#eta;Rate").c_str()); //hFakeRateEta->SetMarkerStyle(21); for(int xbin = 1; xbin <= n; ++xbin){ float x = hFakeRateAllEta->GetXaxis()->GetBinCenter(xbin); float pass = hFakeRateNumEta->GetBinContent(xbin); float tot = hFakeRateAllEta->GetBinContent(xbin); float mean = tot>0 ? pass / tot : 0.; float errUp = TEfficiency::ClopperPearson(tot, pass, 0.68, true) - mean;//hFakeRateEff->GetErrorYhigh(bin-1); float errDown = mean - TEfficiency::ClopperPearson(tot, pass, 0.68, false);//hFakeRateEff->GetErrorYlow(bin-1); errDown = max(errDown, (float) 0.); hFakeRateEta->SetPoint (xbin, x, mean); hFakeRateEta->SetPointEYhigh(xbin, errUp); hFakeRateEta->SetPointEYlow (xbin, errDown); //printf("bin: %i, x=%.0f, %.0f/%.0f = %.0f +%.0f -%.0f\n", xbin, x, pass, tot, mean*100, errUp*100, errDown*100); } //hFakeRateEta->Divide(hFakeRateAllEta); //hFakeRateEta->Scale(100.); hFakeRateEta->Draw("ap*"); outName = "FakeRateEta"; outName += useElectrons ? "Elec" : "Muon"; outName += useData ? "Data" : "MC"; outName += !useData && doSystematics ? "Sys" : ""; outName += doWLep ? "WLep" : "ZLep"; outName += ".pdf"; c1.Print(outName.c_str()); //Pt projections (split these by eta?) c1.Clear(); c1.SetLogx(1); //c1.SetGrid(); TH1D* hFakeRateNumPt = hFakeRateNum->ProjectionX("hFakeRateNumPt", 0, -1, "e"); TH1D* hFakeRateAllPt = hFakeRateAll->ProjectionX("hFakeRateAllPt", 0, -1, "e"); //TH1D* hFakeRatePt = (TH1D*) hFakeRateNumPt->Clone("hFakeRatePt"); n = hFakeRateAllPt->GetXaxis()->GetNbins(); TGraphAsymmErrors* hFakeRatePt = new TGraphAsymmErrors(n);//hFakeRateNumPt, hFakeRateAllPt); hFakeRatePt->SetMaximum(1.); hFakeRatePt->SetMinimum(0.); hFakeRatePt->SetTitle((title + ";p_{T} (GeV);Rate").c_str()); for(int xbin = 1; xbin <= n; ++xbin){ float x = hFakeRateAllPt->GetXaxis()->GetBinCenter(xbin); float pass = hFakeRateNumPt->GetBinContent(xbin); float tot = hFakeRateAllPt->GetBinContent(xbin); float mean = tot>0 ? pass / tot : 0.; float errUp = TEfficiency::ClopperPearson(tot, pass, 0.68, true) - mean;//hFakeRateEff->GetErrorYhigh(bin-1); float errDown = mean - TEfficiency::ClopperPearson(tot, pass, 0.68, false);//hFakeRateEff->GetErrorYlow(bin-1); errDown = max(errDown, (float) 0.); hFakeRatePt->SetPoint (xbin, x, mean); hFakeRatePt->SetPointEYhigh(xbin, errUp); hFakeRatePt->SetPointEYlow (xbin, errDown); //cout<<"low edge is "<<hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin)<<" up edge is " // <<hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin+1)<<endl; hFakeRatePt->SetPointEXhigh(xbin, hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin+1) - x); hFakeRatePt->SetPointEXlow (xbin, x - hFakeRateAllPt->GetXaxis()->GetBinLowEdge(xbin)); printf("bin: %i, x=%.0f, %.0f/%.0f = %.0f +%.0f -%.0f\n", xbin, x, pass, tot, mean*100, errUp*100, errDown*100); } //hFakeRatePt->Divide(hFakeRateAllPt); //hFakeRatePt->Scale(100.); hFakeRatePt->Draw("ap*"); outName = "FakeRatePt"; outName += useElectrons ? "Elec" : "Muon"; outName += useData ? "Data" : "MC"; outName += !useData && doSystematics ? "Sys" : ""; outName += doWLep ? "WLep" : "ZLep"; outName += ".pdf"; c1.Print(outName.c_str()); } }
void ana_Run11_eff() { const int rebin = 1; TFile *f = TFile::Open("Rootfiles/Run11_eff.root","read"); // Run with weigth TH2F *hMcPtVsEta = (TH2F*)f->Get("mcJpsiPtY"); TH2F *hRcPtVsEta = (TH2F*)f->Get("hHt2JpsiPE"); draw2D(hMcPtVsEta); draw2D(hRcPtVsEta); hMcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6); TH1F *hMcPt = (TH1F*)hMcPtVsEta->ProjectionY("hMcPt"); hMcPt->Rebin(rebin); hMcPt->SetMarkerStyle(20); draw1D(hMcPt,"",kTRUE); hRcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6); TH1F *hRcPt = (TH1F*)hRcPtVsEta->ProjectionY("hRcPt"); hRcPt->Rebin(rebin); hRcPt->SetMarkerStyle(21); hRcPt->SetMarkerColor(2); hRcPt->SetLineColor(2); hRcPt->Draw("sames P"); TH1F *hRatio = (TH1F*)hRcPt->Clone("hRatio_fromRunning"); hRatio->Rebin(100); hMcPt->Rebin(100); hRatio->Divide(hMcPt); cEff = draw1D(hRatio,""); // Run without weight TH2F *hMcPtVsEtaNoWeight = (TH2F*)f->Get("mcJpsiPtY_Or"); draw2D(hMcPtVsEtaNoWeight); TH2F *hMcPtVsRcNoWeight = (TH2F*)f->Get("hJpsiRcvsMC_Cut1"); hMcPtVsRcNoWeight->RebinX(rebin); hMcPtVsRcNoWeight->RebinY(rebin); draw2D(hMcPtVsRcNoWeight); hMcPtVsEtaNoWeight->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6); TH1F *hMcPtNoWeight = (TH1F*)hMcPtVsEtaNoWeight->ProjectionY("hMcPtNoWeight"); hMcPtNoWeight->Rebin(rebin); hMcPtNoWeight->SetMarkerStyle(20); hMcPtNoWeight->SetMinimum(1); draw1D(hMcPtNoWeight,"",kTRUE); TH1F *hRcPtNoWeight = (TH1F*)hMcPtVsRcNoWeight->ProjectionX("hRcPtNoWeight"); hRcPtNoWeight->SetMarkerStyle(21); hRcPtNoWeight->SetMarkerColor(2); hRcPtNoWeight->SetLineColor(2); hRcPtNoWeight->Draw("sames P"); TH1F *hRatioNoWeight = (TH1F*)hRcPtNoWeight->Clone("hRatioNoWeight"); hRatioNoWeight->Divide(hMcPtNoWeight); cEff->cd(); hRatioNoWeight->SetMarkerColor(4); hRatioNoWeight->Draw("samesP"); // weight with input histogram TH1F *hMcPtWeight = (TH1F*)hMcPtNoWeight->Clone("hMcPtWeight"); TH2F *hMcPtVsRcWeight = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcWeight"); for(int ibin=1; ibin<=hMcPtVsRcNoWeight->GetNbinsX(); ibin++) { double scale = hMcPt->GetBinContent(ibin); hMcPtWeight->SetBinContent(ibin,hMcPtWeight->GetBinContent(ibin)*scale); hMcPtWeight->SetBinError(ibin,hMcPtWeight->GetBinError(ibin)*scale); for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++) { hMcPtVsRcWeight->SetBinContent(ibin,jbin,hMcPtVsRcWeight->GetBinContent(ibin,jbin)*scale); hMcPtVsRcWeight->SetBinError(ibin,jbin,hMcPtVsRcWeight->GetBinError(ibin,jbin)*scale); } } TH1F *hRcPtWeight = (TH1F*)hMcPtVsRcWeight->ProjectionY("hRcPtWeight"); hRcPtWeight->SetMarkerStyle(21); hRcPtWeight->SetMarkerColor(2); hRcPtWeight->SetLineColor(2); draw2D(hMcPtVsRcWeight); draw1D(hMcPtWeight,"",kTRUE); hRcPtWeight->Draw("sames P"); TH1F *hRatioWeight = (TH1F*)hRcPtWeight->Clone("hRatioWeight"); hRatioWeight->Divide(hMcPtWeight); cEff->cd(); hRatioWeight->SetMarkerColor(6); hRatioWeight->Draw("samesP"); TH1F *hCheck = (TH1F*)hRatioWeight->Clone("check"); hCheck->Divide(hRatio); draw1D(hCheck); // weight with fitted function TCanvas *c = new TCanvas("Fit","Fit",800,600); SetPadMargin(gPad,0.15,0.15); gPad->SetLogy(); TH1F *h = new TH1F("histogram",";;;",7,0,30); h->GetYaxis()->SetRangeUser(1e-7,100); h->Draw(); TFile *fdata = TFile::Open("Rootfiles/Spectrum_in_bin.root","read"); TGraphErrors *gr = (TGraphErrors*)fdata->Get("gall"); gr->SetMarkerColor(1); gr->SetLineColor(1); gr->GetXaxis()->SetRangeUser(0,30); gr->Draw("sames PE"); TF1 *func = new TF1("func",InvPt,0,30,4); func->SetParameters(0.4,-0.4796,4.229,-7.54); gr->Fit(func,"RL"); TH1F *hMcPtFunc = (TH1F*)hMcPtNoWeight->Clone("hMcPtFunc"); TH2F *hMcPtVsRcFunc = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcFunc"); for(int ibin=1; ibin<=hMcPtVsRcFunc->GetNbinsX(); ibin++) { double scale = func->Eval(hMcPtFunc->GetBinCenter(ibin)); hMcPtFunc->SetBinContent(ibin,hMcPtFunc->GetBinContent(ibin)*scale); hMcPtFunc->SetBinError(ibin,hMcPtFunc->GetBinError(ibin)*scale); for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++) { hMcPtVsRcFunc->SetBinContent(ibin,jbin,hMcPtVsRcFunc->GetBinContent(ibin,jbin)*scale); hMcPtVsRcFunc->SetBinError(ibin,jbin,hMcPtVsRcFunc->GetBinError(ibin,jbin)*scale); } } TH1F *hRcPtFunc = (TH1F*)hMcPtVsRcFunc->ProjectionY("hRcPtFunc"); hRcPtFunc->SetMarkerStyle(21); hRcPtFunc->SetMarkerColor(2); hRcPtFunc->SetLineColor(2); hMcPtVsRcFunc->GetZaxis()->SetRangeUser(1e-4,1e2); draw2D(hMcPtVsRcFunc); hMcPtFunc->GetYaxis()->SetRangeUser(1e-4,5e4); draw1D(hMcPtFunc,"",kTRUE); hRcPtFunc->Draw("sames P"); TH1F *hRatioFunc = (TH1F*)hRcPtFunc->Clone("hRatioFunc"); hRatioFunc->Rebin(100); hMcPtFunc->Rebin(100); hRatioFunc->Divide(hMcPtFunc); cEff->cd(); hRatioFunc->SetMarkerColor(5); hRatioFunc->Draw("samesP"); TH1F *hCheck2 = (TH1F*)hRatioFunc->Clone("check2"); hCheck2->Divide(hRatio); draw1D(hCheck2); }
void Optimize2D(TString signal, TString background, TString histname, int minxwidth = 2, int minywidth = 2, float minsigeff=0.5){ TFile *sigfile = TFile::Open(signal); TFile *bkgfile = TFile::Open(background); TH2F *sighist = (TH2F*)sigfile->Get(histname); TH2F *bkghist = (TH2F*)bkgfile->Get(histname); int nxbins = sighist->GetNbinsX(); int nybins = sighist->GetNbinsY(); if ( nxbins != bkghist->GetNbinsX() || nybins != bkghist->GetNbinsY() ) { cout << "Error! The two input histograms do not have the same number of bins!" << endl; return; } int nsigtot = sighist->Integral(1,nxbins,1,nybins); int nbkgtot = bkghist->Integral(1,nxbins,1,nybins); cout << "Total number of entries in the signal histogram: " << nsigtot << endl; cout << "Total number of entries in the bkgrnd histogram: " << nbkgtot << endl; if ( nsigtot==0 || nbkgtot==0 ) { cout << "Error! At least one of the input histograms is empty!" << endl; return; } TH1D *projx = sighist->ProjectionX("projx"); TH1D *projy = sighist->ProjectionY("projy"); float bestsob = (float)nsigtot / nbkgtot; cout << "Starting with a \"no-cuts\" s/b of " << bestsob << endl; float x1=0, y1=0, x2=0, y2=0; // corner coordinates for the window for (int i=1; i<=nxbins; ++i) for (int j=minxwidth-1; i+j<=nxbins; ++j) for (int k=1; k<=nybins; ++k) for (int l=minywidth-1; k+l<=nybins; ++l) { int nsig = sighist->Integral(i, i+j, k, k+l); if ( nsig == 0 ) continue; if ( nsig < nsigtot*minsigeff ) continue; int nbkg = bkghist->Integral(i, i+j, k, k+l); if ( nbkg == 0 ) continue; float sob = (float)nsig / nbkg; if ( (float)nsig / nbkg > bestsob ) { bestsob = sob; x1 = projx->GetBinLowEdge(i); x2 = projx->GetBinLowEdge(i+j+1); y1 = projy->GetBinLowEdge(k); y2 = projy->GetBinLowEdge(k+l+1); cout << "x-range " << i << " (" << x1 << ") to " << i+j << " (" << x2 << ") ; \t y-range " << k << " (" << y1 <<") to " << k+l << " (" << y2 << ") ; \t signal= " << nsig << " bkgrnd= " << nbkg << " s/b= " << sob << endl; } } TCanvas *cnv = TCanvas::MakeDefCanvas(); cnv->Divide(2); TBox *box = new TBox(x1, y1, x2, y2); box->SetFillStyle(0); box->SetLineColor(2); box->SetLineWidth(2); cnv->cd(1); sighist->Draw("colbox"); box->Draw(); cnv->cd(2); bkghist->Draw("colbox"); box->Draw(); cnv->SaveAs("Optimize2D"+histname+".eps"); }
void DrawPerform(){ gStyle->SetErrorX(0); TFile *fmb = new TFile("merged.root","ReadOnly"); TFile *fhm = new TFile("merged_FVtx.root","ReadOnly"); const int ncav = 26; TCanvas *c1[ncav]; for(int i=0;i<ncav;i++){ c1[i] = new TCanvas(); } //Tracks TH2F *hcntetaphi = (TH2F*)fmb->Get("hcntetaphi"); c1[0]->cd(); hcntetaphi->Draw("colz"); c1[0]->Print("fig/hcntetaphi.png"); TH1F *hcntpt = (TH1F*)fmb->Get("hcntpt"); TH1F *hcntpt_hm = (TH1F*)fhm->Get("hcntpt"); c1[1]->cd(); c1[1]->SetLogy(); hcntpt->Rebin(4); hcntpt_hm->Rebin(4); SetStyle(*hcntpt,1.2,1,20,0,0); SetStyle(*hcntpt_hm,1.2,2,24,0,0); hcntpt->Draw("P"); hcntpt_hm->Draw("Psame"); c1[1]->Print("fig/hcntpt.png"); TH2F* pc3dphidz = (TH2F*)fmb->Get("pc3dphidz"); TH1F* pc3dphi = (TH1F*)pc3dphidz->ProjectionX("pc3dphi",0,-1); TH1F* pc3dz = (TH1F*)pc3dphidz->ProjectionY("pc3dz",0,-1); c1[2]->cd(); SetStyle(*pc3dphi,1.2,1,20,0,0); pc3dphi->Draw("P"); c1[2]->Print("fig/pc3dphi.png"); c1[3]->cd(); SetStyle(*pc3dz,1.2,1,20,0,0); pc3dz->Rebin(4); pc3dz->Draw("P"); c1[3]->Print("fig/pc3dz.png"); TH2F* hntracknmpc = (TH2F*)fmb->Get("hntracknmpc"); TH2F* hntracknmpc_hm = (TH2F*)fhm->Get("hntracknmpc"); TH1F* hntrack = (TH1F*)hntracknmpc->ProjectionX("hntrack",0,-1); TH1F* hntrack_hm = (TH1F*)hntracknmpc_hm->ProjectionX("hntrack_hm",0,-1); c1[4]->cd(); c1[4]->SetLogy(); hntrack->Scale(1./hntrack->Integral()); hntrack_hm->Scale(1./hntrack_hm->Integral()); SetStyle(*hntrack,1.2,1,20,0,0); SetStyle(*hntrack_hm,1.2,2,24,0,0); SetRange(*hntrack,0,1e-11,20,10); hntrack->Draw(); hntrack_hm->Draw("Psame"); c1[4]->Print("fig/ntrack.png"); /* //tof TH2F* tofdphidz = (TH2F*)f->Get("tofdphidz"); TH1F* tofdphi = (TH1F*)tofdphidz->ProjectionX("tofdphi",0,-1); TH1F* tofdz = (TH1F*)tofdphidz->ProjectionY("tofdz",0,-1); c1[4]->cd(); tofdphi->Draw(); c1[4]->Print("fig/tofdphi.png"); c1[5]->cd(); tofdz->Draw(); c1[5]->Print("fig/tofdz.png"); TH2F* tofwdphidz = (TH2F*)f->Get("tofwdphidz"); TH2F* ttofqpratio = (TH2F*)f->Get("ttofqpratio"); c1[6]->cd(); ttofqpratio->Draw("colz"); c1[6]->Print("fig/ttofqpratio.png"); TH2F* m2qpratio = (TH2F*)f->Get("m2qpratio"); //vtx TH2F* hcluetaphi[4]; c1[7]->Divide(2,2); for(int i=0;i<4;i++){ hcluetaphi[i] = (TH2F*)f->Get(Form("hcluetaphi_%d",i)); c1[7]->cd(i+1); hcluetaphi[i]->Draw("colz"); TLatex t; t.SetNDC(); t.DrawLatex(0.1,0.8,Form("layer %d",i)); } c1[7]->Print("fig/hcluetaphi.png"); //bbc TH1F* bbcet = (TH1F*)f->Get("bbcet"); c1[8]->cd(); c1[8]->SetLogy(); bbcet->Draw(); c1[8]->Print("fig/bbcet.png"); //fvtx TH2D *DCAxydis[2]; TH2D *DCAxy2dis[2]; TH2D *DCAcentdis[2]; c1[9]->Divide(1,2); c1[10]->Divide(1,2); c1[11]->Divide(1,2); for(int iarm=0;iarm<2;iarm++){ DCAxydis[iarm] = (TH2D*)f->Get(Form("DCAxydis_%d",iarm)); DCAxy2dis[iarm] = (TH2D*)f->Get(Form("DCAxy2dis_%d",iarm)); DCAcentdis[iarm] = (TH2D*)f->Get(Form("DCAcentdis_%d",iarm)); c1[9]->cd(iarm+1); c1[9]->SetLogz(); DCAxydis[iarm]->Draw("colz"); c1[10]->cd(iarm+1); c1[10]->SetLogz(); DCAxy2dis[iarm]->Draw("colz"); c1[11]->cd(iarm+1); c1[11]->SetLogz(); DCAcentdis[iarm]->Draw("colz"); } c1[9]->Print("fig/DCAxydis.png"); c1[10]->Print("fig/DCAxy2dis.png"); c1[11]->Print("fig/DCAcentdis.png"); // TH1F *fvtxdphidis; // TH1F *fvtxdphidis2; c1[12]->Divide(1,2); TH2D *hvtx0etaz = (TH2D*) f->Get("hvtx0etaz"); TH2D *hvtx1etaz = (TH2D*) f->Get("hvtx1etaz"); c1[12]->cd(1); hvtx0etaz->Draw("colz"); c1[12]->cd(2); hvtx1etaz->Draw("colz"); c1[12]->Print("fig/hvtxetaz.png"); c1[13]->Divide(1,2); TH2D *hvtx0etaphi = (TH2D*)f->Get("hvtx0etaphi");; TH2D *hvtx1etaphi = (TH2D*)f->Get("hvtx1etaphi");; c1[13]->cd(1); hvtx0etaphi->Draw("colz"); c1[13]->cd(2); hvtx1etaphi->Draw("colz"); c1[13]->Print("fig/hvtxetaphi.png"); //mpc TH2F* mpcetdis; TH2F* mpcetetasouth[1]; TH2F* mpcetetanorth[1]; TH2F* mpc_south_cent; TH2F* mpc_north_cent; TH2F* mpc_south_north; TH2F *south_mpc_north_mpc; //correlate TH2F* hvtxzfvtxz = (TH2F*)f->Get("hvtxzfvtxz"); c1[14]->cd(); c1[14]->SetLogz(); hvtxzfvtxz->Draw("colz"); c1[14]->Print("fig/hvtxzfvtxz.png"); TH2F* hpc1hitsbbc = (TH2F*)f->Get("hpc1hitsbbc"); TH1F* hpc1hits = (TH1F*)hpc1hitsbbc->ProjectionX("hpc1hits",0,-1); c1[15]->cd(); c1[15]->SetLogy(); hpc1hits->Draw(); c1[15]->Print("fig/hpc1hits.png"); TH1F* hbbc = (TH1F*)hpc1hitsbbc->ProjectionY("hbbc",0,-1); c1[16]->cd(); c1[16]->SetLogy(); hbbc->Draw(); c1[16]->Print("fig/hbbc.png"); TH2F* hnpc3hitsntof = (TH2F*)f->Get("hnpc3hitsntof"); TH1F* hnpc3hits = (TH1F*)hnpc3hitsntof->ProjectionX("hnpc3hits",0,-1); c1[17]->cd(); c1[17]->SetLogy(); hnpc3hits->Draw(); c1[17]->Print("fig/hnpc3hits.png"); TH1F* hntof = (TH1F*)hnpc3hitsntof->ProjectionY("hntof",0,-1); c1[18]->cd(); c1[18]->SetLogy(); hntof->Draw(); c1[18]->Print("fig/hntof.png"); TH2F* hbbcnbbc = (TH2F*)f->Get("hbbcnbbc"); c1[19]->cd(); c1[19]->SetLogz(); hbbcnbbc->Draw("colz"); c1[19]->Print("fig/hbbcnbbc.png"); TH2F* hbbcsbbcn = (TH2F*)f->Get("hbbcsbbcn"); c1[20]->cd(); c1[20]->SetLogz(); hbbcsbbcn->Draw("colz"); c1[20]->Print("fig/hbbcsbbcn.png"); */ TH2F* hnvtxnfvtxtrk[4]; TH2F* hbbcsnvtx[4]; TH2F* hbbcnnvtx[4]; TH2F* hbbcnvtx[4]; TH2F* hbbcnvtx_hm[4]; c1[21]->Divide(2,2); for(int i=0;i<4;i++){ hnvtxnfvtxtrk[i] = (TH2F*)fmb->Get(Form("hnvtxnfvtxtrk_%d",i)); hbbcsnvtx[i] = (TH2F*)fmb->Get(Form("hbbcsnvtx_%d",i)); hbbcnnvtx[i] = (TH2F*)fmb->Get(Form("hbbcnvtx_%d",i)); hbbcnvtx[i] = (TH2F*)fmb->Get(Form("hbbcnvtx_%d",i)); hbbcnvtx_hm[i] = (TH2F*)fhm->Get(Form("hbbcnvtx_%d",i)); c1[21]->cd(i+1); c1[21]->SetLogz(); hnvtxnfvtxtrk[i]->Draw("colz"); TLatex t; t.SetNDC(); t.DrawLatex(0.1,0.8,Form("layer %d",i)); } c1[21]->Print("fig/hnvtxnfvtxtrk.png"); TH1F* hnvtx = (TH1F*)hbbcnvtx[0]->ProjectionY("hnvtx",0,-1); TH1F* hnvtx_hm = (TH1F*)hbbcnvtx_hm[0]->ProjectionY("hnvtx_hm",0,-1); TH1F* hbbc = (TH1F*)hbbcnvtx[0]->ProjectionX("hbbc",0,-1); TH1F* hbbc_hm = (TH1F*)hbbcnvtx_hm[0]->ProjectionX("hbbc_hm",0,-1); c1[22]->cd(); c1[22]->SetLogy(); hnvtx->Rebin(4); hnvtx_hm->Rebin(4); hnvtx->Scale(1./hnvtx->Integral()); hnvtx_hm->Scale(1./hnvtx_hm->Integral()); SetRange(*hnvtx,0,1e-11,200,10); SetTitle(*hnvtx,"#hits in cluster layer 1","normalized",""); SetStyle(*hnvtx,1.2,1,20,0,0); SetStyle(*hnvtx_hm,1.2,2,24,0,0); hnvtx->Draw("P"); hnvtx_hm->Draw("Psame"); c1[22]->Print("fig/hnvtx.png"); c1[23]->cd(); c1[23]->SetLogy(); SetTitle(*hbbc,"bbc charge sum","normalized",""); hbbc->Rebin(5); hbbc_hm->Rebin(5); hbbc->Scale(1./hbbc->Integral()); hbbc_hm->Scale(1./hbbc_hm->Integral()); SetRange(*hbbc,0,1e-11,200,10); SetStyle(*hbbc,1.2,1,20,0,0); SetStyle(*hbbc_hm,1.2,2,24,0,0); hbbc->Draw("P"); hbbc_hm->Draw("Psame"); c1[23]->Print("fig/hbbc.png"); c1[24]->cd(); c1[24]->SetLogz(); SetTitle(*hbbcnvtx_hm[0],"bbc charge sum","#hits in cluster layer 1",""); hbbcnvtx_hm[0]->Draw("colz"); c1[24]->Print("fig/hbbcnvtx_hm.png"); /* TH2F* hnbbcnclu = (TH2F*)f->Get("hnbbcnclu"); TH1F* hnbbc = (TH1F*)hnbbcnclu->ProjectionX("hnbbc",0,-1); TH1F* hnclu = (TH1F*)hnbbcnclu->ProjectionY("hnclu",0,-1); c1[23]->cd(); c1[23]->SetLogy(); hnbbc->Draw(); c1[23]->Print("fig/hnbbc.png"); c1[24]->cd(); c1[24]->SetLogy(); hnclu->Draw(); c1[24]->Print("fig/hnclu.png"); TH2F *hnfvtxtrkbbc = (TH2F*)f->Get("hnfvtxtrkbbc"); c1[25]->cd(); c1[25]->SetLogz(); hnfvtxtrkbbc->Draw("colz"); c1[25]->Print("fig/hnfvtxtrkbbc.png"); TH2F *hnfvtxtrksnmpcs = (TH2F*)f->Get("hnfvtxtrksnmpcs"); TH2F *hnfvtxtrknnmpcn = (TH2F*)f->Get("hnfvtxtrknnmpcn"); TH2F *south_mpc_south_bbc; TH2F *north_mpc_north_bbc; */ }
void Getvn(){ TString str; TFile *fin; int nrun = GetTotalRun(); if(nrun<0) exit("Empty run list file!"); ofstream fout, fout1, fout2; int iharE=0; if(nhar==1) iharE=1; 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; if(isub==1) str = "FVTX1S"; else if(isub==2) str = "FVTX2S"; else continue; fout1.open(Form("Run15pAu200MinBias/res%d_%d_%s.dat",n,icent,str.Data())); //using str as event plane detector fout2.open(Form("Run15pAu200MinBias/psi%d_%d_%s.dat",n,icent,str.Data())); //using str as event plane detector float reso = 1.;//GetReso(icent,ihar,isub); fout1<<reso<<endl; TH2F* hvobs = new TH2F(Form("hvobs_%d_%d_%d",icent,ihar,isub),Form("hvobs_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); TH2F* hvobssq = new TH2F(Form("hvobssq_%d_%d_%d",icent,ihar,isub),Form("hvobssq_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); for(int irun=0;irun<nrun;irun++){ fout2<<GetRun(irun)<<" "<<GoodRun(icent,ihar,isub,irun)<<endl; } for(int iphi=0;iphi<nphi;iphi++){ string phistr = (iphi==0)?"east":"west"; fout.open(Form("Run15pAu200MinBias/v%d_%d_%s_%s.dat",n,icent,phistr.c_str(),str.Data())); //using str as event plane detector for(int irun=0;irun<nrun;irun++){ // cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<endl; fin = TFile::Open(Form("Run15pAu200MinBias/output_fvtxwithcntEP_%d.root",GetRun(irun))); if(!(GoodRun(icent,ihar,isub,irun)>0.2 && GoodRun(icent,ihar,isub,irun)<3.0)){ cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<endl; continue; } TH2F* hvobstemp = (TH2F*)fin->Get(Form("vobs%s_%d_%d_%d",str.Data(),icent,ihar,iphi)); TH2F* hvobssqtemp = (TH2F*)fin->Get(Form("vobs%ssq_%d_%d_%d",str.Data(),icent,ihar,iphi)); hvobs->Add(hvobstemp); hvobssq->Add(hvobssqtemp); fin->Close(); } TH1F* ptProj = (TH1F*)hvobs->ProjectionX(Form("hptProj"),0,-1); for(int ipt=0;ipt<npt-1;ipt++){ TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),hvobs->GetXaxis()->FindBin(ptbin[ipt]),hvobs->GetXaxis()->FindBin(ptbin[ipt+1])); TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),hvobs->GetXaxis()->FindBin(ptbin[ipt]),hvobs->GetXaxis()->FindBin(ptbin[ipt+1])); float vobs = hvobsProj->GetMean(); float Ntracks = hvobsProj->GetEntries(); float vobssq = hvobsProj->GetMean(); float v = vobs/reso; float verr = sqrt(vobssq/reso/reso-(v*v))/sqrt(Ntracks); ptProj->GetXaxis()->SetRangeUser(ptbin[ipt],ptbin[ipt+1]); float pt = ptProj->GetMean(); fout<<pt<<" "<<v<<" "<<" "<<verr<<endl; } fout.close(); } fout1.close(); fout2.close(); } } } }
void Getvn2D(bool usingCNTEP=0){ TString str; TFile *fin; 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||nhar==2) iharE=1; for(int icent=0;icent<ncent;icent++){ for(int ihar=0;ihar<nhar;ihar++){ if(icent!=0) continue; 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; cout<<Form("Result/%s/res%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())<<endl; fout1.open(Form("Result/%s/res%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())); //using str as event plane detector fout2.open(Form("Result/%s/psi%d_%d_%s.dat",UseCNTEP.Data(),n,icent,str.Data())); //using str as event plane detector float reso = GetReso(icent,ihar,isub,usingCNTEP); fout1<<reso<<std::endl; if(reso<0) {std::cout<<"resolution is wrong!"<<std::endl; reso = -9999;} for(int irun=0;irun<nrun;irun++){ fout2<<GetRun(irun)<<" "<<GoodRunFit[icent][ihar][isub][irun]<<std::endl; } TH2F* hvobsall = new TH2F(Form("hvobs_%d_%d_%d",icent,ihar,isub),Form("hvobs_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); // TH2F* hvobsallsq = new TH2F(Form("hvobssq_%d_%d_%d",icent,ihar,isub),Form("hvobssq_%d_%d_%d",icent,ihar,isub),60,0,6,220,-1.1,1.1); for(int iphi=0;iphi<nphi+1;iphi++){ TH2F* hvobs = new TH2F(Form("hvobs_%d_%d_%d_%d",icent,ihar,isub,iphi),Form("hvobs_%d_%d_%d_%d",icent,ihar,isub,iphi),60,0,6,220,-1.1,1.1); // TH2F* hvobssq = new TH2F(Form("hvobssq_%d_%d_%d_%d",icent,ihar,isub,iphi),Form("hvobssq_%d_%d_%d_%d",icent,ihar,isub,iphi),60,0,6,220,-1.1,1.1); string phistr = (iphi==0)?"_east":"_west"; if(iphi==nphi) phistr = ""; cout<<"open v2 file"<<endl; fout.open(Form("Result/%s/v%d_%d%s_%s.dat",UseCNTEP.Data(),n,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%s_%s.dat",UseCNTEP.Data(),n,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())); //fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/output/%s",GetRun(irun).Data())); fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/39GeV/treeout/%s",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; } TH2F* hvobstemp = (TH2F*)fin->Get(Form("vobs%s_0_0_%d_%d_%d",str.Data(),icent,ihar,iphi)); //TH2F* hvobssqtemp = (TH2F*)fin->Get(Form("vobs%ssq_%d_%d_%d",str.Data(),icent,ihar,iphi)); hvobs->Add(hvobstemp); //hvobssq->Add(hvobssqtemp); fin->Close(); } } hvobsall->Add(hvobs); //hvobsallsq->Add(hvobssq); if(iphi==nphi){ hvobs = hvobsall; //hvobssq = hvobsallsq; } TH1F* ptProj = (TH1F*)hvobs->ProjectionX(Form("hptProj"),0,-1); 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 vobs = hvobsProj->GetMean(); float Ntracks = hvobsProj->Integral(); // float vobssq = hvobssqProj->GetMean(); float v = vobs/reso; if(Ntracks>0) float verr = hvobsProj->GetRMS()/reso/sqrt(Ntracks); else verr = -9999; // float verr = sqrt(vobssq/reso/reso-(v*v))/sqrt(Ntracks); ptProj->GetXaxis()->SetRangeUser(ptbin[ipt]+eps,ptbin[ipt+1]-eps); float pt = ptProj->GetMean(); fout<<pt<<" "<<v<<" "<<verr<<" "<<std::endl; foutraw<<pt<<" "<<vobs<<" "<<verr*reso<<" "<<std::endl; } fout.close(); foutraw.close(); } fout1.close(); fout2.close(); } } } }
void DrawdNdeta(){ gStyle->SetOptStat(kTRUE); TFile *f = TFile::Open("mergedouthisto_pAu.root"); //TFile *f = TFile::Open("outhisto.root"); TString coll = "pAu"; TH1F* hKF = (TH1F*)f->Get("hKF"); TH1F* hy = (TH1F*)f->Get("hy"); TH1F* hy1 = (TH1F*)f->Get("hy1"); TH1F* heta = (TH1F*)f->Get("heta"); TH1F* hMass = (TH1F*)f->Get("hMass"); TH1F* hn = (TH1F*)f->Get("hn"); TH1F* hnch = (TH1F*)f->Get("hnch"); TH1F* hphi = (TH1F*)f->Get("hphi"); TH2F* hpteta = (TH2F*)f->Get("hpteta"); TH1F* hpt = (TH1F*)hpteta->ProjectionX(); TCanvas *c1 = new TCanvas("c1"); hy->GetXaxis()->SetTitle("y"); hy->GetYaxis()->SetTitle("# of particles"); hy->Draw(); TLatex t; t.SetNDC(); // t.DrawLatex(0.1,0.4,Form("#pi_{0}=%d, #pi^{#pm}=%d,K^{#pm}=%d",18308,32043,3714)); // t.DrawLatex(0.1,0.3,Form("#pi_{0}/#pi^{#pm}=%.2f,K^{#pm}/#pi^{#pm}=%.2f",18308./32043,3714./32043)); c1->Print(Form("fig/%s_hy.png",coll.Data())); TCanvas *c2 = new TCanvas("c2"); c2->cd(); hy1->GetXaxis()->SetTitle("y"); hy1->GetYaxis()->SetTitle("# of particles"); hy1->Draw(); // t.DrawLatex(0.1,0.4,Form("#pi_{0}=%d, #pi_{#pm}=%d,K^{#pm}=%d",11676,20281,2530)); // t.DrawLatex(0.1,0.3,Form("#pi_{0}/#pi_{#pm}=%.2f,K^{#pm}/#pi^{#pm}=%.2f",11676./20281,2530./20281)); c2->Print(Form("fig/%s_hy1.png",coll.Data())); TCanvas *c3 = new TCanvas("c3"); c3->SetLogy(); hKF->GetXaxis()->SetTitle("particle id"); hKF->GetYaxis()->SetTitle("# of particles"); hKF->Draw(); c3->Print(Form("fig/%s_pid.png",coll.Data())); TCanvas *c4 = new TCanvas("c4"); heta->GetXaxis()->SetTitle("#eta"); heta->GetYaxis()->SetTitle("# of particles"); heta->Draw(); c4->Print(Form("fig/%s_eta.png",coll.Data())); TCanvas *c5 = new TCanvas("c5"); hMass->GetXaxis()->SetTitle("mass(GeV)"); hMass->GetYaxis()->SetTitle("# of particles"); hMass->Draw(); c5->Print(Form("fig/%s_mass.png",coll.Data())); TCanvas *c6 = new TCanvas("c6"); c6->SetLogy(); hn->GetXaxis()->SetTitle("N"); hn->GetYaxis()->SetTitle("# of events"); hn->Draw(); c6->Print(Form("fig/%s_N.png",coll.Data())); TCanvas *c7 = new TCanvas("c7"); c7->SetLogy(); hnch->GetXaxis()->SetTitle("N_{ch}"); hnch->GetYaxis()->SetTitle("# of events"); hnch->Draw(); c7->Print(Form("fig/%s_Nch.png",coll.Data())); TCanvas *c8 = new TCanvas("c8"); c8->SetLogy(); hpt->GetXaxis()->SetTitle("particle p_{T}(GeV/c)"); hpt->GetYaxis()->SetTitle("# of particles"); hpt->Draw(); c8->Print(Form("fig/%s_pt.png",coll.Data())); TCanvas *c9 = new TCanvas("c9"); hphi->GetXaxis()->SetRangeUser(0,6.2); hphi->GetYaxis()->SetRangeUser(0,6.2); hphi->GetXaxis()->SetTitle("#phi"); hphi->GetYaxis()->SetTitle("# of particles"); hphi->Draw(); c9->Print(Form("fig/%s_phi.png",coll.Data())); }
void makeCorrections(int typeData = 0, int hyp=1 , int niter=0 , int acc = 5 , double E = 0.9 , int typeMC = 0 , int iTr = 1 , int syst = 0 , int syst_sign = 0 , bool doPTcorr = true , double Emc = 0 , TString filename = "" , int scaleWbin0 = true , bool drawcanv = true , float mu = 14 , float sigma = 15 ){ if(typeMC==0){ typeMC = 10; if(E == 7.0) typeMC = 31; } //gROOT->ProcessLine(".x ../macro/BuildLibDico.C+"); useData = true; doptcorr = doPTcorr; if(Emc==0) Emc = E; double syst_val = 0; if(syst==0) syst_sign=0; #include "../macro/acceptanceMap.C" TString filedir("../plots/simpleana_current/"); //TString addstr("binning1"); TString addstr(""); if(syst==201) addstr = "evtSelSyst"; if(syst==600) addstr = "nsigma5"; //addstr = filename; TFile* mctmp = NULL; //Get the MC file TString mcfile = fileManager(2,typeMC,Emc,iTr,0,0,addstr,filedir); TFile* mc = TFile::Open(mcfile,"READ");//"newbinning","../plots/unfoldingv2/" cout<<"MC input file : "<<mcfile<<endl; //#include "syst_MCfile.C" //Get the data file TString datafile = fileManager(2,typeData,E,iTr,0,0,addstr,filedir); TFile* data = TFile::Open(datafile,"READ"); cout<<"Data input file : "<<datafile<<endl; //Checking if both files exist if(mc == 0){ cout<<"The MC input file doesn't exist ..."<<endl; } if(data == 0){ cout<<"The Data input file doesn't exist ..."<<endl; } if(mc == 0 || data == 0) return; ostringstream dirstr(""); dirstr << "/ptGen" << accMap.at(acc).at(0) << "_etaGen" << accMap.at(acc).at(1) << "_ptReco" << accMap.at(acc).at(2) << "_etaReco" << accMap.at(acc).at(3) ; if(accMap.at(acc).at(4)==-1) dirstr << "_chargemin"; else if(accMap.at(acc).at(4)==1) dirstr << "_chargeplus"; dirstr << "/"; TString dir = dirstr.str(); //cout<<dir<<endl; //return; //------------------------------------------------------------ //Don't even create the output file if can't do the systematic. if(syst%100==typeMC){ cout<<"!! WARNING : this is not a systematic, the MC tune for the SD distri is the same as for the rest. Exiting now ..."<<endl; return; } if( (getNIter(acc,E)-(syst%300)) < 1 && int(syst/100) == 3 && syst_sign == -1){ cout<<"!! WARNING : can't do the negative systematic, niter is already 1. Exiting now ..."<<endl; return; } if((syst==401 ||syst==402 || syst==403) && E==7.0){ cout<<"!! WARNING : can't do this systematic, don't have the right energy mc. Exiting now ..."<<endl; return; } if(syst%400==typeMC){ cout<<"!! WARNING : this is not a systematic, the MC tune for the matrix is the same as for the rest. Exiting now ..."<<endl; return; } //------------------------------------------------------------ //Opening the output file ostringstream outstr(""); outstr << "hyp" << hyp << "_niter" << niter << "_cut" << acc << "_DataType" << typeData; if(E!=Emc) outstr << "_Emc"<<Emc; if(!doptcorr) outstr<<"_noPtCorr"; if(filename!="") outstr << "__" << filename; cout<<"Output file : "<<fileManager(3,typeMC,E,iTr,syst,syst_sign,outstr.str())<<endl; TFile* out = new TFile(fileManager(3,typeMC,E,iTr,syst,syst_sign,outstr.str()),"RECREATE"); out->cd(); TDirectory* currentdir = gDirectory; //Getting the good #iter if adaptive. //BEWARE : needs to be after output file naming/creation. if(niter==0){ niter = getNIter(acc,E); cout<<"Will use "<<niter<<" iterations for the unfolding ..."<<endl; } //including the systematic on #iterations #include "syst_niter.C" //------------------------------------------------------------------------------ //---------------------------- UNFOLDING --------------------------------------- //------------------------------------------------------------------------------ gDirectory->mkdir("unfolding"); gDirectory->cd("unfolding"); //Get the Unfolding matrix //TFile* mc_matrix = new TFile(fileManager(2,type,0.9,iTr),"READ"); //TH2F* matrixhist = (TH2F*) mc_matrix->Get(dir+st("MatrixPlots_evtSel",acc)+st("/nch_matrix_evtSel",acc)); TH2F* matrixhist = (TH2F*) mc->Get(dir+st("MatrixPlots_evtSel",acc)+st("/nch_matrix_evtSel",acc)); #include "syst_matrix.C" //if(matrixhist==0)cout<<dir+st("MatrixPlots_evtSel",acc)+st("/nch_matrix_evtSel",acc)<<endl; matrixhist->SetName("nch_matrix"); /*for(int i=1;i<=matrixhist->GetNbinsX();++i){ matrixhist->SetBinContent(i,1,0); //matrixhist->SetBinContent(1,i,0); }*/ //Setting the limits from the matrix Ngen1 = matrixhist->GetNbinsX(); Nreco1 = matrixhist->GetNbinsX(); if(drawcanv){ TCanvas* cm = new TCanvas("cm","c",2500,10,500,500); cm->cd(); matrixhist->Draw("colz"); //gPad->WaitPrimitive(); } //Transform the TH2F into an array matrix4dObj matrix; transform2Matrix(matrixhist,matrix); //get the true nch distribution (from MC) //TH1F* nch_trueGen = (TH1F*) mc->Get("GenMultiPlots_etaCut/MultiPlots_NSD_etaCut/nch_NSD_etaCut"); TH1F* nch_trueGen_afterUnfolding = (TH1F*) mc->Get(dir+st("MatrixPlots_evtSel",acc)+st("/nch_gen_evtSel",acc)); nch_trueGen_afterUnfolding->SetName("nch_MC_gen_afterUnfolding"); //TH1F* nch_trueGen = (TH1F*) mc->Get("MatrixPlots_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx/nch_gen_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx"); TH1F* nch_trueGen = (TH1F*) mc->Get(dir+st("MultiPlots_etaCut_noSel_NSD_gen",acc)+st("/nch_etaCut_noSel_NSD_gen",acc)); nch_trueGen->SetName("nch_MC_gen_afterEvtSelCorrection"); //nch_trueGen->Scale(1./nch_trueGen->GetEntries()); //nch_trueGen->Draw(); //gPad->WaitPrimitive(); //get the nch to Unfold distribution TH1F* nch_INC; if(!useData) //nch_INC = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_INC_evtSel_reco",acc)+st("/nch_INC_evtSel_reco",acc)); nch_INC = (TH1F*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/nch_evtSel_INC_reco",acc)); else nch_INC = (TH1F*) data->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/nch_evtSel_INC_reco",acc)); //nch_INC = (TH1F*) data->Get(dir+st("MultiPlots_evtSel_PV",acc)+st("/nch_evtSel_PV",acc)); nch_INC->SetName("nch_data_INC_beforeSDsub"); //nch_INC->SetBinContent(1,0); //insertion of systematic code: #include "syst_tracking.C" //Getting the class MultiPlots* mp_INC_evtSel_reco_MC; MultiPlots* mp_INC_evtSel_reco_data; mp_INC_evtSel_reco_MC = (MultiPlots*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_INC_evtSel_reco",acc)+st("/multi_class_INC_evtSel_reco",acc)); if(useData) mp_INC_evtSel_reco_data = (MultiPlots*) data->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); else mp_INC_evtSel_reco_data = (MultiPlots*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); //nch_INC->Scale(1./double(mp_INC_evtSel_reco_data->nbEvts)); double MC_factor; if(nch_INC->Integral()<2) MC_factor = 1. / double(mp_INC_evtSel_reco_MC->nbEvts) ; else MC_factor = double(mp_INC_evtSel_reco_data->nbEvts) / double(mp_INC_evtSel_reco_MC->nbEvts) ; cout<<"The ratio data_INC/MC_INC is "<<MC_factor<<endl; //if( useData ) { //TH1F* nch_trueRec = (TH1F*) mc->Get("MatrixPlots_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx/nch_reco_etaGenCut_L1_hf_VtxSel_PV_gTr_oVtx"); //nch_trueRec->Draw("same"); //} //------------------------------------------------------------------------------ //---------------------------- SD Substraction --------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING SD SUB ++++" <<endl; TH1F* nch_evtSel_SD = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_SD_evtSel_reco",acc)+st("/nch_SD_evtSel_reco",acc)); TH1F* nch_evtSel_NSD = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_NSD_evtSel_reco",acc)+st("/nch_NSD_evtSel_reco",acc)); TH1F* nch_evtSel_INC = (TH1F*) mc->Get(dir+st("GenMultiPlots_evtSel_reco",acc)+st("/MultiPlots_INC_evtSel_reco",acc)+st("/nch_INC_evtSel_reco",acc)); nch_evtSel_SD->SetName("nch_MC_gen_SD"); nch_evtSel_NSD->SetName("nch_MC_gen_NSD"); nch_evtSel_INC->SetName("nch_MC_gen_INC"); nch_evtSel_SD->Scale(MC_factor); nch_evtSel_NSD->Scale(MC_factor); nch_evtSel_INC->Scale(MC_factor); TH1F* nch_NSD = (TH1F*) nch_INC->Clone("nch_data_NSD_afterSDsub"); //Checking the integral, nentries & nevts if( nch_evtSel_INC->GetEntries()!=mp_INC_evtSel_reco_MC->nbEvts || nch_INC->GetEntries()!=mp_INC_evtSel_reco_data->nbEvts){ cout<<"Problem in normalization of SD MC component, please correct it or resampling will be wrong !"<<endl; return; } if( int(nch_INC->GetEntries() - nch_INC->Integral()) != 0 ){ cout<<"!! WARNING : nch_INC->Integral differs from the #entries ==> there are some over/underflows ..."<<endl; cout<<" ===> Integral : "<<nch_INC->Integral()<<" | #Entries : "<<nch_INC->GetEntries() <<" | Diff : "<<nch_INC->Integral()-nch_INC->GetEntries()<<endl; cout<<" ===> #Overflows : "<<nch_INC->GetBinContent(nch_INC->GetNbinsX()+1)<<endl; } //Current % of SD & NSD /*double frac_SD = nch_evtSel_SD->Integral() / nch_evtSel_INC->GetEntries(); double frac_NSD = nch_evtSel_NSD->Integral() / nch_evtSel_INC->GetEntries();*/ double frac_SD = nch_evtSel_SD->Integral() / nch_evtSel_INC->Integral(); double frac_NSD = nch_evtSel_NSD->Integral() / nch_evtSel_INC->Integral(); if(nch_evtSel_INC->GetBinContent(nch_evtSel_INC->GetNbinsX()+1)!=0) cout<<"!! WARNING : the MC INC distri has overflows ..."<<endl; cout<<"Fraction of SD events : "<< frac_SD * 100. << endl; cout<<"Fraction of NSD events : "<< frac_NSD * 100. << endl; //inserting the SD systematic #include "syst_SDsub.C" //Doing the SD substraction nch_NSD->Add(nch_evtSel_SD,-1); //nch_NSD->SetBinContent(1,0); /*int bintochange = 15; int nsigma = 3; nch_NSD->SetBinContent(bintochange,nch_NSD->GetBinContent(bintochange)- nsigma * nch_NSD->GetBinError(bintochange)); //nch_NSD->SetBinContent(bintochange+1,nch_NSD->GetBinContent(bintochange+1)- nsigma * nch_NSD->GetBinError(bintochange+1)); bintochange +=4; //nch_NSD->SetBinContent(bintochange,nch_NSD->GetBinContent(bintochange)- nsigma * nch_NSD->GetBinError(bintochange)); */ if(drawcanv){ TCanvas* c_SDsub = new TCanvas("c_SDsub","c_SDsub",2500,510,500,500); c_SDsub->cd(); nch_INC->SetLineColor(kGreen); nch_INC->Draw(); nch_evtSel_SD->SetLineColor(kRed); nch_evtSel_SD->Draw("hist same"); nch_evtSel_NSD->Draw("hist same"); nch_NSD->SetLineColor(kBlue); nch_NSD->Draw("e same"); TLegend *leg = new TLegend (.65,.70,.90,.99); leg->AddEntry(nch_INC,"data - Raw","l" ); leg->AddEntry(nch_NSD,"Data after SD corr","l" ); leg->AddEntry(nch_evtSel_SD,"MC SD","l" ); leg->AddEntry(nch_evtSel_NSD,"MC NSD","l" ); leg->Draw("same"); } TH1F* eff_evtSel = (TH1F*) mc->Get(dir+st("eff_evtSel",acc)); TH1F* evtSel_before = (TH1F*) mc->Get(dir+st("evtSel_before",acc)); TH1F* evtSel_after = (TH1F*) mc->Get(dir+st("evtSel_after",acc)); eff_evtSel->Divide(evtSel_after,evtSel_before,1,1,"B"); eff_evtSel->SetName("eff_evtSel"); TH1F* nch_toUnfold = (TH1F*) nch_NSD->Clone("nch_toUnfold"); //nch_toUnfold->Divide(eff_evtSel); divideByWidth(nch_evtSel_SD); divideByWidth(nch_evtSel_NSD); divideByWidth(nch_evtSel_INC); nch_evtSel_SD->Write(); nch_evtSel_NSD->Write(); nch_evtSel_INC->Write(); ////////////////////////////////////////////////////////////////////////////////// ///////////////////////// TEST AREA /////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ////////// TEMP TO CHECK ERRORS // makeFakeMatrix(matrixhist,nch_toUnfold,1); // transform2Matrix(matrixhist,matrix); // matrixhist->Scale(1,"width"); // matrixhist->Write(); ////////// TEMP TO CHECK ERRORS //------------------------------------------------------------------------------ //---------------------------- Unfolding --------------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING UNFOLDING ++++" <<endl; TH1F nch_unfolded("","",1,0,1); TH1F* hypothesis = (TH1F*) nch_trueGen->Clone("hypothesis"); if (hyp == 0){ for (int i=1;i<=hypothesis->GetNbinsX();i++) hypothesis->SetBinContent(i,hypothesis->GetBinWidth(i)); } else if (hyp == 1) hypothesis = nch_trueGen_afterUnfolding; else if (hyp == 2) hypothesis = nch_toUnfold; else if (hyp == 3) { hypothesis->Reset(); for (int i=0 ; i<10000 ; ++i) hypothesis->Fill(gRandom->Gaus(mu,sigma) ) ; } else if(hyp == 4){ hypothesis->Reset(); for(int i=0 ; i<=hypothesis->GetNbinsX() ; ++i) hypothesis->SetBinContent(i,NBD(i , 26.9 , 7 )); } else if(hyp == 5){ hypothesis->Reset(); TH1F* nbd1 = (TH1F*) hypothesis->Clone("nbd1"); for(int i=1 ; i<=hypothesis->GetNbinsX() ; ++i) nbd1->SetBinContent(i,NBD(i , 26.9 , 7 )); TH1F* nbd2 = (TH1F*) hypothesis->Clone("nbd2"); for(int i=1 ; i<=hypothesis->GetNbinsX() ; ++i) nbd2->SetBinContent(i,NBD(i , 57.9 , 13 )); //hypothesis->Add(nbd1,nbd2,0.72,0.28); hypothesis->Add(nbd1,nbd2,1,0); //hypothesis->SetBinContent(1,0.1); TCanvas t("t","t"); hypothesis->Draw(); gPad->WaitPrimitive(); } bool reweightmtx = false; if(E==7.) reweightmtx = true; TH1D* projX = new TH1D(); TH1D* projY = new TH1D(); cout << "Reweighting the matrix : " << reweightmtx << endl; if(reweightmtx){ matrixhist->Write("nch_matrix_beforeReweighting"); projY = (TH1D*) (matrixhist->ProjectionY("_py",1,matrixhist->GetNbinsY())); //reweighting the reco side for(int ireco = 1 ; ireco <= matrixhist->GetNbinsY() ; ++ireco){ double factor = 0; if(projY->GetBinContent(ireco)!=0) factor = nch_toUnfold->GetBinContent(ireco) / projY->GetBinContent(ireco); double sumb = 0 , suma = 0; for(int igen = 1 ; igen <= matrixhist->GetNbinsX() ; ++igen){ sumb += matrixhist->GetBinContent(igen , ireco); matrixhist->SetBinContent(igen , ireco , matrixhist->GetBinContent(igen , ireco) * factor ); suma += matrixhist->GetBinContent(igen , ireco); } //cout << "bin " << ireco << " before = " << sumb << "( " << projY->GetBinContent(ireco) << " ) after = " << suma << "( " << nch_toUnfold->GetBinContent(ireco) << " )" << endl; } } projX = (TH1D*) (matrixhist->ProjectionX("_px",1,matrixhist->GetNbinsX())); projY = (TH1D*) (matrixhist->ProjectionY("_py",1,matrixhist->GetNbinsY())); nch_unfolded = (runalgo(matrixhist,nch_toUnfold,hypothesis,niter)); TH1F* nch_unfoldedPtr = (TH1F*) nch_unfolded.Clone("nch_unfoldedPtr"); cout<< nch_unfoldedPtr->GetBinContent(31) << " " << nch_unfoldedPtr->GetBinError(31) << endl; //------------------------------------------------------------------------------ //---------------------------- ReScaling ------------------------------------- //------------------------------------------------------------------------------ /*nch_unfoldedPtr->Scale(1./double(mp_INC_evtSel_reco_data->nbEvts)); nch_INC->Scale(1./double(mp_INC_evtSel_reco_data->nbEvts)); if(nch_unfoldedPtr->Integral()<2) MC_factor = 1. / double(mp_INC_evtSel_reco_MC->nbEvts) ; else MC_factor = double(mp_INC_evtSel_reco_data->nbEvts) / double(mp_INC_evtSel_reco_MC->nbEvts) ; */ //------------------------------------------------------------------------------ //---------------------------- Resampling & moments ---------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING RESAMPLING & MOMENTS' STAT ERRORS ++++" <<endl; TMoments* moment = new TMoments(); gDirectory->mkdir("hist_resampling"); gDirectory->cd("hist_resampling"); int niter_resampling = 100; if(syst!=0) niter_resampling = 1; cout << "WARNING !! The resampling is done with " << niter_resampling << " iterations ..." << endl; TH1F nch_resampled = resample(matrixhist,nch_INC,nch_NSD,nch_unfoldedPtr,hypothesis,niter_resampling,0,nch_evtSel_SD,moment,eff_evtSel,false); TH1F* nch_resampledPtr = &nch_resampled; gDirectory->cd("../"); if(drawcanv){ TCanvas* c_resample = new TCanvas("resampling","resampling",1460,510,500,500); c_resample->cd(); nch_unfoldedPtr->SetLineColor(kBlack); nch_unfoldedPtr->Draw("hist"); nch_resampledPtr->Draw("e"); //gPad->WaitPrimitive(); } gDirectory->mkdir("mtx_resampling"); gDirectory->cd("mtx_resampling"); TH1F nch_mtxresampled = mtxresample(matrixhist,nch_toUnfold,hypothesis,niter_resampling,moment,eff_evtSel); TH1F* nch_mtxresampledPtr = &nch_mtxresampled; gDirectory->cd("../"); /* for(int nbin = 1 ; nbin<=nch_unfoldedPtr->GetNbinsX() ; ++nbin){ nch_unfoldedPtr->SetBinError(nbin , sqrt(pow(nch_resampledPtr->GetBinError(nbin),2)+pow(nch_mtxresampledPtr->GetBinError(nbin),2))); }*/ //------------------------------------------------------------------------------ //---------------------------- EvtSel Correction ------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING EVT SEL CORRECTION ++++" <<endl; TH1F* nch_corrected = (TH1F*) nch_unfoldedPtr->Clone("nch_data_corrected"); //eff_evtSel->Sumw2(); //including the systematic for evtSel Eff #include "syst_evtSelEff.C" nch_corrected->Divide(nch_corrected,eff_evtSel,1,1); /* nch_corrected->Scale(1./nch_corrected->Integral()); nch_trueGen->Scale(1./nch_trueGen->Integral()); nch_trueGen_afterUnfolding->Scale(1./nch_trueGen_afterUnfolding->Integral());*/ if(drawcanv){ TCanvas* c_effcorr = new TCanvas("c_effcorr","c_effcorr",1980,510,500,500); c_effcorr->cd(); nch_trueGen->Draw("hist"); nch_corrected->Draw("same e"); nch_trueGen_afterUnfolding->Draw("same hist"); nch_unfoldedPtr->SetLineWidth(2); nch_unfoldedPtr->SetLineColor(kGreen); nch_unfoldedPtr->Draw("same e"); TLegend* leg = new TLegend (.65,.70,.90,.99); leg->AddEntry(nch_trueGen,"MC after Correction","l" ); leg->AddEntry(nch_corrected,"Data after Correction","l" ); leg->AddEntry(nch_trueGen_afterUnfolding,"MC after Unfolding","l" ); leg->AddEntry(nch_unfoldedPtr,"Data after Unfolding","l" ); leg->Draw("same"); } //------------------------------------------------------------------------------ //---------------------------- pt frac Correction ------------------------------ //------------------------------------------------------------------------------ TH1F* nch_evtSelCorr = (TH1F*) nch_corrected->Clone("nch_data_evtSelCorr"); if(doPTcorr){ cout<<" ++++ DOING PT FRAC CORRECTION ++++" <<endl; #include "ptcorr.C" if(syst==700) ptcorr_val += 1. * syst_sign; increaseNTracks(nch_corrected , ptcorr_val , 1); } cout<<"Mean of multiplicity --------> "<<nch_corrected->GetMean()<<endl; cout<<"RMS of multiplicity --------> "<<nch_corrected->GetRMS()<<endl; //------------------------------------------------------------------------------ //-------------------------- Adding Stat Errors ---------------------------- //-------------------------- to the final curve ---------------------------- //------------------------------------------------------------------------------ for(int nbin = 1 ; nbin<=nch_corrected->GetNbinsX() ; ++nbin){ nch_corrected->SetBinError(nbin , sqrt(pow(nch_resampledPtr->GetBinError(nbin),2)+pow(nch_mtxresampledPtr->GetBinError(nbin),2))); //cout<<nbin<<" "<<nch_resampledPtr->GetBinError(nbin)<<" "<<nch_mtxresampledPtr->GetBinError(nbin)<<endl; //cout<<" "<<sqrt(pow(nch_resampledPtr->GetBinError(nbin),2)+pow(nch_mtxresampledPtr->GetBinError(nbin),2)) // <<" "<<nch_unfoldedPtr->GetBinError(nbin)<<endl; } //------------------------------------------------------------------------------ //--------------------------------- Rescaling ---------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ RESCALING ++++" <<endl; divideByWidth(nch_trueGen); divideByWidth(nch_trueGen_afterUnfolding); divideByWidth(nch_INC); divideByWidth(nch_NSD); divideByWidth(nch_unfoldedPtr); if(doPTcorr) divideByWidth(nch_evtSelCorr); divideByWidth(nch_corrected); divideByWidth(nch_resampledPtr); divideByWidth(nch_mtxresampledPtr); divideByWidth(matrixhist); divideByWidth(hypothesis); divideByWidth(projX); divideByWidth(projY); //divideByWidth(projX); //divideByWidth(projY); //nch_corrected->Scale(1./nch_corrected->Integral()); //------------------------------------------------------------------------------ //--------------------------------- Moments ------------------------------------ //------------------------------------------------------------------------------ cout<<" ++++ DOING MOMENTS ++++" <<endl; gDirectory->mkdir("moments"); gDirectory->cd("moments"); /*const int nmoments = 6; TH1F** moments = new TH1F*[nmoments]; vector<double> cmom = getCMoments(nch_corrected); vector<double> fmom = getFMoments(nch_corrected); vector<double> cmomerror = getMomentErrors(nch_corrected); for(int m = 0 ; m < nmoments ; ++m){ cout<<cmom[m]<<" "<<cmomerror[m]<<endl; ostringstream momname(""); momname << "moment_" << m; moments[m] = new TH1F(momname.str().c_str() , momname.str().c_str() , 1 , E*1000.-0.5 , E*1000.+0.5); moments[m]->SetBinContent(1, cmom[m]); moments[m]->SetBinError(1, cmomerror[m]); moments[m]->Write(); }*/ //TMoments* moment = new TMoments(nch_corrected); //moment->print(); moment->Add(nch_corrected); moment->ComputeMoments(); //moment->print(); //moment->ComputeErrorsFromResampling(nch_corrected); moment->print(); moment->Write("moments"); /* TH1F* test = new TH1F("jj","jj",3,4.5,7.5); test->Fill(5,10); test->Fill(6,10); test->Fill(7,10); TH1F* test = new TH1F("jj","jj",20000,-5,20); for(int t=0;t<1000000;++t) test->Fill(gRandom->Poisson(1)); cout<<"--------------------------"<<endl; getCMoments(test); getFMoments(test); TMoments* moment = new TMoments(); for(int ll = 1 ; ll <= test->GetNbinsX() ; ++ll){ cout<<"hjkhkjhkjhkhkjhjkhjkhjkhkjhjkhjkhjkhjkhkj "<<ll<<endl; moment->Add(test->GetBinCenter(ll) , test->GetBinContent(ll)); } moment->ComputeMoments(); moment->print(); */ gDirectory->cd("../"); //------------------------------------------------------------------------------ //------------------------------------ KNO ------------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING KNO ++++" <<endl; double knomean = nch_corrected->GetMean(); TString tkno = out->GetName(); tkno.ReplaceAll("plots/","plots/current_b1_2/"); cout<<"Opening for kno mean the file : "<<tkno<<endl; TFile* fkno = TFile::Open(tkno,"READ"); if(fkno!=0){ TMoments* mom_kno = (TMoments*) fkno->Get("unfolding/moments/moments"); knomean = mom_kno->mean->GetMean(); } else{ cout<<"WARNING !! The file does not exist, taking the mean of the hist instead"<<endl; } TH1F* kno = new TH1F("kno_corrected","kno_corrected;z = n_{ch} / < n_{ch} >;#psi(z)",nch_corrected->GetNbinsX(),Divide(nch_corrected->GetXaxis()->GetXbins(),knomean)); kno->Sumw2(); /*for( int k = 60 ; k <= nch_corrected->GetNbinsX() ; ++k) nch_corrected->SetBinContent(k,0);*/ for( int k = 1 ; k <= nch_corrected->GetNbinsX() ; ++k){ kno->SetBinContent(k , knomean * nch_corrected->GetBinContent(k) / nch_corrected->Integral()); kno->SetBinError(k , knomean * nch_corrected->GetBinError(k) / nch_corrected->Integral()); } if(drawcanv){ TCanvas* c_kno = new TCanvas("c_kno","c_kno",200,510,500,500); c_kno->cd(); kno->Draw(); } TMoments* moment_gen = new TMoments(nch_trueGen); moment_gen->ComputeMoments(); knomean = moment_gen->mean->GetMean(); if(fkno!=0){ TH1F* mom_kno_gen = (TH1F*) fkno->Get("unfolding/nch_MC_gen_afterEvtSelCorrection"); knomean = mom_kno_gen->GetMean(); } TH1F* kno_gen = new TH1F("kno_gen","kno_gen;z = n_{ch} / < n_{ch} >;#psi(z)",nch_trueGen->GetNbinsX(),Divide(nch_trueGen->GetXaxis()->GetXbins(),knomean)); kno_gen->Sumw2(); for( int k = 1 ; k <= nch_trueGen->GetNbinsX() ; ++k){ kno_gen->SetBinContent(k , knomean * nch_trueGen->GetBinContent(k) / nch_trueGen->Integral()); kno_gen->SetBinError(k , knomean * nch_trueGen->GetBinError(k) / nch_trueGen->Integral()); } out->cd("unfolding"); kno_gen->Write(); //------------------------------------------------------------------------------ //---------------------------------- Plots ------------------------------------- //------------------------------------------------------------------------------ if(drawcanv){ TCanvas* c_final = new TCanvas("c_final","c_final",1980,10,500,500); c_final->SetLeftMargin(0.17); c_final->SetBottomMargin(0.10); c_final->SetFillColor(0); c_final->GetFrame()->SetFillColor(21); c_final->GetFrame()->SetBorderSize(12); c_final->SetGrid(); //Unfolding nch_trueGen->SetLineWidth(2); nch_INC->SetLineWidth(2); nch_corrected->SetLineWidth(2); nch_trueGen->SetLineColor(kBlue); nch_INC->SetLineColor(kGreen); nch_corrected->SetLineColor(kRed); nch_INC->Draw("hist"); nch_trueGen->Draw("same hist"); nch_corrected->Draw("same e"); /*nch_trueGen->Scale(1./nch_trueGen->Integral()); nch_INC->Scale(1./nch_INC->Integral()); nch_corrected->Scale(1./nch_corrected->Integral());*/ // UA5 bool lua5 = true; TGraphAsymmErrors* ua5_multi; if ( lua5 ) { ifstream ua5("/user/xjanssen/ua5_dsigdn_eta15"); const Int_t n = 300 ; Int_t i = 0; Double_t xl[n], xh[n], x[n] , y[n], eyl[n] , eyh[n] , ex[n]; //ua5.open ("/user/xjanssen/ua5_dsigdn_eta15"); while ( ua5 >> xl[i] >> xh[i] >> y[i] >> eyh[i] >> eyl[i] ) { eyl[i] = -eyl[i] ; x[i] = xl[i]+(xh[i]-xl[i])/2; //y[i] = 3*50000 * y[i]; //eyl[i]*=3*50000; //eyh[i]*=3*50000; //cout<<y[i]<<endl; ex[i] = (xh[i]-xl[i])/2; i++; } ua5.close(); ua5_multi = new TGraphAsymmErrors(i,x,y,ex,ex,eyl,eyh); //gr->SetMarkerColor(0); //gr->SetMarkerStyle(24); ua5_multi->Draw("L"); ua5_multi->Write("ua5"); } TLegend* leg = new TLegend (.65,.90,.90,.99); leg->AddEntry(nch_trueGen,"PYTHIA D6T","l" ); if (useData) { leg->AddEntry(nch_INC,"Data - Raw","l" ); leg->AddEntry(nch_corrected,"Data - Corrected","l" ); } else { leg->AddEntry(nch_INC,"MC - Raw","l" ); leg->AddEntry(nch_corrected,"MC - Corrected","l" ); } if (lua5) leg->AddEntry(ua5_multi,"UA5 #eta < 1.5","l"); leg->SetBorderSize(0); leg->SetFillColor(0); leg->Draw(); cout<<"bin 0 corrected:"<<nch_corrected->GetBinContent(1)<<endl; cout<<"Err bin 0 corrected:"<<nch_corrected->GetBinError(1)<<endl; cout<<"bin 0 before:"<<nch_unfoldedPtr->GetBinContent(1)<<endl; cout<<"Err bin 0 before:"<<nch_unfoldedPtr->GetBinError(1)<<endl; cout<<"bin 0 eff:"<<eff_evtSel->GetBinContent(1)<<endl; cout<<"Err bin 0 eff:"<<eff_evtSel->GetBinError(1)<<endl; //------------------------------------------------------------------------------ //---------------------------------- Fits ------------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING FITS ++++" <<endl; #include "fitting.C" }//End of if(drawcanv) for final plot //Unfolding hypothesis->Write("hypothesis"); nch_trueGen->Write(); nch_trueGen_afterUnfolding->Write(); nch_INC->Write(); nch_NSD->Write(); nch_unfoldedPtr->Write(); if(doPTcorr) nch_evtSelCorr->Write(); nch_corrected->Write(); nch_resampledPtr->Write("nch_histresampled"); nch_mtxresampledPtr->Write("nch_mtxresampledPtr"); eff_evtSel->Write(); h2g(nch_corrected).Write(); //h2g(nch_mtxresampledPtr).Write(); //eff_nch_L1_hf_vtxSel->Write(); kno->Write(); matrixhist->Write(); projX->Write(); projY->Write(); gDirectory->cd("../"); //------------------------------------------------------------------------------ //-------------------------------- Corrections --------------------------------- //------------------------------------------------------------------------------ cout<<" ++++ DOING BASIC CORRECTIONS ++++" <<endl; MultiPlots* mp_etaCut_noSel_NSD_gen = (MultiPlots*) mc->Get(dir+st("MultiPlots_etaCut_noSel_NSD_gen",acc)+st("/multi_class_etaCut_noSel_NSD_gen",acc)); MultiPlots* mp_etaCut_evtSel_INC_reco_MC = (MultiPlots*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); MultiPlots* mp_etaCut_evtSel_INC_reco_data; if(!useData) mp_etaCut_evtSel_INC_reco_data = (MultiPlots*) mc->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); else mp_etaCut_evtSel_INC_reco_data = (MultiPlots*) data->Get(dir+st("MultiPlots_evtSel_INC_reco",acc)+st("/multi_class_evtSel_INC_reco",acc)); cout << " nbEvts MC gen,reco : " << mp_etaCut_noSel_NSD_gen->nbEvts << " " << mp_etaCut_evtSel_INC_reco_data->nbEvts << endl; #include "makeBasicCorrections.C" // out->Close(); //data->Close(); //mc->Close(); /* delete c1; delete cm; out->Close(); data->Close(); mc->Close(); delete mc; delete data; */ }