void rochcor::momcor_mc( TLorentzVector& mu, float charge, float sysdev, int runopt){ //sysdev == num : deviation = num float ptmu = mu.Pt(); float muphi = mu.Phi(); float mueta = mu.Eta(); // same with mu.Eta() in Root float px = mu.Px(); float py = mu.Py(); float pz = mu.Pz(); float e = mu.E(); int mu_phibin = phibin(muphi); int mu_etabin = etabin(mueta); //float mptsys = sran.Gaus(0.0,sysdev); float dm = (mcor_bf[mu_phibin][mu_etabin] + mptsys_mc_dm[mu_phibin][mu_etabin]*mcor_bfer[mu_phibin][mu_etabin])/mmavg[mu_phibin][mu_etabin]; float da = mcor_ma[mu_phibin][mu_etabin] + mptsys_mc_da[mu_phibin][mu_etabin]*mcor_maer[mu_phibin][mu_etabin]; float cor = 1.0/(1.0 + dm + charge*da*ptmu); //for the momentum tuning - eta,phi,Q correction px *= cor; py *= cor; pz *= cor; e *= cor; float gscler = 0.0; float deltaer = 0.0; float sfer = 0.0; gscler = TMath::Sqrt( TMath::Power(mgscl_stat,2) + TMath::Power(mgscl_syst,2) ); deltaer = TMath::Sqrt( TMath::Power(delta_stat,2) + TMath::Power(delta_syst,2) ); sfer = TMath::Sqrt( TMath::Power(sf_stat,2) + TMath::Power(sf_syst,2) ); float tune = 1.0/(1.0 + (delta + sysdev*deltaer)*sqrt(px*px + py*py)*eran.Gaus(1.0,(sf + sysdev*sfer))); px *= (tune); py *= (tune); pz *= (tune); e *= (tune); float gscl = (genm_smr/mrecm); px *= (gscl + gscler_mc_dev*gscler); py *= (gscl + gscler_mc_dev*gscler); pz *= (gscl + gscler_mc_dev*gscler); e *= (gscl + gscler_mc_dev*gscler); mu.SetPxPyPzE(px,py,pz,e); }
double Histogrammer::minDrPhoB(int PhoInd, EventTree* tree){ // find the closest b-jet TLorentzVector b; TLorentzVector bBar; int phoGen=-1; double mindr = 999.0; for( int mcI = 0; mcI < tree->nMC_; ++mcI){ if( tree->mcIndex->at(mcI) == tree->phoGenIndex_->at(PhoInd) ) phoGen=mcI; if( tree->mcPID->at(mcI) == 5) b.SetPtEtaPhiM(tree->mcPt->at(mcI), tree->mcEta->at(mcI), tree->mcPhi->at(mcI), tree->mcMass->at(mcI)); if( tree->mcPID->at(mcI) == -5) bBar.SetPtEtaPhiM(tree->mcPt->at(mcI), tree->mcEta->at(mcI), tree->mcPhi->at(mcI), tree->mcMass->at(mcI)); } if( phoGen > 0 && b.Pt() > 0.0001 && bBar.Pt() > 0.0001 ) { mindr = std::min(dR(tree->mcEta->at(phoGen), tree->mcPhi->at(phoGen), b.Eta(), b.Phi()), dR(tree->mcEta->at(phoGen), tree->mcPhi->at(phoGen), bBar.Eta(), bBar.Phi())); } return mindr; }
void rochcor2012jan22::momcor_mc( TLorentzVector& mu, float charge, int runopt, float& qter){ //sysdev == num : deviation = num float ptmu = mu.Pt(); float muphi = mu.Phi(); float mueta = mu.Eta(); // same with mu.Eta() in Root float px = mu.Px(); float py = mu.Py(); float pz = mu.Pz(); float e = mu.E(); int mu_phibin = phibin(muphi); int mu_etabin = etabin(mueta); if(mu_phibin>=0 && mu_etabin>=0){ float Mf = (mcor_bf[mu_phibin][mu_etabin] + mptsys_mc_dm[mu_phibin][mu_etabin]*mcor_bfer[mu_phibin][mu_etabin])/(mpavg[mu_phibin][mu_etabin]+mmavg[mu_phibin][mu_etabin]); float Af = ((mcor_ma[mu_phibin][mu_etabin]+mptsys_mc_da[mu_phibin][mu_etabin]*mcor_maer[mu_phibin][mu_etabin]) - Mf*(mpavg[mu_phibin][mu_etabin]-mmavg[mu_phibin][mu_etabin])); float cor = 1.0/(1.0 + 2.0*Mf + charge*Af*ptmu); //for the momentum tuning - eta,phi,Q correction px *= cor; py *= cor; pz *= cor; e *= cor; float gscler = mgscl_stat; float gscl = (genm_smr/mrecm); px *= (gscl + gscler_mc_dev*gscler); py *= (gscl + gscler_mc_dev*gscler); pz *= (gscl + gscler_mc_dev*gscler); e *= (gscl + gscler_mc_dev*gscler); float momscl = sqrt(px*px + py*py)/ptmu; float tune = gsf[mu_etabin]*eran.Gaus(1.0,sf[mu_etabin]); px *= (tune); py *= (tune); pz *= (tune); e *= (tune); qter *= sqrt(momscl*momscl + (1.0-tune)*(1.0-tune)); } mu.SetPxPyPzE(px,py,pz,e); }
void rochcor2012::momcor_data( TLorentzVector& mu, float charge, int runopt, float& qter){ float ptmu = mu.Pt(); float muphi = mu.Phi(); float mueta = mu.Eta(); // same with mu.Eta() in Root float px = mu.Px(); float py = mu.Py(); float pz = mu.Pz(); float e = mu.E(); int mu_phibin = phibin(muphi); int mu_etabin = etabin(mueta); float Mf = 0.0; float Af = 0.0; if(runopt==0){ Mf = (dcor_bf[mu_phibin][mu_etabin]+mptsys_da_dm[mu_phibin][mu_etabin]*dcor_bfer[mu_phibin][mu_etabin])/(dpavg[mu_phibin][mu_etabin]+dmavg[mu_phibin][mu_etabin]); Af = ((dcor_ma[mu_phibin][mu_etabin]+mptsys_da_da[mu_phibin][mu_etabin]*dcor_maer[mu_phibin][mu_etabin]) - Mf*(dpavg[mu_phibin][mu_etabin]-dmavg[mu_phibin][mu_etabin])); }else if(runopt==1){ Mf = (dcor_bfD[mu_phibin][mu_etabin]+mptsys_da_dm[mu_phibin][mu_etabin]*dcor_bfDer[mu_phibin][mu_etabin])/(dpavgD[mu_phibin][mu_etabin]+dmavgD[mu_phibin][mu_etabin]); Af = ((dcor_maD[mu_phibin][mu_etabin]+mptsys_da_da[mu_phibin][mu_etabin]*dcor_maDer[mu_phibin][mu_etabin]) - Mf*(dpavgD[mu_phibin][mu_etabin]-dmavgD[mu_phibin][mu_etabin])); } float cor = 1.0/(1.0 + 2.0*Mf + charge*Af*ptmu); px *= cor; py *= cor; pz *= cor; e *= cor; //after Z pt correction float gscler = dgscl_stat; float gscl = (genm_smr/drecm); px *= (gscl + gscler_da_dev*gscler); py *= (gscl + gscler_da_dev*gscler); pz *= (gscl + gscler_da_dev*gscler); e *= (gscl + gscler_da_dev*gscler); float momscl = sqrt(px*px + py*py)/ptmu; qter *= momscl; mu.SetPxPyPzE(px,py,pz,e); }
TLorentzVector doCalEnergy(double BeamEnergy, TLorentzVector Particle1, TLorentzVector Particle2, double nucleusMass, double Particle2Mass, double Particle3Mass) { double E_Particle1 = Particle1.E(); double p_Particle1_x = Particle1.Px(); double p_Particle1_y = Particle1.Py(); double p_Particle1_z = Particle1.Pz(); double p_Particle1 = sqrt(TMath::Power(p_Particle1_x,2.0) + TMath::Power(p_Particle1_y,2.0) + TMath::Power(p_Particle1_z,2.0)); double phi = Particle2.Phi(); double theta = Particle2.Theta(); double b = 2.0 * ( p_Particle1_x * cos(phi) * sin(theta) + p_Particle1_y * sin(phi) * sin(theta) + p_Particle1_z * cos(theta) - BeamEnergy * cos(theta) ); double c = p_Particle1 * p_Particle1 + BeamEnergy * BeamEnergy - 2.0 * BeamEnergy * p_Particle1_z; double d = BeamEnergy + nucleusMass - E_Particle1; double e = TMath::Power(Particle3Mass,2.0) - TMath::Power(Particle2Mass,2.0) - d * d + c; double Delta = 16.0 * TMath::Power(d,2.0) * (TMath::Power(e,2.0) + TMath::Power(b * Particle2Mass,2.0) - TMath::Power(d * Particle2Mass * 2.0,2.0)); TLorentzVector NewParticle(0.0,0.0,0.0,0.0); if(Delta>0.) { double sol2 = (2.0 * e * b + sqrt(Delta)) / (2.0 * (4.0 * TMath::Power(d,2.0) - TMath::Power(b,2.0))); double newpxcal = sol2 * cos(phi) * sin(theta); double newpycal = sol2 * sin(phi) * sin(theta); double newpzcal = sol2 * cos(theta); double energy = sqrt(TMath::Power(sol2,2.0) + TMath::Power(Particle2Mass,2.0)); TLorentzVector NewParticle2(newpxcal,newpycal,newpzcal,energy); NewParticle = NewParticle2; } return NewParticle; }
void rochcor::momcor_data( TLorentzVector& mu, float charge, float sysdev, int runopt){ float ptmu = mu.Pt(); float muphi = mu.Phi(); float mueta = mu.Eta(); // same with mu.Eta() in Root float px = mu.Px(); float py = mu.Py(); float pz = mu.Pz(); float e = mu.E(); int mu_phibin = phibin(muphi); int mu_etabin = etabin(mueta); //float mptsys1 = sran.Gaus(0.0,sysdev); float dm = (dcor_bf[mu_phibin][mu_etabin] + mptsys_da_dm[mu_phibin][mu_etabin]*dcor_bfer[mu_phibin][mu_etabin])/dmavg[mu_phibin][mu_etabin]; float da = dcor_ma[mu_phibin][mu_etabin] + mptsys_da_da[mu_phibin][mu_etabin]*dcor_maer[mu_phibin][mu_etabin]; float cor = 1.0/(1.0 + dm + charge*da*ptmu); px *= cor; py *= cor; pz *= cor; e *= cor; //after Z pt correction float gscler = 0.0; gscler = TMath::Sqrt( TMath::Power(dgscl_stat,2) + TMath::Power(dgscl_syst,2) ); float gscl = (genm_smr/drecm); px *= (gscl + gscler_da_dev*gscler); py *= (gscl + gscler_da_dev*gscler); pz *= (gscl + gscler_da_dev*gscler); e *= (gscl + gscler_da_dev*gscler); mu.SetPxPyPzE(px,py,pz,e); }
double Delta(double pt1, double eta1, double phi1,double pt2, double eta2, double phi2,double t1pfmetPhi){ TLorentzVector fLorentzVec1; TLorentzVector fLorentzVec2; TLorentzVector fLorentzVecgg; // Fill TLorentzVector fLorentzVec1.SetPtEtaPhiM(pt1,eta1,phi1,0.); fLorentzVec2.SetPtEtaPhiM(pt2,eta2,phi2,0.); fLorentzVecgg = fLorentzVec1 + fLorentzVec2; double phigg= fLorentzVecgg.Phi(); double delta = phigg-t1pfmetPhi; if(delta>3.14){ delta-=6.28; } if(delta<-3.14){ delta+=6.28; } delta =fabs(delta); return delta; }
void smearEmEnergy( TLorentzVector& p ) { float smearEBlowEta = 0.013898; float smearEBhighEta = 0.0189895; float smearEElowEta = 0.027686; float smearEEhighEta = 0.031312; float theGaussMean = 1.; float pt = p.Pt(); float eta = p.Eta(); float phi = p.Phi(); float mass = p.M(); float theSmear = 0.; if (fabs(eta)<1. ) theSmear = smearEBlowEta; else if (fabs(eta)>=1. && fabs(eta)<1.5) theSmear = smearEBhighEta; else if (fabs(eta)>=1.5 && fabs(eta)<2. ) theSmear = smearEElowEta; else if (fabs(eta)>=2. && fabs(eta)<2.5) theSmear = smearEEhighEta; float fromGauss = myRandom_.Gaus(theGaussMean,theSmear); p.SetPtEtaPhiM( fromGauss*pt, eta, phi, mass ); // keep mass and direction same }
std::vector<double> CalculateDeltaEtaAndPhi(bool possibleMultW, bool possibleMultAntiW, int w1, TLorentzVector TL_munu){ //Don't take into account the events with multiple W's. Think of something double deltaphi, deltaeta; if(possibleMultW == false && possibleMultAntiW == false){ deltaphi = TMath::Abs(TVector2::Phi_mpi_pi(TL_munu.Phi() - genPhi[w1]) ); deltaeta = TMath::Abs(TL_munu.Eta() - genEta[w1] ); } else { deltaphi = 99.; deltaeta = 99.; } std::vector<double> EtaAndPhi; EtaAndPhi.push_back(deltaeta); EtaAndPhi.push_back(deltaphi); return EtaAndPhi; }
int main( int argc, char* argv[] ) { std::string filename; if( use76 ) filename = "dcap://t3se01.psi.ch:22125//pnfs/psi.ch/cms/trivcat/store/user/mschoene/MT2production/76X/Spring15/PostProcessed/12Feb2016_ZGammaMC/ZGTo2LG_post.root"; else filename = "dcap://t3se01.psi.ch:22125//pnfs/psi.ch/cms/trivcat/store/user/mmasciov/MT2production/74X/Spring15/PostProcessed/20Dec2015_forGunther/ZGTo2LG_post.root"; TFile* file = TFile::Open(filename.c_str()); TTree* tree = (TTree*)file->Get("mt2"); std::cout << "-> Opened file: " << filename << std::endl; TFile* puFile_data = TFile::Open("puData.root"); TH1D* h1_nVert_data = (TH1D*)puFile_data->Get("nVert"); TFile* puFile_mc = TFile::Open("puMC.root"); TH1D* h1_nVert_mc = (TH1D*)puFile_mc->Get("nVert"); ZGTree myTree; myTree.loadGenStuff = true; myTree.Init(tree); TFile* outFile; if( use76 ) outFile = TFile::Open("genEfficiency76.root", "recreate"); else outFile = TFile::Open("genEfficiency.root", "recreate"); outFile->cd(); int nBins = 8; Double_t bins[nBins+1]; bins[0] = 300.; bins[1] = 350.; bins[2] = 400.; bins[3] = 450.; bins[4] = 500.; bins[5] = 600.; bins[6] = 700.; bins[7] = 800.; bins[8] = 950.; TH1D* h1_eff_denom = new TH1D( "eff_denom", "", nBins, bins ); h1_eff_denom->Sumw2(); TH1D* h1_eff_denom_ee = new TH1D( "eff_denom_ee", "", nBins, bins ); h1_eff_denom_ee->Sumw2(); TH1D* h1_eff_denom_mm = new TH1D( "eff_denom_mm", "", nBins, bins ); h1_eff_denom_mm->Sumw2(); TH1D* h1_eff_all_num = new TH1D( "eff_all_num", "", nBins, bins ); h1_eff_all_num->Sumw2(); TH1D* h1_eff_ee_num = new TH1D( "eff_ee_num", "", nBins, bins ); h1_eff_ee_num->Sumw2(); TH1D* h1_eff_mm_num = new TH1D( "eff_mm_num", "", nBins, bins ); h1_eff_mm_num->Sumw2(); TH1D* h1_eff_noHLT_num = new TH1D( "eff_noHLT_num", "", nBins, bins ); h1_eff_noHLT_num->Sumw2(); TH1D* h1_eff_noIso_num = new TH1D( "eff_noIso_num", "", nBins, bins ); h1_eff_noIso_num->Sumw2(); TH1D* h1_massBias = new TH1D( "massBias", "", nBins, bins ); h1_massBias->Sumw2(); TH1D* h1_massReso = new TH1D( "massReso", "", nBins, bins ); h1_massReso->Sumw2(); TH1D* h1_massBias_ee = new TH1D( "massBias_ee", "", nBins, bins ); h1_massBias_ee->Sumw2(); TH1D* h1_massReso_ee = new TH1D( "massReso_ee", "", nBins, bins ); h1_massReso_ee->Sumw2(); TH1D* h1_massBias_mm = new TH1D( "massBias_mm", "", nBins, bins ); h1_massBias_mm->Sumw2(); TH1D* h1_massReso_mm = new TH1D( "massReso_mm", "", nBins, bins ); h1_massReso_mm->Sumw2(); std::vector<TH1D*> vh1_massReso, vh1_massReso_ee, vh1_massReso_mm; for( int i=0; i<nBins; ++i ) { TH1D* h1_tmp = new TH1D( Form("reso_%d", i), "", 40, -0.2, 0.2); h1_tmp->Sumw2(); vh1_massReso.push_back( h1_tmp ); TH1D* h1_tmp_ee = new TH1D( Form("reso_ee_%d", i), "", 40, -0.2, 0.2); h1_tmp_ee->Sumw2(); vh1_massReso_ee.push_back( h1_tmp_ee ); TH1D* h1_tmp_mm = new TH1D( Form("reso_mm_%d", i), "", 40, -0.2, 0.2); h1_tmp_mm->Sumw2(); vh1_massReso_mm.push_back( h1_tmp_mm ); } rochcor2015 *rmcor = new rochcor2015(); TTree* outtree = new TTree("genTree", ""); int leptType; outtree->Branch( "leptType", &leptType, "leptType/I" ); float gammaReco_pt; outtree->Branch( "gammaReco_pt", &gammaReco_pt, "gammaReco_pt/F" ); float gammaReco_eta; outtree->Branch( "gammaReco_eta", &gammaReco_eta, "gammaReco_eta/F" ); float gammaReco_phi; outtree->Branch( "gammaReco_phi", &gammaReco_phi, "gammaReco_phi/F" ); float gammaReco_mass; outtree->Branch( "gammaReco_mass", &gammaReco_mass, "gammaReco_mass/F" ); float lept0Reco_pt; outtree->Branch( "lept0Reco_pt", &lept0Reco_pt, "lept0Reco_pt/F" ); float lept0Reco_eta; outtree->Branch( "lept0Reco_eta", &lept0Reco_eta, "lept0Reco_eta/F" ); float lept0Reco_phi; outtree->Branch( "lept0Reco_phi", &lept0Reco_phi, "lept0Reco_phi/F" ); float lept0Reco_mass; outtree->Branch( "lept0Reco_mass", &lept0Reco_mass, "lept0Reco_mass/F" ); float lept1Reco_pt; outtree->Branch( "lept1Reco_pt", &lept1Reco_pt, "lept1Reco_pt/F" ); float lept1Reco_eta; outtree->Branch( "lept1Reco_eta", &lept1Reco_eta, "lept1Reco_eta/F" ); float lept1Reco_phi; outtree->Branch( "lept1Reco_phi", &lept1Reco_phi, "lept1Reco_phi/F" ); float lept1Reco_mass; outtree->Branch( "lept1Reco_mass", &lept1Reco_mass, "lept1Reco_mass/F" ); float zReco_pt; outtree->Branch( "zReco_pt", &zReco_pt, "zReco_pt/F" ); float zReco_eta; outtree->Branch( "zReco_eta", &zReco_eta, "zReco_eta/F" ); float zReco_phi; outtree->Branch( "zReco_phi", &zReco_phi, "zReco_phi/F" ); float zReco_mass; outtree->Branch( "zReco_mass", &zReco_mass, "zReco_mass/F" ); float bossReco_pt; outtree->Branch( "bossReco_pt", &bossReco_pt, "bossReco_pt/F" ); float bossReco_eta; outtree->Branch( "bossReco_eta", &bossReco_eta, "bossReco_eta/F" ); float bossReco_phi; outtree->Branch( "bossReco_phi", &bossReco_phi, "bossReco_phi/F" ); float bossReco_mass; outtree->Branch( "bossReco_mass", &bossReco_mass, "bossReco_mass/F" ); float gammaGen_pt; outtree->Branch( "gammaGen_pt", &gammaGen_pt, "gammaGen_pt/F" ); float gammaGen_eta; outtree->Branch( "gammaGen_eta", &gammaGen_eta, "gammaGen_eta/F" ); float gammaGen_phi; outtree->Branch( "gammaGen_phi", &gammaGen_phi, "gammaGen_phi/F" ); float gammaGen_mass; outtree->Branch( "gammaGen_mass", &gammaGen_mass, "gammaGen_mass/F" ); float lept0Gen_pt; outtree->Branch( "lept0Gen_pt", &lept0Gen_pt, "lept0Gen_pt/F" ); float lept0Gen_eta; outtree->Branch( "lept0Gen_eta", &lept0Gen_eta, "lept0Gen_eta/F" ); float lept0Gen_phi; outtree->Branch( "lept0Gen_phi", &lept0Gen_phi, "lept0Gen_phi/F" ); float lept0Gen_mass; outtree->Branch( "lept0Gen_mass", &lept0Gen_mass, "lept0Gen_mass/F" ); float lept1Gen_pt; outtree->Branch( "lept1Gen_pt", &lept1Gen_pt, "lept1Gen_pt/F" ); float lept1Gen_eta; outtree->Branch( "lept1Gen_eta", &lept1Gen_eta, "lept1Gen_eta/F" ); float lept1Gen_phi; outtree->Branch( "lept1Gen_phi", &lept1Gen_phi, "lept1Gen_phi/F" ); float lept1Gen_mass; outtree->Branch( "lept1Gen_mass", &lept1Gen_mass, "lept1Gen_mass/F" ); float zGen_pt; outtree->Branch( "zGen_pt", &zGen_pt, "zGen_pt/F" ); float zGen_eta; outtree->Branch( "zGen_eta", &zGen_eta, "zGen_eta/F" ); float zGen_phi; outtree->Branch( "zGen_phi", &zGen_phi, "zGen_phi/F" ); float zGen_mass; outtree->Branch( "zGen_mass", &zGen_mass, "zGen_mass/F" ); float bossGen_pt; outtree->Branch( "bossGen_pt", &bossGen_pt, "bossGen_pt/F" ); float bossGen_eta; outtree->Branch( "bossGen_eta", &bossGen_eta, "bossGen_eta/F" ); float bossGen_phi; outtree->Branch( "bossGen_phi", &bossGen_phi, "bossGen_phi/F" ); float bossGen_mass; outtree->Branch( "bossGen_mass", &bossGen_mass, "bossGen_mass/F" ); int nentries = tree->GetEntries(); for( int iEntry=0; iEntry<nentries; ++iEntry ) { if( iEntry % 50000 == 0 ) std::cout << " Entry: " << iEntry << " / " << nentries << std::endl; myTree.GetEntry(iEntry); float weight = (myTree.isData) ? 1. : myTree.evt_scale1fb; // pu reweighting: if( !myTree.isData ) { //weight *= myTree.puWeight; } // first find leptons //if( myTree.ngenLep!=2 ) continue; //TLorentzVector genLep0, genLep1; //genLep0.SetPtEtaPhiM( myTree.genLep_pt[0], myTree.genLep_eta[0], myTree.genLep_phi[0], myTree.genLep_mass[0] ); //genLep1.SetPtEtaPhiM( myTree.genLep_pt[1], myTree.genLep_eta[1], myTree.genLep_phi[1], myTree.genLep_mass[1] ); std::vector<TLorentzVector> genLeptons; int genLeptType = 0; for( int iGen=0; iGen<myTree.ngenPart && genLeptons.size()<2; ++iGen ) { if( myTree.genPart_pt[iGen]<1. ) continue; if( myTree.genPart_status[iGen]!=1 ) continue; if( abs(myTree.genPart_pdgId[iGen])!=11 && abs(myTree.genPart_pdgId[iGen])!=13 ) continue; if( myTree.genPart_motherId[iGen]!=myTree.genPart_pdgId[iGen] ) continue; TLorentzVector tmpLep; tmpLep.SetPtEtaPhiM( myTree.genPart_pt[iGen], myTree.genPart_eta[iGen], myTree.genPart_phi[iGen], myTree.genPart_mass[iGen] ); genLeptons.push_back(tmpLep); genLeptType = abs(myTree.genPart_pdgId[iGen]); } if( genLeptType!=11 && genLeptType!=13 ) continue; if( genLeptons.size()<2 ) continue; TLorentzVector genLep0, genLep1; genLep0 = genLeptons[0]; genLep1 = genLeptons[1]; float maxPt = TMath::Max( genLep0.Pt(), genLep1.Pt() ); float minPt = TMath::Min( genLep0.Pt(), genLep1.Pt() ); if( maxPt<25. ) continue; if( minPt<20. ) continue; if( fabs(genLep0.Eta()) > 2.4 ) continue; if( fabs(genLep1.Eta()) > 2.4 ) continue; TLorentzVector genZ = genLep0 + genLep1; if( genZ.M()<50. ) continue; //if( genZ.M()<50. || genZ.M()>130. ) continue; TLorentzVector genPhoton; bool foundGenPhoton = false; for( int iGen=0; iGen<myTree.ngenPart && !foundGenPhoton; ++iGen ) { if( myTree.genPart_pdgId[iGen]!=22 ) continue; if( myTree.genPart_status[iGen]!=1 ) continue; if( myTree.genPart_pt[iGen]<40. ) continue; if( fabs(myTree.genPart_eta[iGen])>2.5 ) continue; TLorentzVector photon_temp; photon_temp.SetPtEtaPhiM( myTree.genPart_pt[iGen], myTree.genPart_eta[iGen], myTree.genPart_phi[iGen], myTree.genPart_mass[iGen] ); float deltaRmin_part = 999.; // look for closest parton for( int jGen=0; jGen<myTree.ngenPart && iGen!=jGen; ++jGen ) { if( myTree.genPart_pt[jGen]<1. ) continue; if( myTree.genPart_status[jGen]<=21 ) continue; bool isParton = ( myTree.genPart_pdgId[jGen]==21 || abs(myTree.genPart_pdgId[jGen])<7 ); if( !isParton ) continue; TLorentzVector thisparton; thisparton.SetPtEtaPhiM( myTree.genPart_pt[jGen], myTree.genPart_eta[jGen], myTree.genPart_phi[jGen], myTree.genPart_mass[jGen] ); float thisDeltaR = thisparton.DeltaR(photon_temp); if( thisDeltaR<deltaRmin_part ) { deltaRmin_part = thisDeltaR; } } // far away from partons if( deltaRmin_part<0.4 ) continue; // far away from leptons if( photon_temp.DeltaR( genLep0 ) > 0.4 && photon_temp.DeltaR( genLep1 ) > 0.4 ) { genPhoton.SetPtEtaPhiM( myTree.genPart_pt[iGen], myTree.genPart_eta[iGen], myTree.genPart_phi[iGen], myTree.genPart_mass[iGen] ); foundGenPhoton = true; } } if( !foundGenPhoton ) continue; if( genPhoton.Pt()<40. ) continue; if( fabs(genPhoton.Eta())>2.5 ) continue; if( fabs(genPhoton.Eta())>1.44 && fabs(genPhoton.Eta())<1.57 ) continue; TLorentzVector genBoss = genZ + genPhoton; float genMass = genBoss.M(); if( genMass<200. ) continue; h1_eff_denom->Fill( genMass, weight ); if( genLeptType==11 ) h1_eff_denom_ee->Fill( genMass, weight ); else h1_eff_denom_mm->Fill( genMass, weight ); // and now reco! if( myTree.nVert==0 ) continue; if( myTree.nlep!=2 ) continue; // two leptons if( myTree.lep_pdgId[0] != -myTree.lep_pdgId[1] ) continue; // same flavour, opposite sign leptType = abs(myTree.lep_pdgId[0]); if( leptType!=11 && leptType!=13 ) continue; // just in case TLorentzVector lept0; lept0.SetPtEtaPhiM( myTree.lep_pt[0], myTree.lep_eta[0], myTree.lep_phi[0], myTree.lep_mass[0] ); TLorentzVector lept1; lept1.SetPtEtaPhiM( myTree.lep_pt[1], myTree.lep_eta[1], myTree.lep_phi[1], myTree.lep_mass[1] ); if( lept0.Pt()<25. ) continue; if( lept1.Pt()<20. ) continue; if( leptType==11 ) { //electrons if( myTree.lep_tightId[0]==0 || myTree.lep_tightId[1]==0 ) continue; // loose electron ID } else { // muons float qter = 1.0; rmcor->momcor_mc(lept0, myTree.lep_pdgId[0]/(abs(myTree.lep_pdgId[0])), 0, qter); rmcor->momcor_mc(lept1, myTree.lep_pdgId[1]/(abs(myTree.lep_pdgId[1])), 0, qter); //if( myTree.lep_tightId[0]==0 && myTree.lep_tightId[1]==0 ) continue; // tight muon ID on one leg } TLorentzVector zBoson = lept0+lept1; if( zBoson.M()<50. ) continue; //if( zBoson.M()<50. || zBoson.M()>130. ) continue; if( myTree.ngamma==0 ) continue; // photon bool foundPhoton = false; TLorentzVector photon; for( int iPhot=0; iPhot<myTree.ngamma && !foundPhoton; ++iPhot ) { TLorentzVector tmp_photon; tmp_photon.SetPtEtaPhiM( myTree.gamma_pt[iPhot], myTree.gamma_eta[iPhot], myTree.gamma_phi[iPhot], myTree.gamma_mass[iPhot] ); if( tmp_photon.Pt()<40. ) continue; if( fabs(tmp_photon.Eta())>1.44 && fabs(tmp_photon.Eta())<1.57 ) continue; if( fabs(tmp_photon.Eta())>2.5 ) continue; if( myTree.gamma_idCutBased[iPhot]==0 ) continue; //if( fabs(myTree.gamma_eta[iPhot])<1.44 ) { // if( myTree.gamma_sigmaIetaIeta[iPhot]>0.0102 ) continue; //} else { // if( myTree.gamma_sigmaIetaIeta[iPhot]>0.0274 ) continue; //} float deltaR_thresh = 0.4; if( tmp_photon.DeltaR(lept0)<deltaR_thresh || tmp_photon.DeltaR(lept1)<deltaR_thresh ) continue; photon.SetPtEtaPhiM( myTree.gamma_pt[iPhot], myTree.gamma_eta[iPhot], myTree.gamma_phi[iPhot], myTree.gamma_mass[iPhot] ); foundPhoton = true; } if( !foundPhoton ) continue; smearEmEnergy( photon ); TLorentzVector boss = zBoson + photon; float recoMass = boss.M(); if( recoMass<200. ) continue; h1_eff_noHLT_num->Fill( genMass, weight ); if( !( myTree.HLT_DoubleEl || myTree.HLT_DoubleMu || myTree.HLT_DoubleEl33 || myTree.HLT_SingleMu ) ) continue; h1_eff_noIso_num->Fill( genMass, weight ); if( myTree.gamma_chHadIso[0]>2.5 ) continue; h1_eff_all_num->Fill( genMass, weight ); if( leptType==11 ) h1_eff_ee_num->Fill( genMass, weight ); else h1_eff_mm_num->Fill( genMass, weight ); int iBin = h1_eff_all_num->FindBin( genMass ) - 1; if( iBin>=0 && iBin<vh1_massReso.size() ) { vh1_massReso[iBin]->Fill( (recoMass-genMass)/genMass, weight ); if( leptType==11 ) { vh1_massReso_ee[iBin]->Fill( (recoMass-genMass)/genMass, weight ); } else { vh1_massReso_mm[iBin]->Fill( (recoMass-genMass)/genMass, weight ); } } // set tree branches and fill tree gammaReco_pt = photon.Pt(); gammaReco_eta = photon.Eta(); gammaReco_phi = photon.Phi(); gammaReco_mass = photon.M(); lept0Reco_pt = lept0.Pt(); lept0Reco_eta = lept0.Eta(); lept0Reco_phi = lept0.Phi(); lept0Reco_mass = lept0.M(); lept1Reco_pt = lept1.Pt(); lept1Reco_eta = lept1.Eta(); lept1Reco_phi = lept1.Phi(); lept1Reco_mass = lept1.M(); zReco_pt = zBoson.Pt(); zReco_eta = zBoson.Eta(); zReco_phi = zBoson.Phi(); zReco_mass = zBoson.M(); bossReco_pt = boss.Pt(); bossReco_eta = boss.Eta(); bossReco_phi = boss.Phi(); bossReco_mass = boss.M(); gammaGen_pt = genPhoton.Pt(); gammaGen_eta = genPhoton.Eta(); gammaGen_phi = genPhoton.Phi(); gammaGen_mass = genPhoton.M(); lept0Gen_pt = genLep0.Pt(); lept0Gen_eta = genLep0.Eta(); lept0Gen_phi = genLep0.Phi(); lept0Gen_mass = genLep0.M(); lept1Gen_pt = genLep1.Pt(); lept1Gen_eta = genLep1.Eta(); lept1Gen_phi = genLep1.Phi(); lept1Gen_mass = genLep1.M(); zGen_pt = genZ.Pt(); zGen_eta = genZ.Eta(); zGen_phi = genZ.Phi(); zGen_mass = genZ.M(); bossGen_pt = genBoss.Pt(); bossGen_eta = genBoss.Eta(); bossGen_phi = genBoss.Phi(); bossGen_mass = genBoss.M(); outtree->Fill(); } // for entries outFile->cd(); h1_eff_denom->Write(); h1_eff_denom_ee->Write(); h1_eff_denom_mm->Write(); h1_eff_all_num->Write(); h1_eff_ee_num->Write(); h1_eff_mm_num->Write(); h1_eff_noHLT_num->Write(); h1_eff_noIso_num->Write(); TEfficiency* eff_all = new TEfficiency( *h1_eff_all_num, *h1_eff_denom); eff_all->SetName( "eff_all" ); eff_all->Write(); TEfficiency* eff_ee = new TEfficiency( *h1_eff_ee_num, *h1_eff_denom_ee); eff_ee->SetName( "eff_ee" ); eff_ee->Write(); TEfficiency* eff_mm = new TEfficiency( *h1_eff_mm_num, *h1_eff_denom_mm); eff_mm->SetName( "eff_mm" ); eff_mm->Write(); TEfficiency* eff_noHLT = new TEfficiency( *h1_eff_noHLT_num, *h1_eff_denom); eff_noHLT->SetName( "eff_noHLT" ); eff_noHLT->Write(); TEfficiency* eff_noIso = new TEfficiency( *h1_eff_noIso_num, *h1_eff_denom); eff_noIso->SetName( "eff_noIso" ); eff_noIso->Write(); for( unsigned i=0; i<vh1_massReso.size(); ++i ) { h1_massBias->SetBinContent( i+1, vh1_massReso[i]->GetMean() ); h1_massReso->SetBinContent( i+1, vh1_massReso[i]->GetRMS() ); h1_massBias->SetBinError ( i+1, vh1_massReso[i]->GetMeanError() ); h1_massReso->SetBinError ( i+1, vh1_massReso[i]->GetRMSError() ); h1_massBias_ee->SetBinContent( i+1, vh1_massReso_ee[i]->GetMean() ); h1_massReso_ee->SetBinContent( i+1, vh1_massReso_ee[i]->GetRMS() ); h1_massBias_ee->SetBinError ( i+1, vh1_massReso_ee[i]->GetMeanError() ); h1_massReso_ee->SetBinError ( i+1, vh1_massReso_ee[i]->GetRMSError() ); h1_massBias_mm->SetBinContent( i+1, vh1_massReso_mm[i]->GetMean() ); h1_massReso_mm->SetBinContent( i+1, vh1_massReso_mm[i]->GetRMS() ); h1_massBias_mm->SetBinError ( i+1, vh1_massReso_mm[i]->GetMeanError() ); h1_massReso_mm->SetBinError ( i+1, vh1_massReso_mm[i]->GetRMSError() ); vh1_massReso[i]->Write(); vh1_massReso_ee[i]->Write(); vh1_massReso_mm[i]->Write(); } h1_massReso->Write(); h1_massBias->Write(); h1_massReso_ee->Write(); h1_massBias_ee->Write(); h1_massReso_mm->Write(); h1_massBias_mm->Write(); outtree->Write(); outFile->Close(); return 0; }
void fill(int const kf, TLorentzVector* b, double const weight, TClonesArray& daughters) { TLorentzVector kMom; TLorentzVector p1Mom; TLorentzVector p2Mom; int nTrk = daughters.GetEntriesFast(); for (int iTrk = 0; iTrk < nTrk; ++iTrk) { TParticle* ptl0 = (TParticle*)daughters.At(iTrk); switch(abs(ptl0->GetPdgCode())) { case 321: ptl0->Momentum(kMom); break; case 211: if(!p1Mom.P()) ptl0->Momentum(p1Mom); else ptl0->Momentum(p2Mom); break; default: break; } } daughters.Clear(); // smear and get total momentum TLorentzVector kRMom = smearMom(kMom,fKaonMomResolution); TLorentzVector p1RMom = smearMom(p1Mom,fPionMomResolution); TLorentzVector p2RMom = smearMom(p2Mom,fPionMomResolution); TLorentzVector rMom = kRMom + p1RMom + p2RMom; // save float arr[100]; int iArr = 0; arr[iArr++] = kf; arr[iArr++] = weight; arr[iArr++] = b->M(); arr[iArr++] = b->Perp(); arr[iArr++] = b->PseudoRapidity(); arr[iArr++] = b->Rapidity(); arr[iArr++] = b->Phi(); arr[iArr++] = rMom.M(); arr[iArr++] = rMom.Perp(); arr[iArr++] = rMom.PseudoRapidity(); arr[iArr++] = rMom.Rapidity(); arr[iArr++] = rMom.Phi(); arr[iArr++] = kMom.M(); arr[iArr++] = kMom.Perp(); arr[iArr++] = kMom.PseudoRapidity(); arr[iArr++] = kMom.Rapidity(); arr[iArr++] = kMom.Phi(); arr[iArr++] = kRMom.M(); arr[iArr++] = kRMom.Perp(); arr[iArr++] = kRMom.PseudoRapidity(); arr[iArr++] = kRMom.Rapidity(); arr[iArr++] = kRMom.Phi(); arr[iArr++] = p1Mom.M(); arr[iArr++] = p1Mom.Perp(); arr[iArr++] = p1Mom.PseudoRapidity(); arr[iArr++] = p1Mom.Rapidity(); arr[iArr++] = p1Mom.Phi(); arr[iArr++] = p1RMom.M(); arr[iArr++] = p1RMom.Perp(); arr[iArr++] = p1RMom.PseudoRapidity(); arr[iArr++] = p1RMom.Rapidity(); arr[iArr++] = p1RMom.Phi(); arr[iArr++] = p2Mom.M(); arr[iArr++] = p2Mom.Perp(); arr[iArr++] = p2Mom.PseudoRapidity(); arr[iArr++] = p2Mom.Rapidity(); arr[iArr++] = p2Mom.Phi(); arr[iArr++] = p2RMom.M(); arr[iArr++] = p2RMom.Perp(); arr[iArr++] = p2RMom.PseudoRapidity(); arr[iArr++] = p2RMom.Rapidity(); arr[iArr++] = p2RMom.Phi(); nt->Fill(arr); }
void skim(std::string var, TTree *fullTree, TTree *newTree, std::string cutstr, bool isWeighted , bool reweighted, bool addDiMuSel, bool addMuSel, bool addPhoSel){ std::cout << fullTree->GetName() << " -> " << newTree->GetName() << " " << cutstr.c_str() << std::endl; fullTree->Draw(">>cutlist",cutstr.c_str()); TEventList *keep_points = (TEventList*)gDirectory->Get("cutlist"); int nEntries = fullTree->GetEntries(); float x,x_orig; float mvametPhi, metRaw; float mvametPhiCor ;// corected phis for deltaPhi(met,jet) cut (// NOT to be used in calculation of MT!) float weight, weight_wpt, weight_in, weight_in_pu; float catvar1,catvar2,catvar3,catvar4,catvar5,catvar6; // These are empty, do as we want with them float tau1,tau2; float dimuM, mt; // used for the W/Z selection int passVBF; unsigned int njets; unsigned int nphotons; float phopt, phoeta; // Why do we use these? float metBasicPhi, metBasic; // Used for reweighting if needed ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *genZ = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); TBranch *brgenZ ; // W/Z selection for leptions ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *lepV = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *lep2V = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); TBranch *brlep = fullTree->GetBranch("lep1"); TBranch *brlep_2 = fullTree->GetBranch("lep2"); brlep->SetAddress(&lepV); brlep_2->SetAddress(&lep2V); // Check VBF selection ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *jetV = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *jet2V = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); // Also need these for second jet veto TBranch *brjet = fullTree->GetBranch("jet1"); TBranch *brjet_2 = fullTree->GetBranch("jet2"); brjet->SetAddress(&jetV); brjet_2->SetAddress(&jet2V); // if addPhoSel add the two photons ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *pho1V = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *pho2V = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >(); TBranch *brpho_1 ; TBranch *brpho_2 ; if (addPhoSel){ brpho_1 = fullTree->GetBranch("pho1"); brpho_2 = fullTree->GetBranch("pho2"); brpho_1->SetAddress(&pho1V); brpho_2->SetAddress(&pho2V); } // mu/dimu ? std::string origVar = var; if (addMuSel) var+="CorW"; if (addDiMuSel) var+="CorZ"; // Add Output branches to our very skimmed down tree. //TTree *newTree = new TTree(newname.c_str(),newname.c_str()); newTree->Branch("mvamet",&x,"mvamet/Float_t"); newTree->Branch("mvamet_orig",&x_orig,"mvamet_orig/Float_t"); newTree->Branch("weight",&weight,"weight/Float_t"); newTree->Branch("weight_wpt",&weight_wpt,"weight_wpt/Float_t"); newTree->Branch("metRaw",&metRaw,"metRaw/Float_t"); // useful to keep this newTree->Branch("jet1mprune",&catvar1,"jet1mprume/Float_t"); newTree->Branch("jet1mtrim",&catvar2,"jet1mtrim/Float_t"); newTree->Branch("jet1tau2o1",&catvar3,"jet1tau12o1/Float_t"); newTree->Branch("jpt",&catvar4,"jpt/Float_t"); newTree->Branch("jet1eta",&catvar6,"jet1eta/Float_t"); newTree->Branch("jet1QGtag",&catvar5,"jet1QGtag/Float_t"); newTree->Branch("passVBF",&passVBF,"passVBF/Int_t"); newTree->Branch("njets",&njets,"njets/Int_t"); if (addDiMuSel) { newTree->Branch("dimu_m",&dimuM,"dimu_m/Float_t"); } if (addMuSel) { newTree->Branch("mt",&mt,"mt/Float_t"); } if (addPhoSel) { newTree->Branch("phopt",&phopt,"phopt/Float_t"); newTree->Branch("phoeta",&phoeta,"phoeta/Float_t"); } fullTree->SetBranchAddress(var.c_str(),&x); if (addDiMuSel || addMuSel) fullTree->SetBranchAddress(origVar.c_str(),&x_orig); fullTree->SetBranchAddress(Form("%sPhi",var.c_str()),&mvametPhiCor); if (addDiMuSel || addMuSel) fullTree->SetBranchAddress(Form("%sPhi",origVar.c_str()),&mvametPhi); if (isWeighted) fullTree->SetBranchAddress("weight",&weight_in); fullTree->SetBranchAddress("metRaw",&metRaw); fullTree->SetBranchAddress("njets",&njets); fullTree->SetBranchAddress("nphotons",&nphotons); if (isWeighted) fullTree->SetBranchAddress("puWeight",&weight_in_pu); //fullTree->SetBranchAddress("jet1mprune",&catvar1); //fullTree->SetBranchAddress("jet1mtrim" ,&catvar2); //fullTree->SetBranchAddress("jet1tau2" ,&tau2); //fullTree->SetBranchAddress("jet1tau1" ,&tau1); //fullTree->SetBranchAddress("jet1QGtag",&catvar5); //fullTree->SetBranchAddress("jet1" ,&jet); if ( reweighted){ std::cout << "Reweighting For Photon Efficiency! " << std::endl; } std::cout << " Filling Skim tree " << newTree->GetName() << std::endl; for (int evt=0;evt<nEntries;evt++){ if ( !(keep_points->Contains(evt)) ) continue; fullTree->GetEntry(evt); TLorentzVector jet, jet2; jet.SetPtEtaPhiM(jetV->Pt(),jetV->Eta(),jetV->Phi(),jetV->M()); jet2.SetPtEtaPhiM(jet2V->Pt(),jet2V->Eta(),jet2V->Phi(),jet2V->M()); if (addDiMuSel){ TLorentzVector lep, lep2; lep.SetPxPyPzE(lepV->Px(),lepV->Py(),lepV->Pz(),lepV->E()); lep2.SetPxPyPzE(lep2V->Px(),lep2V->Py(),lep2V->Pz(),lep2V->E()); dimuM = TMath::Sqrt(2*(lep.E()*lep2.E()-(lep.Px()*lep2.Px()+lep.Py()*lep2.Py()+lep.Pz()*lep2.Pz()))); if ( dimuM < 61 || dimuM > 121 ) continue; } if (addMuSel){ TLorentzVector lep; lep.SetPxPyPzE(lepV->Px(),lepV->Py(),lepV->Pz(),lepV->E()); mt = TMath::Sqrt(2*x_orig*lep.Pt()*(1-TMath::Cos(deltaphi(mvametPhi,lep.Phi())))); // used original metphi and met to calculate mt if ( mt < 50 || mt > 100 ) continue; } if (addPhoSel){ double pho2eta = TMath::Abs(pho2V->Eta()); if (nphotons>1 && pho2V->Pt() > 100 && (pho2eta<1.4442 || ( pho2eta > 1.566 && pho2eta<2.5))) continue; TLorentzVector pho; pho.SetPxPyPzE(pho1V->Px(),pho1V->Py(),pho1V->Pz(),pho1V->E()); x_orig = x; double metphocor = computeMET(x,mvametPhiCor,pho); double metphophicor = computeMETPhi(x,mvametPhiCor,pho); x = metphocor; // Set the variables to the corrected ones now mvametPhiCor = metphophicor; phopt = pho.Pt(); phoeta = pho.Eta(); } // Back to regular selection // Add MET and second Jet balance cuts !!! if (jet2.Pt() > 30){ if (deltaphi(jet.Phi(),jet2.Phi()) >= 2) continue; } if ( deltaphi(jet.Phi(),mvametPhiCor)<2 ) continue; // this will always be the corrected Phi // Weights/Reweightsi if (isWeighted) weight = weight_in*weight_in_pu*luminosity; else weight = 1.; if (reweighted && isWeighted) { //float genpt = genZ->Pt(); double phpt = phopt; double pheta = TMath::Abs(phoeta); if ( phpt<reweightpheff->GetXaxis()->GetXmax() && phpt > reweightpheff->GetXaxis()->GetXmin() && pheta<reweightpheff->GetYaxis()->GetXmax() && pheta > reweightpheff->GetYaxis()->GetXmin() ) { weight_wpt = weight*reweightpheff->GetBinContent(reweightpheff->FindBin(phpt,pheta)); } else { weight_wpt = weight; } } else { weight_wpt = weight; } catvar3 = tau2/tau1; // make the sub-structure variable catvar4 = jet.Pt(); catvar6 = jet.Eta(); // Now check the VBF selection (added as a flag) // pt>50, eta <4.7, eta1*eta2 < 0 , delta(Eta) > 4.2, Mjj > 1100, deltaPhi < 1.0 passVBF=0; if (jet2.Pt() > 50 && TMath::Abs(jet2.Eta()) < 4.7 ) { double j1eta = jet.Eta(); double j2eta = jet2.Eta(); if( j1eta*j2eta <0 && deltaphi(jet.Phi(),jet2.Phi()) < 1.0 && (jet+jet2).M() > 1100 && TMath::Abs(j1eta-j2eta) > 4.2) { passVBF=1; } } newTree->Fill(); } std::cout << " Finished skim " << std::endl; }
void tree1r() { bool muon=0; //JetCorrectionUncertainty *jecUnc; // jecUnc= new JetCorrectionUncertainty("Fall12_V7_DATA_Uncertainty_AK5PFchs.txt"); TChain myTree("analyzeBasicPat/MuonTree"); myTree.Add("/afs/cern.ch/user/b/bbilin/eos/cms/store/group/phys_smp/ZPlusJets/8TeV/ntuples/2111/skimmed/EE_hadd_2012ABCD.root"); TH1::AddDirectory(true); Double_t PU_npT; Double_t PU_npIT; double EvtInfo_NumVtx; double MyWeight; double nup; Int_t event; double realdata; int run; // int lumi; double HLT_Elec17_Elec8; std::vector<double> *Dr01LepPt=0; std::vector<double> *Dr01LepEta=0; std::vector<double> *Dr01LepPhi=0; std::vector<double> *Dr01LepE=0; std::vector<double> *Dr01LepM=0; std::vector<double> *Dr01LepId=0; std::vector<double> *Dr01LepStatus=0; std::vector<double> *Bare01LepPt=0; std::vector<double> *Bare01LepEta=0; std::vector<double> *Bare01LepPhi=0; std::vector<double> *Bare01LepE=0; std::vector<double> *Bare01LepM=0; std::vector<double> *Bare01LepId=0; std::vector<double> *Bare01LepStatus=0; std::vector<double> *St01PhotonPt=0; std::vector<double> *St01PhotonEta=0; std::vector<double> *St01PhotonPhi=0; std::vector<double> *St01PhotonE=0; std::vector<double> *St01PhotonM=0; std::vector<double> *St01PhotonId=0; std::vector<double> *St01PhotonMomId=0; std::vector<double> *St01PhotonNumberMom=0; std::vector<double> *St01PhotonStatus=0; std::vector<double> *St03Pt=0; std::vector<double> *St03Eta=0; std::vector<double> *St03Phi=0; std::vector<double> *St03E=0; std::vector<double> *St03M=0; std::vector<double> *St03Id=0; std::vector<double> *St03Status=0; std::vector<double> *GjPt=0; std::vector<double> *Gjeta=0; std::vector<double> *Gjphi=0; std::vector<double> *GjE=0; std::vector<double> *GjPx=0; std::vector<double> *GjPy=0; std::vector<double> *GjPz=0; vector<double> *patMuonEn_ =0; vector<double> *patMuonCharge_ =0; vector<double> *patMuonPt_ =0; vector<double> *patMuonEta_=0; vector<double> *patMuonPhi_ =0; vector<double> *patMuonCombId_ =0; vector<double> *patMuonTrig_ =0; vector<double> *patMuonDetIsoRho_ =0; vector<double> *patMuonPfIsoDbeta_ =0; std::vector<double> *patElecTrig_ =0; std::vector<double> *patElecCharge_ =0; std::vector<double> *patElecEnergy_ =0; std::vector<double> *patElecEta_ =0; std::vector<double> *patElecScEta_ =0; std::vector<double> *patElecPhi_ =0; // std::vector<double> *patElecEcalEnergy_ =0; std::vector<double> *patElecPt_ =0; std::vector<double> *patElecPfIso_ =0; std::vector<double> *patElecPfIsodb_ =0; std::vector<double> *patElecPfIsoRho_ =0; std::vector<double> *patElecMediumIDOff_ =0; // std::vector<double> *patElecMVATrigId_ =0; // std::vector<double> *patElecMVANonTrigId_ =0; vector<double> *patJetPfAk05En_ =0; vector<double> *patJetPfAk05Pt_ =0; vector<double> *patJetPfAk05Eta_ =0; vector<double> *patJetPfAk05Phi_ =0; // vector<double> *patJetPfAk05JesUncert_ =0; vector<double> *patJetPfAk05LooseId_ =0; vector<double> *patJetPfAk05Et_ =0; // vector<double> *patJetPfAk05HadEHF_ =0; // vector<double> *patJetPfAk05EmEHF_ =0; // vector<double> *patJetPfAk05RawPt_ =0; vector<double> *patJetPfAk05RawEn_ =0; // vector<double> *patJetPfAk05jetBetaClassic_ =0; // vector<double> *patJetPfAk05jetBeta_ =0; // vector<double> *patJetPfAk05jetBetaStar_ =0; // vector<double> *patJetPfAk05jetBetaStarClassic_ =0; vector<double> *patJetPfAk05jetpuMVA_ =0; vector<bool> *patJetPfAk05jetpukLoose_ =0; vector<bool> *patJetPfAk05jetpukMedium_ =0; vector<bool> *patJetPfAk05jetpukTight_ =0; vector<double> *patJetPfAk05chf_=0; vector<double> *patJetPfAk05nhf_=0; vector<double> *patJetPfAk05cemf_=0; vector<double> *patJetPfAk05nemf_=0; vector<double> *patJetPfAk05cmult_=0; vector<double> *patJetPfAk05nconst_=0; myTree.SetBranchAddress("event",&event); myTree.SetBranchAddress("MyWeight",&MyWeight); myTree.SetBranchAddress("realdata",&realdata); myTree.SetBranchAddress("run",&run); // myTree.SetBranchAddress("lumi",&lumi); myTree.SetBranchAddress("PU_npT", &PU_npT); myTree.SetBranchAddress("PU_npIT", &PU_npIT); myTree.SetBranchAddress("nup", &nup); myTree.SetBranchAddress("EvtInfo_NumVtx", &EvtInfo_NumVtx); myTree.SetBranchAddress("patMuonEn_", &patMuonEn_); myTree.SetBranchAddress("patMuonCharge_", &patMuonCharge_); myTree.SetBranchAddress("patMuonPt_", &patMuonPt_); myTree.SetBranchAddress("patMuonEta_", &patMuonEta_); myTree.SetBranchAddress("patMuonPhi_", &patMuonPhi_); myTree.SetBranchAddress("patMuonCombId_", &patMuonCombId_); myTree.SetBranchAddress("patMuonTrig_", &patMuonTrig_); myTree.SetBranchAddress("patMuonDetIsoRho_", &patMuonDetIsoRho_); myTree.SetBranchAddress("patMuonPfIsoDbeta_", &patMuonPfIsoDbeta_); myTree.SetBranchAddress("patElecCharge_",&patElecCharge_); myTree.SetBranchAddress("patElecPt_",&patElecPt_); myTree.SetBranchAddress("patElecEnergy_",&patElecEnergy_); // myTree.SetBranchAddress("patElecEcalEnergy_",&patElecEcalEnergy_); myTree.SetBranchAddress("patElecEta_",&patElecEta_); myTree.SetBranchAddress("patElecScEta_",&patElecScEta_); myTree.SetBranchAddress("patElecPhi_",&patElecPhi_); myTree.SetBranchAddress("patElecPfIso_",&patElecPfIso_); myTree.SetBranchAddress("patElecPfIsodb_",&patElecPfIsodb_); myTree.SetBranchAddress("patElecPfIsoRho_",&patElecPfIsoRho_); myTree.SetBranchAddress("patElecMediumIDOff_",&patElecMediumIDOff_); // myTree.SetBranchAddress("patElecMVATrigId_",&patElecMVATrigId_); // myTree.SetBranchAddress("patElecMVANonTrigId_",&patElecMVANonTrigId_); myTree.SetBranchAddress("patElecTrig_",&patElecTrig_); myTree.SetBranchAddress("patJetPfAk05RawEn_",&patJetPfAk05RawEn_); //myTree.SetBranchAddress("patJetPfAk05HadEHF_",&patJetPfAk05HadEHF_); //myTree.SetBranchAddress("patJetPfAk05EmEHF_",&patJetPfAk05EmEHF_); myTree.SetBranchAddress("patJetPfAk05chf_",&patJetPfAk05chf_); myTree.SetBranchAddress("patJetPfAk05nhf_",&patJetPfAk05nhf_); myTree.SetBranchAddress("patJetPfAk05cemf_",&patJetPfAk05cemf_); myTree.SetBranchAddress("patJetPfAk05nemf_",&patJetPfAk05nemf_); myTree.SetBranchAddress("patJetPfAk05cmult_",&patJetPfAk05cmult_); myTree.SetBranchAddress("patJetPfAk05nconst_",&patJetPfAk05nconst_); myTree.SetBranchAddress("patJetPfAk05En_", &patJetPfAk05En_); myTree.SetBranchAddress("patJetPfAk05Pt_", &patJetPfAk05Pt_); myTree.SetBranchAddress("patJetPfAk05Eta_", &patJetPfAk05Eta_); myTree.SetBranchAddress("patJetPfAk05Phi_", &patJetPfAk05Phi_); // myTree.SetBranchAddress("patJetPfAk05JesUncert_", &patJetPfAk05JesUncert_); myTree.SetBranchAddress("patJetPfAk05LooseId_", &patJetPfAk05LooseId_); myTree.SetBranchAddress("patJetPfAk05Et_", &patJetPfAk05Et_); // myTree.SetBranchAddress("patJetPfAk05HadEHF_", &patJetPfAk05HadEHF_); // myTree.SetBranchAddress("patJetPfAk05EmEHF_", &patJetPfAk05EmEHF_); // myTree.SetBranchAddress("patJetPfAk05RawPt_", &patJetPfAk05RawPt_); // myTree.SetBranchAddress("patJetPfAk05RawEn_", &patJetPfAk05RawEn_); // myTree.SetBranchAddress("patJetPfAk05jetBetaClassic_", &patJetPfAk05jetBetaClassic_); // myTree.SetBranchAddress("patJetPfAk05jetBeta_", &patJetPfAk05jetBeta_); // myTree.SetBranchAddress("patJetPfAk05jetBetaStar_", &patJetPfAk05jetBetaStar_); // myTree.SetBranchAddress("patJetPfAk05jetBetaStarClassic_", &patJetPfAk05jetBetaStarClassic_); myTree.SetBranchAddress("patJetPfAk05jetpuMVA_", &patJetPfAk05jetpuMVA_); myTree.SetBranchAddress("patJetPfAk05jetpukLoose_", &patJetPfAk05jetpukLoose_); myTree.SetBranchAddress("patJetPfAk05jetpukMedium_", &patJetPfAk05jetpukMedium_); myTree.SetBranchAddress("patJetPfAk05jetpukTight_", &patJetPfAk05jetpukTight_); myTree.SetBranchAddress("HLT_Elec17_Elec8",&HLT_Elec17_Elec8); //Gen jets// myTree.SetBranchAddress("GjPt",&GjPt); myTree.SetBranchAddress("Gjeta",&Gjeta); myTree.SetBranchAddress("Gjphi",&Gjphi); myTree.SetBranchAddress("GjE",&GjE); myTree.SetBranchAddress("GjPx",&GjPx); myTree.SetBranchAddress("GjPy",&GjPy); myTree.SetBranchAddress("GjPz",&GjPz); //Dressed Leptons// myTree.SetBranchAddress("Dr01LepPt",&Dr01LepPt); myTree.SetBranchAddress("Dr01LepEta",&Dr01LepEta); myTree.SetBranchAddress("Dr01LepPhi",&Dr01LepPhi); myTree.SetBranchAddress("Dr01LepE",&Dr01LepE); myTree.SetBranchAddress("Dr01LepM",&Dr01LepM); myTree.SetBranchAddress("Dr01LepId",&Dr01LepId); myTree.SetBranchAddress("Dr01LepStatus",&Dr01LepStatus); myTree.SetBranchAddress("Bare01LepPt",&Bare01LepPt); myTree.SetBranchAddress("Bare01LepEt",&Bare01LepEta); myTree.SetBranchAddress("Bare01LepPhi",&Bare01LepPhi); myTree.SetBranchAddress("Bare01LepE",&Bare01LepE); myTree.SetBranchAddress("Bare01LepM",&Bare01LepM); myTree.SetBranchAddress("Bare01LepId",&Bare01LepId); myTree.SetBranchAddress("Bare01LepStatus",&Bare01LepStatus); myTree.SetBranchAddress("St01PhotonPt",&St01PhotonPt); myTree.SetBranchAddress("St01PhotonEta",&St01PhotonEta); myTree.SetBranchAddress("St01PhotonPhi",&St01PhotonPhi); myTree.SetBranchAddress("St01PhotonE",&St01PhotonE); myTree.SetBranchAddress("St01PhotonM",&St01PhotonM); myTree.SetBranchAddress("St01PhotonId",&St01PhotonId); myTree.SetBranchAddress("St01PhotonMomId",&St01PhotonMomId); myTree.SetBranchAddress("St01PhotonNumberMom",&St01PhotonNumberMom); myTree.SetBranchAddress("St01PhotonStatus",&St01PhotonStatus); myTree.SetBranchAddress("St03Pt",&St03Pt); myTree.SetBranchAddress("St03Eta",&St03Eta); myTree.SetBranchAddress("St03Phi",&St03Phi); myTree.SetBranchAddress("St03E",&St03E); myTree.SetBranchAddress("St03M",&St03M); myTree.SetBranchAddress("St03Id",&St03Id); myTree.SetBranchAddress("St03Status",&St03Status); ////Histogram booking/////////// TFile *theFile = new TFile ("test.root","RECREATE"); theFile->cd(); TH1D* h_MZ = new TH1D("MZ","M(Z)#rightarrow #mu#mu",40, 71,111.); TH1D* h_GMZElec = new TH1D("GMZElec","M(Z)#rightarrow #mu#mu",40, 71,111.); int puYear(2013); cout << "Pile Up Distribution: " << puYear << endl; standalone_LumiReWeighting puWeight(puYear), puUp(puYear,1), puDown(puYear,-1); Int_t nevent = myTree.GetEntries(); nevent =100000; for (Int_t iev=0;iev<nevent;iev++) { if (iev%100000 == 0) cout<<"DATA"<<" ===>>> "<<iev<<"/"<<nevent<<endl; myTree.GetEntry(iev); if(HLT_Elec17_Elec8!=1)continue; //require global trigger fired /////////////////////////////// double PUweight =1; double PUweightUp =1; double PUweightDn =1; if (PU_npT > 0) PUweight = PUweight * puWeight.weight(int(PU_npT)); if (PU_npT > 0) PUweightUp = PUweightUp * puUp.weight(int(PU_npT)); if (PU_npT > 0) PUweightDn = PUweightDn * puDown.weight(int(PU_npT)); int Gcommon = 0; int Gindex1[10],Gindex2[10]; for (unsigned int j = 0; j < Dr01LepPt->size(); ++j){ for (unsigned int jk = j; jk < Dr01LepPt->size(); ++jk){ // if(fabs(Dr01LepId->at(j))==11)cout<<Dr01LepId->at(j)<<endl; if (j == jk) continue; if ( Dr01LepStatus->at(j) == 1 && Dr01LepStatus->at(jk) == 1 && (Dr01LepId->at(j)*Dr01LepId->at(jk)) == -121 && //common1 Dr01LepPt->at(j) > 30. && Dr01LepPt->at(jk) > 30. && //common2 fabs(Dr01LepEta->at(j)) <2.4 && fabs(Dr01LepEta->at(jk)) <2.4 //common3 ){ Gindex1[Gcommon] = j; Gindex2[Gcommon] = jk; Gcommon++; } } } // cout<<Gcommon<<endl; float GMZElec = 0; // float Gdielecpt =0; // float Gdielecrapidity =0; // float Gdielecphi =0; int Gind1 = -99; int Gind2 = -99; for (int gg = 0;gg<Gcommon;++gg){ Gind1 = Gindex1[gg]; Gind2 = Gindex2[gg]; } if (Gind1 != -99 && Gind2 != -99){ TLorentzVector m1; TLorentzVector m2; m1.SetPtEtaPhiE(Dr01LepPt->at(Gind1), Dr01LepEta->at(Gind1) ,Dr01LepPhi->at(Gind1),Dr01LepE->at(Gind1) ); m2.SetPtEtaPhiE(Dr01LepPt->at(Gind2), Dr01LepEta->at(Gind2) ,Dr01LepPhi->at(Gind2),Dr01LepE->at(Gind2) ); GMZElec= (m1+m2).M(); if (GMZElec > 20.){ // Gdielecpt = (m1+m2).Perp(); // Gdielecrapidity = (m1+m2).Rapidity(); // Gdielecphi=(m1+m2).Phi(); if (GMZElec > 71.&& GMZElec < 111.){ h_GMZElec->Fill(GMZElec,PUweight); } } } int common = 0; int select_dielec=0; int index1[100],index2[100]; //if(doUnf)cout<<"NEW EVENT"<<endl; if(muon==0){ for (unsigned int j = 0; j < patElecPt_->size(); ++j){ for (unsigned int jk = j; jk < patElecPt_->size(); ++jk){ if (j == jk) continue; if (select_dielec==1) continue; if ( (patElecCharge_->at(j)*patElecCharge_->at(jk)) == -1 && patElecPt_->at(j) > 20. && patElecPt_->at(jk) > 20. && fabs(patElecScEta_->at(j)) <=2.4 && fabs(patElecScEta_->at(jk)) <=2.4 && ( !(fabs(patElecScEta_->at(j)) >1.4442 && fabs(patElecScEta_->at(j))<1.566) && !(fabs(patElecScEta_->at(jk)) >1.4442 && fabs(patElecScEta_->at(jk))<1.566) ) && patElecTrig_->at(j) > 0 && patElecTrig_->at(jk) > 0 && patElecPfIsoRho_->at(j)<0.150 && patElecPfIsoRho_->at(jk)<0.150 && patElecMediumIDOff_->at(j) >0 && patElecMediumIDOff_->at(jk) >0 ){ select_dielec=1; if(fabs(patElecScEta_->at(j)) >1.4442 && fabs(patElecScEta_->at(j))<1.566)cout<<"Elektron gap dışlanmamış!!"<<endl; TLorentzVector e1_tmp; TLorentzVector e2_tmp; e1_tmp.SetPtEtaPhiE(patElecPt_->at(j), patElecEta_->at(j) ,patElecPhi_->at(j),patElecEnergy_->at(j) ); e2_tmp.SetPtEtaPhiE(patElecPt_->at(jk), patElecEta_->at(jk) ,patElecPhi_->at(jk),patElecEnergy_->at(jk) ); float MZElec_tmp= (e1_tmp+e2_tmp).M(); if(MZElec_tmp<71. || MZElec_tmp>111.)continue; index1[common] = j; index2[common] = jk; common++; } } } } double ptcut = 20; if(muon==1){ for (unsigned int j = 0; j < patMuonPt_->size(); ++j){ for (unsigned int jk = j; jk < patMuonPt_->size(); ++jk){ if (j == jk) continue; if ((patMuonCharge_->at(j)*patMuonCharge_->at(jk)) == -1 && patMuonPt_->at(j) > ptcut && patMuonPt_->at(jk) > ptcut && fabs(patMuonEta_->at(j)) <2.4 && fabs(patMuonEta_->at(jk)) <2.4 && patMuonTrig_->at(j) ==1 && patMuonTrig_->at(jk) == 1 && patMuonPfIsoDbeta_->at(j)<0.2 && patMuonPfIsoDbeta_->at(jk)<0.2 && patMuonCombId_->at(j) ==1 && patMuonCombId_->at(jk) ==1 ) { index1[common] = j; index2[common] = jk; common++; } } } } int ind1 = -99; int ind2 = -99; if(common>0){ ind1 = index1[0]; ind2 = index2[0]; } float MZ = 0; // float Zpt =0; // float Zphi =0; // float Zrapidity =0; TLorentzVector l1; TLorentzVector l2; if (ind1 != -99 && ind2 != -99 &&common>0 /*&&common==1*/){ if(muon==0){ l1.SetPtEtaPhiE(patElecPt_->at(ind1), patElecEta_->at(ind1) ,patElecPhi_->at(ind1),patElecEnergy_->at(ind1) ); l2.SetPtEtaPhiE(patElecPt_->at(ind2), patElecEta_->at(ind2) ,patElecPhi_->at(ind2),patElecEnergy_->at(ind2) ); } if(muon==1){ l1.SetPtEtaPhiE(patMuonPt_->at(ind1), patMuonEta_->at(ind1) ,patMuonPhi_->at(ind1),patMuonEn_->at(ind1) ); l2.SetPtEtaPhiE(patMuonPt_->at(ind2), patMuonEta_->at(ind2) ,patMuonPhi_->at(ind2),patMuonEn_->at(ind2) ); } MZ= (l1+l2).M(); if ( MZ > 20.){ // Zpt= (l1+l2).Perp(); // Zrapidity = (l1+l2).Rapidity(); // Zphi = (l1+l2).Phi(); if (MZ>71 && MZ<111){ h_MZ->Fill(MZ,PUweight); } } } TLorentzVector j1_BEF; TLorentzVector j2_BEF; TLorentzVector j1G_BE; TLorentzVector j2G_BE; int Gn_jet_30_n=0; int n_jet_30_n_bef=0; /////////////Gen Jets/////////////////////// for (unsigned int pf=0;pf < GjPt->size();pf++){ if (GjPt->at(pf) > 30. && fabs(Gjeta->at(pf))<2.4){ Gn_jet_30_n++; if(Gn_jet_30_n==1){ j1G_BE.SetPtEtaPhiE(GjPt->at(pf),Gjeta->at(pf),Gjphi->at(pf),GjE->at(pf)); } if(Gn_jet_30_n==2){ j2G_BE.SetPtEtaPhiE(GjPt->at(pf),Gjeta->at(pf),Gjphi->at(pf),GjE->at(pf)); } } }/// end Gen jet loop /////////////Jets/////////////////////// for (unsigned int pf=0;pf < patJetPfAk05Pt_->size();pf++){ if(patJetPfAk05Pt_->at(pf) > 30.&&0.0<fabs(patJetPfAk05Eta_->at(pf)) && fabs(patJetPfAk05Eta_->at(pf))<4.7 ){ if ( patJetPfAk05LooseId_->at(pf)>=1 && patJetPfAk05jetpukLoose_->at(pf)==1){ n_jet_30_n_bef++; TLorentzVector j; j.SetPtEtaPhiE(patJetPfAk05Pt_->at(pf),patJetPfAk05Eta_->at(pf),patJetPfAk05Phi_->at(pf),patJetPfAk05En_->at(pf)); if(n_jet_30_n_bef==1){ j1_BEF.SetPtEtaPhiE(j.Pt(),j.Eta(),j.Phi(),j.E()); } if(n_jet_30_n_bef==2){ j2_BEF.SetPtEtaPhiE(j.Pt(),j.Eta(),j.Phi(),j.E()); } } } } }// end of event loop theFile->Write(); theFile->Close(); }//end void
Bool_t monojet::Process(Long64_t entry) { GetEntry(entry); if( entry % 100000 == 0 ) cout << "Processing event number: " << entry << endl; //cout << "Processing event number: " << entry << endl; // To make the processing fast, apply a very looose selection if (((TLorentzVector*)((*metP4)[0]))->Pt() < 40. or jetP4->GetEntries() < 1) return kTRUE; //this is the type tree tm->SetValue("run",runNum); tm->SetValue("event",eventNum); tm->SetValue("lumi",lumiNum); float dR = 0.; TClonesArray *tightLep; TClonesArray *cleanJet; TClonesArray *cleanTau; tightLep = new TClonesArray("TLorentzVector",20); cleanJet = new TClonesArray("TLorentzVector",20); cleanTau = new TClonesArray("TLorentzVector",20); std::vector<bool> jetMonojetId_clean; jetMonojetId_clean.clear(); std::vector<bool> jetMonojetIdLoose_clean; jetMonojetIdLoose_clean.clear(); //std::vector<float> jetPuId_clean; //jetPuId_clean.clear(); std::vector<float> tauId_clean; tauId_clean.clear(); std::vector<float> tauIso_clean; tauIso_clean.clear(); int n_tightlep = 0; // ********* Leptons ********** // for(int lepton = 0; lepton < lepP4->GetEntries(); lepton++) { TLorentzVector* Lepton = (TLorentzVector*) lepP4->At(lepton); // check if this is a tight lep, and check the overlap //iso_1 = divide(input_tree.lepIso[0],input_tree.lepP4[0].Pt()) //if (input_tree.lepTightId[0]==0 or iso_1 > 0.12): continue if (Lepton->Pt() > 20. && (*lepTightId)[lepton] > 1) { n_tightlep +=1; new ( (*tightLep)[tightLep->GetEntriesFast()]) TLorentzVector(Lepton->Px(), Lepton->Py(), Lepton->Pz(), Lepton->Energy()); //check overlap with jets for(int j = 0; j < jetP4->GetEntries(); j++) { TLorentzVector* Jet = (TLorentzVector*) jetP4->At(j); dR = deltaR(Lepton,Jet); if (dR > dR_cut) { new ( (*cleanJet)[cleanJet->GetEntriesFast()]) TLorentzVector(Jet->Px(), Jet->Py(), Jet->Pz(), Jet->Energy()); jetMonojetId_clean.push_back((*jetMonojetId)[j]); jetMonojetIdLoose_clean.push_back((*jetMonojetIdLoose)[j]); //jetPuId_clean.push_back((*jetPuId)[j]); } } //check overlap with taus for(int tau = 0; tau < tauP4->GetEntries(); tau++) { TLorentzVector* Tau = (TLorentzVector*) tauP4->At(tau); dR = deltaR(Lepton,Tau); if (dR > dR_cut) new ( (*cleanTau)[cleanTau->GetEntriesFast()]) TLorentzVector(Tau->Px(), Tau->Py(), Tau->Pz(), Tau->Energy()); tauId_clean.push_back((*tauId)[tau]); tauIso_clean.push_back((*tauIso)[tau]); } // tau overlap } // tight lepton selection }//lepton loop tm->SetValue("n_tightlep",n_tightlep); TLorentzVector fakeMET; // Z Selection TLorentzVector Z; if(lepP4->GetEntries() == 2 && n_tightlep > 0) { if (((*lepPdgId)[0]+(*lepPdgId)[1])==0 ) { Z = *((TLorentzVector*)((*lepP4)[0])) + *((TLorentzVector*)((*lepP4)[1])); fakeMET = *((TLorentzVector*)((*metP4)[0])) + Z; } } float MT = 0.0; //// W Selection if(lepP4->GetEntries() == 1 && n_tightlep == 1) { fakeMET = *((TLorentzVector*)((*metP4)[0])) + *((TLorentzVector*)((*lepP4)[0])) ; MT = transverseMass( ((TLorentzVector*)((*lepP4)[0]))->Pt(), ((TLorentzVector*)((*lepP4)[0]))->Phi(), ((TLorentzVector*)((*metP4)[0]))->Pt(), ((TLorentzVector*)((*metP4)[0]))->Phi()); } tm->SetValue("mt",MT); // ********* Jets ********** // for(int jet = 0; jet < jetP4->GetEntries(); jet++) { TLorentzVector* Jet = (TLorentzVector*) jetP4->At(jet); //cout << (*jetMonojetId)[0] <<endl; //cout << Jet->Pt()<<endl; } // ********* Met ********** // // Here try to save all possible met variables // and the recoil vectors (for Z and Photon) TLorentzVector Recoil(-9999.,-9999.,-9999.,-9999); float uPar = -9999. ; float uPerp = -9999.; if(Z.Pt() > 0) { Recoil = *((TLorentzVector*)((*metP4)[0])) + Z; Recoil.RotateZ(TMath::Pi()); Recoil.RotateZ(-Z.Phi()); if (Z.Phi() > TMath::Pi()) uPar = Recoil.Px() - Z.Pt() ; else uPar = Recoil.Px() + Z.Pt(); uPerp = Recoil.Py(); } tm->SetValue("uperp",uPerp); tm->SetValue("upar",uPar); // Decide on the type of the event and fill the // type tree int type_event = -1; // forcing all regions to be orthogonal wrt to each other if (((TLorentzVector*)((*metP4)[0]))->Pt() > 100. && jetP4->GetEntries() > 0 && lepP4->GetEntries() == 0) type_event=0; if (lepP4->GetEntriesFast() == 1) type_event=1; //&& (*lepTightId)[0] == 1) type_event=1; if (lepP4->GetEntriesFast() == 2) type_event=2; //&& ((*lepTightId)[0] == 1 || (*lepTightId)[1] == 1 )) type_event=2; if ( lepP4->GetEntriesFast() == 2 && type_event!=2 ) std::cout << "WTF??" << std::endl; tm->SetValue("event_type",type_event); // Now replace all the needed collections based // on the type if (type_event ==1 || type_event==2) { jetP4 = cleanJet; tauP4 = cleanTau; *jetMonojetId = jetMonojetId_clean; *jetMonojetIdLoose = jetMonojetIdLoose_clean; //*jetPuId = jetPuId_clean; *tauId = tauId_clean; *tauIso = tauIso_clean; *(TLorentzVector*)((*metP4)[0]) = fakeMET; } // final skim if(((TLorentzVector*)((*metP4)[0]))->Pt() < 100.) return kTRUE; //re-write the mc weight content to be +1 or -1 if(mcWeight < 0) mcWeight = -1.0; if(mcWeight > 0) mcWeight = 1.0; // and fill both trees; tm ->TreeFill(); eventstree->Fill(); return kTRUE; }
void xAna_ele_subleading_ele_pt_optimize(TString inputFile, TCanvas *c1 , TCanvas *c2 , TCanvas *c3 ,TCanvas *c4 ,TCanvas *c5 , TCanvas *c6 , int mass_point ,double eff,double eff_err, TString dir_name, int dir_flag ,int signal_background_flag, int background_file_index ){ // define histograms TString title2 = Form("ele pT for Zprime mass = %d",mass_point); TString title3 = Form("lepton pairs' pT for Zprime mass = %d",mass_point); TString title4 = Form("SD mass for Zprime mass = %d",mass_point); TString title5 = Form("Z mass for Zprime mass = %d",mass_point); TString title6 = Form("Zprime mass for Zprime mass = %d",mass_point); TString title7 = Form("|dEta| of ZH for Zprime mass = %d",mass_point); TString title8 = Form("|dPhi| of ZH for Zprime mass = %d",mass_point); TString title9 = Form("dR of ZH for Zprime mass = %d",mass_point); TH1D* h_ele_pT = new TH1D("h_ele_pT", title2 ,3000 , 0,3000 ); TH1D* h_lepton_pair_pT = new TH1D("h_lepton_pair_pT", title3 ,400 , 0,4000 ); TH1D* h_SD =new TH1D("h_SD",title4 ,100,0,200); TH1D* h_Z_mass = new TH1D("h_Z_mass",title5 ,250,0,500); TH1D* h_Zprime_mass = new TH1D("h_Zprime_mass",title6 ,1000,0,5000); TH1D* h_abs_dEta_ZH = new TH1D("h_abs_dEta_ZH",title7 ,80,-1,3); TH1D* h_abs_dPhi_ZH = new TH1D("h_abs_dPhi_ZH",title8 ,80,0,4); TH1D* h_abs_dR_ZH = new TH1D("h_abs_dR_ZH" ,title9 ,80,0,4); //get TTree from file ... // TreeReader data(inputFile.data()); TreeReader data(inputFile.Data()); Long64_t nTotal=0; Long64_t nPass[20]={0}; ofstream fout; fout.open("ele_Eiko.txt"); //Event loop for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){ if (jEntry % 50000 == 0) fprintf(stderr, "Processing event %lli of %lli\n", jEntry + 1, data.GetEntriesFast()); data.GetEntry(jEntry); nTotal ++; // 0. check the generator-level information and make sure there is a Z->e+e- /* Int_t nGenPar = data.GetInt("nGenPar"); Int_t* genParId = data.GetPtrInt("genParId"); Int_t* genParSt = data.GetPtrInt("genParSt"); Int_t* genMomParId = data.GetPtrInt("genMomParId"); Int_t* genDa1 = data.GetPtrInt("genDa1"); Int_t* genDa2 = data.GetPtrInt("genDa2"); Int_t* genMo1 = data.GetPtrInt("genMo1"); Int_t* genMo2 = data.GetPtrInt("genMo2"); bool hasLepton=false; for(int ig=0; ig < nGenPar; ig++){ if(genParId[ig]!=23)continue; int da1=genDa1[ig]; int da2=genDa2[ig]; if(da1<0 || da2<0)continue; int da1pdg = genParId[da1]; int da2pdg = genParId[da2]; if(abs(da1pdg)==11) hasLepton=true; if(hasLepton)break; } */ /* // 1. make sure there is a h-> bb, Yu-Hsiang change it bool hasHadron=false; for(int ig=0; ig < nGenPar; ig++){ if(genParId[ig]!=25)continue; int da1=genDa1[ig]; int da2=genDa2[ig]; if(da1<0 || da2<0)continue; int da1pdg = genParId[da1]; int da2pdg = genParId[da2]; if(abs(da1pdg)==5) hasHadron=true; if(hasHadron)break; } */ // if(!hasLepton)continue; nPass[0]++; // if(!hasHadron)continue; nPass[1]++; //2. pass electron or muon trigger std::string* trigName = data.GetPtrString("hlt_trigName"); vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult")); const Int_t nsize = data.GetPtrStringSize(); bool passTrigger=false; for(int it=0; it< nsize; it++) { std::string thisTrig= trigName[it]; bool results = trigResult[it]; // std::cout << thisTrig << " : " << results << std::endl; if( (thisTrig.find("HLT_Ele105")!= std::string::npos && results==1) || (thisTrig.find("HLT_Mu45")!= std::string::npos && results==1) ) { passTrigger=true; break; } } if(!passTrigger)continue; nPass[2]++; //3. has a good vertex Int_t nVtx = data.GetInt("nVtx"); if(nVtx<1)continue; nPass[3]++; //4. look for good electrons first Int_t nEle = data.GetInt("nEle"); Int_t run = data.GetInt("runId"); Int_t lumi = data.GetInt("lumiSection"); Int_t event = data.GetInt("eventId"); vector<bool> &passHEEPID = *((vector<bool>*) data.GetPtr("eleIsPassHEEPNoIso")); vector<bool> &passLoose = *((vector<bool>*) data.GetPtr("eleIsPassLoose")); TClonesArray* eleP4 = (TClonesArray*) data.GetPtrTObject("eleP4"); Float_t* eleSCEta = data.GetPtrFloat("eleScEta"); Float_t* eleSCEt = data.GetPtrFloat("eleScEt"); Float_t* eleMiniIso = data.GetPtrFloat("eleMiniIso"); Int_t* eleCharge = data.GetPtrInt("eleCharge"); //5. select good electrons // save index of electron accepted by ElectronSelection.h std::vector<int> accepted; select_electrons(data, &accepted); std::vector<int> goodElectrons; for(int ie=0; ie< nEle; ie++) { TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie); if(fabs(thisEle->Eta())>2.5)continue; if(! (fabs(eleSCEta[ie])<1.442 || fabs(eleSCEta[ie])>1.566))continue; float ele_pt = thisEle->Pt(); // cout<<"ie: "<< ie <<endl; // cout<<"before accepted" <<endl; // cout<<"ele_pt: "<< ele_pt <<endl; // if (dir_flag == 1) {if(!passHEEPID[ie])continue;} // else if (dir_flag == 2) {if(!passLoose[ie])continue;} // using the cut in ElectronSelection.h bool has_accepted = false; for(int j=0; j< accepted.size();j++) { if(ie == accepted[j]){has_accepted=true; break;} } if(!has_accepted)continue; // cout<<"after accepted" <<endl; // cout<<"ele_pt: "<< ele_pt <<endl; if(eleMiniIso[ie]>0.1)continue; goodElectrons.push_back(ie); } // //6. select a good Z boson bool findEPair=false; TLorentzVector l4_Z(0,0,0,0); std::vector<double> LeptonPairPt; std::vector<double> LeptonPairM; std::vector<int> leading_ele_index; std::vector<int> subleading_ele_index; for(unsigned int i=0; i< goodElectrons.size(); i++) { int ie = goodElectrons[i]; TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie); for(unsigned int j=0; j< i; j++) { int je= goodElectrons[j]; if(eleCharge[ie]*eleCharge[je]>0)continue; TLorentzVector* thatEle = (TLorentzVector*)eleP4->At(je); float pt1 = thisEle->Pt();// use pt float pt2 = thatEle->Pt(); // float pt1 = eleSCEt[ie];// use Super Cluster Et to replace using pt // float pt2 = eleSCEt[je]; float ptmax = TMath::Max(pt1,pt2); float ptmin = TMath::Min(pt1,pt2); if(ptmax<115)continue; // if(ptmin<35)continue; if(ptmin<35)continue; int leadingIndex = pt1>pt2? ie : je; int subleadingIndex = pt1 > pt2? je : ie; Float_t ptll = (*thisEle+*thatEle).Pt(); Float_t mll = (*thisEle+*thatEle).M(); if(mll<70 || mll>110)continue; // if(ptll<100)continue; // if(ptll<120)continue; if(ptll<200)continue; leading_ele_index.push_back(leadingIndex); subleading_ele_index.push_back(subleadingIndex); LeptonPairPt.push_back(ptll); LeptonPairM.push_back(mll); Float_t Phi_ll = (*thisEle+*thatEle).Phi(); Float_t Eta_ll = (*thisEle+*thatEle).Eta(); // cout<<" Phi_ll: "<< Phi_ll <<endl; // cout<<" Eta_ll: "<< Eta_ll <<endl; if(!findEPair)l4_Z=(*thisEle+*thatEle); findEPair=true; } } if(!findEPair) continue; nPass[4]++; //7.select a good CA8 and cleaned jet // first select muons for cleaning against jet std::vector<int> goodMuons; Int_t nMu = data.GetInt("nMu"); vector<bool> &isHighPtMuon = *((vector<bool>*) data.GetPtr("isHighPtMuon")); vector<bool> &isCustomTrackerMuon = *((vector<bool>*) data.GetPtr("isCustomTrackerMuon")); TClonesArray* muP4 = (TClonesArray*) data.GetPtrTObject("muP4"); Float_t* muMiniIso = data.GetPtrFloat("muMiniIso"); for(int im=0; im< nMu; im++) { TLorentzVector* thisMu = (TLorentzVector*)muP4->At(im); if(!isHighPtMuon[im] && !isCustomTrackerMuon[im])continue; if(muMiniIso[im]>0.1)continue; if ( goodMuons.size()==1 ) { bool highPt_AND_tracker = isHighPtMuon[0] && isCustomTrackerMuon[im]; bool tracker_AND_highPt = isHighPtMuon[im] && isCustomTrackerMuon[0]; if ( !(highPt_AND_tracker or tracker_AND_highPt) ) continue; } if(fabs(thisMu->Eta())>2.1)continue; if(thisMu->Pt() < 50)continue; goodMuons.push_back(im); } Int_t nJet = data.GetInt("FATnJet"); TClonesArray* jetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4"); Float_t* jetSDmass = data.GetPtrFloat("FATjetSDmass"); Float_t* jetPRmass = data.GetPtrFloat("FATjetPRmass"); std::vector<int> goodJets; std::vector<double> SD_Mass; TLorentzVector l4_leadingJet(0,0,0,0); bool findAJet=false; for(int ij=0; ij<nJet; ij++) { TLorentzVector* thisJet = (TLorentzVector*)jetP4->At(ij); // double SD_low = 60, SD_high = 140; // if(jetSDmass[ij]<SD_low || jetSDmass[ij]>SD_high)continue; double PR_low = 95, PR_high = 130; if(jetPRmass[ij]<PR_low || jetPRmass[ij]>PR_high)continue; bool hasOverLap=false; { TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(leading_ele_index[0]); if(thisEle->DeltaR(*thisJet)<0.8)hasOverLap=true; TLorentzVector* thatEle = (TLorentzVector*)eleP4->At(subleading_ele_index[0]); if(thatEle->DeltaR(*thisJet)<0.8)hasOverLap=true; } /* for(unsigned int im=0; im < goodMuons.size(); im++) { TLorentzVector* thisMuo = (TLorentzVector*)muP4->At(goodMuons[im]); if(thisMuo->DeltaR(*thisJet)<0.8)hasOverLap=true; if(hasOverLap)break; } */ if(hasOverLap)continue; if(thisJet->Pt()<200)continue; if(fabs(thisJet->Eta())>2.4)continue; if(!findAJet) { l4_leadingJet = *thisJet; // h_SD->Fill(jetSDmass[ij]); SD_Mass.push_back( jetSDmass[ij] ); goodJets.push_back(ij);// save leading jet } findAJet=true; // SD_Mass.push_back( jetSDmass[ij] ); // change to this place so that loop to all jets passing cuts } if(!findAJet) continue; nPass[5]++; Float_t MGrav = (l4_leadingJet + l4_Z).M(); double Mass_Point = mass_point; double mass_upper = Mass_Point + Mass_Point*0.15; double mass_lower = Mass_Point - Mass_Point*0.15; // cout<<"Mass_Point: "<<Mass_Point <<" mass_upper: "<< mass_upper <<" mass_lower: "<< mass_lower <<endl; if( MGrav< mass_lower || MGrav>mass_upper )continue; h_Zprime_mass->Fill( MGrav ); nPass[6]++; // if event can go here, then fill the histograms to plot the distributions. Yu-Hsiang add { int ie = leading_ele_index[0]; // int ie = subleading_ele_index[0]; TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie); h_ele_pT->Fill( thisEle->Pt() ); // if(eleSCEt[ie]<10){ cout<<"eleSCEt[ie]: "<< eleSCEt[ie] << endl;} // cout<<"eleSCEt[ie]: "<< eleSCEt[ie] << endl; // h_ele_pT->Fill( eleSCEt[ie] ); //cout<<endl; //cout<< "jEntry: "<< jEntry <<endl; //cout<<"ie: " << ie<< endl; //cout<<"thisEle->Pt(): " << thisEle->Pt()<< endl; } /* for(unsigned int i=0; i< LeadingElectrons.size(); i++) { int ie = LeadingElectrons[i]; TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie); h_ele_pT->Fill( thisEle->Pt() ); } */ for(unsigned int i=0; i< LeptonPairPt.size(); i++) { h_lepton_pair_pT->Fill( LeptonPairPt[i] ); } for(unsigned int i=0; i< LeptonPairM.size(); i++) { h_Z_mass->Fill( LeptonPairM[i] ); } for(unsigned int i=0; i< SD_Mass.size(); i++) { h_SD->Fill( SD_Mass[i] ); } // save delta Eta, delta Phi and delta R BTW reco-Z and reco-H { int ie_1st = leading_ele_index[0]; int ie_2nd = subleading_ele_index[0]; TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie_1st); TLorentzVector* thatEle = (TLorentzVector*)eleP4->At(ie_2nd); int ij_1st = goodJets[0]; TLorentzVector* thisJet = (TLorentzVector*)jetP4->At(ij_1st); // get Eta, Phi of Z and H float eta_H = thisJet->Eta(); float phi_H = thisJet->Phi(); float eta_Z = (*thisEle+*thatEle).Eta(); float phi_Z = (*thisEle+*thatEle).Phi(); // calculate the |dEta|, |dPhi| and dR float abs_dEta = fabs(eta_H - eta_Z); float abs_dPhi = -99; if(fabs(phi_H - phi_Z) < 3.14){ abs_dPhi = fabs(phi_H - phi_Z); } if(fabs(phi_H - phi_Z) > 3.14){ abs_dPhi = 6.28 - fabs(phi_H - phi_Z); } float dR_ZH = (*thisEle+*thatEle).DeltaR( *thisJet ); // cout<<"eta_H :"<< eta_H<<endl; // cout<<"eta_Z :"<< eta_Z<<endl; // cout<<"abs_dEta :"<< abs_dEta<<endl; // cout<<"phi_H :"<< phi_H<<endl; // cout<<"phi_Z :"<< phi_Z<<endl; // cout<<"abs_dPhi :"<< abs_dPhi<<endl; // cout<<"dR_ZH :"<< dR_ZH<<endl; // fill histogram h_abs_dEta_ZH ->Fill( abs_dEta ); h_abs_dPhi_ZH ->Fill( abs_dPhi); h_abs_dR_ZH ->Fill( dR_ZH ); } //////// fout << run << " " << lumi << " " << event << endl; } // end of loop over entries fout.close(); std::cout << "nTotal = " << nTotal << std::endl; for(int i=0;i<20;i++) if(nPass[i]>0) std::cout << "nPass[" << i << "]= " << nPass[i] << std::endl; // Yu-Hsiang add calulation of total efficiency and eff uncertainty double pass =-99,fail=-99,f_over_p=-99,f_over_p_error=-99; // double n_total = nTotal;// from int to double double n_total = nPass[1];// from int to double eff = nPass[6]/n_total; pass = nPass[6]; fail = nTotal - nPass[6]; f_over_p = fail/pass; f_over_p_error = f_over_p * sqrt( (1/fail) + (1/pass) ); eff_err = f_over_p_error/pow( 1 + f_over_p ,2); cout<<"eff: "<< eff << " eff_err: "<< eff_err <<endl; // Yu-Hsiang add cut flow figure TString title1 = Form("Cut Flow for Zprime mass = %d, eff=%f +/- %f",mass_point,eff,eff_err); TH1D* h_CutFlow = new TH1D("h_CutFlow", title1 ,8 , 0,8 ); char* cut_name[8] = {"Began","Z->ee in Gen","H->bb in Gen","HLT","Vertex","Leptons","V-jet","Zprime mass"}; for(int i=1;i<=8;i++){ // i is the index of column of cut flow plot if(i==1) {h_CutFlow->SetBinContent(i,nTotal); } else {h_CutFlow->SetBinContent(i,nPass[i-2]); } h_CutFlow->GetXaxis()->SetBinLabel( i , cut_name[i-1] ); } // TString png1_name = Form("Zprime_Cut_Flow_M_%d.png",mass_point); TString png2_name = Form("Zprime_ele_pT_M_%d.png",mass_point); TString png3_name = Form("Zprime_ll_pT_M_%d.png",mass_point); TString png4_name = Form("Zprime_SD_mass_M_%d.png",mass_point); TString png5_name = Form("Zprime_Z_mass_M_%d.png",mass_point); // TCanvas *c1 = new TCanvas("c1","try to show cut flow ",200,10,700,500); c1->cd(); gPad->SetGridx(); // gPad->SetLogy(); h_CutFlow->SetMarkerStyle(8); h_CutFlow->SetMarkerSize(1); h_CutFlow->GetXaxis()->SetLabelSize(0.041); // h_CutFlow->GetYaxis()->SetLabelSize(0.035); h_CutFlow->SetStats(0); h_CutFlow->SetMarkerSize(2.0); h_CutFlow->Draw(); h_CutFlow->Draw("HIST TEXT0 SAME"); // // Yu-Hsiang add drawing histogram of distributuion c2->cd(); h_ele_pT->Draw(); c3->cd(); h_lepton_pair_pT->Draw(); c4->cd(); h_SD->Draw(); c5->cd(); h_Z_mass->Draw(); c6->cd(); h_Zprime_mass->Draw(); TCanvas *c7 = new TCanvas("c7","",200,10,700,500); TCanvas *c8 = new TCanvas("c8","",200,10,700,500); TCanvas *c9 = new TCanvas("c9","",200,10,700,500); c7->cd(); h_abs_dEta_ZH->Draw(); c8->cd(); h_abs_dPhi_ZH->Draw(); c9->cd(); h_abs_dR_ZH->Draw(); //// // Yu-Hsiang add that save TH1D in the ROOT file TString ROOT_name; // when read signal sample if (signal_background_flag ==0){ ROOT_name = Form("signal_shape_in_Zprime_M-%d.root",mass_point); ROOT_name = dir_name + ROOT_name; // ROOT_name = dir_name +"no_zprime_cut_"+ ROOT_name; } // when read background sample if (signal_background_flag ==1){ if ( background_file_index ==0) { ROOT_name = Form("background_shape_DYJets_HT100to200_in_Zprime_M-%d.root",mass_point);} if ( background_file_index ==1) { ROOT_name = Form("background_shape_DYJets_HT200to400_in_Zprime_M-%d.root",mass_point);} if ( background_file_index ==2) { ROOT_name = Form("background_shape_DYJets_HT400to600_in_Zprime_M-%d.root",mass_point);} if ( background_file_index ==3) { ROOT_name = Form("background_shape_DYJets_HT600toInf_in_Zprime_M-%d.root",mass_point);} ROOT_name = dir_name + ROOT_name; // ROOT_name = dir_name +"no_zprime_cut_"+ ROOT_name; } bool save_flag = false; save_flag = true; if(save_flag){ TFile *myFile = new TFile(ROOT_name,"recreate"); h_CutFlow->Write(); h_ele_pT->Write(); h_lepton_pair_pT->Write(); h_SD->Write(); h_Z_mass->Write(); h_Zprime_mass->Write(); h_abs_dEta_ZH->Write(); h_abs_dPhi_ZH->Write(); h_abs_dR_ZH->Write(); myFile->Close(); delete myFile; } // delete the finished used TH1D so it will not replacing the existing TH1 (no potential memory leak warning) when loop again /* delete h_CutFlow; delete h_ele_pT; delete h_lepton_pair_pT; delete h_SD; delete h_Z_mass; */ }
void UpsCheck() { TFile *file = TFile::Open("/scratch_rigel/CMSTrees/PbPb_Data/MegaTree/OniaTree_MEGA_Peripheral30100_PromptReco_262548_263757.root"); //Track Tree Set Up TTree *trackTree = (TTree*)file->Get("anaTrack/trackTree"); trackTree->SetBranchStatus("*",0); trackTree->SetBranchStatus("nLumi", 1); trackTree->SetBranchStatus("nTrk", 1); trackTree->SetBranchStatus("trkPt", 1); trackTree->SetBranchStatus("trkEta", 1); trackTree->SetBranchStatus("trkPhi", 1); trackTree->SetBranchStatus("trkCharge", 1); trackTree->SetBranchStatus("nEv", 1); Int_t Lumi, nTrk, event; Float_t eta[9804]; Float_t phi[9804]; Int_t charge[9804]; Float_t pT[9804]; trackTree->SetBranchAddress("nLumi", &Lumi); trackTree->SetBranchAddress("nTrk", &nTrk); trackTree->SetBranchAddress("trkPt", pT); trackTree->SetBranchAddress("trkEta", eta); trackTree->SetBranchAddress("trkPhi", phi); trackTree->SetBranchAddress("trkCharge", charge); trackTree->SetBranchAddress("nEv", &event); //Dimuon Tree Set Up TTree *myTree = (TTree*)file->Get("hionia/myTree"); myTree->SetBranchStatus("*",0); myTree->SetBranchStatus("Reco_QQ_4mom",1); myTree->SetBranchStatus("Reco_QQ_mupl_4mom",1); myTree->SetBranchStatus("Reco_QQ_mumi_4mom",1); myTree->SetBranchStatus("Reco_QQ_size",1); myTree->SetBranchStatus("Centrality",1); myTree->SetBranchStatus("HLTriggers",1); myTree->SetBranchStatus("Reco_QQ_trig",1); myTree->SetBranchStatus("Reco_QQ_sign",1); TClonesArray *Reco_QQ_4mom=0; TClonesArray *Reco_QQ_mupl_4mom=0; TClonesArray *Reco_QQ_mumi_4mom=0; TLorentzVector *dimuon; TLorentzVector *mumi; TLorentzVector *mupl; double events=0; events = myTree->GetEntries(); cout << events << endl; Int_t QQsize=0; Int_t Centrality=0; ULong64_t HLTrigger=0; ULong64_t Reco_QQ_trig[21]; Int_t Reco_QQ_sign[21]; myTree->SetBranchAddress("Centrality",&Centrality); myTree->SetBranchAddress("HLTriggers",&HLTrigger); myTree->SetBranchAddress("Reco_QQ_4mom",&Reco_QQ_4mom); myTree->SetBranchAddress("Reco_QQ_mupl_4mom", &Reco_QQ_mupl_4mom); myTree->SetBranchAddress("Reco_QQ_mumi_4mom", &Reco_QQ_mumi_4mom); myTree->SetBranchAddress("Reco_QQ_size", &QQsize); myTree->SetBranchAddress("Reco_QQ_trig", Reco_QQ_trig); myTree->SetBranchAddress("Reco_QQ_sign", Reco_QQ_sign); //Histogram Initialization TH1D* phidiffmid = new TH1D( "phidiffmid", "#Delta#phi for mid mass band (9.0-9.8 GeV)",128,0,3.2); TH1D* rapdiffmid = new TH1D( "rapdiffmid", "#Delta#eta for mid mass band (9.0-9.8 GeV)",200,-5, 5); TH2D* midmass = new TH2D("midmass","#Delta#phi vs #Delta#eta for mid mass band",128,0,3.2,200,-5,5); //Event Loop int test = 0; int mid = 0; int index = 0; for(int i = 0; i < trackTree->GetEntries(); i++) { trackTree->GetEntry(i); myTree->GetEntry(i); if(Centrality > 140) { if((HLTrigger&128) == 128 || (HLTrigger&256) == 256) { for(Int_t j=0; j < QQsize; j++) { dimuon = (TLorentzVector*)Reco_QQ_4mom->At(j); mumi = (TLorentzVector*)Reco_QQ_mumi_4mom->At(j); mupl = (TLorentzVector*)Reco_QQ_mupl_4mom->At(j); if(((Reco_QQ_trig[j]&128) == 128 || (Reco_QQ_trig[j]&256) == 256) && Reco_QQ_sign[j] == 0) { if(mumi->Pt() > 4 && mupl->Pt() > 4 && TMath::Abs(mumi->Eta()) < 2.4 && TMath::Abs(mupl->Eta()) < 2.4 ) { index++; if(dimuon->M() > 9.3 && dimuon->M() < 9.6) { test++; for(Int_t k=0; k < nTrk; k++) { if(TMath::Abs(eta[k]) < 2.4 && pT[k] > .1 && TMath::Abs(charge[k]) == 1) { if(TMath::Abs(dimuon->Phi() - phi[k]) > 3.1416) { phidiffmid->Fill(6.2832-TMath::Abs(phi[k]-dimuon->Phi())); rapdiffmid->Fill(eta[k] - dimuon->Rapidity()); midmass->Fill(6.2832-TMath::Abs(phi[k]-dimuon->Phi()),eta[k]-dimuon->Rapidity()); } if(TMath::Abs(dimuon->Phi() - phi[k]) <= 3.1416) { phidiffmid->Fill(TMath::Abs(phi[k] - dimuon->Phi())); rapdiffmid->Fill(eta[k]-dimuon->Rapidity()); midmass->Fill(TMath::Abs(phi[k]-dimuon->Phi()),eta[k]-dimuon->Rapidity()); } } } } } } } } } } TFile out("EtaPhiMidCent.root", "RECREATE"); phidiffmid->Write(); rapdiffmid->Write(); midmass->Write(); out.Close(); cout << "Done! " << test << " Total Dimuons: " << index <<endl; cout << "Mid: " << mid << endl; return; }
void rochcor_42X::momcor_mc( TLorentzVector& mu, float charge, float sysdev, int runopt){ //sysdev == num : deviation = num float ptmu = mu.Pt(); float muphi = mu.Phi(); float mueta = mu.Eta(); // same with mu.Eta() in Root float px = mu.Px(); float py = mu.Py(); float pz = mu.Pz(); float e = mu.E(); int mu_phibin = phibin(muphi); int mu_etabin = etabin(mueta); //float mptsys = sran.Gaus(0.0,sysdev); float dm = 0.0; float da = 0.0; if(runopt == 0){ dm = (mcor_bfA[mu_phibin][mu_etabin] + mptsys_mc_dm[mu_phibin][mu_etabin]*mcor_bfAer[mu_phibin][mu_etabin])/mmavgA[mu_phibin][mu_etabin]; da = mcor_maA[mu_phibin][mu_etabin] + mptsys_mc_da[mu_phibin][mu_etabin]*mcor_maAer[mu_phibin][mu_etabin]; }else if(runopt == 1){ dm = (mcor_bfB[mu_phibin][mu_etabin] + mptsys_mc_dm[mu_phibin][mu_etabin]*mcor_bfBer[mu_phibin][mu_etabin])/mmavgB[mu_phibin][mu_etabin]; da = mcor_maB[mu_phibin][mu_etabin] + mptsys_mc_da[mu_phibin][mu_etabin]*mcor_maBer[mu_phibin][mu_etabin]; } float cor = 1.0/(1.0 + dm + charge*da*ptmu); //for the momentum tuning - eta,phi,Q correction px *= cor; py *= cor; pz *= cor; e *= cor; float recm = 0.0; float drecm = 0.0; float delta = 0.0; float sf = 0.0; float gscler = 0.0; float deltaer = 0.0; float sfer = 0.0; if(runopt==0){ recm = recmA; drecm = drecmA; delta = deltaA; sf = sfA; gscler = TMath::Sqrt( TMath::Power(mgsclA_stat,2) + TMath::Power(mgsclA_syst,2) ); deltaer = TMath::Sqrt( TMath::Power(deltaA_stat,2) + TMath::Power(deltaA_syst,2) ); sfer = TMath::Sqrt( TMath::Power(sfA_stat,2) + TMath::Power(sfA_syst,2) ); }else if(runopt==1){ recm = recmB; drecm = drecmB; delta = deltaB; sf = sfB; gscler = TMath::Sqrt( TMath::Power(mgsclB_stat,2) + TMath::Power(mgsclB_syst,2) ); deltaer = TMath::Sqrt( TMath::Power(deltaB_stat,2) + TMath::Power(deltaB_syst,2) ); sfer = TMath::Sqrt( TMath::Power(sfB_stat,2) + TMath::Power(sfB_syst,2) ); } float tune = 1.0/(1.0 + (delta + sysdev*deltaer)*sqrt(px*px + py*py)*eran.Gaus(1.0,(sf + sysdev*sfer))); px *= (tune); py *= (tune); pz *= (tune); e *= (tune); float gscl = (genm_smr/recm); px *= (gscl + sysdev*gscler); py *= (gscl + sysdev*gscler); pz *= (gscl + sysdev*gscler); e *= (gscl + sysdev*gscler); mu.SetPxPyPzE(px,py,pz,e); }
void test(char * tag= "0", char *infName = "/d102/yjlee/hiForest2MC/Pythia80_HydjetDrum_mix01_HiForest2_v22_simTrack05.root") { // Define the input file and HiForest HiForest *c = new HiForest(infName,"",cPPb); c->hasPFTree=0; c->hasPhotonTree=0; c->hasTowerTree=0; c->hasHbheTree=0; c->hasEbTree=0; c->hasGenpTree=0; c->hasGenParticleTree=0; c->hasAkPu2CaloJetTree=0; c->hasAkPu3CaloJetTree=0; c->hasAkPu4CaloJetTree=0; // c->doTrackCorrections=1; // c->InitTree(); // Output file TFile *output = new TFile(Form("output-%s.root",tag),"recreate"); // Output TTree * t = new TTree("t","gammajet"); JetData data(t,1); HistoData histos_MergedGeneralCalo("MergedGeneral"); HistoData histos2_MergedGeneral("MergedGeneral2"); // phi dependent corr TH1D *hWeight = new TH1D("hWeight","",1000,0,100); TH1D *hWeight2 = new TH1D("hWeight2","",1000,0,100); TH1D *hPt = new TH1D("hPt","",100,0,100); TH1D *hNoWPt = new TH1D("hNoWPt","",100,0,100); TNtuple *nt = new TNtuple("nt","","m:eta:phi:pt:pt1:pt2:ch1:ch2:phi1:phi2:dxy1:dxy2:hiBin:N"); TNtuple *ntEvt = new TNtuple("ntEvt","","N"); nt->SetAutoFlush(30000); cout <<nt->GetAutoFlush()<<endl; TCanvas *cc = new TCanvas("cc","",600,600); // nt->SetCircular(1000); // Main loop TLorentzVector *v2 = new TLorentzVector; TLorentzVector *v = new TLorentzVector; TLorentzVector phi; for (int i=0;i<c->GetEntries()/1.;i++) { c->GetEntry(i); if (!c->selectEvent()) continue; if (i%1000==0){ cout <<i<<" / "<<c->GetEntries()<<endl; } int N=0; for (int j=0;j<c->track.nTrk;j++) { if (!c->selectTrack(j)) continue; if (fabs(c->track.trkEta[j])>2.4) continue; if (fabs(c->track.trkPt[j])<0.4) continue; N++; } ntEvt->Fill(N); for (int j=0;j<c->track.nTrk;j++) { if (!c->selectTrack(j)) continue; if (fabs(c->track.trkPt[j])<1) continue; // if (fabs(c->track.trkDxy1[j]/c->track.trkDxyError1[j])<1) continue; for (int k=j+1;k<c->track.nTrk;k++) { if (j==k) continue; if (!c->selectTrack(k)) continue; // if (c->track.trkCharge[k]==c->track.trkCharge[j]) continue; if (fabs(c->track.trkPt[k])<1) continue; v->SetPtEtaPhiM(c->track.trkPt[j],c->track.trkEta[j],c->track.trkPhi[j],0.493677); v2->SetPtEtaPhiM(c->track.trkPt[k],c->track.trkEta[k],c->track.trkPhi[k],0.493677); // v2->SetPtEtaPhiM(c->track.trkPt[k],c->track.trkEta[k],c->track.trkPhi[k],0.13957); // v->SetPtEtaPhiM(c->track.trkPt[j],c->track.trkEta[j],c->track.trkPhi[j],0.938272); // v->SetPtEtaPhiM(c->track.trkPt[j],c->track.trkEta[j],c->track.trkPhi[j],0.13957); // v2->SetPtEtaPhiM(c->track.trkPt[k],c->track.trkEta[k],c->track.trkPhi[k],0.13957); phi = (*v) + (*v2); // if ((phi.M())>5) { if ((phi.M())>1.2||phi.M()<0.0) { // phi.Delete(); continue; } nt->Fill(phi.M(),phi.Eta(),phi.Phi(),phi.Pt(),v->Pt(),v2->Pt(),c->track.trkCharge[j],c->track.trkCharge[k],v->Phi(),v2->Phi(),c->track.trkDxy1[j],c->track.trkDxy1[k],c->evt.hiBin,N); // phi.Delete(); } } //cout <<data.mpt<<endl; t->Fill(); } // t->Write(); histos_MergedGeneralCalo.calcEff(); histos2_MergedGeneral.calcEff(); output->Write(); output->Close(); }
void applyEmEnergyScale( const EnergyScaleCorrection_class& egcor, TLorentzVector& p, const ZGTree& myTree, float r9 ) { float cor = egcor.ScaleCorrection(myTree.run, fabs(p.Eta())<1.479, r9, p.Eta(), p.Pt()); p.SetPtEtaPhiM( p.Pt()*cor, p.Eta(), p.Phi(), p.M() ); }
void TreeFinalizerC_ZJet::finalize() { TString dataset_tstr(dataset_); gROOT->cd(); std::string outfileName; if( DEBUG_ ) outfileName = "provaZJet_"+dataset_; else { if(dataset_!="") outfileName = "ZJet_"+dataset_; else outfileName = "ZJet"; } outfileName = outfileName; if( nBlocks_ >1 ) { char blockText[100]; sprintf( blockText, "_%d", iBlock_ ); std::string iBlockString(blockText); outfileName = outfileName + iBlockString; } outfileName += ".root"; TFile* outFile = new TFile(outfileName.c_str(), "RECREATE"); outFile->cd(); TTree* tree_passedEvents = new TTree("tree_passedEvents", "Unbinned data for statistical treatment"); TH1D* h1_cutflow_50100 = new TH1D("cutflow_50100", "", 6, 0, 6); h1_cutflow_50100->Sumw2(); TH1F* h1_nvertex = new TH1F("nvertex", "", 21, -0.5, 20.5); h1_nvertex->Sumw2(); TH1F* h1_nvertex_PUW = new TH1F("nvertex_PUW", "", 21, -0.5, 20.5); h1_nvertex_PUW->Sumw2(); TH1D* h1_quarkFraction_3050 = new TH1D("quarkFraction_3050", "", 1, 0., 1.); h1_quarkFraction_3050->Sumw2(); TH1D* h1_quarkFraction_5080 = new TH1D("quarkFraction_5080", "", 1, 0., 1.); h1_quarkFraction_5080->Sumw2(); TH1D* h1_quarkFraction_80120 = new TH1D("quarkFraction_80120", "", 1, 0., 1.); h1_quarkFraction_80120->Sumw2(); TH1D* h1_quarkFraction_antibtag_3050 = new TH1D("quarkFraction_antibtag_3050", "", 1, 0., 1.); h1_quarkFraction_antibtag_3050->Sumw2(); TH1D* h1_quarkFraction_antibtag_5080 = new TH1D("quarkFraction_antibtag_5080", "", 1, 0., 1.); h1_quarkFraction_antibtag_5080->Sumw2(); TH1D* h1_quarkFraction_antibtag_80120 = new TH1D("quarkFraction_antibtag_80120", "", 1, 0., 1.); h1_quarkFraction_antibtag_80120->Sumw2(); TH1D* h1_ptJetReco = new TH1D("ptJetReco", "", 100, 0., 300); h1_ptJetReco->Sumw2(); TH1D* h1_pt2ndJetReco = new TH1D("pt2ndJetReco", "", 100, 5., 400); h1_pt2ndJetReco->Sumw2(); TH1D* h1_ptDJetReco_3050 = new TH1D("ptDJetReco_3050", "", 50, 0., 1.0001); h1_ptDJetReco_3050->Sumw2(); TH1D* h1_nChargedJetReco_3050 = new TH1D("nChargedJetReco_3050", "", 51, -0.5, 50.5); h1_nChargedJetReco_3050->Sumw2(); TH1D* h1_nNeutralJetReco_3050 = new TH1D("nNeutralJetReco_3050", "", 51, -0.5, 50.5); h1_nNeutralJetReco_3050->Sumw2(); TH1D* h1_QGLikelihoodJetReco_3050 = new TH1D("QGLikelihoodJetReco_3050", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_3050->Sumw2(); TH1D* h1_ptDJetReco_antibtag_3050 = new TH1D("ptDJetReco_antibtag_3050", "", 50, 0., 1.0001); h1_ptDJetReco_antibtag_3050->Sumw2(); TH1D* h1_nChargedJetReco_antibtag_3050 = new TH1D("nChargedJetReco_antibtag_3050", "", 51, -0.5, 50.5); h1_nChargedJetReco_antibtag_3050->Sumw2(); TH1D* h1_nNeutralJetReco_antibtag_3050 = new TH1D("nNeutralJetReco_antibtag_3050", "", 51, -0.5, 50.5); h1_nNeutralJetReco_antibtag_3050->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_3050 = new TH1D("QGLikelihoodJetReco_antibtag_3050", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_3050->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_gluon_3050 = new TH1D("QGLikelihoodJetReco_antibtag_gluon_3050", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_gluon_3050->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_quark_3050 = new TH1D("QGLikelihoodJetReco_antibtag_quark_3050", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_quark_3050->Sumw2(); TH1D* h1_ptDJetReco_5080 = new TH1D("ptDJetReco_5080", "", 50, 0., 1.0001); h1_ptDJetReco_5080->Sumw2(); TH1D* h1_nChargedJetReco_5080 = new TH1D("nChargedJetReco_5080", "", 51, -0.5, 50.5); h1_nChargedJetReco_5080->Sumw2(); TH1D* h1_nNeutralJetReco_5080 = new TH1D("nNeutralJetReco_5080", "", 51, -0.5, 50.5); h1_nNeutralJetReco_5080->Sumw2(); TH1D* h1_QGLikelihoodJetReco_5080 = new TH1D("QGLikelihoodJetReco_5080", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_5080->Sumw2(); TH1D* h1_ptDJetReco_antibtag_5080 = new TH1D("ptDJetReco_antibtag_5080", "", 50, 0., 1.0001); h1_ptDJetReco_antibtag_5080->Sumw2(); TH1D* h1_nChargedJetReco_antibtag_5080 = new TH1D("nChargedJetReco_antibtag_5080", "", 51, -0.5, 50.5); h1_nChargedJetReco_antibtag_5080->Sumw2(); TH1D* h1_nNeutralJetReco_antibtag_5080 = new TH1D("nNeutralJetReco_antibtag_5080", "", 51, -0.5, 50.5); h1_nNeutralJetReco_antibtag_5080->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_5080 = new TH1D("QGLikelihoodJetReco_antibtag_5080", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_5080->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_gluon_5080 = new TH1D("QGLikelihoodJetReco_antibtag_gluon_5080", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_gluon_5080->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_quark_5080 = new TH1D("QGLikelihoodJetReco_antibtag_quark_5080", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_quark_5080->Sumw2(); TH1D* h1_ptDJetReco_80120 = new TH1D("ptDJetReco_80120", "", 50, 0., 1.0001); h1_ptDJetReco_80120->Sumw2(); TH1D* h1_nChargedJetReco_80120 = new TH1D("nChargedJetReco_80120", "", 51, -0.5, 50.5); h1_nChargedJetReco_80120->Sumw2(); TH1D* h1_nNeutralJetReco_80120 = new TH1D("nNeutralJetReco_80120", "", 51, -0.5, 50.5); h1_nNeutralJetReco_80120->Sumw2(); TH1D* h1_QGLikelihoodJetReco_80120 = new TH1D("QGLikelihoodJetReco_80120", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_80120->Sumw2(); TH1D* h1_ptDJetReco_antibtag_80120 = new TH1D("ptDJetReco_antibtag_80120", "", 50, 0., 1.0001); h1_ptDJetReco_antibtag_80120->Sumw2(); TH1D* h1_nChargedJetReco_antibtag_80120 = new TH1D("nChargedJetReco_antibtag_80120", "", 51, -0.5, 50.5); h1_nChargedJetReco_antibtag_80120->Sumw2(); TH1D* h1_nNeutralJetReco_antibtag_80120 = new TH1D("nNeutralJetReco_antibtag_80120", "", 51, -0.5, 50.5); h1_nNeutralJetReco_antibtag_80120->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_80120 = new TH1D("QGLikelihoodJetReco_antibtag_80120", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_80120->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_gluon_80120 = new TH1D("QGLikelihoodJetReco_antibtag_gluon_80120", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_gluon_80120->Sumw2(); TH1D* h1_QGLikelihoodJetReco_antibtag_quark_80120 = new TH1D("QGLikelihoodJetReco_antibtag_quark_80120", "", 50, 0., 1.0001); h1_QGLikelihoodJetReco_antibtag_quark_80120->Sumw2(); Double_t ptBinning[4]; ptBinning[0] = 30.; ptBinning[1] = 50.; ptBinning[2] = 80.; ptBinning[3] = 120.; TH1D* h1_nEvents_passed = new TH1D("nEvents_passed", "", 3, ptBinning); h1_nEvents_passed->Sumw2(); TH1D* h1_nEvents_passed_quark = new TH1D("nEvents_passed_quark", "", 3, ptBinning); h1_nEvents_passed_quark->Sumw2(); TH1D* h1_ptZ = new TH1D("ptZ", "", 500, 0., 500.); h1_ptZ->Sumw2(); TH1D* h1_mZ = new TH1D("mZ", "", 100, 50., 150.); h1_mZ->Sumw2(); TH1D* h1_etaZ = new TH1D("etaZ", "", 15, -1.3, 1.3); h1_etaZ->Sumw2(); TH1D* h1_phiZ = new TH1D("phiZ", "", 15, -3.1416, 3.1416); h1_phiZ->Sumw2(); Int_t run; tree_->SetBranchAddress("run", &run); Int_t LS; tree_->SetBranchAddress("LS", &LS); Int_t event; tree_->SetBranchAddress("event", &event); Int_t nvertex; tree_->SetBranchAddress("nvertex", &nvertex); Float_t eventWeight; tree_->SetBranchAddress("eventWeight", &eventWeight); Float_t eventWeight_genjets; Float_t eMet; Float_t phiMet; tree_->SetBranchAddress("epfMet", &eMet); tree_->SetBranchAddress("phipfMet", &phiMet); Float_t ptHat; tree_->SetBranchAddress("ptHat", &ptHat); Int_t nPU; tree_->SetBranchAddress("nPU", &nPU); Int_t PUReWeight; tree_->SetBranchAddress("PUReWeight", &PUReWeight); Float_t rhoPF; tree_->SetBranchAddress("rhoPF", &rhoPF); Float_t rhoJetPF; tree_->SetBranchAddress("rhoJetPF", &rhoJetPF); Float_t eLeptZ1; tree_->SetBranchAddress("eLeptZ1", &eLeptZ1); Float_t ptLeptZ1; tree_->SetBranchAddress("ptLeptZ1", &ptLeptZ1); Float_t etaLeptZ1; tree_->SetBranchAddress("etaLeptZ1", &etaLeptZ1); Float_t phiLeptZ1; tree_->SetBranchAddress("phiLeptZ1", &phiLeptZ1); Float_t eLeptZ2; tree_->SetBranchAddress("eLeptZ2", &eLeptZ2); Float_t ptLeptZ2; tree_->SetBranchAddress("ptLeptZ2", &ptLeptZ2); Float_t etaLeptZ2; tree_->SetBranchAddress("etaLeptZ2", &etaLeptZ2); Float_t phiLeptZ2; tree_->SetBranchAddress("phiLeptZ2", &phiLeptZ2); Bool_t matchedToMC; tree_->SetBranchAddress("matchedToMC", &matchedToMC); Int_t nJets; tree_->SetBranchAddress("nJets", &nJets); Float_t eJet[50]; tree_->SetBranchAddress("eJet", eJet); Float_t ptJet[50]; tree_->SetBranchAddress("ptJet", ptJet); Float_t etaJet[50]; tree_->SetBranchAddress("etaJet", etaJet); Float_t phiJet[50]; tree_->SetBranchAddress("phiJet", phiJet); Int_t nChargedJet[50]; tree_->SetBranchAddress("nChargedJet", nChargedJet); Int_t nNeutralJet[50]; tree_->SetBranchAddress("nNeutralJet", nNeutralJet); Float_t eChargedHadronsJet[50]; tree_->SetBranchAddress("eChargedHadronsJet", eChargedHadronsJet); Float_t eNeutralHadronsJet[50]; tree_->SetBranchAddress("eNeutralHadronsJet", eNeutralHadronsJet); Float_t ePhotonsJet[50]; tree_->SetBranchAddress("ePhotonsJet", ePhotonsJet); Float_t eHFHadronsJet[50]; tree_->SetBranchAddress("eHFHadronsJet", eHFHadronsJet); Float_t eHFEMJet[50]; tree_->SetBranchAddress("eHFEMJet", eHFEMJet); Float_t ptDJet[50]; tree_->SetBranchAddress("ptDJet", ptDJet); Float_t rmsCandJet[50]; tree_->SetBranchAddress("rmsCandJet", rmsCandJet); Float_t betaStarJet[50]; tree_->SetBranchAddress("betaStarJet", betaStarJet); Float_t QGLikelihoodJet[50]; tree_->SetBranchAddress("QGLikelihoodJet", QGLikelihoodJet); Float_t trackCountingHighEffBJetTagsJet[50]; tree_->SetBranchAddress("trackCountingHighEffBJetTagsJet", trackCountingHighEffBJetTagsJet); Float_t combinedSecondaryVertexBJetTagJet[50]; tree_->SetBranchAddress("combinedSecondaryVertexBJetTagJet", combinedSecondaryVertexBJetTagJet); Int_t pdgIdPartJet[50]; tree_->SetBranchAddress("pdgIdPartJet", pdgIdPartJet); Float_t ptPartJet[50]; tree_->SetBranchAddress("ptPartJet", ptPartJet); Float_t etaPartJet[50]; tree_->SetBranchAddress("etaPartJet", etaPartJet); Float_t phiPartJet[50]; tree_->SetBranchAddress("phiPartJet", phiPartJet); Float_t ptGenJet[50]; tree_->SetBranchAddress("ptGenJet", ptGenJet); Float_t etaGenJet[50]; tree_->SetBranchAddress("etaGenJet", etaGenJet); Float_t phiGenJet[50]; tree_->SetBranchAddress("phiGenJet", phiGenJet); Float_t axis1Jet[50]; tree_->SetBranchAddress("axis1Jet",axis1Jet); Float_t axis2Jet[50]; tree_->SetBranchAddress("axis2Jet",axis2Jet); Float_t pullJet[50]; tree_->SetBranchAddress("pullJet",pullJet); Float_t tanaJet[50]; tree_->SetBranchAddress("tanaJet",tanaJet); Float_t ptD_QCJet[50]; tree_->SetBranchAddress("ptD_QCJet",ptD_QCJet); Float_t rmsCand_QCJet[50]; tree_->SetBranchAddress("rmsCand_QCJet",rmsCand_QCJet); Float_t axis1_QCJet[50]; tree_->SetBranchAddress("axis1_QCJet",axis1_QCJet); Float_t axis2_QCJet[50]; tree_->SetBranchAddress("axis2_QCJet",axis2_QCJet); Float_t pull_QCJet[50]; tree_->SetBranchAddress("pull_QCJet",pull_QCJet); Float_t tana_QCJet[50]; tree_->SetBranchAddress("tana_QCJet",tana_QCJet); Int_t nPFCand_QC_ptCutJet[50]; tree_->SetBranchAddress("nPFCand_QC_ptCutJet",nPFCand_QC_ptCutJet); //Float_t nChg_ptCutJet[50]; tree_->SetBranchAddress("nChg_ptCutJet",nChg_ptCutJet); //Float_t nChg_QCJet[50]; tree_->SetBranchAddress("nChg_QCJet",nChg_QCJet); //Float_t nChg_ptCut_QCJet[50]; tree_->SetBranchAddress("nChg_ptCut_QCJet",nChg_ptCut_QCJet); //Float_t nNeutral_ptCutJet[50]; tree_->SetBranchAddress("nNeutral_ptCutJet",nNeutral_ptCutJet); Float_t RchgJet[50]; tree_->SetBranchAddress("RchgJet",RchgJet); Float_t RneutralJet[50]; tree_->SetBranchAddress("RneutralJet",RneutralJet); Float_t RJet[50]; tree_->SetBranchAddress("RJet",RJet); Float_t Rchg_QCJet[50]; tree_->SetBranchAddress("Rchg_QCJet",Rchg_QCJet); Bool_t secondJetOK; Bool_t btagged; Bool_t matchedToGenJet; Float_t deltaPhi_jet; Float_t eventWeight_noPU; Float_t ptZ, etaZ, mZ; Float_t QGlikelihood, QGlikelihood2012; Float_t ptJet0_t; Float_t etaJet0_t; Int_t nChargedJet0_t; Int_t nNeutralJet0_t; Float_t ptDJet0_t; Float_t ptD_QCJet0_t; Float_t axis1_QCJet0_t; Float_t axis2_QCJet0_t; Int_t nPFCand_QC_ptCutJet0_t; Int_t pdgIdPartJet_t; Float_t betaStarJet0_t; Float_t ptJet1_t; Float_t etaJet1_t; tree_passedEvents->Branch( "run", &run, "run/I" ); tree_passedEvents->Branch( "LS", &LS, "LS/I" ); tree_passedEvents->Branch( "nPU", &nPU, "nPU/I" ); tree_passedEvents->Branch( "PUReWeight", &PUReWeight, "PUReWeight/F" ); tree_passedEvents->Branch( "event", &event, "event/I" ); tree_passedEvents->Branch( "eventWeight", &eventWeight, "eventWeight/F"); tree_passedEvents->Branch( "eventWeight_noPU", &eventWeight_noPU, "eventWeight_noPU/F"); tree_passedEvents->Branch( "nvertex", &nvertex, "nvertex/I"); tree_passedEvents->Branch( "rhoPF", &rhoPF, "rhoPF/F"); tree_passedEvents->Branch( "rhoJetPF", &rhoJetPF, "rhoJetPF/F"); tree_passedEvents->Branch( "secondJetOK", &secondJetOK, "secondJetOK/O"); tree_passedEvents->Branch( "btagged", &btagged, "btagged/O"); tree_passedEvents->Branch( "mZ", &mZ, "mZ/F"); tree_passedEvents->Branch( "ptZ", &ptZ, "ptZ/F"); tree_passedEvents->Branch( "etaZ", &etaZ, "etaZ/F"); tree_passedEvents->Branch( "ptJet0", &ptJet0_t, "ptJet0_t/F"); tree_passedEvents->Branch( "etaJet0", &etaJet0_t, "etaJet0_t/F"); tree_passedEvents->Branch( "ptJet1", &ptJet1_t, "ptJet1_t/F"); tree_passedEvents->Branch( "etaJet1", &etaJet1_t, "etaJet1_t/F"); tree_passedEvents->Branch( "nChargedJet0", &nChargedJet0_t, "nChargedJet0_t/I"); tree_passedEvents->Branch( "nNeutralJet0", &nNeutralJet0_t, "nNeutralJet0_t/I"); tree_passedEvents->Branch( "ptDJet0", &ptDJet0_t, "ptDJet0_t/F"); //tree_passedEvents->Branch( "rmsCandJet0", &rmsCandJet0_t, "rmsCandJet[0]/F"); //tree_passedEvents->Branch( "betaStarJet0", &betaStarJet0_t, "betaStarJet[0]/F"); tree_passedEvents->Branch( "QGLikelihoodJet0", &QGlikelihood, "QGlikelihood/F"); tree_passedEvents->Branch( "QGLikelihood2012Jet0", &QGlikelihood2012, "QGlikelihood2012/F"); tree_passedEvents->Branch( "pdgIdPartJet0", &pdgIdPartJet_t, "pdgIdPart_t/I"); tree_passedEvents->Branch( "deltaPhi_jet", &deltaPhi_jet, "deltaPhi_jet/F"); //tree_passedEvents->Branch( "axis1Jet0" , &axis1Jet[0] , "axis1Jet[0]/F"); //tree_passedEvents->Branch( "axis2Jet0" , &axis2Jet[0] , "axis2Jet[0]/F"); //tree_passedEvents->Branch( "pullJet0" , &pullJet[0] , "pullJet[0]/F"); //tree_passedEvents->Branch( "tanaJet0" , &tanaJet[0] , "tanaJet[0]/F"); tree_passedEvents->Branch( "ptD_QCJet0" , &ptD_QCJet0_t , "ptD_QCJet0_t/F"); //tree_passedEvents->Branch( "rmsCand_QCJet0" , &rmsCand_QCJet[0] , "rmsCand_QCJet[0]/F"); tree_passedEvents->Branch( "axis1_QCJet0" , &axis1_QCJet0_t , "axis1_QCJet0_t/F"); tree_passedEvents->Branch( "axis2_QCJet0" , &axis2_QCJet0_t , "axis2_QCJet0_t/F"); //tree_passedEvents->Branch( "pull_QCJet0" , &pull_QCJet[0] , "pull_QCJet[0]/F"); //tree_passedEvents->Branch( "tana_QCJet0" , &tana_QCJet[0] , "tana_QCJet[0]/F"); tree_passedEvents->Branch( "nPFCand_QC_ptCutJet" , &nPFCand_QC_ptCutJet0_t , "nPFCand_QC_ptCutJet0_t/I"); //tree_passedEvents->Branch( "nChg_ptCutJet0" , &nChg_ptCutJet[0] , "nChg_ptCutJet[0]/I"); //tree_passedEvents->Branch( "nChg_QCJet0" , &nChg_QCJet[0] , "nChg_QCJet[0]/I"); //tree_passedEvents->Branch( "nChg_ptCut_QCJet0" , &nChg_ptCut_QCJet[0] , "nChg_ptCut_QCJet[0]/I"); //tree_passedEvents->Branch( "nNeutral_ptCutJet0" , &nNeutral_ptCutJet[0] , "nNeutral_ptCutJet[0]/I"); //tree_passedEvents->Branch( "RchgJet0" , &RchgJet[0] , "RchgJet[0]/F"); //tree_passedEvents->Branch( "RneutralJet0" , &RneutralJet[0] , "RneutralJet[0]/F"); //tree_passedEvents->Branch( "RJet0" , &RJet[0] , "RJet[0]/F"); //tree_passedEvents->Branch( "Rchg_QCJet0" , &Rchg_QCJet[0] , "Rchg_QCJet[0]/F"); tree_passedEvents->Branch( "betaStarJet0" , &betaStarJet0_t , "betaStarJet0_t/F"); QGLikelihoodCalculator* qglikeli = new QGLikelihoodCalculator("/afs/cern.ch/work/p/pandolf/public/QG/QG_QCD_Pt-15to3000_TuneZ2_Flat_8TeV_pythia6_Summer12_DR53X-PU_S10_START53_V7A-v1.root"); TRandom3* rand = new TRandom3(13); int nEntries = tree_->GetEntries(); //nEntries = 100000; std::map< int, std::map<int, std::vector<int> > > run_lumi_ev_map; int blockSize = TMath::Floor( (float)nEntries/nBlocks_ ); int iEventMin = iBlock_*blockSize; int iEventMax = (iBlock_+1)*blockSize; if( iEventMax>nEntries ) iEventMax = nEntries; std::cout << "-> Running on events: " << iEventMin << " - " << iEventMax << std::endl; for(int iEntry=iEventMin; iEntry<iEventMax; ++iEntry) { if( ((iEntry-iEventMin) % 100000)==0 ) std::cout << "Entry: " << (iEntry-iEventMin) << " /" << blockSize << std::endl; tree_->GetEntry(iEntry); if( eventWeight <= 0. ) eventWeight = 1.; int icut = 0; h1_cutflow_50100->Fill( icut++, eventWeight ); h1_nvertex->Fill( nvertex, eventWeight); bool isMC = run<5; if( isMC ) { // PU reweighting: eventWeight_noPU = eventWeight; } else { //it's data: remove duplicate events (if any): std::map<int, std::map<int, std::vector<int> > >::iterator it; it = run_lumi_ev_map.find(run); if( it==run_lumi_ev_map.end() ) { std::vector<int> events; events.push_back(event); std::map<int, std::vector<int> > lumi_ev_map; lumi_ev_map.insert( std::pair<int,std::vector<int> >(LS, events)); run_lumi_ev_map.insert( std::pair<int, std::map<int, std::vector<int> > > (run, lumi_ev_map) ); } else { //run exists, look for LS std::map<int, std::vector<int> >::iterator it_LS; it_LS = it->second.find( LS ); if( it_LS==(it->second.end()) ) { std::vector<int> events; events.push_back(event); it->second.insert( std::pair<int, std::vector<int> > (LS, events) ); } else { //LS exists, look for event std::vector<int>::iterator ev; for( ev=it_LS->second.begin(); ev!=it_LS->second.end(); ++ev ) if( *ev==event ) break; if( ev==it_LS->second.end() ) { it_LS->second.push_back(event); } else { std::cout << "DISCARDING DUPLICATE EVENT!! Run: " << run << " LS: " << LS << " event: " << event << std::endl; continue; } } } } //if is mc h1_nvertex_PUW->Fill( nvertex, eventWeight); TLorentzVector lept1, lept2; lept1.SetPtEtaPhiE( ptLeptZ1, etaLeptZ1, phiLeptZ1, eLeptZ1 ); lept2.SetPtEtaPhiE( ptLeptZ2, etaLeptZ2, phiLeptZ2, eLeptZ2 ); TLorentzVector Z = lept1 + lept2; ptZ = Z.Pt(); mZ = Z.M(); etaZ = Z.Eta(); h1_mZ->Fill( Z.M(), eventWeight ); if( Z.M()<70. || Z.M()>110. ) continue; if( nJets==0 ) continue; if( ptJet[0] < 20. ) continue; // jet id: TLorentzVector jet; jet.SetPtEtaPhiE( ptJet[0], etaJet[0], phiJet[0], eJet[0] ); if( fabs(jet.Eta())<2.4 && nChargedJet[0]==0 ) continue; if( (nNeutralJet[0]+nChargedJet[0])==1 ) continue; if( (ePhotonsJet[0]+eHFEMJet[0])/jet.E()>0.99 ) continue; if( (eNeutralHadronsJet[0])/jet.E()>0.99 ) continue; pdgIdPartJet_t = 0; if( isMC ) { // check if matched to parton/genjet TLorentzVector part; part.SetPtEtaPhiE( ptPartJet[0], etaPartJet[0], phiPartJet[0], ptPartJet[0] ); TLorentzVector genJet; genJet.SetPtEtaPhiE( ptGenJet[0], etaGenJet[0], phiGenJet[0], ptGenJet[0] ); float deltaR_jet_part = jet.DeltaR(part); if( deltaR_jet_part<0.3 ) { pdgIdPartJet_t = pdgIdPartJet[0]; } else { float deltaR_jet_genjet = jet.DeltaR(genJet); if( deltaR_jet_genjet < 0.3 ) { //undefined pdgIdPartJet_t = -999; } else { pdgIdPartJet_t = 0; //PU } } // else (if not matched to parton) } // if is MC //leading jet and Z back2back in transverse plane bool back2back = true; deltaPhi_jet = fabs(delta_phi(Z.Phi(), phiJet[0])); Float_t pi = TMath::Pi(); float deltaPhiThreshold = 1.; if( fabs(deltaPhi_jet) < (pi - deltaPhiThreshold) ) back2back = false; //loose back to back for now // cut away b-jets: //if( trackCountingHighEffBJetTagsJetReco>1.7 ) continue; btagged = combinedSecondaryVertexBJetTagJet[0]>0.244; if( btagged ) continue; if( nJets>1 ) secondJetOK = ( ptJet[1] < secondJetThreshold_*Z.Pt() || ptJet[1] < 10. ); else secondJetOK = true; ptJet0_t = jet.Pt(); etaJet0_t = jet.Eta(); nChargedJet0_t = nChargedJet[0]; nNeutralJet0_t = nNeutralJet[0]; ptDJet0_t = ptDJet[0]; ptD_QCJet0_t = ptD_QCJet[0]; axis1_QCJet0_t = axis1_QCJet[0]; axis2_QCJet0_t = axis2_QCJet[0]; betaStarJet0_t= betaStarJet[0]; nPFCand_QC_ptCutJet0_t = nPFCand_QC_ptCutJet[0]; ptJet1_t = (nJets>0) ? ptJet[1] : 0.; etaJet1_t = (nJets>0) ? etaJet[1] : 10.; QGlikelihood = qglikeli->computeQGLikelihoodPU( ptJet[0], rhoPF, nChargedJet[0], nNeutralJet[0], ptDJet[0], -1. ); QGlikelihood2012 = qglikeli->computeQGLikelihood2012( ptJet[0], etaJet[0], rhoPF, nPFCand_QC_ptCutJet[0], ptD_QCJet[0], axis2_QCJet[0] ); tree_passedEvents->Fill(); } outFile->cd(); tree_passedEvents->Write(); h1_cutflow_50100->Write(); h1_nvertex->Write(); h1_nvertex_PUW->Write(); h1_ptZ->Write(); h1_mZ->Write(); h1_phiZ->Write(); h1_etaZ->Write(); h1_ptJetReco->Write(); h1_pt2ndJetReco->Write(); h1_nEvents_passed_quark->Write(); h1_nEvents_passed->Write(); outFile->Close(); }
/** * @brief Matching L1 jets from L1UpgradeTree, to reference GenJets from L1ExtraTree. * * @author Robin Aggleton, March 2016 */ int main(int argc, char* argv[]) { cout << "Running Matcher, L1 Jets to GenJets" << std::endl; // deal with user args RunMatcherOpts opts(argc, argv); /////////////////////// // SETUP INPUT FILES // /////////////////////// // get input TTrees // Reference jets - GenJets TString refJetDirectory = opts.refJetDirectory(); L1GenericTree<L1AnalysisGeneratorDataFormat> refJetTree(opts.inputFilename(), refJetDirectory+"/L1GenTree", "Generator"); L1AnalysisGeneratorDataFormat * refData = refJetTree.getData(); // L1 jets TString l1JetDirectory = opts.l1JetDirectory(); L1GenericTree<L1AnalysisL1UpgradeDataFormat> l1JetTree(opts.inputFilename(), l1JetDirectory+"/L1UpgradeTree", "L1Upgrade"); L1AnalysisL1UpgradeDataFormat * l1Data = l1JetTree.getData(); // hold Event tree L1GenericTree<L1AnalysisEventDataFormat> eventTree(opts.inputFilename(), "l1EventTree/L1EventTree", "Event"); L1AnalysisEventDataFormat * eventData = eventTree.getData(); // input filename stem (no .root) fs::path inPath(opts.inputFilename()); TString inStem(inPath.stem().c_str()); //////////////////////// // SETUP OUTPUT FILES // //////////////////////// // setup output file to store results // check that we're not overwriting the input file! if (opts.outputFilename() == opts.inputFilename()) { throw std::runtime_error("Cannot use input filename as output filename!"); } TFile * outFile = openFile(opts.outputFilename(), "RECREATE"); fs::path outPath(opts.outputFilename()); TString outDir(outPath.parent_path().c_str()); if (outDir != "") { outDir += "/"; } // setup output tree to store raw variable for quick plotting/debugging TTree outTree("valid", "valid"); // Quantities for L1 jets: float out_pt(-1.), out_eta(99.), out_phi(99.); int out_nL1(-1); // number of jets in the event, int out_indL1(-1); // index of this jet in the collection (ordered by descending pT) outTree.Branch("pt", &out_pt, "pt/Float_t"); outTree.Branch("eta", &out_eta, "eta/Float_t"); outTree.Branch("phi", &out_phi, "phi/Float_t"); outTree.Branch("nL1", &out_nL1, "nL1/Int_t"); outTree.Branch("indL1", &out_indL1, "indL1/Int_t"); // Quantities for reference jets (GenJet, etc): float out_ptRef(-1.), out_etaRef(99.), out_phiRef(99.); int out_nRef(-1); // number of jets in the event, int out_indRef(-1); // index of this jet in the collection (ordered by descending pT) outTree.Branch("ptRef", &out_ptRef, "ptRef/Float_t"); outTree.Branch("etaRef", &out_etaRef, "etaRef/Float_t"); outTree.Branch("phiRef", &out_phiRef, "phiRef/Float_t"); outTree.Branch("nRef", &out_nRef, "nRef/Int_t"); outTree.Branch("inRef", &out_indRef, "indRef/Int_t"); // Quantities to describe relationship between the two: float out_rsp(-1.); float out_dr(99.), out_deta(99.), out_dphi(99.); float out_ptDiff(99999.), out_resL1(99.), out_resRef(99.); int out_nMatches(0); outTree.Branch("ptDiff", &out_ptDiff, "ptDiff/Float_t"); // L1 - Ref outTree.Branch("rsp", &out_rsp, "rsp/Float_t"); // response = l1 pT/ ref jet pT outTree.Branch("dr", &out_dr, "dr/Float_t"); outTree.Branch("deta", &out_deta, "deta/Float_t"); outTree.Branch("dphi", &out_dphi, "dphi/Float_t"); outTree.Branch("resL1", &out_resL1, "resL1/Float_t"); // resolution = L1 - Ref / L1 outTree.Branch("resRef", &out_resRef, "resRef/Float_t"); // resolution = L1 - Ref / Ref outTree.Branch("nMatches", &out_nMatches, "nMatches/Int_t"); // PU quantities float out_trueNumInteractions(-1.), out_numPUVertices(-1.); int out_recoNVtx(0); outTree.Branch("trueNumInteractions", &out_trueNumInteractions, "trueNumInteractions/Float_t"); outTree.Branch("numPUVertices", &out_numPUVertices, "numPUVertices/Float_t"); outTree.Branch("recoNVtx", &out_recoNVtx, "recoNVtx/Int_t"); // Event number ULong64_t out_event(0); outTree.Branch("event", &out_event, "event/Int_t"); // L1 sums int out_nL1JetsSum(0); float out_httL1(0.); float out_mhtL1(0.), out_mhtPhiL1(0.); outTree.Branch("nL1JetsSum", &out_nL1JetsSum); outTree.Branch("httL1", &out_httL1); outTree.Branch("mhtL1", &out_mhtL1); outTree.Branch("mhtPhiL1", &out_mhtPhiL1); // Reference jet Sums int out_nRefJetsSum(0); float out_httRef(0.); float out_mhtRef(0.), out_mhtPhiRef(0.); outTree.Branch("nRefJetsSum", &out_nRefJetsSum); outTree.Branch("httRef", &out_httRef); outTree.Branch("mhtRef", &out_mhtRef); outTree.Branch("mhtPhiRef", &out_mhtPhiRef); // check # events in boths trees is same Long64_t nEntriesRef = refJetTree.getEntries(); Long64_t nEntriesL1 = l1JetTree.getEntries(); Long64_t nEntries(0); if (nEntriesRef != nEntriesL1) { throw std::range_error("Different number of events in L1 & ref trees"); } else { nEntries = (opts.nEvents() > 0) ? opts.nEvents() : nEntriesL1; cout << "Running over " << nEntries << " events." << endl; } /////////////////////// // SETUP JET MATCHER // /////////////////////// double maxDeltaR(opts.deltaR()), minRefJetPt(opts.refJetMinPt()), maxRefJetPt(5000.); double minL1JetPt(opts.l1JetMinPt()), maxL1JetPt(5000.), maxJetEta(5.); // use base class smart pointer for ease of swapping in/out different // matchers if so desired std::unique_ptr<Matcher> matcher(new DeltaR_Matcher(maxDeltaR, minRefJetPt, maxRefJetPt, minL1JetPt, maxL1JetPt, maxJetEta)); std::cout << *matcher << std::endl; ////////////////////// // LOOP OVER EVENTS // ////////////////////// // produce matching pairs and store Long64_t drawCounter = 0; for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) { if (iEntry % 10000 == 0) { cout << "Entry: " << iEntry << " at " << getCurrentTime() << endl; } if (refJetTree.getEntry(iEntry) < 1 || l1JetTree.getEntry(iEntry) < 1 || eventTree.getEntry(iEntry) < 1)// || recoVtxTree.getEntry(iEntry) < 1) break; //////////////////////// // Generic event info // //////////////////////// out_event = eventData->event; ///////////////////////////// // Store pileup quantities // ///////////////////////////// // note these get stored once per pair of matched jets NOT once per event out_trueNumInteractions = refData->nMeanPU; out_numPUVertices = refData->nVtx; // out_recoNVtx = recoVtxData->nVtx; ///////////////////////////////////////////// // Make vectors of ref & L1 jets from trees // ///////////////////////////////////////////// std::vector<TLorentzVector> refJets = makeTLorentzVectors(refData->jetPt, refData->jetEta, refData->jetPhi); std::vector<TLorentzVector> l1Jets = makeTLorentzVectors(l1Data->jetEt, l1Data->jetEta, l1Data->jetPhi); out_nL1 = l1Jets.size(); out_nRef = refJets.size(); if (out_nL1 == 0 || out_nRef == 0) continue; //////////////// // Store sums // //////////////// // L1 sums std::vector<TLorentzVector> httL1Jets = getJetsForHTT(l1Jets); out_nL1JetsSum = httL1Jets.size(); out_httL1 = l1Data->sumEt[2]; out_mhtL1 = l1Data->sumEt[3]; out_mhtPhiL1 = l1Data->sumPhi[3]; // float httL1_check = scalarSumPt(httL1Jets); // Check my calc with stored value // Doens't make sense to do this when applying calibrations on the fly // if (fabs(out_httL1 - httL1_check) > 0.01 && out_httL1 < 2047.5) { // cout << "HTT L1 not agreeing with calculation: " + lexical_cast<std::string>(out_httL1) + " vs " + lexical_cast<std::string>(httL1_check) << endl; // for (const auto& itr: l1Jets) { // cout << itr.Pt() << " " << itr.Eta() << endl; // } // } // TLorentzVector mhtL1_check = vectorSum(httL1Jets); // Override sums with calibrated jets // out_httL1 = httL1_check; // out_mhtL1 = mhtL1_check.Pt(); // out_mhtPhiL1 = mhtL1_check.Phi(); // Ref jet sums std::vector<TLorentzVector> httRefJets = getJetsForHTT(refJets); out_nRefJetsSum = httRefJets.size(); out_httRef = scalarSumPt(httRefJets); // Pass jets to matcher, do matching TLorentzVector mhtVecRef = vectorSum(httRefJets); out_mhtRef = mhtVecRef.Pt(); out_mhtPhiRef = mhtVecRef.Phi(); /////////////////////////////////////// // Pass jets to matcher, do matching // /////////////////////////////////////// matcher->setRefJets(refJets); matcher->setL1Jets(l1Jets); std::vector<MatchedPair> matchResults = matcher->getMatchingPairs(); // matcher->printMatches(); // for debugging ////////////////////////////////////////// // store L1 & ref jet variables in tree // ////////////////////////////////////////// out_nMatches = matchResults.size(); for (const auto &it: matchResults) { // std::cout << it << std::endl; out_pt = it.l1Jet().Et(); out_eta = it.l1Jet().Eta(); out_phi = it.l1Jet().Phi(); out_dr = it.refJet().DeltaR(it.l1Jet()); out_deta = it.refJet().Eta() - it.l1Jet().Eta(); out_dphi = it.refJet().DeltaPhi(it.l1Jet()); out_ptRef = it.refJet().Pt(); out_etaRef = it.refJet().Eta(); out_phiRef = it.refJet().Phi(); out_ptDiff = out_pt - out_ptRef; out_rsp = out_pt/out_ptRef; out_resL1 = out_ptDiff/out_pt; out_resRef = out_ptDiff/out_ptRef; outTree.Fill(); } /////////////////////////////////////////////////// // debugging plot - plots eta vs phi map of jets // /////////////////////////////////////////////////// if (drawCounter < opts.drawNumber()) { if (matchResults.size() > 0) { TString label = TString::Format( "%.1f < E^{gen}_{T} < %.1f GeV, " \ "L1 jet %.1f < E^{L1}_{T} < %.1f GeV, |#eta_{jet}| < %.1f", minRefJetPt, maxRefJetPt, minL1JetPt, maxL1JetPt, maxJetEta); // get jets post pT, eta cuts JetDrawer drawer(matcher->getRefJets(), matcher->getL1Jets(), matchResults, label); TString pdfname = TString::Format("%splots_%s_%s_%s/jets_%lld.pdf", outDir.Data(), inStem.Data(), "gen", "l1", iEntry); drawer.drawAndSave(pdfname); drawCounter++; } } } // end of loop over entries // save tree to new file and cleanup outTree.Write("", TObject::kOverwrite); outFile->Close(); return 0; }
void selectAntiWm(const TString conf="wm.conf", // input file const TString outputDir="." // output directory ) { gBenchmark->Start("selectAntiWm"); //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== const Double_t PT_CUT = 25; const Double_t ETA_CUT = 2.4; const Double_t MUON_MASS = 0.105658369; const Double_t VETO_PT = 10; const Double_t VETO_ETA = 2.4; const Int_t BOSON_ID = 24; const Int_t LEPTON_ID = 13; // load trigger menu const baconhep::TTrigger triggerMenu("../../BaconAna/DataFormats/data/HLT_50nsGRun"); // load pileup reweighting file TFile *f_rw = TFile::Open("../Tools/pileup_weights_2015B.root", "read"); TH1D *h_rw = (TH1D*) f_rw->Get("npv_rw"); //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== vector<TString> snamev; // sample name (for output files) vector<CSample*> samplev; // data/MC samples // // parse .conf file // confParse(conf, snamev, samplev); const Bool_t hasData = (samplev[0]->fnamev.size()>0); // Create output directory gSystem->mkdir(outputDir,kTRUE); const TString ntupDir = outputDir + TString("/ntuples"); gSystem->mkdir(ntupDir,kTRUE); // // Declare output ntuple variables // UInt_t runNum, lumiSec, evtNum; UInt_t npv, npu; UInt_t id_1, id_2; Double_t x_1, x_2, xPDF_1, xPDF_2; Double_t scalePDF, weightPDF; TLorentzVector *genV=0, *genLep=0; Float_t genVPt, genVPhi, genVy, genVMass; Float_t genLepPt, genLepPhi; Float_t scale1fb, puWeight; Float_t met, metPhi, sumEt, mt, u1, u2; Float_t tkMet, tkMetPhi, tkSumEt, tkMt, tkU1, tkU2; Float_t mvaMet, mvaMetPhi, mvaSumEt, mvaMt, mvaU1, mvaU2; Int_t q; TLorentzVector *lep=0; ///// muon specific ///// Float_t trkIso, emIso, hadIso; Float_t pfChIso, pfGamIso, pfNeuIso, pfCombIso; Float_t d0, dz; Float_t muNchi2; UInt_t nPixHits, nTkLayers, nValidHits, nMatch, typeBits; // Data structures to store info from TTrees baconhep::TEventInfo *info = new baconhep::TEventInfo(); baconhep::TGenEventInfo *gen = new baconhep::TGenEventInfo(); TClonesArray *genPartArr = new TClonesArray("baconhep::TGenParticle"); TClonesArray *muonArr = new TClonesArray("baconhep::TMuon"); TClonesArray *vertexArr = new TClonesArray("baconhep::TVertex"); TFile *infile=0; TTree *eventTree=0; // // loop over samples // for(UInt_t isam=0; isam<samplev.size(); isam++) { // Assume data sample is first sample in .conf file // If sample is empty (i.e. contains no ntuple files), skip to next sample Bool_t isData=kFALSE; if(isam==0 && !hasData) continue; else if (isam==0) isData=kTRUE; // Assume signal sample is given name "wm" Bool_t isSignal = (snamev[isam].CompareTo("wm",TString::kIgnoreCase)==0); // flag to reject W->mnu events when selecting wrong-flavor background events Bool_t isWrongFlavor = (snamev[isam].CompareTo("wx",TString::kIgnoreCase)==0); CSample* samp = samplev[isam]; // // Set up output ntuple // TString outfilename = ntupDir + TString("/") + snamev[isam] + TString("_select.root"); TFile *outFile = new TFile(outfilename,"RECREATE"); TTree *outTree = new TTree("Events","Events"); outTree->Branch("runNum", &runNum, "runNum/i"); // event run number outTree->Branch("lumiSec", &lumiSec, "lumiSec/i"); // event lumi section outTree->Branch("evtNum", &evtNum, "evtNum/i"); // event number outTree->Branch("npv", &npv, "npv/i"); // number of primary vertices outTree->Branch("npu", &npu, "npu/i"); // number of in-time PU events (MC) outTree->Branch("id_1", &id_1, "id_1/i"); // PDF info -- parton ID for parton 1 outTree->Branch("id_2", &id_2, "id_2/i"); // PDF info -- parton ID for parton 2 outTree->Branch("x_1", &x_1, "x_1/d"); // PDF info -- x for parton 1 outTree->Branch("x_2", &x_2, "x_2/d"); // PDF info -- x for parton 2 outTree->Branch("xPDF_1", &xPDF_1, "xPDF_1/d"); // PDF info -- x*F for parton 1 outTree->Branch("xPDF_2", &xPDF_2, "xPDF_2/d"); // PDF info -- x*F for parton 2 outTree->Branch("scalePDF", &scalePDF, "scalePDF/d"); // PDF info -- energy scale of parton interaction outTree->Branch("weightPDF", &weightPDF, "weightPDF/d"); // PDF info -- PDF weight outTree->Branch("genV", "TLorentzVector", &genV); // GEN boson 4-vector (signal MC) outTree->Branch("genLep", "TLorentzVector", &genLep); // GEN lepton 4-vector (signal MC) outTree->Branch("genVPt", &genVPt, "genVPt/F"); // GEN boson pT (signal MC) outTree->Branch("genVPhi", &genVPhi, "genVPhi/F"); // GEN boson phi (signal MC) outTree->Branch("genVy", &genVy, "genVy/F"); // GEN boson rapidity (signal MC) outTree->Branch("genVMass", &genVMass, "genVMass/F"); // GEN boson mass (signal MC) outTree->Branch("genLepPt", &genLepPt, "genLepPt/F"); // GEN lepton pT (signal MC) outTree->Branch("genLepPhi", &genLepPhi, "genLepPhi/F"); // GEN lepton phi (signal MC) outTree->Branch("scale1fb", &scale1fb, "scale1fb/F"); // event weight per 1/fb (MC) outTree->Branch("puWeight", &puWeight, "puWeight/F"); // scale factor for pileup reweighting (MC) outTree->Branch("met", &met, "met/F"); // MET outTree->Branch("metPhi", &metPhi, "metPhi/F"); // phi(MET) outTree->Branch("sumEt", &sumEt, "sumEt/F"); // Sum ET outTree->Branch("mt", &mt, "mt/F"); // transverse mass outTree->Branch("u1", &u1, "u1/F"); // parallel component of recoil outTree->Branch("u2", &u2, "u2/F"); // perpendicular component of recoil outTree->Branch("tkMet", &tkMet, "tkMet/F"); // MET (track MET) outTree->Branch("tkMetPhi", &tkMetPhi, "tkMetPhi/F"); // phi(MET) (track MET) outTree->Branch("tkSumEt", &tkSumEt, "tkSumEt/F"); // Sum ET (track MET) outTree->Branch("tkMt", &tkMt, "tkMt/F"); // transverse mass (track MET) outTree->Branch("tkU1", &tkU1, "tkU1/F"); // parallel component of recoil (track MET) outTree->Branch("tkU2", &tkU2, "tkU2/F"); // perpendicular component of recoil (track MET) outTree->Branch("mvaMet", &mvaMet, "mvaMet/F"); // MVA MET outTree->Branch("mvaMetPhi", &mvaMetPhi, "mvaMetPhi/F"); // phi(MVA MET) outTree->Branch("mvaSumEt", &mvaSumEt, "mvaSumEt/F"); // Sum ET (MVA MET) outTree->Branch("mvaMt", &mvaMt, "mvaMt/F"); // transverse mass (MVA MET) outTree->Branch("mvaU1", &mvaU1, "mvaU1/F"); // parallel component of recoil (mva MET) outTree->Branch("mvaU2", &mvaU2, "mvaU2/F"); // perpendicular component of recoil (mva MET) outTree->Branch("q", &q, "q/I"); // lepton charge outTree->Branch("lep", "TLorentzVector", &lep); // lepton 4-vector ///// muon specific ///// outTree->Branch("trkIso", &trkIso, "trkIso/F"); // track isolation of lepton outTree->Branch("emIso", &emIso, "emIso/F"); // ECAL isolation of lepton outTree->Branch("hadIso", &hadIso, "hadIso/F"); // HCAL isolation of lepton outTree->Branch("pfChIso", &pfChIso, "pfChIso/F"); // PF charged hadron isolation of lepton outTree->Branch("pfGamIso", &pfGamIso, "pfGamIso/F"); // PF photon isolation of lepton outTree->Branch("pfNeuIso", &pfNeuIso, "pfNeuIso/F"); // PF neutral hadron isolation of lepton outTree->Branch("pfCombIso", &pfCombIso, "pfCombIso/F"); // PF combined isolation of lepton outTree->Branch("d0", &d0, "d0/F"); // transverse impact parameter of lepton outTree->Branch("dz", &dz, "dz/F"); // longitudinal impact parameter of lepton outTree->Branch("muNchi2", &muNchi2, "muNchi2/F"); // muon fit normalized chi^2 of lepton outTree->Branch("nPixHits", &nPixHits, "nPixHits/i"); // number of pixel hits of muon outTree->Branch("nTkLayers", &nTkLayers, "nTkLayers/i"); // number of tracker layers of muon outTree->Branch("nMatch", &nMatch, "nMatch/i"); // number of matched segments of muon outTree->Branch("nValidHits", &nValidHits, "nValidHits/i"); // number of valid muon hits of muon outTree->Branch("typeBits", &typeBits, "typeBits/i"); // number of valid muon hits of muon // // loop through files // const UInt_t nfiles = samp->fnamev.size(); for(UInt_t ifile=0; ifile<nfiles; ifile++) { // Read input file and get the TTrees cout << "Processing " << samp->fnamev[ifile] << " [xsec = " << samp->xsecv[ifile] << " pb] ... "; cout.flush(); infile = TFile::Open(samp->fnamev[ifile]); assert(infile); Bool_t hasJSON = kFALSE; baconhep::RunLumiRangeMap rlrm; if(samp->jsonv[ifile].CompareTo("NONE")!=0) { hasJSON = kTRUE; rlrm.addJSONFile(samp->jsonv[ifile].Data()); } eventTree = (TTree*)infile->Get("Events"); assert(eventTree); eventTree->SetBranchAddress("Info", &info); TBranch *infoBr = eventTree->GetBranch("Info"); eventTree->SetBranchAddress("Muon", &muonArr); TBranch *muonBr = eventTree->GetBranch("Muon"); eventTree->SetBranchAddress("PV", &vertexArr); TBranch *vertexBr = eventTree->GetBranch("PV"); Bool_t hasGen = eventTree->GetBranchStatus("GenEvtInfo"); TBranch *genBr=0, *genPartBr=0; if(hasGen) { eventTree->SetBranchAddress("GenEvtInfo", &gen); genBr = eventTree->GetBranch("GenEvtInfo"); eventTree->SetBranchAddress("GenParticle",&genPartArr); genPartBr = eventTree->GetBranch("GenParticle"); } // Compute MC event weight per 1/fb const Double_t xsec = samp->xsecv[ifile]; Double_t totalWeight=0; if (hasGen) { TH1D *hall = new TH1D("hall", "", 1,0,1); eventTree->Draw("0.5>>hall", "GenEvtInfo->weight"); totalWeight=hall->Integral(); delete hall; hall=0; } // // loop over events // Double_t nsel=0, nselvar=0; for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { infoBr->GetEntry(ientry); if(ientry%1000000==0) cout << "Processing event " << ientry << ". " << (double)ientry/(double)eventTree->GetEntries()*100 << " percent done with this file." << endl; Double_t weight=1; if(xsec>0 && totalWeight>0) weight = xsec/totalWeight; if(hasGen) { genPartArr->Clear(); genBr->GetEntry(ientry); genPartBr->GetEntry(ientry); weight*=gen->weight; } // veto w -> xv decays for signal and w -> mv for bacground samples (needed for inclusive WToLNu sample) if (isWrongFlavor && hasGen && fabs(toolbox::flavor(genPartArr, BOSON_ID))==LEPTON_ID) continue; else if (isSignal && hasGen && fabs(toolbox::flavor(genPartArr, BOSON_ID))!=LEPTON_ID) continue; // check for certified lumi (if applicable) baconhep::RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec); if(hasJSON && !rlrm.hasRunLumi(rl)) continue; // trigger requirement if (!isMuonTrigger(triggerMenu, info->triggerBits)) continue; // good vertex requirement if(!(info->hasGoodPV)) continue; // // SELECTION PROCEDURE: // (1) Look for 1 good muon matched to trigger // (2) Reject event if another muon is present passing looser cuts // muonArr->Clear(); muonBr->GetEntry(ientry); Int_t nLooseLep=0; const baconhep::TMuon *goodMuon=0; Bool_t passSel=kFALSE; for(Int_t i=0; i<muonArr->GetEntriesFast(); i++) { const baconhep::TMuon *mu = (baconhep::TMuon*)((*muonArr)[i]); if(fabs(mu->eta) > VETO_PT) continue; // loose lepton |eta| cut if(mu->pt < VETO_ETA) continue; // loose lepton pT cut // if(passMuonLooseID(mu)) nLooseLep++; // loose lepton selection if(nLooseLep>1) { // extra lepton veto passSel=kFALSE; break; } if(fabs(mu->eta) > ETA_CUT) continue; // lepton |eta| cut if(mu->pt < PT_CUT) continue; // lepton pT cut if(!passAntiMuonID(mu)) continue; // lepton anti-selection if(!isMuonTriggerObj(triggerMenu, mu->hltMatchBits, kFALSE)) continue; passSel=kTRUE; goodMuon = mu; } if(passSel) { /******** We have a W candidate! HURRAY! ********/ nsel+=weight; nselvar+=weight*weight; TLorentzVector vLep; vLep.SetPtEtaPhiM(goodMuon->pt, goodMuon->eta, goodMuon->phi, MUON_MASS); // // Fill tree // runNum = info->runNum; lumiSec = info->lumiSec; evtNum = info->evtNum; vertexArr->Clear(); vertexBr->GetEntry(ientry); npv = vertexArr->GetEntries(); npu = info->nPUmean; genV = new TLorentzVector(0,0,0,0); genLep = new TLorentzVector(0,0,0,0); genVPt = -999; genVPhi = -999; genVy = -999; genVMass = -999; u1 = -999; u2 = -999; tkU1 = -999; tkU2 = -999; mvaU1 = -999; mvaU2 = -999; id_1 = -999; id_2 = -999; x_1 = -999; x_2 = -999; xPDF_1 = -999; xPDF_2 = -999; scalePDF = -999; weightPDF = -999; if(isSignal && hasGen) { TLorentzVector *gvec=new TLorentzVector(0,0,0,0); TLorentzVector *glep1=new TLorentzVector(0,0,0,0); TLorentzVector *glep2=new TLorentzVector(0,0,0,0); toolbox::fillGen(genPartArr, BOSON_ID, gvec, glep1, glep2,1); if (gvec && glep1) { genV = new TLorentzVector(0,0,0,0); genV->SetPtEtaPhiM(gvec->Pt(),gvec->Eta(),gvec->Phi(),gvec->M()); genLep = new TLorentzVector(0,0,0,0); genLep->SetPtEtaPhiM(glep1->Pt(),glep1->Eta(),glep1->Phi(),glep1->M()); genVPt = gvec->Pt(); genVPhi = gvec->Phi(); genVy = gvec->Rapidity(); genVMass = gvec->M(); genLepPt = glep1->Pt(); genLepPhi = glep1->Phi(); TVector2 vWPt((genVPt)*cos(genVPhi),(genVPt)*sin(genVPhi)); TVector2 vLepPt(vLep.Px(),vLep.Py()); TVector2 vMet((info->pfMETC)*cos(info->pfMETCphi), (info->pfMETC)*sin(info->pfMETCphi)); TVector2 vU = -1.0*(vMet+vLepPt); u1 = ((vWPt.Px())*(vU.Px()) + (vWPt.Py())*(vU.Py()))/(genVPt); // u1 = (pT . u)/|pT| u2 = ((vWPt.Px())*(vU.Py()) - (vWPt.Py())*(vU.Px()))/(genVPt); // u2 = (pT x u)/|pT| TVector2 vTkMet((info->trkMET)*cos(info->trkMETphi), (info->trkMET)*sin(info->trkMETphi)); TVector2 vTkU = -1.0*(vTkMet+vLepPt); tkU1 = ((vWPt.Px())*(vTkU.Px()) + (vWPt.Py())*(vTkU.Py()))/(genVPt); // u1 = (pT . u)/|pT| tkU2 = ((vWPt.Px())*(vTkU.Py()) - (vWPt.Py())*(vTkU.Px()))/(genVPt); // u2 = (pT x u)/|pT| TVector2 vMvaMet((info->mvaMET)*cos(info->mvaMETphi), (info->mvaMET)*sin(info->mvaMETphi)); TVector2 vMvaU = -1.0*(vMvaMet+vLepPt); mvaU1 = ((vWPt.Px())*(vMvaU.Px()) + (vWPt.Py())*(vMvaU.Py()))/(genVPt); // u1 = (pT . u)/|pT| mvaU2 = ((vWPt.Px())*(vMvaU.Py()) - (vWPt.Py())*(vMvaU.Px()))/(genVPt); // u2 = (pT x u)/|pT| } id_1 = gen->id_1; id_2 = gen->id_2; x_1 = gen->x_1; x_2 = gen->x_2; xPDF_1 = gen->xPDF_1; xPDF_2 = gen->xPDF_2; scalePDF = gen->scalePDF; weightPDF = gen->weight; delete gvec; delete glep1; delete glep2; gvec=0; glep1=0; glep2=0; } scale1fb = weight; puWeight = h_rw->GetBinContent(info->nPUmean+1); met = info->pfMETC; metPhi = info->pfMETCphi; sumEt = 0; mt = sqrt( 2.0 * (vLep.Pt()) * (info->pfMETC) * (1.0-cos(toolbox::deltaPhi(vLep.Phi(),info->pfMETCphi))) ); tkMet = info->trkMET; tkMetPhi = info->trkMETphi; tkSumEt = 0; tkMt = sqrt( 2.0 * (vLep.Pt()) * (info->trkMET) * (1.0-cos(toolbox::deltaPhi(vLep.Phi(),info->trkMETphi))) ); mvaMet = info->mvaMET; mvaMetPhi = info->mvaMETphi; mvaSumEt = 0; mvaMt = sqrt( 2.0 * (vLep.Pt()) * (info->mvaMET) * (1.0-cos(toolbox::deltaPhi(vLep.Phi(),info->mvaMETphi))) ); q = goodMuon->q; lep = &vLep; ///// muon specific ///// trkIso = goodMuon->trkIso; emIso = goodMuon->ecalIso; hadIso = goodMuon->hcalIso; pfChIso = goodMuon->chHadIso; pfGamIso = goodMuon->gammaIso; pfNeuIso = goodMuon->neuHadIso; pfCombIso = goodMuon->chHadIso + TMath::Max(goodMuon->neuHadIso + goodMuon->gammaIso - 0.5*(goodMuon->puIso),Double_t(0)); d0 = goodMuon->d0; dz = goodMuon->dz; muNchi2 = goodMuon->muNchi2; nPixHits = goodMuon->nPixHits; nTkLayers = goodMuon->nTkLayers; nMatch = goodMuon->nMatchStn; nValidHits = goodMuon->nValidHits; typeBits = goodMuon->typeBits; outTree->Fill(); delete genV; delete genLep; genV=0, genLep=0, lep=0; } } delete infile; infile=0, eventTree=0; cout << nsel << " +/- " << sqrt(nselvar); if(isam!=0) cout << " per 1/fb"; cout << endl; } outFile->Write(); outFile->Close(); } delete h_rw; delete f_rw; delete info; delete gen; delete genPartArr; delete muonArr; delete vertexArr; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << " W -> mu nu" << endl; cout << " pT > " << PT_CUT << endl; cout << " |eta| < " << ETA_CUT << endl; cout << endl; cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; gBenchmark->Show("selectAntiWm"); }
void pgsAnalysis::Loop() { double tHrec, tZ1m, tZ2m, tcosthetaStar, tPhi, tPhi1, tcostheta1, tcostheta2,tHrec_constr,tZ1m_constr, tZ2m_constr; string ttype; hists->Branch("Hrec", &tHrec); hists->Branch("Z1m", &tZ1m); hists->Branch("Z2m", &tZ2m); hists->Branch("costhetaStar", &tcosthetaStar); hists->Branch("Phi", &tPhi); hists->Branch("Phi1", &tPhi1); hists->Branch("costheta1", &tcostheta1); hists->Branch("costheta2", &tcostheta2); hists->Branch("type", &ttype); //event type!! int eeee, xxxx, eexx, xxee; double Zmass = 91.19; double vZmass; if (pairing == 0){ vZmass = 91.19; } else{ vZmass = 45.; } TVectorT<double> elSum(4); TVectorT<double> muSum(4); //electrons array vector<int> el; int elC = 0; //muons array vector<int> mu; int muC = 0; //antielectrons array vector<int> antiel; int antielC = 0; //antimuons array vector<int> antimu; int antimuC = 0; vector<TVector3> leptons; TVector3 lep1,lep2,lep3,lep4; TVector3 Za, Zb, Zc, Zd, H; int lCounter = 0; int totaLlCounter = 0; int goodEventCounter = 0; int histCounter = 0; if (fChain == 0) return; int nentries = n; // cout << " nentries are "<<nentries<<endl; Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; el.clear(); antiel.clear(); mu.clear(); antimu.clear(); lCounter = 0; eeee = 0; xxxx = 0; eexx = 0; xxee = 0; //particles identified by type, ntrk for (int inst = 0; inst < npart; inst++){ // inst from "instance" on the scan tree // cout<< " instance "<< inst <<endl; // cout<< pT[inst]<< endl; //fill el mu vectors if ( typ[inst] == 1 && ntrk[inst] == -1){ el.push_back(inst); elC++; lCounter++; totaLlCounter++; } if ( typ[inst] == 1 && ntrk[inst] == 1){ antiel.push_back(inst); antielC++; lCounter++; totaLlCounter++; } if ( typ[inst] == 2 && ntrk[inst] == -1){ mu.push_back(inst); muC++; lCounter++; totaLlCounter++; } if ( typ[inst] == 2 && ntrk[inst] == 1){ antimu.push_back(inst); antimuC++; lCounter++; totaLlCounter++; } if ( (typ[inst] == 4 && jmas[inst] > 10. )|| (typ[inst] == 6 && pT[inst] > 10. )){ lCounter = 0; //dont count the event } }//end instance loop (particles in an event // cout<< "leptons in the event are "<< lCounter<<endl; // if (lCounter == 4) { fillFlag = false; // If else if loops reconstructing the particles according to the type 4e,4mu, 2e2mu if (el.size() == 1 && mu.size() == 1 && antiel.size() == 1 && antimu.size() == 1){ //2e2m goodEventCounter++; lep1.SetPtEtaPhi( pT[el[0]], eta[el[0]] , phi[el[0]]); //set up of lepton four-vectors lep2.SetPtEtaPhi( pT[antiel[0]], eta[antiel[0]] , phi[antiel[0]]); lep3.SetPtEtaPhi( pT[mu[0]], eta[mu[0]] , phi[mu[0]]); lep4.SetPtEtaPhi( pT[antimu[0]], eta[antimu[0]] , phi[antimu[0]]); Za = lep1 + lep2; Zb = lep3 + lep4; mZ1 = sqrt(pow(lep1.Mag()+lep2.Mag(),2)-Za.Mag2()); // reconstruct z masses mZ2 = sqrt(pow(lep3.Mag()+lep4.Mag(),2)-Zb.Mag2()); //select leading Z if(mZ1 > mZ2) { Z1.SetVectM( Za, mZ1); Z2.SetVectM(Zb,mZ2); lep_min1.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus1.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag()); lep_min2.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus2.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag());eexx++;} //to set the highest mass the z else { Z2.SetVectM( Za, mZ1); Z1.SetVectM(Zb,mZ2); lep_min2.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus2.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag()); lep_min1.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus1.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag());xxee++;} fillFlag = true; } else if (el.size() == 2 && mu.size() == 0 && antiel.size() == 2 && antimu.size() == 0){ //4e goodEventCounter++; lep1.SetPtEtaPhi( pT[el[0]], eta[el[0]] , phi[el[0]]); lep2.SetPtEtaPhi( pT[antiel[0]], eta[antiel[0]] , phi[antiel[0]]); lep3.SetPtEtaPhi( pT[el[1]], eta[el[1]] , phi[el[1]]); lep4.SetPtEtaPhi( pT[antiel[1]], eta[antiel[1]] , phi[antiel[1]]); Za = lep1 + lep2; Zb = lep3 + lep4; Zc = lep1 + lep4; Zd = lep3 + lep2; double mZa = sqrt(pow(lep1.Mag()+lep2.Mag(),2)-Za.Mag2()); double mZb = sqrt(pow(lep3.Mag()+lep4.Mag(),2)-Zb.Mag2()); double mZc = sqrt(pow(lep1.Mag()+lep4.Mag(),2)-Zc.Mag2()); double mZd = sqrt(pow(lep2.Mag()+lep3.Mag(),2)-Zd.Mag2()); double s1a; double s1b; double s2a; double s2b; if ( pairing == 0){ s1a = pow(mZa-vZmass,2) + pow(mZb-Zmass,2); s1b = pow(mZa-Zmass,2) + pow(mZb-vZmass,2); s2a = pow(mZc-vZmass,2) + pow(mZd-Zmass,2); s2b = pow(mZc-Zmass,2) + pow(mZd-vZmass,2); } else{ s1a = fabs(mZb-Zmass); s1b = fabs(mZa-Zmass); s2a = fabs(mZd-Zmass); s2b = fabs(mZc-Zmass); } elSum[0] = s1a; elSum[1] = s1b; elSum[2] = s2a; elSum[3] = s2b; int min = TMath::LocMin(4, &elSum[0]); if( (min == 0 || min == 1) ){ if(mZa > mZb) { Z1.SetVectM( Za, mZa); Z2.SetVectM(Zb,mZb); lep_min1.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus1.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag()); lep_min2.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus2.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag());} //to set the highest mass the z else { Z2.SetVectM( Za, mZa); Z1.SetVectM(Zb,mZb); lep_min2.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus2.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag()); lep_min1.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus1.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag());} } else if( (min == 2 || min == 3) ){ if(mZc > mZd) { Z1.SetVectM( Zc, mZc); Z2.SetVectM(Zd,mZd); lep_min1.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus1.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag()); lep_min2.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus2.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag());} //to set the highest mass the z else { Z2.SetVectM( Zc, mZc); Z1.SetVectM(Zd,mZd); lep_min2.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus2.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag()); lep_min1.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus1.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag());} } eeee++; fillFlag = true; } else if(el.size() == 0 && mu.size() == 2 && antiel.size() == 0 && antimu.size() == 2 ) { //4m goodEventCounter++; lep1.SetPtEtaPhi( pT[mu[0]], eta[mu[0]] , phi[mu[0]]); lep2.SetPtEtaPhi( pT[antimu[0]], eta[antimu[0]] , phi[antimu[0]]); lep3.SetPtEtaPhi( pT[mu[1]], eta[mu[1]] , phi[mu[1]]); lep4.SetPtEtaPhi( pT[antimu[1]], eta[antimu[1]] , phi[antimu[1]]); Za = lep1 + lep2; Zb = lep3 + lep4; Zc = lep1 + lep4; Zd = lep3 + lep2; double mZa = sqrt(pow(lep1.Mag()+lep2.Mag(),2)-Za.Mag2()); double mZb = sqrt(pow(lep3.Mag()+lep4.Mag(),2)-Zb.Mag2()); double mZc = sqrt(pow(lep1.Mag()+lep4.Mag(),2)-Zc.Mag2()); double mZd = sqrt(pow(lep2.Mag()+lep3.Mag(),2)-Zd.Mag2()); double s1a; double s1b; double s2a; double s2b; if ( pairing == 0){ s1a = pow(mZa-vZmass,2) + pow(mZb-Zmass,2); s1b = pow(mZa-Zmass,2) + pow(mZb-vZmass,2); s2a = pow(mZc-vZmass,2) + pow(mZd-Zmass,2); s2b = pow(mZc-Zmass,2) + pow(mZd-vZmass,2); } else{ s1a = fabs(mZb-Zmass); s1b = fabs(mZa-Zmass); s2a = fabs(mZd-Zmass); s2b = fabs(mZc-Zmass); } muSum[0] = s1a; muSum[1] = s1b; muSum[2] = s2a; muSum[3] = s2b; int min = TMath::LocMin(4, &muSum[0]); if( (min == 0 || min == 1) ){ if(mZa > mZb) { Z1.SetVectM( Za, mZa); Z2.SetVectM(Zb,mZb); lep_min1.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus1.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag()); lep_min2.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus2.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag());} //to set the highest mass the z else { Z2.SetVectM( Za, mZa); Z1.SetVectM(Zb,mZb); lep_min2.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus2.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag()); lep_min1.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus1.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag());} } else if( (min == 2 || min == 3) ){ if(mZc > mZd) { Z1.SetVectM( Zc, mZc); Z2.SetVectM(Zd,mZd); lep_min1.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus1.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag()); lep_min2.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus2.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag());} //to set the highest mass the z else { Z2.SetVectM( Zc, mZc); Z1.SetVectM(Zd,mZd); lep_min2.SetPtEtaPhiE(lep1.Pt(),lep1.Eta(), lep1.Phi(),lep1.Mag()); lep_plus2.SetPtEtaPhiE(lep4.Pt(),lep4.Eta(), lep4.Phi(),lep4.Mag()); lep_min1.SetPtEtaPhiE(lep3.Pt(),lep3.Eta(), lep3.Phi(),lep3.Mag()); lep_plus1.SetPtEtaPhiE(lep2.Pt(),lep2.Eta(), lep2.Phi(),lep2.Mag());} } xxxx++; fillFlag = true; } if ( fillFlag == true && goodEventCounter < 25001) { //if it fullfills the specs then fill and find angles rec_H = Z1 + Z2; double Hmass = rec_H.M(); tHrec = Hmass; // cout<<tHrec<<endl; double Z1mass = Z1.M(); tZ1m = Z1mass; double Z2mass = Z2.M(); tZ2m = Z2mass; double ptlepp1 = lep_plus1.Pt(); double ptlepm1 = lep_min1.Pt(); double ptlepp2 = lep_plus2.Pt(); double ptlepm2 = lep_min2.Pt(); double dR1 = sqrt(pow(fabs(lep_min1.Eta() - lep_plus1.Eta()),2)+pow(fabs(lep_min1.DeltaPhi(lep_plus1)),2)); double dR2 = sqrt(pow(fabs(lep_min2.Eta() - lep_plus2.Eta()),2)+pow(fabs(lep_min2.DeltaPhi(lep_plus2)),2)); // if ( /*Hmass<120 || Hmass>130 || */Z1mass < 49 || Z1mass>107 || Z2mass < 12 || Z2mass> 115 ){continue;} //constrains //filling the simple histogram values h_Z1_m -> Fill(Z1.M()); h_Z1_E -> Fill(Z1.E()); h_Z1_Pt -> Fill(Z1.Pt()); h_Z1_eta -> Fill(Z1.Eta()); h_Z1_phi -> Fill(Z1.Phi()); h_Z2_m -> Fill(Z2.M()); h_Z2_E -> Fill(Z2.E()); h_Z2_Pt -> Fill(Z2.Pt()); h_Z2_eta -> Fill(Z2.Eta()); h_Z2_phi -> Fill(Z2.Phi()); h_rec_H_m -> Fill(Hmass); h_rec_H_E -> Fill(rec_H.E()); h_rec_H_Pt -> Fill(rec_H.Pt()); h_rec_H_eta -> Fill(rec_H.Eta()); h_rec_H_phi -> Fill(rec_H.Phi()); h_lep_plus1_E -> Fill(lep_plus1.E()); h_lep_plus1_Pt -> Fill(ptlepp1); h_lep_plus1_eta -> Fill(lep_plus1.Eta()); h_lep_plus1_phi -> Fill(lep_plus1.Phi()); h_lep_min1_E -> Fill(lep_min1.E()); h_lep_min1_Pt -> Fill(ptlepm1); h_lep_min1_eta -> Fill(lep_min1.Eta()); h_lep_min1_phi -> Fill(lep_min1.Phi()); h_lep_plus2_E -> Fill(lep_plus2.E()); h_lep_plus2_Pt -> Fill(ptlepp2); h_lep_plus2_eta -> Fill(lep_plus2.Eta()); h_lep_plus2_phi -> Fill(lep_plus2.Phi()); h_lep_min2_E -> Fill(lep_min2.E()); h_lep_min2_Pt -> Fill(ptlepm2); h_lep_min2_eta -> Fill(lep_min2.Eta()); h_lep_min2_phi -> Fill(lep_min2.Phi()); //reconstructing the two lepton pairs Lorentz vectors lpair1 = lep_plus1 + lep_min1; lpair2 = lep_plus2 + lep_min2; //constructing 3-vectors in the lab frame lep_plus1_lab = lep_plus1.Vect(); lep_plus2_lab = lep_plus2.Vect(); //.Vect() gives 3 vector from 4vector lep_min1_lab = lep_min1.Vect(); lep_min2_lab = lep_min2.Vect(); lpair1_lab = lep_plus1_lab.Cross(lep_min1_lab); lpair2_lab = lep_plus2_lab.Cross(lep_min2_lab); // cout << " pt of lepton pair1 on rest frame is: "<< lpair1.Perp()<<endl; //Filling up Histograms with angles defined in the lab frame h_angle_lab_pair1 -> Fill(lep_plus1_lab.Angle(lep_min1_lab)); h_angle_lab_pair2 -> Fill(lep_plus2_lab.Angle(lep_min2_lab)); //Filling up histograms with variables from articles h_angle_lab_deleta1 -> Fill(fabs(lep_min1.Eta() - lep_plus1.Eta())); h_angle_lab_delphi1 -> Fill(fabs(lep_min1.DeltaPhi(lep_plus1))); h_angle_lab_deleta2 -> Fill(fabs(lep_min2.Eta() - lep_plus2.Eta())); h_angle_lab_delphi2 -> Fill(fabs(lep_min2.DeltaPhi(lep_plus2))); //Looking at the Higgs rest frame TVector3 boost_rH = -rec_H.BoostVector(); //NOTE the minus sign! WHY - sign??? TVector3 boost_rZ1 = -Z1.BoostVector(); TVector3 boost_rZ2 = -Z2.BoostVector(); Higgs_rest = rec_H; Z1_rH = Z1; Z2_rH = Z2; lep_p1_rH = lep_plus1; // lep_m1_rH = lep_min1; lep_p2_rH = lep_plus2; lep_m2_rH = lep_min2; lep_p1_rZ1 = lep_plus1; lep_m2_rZ2 = lep_min2; lep_p2_rZ2 = lep_plus2; lep_m1_rZ1 = lep_min1; //Boosting vectors to the Higgs rest frame Higgs_rest.Boost(boost_rH); Z1_rH.Boost(boost_rH); Z2_rH.Boost(boost_rH); lep_p1_rH.Boost(boost_rH); lep_m1_rH.Boost(boost_rH); lep_p2_rH.Boost(boost_rH); lep_m2_rH.Boost(boost_rH); //Boosting leptons to Z rest frames lep_p1_rZ1.Boost(boost_rZ1); lep_m1_rZ1.Boost(boost_rZ1); lep_p2_rZ2.Boost(boost_rZ2); lep_m2_rZ2.Boost(boost_rZ2); //Setting 3Vectors in Higgs rest frame Z3_1_rH = Z1_rH.Vect(); Z3_2_rH = Z2_rH.Vect(); lep3_plus1_rH = lep_p1_rH.Vect(); lep3_min1_rH = lep_m1_rH.Vect(); lep3_plus2_rH = lep_p2_rH.Vect(); lep3_min2_rH = lep_m2_rH.Vect(); TVector3 Z3_1plane_rH = lep3_plus1_rH.Cross(lep3_min1_rH); //wrong? TVector3 Z3_2plane_rH = lep3_plus2_rH.Cross(lep3_min2_rH); //Setting 3Vectors in Z1/Z2 rest frame lep3_plus1_rZ1 = lep_p1_rZ1.Vect(); lep3_plus2_rZ2 = lep_p2_rZ2.Vect(); lep3_min1_rZ1 = lep_m1_rZ1.Vect(); lep3_min2_rZ2 = lep_m2_rZ2.Vect(); //Filling up histogram for the phi angle distribution //pairnoume ta monadiaia dianysmata twn kathetwn pediwn, prwta ypologizoume to metro tous, meta eswteriko ginomeno, meta tokso tou costheta tous double metro1 = sqrt((pow(Z3_1plane_rH.X(),2))+(pow(Z3_1plane_rH.Y(),2))+(pow(Z3_1plane_rH.Z(),2))); double metro2 = sqrt((pow(Z3_2plane_rH.X(),2))+(pow(Z3_2plane_rH.Y(),2))+(pow(Z3_2plane_rH.Z(),2))); TVector3 Z3_1plane_rH_un = Z3_1plane_rH.Unit(); TVector3 Z3_2plane_rH_un = Z3_2plane_rH.Unit(); TVector3 drtPlane = Z3_1plane_rH_un.Cross(Z3_2plane_rH_un); double phi = acos(-Z3_1plane_rH_un.Dot(Z3_2plane_rH_un))*(Z3_1_rH.Dot(skata))/fabs(Z3_1_rH.Dot(skata)); h_angle_rH_phi -> Fill( phi ); tPhi = phi; //****Phi one angle , same procedure as before. Now the plane is the first Z boson vector with beam axis, so they form a plane, phi1 is angle between this plane and the Z1 plane (apo to decay twn 2 leptoniwn) TVector3 niScatter_un = (beamAxis.Cross(Z3_1_rH)).Unit(); TVector3 drtPlane2 = Z3_1plane_rH_un.Cross(niScatter_un); double phiOne = acos(Z3_1plane_rH_un.Dot(niScatter_un))*(Z3_1_rH.Dot(skata2))/fabs(Z3_1_rH.Dot(skata2)); h_angle_rH_phiOne -> Fill( phiOne ); tPhi1 = phiOne; //Filling up histogram for theta* angle: Z1/Z2 with Higgs boost vector h_angle_rH_thetaZ2 -> Fill(Z3_2_rH.CosTheta()); double cosThetaStar = Z3_1_rH.CosTheta(); h_angle_rH_thetaZ1 -> Fill(cosThetaStar); tcosthetaStar = cosThetaStar; // boosting the z to the other z frame TLorentzVector Z_1_rZ2 = Z1; Z_1_rZ2.Boost(boost_rZ2); TVector3 Z3_1_rZ2 = Z_1_rZ2.Vect(); TLorentzVector Z_2_rZ1 = Z2; Z_2_rZ1.Boost(boost_rZ1); TVector3 Z3_2_rZ1 = Z_2_rZ1.Vect(); double cosTheta1 = cos(lep3_min1_rZ1.Angle(-Z3_2_rZ1)); double cosTheta2 = cos(lep3_min2_rZ2.Angle(-Z3_1_rZ2)); h_angle_rZ1_lp1Z1 -> Fill(cos(lep3_plus1_rZ1.Angle(-Z3_2_rZ1))); h_angle_rZ1_lm1Z1 -> Fill(cosTheta1); // theta1 h_angle_rZ2_lp2Z2 -> Fill(cos(lep3_plus2_rZ2.Angle(-Z3_1_rZ2))); h_angle_rZ2_lm2Z2 -> Fill(cosTheta2); // theta2 tcostheta1 = cosTheta1; tcostheta2 = cosTheta2; h_angle_rH_delphi1 -> Fill(fabs(lep_p1_rH.DeltaPhi(lep_m1_rH))); h_angle_rH_delphi2 -> Fill(fabs(lep_p2_rH.DeltaPhi(lep_m2_rH))); h_mZ1mZ2 -> Fill(Z1.M(),Z2.M()); h_mVsPtZ1 -> Fill(Z1.M(),Z1.Pt()); h_delphi1VsPtZ1_lab -> Fill(Z1.Pt(),fabs(lep_min1.DeltaPhi(lep_plus1))); h_delphi2VsPtZ2_lab -> Fill(Z2.Pt(),fabs(lep_min2.DeltaPhi(lep_plus2))); if (eexx ==1){ttype = "eexx";} else if(xxee ==1){ttype = "xxee";} else if(eeee ==1){ttype = "eeee";} else if(xxxx ==1){ttype = "xxxx";} hists->Fill(); histCounter++; hists->Close(); } //end if fill ////////////// fill out the decay type // filling the TTree }//end entries loop (events) //some regular reports cout<<endl; cout<<" good events are "<<goodEventCounter<<endl; cout<<" we see % "<< (double) goodEventCounter/n <<endl; cout<<endl; cout<<" histogram fills are "<<histCounter<<endl; // cout<<" we see % "<< (double) goodEventCounter/n <<endl; }//end loop void
void addTreeToFile( TFile* file, const std::string& treeName, std::vector<ZGSample> samples, const ZGConfig& cfg, int idMin, int idMax ) { if( idMin>=0 && idMax<0 ) idMax=idMin; TChain* tree = new TChain("mt2"); for( unsigned i=0; i<samples.size(); ++i ) { if( idMin>0 ) { int thisId = samples[i].id; if( thisId<idMin ) continue; if( thisId>idMax ) continue; } std::string fileName(Form("%s/mt2", samples[i].file.c_str()) ); tree->Add( fileName.c_str() ); std::cout << "-> Added: " << fileName << std::endl; } //TFile* puFile_data = TFile::Open("puData.root"); //TH1D* h1_nVert_data = (TH1D*)puFile_data->Get("nVert"); //TFile* puFile_mc = TFile::Open("puMC.root"); //TH1D* h1_nVert_mc = (TH1D*)puFile_mc->Get("nVert"); // for pu reweighting: TFile* puFile = TFile::Open("DoubleEG_cert_210.root"); TH1D* h1_pu = (TH1D*)puFile->Get("pileup"); ZGTree myTree; myTree.loadGenStuff = false; myTree.Init(tree); // compute denominators of efficiency for PDF syst std::vector<float> pdf_denom; std::vector<float> pdf_num; file->cd(); gDirectory->Delete(Form("%s;*", treeName.c_str())); gDirectory->Delete(Form("pdf_%s;*", treeName.c_str())); TTree* outTree = new TTree( treeName.c_str(), "" ); int run; outTree->Branch( "run", &run, "run/I"); int lumi; outTree->Branch( "lumi", &lumi, "lumi/I"); UInt_t event; outTree->Branch( "event", &event, "event/i"); float weight; outTree->Branch( "weight", &weight, "weight/F"); float puWeight; outTree->Branch( "puWeight", &puWeight, "puWeight/F"); int id; outTree->Branch( "id", &id, "id/I"); int leptType; outTree->Branch( "leptType", &leptType, "leptType/I"); float met; outTree->Branch( "met", &met, "met/F" ); int nVert; outTree->Branch( "nVert", &nVert, "nVert/I" ); int nGamma; outTree->Branch( "nGamma", &nGamma, "nGamma/I" ); bool isGolden; outTree->Branch( "isGolden", &isGolden, "isGolden/O"); bool isSilver; outTree->Branch( "isSilver", &isSilver, "isSilver/O"); bool passHLT_old; outTree->Branch( "passHLT_old", &passHLT_old, "passHLT_old/O" ); bool passHLT; outTree->Branch( "passHLT", &passHLT, "passHLT/O" ); bool HLT_Photon165; outTree->Branch( "HLT_Photon165", &HLT_Photon165, "HLT_Photon165/O" ); bool HLT_DoubleEle; outTree->Branch( "HLT_DoubleEle", &HLT_DoubleEle, "HLT_DoubleEle/O" ); bool HLT_DoubleEle33; outTree->Branch( "HLT_DoubleEle33", &HLT_DoubleEle33, "HLT_DoubleEle33/O" ); bool HLT_DoubleMu; outTree->Branch( "HLT_DoubleMu", &HLT_DoubleMu, "HLT_DoubleMu/O" ); bool HLT_Mu30_TkMu11; outTree->Branch( "HLT_Mu30_TkMu11", &HLT_Mu30_TkMu11, "HLT_Mu30_TkMu11/O" ); bool HLT_SingleMu; outTree->Branch( "HLT_SingleMu", &HLT_SingleMu, "HLT_SingleMu/O" ); bool passStandardIso; outTree->Branch( "passStandardIso", &passStandardIso, "passStandardIso/O" ); float weight_scale; outTree->Branch( "weight_scale", &weight_scale, "weight_scale/F"); float weight_pdf; outTree->Branch( "weight_pdf", &weight_pdf, "weight_pdf/F"); float weight_lep; outTree->Branch( "weight_lep", &weight_lep, "weight_lep/F"); float lept0_pt; outTree->Branch( "lept0_pt", &lept0_pt, "lept0_pt/F" ); float lept0_eta; outTree->Branch( "lept0_eta", &lept0_eta, "lept0_eta/F" ); float lept0_phi; outTree->Branch( "lept0_phi", &lept0_phi, "lept0_phi/F" ); float lept0_mass; outTree->Branch( "lept0_mass", &lept0_mass, "lept0_mass/F" ); float lept0_miniRelIso; outTree->Branch( "lept0_miniRelIso", &lept0_miniRelIso, "lept0_miniRelIso/F" ); int lept0_pdgId; outTree->Branch( "lept0_pdgId", &lept0_pdgId, "lept0_pdgId/I" ); float lept1_pt; outTree->Branch( "lept1_pt", &lept1_pt, "lept1_pt/F" ); float lept1_eta; outTree->Branch( "lept1_eta", &lept1_eta, "lept1_eta/F" ); float lept1_phi; outTree->Branch( "lept1_phi", &lept1_phi, "lept1_phi/F" ); float lept1_mass; outTree->Branch( "lept1_mass", &lept1_mass, "lept1_mass/F" ); float lept1_miniRelIso; outTree->Branch( "lept1_miniRelIso", &lept1_miniRelIso, "lept1_miniRelIso/F" ); int lept1_pdgId; outTree->Branch( "lept1_pdgId", &lept1_pdgId, "lept1_pdgId/I" ); float deltaR_lept; outTree->Branch( "deltaR_lept", &deltaR_lept, "deltaR_lept/F" ); float gamma_pt; outTree->Branch( "gamma_pt", &gamma_pt, "gamma_pt/F" ); float gamma_eta; outTree->Branch( "gamma_eta", &gamma_eta, "gamma_eta/F" ); float gamma_phi; outTree->Branch( "gamma_phi", &gamma_phi, "gamma_phi/F" ); float gamma_mass; outTree->Branch( "gamma_mass", &gamma_mass, "gamma_mass/F" ); float gamma_iso; outTree->Branch( "gamma_iso", &gamma_iso, "gamma_iso/F" ); float z_pt; outTree->Branch( "z_pt", &z_pt, "z_pt/F" ); float z_eta; outTree->Branch( "z_eta", &z_eta, "z_eta/F" ); float z_phi; outTree->Branch( "z_phi", &z_phi, "z_phi/F" ); float z_mass; outTree->Branch( "z_mass", &z_mass, "z_mass/F" ); float boss_pt; outTree->Branch( "boss_pt", &boss_pt, "boss_pt/F" ); float boss_eta; outTree->Branch( "boss_eta", &boss_eta, "boss_eta/F" ); float boss_phi; outTree->Branch( "boss_phi", &boss_phi, "boss_phi/F" ); float boss_mass; outTree->Branch( "boss_mass", &boss_mass, "boss_mass/F" ); float boss2_pt; outTree->Branch( "boss2_pt", &boss2_pt, "boss2_pt/F" ); float boss2_eta; outTree->Branch( "boss2_eta", &boss2_eta, "boss2_eta/F" ); float boss2_phi; outTree->Branch( "boss2_phi", &boss2_phi, "boss2_phi/F" ); float boss2_mass; outTree->Branch( "boss2_mass", &boss2_mass, "boss2_mass/F" ); float qgamma_mass; outTree->Branch( "qgamma_mass", &qgamma_mass, "qgamma_mass/F" ); float qZ_mass; outTree->Branch( "qZ_mass", &qZ_mass, "qZ_mass/F" ); // for muon rochester corrections rochcor2016 *rmcor = new rochcor2016(); EnergyScaleCorrection_class egcor("Golden10June_plus_DCS"); int nentries = tree->GetEntries(); for( int iEntry=0; iEntry<nentries; ++iEntry ) { if( iEntry % 50000 == 0 ) std::cout << " Entry: " << iEntry << " / " << nentries << std::endl; myTree.GetEntry(iEntry); run = myTree.run; lumi = myTree.lumi; event = myTree.evt; id = myTree.evt_id; if( iEntry==0 ) { // initialize stuff if( id<100 ) { egcor.doScale=true; egcor.doSmearings=false; } else { egcor.doScale=false; egcor.doSmearings=true; } } if( event == DEBUG_EVENT ) { std::cout << "++++ STARTING DEBUG COUT FOR: " << std::endl; std::cout << " Run: " << run << std::endl; std::cout << " LS : " << lumi << std::endl; std::cout << " Event : " << event << std::endl; } bool doSystForThisSample = doSyst && (id==851 || id==852 || id==4301 || id==4302); if( iEntry==0 && doSystForThisSample ) { // allocate all of the PDF stuff for( int i=0; i<myTree.nLHEweight; ++i ) { pdf_num.push_back(0.); std::cout << "[PDF Systematics] Allocating stuff for LHE weight: " << myTree.LHEweight_id[i] << " (" << i << "/" << myTree.nLHEweight << ")" << std::endl; bool goodIndex = (myTree.LHEweight_id[i]>=2000 && myTree.LHEweight_id[i]<=3000); if( goodIndex ) { TH1D* h1_tmp = new TH1D("pdf_tmp", "", 100, 0., 10000. ); h1_tmp->Sumw2(); tree->Project( "pdf_tmp", "met_pt", Form("LHEweight_wgt[%d]", i) ); pdf_denom.push_back( h1_tmp->Integral() ); delete h1_tmp; } else { pdf_denom.push_back( 1. ); } } } // if first entry // remove overlap from DY: if( id>=700 && id<710 ) { if( myTree.ngamma>0 && myTree.gamma_mcMatchId[0]==22 ) continue; //if( myTree.ngamma>0 ) { // bool isFake = myTree.gamma_mcMatchId[0]!=22; // bool okFromDY = isFake || (!isFake && myTree.gamma_drMinParton[0]<0.05); // if( !okFromDY ) continue; //} } if( myTree.nVert==0 ) continue; nVert = myTree.nVert; // filters if( myTree.isData ) { if( !myTree.passFilters() ) continue; } isGolden = myTree.isGolden; isSilver = myTree.isSilver; HLT_Photon165 = myTree.HLT_Photon165_HE10; HLT_DoubleEle = myTree.HLT_DoubleEl; HLT_DoubleMu = myTree.HLT_DoubleMu; HLT_Mu30_TkMu11 = myTree.HLT_Mu30_TkMu11; HLT_DoubleEle33 = myTree.HLT_DoubleEle33; HLT_SingleMu = myTree.HLT_SingleMu; // hlt on data: if( myTree.isData ) { if( !myTree.isGolden ) continue; //if( !myTree.isSilver ) continue; passHLT = false; if( id==5 ) passHLT = myTree.HLT_DoubleMu || myTree.HLT_Mu30_TkMu11; //DoubleMu PD if( id==8 ) passHLT = myTree.HLT_SingleMu && !myTree.HLT_DoubleMu && !myTree.HLT_Mu30_TkMu11; //SingleMu PD if( id==4 ) passHLT = (myTree.HLT_DoubleEl || myTree.HLT_DoubleEle33) && !myTree.HLT_DoubleMu && !myTree.HLT_Mu30_TkMu11 && !myTree.HLT_SingleMu; //DoubleEG PD //if( id==7 ) passHLT = myTree.HLT_Photon165_HE10 && !myTree.HLT_DoubleEl && !myTree.HLT_DoubleMu; //SinglePhoton PD //if( id==5 ) passHLT = myTree.HLT_DoubleMu; //DoubleMu PD //if( id==4 ) passHLT = myTree.HLT_DoubleEl && !myTree.HLT_DoubleMu && !myTree.HLT_SingleMu; //DoubleEG PD //if( id==9 ) passHLT = myTree.HLT_SingleEl && !myTree.HLT_DoubleEl && !myTree.HLT_DoubleMu && !myTree.HLT_SingleMu; //SingleElectron PD } else { // hlt on mc: passHLT = true; // no HLT in 80X MC //passHLT = ( myTree.HLT_DoubleEl || myTree.HLT_DoubleMu || myTree.HLT_Mu30_TkMu11 || myTree.HLT_DoubleEle33 ); //passHLT = ( myTree.HLT_DoubleEl || myTree.HLT_DoubleMu || myTree.HLT_Mu30_TkMu11 || myTree.HLT_DoubleEle33 || myTree.HLT_SingleMu ); } if( !passHLT && cfg.additionalStuff()!="noHLT" ) continue; if( event == DEBUG_EVENT ) std::cout << " -> passed HLT " << std::endl; if( myTree.nlep!=2 ) continue; // two leptons if( event == DEBUG_EVENT ) std::cout << " -> passed 2 lepton requirement " << std::endl; if( myTree.lep_pdgId[0] != -myTree.lep_pdgId[1] ) continue; // same flavour, opposite sign if( event == DEBUG_EVENT ) std::cout << " -> passed same flavor opposite charge requirement " << std::endl; leptType = abs(myTree.lep_pdgId[0]); if( leptType!=11 && leptType!=13 ) continue; // just in case if( event == DEBUG_EVENT ) std::cout << " -> passed electron/muon requirement " << std::endl; TLorentzVector lept0; lept0.SetPtEtaPhiM( myTree.lep_pt[0], myTree.lep_eta[0], myTree.lep_phi[0], myTree.lep_mass[0] ); TLorentzVector lept1; lept1.SetPtEtaPhiM( myTree.lep_pt[1], myTree.lep_eta[1], myTree.lep_phi[1], myTree.lep_mass[1] ); if( lept0.Pt()<25. ) continue; if( lept1.Pt()<20. ) continue; if( leptType==11 ) { if( myTree.lep_tightId[0]==0 || myTree.lep_tightId[1]==0 ) continue; // loose electron ID } else { //if( myTree.lep_tightId[0]==0 || myTree.lep_tightId[1]==0 ) continue; // tight muon ID on both if( !( (myTree.lep_tightId[0]==1 && myTree.lep_tightId[0]>=0) || (myTree.lep_tightId[1]==1 && myTree.lep_tightId[1]>=0)) ) continue; // tight muon ID on at least one of the muons } // apply rochester corrections for muons: if( leptType==13 ) { // instructions taken from https://twiki.cern.ch/twiki/pub/CMS/RochcorMuon/manual_rochcor_run2.pdf // linked from twiki: https://twiki.cern.ch/twiki/bin/viewauth/CMS/RochcorMuon float qter = 1.0; if( !myTree.isData ) { rmcor->momcor_mc(lept0, myTree.lep_pdgId[0]/(abs(myTree.lep_pdgId[0])), 0, qter); rmcor->momcor_mc(lept1, myTree.lep_pdgId[1]/(abs(myTree.lep_pdgId[1])), 0, qter); } else { rmcor->momcor_data(lept0, myTree.lep_pdgId[0]/(abs(myTree.lep_pdgId[0])), 0, qter); rmcor->momcor_data(lept1, myTree.lep_pdgId[1]/(abs(myTree.lep_pdgId[1])), 0, qter); } passStandardIso = (myTree.lep_relIso04[0]<0.25 && myTree.lep_relIso04[1]<0.25); } else if( leptType==11 ) { if( !myTree.isData ) { if( cfg.smearing() ) { smearEmEnergy( egcor, lept0, myTree, myTree.lep_r9[0] ); smearEmEnergy( egcor, lept1, myTree, myTree.lep_r9[1] ); } } else { if( cfg.smearing() ) { applyEmEnergyScale( egcor, lept0, myTree, myTree.lep_r9[0] ); applyEmEnergyScale( egcor, lept1, myTree, myTree.lep_r9[1] ); } } bool passStandardIso0 = (fabs(myTree.lep_eta[0])<1.479) ? myTree.lep_relIso03[0]<0.0893 : myTree.lep_relIso03[0]<0.121; bool passStandardIso1 = (fabs(myTree.lep_eta[1])<1.479) ? myTree.lep_relIso03[1]<0.0893 : myTree.lep_relIso03[1]<0.121; passStandardIso = passStandardIso0 && passStandardIso1; } lept0_miniRelIso = myTree.lep_miniRelIso[0]; lept1_miniRelIso = myTree.lep_miniRelIso[1]; lept0_pdgId = myTree.lep_pdgId[0]; lept1_pdgId = myTree.lep_pdgId[1]; weight = 1.; puWeight = 1.; weight_scale = 1.; weight_pdf = 1.; weight_lep = 1.; if( !myTree.isData ) { weight = myTree.evt_scale1fb*cfg.lumi(); // pu reweighting: //puWeight = getPUweight( h1_pu, myTree.nTrueInt ); puWeight = myTree.puWeight; weight *= puWeight; // lepton SF: float leptonSF = 1.; if( leptType==13 ) { float isoSF = 0.9997; float idSF_loose = 0.997; float idSF_tight = 0.983; float idSF = idSF_loose*idSF_tight; if( myTree.lep_tightId[0]==1 && myTree.lep_tightId[1]==1 ) idSF = 2.*idSF_loose*idSF_tight - idSF_tight*idSF_tight; leptonSF = isoSF*idSF; } weight *= leptonSF; // trigger SF: float hltSF = 1.; if( leptType==11 ) { // electrons if( lept0.Pt()<35. || lept1.Pt()<35. ) { hltSF = 0.965; } else { hltSF = 1.; } } else { // muons hltSF = 0.989; } weight *= hltSF; weight_lep = myTree.weight_lepsf_UP; weight_scale = weight; // will compute later weight_pdf = weight; // will compute later } TLorentzVector photon; TLorentzVector photon2; bool foundSecondPhoton = false; if( cfg.selection()!="veryloose" ) { if( myTree.ngamma==0 ) continue; // photon if( event == DEBUG_EVENT ) std::cout << " -> passed ngamma requirement " << std::endl; photon = selectPhoton(cfg, myTree, 0, lept0, lept1, egcor); if( photon.Pt()<1. ) continue; if( event == DEBUG_EVENT ) std::cout << " -> passed photon requirement " << std::endl; photon2 = selectPhoton(cfg, myTree, 1, lept0, lept1, egcor); foundSecondPhoton = photon2.Pt()>10.; } TLorentzVector zBoson = lept0+lept1; if( zBoson.M()<50. ) continue; if( cfg.selection()!="presel" && zBoson.M()>130. ) continue; if( event == DEBUG_EVENT ) std::cout << " -> passed M(ll) cut " << std::endl; TLorentzVector boss = zBoson + photon; TLorentzVector boss2; if( foundSecondPhoton ) boss2 = zBoson + photon + photon2; else boss2.SetPtEtaPhiM( 0.1, 0., 0., 0.); if( id==851 && boss.M()>410. ) continue; lept0_pt = lept0.Pt(); lept0_eta = lept0.Eta(); lept0_phi = lept0.Phi(); lept0_mass = lept0.M(); lept1_pt = lept1.Pt(); lept1_eta = lept1.Eta(); lept1_phi = lept1.Phi(); lept1_mass = lept1.M(); deltaR_lept = lept0.DeltaR(lept1); nGamma = myTree.ngamma; if( photon.Pt()>0. ) { gamma_pt = photon.Pt(); gamma_eta = photon.Eta(); gamma_phi = photon.Phi(); gamma_mass = photon.M(); gamma_iso = myTree.gamma_chHadIso[0]; } else { gamma_pt = 0.; gamma_eta = 0.; gamma_phi = 0.; gamma_mass = 0.; gamma_iso = -1.; } z_pt = zBoson.Pt(); z_eta = zBoson.Eta(); z_phi = zBoson.Phi(); z_mass = zBoson.M(); boss_pt = boss.Pt(); boss_eta = boss.Eta(); boss_phi = boss.Phi(); boss_mass = boss.M(); boss2_pt = boss2.Pt(); boss2_eta = boss2.Eta(); boss2_phi = boss2.Phi(); boss2_mass = boss2.M(); met = myTree.met_pt; if( cfg.selection()=="v0" ) if( gamma_pt/boss_mass < 40./150. ) continue; if( cfg.selection()=="Qv0" ) { if( myTree.njet==0 ) continue; if( fabs(myTree.jet_eta[0])>2.5 ) continue; if( myTree.jet_pt[0]<30. ) continue; } if( event == DEBUG_EVENT ) std::cout << " -> passed additional cuts" << std::endl; qgamma_mass = -1.; qZ_mass = -1.; if( myTree.njet>0 && myTree.jet_pt[0]>30. ) { TLorentzVector jet; jet.SetPtEtaPhiM( myTree.jet_pt[0], myTree.jet_eta[0], myTree.jet_phi[0], myTree.jet_mass[0] ); TLorentzVector qgamma = jet+photon; TLorentzVector qZ = jet+zBoson; qgamma_mass = qgamma.M(); qZ_mass = qZ.M(); } if( DATABLINDING && myTree.isData && boss_mass>500. ) continue; if( doSystForThisSample ) { // systematic uncertainties for( int i=0; i<myTree.nLHEweight; ++i ) { bool goodIndex = (myTree.LHEweight_id[i]>=2000 && myTree.LHEweight_id[i]<=3000); if( goodIndex ) pdf_num[i] += myTree.LHEweight_wgt[i]; } //for pdf sets } //if( id==851 && doSyst ) { // systematic uncertainties // // first scale // float ref = myTree.LHEweight_original; // float maxScaleDiff = 0.; // TH1D* h1_pdf = new TH1D("pdf", "", 1000, -3000., 3000.); // for( int i=0; i<myTree.nLHEweight; ++i ) { // if( myTree.LHEweight_id[i]>=1000 && myTree.LHEweight_id[i]<1010 ) { // float thisScaleDiff = fabs( (myTree.LHEweight_wgt[i]-ref)/ref ); // if( thisScaleDiff>maxScaleDiff) // maxScaleDiff = thisScaleDiff+1.; // } // if( myTree.LHEweight_id[i]>=2000 ) { // if( myTree.LHEweight_wgt[i] > h1_pdf->GetXaxis()->GetXmax() || myTree.LHEweight_wgt[i] < h1_pdf->GetXaxis()->GetXmin() ) // std::cout << "WARNING!! PDF weight out of bounds: " << myTree.LHEweight_wgt[i] << std::endl; // h1_pdf->Fill( myTree.LHEweight_wgt[i]/ref ); // } // } // for lhe weights // float meanPdfWgt = h1_pdf->GetMean(); // float rmsPdfWgt = h1_pdf->GetRMS(); // weight_pdf *= (1.+rmsPdfWgt/meanPdfWgt); // weight_scale *= maxScaleDiff; // delete h1_pdf; //} // if correct sample if( event == DEBUG_EVENT ) std::cout << " -> filling tree" << std::endl; outTree->Fill(); } // for entries TH1D* h1_pdf = new TH1D( Form("pdf_%s", treeName.c_str()), "", 2000, 0., 1. ); for( unsigned i=0; i<pdf_num.size(); ++i ) { if( pdf_num[i]!=0. ) h1_pdf->Fill( pdf_num[i]/pdf_denom[i] ); } if( h1_pdf->GetMean()>0. ) h1_pdf->Write(); outTree->Write(); puFile->Close(); }
//////////////////Taking in/out file name as input void loop(string infile, string outfile, bool REAL=0){ //void loop(bool REAL=0){ const char* infname; const char* outfname; ///////////////// if(REAL) { cout<<"--- REAL DATA ---"<<endl; infname = "/net/hidsk0001/d00/scratch/yjlee/bmeson/merged_pPbData_20131114.root"; outfname = "nt_data.root"; } else { cout<<"--- MC ---"<<endl; //infname = "/mnt/hadoop/cms/store/user/wangj/HI_Btuple/20140218_PAMuon_HIRun2013_PromptReco_v1/Bfinder_all_100_1_Jrd.root"; //outfname = "nt_mc.root"; ////////////////// infname = infile.c_str(); outfname = outfile.c_str(); ///////////////// } //File type TFile *f = new TFile(infname); TTree *root = (TTree*)f->Get("demo/root"); //Chain type //TChain* root = new TChain("demo/root"); //root->Add("/mnt/hadoop/cms/store/user/twang/HI_Btuple/20131202_PPMuon_Run2013A-PromptReco-v1_RECO/Bfinder_all_*"); setBranch(root); TFile *outf = new TFile(outfname,"recreate"); int ifchannel[7]; ifchannel[0] = 1; //jpsi+Kp ifchannel[1] = 1; //jpsi+pi ifchannel[2] = 1; //jpsi+Ks(pi+,pi-) ifchannel[3] = 1; //jpsi+K*(K+,pi-) ifchannel[4] = 1; //jpsi+K*(K-,pi+) ifchannel[5] = 1; //jpsi+phi ifchannel[6] = 1; //jpsi+pi pi <= psi', X(3872), Bs->J/psi f0 bNtuple* b0 = new bNtuple; bNtuple* b1 = new bNtuple; bNtuple* b2 = new bNtuple; bNtuple* b3 = new bNtuple; bNtuple* b4 = new bNtuple; bNtuple* b5 = new bNtuple; bNtuple* b6 = new bNtuple; TTree* nt0 = new TTree("ntKp",""); b0->buildBranch(nt0); TTree* nt1 = new TTree("ntpi",""); b1->buildBranch(nt1); TTree* nt2 = new TTree("ntKs",""); b2->buildBranch(nt2); TTree* nt3 = new TTree("ntKstar1",""); b3->buildBranch(nt3); TTree* nt4 = new TTree("ntKstar2",""); b4->buildBranch(nt4); TTree* nt5 = new TTree("ntphi",""); b5->buildBranch(nt5); TTree* nt6 = new TTree("ntmix",""); b6->buildBranch(nt6); TNtuple* ntGen = new TNtuple("ntGen","","y:eta:phi:pt:pdgId"); Long64_t nentries = root->GetEntries(); Long64_t nbytes = 0; TVector3* bP = new TVector3; TVector3* bVtx = new TVector3; TLorentzVector bGen; int type; for (Long64_t i=0; i<100;i++) { // for (Long64_t i=0; i<nentries;i++) { nbytes += root->GetEntry(i); if (i%10000==0) cout <<i<<" / "<<nentries<<endl; for (int j=0;j<BInfo_size;j++) { if(BInfo_type[j]>7) continue; if (ifchannel[BInfo_type[j]-1]!=1) continue; if(BInfo_type[j]==1) { fillTree(b0,bP,bVtx,j); nt0->Fill(); } if(BInfo_type[j]==2) { fillTree(b1,bP,bVtx,j); nt1->Fill(); } if(BInfo_type[j]==3) { fillTree(b2,bP,bVtx,j); nt2->Fill(); } if(BInfo_type[j]==4) { fillTree(b3,bP,bVtx,j); nt3->Fill(); } if(BInfo_type[j]==5) { fillTree(b4,bP,bVtx,j); nt4->Fill(); } if(BInfo_type[j]==6) { fillTree(b5,bP,bVtx,j); nt5->Fill(); } if(BInfo_type[j]==7) { fillTree(b6,bP,bVtx,j); nt6->Fill(); } } for (int j=0;j<GenInfo_size;j++) { for(type=1;type<8;type++) { if(signalGen(type,j)) { bGen.SetPtEtaPhiM(GenInfo_pt[j],GenInfo_eta[j],GenInfo_phi[j],GenInfo_mass[j]); ntGen->Fill(bGen.Rapidity(),bGen.Eta(),bGen.Phi(),bGen.Pt(),GenInfo_pdgId[j]); break; } } } } outf->Write(); outf->Close(); }
void testPhiSRvsDetPhi(){ //LOAD LIBS_____________________ cout << "\n"; gROOT->Macro("StRoot/LoadLibs.C"); gSystem->Load("pionPair"); cout << " loading of pionPair library done" << endl; //______________________________ TH2D* hPhiSRvPhi_Up = new TH2D("hPhiSRvPhi_Up","hPhiSRvPhi_Up",16,-3.14159,3.14159,16,-3.14159,3.14159); TH2D* hPhiSRvPhi_Down = new TH2D("hPhiSRvPhi_Down","hPhiSRvPhi_Down",16,-3.14159,3.14159,16,-3.14159,3.14159); TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOut_Full_4_2/allPairs_4_2.root"); string outFileName = "./resultsNew_4_22/yellowEtaGT0_pairs_4_2.root"; //______________________________ //SET UP TREE TO RECEIVE INPUT__ pionPair* pair1 = new pionPair(); TTree* pairTree = infile->Get("pionPairTree"); pairTree->SetBranchAddress("pionPair", &pair1); //______________________________ TLorentzVector sum; TLorentzVector sumY; TLorentzVector sumB; for (int iPair = 0; iPair < pairTree->GetEntries(); iPair++) { if (iPair%10000 == 0) {cout << "processing pair number " << iPair << endl;} if (iPair == 1000000){break;} pairTree->GetEntry(iPair); if (pair1->withinRadius(0.05, 0.3)) { bool triggerFired = false; bool fromKaon = false; bool passInitialCut_B = false; bool passInitialCut_Y = false; bool passDCAcut = false; StTriggerId trigId = pair1->triggerIds(); //JP0,JP1,JP2,AJP if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621) || trigId.isTrigger(370641)) { triggerFired = true; } //BHT0VPD,BHT1VPD,BHT2BBC,BHT2 if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531)) { triggerFired = true; } if (triggerFired) { sum = pair1->piPlusLV() + pair1->piMinusLV(); sumB = sum; //blue beam. if (sumB.Pt() >= 3 && sumB.Pt() <= 50 && sumB.M() >= 0 && sumB.M() <= 100 && sumB.Eta() >= -1.4 && sumB.Eta() <= 1.4) { passInitialCut_B = true; } if (passInitialCut_B && (pair1->spinBit() == 9 || pair1->spinBit() == 10)) { cout << pair1->phiSR('b') << " " << sumB.Phi() << endl; hPhiSRvPhi_Up->Fill(pair1->phiSR('b'), sumB.Phi()); } if (passInitialCut_B && (pair1->spinBit() == 5 || pair1->spinBit() == 6)) { hPhiSRvPhi_Down->Fill(pair1->phiSR('b'), sumB.Phi()); } } } } TCanvas* cUp = new TCanvas(); hPhiSRvPhi_Up->Draw("colz"); TCanvas* cDown = new TCanvas(); hPhiSRvPhi_Down->Draw("colz"); }
void recursive_inter_with_air(){ TFile *f1 = new TFile("muon.root", "recreate"); TCanvas *c1 = new TCanvas("test", "test", 600, 700); TH1F * mu_c_1 = new TH1F("mu_c_1", "mu_c_1", 100, 0, 500); TH1F * mu_c_2 = new TH1F("mu_c_2", "mu_c_2", 100, 0, 500); TH1F * mu_c_3 = new TH1F("mu_c_3", "mu_c_3", 100, 0, 500); fn_muon_dxde = new TF1("f1", dxde_muon, M_mu, 1000, 1); TNtuple * ntuple = new TNtuple("ntuple", "ntuple", "nobs:detz:theta:press"); // TNtuple *ntuple = new TNtuple("ntuple", "ntuple", "id:flag:e:px:py:pz:x:y:z"); r = new TRandom(); // r ->SetSeed(12232); for (int ievertex_nt = 0; ievertex_nt < 500; ievertex_nt++) { n_particle = 0; // init muon conunter int mu_counter1 = 0; int mu_counter2 = 0; int mu_counter3 = 0; double E = 1000; // GeV double theta = 0; // double theta = acos(r->Rndm()); double phi = r->Rndm()*pi*2; double x = 0, y = 0, z = 1.0e10; //infinity double vertex_z, vertex_x, vertex_y; //km Get_Int_Posi(pdg_proton_p, theta, phi, x, y, z, vertex_x, vertex_y, vertex_z); Hillas_Split(pdg_proton_p, E, theta, phi, vertex_x, vertex_y, vertex_z); double proton_threshold = 10; double pion_threshold = 10; int i_particle = 0; while(i_particle < n_particle){ int id = Ptcl_bank[i_particle].id; int flag = Ptcl_bank[i_particle].flag; double e = Ptcl_bank[i_particle].e; double x = Ptcl_bank[i_particle].vertex_x; double y = Ptcl_bank[i_particle].vertex_y; double z = Ptcl_bank[i_particle].vertex_z; if (id == pdg_proton_p && flag == 1 && e > proton_threshold) { Get_Int_Posi(id, theta, phi, x, y, z, vertex_x, vertex_y, vertex_z); if (vertex_z > 0) { Hillas_Split(id, e, theta, phi, vertex_x, vertex_y, vertex_z); Ptcl_bank[i_particle].flag = 0; } } if (id == pdg_pion_p &&flag == 1){ Get_Int_Posi(id, theta, phi, x, y, z, vertex_x, vertex_y, vertex_z) ; double l_to_interaction = sqrt((vertex_x-x)*(vertex_x-x)+(vertex_y-y)*(vertex_y-y)+(vertex_z-z)*(vertex_z-z)); double l_to_decay = get_decay_length(pdg_pion_p, tau_pion, e); if (l_to_decay>l_to_interaction){ if (vertex_z > 0){ Hillas_Split(id, e, theta, phi, vertex_x, vertex_y, vertex_z); Ptcl_bank[i_particle].flag = 0; } }else{ // pion decay Ptcl_bank[i_particle].flag = 0; double px = Ptcl_bank[i_particle].px; double py = Ptcl_bank[i_particle].py; double pz = Ptcl_bank[i_particle].pz; // GeV TLorentzVector pion(px, py, pz, e); double decay_particle_mass[2] = {M_mu, M_neu}; TGenPhaseSpace event; event.SetDecay(pion, 2, decay_particle_mass); event.Generate(); TLorentzVector Muon = *(event.GetDecay(0)); TLorentzVector Neu = *(event.GetDecay(1)); double mu_theta = Muon.Theta(); double mu_phi = Muon.Phi(); if (mu_theta>pi/2.) { double mu_E = Muon.E(); double muon_decay_time = r ->Exp(tau_muon); double muon_decay_length = get_decay_length(pdg_muon_n, tau_muon, mu_E); float det_x = 0; float det_y = 0; float det_z = 0; mu_counter1++; double l_mu_vtx_to_det = sqrt(pow(vertex_x-det_x,2)+pow(vertex_y-det_y,2)+pow(vertex_z-det_z,2)); // cout << "MuE" << mu_E << " Mass" <<M_mu<< " dl" << muon_decay_length << " lvd" << l_mu_vtx_to_det << endl; if (muon_decay_length > l_mu_vtx_to_det) { mu_counter2++; double mu_stop_x; double mu_stop_y; double mu_stop_z; get_muon_stop_position(mu_E, mu_theta, mu_phi, vertex_x, vertex_y, vertex_z, mu_stop_x, mu_stop_y, mu_stop_z); double l_muon_stop = sqrt(pow(vertex_x-mu_stop_x,2)+pow(vertex_y-mu_stop_y,2)+pow(vertex_z-mu_stop_z,2)); // cout << l_muon_stop << " " << l_mu_vtx_to_det <<endl; if (l_muon_stop > l_mu_vtx_to_det) { mu_counter3++; } } } } } i_particle++; } mu_c_1 ->Fill(mu_counter1); mu_c_2 ->Fill(mu_counter2); mu_c_3 ->Fill(mu_counter3); // for (int i_particle = 0; i_particle < n_particle; ++i_particle){ // int id = Ptcl_bank[i_particle].id; // int flag = Ptcl_bank[i_particle].flag; // double e = Ptcl_bank[i_particle].e; // double px = Ptcl_bank[i_particle].px; // double py = Ptcl_bank[i_particle].py; // double pz = Ptcl_bank[i_particle].pz; // double x = Ptcl_bank[i_particle].vertex_x; // double y = Ptcl_bank[i_particle].vertex_y; // double z = Ptcl_bank[i_particle].vertex_z; // ntuple->Fill(id, flag, e, px, py, pz, x, y, z); // } } mu_c_3 ->Draw(); mu_c_2 ->SetLineColor(2); mu_c_2 ->Draw("same"); mu_c_1 ->SetLineColor(4); mu_c_1 ->Draw("same"); // ntuple->Draw("z"); }
void test_JVBF(int erg_tev=8, float mSample=0, bool isggH=false){ float mPOLE=mSample; if (mPOLE<=0) mPOLE=125.6; float wPOLE=4.15e-3; char TREE_NAME[] = "SelectedTree"; // TVar::VerbosityLevel verbosity = TVar::INFO; Mela mela(erg_tev, mPOLE); TFile* foutput; if (!isggH){ if (mSample>0) foutput = new TFile(Form("HZZ4lTree_jvbfMELA_H%.0f_%iTeV.root", mSample, erg_tev), "recreate"); else foutput = new TFile(Form("HZZ4lTree_jvbfMELA_HAll_%iTeV.root", erg_tev), "recreate"); } else{ if (mSample>0) foutput = new TFile(Form("HZZ4lTree_jvbfMELA_ggH%.0f_%iTeV.root", mSample, erg_tev), "recreate"); else foutput = new TFile(Form("HZZ4lTree_jvbfMELA_ggHAll_%iTeV.root", erg_tev), "recreate"); } TLorentzVector nullFourVector(0, 0, 0, 0); float MC_weight_noxsec; float pjvbf_VAJHU; float pjvbf_VAJHU_first; float pjvbf_VAJHU_second; float phj_VAJHU_first; float phj_VAJHU_second; float pAux_vbf; float pAux_vbf_first; float pAux_vbf_second; float jet1Pt, jet2Pt; float jet1Eta, jet2Eta; float jet1Phi, jet2Phi; float jet1E, jet2E; float jet1Pt_Fake, jet2Pt_Fake; float jet1Eta_Fake, jet2Eta_Fake; float jet1Phi_Fake, jet2Phi_Fake; float jet1E_Fake, jet2E_Fake; float jet1px, jet1py, jet1pz; float jet2px, jet2py, jet2pz; float ZZPx, ZZPy, ZZPz, ZZE, dR; short NJets30; std::vector<double> * JetPt=0; std::vector<double> * JetEta=0; std::vector<double> * JetPhi=0; std::vector<double> * JetMass=0; std::vector<double> myJetPt; std::vector<double> myJetCosTheta; std::vector<double> myJetEta; std::vector<double> myJetPhi; std::vector<double> myJetMass; TBranch* bJetPt=0; TBranch* bJetEta=0; TBranch* bJetPhi=0; TBranch* bJetMass=0; float ZZMass, ZZPt, ZZPhi, ZZEta; int GenLep1Id, GenLep2Id, GenLep3Id, GenLep4Id; TChain* tree = new TChain(TREE_NAME); char* user_folder[3]={ "4mu", "4e", "2mu2e" }; TString cinput_main = "/scratch0/hep/ianderso/CJLST/140519/PRODFSR"; if (erg_tev==8) cinput_main.Append("_8TeV"); // TString cinput_main = "/afs/cern.ch/work/u/usarica/HZZ4l-125p6-FullAnalysis/LHC_"; // cinput_main.Append(Form("%iTeV", erg_tev)); for (int ff=0; ff<3; ff++){ if (!isggH){ if (mSample>0) tree->Add(Form("%s/%s/HZZ4lTree_VBFH%.0f.root", cinput_main.Data(), user_folder[ff], mSample)); else tree->Add(Form("%s/%s/HZZ4lTree_VBFH*.root", cinput_main.Data(), user_folder[ff])); } else{ if (mSample>0) tree->Add(Form("%s/%s/HZZ4lTree_minloH%.0f.root", cinput_main.Data(), user_folder[ff], mSample)); else tree->Add(Form("%s/%s/HZZ4lTree_minloH*.root", cinput_main.Data(), user_folder[ff])); } } tree->SetBranchAddress("MC_weight_noxsec", &MC_weight_noxsec); tree->SetBranchAddress("NJets30", &NJets30); tree->SetBranchAddress("JetPt", &JetPt, &bJetPt); tree->SetBranchAddress("JetEta", &JetEta, &bJetEta); tree->SetBranchAddress("JetPhi", &JetPhi, &bJetPhi); tree->SetBranchAddress("JetMass", &JetMass, &bJetMass); tree->SetBranchAddress("ZZMass", &ZZMass); tree->SetBranchAddress("ZZPt", &ZZPt); tree->SetBranchAddress("ZZEta", &ZZEta); tree->SetBranchAddress("ZZPhi", &ZZPhi); TTree* newtree = new TTree("TestTree", ""); newtree->Branch("MC_weight_noxsec", &MC_weight_noxsec); newtree->Branch("ZZMass", &ZZMass); newtree->Branch("pAux_vbf", &pAux_vbf); newtree->Branch("pAux_vbf_first", &pAux_vbf_first); newtree->Branch("pAux_vbf_second", &pAux_vbf_second); newtree->Branch("pjvbf_VAJHU", &pjvbf_VAJHU); newtree->Branch("pjvbf_VAJHU_first", &pjvbf_VAJHU_first); newtree->Branch("pjvbf_VAJHU_second", &pjvbf_VAJHU_second); newtree->Branch("phj_VAJHU_first", &phj_VAJHU_first); newtree->Branch("phj_VAJHU_second", &phj_VAJHU_second); newtree->Branch("NJets30", &NJets30); newtree->Branch("jet1Pt", &jet1Pt); newtree->Branch("jet1Eta", &jet1Eta); newtree->Branch("jet1Phi", &jet1Phi); newtree->Branch("jet1E", &jet1E); newtree->Branch("jet2Pt", &jet2Pt); newtree->Branch("jet2Eta", &jet2Eta); newtree->Branch("jet2Phi", &jet2Phi); newtree->Branch("jet2E", &jet2E); newtree->Branch("jet1_Fake_Pt", &jet1Pt_Fake); newtree->Branch("jet1_Fake_Eta", &jet1Eta_Fake); newtree->Branch("jet1_Fake_Phi", &jet1Phi_Fake); newtree->Branch("jet1_Fake_E", &jet1E_Fake); newtree->Branch("jet2_Fake_Pt", &jet2Pt_Fake); newtree->Branch("jet2_Fake_Eta", &jet2Eta_Fake); newtree->Branch("jet2_Fake_Phi", &jet2Phi_Fake); newtree->Branch("jet2_Fake_E", &jet2E_Fake); newtree->Branch("JetPt", &myJetPt); // newtree->Branch("JetCosTheta", &myJetCosTheta); newtree->Branch("JetPhi", &myJetPhi); newtree->Branch("JetMass", &myJetMass); int nEntries = tree->GetEntries(); double selfDHggcoupl[SIZE_HGG][2] ={ { 0 } }; double selfDHvvcoupl[SIZE_HVV_VBF][2] ={ { 0 } }; double selfDHwwcoupl[SIZE_HWW_VBF][2] ={ { 0 } }; double ggvvcoupl[2]={ 0, 0 }; mela.setProcess(TVar::SelfDefine_spin0, TVar::JHUGen, TVar::ZZGG); int recorded=0; for (int ev = 0; ev < nEntries; ev++){ pjvbf_VAJHU=-1; pjvbf_VAJHU_first=-1; pjvbf_VAJHU_second=-1; jet1Pt=-1; jet2Pt=-1; jet1Eta=0; jet2Eta=0; tree->GetEntry(ev); GenLep1Id=11; GenLep2Id=-11; GenLep3Id=11; GenLep4Id=-11; myJetPt.clear(); myJetEta.clear(); myJetPhi.clear(); myJetMass.clear(); myJetCosTheta.clear(); TLorentzVector jet1(0, 0, 1e-3, 1e-3), jet2(0, 0, 1e-3, 1e-3), higgs(0, 0, 0, 0); TLorentzVector p4[3], jets[2]; higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, ZZMass); for (int i = 0; i < NJets30; i++){ myJetPt.push_back(JetPt->at(i)); myJetEta.push_back(JetEta->at(i)); myJetPhi.push_back(JetPhi->at(i)); myJetMass.push_back(JetMass->at(i)); myJetCosTheta.push_back(eta_to_costheta(JetEta->at(i))); } int filled = 0; if (myJetPt.size()>=1){ jets[0].SetPxPyPzE(0, 0, 0, 1); jets[1].SetPxPyPzE(0, 0, 0, 1); for (int i = 0; i < myJetPt.size(); i++){ jets[filled].SetPtEtaPhiM(myJetPt[i], myJetEta[i], myJetPhi[i], myJetMass[i]); if (filled==0){ double jetE = jets[filled].Energy(); double jetP = jets[filled].P(); double ratio = (jetP>0 ? jetE/jetP : 1); ratio = 1.; jet1.SetPxPyPzE(jets[filled].Px()*ratio, jets[filled].Py()*ratio, jets[filled].Pz()*ratio, jetE); filled++; jet1Pt = jet1.Pt(); jet1Eta = jet1.Eta(); jet1Phi = jet1.Phi(); jet1E = jet1.E(); jet2.SetXYZT(0, 0, 0, 0); } else if(filled==1){ double jetE = jets[filled].Energy(); double jetP = jets[filled].P(); double ratio = (jetP>0 ? jetE/jetP : 1); ratio = 1.; jet2.SetXYZT(jets[filled].Px()*ratio, jets[filled].Py()*ratio, jets[filled].Pz()*ratio, jetE); filled++; jet2Pt = jet2.Pt(); jet2Eta = jet2.Eta(); jet2Phi = jet2.Phi(); jet2E = jet2.E(); } else continue; /* if (filled == 0){ if (jets[filled].Pt()>jet1.Pt()){ jet1.SetPxPyPzE(jets[filled].Px(), jets[filled].Py(), jets[filled].Pz(), jetE); jet1Pt = jet1.Pt(); } if (i == myJetPt.size() - 1){ filled++; i = 0; } } else{ if (jets[filled].Pt()<jet1.Pt() && jets[filled].Pt()>jet2.Pt()){ jet2.SetPxPyPzE(jets[filled].Px(), jets[filled].Py(), jets[filled].Pz(), jetE); jet2Pt = jet2.Pt(); } if (i == myJetPt.size() - 1){ filled++; } } if (filled == 2) break; */ } //cos(atan(exp(-jet2Eta))*2) if (filled == 2){ mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JJVBF); mela.computeProdP(jet1, 2, jet2, 2, higgs, 25, nullFourVector, 0, pjvbf_VAJHU); mela.get_PAux(pAux_vbf); TLorentzVector pTotal; pTotal.SetXYZT(0, 0, 0, 0); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JJVBF); mela.computeProdP(jet1, 2, pTotal, 2, higgs, 25, nullFourVector, 0, pjvbf_VAJHU_first); mela.get_PAux(pAux_vbf_first); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JH); mela.computeProdP(jet1, 2, pTotal, 2, higgs, 25, nullFourVector, 0, phj_VAJHU_first); mela::computeFakeJet(jet1, higgs, pTotal); jet2Pt_Fake = pTotal.Pt(); jet2Eta_Fake = pTotal.Eta(); jet2Phi_Fake = pTotal.Phi(); jet2E_Fake = pTotal.E(); pTotal.SetXYZT(0, 0, 0, 0); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JJVBF); mela.computeProdP(pTotal, 2, jet2, 2, higgs, 25, nullFourVector, 0, pjvbf_VAJHU_second); mela.get_PAux(pAux_vbf_second); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JH); mela.computeProdP(pTotal, 2, jet2, 2, higgs, 25, nullFourVector, 0, phj_VAJHU_second); mela::computeFakeJet(jet2, higgs, pTotal); jet1Pt_Fake = pTotal.Pt(); jet1Eta_Fake = pTotal.Eta(); jet1Phi_Fake = pTotal.Phi(); jet1E_Fake = pTotal.E(); newtree->Fill(); } else if (filled == 1){ /* TLorentzVector pTotal = higgs+jet1; pTotal.SetVect(-pTotal.Vect()); pTotal.SetE(pTotal.P()); jet2 = pTotal; jet2Pt = jet2.Pt(); jet2Eta = jet2.Eta(); jet2Phi = jet2.Phi(); jet2E = jet2.E(); jet1Pt_Fake = jet1.Pt(); jet1Eta_Fake = jet1.Eta(); jet1Phi_Fake = jet1.Phi(); jet1E_Fake = jet1.E(); jet2Pt_Fake = jet2.Pt(); jet2Eta_Fake = jet2.Eta(); jet2Phi_Fake = jet2.Phi(); jet2E_Fake = jet2.E(); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JJVBF); mela.computeProdP(jet1, 2, jet2, 2, higgs, 25, nullFourVector, 0, pjvbf_VAJHU); */ // jet2.SetXYZT(0,0,0,0); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JJVBF); mela.computeProdP(jet1, 2, jet2, 2, higgs, 25, nullFourVector, 0, pjvbf_VAJHU); mela.get_PAux(pAux_vbf); mela.setProcess(TVar::HSMHiggs, TVar::JHUGen, TVar::JH); mela.computeProdP(jet1, 2, jet2, 2, higgs, 25, nullFourVector, 0, phj_VAJHU_first); mela::computeFakeJet(jet1, higgs, jet2); /* cout << "TEST:" << " Higgs Pz: " << higgs.Pz() << " Higgs P: " << higgs.P() << " Higgs E: " << higgs.T() << " Jet 1 Pz: " << jet1.Pz() << " Jet 1 P: " << jet1.P() << " Jet 1 E: " << jet1.T() << " Jet 2 Pz: " << jet2.Pz() << " Jet 2 P: " << jet2.P() << " Jet 2 E: " << jet2.T() << '\n' << endl; */ jet2Pt = jet2.Pt(); jet2Eta = jet2.Eta(); jet2Phi = jet2.Phi(); jet2E = jet2.E(); jet1Pt_Fake = jet1.Pt(); jet1Eta_Fake = jet1.Eta(); jet1Phi_Fake = jet1.Phi(); jet1E_Fake = jet1.E(); jet2Pt_Fake = jet2.Pt(); jet2Eta_Fake = jet2.Eta(); jet2Phi_Fake = jet2.Phi(); jet2E_Fake = jet2.E(); // pjvbf_VAJHU_first = pjvbf_VAJHU; pjvbf_VAJHU_second = pjvbf_VAJHU; pAux_vbf_first = pAux_vbf; pAux_vbf_second = pAux_vbf; phj_VAJHU_second = phj_VAJHU_first; newtree->Fill(); } } } foutput->WriteTObject(newtree); delete newtree; foutput->Close(); delete tree; }
void fill(int const kf, TLorentzVector* b, double weight, TLorentzVector const& p1Mom, TLorentzVector const& p2Mom, TVector3 v00) { int const centrality = floor(nCent * gRandom->Rndm()); TVector3 const vertex = getVertex(centrality); // smear primary vertex // float const sigmaVertex = sigmaVertexCent[cent]; // TVector3 const vertex(gRandom->Gaus(0, sigmaVertex), gRandom->Gaus(0, sigmaVertex), gRandom->Gaus(0, sigmaVertex)); v00 += vertex; // smear momentum TLorentzVector const p1RMom = smearMom(0, p1Mom); TLorentzVector const p2RMom = smearMom(0, p2Mom); // smear position TVector3 const p1RPos = smearPosData(0, vertex.z(), centrality, p1RMom, v00); TVector3 const p2RPos = smearPosData(0, vertex.z(), centrality, p2RMom, v00); // TVector3 const kRPos = smearPos(kMom, kRMom, v00); // TVector3 const pRPos = smearPos(pMom, pRMom, v00); // reconstruct TLorentzVector const rMom = p1RMom + p2RMom; float const p1Dca = dca(p1Mom.Vect(), v00, vertex); float const p2Dca = dca(p2Mom.Vect(), v00, vertex); float const p1RDca = dca(p1RMom.Vect(), p1RPos, vertex); float const p2RDca = dca(p2RMom.Vect(), p2RPos, vertex); TVector3 v0; float const dca12 = dca1To2(p1RMom.Vect(), p1RPos, p2RMom.Vect(), p2RPos, v0); float const decayLength = (v0 - vertex).Mag(); float const dcaD0ToPv = dca(rMom.Vect(), v0, vertex); float const cosTheta = (v0 - vertex).Unit().Dot(rMom.Vect().Unit()); float const angle12 = p1RMom.Vect().Angle(p2RMom.Vect()); TLorentzVector p1RMomRest = p1RMom; TVector3 beta; beta.SetMagThetaPhi(rMom.Beta(), rMom.Theta(), rMom.Phi()); p1RMomRest.Boost(-beta); float const cosThetaStar = rMom.Vect().Unit().Dot(p1RMomRest.Vect().Unit()); // save float arr[100]; int iArr = 0; arr[iArr++] = centrality; arr[iArr++] = vertex.X(); arr[iArr++] = vertex.Y(); arr[iArr++] = vertex.Z(); arr[iArr++] = kf; arr[iArr++] = b->M(); arr[iArr++] = b->Perp(); arr[iArr++] = b->PseudoRapidity(); arr[iArr++] = b->Rapidity(); arr[iArr++] = b->Phi(); arr[iArr++] = v00.X(); arr[iArr++] = v00.Y(); arr[iArr++] = v00.Z(); arr[iArr++] = rMom.M(); arr[iArr++] = rMom.Perp(); arr[iArr++] = rMom.PseudoRapidity(); arr[iArr++] = rMom.Rapidity(); arr[iArr++] = rMom.Phi(); arr[iArr++] = v0.X(); arr[iArr++] = v0.Y(); arr[iArr++] = v0.Z(); arr[iArr++] = dca12; arr[iArr++] = decayLength; arr[iArr++] = dcaD0ToPv; arr[iArr++] = cosTheta; arr[iArr++] = angle12; arr[iArr++] = cosThetaStar; arr[iArr++] = p1Mom.M(); arr[iArr++] = p1Mom.Perp(); arr[iArr++] = p1Mom.PseudoRapidity(); arr[iArr++] = p1Mom.Rapidity(); arr[iArr++] = p1Mom.Phi(); arr[iArr++] = p1Dca; arr[iArr++] = p1RMom.M(); arr[iArr++] = p1RMom.Perp(); arr[iArr++] = p1RMom.PseudoRapidity(); arr[iArr++] = p1RMom.Rapidity(); arr[iArr++] = p1RMom.Phi(); arr[iArr++] = p1RPos.X(); arr[iArr++] = p1RPos.Y(); arr[iArr++] = p1RPos.Z(); arr[iArr++] = p1RDca; arr[iArr++] = tpcReconstructed(0,1,centrality,p1RMom); arr[iArr++] = p2Mom.M(); arr[iArr++] = p2Mom.Perp(); arr[iArr++] = p2Mom.PseudoRapidity(); arr[iArr++] = p2Mom.Rapidity(); arr[iArr++] = p2Mom.Phi(); arr[iArr++] = p2Dca; arr[iArr++] = p2RMom.M(); arr[iArr++] = p2RMom.Perp(); arr[iArr++] = p2RMom.PseudoRapidity(); arr[iArr++] = p2RMom.Rapidity(); arr[iArr++] = p2RMom.Phi(); arr[iArr++] = p2RPos.X(); arr[iArr++] = p2RPos.Y(); arr[iArr++] = p2RPos.Z(); arr[iArr++] = p2RDca; arr[iArr++] = tpcReconstructed(0,-1,centrality,p2RMom); arr[iArr++] = matchHft(1, vertex.z(), centrality, p1RMom); arr[iArr++] = matchHft(0, vertex.z(), centrality, p2RMom); nt->Fill(arr); }
void analyzer_data40pb(int files, int files_max){ const int nfiles = 1; TString file_names[nfiles] = {"tree_BTagCSV.root"}; TString type[nfiles] = {"Data40pb_DoubleBtag"}; do { Float_t presel=0; Float_t cut1 = 0; Float_t cut2 = 0; Float_t cut3 = 0; Float_t genweight=1.; Int_t global_counter = 0; Bool_t HLT_QuadPFJet_DoubleBTag_CSV_VBF_Mqq200; TFile *file_initial = new TFile(file_names[files]); TTree *tree_initial = (TTree*)file_initial->Get("tree"); Jets Jet; Float_t v_type; Float_t wrong_type=0.; Int_t nJets; Int_t JSON = 0; tree_initial->SetBranchAddress("offJet_num",&nJets); tree_initial->SetBranchAddress("offJet_pt",Jet.pt); tree_initial->SetBranchAddress("offJet_eta",Jet.eta); tree_initial->SetBranchAddress("offJet_phi",Jet.phi); tree_initial->SetBranchAddress("offJet_mass",Jet.mass); tree_initial->SetBranchAddress("offJet_csv",Jet.btag); tree_initial->SetBranchAddress("HLT_QuadPFJet_DoubleBTagCSV_VBF_Mqq200_v2",&HLT_QuadPFJet_DoubleBTag_CSV_VBF_Mqq200); tree_initial->SetBranchAddress("JSON",&JSON); TH1F *hJet1_pt_bin = new TH1F("hJet1_pt_bin", "", 50, 90., 140.); hJet1_pt_bin->GetXaxis()->SetTitle("1st Jet p_{T} (GeV)"); TH1F *hJet2_pt_bin = new TH1F("hJet2_pt_bin", "", 40, 70., 110.); hJet2_pt_bin->GetXaxis()->SetTitle("2nd Jet p_{T} (GeV)"); TH1F *hJet3_pt_bin = new TH1F("hJet3_pt_bin", "", 30, 60., 90.); hJet3_pt_bin->GetXaxis()->SetTitle("3rd Jet p_{T} (GeV)"); TH1F *hJet4_pt_bin = new TH1F("hJet4_pt_bin", "", 40, 30., 70.); hJet4_pt_bin->GetXaxis()->SetTitle("4th Jet p_{T} (GeV)"); TH1F *hMqq_bin = new TH1F("hMqq_bin","",50.,200.,250.); hMqq_bin->GetXaxis()->SetTitle("m_{qq} (GeV)"); TH1F *hJet1_pt = new TH1F("hJet1_pt", "", 30, 0., 600.); hJet1_pt->GetXaxis()->SetTitle("1st Jet p_{T} (GeV)"); TH1F *hJet2_pt = new TH1F("hJet2_pt", "", 30, 0., 600.); hJet2_pt->GetXaxis()->SetTitle("2nd Jet p_{T} (GeV)"); TH1F *hJet3_pt = new TH1F("hJet3_pt", "", 20, 0., 400.); hJet3_pt->GetXaxis()->SetTitle("3rd Jet p_{T} (GeV)"); TH1F *hJet4_pt = new TH1F("hJet4_pt", "", 20, 0., 400.); hJet4_pt->GetXaxis()->SetTitle("4th Jet p_{T} (GeV)"); TH1F *hJet5_pt = new TH1F("hJet5_pt", "", 25, 0., 500.); hJet5_pt->GetXaxis()->SetTitle("5th Jet p_{T} (GeV)"); TH1F *hJet1_eta = new TH1F("hJet1_eta", "", 20, -5., 5.); hJet1_eta->GetXaxis()->SetTitle("1st Jet #eta"); TH1F *hJet2_eta = new TH1F("hJet2_eta", "", 20, -5., 5.); hJet2_eta->GetXaxis()->SetTitle("2nd Jet #eta"); TH1F *hJet3_eta = new TH1F("hJet3_eta", "", 20, -5., 5.); hJet3_eta->GetXaxis()->SetTitle("3rd Jet #eta"); TH1F *hJet4_eta = new TH1F("hJet4_eta", "", 20, -5., 5.); hJet4_eta->GetXaxis()->SetTitle("4th Jet #eta"); TH1F *hJet1_phi = new TH1F("hJet1_phi", "", 32,-3.2,3.2); hJet1_phi->GetXaxis()->SetTitle("1st Jet #phi"); TH1F *hJet2_phi = new TH1F("hJet2_phi", "", 32,-3.2,3.2); hJet2_phi->GetXaxis()->SetTitle("2nd Jet #phi"); TH1F *hJet3_phi = new TH1F("hJet3_phi", "", 32,-3.2,3.2); hJet3_phi->GetXaxis()->SetTitle("3rd Jet #phi"); TH1F *hJet4_phi = new TH1F("hJet4_phi", "", 32,-3.2,3.2); hJet4_phi->GetXaxis()->SetTitle("4th Jet #phi"); TH1F *hVtype = new TH1F("hVtype","", 6,-1.,6.); hVtype->GetXaxis()->SetTitle("vtype"); TH1F *hMqq = new TH1F("hMqq","",100.,0.,3000.); hMqq->GetXaxis()->SetTitle("m_{qq} (GeV)"); TH1F *hEtaQQ = new TH1F("hEtaQQ","",80,0.,8.); hEtaQQ->GetXaxis()->SetTitle("|#Delta#eta_{qq}|"); TH1F *hPhiBB = new TH1F("hPhiBB","",32,0.,3.2); hPhiBB->GetXaxis()->SetTitle("|#Delta#phi_{bb}|"); TH1F* hMbb = new TH1F("hMbb","",250,0.,250.); hMbb->GetXaxis()->SetTitle("m_{bb} (GeV)"); TH1F *hbtag = new TH1F("hbtag","",110,0.,1.1); hbtag->GetXaxis()->SetTitle("CSV 1^{st} b-jet"); TH1F *hbtag2 = new TH1F("hbtag2","",110,0.,1.1); hbtag2->GetXaxis()->SetTitle("CSV 2^{nd} b-jet"); TH1F *hcosOqqbb = new TH1F("hcosOqqbb","",100,-1.,1.); hcosOqqbb->GetXaxis()->SetTitle("cos(#theta_{bb_qq})"); TH1F *hEtaQB1 = new TH1F("hEtaQB1","",160.,-8.,8.); hEtaQB1->GetXaxis()->SetTitle("#Delta#eta_{qb}^{forward}"); TH1F *hEtaQB2 = new TH1F("hEtaQB2","",160.,-8.,8.); hEtaQB2->GetXaxis()->SetTitle("#Delta#eta_{qb}^{backward}"); TH1F *hPhiQB1 = new TH1F("hPhiQB1","",32,0.,3.2); hPhiQB1->GetXaxis()->SetTitle("#Delta#phi_{qb}^{forward}"); TH1F *hPhiQB2 = new TH1F("hPhiQB2","",32,0.,3.2); hPhiQB2->GetXaxis()->SetTitle("#Delta#phi_{qb}^{backward}"); TH1F *hx1 = new TH1F("hx1","",100.,0.,1.); hx1->GetXaxis()->SetTitle("x_{1}"); TH1F *hx2 = new TH1F("hx2","",100.,0.,1.); hx2->GetXaxis()->SetTitle("x_{2}"); TH1F *hVB1_mass = new TH1F("hVB1_mass","",100,0.,1000.); hVB1_mass->GetXaxis()->SetTitle("M_{W'_{1}} (GeV)"); TH1F *hVB2_mass = new TH1F("hVB2_mass","",100.,0.,1000.); hVB2_mass->GetXaxis()->SetTitle("M_{W'_{2}} (GeV)"); TH1F* hEtot = new TH1F("hEtot","",150.,0.,6000.); hEtot->GetXaxis()->SetTitle("E^{tot} (GeV)"); TH1F* hPxtot= new TH1F("hPxtot","",100,-500.,500.); hPxtot->GetXaxis()->SetTitle("P_{x}^{tot} (GeV)"); TH1F* hPytot= new TH1F("hPytot","",100,-500.,500.); hPytot->GetXaxis()->SetTitle("P_{y}^{tot} (GeV)"); TH1F* hPztot= new TH1F("hPztot","",100,-5000.,5000); hPztot->GetXaxis()->SetTitle("P_{z}^{tot} (GeV)"); TH1F *hPtqqbb = new TH1F("hPtqqbb","",50.,0.,500.); hPtqqbb->GetXaxis()->SetTitle("p_{T} of qqbb system (GeV)"); TH1F *hPhiqqbb = new TH1F("hPhiqqbb","",32,-3.2,3.2); hPhiqqbb->GetXaxis()->SetTitle("-#phi of qqbb system"); TH1F *hEtaqqbb = new TH1F("hEtaqqbb","",160,-8,8); hEtaqqbb->GetXaxis()->SetTitle("#eta of qqbb system"); const int numArray= 40; TH1F* histArray[numArray] = {hJet1_pt,hJet2_pt,hJet3_pt,hJet4_pt, hJet1_eta,hJet2_eta,hJet3_eta,hJet4_eta, hJet1_phi,hJet2_phi,hJet3_phi,hJet4_phi, hMqq, hEtaQQ, hPhiBB,hMbb,hbtag,hbtag2,hcosOqqbb,hEtaQB1, hEtaQB2, hPhiQB1, hPhiQB2,hx1,hx2,hVB1_mass, hVB2_mass, hEtot, hPxtot, hPytot, hPztot, hJet5_pt,hPtqqbb, hPhiqqbb, hEtaqqbb, hJet1_pt_bin,hJet2_pt_bin,hJet3_pt_bin,hJet4_pt_bin, hMqq_bin }; for (int i=0;i<numArray;i++){ histArray[i]->Sumw2(); } int nentries = tree_initial->GetEntries() ; for (int entry=0; entry<nentries;++entry){ tree_initial->GetEntry(entry); if (JSON!=1) { continue; } if (!((Jet.pt[0]>92.)&&(Jet.pt[1]>76.)&&(Jet.pt[2]>64.)&&(Jet.pt[3]>30.))) {continue; } cut1++; Float_t btag_max = 0.4; int btag_max1_number = -1; int btag_max2_number = -1; for (int i=0;i<6;i++){ if ((Jet.btag[i]>btag_max)){ btag_max=Jet.btag[i]; btag_max1_number=i; } } btag_max = 0.4; for (int i=0;i<6;i++){ if ((Jet.btag[i]>btag_max)&&(i!=btag_max1_number)) { btag_max=Jet.btag[i]; btag_max2_number=i; } } if (!((btag_max1_number>=0)&&(btag_max2_number>=0))) {continue;} TLorentzVector Bjet1; Bjet1.SetPtEtaPhiM(Jet.pt[btag_max1_number],Jet.eta[btag_max1_number],Jet.phi[btag_max1_number],Jet.mass[btag_max1_number]); TLorentzVector Bjet2; Bjet2.SetPtEtaPhiM(Jet.pt[btag_max2_number],Jet.eta[btag_max2_number],Jet.phi[btag_max2_number],Jet.mass[btag_max2_number]); Float_t pt_max = 20.; int pt_max1_number = -1; int pt_max2_number = -1; for (int i=0;i<6;i++){ if ((Jet.pt[i]>pt_max)&&(i!=btag_max1_number)&&(i!=btag_max2_number)) { pt_max=Jet.pt[i]; pt_max1_number=i; } } pt_max = 20.; for (int i=0;i<6;i++){ if ((Jet.pt[i]>pt_max)&&(i!=btag_max1_number)&&(i!=btag_max2_number)&&(i!=pt_max1_number)) { pt_max=Jet.pt[i]; pt_max2_number=i; } } if (!((pt_max1_number>=0)&&(pt_max2_number>=0))) continue; TLorentzVector Qjet1; Qjet1.SetPtEtaPhiM(Jet.pt[pt_max1_number],Jet.eta[pt_max1_number],Jet.phi[pt_max1_number],Jet.mass[pt_max1_number]); TLorentzVector Qjet2; Qjet2.SetPtEtaPhiM(Jet.pt[pt_max2_number],Jet.eta[pt_max2_number],Jet.phi[pt_max2_number],Jet.mass[pt_max2_number]); TLorentzVector qq; qq = Qjet1+Qjet2; Float_t Mqq = qq.M(); Float_t bbDeltaPhi = TMath::Abs(Bjet1.DeltaPhi(Bjet2)); Float_t qqDeltaEta = TMath::Abs(Qjet1.Eta()-Qjet2.Eta()); if (!((Mqq>200)&&(qqDeltaEta>1.2)&&(bbDeltaPhi<2.4))) {continue;} cut2++; if (HLT_QuadPFJet_DoubleBTag_CSV_VBF_Mqq200!=1) {continue;} cut3++; presel++; TLorentzVector bb; bb = Bjet1+Bjet2; Float_t Mbb = bb.M(); TLorentzVector bbqq; bbqq = Bjet1 + Bjet2 + Qjet1 + Qjet2; Float_t cosObbqq =TMath::Cos( ( ( Bjet1.Vect() ).Cross(Bjet2.Vect()) ).Angle( ( Qjet1.Vect() ).Cross(Qjet2.Vect()) ) ); Float_t EtaBQ1; Float_t EtaBQ2; Float_t PhiBQ1; Float_t PhiBQ2; if (Qjet1.Eta() >= Qjet2.Eta()) { if (Bjet1.Eta() >= Bjet2.Eta()) { EtaBQ1 = Qjet1.Eta()-Bjet1.Eta(); PhiBQ1 = TMath::Abs(Bjet1.DeltaPhi(Qjet1)); } else { EtaBQ1 = Qjet1.Eta()-Bjet2.Eta(); PhiBQ1 = TMath::Abs(Bjet2.DeltaPhi(Qjet1)); } } else if (Bjet1.Eta() >= Bjet2.Eta()) { EtaBQ1 = Qjet2.Eta()-Bjet1.Eta(); PhiBQ1 = TMath::Abs(Bjet1.DeltaPhi(Qjet2)); } else { EtaBQ1 = Qjet2.Eta()-Bjet2.Eta(); PhiBQ1 = TMath::Abs(Bjet2.DeltaPhi(Qjet2)); } if (Qjet1.Eta() <= Qjet2.Eta()) { if (Bjet1.Eta() <= Bjet2.Eta()) { EtaBQ2 = Qjet1.Eta()-Bjet1.Eta(); PhiBQ2 = TMath::Abs(Bjet1.DeltaPhi(Qjet1)); } else { EtaBQ2 = Qjet1.Eta()-Bjet2.Eta(); PhiBQ2 = TMath::Abs(Bjet2.DeltaPhi(Qjet1)); } } else if (Bjet1.Eta() <= Bjet2.Eta()) { EtaBQ2 = Qjet2.Eta()-Bjet1.Eta(); PhiBQ2 = TMath::Abs(Bjet1.DeltaPhi(Qjet2)); } else { EtaBQ2 = Qjet2.Eta()-Bjet2.Eta(); PhiBQ2 = TMath::Abs(Bjet2.DeltaPhi(Qjet2)); } Float_t Etot = Bjet1.E()+Bjet2.E()+Qjet1.E()+Qjet2.E(); Float_t PzTot = Bjet1.Pz()+Bjet2.Pz()+Qjet1.Pz()+Qjet2.Pz(); Float_t PxTot = Bjet1.Px()+Bjet2.Px()+Qjet1.Px()+Qjet2.Px(); Float_t PyTot = Bjet1.Py()+Bjet2.Py()+Qjet1.Py()+Qjet2.Py(); Float_t x1 = 0.; Float_t x2 = 0.; x1 = (Etot + PzTot)/2./13000.; x2 = (Etot - PzTot)/2./13000.; TLorentzVector q1,q2,q1_after,q2_after, VB1, VB2; q1.SetPxPyPzE(0.,0.,13000./2.*x1,13000./2.*x1); q2.SetPxPyPzE(0.,0.,-13000./2.*x2,13000./2.*x2); q1_after.SetPxPyPzE(Qjet1.Px()/Qjet1.Beta(),Qjet1.Py()/Qjet1.Beta(),Qjet1.Pz()/Qjet1.Beta(),Qjet1.E()); q2_after.SetPxPyPzE(Qjet2.Px()/Qjet2.Beta(),Qjet2.Py()/Qjet2.Beta(),Qjet2.Pz()/Qjet2.Beta(),Qjet2.E()); if (q1_after.Eta()>=0.) { VB1 = -q1_after+q1; VB2 = -q2_after+q2; } else { VB1 = -q2_after+q1; VB2 = -q1_after+q2; } Float_t VB1_mass, VB2_mass; VB1_mass = TMath::Abs(VB1.M()); VB2_mass = TMath::Abs(VB2.M()); hJet1_pt->Fill(Jet.pt[0],genweight); hJet1_eta->Fill(Jet.eta[0],genweight); hJet1_phi->Fill(Jet.phi[0],genweight); hJet2_pt->Fill(Jet.pt[1],genweight); hJet2_eta->Fill(Jet.eta[1],genweight); hJet2_phi->Fill(Jet.phi[1],genweight); hJet3_pt->Fill(Jet.pt[2],genweight); hJet3_eta->Fill(Jet.eta[2],genweight); hJet3_phi->Fill(Jet.phi[2],genweight); hJet4_pt->Fill(Jet.pt[3],genweight); hJet4_eta->Fill(Jet.eta[3],genweight); hJet4_phi->Fill(Jet.phi[3],genweight); hJet5_pt->Fill(Jet.pt[4],genweight); hVtype->Fill(v_type,genweight); hMqq->Fill(Mqq,genweight); hEtaQQ->Fill(qqDeltaEta,genweight); hPhiBB->Fill(bbDeltaPhi,genweight); hMbb->Fill(Mbb,genweight); hbtag->Fill(Jet.btag[btag_max1_number],genweight); hbtag2->Fill(Jet.btag[btag_max2_number],genweight); hcosOqqbb->Fill(cosObbqq,genweight); hEtaQB1->Fill(EtaBQ1,genweight); hEtaQB2->Fill(EtaBQ2,genweight); hPhiQB1->Fill(PhiBQ1,genweight); hPhiQB2->Fill(PhiBQ2,genweight); hx1->Fill(x1,genweight); hx2->Fill(x2,genweight); hVB1_mass->Fill(VB1_mass,genweight); hVB2_mass->Fill(VB2_mass,genweight); hEtot->Fill(Etot,genweight); hPxtot->Fill(PxTot,genweight); hPytot->Fill(PyTot,genweight); hPztot->Fill(PzTot,genweight); hPtqqbb->Fill(bbqq.Pt(),genweight); hPhiqqbb->Fill((-1)*bbqq.Phi(),genweight); hEtaqqbb->Fill(bbqq.Eta(), genweight); hJet1_pt_bin->Fill(Jet.pt[0],genweight); hJet2_pt_bin->Fill(Jet.pt[1],genweight); hJet3_pt_bin->Fill(Jet.pt[2],genweight); hJet4_pt_bin->Fill(Jet.pt[3],genweight); hMqq_bin->Fill(Mqq,genweight); } TFile file("tree"+type[files]+".root","recreate"); for (int i=0;i<numArray;++i){ histArray[i]->SetLineWidth(2); histArray[i]->GetYaxis()->SetTitle("N_{events}"); histArray[i]->GetYaxis()->SetTitleFont(42); histArray[i]->GetYaxis()->SetTitleSize(0.060); histArray[i]->GetYaxis()->SetTitleOffset(0.8); histArray[i]->SetLineColor(kBlue); histArray[i]->Draw(); histArray[i]->Write(); } file.Write(); file.Close(); ofstream out("data_"+type[files]+".txt"); out<< "preselection only = "<< presel<<" , all evetns in the begining = "<<nentries<<", % = "<< (float)presel/nentries<<endl; out<<" after cut 1 events left = "<< cut1<<endl; out<<" after cut 2 events left = "<< cut2<<endl; out<<" after cut 3 events left = "<< cut3<<endl; out.close(); files++; } while (files<files_max); }