CMS 3D CMS Logo

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

#include <DQMRivetClient.h>

Inheritance diagram for DQMRivetClient:
edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  LumiOption
 
struct  ScaleFactorOption
 

Public Member Functions

void analyze (const edm::Event &event, const edm::EventSetup &eventSetup)
 
 DQMRivetClient (const edm::ParameterSet &pset)
 
void endJob ()
 
void endRun (const edm::Run &r, const edm::EventSetup &c)
 EndRun. More...
 
void normalizeToIntegral (const std::string &startDir, const std::string &histName, const std::string &normHistName)
 
void normalizeToLumi (const std::string &startDir, const std::string &histName, const std::string &normHistName, double xsection)
 
void scaleByFactor (const std::string &startDir, const std::string &histName, double factor)
 
 ~DQMRivetClient ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

std::vector< LumiOptionlumiOptions_
 
std::vector
< DQMGenericClient::NormOption
normOptions_
 
std::string outputFileName_
 
std::vector< ScaleFactorOptionscaleOptions_
 
std::vector< std::string > subDirs_
 
DQMStoretheDQM
 
unsigned int verbose_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- 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::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
CurrentProcessingContext const * currentContext () const
 
- 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 15 of file DQMRivetClient.h.

Constructor & Destructor Documentation

DQMRivetClient::DQMRivetClient ( const edm::ParameterSet pset)

Definition at line 35 of file DQMRivetClient.cc.

References harvestRelVal::args, edm::ParameterSet::getUntrackedParameter(), DQMRivetClient::LumiOption::name, DQMRivetClient::ScaleFactorOption::name, DQMGenericClient::NormOption::name, DQMRivetClient::LumiOption::normHistName, DQMGenericClient::NormOption::normHistName, or, DQMRivetClient::ScaleFactorOption::scale, and DQMRivetClient::LumiOption::xsection.

36 {
37 
38  typedef std::vector<edm::ParameterSet> VPSet;
39  typedef std::vector<std::string> vstring;
40  typedef boost::escaped_list_separator<char> elsc;
41 
42  elsc commonEscapes("\\", " \t", "\'");
43 
44  // Parse Normalization commands
45  vstring normCmds = pset.getUntrackedParameter<vstring>("normalizationToIntegral", vstring());
46  for ( vstring::const_iterator normCmd = normCmds.begin();
47  normCmd != normCmds.end(); ++normCmd )
48  {
49  if ( normCmd->empty() ) continue;
50  boost::tokenizer<elsc> tokens(*normCmd, commonEscapes);
51 
52  vector<string> args;
53  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
54  iToken != tokens.end(); ++iToken) {
55  if ( iToken->empty() ) continue;
56  args.push_back(*iToken);
57  }
58 
59  if ( args.empty() or args.size() > 2 ) {
60  LogInfo("DQMRivetClient") << "Wrong input to normCmds\n";
61  continue;
62  }
63 
65  opt.name = args[0];
66  opt.normHistName = args.size() == 2 ? args[1] : args[0];
67 
68  normOptions_.push_back(opt);
69  }
70 
71  VPSet normSets = pset.getUntrackedParameter<VPSet>("normalizationToIntegralSets", VPSet());
72  for ( VPSet::const_iterator normSet = normSets.begin();
73  normSet != normSets.end(); ++normSet )
74  {
76  opt.name = normSet->getUntrackedParameter<string>("name");
77  opt.normHistName = normSet->getUntrackedParameter<string>("normalizedTo", opt.name);
78 
79  normOptions_.push_back(opt);
80  }
81 
82  //normalize to lumi
83  vstring lumiCmds = pset.getUntrackedParameter<vstring>("normalizationToLumi", vstring());
84  for ( vstring::const_iterator lumiCmd = lumiCmds.begin();
85  lumiCmd != lumiCmds.end(); ++lumiCmd )
86  {
87  if ( lumiCmd->empty() ) continue;
88  boost::tokenizer<elsc> tokens(*lumiCmd, commonEscapes);
89 
90  vector<string> args;
91  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
92  iToken != tokens.end(); ++iToken) {
93  if ( iToken->empty() ) continue;
94  args.push_back(*iToken);
95  }
96 
97  if ( args.size() != 2 ) {
98  LogInfo("DQMRivetClient") << "Wrong input to lumiCmds\n";
99  continue;
100  }
101 
103  opt.name = args[0];
104  opt.normHistName = args[1] ;
105  opt.xsection = pset.getUntrackedParameter<double>("xsection", -1.);
106  //opt.xsection = atof(args[2].c_str());
107 
108  //std::cout << opt.name << " " << opt.normHistName << " " << opt.xsection << std::endl;
109  lumiOptions_.push_back(opt);
110  }
111 
112  //multiply by a number
113  vstring scaleCmds = pset.getUntrackedParameter<vstring>("scaleBy", vstring());
114  for ( vstring::const_iterator scaleCmd = scaleCmds.begin();
115  scaleCmd != scaleCmds.end(); ++scaleCmd )
116  {
117  if ( scaleCmd->empty() ) continue;
118  boost::tokenizer<elsc> tokens(*scaleCmd, commonEscapes);
119 
120  vector<string> args;
121  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
122  iToken != tokens.end(); ++iToken) {
123  if ( iToken->empty() ) continue;
124  args.push_back(*iToken);
125  }
126 
127  if ( args.empty() or args.size() > 2 ) {
128  LogInfo("DQMRivetClient") << "Wrong input to normCmds\n";
129  continue;
130  }
131 
132  ScaleFactorOption opt;
133  opt.name = args[0];
134  opt.scale = atof(args[1].c_str());
135  scaleOptions_.push_back(opt);
136  }
137 
138 
139  outputFileName_ = pset.getUntrackedParameter<string>("outputFileName", "");
140  subDirs_ = pset.getUntrackedParameter<vstring>("subDirs");
141 
142 }
std::vector< ScaleFactorOption > scaleOptions_
T getUntrackedParameter(std::string const &, T const &) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
vector< string > vstring
Definition: ExoticaDQM.cc:75
std::vector< DQMGenericClient::NormOption > normOptions_
std::string outputFileName_
std::vector< LumiOption > lumiOptions_
dictionary args
std::vector< std::string > subDirs_
DQMRivetClient::~DQMRivetClient ( )
inline

Definition at line 19 of file DQMRivetClient.h.

19 {};

Member Function Documentation

void DQMRivetClient::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
inlinevirtual

Implements edm::EDAnalyzer.

Definition at line 21 of file DQMRivetClient.h.

21 {};
void DQMRivetClient::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 210 of file DQMRivetClient.cc.

References LogTrace.

211 {
212 
213  // Update 2009-09-23
214  // Migrated all code from here to endRun
215 
216  LogTrace ("DQMRivetClient") << "inside of DQMGenericClient::endJob()"
217  << endl;
218 
219 }
#define LogTrace(id)
void DQMRivetClient::endRun ( const edm::Run r,
const edm::EventSetup c 
)
virtual

EndRun.

Reimplemented from edm::EDAnalyzer.

Definition at line 144 of file DQMRivetClient.cc.

References TrackerOfflineValidation_Dqm_cff::dirName, and cppFunctionSkipper::operator.

144  {
145 
146  typedef vector<string> vstring;
147 
148  // Update 2009-09-23
149  // Migrated all code from endJob to this function
150  // endJob is not necessarily called in the proper sequence
151  // and does not necessarily book histograms produced in
152  // that step.
153  // It more robust to do the histogram manipulation in
154  // this endRun function
155 
156 
157 
158  theDQM = 0;
160 
161  if ( ! theDQM ) {
162  LogInfo("DQMRivetClient") << "Cannot create DQMStore instance\n";
163  return;
164  }
165 
166  // Process wildcard in the sub-directory
167  set<string> subDirSet;
168 
169  for(vstring::const_iterator iSubDir = subDirs_.begin();
170  iSubDir != subDirs_.end(); ++iSubDir) {
171  string subDir = *iSubDir;
172 
173  if ( subDir[subDir.size()-1] == '/' ) subDir.erase(subDir.size()-1);
174 
175  subDirSet.insert(subDir);
176  }
177 
178  for(set<string>::const_iterator iSubDir = subDirSet.begin();
179  iSubDir != subDirSet.end(); ++iSubDir) {
180  const string& dirName = *iSubDir;
181  for ( vector<DQMGenericClient::NormOption>::const_iterator normOption = normOptions_.begin();
182  normOption != normOptions_.end(); ++normOption ){
183  normalizeToIntegral(dirName, normOption->name, normOption->normHistName);
184  }
185  }
186 
187  for(set<string>::const_iterator iSubDir = subDirSet.begin();
188  iSubDir != subDirSet.end(); ++iSubDir) {
189  const string& dirName = *iSubDir;
190  for ( vector<LumiOption>::const_iterator lumiOption = lumiOptions_.begin();
191  lumiOption != lumiOptions_.end(); ++lumiOption ){
192  normalizeToLumi(dirName, lumiOption->name, lumiOption->normHistName, lumiOption->xsection);
193  }
194  }
195 
196  for(set<string>::const_iterator iSubDir = subDirSet.begin();
197  iSubDir != subDirSet.end(); ++iSubDir) {
198  const string& dirName = *iSubDir;
199  for ( vector<ScaleFactorOption>::const_iterator scaleOption = scaleOptions_.begin();
200  scaleOption != scaleOptions_.end(); ++scaleOption ){
201  scaleByFactor(dirName, scaleOption->name, scaleOption->scale);
202  }
203  }
204 
205 
206  if ( ! outputFileName_.empty() ) theDQM->save(outputFileName_);
207 
208 }
std::vector< ScaleFactorOption > scaleOptions_
vector< string > vstring
Definition: ExoticaDQM.cc:75
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2118
void scaleByFactor(const std::string &startDir, const std::string &histName, double factor)
std::vector< DQMGenericClient::NormOption > normOptions_
std::string outputFileName_
void normalizeToIntegral(const std::string &startDir, const std::string &histName, const std::string &normHistName)
std::vector< LumiOption > lumiOptions_
DQMStore * theDQM
std::vector< std::string > subDirs_
void normalizeToLumi(const std::string &startDir, const std::string &histName, const std::string &normHistName, double xsection)
void DQMRivetClient::normalizeToIntegral ( const std::string &  startDir,
const std::string &  histName,
const std::string &  normHistName 
)

Definition at line 221 of file DQMRivetClient.cc.

References python.tagInventory::entries, and estimatePileup::hist.

222 {
223  if ( ! theDQM->dirExists(startDir) ) {
224  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
225  << "Cannot find sub-directory " << startDir << endl;
226  return;
227  }
228 
229  theDQM->cd();
230 
231  ME* element = theDQM->get(startDir+"/"+histName);
232  ME* normME = theDQM->get(startDir+"/"+normHistName);
233 
234  if ( !element ) {
235  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
236  << "No such element '" << histName << "' found\n";
237  return;
238  }
239 
240  if ( !normME ) {
241  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
242  << "No such element '" << normHistName << "' found\n";
243  return;
244  }
245 
246  TH1F* hist = element->getTH1F();
247  if ( !hist) {
248  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
249  << "Cannot create TH1F from ME\n";
250  return;
251  }
252 
253  TH1F* normHist = normME->getTH1F();
254  if ( !normHist ) {
255  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
256  << "Cannot create TH1F from ME\n";
257  return;
258  }
259 
260  const double entries = normHist->Integral();
261  if ( entries != 0 ) {
262  hist->Scale(1./entries, "width");
263  }
264  else {
265  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
266  << "Zero entries in histogram\n";
267  }
268 
269  return;
270 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:411
Definition: ME.h:11
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1473
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:498
DQMStore * theDQM
void DQMRivetClient::normalizeToLumi ( const std::string &  startDir,
const std::string &  histName,
const std::string &  normHistName,
double  xsection 
)

Definition at line 272 of file DQMRivetClient.cc.

References estimatePileup::hist.

272  {
273  normalizeToIntegral(startDir, histName, normHistName);
274  theDQM->cd();
275  ME* element = theDQM->get(startDir+"/"+histName);
276  TH1F* hist = element->getTH1F();
277  if ( !hist) {
278  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
279  << "Cannot create TH1F from ME\n";
280  return;
281  }
282  hist->Scale(xsection);
283  return;
284 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:411
Definition: ME.h:11
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1473
void normalizeToIntegral(const std::string &startDir, const std::string &histName, const std::string &normHistName)
DQMStore * theDQM
void DQMRivetClient::scaleByFactor ( const std::string &  startDir,
const std::string &  histName,
double  factor 
)

Definition at line 286 of file DQMRivetClient.cc.

References estimatePileup::hist.

286  {
287  if ( ! theDQM->dirExists(startDir) ) {
288  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
289  << "Cannot find sub-directory " << startDir << endl;
290  return;
291  }
292 
293  theDQM->cd();
294 
295  ME* element = theDQM->get(startDir+"/"+histName);
296 
297  if ( !element ) {
298  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
299  << "No such element '" << histName << "' found\n";
300  return;
301  }
302 
303  TH1F* hist = element->getTH1F();
304  if ( !hist) {
305  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
306  << "Cannot create TH1F from ME\n";
307  return;
308  }
309  hist->Scale(factor);
310 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:411
Definition: ME.h:11
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1473
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:498
DQMStore * theDQM

Member Data Documentation

std::vector<LumiOption> DQMRivetClient::lumiOptions_
private

Definition at line 52 of file DQMRivetClient.h.

std::vector<DQMGenericClient::NormOption> DQMRivetClient::normOptions_
private

Definition at line 51 of file DQMRivetClient.h.

std::string DQMRivetClient::outputFileName_
private

Definition at line 49 of file DQMRivetClient.h.

std::vector<ScaleFactorOption> DQMRivetClient::scaleOptions_
private

Definition at line 53 of file DQMRivetClient.h.

std::vector<std::string> DQMRivetClient::subDirs_
private

Definition at line 48 of file DQMRivetClient.h.

DQMStore* DQMRivetClient::theDQM
private

Definition at line 47 of file DQMRivetClient.h.

unsigned int DQMRivetClient::verbose_
private

Definition at line 45 of file DQMRivetClient.h.