CMS 3D CMS Logo

TtEvtBuilder.h
Go to the documentation of this file.
1 #ifndef TtEvtBuilder_h
2 #define TtEvtBuilder_h
3 
4 #include <vector>
5 
15 
32 template <typename C>
33 class TtEvtBuilder : public edm::EDProducer {
34 public:
36  explicit TtEvtBuilder(const edm::ParameterSet&);
38  ~TtEvtBuilder() override{};
39 
40 private:
43  void produce(edm::Event&, const edm::EventSetup&) override;
45  virtual void fillSpecific(C&, const edm::Event&);
46 
47 private:
51  std::vector<edm::EDGetTokenT<int> > hypKeyTokens_;
52  std::vector<edm::EDGetTokenT<std::vector<TtEvent::HypoCombPair> > > hypTokens_;
53  std::vector<edm::EDGetTokenT<int> > hypNeutrTokens_;
54  std::vector<edm::EDGetTokenT<int> > hypJetTokens_;
55  typedef std::vector<edm::EDGetTokenT<int> >::const_iterator EventHypoIntToken;
56  typedef std::vector<edm::EDGetTokenT<std::vector<TtEvent::HypoCombPair> > >::const_iterator EventHypoToken;
64 
92 };
93 
94 template <typename C>
96  : verbosity_(cfg.getParameter<int>("verbosity")),
97  hypKeyTokens_(edm::vector_transform(
98  cfg.getParameter<std::vector<edm::InputTag> >("hypotheses"),
99  [this](edm::InputTag const& tag) { return consumes<int>(edm::InputTag(tag.label(), "Key")); })),
100  hypTokens_(edm::vector_transform(
101  cfg.getParameter<std::vector<edm::InputTag> >("hypotheses"),
102  [this](edm::InputTag const& tag) { return consumes<std::vector<TtEvent::HypoCombPair> >(tag); })),
103  hypNeutrTokens_(edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("hypotheses"),
104  [this](edm::InputTag const& tag) {
105  return consumes<int>(
106  edm::InputTag(tag.label(), "NumberOfRealNeutrinoSolutions"));
107  })),
108  hypJetTokens_(edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("hypotheses"),
109  [this](edm::InputTag const& tag) {
110  return consumes<int>(edm::InputTag(tag.label(), "NumberOfConsideredJets"));
111  })),
112  genEvt_(cfg.getParameter<edm::InputTag>("genEvent")),
113  genEvtToken_(mayConsume<TtGenEvent>(genEvt_)),
114  decayChnTop1_(cfg.getParameter<int>("decayChannel1")),
115  decayChnTop2_(cfg.getParameter<int>("decayChannel2")) {
116  // parameter subsets for kKinFit
117  if (cfg.exists("kinFit")) {
118  kinFit_ = cfg.getParameter<edm::ParameterSet>("kinFit");
119  fitChi2Token_ = mayConsume<std::vector<double> >(kinFit_.getParameter<edm::InputTag>("chi2"));
120  fitProbToken_ = mayConsume<std::vector<double> >(kinFit_.getParameter<edm::InputTag>("prob"));
121  }
122  // parameter subsets for kHitFit
123  if (cfg.exists("hitFit")) {
124  hitFit_ = cfg.getParameter<edm::ParameterSet>("hitFit");
125  hitFitChi2Token_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("chi2"));
126  hitFitProbToken_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("prob"));
127  hitFitMTToken_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("mt"));
128  hitFitSigMTToken_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("sigmt"));
129  }
130  // parameter subsets for kKinSolution
131  if (cfg.exists("kinSolution")) {
132  kinSolution_ = cfg.getParameter<edm::ParameterSet>("kinSolution");
133  solWeightToken_ = mayConsume<std::vector<double> >(kinSolution_.getParameter<edm::InputTag>("solWeight"));
134  wrongChargeToken_ = mayConsume<bool>(kinSolution_.getParameter<edm::InputTag>("wrongCharge"));
135  }
136  // parameter subsets for kGenMatch
137  if (cfg.exists("genMatch")) {
138  genMatch_ = cfg.getParameter<edm::ParameterSet>("genMatch");
139  sumPtToken_ = mayConsume<std::vector<double> >(genMatch_.getParameter<edm::InputTag>("sumPt"));
140  sumDRToken_ = mayConsume<std::vector<double> >(genMatch_.getParameter<edm::InputTag>("sumDR"));
141  }
142  // parameter subsets for kMvaDisc
143  if (cfg.exists("mvaDisc")) {
144  mvaDisc_ = cfg.getParameter<edm::ParameterSet>("mvaDisc");
145  methToken_ = mayConsume<std::string>(mvaDisc_.getParameter<edm::InputTag>("meth"));
146  discToken_ = mayConsume<std::vector<double> >(mvaDisc_.getParameter<edm::InputTag>("disc"));
147  }
148  // produces a TtEventEvent for:
149  // * TtSemiLeptonicEvent
150  // * TtFullLeptonicEvent
151  // * TtFullHadronicEvent
152  // from hypotheses and associated extra information
153  produces<C>();
154 }
155 
156 template <typename C>
158  C ttEvent;
159 
160  // set leptonic decay channels
161  ttEvent.setLepDecays(WDecay::LeptonType(decayChnTop1_), WDecay::LeptonType(decayChnTop2_));
162 
163  // set genEvent (if available)
165  if (!genEvt_.label().empty())
166  if (evt.getByToken(genEvtToken_, genEvt))
167  ttEvent.setGenEvent(genEvt);
168 
169  // add event hypotheses for all given
170  // hypothesis classes to the TtEvent
171  EventHypoIntToken hKey = hypKeyTokens_.begin();
172  EventHypoToken h = hypTokens_.begin();
173  for (; hKey != hypKeyTokens_.end(); ++hKey, ++h) {
175  evt.getByToken(*hKey, key);
176 
178  evt.getByToken(*h, hypMatchVec);
179 
180  typedef std::vector<TtEvent::HypoCombPair>::const_iterator HypMatch;
181  for (HypMatch hm = hypMatchVec->begin(); hm != hypMatchVec->end(); ++hm) {
182  ttEvent.addEventHypo((TtEvent::HypoClassKey&)*key, *hm);
183  }
184  }
185 
186  // set kKinFit extras
187  if (ttEvent.isHypoAvailable(TtEvent::kKinFit)) {
189  evt.getByToken(fitChi2Token_, fitChi2);
190  ttEvent.setFitChi2(*fitChi2);
191 
193  evt.getByToken(fitProbToken_, fitProb);
194  ttEvent.setFitProb(*fitProb);
195  }
196 
197  // set kHitFit extras
198  if (ttEvent.isHypoAvailable(TtEvent::kHitFit)) {
199  edm::Handle<std::vector<double> > hitFitChi2;
200  evt.getByToken(hitFitChi2Token_, hitFitChi2);
201  ttEvent.setHitFitChi2(*hitFitChi2);
202 
203  edm::Handle<std::vector<double> > hitFitProb;
204  evt.getByToken(hitFitProbToken_, hitFitProb);
205  ttEvent.setHitFitProb(*hitFitProb);
206 
208  evt.getByToken(hitFitMTToken_, hitFitMT);
209  ttEvent.setHitFitMT(*hitFitMT);
210 
211  edm::Handle<std::vector<double> > hitFitSigMT;
212  evt.getByToken(hitFitSigMTToken_, hitFitSigMT);
213  ttEvent.setHitFitSigMT(*hitFitSigMT);
214  }
215 
216  // set kGenMatch extras
217  if (ttEvent.isHypoAvailable(TtEvent::kGenMatch)) {
219  evt.getByToken(sumPtToken_, sumPt);
220  ttEvent.setGenMatchSumPt(*sumPt);
221 
223  evt.getByToken(sumDRToken_, sumDR);
224  ttEvent.setGenMatchSumDR(*sumDR);
225  }
226 
227  // set kMvaDisc extras
228  if (ttEvent.isHypoAvailable(TtEvent::kMVADisc)) {
230  evt.getByToken(methToken_, meth);
231  ttEvent.setMvaMethod(*meth);
232 
234  evt.getByToken(discToken_, disc);
235  ttEvent.setMvaDiscriminators(*disc);
236  }
237 
238  // fill data members that are decay-channel specific
239  fillSpecific(ttEvent, evt);
240 
241  // print summary via MessageLogger if verbosity_>0
242  ttEvent.print(verbosity_);
243 
244  // write object into the edm::Event
245  std::unique_ptr<C> pOut(new C);
246  *pOut = ttEvent;
247  evt.put(std::move(pOut));
248 }
249 
250 template <>
252 
253 template <>
255  // set kKinSolution extras
256  if (ttEvent.isHypoAvailable(TtEvent::kKinSolution)) {
258  evt.getByToken(solWeightToken_, solWeight);
259  ttEvent.setSolWeight(*solWeight);
260 
262  evt.getByToken(wrongChargeToken_, wrongCharge);
263  ttEvent.setWrongCharge(*wrongCharge);
264  }
265 }
266 
267 template <>
269  EventHypoIntToken hKey = hypKeyTokens_.begin();
270  EventHypoIntToken hNeutr = hypNeutrTokens_.begin();
271  EventHypoIntToken hJet = hypJetTokens_.begin();
272  for (; hKey != hypKeyTokens_.end(); ++hKey, ++hNeutr, ++hJet) {
274  evt.getByToken(*hKey, key);
275 
276  // set number of real neutrino solutions for all hypotheses
277  edm::Handle<int> numberOfRealNeutrinoSolutions;
278  evt.getByToken(*hNeutr, numberOfRealNeutrinoSolutions);
279  ttEvent.setNumberOfRealNeutrinoSolutions((TtEvent::HypoClassKey&)*key, *numberOfRealNeutrinoSolutions);
280 
281  // set number of considered jets for all hypotheses
282  edm::Handle<int> numberOfConsideredJets;
283  evt.getByToken(*hJet, numberOfConsideredJets);
284  ttEvent.setNumberOfConsideredJets((TtEvent::HypoClassKey&)*key, *numberOfConsideredJets);
285  }
286 }
287 
288 #endif
TtEvtBuilder::~TtEvtBuilder
~TtEvtBuilder() override
default destructor
Definition: TtEvtBuilder.h:38
TtFullLeptonicEvent
Class derived from the TtEvent for the full leptonic decay channel.
Definition: TtFullLeptonicEvent.h:24
TtEvtBuilder::hitFitSigMTToken_
edm::EDGetTokenT< std::vector< double > > hitFitSigMTToken_
Definition: TtEvtBuilder.h:76
EDProducer.h
TtEvtBuilder::EventHypoIntToken
std::vector< edm::EDGetTokenT< int > >::const_iterator EventHypoIntToken
Definition: TtEvtBuilder.h:55
TtEvent::isHypoAvailable
bool isHypoAvailable(const std::string &key, const unsigned &cmb=0) const
Definition: TtEvent.h:70
TtFullLeptonicEvent.h
TtEvtBuilder::fitChi2Token_
edm::EDGetTokenT< std::vector< double > > fitChi2Token_
Definition: TtEvtBuilder.h:68
edm::EDGetTokenT< TtGenEvent >
TtEvtBuilder::kinFit_
edm::ParameterSet kinFit_
Definition: TtEvtBuilder.h:67
edm
HLT enums.
Definition: AlignableModifier.h:19
TtEvtBuilder::EventHypoToken
std::vector< edm::EDGetTokenT< std::vector< TtEvent::HypoCombPair > > >::const_iterator EventHypoToken
Definition: TtEvtBuilder.h:56
TtEvtBuilder::wrongChargeToken_
edm::EDGetTokenT< bool > wrongChargeToken_
Definition: TtEvtBuilder.h:81
TtEvtBuilder::hitFitProbToken_
edm::EDGetTokenT< std::vector< double > > hitFitProbToken_
Definition: TtEvtBuilder.h:74
TtEvtBuilder
Template class to fill the TtEvent structure.
Definition: TtEvtBuilder.h:33
TtFullHadronicEvent
Class derived from the TtEvent for the full hadronic decay channel.
Definition: TtFullHadronicEvent.h:25
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
TtEvtBuilder::kinSolution_
edm::ParameterSet kinSolution_
Definition: TtEvtBuilder.h:79
L1TrackObjectNtupleMaker_cfg.pOut
pOut
Definition: L1TrackObjectNtupleMaker_cfg.py:172
TtFullLepEvtBuilder_cfi.solWeight
solWeight
Definition: TtFullLepEvtBuilder_cfi.py:37
TtEvent::kKinFit
Definition: TtEvent.h:32
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
watchdog.const
const
Definition: watchdog.py:83
edm::Handle
Definition: AssociativeIterator.h:50
TtSemiLepEvtBuilder_cfi.disc
disc
Definition: TtSemiLepEvtBuilder_cfi.py:60
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
TtSemiLepEvtBuilder_cfi.meth
meth
Definition: TtSemiLepEvtBuilder_cfi.py:59
TtFullHadEvtBuilder_cfi.sumPt
sumPt
Definition: TtFullHadEvtBuilder_cfi.py:38
TtFullLeptonicEvent::setWrongCharge
void setWrongCharge(const bool &val)
set right or wrong charge combination of kKinSolution hypothesis
Definition: TtFullLeptonicEvent.h:141
TtSemiLeptonicEvent
Class derived from the TtEvent for the semileptonic decay channel.
Definition: TtSemiLeptonicEvent.h:24
TtEvtBuilder::hypJetTokens_
std::vector< edm::EDGetTokenT< int > > hypJetTokens_
Definition: TtEvtBuilder.h:54
TtFullLeptonicEvent::setSolWeight
void setSolWeight(const std::vector< double > &val)
set weight of kKinSolution hypothesis
Definition: TtFullLeptonicEvent.h:139
TtEvtBuilder::sumPtToken_
edm::EDGetTokenT< std::vector< double > > sumPtToken_
Definition: TtEvtBuilder.h:85
TtEvtBuilder::verbosity_
int verbosity_
vebosity level
Definition: TtEvtBuilder.h:49
TtEvtBuilder::hypTokens_
std::vector< edm::EDGetTokenT< std::vector< TtEvent::HypoCombPair > > > hypTokens_
Definition: TtEvtBuilder.h:52
TtFullLepEvtBuilder_cfi.wrongCharge
wrongCharge
Definition: TtFullLepEvtBuilder_cfi.py:38
TtEvtBuilder::genEvtToken_
edm::EDGetTokenT< TtGenEvent > genEvtToken_
Definition: TtEvtBuilder.h:59
TtEvent::setNumberOfConsideredJets
void setNumberOfConsideredJets(const HypoClassKey &key, const unsigned int nJets)
set number of jets considered when building a given hypothesis
Definition: TtEvent.h:162
TtSemiLeptonicEvent.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
h
TtEvent::kMVADisc
Definition: TtEvent.h:31
TtFullHadronicEvent.h
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
TtEvtBuilder::hitFitChi2Token_
edm::EDGetTokenT< std::vector< double > > hitFitChi2Token_
Definition: TtEvtBuilder.h:73
TtFullHadEvtBuilder_cfi.sumDR
sumDR
Definition: TtFullHadEvtBuilder_cfi.py:39
TtEvtBuilder::hitFit_
edm::ParameterSet hitFit_
Definition: TtEvtBuilder.h:72
TtEvent::kHitFit
Definition: TtEvent.h:35
TtSemiLeptonicEvent::setNumberOfRealNeutrinoSolutions
void setNumberOfRealNeutrinoSolutions(const HypoClassKey &key, const int &nr)
set number of real neutrino solutions for a given hypo class
Definition: TtSemiLeptonicEvent.h:157
edm::ParameterSet
Definition: ParameterSet.h:47
TtEvent::HypoClassKey
HypoClassKey
supported classes of event hypotheses
Definition: TtEvent.h:26
TtEvtBuilder::hitFitMTToken_
edm::EDGetTokenT< std::vector< double > > hitFitMTToken_
Definition: TtEvtBuilder.h:75
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
TtEvtBuilder::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TtEvtBuilder.h:157
TtEvtBuilder::fitProbToken_
edm::EDGetTokenT< std::vector< double > > fitProbToken_
Definition: TtEvtBuilder.h:69
createfilelist.int
int
Definition: createfilelist.py:10
TtEvtBuilder::genEvt_
edm::InputTag genEvt_
TtGenEvent.
Definition: TtEvtBuilder.h:58
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
TtEvtBuilder::hypKeyTokens_
std::vector< edm::EDGetTokenT< int > > hypKeyTokens_
vector of hypothesis class names
Definition: TtEvtBuilder.h:51
edm::EventSetup
Definition: EventSetup.h:58
TtEvtBuilder::discToken_
edm::EDGetTokenT< std::vector< double > > discToken_
Definition: TtEvtBuilder.h:91
looper.cfg
cfg
Definition: looper.py:296
WDecay::LeptonType
LeptonType
Definition: TopGenEvent.h:27
TtEvtBuilder::mvaDisc_
edm::ParameterSet mvaDisc_
Definition: TtEvtBuilder.h:89
TtEvent::kGenMatch
Definition: TtEvent.h:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
gen::C
C
Definition: PomwigHadronizer.cc:78
TtEvent::kKinSolution
Definition: TtEvent.h:33
Frameworkfwd.h
transform.h
TtEvtBuilder::decayChnTop2_
int decayChnTop2_
Definition: TtEvtBuilder.h:63
TtEvtBuilder::genMatch_
edm::ParameterSet genMatch_
Definition: TtEvtBuilder.h:84
edm::EDProducer
Definition: EDProducer.h:35
TtEvtBuilder::decayChnTop1_
int decayChnTop1_
Definition: TtEvtBuilder.h:62
TtEvtBuilder::solWeightToken_
edm::EDGetTokenT< std::vector< double > > solWeightToken_
Definition: TtEvtBuilder.h:80
TtEvtBuilder::sumDRToken_
edm::EDGetTokenT< std::vector< double > > sumDRToken_
Definition: TtEvtBuilder.h:86
TtEvtBuilder::hypNeutrTokens_
std::vector< edm::EDGetTokenT< int > > hypNeutrTokens_
Definition: TtEvtBuilder.h:53
TtEvent.h
ParameterSet.h
TtEvtBuilder::fillSpecific
virtual void fillSpecific(C &, const edm::Event &)
fill data members that are decay-channel specific
fitChi2
static double fitChi2(const CachingVertex< 5 > &vtx)
Definition: GhostTrackVertexFinder.cc:638
edm::Event
Definition: Event.h:73
TtEvtBuilder::methToken_
edm::EDGetTokenT< std::string > methToken_
Definition: TtEvtBuilder.h:90
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::InputTag
Definition: InputTag.h:15
TtGenEvtProducer_cfi.genEvt
genEvt
Definition: TtGenEvtProducer_cfi.py:7
TtEvtBuilder::TtEvtBuilder
TtEvtBuilder(const edm::ParameterSet &)
default constructor
Definition: TtEvtBuilder.h:95