CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATGenericParticleProducer.cc
Go to the documentation of this file.
1 //
2 // $Id: PATGenericParticleProducer.cc,v 1.11 2009/10/13 14:23:56 rwolf Exp $
3 //
4 
8 #include <memory>
9 
10 using namespace pat;
11 
13  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false),
14  userDataHelper_ ( iConfig.getParameter<edm::ParameterSet>("userData") )
15 {
16  // initialize the configurables
17  src_ = iConfig.getParameter<edm::InputTag>( "src" );
18 
19  // RECO embedding
20  embedTrack_ = iConfig.getParameter<bool>( "embedTrack" );
21  embedGsfTrack_ = iConfig.getParameter<bool>( "embedGsfTrack" );
22  embedStandalone_ = iConfig.getParameter<bool>( "embedStandAloneMuon" );
23  embedCombined_ = iConfig.getParameter<bool>( "embedCombinedMuon" );
24  embedSuperCluster_ = iConfig.getParameter<bool>( "embedSuperCluster" );
25  embedTracks_ = iConfig.getParameter<bool>( "embedMultipleTracks" );
26  embedCaloTower_ = iConfig.getParameter<bool>( "embedCaloTower" );
27 
28  // MC matching configurables
29  addGenMatch_ = iConfig.getParameter<bool>( "addGenMatch" );
30  if (addGenMatch_) {
31  embedGenMatch_ = iConfig.getParameter<bool> ( "embedGenMatch" );
32  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
33  genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
34  } else {
35  genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
36  }
37  }
38 
39  // quality
40  addQuality_ = iConfig.getParameter<bool>("addQuality");
41  qualitySrc_ = iConfig.getParameter<edm::InputTag>("qualitySource");
42 
43  // produces vector of particles
44  produces<std::vector<GenericParticle> >();
45 
46  if (iConfig.exists("isoDeposits")) {
47  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
48  if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
49  if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
50  if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
51  if (depconf.exists("user")) {
52  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
53  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
54  int key = UserBaseIso;
55  for ( ; it != ed; ++it, ++key) {
56  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
57  }
58  }
59  }
60 
61  // Efficiency configurables
62  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
63  if (addEfficiencies_) {
65  }
66 
67  // Resolution configurables
68  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
69  if (addResolutions_) {
71  }
72 
73  if (iConfig.exists("vertexing")) {
75  }
76 
77  // Check to see if the user wants to add user data
78  useUserData_ = false;
79  if ( iConfig.exists("userData") ) {
80  useUserData_ = true;
81  }
82 }
83 
85 }
86 
88  // Get the vector of GenericParticle's from the event
90  iEvent.getByLabel(src_, cands);
91 
92  // prepare isolation
93  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
94 
96  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
97  if (vertexingHelper_.enabled()) vertexingHelper_.newEvent(iEvent,iSetup);
98 
99  // prepare IsoDeposits
100  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositLabels_.size());
101  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
103  }
104 
105  // prepare the MC matching
106  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchSrc_.size());
107  if (addGenMatch_) {
108  for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
109  iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
110  }
111  }
112 
113  // prepare the quality
115  if (addQuality_) iEvent.getByLabel(qualitySrc_, qualities);
116 
117  // loop over cands
118  std::vector<GenericParticle> * PATGenericParticles = new std::vector<GenericParticle>();
119  for (edm::View<reco::Candidate>::const_iterator itGenericParticle = cands->begin(); itGenericParticle != cands->end(); itGenericParticle++) {
120  // construct the GenericParticle from the ref -> save ref to original object
121  unsigned int idx = itGenericParticle - cands->begin();
122  edm::RefToBase<reco::Candidate> candRef = cands->refAt(idx);
123 
124  PATGenericParticles->push_back(GenericParticle(candRef));
125  GenericParticle & aGenericParticle = PATGenericParticles->back();
126 
127  // embed RECO
128  if (embedTrack_) aGenericParticle.embedTrack();
129  if (embedGsfTrack_) aGenericParticle.embedGsfTrack();
130  if (embedTracks_) aGenericParticle.embedTracks();
131  if (embedStandalone_) aGenericParticle.embedStandalone();
132  if (embedCombined_) aGenericParticle.embedCombined();
133  if (embedSuperCluster_) aGenericParticle.embedSuperCluster();
134  if (embedCaloTower_) aGenericParticle.embedCaloTower();
135 
136  // isolation
137  if (isolator_.enabled()) {
138  isolator_.fill(*cands, idx, isolatorTmpStorage_);
139  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
140  // better to loop backwards, so the vector is resized less times
141  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
142  aGenericParticle.setIsolation(it->first, it->second);
143  }
144  }
145 
146  // isodeposit
147  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
148  aGenericParticle.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[candRef]);
149  }
150 
151  // store the match to the generated final state muons
152  if (addGenMatch_) {
153  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
154  reco::GenParticleRef genGenericParticle = (*genMatches[i])[candRef];
155  aGenericParticle.addGenParticleRef(genGenericParticle);
156  }
157  if (embedGenMatch_) aGenericParticle.embedGenParticle();
158  }
159 
160  if (addQuality_) {
161  aGenericParticle.setQuality( (*qualities)[candRef] );
162  }
163 
164  if (efficiencyLoader_.enabled()) {
165  efficiencyLoader_.setEfficiencies( aGenericParticle, candRef );
166  }
167 
168  if (resolutionLoader_.enabled()) {
169  resolutionLoader_.setResolutions(aGenericParticle);
170  }
171 
172  if (vertexingHelper_.enabled()) {
173  aGenericParticle.setVertexAssociation( vertexingHelper_(candRef) );
174  }
175 
176  if ( useUserData_ ) {
177  userDataHelper_.add( aGenericParticle, iEvent, iSetup );
178  }
179 
180  // PATGenericParticles->push_back(aGenericParticle); // NOOOOO!!!!
181  // We have already pushed_back this generic particle in the collection
182  // (we first push an empty particle and then fill it, to avoid useless copies)
183  }
184 
185  // sort GenericParticles in ET
186  std::sort(PATGenericParticles->begin(), PATGenericParticles->end(), eTComparator_);
187 
188  // put genEvt object in Event
189  std::auto_ptr<std::vector<GenericParticle> > myGenericParticles(PATGenericParticles);
190  iEvent.put(myGenericParticles);
192 
193 }
194 
196 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:180
void setIsolation(IsolationKeys key, float value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
void embedTrack()
embeds the master track instead of keeping a reference to it
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
U second(std::pair< T, U > const &p)
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:50
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
pat::PATUserDataHelper< pat::GenericParticle > userDataHelper_
int iEvent
Definition: GenABIO.cc:243
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
void embedStandalone()
embeds the stand-alone track instead of keeping a reference to it
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void embedGenParticle()
Definition: PATObject.h:665
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
PATGenericParticleProducer(const edm::ParameterSet &iConfig)
GreaterByEt< GenericParticle > eTComparator_
Produces the pat::GenericParticle.
int j
Definition: DBlmapReader.cc:9
bool first
Definition: L1TdeRCT.cc:79
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
void embedGsfTrack()
embeds the gsf track instead of keeping a reference to it
void embedSuperCluster()
embeds the supercluster instead of keeping a reference to it
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:649
void embedTracks()
embeds the other tracks instead of keeping references
void newEvent(const edm::Event &event)
To be called for each new event, reads in the vertex collection.
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
bool enabled() const
returns true if this was given a non dummy configuration
pat::helper::EfficiencyLoader efficiencyLoader_
pat::helper::VertexingHelper vertexingHelper_
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
std::vector< edm::InputTag > genMatchSrc_
list key
Definition: combine.py:13
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
void setQuality(float quality)
sets a user defined quality value
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
void embedCombined()
embeds the combined track instead of keeping a reference to it
pat::helper::KinResolutionsLoader resolutionLoader_
Produces and/or checks pat::VertexAssociation&#39;s.
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
void setVertexAssociation(const pat::VertexAssociation &assoc)
Set a single vertex association.
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82