CMS 3D CMS Logo

PATGenericParticleProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
8 #include <memory>
9 
10 using namespace pat;
11 
13  : isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation")
14  : edm::ParameterSet(),
15  consumesCollector(),
16  false),
17  userDataHelper_(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector()) {
18  // initialize the configurables
19  srcToken_ = consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("src"));
20 
21  // RECO embedding
22  embedTrack_ = iConfig.getParameter<bool>("embedTrack");
23  embedGsfTrack_ = iConfig.getParameter<bool>("embedGsfTrack");
24  embedStandalone_ = iConfig.getParameter<bool>("embedStandAloneMuon");
25  embedCombined_ = iConfig.getParameter<bool>("embedCombinedMuon");
26  embedSuperCluster_ = iConfig.getParameter<bool>("embedSuperCluster");
27  embedTracks_ = iConfig.getParameter<bool>("embedMultipleTracks");
28  embedCaloTower_ = iConfig.getParameter<bool>("embedCaloTower");
29 
30  // MC matching configurables
31  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
32  if (addGenMatch_) {
33  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
34  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
36  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
37  } else {
39  iConfig.getParameter<std::vector<edm::InputTag> >("genParticleMatch"),
40  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection> >(tag); });
41  }
42  }
43 
44  // quality
45  addQuality_ = iConfig.getParameter<bool>("addQuality");
46  qualitySrcToken_ = mayConsume<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("qualitySource"));
47 
48  // produces vector of particles
49  produces<std::vector<GenericParticle> >();
50 
51  if (iConfig.exists("isoDeposits")) {
52  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
53  if (depconf.exists("tracker"))
54  isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
55  if (depconf.exists("ecal"))
56  isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
57  if (depconf.exists("hcal"))
58  isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
59  if (depconf.exists("user")) {
60  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
61  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
62  int key = UserBaseIso;
63  for (; it != ed; ++it, ++key) {
64  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
65  }
66  }
67  }
69  edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys, edm::InputTag> const& label) {
70  return consumes<edm::ValueMap<IsoDeposit> >(label.second);
71  });
72 
73  // Efficiency configurables
74  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
75  if (addEfficiencies_) {
77  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
78  }
79 
80  // Resolution configurables
81  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
82  if (addResolutions_) {
84  }
85 
86  if (iConfig.exists("vertexing")) {
88  pat::helper::VertexingHelper(iConfig.getParameter<edm::ParameterSet>("vertexing"), consumesCollector());
89  }
90 
91  // Check to see if the user wants to add user data
92  useUserData_ = false;
93  if (iConfig.exists("userData")) {
94  useUserData_ = true;
95  }
96 }
97 
99 
101  // Get the vector of GenericParticle's from the event
103  iEvent.getByToken(srcToken_, cands);
104 
105  // prepare isolation
106  if (isolator_.enabled())
107  isolator_.beginEvent(iEvent, iSetup);
108 
115 
116  // prepare IsoDeposits
117  std::vector<edm::Handle<edm::ValueMap<IsoDeposit> > > deposits(isoDepositTokens_.size());
118  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
119  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
120  }
121 
122  // prepare the MC matching
123  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection> > > genMatches(genMatchTokens_.size());
124  if (addGenMatch_) {
125  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
126  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
127  }
128  }
129 
130  // prepare the quality
132  if (addQuality_)
133  iEvent.getByToken(qualitySrcToken_, qualities);
134 
135  // loop over cands
136  std::vector<GenericParticle>* PATGenericParticles = new std::vector<GenericParticle>();
137  for (edm::View<reco::Candidate>::const_iterator itGenericParticle = cands->begin(); itGenericParticle != cands->end();
138  itGenericParticle++) {
139  // construct the GenericParticle from the ref -> save ref to original object
140  unsigned int idx = itGenericParticle - cands->begin();
141  edm::RefToBase<reco::Candidate> candRef = cands->refAt(idx);
142 
143  PATGenericParticles->push_back(GenericParticle(candRef));
144  GenericParticle& aGenericParticle = PATGenericParticles->back();
145 
146  // embed RECO
147  if (embedTrack_)
148  aGenericParticle.embedTrack();
149  if (embedGsfTrack_)
150  aGenericParticle.embedGsfTrack();
151  if (embedTracks_)
152  aGenericParticle.embedTracks();
153  if (embedStandalone_)
154  aGenericParticle.embedStandalone();
155  if (embedCombined_)
156  aGenericParticle.embedCombined();
157  if (embedSuperCluster_)
158  aGenericParticle.embedSuperCluster();
159  if (embedCaloTower_)
160  aGenericParticle.embedCaloTower();
161 
162  // isolation
163  if (isolator_.enabled()) {
165  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
166  // better to loop backwards, so the vector is resized less times
167  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
168  ed = isolatorTmpStorage_.rend();
169  it != ed;
170  ++it) {
171  aGenericParticle.setIsolation(it->first, it->second);
172  }
173  }
174 
175  // isodeposit
176  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
177  aGenericParticle.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[candRef]);
178  }
179 
180  // store the match to the generated final state muons
181  if (addGenMatch_) {
182  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
183  reco::GenParticleRef genGenericParticle = (*genMatches[i])[candRef];
184  aGenericParticle.addGenParticleRef(genGenericParticle);
185  }
186  if (embedGenMatch_)
187  aGenericParticle.embedGenParticle();
188  }
189 
190  if (addQuality_) {
191  aGenericParticle.setQuality((*qualities)[candRef]);
192  }
193 
194  if (efficiencyLoader_.enabled()) {
195  efficiencyLoader_.setEfficiencies(aGenericParticle, candRef);
196  }
197 
198  if (resolutionLoader_.enabled()) {
199  resolutionLoader_.setResolutions(aGenericParticle);
200  }
201 
202  if (vertexingHelper_.enabled()) {
203  aGenericParticle.setVertexAssociation(vertexingHelper_(candRef));
204  }
205 
206  if (useUserData_) {
207  userDataHelper_.add(aGenericParticle, iEvent, iSetup);
208  }
209 
210  // PATGenericParticles->push_back(aGenericParticle); // NOOOOO!!!!
211  // We have already pushed_back this generic particle in the collection
212  // (we first push an empty particle and then fill it, to avoid useless copies)
213  }
214 
215  // sort GenericParticles in ET
216  std::sort(PATGenericParticles->begin(), PATGenericParticles->end(), eTComparator_);
217 
218  // put genEvt object in Event
219  std::unique_ptr<std::vector<GenericParticle> > myGenericParticles(PATGenericParticles);
220  iEvent.put(std::move(myGenericParticles));
221  if (isolator_.enabled())
223 }
224 
226 
pat::PATGenericParticleProducer::addGenMatch_
bool addGenMatch_
Definition: PATGenericParticleProducer.h:59
pat::PATGenericParticleProducer::srcToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcToken_
Definition: PATGenericParticleProducer.h:50
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.h:61
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::PATGenericParticleProducer::userDataHelper_
pat::PATUserDataHelper< pat::GenericParticle > userDataHelper_
Definition: PATGenericParticleProducer.h:80
pat::helper::EfficiencyLoader
Definition: EfficiencyLoader.h:16
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.h:74
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::PATGenericParticleProducer::efficiencyLoader_
pat::helper::EfficiencyLoader efficiencyLoader_
Definition: PATGenericParticleProducer.h:72
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
pat::PATGenericParticleProducer::isoDepositTokens_
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
Definition: PATGenericParticleProducer.h:69
pat::PATGenericParticleProducer::embedTracks_
bool embedTracks_
Definition: PATGenericParticleProducer.h:53
pat::PATObject::addGenParticleRef
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:753
pat::PATGenericParticleProducer::isolator_
pat::helper::MultiIsolator isolator_
Definition: PATGenericParticleProducer.h:66
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
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.h:79
dqmdumpme.first
first
Definition: dqmdumpme.py:55
pat::helper::MultiIsolator::IsolationValuePairs
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
PATGenericParticleProducer.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
pat::PATGenericParticleProducer::eTComparator_
GreaterByEt< GenericParticle > eTComparator_
Definition: PATGenericParticleProducer.h:64
pat::PATGenericParticleProducer::addEfficiencies_
bool addEfficiencies_
Definition: PATGenericParticleProducer.h:71
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
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
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
pat::PATGenericParticleProducer::PATGenericParticleProducer
PATGenericParticleProducer(const edm::ParameterSet &iConfig)
Definition: PATGenericParticleProducer.cc:12
pat::helper::KinResolutionsLoader
Definition: KinResolutionsLoader.h:18
pat::PATGenericParticleProducer::embedCombined_
bool embedCombined_
Definition: PATGenericParticleProducer.h:53
pat::GenericParticle::setQuality
void setQuality(float quality)
sets a user defined quality value
Definition: GenericParticle.h:132
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:15142
pat::PATGenericParticleProducer::isoDepositLabels_
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
Definition: PATGenericParticleProducer.h:68
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
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.h:41
ParameterSet
Definition: Functions.h:16
pat::PATGenericParticleProducer::resolutionLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
Definition: PATGenericParticleProducer.h:75
pat::PATGenericParticleProducer::embedStandalone_
bool embedStandalone_
Definition: PATGenericParticleProducer.h:53
pat::UserBaseIso
Definition: Isolation.h:22
pat::TrackIso
Definition: Isolation.h:10
pat::PATGenericParticleProducer::embedCaloTower_
bool embedCaloTower_
Definition: PATGenericParticleProducer.h:53
pat::PATGenericParticleProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATGenericParticleProducer.cc:100
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.h:53
pat::PATGenericParticleProducer::embedTrack_
bool embedTrack_
Definition: PATGenericParticleProducer.h:53
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:57
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
pat::helper::VertexingHelper::enabled
bool enabled() const
returns true if this was given a non dummy configuration
Definition: VertexingHelper.h:56
eostools.move
def move(src, dest)
Definition: eostools.py:511
pat::PATGenericParticleProducer::~PATGenericParticleProducer
~PATGenericParticleProducer() override
Definition: PATGenericParticleProducer.cc:98
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.h:53
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.h:57
transform.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.h:56
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
pat::PATGenericParticleProducer::vertexingHelper_
pat::helper::VertexingHelper vertexingHelper_
Definition: PATGenericParticleProducer.h:77
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
pat::PATObject::embedGenParticle
void embedGenParticle()
Definition: PATObject.h:770
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.h:60
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
pat::PATGenericParticleProducer::isolatorTmpStorage_
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
Definition: PATGenericParticleProducer.h:67
pat::GenericParticle::embedTrack
void embedTrack()
embeds the master track instead of keeping a reference to it
Definition: GenericParticle.cc:96