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
TagProbeFitTreeProducer Class Reference

#include <TagProbeFitTreeProducer.cc>

Inheritance diagram for TagProbeFitTreeProducer:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 TagProbeFitTreeProducer (const edm::ParameterSet &)
 
 ~TagProbeFitTreeProducer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &) override
 
bool checkMother (const reco::GenParticleRef &ref) const
 Return true if ref is not null and has an ancestor with pdgId inside 'motherPdgId_'. More...
 
virtual void endJob () override
 

Private Attributes

edm::EDGetTokenT
< reco::CandidateView
allProbesToken_
 InputTag to the collection of all probes. More...
 
bool checkMotherInUnbiasEff_
 Check mother pdgId in unbiased inefficiency measurement. More...
 
bool isMC_
 Is this sample MC? More...
 
bool makeMCUnbiasTree_
 Do we have to compute this. More...
 
std::auto_ptr
< tnp::BaseTreeFiller
mcFiller_
 
std::auto_ptr
< tnp::BaseTreeFiller
mcUnbiasFiller_
 The object that actually computes variables and fills the tree for unbiased MC. More...
 
std::set< int32_t > motherPdgId_
 Possible pdgids for the mother. If empty, any truth-matched mu will be considered good. More...
 
std::auto_ptr
< tnp::BaseTreeFiller
oldTagFiller_
 
std::auto_ptr
< tnp::BaseTreeFiller
pairFiller_
 
edm::EDGetTokenT
< edm::Association
< std::vector
< reco::GenParticle > > > 
probeMatchesToken_
 
std::auto_ptr
< tnp::BaseTreeFiller
tagFiller_
 
edm::EDGetTokenT
< edm::Association
< std::vector
< reco::GenParticle > > > 
tagMatchesToken_
 Token foran edm::Association<reco::GenParticle> from tags & probes to MC truth. More...
 
tnp::TagProbePairMaker tagProbePairMaker_
 The object that produces pairs of tags and probes, making any arbitration needed. More...
 
std::auto_ptr< tnp::TPTreeFillertreeFiller_
 The object that actually computes variables and fills the tree for T&P. More...
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- 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

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 48 of file TagProbeFitTreeProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 91 of file TagProbeFitTreeProducer.cc.

References edm::ParameterSet::addParameter(), allProbesToken_, edm::EDConsumerBase::consumesCollector(), edm::ParameterSet::empty(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), isMC_, makeMCUnbiasTree_, mcFiller_, mcUnbiasFiller_, motherPdgId_, pairFiller_, probeMatchesToken_, tagFiller_, tagMatchesToken_, and treeFiller_.

91  :
92  isMC_(iConfig.getParameter<bool>("isMC")),
93  makeMCUnbiasTree_(isMC_ ? iConfig.getParameter<bool>("makeMCUnbiasTree") : false),
94  checkMotherInUnbiasEff_(makeMCUnbiasTree_ ? iConfig.getParameter<bool>("checkMotherInUnbiasEff") : false),
97  oldTagFiller_((iConfig.existsAs<bool>("fillTagTree") && iConfig.getParameter<bool>("fillTagTree")) ? new tnp::BaseTreeFiller("tag_tree",iConfig, consumesCollector()) : 0)
98 {
99  if (isMC_) {
100  // For mc efficiency we need the MC matches for tags & probes
101  tagMatchesToken_ = consumes<edm::Association<std::vector<reco::GenParticle> > >(iConfig.getParameter<edm::InputTag>("tagMatches"));
102  probeMatchesToken_ = consumes<edm::Association<std::vector<reco::GenParticle> > >(iConfig.getParameter<edm::InputTag>("probeMatches"));
103  //.. and the pdgids of the possible mothers
104  if (iConfig.existsAs<int32_t>("motherPdgId")) {
105  motherPdgId_.insert(iConfig.getParameter<int32_t>("motherPdgId"));
106  } else {
107  std::vector<int32_t> motherIds = iConfig.getParameter<std::vector<int32_t> >("motherPdgId");
108  motherPdgId_.insert(motherIds.begin(), motherIds.end());
109  }
110 
111  // For unbiased efficiency we also need the collection of all probes
112  if (makeMCUnbiasTree_) {
113  allProbesToken_ = consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("allProbes"));
114  mcUnbiasFiller_.reset(new tnp::BaseTreeFiller("mcUnbias_tree",iConfig, consumesCollector()));
115  }
116  }
117 
118  edm::ParameterSet tagPSet;
119  if (iConfig.existsAs<edm::ParameterSet>("tagVariables")) tagPSet.addParameter<edm::ParameterSet>("variables", iConfig.getParameter<edm::ParameterSet>("tagVariables"));
120  if (iConfig.existsAs<edm::ParameterSet>("tagFlags" )) tagPSet.addParameter<edm::ParameterSet>("flags", iConfig.getParameter<edm::ParameterSet>("tagFlags"));
121  if (!tagPSet.empty()) { tagFiller_.reset(new tnp::BaseTreeFiller(*treeFiller_, tagPSet, consumesCollector(), "tag_")); }
122  edm::ParameterSet mcPSet;
123  if (iConfig.existsAs<edm::ParameterSet>("mcVariables")) mcPSet.addParameter<edm::ParameterSet>("variables", iConfig.getParameter<edm::ParameterSet>("mcVariables"));
124  if (iConfig.existsAs<edm::ParameterSet>("mcFlags" )) mcPSet.addParameter<edm::ParameterSet>("flags", iConfig.getParameter<edm::ParameterSet>("mcFlags"));
125  if (!mcPSet.empty()) { mcFiller_.reset(new tnp::BaseTreeFiller(*treeFiller_, mcPSet, consumesCollector(), "mc_")); }
126  edm::ParameterSet pairPSet;
127  if (iConfig.existsAs<edm::ParameterSet>("pairVariables")) pairPSet.addParameter<edm::ParameterSet>("variables", iConfig.getParameter<edm::ParameterSet>("pairVariables"));
128  if (iConfig.existsAs<edm::ParameterSet>("pairFlags" )) pairPSet.addParameter<edm::ParameterSet>("flags", iConfig.getParameter<edm::ParameterSet>("pairFlags"));
129  if (!pairPSet.empty()) { pairFiller_.reset(new tnp::BaseTreeFiller(*treeFiller_, pairPSet, consumesCollector(), "pair_")); }
130 }
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:218
edm::EDGetTokenT< edm::Association< std::vector< reco::GenParticle > > > tagMatchesToken_
Token foran edm::Association&lt;reco::GenParticle&gt; from tags &amp; probes to MC truth.
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
std::auto_ptr< tnp::TPTreeFiller > treeFiller_
The object that actually computes variables and fills the tree for T&amp;P.
std::auto_ptr< tnp::BaseTreeFiller > oldTagFiller_
std::auto_ptr< tnp::BaseTreeFiller > tagFiller_
edm::EDGetTokenT< reco::CandidateView > allProbesToken_
InputTag to the collection of all probes.
bool checkMotherInUnbiasEff_
Check mother pdgId in unbiased inefficiency measurement.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
bool isMC_
Is this sample MC?
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
std::auto_ptr< tnp::BaseTreeFiller > mcFiller_
bool makeMCUnbiasTree_
Do we have to compute this.
tnp::TagProbePairMaker tagProbePairMaker_
The object that produces pairs of tags and probes, making any arbitration needed. ...
std::auto_ptr< tnp::BaseTreeFiller > mcUnbiasFiller_
The object that actually computes variables and fills the tree for unbiased MC.
edm::EDGetTokenT< edm::Association< std::vector< reco::GenParticle > > > probeMatchesToken_
std::set< int32_t > motherPdgId_
Possible pdgids for the mother. If empty, any truth-matched mu will be considered good...
std::auto_ptr< tnp::BaseTreeFiller > pairFiller_
TagProbeFitTreeProducer::~TagProbeFitTreeProducer ( )

Definition at line 133 of file TagProbeFitTreeProducer.cc.

134 {
135 }

Member Function Documentation

void TagProbeFitTreeProducer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDAnalyzer.

Definition at line 144 of file TagProbeFitTreeProducer.cc.

References allProbesToken_, checkMother(), checkMotherInUnbiasEff_, edm::Event::getByToken(), i, isMC_, edm::Ref< C, T, F >::isNonnull(), makeMCUnbiasTree_, mcFiller_, mcUnbiasFiller_, gen::n, oldTagFiller_, pairFiller_, probeMatchesToken_, tnp::TagProbePairMaker::run(), alcazmumu_cfi::src, tagFiller_, tagMatchesToken_, tagProbePairMaker_, and treeFiller_.

145 {
146  using namespace edm; using namespace std;
147  Handle<reco::CandidateView> src, allProbes;
148  Handle<Association<vector<reco::GenParticle> > > tagMatches, probeMatches;
149  treeFiller_->init(iEvent); // read out info from the event if needed (external vars, list of passing probes, ...)
150  if (oldTagFiller_.get()) oldTagFiller_->init(iEvent);
151  if (tagFiller_.get()) tagFiller_->init(iEvent);
152  if (pairFiller_.get()) pairFiller_->init(iEvent);
153  if (mcFiller_.get()) mcFiller_->init(iEvent);
154 
155  // on mc we want to load also the MC match info
156  if (isMC_) {
157  iEvent.getByToken(tagMatchesToken_, tagMatches);
158  iEvent.getByToken(probeMatchesToken_, probeMatches);
159  }
160 
161  // get the list of (tag+probe) pairs, performing arbitration
162  tnp::TagProbePairs pairs = tagProbePairMaker_.run(iEvent);
163  // loop on them to fill the tree
164  for (tnp::TagProbePairs::const_iterator it = pairs.begin(), ed = pairs.end(); it != ed; ++it) {
165  // on mc, fill mc info (on non-mc, let it to 'true', the treeFiller will ignore it anyway
166  bool mcTrue = false;
167  float mcMass = 0.f;
168  if (isMC_) {
169  reco::GenParticleRef mtag = (*tagMatches)[it->tag], mprobe = (*probeMatches)[it->probe];
170  mcTrue = checkMother(mtag) && checkMother(mprobe);
171  if (mcTrue) {
172  mcMass = (mtag->p4() + mprobe->p4()).mass();
173  if (mcFiller_.get()) mcFiller_->fill(reco::CandidateBaseRef(mprobe));
174  }
175  }
176  // fill in the variables for this t+p pair
177  if (tagFiller_.get()) tagFiller_->fill(it->tag);
178  if (oldTagFiller_.get()) oldTagFiller_->fill(it->tag);
179  if (pairFiller_.get()) pairFiller_->fill(it->pair);
180  treeFiller_->fill(it->probe, it->mass, mcTrue, mcMass);
181  }
182 
183  if (isMC_ && makeMCUnbiasTree_) {
184  // read full collection of probes
185  iEvent.getByToken(allProbesToken_, allProbes);
186  // init the tree filler
187  mcUnbiasFiller_->init(iEvent);
188  // loop on probes
189  for (size_t i = 0, n = allProbes->size(); i < n; ++i) {
190  const reco::CandidateBaseRef & probe = allProbes->refAt(i);
191  // check mc match, and possibly mother match
192  reco::GenParticleRef probeMatch = (*probeMatches)[probe];
193  bool probeOk = checkMotherInUnbiasEff_ ? checkMother(probeMatch) : probeMatch.isNonnull();
194  // fill the tree only for good ones
195  if (probeOk) mcUnbiasFiller_->fill(probe);
196  }
197  }
198 
199 }
edm::EDGetTokenT< edm::Association< std::vector< reco::GenParticle > > > tagMatchesToken_
Token foran edm::Association&lt;reco::GenParticle&gt; from tags &amp; probes to MC truth.
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< tnp::TPTreeFiller > treeFiller_
The object that actually computes variables and fills the tree for T&amp;P.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
std::vector< TagProbePair > TagProbePairs
std::auto_ptr< tnp::BaseTreeFiller > oldTagFiller_
std::auto_ptr< tnp::BaseTreeFiller > tagFiller_
edm::EDGetTokenT< reco::CandidateView > allProbesToken_
InputTag to the collection of all probes.
bool checkMotherInUnbiasEff_
Check mother pdgId in unbiased inefficiency measurement.
bool isMC_
Is this sample MC?
std::auto_ptr< tnp::BaseTreeFiller > mcFiller_
bool makeMCUnbiasTree_
Do we have to compute this.
tnp::TagProbePairMaker tagProbePairMaker_
The object that produces pairs of tags and probes, making any arbitration needed. ...
std::auto_ptr< tnp::BaseTreeFiller > mcUnbiasFiller_
The object that actually computes variables and fills the tree for unbiased MC.
edm::EDGetTokenT< edm::Association< std::vector< reco::GenParticle > > > probeMatchesToken_
bool checkMother(const reco::GenParticleRef &ref) const
Return true if ref is not null and has an ancestor with pdgId inside &#39;motherPdgId_&#39;.
TagProbePairs run(const edm::Event &iEvent) const
fill in tghe T&amp;P pairs for this event
std::auto_ptr< tnp::BaseTreeFiller > pairFiller_
bool TagProbeFitTreeProducer::checkMother ( const reco::GenParticleRef ref) const
private

Return true if ref is not null and has an ancestor with pdgId inside 'motherPdgId_'.

Definition at line 202 of file TagProbeFitTreeProducer.cc.

References funct::abs(), edm::RefVector< C, T, F >::begin(), alignCSCRings::e, edm::RefVector< C, T, F >::end(), edm::Ref< C, T, F >::isNull(), visualization-live-secondInstance_cfg::m, and motherPdgId_.

Referenced by analyze().

202  {
203  if (ref.isNull()) return false;
204  if (motherPdgId_.empty()) return true;
205  if (motherPdgId_.find(abs(ref->pdgId())) != motherPdgId_.end()) return true;
206  reco::GenParticle::mothers m = ref->motherRefVector();
207  for (reco::GenParticle::mothers::const_iterator it = m.begin(), e = m.end(); it != e; ++it) {
208  if (checkMother(*it)) return true;
209  }
210  return false;
211 }
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isNull() const
Checks for null.
Definition: Ref.h:249
bool checkMother(const reco::GenParticleRef &ref) const
Return true if ref is not null and has an ancestor with pdgId inside &#39;motherPdgId_&#39;.
std::set< int32_t > motherPdgId_
Possible pdgids for the mother. If empty, any truth-matched mu will be considered good...
void TagProbeFitTreeProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 216 of file TagProbeFitTreeProducer.cc.

References edm::getProcessParameterSetContainingModule(), edm::EDAnalyzer::moduleDescription(), and treeFiller_.

216  {
217  // ask to write the current PSet info into the TTree header
219 }
std::auto_ptr< tnp::TPTreeFiller > treeFiller_
The object that actually computes variables and fills the tree for T&amp;P.
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
ModuleDescription const & moduleDescription() const
Definition: EDAnalyzer.h:43

Member Data Documentation

edm::EDGetTokenT<reco::CandidateView> TagProbeFitTreeProducer::allProbesToken_
private

InputTag to the collection of all probes.

Definition at line 74 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

bool TagProbeFitTreeProducer::checkMotherInUnbiasEff_
private

Check mother pdgId in unbiased inefficiency measurement.

Definition at line 72 of file TagProbeFitTreeProducer.cc.

Referenced by analyze().

bool TagProbeFitTreeProducer::isMC_
private

Is this sample MC?

Definition at line 60 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

bool TagProbeFitTreeProducer::makeMCUnbiasTree_
private

Do we have to compute this.

Definition at line 70 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

std::auto_ptr<tnp::BaseTreeFiller> TagProbeFitTreeProducer::mcFiller_
private

Definition at line 85 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

std::auto_ptr<tnp::BaseTreeFiller> TagProbeFitTreeProducer::mcUnbiasFiller_
private

The object that actually computes variables and fills the tree for unbiased MC.

Definition at line 81 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

std::set<int32_t> TagProbeFitTreeProducer::motherPdgId_
private

Possible pdgids for the mother. If empty, any truth-matched mu will be considered good.

Definition at line 64 of file TagProbeFitTreeProducer.cc.

Referenced by checkMother(), and TagProbeFitTreeProducer().

std::auto_ptr<tnp::BaseTreeFiller> TagProbeFitTreeProducer::oldTagFiller_
private

Definition at line 82 of file TagProbeFitTreeProducer.cc.

Referenced by analyze().

std::auto_ptr<tnp::BaseTreeFiller> TagProbeFitTreeProducer::pairFiller_
private

Definition at line 84 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

edm::EDGetTokenT<edm::Association<std::vector<reco::GenParticle> > > TagProbeFitTreeProducer::probeMatchesToken_
private

Definition at line 62 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

std::auto_ptr<tnp::BaseTreeFiller> TagProbeFitTreeProducer::tagFiller_
private

Definition at line 83 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

edm::EDGetTokenT<edm::Association<std::vector<reco::GenParticle> > > TagProbeFitTreeProducer::tagMatchesToken_
private

Token foran edm::Association<reco::GenParticle> from tags & probes to MC truth.

Definition at line 62 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

tnp::TagProbePairMaker TagProbeFitTreeProducer::tagProbePairMaker_
private

The object that produces pairs of tags and probes, making any arbitration needed.

Definition at line 77 of file TagProbeFitTreeProducer.cc.

Referenced by analyze().

std::auto_ptr<tnp::TPTreeFiller> TagProbeFitTreeProducer::treeFiller_
private

The object that actually computes variables and fills the tree for T&P.

Definition at line 79 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), endJob(), and TagProbeFitTreeProducer().