void makeBSM_MCFM_single(int folder, int erg_tev){ // if (erg_tev==7) return; // char TREE_NAME[] = "SelectedTree"; char TREE_NAME[] = "GenTree"; TString INPUT_NAME = "HZZ4l-125_6-"; int tFitD = 0; TString comstring; comstring.Form("%iTeV", erg_tev); TString erg_dir; erg_dir.Form("LHC_%iTeV/", erg_tev); INPUT_NAME.Append(comstring); INPUT_NAME.Append("-"); double mPOLE = 125.6; Mela mela(erg_tev, mPOLE); TString cinput_common = "/scratch0/hep/usarical/WidthSamples/" + erg_dir + "/"; if (erg_tev!=7) cinput_common = cinput_common + user_folder[folder] + "/"; int EnergyIndex = 1; if (erg_tev == 7) EnergyIndex = 0; float templateWeight = 1; float MC_weight; float ZZMass = 0; float Z1Mass = 0; float Z2Mass = 0; float GenHMass = 0; float GenZ1Mass = 0; float GenZ2Mass = 0; float GenLep1Id, GenLep2Id, GenLep3Id, GenLep4Id; float GenLep1Mass, GenLep2Mass, GenLep3Mass, GenLep4Mass; float GenLep1Pt, GenLep2Pt, GenLep3Pt, GenLep4Pt; float GenLep1Phi, GenLep2Phi, GenLep3Phi, GenLep4Phi; float GenLep1Eta, GenLep2Eta, GenLep3Eta, GenLep4Eta; float GenLep1E, GenLep2E, GenLep3E, GenLep4E; float p0plus_VAJHU; float p0hplus_VAJHU; float p0minus_VAJHU; float p0_g1prime2_VAJHU; float p0_g1prime4_VAJHU; float pg1g2_VAJHU; float pg1g4_VAJHU; float pg1g1prime2_VAJHU; float pg1g1prime4_VAJHU; TString coutput_common = user_TemplateswithTrees_dir + "../BSMReweight_GenLevel/" + erg_dir; coutput_common += user_folder[folder] + "/"; gSystem->Exec("mkdir -p " + coutput_common); TString cinput_KDFactor = "./data/HZZ4l-KDFactorGraph"; if (EnergyIndex == 0) cinput_KDFactor = cinput_KDFactor + "_7TeV"; cinput_KDFactor = cinput_KDFactor + ".root"; TFile* finput_KDFactor = new TFile(cinput_KDFactor, "read"); TString tgkfname = "KDScale_"; tgkfname = tgkfname + "AllFlavors_UnNormalized"; TGraphAsymmErrors* tgkf = (TGraphAsymmErrors*)finput_KDFactor->Get(tgkfname); TGraph* tg_interf = make_HZZ_LeptonInterferenceGraph(); cout<<endl; cout<<"==============================="<<endl; cout<<"CoM Energy: "<<erg_tev<<" TeV"<<endl; cout<<"Decay Channel: "<<user_folder[folder]<<endl; cout<<"==============================="<<endl; cout<<endl; const int kNumTemplates = 4; TString templatenames[kNumTemplates] ={ "ggF Sig", "gg Bkg", "ggF BSI", "ggF BSI25" }; int nEntries; float fitYval = 0; MC_weight = 1; ZZMass = 0; double selfDHvvcoupl[SIZE_HVV][2] ={ { 0 } }; double ggvvcoupl[2]={ 0, 0 }; //Template and tree filler for (int t = 0; t < kNumTemplates; t++){ TString OUTPUT_NAME; OUTPUT_NAME = "HtoZZ4l_MCFM_125p6_BSMTrees_"; OUTPUT_NAME += sample_suffix[t] + ".root"; TString coutput = coutput_common + OUTPUT_NAME; TFile* foutput = new TFile(coutput, "recreate"); foutput->cd(); TChain* tree = new TChain(TREE_NAME); TTree* templateTree = new TTree(TREE_NAME, TREE_NAME); float wPOLE=4.15e-3; if (t==3) wPOLE*=25; TString cinput = cinput_common + sample_suffix[t] + "/" + INPUT_NAME + sample_suffix[t] + ".root"; tree->Add(cinput); templateTree->Branch("MC_weight", &templateWeight); templateTree->Branch("ZZMass", &ZZMass); templateTree->Branch("Z1Mass", &Z1Mass); templateTree->Branch("Z2Mass", &Z2Mass); // templateTree->Branch("GenHMass", &GenHMass); templateTree->Branch("p0plus_VAJHU", &p0plus_VAJHU); templateTree->Branch("p0hplus_VAJHU", &p0hplus_VAJHU); templateTree->Branch("p0minus_VAJHU", &p0minus_VAJHU); templateTree->Branch("p0_g1prime2_VAJHU", &p0_g1prime2_VAJHU); templateTree->Branch("p0_g1prime4_VAJHU", &p0_g1prime4_VAJHU); templateTree->Branch("pg1g2_VAJHU", &pg1g2_VAJHU); templateTree->Branch("pg1g4_VAJHU", &pg1g4_VAJHU); templateTree->Branch("pg1g1prime2_VAJHU", &pg1g1prime2_VAJHU); templateTree->Branch("pg1g1prime4_VAJHU", &pg1g1prime4_VAJHU); //Making templates using appropriate weights // tree->SetBranchAddress("ZZMass", &ZZMass); // tree->SetBranchAddress("MC_weight", &MC_weight); tree->SetBranchAddress("GenZZMass", &GenHMass); tree->SetBranchAddress("GenLep1Id", &GenLep1Id); tree->SetBranchAddress("GenLep2Id", &GenLep2Id); tree->SetBranchAddress("GenLep3Id", &GenLep3Id); tree->SetBranchAddress("GenLep4Id", &GenLep4Id); tree->SetBranchAddress("GenLep1Pt", &GenLep1Pt); tree->SetBranchAddress("GenLep2Pt", &GenLep2Pt); tree->SetBranchAddress("GenLep3Pt", &GenLep3Pt); tree->SetBranchAddress("GenLep4Pt", &GenLep4Pt); tree->SetBranchAddress("GenLep1Phi", &GenLep1Phi); tree->SetBranchAddress("GenLep2Phi", &GenLep2Phi); tree->SetBranchAddress("GenLep3Phi", &GenLep3Phi); tree->SetBranchAddress("GenLep4Phi", &GenLep4Phi); tree->SetBranchAddress("GenLep1Eta", &GenLep1Eta); tree->SetBranchAddress("GenLep2Eta", &GenLep2Eta); tree->SetBranchAddress("GenLep3Eta", &GenLep3Eta); tree->SetBranchAddress("GenLep4Eta", &GenLep4Eta); tree->SetBranchAddress("GenLep1E", &GenLep1E); tree->SetBranchAddress("GenLep2E", &GenLep2E); tree->SetBranchAddress("GenLep3E", &GenLep3E); tree->SetBranchAddress("GenLep4E", &GenLep4E); if (tFitD != 0){ if (tree->GetBranchStatus(strFitDim[tFitD])){ tree->SetBranchAddress("Dgg10_VAMCFM", &fitYval); templateTree->Branch(strFitDim[tFitD], &fitYval); } else{ cerr << "Could NOT find branch named " << strFitDim[tFitD] << "!!! Setting strFitDim[" << tFitD << "] = 0." << endl; fitYval = 0; } } nEntries = tree->GetEntries(); double xsec = 1./nEntries; if (t==0) xsec *= xsec_ggHZZ_MCFM[EnergyIndex]; else if (t==1) xsec *= xsec_ggZZ_MCFM[EnergyIndex]; else if (t==2) xsec *= xsec_ggHZZ_BSI_MCFM[EnergyIndex]; else if (t==3) xsec *= xsec_ggHZZ_BSI25_MCFM[EnergyIndex]; else xsec = 1; if (folder<2) xsec *= 0.25; else xsec *= 0.5; // for (int ev = 0; ev < 100; ev++){ for (int ev = 0; ev < nEntries; ev++){ tree->GetEntry(ev); ZZMass = GenHMass; MC_weight = xsec; if (fitYval != fitYval) continue; // Protect against any KD exceeding boundaries if (tFitD!=0 && fitYval>=1){ cout << "Found fitYval == " << fitYval; fitYval = 0.999; cout << ". Fixed to " << fitYval << endl; } if (tFitD!=0 && fitYval<0) fitYval = 0; if (t < 4 && erg_tev==7){ if (folder==1){ GenLep1Id=11; GenLep2Id=-11; GenLep3Id=11; GenLep4Id=-11; } else if (folder==0){ GenLep1Id=13; GenLep2Id=-13; GenLep3Id=13; GenLep4Id=-13; } } double weight = MC_weight; if (t < 4) weight *= tgkf->Eval(GenHMass); if (t < 4 && abs(GenLep1Id)==abs(GenLep2Id) && abs(GenLep1Id)==abs(GenLep3Id) && abs(GenLep1Id)==abs(GenLep4Id) ) weight *= tg_interf->Eval(GenHMass); templateWeight = weight; float mzz = mPOLE; float m1 = 0; float m2 = 0; float h1 = 0; float h2 = 0; float phi = 0; float hs = 0; float phi1 = 0; GenLep1Mass = findLeptonMass(GenLep1Id); GenLep2Mass = findLeptonMass(GenLep2Id); GenLep3Mass = findLeptonMass(GenLep3Id); GenLep4Mass = findLeptonMass(GenLep4Id); TLorentzVector p1, p2, p3, p4; p1.SetPtEtaPhiE(GenLep1Pt, GenLep1Eta, GenLep1Phi, GenLep1E); p2.SetPtEtaPhiE(GenLep2Pt, GenLep2Eta, GenLep2Phi, GenLep2E); p3.SetPtEtaPhiE(GenLep3Pt, GenLep3Eta, GenLep3Phi, GenLep3E); p4.SetPtEtaPhiE(GenLep4Pt, GenLep4Eta, GenLep4Phi, GenLep4E); TLorentzVector pZ1 = p1+p2; TLorentzVector pZ2 = p3+p4; TLorentzVector pZ1p = p1+p4; TLorentzVector pZ2p = p3+p2; TLorentzVector pZZ = pZ1+pZ2; mzz=pZZ.M(); m1=pZ1.M(); m2=pZ2.M(); Z1Mass = m1; Z2Mass=m2; if (Z1Mass>=120 || Z1Mass<=40) continue; if (Z2Mass>=120 || Z2Mass<=12) continue; if (!passAcceptance(GenLep1Pt, GenLep1Eta, (int)GenLep1Id)) continue; if (!passAcceptance(GenLep2Pt, GenLep2Eta, (int)GenLep2Id)) continue; if (!passAcceptance(GenLep3Pt, GenLep3Eta, (int)GenLep3Id)) continue; if (!passAcceptance(GenLep4Pt, GenLep4Eta, (int)GenLep4Id)) continue; if (pZ1.M()<=4 ||pZ2.M()<=4 ||pZ1p.M()<=4 ||pZ2p.M()<=4) continue; TLorentzVector pp[4] ={ p1, p2, p3, p4 }; int pass20=-1; int pass10=-1; for (int vv=0; vv<4; vv++){ if (pp[vv].Pt()>20){ pass20=vv; break; } } for (int vv=0; vv<4; vv++){ if (vv==pass20) continue; if (pp[vv].Pt()>10){ pass10=vv; break; } } if (pass20<0 || pass10<0) continue; mela::computeAngles(p1, GenLep1Id, p2, GenLep2Id, p3, GenLep3Id, p4, GenLep4Id, hs, h1, h2, phi, phi1); int lepIdOrdered[4] ={ (int)GenLep1Id, (int)GenLep2Id, (int)GenLep3Id, (int)GenLep4Id }; float angularOrdered[8] ={ mzz, m1, m2, hs, h1, h2, phi, phi1 }; if (t==0) mela.setProcess(TVar::HSMHiggs, TVar::MCFM, TVar::ZZGG); if (t==2 || t==3) mela.setProcess(TVar::bkgZZ_SMHiggs, TVar::MCFM, TVar::ZZGG); if (t!=1){ for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[0][0]=1; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); p0plus_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[1][0]=1.638; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); p0hplus_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[3][0]=2.521; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); p0minus_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[11][0]=-12046.01; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); p0_g1prime2_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[13][0]=-pow(10000.0/mPOLE, 2); mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); p0_g1prime4_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[0][0]=1; selfDHvvcoupl[1][0]=1.638; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); pg1g2_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[0][0]=1; selfDHvvcoupl[3][0]=2.521; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); pg1g4_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[0][0]=1; selfDHvvcoupl[11][0]=-12046.01; mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); pg1g1prime2_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); for (int ii = 0; ii < SIZE_HVV; ii++){ for (int jj = 0; jj < 2; jj++) selfDHvvcoupl[ii][jj] = 0; } selfDHvvcoupl[0][0]=1; selfDHvvcoupl[13][0]=-pow(10000.0/mPOLE, 2); mela.setMelaLeptonInterference(TVar::InterfOn); mela.setMelaHiggsWidth(wPOLE); pg1g1prime4_VAJHU = getJHUGenMELAWeight(mela, lepIdOrdered, angularOrdered, selfDHvvcoupl); if (p0plus_VAJHU!=0){ p0hplus_VAJHU/=p0plus_VAJHU; p0minus_VAJHU/=p0plus_VAJHU; p0_g1prime2_VAJHU/=p0plus_VAJHU; p0_g1prime4_VAJHU/=p0plus_VAJHU; pg1g2_VAJHU/=p0plus_VAJHU; pg1g4_VAJHU/=p0plus_VAJHU; pg1g1prime2_VAJHU/=p0plus_VAJHU; pg1g1prime4_VAJHU/=p0plus_VAJHU; p0plus_VAJHU=1; } else{ p0plus_VAJHU=0; p0hplus_VAJHU=0; p0minus_VAJHU=0; p0_g1prime2_VAJHU=0; p0_g1prime4_VAJHU=0; pg1g2_VAJHU=0; pg1g4_VAJHU=0; pg1g1prime2_VAJHU=0; pg1g1prime4_VAJHU=0; } } else{ p0plus_VAJHU=1; p0hplus_VAJHU=1; p0minus_VAJHU=1; p0_g1prime2_VAJHU=1; p0_g1prime4_VAJHU=1; pg1g2_VAJHU=1; pg1g4_VAJHU=1; pg1g1prime2_VAJHU=1; pg1g1prime4_VAJHU=1; } p0plus_VAJHU*=templateWeight; p0hplus_VAJHU*=templateWeight; p0minus_VAJHU*=templateWeight; p0_g1prime2_VAJHU*=templateWeight; p0_g1prime4_VAJHU*=templateWeight; pg1g2_VAJHU*=templateWeight; pg1g4_VAJHU*=templateWeight; pg1g1prime2_VAJHU*=templateWeight; pg1g1prime4_VAJHU*=templateWeight; templateTree->Fill(); } foutput->WriteTObject(templateTree); delete tree; delete templateTree; foutput->Close(); } delete tg_interf; delete tgkf; finput_KDFactor->Close(); }
void createPlot(std::vector<TString> samples, std::vector<TString> files, std::vector<TString> legend) { TString y_title = "Number of Entries"; const int nHist = files.size(); // number of files // Declare the histograms to be saved TH1F *h_mll[nHist]; TH1F *h_dilpt[nHist]; TH1F *h_dphill[nHist]; TH1F *h_leadleppt[nHist]; TH1F *h_trailleppt[nHist]; TH1F *h_met[nHist]; TH1F *h_mt[nHist]; // Get the histograms from the ntuples for (int i=0;i<nHist;i++) { TString treeName = "angles"; TChain *chain = new TChain(treeName); chain->Add(files[i]); assert(chain); // declare histograms to fill Color_t color = kBlack; TString sampleName = samples[i]; if ( sampleName.Contains("SMHiggs",TString::kExact )) color = kBlue; if ( sampleName.Contains("PSHiggs", TString::kExact)) color = kMagenta; if ( sampleName.Contains("T", TString::kExact)) color = kRed; if ( sampleName.Contains("THiggs", TString::kExact)) color = kRed; // define the histograms to plot // dilmass h_mll[i] = new TH1F(TString("HWW_"+sampleName+"_hdilmass"), TString("HWW_"+sampleName+"_hdilmass"), 20, 0, 200); h_mll[i]->SetLineColor(color); h_mll[i]->SetMarkerColor(color); // leading lepton pT h_leadleppt[i] = new TH1F(TString("HWW_"+sampleName+"_hleadleppt"), TString("HWW_"+sampleName+"_hleadleppt"), 20, 0, 100); h_leadleppt[i]->SetLineColor(color); h_leadleppt[i]->SetMarkerColor(color); // trailing lepton pT h_trailleppt[i] = new TH1F(TString("HWW_"+sampleName+"_htrailleppt"), TString("HWW_"+sampleName+"_htrailleppt"), 20, 0, 100); h_trailleppt[i]->SetLineColor(color); h_trailleppt[i]->SetMarkerColor(color); // MET h_met[i] = new TH1F(TString("HWW_"+sampleName+"_hmet"), TString("HWW_"+sampleName+"_hmet"), 20, 0, 100); h_met[i]->SetLineColor(color); h_met[i]->SetMarkerColor(color); // dilepton pT h_dilpt[i] = new TH1F(TString("HWW_"+sampleName+"_hdilpt"), TString("HWW_"+sampleName+"_hdilpt"), 30, 20, 100); h_dilpt[i]->SetLineColor(color); h_dilpt[i]->SetMarkerColor(color); // deltaphi (ll) h_dphill[i] = new TH1F(TString("HWW_"+sampleName+"_hdphi"), TString("HWW_"+sampleName+"_hdphi"), 18, 0, 180.0); h_dphill[i]->SetLineColor(color); h_dphill[i]->SetMarkerColor(color); // transverse mass h_mt[i] = new TH1F(TString("HWW_"+sampleName+"_hmt"), TString("HWW_"+sampleName+"_hmt"), 20, 0, 200); h_mt[i]->SetLineColor(color); h_mt[i]->SetMarkerColor(color); std::cout << "Processing " << chain->GetEntries() << " entries. \n"; int nEntries = chain->GetEntries() ; int nSelected = 0; // mcfm variables to be used double mll_ = 0.0; double leadleppt_ = 0.0; double trailleppt_ = 0.0; double leadlepeta_ = 0.0; double traillepeta_ = 0.0; double dphill_ = 0.0; double met_ = 0.0; double mt_ = 0.0; double dilpt_ = 0.0; double wt_ = 1.0; if (chain->GetBranchStatus("mll")) chain->SetBranchAddress("mll", &mll_); if (chain->GetBranchStatus("leadleppt")) chain->SetBranchAddress("leadleppt", &leadleppt_); if (chain->GetBranchStatus("trailleppt")) chain->SetBranchAddress("trailleppt", &trailleppt_); if (chain->GetBranchStatus("dphill")) chain->SetBranchAddress("dphill", &dphill_); if (chain->GetBranchStatus("met")) chain->SetBranchAddress("met", &met_); if (chain->GetBranchStatus("mt")) chain->SetBranchAddress("mt", &mt_); if (chain->GetBranchStatus("dilpt")) chain->SetBranchAddress("dilpt", &dilpt_); if (chain->GetBranchStatus("leadlepeta")) chain->SetBranchAddress("leadlepeta", &leadlepeta_); if (chain->GetBranchStatus("traillepeta")) chain->SetBranchAddress("traillepeta", &traillepeta_); if (chain->GetBranchStatus("wt")) chain->SetBranchAddress("wt", &wt_); for ( int ievt = 0; ievt < chain->GetEntries(); ievt++) { chain->GetEntry(ievt); // // apply WW selections // if ( ievt == 0 ) std::cout << leadleppt_ << "\t" << trailleppt_ << "\t" << dilpt_ << "\t" << met_ << "\t" << mll_ << "\n"; float weight = wt_; if ( leadleppt_ < 20. ) continue; if ( trailleppt_ < 10. ) continue; if ( TMath::Abs(leadlepeta_) > 2.5) continue; if ( TMath::Abs(traillepeta_) > 2.5) continue; /* if ( dilpt_ < 45.) continue; if ( mll_ < 12.) continue; if ( met_ < 20.) continue; */ h_mll[i]->Fill(mll_, weight); h_dilpt[i]->Fill(dilpt_, weight); h_dphill[i]->Fill(dphill_ * 180. / TMath::Pi(), weight); h_leadleppt[i]->Fill(leadleppt_, weight); h_trailleppt[i]->Fill(trailleppt_, weight); h_mt[i]->Fill(mt_, weight); h_met[i]->Fill(met_, weight); // // apply HWW selections for 125 // if ( higgselection(mH, mt_, mll_, dphill_, leadleppt_, trailleppt_) ) nSelected++; } // end of event loop in each sample std::cout << Form("sample %s: selection effiency is %i / %i = %.2f\n", samples[i].Data(), nSelected, nEntries, float(nSelected)/float(nEntries)); } drawsingle("mll", nHist, h_mll, samples, legend, "Dilepton Invariant Mass [GeV]"); drawsingle("dphill", nHist, h_dphill, samples, legend, "#Delta#phi(leptons) [degrees]"); drawsingle("mt", nHist, h_mt, samples, legend, "Transverse Higgs Mass [GeV]"); drawsingle("met", nHist, h_met, samples, legend, "Transverse Missing Energy [GeV]"); drawsingle("dilpt", nHist, h_dilpt, samples, legend, "Dilepton pT [GeV]"); output_file->cd(); for(int i=0;i<nHist;i++) { h_mll[i]->Write(); h_dphill[i]->Write(); h_leadleppt[i]->Write(); h_trailleppt[i]->Write(); h_met[i]->Write(); h_mt[i]->Write(); h_dilpt[i]->Write(); } // tidy up for ( int i = 0; i<nHist;i++) { delete h_mll[i]; delete h_dphill[i]; delete h_leadleppt[i]; delete h_trailleppt[i]; delete h_met[i]; delete h_mt[i]; delete h_dilpt[i]; } }
void analyzer (TString inputFileName,TString outputFileName, TString runPeriod, bool isData, bool isSignal, unsigned maxEvents) { using namespace std; /////////////////// // Configuration float minMmm = 110; float maxMmm = 160; //gErrorIgnoreLevel = kError; const unsigned ISMEAR = 2; /////////////////////////// // Output Histograms setStyle(); TH1F* dimuonMassHist = new TH1F("dimuonMass","",50,110,160); setHistTitles(dimuonMassHist,"M(#mu#mu) [GeV/c^{2}]","Events"); dimuonMassHist->Sumw2(); TH1F* nJetsHist = new TH1F("nJets","",10,0,10); setHistTitles(nJetsHist,"N_{Jets}","Events"); nJetsHist->Sumw2(); /////////////////////////// Double_t MASS_MUON = 0.105658367; //GeV/c2 ////////////////////////// // Tree Branches cout << "Analyzing filename: "<< inputFileName.Data() << endl; if (isData) cout << "isData\n"; if (isSignal) cout << "isSignal\n"; TChain * tree = new TChain("tree"); tree->Add(inputFileName); // These are the names of the muons (See src/DataFormats.h for definitions!) _MuonInfo reco1, reco2; tree->SetBranchAddress("reco1", &reco1); tree->SetBranchAddress("reco2", &reco2); // These are the dimuon mass, pt, rapidity, and phi float recoCandMass, recoCandPt, recoCandY, recoCandPhi; float recoCandMassRes, recoCandMassResCov; tree->SetBranchAddress("recoCandMass", &recoCandMass); tree->SetBranchAddress("recoCandPt", &recoCandPt); tree->SetBranchAddress("recoCandY", &recoCandY); tree->SetBranchAddress("recoCandPhi", &recoCandPhi); tree->SetBranchAddress("recoCandMassRes", &recoCandMassRes); tree->SetBranchAddress("recoCandMassResCov", &recoCandMassResCov); // MC truth info float trueMass=-99999.0; if(!isData && tree->GetBranchStatus("trueMass")) tree->SetBranchAddress("trueMass", &trueMass); /// Higgs Boson MC truth info (after FSR) _genPartInfo genHpostFSR; if(!isData && tree->GetBranchStatus("genHpostFSR")) tree->SetBranchAddress("genHpostFSR", &genHpostFSR); _TrackInfo reco1GenPostFSR; if(!isData && tree->GetBranchStatus("genM1HpostFSR")) tree->SetBranchAddress("genM1HpostFSR", &reco1GenPostFSR); _TrackInfo reco2GenPostFSR; if(!isData && tree->GetBranchStatus("genM2HpostFSR")) tree->SetBranchAddress("genM2HpostFSR", &reco2GenPostFSR); /// the jet collection // these 'rawJets' already have Loose Jet ID applied, and JES corrections // and are cross-cleaned of tight muons // later, jets will have JER corrections, PUID, and basic cuts applied _PFJetInfo rawJets; tree->SetBranchAddress("pfJets",&rawJets); float puJetFullDisc[10]; float puJetSimpleDisc[10]; float puJetCutDisc[10]; tree->SetBranchAddress("puJetFullDisc",&puJetFullDisc); tree->SetBranchAddress("puJetSimpleDisc",&puJetSimpleDisc); tree->SetBranchAddress("puJetCutDisc",&puJetCutDisc); float puJetFullId[10]; float puJetSimpleId[10]; float puJetCutId[10]; tree->SetBranchAddress("puJetFullId",&puJetFullId); tree->SetBranchAddress("puJetSimpleId",&puJetSimpleId); tree->SetBranchAddress("puJetCutId",&puJetCutId); int nPU=0; if (!isData) { tree->SetBranchAddress("nPU",&nPU); } _VertexInfo vertexInfo; tree->SetBranchAddress("vertexInfo",&vertexInfo); _EventInfo eventInfo; tree->SetBranchAddress("eventInfo",&eventInfo); // Be careful, the met has not been well validated _MetInfo met; tree->SetBranchAddress("met",&met); ////////////////////////// //for PU reweighting reweight::LumiReWeighting lumiWeights("pileupDists/PileUpHistMC2012Summer50nsPoissonOOTPU.root","pileupDists/PileUpHist2012ABCD.root","pileup","pileup"); if (runPeriod == "7TeV") { cout << "Using 2011AB PU reweighting\n"; lumiWeights = reweight::LumiReWeighting("pileupDists/PileUpHistMCFall11.root","pileupDists/PileUpHist2011AB.root","pileup","pileup"); } else { cout << "Using 2012ABCD PU reweighting\n"; } /////////////////////////////// // Which Muon Selection to Use bool (*muonIdFuncPtr)(_MuonInfo&); if (runPeriod == "7TeV") { cout << "Using 2011 Tight Muon Selection\n"; muonIdFuncPtr = &isKinTight_2011_noIso; } else { cout << "Using 2012 Tight Muon Selection\n"; muonIdFuncPtr = &isKinTight_2012_noIso; } ///////////////////////// // Smearing SmearingTool *smearPT = new SmearingTool(); SmearingTool2011 *smearPT2011 = new SmearingTool2011(); ///////////////////////////// ///////////////////////////// unsigned nEvents = tree->GetEntries(); unsigned reportEach=1000; if (nEvents/1000>reportEach) reportEach = nEvents/1000; /////////////////////////////// /////////////////////////////// /////////////////////////////// // Event Loop for(unsigned i=0; i<nEvents;i++) { if(i >= maxEvents) break; tree->GetEvent(i); if (i % reportEach == 0) cout << "Event: " << i << endl; // Reject events with invalid muons if (reco1.pt < 0. || reco2.pt < 0.) continue; ///////////////////////////////////////////////// // Muon Resolution Smearing to match MuScleFit if(isSignal) // smear only signal because it has muons from higgs { if(reco1GenPostFSR.pt<0.) cout << "Muon 1 Post FSR not valid!\n"; if(reco2GenPostFSR.pt<0.) cout << "Muon 2 Post FSR not valid!\n"; float ptReco1 = -1.; float ptReco2 = -1.; if(runPeriod == "7TeV") { ptReco1 = smearPT2011 -> PTsmear(reco1GenPostFSR.pt, reco1GenPostFSR.eta, reco1GenPostFSR.charge, reco1.pt, ISMEAR); ptReco2 = smearPT2011 -> PTsmear(reco2GenPostFSR.pt, reco2GenPostFSR.eta, reco2GenPostFSR.charge, reco2.pt, ISMEAR); } else { ptReco1 = smearPT -> PTsmear(reco1GenPostFSR.pt, reco1GenPostFSR.eta, reco1GenPostFSR.charge, reco1.pt, ISMEAR); ptReco2 = smearPT -> PTsmear(reco2GenPostFSR.pt, reco2GenPostFSR.eta, reco2GenPostFSR.charge, reco2.pt, ISMEAR); } TLorentzVector reco1Vec; TLorentzVector reco2Vec; reco1Vec.SetPtEtaPhiM(ptReco1,reco1.eta,reco1.phi,MASS_MUON); reco2Vec.SetPtEtaPhiM(ptReco2,reco2.eta,reco2.phi,MASS_MUON); TLorentzVector diMuonVec = reco1Vec + reco2Vec; reco1.pt = ptReco1; reco2.pt = ptReco2; recoCandMass = diMuonVec.M(); recoCandPt = diMuonVec.Pt(); recoCandY = diMuonVec.Rapidity(); recoCandPhi = diMuonVec.Phi(); reco1Vec.SetPtEtaPhiM(ptReco1,reco1.eta,reco1.phi,MASS_MUON); reco2Vec.SetPtEtaPhiM(ptReco2,reco2.eta,reco2.phi,MASS_MUON); diMuonVec = reco1Vec + reco2Vec; } ////////////////////////////////////////// // Muon-related cuts if (recoCandMass > maxMmm || recoCandMass < minMmm) continue; bool muon1PassId = (*muonIdFuncPtr)(reco1); bool muon2PassId = (*muonIdFuncPtr)(reco2); if ( !(muon1PassId && muon2PassId)) continue; bool muon1PassIso = (getPFRelIso(reco1) <= 0.12); bool muon2PassIso = (getPFRelIso(reco2) <= 0.12); if ( !(muon1PassIso && muon2PassIso)) continue; // Order muons by pt if (reco1.pt < reco2.pt) { _MuonInfo tmpMuon = reco1; reco1 = reco2; reco1 = tmpMuon; } // PU reweight float weight = 1.; if (!isData) { weight *= lumiWeights.weight(nPU); } // Jet Part // Do basic selection on jets and JER corrections std::vector<TLorentzVector> jets; std::vector<TLorentzVector> genJets; const float jetPtCut = 30.; const float jetAbsEtaCut = 4.7; const int jetPUIDCut = 4; // >= tight = 7, medium = 6, loose = 4. Only loose is useful!! for(unsigned iJet=0; (iJet < unsigned(rawJets.nJets) && iJet < 10);iJet++) { // apply jet energy resolution corrections if (rawJets.genPt[iJet]>0.0 && rawJets.pt[iJet]>15.) rawJets.pt[iJet] = jerCorr(rawJets.pt[iJet],rawJets.genPt[iJet],rawJets.eta[iJet]); bool goodPt = rawJets.pt[iJet]>jetPtCut; bool goodEta = fabs(rawJets.eta[iJet])<jetAbsEtaCut; bool goodPUID = puJetFullId[iJet] >= jetPUIDCut; if (goodPt && goodEta && goodPUID) { TLorentzVector tmpJetVec; tmpJetVec.SetPtEtaPhiM(rawJets.pt[iJet],rawJets.eta[iJet],rawJets.phi[iJet],rawJets.mass[iJet]); jets.push_back(tmpJetVec); TLorentzVector tmpGenJetVec; tmpGenJetVec.SetPtEtaPhiM(rawJets.genPt[iJet],rawJets.genEta[iJet],rawJets.genPhi[iJet],rawJets.genMass[iJet]); genJets.push_back(tmpGenJetVec); } } // ///////////////////////////////////////////// // // cout << "Event: "<< eventInfo.run << ":" << eventInfo.event << endl; // // // print muon-related info // cout << "recoCandMass: " << recoCandMass << endl; // cout << "muon Pt1: " << reco1.pt << endl; // cout << "muon Pt2: " << reco2.pt << endl; // cout << "muon eta1: " << reco1.eta << endl; // cout << "muon eta2: " << reco2.eta << endl; // cout << "muon iso1: " << getPFRelIso(reco1) << endl; // cout << "muon iso2: " << getPFRelIso(reco2) << endl; // cout << "PU weight: " << weight << endl; // cout << endl; // // // print jet-related info // cout << "nJets: " << jets.size() << endl; // for (unsigned iJet=0; iJet < jets.size(); iJet++) // { // cout << "Jet "<<(iJet+1)<<": pt="<< jets[iJet].Pt() << " eta="<<jets[iJet].Eta()<<endl; // } // cout << endl; // // ///////////////////////////////////////////// // Fill Histograms dimuonMassHist->Fill(recoCandMass,weight); nJetsHist->Fill(jets.size(),weight); } TFile* outFile = new TFile(outputFileName,"RECREATE"); outFile->cd(); dimuonMassHist->Write(); nJetsHist->Write(); }