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
 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
 
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
 
std::vector< MonitorElement * > _mes
 
std::string _outFileName
 
bool _produceDQM
 
bool _useExternalWeight
 
DQMStoredbe
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- 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 23 of file RivetAnalyzer.cc.

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

23  :
25 _isFirstEvent(true),
26 _outFileName(pset.getParameter<std::string>("OutputFile")),
27 //decide whether to finlaize tthe plots or not.
28 //deciding not to finalize them can be useful for further harvesting of many jobs
29 _doFinalize(pset.getParameter<bool>("DoFinalize")),
30 _produceDQM(pset.getParameter<bool>("ProduceDQMOutput"))
31 {
32  //retrive the analysis name from paarmeter set
33  std::vector<std::string> analysisNames = pset.getParameter<std::vector<std::string> >("AnalysisNames");
34 
35  _hepmcCollection = pset.getParameter<edm::InputTag>("HepMCCollection");
36 
37  _useExternalWeight = pset.getParameter<bool>("UseExternalWeight");
38  if (_useExternalWeight) {
39  if (!pset.exists("GenEventInfoCollection")){
40  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 " ;
41  }
42  _genEventInfoCollection = pset.getParameter<edm::InputTag>("GenEventInfoCollection");
43  }
44 
45  //get the analyses
46  _analysisHandler.addAnalyses(analysisNames);
47 
48  //go through the analyses and check those that need the cross section
49  const std::set< AnaHandle, CmpAnaHandle > & analyses = _analysisHandler.analyses();
50 
51  std::set< AnaHandle, CmpAnaHandle >::const_iterator ibeg = analyses.begin();
52  std::set< AnaHandle, CmpAnaHandle >::const_iterator iend = analyses.end();
53  std::set< AnaHandle, CmpAnaHandle >::const_iterator iana;
54  double xsection = -1.;
55  xsection = pset.getParameter<double>("CrossSection");
56  for (iana = ibeg; iana != iend; ++iana){
57  if ((*iana)->needsCrossSection())
58  (*iana)->setCrossSection(xsection);
59  }
60  if (_produceDQM){
61  // book stuff needed for DQM
62  dbe = 0;
64  dbe->setVerbose(50);
65  }
66 
67 }
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:51
DQMStore * dbe
Definition: RivetAnalyzer.h:57
std::string _outFileName
Definition: RivetAnalyzer.h:53
bool _useExternalWeight
Definition: RivetAnalyzer.h:49
edm::InputTag _genEventInfoCollection
Definition: RivetAnalyzer.h:50
RivetAnalyzer::~RivetAnalyzer ( )
virtual

Definition at line 69 of file RivetAnalyzer.cc.

69  {
70 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 87 of file RivetAnalyzer.cc.

References _analysisHandler, _genEventInfoCollection, _hepmcCollection, _isFirstEvent, _useExternalWeight, edm::hlt::Exception, and edm::Event::getByLabel().

87  {
88 
89  //get the hepmc product from the event
91  iEvent.getByLabel(_hepmcCollection, evt);
92 
93  // get HepMC GenEvent
94  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
95  //if you want to use an external weight we have to clene the GenEvent and change the weight
96  if ( _useExternalWeight ){
97  HepMC::GenEvent * tmpGenEvtPtr = new HepMC::GenEvent( *(evt->GetEvent()) );
98  if (tmpGenEvtPtr->weights().size() == 0) {
99  throw cms::Exception("RivetAnalyzer") << "Original weight container has 0 size ";
100  }
101  if (tmpGenEvtPtr->weights().size() > 1) {
102  edm::LogWarning("RivetAnalyzer") << "Original event weight size is " << tmpGenEvtPtr->weights().size() << ". Will change only the first one ";
103  }
104  edm::Handle<GenEventInfoProduct> genEventInfoProduct;
105  iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct);
106  tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight();
107  myGenEvent = tmpGenEvtPtr;
108  }
109 
110 
111  //aaply the beams initialization on the first event
112  if (_isFirstEvent){
113  _analysisHandler.init(*myGenEvent);
114  _isFirstEvent = false;
115  }
116 
117  //run the analysis
118  _analysisHandler.analyze(*myGenEvent);
119 
120  //if we have cloned the GenEvent, we delete it
121  if ( _useExternalWeight )
122  delete myGenEvent;
123 }
edm::InputTag _hepmcCollection
Definition: RivetAnalyzer.h:48
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:51
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
bool _useExternalWeight
Definition: RivetAnalyzer.h:49
edm::InputTag _genEventInfoCollection
Definition: RivetAnalyzer.h:50
void RivetAnalyzer::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 72 of file RivetAnalyzer.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 83 of file RivetAnalyzer.cc.

83  {
84  return;
85 }
void RivetAnalyzer::endJob ( void  )
virtual

List of registered analysis data objects.

Reimplemented from edm::EDAnalyzer.

Definition at line 150 of file RivetAnalyzer.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 126 of file RivetAnalyzer.cc.

References _analysisHandler, _doFinalize, and _outFileName.

126  {
127  if (_doFinalize)
128  _analysisHandler.finalize();
129  else {
130  //if we don't finalize we just want to do the transformation from histograms to DPS
132  //normalizeTree();
133 
134  }
135  _analysisHandler.writeData(_outFileName);
136 
137  return;
138 }
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:51
std::string _outFileName
Definition: RivetAnalyzer.h:53
void RivetAnalyzer::normalizeTree ( )
private

Definition at line 154 of file RivetAnalyzer.cc.

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

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

Member Data Documentation

Rivet::AnalysisHandler RivetAnalyzer::_analysisHandler
private

Definition at line 51 of file RivetAnalyzer.h.

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

bool RivetAnalyzer::_doFinalize
private

Definition at line 54 of file RivetAnalyzer.h.

Referenced by endRun().

edm::InputTag RivetAnalyzer::_genEventInfoCollection
private

Definition at line 50 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 52 of file RivetAnalyzer.h.

Referenced by analyze().

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

Definition at line 58 of file RivetAnalyzer.h.

Referenced by normalizeTree().

std::string RivetAnalyzer::_outFileName
private

Definition at line 53 of file RivetAnalyzer.h.

Referenced by endRun().

bool RivetAnalyzer::_produceDQM
private

Definition at line 55 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().

DQMStore* RivetAnalyzer::dbe
private

Definition at line 57 of file RivetAnalyzer.h.

Referenced by normalizeTree(), and RivetAnalyzer().