CMS 3D CMS Logo

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

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void beginRun (const edm::Run &, const edm::EventSetup &) override
 
void endJob () override
 
void endRun (const edm::Run &, const edm::EventSetup &) override
 
 RivetHarvesting (const edm::ParameterSet &)
 
 ~RivetHarvesting () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

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
 
- 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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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, Exception, edm::ParameterSet::getParameter(), and mps_fire::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
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 ( )
override

Definition at line 71 of file RivetHarvesting.cc.

71  {
72 }

Member Function Documentation

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

Definition at line 93 of file RivetHarvesting.cc.

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

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

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  char *rivetrefCstr = strdup(rivetref.c_str());
82  putenv(rivetrefCstr);
83  free(rivetrefCstr);
84  char *rivetinfoCstr = strdup(rivetinfo.c_str());
85  putenv(rivetinfoCstr);
86  free(rivetinfoCstr);
87 }
void RivetHarvesting::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
override

Definition at line 89 of file RivetHarvesting.cc.

89  {
90  return;
91 }
void RivetHarvesting::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 181 of file RivetHarvesting.cc.

References _analysisHandler, and _outFileName.

181  {
182  _analysisHandler.finalize();
183  _analysisHandler.writeData(_outFileName);
184 }
Rivet::AnalysisHandler _analysisHandler
std::string _outFileName
void RivetHarvesting::endRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
override

Definition at line 177 of file RivetHarvesting.cc.

177  {
178  return;
179 }
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 186 of file RivetHarvesting.cc.

References MessageLogger_cfi::cerr, DEFINE_FWK_MODULE, common_cff::doc, MillePedeFileConverter_cfg::e, cppFunctionSkipper::exception, Exception, corrVsCorr::filename, hiPixelPairStep_cff::points, EnergyCorrector::pt, and AlCaHLTBitMon_QueryRunRegistry::string.

186  {
187 
188  // Open YODA XML file
189  TiXmlDocument doc(filename);
190  doc.LoadFile();
191  if (doc.Error()) {
192  string err = "Error in " + string(doc.Value());
193  err += ": " + string(doc.ErrorDesc());
194  cerr << err << endl;
195  throw cms::Exception("RivetHarvesting") << "Cannot open " << filename;
196  }
197 
198  // Return value, to be populated
199  vector<Point2D> rtn;
200 
201  try {
202  // Walk down tree to get to the <paper> element
203  const TiXmlNode* yodaN = doc.FirstChild("yoda");
204  if (!yodaN) throw cms::Exception("RivetHarvesting") << "Couldn't get <yoda> root element";
205  for (const TiXmlNode* dpsN = yodaN->FirstChild("dataPointSet"); dpsN; dpsN = dpsN->NextSibling()) {
206  const TiXmlElement* dpsE = dpsN->ToElement();
207  const string plotname = dpsE->Attribute("name");
208  const string plotpath = dpsE->Attribute("path");
209  if (plotpath != path && plotname != name)
210  continue;
212  //if (plotpath.find("/REF") != 0) {
213  // cerr << "Skipping non-reference histogram " << plotname << endl;
214  // continue;
215  //}
216 
218  vector<Point2D> points;
219  for (const TiXmlNode* dpN = dpsN->FirstChild("dataPoint"); dpN; dpN = dpN->NextSibling()) {
220  const TiXmlNode* xMeasN = dpN->FirstChild("measurement");
221  const TiXmlNode* yMeasN = xMeasN->NextSibling();
222  if (xMeasN && yMeasN) {
223  const TiXmlElement* xMeasE = xMeasN->ToElement();
224  const TiXmlElement* yMeasE = yMeasN->ToElement();
225  const string xcentreStr = xMeasE->Attribute("value");
226  const string xerrplusStr = xMeasE->Attribute("errorPlus");
227  const string xerrminusStr = xMeasE->Attribute("errorMinus");
228  const string ycentreStr = yMeasE->Attribute("value");
229  const string yerrplusStr = yMeasE->Attribute("errorPlus");
230  const string yerrminusStr = yMeasE->Attribute("errorMinus");
231  //if (!centreStr) throw Error("Couldn't get a valid bin centre");
232  //if (!errplusStr) throw Error("Couldn't get a valid bin err+");
233  //if (!errminusStr) throw Error("Couldn't get a valid bin err-");
234  istringstream xssC(xcentreStr);
235  istringstream xssP(xerrplusStr);
236  istringstream xssM(xerrminusStr);
237  istringstream yssC(ycentreStr);
238  istringstream yssP(yerrplusStr);
239  istringstream yssM(yerrminusStr);
240  double xcentre, xerrplus, xerrminus, ycentre, yerrplus, yerrminus;
241  xssC >> xcentre; xssP >> xerrplus; xssM >> xerrminus;
242  yssC >> ycentre; yssP >> yerrplus; yssM >> yerrminus;
243  //cout << " " << centre << " + " << errplus << " - " << errminus << endl;
244  Point2D pt(xcentre, xerrminus, xerrplus, ycentre, yerrminus, yerrplus);
245  points.push_back(pt);
246  } else {
247  cerr << "Couldn't get <measurement> tag" << endl;
249  }
250  }
251 
252  return points;
253  }
254 
255  }
256  // Write out the error
258  catch (std::exception& e) {
259  cerr << e.what() << endl;
260  throw;
261  }
262 
263  throw cms::Exception("RivetHarvesting") << "could not find " << path << "/" << name << " in file " << filename;
264 
265  return rtn;
266 
267 }

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().