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

Public Member Functions

 TagProbeFitTreeProducer (const edm::ParameterSet &)
 
 ~TagProbeFitTreeProducer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
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 ()
 

Private Attributes

edm::InputTag allProbes_
 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::InputTag probeMatches_
 
std::auto_ptr
< tnp::BaseTreeFiller
tagFiller_
 
edm::InputTag tagMatches_
 InputTag to an 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
 
typedef WorkerT< EDAnalyzerWorkerType
 
- 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::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

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

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

Definition at line 51 of file TagProbeFitTreeProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 94 of file TagProbeFitTreeProducer.cc.

References edm::ParameterSet::addParameter(), allProbes_, edm::ParameterSet::empty(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), isMC_, makeMCUnbiasTree_, mcFiller_, mcUnbiasFiller_, motherPdgId_, pairFiller_, probeMatches_, tagFiller_, tagMatches_, and treeFiller_.

94  :
95  isMC_(iConfig.getParameter<bool>("isMC")),
96  makeMCUnbiasTree_(isMC_ ? iConfig.getParameter<bool>("makeMCUnbiasTree") : false),
97  checkMotherInUnbiasEff_(makeMCUnbiasTree_ ? iConfig.getParameter<bool>("checkMotherInUnbiasEff") : false),
98  tagProbePairMaker_(iConfig),
99  treeFiller_(new tnp::TPTreeFiller(iConfig)),
100  oldTagFiller_((iConfig.existsAs<bool>("fillTagTree") && iConfig.getParameter<bool>("fillTagTree")) ? new tnp::BaseTreeFiller("tag_tree",iConfig) : 0)
101 {
102  if (isMC_) {
103  // For mc efficiency we need the MC matches for tags & probes
104  tagMatches_ = iConfig.getParameter<edm::InputTag>("tagMatches");
105  probeMatches_ = iConfig.getParameter<edm::InputTag>("probeMatches");
106  //.. and the pdgids of the possible mothers
107  if (iConfig.existsAs<int32_t>("motherPdgId")) {
108  motherPdgId_.insert(iConfig.getParameter<int32_t>("motherPdgId"));
109  } else {
110  std::vector<int32_t> motherIds = iConfig.getParameter<std::vector<int32_t> >("motherPdgId");
111  motherPdgId_.insert(motherIds.begin(), motherIds.end());
112  }
113 
114  // For unbiased efficiency we also need the collection of all probes
115  if (makeMCUnbiasTree_) {
116  allProbes_ = iConfig.getParameter<edm::InputTag>("allProbes");
117  mcUnbiasFiller_.reset(new tnp::BaseTreeFiller("mcUnbias_tree",iConfig));
118  }
119  }
120 
121  edm::ParameterSet tagPSet;
122  if (iConfig.existsAs<edm::ParameterSet>("tagVariables")) tagPSet.addParameter<edm::ParameterSet>("variables", iConfig.getParameter<edm::ParameterSet>("tagVariables"));
123  if (iConfig.existsAs<edm::ParameterSet>("tagFlags" )) tagPSet.addParameter<edm::ParameterSet>("flags", iConfig.getParameter<edm::ParameterSet>("tagFlags"));
124  if (!tagPSet.empty()) { tagFiller_.reset(new tnp::BaseTreeFiller(*treeFiller_, tagPSet, "tag_")); }
125  edm::ParameterSet mcPSet;
126  if (iConfig.existsAs<edm::ParameterSet>("mcVariables")) mcPSet.addParameter<edm::ParameterSet>("variables", iConfig.getParameter<edm::ParameterSet>("mcVariables"));
127  if (iConfig.existsAs<edm::ParameterSet>("mcFlags" )) mcPSet.addParameter<edm::ParameterSet>("flags", iConfig.getParameter<edm::ParameterSet>("mcFlags"));
128  if (!mcPSet.empty()) { mcFiller_.reset(new tnp::BaseTreeFiller(*treeFiller_, mcPSet, "mc_")); }
129  edm::ParameterSet pairPSet;
130  if (iConfig.existsAs<edm::ParameterSet>("pairVariables")) pairPSet.addParameter<edm::ParameterSet>("variables", iConfig.getParameter<edm::ParameterSet>("pairVariables"));
131  if (iConfig.existsAs<edm::ParameterSet>("pairFlags" )) pairPSet.addParameter<edm::ParameterSet>("flags", iConfig.getParameter<edm::ParameterSet>("pairFlags"));
132  if (!pairPSet.empty()) { pairFiller_.reset(new tnp::BaseTreeFiller(*treeFiller_, pairPSet, "pair_")); }
133 }
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:219
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 tagMatches_
InputTag to an edm::Association&lt;reco::GenParticle&gt; from tags &amp; probes to MC truth.
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_
bool checkMotherInUnbiasEff_
Check mother pdgId in unbiased inefficiency measurement.
edm::InputTag allProbes_
InputTag to the collection of all probes.
bool isMC_
Is this sample MC?
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
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.
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 136 of file TagProbeFitTreeProducer.cc.

137 {
138 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 147 of file TagProbeFitTreeProducer.cc.

References allProbes_, checkMother(), checkMotherInUnbiasEff_, edm::Event::getByLabel(), i, isMC_, edm::Ref< C, T, F >::isNonnull(), makeMCUnbiasTree_, mcFiller_, mcUnbiasFiller_, n, oldTagFiller_, pairFiller_, probeMatches_, tnp::TagProbePairMaker::run(), alcazmumu_cfi::src, tagFiller_, tagMatches_, tagProbePairMaker_, and treeFiller_.

148 {
149  using namespace edm; using namespace std;
150  Handle<reco::CandidateView> src, allProbes;
151  Handle<Association<vector<reco::GenParticle> > > tagMatches, probeMatches;
152 
153  treeFiller_->init(iEvent); // read out info from the event if needed (external vars, list of passing probes, ...)
154  if (oldTagFiller_.get()) oldTagFiller_->init(iEvent);
155  if (tagFiller_.get()) tagFiller_->init(iEvent);
156  if (pairFiller_.get()) pairFiller_->init(iEvent);
157  if (mcFiller_.get()) mcFiller_->init(iEvent);
158 
159  // on mc we want to load also the MC match info
160  if (isMC_) {
161  iEvent.getByLabel(tagMatches_, tagMatches);
162  iEvent.getByLabel(probeMatches_, probeMatches);
163  }
164 
165  // get the list of (tag+probe) pairs, performing arbitration
166  tnp::TagProbePairs pairs = tagProbePairMaker_.run(iEvent);
167  // loop on them to fill the tree
168  for (tnp::TagProbePairs::const_iterator it = pairs.begin(), ed = pairs.end(); it != ed; ++it) {
169  // on mc, fill mc info (on non-mc, let it to 'true', the treeFiller will ignore it anyway
170  bool mcTrue = false;
171  if (isMC_) {
172  reco::GenParticleRef mtag = (*tagMatches)[it->tag], mprobe = (*probeMatches)[it->probe];
173  mcTrue = checkMother(mtag) && checkMother(mprobe);
174  if (mcTrue && mcFiller_.get()) mcFiller_->fill(reco::CandidateBaseRef(mprobe));
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);
181  }
182 
183  if (isMC_ && makeMCUnbiasTree_) {
184  // read full collection of probes
185  iEvent.getByLabel(allProbes_, 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 }
int i
Definition: DBlmapReader.cc:9
edm::InputTag tagMatches_
InputTag to an edm::Association&lt;reco::GenParticle&gt; from tags &amp; probes to MC truth.
std::auto_ptr< tnp::TPTreeFiller > treeFiller_
The object that actually computes variables and fills the tree for T&amp;P.
std::vector< TagProbePair > TagProbePairs
std::auto_ptr< tnp::BaseTreeFiller > oldTagFiller_
std::auto_ptr< tnp::BaseTreeFiller > tagFiller_
bool checkMotherInUnbiasEff_
Check mother pdgId in unbiased inefficiency measurement.
edm::InputTag allProbes_
InputTag to the collection of all probes.
bool isMC_
Is this sample MC?
std::auto_ptr< tnp::BaseTreeFiller > mcFiller_
bool makeMCUnbiasTree_
Do we have to compute this.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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.
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 abs, edm::RefVector< C, T, F >::begin(), alignCSCRings::e, edm::RefVector< C, T, F >::end(), edm::Ref< C, T, F >::isNull(), 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 }
#define abs(x)
Definition: mlp_lapack.h:159
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
bool isNull() const
Checks for null.
Definition: Ref.h:247
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  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 216 of file TagProbeFitTreeProducer.cc.

References edm::getProcessParameterSet(), and treeFiller_.

216  {
217  // ask to write the current PSet info into the TTree header
218  treeFiller_->writeProvenance(edm::getProcessParameterSet());
219 }
std::auto_ptr< tnp::TPTreeFiller > treeFiller_
The object that actually computes variables and fills the tree for T&amp;P.
ParameterSet const & getProcessParameterSet()
Definition: Registry.cc:34

Member Data Documentation

edm::InputTag TagProbeFitTreeProducer::allProbes_
private

InputTag to the collection of all probes.

Definition at line 77 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

bool TagProbeFitTreeProducer::checkMotherInUnbiasEff_
private

Check mother pdgId in unbiased inefficiency measurement.

Definition at line 75 of file TagProbeFitTreeProducer.cc.

Referenced by analyze().

bool TagProbeFitTreeProducer::isMC_
private

Is this sample MC?

Definition at line 63 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

bool TagProbeFitTreeProducer::makeMCUnbiasTree_
private

Do we have to compute this.

Definition at line 73 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

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

Definition at line 88 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 84 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 67 of file TagProbeFitTreeProducer.cc.

Referenced by checkMother(), and TagProbeFitTreeProducer().

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

Definition at line 85 of file TagProbeFitTreeProducer.cc.

Referenced by analyze().

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

Definition at line 87 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

edm::InputTag TagProbeFitTreeProducer::probeMatches_
private

Definition at line 65 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

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

Definition at line 86 of file TagProbeFitTreeProducer.cc.

Referenced by analyze(), and TagProbeFitTreeProducer().

edm::InputTag TagProbeFitTreeProducer::tagMatches_
private

InputTag to an edm::Association<reco::GenParticle> from tags & probes to MC truth.

Definition at line 65 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 80 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 82 of file TagProbeFitTreeProducer.cc.

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