CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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")); })),
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
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 
261  edm::Handle<bool> wrongCharge;
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
hypJetTokens_(edm::vector_transform(cfg.getParameter< std::vector< edm::InputTag > >("hypotheses"), [this](edm::InputTag const &tag){return consumes< int >(edm::InputTag(tag.label(),"NumberOfConsideredJets"));}))
edm::EDGetTokenT< std::vector< double > > solWeightToken_
Definition: TtEvtBuilder.h:80
void setWrongCharge(const bool &val)
set right or wrong charge combination of kKinSolution hypothesis
HypoClassKey
supported classes of event hypotheses
Definition: TtEvent.h:26
bool isHypoAvailable(const std::string &key, const unsigned &cmb=0) const
Definition: TtEvent.h:70
decayChnTop2_(cfg.getParameter< int >("decayChannel2"))
Definition: TtEvtBuilder.h:115
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
tuple cfg
Definition: looper.py:296
edm::EDGetTokenT< std::vector< double > > hitFitMTToken_
Definition: TtEvtBuilder.h:75
hypTokens_(edm::vector_transform(cfg.getParameter< std::vector< edm::InputTag > >("hypotheses"), [this](edm::InputTag const &tag){return consumes< std::vector< TtEvent::HypoCombPair > >(tag);}))
edm::EDGetTokenT< std::string > methToken_
Definition: TtEvtBuilder.h:90
TtEvtBuilder(const edm::ParameterSet &)
default constructor
Definition: TtEvtBuilder.h:95
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::InputTag genEvt_
TtGenEvent.
Definition: TtEvtBuilder.h:58
decayChnTop1_(cfg.getParameter< int >("decayChannel1"))
void setNumberOfRealNeutrinoSolutions(const HypoClassKey &key, const int &nr)
set number of real neutrino solutions for a given hypo class
Class derived from the TtEvent for the semileptonic decay channel.
std::vector< edm::EDGetTokenT< std::vector< TtEvent::HypoCombPair > > > hypTokens_
Definition: TtEvtBuilder.h:52
hypNeutrTokens_(edm::vector_transform(cfg.getParameter< std::vector< edm::InputTag > >("hypotheses"), [this](edm::InputTag const &tag){return consumes< int >(edm::InputTag(tag.label(),"NumberOfRealNeutrinoSolutions"));}))
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
std::vector< edm::EDGetTokenT< int > >::const_iterator EventHypoIntToken
Definition: TtEvtBuilder.h:55
static double fitChi2(const CachingVertex< 5 > &vtx)
edm::ParameterSet genMatch_
Definition: TtEvtBuilder.h:84
std::vector< edm::EDGetTokenT< int > > hypNeutrTokens_
Definition: TtEvtBuilder.h:53
edm::EDGetTokenT< std::vector< double > > sumDRToken_
Definition: TtEvtBuilder.h:86
Template class to fill the TtEvent structure.
Definition: TtEvtBuilder.h:33
std::vector< edm::EDGetTokenT< int > > hypKeyTokens_
vector of hypothesis class names
Definition: TtEvtBuilder.h:51
virtual void fillSpecific(C &, const edm::Event &)
fill data members that are decay-channel specific
edm::EDGetTokenT< std::vector< double > > discToken_
Definition: TtEvtBuilder.h:91
def move
Definition: eostools.py:511
tuple key
prepare the HTCondor submission files and eventually submit them
std::vector< edm::EDGetTokenT< int > > hypJetTokens_
Definition: TtEvtBuilder.h:54
int verbosity_
vebosity level
Definition: TtEvtBuilder.h:49
edm::EDGetTokenT< std::vector< double > > hitFitSigMTToken_
Definition: TtEvtBuilder.h:76
edm::ParameterSet mvaDisc_
Definition: TtEvtBuilder.h:89
edm::EDGetTokenT< bool > wrongChargeToken_
Definition: TtEvtBuilder.h:81
~TtEvtBuilder() override
default destructor
Definition: TtEvtBuilder.h:38
Class derived from the TtEvent for the full leptonic decay channel.
edm::EDGetTokenT< std::vector< double > > fitChi2Token_
Definition: TtEvtBuilder.h:68
void setSolWeight(const std::vector< double > &val)
set weight of kKinSolution hypothesis
edm::ParameterSet kinFit_
Definition: TtEvtBuilder.h:67
edm::ParameterSet kinSolution_
Definition: TtEvtBuilder.h:79
Class derived from the TtEvent for the full hadronic decay channel.
edm::EDGetTokenT< std::vector< double > > hitFitChi2Token_
Definition: TtEvtBuilder.h:73
std::vector< edm::EDGetTokenT< std::vector< TtEvent::HypoCombPair > > >::const_iterator EventHypoToken
Definition: TtEvtBuilder.h:56
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TtEvtBuilder.h:157
edm::ParameterSet hitFit_
Definition: TtEvtBuilder.h:72
edm::EDGetTokenT< std::vector< double > > fitProbToken_
Definition: TtEvtBuilder.h:69
void setNumberOfConsideredJets(const HypoClassKey &key, const unsigned int nJets)
set number of jets considered when building a given hypothesis
Definition: TtEvent.h:162
std::string const & label() const
Definition: InputTag.h:36
genEvt_(cfg.getParameter< edm::InputTag >("genEvent"))
edm::EDGetTokenT< std::vector< double > > sumPtToken_
Definition: TtEvtBuilder.h:85
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
edm::EDGetTokenT< TtGenEvent > genEvtToken_
Definition: TtEvtBuilder.h:59
genEvtToken_(mayConsume< TtGenEvent >(genEvt_))
edm::EDGetTokenT< std::vector< double > > hitFitProbToken_
Definition: TtEvtBuilder.h:74