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
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 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
 
- 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 15 of file DQMRivetClient.h.

Constructor & Destructor Documentation

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

Definition at line 33 of file DQMRivetClient.cc.

References ExtractAppInfoFromXML::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.

34 {
35 
36  typedef std::vector<edm::ParameterSet> VPSet;
37  typedef std::vector<std::string> vstring;
38  typedef boost::escaped_list_separator<char> elsc;
39 
40  elsc commonEscapes("\\", " \t", "\'");
41 
42  // Parse Normalization commands
43  vstring normCmds = pset.getUntrackedParameter<vstring>("normalizationToIntegral", vstring());
44  for ( vstring::const_iterator normCmd = normCmds.begin();
45  normCmd != normCmds.end(); ++normCmd )
46  {
47  if ( normCmd->empty() ) continue;
48  boost::tokenizer<elsc> tokens(*normCmd, commonEscapes);
49 
50  vector<string> args;
51  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
52  iToken != tokens.end(); ++iToken) {
53  if ( iToken->empty() ) continue;
54  args.push_back(*iToken);
55  }
56 
57  if ( args.empty() or args.size() > 2 ) {
58  LogInfo("DQMRivetClient") << "Wrong input to normCmds\n";
59  continue;
60  }
61 
63  opt.name = args[0];
64  opt.normHistName = args.size() == 2 ? args[1] : args[0];
65 
66  normOptions_.push_back(opt);
67  }
68 
69  VPSet normSets = pset.getUntrackedParameter<VPSet>("normalizationToIntegralSets", VPSet());
70  for ( VPSet::const_iterator normSet = normSets.begin();
71  normSet != normSets.end(); ++normSet )
72  {
74  opt.name = normSet->getUntrackedParameter<string>("name");
75  opt.normHistName = normSet->getUntrackedParameter<string>("normalizedTo", opt.name);
76 
77  normOptions_.push_back(opt);
78  }
79 
80  //normalize to lumi
81  vstring lumiCmds = pset.getUntrackedParameter<vstring>("normalizationToLumi", vstring());
82  for ( vstring::const_iterator lumiCmd = lumiCmds.begin();
83  lumiCmd != lumiCmds.end(); ++lumiCmd )
84  {
85  if ( lumiCmd->empty() ) continue;
86  boost::tokenizer<elsc> tokens(*lumiCmd, commonEscapes);
87 
88  vector<string> args;
89  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
90  iToken != tokens.end(); ++iToken) {
91  if ( iToken->empty() ) continue;
92  args.push_back(*iToken);
93  }
94 
95  if ( args.size() != 2 ) {
96  LogInfo("DQMRivetClient") << "Wrong input to lumiCmds\n";
97  continue;
98  }
99 
101  opt.name = args[0];
102  opt.normHistName = args[1] ;
103  opt.xsection = pset.getUntrackedParameter<double>("xsection", -1.);
104  //opt.xsection = atof(args[2].c_str());
105 
106  //std::cout << opt.name << " " << opt.normHistName << " " << opt.xsection << std::endl;
107  lumiOptions_.push_back(opt);
108  }
109 
110  //multiply by a number
111  vstring scaleCmds = pset.getUntrackedParameter<vstring>("scaleBy", vstring());
112  for ( vstring::const_iterator scaleCmd = scaleCmds.begin();
113  scaleCmd != scaleCmds.end(); ++scaleCmd )
114  {
115  if ( scaleCmd->empty() ) continue;
116  boost::tokenizer<elsc> tokens(*scaleCmd, commonEscapes);
117 
118  vector<string> args;
119  for(boost::tokenizer<elsc>::const_iterator iToken = tokens.begin();
120  iToken != tokens.end(); ++iToken) {
121  if ( iToken->empty() ) continue;
122  args.push_back(*iToken);
123  }
124 
125  if ( args.empty() or args.size() > 2 ) {
126  LogInfo("DQMRivetClient") << "Wrong input to normCmds\n";
127  continue;
128  }
129 
130  ScaleFactorOption opt;
131  opt.name = args[0];
132  opt.scale = atof(args[1].c_str());
133  scaleOptions_.push_back(opt);
134  }
135 
136 
137  outputFileName_ = pset.getUntrackedParameter<string>("outputFileName", "");
138  subDirs_ = pset.getUntrackedParameter<vstring>("subDirs");
139 
140 }
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_
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 208 of file DQMRivetClient.cc.

References LogTrace.

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

EndRun.

Reimplemented from edm::EDAnalyzer.

Definition at line 142 of file DQMRivetClient.cc.

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

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

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

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

Definition at line 270 of file DQMRivetClient.cc.

References estimatePileup::hist.

270  {
271  normalizeToIntegral(startDir, histName, normHistName);
272  theDQM->cd();
273  ME* element = theDQM->get(startDir+"/"+histName);
274  TH1F* hist = element->getTH1F();
275  if ( !hist) {
276  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
277  << "Cannot create TH1F from ME\n";
278  return;
279  }
280  hist->Scale(xsection);
281  return;
282 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:632
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:1696
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 284 of file DQMRivetClient.cc.

References estimatePileup::hist.

284  {
285  if ( ! theDQM->dirExists(startDir) ) {
286  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
287  << "Cannot find sub-directory " << startDir << endl;
288  return;
289  }
290 
291  theDQM->cd();
292 
293  ME* element = theDQM->get(startDir+"/"+histName);
294 
295  if ( !element ) {
296  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
297  << "No such element '" << histName << "' found\n";
298  return;
299  }
300 
301  TH1F* hist = element->getTH1F();
302  if ( !hist) {
303  LogInfo("DQMRivetClient") << "normalizeToEntries() : "
304  << "Cannot create TH1F from ME\n";
305  return;
306  }
307  hist->Scale(factor);
308 }
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:632
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:1696
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:720
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.