CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
RivetAnalyzer Class Reference

#include <RivetAnalyzer.h>

Inheritance diagram for RivetAnalyzer:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &)
 
virtual void endJob ()
 List of registered analysis data objects. More...
 
virtual void endRun (const edm::Run &, const edm::EventSetup &)
 
 RivetAnalyzer (const edm::ParameterSet &)
 
virtual ~RivetAnalyzer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

void normalizeTree ()
 

Private Attributes

Rivet::AnalysisHandler _analysisHandler
 
bool _doFinalize
 
edm::InputTag _genEventInfoCollection
 
edm::InputTag _hepmcCollection
 
bool _isFirstEvent
 
edm::InputTag _LHECollection
 
int _LHEweightNumber
 
std::vector< MonitorElement * > _mes
 
std::string _outFileName
 
bool _produceDQM
 
bool _useExternalWeight
 
bool _useLHEweights
 
DQMStoredbe
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 27 of file RivetAnalyzer.h.

Constructor & Destructor Documentation

RivetAnalyzer::RivetAnalyzer ( const edm::ParameterSet pset)

Definition at line 24 of file RivetAnalyzer.cc.

References _analysisHandler, _genEventInfoCollection, _hepmcCollection, _LHECollection, _LHEweightNumber, _produceDQM, _useExternalWeight, _useLHEweights, dbe, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), and cppFunctionSkipper::operator.

24  :
26 _isFirstEvent(true),
27 _outFileName(pset.getParameter<std::string>("OutputFile")),
28 //decide whether to finlaize tthe plots or not.
29 //deciding not to finalize them can be useful for further harvesting of many jobs
30 _doFinalize(pset.getParameter<bool>("DoFinalize")),
31 _produceDQM(pset.getParameter<bool>("ProduceDQMOutput"))
32 {
33  //retrive the analysis name from paarmeter set
34  std::vector<std::string> analysisNames = pset.getParameter<std::vector<std::string> >("AnalysisNames");
35 
36  _hepmcCollection = pset.getParameter<edm::InputTag>("HepMCCollection");
37 
38  _useExternalWeight = pset.getParameter<bool>("UseExternalWeight");
39  if (_useExternalWeight) {
40  if (!pset.exists("GenEventInfoCollection")){
41  throw cms::Exception("RivetAnalyzer") << "when using an external event weight you have to specify the GenEventInfoProduct collection from which the weight has to be taken " ;
42  }
43  _genEventInfoCollection = pset.getParameter<edm::InputTag>("GenEventInfoCollection");
44  _LHECollection = pset.getParameter<edm::InputTag>("LHECollection");
45  _useLHEweights = pset.getParameter<bool>("useLHEweights");
46  _LHEweightNumber = pset.getParameter<int>("LHEweightNumber");
47 
48  }
49 
50  //get the analyses
51  _analysisHandler.addAnalyses(analysisNames);
52 
53  //go through the analyses and check those that need the cross section
54  const std::set< AnaHandle, CmpAnaHandle > & analyses = _analysisHandler.analyses();
55 
56  std::set< AnaHandle, CmpAnaHandle >::const_iterator ibeg = analyses.begin();
57  std::set< AnaHandle, CmpAnaHandle >::const_iterator iend = analyses.end();
58  std::set< AnaHandle, CmpAnaHandle >::const_iterator iana;
59  double xsection = -1.;
60  xsection = pset.getParameter<double>("CrossSection");
61  for (iana = ibeg; iana != iend; ++iana){
62  if ((*iana)->needsCrossSection())
63  (*iana)->setCrossSection(xsection);
64  }
65  if (_produceDQM){
66  // book stuff needed for DQM
67  dbe = 0;
69  dbe->setVerbose(50);
70  }
71 
72 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::InputTag _hepmcCollection
Definition: RivetAnalyzer.h:48
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:54
DQMStore * dbe
Definition: RivetAnalyzer.h:60
std::string _outFileName
Definition: RivetAnalyzer.h:56
edm::InputTag _LHECollection
Definition: RivetAnalyzer.h:52
bool _useExternalWeight
Definition: RivetAnalyzer.h:49
edm::InputTag _genEventInfoCollection
Definition: RivetAnalyzer.h:53
RivetAnalyzer::~RivetAnalyzer ( )
virtual

Definition at line 74 of file RivetAnalyzer.cc.

74  {
75 }

Member Function Documentation

void RivetAnalyzer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 92 of file RivetAnalyzer.cc.

References _analysisHandler, _genEventInfoCollection, _hepmcCollection, _isFirstEvent, _LHECollection, _LHEweightNumber, _useExternalWeight, _useLHEweights, Exception, edm::Event::getByLabel(), and gen::WeightsInfo::wgt.

92  {
93 
94  //get the hepmc product from the event
96  iEvent.getByLabel(_hepmcCollection, evt);
97 
98  // get HepMC GenEvent
99  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
100 
101  //if you want to use an external weight we have to clone the GenEvent and change the weight
102  if ( _useExternalWeight ){
103 
104  HepMC::GenEvent * tmpGenEvtPtr = new HepMC::GenEvent( *(evt->GetEvent()) );
105  if (tmpGenEvtPtr->weights().size() == 0) {
106  throw cms::Exception("RivetAnalyzer") << "Original weight container has 0 size ";
107  }
108  if (tmpGenEvtPtr->weights().size() > 1) {
109  edm::LogWarning("RivetAnalyzer") << "Original event weight size is " << tmpGenEvtPtr->weights().size() << ". Will change only the first one ";
110  }
111 
112  if(!_useLHEweights){
113  edm::Handle<GenEventInfoProduct> genEventInfoProduct;
114  iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct);
115  tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight();
116  }else{
117  edm::Handle<LHEEventProduct> lheEventHandle;
118  iEvent.getByLabel(_LHECollection,lheEventHandle);
119  const LHEEventProduct::WGT& wgt = lheEventHandle->weights().at(_LHEweightNumber);
120  tmpGenEvtPtr->weights()[0] = wgt.wgt;
121  }
122  myGenEvent = tmpGenEvtPtr;
123 
124  }
125 
126 
127  //aaply the beams initialization on the first event
128  if (_isFirstEvent){
129  _analysisHandler.init(*myGenEvent);
130  _isFirstEvent = false;
131  }
132 
133  //run the analysis
134  _analysisHandler.analyze(*myGenEvent);
135 
136  //if we have cloned the GenEvent, we delete it
137  if ( _useExternalWeight )
138  delete myGenEvent;
139 }
edm::InputTag _hepmcCollection
Definition: RivetAnalyzer.h:48
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:54
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
edm::InputTag _LHECollection
Definition: RivetAnalyzer.h:52
bool _useExternalWeight
Definition: RivetAnalyzer.h:49
edm::InputTag _genEventInfoCollection
Definition: RivetAnalyzer.h:53
void RivetAnalyzer::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 77 of file RivetAnalyzer.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

77  {
78  //set the environment, very ugly but rivet is monolithic when it comes to paths
79  char * cmsswbase = getenv("CMSSW_BASE");
80  char * cmsswrelease = getenv("CMSSW_RELEASE_BASE");
81  std::string rivetref, rivetinfo;
82  rivetref = "RIVET_REF_PATH=" + string(cmsswbase) + "/src/GeneratorInterface/RivetInterface/data:" + string(cmsswrelease) + "/src/GeneratorInterface/RivetInterface/data";
83  rivetinfo = "RIVET_INFO_PATH=" + string(cmsswbase) + "/src/GeneratorInterface/RivetInterface/data:" + string(cmsswrelease) + "/src/GeneratorInterface/RivetInterface/data";
84  putenv(strdup(rivetref.c_str()));
85  putenv(strdup(rivetinfo.c_str()));
86 }
void RivetAnalyzer::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 88 of file RivetAnalyzer.cc.

88  {
89  return;
90 }
void RivetAnalyzer::endJob ( void  )
virtual

List of registered analysis data objects.

Reimplemented from edm::EDAnalyzer.

Definition at line 166 of file RivetAnalyzer.cc.

166  {
167 }
void RivetAnalyzer::endRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 142 of file RivetAnalyzer.cc.

References _analysisHandler, _doFinalize, and _outFileName.

142  {
143  if (_doFinalize)
144  _analysisHandler.finalize();
145  else {
146  //if we don't finalize we just want to do the transformation from histograms to DPS
148  //normalizeTree();
149 
150  }
151  _analysisHandler.writeData(_outFileName);
152 
153  return;
154 }
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:54
std::string _outFileName
Definition: RivetAnalyzer.h:56
void RivetAnalyzer::normalizeTree ( )
private

Definition at line 170 of file RivetAnalyzer.cc.

References _analysisHandler, _mes, _produceDQM, dbe, and nevent.

170  {
171  using namespace YODA;
172  std::vector<string> analyses = _analysisHandler.analysisNames();
173 
174  //tree.ls(".", true);
175  const string tmpdir = "/RivetNormalizeTmp";
176  //tree.mkdir(tmpdir);
177  foreach (const string& analysis, analyses) {
178  if (_produceDQM){
179  dbe->setCurrentFolder(("Rivet/"+analysis).c_str());
180  //global variables that are always present
181  //sumOfWeights
182  TH1F nevent("nEvt", "n analyzed Events", 1, 0., 1.);
183  nevent.SetBinContent(1,_analysisHandler.sumOfWeights());
184  _mes.push_back(dbe->book1D("nEvt",&nevent));
185  }
186  //cross section
187  //TH1F xsection("xSection", "Cross Section", 1, 0., 1.);
188  //xsection.SetBinContent(1,_analysisHandler.crossSection());
189  //_mes.push_back(dbe->book1D("xSection",&xsection));
190  //now loop over the histograms
191 
192  /*
193  const vector<string> paths = tree.listObjectNames("/"+analysis, true); // args set recursive listing
194  std::cout << "Number of objects in YODA tree for analysis " << analysis << " = " << paths.size() << std::endl;
195  foreach (const string& path, paths) {
196  IManagedObject* hobj = tree.find(path);
197  if (hobj) {
198  // Weird seg fault on SLC4 when trying to dyn cast an IProfile ptr to a IHistogram
199  // Fix by attempting to cast to IProfile first, only try IHistogram if it fails.
200  IHistogram1D* histo = 0;
201  IProfile1D* prof = dynamic_cast<IProfile1D*>(hobj);
202  if (!prof) histo = dynamic_cast<IHistogram1D*>(hobj);
203 
204  std::cout << "Converting histo " << path << " to DPS" << std::endl;
205  tree.mv(path, tmpdir);
206  const size_t lastslash = path.find_last_of("/");
207  const string basename = path.substr(lastslash+1, path.length() - (lastslash+1));
208  const string tmppath = tmpdir + "/" + basename;
209 
210  // If it's a normal histo:
211  if (histo) {
212  IHistogram1D* tmphisto = dynamic_cast<IHistogram1D*>(tree.find(tmppath));
213  if (tmphisto) {
214  _analysisHandler.datapointsetFactory().create(path, *tmphisto);
215  }
216  //now convert to root and then ME
217  //need aida2flat (from Rivet 1.X) & flat2root here
218  TH1F* h = aida2root<IHistogram1D, TH1F>(histo, basename);
219  if (_produceDQM)
220  _mes.push_back(dbe->book1D(h->GetName(), h));
221  delete h;
222  tree.rm(tmppath);
223  }
224  // If it's a profile histo:
225  else if (prof) {
226  IProfile1D* tmpprof = dynamic_cast<IProfile1D*>(tree.find(tmppath));
227  if (tmpprof) {
228  _analysisHandler.datapointsetFactory().create(path, *tmpprof);
229  }
230  //now convert to root and then ME
231  //need aida2flat (from Rivet 1.X) & flat2root here
232  TProfile* p = aida2root<IProfile1D, TProfile>(prof, basename);
233  if (_produceDQM)
234  _mes.push_back(dbe->bookProfile(p->GetName(), p));
235  delete p;
236  tree.rm(tmppath);
237  }
238  }
239  }
240  */
241  }
242  //tree.rmdir(tmpdir);
243 
244 }
int nevent
Definition: AMPTWrapper.h:74
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:54
DQMStore * dbe
Definition: RivetAnalyzer.h:60
std::vector< MonitorElement * > _mes
Definition: RivetAnalyzer.h:61

Member Data Documentation

Rivet::AnalysisHandler RivetAnalyzer::_analysisHandler
private

Definition at line 54 of file RivetAnalyzer.h.

Referenced by analyze(), endRun(), normalizeTree(), and RivetAnalyzer().

bool RivetAnalyzer::_doFinalize
private

Definition at line 57 of file RivetAnalyzer.h.

Referenced by endRun().

edm::InputTag RivetAnalyzer::_genEventInfoCollection
private

Definition at line 53 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

edm::InputTag RivetAnalyzer::_hepmcCollection
private

Definition at line 48 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

bool RivetAnalyzer::_isFirstEvent
private

Definition at line 55 of file RivetAnalyzer.h.

Referenced by analyze().

edm::InputTag RivetAnalyzer::_LHECollection
private

Definition at line 52 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

int RivetAnalyzer::_LHEweightNumber
private

Definition at line 51 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

std::vector<MonitorElement *> RivetAnalyzer::_mes
private

Definition at line 61 of file RivetAnalyzer.h.

Referenced by normalizeTree().

std::string RivetAnalyzer::_outFileName
private

Definition at line 56 of file RivetAnalyzer.h.

Referenced by endRun().

bool RivetAnalyzer::_produceDQM
private

Definition at line 58 of file RivetAnalyzer.h.

Referenced by normalizeTree(), and RivetAnalyzer().

bool RivetAnalyzer::_useExternalWeight
private

Definition at line 49 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

bool RivetAnalyzer::_useLHEweights
private

Definition at line 50 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

DQMStore* RivetAnalyzer::dbe
private

Definition at line 60 of file RivetAnalyzer.h.

Referenced by normalizeTree(), and RivetAnalyzer().