int NeroPhotons::analyze(const edm::Event& iEvent,const edm::EventSetup &iSetup){ if ( mOnlyMc ) return 0; // maybe handle should be taken before iEvent.getByToken(token, handle); // ID and ISO iEvent.getByToken(loose_id_token,loose_id); iEvent.getByToken(medium_id_token,medium_id); iEvent.getByToken(tight_id_token,tight_id); iEvent.getByToken(iso_ch_token, iso_ch); iEvent.getByToken(iso_nh_token, iso_nh); iEvent.getByToken(iso_pho_token, iso_pho); if ( not handle.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] handle is not valid"<<endl; if ( not loose_id.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] loose_id is not valid"<<endl; if ( not medium_id.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] medium_id is not valid"<<endl; if ( not tight_id.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] tight_id is not valid"<<endl; if ( not iso_ch.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] iso_ch is not valid"<<endl; if ( not iso_nh.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] iso_nh is not valid"<<endl; if ( not iso_pho.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] iso_pho is not valid"<<endl; int iPho = -1; for (auto &pho : *handle) { ++iPho; #ifdef VERBOSE if (VERBOSE>0) cout<<"[NeroPhotons]::[analyze]::[DEBUG] analyzing photon"<<iPho<<" pt="<<pho.pt() <<" pz"<<pho.pz() <<endl; #endif //if ( not pho.passElectronVeto () ) continue; // r9()>0.8 , chargedHadronIso()<20, chargedHadronIso()<0.3*pt() if (pho.pt() <15 or pho.chargedHadronIso()/pho.pt() > 0.3) continue; // 10 -- 14 GeV photons are saved if chargedHadronIso()<10 if (fabs(pho.eta()) > mMaxEta ) continue; if (pho.pt() < mMinPt) continue; #ifdef VERBOSE if (VERBOSE>1) cout<<"[NeroPhotons]::[analize]::[DEBUG2] photonInfo:" <<endl <<" \t pho.chargedHadronIso()/pho.pt() (0.3) "<<pho.chargedHadronIso()/pho.pt() <<endl <<" \t chargedHadronIso() (20) "<<pho.chargedHadronIso()<<endl <<" \t r9 (0.8) "<<pho.r9()<<endl <<" \t SC is non null? "<< pho.superCluster().isNonnull()<<endl <<endl; #endif edm::RefToBase<pat::Photon> ref ( edm::Ref< pat::PhotonCollection >(handle, iPho) ) ; float _chIso_ = (*iso_ch) [ref]; float _nhIso_ = (*iso_nh) [ref]; float _phIso_ = (*iso_pho)[ref]; float _puIso_ = pho.puChargedHadronIso() ; // the other are eff area corrected, no need for this correction float totIso = _chIso_ + _nhIso_ + _phIso_; bool isPassLoose = (*loose_id)[ref]; bool isPassMedium = (*medium_id)[ref]; bool isPassTight = (*tight_id)[ref]; bool isPassVLoose50 = cutBasedPhotonId( pho, "loose_50ns", false, false); // no pho iso , no sieie bool isPassVLoose25 = cutBasedPhotonId( pho, "loose_25ns", false, false); // no pho iso , no sieie //if (not isPassVLoose) continue; if (mMaxIso >=0 and totIso > mMaxIso) continue; unsigned bits=0; bits |= isPassTight * PhoTight; bits |= isPassMedium * PhoMedium; bits |= isPassLoose * PhoLoose; bits |= isPassVLoose50 * PhoVLoose50; bits |= isPassVLoose25 * PhoVLoose25; if (not bits) continue; // even if there is some misalignment ntuples will not be corrupted bits |= pho.passElectronVeto() * PhoElectronVeto; // RC -- with FPR // float _chIsoRC_ = 0; float _nhIsoRC_ = 0; float _phIsoRC_ = 0; float _puIsoRC_ = 0;// not fill for the moment in the FPR TODO if ( pho.chargedHadronIso()< 20 ) { //<<" \t r9 (0.8) "<<pho.r9()<<endl #ifdef VERBOSE if (VERBOSE >0 ) cout <<"[NeroPhotons]::[analyze]::[DEBUG] FPR START"<<endl; #endif fpr -> Config(iSetup); fpr -> SetHandles( pf -> handle, handle, jets-> handle, leps->mu_handle, leps->el_handle ); PFIsolation_struct FPR_out = fpr -> PFIsolation(pho.superCluster(), edm::Ptr<reco::Vertex>(vtx->handle,vtx->firstGoodVertexIdx) ); _chIsoRC_ = FPR_out.chargediso_primvtx_rcone; _nhIsoRC_ = FPR_out.neutraliso_rcone; _phIsoRC_ = FPR_out.photoniso_rcone; #ifdef VERBOSE if (VERBOSE >0 ) cout <<"[NeroPhotons]::[analyze]::[DEBUG] FPR END"<<endl; #endif } else { _chIsoRC_ = -999.; _nhIsoRC_ = -999.; _phIsoRC_ = -999.; _puIsoRC_ = -999.;// not fill for the moment in the FPR TODO } // RC -- without FPR // allowed dphi // -- float dphis[] = { 0.5 * 3.14159 , -.5 *3.14159, 0.25*3.14150 , -0.25*3.14159, 0.75*3.14159,-0.75*3.14159} ; // -- float DR=0.3; // close obj // -- float DRCone=0.3; // default value for iso https://twiki.cern.ch/twiki/bin/view/CMS/EgammaPFBasedIsolationRun2 // -- float dphi = -100; // -- //select dphi // -- for(unsigned i =0 ;i< sizeof(dphis)/sizeof(float) ;++i) // -- { // -- float dphi_cand = dphis[i]; // -- bool close_obj = false; // -- for(auto &j : *jets->handle) // -- { // -- if (j.pt() <20 or j.eta() >2.5) continue; // it's own set of jets // -- TLorentzVector v1,v2; // -- v1.SetPtEtaPhiM( pho.pt(),pho.eta(),pho.phi() + dphi_cand,0 ) ; // -- v2.SetPtEtaPhiM( j.pt(),j.eta(),j.phi(),j.mass() ); // -- if (v1.DeltaR(v2) <DR ) close_obj = true; // -- } // -- if ( not close_obj ) // -- { // -- dphi = dphi_cand; // -- break; // -- } // -- } // -- if (dphi <-99) // -- { // -- _chIsoRC_ = -1; // -- _nhIsoRC_ = -1; // -- _phIsoRC_ = -1; // -- _puIsoRC_ = -1; // -- } // -- else // -- { // -- for( auto &cand : *pf->handle ) // -- { // -- TLorentzVector v1,v2; // -- v1.SetPtEtaPhiM( pho.pt(),pho.eta(),pho.phi() + dphi,0 ) ; // -- v2.SetPtEtaPhiM( cand.pt(),cand.eta(),cand.phi(),cand.mass() ); // -- if (v1.DeltaR(v2) < DRCone ) // -- { // -- // TO BE CHECKED !!! TODO FIXME // -- if (cand.charge() != 0 and abs(cand.pdgId())>20 and fabs( cand.dz() ) <=0.1 and cand.fromPV()>1 and cand.trackHighPurity() ) _chIsoRC_ += cand.pt(); // -- if (cand.charge() == 0 and cand.pdgId() == 22 ) _phIsoRC_ += cand.pt(); // -- if (cand.charge() == 0 and cand.pdgId() != 22 ) _nhIsoRC_ += cand.pt(); // -- if (cand.charge() != 0 and abs(cand.pdgId() )>20 and ( // -- fabs( cand.dz() ) >0.1 or cand.fromPV()<=1 or not cand.trackHighPurity() // -- ) ) _puIsoRC_ += cand.pt(); // -- } // -- } // -- } //FILL new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(pho.px(),pho.py(),pho.pz(),pho.energy()); iso->push_back(totIso); sieie -> push_back( pho. full5x5_sigmaIetaIeta() ); selBits -> push_back( bits); chIso -> push_back( _chIso_); phoIso -> push_back( _phIso_ ) ; nhIso -> push_back ( _nhIso_ ) ; puIso -> push_back ( _puIso_ ) ; chIsoRC -> push_back( _chIsoRC_); phoIsoRC -> push_back( _phIsoRC_ ) ; nhIsoRC -> push_back ( _nhIsoRC_ ) ; puIsoRC -> push_back ( _puIsoRC_ ) ; } if ( int(selBits -> size()) < mMinNpho ) return 1; return 0; }
int NeroPhotons::analyze(const edm::Event& iEvent,const edm::EventSetup &iSetup){ if ( mOnlyMc ) return 0; // maybe handle should be taken before iEvent.getByToken(token, handle); // ID and ISO iEvent.getByToken(loose_id_token,loose_id); iEvent.getByToken(medium_id_token,medium_id); iEvent.getByToken(tight_id_token,tight_id); iEvent.getByToken(iso_ch_token, iso_ch); iEvent.getByToken(iso_nh_token, iso_nh); iEvent.getByToken(iso_pho_token, iso_pho); int iPho = -1; for (auto &pho : *handle) { ++iPho; if (pho.pt() <15 or pho.chargedHadronIso()/pho.pt() > 0.3) continue; if (fabs(pho.eta()) > mMinEta ) continue; if (pho.pt() < mMinPt) continue; edm::RefToBase<pat::Photon> ref ( edm::Ref< pat::PhotonCollection >(handle, iPho) ) ; float _chIso_ = (*iso_ch) [ref]; float _nhIso_ = (*iso_nh) [ref]; float _phIso_ = (*iso_pho)[ref]; float _puIso_ = pho.puChargedHadronIso() ; // the other are eff area corrected, no need for this correction float totIso = _chIso_ + _nhIso_ + _phIso_; bool isPassLoose = (*loose_id)[ref]; bool isPassMedium = (*medium_id)[ref]; bool isPassTight = (*tight_id)[ref]; bool isPassVLoose = cutBasedPhotonId( pho, "loose_50ns", false, false); // no pho iso , no sieie if (not isPassVLoose) continue; if (mMaxIso >=0 and totIso > mMaxIso) continue; // RC -- with FPR // float _chIsoRC_ = 0; float _nhIsoRC_ = 0; float _phIsoRC_ = 0; float _puIsoRC_ = 0;// not fill for the moment in the FPR TODO fpr -> Config(iSetup); fpr -> SetHandles( pf -> handle, handle, jets-> handle, leps->mu_handle, leps->el_handle ); PFIsolation_struct FPR_out = fpr -> PFIsolation(pho.superCluster(), edm::Ptr<reco::Vertex>(vtx->handle,vtx->firstGoodVertexIdx) ); _chIsoRC_ = FPR_out.chargediso_primvtx_rcone; _nhIsoRC_ = FPR_out.neutraliso_rcone; _phIsoRC_ = FPR_out.photoniso_rcone; // RC -- without FPR // allowed dphi // -- float dphis[] = { 0.5 * 3.14159 , -.5 *3.14159, 0.25*3.14150 , -0.25*3.14159, 0.75*3.14159,-0.75*3.14159} ; // -- float DR=0.3; // close obj // -- float DRCone=0.3; // default value for iso https://twiki.cern.ch/twiki/bin/view/CMS/EgammaPFBasedIsolationRun2 // -- float dphi = -100; // -- //select dphi // -- for(unsigned i =0 ;i< sizeof(dphis)/sizeof(float) ;++i) // -- { // -- float dphi_cand = dphis[i]; // -- bool close_obj = false; // -- for(auto &j : *jets->handle) // -- { // -- if (j.pt() <20 or j.eta() >2.5) continue; // it's own set of jets // -- TLorentzVector v1,v2; // -- v1.SetPtEtaPhiM( pho.pt(),pho.eta(),pho.phi() + dphi_cand,0 ) ; // -- v2.SetPtEtaPhiM( j.pt(),j.eta(),j.phi(),j.mass() ); // -- if (v1.DeltaR(v2) <DR ) close_obj = true; // -- } // -- if ( not close_obj ) // -- { // -- dphi = dphi_cand; // -- break; // -- } // -- } // -- if (dphi <-99) // -- { // -- _chIsoRC_ = -1; // -- _nhIsoRC_ = -1; // -- _phIsoRC_ = -1; // -- _puIsoRC_ = -1; // -- } // -- else // -- { // -- for( auto &cand : *pf->handle ) // -- { // -- TLorentzVector v1,v2; // -- v1.SetPtEtaPhiM( pho.pt(),pho.eta(),pho.phi() + dphi,0 ) ; // -- v2.SetPtEtaPhiM( cand.pt(),cand.eta(),cand.phi(),cand.mass() ); // -- if (v1.DeltaR(v2) < DRCone ) // -- { // -- // TO BE CHECKED !!! TODO FIXME // -- if (cand.charge() != 0 and abs(cand.pdgId())>20 and fabs( cand.dz() ) <=0.1 and cand.fromPV()>1 and cand.trackHighPurity() ) _chIsoRC_ += cand.pt(); // -- if (cand.charge() == 0 and cand.pdgId() == 22 ) _phIsoRC_ += cand.pt(); // -- if (cand.charge() == 0 and cand.pdgId() != 22 ) _nhIsoRC_ += cand.pt(); // -- if (cand.charge() != 0 and abs(cand.pdgId() )>20 and ( // -- fabs( cand.dz() ) >0.1 or cand.fromPV()<=1 or not cand.trackHighPurity() // -- ) ) _puIsoRC_ += cand.pt(); // -- } // -- } // -- } //FILL new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(pho.px(),pho.py(),pho.pz(),pho.energy()); iso->push_back(totIso); sieie -> push_back( pho. full5x5_sigmaIetaIeta() ); tightid->push_back(isPassTight); mediumid->push_back(isPassMedium); looseid->push_back(isPassLoose); chIso -> push_back( _chIso_); phoIso -> push_back( _phIso_ ) ; nhIso -> push_back ( _nhIso_ ) ; puIso -> push_back ( _puIso_ ) ; chIsoRC -> push_back( _chIsoRC_); phoIsoRC -> push_back( _phIsoRC_ ) ; nhIsoRC -> push_back ( _nhIsoRC_ ) ; puIsoRC -> push_back ( _puIsoRC_ ) ; } return 0; }