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
RivetHarvesting Class Reference

#include <RivetHarvesting.h>

Inheritance diagram for RivetHarvesting:
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 ()
 
virtual void endRun (const edm::Run &, const edm::EventSetup &)
 
 RivetHarvesting (const edm::ParameterSet &)
 
virtual ~RivetHarvesting ()
 
- 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

std::vector< YODA::Point2DgetPoint2DValsErrs (std::string filename, std::string path, std::string name)
 

Private Attributes

Rivet::AnalysisHandler _analysisHandler
 
std::vector< std::string > _analysisNames
 
std::vector< double > _crossSections
 
std::vector< std::string > _fileNames
 
edm::InputTag _hepmcCollection
 
bool _isFirstEvent
 
std::vector< double > _lumis
 
std::string _outFileName
 
std::vector< double > _sumOfWeights
 

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 19 of file RivetHarvesting.h.

Constructor & Destructor Documentation

RivetHarvesting::RivetHarvesting ( const edm::ParameterSet pset)

Definition at line 26 of file RivetHarvesting.cc.

References _analysisHandler, _analysisNames, _crossSections, _fileNames, _lumis, _sumOfWeights, edm::hlt::Exception, edm::ParameterSet::getParameter(), and i.

26  :
28 _fileNames(pset.getParameter<std::vector<std::string> >("FilesToHarvest")),
29 _sumOfWeights(pset.getParameter<std::vector<double> >("VSumOfWeights")),
30 _crossSections(pset.getParameter<std::vector<double> >("VCrossSections")),
31 _outFileName(pset.getParameter<std::string>("OutputFile")),
32 _isFirstEvent(true),
33 _hepmcCollection(pset.getParameter<edm::InputTag>("HepMCCollection")),
34 _analysisNames(pset.getParameter<std::vector<std::string> >("AnalysisNames"))
35 {
36 
37  if (_sumOfWeights.size() != _fileNames.size() ||
38  _sumOfWeights.size() != _crossSections.size() ||
39  _fileNames.size() != _crossSections.size()){
40  throw cms::Exception("RivetHarvesting") << "Mismatch in vector sizes: FilesToHarvest: " << _sumOfWeights.size() << ", VSumOfWeights: " << _sumOfWeights.size() << ", VCrossSections: " << _crossSections.size();
41  }
42 
43 
44  //get the analyses
45  _analysisHandler.addAnalyses(_analysisNames);
46 
47  //go through the analyses and check those that need the cross section
48  const std::set< AnaHandle, CmpAnaHandle > & analyses = _analysisHandler.analyses();
49 
50  std::set< AnaHandle, CmpAnaHandle >::const_iterator ibeg = analyses.begin();
51  std::set< AnaHandle, CmpAnaHandle >::const_iterator iend = analyses.end();
52  std::set< AnaHandle, CmpAnaHandle >::const_iterator iana;
53  double xsection = -1.;
54  xsection = pset.getParameter<double>("CrossSection");
55  for (iana = ibeg; iana != iend; ++iana){
56  if ((*iana)->needsCrossSection())
57  (*iana)->setCrossSection(xsection);
58  }
59 
60  double totalSumOfWeights = _sumOfWeights[0];
61  _lumis.push_back(_sumOfWeights[0]/_crossSections[0]);
62  for (unsigned int i = 1; i < _sumOfWeights.size(); ++i){
63  _lumis.push_back(_sumOfWeights[i]/_crossSections[i]);
64  totalSumOfWeights += _sumOfWeights[i]*_lumis[0]/_lumis[i];
65  }
66  _analysisHandler.setSumOfWeights(totalSumOfWeights);
67 
68 
69 }
T getParameter(std::string const &) const
std::vector< double > _lumis
int i
Definition: DBlmapReader.cc:9
edm::InputTag _hepmcCollection
std::vector< double > _crossSections
std::vector< std::string > _fileNames
std::vector< double > _sumOfWeights
Rivet::AnalysisHandler _analysisHandler
std::string _outFileName
std::vector< std::string > _analysisNames
RivetHarvesting::~RivetHarvesting ( )
virtual

Definition at line 71 of file RivetHarvesting.cc.

71  {
72 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 89 of file RivetHarvesting.cc.

References _analysisHandler, _hepmcCollection, _isFirstEvent, and edm::Event::getByLabel().

89  {
90  if (!_isFirstEvent)
91  return;
92 
93  //initialize the analysis handles, all histograms are booked
94  //we need at least one event to get the handler initialized
96  iEvent.getByLabel(_hepmcCollection, evt);
97 
98  // get HepMC GenEvent
99  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
100  _analysisHandler.init(*myGenEvent);
101  //gain access to the histogram factory and change the histograms
102  /*
103  AIDA::ITree & tree = _analysisHandler.tree();
104  tree.ls(".", true);
105 
106  //from Analysis.hh (cls 18Feb2014)
108  //const vector<AnalysisObjectPtr>& analysisObjects() const {
109  //return _analysisobjects;
110  //}
111 
112 
113 
114  for (std::vector<std::string>::const_iterator iAna = _analysisNames.begin(); iAna != _analysisNames.end(); ++iAna){
115  std::vector<std::string> listOfNames = tree.listObjectNames("./"+(*iAna), true);
116  std::vector<std::string>::const_iterator iNameBeg = listOfNames.begin();
117  std::vector<std::string>::const_iterator iNameEnd = listOfNames.end();
118  for (std::vector<std::string>::const_iterator iName = iNameBeg; iName != iNameEnd; ++iName ){
119  AIDA::IManagedObject * iObj = tree.find(*iName);
120  if (!iObj){
121  std::cout << *iName << " not found; SKIPPING!" << std::endl;
122  continue;
123  }
124 
125  std::cout << *iName << " FOUND!" << std::endl;
126  vector<string>::const_iterator iFile;
127  vector<string>::const_iterator iFileBeg = _fileNames.begin();
128  vector<string>::const_iterator iFileEnd = _fileNames.end();
129  AIDA::IHistogram1D* histo = dynamic_cast<AIDA::IHistogram1D*>(iObj);
130  AIDA::IProfile1D* prof = dynamic_cast<AIDA::IProfile1D*>(iObj);
131  string tmpdir = "/tmpdir";
132  tree.mkdir(tmpdir);
133  unsigned int ifc = 0;
134  for (iFile = iFileBeg; iFile != iFileEnd; ++iFile) {
135  std::cout << "opening file " << *iFile << std::endl;
136  string name = *iName;
137  string tostrip = *iAna+'/';
138  name.replace(name.find(tostrip),tostrip.length(),"");
139  name.replace(name.find("/"),1,"");
140  cout << name << endl;
141  //vector<DPSXYPoint> original = getDPSXYValsErrs(*iFile, *iAna, name);
142  vector<Point2D> original = getPoint2DValsErrs(*iFile, *iAna, name);
143  if (histo){
144  const string tmppath = tmpdir + "/" + name;
145  cout << tmppath << endl;
146  IHistogram1D* tmphisto = _analysisHandler.histogramFactory().createCopy(tmppath, *histo);
147  tmphisto->reset();
148  for (unsigned int i = 0; i < original.size(); ++i){
149  tmphisto->fill(original[i].xval, original[i].yval);
150  }
151  tmphisto->scale(_lumis[ifc]);
152  histo->add(*tmphisto);
153  //iObj = new AIDA::IHistogram1D(*(_analysisHandler.histogramFactory().add(*iName, *histo, *tmphisto)));
154  tree.rm(tmppath);
155  //delete tmphisto;
156  } else if (prof) {
157  std::cout << *iName << "is a profile, doing nothing " << std::endl;
158  } else {
159  std::cout << *iName << " is neither a IHistogram1D neither a IProfile1D. Doing nothing with it." << std::endl;
160  }
161  ++ifc;
162  }
163  cout << iObj << endl;
164  }
165  }
166 
167  tree.ls(".", true);
168  */
169  _isFirstEvent = false;
170 }
edm::InputTag _hepmcCollection
Rivet::AnalysisHandler _analysisHandler
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
void RivetHarvesting::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 74 of file RivetHarvesting.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 RivetHarvesting::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 85 of file RivetHarvesting.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 177 of file RivetHarvesting.cc.

References _analysisHandler, and _outFileName.

177  {
178  _analysisHandler.finalize();
179  _analysisHandler.writeData(_outFileName);
180 }
Rivet::AnalysisHandler _analysisHandler
std::string _outFileName
void RivetHarvesting::endRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 173 of file RivetHarvesting.cc.

173  {
174  return;
175 }
vector< YODA::Point2D > RivetHarvesting::getPoint2DValsErrs ( std::string  filename,
std::string  path,
std::string  name 
)
private

Check path to make sure that this is a reference histogram.

Definition at line 182 of file RivetHarvesting.cc.

References TiXmlElement::Attribute(), dtNoiseDBValidation_cfg::cerr, asciidump::doc, alignCSCRings::e, TiXmlDocument::Error(), TiXmlDocument::ErrorDesc(), cppFunctionSkipper::exception, edm::hlt::Exception, lut2db_cfg::filename, TiXmlNode::FirstChild(), TiXmlDocument::LoadFile(), TiXmlNode::NextSibling(), EnergyCorrector::pt, AlCaHLTBitMon_QueryRunRegistry::string, TiXmlNode::ToElement(), TiXmlElement::ToElement(), and TiXmlNode::Value().

182  {
183 
184  // Open YODA XML file
186  doc.LoadFile();
187  if (doc.Error()) {
188  string err = "Error in " + string(doc.Value());
189  err += ": " + string(doc.ErrorDesc());
190  cerr << err << endl;
191  throw cms::Exception("RivetHarvesting") << "Cannot open " << filename;
192  }
193 
194  // Return value, to be populated
195  vector<Point2D> rtn;
196 
197  try {
198  // Walk down tree to get to the <paper> element
199  const TiXmlNode* yodaN = doc.FirstChild("yoda");
200  if (!yodaN) throw cms::Exception("RivetHarvesting") << "Couldn't get <yoda> root element";
201  for (const TiXmlNode* dpsN = yodaN->FirstChild("dataPointSet"); dpsN; dpsN = dpsN->NextSibling()) {
202  const TiXmlElement* dpsE = dpsN->ToElement();
203  const string plotname = dpsE->Attribute("name");
204  const string plotpath = dpsE->Attribute("path");
205  if (plotpath != path && plotname != name)
206  continue;
208  //if (plotpath.find("/REF") != 0) {
209  // cerr << "Skipping non-reference histogram " << plotname << endl;
210  // continue;
211  //}
212 
214  vector<Point2D> points;
215  for (const TiXmlNode* dpN = dpsN->FirstChild("dataPoint"); dpN; dpN = dpN->NextSibling()) {
216  const TiXmlNode* xMeasN = dpN->FirstChild("measurement");
217  const TiXmlNode* yMeasN = xMeasN->NextSibling();
218  if (xMeasN && yMeasN) {
219  const TiXmlElement* xMeasE = xMeasN->ToElement();
220  const TiXmlElement* yMeasE = yMeasN->ToElement();
221  const string xcentreStr = xMeasE->Attribute("value");
222  const string xerrplusStr = xMeasE->Attribute("errorPlus");
223  const string xerrminusStr = xMeasE->Attribute("errorMinus");
224  const string ycentreStr = yMeasE->Attribute("value");
225  const string yerrplusStr = yMeasE->Attribute("errorPlus");
226  const string yerrminusStr = yMeasE->Attribute("errorMinus");
227  //if (!centreStr) throw Error("Couldn't get a valid bin centre");
228  //if (!errplusStr) throw Error("Couldn't get a valid bin err+");
229  //if (!errminusStr) throw Error("Couldn't get a valid bin err-");
230  istringstream xssC(xcentreStr);
231  istringstream xssP(xerrplusStr);
232  istringstream xssM(xerrminusStr);
233  istringstream yssC(ycentreStr);
234  istringstream yssP(yerrplusStr);
235  istringstream yssM(yerrminusStr);
236  double xcentre, xerrplus, xerrminus, ycentre, yerrplus, yerrminus;
237  xssC >> xcentre; xssP >> xerrplus; xssM >> xerrminus;
238  yssC >> ycentre; yssP >> yerrplus; yssM >> yerrminus;
239  //cout << " " << centre << " + " << errplus << " - " << errminus << endl;
240  Point2D pt(xcentre, xerrminus, xerrplus, ycentre, yerrminus, yerrplus);
241  points.push_back(pt);
242  } else {
243  cerr << "Couldn't get <measurement> tag" << endl;
245  }
246  }
247 
248  return points;
249  }
250 
251  }
252  // Write out the error
254  catch (std::exception& e) {
255  cerr << e.what() << endl;
256  throw;
257  }
258 
259  throw cms::Exception("RivetHarvesting") << "could not find " << path << "/" << name << " in file " << filename;
260 
261  return rtn;
262 
263 }
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:1127
tuple path
else: Piece not in the list, fine.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:526
tuple doc
Definition: asciidump.py:381
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:630
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:702
tuple filename
Definition: lut2db_cfg.py:20
const char * Attribute(const char *name) const
Definition: tinyxml.cc:564

Member Data Documentation

Rivet::AnalysisHandler RivetHarvesting::_analysisHandler
private

Definition at line 41 of file RivetHarvesting.h.

Referenced by analyze(), endJob(), and RivetHarvesting().

std::vector<std::string> RivetHarvesting::_analysisNames
private

Definition at line 49 of file RivetHarvesting.h.

Referenced by RivetHarvesting().

std::vector<double> RivetHarvesting::_crossSections
private

Definition at line 44 of file RivetHarvesting.h.

Referenced by RivetHarvesting().

std::vector<std::string> RivetHarvesting::_fileNames
private

Definition at line 42 of file RivetHarvesting.h.

Referenced by RivetHarvesting().

edm::InputTag RivetHarvesting::_hepmcCollection
private

Definition at line 48 of file RivetHarvesting.h.

Referenced by analyze().

bool RivetHarvesting::_isFirstEvent
private

Definition at line 47 of file RivetHarvesting.h.

Referenced by analyze().

std::vector<double> RivetHarvesting::_lumis
private

Definition at line 45 of file RivetHarvesting.h.

Referenced by RivetHarvesting().

std::string RivetHarvesting::_outFileName
private

Definition at line 46 of file RivetHarvesting.h.

Referenced by endJob().

std::vector<double> RivetHarvesting::_sumOfWeights
private

Definition at line 43 of file RivetHarvesting.h.

Referenced by RivetHarvesting().