CMS 3D CMS Logo

PATGenericParticleProducer.cc
Go to the documentation of this file.
1 
30 
31 #include <memory>
32 
33 namespace pat {
34 
36  public:
37  explicit PATGenericParticleProducer(const edm::ParameterSet& iConfig);
38  ~PATGenericParticleProducer() override;
39 
40  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
41 
42  private:
43  // configurables
45 
46  // embed RECo objects
49 
52 
55  std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > > genMatchTokens_;
56 
57  // tools
59 
61  pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_; // better here than recreate at each event
62  std::vector<std::pair<pat::IsolationKeys, edm::InputTag> > isoDepositLabels_;
63  std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit> > > isoDepositTokens_;
64 
67 
70 
72 
75  };
76 
77 } // namespace pat
78 
79 using namespace pat;
80 
82  : isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation")
83  : edm::ParameterSet(),
84  consumesCollector(),
85  false),
86  userDataHelper_(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector()) {
87  // initialize the configurables
88  srcToken_ = consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"));
89 
90  // RECO embedding
91  embedTrack_ = iConfig.getParameter<bool>("embedTrack");
92  embedGsfTrack_ = iConfig.getParameter<bool>("embedGsfTrack");
93  embedStandalone_ = iConfig.getParameter<bool>("embedStandAloneMuon");
94  embedCombined_ = iConfig.getParameter<bool>("embedCombinedMuon");
95  embedSuperCluster_ = iConfig.getParameter<bool>("embedSuperCluster");
96  embedTracks_ = iConfig.getParameter<bool>("embedMultipleTracks");
97  embedCaloTower_ = iConfig.getParameter<bool>("embedCaloTower");
98 
99  // MC matching configurables
100  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
101  if (addGenMatch_) {
102  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
103  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
105  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
106  } else {
108  iConfig.getParameter<std::vector<edm::InputTag> >("genParticleMatch"),
109  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection> >(tag); });
110  }
111  }
112 
113  // quality
114  addQuality_ = iConfig.getParameter<bool>("addQuality");
115  qualitySrcToken_ = mayConsume<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("qualitySource"));
116 
117  // produces vector of particles
118  produces<std::vector<GenericParticle> >();
119 
120  if (iConfig.exists("isoDeposits")) {
121  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
122  if (depconf.exists("tracker"))
123  isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
124  if (depconf.exists("ecal"))
125  isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
126  if (depconf.exists("hcal"))
127  isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
128  if (depconf.exists("user")) {
129  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
130  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
131  int key = UserBaseIso;
132  for (; it != ed; ++it, ++key) {
133  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
134  }
135  }
136  }
138  edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys, edm::InputTag> const& label) {
139  return consumes<edm::ValueMap<IsoDeposit> >(label.second);
140  });
141 
142  // Efficiency configurables
143  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
144  if (addEfficiencies_) {
146  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
147  }
148 
149  // Resolution configurables
150  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
151  if (addResolutions_) {
153  }
154 
155  if (iConfig.exists("vertexing")) {
157  pat::helper::VertexingHelper(iConfig.getParameter<edm::ParameterSet>("vertexing"), consumesCollector());
158  }
159 
160  // Check to see if the user wants to add user data
161  useUserData_ = false;
162  if (iConfig.exists("userData")) {
163  useUserData_ = true;
164  }
165 }
166 
168 
170  // Get the vector of GenericParticle's from the event
172  iEvent.getByToken(srcToken_, cands);
173 
174  // prepare isolation
175  if (isolator_.enabled())
176  isolator_.beginEvent(iEvent, iSetup);
177 
184 
185  // prepare IsoDeposits
186  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositTokens_.size());
187  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
188  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
189  }
190 
191  // prepare the MC matching
192  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchTokens_.size());
193  if (addGenMatch_) {
194  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
195  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
196  }
197  }
198 
199  // prepare the quality
201  if (addQuality_)
202  iEvent.getByToken(qualitySrcToken_, qualities);
203 
204  // loop over cands
205  std::vector<GenericParticle>* PATGenericParticles = new std::vector<GenericParticle>();
206  for (edm::View<reco::Candidate>::const_iterator itGenericParticle = cands->begin(); itGenericParticle != cands->end();
207  itGenericParticle++) {
208  // construct the GenericParticle from the ref -> save ref to original object
209  unsigned int idx = itGenericParticle - cands->begin();
210  edm::RefToBase<reco::Candidate> candRef = cands->refAt(idx);
211 
212  PATGenericParticles->push_back(GenericParticle(candRef));
213  GenericParticle& aGenericParticle = PATGenericParticles->back();
214 
215  // embed RECO
216  if (embedTrack_)
217  aGenericParticle.embedTrack();
218  if (embedGsfTrack_)
219  aGenericParticle.embedGsfTrack();
220  if (embedTracks_)
221  aGenericParticle.embedTracks();
222  if (embedStandalone_)
223  aGenericParticle.embedStandalone();
224  if (embedCombined_)
225  aGenericParticle.embedCombined();
226  if (embedSuperCluster_)
227  aGenericParticle.embedSuperCluster();
228  if (embedCaloTower_)
229  aGenericParticle.embedCaloTower();
230 
231  // isolation
232  if (isolator_.enabled()) {
234  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
235  // better to loop backwards, so the vector is resized less times
236  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
237  ed = isolatorTmpStorage_.rend();
238  it != ed;
239  ++it) {
240  aGenericParticle.setIsolation(it->first, it->second);
241  }
242  }
243 
244  // isodeposit
245  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
246  aGenericParticle.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[candRef]);
247  }
248 
249  // store the match to the generated final state muons
250  if (addGenMatch_) {
251  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
252  reco::GenParticleRef genGenericParticle = (*genMatches[i])[candRef];
253  aGenericParticle.addGenParticleRef(genGenericParticle);
254  }
255  if (embedGenMatch_)
256  aGenericParticle.embedGenParticle();
257  }
258 
259  if (addQuality_) {
260  aGenericParticle.setQuality((*qualities)[candRef]);
261  }
262 
263  if (efficiencyLoader_.enabled()) {
264  efficiencyLoader_.setEfficiencies(aGenericParticle, candRef);
265  }
266 
267  if (resolutionLoader_.enabled()) {
268  resolutionLoader_.setResolutions(aGenericParticle);
269  }
270 
271  if (vertexingHelper_.enabled()) {
272  aGenericParticle.setVertexAssociation(vertexingHelper_(candRef));
273  }
274 
275  if (useUserData_) {
276  userDataHelper_.add(aGenericParticle, iEvent, iSetup);
277  }
278 
279  // PATGenericParticles->push_back(aGenericParticle); // NOOOOO!!!!
280  // We have already pushed_back this generic particle in the collection
281  // (we first push an empty particle and then fill it, to avoid useless copies)
282  }
283 
284  // sort GenericParticles in ET
285  std::sort(PATGenericParticles->begin(), PATGenericParticles->end(), eTComparator_);
286 
287  // put genEvt object in Event
288  std::unique_ptr<std::vector<GenericParticle> > myGenericParticles(PATGenericParticles);
289  iEvent.put(std::move(myGenericParticles));
290  if (isolator_.enabled())
292 }
293 
pat::PATGenericParticleProducer::addGenMatch_
bool addGenMatch_
Definition: PATGenericParticleProducer.cc:53
pat::PATUserDataHelper< pat::GenericParticle >
pat::PATGenericParticleProducer::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Definition: PATGenericParticleProducer.cc:44
mps_fire.i
i
Definition: mps_fire.py:428
pat::EcalIso
Definition: Isolation.h:11
MessageLogger.h
pat::PATGenericParticleProducer::genMatchTokens_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
Definition: PATGenericParticleProducer.cc:55
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::PATGenericParticleProducer::userDataHelper_
pat::PATUserDataHelper< pat::GenericParticle > userDataHelper_
Definition: PATGenericParticleProducer.cc:74
pat::helper::EfficiencyLoader
Definition: EfficiencyLoader.h:16
edm::EDGetTokenT
Definition: EDGetToken.h:33
pat::helper::MultiIsolator::fill
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:84
pat::PATGenericParticleProducer::addResolutions_
bool addResolutions_
Definition: PATGenericParticleProducer.cc:68
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::PATGenericParticleProducer::efficiencyLoader_
pat::helper::EfficiencyLoader efficiencyLoader_
Definition: PATGenericParticleProducer.cc:66
GenericParticle.h
pat::GenericParticle::embedSuperCluster
void embedSuperCluster()
embeds the supercluster instead of keeping a reference to it
Definition: GenericParticle.cc:135
pat::helper::EfficiencyLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: EfficiencyLoader.h:25
EDProducer.h
pat::PATGenericParticleProducer::isoDepositTokens_
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
Definition: PATGenericParticleProducer.cc:63
pat::PATGenericParticleProducer::embedTracks_
bool embedTracks_
Definition: PATGenericParticleProducer.cc:47
pat::PATObject::addGenParticleRef
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:751
pat::PATGenericParticleProducer::isolator_
pat::helper::MultiIsolator isolator_
Definition: PATGenericParticleProducer.cc:60
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
Association.h
edm::Handle
Definition: AssociativeIterator.h:50
pat::GenericParticle::embedGsfTrack
void embedGsfTrack()
embeds the gsf track instead of keeping a reference to it
Definition: GenericParticle.cc:127
pat::PATGenericParticleProducer::useUserData_
bool useUserData_
Definition: PATGenericParticleProducer.cc:73
pat::helper::MultiIsolator::IsolationValuePairs
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
MultiIsolator.h
EfficiencyLoader.h
pat::helper::KinResolutionsLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: KinResolutionsLoader.h:27
pat::helper::MultiIsolator::enabled
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:55
edm::Ref< GenParticleCollection >
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
pat::helper::MultiIsolator::endEvent
void endEvent()
Definition: MultiIsolator.cc:85
GenParticle.h
GreaterByEt
Definition: EtComparator.h:23
pat::PATGenericParticleProducer::eTComparator_
GreaterByEt< GenericParticle > eTComparator_
Definition: PATGenericParticleProducer.cc:58
pat::PATGenericParticleProducer::addEfficiencies_
bool addEfficiencies_
Definition: PATGenericParticleProducer.cc:65
MakerMacros.h
pat::GenericParticle::setIsolation
void setIsolation(IsolationKeys key, float value)
Definition: GenericParticle.h:201
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATUserDataHelper::add
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
Definition: PATUserDataHelper.h:114
pat::helper::EfficiencyLoader::newEvent
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
Definition: EfficiencyLoader.cc:21
GenParticleFwd.h
pat::PATGenericParticleProducer::PATGenericParticleProducer
PATGenericParticleProducer(const edm::ParameterSet &iConfig)
Definition: PATGenericParticleProducer.cc:81
pat::helper::KinResolutionsLoader
Definition: KinResolutionsLoader.h:18
KinResolutionsLoader.h
pat::PATGenericParticleProducer::embedCombined_
bool embedCombined_
Definition: PATGenericParticleProducer.cc:47
pat::GenericParticle::setQuality
void setQuality(float quality)
sets a user defined quality value
Definition: GenericParticle.h:132
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
pat::GenericParticle::embedStandalone
void embedStandalone()
embeds the stand-alone track instead of keeping a reference to it
Definition: GenericParticle.cc:113
pat::helper::VertexingHelper
Produces and/or checks pat::VertexAssociation's.
Definition: VertexingHelper.h:50
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
pat::GenericParticle::embedCaloTower
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
Definition: GenericParticle.cc:142
pat::helper::KinResolutionsLoader::setResolutions
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
Definition: KinResolutionsLoader.h:49
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15161
pat::PATGenericParticleProducer::isoDepositLabels_
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
Definition: PATGenericParticleProducer.cc:62
pat::helper::VertexingHelper::newEvent
void newEvent(const edm::Event &event)
To be called for each new event, reads in the vertex collection.
Definition: VertexingHelper.cc:38
EtComparator.h
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed)
Definition: GenericParticle.h:38
edm::ParameterSet
Definition: ParameterSet.h:47
pat::PATGenericParticleProducer
Produces the pat::GenericParticle.
Definition: PATGenericParticleProducer.cc:35
Event.h
ParameterSet
Definition: Functions.h:16
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
UserData.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
pat::PATGenericParticleProducer::resolutionLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
Definition: PATGenericParticleProducer.cc:69
pat::PATGenericParticleProducer::embedStandalone_
bool embedStandalone_
Definition: PATGenericParticleProducer.cc:47
pat::UserBaseIso
Definition: Isolation.h:22
pat::TrackIso
Definition: Isolation.h:10
pat::PATGenericParticleProducer::embedCaloTower_
bool embedCaloTower_
Definition: PATGenericParticleProducer.cc:47
pat::PATGenericParticleProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATGenericParticleProducer.cc:169
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::HcalIso
Definition: Isolation.h:12
pat::GenericParticle::setVertexAssociation
void setVertexAssociation(const pat::VertexAssociation &assoc)
Set a single vertex association.
Definition: GenericParticle.h:283
pat::PATGenericParticleProducer::embedSuperCluster_
bool embedSuperCluster_
Definition: PATGenericParticleProducer.cc:47
edm::stream::EDProducer
Definition: EDProducer.h:36
pat::PATGenericParticleProducer::embedTrack_
bool embedTrack_
Definition: PATGenericParticleProducer.cc:47
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
pat::helper::KinResolutionsLoader::newEvent
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
Definition: KinResolutionsLoader.cc:27
ValueMap.h
pat::helper::VertexingHelper::enabled
bool enabled() const
returns true if this was given a non dummy configuration
Definition: VertexingHelper.h:56
pat::helper::MultiIsolator
Definition: MultiIsolator.h:15
eostools.move
def move(src, dest)
Definition: eostools.py:511
VertexingHelper.h
pat::PATGenericParticleProducer::~PATGenericParticleProducer
~PATGenericParticleProducer() override
Definition: PATGenericParticleProducer.cc:167
pat::GenericParticle::embedCombined
void embedCombined()
embeds the combined track instead of keeping a reference to it
Definition: GenericParticle.cc:120
pat::IsolationKeys
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
pat::helper::MultiIsolator::beginEvent
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
Definition: MultiIsolator.cc:79
pat::PATGenericParticleProducer::embedGsfTrack_
bool embedGsfTrack_
Definition: PATGenericParticleProducer.cc:47
pat::helper::EfficiencyLoader::setEfficiencies
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
Definition: EfficiencyLoader.h:41
pat::PATGenericParticleProducer::qualitySrcToken_
edm::EDGetTokenT< edm::ValueMap< float > > qualitySrcToken_
Definition: PATGenericParticleProducer.cc:51
transform.h
PATUserDataHelper.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase
Definition: AssociativeIterator.h:54
pat::PATGenericParticleProducer::addQuality_
bool addQuality_
Definition: PATGenericParticleProducer.cc:50
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
pat::GenericParticle::embedTracks
void embedTracks()
embeds the other tracks instead of keeping references
Definition: GenericParticle.cc:103
pat::GenericParticle::setIsoDeposit
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: GenericParticle.h:251
View.h
ParameterSet.h
pat::PATGenericParticleProducer::vertexingHelper_
pat::helper::VertexingHelper vertexingHelper_
Definition: PATGenericParticleProducer.cc:71
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
pat::PATObject::embedGenParticle
void embedGenParticle()
Definition: PATObject.h:768
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
CandIsolatorFromDeposits_cfi.deposits
deposits
Definition: CandIsolatorFromDeposits_cfi.py:4
pat::PATGenericParticleProducer::embedGenMatch_
bool embedGenMatch_
Definition: PATGenericParticleProducer.cc:54
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
pat::PATGenericParticleProducer::isolatorTmpStorage_
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
Definition: PATGenericParticleProducer.cc:61
pat::GenericParticle::embedTrack
void embedTrack()
embeds the master track instead of keeping a reference to it
Definition: GenericParticle.cc:96