CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
MuonSimClassifier Class Reference
Inheritance diagram for MuonSimClassifier:
edm::stream::EDProducer<>

Public Member Functions

 MuonSimClassifier (const edm::ParameterSet &)
 
 ~MuonSimClassifier () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

int convertAndPush (const TrackingParticle &tp, reco::GenParticleCollection &out, const TrackingParticleRef &momRef, const edm::Handle< reco::GenParticleCollection > &genParticles) const
 
int flavour (int pdgId) const
 Returns the flavour given a pdg id code. More...
 
TrackingParticleRef getTpMother (TrackingParticleRef tp)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
template<typename T >
void writeValueMap (edm::Event &iEvent, const edm::Handle< edm::View< reco::Muon >> &handle, const std::vector< T > &values, const std::string &label) const
 Write a ValueMap<int> in the event. More...
 

Private Attributes

edm::InputTag associatorLabel_
 The Associations. More...
 
double decayAbsZ_
 
double decayRho_
 Cylinder to use to decide if a decay is early or late. More...
 
edm::InputTag genParticles_
 
edm::EDGetTokenT< reco::GenParticleCollectiongenParticlesToken_
 
bool linkToGenParticles_
 Create a link to the generator level particles. More...
 
edm::EDGetTokenT< reco::MuonToTrackingParticleAssociatormuAssocToken_
 
edm::EDGetTokenT< edm::View< reco::Muon > > muonsToken_
 The RECO objects. More...
 
edm::EDGetTokenT< TrackingParticleCollectiontrackingParticlesToken_
 The TrackingParticle objects. More...
 
reco::MuonTrackType trackType_
 Track to use. More...
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 70 of file MuonSimClassifier.cc.

Constructor & Destructor Documentation

MuonSimClassifier::MuonSimClassifier ( const edm::ParameterSet iConfig)
explicit

Definition at line 125 of file MuonSimClassifier.cc.

References Exception, genParticles_, genParticlesToken_, edm::ParameterSet::getParameter(), reco::GlbOrTrk, reco::GlobalTk, reco::InnerTk, linkToGenParticles_, reco::OuterTk, reco::Segments, AlCaHLTBitMon_QueryRunRegistry::string, tkIsoDeposits_cff::trackType, and trackType_.

126  : muonsToken_(consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("muons"))),
128  consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles"))),
130  consumes<reco::MuonToTrackingParticleAssociator>(iConfig.getParameter<edm::InputTag>("associatorLabel"))),
131  decayRho_(iConfig.getParameter<double>("decayRho")),
132  decayAbsZ_(iConfig.getParameter<double>("decayAbsZ")),
133  linkToGenParticles_(iConfig.getParameter<bool>("linkToGenParticles")),
135 
136 {
137  std::string trackType = iConfig.getParameter<std::string>("trackType");
138  if (trackType == "inner")
140  else if (trackType == "outer")
142  else if (trackType == "global")
144  else if (trackType == "segments")
146  else if (trackType == "glb_or_trk")
148  else
149  throw cms::Exception("Configuration") << "Track type '" << trackType << "' not supported.\n";
150  if (linkToGenParticles_) {
151  genParticlesToken_ = consumes<reco::GenParticleCollection>(genParticles_);
152  }
153 
154  produces<edm::ValueMap<reco::MuonSimInfo>>();
155  if (linkToGenParticles_) {
156  produces<reco::GenParticleCollection>("secondaries");
157  produces<edm::Association<reco::GenParticleCollection>>("toPrimaries");
158  produces<edm::Association<reco::GenParticleCollection>>("toSecondaries");
159  }
160 }
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::View< reco::Muon > > muonsToken_
The RECO objects.
reco::MuonTrackType trackType_
Track to use.
edm::InputTag genParticles_
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
edm::EDGetTokenT< reco::MuonToTrackingParticleAssociator > muAssocToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticlesToken_
The TrackingParticle objects.
double decayRho_
Cylinder to use to decide if a decay is early or late.
bool linkToGenParticles_
Create a link to the generator level particles.
MuonSimClassifier::~MuonSimClassifier ( )
override

Definition at line 162 of file MuonSimClassifier.cc.

162 {}

Member Function Documentation

int MuonSimClassifier::convertAndPush ( const TrackingParticle tp,
reco::GenParticleCollection out,
const TrackingParticleRef momRef,
const edm::Handle< reco::GenParticleCollection > &  genParticles 
) const
private

Convert TrackingParticle into GenParticle, save into output collection, if mother is primary set reference to it, return index in output collection

Definition at line 573 of file MuonSimClassifier.cc.

References TrackingParticle::charge(), DEFINE_FWK_MODULE, Exception, genParticles_, edm::HandleBase::id(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::isNonnull(), TrackingParticle::p4(), TrackingParticle::pdgId(), TrackingParticle::status(), and TrackingParticle::vertex().

Referenced by getTpMother(), and produce().

576  {
577  out.push_back(reco::GenParticle(tp.charge(), tp.p4(), tp.vertex(), tp.pdgId(), tp.status(), true));
578  if (simMom.isNonnull() && !simMom->genParticles().empty()) {
579  if (genParticles.id() != simMom->genParticles().id()) {
580  throw cms::Exception("Configuration")
581  << "Product ID mismatch between the genParticle collection (" << genParticles_ << ", id " << genParticles.id()
582  << ") and the references in the TrackingParticles (id " << simMom->genParticles().id() << ")\n";
583  }
584  out.back().addMother(simMom->genParticles()[0]);
585  }
586  return out.size() - 1;
587 }
const LorentzVector & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
ProductID id() const
Definition: HandleBase.cc:15
int pdgId() const
PDG ID.
int status() const
Status word.
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
edm::InputTag genParticles_
Point vertex() const
Parent vertex position.
ProductIndex id() const
Definition: ProductID.h:38
int MuonSimClassifier::flavour ( int  pdgId) const
private

Returns the flavour given a pdg id code.

Definition at line 554 of file MuonSimClassifier.cc.

References funct::abs().

Referenced by produce().

554  {
555  int flav = std::abs(pdgId);
556  // for quarks, leptons and bosons except gluons, take their pdgId
557  // muons and taus have themselves as flavour
558  if (flav <= 37 && flav != 21)
559  return flav;
560  // look for barions
561  int bflav = ((flav / 1000) % 10);
562  if (bflav != 0)
563  return bflav;
564  // look for mesons
565  int mflav = ((flav / 100) % 10);
566  if (mflav != 0)
567  return mflav;
568  return 0;
569 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TrackingParticleRef MuonSimClassifier::getTpMother ( TrackingParticleRef  tp)
inlineprivate

Definition at line 108 of file MuonSimClassifier.cc.

References convertAndPush(), GenHFHadronMatcher_cfi::genParticles, edm::Ref< C, T, F >::isNonnull(), and MillePedeFileConverter_cfg::out.

Referenced by produce().

108  {
109  if (tp.isNonnull() && tp->parentVertex().isNonnull() && !tp->parentVertex()->sourceTracks().empty()) {
110  return tp->parentVertex()->sourceTracks()[0];
111  } else {
112  return TrackingParticleRef();
113  }
114  }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
edm::Ref< TrackingParticleCollection > TrackingParticleRef
void MuonSimClassifier::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 175 of file MuonSimClassifier.cc.

References funct::abs(), allMuons_cfi::allMuons, reco::MuonToTrackingParticleAssociator::associateMuons(), edm::RefToBaseVector< T >::at(), convertAndPush(), decayAbsZ_, decayRho_, dumpFormatedInfo(), Exception, reco::ExtGhostElectron, reco::ExtGhostPunchthrough, reco::ExtMatchedElectron, reco::ExtMatchedPunchthrough, reco::ExtNotMatched, edm::helper::Filler< Map >::fill(), flavour(), GenHFHadronMatcher_cfi::genParticles, genParticles_, genParticlesToken_, edm::Event::getByToken(), getTpMother(), reco::GhostElectron, reco::GhostMuonFromB, reco::GhostMuonFromBtoC, reco::GhostMuonFromC, reco::GhostMuonFromGaugeOrHiggsBoson, reco::GhostMuonFromHeavyFlavour, reco::GhostMuonFromLightFlavour, reco::GhostMuonFromNonPrimaryParticle, reco::GhostMuonFromOtherLight, reco::GhostMuonFromPiKNotppMuX, reco::GhostMuonFromPiKppMuX, reco::GhostMuonFromTau, reco::GhostPrimaryMuon, reco::GhostPunchthrough, reco::GlobalTk, mps_fire::i, edm::HandleBase::id(), edm::Ref< C, T, F >::id(), edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::key(), linkToGenParticles_, LogTrace, match(), reco::MatchedElectron, reco::MatchedMuonFromB, reco::MatchedMuonFromBtoC, reco::MatchedMuonFromC, reco::MatchedMuonFromGaugeOrHiggsBoson, reco::MatchedMuonFromHeavyFlavour, reco::MatchedMuonFromLightFlavour, reco::MatchedMuonFromNonPrimaryParticle, reco::MatchedMuonFromOtherLight, reco::MatchedMuonFromPiKNotppMuX, reco::MatchedMuonFromPiKppMuX, reco::MatchedMuonFromTau, reco::MatchedPrimaryMuon, reco::MatchedPunchthrough, eostools::move(), muAssocToken_, extraflags_cff::muons, muonsToken_, gen::n, reco::NotMatched, reco::OuterTk, edm::Handle< T >::product(), edm::RefToBaseVector< T >::push_back(), edm::RefVector< C, T, F >::push_back(), edm::Event::put(), trackingTruthProducer_cfi::trackingParticles, trackingParticlesToken_, trackType_, and writeValueMap().

175  {
177  iEvent.getByToken(muonsToken_, muons);
178 
180  iEvent.getByToken(trackingParticlesToken_, trackingParticles);
181 
183  if (linkToGenParticles_) {
184  iEvent.getByToken(genParticlesToken_, genParticles);
185  }
186 
188  iEvent.getByToken(muAssocToken_, associatorBase);
189  const reco::MuonToTrackingParticleAssociator *assoByHits = associatorBase.product();
190 
191  reco::MuonToSimCollection recSimColl;
192  reco::SimToMuonCollection simRecColl;
193  LogTrace("MuonSimClassifier") << "\n "
194  "***************************************************************** ";
195  LogTrace("MuonSimClassifier") << " RECO MUON association, type: " << trackType_;
196  LogTrace("MuonSimClassifier") << " ******************************************"
197  "*********************** \n";
198 
200  for (size_t i = 0, n = muons->size(); i < n; ++i) {
201  allMuons.push_back(muons->refAt(i));
202  }
203 
205  for (size_t i = 0, n = trackingParticles->size(); i < n; ++i) {
206  allTPs.push_back(TrackingParticleRef(trackingParticles, i));
207  }
208 
209  assoByHits->associateMuons(recSimColl, simRecColl, allMuons, trackType_, allTPs);
210 
211  // for global muons without hits on muon detectors, look at the linked
212  // standalone muon
213  reco::MuonToSimCollection updSTA_recSimColl;
214  reco::SimToMuonCollection updSTA_simRecColl;
215  if (trackType_ == reco::GlobalTk) {
216  LogTrace("MuonSimClassifier") << "\n "
217  "***************************************************************** ";
218  LogTrace("MuonSimClassifier") << " STANDALONE (UpdAtVtx) MUON association ";
219  LogTrace("MuonSimClassifier") << " ****************************************"
220  "************************* \n";
221  assoByHits->associateMuons(updSTA_recSimColl, updSTA_simRecColl, allMuons, reco::OuterTk, allTPs);
222  }
223 
224  typedef reco::MuonToSimCollection::const_iterator r2s_it;
225  typedef reco::SimToMuonCollection::const_iterator s2r_it;
226 
227  size_t nmu = muons->size();
228  LogTrace("MuonSimClassifier") << "\n There are " << nmu << " reco::Muons.";
229 
230  std::vector<reco::MuonSimInfo> simInfo;
231 
232  std::unique_ptr<reco::GenParticleCollection> secondaries; // output collection of secondary muons
233  std::map<TrackingParticleRef, int> tpToSecondaries; // map from tp to (index+1) in output collection
234  std::vector<int> muToPrimary(nmu, -1), muToSecondary(nmu,
235  -1); // map from input into (index) in output, -1 for null
237  secondaries.reset(new reco::GenParticleCollection());
238 
239  // loop on reco muons
240  for (size_t i = 0; i < nmu; ++i) {
241  simInfo.push_back(reco::MuonSimInfo());
242  LogTrace("MuonSimClassifier") << "\n reco::Muon # " << i;
243 
245  edm::RefToBase<reco::Muon> muMatchBack;
246  r2s_it match = recSimColl.find(allMuons.at(i));
247  s2r_it matchback;
248  if (match != recSimColl.end()) {
249  // match->second is vector, front is first element, first is the ref
250  // (second would be the quality)
251  tp = match->second.front().first;
252  simInfo[i].tpId = tp.isNonnull() ? tp.key() : -1; // we check, even if null refs should not appear here at all
253  simInfo[i].tpAssoQuality = match->second.front().second;
254  s2r_it matchback = simRecColl.find(tp);
255  if (matchback != simRecColl.end()) {
256  muMatchBack = matchback->second.front().first;
257  } else {
258  LogTrace("MuonSimClassifier") << "\n***WARNING: This I do NOT understand: why no match back? "
259  "*** \n";
260  }
261  } else {
262  if ((trackType_ == reco::GlobalTk) && allMuons.at(i)->isGlobalMuon()) {
263  // perform a second attempt, matching with the standalone muon
264  r2s_it matchSta = updSTA_recSimColl.find(allMuons.at(i));
265  if (matchSta != updSTA_recSimColl.end()) {
266  tp = matchSta->second.front().first;
267  simInfo[i].tpId = tp.isNonnull() ? tp.key() : -1; // we check, even if null refs
268  // should not appear here at all
269  simInfo[i].tpAssoQuality = matchSta->second.front().second;
270  s2r_it matchback = updSTA_simRecColl.find(tp);
271  if (matchback != updSTA_simRecColl.end()) {
272  muMatchBack = matchback->second.front().first;
273  } else {
274  LogTrace("MuonSimClassifier") << "\n***WARNING: This I do NOT understand: why no match back "
275  "in updSTA? *** \n";
276  }
277  }
278  } else {
279  LogTrace("MuonSimClassifier") << "\t No matching TrackingParticle is found ";
280  }
281  }
282 
283  if (tp.isNonnull()) {
284  bool isGhost = muMatchBack != allMuons.at(i);
285  if (isGhost)
286  LogTrace("MuonSimClassifier") << "\t *** This seems a Duplicate muon ! "
287  "classif[i] will be < 0 ***";
288 
289  // identify signal and pileup TP
290  simInfo[i].tpBX = tp->eventId().bunchCrossing();
291  simInfo[i].tpEvent = tp->eventId().event();
292 
293  simInfo[i].pdgId = tp->pdgId();
294  simInfo[i].vertex = tp->vertex();
295 
296  // added info on GEANT process producing the TrackingParticle
297  const std::vector<SimVertex> &g4Vs = tp->parentVertex()->g4Vertices();
298  simInfo[i].g4processType = g4Vs[0].processType();
299 
300  simInfo[i].charge = tp->charge();
301  simInfo[i].p4 = tp->p4();
302 
303  // Try to extract mother and grand mother of this muon.
304  // Unfortunately, SIM and GEN histories require diffent code :-(
305  if (!tp->genParticles().empty()) { // Muon is in GEN
306  reco::GenParticleRef genp = tp->genParticles()[0];
307  reco::GenParticleRef genMom = genp->numberOfMothers() > 0 ? genp->motherRef() : reco::GenParticleRef();
308  reco::GenParticleRef mMom = genMom;
309 
310  if (genMom.isNonnull()) {
311  if (genMom->pdgId() != tp->pdgId()) {
312  simInfo[i].motherPdgId = genMom->pdgId();
313  simInfo[i].motherStatus = genMom->status();
314  simInfo[i].motherVertex = genMom->vertex();
315  } else {
316  // if mother has the same identity look backwards for the real
317  // mother (it may happen in radiative decays)
318  int jm = 0;
319  while (mMom->pdgId() == tp->pdgId()) {
320  jm++;
321  if (mMom->numberOfMothers() > 0) {
322  mMom = mMom->motherRef();
323  }
324  LogTrace("MuonSimClassifier") << "\t\t backtracking mother " << jm << ", pdgId = " << mMom->pdgId()
325  << ", status= " << mMom->status();
326  }
327  genMom = mMom; // redefine genMom
328  simInfo[i].motherPdgId = genMom->pdgId();
329  simInfo[i].motherStatus = genMom->status();
330  simInfo[i].motherVertex = genMom->vertex();
331  }
332  dumpFormatedInfo(simInfo[i]);
333  LogTrace("MuonSimClassifier") << "\t has GEN mother pdgId = " << simInfo[i].motherPdgId
334  << " (status = " << simInfo[i].motherStatus << ")";
335 
336  reco::GenParticleRef genGMom = genMom->numberOfMothers() > 0 ? genMom->motherRef() : reco::GenParticleRef();
337 
338  if (genGMom.isNonnull()) {
339  simInfo[i].grandMotherPdgId = genGMom->pdgId();
340  LogTrace("MuonSimClassifier")
341  << "\t\t mother prod. vertex rho = " << simInfo[i].motherVertex.Rho()
342  << ", z = " << simInfo[i].motherVertex.Z() << ", grand-mom pdgId = " << simInfo[i].grandMotherPdgId;
343  }
344  // in this case, we might want to know the heaviest mom flavour
345  for (reco::GenParticleRef nMom = genMom;
346  nMom.isNonnull() && std::abs(nMom->pdgId()) >= 100; // stop when we're no longer
347  // looking at hadrons or mesons
348  nMom = nMom->numberOfMothers() > 0 ? nMom->motherRef() : reco::GenParticleRef()) {
349  int flav = flavour(nMom->pdgId());
350  if (simInfo[i].heaviestMotherFlavour < flav)
351  simInfo[i].heaviestMotherFlavour = flav;
352  LogTrace("MuonSimClassifier")
353  << "\t\t backtracking flavour: mom pdgId = " << nMom->pdgId() << ", flavour = " << flav
354  << ", heaviest so far = " << simInfo[i].heaviestMotherFlavour;
355  }
356  } else { // mother is null ??
357  dumpFormatedInfo(simInfo[i]);
358  LogTrace("MuonSimClassifier") << "\t has NO mother!";
359  }
360  } else { // Muon is in SIM Only
361  TrackingParticleRef simMom = getTpMother(tp);
362  if (simMom.isNonnull()) {
363  simInfo[i].motherPdgId = simMom->pdgId();
364  simInfo[i].motherVertex = simMom->vertex();
365  dumpFormatedInfo(simInfo[i]);
366  LogTrace("MuonSimClassifier") << "\t has SIM mother pdgId = " << simInfo[i].motherPdgId
367  << " produced at rho = " << simMom->vertex().Rho()
368  << ", z = " << simMom->vertex().Z();
369 
370  if (!simMom->genParticles().empty()) {
371  simInfo[i].motherStatus = simMom->genParticles()[0]->status();
372  reco::GenParticleRef genGMom =
373  (simMom->genParticles()[0]->numberOfMothers() > 0 ? simMom->genParticles()[0]->motherRef()
375  if (genGMom.isNonnull())
376  simInfo[i].grandMotherPdgId = genGMom->pdgId();
377  LogTrace("MuonSimClassifier") << "\t\t SIM mother is in GEN (status " << simInfo[i].motherStatus
378  << "), grand-mom id = " << simInfo[i].grandMotherPdgId;
379  } else {
380  simInfo[i].motherStatus = -1;
381  TrackingParticleRef simGMom = getTpMother(simMom);
382  if (simGMom.isNonnull())
383  simInfo[i].grandMotherPdgId = simGMom->pdgId();
384  LogTrace("MuonSimClassifier")
385  << "\t\t SIM mother is in SIM only, grand-mom id = " << simInfo[i].grandMotherPdgId;
386  }
387  } else {
388  dumpFormatedInfo(simInfo[i]);
389  LogTrace("MuonSimClassifier") << "\t has NO mother!";
390  }
391  }
392  simInfo[i].motherFlavour = flavour(simInfo[i].motherPdgId);
393  simInfo[i].grandMotherFlavour = flavour(simInfo[i].grandMotherPdgId);
394 
395  // Check first IF this is a muon at all
396  if (std::abs(tp->pdgId()) != 13) {
397  if (std::abs(tp->pdgId()) == 11) {
398  simInfo[i].primaryClass = isGhost ? reco::MuonSimType::GhostElectron : reco::MuonSimType::MatchedElectron;
399  simInfo[i].extendedClass =
401  LogTrace("MuonSimClassifier") << "\t This is electron/positron. classif[i] = " << simInfo[i].primaryClass;
402  } else {
403  simInfo[i].primaryClass =
405  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::ExtGhostPunchthrough
407  LogTrace("MuonSimClassifier") << "\t This is not a muon. Sorry. classif[i] = " << simInfo[i].primaryClass;
408  }
409  continue;
410  }
411 
412  // Is this SIM muon also a GEN muon, with a mother?
413  if (!tp->genParticles().empty() && (simInfo[i].motherPdgId != 0)) {
414  if (std::abs(simInfo[i].motherPdgId) < 100 && (std::abs(simInfo[i].motherPdgId) != 15)) {
415  simInfo[i].primaryClass =
417  simInfo[i].flavour = 13;
418  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromGaugeOrHiggsBoson
420  LogTrace("MuonSimClassifier") << "\t This seems PRIMARY MUON ! classif[i] = " << simInfo[i].primaryClass;
421  } else if (simInfo[i].motherFlavour == 4 || simInfo[i].motherFlavour == 5 || simInfo[i].motherFlavour == 15) {
422  simInfo[i].primaryClass =
424  simInfo[i].flavour = simInfo[i].motherFlavour;
425  if (simInfo[i].motherFlavour == 15)
426  simInfo[i].extendedClass =
428  else if (simInfo[i].motherFlavour == 5)
429  simInfo[i].extendedClass =
431  else if (simInfo[i].heaviestMotherFlavour == 5)
432  simInfo[i].extendedClass =
434  else
435  simInfo[i].extendedClass =
437  LogTrace("MuonSimClassifier") << "\t This seems HEAVY FLAVOUR ! classif[i] = " << simInfo[i].primaryClass;
438  } else {
439  simInfo[i].primaryClass =
441  simInfo[i].flavour = simInfo[i].motherFlavour;
442  LogTrace("MuonSimClassifier") << "\t This seems LIGHT FLAVOUR ! classif[i] = " << simInfo[i].primaryClass;
443  }
444  } else {
445  simInfo[i].primaryClass =
447  simInfo[i].flavour = simInfo[i].motherFlavour;
448  LogTrace("MuonSimClassifier") << "\t This seems LIGHT FLAVOUR ! classif[i] = " << simInfo[i].primaryClass;
449  }
450 
451  // extended classification
452  // don't we override previous decisions?
453  if (simInfo[i].motherPdgId == 0)
454  // if it has no mom, it's not a primary particle so it won't be in ppMuX
455  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromNonPrimaryParticle
457  else if (std::abs(simInfo[i].motherPdgId) < 100) {
458  if (simInfo[i].motherFlavour == 15)
459  simInfo[i].extendedClass =
461  else
462  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromGaugeOrHiggsBoson
464  } else if (simInfo[i].motherFlavour == 5)
465  simInfo[i].extendedClass =
467  else if (simInfo[i].motherFlavour == 4) {
468  if (simInfo[i].heaviestMotherFlavour == 5)
469  simInfo[i].extendedClass =
471  else
472  simInfo[i].extendedClass =
474  } else if (simInfo[i].motherStatus != -1) { // primary light particle
475  int id = std::abs(simInfo[i].motherPdgId);
476  if (id != /*pi+*/ 211 && id != /*K+*/ 321 && id != 130 /*K0L*/)
477  // other light particle, possibly short-lived
478  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromOtherLight
480  else if (simInfo[i].vertex.Rho() < decayRho_ && std::abs(simInfo[i].vertex.Z()) < decayAbsZ_)
481  // decay a la ppMuX (primary pi/K within a cylinder)
482  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromPiKppMuX
484  else
485  // late decay that wouldn't be in ppMuX
486  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromPiKNotppMuX
488  } else
489  // decay of non-primary particle, would not be in ppMuX
490  simInfo[i].extendedClass = isGhost ? reco::ExtendedMuonSimType::GhostMuonFromNonPrimaryParticle
492 
493  if (linkToGenParticles_ && std::abs(simInfo[i].extendedClass) >= 2) {
494  // Link to the genParticle if possible, but not decays in flight (in
495  // ppMuX they're in GEN block, but they have wrong parameters)
496  if (!tp->genParticles().empty() && std::abs(simInfo[i].extendedClass) >= 5) {
497  if (genParticles.id() != tp->genParticles().id()) {
498  throw cms::Exception("Configuration")
499  << "Product ID mismatch between the genParticle collection (" << genParticles_ << ", id "
500  << genParticles.id() << ") and the references in the TrackingParticles (id " << tp->genParticles().id()
501  << ")\n";
502  }
503  muToPrimary[i] = tp->genParticles()[0].key();
504  } else {
505  // Don't put the same trackingParticle twice!
506  int &indexPlus1 = tpToSecondaries[tp]; // will create a 0 if the tp is
507  // not in the list already
508  if (indexPlus1 == 0)
509  indexPlus1 = convertAndPush(*tp, *secondaries, getTpMother(tp), genParticles) + 1;
510  muToSecondary[i] = indexPlus1 - 1;
511  }
512  }
513  LogTrace("MuonSimClassifier") << "\t Extended classification code = " << simInfo[i].extendedClass;
514  } else { // if (tp.isNonnull())
515  simInfo[i].primaryClass = reco::MuonSimType::NotMatched;
516  simInfo[i].extendedClass = reco::ExtendedMuonSimType::ExtNotMatched;
517  }
518  } // end loop on reco muons
519 
520  writeValueMap(iEvent, muons, simInfo, "");
521 
522  if (linkToGenParticles_) {
523  edm::OrphanHandle<reco::GenParticleCollection> secHandle = iEvent.put(std::move(secondaries), "secondaries");
524  edm::RefProd<reco::GenParticleCollection> priRP(genParticles);
526  std::unique_ptr<edm::Association<reco::GenParticleCollection>> outPri(
528  std::unique_ptr<edm::Association<reco::GenParticleCollection>> outSec(
530  edm::Association<reco::GenParticleCollection>::Filler fillPri(*outPri), fillSec(*outSec);
531  fillPri.insert(muons, muToPrimary.begin(), muToPrimary.end());
532  fillSec.insert(muons, muToSecondary.begin(), muToSecondary.end());
533  fillPri.fill();
534  fillSec.fill();
535  iEvent.put(std::move(outPri), "toPrimaries");
536  iEvent.put(std::move(outSec), "toSecondaries");
537  }
538 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
Definition: MuonTrackType.h:37
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
TrackingParticleRef getTpMother(TrackingParticleRef tp)
edm::EDGetTokenT< edm::View< reco::Muon > > muonsToken_
The RECO objects.
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::Muon >> &handle, const std::vector< T > &values, const std::string &label) const
Write a ValueMap<int> in the event.
reco::MuonTrackType trackType_
Track to use.
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
int flavour(int pdgId) const
Returns the flavour given a pdg id code.
int convertAndPush(const TrackingParticle &tp, reco::GenParticleCollection &out, const TrackingParticleRef &momRef, const edm::Handle< reco::GenParticleCollection > &genParticles) const
key_type key() const
Accessor for product key.
Definition: Ref.h:263
value_type at(size_type idx) const
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
Definition: MuonTrackType.h:38
edm::InputTag genParticles_
void associateMuons(MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &muons, MuonTrackType type, const edm::RefVector< TrackingParticleCollection > &tpColl) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
edm::EDGetTokenT< reco::MuonToTrackingParticleAssociator > muAssocToken_
#define LogTrace(id)
T const * product() const
Definition: Handle.h:74
edm::EDGetTokenT< TrackingParticleCollection > trackingParticlesToken_
The TrackingParticle objects.
void dumpFormatedInfo(const reco::MuonSimInfo &simInfo)
double decayRho_
Cylinder to use to decide if a decay is early or late.
void push_back(const RefToBase< T > &)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
bool linkToGenParticles_
Create a link to the generator level particles.
edm::Ref< TrackingParticleCollection > TrackingParticleRef
def move(src, dest)
Definition: eostools.py:511
template<typename T >
void MuonSimClassifier::writeValueMap ( edm::Event iEvent,
const edm::Handle< edm::View< reco::Muon >> &  handle,
const std::vector< T > &  values,
const std::string &  label 
) const
private

Write a ValueMap<int> in the event.

Definition at line 541 of file MuonSimClassifier.cc.

References edm::helper::Filler< Map >::fill(), objects.autophobj::filler, cmsBatch::handle, edm::helper::Filler< Map >::insert(), eostools::move(), and edm::Event::put().

Referenced by produce().

544  {
545  using namespace edm;
546  using namespace std;
547  unique_ptr<ValueMap<T>> valMap(new ValueMap<T>());
548  typename edm::ValueMap<T>::Filler filler(*valMap);
549  filler.insert(handle, values.begin(), values.end());
550  filler.fill();
551  iEvent.put(std::move(valMap), label);
552 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
char const * label
HLT enums.
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

edm::InputTag MuonSimClassifier::associatorLabel_
private

The Associations.

Definition at line 87 of file MuonSimClassifier.cc.

double MuonSimClassifier::decayAbsZ_
private

Definition at line 91 of file MuonSimClassifier.cc.

Referenced by produce().

double MuonSimClassifier::decayRho_
private

Cylinder to use to decide if a decay is early or late.

Definition at line 91 of file MuonSimClassifier.cc.

Referenced by produce().

edm::InputTag MuonSimClassifier::genParticles_
private

Definition at line 95 of file MuonSimClassifier.cc.

Referenced by convertAndPush(), MuonSimClassifier(), and produce().

edm::EDGetTokenT<reco::GenParticleCollection> MuonSimClassifier::genParticlesToken_
private

Definition at line 96 of file MuonSimClassifier.cc.

Referenced by MuonSimClassifier(), and produce().

bool MuonSimClassifier::linkToGenParticles_
private

Create a link to the generator level particles.

Definition at line 94 of file MuonSimClassifier.cc.

Referenced by MuonSimClassifier(), and produce().

edm::EDGetTokenT<reco::MuonToTrackingParticleAssociator> MuonSimClassifier::muAssocToken_
private

Definition at line 88 of file MuonSimClassifier.cc.

Referenced by produce().

edm::EDGetTokenT<edm::View<reco::Muon> > MuonSimClassifier::muonsToken_
private

The RECO objects.

Definition at line 78 of file MuonSimClassifier.cc.

Referenced by produce().

edm::EDGetTokenT<TrackingParticleCollection> MuonSimClassifier::trackingParticlesToken_
private

The TrackingParticle objects.

Definition at line 84 of file MuonSimClassifier.cc.

Referenced by produce().

reco::MuonTrackType MuonSimClassifier::trackType_
private

Track to use.

Definition at line 81 of file MuonSimClassifier.cc.

Referenced by MuonSimClassifier(), and produce().