CMS 3D CMS Logo

HTXSRivetProducer.cc
Go to the documentation of this file.
1 /* \class HTXSRivetProducer
2  *
3  * \author David Sperka, University of Florida
4  *
5  * $Id: HTXSRivetProducer.cc,v 1.1 2016/09/27 13:07:29 dsperka Exp $
6  *
7  */
8 
14 
17 
18 #include "Rivet/AnalysisHandler.hh"
21 
22 #include <memory>
23 
24 #include <vector>
25 #include <cstdio>
26 #include <cstring>
27 
28 using namespace Rivet;
29 using namespace edm;
30 using namespace std;
31 
32 class HTXSRivetProducer : public edm::one::EDProducer<edm::one::WatchRuns, edm::one::SharedResources> {
33 public:
35  : _hepmcCollection(consumes<HepMCProduct>(cfg.getParameter<edm::InputTag>("HepMCCollection"))),
36  _lheRunInfo(consumes<LHERunInfoProduct, edm::InRun>(cfg.getParameter<edm::InputTag>("LHERunInfo"))) {
37  usesResource("Rivet");
38  _prodMode = cfg.getParameter<string>("ProductionMode");
39  m_HiggsProdMode = HTXS::UNKNOWN;
40  _HTXS = nullptr;
41  _analysisHandler = nullptr;
42  produces<HTXS::HiggsClassification>("HiggsClassification").setBranchAlias("HiggsClassification");
43  }
44 
45 private:
46  void produce(edm::Event&, const edm::EventSetup&) override;
47 
48  void beginRun(edm::Run const& iRun, edm::EventSetup const& es) override;
49  void endRun(edm::Run const& iRun, edm::EventSetup const& es) override;
50 
53 
54  std::unique_ptr<Rivet::AnalysisHandler> _analysisHandler;
56 
59 
61 };
62 
64  //get the hepmc product from the event
66 
67  bool product_exists = iEvent.getByToken(_hepmcCollection, evt);
68  if (product_exists) {
69  // get HepMC GenEvent
70  const HepMC::GenEvent* myGenEvent = evt->GetEvent();
71 
72  if (_prodMode == "AUTO") {
73  // for these prod modes, don't change what is set in BeginRun
74  if (m_HiggsProdMode != HTXS::GGF && m_HiggsProdMode != HTXS::VBF && m_HiggsProdMode != HTXS::GG2ZH) {
75  unsigned nWs = 0;
76  unsigned nZs = 0;
77  unsigned nTs = 0;
78  unsigned nBs = 0;
79  unsigned nHs = 0;
80 
81  HepMC::GenVertex* HSvtx = myGenEvent->signal_process_vertex();
82 
83  if (HSvtx) {
84  for (auto ptcl : HepMCUtils::particles(HSvtx, HepMC::children)) {
85  if (std::abs(ptcl->pdg_id()) == 24)
86  ++nWs;
87  if (ptcl->pdg_id() == 23)
88  ++nZs;
89  if (abs(ptcl->pdg_id()) == 6)
90  ++nTs;
91  if (abs(ptcl->pdg_id()) == 5)
92  ++nBs;
93  if (ptcl->pdg_id() == 25)
94  ++nHs;
95  }
96  }
97 
98  if (nZs == 1 && nHs == 1 && (nWs + nTs) == 0) {
99  m_HiggsProdMode = HTXS::QQ2ZH;
100  } else if (nWs == 1 && nHs == 1 && (nZs + nTs) == 0) {
101  m_HiggsProdMode = HTXS::WH;
102  } else if (nTs == 2 && nHs == 1 && nZs == 0) {
103  m_HiggsProdMode = HTXS::TTH;
104  } else if (nTs == 1 && nHs == 1 && nZs == 0) {
105  m_HiggsProdMode = HTXS::TH;
106  } else if (nBs == 2 && nHs == 1 && nZs == 0) {
107  m_HiggsProdMode = HTXS::BBH;
108  }
109  }
110  }
111 
112  if (!_HTXS || !_HTXS->hasProjection("FS")) {
113  _analysisHandler = std::make_unique<Rivet::AnalysisHandler>();
114  _HTXS = new Rivet::HiggsTemplateCrossSections();
115  _analysisHandler->addAnalysis(_HTXS);
116 
117  // set the production mode if not done already
118  if (_prodMode == "GGF")
119  m_HiggsProdMode = HTXS::GGF;
120  else if (_prodMode == "VBF")
121  m_HiggsProdMode = HTXS::VBF;
122  else if (_prodMode == "WH")
123  m_HiggsProdMode = HTXS::WH;
124  else if (_prodMode == "ZH")
125  m_HiggsProdMode = HTXS::QQ2ZH;
126  else if (_prodMode == "QQ2ZH")
127  m_HiggsProdMode = HTXS::QQ2ZH;
128  else if (_prodMode == "GG2ZH")
129  m_HiggsProdMode = HTXS::GG2ZH;
130  else if (_prodMode == "TTH")
131  m_HiggsProdMode = HTXS::TTH;
132  else if (_prodMode == "BBH")
133  m_HiggsProdMode = HTXS::BBH;
134  else if (_prodMode == "TH")
135  m_HiggsProdMode = HTXS::TH;
136  else if (_prodMode == "AUTO") {
137  edm::LogInfo("HTXSRivetProducer")
138  << "Using AUTO for HiggsProdMode, found it to be: " << m_HiggsProdMode << "\n";
139  edm::LogInfo("HTXSRivetProducer")
140  << "(UNKNOWN=0, GGF=1, VBF=2, WH=3, QQ2ZH=4, GG2ZH=5, TTH=6, BBH=7, TH=8)" << endl;
141  } else {
142  throw cms::Exception("HTXSRivetProducer")
143  << "ProductionMode must be one of: GGF,VBF,WH,ZH,QQ2ZH,GG2ZH,TTH,BBH,TH,AUTO ";
144  }
145  _HTXS->setHiggsProdMode(m_HiggsProdMode);
146 
147  // at this point the production mode must be known
148  if (m_HiggsProdMode == HTXS::UNKNOWN) {
149  edm::LogInfo("HTXSRivetProducer") << "HTXSRivetProducer WARNING: HiggsProduction mode is UNKNOWN" << endl;
150  }
151 
152  // initialize rivet analysis
153  _analysisHandler->init(*myGenEvent);
154  }
155 
156  // classify the event
157  Rivet::HiggsClassification rivet_cat = _HTXS->classifyEvent(*myGenEvent, m_HiggsProdMode);
158  cat_ = HTXS::Rivet2Root(rivet_cat);
159 
160  unique_ptr<HTXS::HiggsClassification> cat(new HTXS::HiggsClassification(cat_));
161 
162  iEvent.put(std::move(cat), "HiggsClassification");
163  }
164 }
165 
166 void HTXSRivetProducer::endRun(edm::Run const& iRun, edm::EventSetup const& es) {
167  if (_HTXS)
168  _HTXS->printClassificationSummary();
169 }
170 
172  if (_prodMode == "AUTO") {
174  bool product_exists = iRun.getByLabel(edm::InputTag("externalLHEProducer"), run);
175  if (product_exists) {
176  typedef std::vector<LHERunInfoProduct::Header>::const_iterator headers_const_iterator;
177  LHERunInfoProduct myLHERunInfoProduct = *(run.product());
178  for (headers_const_iterator iter = myLHERunInfoProduct.headers_begin(); iter != myLHERunInfoProduct.headers_end();
179  iter++) {
180  std::vector<std::string> lines = iter->lines();
181  for (unsigned int iLine = 0; iLine < lines.size(); iLine++) {
182  std::string line = lines.at(iLine);
183  // POWHEG
184  if (line.find("gg_H_quark-mass-effects") != std::string::npos) {
185  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
186  m_HiggsProdMode = HTXS::GGF;
187  break;
188  }
189  if (line.find("Process: HJ") != std::string::npos) {
190  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
191  m_HiggsProdMode = HTXS::GGF;
192  break;
193  }
194  if (line.find("Process: HJJ") != std::string::npos) {
195  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
196  m_HiggsProdMode = HTXS::GGF;
197  break;
198  }
199  if (line.find("VBF_H") != std::string::npos) {
200  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
201  m_HiggsProdMode = HTXS::VBF;
202  break;
203  }
204  if (line.find("HZJ") != std::string::npos) {
205  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
206  m_HiggsProdMode = HTXS::QQ2ZH;
207  break;
208  }
209  if (line.find("ggHZ") != std::string::npos) {
210  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
211  m_HiggsProdMode = HTXS::GG2ZH;
212  break;
213  }
214  // MC@NLO
215  if (line.find("ggh012j") != std::string::npos) {
216  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
217  m_HiggsProdMode = HTXS::GGF;
218  break;
219  }
220  if (line.find("vbfh") != std::string::npos) {
221  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
222  m_HiggsProdMode = HTXS::VBF;
223  break;
224  }
225  if (line.find("zh012j") != std::string::npos) {
226  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
227  m_HiggsProdMode = HTXS::QQ2ZH;
228  break;
229  }
230  if (line.find("ggzh01j") != std::string::npos) {
231  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
232  m_HiggsProdMode = HTXS::GG2ZH;
233  break;
234  }
235  }
236 
237  if (m_HiggsProdMode != HTXS::UNKNOWN)
238  break;
239  }
240  }
241  }
242 }
243 
245 
headers_const_iterator headers_begin() const
HiggsProdMode
Higgs production modes, corresponding to input sample.
HTXS::HiggsProdMode m_HiggsProdMode
std::unique_ptr< Rivet::AnalysisHandler > _analysisHandler
Rivet::HiggsTemplateCrossSections * _HTXS
headers_const_iterator headers_end() const
int iEvent
Definition: GenABIO.cc:224
def cat(path)
Definition: eostools.py:401
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void produce(edm::Event &, const edm::EventSetup &) override
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:280
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
Log< level::Info, false > LogInfo
void beginRun(edm::Run const &iRun, edm::EventSetup const &es) override
Rivet routine for classifying MC events according to the Higgs template cross section categories...
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
HLT enums.
HTXS::HiggsClassification Rivet2Root(category const &htxs_cat_rivet)
HTXS::HiggsClassification cat_
void endRun(edm::Run const &iRun, edm::EventSetup const &es) override
HTXSRivetProducer(const edm::ParameterSet &cfg)
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfo
Definition: Run.h:45