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.23 by eusai, Fri Apr 5 13:23:16 2013 UTC vs.
Revision 1.29 by rkogler, Wed Jun 19 22:05:46 2013 UTC

# Line 18 | Line 18
18   //
19  
20   #include "UHHAnalysis/NtupleWriter/interface/NtupleWriter.h"
21 + #include "UHHAnalysis/NtupleWriter/interface/JetProps.h"
22   #include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputer.h"
23   #include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputerWrapper.h"
24   #include "RecoBTau/JetTagComputer/interface/JetTagComputer.h"
25   #include "RecoBTau/JetTagComputer/interface/JetTagComputerRecord.h"
26   #include "RecoBTag/SecondaryVertex/interface/CombinedSVComputer.h"
27 + #include "DataFormats/TrackReco/interface/Track.h"
28  
29   //
30   // constants, enums and typedefs
# Line 53 | Line 55 | NtupleWriter::NtupleWriter(const edm::Pa
55    doMuons = iConfig.getParameter<bool>("doMuons");
56    doTaus = iConfig.getParameter<bool>("doTaus");
57    doJets = iConfig.getParameter<bool>("doJets");
58 <  doJECUncertainty = iConfig.getParameter<bool>("doJECUncertainty");
58 >  doGenJets = iConfig.getParameter<bool>("doGenJets");
59    doGenTopJets = iConfig.getParameter<bool>("doGenTopJets");  
60    doPhotons = iConfig.getParameter<bool>("doPhotons");
61    doMET = iConfig.getParameter<bool>("doMET");
# Line 62 | Line 64 | NtupleWriter::NtupleWriter(const edm::Pa
64    doLumiInfo = iConfig.getParameter<bool>("doLumiInfo");
65    doPV = iConfig.getParameter<bool>("doPV");
66    doTopJets = iConfig.getParameter<bool>("doTopJets");
67 +  doTopJetsConstituents = iConfig.getParameter<bool>("doTopJetsConstituents");
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  
75    tr->Branch("run",&run);
# Line 112 | Line 117 | NtupleWriter::NtupleWriter(const edm::Pa
117        tr->Branch( jet_sources[j].c_str(), "std::vector<Jet>", &jets[j]);
118      }
119    }
120 +  if(doGenJets){
121 +    genjet_sources = iConfig.getParameter<std::vector<std::string> >("genjet_sources");
122 +    genjet_ptmin = iConfig.getParameter<double> ("genjet_ptmin");
123 +    genjet_etamax = iConfig.getParameter<double> ("genjet_etamax");
124 +    for(size_t j=0; j< genjet_sources.size(); ++j){  
125 +      tr->Branch( genjet_sources[j].c_str(), "std::vector<Particle>", &genjets[j]);
126 +    }
127 +  }
128    if(doTopJets){
129      topjet_sources = iConfig.getParameter<std::vector<std::string> >("topjet_sources");
130      topjet_ptmin = iConfig.getParameter<double> ("topjet_ptmin");
# Line 120 | Line 133 | NtupleWriter::NtupleWriter(const edm::Pa
133        tr->Branch( topjet_sources[j].c_str(), "std::vector<TopJet>", &topjets[j]);
134      }
135    }
136 +  if(doTopJetsConstituents){
137 +    topjet_constituents_sources = iConfig.getParameter<std::vector<std::string> >("topjet_constituents_sources");
138 +    tr->Branch( "PFParticles", "std::vector<PFParticle>", &pfparticles);
139 +  }
140    if(doGenTopJets){
141      gentopjet_sources = iConfig.getParameter<std::vector<std::string> >("gentopjet_sources");
142      gentopjet_ptmin = iConfig.getParameter<double> ("gentopjet_ptmin");
143      gentopjet_etamax = iConfig.getParameter<double> ("gentopjet_etamax");
144      for(size_t j=0; j< gentopjet_sources.size(); ++j){  
145 <      tr->Branch( gentopjet_sources[j].c_str(), "std::vector<TopJet>", &gentopjets[j]);
145 >      tr->Branch( gentopjet_sources[j].c_str(), "std::vector<GenTopJet>", &gentopjets[j]);
146      }
147    }
148    if(doPhotons){
# Line 159 | 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 302 | Line 322 | NtupleWriter::analyze(const edm::Event&
322       for(reco::GenParticleCollection::const_iterator iter = genPartColl->begin(); iter != genPartColl->end(); ++ iter){
323         index++;
324        
325 <       //write out only top quarks and status 3 particles (works fine only for MadGraph)
326 <       if(abs(iter->pdgId())==6 || iter->status()==3 || doAllGenParticles){
325 >       //write out only top quarks,final state leptons and status 3 particles (works fine only for MadGraph)
326 >       bool islepton = iter->status()==1 && abs(iter->pdgId())>=11 && abs(iter->pdgId())<=16 ;
327 >       if(abs(iter->pdgId())==6 || iter->status()==3 || islepton ||  doAllGenParticles){
328           GenParticle genp;
329           genp.set_charge(iter->charge());
330           genp.set_pt(iter->p4().pt());
# Line 333 | Line 354 | NtupleWriter::analyze(const edm::Event&
354       }
355     }
356  
357 +   // ------------- full PF collection -------------  
358 +
359 +
360     // ------------- electrons -------------  
361     if(doElectrons){
362  
# Line 397 | 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 492 | 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 518 | Line 558 | NtupleWriter::analyze(const edm::Event&
558           tau.set_phi( pat_tau.phi());
559           tau.set_energy( pat_tau.energy());
560           tau.set_decayModeFinding ( pat_tau.tauID("decayModeFinding")>0.5);
561 <         tau.set_byVLooseCombinedIsolationDeltaBetaCorr  ( pat_tau.tauID("byVLooseCombinedIsolationDeltaBetaCorr")>0.5);
561 >         //tau.set_byVLooseCombinedIsolationDeltaBetaCorr  ( pat_tau.tauID("byVLooseCombinedIsolationDeltaBetaCorr")>0.5);
562           tau.set_byLooseCombinedIsolationDeltaBetaCorr ( pat_tau.tauID("byLooseCombinedIsolationDeltaBetaCorr")>0.5);
563           tau.set_byMediumCombinedIsolationDeltaBetaCorr ( pat_tau.tauID("byMediumCombinedIsolationDeltaBetaCorr")>0.5);
564           tau.set_byTightCombinedIsolationDeltaBetaCorr ( pat_tau.tauID("byTightCombinedIsolationDeltaBetaCorr")>0.5);
565 <         tau.set_againstElectronLoose  ( pat_tau.tauID("againstElectronLoose")>0.5);
566 <         tau.set_againstElectronMedium ( pat_tau.tauID("againstElectronMedium")>0.5);
567 <         tau.set_againstElectronTight ( pat_tau.tauID("againstElectronTight")>0.5);
568 <         tau.set_againstElectronMVA  ( pat_tau.tauID("againstElectronMVA")>0.5);
569 <         tau.set_againstMuonLoose ( pat_tau.tauID("againstMuonLoose")>0.5);
570 <         tau.set_againstMuonMedium ( pat_tau.tauID("againstMuonMedium")>0.5);
571 <         tau.set_againstMuonTight ( pat_tau.tauID("againstMuonTight")>0.5);
565 >         tau.set_byLooseIsolationMVA( pat_tau.tauID("byLooseIsolationMVA")>0.5);
566 >         tau.set_byMediumIsolationMVA( pat_tau.tauID("byMediumIsolationMVA")>0.5);
567 >         tau.set_byTightIsolationMVA( pat_tau.tauID("byTightIsolationMVA")>0.5);
568 >         tau.set_byLooseIsolationMVA2( pat_tau.tauID("byLooseIsolationMVA2")>0.5);
569 >         tau.set_byMediumIsolationMVA2( pat_tau.tauID("byMediumIsolationMVA2")>0.5);
570 >         tau.set_byTightIsolationMVA2( pat_tau.tauID("byTightIsolationMVA2")>0.5);
571 >         tau.set_byLooseCombinedIsolationDeltaBetaCorr3Hits(  pat_tau.tauID("byLooseCombinedIsolationDeltaBetaCorr3Hits")>0.5);
572 >         tau.set_byMediumCombinedIsolationDeltaBetaCorr3Hits ( pat_tau.tauID("byMediumCombinedIsolationDeltaBetaCorr3Hits")>0.5);
573 >         tau.set_byTightCombinedIsolationDeltaBetaCorr3Hits ( pat_tau.tauID("byTightCombinedIsolationDeltaBetaCorr3Hits")>0.5);
574 >         tau.set_againstElectronLooseMVA3  ( pat_tau.tauID("againstElectronLooseMVA3")>0.5);
575 >         tau.set_againstElectronMediumMVA3 ( pat_tau.tauID("againstElectronMediumMVA3")>0.5);
576 >         tau.set_againstElectronTightMVA3 ( pat_tau.tauID("againstElectronTightMVA3")>0.5);
577 >         tau.set_againstElectronVTightMVA3 ( pat_tau.tauID("againstElectronVTightMVA3")>0.5);
578 >         tau.set_againstMuonLoose2 ( pat_tau.tauID("againstMuonLoose2")>0.5);
579 >         tau.set_againstMuonMedium2 ( pat_tau.tauID("againstMuonMedium2")>0.5);
580 >         tau.set_againstMuonTight2 ( pat_tau.tauID("againstMuonTight2")>0.5);
581 >         tau.set_byIsolationMVAraw(  pat_tau.tauID("byIsolationMVAraw"));
582 >         tau.set_byIsolationMVA2raw(  pat_tau.tauID("byIsolationMVA2raw"));
583 >         tau.set_decayMode( pat_tau.decayMode() );
584 >         tau.set_byCombinedIsolationDeltaBetaCorrRaw( pat_tau.tauID("byCombinedIsolationDeltaBetaCorrRaw"));
585 >         tau.set_byCombinedIsolationDeltaBetaCorrRaw3Hits( pat_tau.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits"));
586  
587 + //       std::cout << pat_tau.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits") << std::endl;
588 +        
589   //       reco::PFCandidateRef leadPFCand = pat_tau.leadPFCand();
590   //       if(!leadPFCand.isNull()){
591   //         tau.set_leadPFCand_px ( leadPFCand->px());
# Line 542 | 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 +   }
615 +
616 +   //-------------- gen jets -------------
617 +
618 +   if(doGenJets){
619 +     for(size_t j=0; j< genjet_sources.size(); ++j){
620 +      
621 +       genjets[j].clear();
622 +
623 +       edm::Handle< std::vector<reco::GenJet> > genjet_handle;
624 +       iEvent.getByLabel(genjet_sources[j], genjet_handle);
625 +       const std::vector<reco::GenJet>& gen_jets = *(genjet_handle.product());
626 +  
627 +       for (unsigned int i = 0; i < gen_jets.size(); ++i) {
628 +
629 +         const reco::GenJet* gen_jet = &gen_jets[i];
630 +         if(gen_jet->pt() < genjet_ptmin) continue;
631 +         if(fabs(gen_jet->eta()) > genjet_etamax) continue;
632 +
633 +         Particle jet;
634 +         jet.set_charge(gen_jet->charge());
635 +         jet.set_pt(gen_jet->pt());
636 +         jet.set_eta(gen_jet->eta());
637 +         jet.set_phi(gen_jet->phi());
638 +         jet.set_energy(gen_jet->energy());
639 +
640 +         // recalculate the jet charge
641 +         int jet_charge = 0;
642 +         std::vector<const reco::GenParticle * > jetgenps = gen_jet->getGenConstituents();
643 +         for(unsigned int l = 0; l<jetgenps.size(); ++l){
644 +           jet_charge +=  jetgenps[l]->charge();
645 +         }
646 +         jet.set_charge(jet_charge);
647 +
648 +         genjets[j].push_back(jet);
649         }
650       }
651     }
# Line 572 | Line 676 | NtupleWriter::analyze(const edm::Event&
676           jet.set_eta(pat_jet.eta());
677           jet.set_phi(pat_jet.phi());
678           jet.set_energy(pat_jet.energy());
679 +         jet.set_flavor(pat_jet.partonFlavour());
680           jet.set_numberOfDaughters (pat_jet.numberOfDaughters());
681           const reco::TrackRefVector&  jettracks = pat_jet.associatedTracks();
682           jet.set_nTracks ( jettracks.size());
683           jet.set_jetArea(pat_jet.jetArea());
579         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 590 | Line 694 | NtupleWriter::analyze(const edm::Event&
694             jet.set_electronMultiplicity (pat_jet.electronMultiplicity());
695             jet.set_photonMultiplicity (pat_jet.photonMultiplicity());
696           }
697 <         if(doJECUncertainty){
594 <           jecUnc->setJetEta(pat_jet.eta());
595 <           jecUnc->setJetPt(pat_jet.pt());
596 <           jet.set_JEC_uncertainty(jecUnc->getUncertainty(true));
597 <         }
697 >
698           jet.set_JEC_factor_raw(pat_jet.jecFactor("Uncorrected"));
699          
700           jet.set_btag_simpleSecondaryVertexHighEff(pat_jet.bDiscriminator("simpleSecondaryVertexHighEffBJetTags"));
# Line 607 | Line 707 | NtupleWriter::analyze(const edm::Event&
707          
708           const reco::GenJet *genj = pat_jet.genJet();
709           if(genj){
710 <           jet.set_genjet_pt(genj->pt());
711 <           jet.set_genjet_eta(genj->eta());
712 <           jet.set_genjet_phi(genj->phi());
713 <           jet.set_genjet_energy(genj->energy());
614 <           if(doAllGenParticles){
615 <             std::vector<const reco::GenParticle * > jetgenps = genj->getGenConstituents();
616 <             for(unsigned int l = 0; l<jetgenps.size(); ++l){
617 <               for(unsigned int k=0; k< genps.size(); ++k){
618 <                 if(jetgenps[l]->pt() == genps[k].pt() && jetgenps[l]->pdgId() == genps[k].pdgId()){
619 <                   jet.add_genparticles_index(genps[k].index());
620 <                   break;
621 <                 }
622 <               }
710 >
711 >           for(unsigned int k=0; k<genjets->size(); ++k){
712 >             if(genj->pt()==genjets->at(k).pt() && genj->eta()==genjets->at(k).eta()){
713 >               jet.set_genjet_index(k);
714               }
624             if(jet.genparticles_indices().size()!= jetgenps.size())
625               std::cout << "WARNING: Found only " << jet.genparticles_indices().size() << " from " << jetgenps.size() << " gen particles of this jet"<<std::endl;
715             }
716 + //         if( jet.genjet_index()<0){
717 + //           std::cout<< "genjet not found for " << genj->pt() << "  " << genj->eta() << std::endl;
718 + //         }
719            
720           }
721          
# Line 632 | Line 724 | NtupleWriter::analyze(const edm::Event&
724       }
725     }
726  
727 +
728     // ------------- top jets -------------
729     if(doTopJets){
730 +
731       for(size_t j=0; j< topjet_sources.size(); ++j){
732        
733         topjets[j].clear();
# Line 654 | Line 748 | NtupleWriter::analyze(const edm::Event&
748           topjet.set_eta(pat_topjet.eta());
749           topjet.set_phi(pat_topjet.phi());
750           topjet.set_energy(pat_topjet.energy());
751 +         topjet.set_flavor(pat_topjet.partonFlavour());
752           topjet.set_numberOfDaughters(pat_topjet.numberOfDaughters());
753           const reco::TrackRefVector&  topjettracks = pat_topjet.associatedTracks();
754           topjet.set_nTracks( topjettracks.size());
755           topjet.set_jetArea( pat_topjet.jetArea());
756 <         topjet.set_pileup( pat_topjet.pileup());
662 < //       topjet.set_neutralEmEnergyFraction(pat_topjet.neutralEmEnergyFraction());
663 < //       topjet.set_neutralHadronEnergyFraction(pat_topjet.neutralHadronEnergyFraction());
664 < //       topjet.set_chargedEmEnergyFraction(pat_topjet.chargedEmEnergyFraction());
665 < //       topjet.set_chargedHadronEnergyFraction(pat_topjet.chargedHadronEnergyFraction());
666 < //       topjet.set_muonEnergyFraction(pat_topjet.muonEnergyFraction());
667 < //       topjet.set_photonEnergyFraction(pat_topjet.photonEnergyFraction());
668 < //       topjet.set_chargedMultiplicity(pat_topjet.chargedMultiplicity());
669 < //       topjet.set_neutralMultiplicity(pat_topjet.neutralMultiplicity());
670 < //       topjet.set_muonMultiplicity(pat_topjet.muonMultiplicity());
671 < //       topjet.set_electronMultiplicity(pat_topjet.electronMultiplicity());
672 < //       topjet.set_photonMultiplicity(pat_topjet.photonMultiplicity());
673 <         if(doJECUncertainty){
674 <           jecUnc->setJetEta(pat_topjet.eta());
675 <           jecUnc->setJetPt(pat_topjet.pt());
676 <           topjet.set_JEC_uncertainty( jecUnc->getUncertainty(true));
677 <         }
756 >
757           topjet.set_JEC_factor_raw( pat_topjet.jecFactor("Uncorrected"));
758  
759           topjet.set_btag_simpleSecondaryVertexHighEff(pat_topjet.bDiscriminator("simpleSecondaryVertexHighEffBJetTags"));
# Line 707 | Line 786 | NtupleWriter::analyze(const edm::Event&
786           }
787           */
788  
789 +         // add constituents to the jet, if requested
790 +         if (doTopJetsConstituents){
791 +
792 +           if (topjet_constituents_sources.size()>j){ //only add constituents if they are defined
793 +
794 +             edm::Handle<pat::JetCollection> pat_topjets_with_cands;
795 +             iEvent.getByLabel(topjet_constituents_sources[j], pat_topjets_with_cands);
796 +             pat::Jet* pat_topjet_wc = NULL;
797 +
798 +             for (unsigned int it = 0; it < pat_topjets_with_cands->size(); it++) {
799 +               const pat::Jet* cand =  dynamic_cast<pat::Jet const *>(&pat_topjets_with_cands->at(it));
800 +               double dphi = cand->phi() - pat_topjet.phi();
801 +               if (dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
802 +               if (dphi < -TMath::Pi()) dphi += 2*TMath::Pi();        
803 +               if (fabs(dphi)<0.5 && fabs(cand->eta()-pat_topjet.eta())<0.5){ // be generous: filtering, pruning... can change jet axis
804 +                 pat_topjet_wc = const_cast<pat::Jet*>(cand);
805 +                 break;
806 +               }
807 +             }
808 +
809 +             if (pat_topjet_wc){
810 +               StoreJetConstituents(pat_topjet_wc, &topjet);
811 +
812 +               // now run substructure information
813 +               JetProps substructure(&topjet);
814 +               substructure.set_pf_cands(&pfparticles);
815 +               double tau1 = substructure.GetNsubjettiness(1, Njettiness::onepass_kt_axes, 1., 2.0);
816 +               double tau2 = substructure.GetNsubjettiness(2, Njettiness::onepass_kt_axes, 1., 2.0);
817 +               double tau3 = substructure.GetNsubjettiness(3, Njettiness::onepass_kt_axes, 1., 2.0);
818 +               double qjets = substructure.GetQjetVolatility(iEvent.id().event(), 2.0);
819 +               topjet.set_tau1(tau1);
820 +               topjet.set_tau2(tau2);
821 +               topjet.set_tau3(tau3);
822 +               topjet.set_qjets_volatility(qjets);
823 +
824 +             }
825 +           }
826 +         }
827 +
828 +
829 +
830           for (unsigned int k = 0; k < pat_topjet.numberOfDaughters(); k++) {
831             Particle subjet_v4;
832  
# Line 810 | Line 930 | NtupleWriter::analyze(const edm::Event&
930         }
931       }
932     }
933 <  
933 >
934    
935     // ------------- generator top jets -------------
936     if(doGenTopJets){
# Line 819 | Line 939 | NtupleWriter::analyze(const edm::Event&
939         gentopjets[j].clear();
940        
941         edm::Handle<reco::BasicJetCollection> reco_gentopjets;
822       //edm::Handle<std::vector<reco::Jet> > reco_gentopjets;
942         iEvent.getByLabel(gentopjet_sources[j], reco_gentopjets);
943  
944         for (unsigned int i = 0; i < reco_gentopjets->size(); i++) {
# Line 828 | Line 947 | NtupleWriter::analyze(const edm::Event&
947           if(reco_gentopjet.pt() < gentopjet_ptmin) continue;
948           if(fabs(reco_gentopjet.eta()) > gentopjet_etamax) continue;
949  
950 <         TopJet gentopjet;
950 >         GenTopJet gentopjet;
951           gentopjet.set_charge(reco_gentopjet.charge());
952           gentopjet.set_pt(reco_gentopjet.pt());
953           gentopjet.set_eta(reco_gentopjet.eta());
954           gentopjet.set_phi(reco_gentopjet.phi());
955           gentopjet.set_energy(reco_gentopjet.energy());
837         gentopjet.set_numberOfDaughters(reco_gentopjet.numberOfDaughters());
956  
957           for (unsigned int k = 0; k < reco_gentopjet.numberOfDaughters(); k++) {
958             Particle subjet_v4;
# Line 849 | Line 967 | NtupleWriter::analyze(const edm::Event&
967       }
968     }
969  
970 +
971     // ------------- photons -------------
972     if(doPhotons){
973       for(size_t j=0; j< photon_sources.size(); ++j){
# Line 953 | Line 1072 | NtupleWriter::analyze(const edm::Event&
1072     tr->Fill();
1073     if(doLumiInfo)
1074       previouslumiblockwasfilled=true;
1075 +
1076 +   // clean up
1077 +   if(doTopJetsConstituents){
1078 +     pfparticles.clear();
1079 +   }
1080 +  
1081 +   // need to do a check if necessary
1082 +   pfparticles.clear();
1083 +
1084   }
1085  
1086  
# Line 986 | Line 1114 | NtupleWriter::beginRun(edm::Run const& i
1114      newrun=true;
1115    }
1116  
989  if(doJets || doTopJets){
990    if(doJECUncertainty){
991      edm::ESHandle<JetCorrectorParametersCollection> JetCorParColl;
992      iSetup.get<JetCorrectionsRecord>().get("AK5PF",JetCorParColl);
993      JetCorrectorParameters const & JetCorPar = (*JetCorParColl)["Uncertainty"];
994      jecUnc = new JetCorrectionUncertainty(JetCorPar);
995    }
996  }
1117   }
1118  
1119   // ------------ method called when ending the processing of a run  ------------
# Line 1046 | Line 1166 | NtupleWriter::fillDescriptions(edm::Conf
1166    descriptions.addDefault(desc);
1167   }
1168  
1169 + // ------------ method fills constituents of the pat_jet into the Ntuple and stores a reference
1170 + // ------------ to those in the topjet
1171 + // ------------ it is checked if the constituents have been stored already
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 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 +
1187 +    PFParticle part;
1188 +    const reco::PFCandidate* pf = jconstits[i].get();
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<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){    
1203 +      continue;
1204 +    }
1205 +
1206 +
1207 +    part.set_pt(pf->pt());
1208 +    part.set_eta(pf->eta());
1209 +    part.set_phi(pf->phi());
1210 +    part.set_energy(pf->energy());
1211 +    part.set_charge(pf->charge());
1212 +
1213 +    part.set_ecal_en(pf->ecalEnergy());
1214 +    part.set_hcal_en(pf->hcalEnergy());
1215 +    reco::TrackRef trackref = pf->trackRef();
1216 +    if (!trackref.isNull()){
1217 +      part.set_track_mom(trackref->p());
1218 +    }
1219 +
1220 +    PFParticle::EParticleID id = PFParticle::eX;
1221 +    switch ( pf->translatePdgIdToType(pf->pdgId()) ){
1222 +    case reco::PFCandidate::X : id = PFParticle::eX; break;
1223 +    case reco::PFCandidate::h : id = PFParticle::eH; break;
1224 +    case reco::PFCandidate::e : id = PFParticle::eE; break;
1225 +    case reco::PFCandidate::mu : id = PFParticle::eMu; break;
1226 +    case reco::PFCandidate::gamma : id = PFParticle::eGamma; break;
1227 +    case reco::PFCandidate::h0 : id = PFParticle::eH0; break;
1228 +    case reco::PFCandidate::h_HF : id = PFParticle::eH_HF; break;
1229 +    case reco::PFCandidate::egamma_HF : id = PFParticle::eEgamma_HF; break;
1230 +    }
1231 +    part.set_particleID(id);
1232 +
1233 +    pfparticles.push_back(part);
1234 +
1235 +    // add a reference to the particle
1236 +    jet->add_pfconstituents_index(pfparticles.size()-1);
1237 +    
1238 +  }
1239 +  
1240 +  if(pat_jet->isPFJet()){
1241 +    jet->set_charge(pat_jet->charge());
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());
1246 +    jet->set_muonEnergyFraction (pat_jet->muonEnergyFraction());
1247 +    jet->set_photonEnergyFraction (pat_jet->photonEnergyFraction());
1248 +    jet->set_chargedMultiplicity (pat_jet->chargedMultiplicity());
1249 +    jet->set_neutralMultiplicity (pat_jet->neutralMultiplicity());
1250 +    jet->set_muonMultiplicity (pat_jet->muonMultiplicity());
1251 +    jet->set_electronMultiplicity (pat_jet->electronMultiplicity());
1252 +    jet->set_photonMultiplicity (pat_jet->photonMultiplicity());
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 +
1351   //define this as a plug-in
1352   DEFINE_FWK_MODULE(NtupleWriter);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines