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

template<>
TH1F * aida2root (const AIDA::IHistogram1D *aidah, const std::string &name)
 
template<>
TProfile * aida2root (const AIDA::IProfile1D *aidah, const std::string &name)
 
virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &)
 
virtual void endJob ()
 
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
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

template<class AIDATYPE , class ROOTTYPE >
ROOTTYPE * aida2root (const AIDATYPE *, const std::string &)
 
void normalizeTree (AIDA::ITree &tree)
 
template<class AIDATYPE , class ROOTTYPE >
ROOTTYPE * prebook (const AIDATYPE *, const std::string &)
 

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 28 of file RivetAnalyzer.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file RivetAnalyzer.cc.

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

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

Definition at line 71 of file RivetAnalyzer.cc.

71  {
72 }

Member Function Documentation

template<class AIDATYPE , class ROOTTYPE >
ROOTTYPE* RivetAnalyzer::aida2root ( const AIDATYPE *  ,
const std::string &   
)
private
template<>
TH1F* RivetAnalyzer::aida2root ( const AIDA::IHistogram1D *  aidah,
const std::string &  name 
)

Definition at line 91 of file RivetAnalyzer.h.

References h, i, and mergeVDriftHistosByStation::name.

91  {
92  /*TH1F* h = 0;
93  if (aidah->axis().isFixedBinning() ) {//equidistant binning (easier case)
94  int nbins = aidah->axis().bins();
95  h = new TH1F(name.c_str(), name.c_str(), nbins, aidah->axis().lowerEdge(), aidah->axis().upperEdge());
96  } else {
97  int nbins = aidah->axis().bins();
98  //need to dyn cast, IAxis lacks polymorfism
99  const LWH::VariAxis* vax = dynamic_cast<const LWH::VariAxis*>(&aidah->axis());
100  if (! vax ){
101  throw cms::Exception("RivetAnalyzer") << "Cannot dynamix cast an AIDA axis to VariAxis ";
102  }
103  double* bins = new double[nbins+1];
104  for (int i=0; i<nbins; ++i) {
105  bins[i] = vax->binEdges(i).first;
106  }
107  bins[nbins] = vax->binEdges(nbins-1).second; //take last bin right border
108  h = new TH1F(name.c_str(), name.c_str(), nbins, bins);
109  delete bins;
110  }
111  */
112  TH1F* h = prebook<AIDA::IHistogram1D, TH1F>(aidah, name);
113  for (int i = 0; i < aidah->axis().bins(); ++i){
114  h->SetBinContent(i+1, aidah->binHeight(i));
115  h->SetBinError(i+1, aidah->binError(i));
116  }
117  return h;
118 }
int i
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
template<>
TProfile* RivetAnalyzer::aida2root ( const AIDA::IProfile1D *  aidah,
const std::string &  name 
)

Definition at line 121 of file RivetAnalyzer.h.

References h, i, and mergeVDriftHistosByStation::name.

121  {
122  TProfile* h = prebook<AIDA::IProfile1D, TProfile>(aidah, name);
123  for (int i = 0; i < aidah->axis().bins(); ++i){
124  h->SetBinContent(i+1, aidah->binMean(i));
125  h->SetBinError(i+1, aidah->binRms(i));
126  }
127  return h;
128 }
int i
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void RivetAnalyzer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 89 of file RivetAnalyzer.cc.

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

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

Reimplemented from edm::EDAnalyzer.

Definition at line 74 of file RivetAnalyzer.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 85 of file RivetAnalyzer.cc.

85  {
86  return;
87 }
void RivetAnalyzer::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 140 of file RivetAnalyzer.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 128 of file RivetAnalyzer.cc.

References _analysisHandler, _doFinalize, _outFileName, and normalizeTree().

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

Definition at line 143 of file RivetAnalyzer.cc.

References _analysisHandler, _mes, _produceDQM, DQMStore::book1D(), DQMStore::bookProfile(), gather_cfg::cout, dbe, h, timingPdfMaker::histo, nevent, AlCaHLTBitMon_ParallelJobs::p, getHLTPrescaleColumns::path, EgammaValidation_cff::paths, and DQMStore::setCurrentFolder().

Referenced by endRun().

143  {
144  using namespace AIDA;
145  std::vector<string> analyses = _analysisHandler.analysisNames();
146  tree.ls(".", true);
147  const string tmpdir = "/RivetNormalizeTmp";
148  tree.mkdir(tmpdir);
149  foreach (const string& analysis, analyses) {
150  if (_produceDQM){
151  dbe->setCurrentFolder(("Rivet/"+analysis).c_str());
152  //global variables that are always present
153  //sumOfWeights
154  TH1F nevent("nEvt", "n analyzed Events", 1, 0., 1.);
155  nevent.SetBinContent(1,_analysisHandler.sumOfWeights());
156  _mes.push_back(dbe->book1D("nEvt",&nevent));
157  }
158  //cross section
159  //TH1F xsection("xSection", "Cross Section", 1, 0., 1.);
160  //xsection.SetBinContent(1,_analysisHandler.crossSection());
161  //_mes.push_back(dbe->book1D("xSection",&xsection));
162  //now loop over the histograms
163  const vector<string> paths = tree.listObjectNames("/"+analysis, true); // args set recursive listing
164  std::cout << "Number of objects in AIDA tree for analysis " << analysis << " = " << paths.size() << std::endl;
165  foreach (const string& path, paths) {
166  IManagedObject* hobj = tree.find(path);
167  if (hobj) {
168  // Weird seg fault on SLC4 when trying to dyn cast an IProfile ptr to a IHistogram
169  // Fix by attempting to cast to IProfile first, only try IHistogram if it fails.
170  IHistogram1D* histo = 0;
171  IProfile1D* prof = dynamic_cast<IProfile1D*>(hobj);
172  if (!prof) histo = dynamic_cast<IHistogram1D*>(hobj);
173 
174  std::cout << "Converting histo " << path << " to DPS" << std::endl;
175  tree.mv(path, tmpdir);
176  const size_t lastslash = path.find_last_of("/");
177  const string basename = path.substr(lastslash+1, path.length() - (lastslash+1));
178  const string tmppath = tmpdir + "/" + basename;
179 
180  // If it's a normal histo:
181  if (histo) {
182  IHistogram1D* tmphisto = dynamic_cast<IHistogram1D*>(tree.find(tmppath));
183  if (tmphisto) {
184  _analysisHandler.datapointsetFactory().create(path, *tmphisto);
185  }
186  //now convert to root and then ME
187  TH1F* h = aida2root<IHistogram1D, TH1F>(histo, basename);
188  if (_produceDQM)
189  _mes.push_back(dbe->book1D(h->GetName(), h));
190  delete h;
191  tree.rm(tmppath);
192  }
193  // If it's a profile histo:
194  else if (prof) {
195  IProfile1D* tmpprof = dynamic_cast<IProfile1D*>(tree.find(tmppath));
196  if (tmpprof) {
197  _analysisHandler.datapointsetFactory().create(path, *tmpprof);
198  }
199  //now convert to root and then ME
200  TProfile* p = aida2root<IProfile1D, TProfile>(prof, basename);
201  if (_produceDQM)
202  _mes.push_back(dbe->bookProfile(p->GetName(), p));
203  delete p;
204  tree.rm(tmppath);
205  }
206  }
207  }
208  }
209  tree.rmdir(tmpdir);
210 }
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:873
int nevent
Definition: AMPTWrapper.h:74
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:55
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1187
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
DQMStore * dbe
Definition: RivetAnalyzer.h:61
tuple cout
Definition: gather_cfg.py:121
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:585
std::vector< MonitorElement * > _mes
Definition: RivetAnalyzer.h:62
template<class AIDATYPE , class ROOTTYPE >
ROOTTYPE * RivetAnalyzer::prebook ( const AIDATYPE *  aidah,
const std::string &  name 
)
private

Definition at line 67 of file RivetAnalyzer.h.

References edm::hlt::Exception, h, i, and pileupCalc::nbins.

67  {
68  ROOTTYPE* h = 0;
69  if (aidah->axis().isFixedBinning() ) {//equidistant binning (easier case)
70  int nbins = aidah->axis().bins();
71  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, aidah->axis().lowerEdge(), aidah->axis().upperEdge());
72  } else {
73  int nbins = aidah->axis().bins();
74  //need to dyn cast, IAxis lacks polymorfism
75  const LWH::VariAxis* vax = dynamic_cast<const LWH::VariAxis*>(&aidah->axis());
76  if (! vax ){
77  throw cms::Exception("RivetAnalyzer") << "Cannot dynamix cast an AIDA axis to VariAxis ";
78  }
79  double* bins = new double[nbins+1];
80  for (int i=0; i<nbins; ++i) {
81  bins[i] = vax->binEdges(i).first;
82  }
83  bins[nbins] = vax->binEdges(nbins-1).second; //take last bin right border
84  h = new ROOTTYPE(name.c_str(), name.c_str(), nbins, bins);
85  delete bins;
86  }
87  return h;
88 }
int i
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

Member Data Documentation

Rivet::AnalysisHandler RivetAnalyzer::_analysisHandler
private

Definition at line 55 of file RivetAnalyzer.h.

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

bool RivetAnalyzer::_doFinalize
private

Definition at line 58 of file RivetAnalyzer.h.

Referenced by endRun().

edm::InputTag RivetAnalyzer::_genEventInfoCollection
private

Definition at line 54 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

edm::InputTag RivetAnalyzer::_hepmcCollection
private

Definition at line 52 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

bool RivetAnalyzer::_isFirstEvent
private

Definition at line 56 of file RivetAnalyzer.h.

Referenced by analyze().

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

Definition at line 62 of file RivetAnalyzer.h.

Referenced by normalizeTree().

std::string RivetAnalyzer::_outFileName
private

Definition at line 57 of file RivetAnalyzer.h.

Referenced by endRun().

bool RivetAnalyzer::_produceDQM
private

Definition at line 59 of file RivetAnalyzer.h.

Referenced by normalizeTree(), and RivetAnalyzer().

bool RivetAnalyzer::_useExternalWeight
private

Definition at line 53 of file RivetAnalyzer.h.

Referenced by analyze(), and RivetAnalyzer().

DQMStore* RivetAnalyzer::dbe
private

Definition at line 61 of file RivetAnalyzer.h.

Referenced by normalizeTree(), and RivetAnalyzer().