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) { _HTXS->printClassificationSummary(); }
167 
169  if (_prodMode == "AUTO") {
171  bool product_exists = iRun.getByLabel(edm::InputTag("externalLHEProducer"), run);
172  if (product_exists) {
173  typedef std::vector<LHERunInfoProduct::Header>::const_iterator headers_const_iterator;
174  LHERunInfoProduct myLHERunInfoProduct = *(run.product());
175  for (headers_const_iterator iter = myLHERunInfoProduct.headers_begin(); iter != myLHERunInfoProduct.headers_end();
176  iter++) {
177  std::vector<std::string> lines = iter->lines();
178  for (unsigned int iLine = 0; iLine < lines.size(); iLine++) {
179  std::string line = lines.at(iLine);
180  // POWHEG
181  if (line.find("gg_H_quark-mass-effects") != std::string::npos) {
182  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
183  m_HiggsProdMode = HTXS::GGF;
184  break;
185  }
186  if (line.find("Process: HJ") != std::string::npos) {
187  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
188  m_HiggsProdMode = HTXS::GGF;
189  break;
190  }
191  if (line.find("Process: HJJ") != std::string::npos) {
192  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
193  m_HiggsProdMode = HTXS::GGF;
194  break;
195  }
196  if (line.find("VBF_H") != std::string::npos) {
197  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
198  m_HiggsProdMode = HTXS::VBF;
199  break;
200  }
201  if (line.find("HZJ") != std::string::npos) {
202  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
203  m_HiggsProdMode = HTXS::QQ2ZH;
204  break;
205  }
206  if (line.find("ggHZ") != std::string::npos) {
207  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
208  m_HiggsProdMode = HTXS::GG2ZH;
209  break;
210  }
211  // MC@NLO
212  if (line.find("ggh012j") != std::string::npos) {
213  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
214  m_HiggsProdMode = HTXS::GGF;
215  break;
216  }
217  if (line.find("vbfh") != std::string::npos) {
218  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
219  m_HiggsProdMode = HTXS::VBF;
220  break;
221  }
222  if (line.find("zh012j") != std::string::npos) {
223  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
224  m_HiggsProdMode = HTXS::QQ2ZH;
225  break;
226  }
227  if (line.find("ggzh01j") != std::string::npos) {
228  edm::LogInfo("HTXSRivetProducer") << iLine << " " << line << std::endl;
229  m_HiggsProdMode = HTXS::GG2ZH;
230  break;
231  }
232  }
233 
234  if (m_HiggsProdMode != HTXS::UNKNOWN)
235  break;
236  }
237  }
238  }
239 }
240 
242 
Ecal2004TBTDCRanges_v1_cff.endRun
endRun
Definition: Ecal2004TBTDCRanges_v1_cff.py:4
EDProducer.h
MessageLogger.h
HTXS::GG2ZH
Definition: HiggsTemplateCrossSections.h:25
HTXS::UNKNOWN
Definition: HiggsTemplateCrossSections.h:25
HTXS::TTH
Definition: HiggsTemplateCrossSections.h:25
HTXSRivetProducer::_lheRunInfo
edm::EDGetTokenT< LHERunInfoProduct > _lheRunInfo
Definition: HTXSRivetProducer.cc:52
HiggsTemplateCrossSections.cc
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< edm::HepMCProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
Rivet
Definition: RivetAnalysis.h:21
class-composition.children
children
Definition: class-composition.py:88
eostools.cat
def cat(path)
Definition: eostools.py:401
HTXS::GGF
Definition: HiggsTemplateCrossSections.h:25
Rivet::HiggsTemplateCrossSections
Rivet routine for classifying MC events according to the Higgs template cross section categories.
Definition: HiggsTemplateCrossSections.cc:21
HTXSRivetProducer
Definition: HTXSRivetProducer.cc:32
edm::one::EDProducer
Definition: EDProducer.h:30
LHERunInfoProduct::headers_end
headers_const_iterator headers_end() const
Definition: LHERunInfoProduct.h:59
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::InRun
Definition: BranchType.h:11
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
HiggsTemplateCrossSections.h
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
HTXSRivetProducer::m_HiggsProdMode
HTXS::HiggsProdMode m_HiggsProdMode
Definition: HTXSRivetProducer.cc:58
HTXSRivetProducer::_analysisHandler
std::unique_ptr< Rivet::AnalysisHandler > _analysisHandler
Definition: HTXSRivetProducer.cc:54
LHERunInfoProduct::headers_begin
headers_const_iterator headers_begin() const
Definition: LHERunInfoProduct.h:58
LHERunInfoProduct.h
MakerMacros.h
LHERunInfoProduct
Definition: LHERunInfoProduct.h:13
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Run.h
HTXS::Rivet2Root
HTXS::HiggsClassification Rivet2Root(category const &htxs_cat_rivet)
Definition: HiggsTemplateCrossSections.h:548
HTXSRivetProducer::_HTXS
Rivet::HiggsTemplateCrossSections * _HTXS
Definition: HTXSRivetProducer.cc:55
HTXSRivetProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HTXSRivetProducer.cc:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
groupFilesInBlocks.lines
lines
Definition: groupFilesInBlocks.py:95
Event.h
HTXSRivetProducer::_hepmcCollection
edm::EDGetTokenT< edm::HepMCProduct > _hepmcCollection
Definition: HTXSRivetProducer.cc:51
iEvent
int iEvent
Definition: GenABIO.cc:224
HTXSRivetProducer::beginRun
void beginRun(edm::Run const &iRun, edm::EventSetup const &es) override
Definition: HTXSRivetProducer.cc:168
HTXS::HiggsProdMode
HiggsProdMode
Higgs production modes, corresponding to input sample.
Definition: HiggsTemplateCrossSections.h:25
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
looper.cfg
cfg
Definition: looper.py:297
HTXSRivetProducer::cat_
HTXS::HiggsClassification cat_
Definition: HTXSRivetProducer.cc:60
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HTXS::HiggsClassification
Definition: HiggsTemplateCrossSections.h:514
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Exception
Definition: hltDiff.cc:246
HTXSRivetProducer::HTXSRivetProducer
HTXSRivetProducer(const edm::ParameterSet &cfg)
Definition: HTXSRivetProducer.cc:34
HTXSRivetProducer::_prodMode
std::string _prodMode
Definition: HTXSRivetProducer.cc:57
edm::Run::getByLabel
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:281
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::HepMCProduct
Definition: HepMCProduct.h:18
ParameterSet.h
HepMCProduct.h
HTXSRivetProducer::endRun
void endRun(edm::Run const &iRun, edm::EventSetup const &es) override
Definition: HTXSRivetProducer.cc:166
HTXS::TH
Definition: HiggsTemplateCrossSections.h:25
edm::Event
Definition: Event.h:73
mps_splice.line
line
Definition: mps_splice.py:76
edm::InputTag
Definition: InputTag.h:15
HTXS::WH
Definition: HiggsTemplateCrossSections.h:25
HTXS::VBF
Definition: HiggsTemplateCrossSections.h:25
HTXS::BBH
Definition: HiggsTemplateCrossSections.h:25
HTXS::QQ2ZH
Definition: HiggsTemplateCrossSections.h:25