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 Attributes
DimuonMCMatcher Class Reference
Inheritance diagram for DimuonMCMatcher:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 DimuonMCMatcher (const edm::ParameterSet &cfg)
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
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 ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

edm::EDGetTokenT
< reco::CandidateView
srcToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- 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::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

Definition at line 7 of file DimuonMCMatcher.cc.

Constructor & Destructor Documentation

DimuonMCMatcher::DimuonMCMatcher ( const edm::ParameterSet cfg)

Definition at line 26 of file DimuonMCMatcher.cc.

26  :
27  srcToken_(consumes<CandidateView>(cfg.getParameter<InputTag>("src"))) {
28  produces<vector<GenParticleRef> >();
29 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::CandidateView > srcToken_

Member Function Documentation

void DimuonMCMatcher::produce ( edm::Event evt,
const edm::EventSetup  
)
overridevirtual

Implements edm::EDProducer.

Definition at line 31 of file DimuonMCMatcher.cc.

References alignmentValidation::c1, edm::hlt::Exception, pat::PATObject< ObjectType >::genParticleRef(), edm::RefToBase< T >::get(), edm::Event::getByToken(), i, edm::errors::InvalidReference, edm::Ref< C, T, F >::isNonnull(), j, gen::k, reco::Candidate::masterClone(), edm::Event::put(), alcazmumu_cfi::src, and srcToken_.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

31  {
33  evt.getByToken(srcToken_, src);
34  auto_ptr<vector<GenParticleRef> > matched(new vector<GenParticleRef>);
35  matched->reserve(src->size());
36  int j=0;
37  for(CandidateView::const_iterator i = src->begin(); i != src->end(); ++i) {
38  j++;
39  const Candidate * dau1 = i->daughter(0);
40  const Candidate * dau2 = i->daughter(1);
41  if(dau1 == 0|| dau2 == 0)
43  "one of the two daughter does not exist\n";
44  const Candidate * c1 = dau1->masterClone().get();
45  GenParticleRef mc1;
46  const pat::Muon * mu1 = dynamic_cast<const pat::Muon*>(c1);
47  if(mu1 != 0) {
48  mc1 = mu1->genParticleRef();
49  // if (mc1.isNonnull()) cout << "DimuonMCMatcher> genParticleRef1 " << mc1->pdgId() << endl;
50  } else {
51  const pat::GenericParticle * gp1 = dynamic_cast<const pat::GenericParticle*>(c1);
52  if(gp1 == 0)
54  "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
55  mc1 = gp1->genParticleRef();
56  }
57  const Candidate * c2 = dau2->masterClone().get();
58  GenParticleRef mc2;
59  const pat::Muon * mu2 = dynamic_cast<const pat::Muon*>(c2);
60  if(mu2 != 0) {
61  mc2 = mu2->genParticleRef();
62  // if (mc2.isNonnull()) cout << "DimuonMCMatcher> genParticleRef2 " << mc2->pdgId() << endl;
63  } else {
64  const pat::GenericParticle * gp2 = dynamic_cast<const pat::GenericParticle*>(c2);
65  if(gp2 == 0)
67  "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
68  mc2 = gp2->genParticleRef();
69  }
70  GenParticleRef dimuonMatch;
71  // cout << "DimuonMatcher> mc1 " << mc1.isNonnull() << " mc2 " << mc2.isNonnull() << endl;
72  if(mc1.isNonnull() && mc2.isNonnull()) {
73  int k=0;
74  do {
75  k++;
76  mc1 = mc1->numberOfMothers() > 0 ? mc1->motherRef() : GenParticleRef();
77  mc2 = mc2->numberOfMothers() > 0 ? mc2->motherRef() : GenParticleRef();
78  // cout << "DimuonMCMatcher> do loop: " << k << " id1 " << mc1->pdgId() << " id2 " << mc2->pdgId() << endl;
79  } while(mc1 != mc2 && mc1.isNonnull() && mc2.isNonnull());
80  if(mc1.isNonnull() && mc2.isNonnull() && mc1->pdgId()==23) {
81  dimuonMatch = mc1;
82  }
83  }
84  // cout << "DimuonMatcher> dimuonMatch " << dimuonMatch.isNonnull() << endl;
85  matched->push_back(dimuonMatch);
86  }
87 
88  evt.put(matched);
89 }
value_type const * get() const
Definition: RefToBase.h:213
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
reco::GenParticleRef genParticleRef(size_t idx=0) const
Definition: PATObject.h:217
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
edm::EDGetTokenT< reco::CandidateView > srcToken_
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
Analysis-level muon class.
Definition: Muon.h:50
virtual const CandidateBaseRef & masterClone() const =0

Member Data Documentation

edm::EDGetTokenT<reco::CandidateView> DimuonMCMatcher::srcToken_
private

Definition at line 12 of file DimuonMCMatcher.cc.

Referenced by produce().