ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFCandidates.cc
Revision: 1.12
Committed: Wed Sep 14 15:26:53 2011 UTC (13 years, 7 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_024b
Changes since 1.11: +14 -9 lines
Log Message:
add configurable missing reference bypass for tau embedding samples

File Contents

# User Rev Content
1 bendavid 1.12 // $Id: FillerPFCandidates.cc,v 1.11 2011/09/12 15:21:38 bendavid Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillerPFCandidates.h"
4     #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
5     #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
6     #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
7     #include "DataFormats/MuonReco/interface/Muon.h"
8     #include "DataFormats/MuonReco/interface/MuonFwd.h"
9     #include "DataFormats/Common/interface/RefToPtr.h"
10     #include "MitAna/DataTree/interface/Muon.h"
11 loizides 1.3 #include "MitAna/DataTree/interface/Names.h"
12     #include "MitAna/DataTree/interface/PFCandidateCol.h"
13 bendavid 1.1 #include "MitAna/DataTree/interface/Track.h"
14 loizides 1.3 #include "MitProd/ObjectService/interface/ObjectService.h"
15 bendavid 1.1
16     using namespace std;
17     using namespace edm;
18     using namespace mithep;
19    
20     //--------------------------------------------------------------------------------------------------
21 loizides 1.2 FillerPFCandidates::FillerPFCandidates(const edm::ParameterSet &cfg,
22     const char *name, bool active) :
23 bendavid 1.1 BaseFiller(cfg,name,active),
24     edmName_(Conf().getUntrackedParameter<string>("edmName","particleFlow")),
25     mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkPFCandidatesBrn)),
26     trackerTrackMapName_(Conf().getUntrackedParameter<string>("trackerTrackMapName","")),
27     gsfTrackMapName_(Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
28     muonMapName_(Conf().getUntrackedParameter<string>("muonMapName","")),
29     conversionMapName_(Conf().getUntrackedParameter<string>("conversionMapName","")),
30     pfCandMapName_(Conf().getUntrackedParameter<string>("pfCandMapName","")),
31 bendavid 1.12 allowMissingTrackRef_(Conf().getUntrackedParameter<bool>("allowMissingTrackRef",false)),
32 bendavid 1.1 trackerTrackMap_(0),
33     gsfTrackMap_(0),
34     muonMap_(0),
35     conversionMap_(0),
36     pfCandMap_(new mithep::PFCandidateMap),
37     pfCands_(new mithep::PFCandidateArr(16))
38     {
39     // Constructor.
40     }
41    
42     //--------------------------------------------------------------------------------------------------
43 loizides 1.2 FillerPFCandidates::~FillerPFCandidates()
44     {
45     // Destructor.
46    
47 bendavid 1.1 delete pfCands_;
48     delete pfCandMap_;
49     }
50    
51     //--------------------------------------------------------------------------------------------------
52 bendavid 1.5 void FillerPFCandidates::BookDataBlock(TreeWriter &tws)
53 loizides 1.2 {
54     // Add particle-flow candidate branch to tree and get pointers to maps.
55    
56     tws.AddBranch(mitName_,&pfCands_);
57     OS()->add<mithep::PFCandidateArr>(pfCands_,mitName_);
58    
59     if (!trackerTrackMapName_.empty()) {
60     trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
61     if (trackerTrackMap_)
62     AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
63     }
64     if (!gsfTrackMapName_.empty()) {
65     gsfTrackMap_ = OS()->get<TrackMap>(gsfTrackMapName_);
66     if (gsfTrackMap_)
67     AddBranchDep(mitName_,gsfTrackMap_->GetBrName());
68     }
69     if (!muonMapName_.empty()) {
70     muonMap_ = OS()->get<MuonMap>(muonMapName_);
71     if (muonMap_)
72     AddBranchDep(mitName_,muonMap_->GetBrName());
73     }
74     if (!conversionMapName_.empty()) {
75     conversionMap_ = OS()->get<ConversionMap>(conversionMapName_);
76     if (conversionMap_)
77     AddBranchDep(mitName_,conversionMap_->GetBrName());
78     }
79     if (!pfCandMapName_.empty()) {
80     pfCandMap_->SetBrName(mitName_);
81     OS()->add<PFCandidateMap>(pfCandMap_,pfCandMapName_);
82     }
83 bendavid 1.1 }
84    
85     //--------------------------------------------------------------------------------------------------
86     void FillerPFCandidates::FillDataBlock(const edm::Event &event,
87 loizides 1.2 const edm::EventSetup &setup)
88 bendavid 1.1 {
89     // Fill muon information.
90    
91     pfCands_->Delete();
92     pfCandMap_->Reset();
93    
94     Handle<reco::PFCandidateCollection> hPfCandProduct;
95     GetProduct(edmName_, hPfCandProduct, event);
96     const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
97    
98 loizides 1.2 for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
99     iP != inPfCands.end(); ++iP) {
100 bendavid 1.1 mithep::PFCandidate *outPfCand = pfCands_->Allocate();
101     new (outPfCand) mithep::PFCandidate(iP->px(),iP->py(),iP->pz(),iP->energy());
102    
103 loizides 1.2 // fill variables
104 bendavid 1.1 outPfCand->SetCharge(iP->charge());
105     outPfCand->SetEECal(iP->ecalEnergy());
106     outPfCand->SetEHCal(iP->hcalEnergy());
107     outPfCand->SetEECalRaw(iP->rawEcalEnergy());
108     outPfCand->SetEHCalRaw(iP->rawHcalEnergy());
109     outPfCand->SetEPS1(iP->pS1Energy());
110     outPfCand->SetEPS2(iP->pS2Energy());
111     outPfCand->SetPError(iP->deltaP());
112     outPfCand->SetMvaEPi(iP->mva_e_pi());
113     outPfCand->SetMvaEMu(iP->mva_e_mu());
114     outPfCand->SetMvaPiMu(iP->mva_pi_mu());
115     outPfCand->SetMvaGamma(iP->mva_nothing_gamma());
116     outPfCand->SetMvaNeutralH(iP->mva_nothing_nh());
117     outPfCand->SetMvaGammaNeutralH(iP->mva_gamma_nh());
118     outPfCand->SetEtaECal(iP->positionAtECALEntrance().eta());
119 bendavid 1.10 outPfCand->SetPhiECal(iP->positionAtECALEntrance().phi());
120 bendavid 1.1
121 loizides 1.2 // fill source vertex
122 bendavid 1.1 outPfCand->SetVertex(iP->vertex().x(),iP->vertex().y(),iP->vertex().z());
123    
124 loizides 1.2 // fill pf type enum
125 bendavid 1.1 if (iP->particleId()==reco::PFCandidate::X)
126     outPfCand->SetPFType(mithep::PFCandidate::eX);
127     else if (iP->particleId()==reco::PFCandidate::h)
128     outPfCand->SetPFType(mithep::PFCandidate::eHadron);
129     else if (iP->particleId()==reco::PFCandidate::e)
130     outPfCand->SetPFType(mithep::PFCandidate::eElectron);
131     else if (iP->particleId()==reco::PFCandidate::mu)
132     outPfCand->SetPFType(mithep::PFCandidate::eMuon);
133     else if (iP->particleId()==reco::PFCandidate::gamma)
134     outPfCand->SetPFType(mithep::PFCandidate::eGamma);
135     else if (iP->particleId()==reco::PFCandidate::h0)
136     outPfCand->SetPFType(mithep::PFCandidate::eNeutralHadron);
137     else if (iP->particleId()==reco::PFCandidate::h_HF)
138     outPfCand->SetPFType(mithep::PFCandidate::eHadronHF);
139     else if (iP->particleId()==reco::PFCandidate::egamma_HF)
140     outPfCand->SetPFType(mithep::PFCandidate::eEGammaHF);
141    
142 loizides 1.2 // fill pf flags bitmask
143     outPfCand->SetFlag(mithep::PFCandidate::eNormal,
144     iP->flag(reco::PFCandidate::NORMAL));
145     outPfCand->SetFlag(mithep::PFCandidate::eEMPhiSModules,
146     iP->flag(reco::PFCandidate::E_PHI_SMODULES));
147     outPfCand->SetFlag(mithep::PFCandidate::eEMEta0,
148     iP->flag(reco::PFCandidate::E_ETA_0));
149     outPfCand->SetFlag(mithep::PFCandidate::eEMEtaModules,
150     iP->flag(reco::PFCandidate::E_ETA_MODULES));
151     outPfCand->SetFlag(mithep::PFCandidate::eEMBarrelEndcap,
152     iP->flag(reco::PFCandidate::E_BARREL_ENDCAP));
153     outPfCand->SetFlag(mithep::PFCandidate::eEMPreshowerEdge,
154     iP->flag(reco::PFCandidate::E_PRESHOWER_EDGE));
155     outPfCand->SetFlag(mithep::PFCandidate::eEMPreshower,
156     iP->flag(reco::PFCandidate::E_PRESHOWER));
157     outPfCand->SetFlag(mithep::PFCandidate::eEMEndCapEdge,
158     iP->flag(reco::PFCandidate::E_ENDCAP_EDGE));
159     outPfCand->SetFlag(mithep::PFCandidate::eHEta0,
160     iP->flag(reco::PFCandidate::H_ETA_0));
161     outPfCand->SetFlag(mithep::PFCandidate::eHBarrelEndcap,
162     iP->flag(reco::PFCandidate::H_BARREL_ENDCAP));
163     outPfCand->SetFlag(mithep::PFCandidate::eHEndcapVFCal,
164     iP->flag(reco::PFCandidate::H_ENDCAP_VFCAL));
165     outPfCand->SetFlag(mithep::PFCandidate::eHVFCalEdge,
166     iP->flag(reco::PFCandidate::H_VFCAL_EDGE));
167 bendavid 1.9 outPfCand->SetFlag(mithep::PFCandidate::eToDispVtx,
168     iP->flag(reco::PFCandidate::T_TO_DISP));
169     outPfCand->SetFlag(mithep::PFCandidate::eFromDispVtx,
170     iP->flag(reco::PFCandidate::T_FROM_DISP));
171 loizides 1.2 outPfCand->SetFlag(mithep::PFCandidate::eFromV0,
172     iP->flag(reco::PFCandidate::T_FROM_V0));
173     outPfCand->SetFlag(mithep::PFCandidate::eFromGammaConv,
174     iP->flag(reco::PFCandidate::T_FROM_GAMMACONV));
175     outPfCand->SetFlag(mithep::PFCandidate::eToConversion,
176     iP->flag(reco::PFCandidate::GAMMA_TO_GAMMACONV));
177 bendavid 1.1
178 loizides 1.2 // fill references to other branches
179 bendavid 1.12 if (trackerTrackMap_ && iP->trackRef().isNonnull()) {
180     //printf("process = %i, product = %i\n",iP->trackRef().id().processIndex(),iP->trackRef().id().productIndex());
181     if (!allowMissingTrackRef_ || trackerTrackMap_->HasMit(refToPtr(iP->trackRef()))) {
182     outPfCand->SetTrackerTrk(trackerTrackMap_->GetMit(refToPtr(iP->trackRef())));
183     }
184     }
185 bendavid 1.1 if (gsfTrackMap_ && iP->gsfTrackRef().isNonnull())
186     outPfCand->SetGsfTrk(gsfTrackMap_->GetMit(refToPtr(iP->gsfTrackRef())));
187     if (muonMap_ && iP->muonRef().isNonnull())
188     outPfCand->SetMuon(muonMap_->GetMit(refToPtr(iP->muonRef())));
189     if (conversionMap_ && iP->conversionRef().isNonnull())
190     outPfCand->SetConversion(conversionMap_->GetMit(iP->conversionRef()));
191    
192 loizides 1.2 // add to exported pf candidate map
193 bendavid 1.1 reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
194     pfCandMap_->Add(thePtr, outPfCand);
195    
196     }
197     pfCands_->Trim();
198     }
199    
200     //--------------------------------------------------------------------------------------------------
201     void FillerPFCandidates::ResolveLinks(const edm::Event &event,
202 loizides 1.2 const edm::EventSetup &setup)
203 bendavid 1.1 {
204 loizides 1.2 // Resolve and fill mother-daughter links.
205 bendavid 1.1
206     Handle<reco::PFCandidateCollection> hPfCandProduct;
207     GetProduct(edmName_, hPfCandProduct, event);
208     const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
209    
210 loizides 1.2 // loop through pf candidates and resolve mother-daughter links
211     for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
212     iP != inPfCands.end(); ++iP) {
213    
214 bendavid 1.1 reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
215     mithep::PFCandidate *outPfCand = pfCandMap_->GetMit(thePtr);
216    
217 loizides 1.2 // fill mother-daughter links
218 bendavid 1.1 const reco::CandidatePtr motherCandPtr = iP->sourceCandidatePtr(0);
219 bendavid 1.12 const reco::PFCandidatePtr motherPtr(motherCandPtr);
220     if (motherCandPtr.isNonnull()) {
221     mithep::PFCandidate *mother = pfCandMap_->GetMit(motherPtr);
222     outPfCand->SetMother(mother);
223     mother->AddDaughter(outPfCand);
224     }
225 bendavid 1.1 }
226     }