ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/UHHAnalysis/NtupleWriter/src/NtupleWriter.cc
(Generate patch)

Comparing UserCode/UHHAnalysis/NtupleWriter/src/NtupleWriter.cc (file contents):
Revision 1.28 by peiffer, Wed Jun 19 16:02:37 2013 UTC vs.
Revision 1.29 by rkogler, Wed Jun 19 22:05:46 2013 UTC

# Line 68 | Line 68 | NtupleWriter::NtupleWriter(const edm::Pa
68    doTrigger = iConfig.getParameter<bool>("doTrigger");
69    SVComputer_  = iConfig.getUntrackedParameter<edm::InputTag>("svComputer",edm::InputTag("combinedSecondaryVertex"));
70    doTagInfos = iConfig.getUntrackedParameter<bool>("doTagInfos",false);
71 +  storePFsAroundLeptons = iConfig.getUntrackedParameter<bool>("storePFsAroundLeptons",false);
72  
73    // initialization of tree variables
74  
# Line 175 | Line 176 | NtupleWriter::NtupleWriter(const edm::Pa
176      //tr->Branch("L1_prescale", "std::vector<int>", &L1_prescale);
177      //tr->Branch("HLT_prescale", "std::vector<int>", &HLT_prescale);
178    }
179 +  if (storePFsAroundLeptons){
180 +    pf_around_leptons_source = iConfig.getParameter<std::string>("pf_around_leptons_source");
181 +  }
182    newrun = true;
183   }
184  
# Line 350 | Line 354 | NtupleWriter::analyze(const edm::Event&
354       }
355     }
356  
357 +   // ------------- full PF collection -------------  
358 +
359 +
360     // ------------- electrons -------------  
361     if(doElectrons){
362  
# Line 414 | Line 421 | NtupleWriter::analyze(const edm::Event&
421           ele.set_AEff(AEff03);
422  
423           eles[j].push_back(ele);
424 +        
425 +         if (storePFsAroundLeptons){
426 +           edm::Handle< std::vector<reco::PFCandidate> > pfcand_handle;
427 +           iEvent.getByLabel(pf_around_leptons_source, pfcand_handle);  // default: "pfNoPileUpPFlow"
428 +           const std::vector<reco::PFCandidate>& pf_cands = *(pfcand_handle.product());
429 +           StorePFCandsInCone(&ele, pf_cands, 0.4);
430 +         }
431 +
432         }
433       }
434     }
# Line 509 | Line 524 | NtupleWriter::analyze(const edm::Event&
524           }
525  
526           mus[j].push_back(mu);
527 +
528 +         if (storePFsAroundLeptons){
529 +           edm::Handle< std::vector<reco::PFCandidate> > pfcand_handle;
530 +           iEvent.getByLabel(pf_around_leptons_source, pfcand_handle);  // default: "pfNoPileUpPFlow"
531 +           const std::vector<reco::PFCandidate>& pf_cands = *(pfcand_handle.product());
532 +           StorePFCandsInCone(&mu, pf_cands, 0.4);
533 +         }
534 +        
535         }
536       }
537     }
# Line 575 | Line 598 | NtupleWriter::analyze(const edm::Event&
598   //         tau.set_leadPFCand_pz ( 0);
599   //       }
600           taus[j].push_back(tau);
601 +
602 +         // store isolation info only for identified taus
603 +         if (pat_tau.tauID("decayModeFinding")>0.5){
604 +           bool storepfs = (pat_tau.tauID("byLooseCombinedIsolationDeltaBetaCorr")>0.5) || (pat_tau.tauID("byLooseIsolationMVA")>0.5);    
605 +           if (storePFsAroundLeptons && storepfs){        
606 +             edm::Handle< std::vector<reco::PFCandidate> > pfcand_handle;
607 +             iEvent.getByLabel(pf_around_leptons_source, pfcand_handle);  // default: "pfNoPileUpPFlow"
608 +             const std::vector<reco::PFCandidate>& pf_cands = *(pfcand_handle.product());
609 +             StorePFCandsInCone(&tau, pf_cands, 0.4);
610 +           }
611 +         }
612         }
613       }
614     }
# Line 647 | Line 681 | NtupleWriter::analyze(const edm::Event&
681           const reco::TrackRefVector&  jettracks = pat_jet.associatedTracks();
682           jet.set_nTracks ( jettracks.size());
683           jet.set_jetArea(pat_jet.jetArea());
650         jet.set_pileup(pat_jet.pileup());
684           if(pat_jet.isPFJet()){
685             jet.set_neutralEmEnergyFraction (pat_jet.neutralEmEnergyFraction());
686             jet.set_neutralHadronEnergyFraction (pat_jet.neutralHadronEnergyFraction());
# Line 683 | Line 716 | NtupleWriter::analyze(const edm::Event&
716   //         if( jet.genjet_index()<0){
717   //           std::cout<< "genjet not found for " << genj->pt() << "  " << genj->eta() << std::endl;
718   //         }
686
687           if(doAllGenParticles){
688             std::vector<const reco::GenParticle * > jetgenps = genj->getGenConstituents();
689             for(unsigned int l = 0; l<jetgenps.size(); ++l){
690               for(unsigned int k=0; k< genps.size(); ++k){
691                 if(jetgenps[l]->pt() == genps[k].pt() && jetgenps[l]->pdgId() == genps[k].pdgId()){
692                   jet.add_genparticles_index(genps[k].index());
693                   break;
694                 }
695               }
696             }
697             if(jet.genparticles_indices().size()!= jetgenps.size())
698               std::cout << "WARNING: Found only " << jet.genparticles_indices().size() << " from " << jetgenps.size() << " gen particles of this jet"<<std::endl;
699           }
719            
720           }
721          
# Line 734 | Line 753 | NtupleWriter::analyze(const edm::Event&
753           const reco::TrackRefVector&  topjettracks = pat_topjet.associatedTracks();
754           topjet.set_nTracks( topjettracks.size());
755           topjet.set_jetArea( pat_topjet.jetArea());
737         topjet.set_pileup( pat_topjet.pileup());
756  
757           topjet.set_JEC_factor_raw( pat_topjet.jecFactor("Uncorrected"));
758  
# Line 1056 | Line 1074 | NtupleWriter::analyze(const edm::Event&
1074       previouslumiblockwasfilled=true;
1075  
1076     // clean up
1059   m_stored_pfs.clear();
1077     if(doTopJetsConstituents){
1078       pfparticles.clear();
1079     }
1080 +  
1081 +   // need to do a check if necessary
1082 +   pfparticles.clear();
1083  
1084   }
1085  
# Line 1152 | Line 1172 | NtupleWriter::fillDescriptions(edm::Conf
1172   void
1173   NtupleWriter::StoreJetConstituents(pat::Jet* pat_jet, Jet* jet)
1174   {
1175 <  // checks if the pf cand has already been stored, only stores so far missing
1175 >  // checks if the pf cand has already been stored, only stores so far missing ones
1176    // PF candidates, then stores a reference to the pf candidate in the jet
1177    // also calculates the jet charge and sets it
1178  
1179  
1180    const std::vector<reco::PFCandidatePtr> jconstits = pat_jet->getPFConstituents();
1181  
1182 +  unsigned int NstoredPFs = pfparticles.size();
1183 +
1184    // loop over all jet constituents and store them
1185    for (unsigned int i=0; i<jconstits.size(); ++i){
1186  
# Line 1167 | Line 1189 | NtupleWriter::StoreJetConstituents(pat::
1189  
1190      // check if it has already been stored, omit if true
1191      int is_already_in_list = -1;
1192 <    for (unsigned int j=0; j<m_stored_pfs.size(); ++j){
1193 <      
1194 <      const reco::PFCandidate* spf = m_stored_pfs[j];
1195 <      double r2 = pow(pf->eta()-spf->eta(),2) + pow(pf->phi()-spf->phi(),2);
1174 <      double dpt = fabs( pf->pt() - spf->pt() );
1192 >    for (unsigned int j=0; j<NstoredPFs; ++j){
1193 >      PFParticle spf = pfparticles[j];
1194 >      double r2 = pow(pf->eta()-spf.eta(),2) + pow(pf->phi()-spf.phi(),2);
1195 >      double dpt = fabs( pf->pt() - spf.pt() );
1196        if (r2<1e-10 && dpt<1e-10){
1197          is_already_in_list = j;
1198          break;
1199        }            
1200      }
1201      
1202 <    if (is_already_in_list>-1){
1182 <      jet->add_pfconstituents_index(is_already_in_list);
1202 >    if (is_already_in_list>-1){    
1203        continue;
1204      }
1205  
1206 +
1207      part.set_pt(pf->pt());
1208      part.set_eta(pf->eta());
1209      part.set_phi(pf->phi());
# Line 1210 | Line 1231 | NtupleWriter::StoreJetConstituents(pat::
1231      part.set_particleID(id);
1232  
1233      pfparticles.push_back(part);
1213    m_stored_pfs.push_back(pf);
1234  
1235      // add a reference to the particle
1236      jet->add_pfconstituents_index(pfparticles.size()-1);
# Line 1219 | Line 1239 | NtupleWriter::StoreJetConstituents(pat::
1239    
1240    if(pat_jet->isPFJet()){
1241      jet->set_charge(pat_jet->charge());
1242 <    jet->set_neutralEmEnergyFraction (pat_jet->neutralEmEnergyFraction());
1242 >    jet->set_neutralEmEnergyFraction(pat_jet->neutralEmEnergyFraction());
1243      jet->set_neutralHadronEnergyFraction (pat_jet->neutralHadronEnergyFraction());
1244      jet->set_chargedEmEnergyFraction (pat_jet->chargedEmEnergyFraction());
1245      jet->set_chargedHadronEnergyFraction (pat_jet->chargedHadronEnergyFraction());
# Line 1233 | Line 1253 | NtupleWriter::StoreJetConstituents(pat::
1253    }
1254    
1255    return;
1256 +
1257 + }
1258 +
1259 + // ------------ method fills PF candidates in a cone of radius R around
1260 + // ------------ a given particle (lepton, most likely)
1261 + // ------------ it is checked if the constituents have been stored already
1262 + void
1263 + NtupleWriter::StorePFCandsInCone(Particle* inpart, const std::vector<reco::PFCandidate>& pf_cands, double R0)
1264 + {
1265 +  // checks if the pf cand has already been stored, only stores so far missing ones
1266 +
1267 +  //cout << "\nStorePFCandsInCone: R0 = " << R0 << endl;
1268 +  //cout << "found " << pf_cands.size() << " PF candidates in the event" << endl;
1269 +  //cout << "Input inparticle: pt = " << inpart->pt() << " eta = " << inpart->eta() << " phi = " << inpart->phi() << endl;
1270 +  
1271 +  unsigned int NstoredPFs = pfparticles.size();
1272 +  //cout << "got already " <<  NstoredPFs << " which need to be checked to avoid double counting" << endl;
1273 +
1274 +  // loop over all PF candidates and store the ones in a cone with radius R0
1275 +  for (unsigned int i=0; i<pf_cands.size(); ++i){
1276 +
1277 +    reco::PFCandidate pf = pf_cands[i];
1278 +
1279 +    // calculate distance in eta/phi
1280 +    double dphi = pf.phi() - inpart->phi();
1281 +    if (dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
1282 +    if (dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
1283 +    double dr2 = dphi*dphi + pow(pf.eta() - inpart->eta(),2);
1284 +    
1285 +    // check if PF candidate is in cone around particle
1286 +    if (sqrt(dr2)>R0) continue;
1287 +
1288 +    //cout << "found particle with distance " << dr2 << " at position " << i << endl;
1289 +    //cout << "PF: pt = " << pf.pt() << " eta = " << pf.eta() << " phi = " << pf.phi() << endl;
1290 +
1291 +    // check if it's the same as the input particle
1292 +    double dpt = fabs( inpart->pt() - pf.pt() );
1293 +    if (dr2<1e-10 && dpt<1e-10){
1294 +      //cout << "same particle, don't store" << endl;
1295 +      continue;
1296 +    }
1297 +
1298 +    // check if it has already been stored, omit if true
1299 +    int is_already_in_list = -1;
1300 +    for (unsigned int j=0; j<NstoredPFs; ++j){
1301 +      PFParticle spf = pfparticles[j];
1302 +      double r2 = pow(pf.eta()-spf.eta(),2) + pow(pf.phi()-spf.phi(),2);
1303 +      double dpt = fabs( pf.pt() - spf.pt() );
1304 +      if (r2<1e-10 && dpt<1e-10){
1305 +        is_already_in_list = j;
1306 +        break;
1307 +      }            
1308 +    }
1309 +    
1310 +    if (is_already_in_list>-1){    
1311 +      //cout << "is already in list, continue" << endl;
1312 +      continue;
1313 +    }
1314 +
1315 +
1316 +    PFParticle part;
1317 +    part.set_pt(pf.pt());
1318 +    part.set_eta(pf.eta());
1319 +    part.set_phi(pf.phi());
1320 +    part.set_energy(pf.energy());
1321 +    part.set_charge(pf.charge());
1322 +
1323 +    part.set_ecal_en(pf.ecalEnergy());
1324 +    part.set_hcal_en(pf.hcalEnergy());
1325 +    reco::TrackRef trackref = pf.trackRef();
1326 +    if (!trackref.isNull()){
1327 +      part.set_track_mom(trackref->p());
1328 +    }
1329 +
1330 +    PFParticle::EParticleID id = PFParticle::eX;
1331 +    switch ( pf.translatePdgIdToType(pf.pdgId()) ){
1332 +    case reco::PFCandidate::X : id = PFParticle::eX; break;
1333 +    case reco::PFCandidate::h : id = PFParticle::eH; break;
1334 +    case reco::PFCandidate::e : id = PFParticle::eE; break;
1335 +    case reco::PFCandidate::mu : id = PFParticle::eMu; break;
1336 +    case reco::PFCandidate::gamma : id = PFParticle::eGamma; break;
1337 +    case reco::PFCandidate::h0 : id = PFParticle::eH0; break;
1338 +    case reco::PFCandidate::h_HF : id = PFParticle::eH_HF; break;
1339 +    case reco::PFCandidate::egamma_HF : id = PFParticle::eEgamma_HF; break;
1340 +    }
1341 +    part.set_particleID(id);
1342 +    
1343 +    pfparticles.push_back(part);
1344 +    
1345 +  }
1346 +  
1347 +  return;
1348  
1349   }
1350  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines