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 
35  public:
36 
38  explicit TtEvtBuilder(const edm::ParameterSet&);
40  ~TtEvtBuilder() override{};
41 
42  private:
43 
46  void produce(edm::Event&, const edm::EventSetup&) override;
48  virtual void fillSpecific(C&, const edm::Event&);
49 
50  private:
51 
55  std::vector<edm::EDGetTokenT<int> > hypKeyTokens_;
56  std::vector<edm::EDGetTokenT<std::vector<TtEvent::HypoCombPair> > > hypTokens_;
57  std::vector<edm::EDGetTokenT<int> > hypNeutrTokens_;
58  std::vector<edm::EDGetTokenT<int> > hypJetTokens_;
59  typedef std::vector<edm::EDGetTokenT<int> >::const_iterator EventHypoIntToken;
60  typedef std::vector<edm::EDGetTokenT<std::vector<TtEvent::HypoCombPair> > >::const_iterator EventHypoToken;
68 
96 };
97 
98 template <typename C>
100  verbosity_ (cfg.getParameter<int> ("verbosity" )),
101  hypKeyTokens_ (edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("hypotheses" ), [this](edm::InputTag const & tag){return consumes<int>(edm::InputTag(tag.label(), "Key"));})),
102  hypTokens_ (edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("hypotheses" ), [this](edm::InputTag const & tag){return consumes<std::vector<TtEvent::HypoCombPair> >(tag);})),
103  hypNeutrTokens_ (edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("hypotheses" ), [this](edm::InputTag const & tag){return consumes<int>(edm::InputTag(tag.label(), "NumberOfRealNeutrinoSolutions"));})),
104  hypJetTokens_ (edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("hypotheses" ), [this](edm::InputTag const & tag){return consumes<int>(edm::InputTag(tag.label(), "NumberOfConsideredJets"));})),
105  genEvt_ (cfg.getParameter<edm::InputTag> ("genEvent" )),
106  genEvtToken_ (mayConsume<TtGenEvent>(genEvt_)),
107  decayChnTop1_(cfg.getParameter<int> ("decayChannel1")),
108  decayChnTop2_(cfg.getParameter<int> ("decayChannel2"))
109 {
110  // parameter subsets for kKinFit
111  if( cfg.exists("kinFit") ) {
112  kinFit_ = cfg.getParameter<edm::ParameterSet>("kinFit");
113  fitChi2Token_ = mayConsume<std::vector<double> >(kinFit_.getParameter<edm::InputTag>("chi2"));
114  fitProbToken_ = mayConsume<std::vector<double> >(kinFit_.getParameter<edm::InputTag>("prob"));
115  }
116  // parameter subsets for kHitFit
117  if( cfg.exists("hitFit") ) {
118  hitFit_ = cfg.getParameter<edm::ParameterSet>("hitFit");
119  hitFitChi2Token_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("chi2"));
120  hitFitProbToken_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("prob"));
121  hitFitMTToken_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("mt"));
122  hitFitSigMTToken_ = mayConsume<std::vector<double> >(hitFit_.getParameter<edm::InputTag>("sigmt"));
123  }
124  // parameter subsets for kKinSolution
125  if( cfg.exists("kinSolution") ) {
126  kinSolution_ = cfg.getParameter<edm::ParameterSet>("kinSolution");
127  solWeightToken_ = mayConsume<std::vector<double> >(kinSolution_.getParameter<edm::InputTag>("solWeight"));
128  wrongChargeToken_ = mayConsume<bool>(kinSolution_.getParameter<edm::InputTag>("wrongCharge"));
129  }
130  // parameter subsets for kGenMatch
131  if( cfg.exists("genMatch") ) {
132  genMatch_ = cfg.getParameter<edm::ParameterSet>("genMatch");
133  sumPtToken_ = mayConsume<std::vector<double> >(genMatch_.getParameter<edm::InputTag>("sumPt"));
134  sumDRToken_ = mayConsume<std::vector<double> >(genMatch_.getParameter<edm::InputTag>("sumDR"));
135  }
136  // parameter subsets for kMvaDisc
137  if( cfg.exists("mvaDisc") ) {
138  mvaDisc_ = cfg.getParameter<edm::ParameterSet>("mvaDisc");
139  methToken_ = mayConsume<std::string>(mvaDisc_.getParameter<edm::InputTag>("meth"));
140  discToken_ = mayConsume<std::vector<double> >(mvaDisc_.getParameter<edm::InputTag>("disc"));
141  }
142  // produces a TtEventEvent for:
143  // * TtSemiLeptonicEvent
144  // * TtFullLeptonicEvent
145  // * TtFullHadronicEvent
146  // from hypotheses and associated extra information
147  produces<C>();
148 }
149 
150 template <typename C>
151 void
153 {
154  C ttEvent;
155 
156  // set leptonic decay channels
158 
159  // set genEvent (if available)
161  if ( !genEvt_.label().empty() )
162  if( evt.getByToken(genEvtToken_, genEvt) )
163  ttEvent.setGenEvent(genEvt);
164 
165  // add event hypotheses for all given
166  // hypothesis classes to the TtEvent
167  EventHypoIntToken hKey = hypKeyTokens_.begin();
168  EventHypoToken h = hypTokens_.begin();
169  for( ; hKey != hypKeyTokens_.end(); ++hKey, ++h){
171  evt.getByToken(*hKey, key);
172 
174  evt.getByToken(*h, hypMatchVec);
175 
176  typedef std::vector<TtEvent::HypoCombPair>::const_iterator HypMatch;
177  for(HypMatch hm=hypMatchVec->begin(); hm != hypMatchVec->end(); ++hm){
178  ttEvent.addEventHypo((TtEvent::HypoClassKey&)*key, *hm);
179  }
180  }
181 
182  // set kKinFit extras
183  if( ttEvent.isHypoAvailable(TtEvent::kKinFit) ) {
185  evt.getByToken(fitChi2Token_, fitChi2);
186  ttEvent.setFitChi2( *fitChi2 );
187 
189  evt.getByToken(fitProbToken_, fitProb);
190  ttEvent.setFitProb( *fitProb );
191  }
192 
193  // set kHitFit extras
194  if( ttEvent.isHypoAvailable(TtEvent::kHitFit) ) {
195  edm::Handle<std::vector<double> > hitFitChi2;
196  evt.getByToken(hitFitChi2Token_, hitFitChi2);
197  ttEvent.setHitFitChi2( *hitFitChi2 );
198 
199  edm::Handle<std::vector<double> > hitFitProb;
200  evt.getByToken(hitFitProbToken_, hitFitProb);
201  ttEvent.setHitFitProb( *hitFitProb );
202 
204  evt.getByToken(hitFitMTToken_, hitFitMT);
205  ttEvent.setHitFitMT( *hitFitMT );
206 
207  edm::Handle<std::vector<double> > hitFitSigMT;
208  evt.getByToken(hitFitSigMTToken_, hitFitSigMT);
209  ttEvent.setHitFitSigMT( *hitFitSigMT );
210  }
211 
212  // set kGenMatch extras
213  if( ttEvent.isHypoAvailable(TtEvent::kGenMatch) ) {
215  evt.getByToken(sumPtToken_, sumPt);
216  ttEvent.setGenMatchSumPt( *sumPt );
217 
219  evt.getByToken(sumDRToken_, sumDR);
220  ttEvent.setGenMatchSumDR( *sumDR );
221  }
222 
223  // set kMvaDisc extras
224  if( ttEvent.isHypoAvailable(TtEvent::kMVADisc) ) {
226  evt.getByToken(methToken_, meth);
227  ttEvent.setMvaMethod( *meth );
228 
230  evt.getByToken(discToken_, disc);
231  ttEvent.setMvaDiscriminators( *disc );
232  }
233 
234  // fill data members that are decay-channel specific
235  fillSpecific(ttEvent, evt);
236 
237  // print summary via MessageLogger if verbosity_>0
238  ttEvent.print(verbosity_);
239 
240  // write object into the edm::Event
241  std::unique_ptr<C> pOut(new C);
242  *pOut=ttEvent;
243  evt.put(std::move(pOut));
244 }
245 
246 template <>
248 {
249 }
250 
251 template <>
253 {
254 
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 
268 template <>
270 {
271 
272  EventHypoIntToken hKey = hypKeyTokens_.begin();
273  EventHypoIntToken hNeutr = hypNeutrTokens_.begin();
274  EventHypoIntToken hJet = hypJetTokens_.begin();
275  for( ; hKey != hypKeyTokens_.end(); ++hKey, ++hNeutr, ++hJet){
277  evt.getByToken(*hKey, key);
278 
279  // set number of real neutrino solutions for all hypotheses
280  edm::Handle<int> numberOfRealNeutrinoSolutions;
281  evt.getByToken(*hNeutr, numberOfRealNeutrinoSolutions);
282  ttEvent.setNumberOfRealNeutrinoSolutions((TtEvent::HypoClassKey&)*key, *numberOfRealNeutrinoSolutions);
283 
284  // set number of considered jets for all hypotheses
285  edm::Handle<int> numberOfConsideredJets;
286  evt.getByToken(*hJet, numberOfConsideredJets);
287  ttEvent.setNumberOfConsideredJets((TtEvent::HypoClassKey&)*key, *numberOfConsideredJets);
288  }
289 
290 }
291 
292 #endif
edm::EDGetTokenT< std::vector< double > > solWeightToken_
Definition: TtEvtBuilder.h:84
void setWrongCharge(const bool &val)
set right or wrong charge combination of kKinSolution hypothesis
T getParameter(std::string const &) const
HypoClassKey
supported classes of event hypotheses
Definition: TtEvent.h:31
bool isHypoAvailable(const std::string &key, const unsigned &cmb=0) const
Definition: TtEvent.h:60
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
edm::EDGetTokenT< std::vector< double > > hitFitMTToken_
Definition: TtEvtBuilder.h:79
edm::EDGetTokenT< std::string > methToken_
Definition: TtEvtBuilder.h:94
TtEvtBuilder(const edm::ParameterSet &)
default constructor
Definition: TtEvtBuilder.h:99
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::InputTag genEvt_
TtGenEvent.
Definition: TtEvtBuilder.h:62
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:56
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::vector< edm::EDGetTokenT< int > >::const_iterator EventHypoIntToken
Definition: TtEvtBuilder.h:59
static double fitChi2(const CachingVertex< 5 > &vtx)
edm::ParameterSet genMatch_
Definition: TtEvtBuilder.h:88
std::vector< edm::EDGetTokenT< int > > hypNeutrTokens_
Definition: TtEvtBuilder.h:57
edm::EDGetTokenT< std::vector< double > > sumDRToken_
Definition: TtEvtBuilder.h:90
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:55
virtual void fillSpecific(C &, const edm::Event &)
fill data members that are decay-channel specific
edm::EDGetTokenT< std::vector< double > > discToken_
Definition: TtEvtBuilder.h:95
std::vector< edm::EDGetTokenT< int > > hypJetTokens_
Definition: TtEvtBuilder.h:58
int verbosity_
vebosity level
Definition: TtEvtBuilder.h:53
edm::EDGetTokenT< std::vector< double > > hitFitSigMTToken_
Definition: TtEvtBuilder.h:80
edm::ParameterSet mvaDisc_
Definition: TtEvtBuilder.h:93
edm::EDGetTokenT< bool > wrongChargeToken_
Definition: TtEvtBuilder.h:85
~TtEvtBuilder() override
default destructor
Definition: TtEvtBuilder.h:40
Class derived from the TtEvent for the full leptonic decay channel.
edm::EDGetTokenT< std::vector< double > > fitChi2Token_
Definition: TtEvtBuilder.h:72
void setSolWeight(const std::vector< double > &val)
set weight of kKinSolution hypothesis
edm::ParameterSet kinFit_
Definition: TtEvtBuilder.h:71
edm::ParameterSet kinSolution_
Definition: TtEvtBuilder.h:83
Class derived from the TtEvent for the full hadronic decay channel.
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
edm::EDGetTokenT< std::vector< double > > hitFitChi2Token_
Definition: TtEvtBuilder.h:77
std::vector< edm::EDGetTokenT< std::vector< TtEvent::HypoCombPair > > >::const_iterator EventHypoToken
Definition: TtEvtBuilder.h:60
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TtEvtBuilder.h:152
edm::ParameterSet hitFit_
Definition: TtEvtBuilder.h:76
edm::EDGetTokenT< std::vector< double > > fitProbToken_
Definition: TtEvtBuilder.h:73
void setNumberOfConsideredJets(const HypoClassKey &key, const unsigned int nJets)
set number of jets considered when building a given hypothesis
Definition: TtEvent.h:123
std::string const & label() const
Definition: InputTag.h:36
HLT enums.
edm::EDGetTokenT< std::vector< double > > sumPtToken_
Definition: TtEvtBuilder.h:89
edm::EDGetTokenT< TtGenEvent > genEvtToken_
Definition: TtEvtBuilder.h:63
edm::EDGetTokenT< std::vector< double > > hitFitProbToken_
Definition: TtEvtBuilder.h:78
def move(src, dest)
Definition: eostools.py:511