ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFCandidates.cc
Revision: 1.13
Committed: Wed Sep 28 16:50:07 2011 UTC (13 years, 7 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025pre2
Changes since 1.12: +57 -19 lines
Log Message:
changes for 440 event content

File Contents

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