int NeroMonteCarlo::analyze(const edm::Event& iEvent){ if ( iEvent.isRealData() ) return 0; isRealData = iEvent.isRealData() ? 1 : 0 ; // private, not the one in the tree TStopwatch sw; if(VERBOSE)sw.Start(); // maybe handle should be taken before iEvent.getByToken(info_token, info_handle); iEvent.getByToken(packed_token, packed_handle); iEvent.getByToken(pruned_token, pruned_handle); iEvent.getByToken(pu_token, pu_handle); iEvent.getByToken(jet_token, jet_handle); if ( not info_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] info_handle is not valid"<<endl; if ( not packed_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] packed_handle is not valid"<<endl; if ( not pruned_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] pruned_handle is not valid"<<endl; if ( not pu_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] pu_handle is not valid"<<endl; if ( not jet_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] jet_handle is not valid"<<endl; if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] getToken took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();} // INFO if(VERBOSE>1) cout<<"[NeroMonteCarlo]::[analyze]::[DEBUG] mcWeight="<<endl; mcWeight = info_handle -> weight(); if(VERBOSE>1) cout<<" mcWeight="<<mcWeight<<endl; //weights() //--- scale if ( info_handle -> weights() .size() >= 9){ r1f2 = info_handle -> weights() [1] ; r1f5 = info_handle -> weights() [2] ; r2f1 = info_handle -> weights() [3] ; r2f2 = info_handle -> weights() [4] ; r5f1 = info_handle -> weights() [6] ; r5f5 = info_handle -> weights() [8] ; } if (info_handle -> weights().size() > 109) for( int pdfw = 9 ; pdfw<109 ;++pdfw) { pdfRwgt -> push_back( info_handle -> weights() [pdfw] ); } // --- fill pdf Weights // if(VERBOSE>1) cout<<"[NeroMonteCarlo]::[analyze]::[DEBUG] PDF="<<endl; if ( mParticleGun ) { qScale = -999 ; alphaQED = -999 ; alphaQCD = -999 ; x1 = -999 ; x2 = -999 ; pdf1Id = -999 ; pdf2Id = -999 ; scalePdf = -999 ; } else { qScale = info_handle -> qScale(); alphaQED = info_handle -> alphaQED(); alphaQCD = info_handle -> alphaQCD(); x1 = info_handle -> pdf() -> x.first; x2 = info_handle -> pdf() -> x.second; pdf1Id = info_handle -> pdf() -> id.first; pdf2Id = info_handle -> pdf() -> id.second; scalePdf = info_handle -> pdf() -> scalePDF; } if(VERBOSE>1) cout<<" PDF="<<qScale<<" "<< alphaQED<<endl; //PU if(VERBOSE>1){ cout<<endl<<"[NeroMonteCarlo]::[analyze] PU LOOP"<<endl;} puTrueInt = 0; for(const auto & pu : *pu_handle) { //Intime if (pu.getBunchCrossing() == 0) puTrueInt += pu.getTrueNumInteractions(); //puInt += getPU_NumInteractions(); //old //Out-of-time } if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] pu&info took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();} // GEN PARTICLES //TLorentzVector genmet(0,0,0,0); //for ( auto & gen : *packed_handle) for ( unsigned int i=0;i < packed_handle->size() ;++i) { const auto gen = & (*packed_handle)[i]; if (gen->pt() < 5 ) continue; if (gen->pt() < mMinGenParticlePt ) continue; int pdg = gen->pdgId(); int apdg = abs(pdg); //neutrinos // --- if ( (apdg != 12 and apdg !=14 and apdg != 16 // --- and apdg > 1000000 neutrinos and neutralinos // --- )//SUSY // --- and fabs(gen->eta() ) <4.7 // --- ) // --- { // --- TLorentzVector tmp( gen->px(),gen->py(),gen->pz(),gen->energy() ); // --- genmet += tmp; // --- } // --- genmet = -genmet; //FILL // e mu photons if ( apdg == 11 or apdg == 13 or apdg == 22 // e - mu - gamma or (apdg >=12 and apdg<=16) // neutrinos or apdg > 1000000 // susy neutrinos and neutralinos ) { new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(gen->px(), gen->py(), gen->pz(), gen->energy()); pdgId -> push_back( pdg ); flags -> push_back( ComputeFlags( *gen ) ); // compute ISOLATION float iso=0; float isoFx=0; if (apdg == 22 or apdg ==11 or apdg ==13) { TLorentzVector g1(gen->px(),gen->py(),gen->pz(),gen->energy()); vector< pair<float,float> > inIsoFx ; //isoFx, dR, pT for ( unsigned int j=0;j < packed_handle->size() ;++j) { if (i==j) continue; const auto gen2 = & (*packed_handle)[j]; if ( gen2->pt() ==0 ) continue; if (gen2->pz() > 10e8 ) continue; // inf TLorentzVector g2(gen2->px(),gen2->py(),gen2->pz(),gen2->energy()); if (g2.DeltaR(g1) <0.4){ iso += g2.Pt(); // isoFx containes the epsilon inIsoFx.push_back( pair<float,float>(g2.DeltaR(g1) ,g2.Pt() ) ); } } if (apdg==22){ // ONLY for photon Frixione isolation sort(inIsoFx.begin(), inIsoFx.end() ); // sort in DR, first entry float sumEtFx=0; for( const auto & p : inIsoFx ) { const float& pt= p.second ; const float& delta = p.first; sumEtFx += pt / gen->pt(); // relative iso if (delta == 0 ) continue; // guard float isoCandidate = sumEtFx * TMath::Power( (1. - TMath::Cos(0.4) ) / (1. - TMath::Cos(delta ) ), 2) ;// n=2 if (isoFx < isoCandidate) isoFx = isoCandidate; } } } genIso -> push_back(iso); genIsoFrixione -> push_back(isoFx); // computed dressed objects // if (apdg == 11 or apdg == 13) { // only for final state muons and electrons TLorentzVector dressedLepton(gen->px(),gen->py(),gen->pz(),gen->energy()); TLorentzVector lepton(dressedLepton); //original lepton for dR for ( unsigned int j=0;j < packed_handle->size() ;++j) { const auto gen2 = & (*packed_handle)[j]; TLorentzVector photon(gen2->px(),gen2->py(),gen2->pz(),gen2->energy()); if (i != j and abs( gen->pdgId() ) ==22 and lepton.DeltaR( photon ) <0.1 ) dressedLepton += photon; } new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( dressedLepton ); pdgId -> push_back( pdg ); flags -> push_back( Dressed ); genIso -> push_back (0.) ; genIsoFrixione -> push_back (0.) ; // --- end of dressing } } } //end packed if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] packed took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();} // LOOP over PRUNED PARTICLES //for (auto & gen : *pruned_handle) for (unsigned int i=0;i<pruned_handle->size() ;++i) { const auto gen = &(*pruned_handle)[i]; if (gen->pt() < 5 ) continue; if (gen->pt() < mMinGenParticlePt ) continue; int pdg = gen->pdgId(); int apdg = abs(pdg); if (gen->status() == 1) continue; //packed unsigned flag = ComputeFlags(*gen); if ( apdg == 15 or // tau (15) (apdg >= 23 and apdg <26 ) or // Z(23) W(24) H(25) apdg == 37 or // chHiggs: H+(37) apdg <= 6 or // quarks up (2) down (1) charm (4) strange (3) top (6) bottom (5) apdg == 21 or // gluons (21) apdg > 1000000 // susy neutrinos,neutralinos, charginos ... lightest neutralinos (1000022) or ( apdg == 11 and ( flag & HardProcessBeforeFSR) ) or ( apdg == 11 and ( flag & HardProcess) ) or ( apdg == 13 and ( flag & HardProcessBeforeFSR) ) or ( apdg == 13 and ( flag & HardProcess) ) ) { new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(gen->px(), gen->py(), gen->pz(), gen->energy()); pdgId -> push_back( pdg ); flags -> push_back( flag ); genIso -> push_back (0.) ; genIsoFrixione -> push_back (0.) ; } } if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] pruned took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();} // GEN JETS for (const auto & j : *jet_handle) { if (j.pt() < 20 ) continue; if (j.pt() < mMinGenJetPt ) continue; // --- FILL new ( (*jetP4)[jetP4->GetEntriesFast()]) TLorentzVector(j.px(), j.py(), j.pz(), j.energy()); } if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] jets took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset();} return 0; }
bool PECLeptonReader::ProcessEvent() { // Clear vectors with leptons from the previous event leptons.clear(); looseLeptons.clear(); // Read and process electrons in the current event inputDataPlugin->ReadEventFromTree(electronTreeName); for (pec::Electron const &l: bfElectrons) { TLorentzVector p4; p4.SetPtEtaPhiM(l.Pt(), l.Eta(), l.Phi(), 0.511e-3); // Selection to define a loose electron double const absEtaSC = std::abs(l.EtaSC()); if (p4.Pt() < 20. or absEtaSC > 2.5 or not l.BooleanID(0) /* "veto" cut-based ID */) //^ The cut-based ID already includes selection on isolation continue; Lepton lepton(Lepton::Flavour::Electron, p4); lepton.SetRelIso(l.RelIso()); lepton.SetCharge(l.Charge()); lepton.SetUserFloat("etaSC", l.EtaSC()); looseLeptons.push_back(lepton); // Further selection for a tight electron if (not l.BooleanID(3) /* "tight" cut-based ID */ or (absEtaSC > 1.4442 and absEtaSC < 1.5660) /* EB-EE gap */ or not l.TestBit(0) /* loose selection on impact parameters */) continue; leptons.push_back(lepton); } // Read and process muons in the current event inputDataPlugin->ReadEventFromTree(muonTreeName); for (pec::Muon const &l: bfMuons) { TLorentzVector p4; p4.SetPtEtaPhiM(l.Pt(), l.Eta(), l.Phi(), 0.105); // Selection to define a loose muon if (p4.Pt() < 10. or fabs(p4.Eta()) > 2.4 or l.RelIso() > 0.25 or not l.TestBit(0) /* "loose" ID */) continue; Lepton lepton(Lepton::Flavour::Muon, p4); lepton.SetRelIso(l.RelIso()); lepton.SetCharge(l.Charge()); looseLeptons.push_back(lepton); // Further selection for a tight muon if (l.RelIso() > 0.15 or not l.TestBit(2) /* "tight" ID */) continue; leptons.push_back(lepton); } // Make sure both collections are ordered in transverse momentum std::sort(leptons.rbegin(), leptons.rend()); std::sort(looseLeptons.rbegin(), looseLeptons.rend()); // Since this reader does not have access to the input file, it does not know when there are //no more events in the dataset and thus always returns true return true; }