// // // double analysisClass::RecoHLTdeltaRmin_SingleMu24Trigger( unsigned int iReco ){ TLorentzVector HLTLep; TLorentzVector RecoLep; double deltaRmin=999999.9; RecoLep.SetPtEtaPhiM( muPtcorr(iReco), MuonEta->at(iReco), MuonPhi->at(iReco), 0); // for(unsigned int ifilter=0; ifilter<HLTFilterName->size(); ifilter++){ // // HLT_Mu24_eta2p1_v* if( HLTFilterName->at(ifilter) == "hltL3fL1sMu16Eta2p1L1f0L2f16QL3Filtered24Q" //V3,V4,V5 ){ // // ----- extract TrigObject 4-vector ----- std::vector<std::vector<float> > * TrigObjectPt_TrigArray; vector<float> trigObjPtArray; float trigObjPt_; std::vector<std::vector<float> > * TrigObjectEta_TrigArray; vector<float> trigObjEtaArray; float trigObjEta_; std::vector<std::vector<float> > * TrigObjectPhi_TrigArray; vector<float> trigObjPhiArray; float trigObjPhi_; TrigObjectPt_TrigArray = HLTFilterObjPt; trigObjPtArray = (*TrigObjectPt_TrigArray)[ifilter]; TrigObjectEta_TrigArray = HLTFilterObjEta; trigObjEtaArray = (*TrigObjectEta_TrigArray)[ifilter]; TrigObjectPhi_TrigArray = HLTFilterObjPhi; trigObjPhiArray = (*TrigObjectPhi_TrigArray)[ifilter]; // ----- ----- ----- ----- ----- ----- ----- for(unsigned int iobj=0; iobj<trigObjPtArray.size(); iobj++){//loop over all trigObjects of selected Filter trigObjPt_ = (trigObjPtArray)[iobj]; trigObjEta_= (trigObjEtaArray)[iobj]; trigObjPhi_= (trigObjPhiArray)[iobj]; HLTLep.SetPtEtaPhiM( trigObjPt_, trigObjEta_, trigObjPhi_, 0 ); if(RecoLep.DeltaR(HLTLep)<deltaRmin) deltaRmin = RecoLep.DeltaR(HLTLep); } } } // return deltaRmin; }
void ZgSelectData::printEvent(int index_e1, int index_e2, int index_pho, vector<Float_t> elePt_){ cout << "PassedZeeGamma: run " << run << " event " << event << " rho " << rho << endl ; cout << "electron :index,pt,eta,phi,En " << endl ; cout << index_e1 << " , " << elePt_[index_e1] << " , " << eleEta[index_e1] ; cout << " , " << elePhi[index_e1] << " , " << eleEn[index_e1] << endl ; cout << index_e2 << " , " << elePt_[index_e2] << " , " << eleEta[index_e2] ; cout << " , " << elePhi[index_e2] << " , " << eleEn[index_e2] << endl ; cout << "Electron Pass " << endl ; cout << "TrackIso " << eleIsoTrkDR03[index_e1] << " EcalIso " << eleIsoEcalDR03[index_e1] << " HcalSolidIso "; cout << eleIsoHcalSolidDR03[index_e1] << " passID = " << elePassID(index_e1,3,elePt_) << endl ; cout << "TrackIso " << eleIsoTrkDR03[index_e2] << " EcalIso " << eleIsoEcalDR03[index_e2] << " HcalSolidIso "; cout << eleIsoHcalSolidDR03[index_e2] << " passID = " << elePassID(index_e2,3,elePt_) << endl ; TLorentzVector ve1, ve2, vZ ; ve1.SetPtEtaPhiE(elePt[index_e1],eleEta[index_e1],elePhi[index_e1],eleEn[index_e1]); ve2.SetPtEtaPhiE(elePt[index_e2],eleEta[index_e2],elePhi[index_e2],eleEn[index_e2]); vZ = ve1 + ve2 ; cout << "ZMass = " << vZ.M() << endl ; cout << "Photon : index, pt, eta, phi, dr1, dr2 " << endl ; TLorentzVector vp ; vp.SetPtEtaPhiM(phoEt[index_pho],phoEta[index_pho],phoPhi[index_pho],0); cout << index_pho << " , " << vp.Pt() << " , " << vp.Eta() << " , " << vp.Phi() ; cout << " , " << vp.DeltaR(ve1) << " , " << vp.DeltaR(ve2) << endl ; cout << "=================================================================" << endl ; }
// // // bool analysisClass::isRecoMuMatchedTO( double genPt , double genEta , double genPhi , double dRcut ){ double deltaR=999; TLorentzVector RecoMu; TLorentzVector GenMu; GenMu.SetPtEtaPhiM( genPt, genEta, genPhi, 0 ); // for(unsigned int iMuR=0; iMuR<MuonPt->size(); iMuR++){ if( !muRCheck( iMuR ) ) continue; RecoMu.SetPtEtaPhiM( muPtcorr(iMuR) , MuonEta->at(iMuR) , MuonPhi->at(iMuR) , 0 ); if( RecoMu.DeltaR(GenMu)<deltaR ) deltaR=RecoMu.DeltaR(GenMu); } // if( deltaR<dRcut ) return true; return false; }
// // // bool analysisClass::isRecoTauMatchedTO( double genPt , double genEta , double genPhi , double dRcut ){ double deltaR=999; TLorentzVector RecoTau; TLorentzVector GenTau; GenTau.SetPtEtaPhiM( genPt, genEta, genPhi, 0 ); // for(unsigned int iTauR=0; iTauR<HPSTauPt->size(); iTauR++){ if( !tauRCheck( iTauR ) ) continue; RecoTau.SetPtEtaPhiM( tauPtcorr(iTauR) , HPSTauEta->at(iTauR) , HPSTauPhi->at(iTauR) , 0 ); if( fabs(RecoTau.DeltaR(GenTau))<deltaR ) deltaR=fabs(RecoTau.DeltaR(GenTau)); } // if( deltaR<dRcut ) return true; return false; }
bool isThisJetALepton(TLorentzVector jet, TLorentzVector l1, TLorentzVector l2){ double DRmax = 0.2; bool isLep = false; if (jet.DeltaR(l1) < DRmax) isLep = true; if (jet.DeltaR(l2) < DRmax) isLep = true; return isLep; }
//------------------------------------------------------------------------------ // GetAwayJets //------------------------------------------------------------------------------ void AnalysisFR::GetAwayJets() { AnalysisJets.clear(); int jetsize = std_vector_jet_pt->size(); for (int j=0; j<jetsize; j++) { Jet jet_; jet_.index = j; float pt = std_vector_jet_pt ->at(j); float eta = std_vector_jet_eta->at(j); float phi = std_vector_jet_phi->at(j); if (pt < 10.) continue; TLorentzVector tlv; tlv.SetPtEtaPhiM(pt, eta, phi, 0); jet_.v = tlv; float dR = tlv.DeltaR(Lepton1.v); if (dR > 1) AnalysisJets.push_back(jet_); } }
// // // double analysisClass::tauGenMatchDeltaR(unsigned int iTauR){ TLorentzVector tauMgen; TLorentzVector taureco; if(HPSTauMatchedGenParticlePt->at(iTauR)<=0) return 9; tauMgen.SetPtEtaPhiM( HPSTauMatchedGenParticlePt->at(iTauR), HPSTauMatchedGenParticleEta->at(iTauR), HPSTauMatchedGenParticlePhi->at(iTauR), 0 ); taureco.SetPtEtaPhiM( tauPtcorr(iTauR), HPSTauEta->at(iTauR), HPSTauPhi->at(iTauR), 0 ); return taureco.DeltaR(tauMgen); }
// // // double analysisClass::muGenMatchDeltaR(unsigned int iMuR){ TLorentzVector muMgen; TLorentzVector mureco; if(MuonMatchedGenParticlePt->at(iMuR)<=0) return 9; muMgen.SetPtEtaPhiM( MuonMatchedGenParticlePt->at(iMuR), MuonMatchedGenParticleEta->at(iMuR), MuonMatchedGenParticlePhi->at(iMuR), 0 ); mureco.SetPtEtaPhiM( muPtcorr(iMuR), MuonEta->at(iMuR), MuonPhi->at(iMuR), 0 ); return mureco.DeltaR(muMgen); }
// // // double analysisClass::RecoHLTdeltaRmin_SingleMuTrigger( unsigned int iReco ){ TLorentzVector HLTLep; TLorentzVector RecoLep; double deltaRmin=999999.9; RecoLep.SetPtEtaPhiM( muPtcorr(iReco), MuonEta->at(iReco), MuonPhi->at(iReco), 0); // // This is the trigger list for 2012 :: 190456-203002 // //| HLT_IsoMu24_eta2p1_v11 | 833 | 28.303(/pb) | 28.303(/pb) | "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoFiltered10" //| HLT_IsoMu24_eta2p1_v12 | 11046 | 669.888(/pb) | 669.888(/pb) | "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoFiltered10" //| HLT_IsoMu24_eta2p1_v13 | 51172 | 4.427(/fb) | 4.427(/fb) | "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoRhoFiltered0p15" //| HLT_IsoMu24_eta2p1_v14 | 22079 | 1.783(/fb) | 1.783(/fb) | "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoRhoFiltered0p15" //| HLT_IsoMu24_eta2p1_v15 | 54847 | 5.023(/fb) | 5.023(/fb) | "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoRhoFiltered0p15" // //| HLT_IsoMu20_eta2p1_v3 | 833 | 28.303(/pb) | 346.522(/nb) | <<< PRESCALED "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoFiltered10" //| HLT_IsoMu20_eta2p1_v4 | 11046 | 669.888(/pb) | 4.160(/pb) | <<< PRESCALED "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoFiltered10" //| HLT_IsoMu20_eta2p1_v5 | 51172 | 4.427(/fb) | 19.806(/pb) | <<< PRESCALED "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoRhoFiltered0p15" //| HLT_IsoMu20_eta2p1_v6 | 22079 | 1.783(/fb) | 7.169(/pb) | <<< PRESCALED "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoRhoFiltered0p15" //| HLT_IsoMu20_eta2p1_v7 | 54847 | 5.023(/fb) | 19.991(/pb) | <<< PRESCALED "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f20L3crIsoRhoFiltered0p15" // // for(unsigned int ifilter=0; ifilter<HLTFilterName->size(); ifilter++){ // // HLT_IsoMu24_eta2p1_v* if( HLTFilterName->at(ifilter) == "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoFiltered10" || //v11,v12 HLTFilterName->at(ifilter) == "hltL3crIsoL1sMu16Eta2p1L1f0L2f16QL3f24QL3crIsoRhoFiltered0p15" //v13, v14, v15 ){ // // ----- extract TrigObject 4-vector ----- std::vector<std::vector<float> > * TrigObjectPt_TrigArray; vector<float> trigObjPtArray; float trigObjPt_; std::vector<std::vector<float> > * TrigObjectEta_TrigArray; vector<float> trigObjEtaArray; float trigObjEta_; std::vector<std::vector<float> > * TrigObjectPhi_TrigArray; vector<float> trigObjPhiArray; float trigObjPhi_; TrigObjectPt_TrigArray = HLTFilterObjPt; trigObjPtArray = (*TrigObjectPt_TrigArray)[ifilter]; TrigObjectEta_TrigArray = HLTFilterObjEta; trigObjEtaArray = (*TrigObjectEta_TrigArray)[ifilter]; TrigObjectPhi_TrigArray = HLTFilterObjPhi; trigObjPhiArray = (*TrigObjectPhi_TrigArray)[ifilter]; // ----- ----- ----- ----- ----- ----- ----- for(unsigned int iobj=0; iobj<trigObjPtArray.size(); iobj++){//loop over all trigObjects of selected Filter trigObjPt_ = (trigObjPtArray)[iobj]; trigObjEta_= (trigObjEtaArray)[iobj]; trigObjPhi_= (trigObjPhiArray)[iobj]; HLTLep.SetPtEtaPhiM( trigObjPt_, trigObjEta_, trigObjPhi_, 0 ); if(RecoLep.DeltaR(HLTLep)<deltaRmin) deltaRmin = RecoLep.DeltaR(HLTLep); } } } // return deltaRmin; }
// // // bool analysisClass::DiscoverySelection( TString SignalChannel ){ // int TotalN=0; int TotalTau=0; int TotalMu=0; int TotalEl=0; int TotalJet=0; int TotalBJet=0; TotalTau = TauCounter(); TotalMu = MuCounter(); TotalEl = ElCounter(); TotalJet = JetCounter(); TotalBJet = BJetCounter(); TotalN = TotalTau + TotalMu + TotalEl + TotalJet; // double LeadMuTauDeltaR=0; TLorentzVector Mu; TLorentzVector Tau; Mu.SetPtEtaPhiM(0,0,0,0); Tau.SetPtEtaPhiM(0,0,0,0); for(unsigned int iTauR=0; iTauR<HPSTauPt->size(); iTauR++){ if( !tauRisoCheck(iTauR) )continue; if( tauPtcorr(iTauR)>Tau.Pt() ){ Tau.SetPtEtaPhiM(tauPtcorr(iTauR), HPSTauEta->at(iTauR), HPSTauPhi->at(iTauR), 0); } } for(unsigned int iMuR=0; iMuR<MuonPt->size(); iMuR++){ if( !muRisoCheck(iMuR) )continue; if( muPtcorr(iMuR)>Mu.Pt() ){ Mu.SetPtEtaPhiM(muPtcorr(iMuR), MuonEta->at(iMuR), MuonPhi->at(iMuR), 0); } } if( TotalMu>0 && TotalTau>0 ) LeadMuTauDeltaR=Mu.DeltaR(Tau); // // // ASSUME PRESELECTION IS ALREADY APPLIED if( SignalChannel == "MuMu" ){ if( TotalBJet<1 ) return false; if( TotalJet<2 ) return false; if( ST()<400 ) return false; if( LeadingMuPt()<20 ) return false; if( RecoSignalType()!=2020 && TotalMu<3 ) return false;//mu-mu SS selection if( isZToMuMu() ) return false;//required to exclude events in MuTrig Calculation } if( SignalChannel == "MuTau" ){ if( TotalBJet<1 ) return false; if( TotalJet<2 ) return false;//SS selection if( ST()<500 ) return false; if( MaxMuTauInvMass()<100 ) return false; if( LeadingTauPt()<50 ) return false; if( RecoSignalType()<2000 ) return false;//mu-tau+X OS selection if( isZToMuMu() ) return false;//required to exclude events in MuTrig Calculation } // return true; // }
// // // double analysisClass::RecoHLTdeltaRmin_DoubleMuTrigger( unsigned int iReco ){ TLorentzVector HLTLep; TLorentzVector RecoLep; double deltaRmin=999999.9; RecoLep.SetPtEtaPhiM( muPtcorr(iReco), MuonEta->at(iReco), MuonPhi->at(iReco), 0); // for(unsigned int ifilter=0; ifilter<HLTFilterName->size(); ifilter++){ // // HLT_Mu17_Mu8_v16 hltL3pfL1DoubleMu10MuOpenL1f0L2pf0L3PreFiltered8 hltL3fL1DoubleMu10MuOpenL1f0L2f10L3Filtered17 hltDiMuonMu17Mu8DzFiltered0p2 // HLT_Mu17_Mu8_v17 hltL3pfL1DoubleMu10MuOpenL1f0L2pf0L3PreFiltered8 hltL3fL1DoubleMu10MuOpenL1f0L2f10L3Filtered17 <<<< MC // HLT_Mu17_Mu8_v18 // HLT_Mu17_Mu8_v19 hltL3pfL1DoubleMu10MuOpenOR3p5L1f0L2pf0L3PreFiltered8 hltL3fL1DoubleMu10MuOpenOR3p5L1f0L2f10L3Filtered17 // HLT_Mu17_Mu8_v21 hltL3pfL1DoubleMu10MuOpenOR3p5L1f0L2pf0L3PreFiltered8 hltL3fL1DoubleMu10MuOpenOR3p5L1f0L2f10L3Filtered17 hltDiMuonGlb17Glb8DzFiltered0p2 // HLT_Mu17_Mu8_v22 hltL3pfL1DoubleMu10MuOpenOR3p5L1f0L2pf0L3PreFiltered8 hltL3fL1DoubleMu10MuOpenOR3p5L1f0L2f10L3Filtered17 hltDiMuonGlb17Glb8DzFiltered0p2 // if( HLTFilterName->at(ifilter) == "hltL3pfL1DoubleMu10MuOpenL1f0L2pf0L3PreFiltered8" || HLTFilterName->at(ifilter) == "hltL3fL1DoubleMu10MuOpenL1f0L2f10L3Filtered17" || HLTFilterName->at(ifilter) == "hltL3pfL1DoubleMu10MuOpenOR3p5L1f0L2pf0L3PreFiltered8" || HLTFilterName->at(ifilter) == "hltL3fL1DoubleMu10MuOpenOR3p5L1f0L2f10L3Filtered17" ){ // // ----- extract TrigObject 4-vector ----- std::vector<std::vector<float> > * TrigObjectPt_TrigArray; vector<float> trigObjPtArray; float trigObjPt_; std::vector<std::vector<float> > * TrigObjectEta_TrigArray; vector<float> trigObjEtaArray; float trigObjEta_; std::vector<std::vector<float> > * TrigObjectPhi_TrigArray; vector<float> trigObjPhiArray; float trigObjPhi_; TrigObjectPt_TrigArray = HLTFilterObjPt; trigObjPtArray = (*TrigObjectPt_TrigArray)[ifilter]; TrigObjectEta_TrigArray = HLTFilterObjEta; trigObjEtaArray = (*TrigObjectEta_TrigArray)[ifilter]; TrigObjectPhi_TrigArray = HLTFilterObjPhi; trigObjPhiArray = (*TrigObjectPhi_TrigArray)[ifilter]; // ----- ----- ----- ----- ----- ----- ----- for(unsigned int iobj=0; iobj<trigObjPtArray.size(); iobj++){//loop over all trigObjects of selected Filter trigObjPt_ = (trigObjPtArray)[iobj]; trigObjEta_= (trigObjEtaArray)[iobj]; trigObjPhi_= (trigObjPhiArray)[iobj]; //debug //std::cout<<HLTFilterName->at(ifilter)<<" "<< trigObjPt_<<" "<<trigObjEta_<<" "<<trigObjPhi_<<std::endl; HLTLep.SetPtEtaPhiM( trigObjPt_, trigObjEta_, trigObjPhi_, 0 ); if(RecoLep.DeltaR(HLTLep)<deltaRmin) deltaRmin = RecoLep.DeltaR(HLTLep); } //debug //std::cout<<std::endl; } } // return deltaRmin; }
TLorentzVector selectPhoton( const ZGConfig& cfg, const ZGTree& myTree, int index, const TLorentzVector& lept0, const TLorentzVector& lept1, EnergyScaleCorrection_class egcor ) { TLorentzVector photon; if( myTree.ngamma<=index ) { photon.SetPtEtaPhiM( 0.01, 0., 0., 0. ); return photon; } photon.SetPtEtaPhiM( myTree.gamma_pt[index], myTree.gamma_eta[index], myTree.gamma_phi[index], myTree.gamma_mass[index] ); // photon energy corrections/smearing if( !myTree.isData ) { if( cfg.smearing() ) { smearEmEnergy( egcor, photon, myTree, myTree.gamma_r9[0] ); } } else { if( cfg.smearing() ) { applyEmEnergyScale( egcor, photon, myTree, myTree.gamma_r9[0] ); } } bool goodPhoton = true; if( photon.Pt()<40. ) goodPhoton=false; if( fabs(photon.Eta())>1.4442 && fabs(photon.Eta())<1.566 ) goodPhoton=false; if( fabs(photon.Eta())>2.5 ) goodPhoton=false; if( myTree.gamma_idCutBased[index]==0 ) goodPhoton=false; if( myTree.gamma_chHadIso[index]>2.5 ) goodPhoton=false; if( fabs(myTree.gamma_eta[index])<1.44 ) { if( myTree.gamma_sigmaIetaIeta[index]>0.0102 ) goodPhoton=false; } else { if( myTree.gamma_sigmaIetaIeta[index]>0.0274 ) goodPhoton=false; } float deltaR_thresh = 0.4; if( photon.DeltaR(lept0)<deltaR_thresh || photon.DeltaR(lept1)<deltaR_thresh ) goodPhoton=false; if( !goodPhoton ) photon.SetPtEtaPhiM( 0.01, 0., 0., 0. ); return photon; }
float DeltaRlj(){ TLorentzVector lep; lep.SetPtEtaPhiM(myEvent.lep1_pt,myEvent.lep1_eta,myEvent.lep1_phi,myEvent.lep1_mass); float minDR = 9999; for(unsigned int i=0;i<myEvent.jet_pt.size();i++){ TLorentzVector p4; p4.SetPtEtaPhiM(myEvent.jet_pt[i],myEvent.jet_eta[i],myEvent.jet_phi[i],myEvent.jet_mass[i]); float dr = lep.DeltaR(p4); if(dr<minDR) minDR = dr; } return minDR; }
void SingleTopTree::FillJets(){ Jets.clear(); bJets.clear(); TLorentzVector muon; int tightMuIndex; bool mu = TightIso06Muons.size() > 0; if( mu ) tightMuIndex = TightIso06Muons[0] ; if(!mu){ mu = Tight12IsoMuons.size() > 0 ; if( mu ) tightMuIndex = Tight12IsoMuons[0] ; } muon.SetPtEtaPhiE( muons_Pt[tightMuIndex] , muons_Eta[tightMuIndex] , muons_Phi[tightMuIndex] , muons_E[tightMuIndex] ); for( int jid = 0 ; jid < jetsAK4_size ; jid++ ){ //if( Event_EventNumber == 672782113 ) cout << (jetsAK4_CorrPt[jid] > 40) << " " << (fabs( jetsAK4_Eta[jid] ) < 4.7) << " " << jetsAK4_PassesID[jid]; if( jetsAK4_CorrPt[jid] > 40 && fabs( jetsAK4_Eta[jid] ) < 4.7 && jetsAK4_PassesID[jid] ){ double DR = 1.0 ; if( mu ){ TLorentzVector jet; jet.SetPtEtaPhiE( jetsAK4_CorrPt[jid] , jetsAK4_Eta[jid] , jetsAK4_Phi[jid] , jetsAK4_CorrE[jid] ); DR = muon.DeltaR( jet ); } // if( Event_EventNumber == 672782113 ) // cout << DR << endl; if ( DR > 0.3 ){ Jets.push_back( jid ); if( jetsAK4_IsCSVT[jid] && fabs( jetsAK4_Eta[jid] ) <= 2.4 ){ bJets.push_back(jid); } } } //if( Event_EventNumber == 672782113 ) //cout << endl; } }
void xAna_hh_massResolution(std::string inputFile, bool matchb=false, bool debug=false, bool cut=false){ TString outputFile; outputFile=gSystem->GetFromPipe(Form("file=%s; test=${file##*/}; echo \"massHisto_${test}\"",inputFile.data())); cout << "output file name = " << outputFile.Data() << endl; //get TTree from file ... TreeReader data(inputFile.data()); Long64_t nTotal=0; Long64_t nPass[20]={0}; const int nHistos=3; TH1F* h_massDiff = new TH1F("h_massDiff","",100,-0.5,0.5); //TH1F* h_mass = new TH1F("h_mass","",100,0,200); TH1F* h_mass = new TH1F("h_mass","",100,62.5,187.5); TH1F* h_SD[nHistos]; TH1F* h_SDCorr[nHistos]; TH1F* h_SDCorrThea[nHistos]; TH1F* h_AK8SD[nHistos]; TH1F* h_AK8SDCorrThea[nHistos]; TH1F* h_PR[nHistos]; TH1F* h_PRCorr[nHistos]; TH1F* h_diff_SD[nHistos]; TH1F* h_diff_SDCorr[nHistos]; TH1F* h_diff_SDCorrThea[nHistos]; TH1F* h_diff_PR[nHistos]; TH1F* h_diff_PRCorr[nHistos]; TH1F* h_diff_AK8SD[nHistos]; TH1F* h_diff_AK8SDCorrThea[nHistos]; std::string prefix[]={"leading","subleading","both"}; for(int i=0; i<nHistos; i++) { h_SD[i] = (TH1F*)h_mass->Clone(Form("h_SD_%s",prefix[i].data())); h_SD[i]->SetXTitle("Raw Puppi+Softdrop mass [GeV]"); h_AK8SD[i] = (TH1F*)h_mass->Clone(Form("h_AK8SD_%s",prefix[i].data())); h_AK8SD[i]->SetXTitle("AK8 Raw Puppi+Softdrop mass [GeV]"); h_SDCorr[i] = (TH1F*)h_mass->Clone(Form("h_SDCorr_%s",prefix[i].data())); h_SDCorr[i]->SetXTitle("L2L3-corrected Puppi+Softdrop mass [GeV]"); h_SDCorrThea[i] = (TH1F*)h_mass->Clone(Form("h_SDCorrThea_%s",prefix[i].data())); h_SDCorrThea[i]->SetXTitle("Thea-corrected Puppi+Softdrop mass [GeV]"); h_AK8SDCorrThea[i] = (TH1F*)h_mass->Clone(Form("h_AK8SDCorrThea_%s",prefix[i].data())); h_AK8SDCorrThea[i]->SetXTitle("AK8 Thea-corrected Puppi+Softdrop mass [GeV]"); h_PR[i] = (TH1F*)h_mass->Clone(Form("h_PR_%s",prefix[i].data())); h_PR[i]->SetXTitle("Raw CHS+Pruned mass [GeV]"); h_PRCorr[i] = (TH1F*)h_mass->Clone(Form("h_PRCorr_%s",prefix[i].data())); h_PRCorr[i]->SetXTitle("L2L3-corrected CHS+Pruned mass [GeV]"); // study the difference with respect to 125 GeV h_diff_SD[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_SD_%s",prefix[i].data())); h_diff_SD[i]->SetXTitle("Raw Puppi+Softdrop (m-125)/125"); h_diff_AK8SD[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_AK8SD_%s",prefix[i].data())); h_diff_AK8SD[i]->SetXTitle("AK8 Raw Puppi+Softdrop (m-125)/125"); h_diff_SDCorr[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_SDCorr_%s",prefix[i].data())); h_diff_SDCorr[i]->SetXTitle("L2L3-corrected Puppi+Softdrop (m-125)/125"); h_diff_SDCorrThea[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_SDCorrThea_%s",prefix[i].data())); h_diff_SDCorrThea[i]->SetXTitle("Thea-corrected Puppi+Softdrop (m-125)/125"); h_diff_AK8SDCorrThea[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_AK8SDCorrThea_%s",prefix[i].data())); h_diff_AK8SDCorrThea[i]->SetXTitle("AK8 Thea-corrected Puppi+Softdrop (m-125)/125"); h_diff_PR[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_PR_%s",prefix[i].data())); h_diff_PR[i]->SetXTitle("Raw CHS+Pruned (m-125)/125"); h_diff_PRCorr[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_PRCorr_%s",prefix[i].data())); h_diff_PRCorr[i]->SetXTitle("L2L3-corrected CHS+Pruned (m-125)/125"); } for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){ if (jEntry % 1000 == 0) fprintf(stderr, "Processing event %lli of %lli\n", jEntry + 1, data.GetEntriesFast()); if(debug && jEntry>10)break; data.GetEntry(jEntry); nTotal++; //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_PFHT900_v")!= std::string::npos && results==1) ) { passTrigger=true; break; } } if(!passTrigger && cut)continue; nPass[4]++; 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 genHIndex[2]={-1,-1}; int genbIndex[2][2]={{-1,-1}, {-1,-1}}; for(int ig=0; ig < nGenPar; ig++){ if(genParId[ig]!=25)continue; if(genHIndex[0]<0) { genHIndex[0]=ig; genbIndex[0][0]=genDa1[ig]; genbIndex[0][1]=genDa2[ig]; } else if(genHIndex[1]<0) { genHIndex[1]=ig; genbIndex[1][0]=genDa1[ig]; genbIndex[1][1]=genDa2[ig]; } } if(genHIndex[0]<0 || genHIndex[1]<0)continue; if(genbIndex[0][0]<0 || genbIndex[0][1]<0)continue; if(genbIndex[1][0]<0 || genbIndex[1][1]<0)continue; nPass[0]++; if(genHIndex[0]==genHIndex[1])continue; nPass[1]++; TLorentzVector genH_l4[2]; TLorentzVector genb_l4[2][2]; TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4"); for(int ih=0; ih<2; ih++) { genH_l4[ih] = *((TLorentzVector*)genParP4->At(genHIndex[ih])); for(int ib=0; ib<2; ib++) { genb_l4[ih][ib] = *((TLorentzVector*)genParP4->At(genbIndex[ih][ib])); } } if(debug){ cout << genHIndex[0] << "\t" << genHIndex[1] << endl; genH_l4[0].Print(); genH_l4[1].Print(); cout << genbIndex[0][0] << "\t" << genbIndex[0][1] << "\t" << genbIndex[1][0] << "\t" << genbIndex[1][1] << endl; genH_l4[0].Print(); genH_l4[1].Print(); genb_l4[0][0].Print(); genb_l4[0][1].Print(); genb_l4[1][0].Print(); genb_l4[1][1].Print(); } int nFATJet = data.GetInt("FATnJet"); const int nJets=nFATJet; TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4"); TClonesArray* puppijetP4 = (TClonesArray*) data.GetPtrTObject("FATjetPuppiP4"); TClonesArray* AK8PuppijetP4 = (TClonesArray*) data.GetPtrTObject("AK8PuppijetP4"); // check matching first bool findAMatch=false; const float dRMax=0.4; const float dRbMax=0.8; int matchedHJetIndex[2]={-1,-1}; for(int ij=0; ij<nJets; ij++) { TLorentzVector* thisJet = (TLorentzVector*)fatjetP4->At(ij); for(int jj=0; jj<nJets; jj++) { if(ij==jj)continue; TLorentzVector* thatJet = (TLorentzVector*)fatjetP4->At(jj); if(thisJet->DeltaR(genH_l4[0])<dRMax && (!matchb || (matchb && thisJet->DeltaR(genb_l4[0][0])<dRbMax && thisJet->DeltaR(genb_l4[0][1])<dRbMax)) && thatJet->DeltaR(genH_l4[1])<dRMax && (!matchb || (matchb && thatJet->DeltaR(genb_l4[1][0])<dRbMax && thatJet->DeltaR(genb_l4[1][1])<dRbMax))) { if(debug) { cout << "dRhb00= " << thisJet->DeltaR(genb_l4[0][0]) << endl; cout << "dRhb01= " << thisJet->DeltaR(genb_l4[0][1]) << endl; cout << "dRhb10= " << thatJet->DeltaR(genb_l4[1][0]) << endl; cout << "dRhb11= " << thatJet->DeltaR(genb_l4[1][1]) << endl; } if(ij<jj){ matchedHJetIndex[0]=ij; matchedHJetIndex[1]=jj; } else { matchedHJetIndex[0]=jj; matchedHJetIndex[1]=ij; } findAMatch=true; break; } if(findAMatch)break; } if(findAMatch)break; } if(!findAMatch)continue; if(debug) cout << matchedHJetIndex[0] << "\t" << matchedHJetIndex[1] << endl; nPass[2]++; bool findAK8Match=false; //const float dRMax=0.4; //const float dRbMax=0.8; int matchedHAK8JetIndex[2]={-1,-1}; int AK8nJet=data.GetInt("AK8PuppinJet"); for(int ij=0; ij<AK8nJet; ij++) { TLorentzVector* thisJet = (TLorentzVector*)AK8PuppijetP4->At(ij); for(int jj=0; jj<AK8nJet; jj++) { if(ij==jj)continue; TLorentzVector* thatJet = (TLorentzVector*)AK8PuppijetP4->At(jj); if(thisJet->DeltaR(genH_l4[0])<dRMax && (!matchb || (matchb && thisJet->DeltaR(genb_l4[0][0])<dRbMax && thisJet->DeltaR(genb_l4[0][1])<dRbMax)) && thatJet->DeltaR(genH_l4[1])<dRMax && (!matchb || (matchb && thatJet->DeltaR(genb_l4[1][0])<dRbMax && thatJet->DeltaR(genb_l4[1][1])<dRbMax))) { if(debug) { cout << "dRhb00= " << thisJet->DeltaR(genb_l4[0][0]) << endl; cout << "dRhb01= " << thisJet->DeltaR(genb_l4[0][1]) << endl; cout << "dRhb10= " << thatJet->DeltaR(genb_l4[1][0]) << endl; cout << "dRhb11= " << thatJet->DeltaR(genb_l4[1][1]) << endl; } if(ij<jj){ matchedHAK8JetIndex[0]=ij; matchedHAK8JetIndex[1]=jj; } else { matchedHAK8JetIndex[0]=jj; matchedHAK8JetIndex[1]=ij; } findAK8Match=true; break; } if(findAK8Match)break; } if(findAK8Match)break; } if(!findAK8Match)continue; //0. has a good vertex Int_t nVtx = data.GetInt("nVtx"); if(nVtx<1 && cut)continue; nPass[3]++; Float_t* fatjetTau1 = data.GetPtrFloat("FATjetTau1"); Float_t* fatjetTau2 = data.GetPtrFloat("FATjetTau2"); Float_t* fatjetCISVV2 = data.GetPtrFloat("FATjetCISVV2"); Float_t* fatjetPRmass = data.GetPtrFloat("FATjetPRmass"); Float_t* fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr"); Float_t* fatjetSDmass = data.GetPtrFloat("FATjetPuppiSDmass"); Float_t* fatjetSDmassL2L3Corr = data.GetPtrFloat("FATjetPuppiSDmassL2L3Corr"); Float_t* AK8PuppijetSDmass = data.GetPtrFloat("AK8PuppijetSDmass"); vector<bool> &passFatJetLooseID = *((vector<bool>*) data.GetPtr("FATjetPassIDLoose")); TLorentzVector recoH_l4[2]; int nGoodJets=0; for(int i=0; i<2; i++) { int ij = matchedHJetIndex[i]; TLorentzVector* thisJet = (TLorentzVector*)fatjetP4->At(ij); recoH_l4[i]= (*thisJet); if(thisJet->Pt()<200)continue; if(fabs(thisJet->Eta())>2.4)continue; nGoodJets++; } if(nGoodJets<2)continue; nPass[5]++; if(debug) { recoH_l4[0].Print(); recoH_l4[1].Print(); } float dEta=fabs(recoH_l4[0].Eta()-recoH_l4[1].Eta()); if(dEta>1.3 && cut)continue; nPass[6]++; float M=(recoH_l4[0] + recoH_l4[1]).M(); if(M<800 && cut)continue; nPass[7]++; int nHP=0; int nLP=0; for(int i=0; i<2; i++) { int ij = matchedHJetIndex[i]; float tau21_i = fatjetTau2[ij]/fatjetTau1[ij]; bool isHP= (tau21_i < 0.6); if(isHP)nHP++; } if(nHP<2 && cut)continue; nPass[8]++; long eventId=data.GetLong64("eventId"); if(AK8nJet<2)continue; // now plot mass for(int i=0; i<2;i++) { //cout<< eventId<<endl; int jet=matchedHJetIndex[i]; int AK8jet=matchedHAK8JetIndex[i]; TLorentzVector* thisJet = (TLorentzVector*)puppijetP4->At(jet); float thea_corr = getPUPPIweight(thisJet->Pt(),thisJet->Eta()); float thea_mass = fatjetSDmass[jet]*thea_corr; //if(jet>AK8nJet-1)break; if(thisJet->Pt()>99998)break; //cout<< eventId<<endl; TLorentzVector* thisAK8Jet = (TLorentzVector*)AK8PuppijetP4->At(AK8jet); thea_corr = getPUPPIweight(thisAK8Jet->Pt(),thisAK8Jet->Eta()); if(debug) cout << thisJet->Pt() << "\t" << thisJet->Eta() << "\t" << thea_corr << endl; h_SD[i]->Fill(fatjetSDmass[jet]); h_SDCorr[i]->Fill(fatjetSDmassL2L3Corr[jet]); h_SDCorrThea[i]->Fill(thea_mass); h_PR[i]->Fill(fatjetPRmass[jet]); h_PRCorr[i]->Fill(fatjetPRmassL2L3Corr[jet]); h_AK8SD[i]->Fill(AK8PuppijetSDmass[AK8jet]); h_AK8SDCorrThea[i]->Fill(AK8PuppijetSDmass[AK8jet]*thea_corr); h_SD[2]->Fill(fatjetSDmass[jet]); h_SDCorr[2]->Fill(fatjetSDmassL2L3Corr[jet]); h_SDCorrThea[2]->Fill(thea_mass); h_PR[2]->Fill(fatjetPRmass[jet]); h_PRCorr[2]->Fill(fatjetPRmassL2L3Corr[jet]); h_AK8SD[2]->Fill(AK8PuppijetSDmass[AK8jet]); h_AK8SDCorrThea[2]->Fill(AK8PuppijetSDmass[AK8jet]*thea_corr); h_diff_SD[i]->Fill((fatjetSDmass[jet]-125)/125); h_diff_SDCorr[i]->Fill((fatjetSDmassL2L3Corr[jet]-125)/125); h_diff_SDCorrThea[i]->Fill((thea_mass-125)/125); h_diff_PR[i]->Fill((fatjetPRmass[jet]-125)/125); h_diff_PRCorr[i]->Fill((fatjetPRmassL2L3Corr[jet]-125)/125); h_diff_AK8SD[i]->Fill((AK8PuppijetSDmass[AK8jet]-125)/125); h_diff_AK8SDCorrThea[i]->Fill((AK8PuppijetSDmass[AK8jet]*thea_corr-125)/125); h_diff_SD[2]->Fill((fatjetSDmass[jet]-125)/125); h_diff_SDCorr[2]->Fill((fatjetSDmassL2L3Corr[jet]-125)/125); h_diff_SDCorrThea[2]->Fill((thea_mass-125)/125); h_diff_PR[2]->Fill((fatjetPRmass[jet]-125)/125); h_diff_PRCorr[2]->Fill((fatjetPRmassL2L3Corr[jet]-125)/125); h_diff_AK8SD[2]->Fill((AK8PuppijetSDmass[AK8jet]-125)/125); h_diff_AK8SDCorrThea[2]->Fill((AK8PuppijetSDmass[AK8jet]*thea_corr-125)/125); } } // end of loop over entries 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; TFile* outFile = new TFile(outputFile.Data(),"recreate"); for(int i=0; i<nHistos; i++) { h_diff_SD[i]->Write(); h_diff_SDCorr[i]->Write(); h_diff_SDCorrThea[i]->Write(); h_diff_PR[i]->Write(); h_diff_PRCorr[i]->Write(); h_SD[i]->Write(); h_SDCorr[i]->Write(); h_SDCorrThea[i]->Write(); h_PR[i]->Write(); h_PRCorr[i]->Write(); h_AK8SD[i]->Write(); h_AK8SDCorrThea[i]->Write(); h_diff_AK8SD[i]->Write(); h_diff_AK8SDCorrThea[i]->Write(); } outFile->Close(); }
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); 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); //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(); // 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<10)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; leading_ele_index.push_back(leadingIndex); subleading_ele_index.push_back(subleadingIndex); LeptonPairPt.push_back(ptll); LeptonPairM.push_back(mll); 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<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] ); } 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] ); } //////// 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(); //// // 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(); 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 xAna_ele_subleading_ele_study(TString inputFile, TCanvas *c1 , TCanvas *c2 , TCanvas *c3 ,TCanvas *c4 ,TCanvas *c5 , int mass_point ,double eff,double eff_err, TString dir_name, int dir_flag ){ // 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); TH1D* h_ele_pT = new TH1D("h_ele_pT", title2 ,300 , 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); //get TTree from file ... 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"); 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* eleMiniIso = data.GetPtrFloat("eleMiniIso"); Int_t* eleCharge = data.GetPtrInt("eleCharge"); //5. select good electrons std::vector<int> LeadingElectrons; for(int ie=0; ie< nEle; ie++)// save the electrons satisfied the leading electron requirement { 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; double ele_pt_threshold = 115; if(thisEle->Pt() < ele_pt_threshold )continue; if (dir_flag == 1) {if(!passHEEPID[ie])continue;} else if (dir_flag == 2) {if(!passLoose[ie])continue;} if(eleMiniIso[ie]>0.1)continue; LeadingElectrons.push_back(ie); } std::vector<int> SubLeadingElectrons; for(int ie=0; ie< nEle; ie++)// save the electrons satisfied the sub-leading electron requirement { 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; // double ele_pt_threshold = 115; double ele_pt_threshold = 0; if(thisEle->Pt() < ele_pt_threshold )continue; if (dir_flag == 1) {if(!passHEEPID[ie])continue;} else if (dir_flag == 2) {if(!passLoose[ie])continue;} if(eleMiniIso[ie]>0.1)continue; SubLeadingElectrons.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; for(unsigned int i=0; i< LeadingElectrons.size(); i++) { int ie = LeadingElectrons[i]; TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie); for(unsigned int j=0; j< SubLeadingElectrons.size(); j++) { int je= SubLeadingElectrons[j]; if(ie == je)continue; // avoid to use the same electron twice to be the pair if(eleCharge[ie]*eleCharge[je]>0)continue; TLorentzVector* thatEle = (TLorentzVector*)eleP4->At(je); Float_t mll = (*thisEle+*thatEle).M(); Float_t ptll = (*thisEle+*thatEle).Pt(); if(mll<70 || mll>110)continue; double ll_pt_threshold = 200; if(ptll<ll_pt_threshold )continue; LeptonPairPt.push_back(ptll); LeptonPairM.push_back(mll); 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"); 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; bool hasOverLap=false; for(unsigned int ie=0; ie < LeadingElectrons.size(); ie++) { TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(LeadingElectrons[ie]); if(thisEle->DeltaR(*thisJet)<0.8)hasOverLap=true; if(hasOverLap)break; } for(unsigned int ie=0; ie < SubLeadingElectrons.size(); ie++) { TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(SubLeadingElectrons[ie]); if(thisEle->DeltaR(*thisJet)<0.8)hasOverLap=true; if(hasOverLap)break; } 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] ); } findAJet=true; } if(!findAJet) continue; nPass[5]++; Float_t MGrav = (l4_leadingJet + l4_Z).M(); if(MGrav<400)continue; nPass[6]++; // if event can go here, then fill the histograms to plot the distributions. Yu-Hsiang add 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] ); } //////// 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(); //// // Yu-Hsiang add that save TH1D in the ROOT file // TString ROOT_name = Form("test_ROOT_name_M-%d.root",mass_point); // TString ROOT_name = Form("plot_TurnOff3Cuts/Zprime_shape_M-%d.root",mass_point); // TString ROOT_name = Form("plot_Cut_SD40to140_ElePt85_llPt200/Zprime_shape_M-%d.root",mass_point); // TString ROOT_name = Form("plot_Cut_SD50to140_ElePt85_llPt200/Zprime_shape_M-%d.root",mass_point); // TString ROOT_name = Form("plot_Cut_SD60to140_ElePt100_llPt200/Zprime_shape_M-%d.root",mass_point); // TString ROOT_name = Form("plot_Cut_SD60to140_ElePt115_llPt200/Zprime_shape_M-%d.root",mass_point); // TString ROOT_name = Form("plot_Cut_SD60to140_ElePt85_llPt200/Zprime_shape_M-%d.root",mass_point); TString ROOT_name = Form("Zprime_shape_M-%d.root",mass_point); ROOT_name = dir_name + ROOT_name; 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(); 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 HHbbbbMikeBase(int wMs,int wM, string st,string st2,string option=""){ //1=signal ,0=QCD ,2=data----------------------------------------------------------- int nameRoot=1; if(st2.find("QCD")!= std::string::npos)nameRoot=0; if(st2.find("data")!= std::string::npos)nameRoot=2; //---------------------Thea correction TFile *f3; f3=TFile::Open("puppiCorr.root"); TF1 * puppisd_corrGEN,* puppisd_corrRECO_cen,* puppisd_corrRECO_for; puppisd_corrGEN=(TF1 *) f3->FindObjectAny("puppiJECcorr_gen"); puppisd_corrRECO_cen=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_0eta1v3"); puppisd_corrRECO_for=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_1v3eta2v5"); TF1* tf1[3]; tf1[0]=puppisd_corrGEN; tf1[1]=puppisd_corrRECO_cen; tf1[2]=puppisd_corrRECO_for; //option----------------------------------------------------------- int JESOption=0; if(option.find("JESUp")!= std::string::npos)JESOption=1; if(option.find("JESDown")!= std::string::npos)JESOption=2; if(option.find("BtagUp")!= std::string::npos)JESOption=3; if(option.find("BtagDown")!= std::string::npos)JESOption=4; if(option.find("tau21Up")!= std::string::npos)JESOption=5; if(option.find("tau21Down")!= std::string::npos)JESOption=6; cout<<"JESOption = "<<JESOption<<endl; bool printHighPtSubjet=0; bool isFast=1; //tuple tree and cutflow variables------------------------------------------------------------------------------------ TFile *f; TTree *tree; int nPass[20]={0},total=0,dataPassingcsc=0; double nPassB[6]={0}; double fixScaleNum[2]={0}; //using for Btag Eff ----------------------------------------------------------------------------- string btagsystematicsType="central"; if(JESOption==3)btagsystematicsType="up"; else if(JESOption==4)btagsystematicsType="down"; BTagCalibration calib("CSVv2L", "subjet_CSVv2_ichep.csv"); BTagCalibrationReader LF(BTagEntry::OP_LOOSE,"central", {"up", "down"}); BTagCalibrationReader HFC(BTagEntry::OP_LOOSE, "central", {"up", "down"}); // other sys types BTagCalibrationReader HF(BTagEntry::OP_LOOSE,"central",{"up", "down"}); // other sys types LF.load(calib, BTagEntry::FLAV_UDSG, // btag flavour "incl"); // measurement type HFC.load(calib, BTagEntry::FLAV_C, // btag flavour "lt"); // measurement type HF.load(calib, BTagEntry::FLAV_B, // btag flavour "lt"); // measurement type TFile *f1; if(nameRoot==2)f1=TFile::Open("btagEffSource/data.root"); else if (nameRoot!=2 && (JESOption==0||JESOption==3||JESOption==4||JESOption==5||JESOption==6))f1=TFile::Open(Form("btagEffSource/%s.root",st2.data())); else if (nameRoot!=2 && JESOption==1)f1=TFile::Open(Form("btagEffSource/%s_JESUp.root",st2.data())); else if (nameRoot!=2 && JESOption==2)f1=TFile::Open(Form("btagEffSource/%s_JESDown.root",st2.data())); TH1D* th1[6]; string btaggingEff[6]={"effD_b","effN_b","effD_c","effN_c","effD_l","effN_l"}; for(int i=0;i<6;i++){ th1[i]=(TH1D*)f1->FindObjectAny(Form("%s_1d",btaggingEff[i].data())); if(i==1||i==3||i==5)th1[i]->Divide(th1[i-1]); } //check for zero btagging SF---------------------------------------------------------------------------------------- TH2D* th3[6]; th3[0]=new TH2D("zeroSF_b","zeroSF_b",200,0,2000,60,-3,3); th3[1]=new TH2D("zeroSF_c","zeroSF_c",200,0,2000,60,-3,3); th3[2]=new TH2D("zeroSF_l","zeroSF_l",200,0,2000,60,-3,3); th3[3]=new TH2D("SF_vs_Pt_b","SF_vs_Pt_b",120,0,1200,40,0.8,1.2); th3[4]=new TH2D("SF_vs_Pt_c","SF_vs_Pt_c",120,0,1200,40,0.8,1.2); th3[5]=new TH2D("SF_vs_Pt_l","SF_vs_Pt_l",120,0,1200,40,0.8,1.2); for(int i=0;i<6;i++)th3[i]->Sumw2(); //check for high btagging SF---------------------------------------------------------------------------------------- TH1D* th4[14]; string SF_jet_sub[8]={"SF_jet0_sub0_pass","SF_jet0_sub1_pass","SF_jet1_sub0_pass","SF_jet1_sub1_pass","SF_jet0_sub0_fail","SF_jet0_sub1_fail","SF_jet1_sub0_fail","SF_jet1_sub1_fail"}; for(int i=0;i<8;i++)th4[i]=new TH1D(Form("%s",SF_jet_sub[i].data()),Form("%s",SF_jet_sub[i].data()),40,0.8,1.2); string weightName[6]={"weight","weight_0b","weight_1b","weight_2b","weight_2b_ll","weight_2b_onel"}; for(int i=0;i<6;i++)th4[i+8]=new TH1D(Form("%s",weightName[i].data()),Form("%s",weightName[i].data()),40,0,2); for(int i=0;i<14;i++)th4[i]->Sumw2(); //saving variables---------------------------------------------------------------------------------------- TH1D * th5[300],* th6[300]; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ for(int k=0;k<5;k++){ th5[(i*2+j)*5+k]=new TH1D(Form("Pt_j%d_sj%d_%db",i,j,k),Form("Pt_j%d_sj%d_%db",i,j,k),200,0,2000); th5[(i*2+j)*5+k+20]=new TH1D(Form("Eta_j%d_sj%d_%db",i,j,k),Form("Eta_j%d_sj%d_%db",i,j,k),60,-3,3); th5[(i*2+j)*5+k+85]=new TH1D(Form("subCSV_j%d_sj%d_%db",i,j,k),Form("subCSV_j%d_sj%d_%db",i,j,k),20,0,1); th5[(i*2+j)*5+k+194]=new TH1D(Form("subCSVCut_j%d_sj%d_%db",i,j,k),Form("subCSVCut_j%d_sj%d_%db",i,j,k),20,0,1); } } for(int k=0;k<5;k++){ th5[i*5+k+40]=new TH1D(Form("deltaR_j%d_%db",i,k),Form("deltaR_j%d_%db",i,k),20,0,1); th5[i*5+k+50]=new TH1D(Form("Pt_j%d_%db",i,k),Form("Pt_j%d_%db",i,k),200,0,2000); th5[i*5+k+60]=new TH1D(Form("Eta_j%d_%db",i,k),Form("Eta_j%d_%db",i,k),60,-3,3); th5[i*5+k+70]=new TH1D(Form("prMassL2L3_j%d_%db",i,k),Form("prMassL2L3_j%d_%db",i,k),15,90,150); th5[i*5+k+105]=new TH1D(Form("tau21_j%d_%db",i,k),Form("tau21_j%d_%db",i,k),25,0,1); th5[i*5+k+120]=new TH1D(Form("PuppiSDMassL2L3_j%d_%db",i,k),Form("PuppiSDMassL2L3_j%d_%db",i,k),15,90,150); th5[i*5+k+130]=new TH1D(Form("puppiTau21_j%d_%db",i,k),Form("puppiTau21_j%d_%db",i,k),25,0,1); th5[i*5+k+140]=new TH1D(Form("prMass_j%d_%db",i,k),Form("prMass_j%d_%db",i,k),15,90,150); th5[i*5+k+150]=new TH1D(Form("PuppiSDMass_j%d_%db",i,k),Form("PuppiSDMass_j%d_%db",i,k),15,90,150); th5[i*5+k+170]=new TH1D(Form("doubleSV_j%d_%db",i,k),Form("doubleSV_j%d_%db",i,k),40,-1,1); th5[i*5+k+184]=new TH1D(Form("FatSV_j%d_%db",i,k),Form("FatSV_j%d_%db",i,k),20,0,1); th5[i*5+k+250]=new TH1D(Form("PuppiSDMassThea_j%d_%db",i,k),Form("PuppiSDMassThea_j%d_%db",i,k),15,90,150); } } for(int k=0;k<5;k++){ th5[k+80]=new TH1D(Form("totalMass_%db",k),Form("totalMass_%db",k),200,1000,5000); th5[k+115]=new TH1D(Form("deltaEta_%db",k),Form("deltaEta_%db",k),40,0,2); th5[k+160]=new TH1D(Form("logPt_%db",k),Form("logPt_%db",k),70,0,7); th5[k+165]=new TH1D(Form("totalMassRed_%db",k),Form("totalMassRed_%db",k),200,1000,5000); } th5[180]= new TH1D("h_nvtx","h_nvtx",60,0,60); th5[181]= new TH1D("h_ntrue","h_ntrue",60,0,60); th5[182]= new TH1D("h_nvtx_cut","h_nvtx_cut",60,0,60); th5[183]= new TH1D("h_ntrue_cut","h_ntrue_cut",60,0,60); string prMass_no[4]={"prMass","prMassL2L3","PuppiSDMass","PuppiSDMassL2L3"}; string tau21_no[2]={"tau21","puppiTau21"}; for (int i=0;i<4;i++){ th5[214+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",prMass_no[i].data()),Form("%s_j0_noPr_noTau21",prMass_no[i].data()),200,0,200); th5[215+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",prMass_no[i].data()),Form("%s_j1_noPr_noTau21",prMass_no[i].data()),200,0,200); th5[222+i*2]=new TH1D(Form("%s_j0_noPr",prMass_no[i].data()),Form("%s_j0_noPr",prMass_no[i].data()),200,0,200); th5[223+i*2]=new TH1D(Form("%s_j1_noPr",prMass_no[i].data()),Form("%s_j1_noPr",prMass_no[i].data()),200,0,200); th5[230+i*2]=new TH1D(Form("%s_j0_noTau21",prMass_no[i].data()),Form("%s_j0_noTau21",prMass_no[i].data()),15,90,150); th5[231+i*2]=new TH1D(Form("%s_j1_noTau21",prMass_no[i].data()),Form("%s_j1_noTau21",prMass_no[i].data()),15,90,150); } for (int i=0;i<2;i++){ th5[238+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",tau21_no[i].data()),Form("%s_j0_noPr_noTau21",tau21_no[i].data()),25,0,1); th5[239+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",tau21_no[i].data()),Form("%s_j1_noPr_noTau21",tau21_no[i].data()),25,0,1); th5[242+i*2]=new TH1D(Form("%s_j0_noPr",tau21_no[i].data()),Form("%s_j0_noPr",tau21_no[i].data()),25,0,1); th5[243+i*2]=new TH1D(Form("%s_j1_noPr",tau21_no[i].data()),Form("%s_j1_noPr",tau21_no[i].data()),25,0,1); th5[246+i*2]=new TH1D(Form("%s_j0_noTau21",tau21_no[i].data()),Form("%s_j0_noTau21",tau21_no[i].data()),25,0,1); th5[247+i*2]=new TH1D(Form("%s_j1_noTau21",tau21_no[i].data()),Form("%s_j1_noTau21",tau21_no[i].data()),25,0,1); } string flavor[4]={"bb","b","cc","udscg"}; for (int i=0;i<4;i++){ th5[260+i]=new TH1D(Form("Pt_j0_0b_%s",flavor[i].data()),Form("Pt_j0_0b_%s",flavor[i].data()),200,0,2000); th5[264+i]=new TH1D(Form("Pt_j0_1b_%s",flavor[i].data()),Form("Pt_j0_1b_%s",flavor[i].data()),200,0,2000); th5[268+i]=new TH1D(Form("Pt_j0_2b_%s",flavor[i].data()),Form("Pt_j0_2b_%s",flavor[i].data()),200,0,2000); th5[272+i]=new TH1D(Form("Pt_j0_DSV_%s",flavor[i].data()),Form("Pt_j0_DSV_%s",flavor[i].data()),200,0,2000); } for(int i=0;i<276;i++){ th6[i]=(TH1D* )th5[i]->Clone(Form("%ss",th5[i]->GetTitle())); th5[i]->Sumw2(); th6[i]->Sumw2(); } //pileup uncertainty---------------------------------------------------------------------------------------- TH1D* th7[14]; th7[0]=new TH1D("totalMass","totalMass",200,1000,5000); th7[1]=new TH1D("totalMass_pileup_up","totalMass_pileup_up",200,1000,5000); th7[2]=new TH1D("totalMass_pileup_down","totalMass_pileup_down",200,1000,5000); th7[3]=new TH1D("pileupEff","pileupEff",15,0.5,15.5); double totalPileup[3]={0},passPileup[3]={0}; standalone_LumiReWeighting LumiWeights_central(0),LumiWeights_up(1),LumiWeights_down(-1); //PDF uncertainty th7[4]=new TH1D("PDFEff","PDFEff",101,0.5,101.5); double passPDF[101]={0},totalPDF[101]={0}; //QCD uncertainty for(int i=5;i<14;i++)th7[i]=new TH1D(Form("uns_QCD_%d",i-5),Form("uns_QCD_%d",i-5),200,1000,5000); //NCUtuple loop---------------------------------------------------------------------------------------- for (int w=wMs;w<wM;w++){ if(w%20==0)cout<<w<<endl; //Get ntuple---------------------------------------------------------------------------------------- if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w)); else f = TFile::Open(st.data()); if (!f || !f->IsOpen())continue; TDirectory * dir; if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w)); else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data())); dir->GetObject("treeMaker",tree); TreeReader data(tree); total+=data.GetEntriesFast(); for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){//event loop---------------------------------------------------------------------------------------- data.GetEntry(jEntry); Int_t nVtx = data.GetInt("nVtx"); Float_t ntrue= data.GetFloat("pu_nTrueInt"); //Float_t* pdfscaleSysWeights= data.GetPtrFloat("pdfscaleSysWeights"); th5[180]->Fill(nVtx); th5[181]->Fill(ntrue); double PU_weight[3]={1,1,1}; if(nameRoot!=2){ if(ntrue<51){ PU_weight[0] = LumiWeights_central.weight(ntrue); PU_weight[1]= LumiWeights_up.weight(ntrue); PU_weight[2] = LumiWeights_down.weight(ntrue); } else { PU_weight[0] = LumiWeights_central.weight(50); PU_weight[1] = LumiWeights_up.weight(50); PU_weight[2]= LumiWeights_down.weight(50); } } th6[180]->Fill(nVtx,PU_weight[0]); th6[181]->Fill(ntrue,PU_weight[0]); fixScaleNum[0]+=PU_weight[0]; for(int i=0;i<3;i++)totalPileup[i]+=PU_weight[i]; for(int i=0;i<101;i++)totalPDF[i]+=PU_weight[0]; //1.trigger std::string* trigName = data.GetPtrString("hlt_trigName"); vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult")); bool passTrigger=false; for(int it=0; it< data.GetPtrStringSize(); it++){ std::string thisTrig= trigName[it]; bool results = trigResult[it]; if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos ) && results==1)){ passTrigger=true; break; } } if(!passTrigger && nameRoot==2)continue;nPass[1]++; Float_t HT= data.GetFloat("HT"); if(nameRoot!=2 && HT<800)continue; int nFATJet = data.GetInt("FATnJet"); TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4"); float* FATjetCorrUncUp = data.GetPtrFloat("FATjetCorrUncUp"); float* FATjetCorrUncDown = data.GetPtrFloat("FATjetCorrUncDown"); vector<bool> &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight")); //2.nJets if(nFATJet<2)continue;nPass[2]++; TLorentzVector* thisJet ,* thatJet; if (JESOption==1){ TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1+FATjetCorrUncUp[0] ); TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1+FATjetCorrUncUp[1] ); thisJet= &test0; thatJet= &test1; } else if (JESOption==2){ TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1-FATjetCorrUncDown[0] ); TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1-FATjetCorrUncDown[1] ); thisJet= &test0; thatJet= &test1; } else{ thisJet= (TLorentzVector*)fatjetP4->At(0); thatJet = (TLorentzVector*)fatjetP4->At(1); } //3. Pt if(thisJet->Pt()<200||thatJet->Pt()<200)continue; nPass[3]++; //4tightId----------------------------------------- if(FATjetPassIDTight[0]==0||FATjetPassIDTight[1]==0)continue; nPass[4]++; //5. Eta----------------------------------------- if(fabs(thisJet->Eta())>2.4||fabs(thatJet->Eta())>2.4)continue; nPass[5]++; //6. DEta----------------------------------------- float dEta = fabs(thisJet->Eta()-thatJet->Eta()); if(dEta>1.3)continue; nPass[6]++; //7. Mjj----------------------------------------- float mjj = (*thisJet+*thatJet).M(); float mjjRed = (*thisJet+*thatJet).M()+250-thisJet->M()-thatJet->M(); //if(mjjRed<1000)continue; nPass[7]++; //8. fatjetPRmassL2L3Corr----------------------------------------- Float_t* fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr"); vector<float> *subjetSDCSV = data.GetPtrVectorFloat("FATsubjetSDCSV"); vector<Int_t> *FATsubjetSDHadronFlavor = data.GetPtrVectorInt("FATsubjetSDHadronFlavor"); int nbtag=0,nbtag2=0; float MaxBJetPt = 670., MaxLJetPt = 1000.; double sf[2][2],eta[2],pt[2],dr[2],subjetPt[2][2],subjetEta[2][2],eff[2][2],btaggingscaleFactor=1; pt[0]=thisJet->Pt(); pt[1]=thatJet->Pt(); double scaleFactor=PU_weight[0]*btaggingscaleFactor; Float_t* fatjetTau1 = data.GetPtrFloat("FATjetTau1"); Float_t* fatjetTau2 = data.GetPtrFloat("FATjetTau2"); Float_t* FATjetPuppiTau1 = data.GetPtrFloat("FATjetPuppiTau1"); Float_t* FATjetPuppiTau2 = data.GetPtrFloat("FATjetPuppiTau2"); double tau21[2]; tau21[0]=(fatjetTau2[0]/fatjetTau1[0]),tau21[1]=(fatjetTau2[1]/fatjetTau1[1]); double puppiTau21[2]; puppiTau21[0]=(FATjetPuppiTau2[0]/FATjetPuppiTau1[0]),puppiTau21[1]=(FATjetPuppiTau2[1]/FATjetPuppiTau1[1]); if(fatjetPRmassL2L3Corr[0]<50||fatjetPRmassL2L3Corr[0]>300)continue; if(fatjetPRmassL2L3Corr[1]<50||fatjetPRmassL2L3Corr[1]>300)continue; nPass[8]++; //9.----------------------------------------- if(tau21[0]>0.6 || tau21[1]>0.6) continue; nPass[9]++; Int_t* FATjetHadronFlavor = data.GetPtrInt("FATjetHadronFlavor"); if(subjetSDCSV[0][0]<0.605 && subjetSDCSV[0][1]<0.605){ if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[260]->Fill(thisJet->Pt()); else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[261]->Fill(thisJet->Pt()); else if(FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[262]->Fill(thisJet->Pt()); else th5[263]->Fill(thisJet->Pt()); } else if (subjetSDCSV[0][0]>0.605 && subjetSDCSV[0][1]>0.605){ if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[268]->Fill(thisJet->Pt()); else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[269]->Fill(thisJet->Pt()); else if (FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[270]->Fill(thisJet->Pt()); else th5[271]->Fill(thisJet->Pt()); } else { if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[264]->Fill(thisJet->Pt()); else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[265]->Fill(thisJet->Pt()); else if (FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[266]->Fill(thisJet->Pt()); else th5[267]->Fill(thisJet->Pt()); } fixScaleNum[1]+=PU_weight[0]; Float_t* ADDjet_DoubleSV = data.GetPtrFloat("ADDjet_DoubleSV"); Float_t FATjet_DoubleSV[2]={0}; Int_t ADDnJet = data.GetInt("ADDnJet"); bool matchThis=0,matchThat=0; TClonesArray* ADDjetP4 = (TClonesArray*) data.GetPtrTObject("ADDjetP4"); for(int i=0;i<ADDnJet;i++){ TLorentzVector* thisAddJet ; thisAddJet= (TLorentzVector*)ADDjetP4->At(i); if(!matchThis && thisAddJet->DeltaR(*thisJet)<0.8){ matchThis=1; FATjet_DoubleSV[0]=ADDjet_DoubleSV[i]; continue; } if(!matchThat && thisAddJet->DeltaR(*thatJet)<0.8){ matchThat=1; FATjet_DoubleSV[1]=ADDjet_DoubleSV[i]; } if(matchThis&& matchThat){ //cout<<"match"<<FATjet_DoubleSV[0]<<","<<FATjet_DoubleSV[0]<<endl; break; } } if(FATjet_DoubleSV[0]>-0.8){ if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[272]->Fill(thisJet->Pt()); else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[273]->Fill(thisJet->Pt()); else if (FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[274]->Fill(thisJet->Pt()); else th5[275]->Fill(thisJet->Pt()); } }//end event loop---------------------------------------------------------------------------------------- } //end ntuple loop---------------------------------------------------------------------------------------- cout<<"entries="<<total<<endl; for(int i=0;i<6;i++)cout<<"nPassB["<<i<<"]="<<nPassB[i]<<endl; for(int i=0;i<16;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl; for(int i=0;i<3;i++)th7[3]->SetBinContent(i+1,passPileup[i]/totalPileup[i]); for(int i=0;i<101;i++)th7[4]->SetBinContent(i+1,passPDF[i]/totalPDF[i]); TH1D * th2o=new TH1D("Nbtagjet","Nbtagjet",5,-0.5,4.5); for (int i=0;i<5;i++){ if(nameRoot==2 && i>2)continue; th2o->SetBinContent(i+1,nPass[i+10]); } TH1D * th2ob=new TH1D("NbtagjetB","NbtagjetB",5,-0.5,4.5); for (int i=0;i<5;i++){ if(nameRoot==2 && i>2)continue; th2ob->SetBinContent(i+1,nPassB[i]); } TH1D * fixScale=new TH1D("fixScale","fixScale",2,-0.5,1.5); fixScale->SetBinContent(1,fixScaleNum[0]); fixScale->SetBinContent(2,fixScaleNum[1]); TH1D * cutflow=new TH1D("cutflow","cutflow",16,0.5,16.5); cutflow->SetBinContent(1,total); if(nameRoot==2)for(int ii=1;ii<14;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]); else for(int ii=1;ii<16;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]); TFile* outFile = new TFile(Form("root_file_mike/%s.root",st2.data()),"recreate"); th2o->Write(); th2ob->Write(); fixScale->Write(); cutflow->Write(); for(int i=0;i<6;i++)th3[i]->Write(); for(int i=0;i<14;i++)th4[i]->Write(); for(int i=0;i<276;i++){ th5[i]->Write(); th6[i]->Write(); } for(int i=0;i<14;i++)th7[i]->Write(); outFile->Close(); }
void xAna_hh_massResolutionBase(std::string inputFile,TString outputFile,bool matchb=false, bool debug=false, bool cut=false){ cout << "output file name = " << outputFile.Data() << endl; //get TTree from file ... TreeReader data(inputFile.data()); Long64_t nTotal=0; Long64_t nPass[20]={0}; const int nHistos=3; TH1F* h_massDiff = new TH1F("h_massDiff","",100,-0.5,0.5); //TH1F* h_mass = new TH1F("h_mass","",100,0,200); TH1F* h_mass = new TH1F("h_mass","",100,62.5,187.5); TH1F* h_AK8SD[nHistos]; TH1F* h_AK8SDCorrThea[nHistos]; TH1F* h_AK8SDHCorr[nHistos]; TH1F* h_PR[nHistos]; TH1F* h_PRCorr[nHistos]; TH1F* h_diff_PR[nHistos]; TH1F* h_diff_PRCorr[nHistos]; TH1F* h_diff_AK8SD[nHistos]; TH1F* h_diff_AK8SDCorrThea[nHistos]; TH1F* h_diff_AK8SDHCorr[nHistos]; std::string prefix[]={"leading","subleading","both"}; for(int i=0; i<nHistos; i++) { h_AK8SD[i] = (TH1F*)h_mass->Clone(Form("h_AK8SD_%s",prefix[i].data())); h_AK8SD[i]->SetXTitle("AK8 Raw Puppi+Softdrop mass [GeV]"); h_AK8SDCorrThea[i] = (TH1F*)h_mass->Clone(Form("h_AK8SDCorrThea_%s",prefix[i].data())); h_AK8SDCorrThea[i]->SetXTitle("AK8 Thea-corrected Puppi+Softdrop mass [GeV]"); h_AK8SDHCorr[i] = (TH1F*)h_mass->Clone(Form("h_AK8SDHCorr_%s",prefix[i].data())); h_AK8SDHCorr[i]->SetXTitle("AK8 H-corrected Puppi+Softdrop mass [GeV]"); h_PR[i] = (TH1F*)h_mass->Clone(Form("h_PR_%s",prefix[i].data())); h_PR[i]->SetXTitle("Raw CHS+Pruned mass [GeV]"); h_PRCorr[i] = (TH1F*)h_mass->Clone(Form("h_PRCorr_%s",prefix[i].data())); h_PRCorr[i]->SetXTitle("L2L3-corrected CHS+Pruned mass [GeV]"); // study the difference with respect to 125 GeV h_diff_AK8SD[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_AK8SD_%s",prefix[i].data())); h_diff_AK8SD[i]->SetXTitle("AK8 Raw Puppi+Softdrop (m-125)/125"); h_diff_AK8SDCorrThea[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_AK8SDCorrThea_%s",prefix[i].data())); h_diff_AK8SDCorrThea[i]->SetXTitle("AK8 Thea-corrected Puppi+Softdrop (m-125)/125"); h_diff_AK8SDHCorr[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_AK8SDHCorr_%s",prefix[i].data())); h_diff_AK8SDHCorr[i]->SetXTitle("AK8 H-corrected Puppi+Softdrop (m-125)/125"); h_diff_PR[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_PR_%s",prefix[i].data())); h_diff_PR[i]->SetXTitle("Raw CHS+Pruned (m-125)/125"); h_diff_PRCorr[i] = (TH1F*)h_massDiff->Clone(Form("h_diff_PRCorr_%s",prefix[i].data())); h_diff_PRCorr[i]->SetXTitle("L2L3-corrected CHS+Pruned (m-125)/125"); } for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){ if((jEntry+1)%2)continue; if (jEntry % 1000 == 0) fprintf(stderr, "Processing event %lli of %lli\n", jEntry + 1, data.GetEntriesFast()); if(debug && jEntry>10)break; data.GetEntry(jEntry); nTotal++; 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 genHIndex[2]={-1,-1}; int genbIndex[2][2]={{-1,-1}, {-1,-1}}; for(int ig=0; ig < nGenPar; ig++){ if(genParId[ig]!=25)continue; if(genHIndex[0]<0) { genHIndex[0]=ig; genbIndex[0][0]=genDa1[ig]; genbIndex[0][1]=genDa2[ig]; } else if(genHIndex[1]<0) { genHIndex[1]=ig; genbIndex[1][0]=genDa1[ig]; genbIndex[1][1]=genDa2[ig]; } } if(genHIndex[0]<0 || genHIndex[1]<0)continue; if(genbIndex[0][0]<0 || genbIndex[0][1]<0)continue; if(genbIndex[1][0]<0 || genbIndex[1][1]<0)continue; nPass[0]++; if(genHIndex[0]==genHIndex[1])continue; nPass[1]++; TLorentzVector genH_l4[2]; TLorentzVector genb_l4[2][2]; TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4"); for(int ih=0; ih<2; ih++) { genH_l4[ih] = *((TLorentzVector*)genParP4->At(genHIndex[ih])); for(int ib=0; ib<2; ib++) { genb_l4[ih][ib] = *((TLorentzVector*)genParP4->At(genbIndex[ih][ib])); } } int nFATJet = data.GetInt("FATnJet"); const int nJets=nFATJet; TClonesArray* FATjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4"); TClonesArray* AK8PuppijetP4 = (TClonesArray*) data.GetPtrTObject("AK8PuppijetP4"); // check matching first bool findAMatch=false; const float dRMax=0.4; const float dRbMax=0.8; int matchedHJetIndex[2]={-1,-1}; for(int ij=0; ij<nJets; ij++) { TLorentzVector* thisJet = (TLorentzVector*)FATjetP4->At(ij); for(int jj=0; jj<nJets; jj++) { if(ij==jj)continue; TLorentzVector* thatJet = (TLorentzVector*)FATjetP4->At(jj); if(thisJet->DeltaR(genH_l4[0])<dRMax && (!matchb || (matchb && thisJet->DeltaR(genb_l4[0][0])<dRbMax && thisJet->DeltaR(genb_l4[0][1])<dRbMax)) && thatJet->DeltaR(genH_l4[1])<dRMax && (!matchb || (matchb && thatJet->DeltaR(genb_l4[1][0])<dRbMax && thatJet->DeltaR(genb_l4[1][1])<dRbMax))) { if(debug) { cout << "dRhb00= " << thisJet->DeltaR(genb_l4[0][0]) << endl; cout << "dRhb01= " << thisJet->DeltaR(genb_l4[0][1]) << endl; cout << "dRhb10= " << thatJet->DeltaR(genb_l4[1][0]) << endl; cout << "dRhb11= " << thatJet->DeltaR(genb_l4[1][1]) << endl; } if(ij<jj){ matchedHJetIndex[0]=ij; matchedHJetIndex[1]=jj; } else { matchedHJetIndex[0]=jj; matchedHJetIndex[1]=ij; } findAMatch=true; break; } if(findAMatch)break; } if(findAMatch)break; } if(!findAMatch)continue; if(debug) cout << matchedHJetIndex[0] << "\t" << matchedHJetIndex[1] << endl; nPass[2]++; //0. has a good vertex Int_t nVtx = data.GetInt("nVtx"); if(nVtx<1 && cut)continue; nPass[3]++; Float_t* fatjetTau1 = data.GetPtrFloat("FATjetTau1"); Float_t* fatjetTau2 = data.GetPtrFloat("FATjetTau2"); Float_t* fatjetCISVV2 = data.GetPtrFloat("FATjetCISVV2"); Float_t* fatjetPRmass = data.GetPtrFloat("FATjetPRmass"); Float_t* fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr"); Float_t* fatjetSDmass = data.GetPtrFloat("FATjetPuppiSDmass"); Float_t* fatjetSDmassL2L3Corr = data.GetPtrFloat("FATjetPuppiSDmassL2L3Corr"); Float_t* AK8PuppijetSDmass = data.GetPtrFloat("AK8PuppijetSDmass"); vector<bool> &passFatJetLooseID = *((vector<bool>*) data.GetPtr("FATjetPassIDLoose")); TLorentzVector recoH_l4[2]; int nGoodJets=0; for(int i=0; i<2; i++) { int ij = matchedHJetIndex[i]; TLorentzVector* thisJet = (TLorentzVector*)FATjetP4->At(ij); recoH_l4[i]= (*thisJet); if(thisJet->Pt()<200)continue; if(fabs(thisJet->Eta())>2.4)continue; nGoodJets++; } if(nGoodJets<2)continue; nPass[5]++; float dEta=fabs(recoH_l4[0].Eta()-recoH_l4[1].Eta()); if(dEta>1.3 && cut)continue; nPass[6]++; float M=(recoH_l4[0] + recoH_l4[1]).M(); if(M<800 && cut)continue; nPass[7]++; int nHP=0; int nLP=0; for(int i=0; i<2; i++) { int ij = matchedHJetIndex[i]; float tau21_i = fatjetTau2[ij]/fatjetTau1[ij]; bool isHP= (tau21_i < 0.6); if(isHP)nHP++; } if(nHP<2 && cut)continue; nPass[8]++; double SDMass[2]; Int_t AK8PuppinJet = data.GetInt("AK8PuppinJet"); if(AK8PuppinJet<2)continue; bool matchThis=0,matchThat=0; //TClonesArray* AK8PuppijetP4 = (TClonesArray*) data.GetPtrTObject("AK8PuppijetP4"); TLorentzVector* thisJet,* thatJet; thisJet= (TLorentzVector*)FATjetP4->At(0); thatJet= (TLorentzVector*)FATjetP4->At(1); for(int i=0;i<AK8PuppinJet;i++){ TLorentzVector* thisAddJet ; thisAddJet= (TLorentzVector*)AK8PuppijetP4->At(i); if(!matchThis && thisAddJet->DeltaR(*thisJet)<0.8){ matchThis=1; SDMass[0]=AK8PuppijetSDmass[i]; continue; } if(!matchThat && thisAddJet->DeltaR(*thatJet)<0.8){ matchThat=1; SDMass[1]=AK8PuppijetSDmass[i]; } if(matchThis&& matchThat)break; } for(int i=0; i<2;i++) { float thea_corr = getPUPPIweight_o(thisJet->Pt(),thisJet->Eta()); if(i==1)thea_corr = getPUPPIweight_o(thatJet->Pt(),thatJet->Eta()); float H_corr= getPUPPIweight(thisJet->Pt(),thisJet->Eta()); if(i==1)H_corr = getPUPPIweight(thatJet->Pt(),thatJet->Eta()); h_PR[i]->Fill(fatjetPRmass[i]); h_PRCorr[i]->Fill(fatjetPRmassL2L3Corr[i]); h_AK8SD[i]->Fill(SDMass[i]); h_AK8SDCorrThea[i]->Fill(SDMass[i]*thea_corr); h_AK8SDHCorr[i]->Fill(SDMass[i]*H_corr); h_PR[2]->Fill(fatjetPRmass[i]); h_PRCorr[2]->Fill(fatjetPRmassL2L3Corr[i]); h_AK8SD[2]->Fill(SDMass[i]); h_AK8SDCorrThea[2]->Fill(SDMass[i]*thea_corr); h_AK8SDHCorr[2]->Fill(SDMass[i]*H_corr); h_diff_PR[i]->Fill((fatjetPRmass[i]-125)/125); h_diff_PRCorr[i]->Fill((fatjetPRmassL2L3Corr[i]-125)/125); h_diff_AK8SD[i]->Fill((SDMass[i]-125)/125); h_diff_AK8SDCorrThea[i]->Fill((SDMass[i]*thea_corr-125)/125); h_diff_AK8SDHCorr[i]->Fill((SDMass[i]*H_corr-125)/125); h_diff_PR[2]->Fill((fatjetPRmass[i]-125)/125); h_diff_PRCorr[2]->Fill((fatjetPRmassL2L3Corr[i]-125)/125); h_diff_AK8SD[2]->Fill((SDMass[i]-125)/125); h_diff_AK8SDCorrThea[2]->Fill((SDMass[i]*thea_corr-125)/125); h_diff_AK8SDHCorr[2]->Fill((SDMass[i]*H_corr-125)/125); } } // end of loop over entries 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; TFile* outFile = new TFile(Form("output/%s",outputFile.Data()),"recreate"); for(int i=0; i<nHistos; i++) { h_diff_PR[i]->Write(); h_diff_PRCorr[i]->Write(); h_diff_AK8SD[i]->Write(); h_diff_AK8SDCorrThea[i]->Write(); h_diff_AK8SDHCorr[i]->Write(); h_PR[i]->Write(); h_PRCorr[i]->Write(); h_AK8SD[i]->Write(); h_AK8SDCorrThea[i]->Write(); h_AK8SDHCorr[i]->Write(); } outFile->Close(); }
void toyMCele_cat1(std::string inputFile, std::string outputFile){ // read the ntuples (in pcncu) TreeReader data(inputFile.data()); // Declare the histogram TFile* f = new TFile(inputFile.data()); TH1D* h_totalEvents = (TH1D*)f->Get("h_totalEv"); TH1D* h_PRmassNoSIG = new TH1D("h_PRmassNoSIG", "PRmassNoSIG", 40, 40, 240); TH1D* h_PRmassAll = new TH1D("h_PRmassAll", "PRmassAll", 40, 40, 240); h_PRmassNoSIG->Sumw2(); h_PRmassAll ->Sumw2(); h_PRmassNoSIG->GetXaxis()->SetTitle("corrPRmass"); h_PRmassAll ->GetXaxis()->SetTitle("corrPRmass"); // begin of event loop Long64_t nentries = data.GetEntriesFast(); for(Long64_t ev = 0; ev < nentries; ev++){ if( ev % 1000000 == 0 ) fprintf(stderr, "Processing event %lli of %lli\n", ev + 1, nentries); data.GetEntry(ev); Float_t eventWeight = data.GetFloat("ev_weight"); TClonesArray* eleP4 = (TClonesArray*) data.GetPtrTObject("eleP4"); Int_t FATnJet = data.GetInt("FATnJet"); Int_t* FATnSubSDJet = data.GetPtrInt("FATnSubSDJet"); Float_t* corrPRmass = data.GetPtrFloat("FATjetPRmassL2L3Corr"); TClonesArray* FATjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4"); vector<bool>& FATjetPassIDLoose = *((vector<bool>*) data.GetPtr("FATjetPassIDLoose")); vector<float>* FATsubjetSDPx = data.GetPtrVectorFloat("FATsubjetSDPx", FATnJet); vector<float>* FATsubjetSDPy = data.GetPtrVectorFloat("FATsubjetSDPy", FATnJet); vector<float>* FATsubjetSDPz = data.GetPtrVectorFloat("FATsubjetSDPz", FATnJet); vector<float>* FATsubjetSDE = data.GetPtrVectorFloat("FATsubjetSDE", FATnJet); vector<float>* FATsubjetSDCSV = data.GetPtrVectorFloat("FATsubjetSDCSV", FATnJet); // select good leptons vector<Int_t> goodLepID; TLorentzVector* thisLep = NULL; TLorentzVector* thatLep = NULL; if( !isPassZee(data,goodLepID) ) continue; thisLep = (TLorentzVector*)eleP4->At(goodLepID[0]); thatLep = (TLorentzVector*)eleP4->At(goodLepID[1]); // select good FATjet Int_t goodFATJetID = -1; TLorentzVector* thisJet = NULL; for(Int_t ij = 0; ij < FATnJet; ij++){ thisJet = (TLorentzVector*)FATjetP4->At(ij); if( thisJet->Pt() < 200 ) continue; if( fabs(thisJet->Eta()) > 2.4 ) continue; if( !FATjetPassIDLoose[ij] ) continue; if( thisJet->DeltaR(*thisLep) < 0.8 || thisJet->DeltaR(*thatLep) < 0.8 ) continue; Int_t nsubBjet = 0; for(Int_t is = 0; is < FATnSubSDJet[ij]; is++){ if( FATsubjetSDCSV[ij][is] > 0.605 ) nsubBjet++; } Double_t subjetDeltaR = -1; if( nsubBjet == 2 ){ TLorentzVector l4_subjet0(0,0,0,0); TLorentzVector l4_subjet1(0,0,0,0); l4_subjet0.SetPxPyPzE(FATsubjetSDPx[ij][0], FATsubjetSDPy[ij][0], FATsubjetSDPz[ij][0], FATsubjetSDE [ij][0]); l4_subjet1.SetPxPyPzE(FATsubjetSDPx[ij][1], FATsubjetSDPy[ij][1], FATsubjetSDPz[ij][1], FATsubjetSDE [ij][1]); subjetDeltaR = l4_subjet0.DeltaR(l4_subjet1); } // deltaR depends loose cut if( subjetDeltaR > 0.3 ) continue; if( nsubBjet < 1 ) continue; goodFATJetID = ij; break; } if( goodFATJetID < 0 ) continue; Float_t mllbb = (*thisLep+*thatLep+*thisJet).M(); if( mllbb < 750 ) continue; h_PRmassAll->Fill(corrPRmass[goodFATJetID],eventWeight); if( corrPRmass[goodFATJetID] > 30 && !(corrPRmass[goodFATJetID] > 65 && corrPRmass[goodFATJetID] < 135) && corrPRmass[goodFATJetID] < 300 ) h_PRmassNoSIG->Fill(corrPRmass[goodFATJetID],eventWeight); } // end of event loop fprintf(stderr, "Processed all events\n"); TFile* outFile = new TFile(Form("%s_pseudoTest.root",outputFile.c_str()), "recreate"); h_PRmassNoSIG->Write("corrPRmass"); h_PRmassAll ->Write("corrPRmassAll"); h_totalEvents->Write("totalEvents"); outFile->Write(); delete f; delete outFile; }
void fitSingleMass( const std::string& basedir, float mass, const std::string& width, TGraphErrors* gr_mean, TGraphErrors* gr_sigma, TGraphErrors* gr_width, TGraphErrors* gr_alpha1, TGraphErrors* gr_n1, TGraphErrors* gr_alpha2, TGraphErrors* gr_n2 ) { std::string outdir = "genSignalShapes"; system( Form("mkdir -p %s", outdir.c_str()) ); std::string dataset( Form( "GluGluSpin0ToZGamma_ZToLL_W_%s_M_%.0f_TuneCUEP8M1_13TeV_pythia8", width.c_str(), mass ) ); std::cout << "-> Starting: " << dataset << std::endl; system( Form("ls %s/%s/crab_%s/*/0000/genAna_1.root >> toBeAdded.txt", basedir.c_str(), dataset.c_str(), dataset.c_str() ) ); TChain* tree = new TChain("mt2"); ifstream ifs("toBeAdded.txt"); while( ifs.good() ) { std::string fileName; ifs >> fileName; TString fileName_tstr(fileName); if( !fileName_tstr.Contains("pnfs") ) continue; tree->Add(Form("$DCAP/%s/mt2", fileName.c_str()) ); } system( "rm toBeAdded.txt" ); if( tree->GetEntries()==0 ) return; int ngenPart; tree->SetBranchAddress( "ngenPart", &ngenPart ); float genPart_pt[100]; tree->SetBranchAddress( "genPart_pt", genPart_pt ); float genPart_eta[100]; tree->SetBranchAddress( "genPart_eta", genPart_eta ); float genPart_phi[100]; tree->SetBranchAddress( "genPart_phi", genPart_phi ); float genPart_mass[100]; tree->SetBranchAddress( "genPart_mass", genPart_mass ); int genPart_pdgId[100]; tree->SetBranchAddress( "genPart_pdgId", genPart_pdgId ); int genPart_motherId[100]; tree->SetBranchAddress( "genPart_motherId", genPart_motherId ); int genPart_status[100]; tree->SetBranchAddress( "genPart_status", genPart_status ); RooRealVar* x = new RooRealVar("boss_mass", "boss_mass", mass, 0.5*mass, 1.5*mass ); RooDataSet* data = new RooDataSet( "data", "data", RooArgSet(*x) ); int nentries = tree->GetEntries(); for( int iEntry = 0; iEntry<nentries; ++iEntry ) { if( iEntry % 25000 == 0 ) std::cout << " Entry: " << iEntry << " / " << nentries << std::endl; tree->GetEntry(iEntry); TLorentzVector leptPlus; TLorentzVector leptMinus; TLorentzVector photon; bool foundLeptPlus = false; bool foundLeptMinus = false; bool foundPhoton = false; bool tauEvent = false; for( int iPart=0; iPart<ngenPart; ++iPart ) { if( genPart_status[iPart]!=1 ) continue; if( abs(genPart_pdgId[iPart])==15 ) { tauEvent = true; break; } if( (genPart_pdgId[iPart]==+11 || genPart_pdgId[iPart]==+13) && genPart_motherId[iPart]==23 ) { leptMinus.SetPtEtaPhiM( genPart_pt[iPart], genPart_eta[iPart], genPart_phi[iPart], genPart_mass[iPart] ); foundLeptMinus = true; } if( (genPart_pdgId[iPart]==-11 || genPart_pdgId[iPart]==-13) && genPart_motherId[iPart]==23 ) { leptPlus.SetPtEtaPhiM( genPart_pt[iPart], genPart_eta[iPart], genPart_phi[iPart], genPart_mass[iPart] ); foundLeptPlus = true; } if( genPart_pdgId[iPart]==22 && genPart_motherId[iPart]==25 ) { photon.SetPtEtaPhiM( genPart_pt[iPart], genPart_eta[iPart], genPart_phi[iPart], genPart_mass[iPart] ); foundPhoton = true; } } // for genparts if( tauEvent ) continue; if( !foundLeptPlus || !foundLeptMinus || !foundPhoton ) continue; if( photon.Pt() < 40. ) continue; float ptMax = TMath::Max( leptPlus.Pt(), leptMinus.Pt() ); float ptMin = TMath::Min( leptPlus.Pt(), leptMinus.Pt() ); if( ptMax<25. ) continue; if( ptMin<20. ) continue; if( fabs( photon.Eta() ) > 2.5 ) continue; if( fabs( photon.Eta())>1.44 && fabs( photon.Eta())<1.57 ) continue; if( fabs( leptPlus.Eta() ) > 2.4 ) continue; if( fabs( leptMinus.Eta() ) > 2.4 ) continue; if( photon.DeltaR( leptPlus ) < 0.4 ) continue; if( photon.DeltaR( leptMinus ) < 0.4 ) continue; TLorentzVector zBoson = leptPlus + leptMinus; if( zBoson.M() < 50. ) continue; TLorentzVector boss = zBoson + photon; if( boss.M() < 200. ) continue; if( photon.Pt()/boss.M()< 40./150. ) continue; x->setVal(boss.M()); data->add(RooArgSet(*x)); } //RooRealVar* bw_mean = new RooRealVar( "bw_mean", "Breit-Wigner Mean" , mass, 0.2*mass, 1.8*mass ); //RooRealVar* bw_gamma = new RooRealVar( "bw_gamma", "Breit-Wigner Width", 0.01*mass, 0., 0.3*mass ); //RooBreitWigner* model = new RooBreitWigner( "bw", "Breit-Wigner", *x, *bw_mean, *bw_gamma); // Crystal-Ball RooRealVar mean( "mean", "mean", mass, 0.9*mass, 1.1*mass ); RooRealVar sigma( "sigma", "sigma", 0.015*mass, 0., 0.07*mass ); RooRealVar alpha1( "alpha1", "alpha1", 1.2, 0., 2.5 ); RooRealVar n1( "n1", "n1", 3., 0., 5. ); RooRealVar alpha2( "alpha2", "alpha2", 1.2, 0., 2.5 ); RooRealVar n2( "n2", "n2", 3., 0., 10. ); RooDoubleCBShape* model = new RooDoubleCBShape( "cb", "cb", *x, mean, sigma, alpha1, n1, alpha2, n2 ); model->fitTo( *data ); int npoints = gr_mean->GetN(); gr_mean ->SetPoint( npoints, mass, mean.getVal() ); gr_sigma ->SetPoint( npoints, mass, sigma.getVal() ); gr_width ->SetPoint( npoints, mass, sigma.getVal()/mean.getVal() ); gr_alpha1->SetPoint( npoints, mass, alpha1.getVal() ); gr_alpha2->SetPoint( npoints, mass, alpha2.getVal() ); gr_n1 ->SetPoint( npoints, mass, n1.getVal() ); gr_n2 ->SetPoint( npoints, mass, n2.getVal() ); gr_mean ->SetPointError( npoints, 0., mean.getError() ); gr_sigma ->SetPointError( npoints, 0., sigma.getError() ); gr_width ->SetPointError( npoints, 0., sigma.getError()/mean.getVal() ); gr_alpha1->SetPointError( npoints, 0., alpha1.getError() ); gr_alpha2->SetPointError( npoints, 0., alpha2.getError() ); gr_n1 ->SetPointError( npoints, 0., n1.getError() ); gr_n2 ->SetPointError( npoints, 0., n2.getError() ); //gr_mean ->SetPoint ( npoints, mass, bw_mean->getVal() ); //gr_gamma->SetPoint ( npoints, mass, bw_gamma->getVal() ); //gr_width->SetPoint ( npoints, mass, bw_gamma->getVal()/bw_mean->getVal() ); //gr_mean ->SetPointError( npoints, 0., bw_mean->getError() ); //gr_gamma->SetPointError( npoints, 0., bw_gamma->getError()/bw_mean->getVal() ); //gr_width->SetPointError( npoints, 0., bw_gamma->getError()/bw_mean->getVal() ); RooPlot* plot = x->frame(); data->plotOn(plot); model->plotOn(plot); TCanvas* c1 = new TCanvas( "c1", "", 600, 600 ); c1->cd(); plot->Draw(); c1->SaveAs( Form("%s/fit_m%.0f_%s.eps", outdir.c_str(), mass, width.c_str()) ); c1->SaveAs( Form("%s/fit_m%.0f_%s.pdf", outdir.c_str(), mass, width.c_str()) ); c1->SetLogy(); c1->SaveAs( Form("%s/fit_m%.0f_%s_log.eps", outdir.c_str(), mass, width.c_str()) ); c1->SaveAs( Form("%s/fit_m%.0f_%s_log.pdf", outdir.c_str(), mass, width.c_str()) ); //delete bw_mean; //delete bw_gamma; delete c1; delete data; delete model; delete plot; delete x; }
void HH4bBtagEffBase_80_v2(int wMs,int wM, string st,string st2,string option=""){ //1=signal ,0=QCD ,2=data----------------------------------------------------------- int nameRoot=1; if((st2.find("QCD")!= std::string::npos)|| (st2.find("bGen")!= std::string::npos)|| (st2.find("bEnriched")!= std::string::npos))nameRoot=0; if(st2.find("data")!= std::string::npos)nameRoot=2; //Thea correction--------------------- TFile *f3; f3=TFile::Open("puppiCorr.root"); TF1* tf1[3]; tf1[0]=(TF1 *) f3->FindObjectAny("puppiJECcorr_gen"); tf1[1]=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_0eta1v3"); tf1[2]=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_1v3eta2v5"); //option----------------------------------------------------------- int JESOption=0; if(option.find("JESUp")!= std::string::npos)JESOption=1; if(option.find("JESDown")!= std::string::npos)JESOption=2; if(option.find("BtagUp")!= std::string::npos)JESOption=3; if(option.find("BtagDown")!= std::string::npos)JESOption=4; if(option.find("tau21Up")!= std::string::npos)JESOption=5; if(option.find("tau21Down")!= std::string::npos)JESOption=6; cout<<"JESOption = "<<JESOption<<endl; bool printHighPtSubjet=0; bool isFast=1; //tuple tree and cutflow variables------------------------------------------------------------------------------------ TFile *f; TTree *tree; double nPass[30]={0},total=0; double fixScaleNum[2]={0}; //using for Btag Eff ----------------------------------------------------------------------------- string btagsystematicsType="central"; if(JESOption==3)btagsystematicsType="up"; else if(JESOption==4)btagsystematicsType="down"; BTagCalibration calib("CSVv2L", "subjet_CSVv2_ichep.csv"); BTagCalibrationReader LF(BTagEntry::OP_LOOSE,"central", {"up", "down"}); BTagCalibrationReader HFC(BTagEntry::OP_LOOSE, "central", {"up", "down"}); // other sys types BTagCalibrationReader HF(BTagEntry::OP_LOOSE,"central",{"up", "down"}); // other sys types LF.load(calib, BTagEntry::FLAV_UDSG, // btag flavour "incl"); // measurement type HFC.load(calib, BTagEntry::FLAV_C, // btag flavour "lt"); // measurement type HF.load(calib, BTagEntry::FLAV_B, // btag flavour "lt"); // measurement type TFile *f1; if(nameRoot==2)f1=TFile::Open("btagEffSource/data.root"); else if (nameRoot!=2 && (JESOption==0||JESOption==3||JESOption==4||JESOption==5||JESOption==6))f1=TFile::Open(Form("btagEffSource/%s.root",st2.data())); else if (nameRoot!=2 && JESOption==1)f1=TFile::Open(Form("btagEffSource/%s_JESUp.root",st2.data())); else if (nameRoot!=2 && JESOption==2)f1=TFile::Open(Form("btagEffSource/%s_JESDown.root",st2.data())); TH1D* th1[6]; string btaggingEff[6]={"effD_b","effN_b","effD_c","effN_c","effD_l","effN_l"}; for(int i=0;i<6;i++){ th1[i]=(TH1D*)f1->FindObjectAny(Form("%s_1d",btaggingEff[i].data())); if(i==1||i==3||i==5)th1[i]->Divide(th1[i-1]); } //saving variables---------------------------------------------------------------------------------------- TH1D * th5[300],* th_flavor[4][300]; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ for(int k=0;k<5;k++){ th5[(i*2+j)*5+k]=new TH1D(Form("Pt_j%d_sj%d_%db",i,j,k),Form("Pt_j%d_sj%d_%db",i,j,k),200,0,2000); th5[(i*2+j)*5+k+20]=new TH1D(Form("Eta_j%d_sj%d_%db",i,j,k),Form("Eta_j%d_sj%d_%db",i,j,k),60,-3,3); th5[(i*2+j)*5+k+85]=new TH1D(Form("subCSV_j%d_sj%d_%db",i,j,k),Form("subCSV_j%d_sj%d_%db",i,j,k),20,0,1); th5[(i*2+j)*5+k+194]=new TH1D(Form("subCSVCut_j%d_sj%d_%db",i,j,k),Form("subCSVCut_j%d_sj%d_%db",i,j,k),20,0,1); } } for(int k=0;k<5;k++){ th5[i*5+k+40]=new TH1D(Form("deltaR_j%d_%db",i,k),Form("deltaR_j%d_%db",i,k),20,0,1); th5[i*5+k+50]=new TH1D(Form("Pt_j%d_%db",i,k),Form("Pt_j%d_%db",i,k),200,0,2000); th5[i*5+k+60]=new TH1D(Form("Eta_j%d_%db",i,k),Form("Eta_j%d_%db",i,k),60,-3,3); th5[i*5+k+70]=new TH1D(Form("prMassL2L3_j%d_%db",i,k),Form("prMassL2L3_j%d_%db",i,k),15,90,150); th5[i*5+k+105]=new TH1D(Form("tau21_j%d_%db",i,k),Form("tau21_j%d_%db",i,k),25,0,1); th5[i*5+k+120]=new TH1D(Form("PuppiSDMassL2L3_j%d_%db",i,k),Form("PuppiSDMassL2L3_j%d_%db",i,k),15,90,150); th5[i*5+k+130]=new TH1D(Form("puppiTau21_j%d_%db",i,k),Form("puppiTau21_j%d_%db",i,k),25,0,1); th5[i*5+k+140]=new TH1D(Form("prMass_j%d_%db",i,k),Form("prMass_j%d_%db",i,k),15,90,150); th5[i*5+k+150]=new TH1D(Form("PuppiSDMass_j%d_%db",i,k),Form("PuppiSDMass_j%d_%db",i,k),15,90,150); th5[i*5+k+170]=new TH1D(Form("doubleSV_j%d_%db",i,k),Form("doubleSV_j%d_%db",i,k),40,-1,1); th5[i*5+k+184]=new TH1D(Form("FatSV_j%d_%db",i,k),Form("FatSV_j%d_%db",i,k),20,0,1); th5[i*5+k+250]=new TH1D(Form("PuppiSDMassThea_j%d_%db",i,k),Form("PuppiSDMassThea_j%d_%db",i,k),15,90,150); } } for(int k=0;k<5;k++){ th5[k+80]=new TH1D(Form("totalMass_%db",k),Form("totalMass_%db",k),200,1000,5000); th5[k+115]=new TH1D(Form("deltaEta_%db",k),Form("deltaEta_%db",k),40,0,2); th5[k+160]=new TH1D(Form("logPt_%db",k),Form("logPt_%db",k),70,0,7); th5[k+165]=new TH1D(Form("totalMassRed_%db",k),Form("totalMassRed_%db",k),200,1000,5000); } th5[180]= new TH1D("h_nvtx","h_nvtx",60,0,60); th5[181]= new TH1D("h_ntrue","h_ntrue",60,0,60); th5[182]= new TH1D("h_nvtx_cut","h_nvtx_cut",60,0,60); th5[183]= new TH1D("h_ntrue_cut","h_ntrue_cut",60,0,60); string prMass_no[4]={"prMass","prMassL2L3","PuppiSDMass","PuppiSDMassL2L3"}; string tau21_no[2]={"tau21","puppiTau21"}; for (int i=0;i<4;i++){ th5[214+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",prMass_no[i].data()),Form("%s_j0_noPr_noTau21",prMass_no[i].data()),200,0,200); th5[215+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",prMass_no[i].data()),Form("%s_j1_noPr_noTau21",prMass_no[i].data()),200,0,200); th5[222+i*2]=new TH1D(Form("%s_j0_noPr",prMass_no[i].data()),Form("%s_j0_noPr",prMass_no[i].data()),200,0,200); th5[223+i*2]=new TH1D(Form("%s_j1_noPr",prMass_no[i].data()),Form("%s_j1_noPr",prMass_no[i].data()),200,0,200); th5[230+i*2]=new TH1D(Form("%s_j0_noTau21",prMass_no[i].data()),Form("%s_j0_noTau21",prMass_no[i].data()),15,90,150); th5[231+i*2]=new TH1D(Form("%s_j1_noTau21",prMass_no[i].data()),Form("%s_j1_noTau21",prMass_no[i].data()),15,90,150); } for (int i=0;i<2;i++){ th5[238+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",tau21_no[i].data()),Form("%s_j0_noPr_noTau21",tau21_no[i].data()),25,0,1); th5[239+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",tau21_no[i].data()),Form("%s_j1_noPr_noTau21",tau21_no[i].data()),25,0,1); th5[242+i*2]=new TH1D(Form("%s_j0_noPr",tau21_no[i].data()),Form("%s_j0_noPr",tau21_no[i].data()),25,0,1); th5[243+i*2]=new TH1D(Form("%s_j1_noPr",tau21_no[i].data()),Form("%s_j1_noPr",tau21_no[i].data()),25,0,1); th5[246+i*2]=new TH1D(Form("%s_j0_noTau21",tau21_no[i].data()),Form("%s_j0_noTau21",tau21_no[i].data()),25,0,1); th5[247+i*2]=new TH1D(Form("%s_j1_noTau21",tau21_no[i].data()),Form("%s_j1_noTau21",tau21_no[i].data()),25,0,1); } for(int i=0;i<260;i++){ th5[i]->Sumw2(); th_flavor[0][i]=(TH1D* )th5[i]->Clone(Form("%s_bb",th5[i]->GetTitle())); th_flavor[1][i]=(TH1D* )th5[i]->Clone(Form("%s_b",th5[i]->GetTitle())); th_flavor[2][i]=(TH1D* )th5[i]->Clone(Form("%s_cc",th5[i]->GetTitle())); th_flavor[3][i]=(TH1D* )th5[i]->Clone(Form("%s_udcsg",th5[i]->GetTitle())); //th_flavor[0][i]->Sumw2(); //th_flavor[1][i]->Sumw2(); //th_flavor[2][i]->Sumw2(); //th_flavor[3][i]->Sumw2(); } //pileup uncertainty---------------------------------------------------------------------------------------- TH1D* th7[14]; th7[0]=new TH1D("totalMass","totalMass",200,1000,5000); th7[1]=new TH1D("totalMass_pileup_up","totalMass_pileup_up",200,1000,5000); th7[2]=new TH1D("totalMass_pileup_down","totalMass_pileup_down",200,1000,5000); th7[3]=new TH1D("pileupEff","pileupEff",15,0.5,15.5); double totalPileup[3]={0},passPileup[3]={0}; standalone_LumiReWeighting LumiWeights_central(0),LumiWeights_up(1),LumiWeights_down(-1); //PDF uncertainty th7[4]=new TH1D("PDFEff","PDFEff",101,0.5,101.5); double passPDF[101]={0},totalPDF[101]={0}; //QCD uncertainty for(int i=5;i<14;i++)th7[i]=new TH1D(Form("uns_QCD_%d",i-5),Form("uns_QCD_%d",i-5),200,1000,5000); //NCUtuple loop---------------------------------------------------------------------------------------- for (int w=wMs;w<wM;w++){ if(w%20==0)cout<<w<<endl; //Get ntuple---------------------------------------------------------------------------------------- if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w)); else f = TFile::Open(st.data()); if (!f || !f->IsOpen())continue; TDirectory * dir; if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w)); else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data())); dir->GetObject("treeMaker",tree); TreeReader data(tree); total+=data.GetEntriesFast(); //TFile* fileFast=TFile::Open(Form("fast/%s/%d.root",st2.data(),w)); //TTree* treeFast=(TTree* )fileFast->Get("hh4bFast"); //TreeReader dataFast(treeFast); //if(isFast)dataFast=TreeReader(treeFast); for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){//event loop---------------------------------------------------------------------------------------- data.GetEntry(jEntry); //if(isFast)dataFast.GetEntry(jEntry); Int_t nVtx = data.GetInt("nVtx"); Float_t ntrue= data.GetFloat("pu_nTrueInt"); //Float_t* pdfscaleSysWeights= data.GetPtrFloat("pdfscaleSysWeights"); double PU_weight[3]={1,1,1}; if(nameRoot!=2){ if(ntrue<51){ PU_weight[0] = LumiWeights_central.weight(ntrue); PU_weight[1]= LumiWeights_up.weight(ntrue); PU_weight[2] = LumiWeights_down.weight(ntrue); } else { PU_weight[0] = LumiWeights_central.weight(50); PU_weight[1] = LumiWeights_up.weight(50); PU_weight[2]= LumiWeights_down.weight(50); } } fixScaleNum[0]+=PU_weight[0]; for(int i=0;i<3;i++)totalPileup[i]+=PU_weight[i]; for(int i=0;i<101;i++)totalPDF[i]+=PU_weight[0]; //Int_t nPassFast; //if(isFast)nPassFast= dataFast.GetInt("nPassB"); //cout<<nPassFast<<endl; //if(isFast &&nPassFast<8)continue; //0. has a good vertex if(nVtx<1)continue;nPass[0]+=PU_weight[0]; //1.trigger std::string* trigName = data.GetPtrString("hlt_trigName"); vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult")); bool passTrigger=false; for(int it=0; it< data.GetPtrStringSize(); it++){ std::string thisTrig= trigName[it]; bool results = trigResult[it]; if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos|| //thisTrig.find("HLT_PFHT650")!= std::string::npos|| thisTrig.find("HLT_PFHT650_WideJetMJJ900DEtaJJ1p5_v")!= std::string::npos|| thisTrig.find("HLT_PFHT650_WideJetMJJ950DEtaJJ1p5_v")!= std::string::npos|| thisTrig.find("HLT_AK8PFJet360_TrimMass30_v")!= std::string::npos|| thisTrig.find("HLT_AK8PFHT700_TrimR0p1PT0p03Mass50_v")!= std::string::npos ) && results==1)){ passTrigger=true; break; } } if(!passTrigger && nameRoot==2)continue;nPass[1]+=PU_weight[0]; int nFATJet = data.GetInt("FATnJet"); TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4"); float* FATjetCorrUncUp = data.GetPtrFloat("FATjetCorrUncUp"); float* FATjetCorrUncDown = data.GetPtrFloat("FATjetCorrUncDown"); vector<bool> &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight")); //2.nJets if(nFATJet<2)continue;nPass[2]+=PU_weight[0]; TLorentzVector* thisJet ,* thatJet; if (JESOption==1){ TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1+FATjetCorrUncUp[0] ); TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1+FATjetCorrUncUp[1] ); thisJet= &test0; thatJet= &test1; } else if (JESOption==2){ TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1-FATjetCorrUncDown[0] ); TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1-FATjetCorrUncDown[1] ); thisJet= &test0; thatJet= &test1; } else{ thisJet= (TLorentzVector*)fatjetP4->At(0); thatJet = (TLorentzVector*)fatjetP4->At(1); } //3. Pt if(thisJet->Pt()<200||thatJet->Pt()<200)continue; nPass[3]+=PU_weight[0]; //4tightId----------------------------------------- if(FATjetPassIDTight[0]==0||FATjetPassIDTight[1]==0)continue; Float_t* FATjetCEmEF = data.GetPtrFloat("FATjetCEmEF"); Float_t* FATjetMuEF = data.GetPtrFloat("FATjetMuEF"); if(FATjetMuEF[0]>0.8||FATjetMuEF[1]>0.8)continue; if(FATjetCEmEF[0]>0.9||FATjetCEmEF[1]>0.9)continue; nPass[4]+=PU_weight[0]; //5. Eta----------------------------------------- if(fabs(thisJet->Eta())>2.4||fabs(thatJet->Eta())>2.4)continue; nPass[5]+=PU_weight[0]; int event_flavor=-1; Int_t* FATjetHadronFlavor = data.GetPtrInt("FATjetHadronFlavor"); vector<Int_t> *FATsubjetSDHadronFlavor = data.GetPtrVectorInt("FATsubjetSDHadronFlavor"); if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)event_flavor=0; else if(FATjetHadronFlavor[1]==5 && FATsubjetSDHadronFlavor[1][0]==5 && FATsubjetSDHadronFlavor[1][1]==5)event_flavor=0; else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))event_flavor=1; else if(FATjetHadronFlavor[1]==5 && (FATsubjetSDHadronFlavor[1][0]==5 || FATsubjetSDHadronFlavor[1][1]==5))event_flavor=1; else if(FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)event_flavor=2; else if(FATjetHadronFlavor[1]==4 && FATsubjetSDHadronFlavor[1][0]==4 && FATsubjetSDHadronFlavor[1][1]==4)event_flavor=2; else event_flavor=3; th5[180]->Fill(nVtx,PU_weight[0]); th5[181]->Fill(ntrue,PU_weight[0]); th_flavor[event_flavor][180]->Fill(nVtx,PU_weight[0]); th_flavor[event_flavor][181]->Fill(ntrue,PU_weight[0]); //6. DEta----------------------------------------- float dEta = fabs(thisJet->Eta()-thatJet->Eta()); if(dEta>1.3)continue; nPass[6]+=PU_weight[0]; //7. Mjj----------------------------------------- float mjj = (*thisJet+*thatJet).M(); float mjjRed = (*thisJet+*thatJet).M()+250-thisJet->M()-thatJet->M(); if(mjjRed<1000)continue; nPass[7]+=PU_weight[0]; //8. fatjetPRmassL2L3Corr----------------------------------------- Float_t* fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr"); Float_t* FATjetPuppiSDmassL2L3Corr = data.GetPtrFloat("FATjetPuppiSDmassL2L3Corr"); Float_t* FATjetPRmass = data.GetPtrFloat("FATjetPRmass"); Float_t* FATjetPuppiSDmass = data.GetPtrFloat("FATjetPuppiSDmass"); vector<float> *subjetSDCSV = data.GetPtrVectorFloat("FATsubjetSDCSV"); vector<float> *subjetSDPx = data.GetPtrVectorFloat("FATsubjetSDPx", nFATJet); vector<float> *subjetSDPy = data.GetPtrVectorFloat("FATsubjetSDPy", nFATJet); vector<float> *subjetSDPz = data.GetPtrVectorFloat("FATsubjetSDPz", nFATJet); vector<float> *subjetSDE = data.GetPtrVectorFloat("FATsubjetSDE", nFATJet); int nbtag=0,nbtag2=0; float MaxBJetPt = 670., MaxLJetPt = 1000.; double sf[2][2],eta[2],pt[2],dr[2],subjetPt[2][2],subjetEta[2][2],eff[2][2],btaggingscaleFactor=1; pt[0]=thisJet->Pt(); pt[1]=thatJet->Pt(); TLorentzVector* subjetP4[2][2]; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ sf[i][j]=1; subjetP4[i][j]=new TLorentzVector(0,0,0,0); subjetP4[i][j]->SetPxPyPzE(subjetSDPx[i][j],subjetSDPy[i][j],subjetSDPz[i][j],subjetSDE[i][j]); subjetPt[i][j]=subjetP4[i][j]->Pt(); subjetEta[i][j]=subjetP4[i][j]->Eta(); } dr[i]=subjetP4[i][0]->DeltaR(*subjetP4[i][1]); } for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ //get btagging eff------------------------------------------------------------ int getPtBin=1; if(subjetPt[i][j]<140)getPtBin=1; else if (140<=subjetPt[i][j] && subjetPt[i][j]<180)getPtBin=2; else if (180<=subjetPt[i][j] && subjetPt[i][j]<240)getPtBin=3; else getPtBin=4; //if(FATsubjetSDHadronFlavor[i][j]==5)eff[i][j]=th1[1]->GetBinContent(getPtBin,ceil(subjetEta[i][j]/0.2)+15); //else if(FATsubjetSDHadronFlavor[i][j]==4)eff[i][j]=th1[3]->GetBinContent(getPtBin,ceil(subjetEta[i][j]/0.2)+15); //else eff[i][j]=th1[5]->GetBinContent(getPtBin,ceil(subjetEta[i][j]/0.2)+15); if(FATsubjetSDHadronFlavor[i][j]==5)eff[i][j]=th1[1]->GetBinContent(getPtBin); else if(FATsubjetSDHadronFlavor[i][j]==4)eff[i][j]=th1[3]->GetBinContent(getPtBin); else { int temp=0; if(subjetPt[i][j]>=900)temp=10; else temp=ceil(subjetPt[i][j]/100); bool checkBinContentIfZero=0; while(checkBinContentIfZero==0){ if(th1[4]->GetBinContent(temp)==0){ temp--; } else checkBinContentIfZero=1; } eff[i][j]=th1[5]->GetBinContent(temp); } //Get SF from csv------------------------------------------------------------ if(FATsubjetSDHadronFlavor[i][j]==5){ sf[i][j]=HF.eval_auto_bounds("central",BTagEntry::FLAV_B, subjetEta[i][j],subjetPt[i][j]); //sf[i][j]=HF.eval(BTagEntry::FLAV_B,subjetEta[i][j],subjetPt[i][j]); } else if(FATsubjetSDHadronFlavor[i][j]==4){ sf[i][j]=HFC.eval_auto_bounds("central",BTagEntry::FLAV_C, subjetEta[i][j],subjetPt[i][j]); //sf[i][j]=HF.eval(BTagEntry::FLAV_C,subjetEta[i][j],subjetPt[i][j]); } else { sf[i][j]=LF.eval_auto_bounds("central",BTagEntry::FLAV_UDSG, subjetEta[i][j],subjetPt[i][j]); //sf[i][j]=LF.eval(BTagEntry::FLAV_UDSG,subjetEta[i][j],subjetPt[i][j]); } //conut nbtag--------------------------------------------------------- if(subjetSDCSV[i][j]>0.46)nbtag++; //get tot. btagging SF if(subjetSDCSV[i][j]>=0.46)btaggingscaleFactor*=sf[i][j]; else btaggingscaleFactor*=((1-eff[i][j]*sf[i][j])/(1-eff[i][j])); } } if(nameRoot==2)btaggingscaleFactor=1; double scaleFactor=PU_weight[0]*btaggingscaleFactor; Float_t* fatjetTau1 = data.GetPtrFloat("FATjetTau1"); Float_t* fatjetTau2 = data.GetPtrFloat("FATjetTau2"); Float_t* FATjetPuppiTau1 = data.GetPtrFloat("FATjetPuppiTau1"); Float_t* FATjetPuppiTau2 = data.GetPtrFloat("FATjetPuppiTau2"); double tau21[2]; tau21[0]=(fatjetTau2[0]/fatjetTau1[0]),tau21[1]=(fatjetTau2[1]/fatjetTau1[1]); double puppiTau21[2]; puppiTau21[0]=(FATjetPuppiTau2[0]/FATjetPuppiTau1[0]),puppiTau21[1]=(FATjetPuppiTau2[1]/FATjetPuppiTau1[1]); for (int i=0;i<2;i++){ th5[214+i]->Fill(FATjetPRmass[i],scaleFactor); th5[216+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th5[218+i]->Fill(FATjetPuppiSDmass[i],scaleFactor); th5[220+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th5[238+i]->Fill(tau21[i],scaleFactor); th5[240+i]->Fill(puppiTau21[i],scaleFactor); th_flavor[event_flavor][214+i]->Fill(FATjetPRmass[i],scaleFactor); th_flavor[event_flavor][216+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][218+i]->Fill(FATjetPuppiSDmass[i],scaleFactor); th_flavor[event_flavor][220+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][238+i]->Fill(tau21[i],scaleFactor); th_flavor[event_flavor][240+i]->Fill(puppiTau21[i],scaleFactor); } if(!(tau21[0]>0.6 || tau21[1]>0.6)){ for (int i=0;i<2;i++){ th5[222+i]->Fill(FATjetPRmass[i],scaleFactor); th5[224+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th5[226+i]->Fill(FATjetPuppiSDmass[i],scaleFactor); th5[228+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th5[242+i]->Fill(tau21[i],scaleFactor); th5[244+i]->Fill(puppiTau21[i],scaleFactor); th_flavor[event_flavor][222+i]->Fill(FATjetPRmass[i],scaleFactor); th_flavor[event_flavor][224+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][226+i]->Fill(FATjetPuppiSDmass[i],scaleFactor); th_flavor[event_flavor][228+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][242+i]->Fill(tau21[i],scaleFactor); th_flavor[event_flavor][244+i]->Fill(puppiTau21[i],scaleFactor); } } if(fatjetPRmassL2L3Corr[0]<105||fatjetPRmassL2L3Corr[0]>135)continue; if(fatjetPRmassL2L3Corr[1]<105||fatjetPRmassL2L3Corr[1]>135)continue; nPass[8]+=PU_weight[0]; for (int i=0;i<2;i++){ th5[230+i]->Fill(FATjetPRmass[i],scaleFactor); th5[232+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th5[234+i]->Fill(FATjetPuppiSDmass[i],scaleFactor); th5[236+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th5[246+i]->Fill(tau21[i],scaleFactor); th5[248+i]->Fill(puppiTau21[i],scaleFactor); th_flavor[event_flavor][230+i]->Fill(FATjetPRmass[i],scaleFactor); th_flavor[event_flavor][232+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][234+i]->Fill(FATjetPuppiSDmass[i],scaleFactor); th_flavor[event_flavor][236+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][246+i]->Fill(tau21[i],scaleFactor); th_flavor[event_flavor][248+i]->Fill(puppiTau21[i],scaleFactor); } //9.----------------------------------------- if(tau21[0]>0.6 || tau21[1]>0.6) continue; nPass[9]+=PU_weight[0]; double tau21_SF=1.031*0.881; if(JESOption==5)tau21_SF=(1.031+0.126)*(0.881+0.49); if(JESOption==6)tau21_SF=(1.031-0.126)*(0.881-0.49); if(tau21[0]<0.6 && tau21[1]<0.6 ){ tau21_SF=1.031*1.031; if(JESOption==5)tau21_SF=(1.031+0.126)*(1.031+0.126); if(JESOption==6)tau21_SF=(1.031-0.126)*(1.031-0.126); } //10.btag //uncertainty ------------------------------------- //double scaleFactor=btaggingscaleFactor*PU_weight[0]*tau21_SF; for(int i=0;i<3;i++){ passPileup[i]+=btaggingscaleFactor*PU_weight[i]*tau21_SF; th7[i]->Fill(mjj,btaggingscaleFactor*PU_weight[i]*tau21_SF); } for(int i=0;i<101;i++)passPDF[i]+=btaggingscaleFactor*PU_weight[0]*tau21_SF; for(int i=5;i<14;i++)th7[i]->Fill(mjj,btaggingscaleFactor*PU_weight[0]*tau21_SF); fixScaleNum[1]+=PU_weight[0]; //-------------------------------------- Float_t FATjetPuppiSDmassThea[2] ={0}; FATjetPuppiSDmassThea[0]=FATjetPuppiSDmass[0]*getPUPPIweight(thisJet->Pt(),thisJet->Eta(),tf1); FATjetPuppiSDmassThea[1]=FATjetPuppiSDmass[1]*getPUPPIweight(thatJet->Pt(),thatJet->Eta(),tf1); eta[0]=thisJet->Eta(); eta[1]=thatJet->Eta(); Float_t* ADDjet_DoubleSV = data.GetPtrFloat("ADDjet_DoubleSV"); Float_t FATjet_DoubleSV[2]={0}; Int_t ADDnJet = data.GetInt("ADDnJet"); bool matchThis=0,matchThat=0; TClonesArray* ADDjetP4 = (TClonesArray*) data.GetPtrTObject("ADDjetP4"); for(int i=0;i<ADDnJet;i++){ TLorentzVector* thisAddJet ; thisAddJet= (TLorentzVector*)ADDjetP4->At(i); if(!matchThis && thisAddJet->DeltaR(*thisJet)<0.8){ matchThis=1; FATjet_DoubleSV[0]=ADDjet_DoubleSV[i]; continue; } if(!matchThat && thisAddJet->DeltaR(*thatJet)<0.8){ matchThat=1; FATjet_DoubleSV[1]=ADDjet_DoubleSV[i]; } if(matchThis&& matchThat)break; } Float_t* FATjetCISVV2 = data.GetPtrFloat("FATjetCISVV2"); for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ th5[(i*2+j)*5+nbtag]->Fill(subjetPt[i][j],scaleFactor); th5[(i*2+j)*5+nbtag+20]->Fill(subjetEta[i][j],scaleFactor); th5[(i*2+j)*5+nbtag+85]->Fill(subjetSDCSV[i][j],scaleFactor); if(subjetPt[i][j]>30 && fabs(subjetEta[i][j])<2.4)th5[(i*2+j)*5+nbtag+194]->Fill(subjetSDCSV[i][j],scaleFactor); th_flavor[event_flavor][(i*2+j)*5+nbtag]->Fill(subjetPt[i][j],scaleFactor); th_flavor[event_flavor][(i*2+j)*5+nbtag+20]->Fill(subjetEta[i][j],scaleFactor); th_flavor[event_flavor][(i*2+j)*5+nbtag+85]->Fill(subjetSDCSV[i][j],scaleFactor); if(subjetPt[i][j]>30 && fabs(subjetEta[i][j])<2.4)th_flavor[event_flavor][(i*2+j)*5+nbtag+194]->Fill(subjetSDCSV[i][j],scaleFactor); } th5[i*5+nbtag+40]->Fill(dr[i],scaleFactor); th5[i*5+nbtag+50]->Fill(pt[i],scaleFactor); th5[i*5+nbtag+60]->Fill(eta[i],scaleFactor); th5[i*5+nbtag+70]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th5[i*5+nbtag+105]->Fill(tau21[i],scaleFactor); th5[i*5+nbtag+120]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th5[i*5+nbtag+130]->Fill(puppiTau21[i],scaleFactor); th5[i*5+nbtag+140]->Fill(FATjetPRmass[i],scaleFactor); th5[i*5+nbtag+150]->Fill(FATjetPuppiSDmass[i],scaleFactor); th5[i*5+nbtag+170]->Fill(FATjet_DoubleSV[i],PU_weight[0]); th5[i*5+nbtag+184]->Fill(FATjetCISVV2[i],scaleFactor); th5[i*5+nbtag+250]->Fill(FATjetPuppiSDmassThea[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+40]->Fill(dr[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+50]->Fill(pt[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+60]->Fill(eta[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+70]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+105]->Fill(tau21[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+120]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+130]->Fill(puppiTau21[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+140]->Fill(FATjetPRmass[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+150]->Fill(FATjetPuppiSDmass[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+170]->Fill(FATjet_DoubleSV[i],PU_weight[0]); th_flavor[event_flavor][i*5+nbtag+184]->Fill(FATjetCISVV2[i],scaleFactor); th_flavor[event_flavor][i*5+nbtag+250]->Fill(FATjetPuppiSDmassThea[i],scaleFactor); } th5[nbtag+80]->Fill(mjj,scaleFactor); th5[nbtag+115]->Fill(dEta,scaleFactor); th5[nbtag+165]->Fill(mjjRed,scaleFactor); th_flavor[event_flavor][nbtag+80]->Fill(mjj,scaleFactor); th_flavor[event_flavor][nbtag+115]->Fill(dEta,scaleFactor); th_flavor[event_flavor][nbtag+165]->Fill(mjjRed,scaleFactor); nPass[nbtag+10]+=PU_weight[0]*btaggingscaleFactor; int nDoubleSV=0; if(FATjet_DoubleSV[0]>0.6)nDoubleSV++; if(FATjet_DoubleSV[1]>0.6)nDoubleSV++; if(nDoubleSV==0)nPass[15]+=PU_weight[0]; else if(nDoubleSV==2)nPass[17]+=PU_weight[0]; else { nPass[16]+=PU_weight[0]; if((FATjet_DoubleSV[0]>0.6 && subjetSDCSV[1][0]<0.46 && subjetSDCSV[1][1]<0.46) || (FATjet_DoubleSV[1]>0.6 && subjetSDCSV[0][0]<0.46 && subjetSDCSV[0][1]<0.46))nPass[18]+=PU_weight[0]; else if((FATjet_DoubleSV[0]>0.6 && subjetSDCSV[1][0]>0.46 && subjetSDCSV[1][1]>0.46) || (FATjet_DoubleSV[1]>0.6 && subjetSDCSV[0][0]>0.46 && subjetSDCSV[0][1]>0.46))nPass[20]+=PU_weight[0]; else nPass[19]+=PU_weight[0]; } th5[182]->Fill(nVtx,scaleFactor); th5[183]->Fill(ntrue,scaleFactor); th_flavor[event_flavor][182]->Fill(nVtx,scaleFactor); th_flavor[event_flavor][183]->Fill(ntrue,scaleFactor); }//end event loop---------------------------------------------------------------------------------------- } //end ntuple loop---------------------------------------------------------------------------------------- cout<<"entries="<<total<<endl; for(int i=0;i<22;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl; for(int i=0;i<3;i++)th7[3]->SetBinContent(i+1,passPileup[i]/totalPileup[i]); for(int i=0;i<101;i++)th7[4]->SetBinContent(i+1,passPDF[i]/totalPDF[i]); TH1D * th2o=new TH1D("Nbtagjet","Nbtagjet",5,-0.5,4.5); for (int i=0;i<5;i++){ if(nameRoot==2 && i>2)continue; th2o->SetBinContent(i+1,nPass[i+10]); } TH1D * fixScale=new TH1D("fixScale","fixScale",2,-0.5,1.5); fixScale->SetBinContent(1,fixScaleNum[0]); fixScale->SetBinContent(2,fixScaleNum[1]); TH1D * cutflow=new TH1D("cutflow","cutflow",21,0.5,21.5); cutflow->SetBinContent(1,fixScaleNum[0]); if(nameRoot!=2)for(int ii=1;ii<22;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]); else for(int ii=1;ii<16;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]); TFile* outFile ; if(JESOption==0)outFile= new TFile(Form("sf2/%s.root",st2.data()),"recreate"); else if(JESOption==1)outFile= new TFile(Form("sf2/%s_JESUp.root",st2.data()),"recreate"); else if(JESOption==2)outFile= new TFile(Form("sf2/%s_JESDown.root",st2.data()),"recreate"); else if(JESOption==3)outFile= new TFile(Form("sf2/%s_BtagUp.root",st2.data()),"recreate"); else if(JESOption==4)outFile= new TFile(Form("sf2/%s_BtagDown.root",st2.data()),"recreate"); else if(JESOption==5)outFile= new TFile(Form("sf2/%s_tau21Up.root",st2.data()),"recreate"); else if(JESOption==6)outFile= new TFile(Form("sf2/%s_tau21Down.root",st2.data()),"recreate"); th2o->Write(); fixScale->Write(); cutflow->Write(); for(int i=0;i<260;i++){ th5[i]->Write(); th_flavor[0][i]->Write(); th_flavor[1][i]->Write(); th_flavor[2][i]->Write(); th_flavor[3][i]->Write(); } for(int i=0;i<14;i++)th7[i]->Write(); outFile->Close(); }
// // // bool analysisClass::PreSelection(TString Process){ // int TotalN=0; int TotalTau=0; int TotalMu=0; int TotalEl=0; int TotalJet=0; int TotalBJet=0; TotalTau = TauCounter(); TotalMu = MuCounter(); TotalEl = ElCounter(); TotalJet = JetCounter(); TotalBJet = BJetCounter(); TotalN = TotalTau + TotalMu + TotalEl + TotalJet; // double LeadMuTauDeltaR=0; TLorentzVector Mu; TLorentzVector Tau; Mu.SetPtEtaPhiM(0,0,0,0); Tau.SetPtEtaPhiM(0,0,0,0); for(unsigned int iTauR=0; iTauR<HPSTauPt->size(); iTauR++){ if( !tauRisoCheck(iTauR) )continue; if( tauPtcorr(iTauR)>Tau.Pt() ){ Tau.SetPtEtaPhiM(tauPtcorr(iTauR), HPSTauEta->at(iTauR), HPSTauPhi->at(iTauR), 0); } } for(unsigned int iMuR=0; iMuR<MuonPt->size(); iMuR++){ if( !muRisoCheck(iMuR) )continue; if( muPtcorr(iMuR)>Mu.Pt() ){ Mu.SetPtEtaPhiM(muPtcorr(iMuR), MuonEta->at(iMuR), MuonPhi->at(iMuR), 0); } } if( TotalMu>0 && TotalTau>0 ) LeadMuTauDeltaR=Mu.DeltaR(Tau); // // if( Process != "Neutr" && Process != "Neutr2Jet" && Process != "NeutrNoQCD" && Process != "Neutr2JetNoQCD" && Process != "Neutr2Jet250ST" && Process != "Neutr2Jet250STtuneZ" && Process != "Neutr0Btag" && Process != "Neutr0BtagNoQCD" && Process != "Neutr2Jet350STtuneZ" && Process != "Neutr1Jet350STtuneZ" && Process != "Neutr1Jet350ST" && Process != "Neutr1Jet300ST" && Process != "Neutr1Jet500ST" && Process != "ZToMuMuAnalysis" && Process != "ZToMuTauAnalysis" && Process != "TTBar" && Process != "WJets" && Process != "FakeTaus" && Process != "ControlRegion1" && Process != "FakeMuons" && Process != "FakeMuonsV2" && Process != "FakeMuonsV3" && Process != "ZJets" && Process != "QCD" && Process != "LQ3M400" ){ return false; } // if( Process == "Neutr" ){ //if( MaxDiLepInvMass()<55 ) return false; if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; //if( isZToMuMu() ) return false;//required to exclude events in MuTrig Calculation if( TotalJet<1 ) return false; } if( Process == "Neutr2Jet" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; if( TotalJet<2 ) return false; } if( Process == "Neutr2Jet250ST" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; if( TotalJet<2 ) return false; if( ST()<250 ) return false; } if( Process == "Neutr2Jet250STtuneZ" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<55 ) return false; if( MaxMuTauInvMass()>0 && MaxMuTauInvMass()<55 ) return false; if( MaxTauTauInvMass()>0 && MaxTauTauInvMass()<55 ) return false; if( TotalJet<2 ) return false; if( ST()<250 ) return false; } if( Process == "Neutr2Jet350STtuneZ" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<55 ) return false; if( MaxMuTauInvMass()>0 && MaxMuTauInvMass()<55 ) return false; if( MaxTauTauInvMass()>0 && MaxTauTauInvMass()<55 ) return false; if( TotalJet<2 ) return false; if( ST()<350 ) return false; } if( Process == "Neutr1Jet350STtuneZ" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<55 ) return false; if( MaxMuTauInvMass()>0 && MaxMuTauInvMass()<55 ) return false; if( MaxTauTauInvMass()>0 && MaxTauTauInvMass()<55 ) return false; if( TotalJet<1 ) return false; if( ST()<350 ) return false; } if( Process == "Neutr1Jet350ST" ){ if( TotalJet<1 ) return false; if( ST()<350 ) return false; } if( Process == "Neutr1Jet500ST" ){ if( TotalJet<1 ) return false; if( ST()<500 ) return false; } if( Process == "Neutr1Jet300ST" ){ if( TotalJet<1 ) return false; if( ST()<300 ) return false; } if( Process == "Neutr0Btag"){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; if( TotalBJet>0 ) return false; } if( Process == "Neutr0BtagNoQCD"){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; if( TotalBJet>0 ) return false; if( METlepMT("Mu")<75 ) return false; } if( Process == "NeutrNoQCD" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; if( isZToMuMu() ) return false;//required to exclude events in MuTrig Calculation if( TotalJet<1 ) return false; if( METlepMT("Mu")<60 ) return false; } if( Process == "Neutr2JetNoQCD" ){ if( MaxMuMuInvMass()>0 && MaxMuMuInvMass()<50 ) return false; if( isZToMuMu() ) return false;//required to exclude events in MuTrig Calculation if( TotalJet<2 ) return false; if( METlepMT("Mu")<60 ) return false; } // if( Process == "FakeTaus" ){ if( TotalBJet>0 ) return false; if( METlepMT("Mu")<40 ) return false; if( TotalJet<1 ) return false; //if( RecoSignalType()!=-2110 ) return false;//this is mu,tau opp sign if( RecoSignalType()!=+2110 ) return false;//this is mu,tau same sign if( MaxMuTauInvMass()<80 ) return false; // if( !isOneMuonSuperIso() ) return false; } if( Process == "ZToMuTauAnalysis" ){ if( MaxMuTauInvMass()<20 ) return false; if( TotalBJet>0 ) return false; if( METlepMT("Mu")>40 ) return false; if( METlepMT("Tau")>90 ) return false; if( TotalJet<1 ) return false; if( RecoSignalType()!=-2110 ) return false;//this is mu,tau opp sign if( MuTaudeltaPzeta()<-15 ) return false; // if( !isOneMuonSuperIso() ) return false; // if( MaxMuTauInvMass()<45 || MaxMuTauInvMass()>75 ) return false; } if( Process == "ZToMuMuAnalysis" ){ double MaxMuMuInvMass_ = MaxMuMuInvMass(); double LeadingMuPt_ =LeadingMuPt(); if( LeadingMuPt_<35 ) return false;//LJ filter if( MaxMuMuInvMass_<80 || MaxMuMuInvMass_>100 ) return false; if( TotalJet<1 ) return false; if( ST()<300 ) return false; if( TotalBJet>0 ) return false; if( RecoSignalType()!=-2020 ) return false;//this is mu,mu opp sign } if( Process == "FakeMuons" ){ double LeadingMuPt_ = LeadingMuPt(); if( LeadingMuPt_<35 ) return false;//LJ filter if( TotalJet<1 ) return false; double LeadingJetPt_ = LeadingJetPt(); if( LeadingJetPt_<50 ) return false; if( ST()<400 ) return false; if( METlepMT("Mu")>20 ) return false; if( METcorr("Pt")>20 ) return false; //if( TotalBJet>0 ) return false; if( abs(RecoSignalType())!=1010 ) return false;//this is one mu } if( Process == "FakeMuonsV2" ){ ////double LeadingMuPt_ = LeadingMuPt(); ////if( LeadingMuPt_<35 ) return false;//LJ filter removed if( TotalJet<1 ) return false; //double LeadingJetPt_ = LeadingJetPt(); //if( LeadingJetPt_<50 ) return false; //if( !isZToMuMu() ) return false; //if( ST()>350 ) return false; if( METlepMT("Mu")>20 ) return false; if( METcorr("Pt")>20 ) return false; if( abs(RecoSignalType())!=1010 ) return false;//this is one mu } if( Process == "FakeMuonsV3" ){ if( METlepMT("Mu")>10 ) return false; if( METcorr("Pt")>10 ) return false; if( TotalJet<1 ) return false;// if( abs(RecoSignalType())!=1010 ) return false;//this is one mu if( !isAllMuonsHLT() ) return false;//mu has to match the trigger // //--------- Veto on 2nd Global Muon --------------------- int nGlobalMuons=0; for(unsigned int iMuR=0; iMuR<MuonPt->size(); iMuR++){ if( muPtcorr(iMuR)>MuonPtCut && fabs(MuonEta->at(iMuR))<2.1 && MuonIsGlobal->at(iMuR)==1 ) nGlobalMuons++; } if( nGlobalMuons>1 ) return false; // //--------- Check for back-to-back Jet-Muon ------------- bool isBackToBackJet=false; TLorentzVector Mu; TLorentzVector Jet; for(unsigned int iMuR=0; iMuR<MuonPt->size(); iMuR++){ if( !muRisoCheck(iMuR) ) continue; Mu.SetPtEtaPhiM(muPtcorr(iMuR), MuonEta->at(iMuR), MuonPhi->at(iMuR), 0); for(unsigned int iJetR=0; iJetR<PFJetPt->size(); iJetR++){ if( !jetRTightCheck(iJetR) ) continue; Jet.SetPtEtaPhiM( jetPtcorr(iJetR), PFJetEta->at(iJetR), PFJetPhi->at(iJetR), 0 ); if( (fabs(fabs(Mu.DeltaPhi(Jet))-TMath::Pi())/TMath::Pi())<0.1 ) isBackToBackJet=true; } } //--------- Check for back-to-back Jet-Muon ------------- if( !isBackToBackJet ) return false; } if( Process == "ControlRegion1" ){ //low in signal contamination, to check tau fakes loose->tight ratio if( TotalBJet<1 ) return false; if( TotalJet<2 ) return false; ///ST cut reverted ///remove MaxMuTauInvMass CUT: /*if( MaxMuTauInvMass()<100 ) return false;*/ if( LeadingTauPt()<50 ) return false; if( RecoSignalType()!=2110 ) return false;// SS selection if( isZToMuMu() ) return false;// required to exclude events in MuTrig Calculation // if( ST()>400 ) return false;// Revert the ST cut } if( Process == "TTBar" ){ double ZToMuMuCentral = 90; double ZToMuTauCentral = 75; if( MaxDiLepInvMass()<65 ) return false; if( TotalN<5 ) return false; if( ST()<250 ) return false; if( RecoSignalType()>0 ) return false; if( TotalJet<3 ) return false; if( fabs(MuTauInZpeak("ZToMuMu")-ZToMuMuCentral)<10 ) return false; //exclue 80-100 if( fabs(MuTauInZpeak("ZToMuTau")-ZToMuTauCentral)<15 ) return false; //exclude 60-90 } if( Process == "WJets" ){ double ZToMuMuCentral = 90; double ZToMuTauCentral = 75; if( MaxDiLepInvMass()<65 ) return false; if( TotalMu!=1 ) return false; if( TotalJet!=0 ) return false; if( ST()>250 ) return false; if( fabs(MuTauInZpeak("ZToMuMu")-ZToMuMuCentral)<10 ) return false; //exclue 80-100 if( fabs(MuTauInZpeak("ZToMuTau")-ZToMuTauCentral)<15 ) return false; //exclude 60-90 } if( Process == "ZJets" ){ if( MaxDiLepInvMass()<65 ) return false; if( METlepMT("Mu")>50 ) return false; if( TotalMu < 2 ) return false; double ZToMuMuCentral = 90; double ZToMuTauCentral = 75; bool dilepZpeak_ = false; if( fabs(MuTauInZpeak("ZToMuMu")-ZToMuMuCentral)<10 ) dilepZpeak_=true; //accept 80-100 if( fabs(MuTauInZpeak("ZToMuTau")-ZToMuTauCentral)<15 ) dilepZpeak_=true; //accept 60-90 if( !dilepZpeak_ ) return false; } if( Process == "LQ3M400" ){ if( MaxDiLepInvMass()<65 ) return false; if( LeadMuTauDeltaR>4 ) return false; if( TotalN<4 ) return false; if( METcorr("Pt")<30 ) return false; if( ST()<400 ) return false; if( RecoSignalType()<0 ) return false; } // return true; // }
void plotMsingle_qlike::Loop() { TH1F * h_mass_lik = new TH1F("h_mass_lik","h_mass_lik", 100, 0, 200); TH1F * h_mass_ref = new TH1F("h_mass_ref","h_mass_ref", 100, 0, 200); TH1F * h_mass_csv = new TH1F("h_mass_csv","h_mass_csv", 100, 0, 200); TH1F * h_mass_lik_pt100 = new TH1F("h_mass_lik_pt100","h_mass_lik_pt100", 100, 0, 200); TH1F * h_mass_ref_pt100 = new TH1F("h_mass_ref_pt100","h_mass_ref_pt100", 100, 0, 200); TH1F * h_mass_csv_pt100 = new TH1F("h_mass_csv_pt100","h_mass_csv_pt100", 100, 0, 200); TH1F * h_blik = new TH1F("h_blik","h_blik",100, -1, 1); TH1F * h_blik_match = new TH1F("h_blik_match","h_blik_match",100, -1, 1); Float_t presel = 0.; Float_t bb_efficiency_find = 0; Int_t loopJet_max; if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); float cont_1m=0,cont_2m=0, cont_1m_=0, cont_2m_=0, nevent=0; float cont_1q=0,cont_2q=0, cont_1q_=0, cont_2q_=0; 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; JetList jetList_CSV, jetList_bl, jetList_ql; float jet_isMatched2=0, jet_isMatched=0; float jet_isMatched2Q=0, jet_isMatchedQ=0; if (!((Jet_pt[0]>92.)&&(Jet_pt[1]>76.)&&(Jet_pt[2]>64.)&&(Jet_pt[3]>30.))) continue; int loopJet_min = 4; if (nJet<4) loopJet_min=nJet; Double_t btag_max = 0.7; int btag_max1_number = -1; int btag_max2_number = -1; for (int i=0;i<loopJet_min;i++){ if ((Jet_btagCSV[i]>btag_max)&&(Jet_id[i]>0)){ btag_max=Jet_btagCSV[i]; btag_max1_number=i; } } if (!((btag_max1_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]); int pt_max1_number = -1; int pt_max2_number = -1; TLorentzVector js[3]; int jcount = 0; int j_num[3] = {}; for (int i=0;i<4;i++){ if ((i!=btag_max1_number)&&(Jet_id[i]>0)) { js[jcount].SetPtEtaPhiM(Jet_pt[jcount], Jet_eta[jcount], Jet_phi[jcount], Jet_mass[jcount]); j_num[jcount] = i; jcount++; } } Float_t deltaEtaJets[3] = {TMath::Abs(js[0].Eta()-js[1].Eta()),TMath::Abs(js[1].Eta()-js[2].Eta()), TMath::Abs(js[0].Eta()-js[2].Eta())}; int eta_num[3][2] = {{0,1}, {1,2} ,{0,2}}; Float_t max_deltaEta = 0.; int max_deltaEta_num = -1; for (int i=0;i<3;i++){ if (deltaEtaJets[i]>max_deltaEta) { max_deltaEta = deltaEtaJets[i]; max_deltaEta_num = i; } } pt_max1_number = j_num[ eta_num[max_deltaEta_num][0]]; pt_max2_number = j_num[ eta_num[max_deltaEta_num][1]]; 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]); for (int i=0;i<4;i++){ if ( (i!=btag_max1_number)&&(i!=pt_max1_number)&&(i!=pt_max2_number)&&(Jet_id[i]>0)) btag_max2_number=i; } if (!((btag_max2_number>=0))) continue; TLorentzVector Bjet2; Bjet2.SetPtEtaPhiM(Jet_pt[btag_max2_number],Jet_eta[btag_max2_number],Jet_phi[btag_max2_number],Jet_mass[btag_max2_number]); TLorentzVector qq; qq = Qjet1+Qjet2; Double_t Mqq = qq.M(); Double_t bbDeltaPhi = TMath::Abs(Bjet1.DeltaPhi(Bjet2)); Double_t qqDeltaEta = TMath::Abs(Qjet1.Eta()-Qjet2.Eta()); if (!((Mqq>460)&&(qqDeltaEta>4.1)&&(bbDeltaPhi<1.6))) continue; if (HLT_BIT_HLT_QuadPFJet_SingleBTagCSV_VBF_Mqq460_v!=1) continue; presel+=TMath::Sign(1.,genWeight); int loopJet_max; if (nJet<5) loopJet_max = nJet; else loopJet_max = 5; for(int i=0; i<loopJet_max; i++){ if(Jet_pt[i]<20 || Jet_id[i] <0) continue; jetList_CSV[Jet_btagCSV[i]]=i; jetList_bl[Jet_blikelihood_b[i]]=i; jetList_ql[Jet_blikelihood_q[i]]=i; h_blik->Fill(Jet_blikelihood_b[i]); } int found_array[15] = {}; int found_idx=0; Float_t bb_found = 0; for(int i=0; i<loopJet_max; i++){ if(Jet_pt[i]<20 || Jet_id[i] <0) continue; TLorentzVector hJall; hJall.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); for(int j =0; j<2; j++){ if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5){ TLorentzVector hJet; hJet.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]); if(hJet.DeltaR(hJall)<0.8) {found_array[found_idx] = i; found_idx++; bb_found++;}; } } } int cont=0; TLorentzVector hJ0, hJ1; JetList::reverse_iterator iJet=jetList_bl.rbegin(); do{ int i = iJet->second; if(cont==0) hJ0.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); if(cont==1) hJ1.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); cont++; iJet++; h_blik->Fill(iJet->first); }while (cont<2); cont=0; TLorentzVector hQ0, hQ1; JetList::reverse_iterator iJet0=jetList_ql.rbegin(); do{ int i = iJet0->second; if(cont==0) hQ0.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); if(cont==1) hQ1.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); cont++; iJet0++; }while (cont<2); for(int j =0; j<2; j++){ if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5) { TLorentzVector hQ; hQ.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]); if((hQ.DeltaR(hJ1)<0.8 || hQ.DeltaR(hJ0)<0.8)) jet_isMatched++; } } if (bb_found>=2) bb_efficiency_find+=TMath::Sign(1.,genWeight); for(int j =0; j<2; j++){ TLorentzVector hQ; hQ.SetPtEtaPhiM(GenHiggsSisters_pt[j],GenHiggsSisters_eta[j],GenHiggsSisters_phi[j],GenHiggsSisters_mass[j]); if((hQ.DeltaR(hQ0)<0.8)||(hQ.DeltaR(hQ1)<0.8)) jet_isMatchedQ++; } int cont1=0; TLorentzVector hJ00, hJ11; for (JetList::reverse_iterator iJet=jetList_CSV.rbegin(); iJet!=jetList_CSV.rend(); ++iJet) { int i = iJet->second; if(cont1==0) hJ00.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); if(cont1==1) hJ11.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); if (cont1>1) continue; cont1++; } for(int j =0; j<2; j++){ if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5) { TLorentzVector hQ; hQ.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]); if(hQ.DeltaR(hJ00)<0.8 || hQ.DeltaR(hJ11)<0.8) jet_isMatched2++; } } TLorentzVector hQ00, hQ11; hQ00.SetPtEtaPhiM(Jet_pt[pt_max1_number],Jet_eta[pt_max1_number],Jet_phi[pt_max1_number],Jet_mass[pt_max1_number]); hQ11.SetPtEtaPhiM(Jet_pt[pt_max2_number],Jet_eta[pt_max2_number],Jet_phi[pt_max2_number],Jet_mass[pt_max2_number]); for(int j =0; j<2; j++){ TLorentzVector hQ; hQ.SetPtEtaPhiM(GenHiggsSisters_pt[j],GenHiggsSisters_eta[j],GenHiggsSisters_phi[j],GenHiggsSisters_mass[j]); if((hQ.DeltaR(hQ00)<0.8)||(hQ.DeltaR(hQ11)<0.8)) jet_isMatched2Q++; } if(jet_isMatched==1) cont_1m+=TMath::Sign(1.,genWeight); if(jet_isMatched==2) cont_2m+=TMath::Sign(1.,genWeight); if (jet_isMatched2!=2) { for (int k=0;k<found_idx;k++){ // cout<<"event number = "<< jentry<< " not matched = " <<found_array[k]<<" , "; } // cout<<endl; } if(jet_isMatched2==1) cont_1m_+=TMath::Sign(1.,genWeight); if(jet_isMatched2==2) cont_2m_+=TMath::Sign(1.,genWeight); if(jet_isMatchedQ==1) cont_1q+=TMath::Sign(1.,genWeight); if(jet_isMatchedQ==2) cont_2q+=TMath::Sign(1.,genWeight); if(jet_isMatched2Q==1) cont_1q_+=TMath::Sign(1.,genWeight); if(jet_isMatched2Q==2) cont_2q_+=TMath::Sign(1.,genWeight); nevent++; h_mass_lik->Fill((hJ0+hJ1).M()); h_mass_csv->Fill((hJ00+hJ11).M()); h_mass_ref->Fill(H_mass); if(V_pt>100) {h_mass_lik_pt100->Fill((hJ0+hJ1).M()); h_mass_csv_pt100->Fill((hJ00+hJ11).M()); h_mass_ref_pt100->Fill(H_mass); } } // std::cout<<" purity b-lik "<<cont_1m/nevent<< " 1/2 "<<cont_2m/nevent <<std::endl; // std::cout<<" purity csv "<<cont_1m_/nevent<< " 1/2 "<<cont_2m_/nevent <<std::endl; std::cout<<" preselection purity b-lik "<<cont_1m/presel<< " 1/2 "<<cont_2m/presel <<std::endl; std::cout<<" preselection purity csv "<<cont_1m_/presel<< " 1/2 "<<cont_2m_/presel << " , presel = "<< presel<<std::endl; std::cout<<" preselection purity q-lik "<<cont_1q/presel<< " 1/2 "<<cont_2q/presel <<std::endl; std::cout<<" preselection purity q_pt "<<cont_1q_/presel<< " 1/2 "<<cont_2q_/presel << " , presel = "<< presel<<std::endl; std::cout<<"bb efficiency to find = " << bb_efficiency_find/presel<<endl; gStyle->SetOptStat(0); TCanvas *c = new TCanvas("c","c",700,700); c->cd(); h_mass_lik->SetLineColor(4); h_mass_lik->GetXaxis()->SetTitle("m_{H} (GeV)"); h_mass_lik->SetTitle("b-likelihood order"); h_mass_lik->Draw(""); h_mass_csv->SetLineColor(2); h_mass_csv->SetTitle("csv order"); h_mass_csv->Draw("same"); h_mass_ref->SetTitle("highest dijet"); h_mass_ref->Draw("same"); c->Print("c.png"); TCanvas *c1 = new TCanvas("c1","c1",700,700); c1->cd(); h_mass_ref_pt100->GetXaxis()->SetTitle("m_{H} (GeV)"); h_mass_lik_pt100->SetTitle("b-likelihood order"); h_mass_csv_pt100->SetTitle("csv order"); h_mass_ref_pt100->SetTitle("csv order"); h_mass_lik_pt100->SetLineColor(4); h_mass_lik_pt100->Draw(""); h_mass_ref_pt100->Draw("same"); h_mass_csv_pt100->SetLineColor(2); h_mass_csv_pt100->Draw("same"); c1->Print("c1.png"); TCanvas *d = new TCanvas("d","d"); d->cd(); d->SetLogy(); h_blik->Draw(); d->Print("d.png"); }
void CreateTree::Loop() { if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; TFile file("spring15_vbf_powheg_new_blike_125_08.root","recreate"); TTree *tree0 = new TTree("Jet_tree_b","Jet_tree_b"); TreeJets TreeJet; tree0->Branch("Jet_pt",&TreeJet.pt,"Jet_pt/F"); tree0->Branch("Jet_eta",&TreeJet.eta,"Jet_eta/F"); tree0->Branch("Jet_btagCSV",&TreeJet.btagCSV,"Jet_btagCSV/F"); tree0->Branch("Jet_pt_idx",&TreeJet.pt_idx,"Jet_pt_idx/I"); tree0->Branch("Jet_eta_idx",&TreeJet.eta_idx,"Jet_eta_idx/I"); tree0->Branch("Jet_btagCSV_idx",&TreeJet.btagCSV_idx,"Jet_btagCSV_idx/I"); tree0->Branch("Jet_btag_idx",&TreeJet.btag_idx,"Jet_btag_idx/I"); tree0->Branch("Jet_chMult",&TreeJet.ch_mult,"Jet_chMult/I"); tree0->Branch("Jet_ptd",&TreeJet.ptd,"Jet_ptd/F"); tree0->Branch("Jet_leadTrackPt",&TreeJet.leadTrPt,"Jet_leadTrPt"); tree0->Branch("Jet_axis2",&TreeJet.axis2, "Jet_axis2"); tree0->Branch("Jet_b_matched",&TreeJet.b_matched,"Jet_b_matched/I"); tree0->Branch("Jet_q_matched",&TreeJet.q_matched,"Jet_q_matched/I"); tree0->Branch("Jet_n_matched",&TreeJet.n_matched,"Jet_n_matched/I"); Float_t bb_efficiency_find=0.; Float_t bb_efficiency=0.; Float_t qq_efficiency_find=0.; Float_t qq_efficiency=0.; Float_t presel =0.; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; JetList jetList_CSV, jetList_pt, jetList_eta; Float_t jet_isMatched2 = 0; Float_t jet_isMatchedQ = 0; if (genWeight<0) continue; if (!((Jet_pt[0]>92.)&&(Jet_pt[1]>76.)&&(Jet_pt[2]>64.)&&(Jet_pt[3]>30.))) continue; int loopJet_min = 6; if (nJet<6) loopJet_min=nJet; Double_t btag_max = 0.4; int btag_max1_number = -1; int btag_max2_number = -1; for (int i=0;i<loopJet_min;i++){ if ((Jet_btagCSV[i]>btag_max)&&(Jet_id[i]>0)){ btag_max=Jet_btagCSV[i]; btag_max1_number=i; } } btag_max = 0.4; for (int i=0;i<loopJet_min;i++){ if ((Jet_btagCSV[i]>btag_max)&&(i!=btag_max1_number)&&(Jet_id[i]>0)) { btag_max=Jet_btagCSV[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]); Double_t pt_max = 20.; int pt_max1_number = -1; int pt_max2_number = -1; for (int i=0;i<loopJet_min;i++){ if ((Jet_pt[i]>pt_max)&&(i!=btag_max1_number)&&(i!=btag_max2_number)&&(Jet_id[i]>0)) { pt_max=Jet_pt[i]; pt_max1_number=i; } } pt_max = 20.; for (int i=0;i<loopJet_min;i++){ if ((Jet_pt[i]>pt_max)&&(i!=btag_max1_number)&&(i!=btag_max2_number)&&(i!=pt_max1_number)&&(Jet_id[i]>0)) { 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; Double_t Mqq = qq.M(); Double_t bbDeltaPhi = TMath::Abs(Bjet1.DeltaPhi(Bjet2)); Double_t qqDeltaEta = TMath::Abs(Qjet1.Eta()-Qjet2.Eta()); if (!((Mqq>200)&&(qqDeltaEta>1.2)&&(bbDeltaPhi<2.4))) continue; if (HLT_BIT_HLT_QuadPFJet_DoubleBTagCSV_VBF_Mqq200_v!=1) continue; int loopJet_max = 7; if (nJet<7) loopJet_max = nJet; for(int i=0; i<loopJet_max; i++){ if(Jet_pt[i]<20 || Jet_id[i] <0) continue; if (Jet_btagCSV[i]==-10) Jet_btagCSV[i]=0; if (Jet_btagCSV[i]>1) Jet_btagCSV[i]=1.; jetList_CSV[Jet_btagCSV[i]]=i; jetList_pt[Jet_pt[i]]=i; jetList_eta[TMath::Abs(Jet_eta[i])]=i; } Float_t bb_found = 0.; Float_t qq_found = 0.; Float_t eta_sort[30]; Float_t btag_sort[30]; for (int i=0;i<loopJet_max;i++){ if ((Jet_pt[i]>20)&&(Jet_id[i]>0)) { TreeJet.eta = TMath::Abs(Jet_eta[i]); eta_sort[i] = TMath::Abs(Jet_eta[i]); TreeJet.btagCSV=Jet_btagCSV[i]; btag_sort[i] = Jet_btagCSV[i]; } } bubblesort(eta_sort,loopJet_max); bubblesort2(btag_sort,loopJet_max); /* for (int i=0;i<loopJet_max;i++){ cout<<btag_sort[i]<<" "<<i<<endl; }*/ int btag_0_num = 0; for(int i=0; i<loopJet_max; i++){ if(Jet_pt[i]<20 || Jet_id[i] <0) continue; TreeJet.b_matched=0; TreeJet.q_matched=0; TreeJet.n_matched=0; TLorentzVector hJ0; TreeJet.pt=Jet_pt[i]; TreeJet.eta=TMath::Abs(Jet_eta[i]); TreeJet.btagCSV=Jet_btagCSV[i]; TreeJet.ptd=Jet_ptd[i]; TreeJet.ch_mult=Jet_chMult[i]; TreeJet.axis2=Jet_axis2[i]; TreeJet.leadTrPt=Jet_leadTrackPt[i]; TreeJet.pt_idx = i; TreeJet.eta_idx = find(eta_sort,TreeJet.eta,loopJet_max); TreeJet.btagCSV_idx = find(btag_sort,TreeJet.btagCSV,loopJet_max); if ((TreeJet.btagCSV==0)&&(btag_0_num==0)) { btag_0_num = find(btag_sort,TreeJet.btagCSV,loopJet_max); TreeJet.btagCSV_idx = btag_0_num; } else if ((TreeJet.btagCSV==0)&&(btag_0_num!=0)) { btag_0_num++; TreeJet.btagCSV_idx = btag_0_num; } TreeJet.btag_idx = Jet_btagIdx[i]; hJ0.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); for(int j =0; j<2; j++){ if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5){ TLorentzVector hQQ; hQQ.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]); if(hQQ.DeltaR(hJ0)<0.8){ TreeJet.b_matched =1; bb_found++; } } } for(int j =0; j<2; j++){ TLorentzVector hQ; hQ.SetPtEtaPhiM(GenHiggsSisters_pt[j],GenHiggsSisters_eta[j],GenHiggsSisters_phi[j],GenHiggsSisters_mass[j]); if(hQ.DeltaR(hJ0)<0.8) {TreeJet.q_matched = 1; qq_found++;} } if ((TreeJet.b_matched==0)&&(TreeJet.q_matched==0)) TreeJet.n_matched=1; tree0->Fill(); } int cont1=0; TLorentzVector hJ00, hJ11; for (JetList::reverse_iterator iJet=jetList_CSV.rbegin(); iJet!=jetList_CSV.rend(); ++iJet) { int i = iJet->second; if(cont1==0) hJ00.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); if(cont1==1) hJ11.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]); if (cont1>1) continue; cont1++; } for(int j =0; j<2; j++){ if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5) { TLorentzVector hQ; hQ.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]); if(hQ.DeltaR(hJ00)<0.8 || hQ.DeltaR(hJ11)<0.8) jet_isMatched2++; } } TLorentzVector hQ00, hQ11; hQ00.SetPtEtaPhiM(Jet_pt[pt_max1_number],Jet_eta[pt_max1_number],Jet_phi[pt_max1_number],Jet_mass[pt_max1_number]); hQ11.SetPtEtaPhiM(Jet_pt[pt_max2_number],Jet_eta[pt_max2_number],Jet_phi[pt_max2_number],Jet_mass[pt_max2_number]); for(int j =0; j<2; j++){ TLorentzVector hQ; hQ.SetPtEtaPhiM(GenHiggsSisters_pt[j],GenHiggsSisters_eta[j],GenHiggsSisters_phi[j],GenHiggsSisters_mass[j]); if((hQ.DeltaR(hQ00)<0.8)||(hQ.DeltaR(hQ11)<0.8)) jet_isMatchedQ++; } if (jet_isMatched2==2) bb_efficiency+=TMath::Sign(1.,genWeight); if (jet_isMatchedQ==2) qq_efficiency+=TMath::Sign(1.,genWeight); if (bb_found>=2) bb_efficiency_find+=TMath::Sign(1.,genWeight); if (qq_found>=2) qq_efficiency_find+=TMath::Sign(1.,genWeight); presel+=TMath::Sign(1.,genWeight); } ofstream out("spring15_powheg_125_08.txt"); out<<"bb efficiency to find b-jets = "<<bb_efficiency_find/presel<<endl; out<<"bb efficiency to match b-jets = "<<bb_efficiency/presel<<endl; out<<"qq efficiency to find q-jets = "<<qq_efficiency_find/presel<<endl; out<<"qq efficiency to match q-jets = "<<qq_efficiency/presel<<endl; cout<<"bb efficiency to find b-jets = "<<bb_efficiency_find/presel<<endl; cout<<"bb efficiency to match b-jets = "<<bb_efficiency/presel<<endl; cout<<"qq efficiency to find q-jets = "<<qq_efficiency_find/presel<<endl; cout<<"qq efficiency to match q-jets = "<<qq_efficiency/presel<<endl; file.Write(); file.Close(); }
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 AK8CorrBase(int wMs,int wM, string st,string st2,string option=""){ //1=signal ,0=QCD ,2=data int nameRoot=1; if((st2.find("QCD")!= std::string::npos)|| (st2.find("bGen")!= std::string::npos)|| (st2.find("bEnriched")!= std::string::npos))nameRoot=0; if(st2.find("data")!= std::string::npos)nameRoot=2; bool fixGen=0; if(st2.find("B1000")!= std::string::npos)fixGen=1; cout<<"nameRoot = "<<nameRoot<<endl; //option----------------------------------------------------------- int JESOption=0; if(option.find("JESUp")!= std::string::npos)JESOption=1; if(option.find("JESDown")!= std::string::npos)JESOption=2; cout<<"JESOption = "<<JESOption<<endl; TFile *f; TTree *tree; int nPass[20]={0}; int total=0; TH1D* th1; th1=new TH1D("mass","mass",150,0,150); TH1D* th3; th3=new TH1D("mass","mass",1500,200,3200); double ptBins[14]={200,300,400,500,600,700,800,900,1000,1250,1500,1750,2000,2500}; TH1D* th2[6][14]; for(int i=0;i<14;i++){ th2[0][i]=(TH1D*)th1->Clone(Form("genBarelMass%.0f",ptBins[i])); th2[1][i]=(TH1D*)th1->Clone(Form("genEndcapMass%.0f",ptBins[i])); th2[2][i]=(TH1D*)th1->Clone(Form("recoBarelMass%.0f",ptBins[i])); th2[3][i]=(TH1D*)th1->Clone(Form("recoEndcapMass%.0f",ptBins[i])); th2[4][i]=(TH1D*)th3->Clone(Form("ptBarel%.0f",ptBins[i])); th2[5][i]=(TH1D*)th3->Clone(Form("ptEndcap%.0f",ptBins[i])); } for(int i=0;i<14;i++){ th2[0][i]->Sumw2(); th2[1][i]->Sumw2(); th2[2][i]->Sumw2(); th2[3][i]->Sumw2(); th2[4][i]->Sumw2(); th2[5][i]->Sumw2(); } //--------------------------------- for (int w=wMs;w<wM;w++){ if(w%20==0)cout<<w<<endl; if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w)); else f = TFile::Open(st.data()); if (!f || !f->IsOpen())continue; TDirectory * dir; if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w)); else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data())); dir->GetObject("treeMaker",tree); TreeReader data(tree); total+=data.GetEntriesFast(); for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){ if(jEntry%2)continue; data.GetEntry(jEntry); 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 genHIndex[2]={-1,-1}; int genbIndex[2][2]={{-1,-1}, {-1,-1}}; for(int ig=0; ig < nGenPar; ig++){ if(genParId[ig]!=25)continue; if(genHIndex[0]<0) { genHIndex[0]=ig; genbIndex[0][0]=genDa1[ig]; genbIndex[0][1]=genDa2[ig]; } else if(genHIndex[1]<0) { genHIndex[1]=ig; genbIndex[1][0]=genDa1[ig]; genbIndex[1][1]=genDa2[ig]; } } if(genHIndex[0]<0 || genHIndex[1]<0)continue; if(genbIndex[0][0]<0 || genbIndex[0][1]<0)continue; if(genbIndex[1][0]<0 || genbIndex[1][1]<0)continue; nPass[0]++; if(genHIndex[0]==genHIndex[1])continue; nPass[1]++; TLorentzVector genH_l4[2]; TLorentzVector genb_l4[2][2]; TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4"); for(int ih=0; ih<2; ih++) { genH_l4[ih] = *((TLorentzVector*)genParP4->At(genHIndex[ih])); for(int ib=0; ib<2; ib++) { genb_l4[ih][ib] = *((TLorentzVector*)genParP4->At(genbIndex[ih][ib])); } } TClonesArray* AK8PuppijetP4 = (TClonesArray*) data.GetPtrTObject("AK8PuppijetP4"); // check matching first bool findAK8Match=false; const float dRMax=0.4; const float dRbMax=0.8; int matchedHAK8JetIndex[2]={-1,-1}; int AK8nJet=data.GetInt("AK8PuppinJet"); if(AK8nJet<2)continue; bool matchb=1; for(int ij=0; ij<AK8nJet; ij++) { TLorentzVector* thisJet = (TLorentzVector*)AK8PuppijetP4->At(ij); for(int jj=0; jj<AK8nJet; jj++) { if(ij==jj)continue; TLorentzVector* thatJet = (TLorentzVector*)AK8PuppijetP4->At(jj); if(thisJet->DeltaR(genH_l4[0])<dRMax && (!matchb || (matchb && thisJet->DeltaR(genb_l4[0][0])<dRbMax && thisJet->DeltaR(genb_l4[0][1])<dRbMax)) && thatJet->DeltaR(genH_l4[1])<dRMax && (!matchb || (matchb && thatJet->DeltaR(genb_l4[1][0])<dRbMax && thatJet->DeltaR(genb_l4[1][1])<dRbMax))) { if(ij<jj){ matchedHAK8JetIndex[0]=ij; matchedHAK8JetIndex[1]=jj; } else { matchedHAK8JetIndex[0]=jj; matchedHAK8JetIndex[1]=ij; } findAK8Match=true; break; } if(findAK8Match)break; } if(findAK8Match)break; } if(!findAK8Match)continue; Float_t* AK8PuppijetGenSDmass; if(fixGen)AK8PuppijetGenSDmass= data.GetPtrFloat("AK8PuppijetSDmass"); else AK8PuppijetGenSDmass= data.GetPtrFloat("AK8PuppijetGenSDmass"); Float_t* AK8PuppijetSDmass = data.GetPtrFloat("AK8PuppijetSDmass"); int* AK8PuppinSubSDJet=data.GetPtrInt("AK8PuppinSubSDJet"); for(int i=0; i<2;i++){ int AK8jet=matchedHAK8JetIndex[i]; TLorentzVector* thisAK8Jet = (TLorentzVector*)AK8PuppijetP4->At(AK8jet); if(thisAK8Jet->Pt()<200)continue; if(fabs(thisAK8Jet->Eta())>2.4)continue; if(AK8PuppinSubSDJet[AK8jet]!=2)continue; th1->Fill(AK8PuppijetGenSDmass[AK8jet]); for(int j=0;j<13;j++){ if(thisAK8Jet->Pt()>ptBins[j] && thisAK8Jet->Pt()<ptBins[j+1]){ if(fabs(thisAK8Jet->Eta())<1.3){ th2[0][j]->Fill(AK8PuppijetGenSDmass[AK8jet]); th2[2][j]->Fill(AK8PuppijetSDmass[AK8jet]); th2[4][j]->Fill(thisAK8Jet->Pt()); } else{ th2[1][j]->Fill(AK8PuppijetGenSDmass[AK8jet]); th2[3][j]->Fill(AK8PuppijetSDmass[AK8jet]); th2[5][j]->Fill(thisAK8Jet->Pt()); } } } if(thisAK8Jet->Pt()>ptBins[13]){ if(fabs(thisAK8Jet->Eta())<1.3){ th2[0][13]->Fill(AK8PuppijetGenSDmass[AK8jet]); th2[2][13]->Fill(AK8PuppijetSDmass[AK8jet]); th2[4][13]->Fill(thisAK8Jet->Pt()); } else{ th2[1][13]->Fill(AK8PuppijetGenSDmass[AK8jet]); th2[3][13]->Fill(AK8PuppijetSDmass[AK8jet]); th2[5][13]->Fill(thisAK8Jet->Pt()); } } } } } cout<<"entries="<<total<<endl; TFile* outFile ; outFile= new TFile(Form("corr2/%s.root",st2.data()),"recreate"); th1->Write(); for(int i=0;i<14;i++){ th2[0][i]->Write(); th2[1][i]->Write(); th2[2][i]->Write(); th2[3][i]->Write(); th2[4][i]->Write(); th2[5][i]->Write(); } outFile->Close(); }
void csvSF_treeReader_13TeV( bool isHF=1, int verNum = 0, int insample=1, int maxNentries=-1, int Njobs=1, int jobN=1, double intLumi=-1 ) { std::string inputFileHF = "data/csv_rwt_hf_IT.root"; std::string inputFileLF = "data/csv_rwt_lf_IT.root"; if( verNum>0 ){ inputFileHF = Form("CSVHistoFiles/csv_rwt_fit_hf_v%i.root", verNum-1); inputFileLF = Form("CSVHistoFiles/csv_rwt_fit_lf_v%i.root", verNum-1); std::cout << "\t inputFileHF = " << inputFileHF << std::endl; std::cout << "\t inputFileLF = " << inputFileLF << std::endl; } TFile* f_CSVwgt_HF = new TFile ((string(getenv("CMSSW_BASE")) + "/src/ttH-LeptonPlusJets/AnalysisCode/" + inputFileHF).c_str()); TFile* f_CSVwgt_LF = new TFile ((string(getenv("CMSSW_BASE")) + "/src/ttH-LeptonPlusJets/AnalysisCode/" + inputFileLF).c_str()); fillCSVhistos(f_CSVwgt_HF, f_CSVwgt_LF); std::cout << " ###===> iteration version " << verNum << std::endl; //// std::cout << " ===> load the root files! " << std::endl; std::string sampleType = ( insample>=0 ) ? "mc" : "data"; std::string str_jobN; std::stringstream stream; stream << jobN; str_jobN = stream.str(); //https://twiki.cern.ch/twiki/bin/viewauth/CMS/StandardModelCrossSectionsat13TeV double mySample_xSec_ = 1.; double mySample_nGen_ = 1.; std::string mySample_sampleName_ = "delete"; std::string mySample_inputDir_ = ""; if( insample==2500 ){ mySample_xSec_ = 831.76;//https://twiki.cern.ch/twiki/bin/view/LHCPhysics/TtbarNNLO mySample_nGen_ = 25446993; mySample_sampleName_ = "TTJets"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TTJets_MSDecaysCKM_central_Tune4C_13TeV-madgraph-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_005136/0000/"; //mySample_inputDir_ = "/uscms_data/d2/dpuigh/TTH/miniAOD/CMSSW_7_2_3/src/ttH-LeptonPlusJets/YggdrasilTreeMaker/"; } else if( insample==2300 ){ mySample_xSec_ = 2008.4; mySample_nGen_ = 2829164; mySample_sampleName_ = "DYJetsToLL"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/DYJetsToLL_M-50_13TeV-madgraph-pythia8/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150216_233924/0000/"; } else if( insample==2400 ){ mySample_xSec_ = 20508.9; mySample_nGen_ = 10017462; mySample_sampleName_ = "WJetsToLNu"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/WJetsToLNu_13TeV-madgraph-pythia8-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_010312/0000/"; } else if( insample==2524 ){ mySample_xSec_ = 1.152; mySample_nGen_ = 246521; mySample_sampleName_ = "TTWJets"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TTWJets_Tune4C_13TeV-madgraph-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_005352/0000/"; } else if( insample==2523 ){ mySample_xSec_ = 2.232; mySample_nGen_ = 249275; mySample_sampleName_ = "TTZJets"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TTZJets_Tune4C_13TeV-madgraph-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_005607/0000/"; } else if( insample==2510 ){ mySample_xSec_ = 2.232; mySample_nGen_ = 500000; mySample_sampleName_ = "TToLeptons_s"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TToLeptons_s-channel-CSA14_Tune4C_13TeV-aMCatNLO-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_005853/0000/"; } else if( insample==2511 ){ mySample_xSec_ = 2.232; mySample_nGen_ = 250000; mySample_sampleName_ = "TBarToLeptons_s"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TBarToLeptons_s-channel-CSA14_Tune4C_13TeV-aMCatNLO-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_004555/0000/"; } else if( insample==2512 ){ mySample_xSec_ = 2.232; mySample_nGen_ = 3991000; mySample_sampleName_ = "TToLeptons_t"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TToLeptons_t-channel-CSA14_Tune4C_13TeV-aMCatNLO-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_005929/0000/"; } else if( insample==2513 ){ mySample_xSec_ = 2.232; mySample_nGen_ = 1999800; mySample_sampleName_ = "TBarToLeptons_t"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TBarToLeptons_t-channel_Tune4C_CSA14_13TeV-aMCatNLO-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_004732/0000/"; } else if( insample==2514 ){ mySample_xSec_ = 35.6; mySample_nGen_ = 986100; mySample_sampleName_ = "T_tW_DR"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/T_tW-channel-DR_Tune4C_13TeV-CSA14-powheg-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_010006/0000/"; } else if( insample==2515 ){ mySample_xSec_ = 35.6; mySample_nGen_ = 971800; mySample_sampleName_ = "Tbar_tW_DR"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/Tbar_tW-channel-DR_Tune4C_13TeV-CSA14-powheg-tauola/Phys14DR-PU20bx25_PHYS14_25_V1-v1_yggdrasilTree_v1/150217_010035/0000/"; } else if( insample==9125 ){ mySample_xSec_ = 0.5085 * 1.0;// YR3 * BR(all) mySample_nGen_ = 199700;//199000; mySample_sampleName_ = "TTbarH_M-125_13TeV_amcatnlo-pythia8-tauola_PU20bx25_tsg_PHYS14_25_V1-v2"; mySample_inputDir_ = "/eos/uscms/store/user/puigh/TTbarH_M-125_13TeV_amcatnlo-pythia8-tauola/Phys14DR-PU20bx25_tsg_PHYS14_25_V1-v2_v1_yggdrasilTree_v1/150217_004834/0000/"; } std::string treefilename = mySample_inputDir_ + "yggdrasil_treeMaker*.root"; std::string s_end = "_histo_" + str_jobN + ".root"; if( Njobs==1 ) s_end = "_histo.root"; std::string histofilename = Form("CSVHistoFiles/csv_rwt_hf_%s_v%i%s",mySample_sampleName_.c_str(),verNum, s_end.c_str()); if( !isHF ) histofilename = Form("CSVHistoFiles/csv_rwt_lf_%s_v%i%s",mySample_sampleName_.c_str(),verNum, s_end.c_str()); std::cout << " treefilename = " << treefilename.c_str() << std::endl; std::cout << " histofilename = " << histofilename.c_str() << std::endl; TChain *chain = new TChain("ttHTreeMaker/worldTree"); chain->Add(treefilename.c_str()); ////////////////////////////////////////////////////////////////////////// /// Tree branches/leaves ////////////////////////////////////////////////////////////////////////// yggdrasilEventVars *eve=0; chain->SetBranchAddress("eve.", &eve ); ////////////////////////////////////////////////////////////////////////// /// Histogram making ////////////////////////////////////////////////////////////////////////// TFile histofile(histofilename.c_str(),"recreate"); histofile.cd(); bool verbose = false; ////////////////////////////////////////////////////////////////////////// /// Histograms ////////////////////////////////////////////////////////////////////////// TH1::SetDefaultSumw2(); TH1D* h_first_jet_pt = new TH1D("h_first_jet_pt",";first jet p_{T}", 100, 0., 500. ); TH1D* h_first_jet_eta = new TH1D("h_first_jet_eta",";first jet #eta", 70, -3.5, 3.5 ); TH1D* h_first_jet_csv = new TH1D("h_first_jet_csv",";first jet CSV", 102, -0.01, 1.01 ); TH1D* h_first_jet_flavour = new TH1D("h_first_jet_flavour",";first jet flavour", 28, -6, 22 ); TH1D* h_first_jet_vtxMass = new TH1D("h_first_jet_vtxMass",";first jet vertex mass", 80, 0., 8.0 ); TH1D* h_first_jet_vtxNtracks = new TH1D("h_first_jet_vtxNtracks",";first jet vertex number of tracks", 14, -0.5, 13.5 ); TH1D* h_first_jet_vtx3DVal = new TH1D("h_first_jet_vtx3DVal",";first jet vertex 3D value", 141, -0.01, 14.0 ); TH1D* h_first_jet_vtx3DSig = new TH1D("h_first_jet_vtx3DSig",";first jet vertex 3D significance", 401, -0.01, 400 ); TH1D* h_first_jet_vtxMass_b = new TH1D("h_first_jet_vtxMass_b",";first jet vertex mass", 80, 0., 8.0 ); TH1D* h_first_jet_vtxMass_c = new TH1D("h_first_jet_vtxMass_c",";first jet vertex mass", 80, 0., 8.0 ); TH1D* h_first_jet_vtxMass_l = new TH1D("h_first_jet_vtxMass_l",";first jet vertex mass", 80, 0., 8.0 ); TH1D* h_first_jet_vtxMass_o = new TH1D("h_first_jet_vtxMass_o",";first jet vertex mass", 80, 0., 8.0 ); TH1D* h_second_jet_pt = new TH1D("h_second_jet_pt",";second jet p_{T}", 100, 0., 500. ); TH1D* h_second_jet_eta = new TH1D("h_second_jet_eta",";second jet #eta", 70, -3.5, 3.5 ); TH1D* h_second_jet_csv = new TH1D("h_second_jet_csv",";second jet CSV", 102, -0.01, 1.01 ); TH1D* h_second_jet_flavour = new TH1D("h_second_jet_flavour",";second jet flavour", 28, -6, 22 ); TH1D* h_second_jet_vtxMass = new TH1D("h_second_jet_vtxMass",";second jet vertex mass", 80, 0., 8.0 ); TH1D* h_second_jet_vtxNtracks = new TH1D("h_second_jet_vtxNtracks",";second jet vertex number of tracks", 14, -0.5, 13.5 ); TH1D* h_second_jet_vtx3DVal = new TH1D("h_second_jet_vtx3DVal",";second jet vertex 3D value", 141, -0.01, 14.0 ); TH1D* h_second_jet_vtx3DSig = new TH1D("h_second_jet_vtx3DSig",";second jet vertex 3D significance", 401, -0.01, 400 ); TH1D* h_second_jet_vtxMass_b = new TH1D("h_second_jet_vtxMass_b",";second jet vertex mass", 80, 0., 8.0 ); TH1D* h_second_jet_vtxMass_c = new TH1D("h_second_jet_vtxMass_c",";second jet vertex mass", 80, 0., 8.0 ); TH1D* h_second_jet_vtxMass_l = new TH1D("h_second_jet_vtxMass_l",";second jet vertex mass", 80, 0., 8.0 ); TH1D* h_second_jet_vtxMass_o = new TH1D("h_second_jet_vtxMass_o",";second jet vertex mass", 80, 0., 8.0 ); TH2D* h_first_jet_csv_vtxMass = new TH2D("h_first_jet_csv_vtxMass",";first jet CSV;first jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_first_jet_csv_vtxMass_b = new TH2D("h_first_jet_csv_vtxMass_b",";first jet CSV;first jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_first_jet_csv_vtxMass_c = new TH2D("h_first_jet_csv_vtxMass_c",";first jet CSV;first jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_first_jet_csv_vtxMass_l = new TH2D("h_first_jet_csv_vtxMass_l",";first jet CSV;first jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_first_jet_csv_vtxMass_o = new TH2D("h_first_jet_csv_vtxMass_o",";first jet CSV;first jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_second_jet_csv_vtxMass = new TH2D("h_second_jet_csv_vtxMass",";second jet CSV;second jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_second_jet_csv_vtxMass_b = new TH2D("h_second_jet_csv_vtxMass_b",";second jet CSV;second jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_second_jet_csv_vtxMass_c = new TH2D("h_second_jet_csv_vtxMass_c",";second jet CSV;second jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_second_jet_csv_vtxMass_l = new TH2D("h_second_jet_csv_vtxMass_l",";second jet CSV;second jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH2D* h_second_jet_csv_vtxMass_o = new TH2D("h_second_jet_csv_vtxMass_o",";second jet CSV;second jet vertex mass", 102, -0.01, 1.01, 80, 0., 8.0 ); TH1D* h_minDR_lepton_first_jet = new TH1D("h_minDR_lepton_first_jet",";min #DeltaR(lepton, first jet)", 102, -0.01, 6.01 ); TH1D* h_minDR_lepton_second_jet = new TH1D("h_minDR_lepton_second_jet",";min #DeltaR(lepton, second jet)", 102, -0.01, 6.01 ); TH1D* h_second_jet_eta_TwoMuon = new TH1D("h_second_jet_eta_TwoMuon",";second jet #eta", 70, -3.5, 3.5 ); TH1D* h_second_jet_eta_TwoElectron = new TH1D("h_second_jet_eta_TwoElectron",";second jet #eta", 70, -3.5, 3.5 ); TH1D* h_second_jet_eta_MuonElectron = new TH1D("h_second_jet_eta_MuonElectron",";second jet #eta", 70, -3.5, 3.5 ); TH2D* h_second_jet_pt_eta = new TH2D("h_second_jet_pt_eta",";second jet #eta;second jet p_{T}", 70, -3.5, 3.5, 100, 0., 500. ); TH2D* h_second_jet_flavour_eta = new TH2D("h_second_jet_flavour_eta",";second jet #eta;second flavour", 70, -3.5, 3.5, 28, -6, 22 ); TH1D* h_mass_lepton_first_jet = new TH1D("h_mass_lepton_first_jet",";first jet + lepton mass", 100, 0., 200. ); TH1D* h_mass_lepton_second_jet = new TH1D("h_mass_lepton_second_jet",";second jet + lepton mass", 100, 0., 200. ); TH1D* h_mass_tight_lepton_first_jet = new TH1D("h_mass_tight_lepton_first_jet",";first jet + tight lepton mass", 100, 0., 200. ); TH1D* h_mass_tight_lepton_second_jet = new TH1D("h_mass_tight_lepton_second_jet",";second jet + tight lepton mass", 100, 0., 200. ); TH2D* h_mass_lepton_second_jet_eta = new TH2D("h_mass_lepton_second_jet_eta",";second jet #eta;second jet + lepton mass", 70, -3.5, 3.5, 100, 0., 200. ); int NumCutsHF = 10; TH1D* h_hf_event_selection = new TH1D("h_hf_event_selection",";cut", NumCutsHF, 0, NumCutsHF ); h_hf_event_selection->GetXaxis()->SetBinLabel(1,"All"); h_hf_event_selection->GetXaxis()->SetBinLabel(2,"==2 jets"); h_hf_event_selection->GetXaxis()->SetBinLabel(3,"Dilepton trigger"); h_hf_event_selection->GetXaxis()->SetBinLabel(4,"==2 leptons"); h_hf_event_selection->GetXaxis()->SetBinLabel(5,"Opposite charge"); h_hf_event_selection->GetXaxis()->SetBinLabel(6,"#Delta R(lep,lep) > 0.2"); h_hf_event_selection->GetXaxis()->SetBinLabel(7,"M(lep,lep) > 12"); h_hf_event_selection->GetXaxis()->SetBinLabel(8,"ZVeto"); h_hf_event_selection->GetXaxis()->SetBinLabel(9,"MET > 50"); h_hf_event_selection->GetXaxis()->SetBinLabel(10,"jet passes medium b-tag"); int NumCutsLF = 10; TH1D* h_lf_event_selection = new TH1D("h_lf_event_selection",";cut", NumCutsLF, 0, NumCutsLF ); h_lf_event_selection->GetXaxis()->SetBinLabel(1,"All"); h_lf_event_selection->GetXaxis()->SetBinLabel(2,"==2 jets"); h_lf_event_selection->GetXaxis()->SetBinLabel(3,"Dilepton trigger"); h_lf_event_selection->GetXaxis()->SetBinLabel(4,"==2 leptons"); h_lf_event_selection->GetXaxis()->SetBinLabel(5,"Opposite charge"); h_lf_event_selection->GetXaxis()->SetBinLabel(6,"#Delta R(lep,lep) > 0.2"); h_lf_event_selection->GetXaxis()->SetBinLabel(7,"M(lep,lep) > 12"); h_lf_event_selection->GetXaxis()->SetBinLabel(8,"Zmass window"); h_lf_event_selection->GetXaxis()->SetBinLabel(9,"MET < 30"); h_lf_event_selection->GetXaxis()->SetBinLabel(10,"jet fails loose b-tag"); TH1D* h_numLooseLeptons = new TH1D("h_numLooseLeptons",";number of loose leptons", 5, 0, 5 ); // single jet specific plots int nPt = 6; int nEta = 1; if ( !isHF ){ nPt = 4; nEta = 3; } ////// TH1D* h_Data_jet_csv[6][3]; TH1D* h_MC_b_jet_csv[6][3]; TH1D* h_MC_nonb_jet_csv[6][3]; TH1D* h_MC_b_jet_vtxMass[6][3]; TH1D* h_MC_nonb_jet_vtxMass[6][3]; TH2D* h_MC_b_jet_csv_vtxMass[6][3]; TH2D* h_MC_nonb_jet_csv_vtxMass[6][3]; ///// int nBins = 18; //Number of bins double xBins_hf[19] = {-10.0, 0.0, 0.122, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.7228, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01}; if(!isHF) nBins = 21; double xBins_lf[22] = {-10.0, 0.0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.752, 0.825, 0.898, 0.915, 0.932, 0.949, 0.966, 0.983, 1.01}; for ( int iPt=0; iPt<nPt; iPt++){ for ( int iEta=0; iEta<nEta; iEta++){ TString h_Data_Name = Form("csv_Data_Pt%i_Eta%i",iPt,iEta); TString h_b_Name = Form("csv_MC_bjets_Pt%i_Eta%i",iPt,iEta); TString h_nonb_Name = Form("csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta); TString h_vtxMass_b_Name = Form("vtxMass_MC_bjets_Pt%i_Eta%i",iPt,iEta); TString h_vtxMass_nonb_Name = Form("vtxMass_MC_nonbjets_Pt%i_Eta%i",iPt,iEta); if ( isHF ){ h_Data_jet_csv[iPt][iEta] = new TH1D(h_Data_Name, h_Data_Name, nBins, xBins_hf); h_MC_b_jet_csv[iPt][iEta] = new TH1D(h_b_Name, h_b_Name, nBins, xBins_hf); h_MC_nonb_jet_csv[iPt][iEta] = new TH1D(h_nonb_Name, h_nonb_Name, nBins, xBins_hf); h_MC_b_jet_vtxMass[iPt][iEta] = new TH1D(h_vtxMass_b_Name, h_vtxMass_b_Name, 16, 0., 8.0); h_MC_nonb_jet_vtxMass[iPt][iEta] = new TH1D(h_vtxMass_nonb_Name, h_vtxMass_nonb_Name, 16, 0., 8.0); h_MC_b_jet_csv_vtxMass[iPt][iEta] = new TH2D("csv_"+h_vtxMass_b_Name, "csv_"+h_vtxMass_b_Name, nBins, xBins_hf, 16, 0., 8.0); h_MC_nonb_jet_csv_vtxMass[iPt][iEta] = new TH2D("csv_"+h_vtxMass_nonb_Name, "csv_"+h_vtxMass_nonb_Name, nBins, xBins_hf, 16, 0., 8.0); } else { h_Data_jet_csv[iPt][iEta] = new TH1D(h_Data_Name, h_Data_Name, nBins, xBins_lf); h_MC_b_jet_csv[iPt][iEta] = new TH1D(h_b_Name, h_b_Name, nBins, xBins_lf); h_MC_nonb_jet_csv[iPt][iEta] = new TH1D(h_nonb_Name, h_nonb_Name, nBins, xBins_lf); h_MC_b_jet_vtxMass[iPt][iEta] = new TH1D(h_vtxMass_b_Name, h_vtxMass_b_Name, 16, 0., 8.0); h_MC_nonb_jet_vtxMass[iPt][iEta] = new TH1D(h_vtxMass_nonb_Name, h_vtxMass_nonb_Name, 16, 0., 8.0); h_MC_b_jet_csv_vtxMass[iPt][iEta] = new TH2D("csv_"+h_vtxMass_b_Name, "csv_"+h_vtxMass_b_Name, nBins, xBins_lf, 16, 0., 8.0); h_MC_nonb_jet_csv_vtxMass[iPt][iEta] = new TH2D("csv_"+h_vtxMass_nonb_Name, "csv_"+h_vtxMass_nonb_Name, nBins, xBins_lf, 16, 0., 8.0); } } } ////////////////////////////////////////////////////////////////////////// ///// ////////////////////////////////////////////////////////////////////////// int numEvents_all=0; int numEvents_2jets=0; int numEvents_lepselection2=0; int numEvents_lepselection1a=0; int numEvents_lepselection1b=0; int numEvents_lepselection1c=0; int numEvents_exselection=0; int nentries = chain->GetEntries(); std::cout << "\n\t Number of entries = " << nentries << std::endl; std::cout << "\t Max number of entries = " << maxNentries << std::endl; std::cout << "\n" << std::endl; int use_nentries = std::max( maxNentries, nentries); int NeventsPerJob = int( double(use_nentries)/double(Njobs) + 0.000001 ) + 1; int firstEvent = (jobN-1)*NeventsPerJob + 1; int lastEvent = firstEvent + NeventsPerJob; if( jobN==Njobs ) lastEvent = -1; if( jobN==1 ) firstEvent = 0; int cnt = 0; int nPass = 0; std::cout << "======== Starting Event Loop ========" << std::endl; for (Long64_t ievt=0; ievt<chain->GetEntries();ievt++) { //Long64_t cnt++; if( ievt<firstEvent ) continue; if( ievt==lastEvent ) break; if( ievt==1 ) std::cout << " Event " << ievt << std::endl; if( ievt%10000==0 && ievt!=1 ) std::cout << " " << ievt << "\t" << int(double(ievt-firstEvent)/double(NeventsPerJob)*100) << "% done" << std::endl; //if( ievt==(maxNentries+1) ) break; if( ievt==(maxNentries+1) && ievt!=0 ) break; chain->GetEntry(ievt); numEvents_all++; //// --------- various weights: PU, topPt, triggerSF, leptonSF... // double wgt_topPtSF = eve->wgt_topPt_; double Xsec = mySample_xSec_;//eve->wgt_xs_; double nGen = ( maxNentries>0 ) ? maxNentries : mySample_nGen_;//eve->wgt_nGen_; double lumi = ( intLumi > 0 ) ? intLumi : eve->wgt_lumi_ ; double wgt_gen = ( insample==9125 || insample==9135 ) ? eve->wgt_generator_ : 1; double wgt = wgt_gen * lumi * (Xsec/nGen);//"weight_PU*topPtWgt*osTriggerSF*lepIDAndIsoSF*"; // various weights /////////////////// ////// selections /////////////////// h_hf_event_selection->Fill(0.5, wgt); h_lf_event_selection->Fill(0.5, wgt); int iSys = 0; //////------- exactly 2 jets ----- vvdouble jet_vect_TLV = eve->jet_loose_vect_TLV_[iSys]; vdouble jet_CSVv2IVf = eve->jet_loose_combinedInclusiveSecondaryVertexV2BJetTags_[iSys]; int numJets = int(jet_vect_TLV.size()) ; if (numJets !=2) continue; numEvents_2jets++; h_hf_event_selection->Fill(1.5, wgt); h_lf_event_selection->Fill(1.5, wgt); double jet1_btag = jet_CSVv2IVf[0]; double jet2_btag = jet_CSVv2IVf[1]; bool passTightBtag = false; bool failLooseBtag = false; if( jet1_btag>0.814 || jet2_btag>0.814 ) passTightBtag = true; if( jet1_btag<0.423 || jet1_btag<0.423 ) failLooseBtag = true; double MHT = eve->MHT_[iSys]; //////------- two leptons ----- double met_pt = eve->MET_[iSys]; //bool PassZmask = eve->PassZmask_ ; int TwoMuon = eve->TwoMuon_; int TwoElectron = eve->TwoElectron_ ; int MuonElectron = eve->MuonElectron_ ; double mass_leplep = eve->mass_leplep_; double dR_leplep = eve->dR_leplep_; int oppositeLepCharge = eve->oppositeLepCharge_; vvdouble lepton_vect_TLV = eve->lepton_vect_TLV_; vint lepton_isTight = eve->lepton_isTight_; vint lepton_isLoose = eve->lepton_isLoose_; vint lepton_trkCharge = eve->lepton_trkCharge_; int numLooseLeptons=0; for( int iLep=0; iLep<int(lepton_vect_TLV.size()); iLep++ ){ bool isLoose1 = lepton_isLoose[iLep]; if( !isLoose1 ) continue; numLooseLeptons++; int charge1 = lepton_trkCharge[iLep]; TLorentzVector myLep1; myLep1.SetPxPyPzE( lepton_vect_TLV[iLep][0], lepton_vect_TLV[iLep][1], lepton_vect_TLV[iLep][2], lepton_vect_TLV[iLep][3] ); for( int jLep=iLep+1; jLep<int(lepton_vect_TLV.size()); jLep++ ){ if( iLep==jLep ) continue; bool isLoose2 = lepton_isLoose[jLep]; if( !isLoose2 ) continue; int charge2 = lepton_trkCharge[jLep]; TLorentzVector myLep2; myLep2.SetPxPyPzE( lepton_vect_TLV[jLep][0], lepton_vect_TLV[jLep][1], lepton_vect_TLV[jLep][2], lepton_vect_TLV[jLep][3] ); TLorentzVector sum = myLep1 + myLep2; mass_leplep = sum.M(); dR_leplep = myLep1.DeltaR(myLep2); if( (charge1 * charge2)==-1 ) oppositeLepCharge = 1; else if( (charge1 * charge2)==1 ) oppositeLepCharge = 0; else if( charge1==-99 ) oppositeLepCharge = -1; else if( charge2==-99 ) oppositeLepCharge = -2; else oppositeLepCharge = -3; } } h_numLooseLeptons->Fill(numLooseLeptons,wgt); bool PassZmask = ( MuonElectron || (mass_leplep < (65.5 + 3*MHT/8)) || (mass_leplep > (108 - MHT/4)) || (mass_leplep < (79 - 3*MHT/4)) || (mass_leplep > (99 + MHT/2)) ); /// triggers bool isDoubleMuTriggerPass = eve->passDoubleMuonTrigger_;//1; bool isDoubleElectronTriggerPass = eve->passDoubleElectronTrigger_;//1; bool isMuEGTriggerPass = eve->passElectronMuonTrigger_;//1; // for different datasets or sub-lep categories bool lepselection1a = ( TwoMuon && isDoubleMuTriggerPass && (PassZmask==1) && (met_pt>50) ); //Selection for TwoMuon data events bool lepselection1b = ( TwoElectron && isDoubleElectronTriggerPass && (PassZmask==1) && (met_pt>50) ); //Selection for TwoEle data events bool lepselection1c = ( MuonElectron && isMuEGTriggerPass ); //Selection for MuonEle data events if (!isHF){ lepselection1a = ( TwoMuon && isDoubleMuTriggerPass && (PassZmask==0) && (met_pt<30) && abs(mass_leplep-91)<10 ); //Selection for TwoMuon data events lepselection1b = ( TwoElectron && isDoubleElectronTriggerPass && (PassZmask==0) && (met_pt<30) && abs(mass_leplep-91)<10 ); //Selection for TwoEle data events lepselection1c = 0; // ( MuonElectron && isMuEGTriggerPass ); //Selection for MuonEle data events } // for MC events bool lepselection2 = ( lepselection1a || lepselection1b || lepselection1c ) ; // if (!isHF) lepselection2 = ( lepselection1a || lepselection1b || lepselection1c ) ; if( lepselection1a ) numEvents_lepselection1a++; if( lepselection1b ) numEvents_lepselection1b++; if( lepselection1c ) numEvents_lepselection1c++; bool isCleanEvent = 1; bool exselection = ((dR_leplep > 0.2) && (mass_leplep > 12) && (isCleanEvent == 1) && (oppositeLepCharge == 1)); //General dilepton selection // trigger if( isDoubleMuTriggerPass || isDoubleElectronTriggerPass || isMuEGTriggerPass ){ h_hf_event_selection->Fill(2.5, wgt); if( TwoMuon || TwoElectron || MuonElectron ){ h_hf_event_selection->Fill(3.5, wgt); if( oppositeLepCharge == 1 ){ h_hf_event_selection->Fill(4.5, wgt); if( (dR_leplep > 0.2) ){ h_hf_event_selection->Fill(5.5, wgt); if( mass_leplep > 12 ){ h_hf_event_selection->Fill(6.5, wgt); if( PassZmask==1 && fabs(mass_leplep-91)>10 ){ h_hf_event_selection->Fill(7.5, wgt); if( met_pt>50 ){ h_hf_event_selection->Fill(8.5, wgt); if( passTightBtag ){ h_hf_event_selection->Fill(9.5, wgt); } } } } } } } } if( isDoubleMuTriggerPass || isDoubleElectronTriggerPass ){ h_lf_event_selection->Fill(2.5, wgt); if( TwoMuon || TwoElectron ){ h_lf_event_selection->Fill(3.5, wgt); if( oppositeLepCharge == 1 ){ h_lf_event_selection->Fill(4.5, wgt); if( (dR_leplep > 0.2) ){ h_lf_event_selection->Fill(5.5, wgt); if( mass_leplep > 12 ){ h_lf_event_selection->Fill(6.5, wgt); if( PassZmask==0 && fabs(mass_leplep-91)<10 ){ h_lf_event_selection->Fill(7.5, wgt); if( met_pt<30 ){ h_lf_event_selection->Fill(8.5, wgt); if( failLooseBtag ){ h_lf_event_selection->Fill(9.5, wgt); } } } } } } } } if ( !lepselection2 ) continue; numEvents_lepselection2++; /////------ extra seletions ----- // double dR_leplep = eve->dR_leplep_; // bool isCleanEvent = 1; // int oppositeLepCharge = eve->oppositeLepCharge_; // bool exselection = ((dR_leplep > 0.2) && (mass_leplep > 12) && (isCleanEvent == 1) && (oppositeLepCharge == 1)); //General dilepton selection // bool exselection = ((dR_leplep > 0.2) && (mass_leplep > 12) && (isCleanEvent == 1)); //General dilepton selection // opposite sign applied in treemaking if ( !exselection ) continue; numEvents_exselection++; nPass++; ///// --------jet variables //vdouble jet_CSV = eve->jet_loose_CSV_[iSys]; vdouble jet_vtxMass = eve->jet_loose_vtxMass_[iSys]; vdouble jet_vtxNtracks = eve->jet_loose_vtxNtracks_[iSys]; vdouble jet_vtx3DVal = eve->jet_loose_vtx3DVal_[iSys]; vdouble jet_vtx3DSig = eve->jet_loose_vtx3DSig_[iSys]; vint jet_flavour = eve->jet_loose_flavour_[iSys]; double first_jet_pt = -9.; double first_jet_eta = -9.; double first_jet_csv = -9.; double first_jet_vtxMass = -9.; double first_jet_vtxNtracks = -9.; double first_jet_vtx3DVal = -9.; double first_jet_vtx3DSig = -9.; int first_jet_flavour = -9; double second_jet_pt = -9.; double second_jet_eta = -9.; double second_jet_csv = -9.; double second_jet_vtxMass = -9.; double second_jet_vtxNtracks = -9.; double second_jet_vtx3DVal = -9.; double second_jet_vtx3DSig = -9.; int second_jet_flavour = -9; if( verbose ) std::cout << "--for event "<< cnt << std::endl; if( verbose ) std::cout << " --number of jets is "<< numJets << std::endl; double minDR_lepton_first_jet = 99, minDR_lepton_second_jet = 99; for( int iJet=0; iJet<int(jet_vect_TLV.size()); iJet++ ){ TLorentzVector myJet; myJet.SetPxPyPzE( jet_vect_TLV[iJet][0], jet_vect_TLV[iJet][1], jet_vect_TLV[iJet][2], jet_vect_TLV[iJet][3] ); double myCSV = jet_CSVv2IVf[iJet]; double myVtxMass = jet_vtxMass[iJet]; double myVtxNtracks = jet_vtxNtracks[iJet]; double myVtx3DVal = jet_vtx3DVal[iJet]; double myVtx3DSig = jet_vtx3DSig[iJet]; double myJetPt = myJet.Pt(); double myJetEta = myJet.Eta(); int myFlavor = jet_flavour[iJet]; if( iJet==0 ){ first_jet_pt = myJetPt; first_jet_eta = myJetEta; first_jet_csv = myCSV; first_jet_vtxMass = myVtxMass; first_jet_vtxNtracks = myVtxNtracks; first_jet_vtx3DVal = myVtx3DVal; first_jet_vtx3DSig = myVtx3DSig; first_jet_flavour = myFlavor; for( int iLep=0; iLep<int(lepton_vect_TLV.size()); iLep++ ){ TLorentzVector myLep; myLep.SetPxPyPzE( lepton_vect_TLV[iLep][0], lepton_vect_TLV[iLep][1], lepton_vect_TLV[iLep][2], lepton_vect_TLV[iLep][3] ); double dR = myLep.DeltaR(myJet); if( dR<minDR_lepton_first_jet ) minDR_lepton_first_jet = dR; TLorentzVector sum = myLep + myJet; h_mass_lepton_first_jet->Fill(sum.M()); if( lepton_isTight[iLep] ) h_mass_tight_lepton_first_jet->Fill(sum.M()); } } if( iJet==1 ){ second_jet_pt = myJetPt; second_jet_eta = myJetEta; second_jet_csv = myCSV; second_jet_vtxMass = myVtxMass; second_jet_vtxNtracks = myVtxNtracks; second_jet_vtx3DVal = myVtx3DVal; second_jet_vtx3DSig = myVtx3DSig; second_jet_flavour = myFlavor; for( int iLep=0; iLep<int(lepton_vect_TLV.size()); iLep++ ){ TLorentzVector myLep; myLep.SetPxPyPzE( lepton_vect_TLV[iLep][0], lepton_vect_TLV[iLep][1], lepton_vect_TLV[iLep][2], lepton_vect_TLV[iLep][3] ); double dR = myLep.DeltaR(myJet); if( dR<minDR_lepton_second_jet ) minDR_lepton_second_jet = dR; TLorentzVector sum = myLep + myJet; h_mass_lepton_second_jet->Fill(sum.M()); h_mass_lepton_second_jet_eta->Fill(second_jet_eta,sum.M()); if( lepton_isTight[iLep] ) h_mass_tight_lepton_second_jet->Fill(sum.M()); } } } // end loop over jets if( verbose ) std::cout << " -first jet pt, eta is " << first_jet_pt << "; "<<first_jet_eta << std::endl; if( verbose ) std::cout << " -second jet pt, eta is " << second_jet_pt << "; "<<second_jet_eta << std::endl; h_first_jet_pt->Fill(first_jet_pt); h_first_jet_eta->Fill(first_jet_eta); h_first_jet_csv->Fill(first_jet_csv); h_first_jet_vtxMass->Fill(first_jet_vtxMass); h_first_jet_vtxNtracks->Fill(first_jet_vtxNtracks); h_first_jet_vtx3DVal->Fill(first_jet_vtx3DVal); h_first_jet_vtx3DSig->Fill(first_jet_vtx3DSig); h_first_jet_flavour->Fill(first_jet_flavour); if( abs(first_jet_flavour)==5 ) h_first_jet_vtxMass_b->Fill(first_jet_vtxMass); else if( abs(first_jet_flavour)==4 ) h_first_jet_vtxMass_c->Fill(first_jet_vtxMass); else if( abs(first_jet_flavour)==0 ) h_first_jet_vtxMass_o->Fill(first_jet_vtxMass); else h_first_jet_vtxMass_l->Fill(first_jet_vtxMass); h_first_jet_csv_vtxMass->Fill(first_jet_csv,first_jet_vtxMass); if( abs(first_jet_flavour)==5 ) h_first_jet_csv_vtxMass_b->Fill(first_jet_csv,first_jet_vtxMass); else if( abs(first_jet_flavour)==4 ) h_first_jet_csv_vtxMass_c->Fill(first_jet_csv,first_jet_vtxMass); else if( abs(first_jet_flavour)==0 ) h_first_jet_csv_vtxMass_o->Fill(first_jet_csv,first_jet_vtxMass); else h_first_jet_csv_vtxMass_l->Fill(first_jet_csv,first_jet_vtxMass); h_second_jet_pt->Fill(second_jet_pt); h_second_jet_eta->Fill(second_jet_eta); h_second_jet_csv->Fill(second_jet_csv); h_second_jet_vtxMass->Fill(second_jet_vtxMass); h_second_jet_vtxNtracks->Fill(second_jet_vtxNtracks); h_second_jet_vtx3DVal->Fill(second_jet_vtx3DVal); h_second_jet_vtx3DSig->Fill(second_jet_vtx3DSig); h_second_jet_flavour->Fill(second_jet_flavour); if( abs(second_jet_flavour)==5 ) h_second_jet_vtxMass_b->Fill(second_jet_vtxMass); else if( abs(second_jet_flavour)==4 ) h_second_jet_vtxMass_c->Fill(second_jet_vtxMass); else if( abs(second_jet_flavour)==0 ) h_second_jet_vtxMass_o->Fill(second_jet_vtxMass); else h_second_jet_vtxMass_l->Fill(second_jet_vtxMass); h_second_jet_csv_vtxMass->Fill(second_jet_csv,second_jet_vtxMass); if( abs(second_jet_flavour)==5 ) h_second_jet_csv_vtxMass_b->Fill(second_jet_csv,second_jet_vtxMass); else if( abs(second_jet_flavour)==4 ) h_second_jet_csv_vtxMass_c->Fill(second_jet_csv,second_jet_vtxMass); else if( abs(second_jet_flavour)==0 ) h_second_jet_csv_vtxMass_o->Fill(second_jet_csv,second_jet_vtxMass); else h_second_jet_csv_vtxMass_l->Fill(second_jet_csv,second_jet_vtxMass); h_second_jet_pt_eta->Fill(second_jet_eta,second_jet_pt); h_second_jet_flavour_eta->Fill(second_jet_eta,second_jet_flavour); h_minDR_lepton_first_jet->Fill(minDR_lepton_first_jet); h_minDR_lepton_second_jet->Fill(minDR_lepton_second_jet); if( TwoMuon ) h_second_jet_eta_TwoMuon->Fill(second_jet_eta); if( TwoElectron ) h_second_jet_eta_TwoElectron->Fill(second_jet_eta); if( MuonElectron ) h_second_jet_eta_MuonElectron->Fill(second_jet_eta); double csvWgtHF, csvWgtLF, csvWgtCF; double newCSVwgt = ( insample<0 ) ? 1 : get_csv_wgt(jet_vect_TLV, jet_CSVv2IVf, jet_flavour,iSys, csvWgtHF, csvWgtLF, csvWgtCF); double wgtfakeData = wgt*newCSVwgt; if( verbose ) std::cout << " HF/LF csv wgts are: " << csvWgtHF << "/"<< csvWgtLF << "\t new CSV wgt = " << newCSVwgt << std::endl; ///// for iteration if (verNum !=0 ) { if ( isHF ) wgt *= csvWgtLF; // applying lfSFs else wgt *= csvWgtHF; // applying lfSFs } ///// ------ tag and proble jet selections -------- // 2nd jet --> tag, 1st jet --> proble //bool jetselection2a = (second_jet_csv > 0.679) ? 1:0; //Probe jet being the first_jet bool jetselection2a = (second_jet_csv > 0.814) ? 1:0; //Probe jet being the first_jet bool firstjetb = ( abs(first_jet_flavour)==5 ) ? 1:0; if(!isHF) { //jetselection2a = second_jet_csv < 0.244 ? 1:0 ; jetselection2a = second_jet_csv < 0.423 ? 1:0 ; firstjetb = ( abs(first_jet_flavour)==5 || abs(first_jet_flavour)==4 ); } if ( jetselection2a ){ double jetPt = first_jet_pt; double jetAbsEta = fabs(first_jet_eta); int iPt = -1; int iEta = -1; if (jetPt >=19.99 && jetPt<30) iPt = 0; else if (jetPt >=30 && jetPt<40) iPt = 1; else if (jetPt >=40 && jetPt<60) iPt = 2; else if (jetPt >=60 && jetPt<100) iPt = 3; else if (jetPt >=100 && jetPt<160) iPt = 4; else if (jetPt >=160 && jetPt<10000) iPt = 5; if (jetAbsEta >=0 && jetAbsEta<0.8 ) iEta = 0; else if ( jetAbsEta>=0.8 && jetAbsEta<1.6 ) iEta = 1; else if ( jetAbsEta>=1.6 && jetAbsEta<2.41 ) iEta = 2; if (isHF && iEta>0) iEta=0; if (!isHF && iPt>3) iPt=3; ///fake data h_Data_jet_csv[iPt][iEta]->Fill(first_jet_csv, wgtfakeData); if( firstjetb ){ h_MC_b_jet_csv[iPt][iEta]->Fill(first_jet_csv, wgt); h_MC_b_jet_vtxMass[iPt][iEta]->Fill(first_jet_vtxMass, wgt); h_MC_b_jet_csv_vtxMass[iPt][iEta]->Fill(first_jet_csv, first_jet_vtxMass, wgt); } else { h_MC_nonb_jet_csv[iPt][iEta]->Fill(first_jet_csv, wgt); h_MC_nonb_jet_vtxMass[iPt][iEta]->Fill(first_jet_vtxMass, wgt); h_MC_nonb_jet_csv_vtxMass[iPt][iEta]->Fill(first_jet_csv, first_jet_vtxMass, wgt); } } // 1st jet --> tag, 2nd jet --> proble //bool jetselection2b = ( first_jet_csv > 0.679) ; //Probe jet being the second_jet bool jetselection2b = ( first_jet_csv > 0.814) ; //Probe jet being the second_jet bool secondjetb = ( abs(second_jet_flavour)==5 ); if(!isHF) { //jetselection2b = first_jet_csv < 0.244 ? 1:0 ; jetselection2b = first_jet_csv < 0.423 ? 1:0 ; secondjetb = ( abs(second_jet_flavour)==5 || abs(second_jet_flavour)==4 ); } if ( jetselection2b ){ double jetPt = second_jet_pt; double jetAbsEta = fabs(second_jet_eta); int iPt = -1; int iEta = -1; if (jetPt >=19.99 && jetPt<30) iPt = 0; else if (jetPt >=30 && jetPt<40) iPt = 1; else if (jetPt >=40 && jetPt<60) iPt = 2; else if (jetPt >=60 && jetPt<100) iPt = 3; else if (jetPt >=100 && jetPt<160) iPt = 4; else if (jetPt >=160 && jetPt<10000) iPt = 5; if (jetAbsEta >=0 && jetAbsEta<0.8 ) iEta = 0; else if ( jetAbsEta>=0.8 && jetAbsEta<1.6 ) iEta = 1; else if ( jetAbsEta>=1.6 && jetAbsEta<2.41 ) iEta = 2; if (isHF && iEta>0) iEta=0; if (!isHF && iPt>3) iPt=3; ///fake data h_Data_jet_csv[iPt][iEta]->Fill(second_jet_csv, wgtfakeData); if( secondjetb ){ h_MC_b_jet_csv[iPt][iEta]->Fill(second_jet_csv, wgt); h_MC_b_jet_vtxMass[iPt][iEta]->Fill(second_jet_vtxMass, wgt); h_MC_b_jet_csv_vtxMass[iPt][iEta]->Fill(second_jet_csv, second_jet_vtxMass, wgt); } else { h_MC_nonb_jet_csv[iPt][iEta]->Fill(second_jet_csv, wgt); h_MC_nonb_jet_vtxMass[iPt][iEta]->Fill(second_jet_vtxMass, wgt); h_MC_nonb_jet_csv_vtxMass[iPt][iEta]->Fill(second_jet_csv, second_jet_vtxMass, wgt); } } } // end loop over events std::cout << "total selected events is " << nPass << std::endl; std::cout << "===========================================" << std::endl; std::cout << "\t Number of all events = " << numEvents_all << std::endl; std::cout << "\t Number of events with ==2 jets = " << numEvents_2jets << std::endl; std::cout << "\t Number of events with lepselection2 = " << numEvents_lepselection2 << std::endl; std::cout << "\t Number of events with lepselection1a = " << numEvents_lepselection1a << std::endl; std::cout << "\t Number of events with lepselection1b = " << numEvents_lepselection1b << std::endl; std::cout << "\t Number of events with lepselection1c = " << numEvents_lepselection1c << std::endl; std::cout << "\t Number of events with exselection = " << numEvents_exselection << std::endl; std::cout << "===========================================" << std::endl; std::cout << " Done! " << std::endl; histofile.Write(); histofile.Close(); }
int xAna::HggTreeWriteLoop(const char* filename, int ijob, bool correctVertex, bool correctEnergy, bool setRho0 ) { //bool invDRtoTrk = false; if( _config == 0 ) { cout << " config file was not set properly... bail out" << endl; return -1; } if (fChain == 0) return -1; Long64_t nentries = fChain->GetEntriesFast(); // nentries = 10000; cout << "nentries: " << nentries << endl; Long64_t entry_start = ijob *_config->nEvtsPerJob(); Long64_t entry_stop = (ijob+1)*_config->nEvtsPerJob(); if( _config->nEvtsPerJob() < 0 ) { entry_stop = nentries; } if( entry_stop > nentries ) entry_stop = nentries; cout << " *** doing entries from: " << entry_start << " -> " << entry_stop << endl; if( entry_start > entry_stop ) return -1; EnergyScaleReader enScaleSkimEOS; /// skim EOS bugged so need to undo the energy scale in the skim EnergyScaleReader enScale; // enScaleSkimEOS.setup( "ecalCalibFiles/EnergyScale2012_Lisbon_9fb.txt" ); enScale.setup( _config->energyScaleFile() ); Float_t HiggsMCMass = _weight_manager->getCrossSection()->getHiggsMass(); Float_t HiggsMCPt = -1; bool isHiggsSignal = false; if( HiggsMCMass > 0 ) isHiggsSignal = true; mode_ = _weight_manager->getCrossSection()->mode(); isData = false; if(mode_==-1) isData = true; // mode_ = ijob; // DoCorrectVertex_ = correctVertex; DoCorrectEnergy_ = correctEnergy; DoSetRho0_ = setRho0; doJetRegression = _config->getDoJetRegression(); doControlSample = _config->getDoControlSample(); phoID_2011[0] = new TMVA::Reader("!Color:Silent"); phoID_2011[1] = new TMVA::Reader("!Color:Silent"); phoID_2012[0] = new TMVA::Reader("!Color:Silent"); phoID_2012[1] = new TMVA::Reader("!Color:Silent"); DiscriDiPho_2011 = new TMVA::Reader("!Color:Silent"); DiscriDiPho_2012 = new TMVA::Reader("!Color:Silent"); if(doJetRegression!=0) jetRegres = new TMVA::Reader("!Color:Silent"); Setup_MVA(); if( _config->setup() == "ReReco2011" ) for( int i = 0 ; i < 2; i++ ) phoID_mva[i] = phoID_2011[i]; else for( int i = 0 ; i < 2; i++ ) phoID_mva[i] = phoID_2012[i]; MassResolution massResoCalc; massResoCalc.addSmearingTerm(); if( _config->setup() == "ReReco2011" ) Ddipho_mva = DiscriDiPho_2011; else Ddipho_mva = DiscriDiPho_2012; float Ddipho_cat[5]; Ddipho_cat[4] = -1; if( _config->setup() == "ReReco2011" ) { Ddipho_cat[0] = 0.89; Ddipho_cat[1] = 0.72; Ddipho_cat[2] = 0.55; Ddipho_cat[3] = +0.05; } else { Ddipho_cat[0] = 0.91; Ddipho_cat[1] = 0.79; Ddipho_cat[2] = 0.49; Ddipho_cat[3] = -0.05; } // else { Ddipho_cat[0] = 0.88; Ddipho_cat[1] = 0.71; Ddipho_cat[2] = 0.50; Ddipho_cat[3] = -0.05; } DiscriVBF_UseDiPhoPt = true; DiscriVBF_UsePhoPt = true; DiscriVBF_cat.resize(2); DiscriVBF_cat[0] = 0.985; DiscriVBF_cat[1] = 0.93; DiscriVBF_useMvaSel = _config->doVBFmvaCat(); /// depending on the selection veto or not on electrons (can do muele, elemu,eleele) bool vetoElec[2] = {true,true}; if( _config->invertElectronVeto() ) { vetoElec[0] = false; vetoElec[1] = false; } if( _config->isEleGamma() ) { vetoElec[0] = false; vetoElec[1] = true ; } if( _config->isGammaEle() ) { vetoElec[0] = true ; vetoElec[1] = false; } cout << " --------- veto electron config -----------" << endl; cout << " Leading Pho VetoElec: " << vetoElec[0] << endl; cout << " Trailing Pho VetoElec: " << vetoElec[1] << endl; DoDebugEvent = true; bool DoPreselection = true; // bool DoPrint = true; TString VertexFileNamePrefix; TRandom3 *rnd = new TRandom3(); rnd->SetSeed(0); /// output tree and cross check file _xcheckTextFile.open(TString(filename)+".xcheck.txt"); // _xcheckTextFile = cout; _minitree = new MiniTree( filename ); TTree * tSkim = 0; if( _config->doSkimming() ) tSkim = (TTree*) fChain->CloneTree(0); InitHists(); _minitree->mc_wXsec = _weight_manager->xSecW(); _minitree->mc_wNgen = 100000./_weight_manager->getNevts(); if( isData ) { _minitree->mc_wXsec = 1; _minitree->mc_wNgen = 1; } Int_t isprompt0 = -1; Int_t isprompt1 = -1; set<Long64_t> syncEvt; cout <<" ================ mode " << mode_ <<" =============================== "<<endl; /// setupType has to be passed via config file // photonOverSmearing overSmearICHEP("Test52_ichep"); photonOverSmearing overSmearHCP( "oversmear_hcp2012" ); photonOverSmearing overSmear( _config->setup() ); int overSmearSyst = _config->getEnergyOverSmearingSyst(); Long64_t nbytes = 0, nb = 0; //////////////////////////////////////////////////////////////////////////// //////////////////////////// Start the loop //////////////////////////////// //////////////////////////////////////////////////////////////////////////// vector<int> nEvts; vector<string> nCutName; nCutName.push_back("TOTAL :"); nEvts.push_back(0); nCutName.push_back("2 gammas :"); nEvts.push_back(0); nCutName.push_back("triggers :"); nEvts.push_back(0); nCutName.push_back("nan weight :"); nEvts.push_back(0); nCutName.push_back("presel kin cuts:"); nEvts.push_back(0); nCutName.push_back("pass 2 gam incl:"); nEvts.push_back(0); nCutName.push_back("pass all :"); nEvts.push_back(0); nCutName.push_back(" --> pass 2 gam lep: "); nEvts.push_back(0); nCutName.push_back(" --> pass 2 gam vbf: "); nEvts.push_back(0); vector<int> selVtxSumPt2(3); selVtxSumPt2[0] = 0; selVtxSumPt2[1] = -1; selVtxSumPt2[2] = -1; for (Long64_t jentry=entry_start; jentry< entry_stop ; ++jentry) { Long64_t ientry = LoadTree(jentry); if (ientry < -9999) break; if( jentry % 10000 == 0) cout<<"processing event "<<jentry<<endl; nb = fChain->GetEntry(jentry); nbytes += nb; /// reset minitree variables _minitree->initEvent(); // study mc truth block if( !isData ) { fillMCtruthInfo_HiggsSignal(); _minitree->fillMCtrueOnly(); } /// reco analysis unsigned icutlevel = 0; nEvts[icutlevel++]++; if( nPho < 2 ) continue; nEvts[icutlevel++]++; /// set synchronisation flag if( syncEvt.find(event) != syncEvt.end() ) DoDebugEvent = true; else DoDebugEvent = false; if( DoDebugEvent ) _xcheckTextFile << "==========================================================" << endl; if( DoDebugEvent ) _xcheckTextFile << "================= debugging event: " << event << endl; /// PU & BSz reweightings if( !isData ) { int itpu = 1; /// 0 without OOT PU - 1 with OOT PU _minitree->mc_wPU = _weight_manager->puW( nPU[itpu] ); // PUwei = _weight_manager->puWTrue( puTrue[itpu] ); } hTotEvents->Fill(1,_minitree->mc_wPU); bool sigWH = false ; bool sigZH = false ; int mc_whzh_type = 0; _minitree->mc_wHQT = 1; if( isHiggsSignal ) { if ( _weight_manager->getCrossSection()->getMCType() == "vh" ) for( Int_t i=0; i < nMC && i <= 1; ++i ) { if( abs(mcPID[i]) == 24 ) sigWH=true; if( abs(mcPID[i]) == 23 ) sigZH=true; } if( sigWH ) mc_whzh_type = 1; if( sigZH ) mc_whzh_type = 2; for( Int_t i=0; i<nMC; ++i) if ( abs(mcPID[i]) == 25 ) HiggsMCPt = mcPt[i]; if( _weight_manager->getCrossSection()->getMCType() == "ggh" && _config->setup().find( "ReReco2011" ) != string::npos ) _minitree->mc_wHQT = getHqTWeight(HiggsMCMass, HiggsMCPt); } if ((mode_ == 2 || mode_ ==1 || mode_ == 18 || mode_ == 19) && processID==18) continue; // Remove double counting in gamma+jets and QCDjets Int_t mcIFSR_pho = 0; Int_t mcPartonic_pho = 0; if (mode_ == 1 || mode_ == 2 || mode_ == 3 || mode_ == 18 || mode_ == 19 ) { for (Int_t i=0; i<nMC; ++i) { if (mcPID[i] == 22 && (fabs(mcMomPID[i]) < 6 || mcMomPID[i] == 21)) mcIFSR_pho++; if (mcPID[i] == 22 && mcMomPID[i] == 22) mcPartonic_pho++; } } // if pythia is used for diphoton.. no IFSR removing from QCD and Gjets!!!!!! if ((mode_==1 || mode_ == 2 || mode_ == 18 ) && mcIFSR_pho >= 1 && mcPartonic_pho >=1) continue; if ((mode_ == 3 || mode_ == 19 )&& mcIFSR_pho == 2) continue; bool prompt2= false; bool prompt1= false; bool prompt0= false; vertProb = -1; if (mode_ == 2 || mode_ == 1 || mode_ == 18 ){ if ( mcPartonic_pho >= 1 && mcIFSR_pho >= 1 ) prompt2 = true; else if ( mcPartonic_pho >= 1 && mcIFSR_pho == 0 ) prompt1 = true; else if ( mcPartonic_pho == 0 && mcIFSR_pho == 0 ) prompt0 = true; } else if(mode_ == 3 || mode_ == 19 ){ if ( mcIFSR_pho >= 2 ) prompt2 = true; else if ( mcIFSR_pho == 1 ) prompt1 = true; else if ( mcIFSR_pho == 0 ) prompt0 = true; if( prompt1 ) _minitree->mc_wXsec = 1.3*_weight_manager->xSecW(); } if(mode_==1 || mode_==2 || mode_==3 || mode_==18 || mode_==19){ if(prompt0)isprompt0=1; else isprompt0=0; if(prompt1)isprompt1=1; else isprompt1=0; } if( mode_ == 20 && isZgamma() ) continue; /// wei weight is just temporary and may not contain all info. float wei = _minitree->mc_wXsec * _minitree->mc_wPU * _minitree->mc_wNgen * _minitree->mc_wHQT; if( isData && !PassTriggerSelection() ) continue; nEvts[icutlevel++]++; if( std::isinf( wei ) || std::isnan( wei ) )continue; nEvts[icutlevel++]++; //// ********************* define S4 variable **********************//// for( int i=0; i<nPho; ++i){ if( _config->setup() == "ReReco2011" ) phoS4ratio[i] = 1; else phoS4ratio[i] = phoE2x2[i] / phoE5x5[i]; } //// ************************************************************* //// if( !isData ) { //// ************** MC corrections (mostly MC) ******************* //// // 1. energy shifting / smearing for( int i=0; i<nPho; ++i) if( fabs(phoSCEta[i]) <= 2.5 ) { float smearing = overSmear.randOverSmearing(phoSCEta[i],phoR9[i],isInGAP_EB(i),overSmearSyst); phoRegrE[i] *= (1 + smearing); phoE[i] *= (1 + smearing); /// from MassFactorized in gglobe: energyCorrectedError[ipho] *=(l.pho_isEB[ipho]) ? 1.07 : 1.045 ; float smearFactor = 1; if( _config->setup() == "ReReco2011" ) smearFactor = fabs(phoSCEta[i]) < 1.45 ? 1.07: 1.045; phoRegrErr[i] *= smearFactor; } // 2. reweighting of photon id variables (R9...) for (int i=0; i<nPho; ++i) ReweightMC_phoIdVar(i); //// ************************************************************* //// } //// ********** Apply regression energy ************* //// float phoStdE[500]; for( int i=0; i<nPho; ++i) if( fabs(phoSCEta[i]) <= 2.5 ) { if( isData ){ float enCorrSkim = 1;//enScaleSkimEOS.energyScale( phoR9[i], phoSCEta[i], run); float phoEnScale = enScale.energyScale( phoR9[i], phoSCEta[i], run)/enCorrSkim; phoRegrE[i] *= phoEnScale; phoE[i] *= phoEnScale; } phoStdE[i] = phoE[i]; phoE[i] = phoRegrE[i]; /// transform calo position abd etaVtx, phiVtx with SC position for( int x = 0 ; x < 3; x++ ) phoCaloPos[i][x] = phoSCPos[i][x]; for( int ivtx = 0 ; ivtx < nVtxBS; ivtx++ ) { TVector3 xxi = getCorPhotonTVector3(i,ivtx); phoEtaVtx[i][ivtx] = xxi.Eta(); phoPhiVtx[i][ivtx] = xxi.Phi(); } /// additionnal smearing to go to data energy resolution phoRegrSmear[i] = phoE[i]*overSmearHCP.meanOverSmearing(phoSCEta[i],phoR9[i],isInGAP_EB(i),0); phoEt[i] = phoE[i] / cosh(phoEta[i]); } //// ************************************************* //// /// lepton selection int iElecVtx(-1), iMuonVtx(-1); vector<int> elecIndex = selectElectronsHCP2012( wei, iElecVtx ); vector<int> muonIndex = selectMuonsHCP2012( wei, iMuonVtx ); vector<int> event_vtx; vector<int> event_ilead ; vector<int> event_itrail; vector<TLorentzVector> event_plead ; vector<TLorentzVector> event_ptrail; TLorentzVector leptag; int lepCat = -1; bool exitLoop = false; for( int ii = 0 ; ii < nPho ; ++ii ) { for( int jj = (ii+1); jj < nPho ; ++jj ) { // Preselection 2nd leg if (DoPreselection && !preselectPhoton(ii,phoEt[ii])) continue; if (DoPreselection && !preselectPhoton(jj,phoEt[jj])) continue; /// define i, j locally, so when they are inverted this does not mess up the loop int i = ii; int j = jj; if(phoEt[j] > phoEt[i]){ i = jj; j = ii; } // Select vertex int selVtx = 0; TLorentzVector gi,gj; double mij(-1); vector<int> selVtxIncl; if(_config->vtxSelType()==0) selVtxIncl = getSelectedVertex(i,j,true,true ); else //use sumpt2 ranking selVtxIncl = selVtxSumPt2; selVtx = selVtxIncl[0]; if( selVtx < 0 ) continue; /// check lepton tag if( muonIndex.size() > 0 ) { //selVtx = iMuonVtx; leptag.SetPtEtaPhiM( muPt[muonIndex[0]], muEta[muonIndex[0]], muPhi[muonIndex[0]],0); if( selectTwoPhotons(i,j,selVtx,gi,gj,vetoElec) ) { lepCat = 0; } } /// check electron tag only if muon tag failed if( elecIndex.size() > 0 && lepCat == -1 ) { //selVtx = iElecVtx; leptag.SetPtEtaPhiM( elePt[elecIndex[0]], eleEta[elecIndex[0]], elePhi[elecIndex[0]],0); if( selectTwoPhotons(i,j,selVtx,gi,gj,vetoElec) ) { lepCat = 1; if( fabs( (leptag+gi).M() - 91.19 ) < 10 || fabs( (leptag+gj).M() - 91.19 ) < 10 ) lepCat = -1; /// this is not actually the cut, but it should be but ok (dR(pho,eleTrk) > 1 no dR(pho,anyTrk) > 1 ) if(phoCiCdRtoTrk[i] < 1 || phoCiCdRtoTrk[j] <1 ) lepCat = -1; } } if( lepCat >= 0 ) { mij = (gi+gj).M(); if( _config->analysisType() == "MVA" ) if( gi.Pt() / mij < 45./120. || gj.Pt() / mij < 30./120. ) lepCat = -1; if( _config->analysisType() == "baselineCiC4PF" ) if( gi.Pt() / mij < 45./120. || gj.Pt() < 25. ) lepCat = -1; if( leptag.DeltaR(gi) < 1.0 || leptag.DeltaR(gj) < 1.0 ) lepCat = -1; } if( lepCat >= 0 ) { cout << " ****** keep leptag event pts[photons] i: " << i << " j: " << j << " -> event: " << ientry << endl; cout << " leptonCat: " << lepCat << endl; /// if one pair passes lepton tag then no need to go further /// fill in variables event_vtx.resize( 1); event_vtx[0] = selVtx; event_ilead.resize( 1); event_ilead[0] = i; event_itrail.resize(1); event_itrail[0] = j; event_plead.resize( 1); event_plead[0] = gi; event_ptrail.resize(1); event_ptrail[0] = gj; exitLoop = true; break; } else { /// inclusive + VBF + MetTag preselection /// apply kinematic cuts if( !selectTwoPhotons(i,j,selVtx,gi,gj,vetoElec) ) continue; /// drop photon pt cuts from inclusive cuts (add them in categorisation only) mij = (gi+gj).M(); if( ! _config->doSkimming() && ( gi.Pt() < _config->pt1Cut() || gi.Pt() < _config->pt2Cut() || gi.Pt()/mij < _config->loosePt1MCut() || gj.Pt()/mij < _config->loosePt2MCut() ) ) continue; } /// here i = lead; j = trail (selectTwoPhotons does that) /// fill in variables event_vtx.push_back( selVtx ); event_ilead.push_back( i ); event_itrail.push_back( j ); event_plead.push_back( gi ); event_ptrail.push_back( gj ); } if( exitLoop ) break; } if(event_ilead.size()==0 || event_itrail.size()==0)continue; if(event_vtx.size() == 0 ) continue; // no pairs selected nEvts[icutlevel++]++; // Now decide which photon-photon pair in the event to select // for lepton tag (size of arrays is 1, so dummy selection) unsigned int selectedPair = 0; float sumEt = -1; for (unsigned int p=0; p < event_vtx.size(); p++) { float tempSumEt = event_plead[p].Pt() + event_ptrail[p].Pt(); if( tempSumEt > sumEt) { sumEt = tempSumEt; selectedPair = p; } } int ilead = event_ilead[ selectedPair ]; int itrail = event_itrail[ selectedPair ]; int selVtx = event_vtx[ selectedPair ]; TLorentzVector glead = event_plead[selectedPair]; TLorentzVector gtrail = event_ptrail[selectedPair]; TLorentzVector hcand = glead + gtrail; int CAT4 = cat4(phoR9[ilead], phoR9[itrail], phoSCEta[ilead], phoSCEta[itrail]); if( glead.Pt() < _config->pt1Cut() ) continue; if( gtrail.Pt() < _config->pt2Cut() ) continue; if( hcand.M() < _config->mggCut() ) continue; nEvts[icutlevel++]++; _minitree->mtree_runNum = run; _minitree->mtree_evtNum = event; _minitree->mtree_lumiSec = lumis; // TLorentzVector g1,g2; // g1.SetPtEtaPhiM(phoE[ilead ]/cosh(phoEta[ilead]),phoEta[ilead ], phoPhi[ilead ], 0); // g2.SetPtEtaPhiM(phoE[itrail]/cosh(phoEta[ilead]),phoEta[itrail], phoPhi[itrail], 0); // TLorentzVector lgg = g1 + g2; //_minitree->mtree_massDefVtx = lgg.M(); _minitree->mtree_massDefVtx = hcand.M()/sqrt(phoE[ilead]*phoE[itrail])*sqrt(phoStdE[ilead]*phoStdE[itrail]); // calc again vertex to get correct vertex probability (can be different from last one in loop) vector<int> sortedVertex; if(_config->vtxSelType()==0) sortedVertex = getSelectedVertex( ilead, itrail, true, true ); else //use sumpt2 ranking sortedVertex = selVtxSumPt2; if( sortedVertex.size() < 2 ) sortedVertex.push_back(-1); if( sortedVertex.size() < 3 ) sortedVertex.push_back(-1); if( lepCat >= 0 ) { /// lepton tag sortedVertex[0] = selVtx; sortedVertex[1] = -1; sortedVertex[2] = -1; // vertProb = 1; } _minitree->mtree_rho = rho2012; _minitree->mtree_rho25 = rho25; _minitree->mtree_zVtx = vtxbs[selVtx][2]; _minitree->mtree_nVtx = nVtxBS; _minitree->mtree_ivtx1 = selVtx; _minitree->mtree_ivtx2 = sortedVertex[1]; _minitree->mtree_ivtx3 = sortedVertex[2]; _minitree->mtree_vtxProb = vertProb; _minitree->mtree_vtxMva = vertMVA; _minitree->mtree_mass = hcand.M(); _minitree->mtree_pt = hcand.Pt(); _minitree->mtree_piT = hcand.Pt()/hcand.M(); _minitree->mtree_y = hcand.Rapidity(); /// spin variables TLorentzVector gtmp1 = glead; gtmp1.Boost( -hcand.BoostVector() ); TLorentzVector gtmp2 = gtrail; gtmp2.Boost( -hcand.BoostVector() ); _minitree->mtree_cThetaLead_heli = cos( gtmp1.Angle(hcand.BoostVector()) ); _minitree->mtree_cThetaTrail_heli = cos( gtmp2.Angle(hcand.BoostVector()) ); _minitree->mtree_cThetaStar_CS = 2*(glead.E()*gtrail.Pz() - gtrail.E()*glead.Pz())/(hcand.M()*sqrt(hcand.M2()+hcand.Pt()*hcand.Pt())); /// fill photon id variables in main tree _minitree->mtree_minR9 = +999; _minitree->mtree_minPhoIdEB = +999; _minitree->mtree_minPhoIdEE = +999; _minitree->mtree_maxSCEta = -1; _minitree->mtree_minSCEta = +999; for( int i = 0 ; i < 2; i++ ) { int ipho = -1; if( i == 0 ) ipho = ilead; if( i == 1 ) ipho = itrail; fillPhotonVariablesToMiniTree( ipho, selVtx, i ); if( _minitree->mtree_r9[i] < _minitree->mtree_minR9 ) _minitree->mtree_minR9 = _minitree->mtree_r9[i]; if( fabs( _minitree->mtree_sceta[i] ) < 1.5 && _minitree->mtree_mvaid[i] < _minitree->mtree_minPhoIdEB ) _minitree->mtree_minPhoIdEB = _minitree->mtree_mvaid[i]; if( fabs( _minitree->mtree_sceta[i] ) >= 1.5 && _minitree->mtree_mvaid[i] < _minitree->mtree_minPhoIdEE ) _minitree->mtree_minPhoIdEE = _minitree->mtree_mvaid[i]; if( fabs( _minitree->mtree_sceta[i] ) > _minitree->mtree_maxSCEta ) _minitree->mtree_maxSCEta = fabs(_minitree->mtree_sceta[i]); if( fabs( _minitree->mtree_sceta[i] ) < _minitree->mtree_minSCEta ) _minitree->mtree_minSCEta = fabs(_minitree->mtree_sceta[i]); } //------------ compute diphoton mva (add var to minitree inside function) ----------------// massResoCalc.setP4CalPosVtxResoSmear( glead,gtrail, TVector3(phoCaloPos[ilead ][0], phoCaloPos[ilead ][1],phoCaloPos[ilead ][2]), TVector3(phoCaloPos[itrail][0], phoCaloPos[itrail][1],phoCaloPos[itrail][2]), TVector3(vtxbs[selVtx][0], vtxbs[selVtx][1], vtxbs[selVtx][2]), _minitree->mtree_relResOverE, _minitree->mtree_relSmearing ); _minitree->mtree_massResoTot = massResoCalc.relativeMassResolutionFab_total( vertProb ); _minitree->mtree_massResoEng = massResoCalc.relativeMassResolutionFab_energy( ); _minitree->mtree_massResoAng = massResoCalc.relativeMassResolutionFab_angular(); float diphotonmva = DiPhoID_MVA( glead, gtrail, hcand, massResoCalc, vertProb, _minitree->mtree_mvaid[0],_minitree->mtree_mvaid[1] ); // ---- Start categorisation ---- // _minitree->mtree_lepTag = 0; _minitree->mtree_metTag = 0; _minitree->mtree_vbfTag = 0; _minitree->mtree_hvjjTag = 0; // 1. lepton tag if( lepCat >= 0 ) { _minitree->mtree_lepTag = 1; _minitree->mtree_lepCat = lepCat; _minitree->mtree_fillLepTree = true; // if( lepCat == 0 ) fillMuonTagVariables(lepTag,glead,gtrail,elecIndex[0],selVtx); // if( lepCat == 1 ) fillElecTagVariables(lepTag,glead,gtrail,muonIndex[0],selVtx); } // 3. met tag (For the jet energy regression, MET needs to be corrected first.) _minitree->mtree_rawMet = recoPfMET; _minitree->mtree_rawMetPhi = recoPfMETPhi; // if( !isData ) { /// bug in data skim, met correction already applied //3.1 Soft Jet correction (FC?) applyJEC4SoftJets(); //3.2 smearing if( !isData ) METSmearCorrection(ilead, itrail); //3.3 shifting (even in data? but different in data and MC) METPhiShiftCorrection(); //3.4 scaling if( isData) METScaleCorrection(ilead, itrail); // } _minitree->mtree_corMet = recoPfMET; _minitree->mtree_corMetPhi = recoPfMETPhi; // 2. dijet tag Int_t nVtxJetID = -1; if( _config->doPUJetID() ) nVtxJetID = nVtxBS; //vector<int> goodJetsIndex = selectJets( ilead, itrail, nVtxJetID, wei, selVtx ); vector<int> goodJetsIndex = selectJetsJEC( ilead, itrail, nVtxJetID, wei, selVtx ); int vbftag(-1),hstratag(-1),catjet(-1); dijetSelection( glead, gtrail, goodJetsIndex, wei, selVtx, vbftag, hstratag, catjet); _minitree->mtree_vbfTag = vbftag; _minitree->mtree_hvjjTag = hstratag; _minitree->mtree_vbfCat = catjet; // 2x. radion analysis // take the very same photon candidates as in the H->GG analysis above _minitree->radion_evtNum = event; *(_minitree->radion_gamma1) = glead; *(_minitree->radion_gamma2) = gtrail; vector<int> goodJetsIndexRadion = selectJetsRadion(nVtxJetID, selVtx); _minitree->radion_bJetTags->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_genJetPt ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_eta ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_cef ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_nef ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_mef ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_nconstituents ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_chf ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_JECUnc ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_ptLeadTrack ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_vtxPt ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_vtx3dL ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_SoftLeptPtCut ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_dPhiMETJet ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_nch ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_vtx3deL ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_vtxMass ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_ptRaw ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_EnRaw ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_SoftLeptptRelCut->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_SoftLeptdRCut ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_partonID ->Set(goodJetsIndexRadion.size()); _minitree->radion_jet_dRJetGenJet ->Set(goodJetsIndexRadion.size()); _minitree->radion_MET = recoPfMET; _minitree->radion_rho25 = rho25; for (unsigned i = 0; i < goodJetsIndexRadion.size(); i++) { int iJet = goodJetsIndexRadion[i]; //_minitree->radion_bJetTags->AddAt(jetCombinedSecondaryVtxMVABJetTags[iJet], i); _minitree->radion_bJetTags->AddAt(jetCombinedSecondaryVtxBJetTags[iJet], i); _minitree->radion_jet_genJetPt ->AddAt(jetGenJetPt[iJet], i); _minitree->radion_jet_eta ->AddAt(jetEta[iJet], i); _minitree->radion_jet_cef ->AddAt(jetCEF[iJet], i); _minitree->radion_jet_nef ->AddAt(jetNEF[iJet], i); _minitree->radion_jet_mef ->AddAt(jetMEF[iJet], i); _minitree->radion_jet_nconstituents ->AddAt(jetNConstituents[iJet], i); _minitree->radion_jet_chf ->AddAt(jetCHF[iJet], i); _minitree->radion_jet_JECUnc ->AddAt(jetJECUnc[iJet], i); _minitree->radion_jet_ptLeadTrack ->AddAt(jetLeadTrackPt[iJet], i); _minitree->radion_jet_vtxPt ->AddAt(jetVtxPt[iJet], i); _minitree->radion_jet_vtx3dL ->AddAt(jetVtx3dL[iJet], i); _minitree->radion_jet_SoftLeptPtCut ->AddAt(jetSoftLeptPt[iJet], i); _minitree->radion_jet_nch ->AddAt(jetNCH[iJet], i); _minitree->radion_jet_vtx3deL ->AddAt(jetVtx3deL[iJet], i); _minitree->radion_jet_vtxMass ->AddAt(jetVtxMass[iJet], i); _minitree->radion_jet_ptRaw ->AddAt(jetRawPt[iJet], i); _minitree->radion_jet_EnRaw ->AddAt(jetRawEn[iJet], i); _minitree->radion_jet_SoftLeptptRelCut ->AddAt(jetSoftLeptPtRel[iJet], i); _minitree->radion_jet_SoftLeptdRCut ->AddAt(jetSoftLeptdR[iJet], i); _minitree->radion_jet_partonID ->AddAt(jetPartonID[iJet], i); _minitree->radion_jet_dRJetGenJet ->AddAt(sqrt(pow(jetEta[iJet]-jetGenEta[iJet],2)+pow(jetPhi[iJet]-jetGenPhi[iJet],2)), i); float tmpPi = 3.1415927, tmpDPhi=fabs(jetPhi[iJet]-recoPfMETPhi); if(tmpDPhi>tmpPi) tmpDPhi=2*tmpPi-tmpDPhi; _minitree->radion_jet_dPhiMETJet ->AddAt(tmpDPhi, i); TLorentzVector* jet = new((*(_minitree->radion_jets))[_minitree->radion_jets->GetEntriesFast()]) TLorentzVector(); jet->SetPtEtaPhiE(jetPt[iJet], jetEta[iJet], jetPhi[iJet], jetEn[iJet]); } // Continue step 3. if ( MetTagSelection(glead,gtrail,goodJetsIndex) && _minitree->mtree_vbfTag == 0 && _minitree->mtree_lepTag == 0 && _minitree->mtree_corMet > 70. && fabs( phoSCEta[ilead] ) < 1.45 && fabs( phoSCEta[itrail]) < 1.45 ) _minitree->mtree_metTag = 1; //----------- categorisation (for now incl + vbf + lep + met) -----------// _minitree->mtree_catBase = CAT4; _minitree->mtree_catMva = -1; for( int icat_mva = 0 ; icat_mva < 4; icat_mva++ ) if( diphotonmva >= Ddipho_cat[icat_mva] ) { _minitree->mtree_catMva = icat_mva; break; } if ( _minitree->mtree_lepTag == 1 ) { _minitree->mtree_catBase = _minitree->mtree_lepCat + 6; _minitree->mtree_catMva = _minitree->mtree_lepCat + 6; } else if( _minitree->mtree_vbfTag == 1 ) { _minitree->mtree_catBase = _minitree->mtree_vbfCat + 4; _minitree->mtree_catMva = _minitree->mtree_vbfCat + 4; } else if( _minitree->mtree_metTag == 1 ) { _minitree->mtree_catBase = 8; _minitree->mtree_catMva = 8; } if( diphotonmva < Ddipho_cat[3] ) _minitree->mtree_catMva = -1; /// photon pt cut was dropped from the inclusive cuts if( _minitree->mtree_catMva < 4 && (glead.Pt()/hcand.M() < 1./3. || gtrail.Pt()/hcand.M() < 1./4.) ) _minitree->mtree_catMva = -1; if( _minitree->mtree_catBase < 4 && (glead.Pt()/hcand.M() < 1./3. || gtrail.Pt()/hcand.M() < 1./4.) ) _minitree->mtree_catBase = -1; //------------ MC weighting factors and corrections if( !isData ) { /// needs to be recomputed for each event (because reinit var for each event) _minitree->mc_wNgen = 100000./_weight_manager->getNevts(); _minitree->mc_wXsec = _weight_manager->xSecW(mc_whzh_type); if( ( mode_ == 3 || mode_ == 19 ) && isprompt1 == 1 ) _minitree->mc_wXsec *= 1.3; _minitree->mc_wBSz = _weight_manager->bszW(vtxbs[selVtx][2]-mcVtx[0][2]); _minitree->mc_wVtxId = _weight_manager->vtxPtCorrW( hcand.Pt() ); /// photon identification float wPhoId[] = { 1., 1.}; for( int i = 0 ; i < 2; i++ ) { wPhoId[i] = 1; int index = -1; if( i == 0 ) index = ilead; if( i == 1 ) index = itrail; wPhoId[i] *= _weight_manager->phoIdPresel(phoR9[index],phoSCEta[index]); if( _config->analysisType() == "baselineCiC4PF" ) wPhoId[i] *= _weight_manager->phoIdCiC(phoR9[index],phoSCEta[index]); if( _config->analysisType() == "MVA" ) wPhoId[i] *= _weight_manager->phoIdMVA(phoR9[index],phoSCEta[index]); if( vetoElec[i] ) wPhoId[i] *= _weight_manager->phoIdEleVeto(phoR9[index],phoSCEta[index]); } _minitree->mc_wPhoEffi = wPhoId[0]*wPhoId[1]; /// trigger efficiency _minitree->mc_wTrigEffi = 0.9968; /// FIX ME /// cross section volontary not included in total weight _minitree->mc_wei = _minitree->mc_wPU * _minitree->mc_wBSz * _minitree->mc_wHQT * /// = 1 but in 2011 _minitree->mc_wVtxId * _minitree->mc_wPhoEffi * _minitree->mc_wTrigEffi * _minitree->mc_wNgen; wei = _minitree->mc_wei; } nEvts[icutlevel++]++; if( _minitree->mtree_lepTag ) nEvts[icutlevel+0]++; if( _minitree->mtree_vbfTag ) nEvts[icutlevel+1]++; //// following crap can be removed when the synchornization will be successfull. if( DoDebugEvent ) { _minitree->setSynchVariables(); _xcheckTextFile << " pho1 pos: " << phoPos[ilead] << endl; _xcheckTextFile << " ieta1 : " << phoSeedDetId1[ilead] << " iphi1: " << phoSeedDetId2[ilead] << endl; _xcheckTextFile << " pho2 pos: " << phoPos[itrail] << endl; _xcheckTextFile << " ieta1 : " << phoSeedDetId1[itrail] << " iphi1: " << phoSeedDetId2[itrail] << endl; _xcheckTextFile << " oversmear 1: " << overSmear.meanOverSmearing(phoSCEta[ilead],phoR9[ilead] ,isInGAP_EB(ilead),0) << endl; _xcheckTextFile << " oversmear 2: " << overSmear.meanOverSmearing(phoSCEta[itrail],phoR9[itrail],isInGAP_EB(itrail),0) << endl; _xcheckTextFile << " mass reso (eng only): " << _minitree->mtree_massResoEng << endl; _xcheckTextFile << " mass reso (ang only): " << _minitree->mtree_massResoAng << endl; for( unsigned i = 0 ; i < _minitree->sync_iName.size(); i++ ) cout << _minitree->sync_iName[i] << ":" << *_minitree->sync_iVal[i] << " "; for( unsigned i = 0 ; i < _minitree->sync_lName.size(); i++ ) cout << _minitree->sync_lName[i] << ":" << *_minitree->sync_lVal[i] << " "; for( unsigned i = 0 ; i < _minitree->sync_fName.size(); i++ ) cout << _minitree->sync_fName[i] << ":" << *_minitree->sync_fVal[i] << " "; cout << endl; cout << " myVtx = " << selVtx << "; 1=" << sortedVertex[1] << " 2= " << sortedVertex[2] << endl; for( int ivtx = 0; ivtx < nVtxBS; ivtx++ ) { cout << " etas[ ivtx = " << ivtx << "] = " << phoEtaVtx[ilead][ivtx] << " - " << phoEtaVtx[itrail][ivtx] << " - zVtx = " << vtxbs[ivtx][2] << endl; } } _minitree->fill(); if( _config->doSkimming() && tSkim ) { /// undo all modifs before filling the skim fChain->GetEntry(jentry); tSkim->Fill(); } //--------------- // } }// end for entry if( _config->doSkimming() ) { _minitree->mtree_file->cd(); TH1F *hEvents = new TH1F("hEvents","hEvents",2,0,2); hEvents->SetBinContent(1,_weight_manager->getNevts()); hEvents->SetBinContent(2,nEvts[nEvts.size()-1]); hEvents->Write(); tSkim->Write(); _minitree->mtree_file->Close(); } else _minitree->end(); for( unsigned icut = 0 ; icut < nEvts.size(); icut++ ) cout << nCutName[icut] << nEvts[icut] << endl; delete rnd; return nEvts[nEvts.size()-1]; }
void PlotTheta( TString inputfilename, TString outputfilename = "output.root"){ // infile= new TFile("../PATGrid.SM.10k.root","READ"); infile = new TFile(inputfilename, "READ"); tree = (TTree*)infile->Get("Event"); outputFile = new TFile(outputfilename, "RECREATE"); outTree = new TTree("MyTree","Untersuchung der RekoObjekte"); //TH2::SetDefaultSumw2(); histogram__CosThetaDiff = new TH1D("histogram__CosThetaDiff", "Differenz CosTheta gen-reko", 400, -2, 2); histogram__CosTheta_GenReko = new TH2D("histogram__CosTheta_GenReko", "Reko-cos(theta) gegen Gen-cos(theta)", 50, -1, 1, 50, -1, 1); histogram__gen_A = new TH2D("histogram__gen_A", "histogram__gen_A", 5, -1, 1, 5, -1, 1); histogram__gen_N = new TH2D("histogram__gen_N", "histogram__gen_N", 5, -1, 1, 5, -1, 1); histogram__gen_LL = new TH2D("histogram__gen_LL", "histogram__gen_LL", 5, -1, 1, 5, -1, 1); histogram__gen_LR = new TH2D("histogram__gen_LR", "histogram__gen_LR", 5, -1, 1, 5, -1, 1); histogram__gen_RR = new TH2D("histogram__gen_RR", "histogram__gen_RR", 5, -1, 1, 5, -1, 1); histogram__gen_RL = new TH2D("histogram__gen_RL", "histogram__gen_RL", 5, -1, 1, 5, -1, 1); histogram__gen_Correlation = new TH2D("histogram__gen_Correlation", "histogram__gen_Correlation", 5, -1, 1, 5, -1, 1); histogram__A = new TH2D("histogram__A", "histogram__A", 5, -1, 1, 5, -1, 1); histogram__N = new TH2D("histogram__N", "histogram__N", 5, -1, 1, 5, -1, 1); histogram__Correlation = new TH2D("histogram__Correlation", "histogram__Correlation", 5, -1, 1, 5, -1, 1); histogram__Correlation_L15_B50_T1 = new TH2D("histogram__Correlation_L15_B50_T1", "histogram__Correlation_L15_B50_T1", 5, -1, 1, 5, -1, 1); histogram__A_L15_B50_T1 = new TH2D("histogram__A_L15_B50_T1", "histogram__A_L15_B50_T1", 5, -1, 1, 5, -1, 1); histogram__N_L15_B50_T1 = new TH2D("histogram__N_L15_B50_T1", "histogram__N_L15_B50_T1", 5, -1, 1, 5, -1, 1); histogram__Correlation_L20 = new TH2D("histogram__Correlation_L20", "histogram__Correlation_L20", 5, -1, 1, 5, -1, 1); histogram__A_L20 = new TH2D("histogram__A_L20", "histogram__A_L20", 5, -1, 1, 5, -1, 1); histogram__N_L20 = new TH2D("histogram__N_L20", "histogram__N_L20", 5, -1, 1, 5, -1, 1); histogram__Correlation_L20_B40 = new TH2D("histogram__Correlation_L20_B40", "histogram__Correlation_L20_B40", 5, -1, 1, 5, -1, 1); histogram__A_L20_B40 = new TH2D("histogram__A_L20_B40", "histogram__A_L20_B40", 5, -1, 1, 5, -1, 1); histogram__N_L20_B40 = new TH2D("histogram__N_L20_B40", "histogram__N_L20_B40", 5, -1, 1, 5, -1, 1); histogram__Correlation_L20_B30_T1 = new TH2D("histogram__Correlation_L20_B30_T1", "histogram__Correlation_L20_B30_T1", 5, -1, 1, 5, -1, 1); histogram__A_L20_B30_T1 = new TH2D("histogram__A_L20_B30_T1", "histogram__A_L20_B30_T1", 5, -1, 1, 5, -1, 1); histogram__N_L20_B30_T1 = new TH2D("histogram__N_L20_B30_T1", "histogram__N_L20_B30_T1", 5, -1, 1, 5, -1, 1); histogram__Correlation_L20_B40_T1 = new TH2D("histogram__Correlation_L20_B40_T1", "histogram__Correlation_L20_B40_T1", 5, -1, 1, 5, -1, 1); histogram__A_L20_B40_T1 = new TH2D("histogram__A_L20_B40_T1", "histogram__A_L20_B40_T1", 5, -1, 1, 5, -1, 1); histogram__N_L20_B40_T1 = new TH2D("histogram__N_L20_B40_T1", "histogram__N_L20_B40_T1", 5, -1, 1, 5, -1, 1); histogram__Correlation_T1 = new TH2D("histogram__Correlation_T1", "histogram__Correlation_T1", 5, -1, 1, 5, -1, 1); histogram__A_T1 = new TH2D("histogram__A_T1", "histogram__A_T1", 5, -1, 1, 5, -1, 1); histogram__N_T1 = new TH2D("histogram__N_T1", "histogram__N_T1", 5, -1, 1, 5, -1, 1); histogram__CosThetaDiff_TTbarPt = new TH2D("histogram__CosThetaDiff_TTbarPt", "histogram__CosThetaDiff_TTbarPt", 100, 0, 1000, 400, -2, 2); histogram__LeptonRelIso = new TH1D("histogram__LeptonRelIso", "histogram__LeptonRelIso", 101, 0, 1.01); histogram__semilepton_BLeptonMinus = new TH1D("histogram__semilepton_BLeptonMinus","histogram__semilepton_BLeptonMinus", 200, -1, 1); histogram__semilepton_BLeptonPlus = new TH1D("histogram__semilepton_BLeptonPlus","histogram__semilepton_BLeptonPlus", 200, -1, 1); histogram_nupx_gen_reco = new TH2D(" histogram_nupx_gen_reco", " histogram_nupx_gen_reco", 600, -300, 300, 600, -300, 300); histogram_nupy_gen_reco = new TH2D(" histogram_nupy_gen_reco", " histogram_nupy_gen_reco", 600, -300, 300, 600, -300, 300); histogram_nupz_gen_reco = new TH2D(" histogram_nupz_gen_reco", " histogram_nupz_gen_reco", 600, -300, 300, 600, -300, 300); histogram_nubpx_gen_reco = new TH2D(" histogram_nubpx_gen_reco", " histogram_nubpx_gen_reco", 600, -300, 300, 600, -300, 300); histogram_nubpy_gen_reco = new TH2D(" histogram_nubpy_gen_reco", " histogram_nubpy_gen_reco", 600, -300, 300, 600, -300, 300); histogram_nubpz_gen_reco = new TH2D(" histogram_nubpz_gen_reco", " histogram_nubpz_gen_reco", 600, -300, 300, 600, -300, 300); outTree->Branch("EventIsGood", &EventIsGood, "Event ist rekonstruiert/I"); outTree->Branch("numberOfJets", &numberOfJets, "Anzahl der Jets/I"); outTree->Branch("numberOfGoodJets", &numberOfGoodJets, "Anzahl der guten Jets/I"); outTree->Branch("CosThetaDiff" ,&CosThetaDiff ,"Differenz im cosTheta Reko zu Gen/D"); outTree->Branch("CosThetaPlus" ,&CosThetaPlus ,"cosTheta LeptonPlus/D"); outTree->Branch("CosThetaMinus" ,&CosThetaMinus ,"cosTheta LeptonMinus/D"); outTree->Branch("RekoCosThetaPlus" ,&RekoCosThetaPlus ,"cosTheta RekoLeptonPlus/D"); outTree->Branch("RekoCosThetaMinus" ,&RekoCosThetaMinus ,"cosTheta RekoLeptonMinus/D"); outTree->Branch("CosLeptonAngleD", &CosLeptonAngleD, "CosinusLeptonWinkel D/D"); outTree->Branch("CosRekoLeptonAngleD", &CosRekoLeptonAngleD, "CosinusRekoLeptonWinkel D/D"); outTree->Branch("TTbar_Pt", &TTbar_Pt, "Pt des TTbarsystems Generator/D"); outTree->Branch("RekoTTbar_Pt", &RekoTTbar_Pt, "Pt des TTbarsystems Reko/D"); outTree->Branch("TTbar_M", &TTbar_M, "Masse des TTbarsystems Generator/D"); outTree->Branch("RekoTTbar_M", &RekoTTbar_M, "Masse des TTbarsystems Reko/D"); outTree->Branch("Top_Pt", &Top_Pt, "Pt des Tops Generator/D"); outTree->Branch("Top_M", &Top_M, "M des Tops Generator/D"); outTree->Branch("AntiTop_Pt", &AntiTop_Pt, "Pt des AntiTops Generator/D"); outTree->Branch("AntiTop_M", &AntiTop_M, "M des AntiTops Generator/D"); outTree->Branch("RekoTop_Pt", &RekoTop_Pt, "Pt des Tops Reko/D"); outTree->Branch("RekoAntiTop_Pt", &RekoAntiTop_Pt, "Pt des AntiTops Reko/D"); outTree->Branch("RekoTop_M", &RekoTop_M, "M des Tops Reko/D"); outTree->Branch("RekoAntiTop_M", &RekoAntiTop_M, "M des AntiTops Reko/D"); outTree->Branch("Nu_Px", &Nu_Px, "Px des Neutrinos Generator/D"); outTree->Branch("Nu_Py", &Nu_Py, "Py des Neutrinos Generator/D"); outTree->Branch("Nu_Pz", &Nu_Pz, "Pz des Neutrinos Generator/D"); outTree->Branch("AntiNu_Px", &AntiNu_Px, "Px des AntiNeutrinos Generator/D"); outTree->Branch("AntiNu_Py", &AntiNu_Py, "Py des AntiNeutrinos Generator/D"); outTree->Branch("AntiNu_Pz", &AntiNu_Pz, "Pz des AntiNeutrinos Generator/D"); outTree->Branch("RekoNu_Px", &RekoNu_Px, "Px des Neutrinos Reko/D"); outTree->Branch("RekoNu_Py", &RekoNu_Py, "Py des Neutrinos Reko/D"); outTree->Branch("RekoNu_Pz", &RekoNu_Pz, "Pz des Neutrinos Reko/D"); outTree->Branch("RekoAntiNu_Px", &RekoAntiNu_Px, "Px des AntiNeutrinos Reko/D"); outTree->Branch("RekoAntiNu_Py", &RekoAntiNu_Py, "Py des AntiNeutrinos Reko/D"); outTree->Branch("RekoAntiNu_Pz", &RekoAntiNu_Pz, "Pz des AntiNeutrinos Reko/D"); outTree->Branch("BestNu_Px", &BestNu_Px, "Px des Neutrinos Best/D"); outTree->Branch("BestNu_Py", &BestNu_Py, "Py des Neutrinos Best/D"); outTree->Branch("BestNu_Pz", &BestNu_Pz, "Pz des Neutrinos Best/D"); outTree->Branch("BestAntiNu_Px", &BestAntiNu_Px, "Px des AntiNeutrinos Best/D"); outTree->Branch("BestAntiNu_Py", &BestAntiNu_Py, "Py des AntiNeutrinos Best/D"); outTree->Branch("BestAntiNu_Pz", &BestAntiNu_Pz, "Pz des AntiNeutrinos Best/D"); outTree->Branch("Lepton_Pt", &Lepton_Pt, "kleineres Pt der beiden gewaehlten Leptonen/D"); outTree->Branch("BJet_Et", &BJet_Et,"niedrigieres Et der BJets/D"); outTree->Branch("BJet_Tag_TrkCount", &BJet_Tag_TrkCount,"niedrigierer BTag der BJets/D"); outTree->Branch("BJet_Tag_SVsimple", &BJet_Tag_SVsimple,"niedrigierer BTag der BJets/D"); outTree->Branch("BJet_Tag_SVcomb", &BJet_Tag_SVcomb,"niedrigierer BTag der BJets/D"); outTree->Branch("BJet_Disc", &BJet_Disc,"niedrigierer Discriminator der BJets/D"); outTree->Branch("Lepton1_Id", &Lepton1_Id, "PdgId des ersten Leptons/I"); outTree->Branch("Lepton2_Id", &Lepton2_Id, "PdgId des zweiten Leptons/I"); outTree->Branch("Lepton_Mass", &Lepton_Mass, "inv. Masse der beiden Leptonen/D"); outTree->Branch("BJet_Angle", &BJet_Angle, "Winkel bJet zu Quark/D"); outTree->Branch("BbarJet_Angle", &BbarJet_Angle, "Winkel bbarJet zu Quark/D"); outTree->Branch("LeptonPlus_Angle", &LeptonPlus_Angle, "Winkel LeptonPlus zu Lepton Gen /D"); outTree->Branch("LeptonMinus_Angle", &LeptonMinus_Angle, "Winkel LeptonMinus zu Lepton Gen /D"); outTree->Branch("RekoNu_Angle", &RekoNu_Angle, "Winkel RekoNu zu GenNu/D"); outTree->Branch("RekoAntiNu_Angle", &RekoAntiNu_Angle, "Winkel RekoAntiNu zu GenAntiNu/D"); outTree->Branch("BestNu_Angle", &BestNu_Angle, "Winkel BestNu zu GenNu/D"); outTree->Branch("BestAntiNu_Angle", &BestAntiNu_Angle, "Winkel BestAntiNu zu GenAntiNu/D"); histogram__gen_Correlation->Sumw2(); histogram__Correlation->Sumw2(); histogram__gen_A->Sumw2(); histogram__A->Sumw2(); histogram__gen_N->Sumw2(); histogram__N->Sumw2(); double PatJetsPx[50]; double PatJetsPy[50]; double PatJetsPz[50]; double PatJetsE[50]; double PatJetsEt[50]; double PatLeptonsPx[20]; double PatLeptonsPy[20]; double PatLeptonsPz[20]; double PatLeptonsPt[20]; double PatLeptonsE[20]; int PatLeptonsCharge[20]; int PatLeptonsPdgId[20]; double PatLeptonsTrkIso[20]; double PatLeptonsCaloIso[20]; double PatJetsBTag_TrkCount[50]; double PatJetsBTag_SVsimple[50]; double PatJetsBTag_SVcomb[50]; double PatJetsCharge[50]; double PatJetsBQuarkDeltaR[50]; double PatJetsBbarQuarkDeltaR[50]; int numberOfPatMuons; int numberOfPatElectrons; int numberOfPatLeptons; int numberOfPatJets; int numberOfLeptons; TLorentzVector *pTop; //FROM TREE TLorentzVector *pAntiTop; //FROM TREE TLorentzVector *pLeptonPlus; //FROM TREE TLorentzVector *pLeptonMinus; //FROM TREE TLorentzVector *pBQuark; //FROM TREE TLorentzVector *pBbarQuark; //FROM TREE TLorentzVector* pGenNu; //FROM TREE TLorentzVector* pGenAntiNu; //FROM TREE TLorentzVector *pTTbar; TLorentzVector *pTopBoosted; TLorentzVector *pAntiTopBoosted; TLorentzVector *pLeptonPlusBoosted; TLorentzVector *pLeptonMinusBoosted; TLorentzVector *pJet[50]; TLorentzVector *pBJet1; TLorentzVector *pBJet2; TLorentzVector *pRekoNu1; TLorentzVector *pRekoAntiNu1; TLorentzVector *pRekoNu2; TLorentzVector *pRekoAntiNu2; TLorentzVector *pRekoLeptonPlus; TLorentzVector *pRekoLeptonMinus; TLorentzVector *pBJet; TLorentzVector *pBbarJet; TLorentzVector *pRekoNu; TLorentzVector *pRekoAntiNu; TLorentzVector *pBestNu; TLorentzVector *pBestAntiNu; TLorentzVector *pBestNu2; TLorentzVector *pBestAntiNu2; TLorentzVector *pRekoTop; TLorentzVector *pRekoAntiTop; TLorentzVector *pRekoTTbar; TLorentzVector *pRekoTopBoosted; TLorentzVector *pRekoAntiTopBoosted; TLorentzVector *pRekoLeptonPlusBoosted; TLorentzVector *pRekoLeptonMinusBoosted; TLorentzVector *pNu; TLorentzVector *pAntiNu; TLorentzVector *pBBoosted; TLorentzVector *pBbarBoosted; pTop = new TLorentzVector(0,0,0,0); pAntiTop = new TLorentzVector(0,0,0,0); pLeptonPlus = new TLorentzVector(0,0,0,0); pLeptonMinus = new TLorentzVector(0,0,0,0); pBQuark = new TLorentzVector(0,0,0,0); pBbarQuark = new TLorentzVector(0,0,0,0); pGenNu = new TLorentzVector(0,0,0,0); pGenAntiNu = new TLorentzVector(0,0,0,0); pTTbar = new TLorentzVector(0,0,0,0); pTopBoosted = new TLorentzVector(0,0,0,0); pAntiTopBoosted = new TLorentzVector(0,0,0,0); pLeptonPlusBoosted = new TLorentzVector(0,0,0,0); pLeptonMinusBoosted = new TLorentzVector(0,0,0,0); pRekoTop = new TLorentzVector(0,0,0,0); pRekoAntiTop = new TLorentzVector(0,0,0,0); pRekoLeptonPlus = new TLorentzVector(0,0,0,0); pRekoLeptonMinus = new TLorentzVector(0,0,0,0); pRekoNu = new TLorentzVector(0,0,0,0); pRekoAntiNu = new TLorentzVector(0,0,0,0); pBestNu = new TLorentzVector(0,0,0,0); pBestAntiNu = new TLorentzVector(0,0,0,0); pBestNu2 = new TLorentzVector(0,0,0,0); pBestAntiNu2 = new TLorentzVector(0,0,0,0); pRekoTTbar = new TLorentzVector(0,0,0,0); pRekoTopBoosted = new TLorentzVector(0,0,0,0); pRekoAntiTopBoosted = new TLorentzVector(0,0,0,0); pRekoLeptonPlusBoosted = new TLorentzVector(0,0,0,0); pRekoLeptonMinusBoosted = new TLorentzVector(0,0,0,0); pNu = new TLorentzVector(0,0,0,0); pAntiNu = new TLorentzVector(0,0,0,0); pBJet1 = new TLorentzVector(0,0,0,0); pBJet2 = new TLorentzVector(0,0,0,0); pRekoNu1 = new TLorentzVector(0,0,0,0); pRekoAntiNu1 = new TLorentzVector(0,0,0,0); pRekoNu2 = new TLorentzVector(0,0,0,0); pRekoAntiNu2 = new TLorentzVector(0,0,0,0); pBJet = new TLorentzVector(0,0,0,0); pBbarJet = new TLorentzVector(0,0,0,0); pBBoosted = new TLorentzVector(0,0,0,0); pBbarBoosted = new TLorentzVector(0,0,0,0); for(int i=0; i<50;i++) pJet[i] = new TLorentzVector(0,0,0,0); double mass_a = 170.0; double mass_b = 175.0; calc Poly(mass_a, mass_b, outputFile); tree->SetBranchAddress("pTop", &pTop); tree->SetBranchAddress("pAntiTop", &pAntiTop); tree->SetBranchAddress("pLeptonPlus", &pLeptonPlus); tree->SetBranchAddress("pLeptonMinus", &pLeptonMinus); tree->SetBranchAddress("pBQuark", &pBQuark); tree->SetBranchAddress("pBbarQuark", &pBbarQuark); tree->SetBranchAddress("PatLeptonsPx", PatLeptonsPx); tree->SetBranchAddress("PatLeptonsPy", PatLeptonsPy); tree->SetBranchAddress("PatLeptonsPz", PatLeptonsPz); tree->SetBranchAddress("PatLeptonsPt", PatLeptonsPt); tree->SetBranchAddress("PatLeptonsE", PatLeptonsE); tree->SetBranchAddress("PatLeptonsCharge", PatLeptonsCharge); tree->SetBranchAddress("PatLeptonsPdgId", PatLeptonsPdgId); tree->SetBranchAddress("PatLeptonsTrkIso", PatLeptonsTrkIso); tree->SetBranchAddress("PatLeptonsCaloIso", PatLeptonsCaloIso); tree->SetBranchAddress("PatJetsPx", PatJetsPx); tree->SetBranchAddress("PatJetsPy", PatJetsPy); tree->SetBranchAddress("PatJetsPz", PatJetsPz); tree->SetBranchAddress("PatJetsE", PatJetsE); tree->SetBranchAddress("PatJetsEt", PatJetsEt); tree->SetBranchAddress("PatJetsCharge", PatJetsCharge); tree->SetBranchAddress("PatJetsBTag_TrkCount", PatJetsBTag_TrkCount); tree->SetBranchAddress("PatJetsBTag_SVsimple", PatJetsBTag_SVsimple); tree->SetBranchAddress("PatJetsBTag_SVcomb", PatJetsBTag_SVcomb); tree->SetBranchAddress("PatJetsBQuarkDeltaR", PatJetsBQuarkDeltaR); tree->SetBranchAddress("PatJetsBbarQuarkDeltaR", PatJetsBbarQuarkDeltaR); tree->SetBranchAddress("numberOfPatMuons", &numberOfPatMuons); tree->SetBranchAddress("numberOfPatElectrons", &numberOfPatElectrons); tree->SetBranchAddress("numberOfPatLeptons", &numberOfPatLeptons); tree->SetBranchAddress("numberOfPatJets", &numberOfPatJets); tree->SetBranchAddress("numberOfLeptons", &numberOfLeptons); tree->SetBranchAddress("pGenNu", &pGenNu); tree->SetBranchAddress("pGenAntiNu", &pGenAntiNu); int nEvents = (int)tree->GetEntries(); //nEvents = 5000; int EventCounter = 0; cout << "Anzahl Ereignisse: " << nEvents << endl; for(int iEvent=1; iEvent<nEvents;iEvent++){ tree->GetEntry(iEvent); EventCounter++; if(iEvent%10000 == 1) { cout << "Event " << iEvent << endl; } EventIsGood = 0; // GENERATOR THETA w_A = 0; w_N = 0; *pTTbar=(*pTop+*pAntiTop); *pTopBoosted = *pTop; *pAntiTopBoosted = *pAntiTop; *pLeptonPlusBoosted = *pLeptonPlus; *pLeptonMinusBoosted = *pLeptonMinus; *pBBoosted = *pBQuark; *pBbarBoosted = *pBbarQuark; pAntiTopBoosted->Boost(-pTTbar->BoostVector()); pTopBoosted->Boost(-pTTbar->BoostVector()); pLeptonPlusBoosted->Boost(-pTop->BoostVector()); pLeptonMinusBoosted->Boost(-pAntiTop->BoostVector()); CosThetaPlus = cos(pLeptonPlusBoosted->Angle(pTopBoosted->Vect())); CosThetaMinus = cos(pLeptonMinusBoosted->Angle(pAntiTopBoosted->Vect())); pBBoosted->Boost(-pTop->BoostVector()); pBbarBoosted->Boost(-pAntiTop->BoostVector()); CosLeptonAngleD = cos(pLeptonPlusBoosted->Angle(pLeptonMinusBoosted->Vect())); double Nenner = 1 - 0.256*CosThetaPlus*CosThetaMinus; w_A = (-CosThetaPlus*CosThetaMinus)/Nenner; w_N = 1./Nenner; w_LL = (1-CosThetaPlus*CosThetaMinus-CosThetaPlus+CosThetaMinus)/Nenner; w_LR = (1+CosThetaPlus*CosThetaMinus-CosThetaPlus-CosThetaMinus)/Nenner; w_RR = (1-CosThetaPlus*CosThetaMinus+CosThetaPlus-CosThetaMinus)/Nenner; w_RL = (1+CosThetaPlus*CosThetaMinus+CosThetaPlus+CosThetaMinus)/Nenner; histogram__gen_A->Fill(CosThetaPlus, CosThetaMinus, w_A); histogram__gen_N->Fill(CosThetaPlus, CosThetaMinus, w_N); histogram__gen_LL->Fill(CosThetaPlus, CosThetaMinus, w_LL); histogram__gen_LR->Fill(CosThetaPlus, CosThetaMinus, w_LR); histogram__gen_RR->Fill(CosThetaPlus, CosThetaMinus, w_RR); histogram__gen_RL->Fill(CosThetaPlus, CosThetaMinus, w_RL); histogram__gen_Correlation->Fill(CosThetaPlus, CosThetaMinus); if(numberOfLeptons == 2) { if(pLeptonMinus->Px() != 0) histogram__semilepton_BLeptonMinus->Fill( cos(pLeptonMinusBoosted->Angle(pBBoosted->Vect())) ); if(pLeptonPlus->Px() != 0) histogram__semilepton_BLeptonPlus->Fill( cos(pLeptonPlusBoosted->Angle(pBbarBoosted->Vect())) ); } numberOfJets = numberOfPatJets; if(numberOfPatLeptons>=2 && numberOfPatJets >=2) { RekoNu_Px = -10000; RekoNu_Py= -10000; RekoNu_Pz= -10000; RekoAntiNu_Px= -10000; RekoAntiNu_Py= -10000; RekoAntiNu_Pz= -10000; RekoTop_M = -10; RekoAntiTop_M = -10; RekoTop_Pt = -10; RekoAntiTop_Pt = -10; // REKO THETA pBJet1->SetPxPyPzE(0.,0.,0.,0.); pBJet2->SetPxPyPzE(0.,0.,0.,0.); pRekoLeptonPlus->SetPxPyPzE(0.,0.,0.,0.); pRekoLeptonMinus->SetPxPyPzE(0.,0.,0.,0.); pBJet->SetPxPyPzE(0.,0.,0.,0.); pBbarJet->SetPxPyPzE(0.,0.,0.,0.); pRekoNu->SetPxPyPzE(0.,0.,0.,-10000.); pRekoAntiNu->SetPxPyPzE(0.,0.,0.,-10000.); pBestNu->SetPxPyPzE(0.,0.,0.,-10000.); pBestAntiNu->SetPxPyPzE(0.,0.,0.,-10000.); pRekoNu1->SetPxPyPzE(0.,0.,0.,-10000.); pRekoAntiNu1->SetPxPyPzE(0.,0.,0.,-10000.); pRekoNu2->SetPxPyPzE(0.,0.,0.,-10000.); pRekoAntiNu2->SetPxPyPzE(0.,0.,0.,-10000.); int LeptonIndex[20]; int BTagTrkCountIndex[50]; int BTagSVsimpleIndex[50]; int BTagSVcombIndex[50]; int BJetsEIndex[50]; int BJetDeltaRIndex[50]; int BbarJetDeltaRIndex[50]; TMath::Sort(20,PatLeptonsE,LeptonIndex); TMath::Sort(50,PatJetsBTag_TrkCount, BTagTrkCountIndex); TMath::Sort(50,PatJetsBTag_SVsimple, BTagSVsimpleIndex); TMath::Sort(50,PatJetsBTag_SVcomb, BTagSVcombIndex); TMath::Sort(50, PatJetsE, BJetsEIndex); TMath::Sort(50, PatJetsBQuarkDeltaR, BJetDeltaRIndex); TMath::Sort(50, PatJetsBbarQuarkDeltaR, BbarJetDeltaRIndex); // Leptonen auswaehlen int OtherLepton = -1; for(int j=0; PatLeptonsCharge[LeptonIndex[0]]==PatLeptonsCharge[LeptonIndex[j]] && j<20; j++){ OtherLepton=j+1; } // if(PatLeptonsCharge[LeptonIndex[OtherLepton]]==0) std::cout<<"Only Leptons of same Charge in Event " << iEvent << "!!"<<std::endl; if(PatLeptonsCharge[LeptonIndex[OtherLepton]]!=0){ // Leptonen zuordnen if(PatLeptonsCharge[LeptonIndex[0]]==-1){ pRekoLeptonMinus->SetPxPyPzE(PatLeptonsPx[LeptonIndex[0]], PatLeptonsPy[LeptonIndex[0]], PatLeptonsPz[LeptonIndex[0]], PatLeptonsE[LeptonIndex[0]] ); } if(PatLeptonsCharge[LeptonIndex[0]]==+1){ pRekoLeptonPlus->SetPxPyPzE(PatLeptonsPx[LeptonIndex[0]], PatLeptonsPy[LeptonIndex[0]], PatLeptonsPz[LeptonIndex[0]], PatLeptonsE[LeptonIndex[0]] ); } if(PatLeptonsCharge[LeptonIndex[OtherLepton]]==-1){ pRekoLeptonMinus->SetPxPyPzE(PatLeptonsPx[LeptonIndex[OtherLepton]], PatLeptonsPy[LeptonIndex[OtherLepton]], PatLeptonsPz[LeptonIndex[OtherLepton]],PatLeptonsE[LeptonIndex[OtherLepton]] ); } if(PatLeptonsCharge[LeptonIndex[OtherLepton]]==+1){ pRekoLeptonPlus->SetPxPyPzE(PatLeptonsPx[LeptonIndex[OtherLepton]], PatLeptonsPy[LeptonIndex[OtherLepton]], PatLeptonsPz[LeptonIndex[OtherLepton]], PatLeptonsE[LeptonIndex[OtherLepton]] ); } //cout << "Leptonen ausgewaehlt" << endl; Lepton_Mass = ((*pRekoLeptonPlus) + (*pRekoLeptonMinus)).M(); if( TMath::Abs( Lepton_Mass - 90.0 ) > 10 || PatLeptonsPdgId[LeptonIndex[0]] + PatLeptonsPdgId[LeptonIndex[OtherLepton]] !=0 ) { double JetDisc[50]; numberOfGoodJets = 0; for(int j=0; j<50; j++){ JetDisc[j] = 0.; if(j<numberOfPatJets){ //JetDisc[j] = PatJetsBTag_TrkCount[j] * PatJetsEt[j]; if(PatJetsBTag_TrkCount[j]>1. && PatJetsEt[j]>20){ pJet[j]->SetPxPyPzE(PatJetsPx[j],PatJetsPy[j], PatJetsPz[j], PatJetsE[j]); if(TMath::Min(pJet[j]->Angle(pRekoLeptonPlus->Vect()), pJet[j]->Angle(pRekoLeptonMinus->Vect())) >0.1){ numberOfGoodJets++; JetDisc[j] = PatJetsBTag_TrkCount[j] * PatJetsEt[j]; } } if(j<numberOfPatLeptons){ histogram__LeptonRelIso->Fill(PatLeptonsPt[j]/(PatLeptonsPt[j]+PatLeptonsTrkIso[j]+PatLeptonsCaloIso[j])); } } } int JetDiscIndex[50]; TMath::Sort(50, JetDisc, JetDiscIndex); // Jets auswaehlen // verbesserte Auswahl (BTag*ET) pBJet1->SetPxPyPzE(PatJetsPx[JetDiscIndex[0]],PatJetsPy[JetDiscIndex[0]],PatJetsPz[JetDiscIndex[0]],PatJetsE[JetDiscIndex[0]]); pBJet2->SetPxPyPzE(PatJetsPx[JetDiscIndex[1]],PatJetsPy[JetDiscIndex[1]],PatJetsPz[JetDiscIndex[1]],PatJetsE[JetDiscIndex[1]]); //pBJet1->SetPxPyPzE(PatJetsPx[BTagTrkCountIndex[0]],PatJetsPy[BTagTrkCountIndex[0]],PatJetsPz[BTagTrkCountIndex[0]],PatJetsE[BTagTrkCountIndex[0]]); //pBJet2->SetPxPyPzE(PatJetsPx[BTagTrkCountIndex[1]],PatJetsPy[BTagTrkCountIndex[1]],PatJetsPz[BTagTrkCountIndex[1]],PatJetsE[BTagTrkCountIndex[1]]); //cout << "Jets gewaehlt" << endl; // Neutrinos berechnen //Generator-Werte setzen fuer Vergleich mit Berechnung pNu->SetPxPyPzE(pGenNu->Px(),pGenNu->Py(),pGenNu->Pz(),pGenNu->E()); pAntiNu->SetPxPyPzE(pGenAntiNu->Px(),pGenAntiNu->Py(),pGenAntiNu->Pz(),pGenAntiNu->E()); Poly.Init(pRekoLeptonPlus, pRekoLeptonMinus, pBJet1, pBJet2, pNu, pAntiNu); // BJet1 = b, BJet2 = bbar Poly.Solve(170.0,171.0 , iEvent, pRekoNu1, pRekoAntiNu1, pBestNu, pBestAntiNu); Poly.Init(pRekoLeptonPlus, pRekoLeptonMinus, pBJet2, pBJet1, pNu, pAntiNu); // BJet1 = bbar, BJet2 = b Poly.Solve(170.0,171.0 , iEvent, pRekoNu2, pRekoAntiNu2, pBestNu2, pBestAntiNu2); //cout << "Neutrinos berechnet" << endl; // Abfrage, ob Neutrinoloesung ungleich -10000 !!! if(pRekoAntiNu1->Pz() != -10000 && pRekoAntiNu2->Pz() != -10000){ if(TMath::Abs( ((*pRekoLeptonPlus)+(*pRekoNu1)+(*pBJet1)).M() + ((*pRekoLeptonMinus)+(*pRekoAntiNu1)+(*pBJet2)).M() - 2*173.2) < TMath::Abs(((*pRekoLeptonPlus)+(*pRekoNu2)+(*pBJet2)).M() + ((*pRekoLeptonMinus)+(*pRekoAntiNu2)+(*pBJet1)).M() - 2*173.2) ){ *pBJet = *pBJet1; *pBbarJet = *pBJet2; *pRekoNu = *pRekoNu1; *pRekoAntiNu = *pRekoAntiNu1; } else { *pBJet = *pBJet2; *pBbarJet = *pBJet1; *pRekoNu = *pRekoNu2; *pRekoAntiNu = *pRekoAntiNu2; *pBestNu = *pBestNu2; *pBestAntiNu = *pBestAntiNu2; } } else if(pRekoAntiNu1->Pz() != -10000){ *pBJet = *pBJet1; *pBbarJet = *pBJet2; *pRekoNu = *pRekoNu1; *pRekoAntiNu = *pRekoAntiNu1; } else if(pRekoAntiNu2->Pz() != -10000){ *pBJet = *pBJet2; *pBbarJet = *pBJet1; *pRekoNu = *pRekoNu2; *pRekoAntiNu = *pRekoAntiNu2; *pBestNu = *pBestNu2; *pBestAntiNu = *pBestAntiNu2; } else{ pRekoNu->SetPxPyPzE(0,0,-10000, 10000); pRekoAntiNu->SetPxPyPzE(0,0,-10000, 10000); pBestNu->SetPxPyPzE(0,0,-10000, 10000); pBestAntiNu->SetPxPyPzE(0,0,-10000, 10000); pBJet->SetPxPyPzE(0,0,-10000, 10000); pBbarJet->SetPxPyPzE(0,0,-10000, 10000); } TTbar_Pt = pTTbar->Pt(); TTbar_M = pTTbar->M(); Top_Pt = pTop->Pt(); AntiTop_Pt = pAntiTop->Pt(); Top_M = pTop->M(); AntiTop_M = pAntiTop->M(); Nu_Px = pNu->Px(); Nu_Py = pNu->Py(); Nu_Pz = pNu->Pz(); AntiNu_Px = pAntiNu->Px(); AntiNu_Py = pAntiNu->Py(); AntiNu_Pz = pAntiNu->Pz(); Lepton_Pt = TMath::Min(pRekoLeptonPlus->Pt(), pRekoLeptonMinus->Pt()); BJet_Et = TMath::Min(pBJet->Et(), pBbarJet->Et()); BJet_Tag_SVsimple = PatJetsBTag_SVsimple[BTagSVsimpleIndex[1]]; BJet_Tag_SVcomb = PatJetsBTag_SVcomb[BTagSVcombIndex[1]]; BJet_Tag_TrkCount = PatJetsBTag_TrkCount[BTagTrkCountIndex[1]]; BJet_Disc = JetDisc[JetDiscIndex[1]]; Lepton1_Id = PatLeptonsPdgId[LeptonIndex[0]]; Lepton2_Id = PatLeptonsPdgId[LeptonIndex[OtherLepton]]; LeptonPlus_Angle = -10.; LeptonMinus_Angle = -10.; BJet_Angle = -10.; BbarJet_Angle = -10.; RekoNu_Angle = -10.; RekoAntiNu_Angle = -10.; BestNu_Angle = -10.; BestAntiNu_Angle = -10.; //cout << "Werte gesetzt" << endl; if(pRekoAntiNu->Pz() > -10000){ histogram_nupx_gen_reco->Fill(pGenNu->Px(), pRekoNu->Px()); histogram_nubpx_gen_reco->Fill(pGenAntiNu->Px(), pRekoAntiNu->Px()); histogram_nupy_gen_reco->Fill(pGenNu->Py(), pRekoNu->Py()); histogram_nubpy_gen_reco->Fill(pGenAntiNu->Py(), pRekoAntiNu->Py()); histogram_nupz_gen_reco->Fill(pGenNu->Pz(), pRekoNu->Pz()); histogram_nubpz_gen_reco->Fill(pGenAntiNu->Pz(), pRekoAntiNu->Pz()); if(pLeptonPlus->E() != 0 && pLeptonMinus->E() != 0 && pBQuark->E() != 0 ){ BJet_Angle = pBJet->DeltaR(*pBQuark); BbarJet_Angle = pBbarJet->DeltaR(*pBbarQuark); LeptonPlus_Angle = pRekoLeptonPlus->DeltaR(*pLeptonPlus); LeptonMinus_Angle = pRekoLeptonMinus->DeltaR(*pLeptonMinus); RekoNu_Angle = pRekoNu->DeltaR(*pNu); RekoAntiNu_Angle = pRekoAntiNu->DeltaR(*pAntiNu); BestNu_Angle = pBestNu->DeltaR(*pNu); BestAntiNu_Angle = pBestAntiNu->DeltaR(*pAntiNu); } RekoNu_Px = pRekoNu->Px(); RekoNu_Py = pRekoNu->Py(); RekoNu_Pz = pRekoNu->Pz(); RekoAntiNu_Px = pRekoAntiNu->Px(); RekoAntiNu_Py = pRekoAntiNu->Py(); RekoAntiNu_Pz = pRekoAntiNu->Pz(); BestNu_Px = pBestNu->Px(); BestNu_Py = pBestNu->Py(); BestNu_Pz = pBestNu->Pz(); BestAntiNu_Px = pBestAntiNu->Px(); BestAntiNu_Py = pBestAntiNu->Py(); BestAntiNu_Pz = pBestAntiNu->Pz(); if(pRekoLeptonPlus->E()!=0 && pRekoLeptonMinus->E()!=0 && pBJet->E()!=0 && pBbarJet->E()!=0){ EventIsGood = 1; *pRekoTop = (*pRekoLeptonPlus) + (*pBJet) + (*pRekoNu); *pRekoAntiTop = (*pRekoLeptonMinus) + (*pBbarJet) + (*pRekoAntiNu); *pRekoTTbar = (*pRekoTop) + (*pRekoAntiTop); *pRekoTopBoosted = *pRekoTop; *pRekoAntiTopBoosted = *pRekoAntiTop; *pRekoLeptonPlusBoosted = *pRekoLeptonPlus; *pRekoLeptonMinusBoosted = *pRekoLeptonMinus; pRekoAntiTopBoosted->Boost(-pRekoTTbar->BoostVector()); pRekoTopBoosted->Boost(-pRekoTTbar->BoostVector()); pRekoLeptonPlusBoosted->Boost(-pRekoTop->BoostVector()); pRekoLeptonMinusBoosted->Boost(-pRekoAntiTop->BoostVector()); RekoCosThetaPlus = cos(pRekoLeptonPlusBoosted->Angle(pRekoTopBoosted->Vect())); RekoCosThetaMinus = cos(pRekoLeptonMinusBoosted->Angle(pRekoAntiTopBoosted->Vect())); //cout << "Cos(Theta) Gen-Reko: " << CosThetaPlus - RekoCosThetaPlus << endl; CosThetaDiff = RekoCosThetaPlus - CosThetaPlus; CosRekoLeptonAngleD = cos(pRekoLeptonPlusBoosted->Angle(pRekoLeptonMinusBoosted->Vect())); RekoTTbar_Pt = pRekoTTbar->Pt(); RekoTTbar_M = pRekoTTbar->M(); RekoTop_Pt = pRekoTop->Pt(); RekoAntiTop_Pt = pRekoAntiTop->Pt(); RekoTop_M = pRekoTop->M(); RekoAntiTop_M = pRekoAntiTop->M(); histogram__A->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); histogram__Correlation->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__CosThetaDiff->Fill( CosThetaPlus - RekoCosThetaPlus ); histogram__CosThetaDiff->Fill( CosThetaMinus - RekoCosThetaMinus ); histogram__CosTheta_GenReko->Fill(CosThetaPlus, RekoCosThetaPlus); histogram__CosThetaDiff_TTbarPt->Fill(pTTbar->Pt(), CosThetaPlus - RekoCosThetaPlus); if(BJet_Tag_TrkCount > 1.0){ histogram__Correlation_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__A_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); } if(pRekoLeptonPlus->Pt()>15 && pRekoLeptonMinus->Pt()>15 && pBJet->Et()>50 && pBbarJet->Et()>50 && PatJetsBTag_TrkCount[BTagTrkCountIndex[1]]>1 ){ histogram__Correlation_L15_B50_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__A_L15_B50_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N_L15_B50_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); } if(pRekoLeptonPlus->Pt()>20 && pRekoLeptonMinus->Pt()>20){ histogram__Correlation_L20->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__A_L20->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N_L20->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); if(pBJet->Et() > 30 && pBbarJet->Et() > 30 && PatJetsBTag_TrkCount[BTagTrkCountIndex[1]] > 1){ histogram__Correlation_L20_B30_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__A_L20_B30_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N_L20_B30_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); } if(pBJet->Et() > 40 && pBbarJet->Et() > 40){ histogram__Correlation_L20_B40->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__A_L20_B40->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N_L20_B40->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); if(PatJetsBTag_TrkCount[BTagTrkCountIndex[1]] > 1 ){ histogram__Correlation_L20_B40_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus); histogram__A_L20_B40_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_A); histogram__N_L20_B40_T1->Fill(RekoCosThetaPlus, RekoCosThetaMinus, w_N); } } } } // Leptonen und B != 0 } // Neutrino-Pz != -10000 } // inv. Masse der Leptonen != Z-Masse+-10 }// abfrage auf 2 Leptonen unterschiedlicher Ladung //cout << "Tree wird gefuellt: "; //cout << " und ist fertig" << endl; } outTree->Fill(); } // EventLoop cout << "gezaehlte Ereignisse: " << EventCounter << endl; cout << "Rekonstruierte Ereignisse: " << histogram__Correlation->Integral() << endl; outputFile->cd(""); outputFile->Write(); outputFile->Close(); delete outputFile; }