CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
MuonMCClassifier Class Reference

#include <MuonAnalysis/MuonAssociators/src/MuonMCClassifier.cc>

Inheritance diagram for MuonMCClassifier:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MuonMCClassifier (const edm::ParameterSet &)
 
 ~MuonMCClassifier ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

int convertAndPush (const TrackingParticle &tp, reco::GenParticleCollection &out, const TrackingParticleRef &momRef, const edm::Handle< reco::GenParticleCollection > &genParticles, const edm::Handle< std::vector< int > > &genBarcodes) const
 
int fetch (const edm::Handle< std::vector< int > > &genBarcodes, int barcode) const
 Find the index of a genParticle given it's barcode. -1 if not found. More...
 
int flavour (int pdgId) const
 Returns the flavour given a pdg id code. More...
 
const HepMC::GenParticle * getGpMother (const HepMC::GenParticle *gp)
 
TrackingParticleRef getTpMother (TrackingParticleRef tp)
 
virtual 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

std::string associatorLabel_
 The Associations. More...
 
double decayAbsZ_
 
double decayRho_
 Cylinder to use to decide if a decay is early or late. More...
 
edm::InputTag genParticles_
 
bool hasMuonCut_
 
bool linkToGenParticles_
 Create a link to the generator level particles. More...
 
StringCutObjectSelector
< pat::Muon
muonCut_
 
edm::InputTag muons_
 The RECO objects. More...
 
edm::InputTag trackingParticles_
 The TrackingParticle objects. More...
 
MuonAssociatorByHits::MuonTrackType trackType_
 Track to use. More...
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

CLASSIFICATION: For each RECO Muon, match to SIM particle, and then:

In any case, if the TP is not preferentially matched back to the same RECO muon, label as Ghost (flip the classification)

FLAVOUR:

Definition at line 70 of file MuonMCClassifier.cc.

Constructor & Destructor Documentation

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

Definition at line 142 of file MuonMCClassifier.cc.

References edm::hlt::Exception, edm::ParameterSet::getParameter(), MuonAssociatorByHits::GlobalTk, MuonAssociatorByHits::InnerTk, linkToGenParticles_, MuonAssociatorByHits::OuterTk, MuonAssociatorByHits::Segments, AlCaHLTBitMon_QueryRunRegistry::string, and trackType_.

142  :
143  muons_(iConfig.getParameter<edm::InputTag>("muons")),
144  hasMuonCut_(iConfig.existsAs<std::string>("muonPreselection")),
145  muonCut_(hasMuonCut_ ? iConfig.getParameter<std::string>("muonPreselection") : ""),
146  trackingParticles_(iConfig.getParameter<edm::InputTag>("trackingParticles")),
147  associatorLabel_(iConfig.getParameter< std::string >("associatorLabel")),
148  decayRho_(iConfig.getParameter<double>("decayRho")),
149  decayAbsZ_(iConfig.getParameter<double>("decayAbsZ")),
150  linkToGenParticles_(iConfig.getParameter<bool>("linkToGenParticles")),
151  genParticles_(linkToGenParticles_ ? iConfig.getParameter<edm::InputTag>("genParticles") : edm::InputTag("NONE"))
152 {
153  std::string trackType = iConfig.getParameter< std::string >("trackType");
154  if (trackType == "inner") trackType_ = MuonAssociatorByHits::InnerTk;
155  else if (trackType == "outer") trackType_ = MuonAssociatorByHits::OuterTk;
156  else if (trackType == "global") trackType_ = MuonAssociatorByHits::GlobalTk;
157  else if (trackType == "segments") trackType_ = MuonAssociatorByHits::Segments;
158  else throw cms::Exception("Configuration") << "Track type '" << trackType << "' not supported.\n";
159 
160  produces<edm::ValueMap<int> >();
161  produces<edm::ValueMap<int> >("ext");
162  produces<edm::ValueMap<int> >("flav");
163  produces<edm::ValueMap<int> >("hitsPdgId");
164  produces<edm::ValueMap<int> >("momPdgId");
165  produces<edm::ValueMap<int> >("momFlav");
166  produces<edm::ValueMap<int> >("momStatus");
167  produces<edm::ValueMap<int> >("gmomPdgId");
168  produces<edm::ValueMap<int> >("gmomFlav");
169  produces<edm::ValueMap<int> >("hmomFlav"); // heaviest mother flavour
170  produces<edm::ValueMap<int> >("tpId");
171  produces<edm::ValueMap<float> >("prodRho");
172  produces<edm::ValueMap<float> >("prodZ");
173  produces<edm::ValueMap<float> >("momRho");
174  produces<edm::ValueMap<float> >("momZ");
175  produces<edm::ValueMap<float> >("tpAssoQuality");
176  if (linkToGenParticles_) {
177  produces<reco::GenParticleCollection>("secondaries");
178  produces<edm::Association<reco::GenParticleCollection> >("toPrimaries");
179  produces<edm::Association<reco::GenParticleCollection> >("toSecondaries");
180  }
181 }
edm::InputTag genParticles_
bool linkToGenParticles_
Create a link to the generator level particles.
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:187
edm::InputTag trackingParticles_
The TrackingParticle objects.
std::string associatorLabel_
The Associations.
MuonAssociatorByHits::MuonTrackType trackType_
Track to use.
double decayRho_
Cylinder to use to decide if a decay is early or late.
edm::InputTag muons_
The RECO objects.
StringCutObjectSelector< pat::Muon > muonCut_
MuonMCClassifier::~MuonMCClassifier ( )

Definition at line 183 of file MuonMCClassifier.cc.

184 {
185 }

Member Function Documentation

int MuonMCClassifier::convertAndPush ( const TrackingParticle tp,
reco::GenParticleCollection out,
const TrackingParticleRef momRef,
const edm::Handle< reco::GenParticleCollection > &  genParticles,
const edm::Handle< std::vector< int > > &  genBarcodes 
) 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 507 of file MuonMCClassifier.cc.

References TrackingParticle::charge(), fetch(), edm::Ref< C, T, F >::isNonnull(), TrackingParticle::p4(), TrackingParticle::pdgId(), TrackingParticle::status(), and TrackingParticle::vertex().

Referenced by produce().

511  {
512  out.push_back(reco::GenParticle(tp.charge(), tp.p4(), tp.vertex(), tp.pdgId(), tp.status(), true));
513  if (simMom.isNonnull() && !simMom->genParticles().empty()) {
514 #warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
515 #ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
516  int momIdx = fetch(genBarcodes, simMom->genParticle()[0]->barcode());
517  if (momIdx != -1) out.back().addMother(reco::GenParticleRef(genParticles, momIdx));
518 #endif
519  }
520  return out.size()-1;
521 }
int pdgId() const
PDG ID.
Point vertex() const
Parent vertex position.
int status() const
Status word.
int fetch(const edm::Handle< std::vector< int > > &genBarcodes, int barcode) const
Find the index of a genParticle given it&#39;s barcode. -1 if not found.
tuple out
Definition: dbtoconf.py:99
const LorentzVector & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
int charge() const
Electric charge. Note this is taken from the first SimTrack only.
int MuonMCClassifier::fetch ( const edm::Handle< std::vector< int > > &  genBarcodes,
int  barcode 
) const
private

Find the index of a genParticle given it's barcode. -1 if not found.

Definition at line 499 of file MuonMCClassifier.cc.

References spr::find().

Referenced by convertAndPush(), and produce().

500 {
501  std::vector<int>::const_iterator it = std::find(genBarcodes->begin(), genBarcodes->end(), barcode);
502  return (it == genBarcodes->end()) ? -1 : (it - genBarcodes->begin());
503 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int MuonMCClassifier::flavour ( int  pdgId) const
private

Returns the flavour given a pdg id code.

Definition at line 485 of file MuonMCClassifier.cc.

References abs.

Referenced by cuy.graphElement::__init__(), and produce().

485  {
486  int flav = abs(pdgId);
487  // for quarks, leptons and bosons except gluons, take their pdgId
488  // muons and taus have themselves as flavour
489  if (flav <= 37 && flav != 21) return flav;
490  // look for barions
491  int bflav = ((flav / 1000) % 10);
492  if (bflav != 0) return bflav;
493  // look for mesons
494  int mflav = ((flav / 100) % 10);
495  if (mflav != 0) return mflav;
496  return 0;
497 }
#define abs(x)
Definition: mlp_lapack.h:159
const HepMC::GenParticle* MuonMCClassifier::getGpMother ( const HepMC::GenParticle *  gp)
inlineprivate

Definition at line 119 of file MuonMCClassifier.cc.

Referenced by produce().

119  {
120  if (gp != 0) {
121  const HepMC::GenVertex *vtx = gp->production_vertex();
122  if (vtx != 0 && vtx->particles_in_size() > 0) {
123  return *vtx->particles_in_const_begin();
124  }
125  }
126  return 0;
127  }
TrackingParticleRef MuonMCClassifier::getTpMother ( TrackingParticleRef  tp)
inlineprivate

Definition at line 111 of file MuonMCClassifier.cc.

References edm::Ref< C, T, F >::isNonnull().

Referenced by produce().

111  {
112  if (tp.isNonnull() && tp->parentVertex().isNonnull() && !tp->parentVertex()->sourceTracks().empty()) {
113  return tp->parentVertex()->sourceTracks()[0];
114  } else {
115  return TrackingParticleRef();
116  }
117  }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
edm::Ref< TrackingParticleCollection > TrackingParticleRef
void MuonMCClassifier::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 188 of file MuonMCClassifier.cc.

References abs, MuonAssociatorByHits::associateMuons(), associatorLabel_, edm::RefToBaseVector< T >::begin(), convertAndPush(), decayAbsZ_, decayRho_, edm::RefToBaseVector< T >::end(), edm::hlt::Exception, fetch(), edm::helper::Filler< Map >::fill(), spr::find(), flavour(), configurableAnalysis::GenParticle, genParticleCandidates2GenParticles_cfi::genParticles, genParticles_, edm::EventSetup::get(), edm::Ref< C, T, F >::get(), edm::Event::getByLabel(), getGpMother(), getTpMother(), MuonAssociatorByHits::GlobalTk, hasMuonCut_, i, edm::helper::Filler< Map >::insert(), reco::Muon::isGlobalMuon(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::key(), linkToGenParticles_, match(), RPCpg::mu, muonCut_, patZpeak::muons, muons_, n, NULL, MuonAssociatorByHits::OuterTk, edm::ESHandle< class >::product(), edm::RefToBaseVector< T >::push_back(), edm::RefVector< C, T, F >::push_back(), edm::Event::put(), trackingTruthProducerFastSim_cfi::trackingParticles, trackingParticles_, trackType_, and writeValueMap().

189 {
190  edm::LogVerbatim("MuonMCClassifier") <<"\n sono in MuonMCClassifier !";
191 
193  iEvent.getByLabel(muons_, muons);
194 
196  iEvent.getByLabel(trackingParticles_, trackingParticles);
197 
199  edm::Handle<std::vector<int> > genBarcodes;
200  if (linkToGenParticles_) {
201  iEvent.getByLabel(genParticles_, genParticles);
202  iEvent.getByLabel(genParticles_, genBarcodes);
203  }
204 
205  edm::ESHandle<TrackAssociatorBase> associatorBase;
206  iSetup.get<TrackAssociatorRecord>().get(associatorLabel_, associatorBase);
207  const MuonAssociatorByHits * assoByHits = dynamic_cast<const MuonAssociatorByHits *>(associatorBase.product());
208  if (assoByHits == 0) throw cms::Exception("Configuration") << "The Track Associator with label '" << associatorLabel_ << "' is not a MuonAssociatorByHits.\n";
209 
212  edm::LogVerbatim("MuonMCClassifier") <<"\n ***************************************************************** ";
213  edm::LogVerbatim("MuonMCClassifier") << " RECO MUON association, type: "<< trackType_;
214  edm::LogVerbatim("MuonMCClassifier") << " ***************************************************************** \n";
215 
217  if (!hasMuonCut_) {
218  // all muons
219  selMuons = muons->refVector();
220  } else {
221  // filter, fill refvectors, associate
222  // I pass through pat::Muon so that I can access muon id selectors
223  for (size_t i = 0, n = muons->size(); i < n; ++i) {
224  edm::RefToBase<reco::Muon> rmu = muons->refAt(i);
225  if (muonCut_(pat::Muon(rmu))) selMuons.push_back(rmu);
226  }
227  }
228 
230  for (size_t i = 0, n = trackingParticles->size(); i < n; ++i) {
231  allTPs.push_back(TrackingParticleRef(trackingParticles,i));
232  }
233 
234  assoByHits->associateMuons(recSimColl, simRecColl, selMuons, trackType_, allTPs, &iEvent, &iSetup);
235 
236  // for global muons without hits on muon detectors, look at the linked standalone muon
240  edm::LogVerbatim("MuonMCClassifier") <<"\n ***************************************************************** ";
241  edm::LogVerbatim("MuonMCClassifier") << " STANDALONE (UpdAtVtx) MUON association ";
242  edm::LogVerbatim("MuonMCClassifier") << " ***************************************************************** \n";
243  assoByHits->associateMuons(UpdSTA_recSimColl, UpdSTA_simRecColl, selMuons, MuonAssociatorByHits::OuterTk,
244  allTPs, &iEvent, &iSetup);
245  }
246 
247  typedef MuonAssociatorByHits::MuonToSimCollection::const_iterator r2s_it;
248  typedef MuonAssociatorByHits::SimToMuonCollection::const_iterator s2r_it;
249 
250  size_t nmu = muons->size();
251  edm::LogVerbatim("MuonMCClassifier") <<"\n There are "<<nmu<<" reco::Muons.";
252 
253  std::vector<int> classif(nmu, 0), ext(nmu, 0);
254  std::vector<int> hitsPdgId(nmu, 0), momPdgId(nmu, 0), gmomPdgId(nmu, 0), momStatus(nmu, 0);
255  std::vector<int> flav(nmu, 0), momFlav(nmu, 0), gmomFlav(nmu, 0), hmomFlav(nmu, 0);
256  std::vector<int> tpId(nmu, -1);
257  std::vector<float> prodRho(nmu, 0.0), prodZ(nmu, 0.0), momRho(nmu, 0.0), momZ(nmu, 0.0);
258  std::vector<float> tpAssoQuality(nmu, -1);
259 
260  std::auto_ptr<reco::GenParticleCollection> secondaries; // output collection of secondary muons
261  std::map<TrackingParticleRef, int> tpToSecondaries; // map from tp to (index+1) in output collection
262  std::vector<int> muToPrimary(nmu, -1), muToSecondary(nmu, -1); // map from input into (index) in output, -1 for null
263  if (linkToGenParticles_) secondaries.reset(new reco::GenParticleCollection());
264 
265  for(size_t i = 0; i < nmu; ++i) {
266  edm::LogVerbatim("MuonMCClassifier") <<"\n reco::Muons # "<<i;
267  edm::RefToBase<reco::Muon> mu = muons->refAt(i);
268  if (hasMuonCut_ && (std::find(selMuons.begin(), selMuons.end(), mu) == selMuons.end()) ) {
269  edm::LogVerbatim("MuonMCClassifier") <<"\t muon didn't pass the selection. classified as -99 and skipped";
270  classif[i] = -99; continue;
271  }
272 
274  edm::RefToBase<reco::Muon> muMatchBack;
275  r2s_it match = recSimColl.find(mu);
276  s2r_it matchback;
277  if (match != recSimColl.end()) {
278  edm::LogVerbatim("MuonMCClassifier") <<"\t RtS matched Ok...";
279  // match->second is vector, front is first element, first is the ref (second would be the quality)
280  tp = match->second.front().first;
281  tpId[i] = tp.isNonnull() ? tp.key() : -1; // we check, even if null refs should not appear here at all
282  tpAssoQuality[i] = match->second.front().second;
283  s2r_it matchback = simRecColl.find(tp);
284  if (matchback != simRecColl.end()) {
285  muMatchBack = matchback->second.front().first;
286  } else {
287  edm::LogWarning("MuonMCClassifier") << "\n***WARNING: This I do NOT understand: why no match back? *** \n";
288  }
289  } else if ((trackType_ == MuonAssociatorByHits::GlobalTk) &&
290  mu->isGlobalMuon()) {
291  // perform a second attempt, matching with the standalone muon
292  r2s_it matchSta = UpdSTA_recSimColl.find(mu);
293  if (matchSta != UpdSTA_recSimColl.end()) {
294  edm::LogVerbatim("MuonMCClassifier") <<"\t RtS matched Ok... from the UpdSTA_recSimColl ";
295  tp = matchSta->second.front().first;
296  tpId[i] = tp.isNonnull() ? tp.key() : -1; // we check, even if null refs should not appear here at all
297  tpAssoQuality[i] = matchSta->second.front().second;
298  s2r_it matchback = UpdSTA_simRecColl.find(tp);
299  if (matchback != UpdSTA_simRecColl.end()) {
300  muMatchBack = matchback->second.front().first;
301  } else {
302  edm::LogWarning("MuonMCClassifier") << "\n***WARNING: This I do NOT understand: why no match back in UpdSTA? *** \n";
303  }
304  }
305  }
306  if (tp.isNonnull()) {
307  bool isGhost = muMatchBack != mu;
308  if (isGhost) edm::LogVerbatim("MuonMCClassifier") <<"\t This seems a GHOST ! classif[i] will be < 0";
309 
310  hitsPdgId[i] = tp->pdgId();
311  prodRho[i] = tp->vertex().Rho();
312  prodZ[i] = tp->vertex().Z();
313  edm::LogVerbatim("MuonMCClassifier") <<"\t TP pdgId = "<<hitsPdgId[i] << ", vertex rho = " << prodRho[i] << ", z = " << prodZ[i];
314 
315  // Try to extract mother and grand mother of this muon.
316  // Unfortunately, SIM and GEN histories require diffent code :-(
317  if (!tp->genParticles().empty()) { // Muon is in GEN
318 #warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
319 #ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
320  const HepMC::GenParticle * genMom = getGpMother(tp->genParticle()[0].get());
321 #else
322  const HepMC::GenParticle * genMom = NULL;
323 #endif
324  if (genMom) {
325  momPdgId[i] = tp->pdgId();
326  momStatus[i] = tp->status();
327  if (genMom->production_vertex()) {
328  const HepMC::ThreeVector & momVtx = genMom->production_vertex()->point3d();
329  momRho[i] = momVtx.perp() * 0.1; momZ[i] = momVtx.z() * 0.1; // HepMC is in mm!
330  }
331  edm::LogVerbatim("MuonMCClassifier") << "\t Particle pdgId = "<<hitsPdgId[i] << " produced at rho = " << prodRho[i] << ", z = " << prodZ[i] << ", has GEN mother pdgId = " << momPdgId[i];
332  const HepMC::GenParticle * genGMom = getGpMother(genMom);
333  if (genGMom) {
334  gmomPdgId[i] = genGMom->pdg_id();
335  edm::LogVerbatim("MuonMCClassifier") << "\t\t mother prod. vertex rho = " << momRho[i] << ", z = " << momZ[i] << ", grand-mom pdgId = " << gmomPdgId[i];
336  }
337  // in this case, we might want to know the heaviest mom flavour
338  for (const HepMC::GenParticle *nMom = genMom;
339  nMom != 0 && abs(nMom->pdg_id()) >= 100; // stop when we're no longer looking at hadrons or mesons
340  nMom = getGpMother(nMom)) {
341  int flav = flavour(nMom->pdg_id());
342  if (hmomFlav[i] < flav) hmomFlav[i] = flav;
343  edm::LogVerbatim("MuonMCClassifier") << "\t\t backtracking flavour: mom pdgId = "<<nMom->pdg_id()<< ", flavour = " << flav << ", heaviest so far = " << hmomFlav[i];
344  }
345  }
346  } else { // Muon is in SIM Only
347  TrackingParticleRef simMom = getTpMother(tp);
348  if (simMom.isNonnull()) {
349  momPdgId[i] = simMom->pdgId();
350  momRho[i] = simMom->vertex().Rho();
351  momZ[i] = simMom->vertex().Z();
352  edm::LogVerbatim("MuonMCClassifier") << "\t Particle pdgId = "<<hitsPdgId[i] << " produced at rho = " << prodRho[i] << ", z = " << prodZ[i] <<
353  ", has SIM mother pdgId = " << momPdgId[i] << " produced at rho = " << simMom->vertex().Rho() << ", z = " << simMom->vertex().Z();
354  if (!simMom->genParticles().empty()) {
355  momStatus[i] = simMom->genParticles()[0]->status();
356 #warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
357  gmomPdgId[i] = simMom->pdgId();
358  edm::LogVerbatim("MuonMCClassifier") << "\t\t SIM mother is in GEN (status " << momStatus[i] << "), grand-mom id = " << gmomPdgId[i];
359  } else {
360  momStatus[i] = -1;
361  TrackingParticleRef simGMom = getTpMother(simMom);
362  if (simGMom.isNonnull()) gmomPdgId[i] = simGMom->pdgId();
363  edm::LogVerbatim("MuonMCClassifier") << "\t\t SIM mother is in SIM only, grand-mom id = " << gmomPdgId[i];
364  }
365  } else {
366  edm::LogVerbatim("MuonMCClassifier") << "\t Particle pdgId = "<<hitsPdgId[i] << " produced at rho = " << prodRho[i] << ", z = " << prodZ[i] << ", has NO mother!";
367  }
368  }
369  momFlav[i] = flavour(momPdgId[i]);
370  gmomFlav[i] = flavour(gmomPdgId[i]);
371 
372  // Check first IF this is a muon at all
373  if (abs(tp->pdgId()) != 13) {
374  classif[i] = isGhost ? -1 : 1;
375  ext[i] = isGhost ? -1 : 1;
376  edm::LogVerbatim("MuonMCClassifier") <<"\t This is not a muon. Sorry. classif[i] = " << classif[i];
377  continue;
378  }
379 
380  // Is this SIM muon also a GEN muon, with a mother?
381  if (!tp->genParticles().empty() && (momPdgId[i] != 0)) {
382  if (abs(momPdgId[i]) < 100 && (abs(momPdgId[i]) != 15)) {
383  classif[i] = isGhost ? -4 : 4;
384  flav[i] = (abs(momPdgId[i]) == 15 ? 15 : 13);
385  edm::LogVerbatim("MuonMCClassifier") <<"\t This seems PRIMARY MUON ! classif[i] = " << classif[i];
386  ext[i] = 10;
387  } else if (momFlav[i] == 4 || momFlav[i] == 5 || momFlav[i] == 15) {
388  classif[i] = isGhost ? -3 : 3;
389  flav[i] = momFlav[i];
390  if (momFlav[i] == 15) ext[i] = 9; // tau->mu
391  else if (momFlav[i] == 5) ext[i] = 8; // b->mu
392  else if (hmomFlav[i] == 5) ext[i] = 7; // b->c->mu
393  else ext[i] = 6; // c->mu
394  edm::LogVerbatim("MuonMCClassifier") <<"\t This seems HEAVY FLAVOUR ! classif[i] = " << classif[i];
395  } else {
396  classif[i] = isGhost ? -2 : 2;
397  flav[i] = momFlav[i];
398  edm::LogVerbatim("MuonMCClassifier") <<"\t This seems LIGHT FLAVOUR ! classif[i] = " << classif[i];
399  }
400  } else {
401  classif[i] = isGhost ? -2 : 2;
402  flav[i] = momFlav[i];
403  edm::LogVerbatim("MuonMCClassifier") <<"\t This seems LIGHT FLAVOUR ! classif[i] = " << classif[i];
404  }
405  // extended classification
406  if (momPdgId[i] == 0) ext[i] = 2; // if it has no mom, it's not a primary particle so it won't be in ppMuX
407  else if (abs(momPdgId[i]) < 100) ext[i] = (momFlav[i] == 15 ? 9 : 10); // primary mu, or tau->mu
408  else if (momFlav[i] == 5) ext[i] = 8; // b->mu
409  else if (momFlav[i] == 4) ext[i] = (hmomFlav[i] == 5 ? 7 : 6); // b->c->mu and c->mu
410  else if (momStatus[i] != -1) { // primary light particle
411  int id = abs(momPdgId[i]);
412  if (id != /*pi+*/211 && id != /*K+*/321 && id != 130 /*K0L*/) ext[i] = 5; // other light particle, possibly short-lived
413  else if (prodRho[i] < decayRho_ && abs(prodZ[i]) < decayAbsZ_) ext[i] = 4; // decay a la ppMuX (primary pi/K within a cylinder)
414  else ext[i] = 3; // late decay that wouldn't be in ppMuX
415  } else ext[i] = 2; // decay of non-primary particle, would not be in ppMuX
416  if (isGhost) ext[i] = -ext[i];
417 
418  if (linkToGenParticles_ && abs(ext[i]) >= 2) {
419  // Link to the genParticle if possible, but not decays in flight (in ppMuX they're in GEN block, but they have wrong parameters)
420  if (!tp->genParticles().empty() && abs(ext[i]) >= 5) {
421 #warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
422 #ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
423  muToPrimary[i] = fetch(genBarcodes, tp->genParticle()[0]->barcode());
424 #endif
425  } else {
426  // Don't put the same trackingParticle twice!
427  int &indexPlus1 = tpToSecondaries[tp]; // will create a 0 if the tp is not in the list already
428  if (indexPlus1 == 0) indexPlus1 = convertAndPush(*tp, *secondaries, getTpMother(tp), genParticles, genBarcodes) + 1;
429  muToSecondary[i] = indexPlus1 - 1;
430  }
431  }
432  edm::LogVerbatim("MuonMCClassifier") <<"\t Extended classification code = " << ext[i];
433  }
434  }
435 
436  writeValueMap(iEvent, muons, classif, "");
437  writeValueMap(iEvent, muons, ext, "ext");
438  writeValueMap(iEvent, muons, flav, "flav");
439  writeValueMap(iEvent, muons, tpId, "tpId");
440  writeValueMap(iEvent, muons, hitsPdgId, "hitsPdgId");
441  writeValueMap(iEvent, muons, momPdgId, "momPdgId");
442  writeValueMap(iEvent, muons, momStatus, "momStatus");
443  writeValueMap(iEvent, muons, momFlav, "momFlav");
444  writeValueMap(iEvent, muons, gmomPdgId, "gmomPdgId");
445  writeValueMap(iEvent, muons, gmomFlav, "gmomFlav");
446  writeValueMap(iEvent, muons, hmomFlav, "hmomFlav");
447  writeValueMap(iEvent, muons, prodRho, "prodRho");
448  writeValueMap(iEvent, muons, prodZ, "prodZ");
449  writeValueMap(iEvent, muons, momRho, "momRho");
450  writeValueMap(iEvent, muons, momZ, "momZ");
451  writeValueMap(iEvent, muons, tpAssoQuality, "tpAssoQuality");
452 
453  if (linkToGenParticles_) {
454  edm::OrphanHandle<reco::GenParticleCollection> secHandle = iEvent.put(secondaries, "secondaries");
455  edm::RefProd<reco::GenParticleCollection> priRP(genParticles);
457  std::auto_ptr<edm::Association<reco::GenParticleCollection> > outPri(new edm::Association<reco::GenParticleCollection>(priRP));
458  std::auto_ptr<edm::Association<reco::GenParticleCollection> > outSec(new edm::Association<reco::GenParticleCollection>(secRP));
459  edm::Association<reco::GenParticleCollection>::Filler fillPri(*outPri), fillSec(*outSec);
460  fillPri.insert(muons, muToPrimary.begin(), muToPrimary.end());
461  fillSec.insert(muons, muToSecondary.begin(), muToSecondary.end());
462  fillPri.fill(); fillSec.fill();
463  iEvent.put(outPri, "toPrimaries");
464  iEvent.put(outSec, "toSecondaries");
465  }
466 }
edm::InputTag genParticles_
bool linkToGenParticles_
Create a link to the generator level particles.
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
int i
Definition: DBlmapReader.cc:9
void associateMuons(MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &, MuonTrackType, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
const_iterator end() const
#define abs(x)
Definition: mlp_lapack.h:159
bool isGlobalMuon() const
Definition: Muon.h:219
#define NULL
Definition: scimark2.h:8
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
edm::InputTag trackingParticles_
The TrackingParticle objects.
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
int fetch(const edm::Handle< std::vector< int > > &genBarcodes, int barcode) const
Find the index of a genParticle given it&#39;s barcode. -1 if not found.
int convertAndPush(const TrackingParticle &tp, reco::GenParticleCollection &out, const TrackingParticleRef &momRef, const edm::Handle< reco::GenParticleCollection > &genParticles, const edm::Handle< std::vector< int > > &genBarcodes) const
TrackingParticleRef getTpMother(TrackingParticleRef tp)
const int mu
Definition: Constants.h:23
std::string associatorLabel_
The Associations.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
MuonAssociatorByHits::MuonTrackType trackType_
Track to use.
const T & get() const
Definition: EventSetup.h:55
key_type key() const
Accessor for product key.
Definition: Ref.h:266
T const * product() const
Definition: ESHandle.h:62
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&lt;int&gt; in the event.
const_iterator begin() const
double decayRho_
Cylinder to use to decide if a decay is early or late.
tuple muons
Definition: patZpeak.py:38
void push_back(const RefToBase< T > &)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
edm::InputTag muons_
The RECO objects.
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
int flavour(int pdgId) const
Returns the flavour given a pdg id code.
Analysis-level muon class.
Definition: Muon.h:51
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
edm::Ref< TrackingParticleCollection > TrackingParticleRef
const HepMC::GenParticle * getGpMother(const HepMC::GenParticle *gp)
StringCutObjectSelector< pat::Muon > muonCut_
template<typename T >
void MuonMCClassifier::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 470 of file MuonMCClassifier.cc.

References edm::helper::Filler< Map >::fill(), patZpeak::handle, edm::helper::Filler< Map >::insert(), and edm::Event::put().

Referenced by produce().

474 {
475  using namespace edm;
476  using namespace std;
477  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
478  typename edm::ValueMap<T>::Filler filler(*valMap);
479  filler.insert(handle, values.begin(), values.end());
480  filler.fill();
481  iEvent.put(valMap, label);
482 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94

Member Data Documentation

std::string MuonMCClassifier::associatorLabel_
private

The Associations.

Definition at line 92 of file MuonMCClassifier.cc.

Referenced by produce().

double MuonMCClassifier::decayAbsZ_
private

Definition at line 95 of file MuonMCClassifier.cc.

Referenced by produce().

double MuonMCClassifier::decayRho_
private

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

Definition at line 95 of file MuonMCClassifier.cc.

Referenced by produce().

edm::InputTag MuonMCClassifier::genParticles_
private

Definition at line 99 of file MuonMCClassifier.cc.

Referenced by produce().

bool MuonMCClassifier::hasMuonCut_
private

A preselection cut for the muon. I pass through pat::Muon so that I can access muon id selectors

Definition at line 82 of file MuonMCClassifier.cc.

Referenced by produce().

bool MuonMCClassifier::linkToGenParticles_
private

Create a link to the generator level particles.

Definition at line 98 of file MuonMCClassifier.cc.

Referenced by MuonMCClassifier(), and produce().

StringCutObjectSelector<pat::Muon> MuonMCClassifier::muonCut_
private

Definition at line 83 of file MuonMCClassifier.cc.

Referenced by produce().

edm::InputTag MuonMCClassifier::muons_
private

The RECO objects.

Definition at line 78 of file MuonMCClassifier.cc.

Referenced by produce().

edm::InputTag MuonMCClassifier::trackingParticles_
private

The TrackingParticle objects.

Definition at line 89 of file MuonMCClassifier.cc.

Referenced by produce().

MuonAssociatorByHits::MuonTrackType MuonMCClassifier::trackType_
private

Track to use.

Definition at line 86 of file MuonMCClassifier.cc.

Referenced by MuonMCClassifier(), and produce().