ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFCandidates.cc
Revision: 1.14.2.2
Committed: Fri Jun 14 19:34:40 2013 UTC (11 years, 10 months ago) by paus
Content type: text/plain
Branch: Mit_025c_branch
CVS Tags: Mit_025c_branch2
Changes since 1.14.2.1: +46 -55 lines
Log Message:
PrepareForBackportVersion3.

File Contents

# User Rev Content
1 paus 1.14.2.2 // $Id: FillerPFCandidates.cc,v 1.14.2.1 2013/05/31 22:58:45 pharris 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 paus 1.14.2.2 BaseFiller (cfg,name,active),
24     edmName_ (Conf().getUntrackedParameter<string>("edmName","particleFlow")),
25     mitName_ (Conf().getUntrackedParameter<string>("mitName",Names::gkPFCandidatesBrn)),
26     trackerTrackMapNames_ (Conf().exists("trackerTrackMapNames") ?
27     Conf().getUntrackedParameter<vector<string> >("trackerTrackMapNames") :
28     vector<string>()),
29     gsfTrackMapName_ (Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
30     muonMapName_ (Conf().getUntrackedParameter<string>("muonMapName","")),
31     barrelSuperClusterMapName_ (Conf().getUntrackedParameter<string>("barrelSuperClusterMapName","")),
32     endcapSuperClusterMapName_ (Conf().getUntrackedParameter<string>("endcapSuperClusterMapName","")),
33     pfElectronSuperClusterMapName_(Conf().getUntrackedParameter<string>("pfElectronSuperClusterMapName","")),
34     conversionMapName_ (Conf().getUntrackedParameter<string>("conversionMapName","")),
35     pfCandMapName_ (Conf().getUntrackedParameter<string>("pfCandMapName","")),
36     allowMissingTrackRef_ (Conf().getUntrackedParameter<bool>("allowMissingTrackRef",false)),
37     gsfTrackMap_ (0),
38     muonMap_ (0),
39     barrelSuperClusterMap_ (0),
40     endcapSuperClusterMap_ (0),
41     pfElectronSuperClusterMap_ (0),
42     conversionMap_ (0),
43     pfCandMap_ (new mithep::PFCandidateMap),
44     pfCands_ (new mithep::PFCandidateArr(16))
45 bendavid 1.1 {
46     // Constructor.
47     }
48    
49     //--------------------------------------------------------------------------------------------------
50 loizides 1.2 FillerPFCandidates::~FillerPFCandidates()
51     {
52     // Destructor.
53    
54 bendavid 1.1 delete pfCands_;
55     delete pfCandMap_;
56     }
57    
58     //--------------------------------------------------------------------------------------------------
59 bendavid 1.5 void FillerPFCandidates::BookDataBlock(TreeWriter &tws)
60 loizides 1.2 {
61     // Add particle-flow candidate branch to tree and get pointers to maps.
62    
63     tws.AddBranch(mitName_,&pfCands_);
64     OS()->add<mithep::PFCandidateArr>(pfCands_,mitName_);
65    
66 bendavid 1.13 // if (!trackerTrackMapName_.empty()) {
67     // trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
68     // if (trackerTrackMap_)
69     // AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
70     // }
71    
72     for (std::vector<std::string>::const_iterator bmapName = trackerTrackMapNames_.begin();
73     bmapName!=trackerTrackMapNames_.end(); ++bmapName) {
74     if (!bmapName->empty()) {
75     const TrackMap *map = OS()->get<TrackMap>(*bmapName);
76     if (map) {
77     trackerTrackMaps_.push_back(map);
78     AddBranchDep(mitName_,map->GetBrName());
79     }
80     }
81 loizides 1.2 }
82 bendavid 1.13
83 loizides 1.2 if (!gsfTrackMapName_.empty()) {
84     gsfTrackMap_ = OS()->get<TrackMap>(gsfTrackMapName_);
85     if (gsfTrackMap_)
86     AddBranchDep(mitName_,gsfTrackMap_->GetBrName());
87     }
88     if (!muonMapName_.empty()) {
89     muonMap_ = OS()->get<MuonMap>(muonMapName_);
90     if (muonMap_)
91     AddBranchDep(mitName_,muonMap_->GetBrName());
92     }
93 paus 1.14.2.2 if (!barrelSuperClusterMapName_.empty()) {
94     barrelSuperClusterMap_ = OS()->get<SuperClusterMap>(barrelSuperClusterMapName_);
95     if (barrelSuperClusterMap_)
96     AddBranchDep(mitName_,barrelSuperClusterMap_->GetBrName());
97     }
98     if (!endcapSuperClusterMapName_.empty()) {
99     endcapSuperClusterMap_ = OS()->get<SuperClusterMap>(endcapSuperClusterMapName_);
100     if (endcapSuperClusterMap_)
101     AddBranchDep(mitName_,endcapSuperClusterMap_->GetBrName());
102     }
103     if (!pfElectronSuperClusterMapName_.empty()) {
104     pfElectronSuperClusterMap_ = OS()->get<SuperClusterMap>(pfElectronSuperClusterMapName_);
105     if (pfElectronSuperClusterMap_)
106     AddBranchDep(mitName_,pfElectronSuperClusterMap_->GetBrName());
107     }
108 loizides 1.2 if (!conversionMapName_.empty()) {
109     conversionMap_ = OS()->get<ConversionMap>(conversionMapName_);
110     if (conversionMap_)
111     AddBranchDep(mitName_,conversionMap_->GetBrName());
112     }
113     if (!pfCandMapName_.empty()) {
114     pfCandMap_->SetBrName(mitName_);
115     OS()->add<PFCandidateMap>(pfCandMap_,pfCandMapName_);
116     }
117 bendavid 1.1 }
118    
119     //--------------------------------------------------------------------------------------------------
120     void FillerPFCandidates::FillDataBlock(const edm::Event &event,
121 loizides 1.2 const edm::EventSetup &setup)
122 bendavid 1.1 {
123     // Fill muon information.
124    
125     pfCands_->Delete();
126     pfCandMap_->Reset();
127    
128     Handle<reco::PFCandidateCollection> hPfCandProduct;
129     GetProduct(edmName_, hPfCandProduct, event);
130     const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
131    
132 loizides 1.2 for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
133     iP != inPfCands.end(); ++iP) {
134 bendavid 1.1 mithep::PFCandidate *outPfCand = pfCands_->Allocate();
135     new (outPfCand) mithep::PFCandidate(iP->px(),iP->py(),iP->pz(),iP->energy());
136    
137 loizides 1.2 // fill variables
138 bendavid 1.1 outPfCand->SetCharge(iP->charge());
139     outPfCand->SetEECal(iP->ecalEnergy());
140     outPfCand->SetEHCal(iP->hcalEnergy());
141     outPfCand->SetEECalRaw(iP->rawEcalEnergy());
142     outPfCand->SetEHCalRaw(iP->rawHcalEnergy());
143     outPfCand->SetEPS1(iP->pS1Energy());
144     outPfCand->SetEPS2(iP->pS2Energy());
145     outPfCand->SetPError(iP->deltaP());
146     outPfCand->SetMvaEPi(iP->mva_e_pi());
147     outPfCand->SetMvaEMu(iP->mva_e_mu());
148     outPfCand->SetMvaPiMu(iP->mva_pi_mu());
149     outPfCand->SetMvaGamma(iP->mva_nothing_gamma());
150     outPfCand->SetMvaNeutralH(iP->mva_nothing_nh());
151     outPfCand->SetMvaGammaNeutralH(iP->mva_gamma_nh());
152     outPfCand->SetEtaECal(iP->positionAtECALEntrance().eta());
153 bendavid 1.10 outPfCand->SetPhiECal(iP->positionAtECALEntrance().phi());
154 bendavid 1.1
155 loizides 1.2 // fill source vertex
156 bendavid 1.1 outPfCand->SetVertex(iP->vertex().x(),iP->vertex().y(),iP->vertex().z());
157    
158 loizides 1.2 // fill pf type enum
159 bendavid 1.1 if (iP->particleId()==reco::PFCandidate::X)
160     outPfCand->SetPFType(mithep::PFCandidate::eX);
161     else if (iP->particleId()==reco::PFCandidate::h)
162     outPfCand->SetPFType(mithep::PFCandidate::eHadron);
163     else if (iP->particleId()==reco::PFCandidate::e)
164     outPfCand->SetPFType(mithep::PFCandidate::eElectron);
165     else if (iP->particleId()==reco::PFCandidate::mu)
166     outPfCand->SetPFType(mithep::PFCandidate::eMuon);
167     else if (iP->particleId()==reco::PFCandidate::gamma)
168     outPfCand->SetPFType(mithep::PFCandidate::eGamma);
169     else if (iP->particleId()==reco::PFCandidate::h0)
170     outPfCand->SetPFType(mithep::PFCandidate::eNeutralHadron);
171     else if (iP->particleId()==reco::PFCandidate::h_HF)
172     outPfCand->SetPFType(mithep::PFCandidate::eHadronHF);
173     else if (iP->particleId()==reco::PFCandidate::egamma_HF)
174     outPfCand->SetPFType(mithep::PFCandidate::eEGammaHF);
175    
176 loizides 1.2 // fill pf flags bitmask
177     outPfCand->SetFlag(mithep::PFCandidate::eNormal,
178     iP->flag(reco::PFCandidate::NORMAL));
179     outPfCand->SetFlag(mithep::PFCandidate::eEMPhiSModules,
180     iP->flag(reco::PFCandidate::E_PHI_SMODULES));
181     outPfCand->SetFlag(mithep::PFCandidate::eEMEta0,
182     iP->flag(reco::PFCandidate::E_ETA_0));
183     outPfCand->SetFlag(mithep::PFCandidate::eEMEtaModules,
184     iP->flag(reco::PFCandidate::E_ETA_MODULES));
185     outPfCand->SetFlag(mithep::PFCandidate::eEMBarrelEndcap,
186     iP->flag(reco::PFCandidate::E_BARREL_ENDCAP));
187     outPfCand->SetFlag(mithep::PFCandidate::eEMPreshowerEdge,
188     iP->flag(reco::PFCandidate::E_PRESHOWER_EDGE));
189     outPfCand->SetFlag(mithep::PFCandidate::eEMPreshower,
190     iP->flag(reco::PFCandidate::E_PRESHOWER));
191     outPfCand->SetFlag(mithep::PFCandidate::eEMEndCapEdge,
192     iP->flag(reco::PFCandidate::E_ENDCAP_EDGE));
193     outPfCand->SetFlag(mithep::PFCandidate::eHEta0,
194     iP->flag(reco::PFCandidate::H_ETA_0));
195     outPfCand->SetFlag(mithep::PFCandidate::eHBarrelEndcap,
196     iP->flag(reco::PFCandidate::H_BARREL_ENDCAP));
197     outPfCand->SetFlag(mithep::PFCandidate::eHEndcapVFCal,
198     iP->flag(reco::PFCandidate::H_ENDCAP_VFCAL));
199     outPfCand->SetFlag(mithep::PFCandidate::eHVFCalEdge,
200     iP->flag(reco::PFCandidate::H_VFCAL_EDGE));
201 bendavid 1.9 outPfCand->SetFlag(mithep::PFCandidate::eToDispVtx,
202     iP->flag(reco::PFCandidate::T_TO_DISP));
203     outPfCand->SetFlag(mithep::PFCandidate::eFromDispVtx,
204     iP->flag(reco::PFCandidate::T_FROM_DISP));
205 loizides 1.2 outPfCand->SetFlag(mithep::PFCandidate::eFromV0,
206     iP->flag(reco::PFCandidate::T_FROM_V0));
207     outPfCand->SetFlag(mithep::PFCandidate::eFromGammaConv,
208     iP->flag(reco::PFCandidate::T_FROM_GAMMACONV));
209     outPfCand->SetFlag(mithep::PFCandidate::eToConversion,
210     iP->flag(reco::PFCandidate::GAMMA_TO_GAMMACONV));
211 bendavid 1.1
212 bendavid 1.13 //printf("pf type = %i\n",iP->particleId());
213    
214 loizides 1.2 // fill references to other branches
215 bendavid 1.13 if (iP->trackRef().isNonnull()) {
216     //printf("track: process = %i, product = %i, algo = %i, highPurity = %i\n",iP->trackRef().id().processIndex(),iP->trackRef().id().productIndex(),iP->trackRef()->algo(),iP->trackRef()->quality(reco::TrackBase::highPurity));
217     const mithep::Track *thetrack = getMitTrack(refToPtr(iP->trackRef()),allowMissingTrackRef_);
218     outPfCand->SetTrackerTrk(thetrack);
219 bendavid 1.12 }
220 bendavid 1.1 if (gsfTrackMap_ && iP->gsfTrackRef().isNonnull())
221     outPfCand->SetGsfTrk(gsfTrackMap_->GetMit(refToPtr(iP->gsfTrackRef())));
222     if (muonMap_ && iP->muonRef().isNonnull())
223     outPfCand->SetMuon(muonMap_->GetMit(refToPtr(iP->muonRef())));
224 paus 1.14.2.2 if (barrelSuperClusterMap_ && endcapSuperClusterMap_ && pfElectronSuperClusterMap_ && iP->superClusterRef().isNonnull()) {
225     if (barrelSuperClusterMap_->HasMit(iP->superClusterRef()))
226     outPfCand->SetSCluster(barrelSuperClusterMap_->GetMit(iP->superClusterRef()));
227     else if (endcapSuperClusterMap_->HasMit(iP->superClusterRef()))
228     outPfCand->SetSCluster(endcapSuperClusterMap_->GetMit(iP->superClusterRef()));
229     else if ( pfElectronSuperClusterMap_->HasMit(iP->superClusterRef()))
230     outPfCand->SetSCluster(pfElectronSuperClusterMap_->GetMit(iP->superClusterRef()));
231     }
232 bendavid 1.1 if (conversionMap_ && iP->conversionRef().isNonnull())
233     outPfCand->SetConversion(conversionMap_->GetMit(iP->conversionRef()));
234    
235 loizides 1.2 // add to exported pf candidate map
236 bendavid 1.1 reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
237     pfCandMap_->Add(thePtr, outPfCand);
238    
239     }
240     pfCands_->Trim();
241     }
242    
243     //--------------------------------------------------------------------------------------------------
244     void FillerPFCandidates::ResolveLinks(const edm::Event &event,
245 loizides 1.2 const edm::EventSetup &setup)
246 bendavid 1.1 {
247 loizides 1.2 // Resolve and fill mother-daughter links.
248 bendavid 1.1
249     Handle<reco::PFCandidateCollection> hPfCandProduct;
250     GetProduct(edmName_, hPfCandProduct, event);
251     const reco::PFCandidateCollection &inPfCands = *(hPfCandProduct.product());
252    
253 loizides 1.2 // loop through pf candidates and resolve mother-daughter links
254     for (reco::PFCandidateCollection::const_iterator iP = inPfCands.begin();
255     iP != inPfCands.end(); ++iP) {
256    
257 bendavid 1.1 reco::PFCandidatePtr thePtr(hPfCandProduct, iP - inPfCands.begin());
258     mithep::PFCandidate *outPfCand = pfCandMap_->GetMit(thePtr);
259    
260 loizides 1.2 // fill mother-daughter links
261 bendavid 1.13 // const reco::CandidatePtr motherCandPtr = iP->sourceCandidatePtr(0);
262     // const reco::PFCandidatePtr motherPtr(motherCandPtr);
263     // if (motherCandPtr.isNonnull()) {
264     // mithep::PFCandidate *mother = pfCandMap_->GetMit(motherPtr);
265     // outPfCand->SetMother(mother);
266     // mother->AddDaughter(outPfCand);
267     // }
268     }
269     }
270    
271     //--------------------------------------------------------------------------------------------------
272     const mithep::Track *FillerPFCandidates::getMitTrack(mitedm::TrackPtr ptr, bool allowmissing) const
273     {
274     // Return our particle referenced by the edm pointer.
275    
276     mithep::Track *mitPart = 0;
277     for (std::vector<const mithep::TrackMap*>::const_iterator bmap = trackerTrackMaps_.begin();
278     bmap!=trackerTrackMaps_.end(); ++bmap) {
279     const mithep::TrackMap *theMap = *bmap;
280     if (theMap->HasMit(ptr)) {
281     mitPart = theMap->GetMit(ptr);
282     return mitPart;
283 bendavid 1.12 }
284 bendavid 1.1 }
285 bendavid 1.13
286     if (!mitPart && !allowmissing)
287     throw edm::Exception(edm::errors::Configuration, "FillerPFCandidates::FillDataBlock()\n")
288     << "Error! MITHEP Object "
289     << "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
290    
291     return mitPart;
292 pharris 1.14.2.1 }