CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
DQMHistNormalizer Class Reference
Inheritance diagram for DQMHistNormalizer:
edm::one::EDAnalyzer< edm::one::SharedResources, edm::one::WatchRuns > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Types

typedef dqm::legacy::DQMStore DQMStore
 
typedef dqm::legacy::MonitorElement MonitorElement
 
- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginRun (const edm::Run &r, const edm::EventSetup &c) override
 
 DQMHistNormalizer (const edm::ParameterSet &)
 
void endRun (const edm::Run &r, const edm::EventSetup &c) override
 
 ~DQMHistNormalizer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources, edm::one::WatchRuns >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

vector< string > plotNamesToNormalize_
 
string reference_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Class to produce efficiency histograms by dividing nominator by denominator histograms

Author
Christian Veelken, UC Davis

Definition at line 45 of file DQMHistNormalizer.cc.

Member Typedef Documentation

◆ DQMStore

Definition at line 47 of file DQMHistNormalizer.cc.

◆ MonitorElement

Definition at line 48 of file DQMHistNormalizer.cc.

Constructor & Destructor Documentation

◆ DQMHistNormalizer()

DQMHistNormalizer::DQMHistNormalizer ( const edm::ParameterSet cfg)
explicit

Definition at line 61 of file DQMHistNormalizer.cc.

62  : plotNamesToNormalize_(cfg.getParameter<std::vector<string> >("plotNamesToNormalize")),
63  reference_(cfg.getParameter<string>("reference")) {
64  usesResource("DQMStore");
65  //std::cout << "<DQMHistNormalizer::DQMHistNormalizer>:" << std::endl;
66 }
vector< string > plotNamesToNormalize_

◆ ~DQMHistNormalizer()

DQMHistNormalizer::~DQMHistNormalizer ( )
override

Definition at line 68 of file DQMHistNormalizer.cc.

68  {
69  //--- nothing to be done yet
70 }

Member Function Documentation

◆ analyze()

void DQMHistNormalizer::analyze ( const edm::Event ,
const edm::EventSetup  
)
overridevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 72 of file DQMHistNormalizer.cc.

72  {
73  //--- nothing to be done yet
74 }

◆ beginRun()

void DQMHistNormalizer::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
inlineoverride

Definition at line 53 of file DQMHistNormalizer.cc.

53 {}

◆ endRun()

void DQMHistNormalizer::endRun ( const edm::Run r,
const edm::EventSetup c 
)
override

Definition at line 76 of file DQMHistNormalizer.cc.

References DeadROC_duringRun::dir, L1TBPTX_cfi::dqmStore, globToRegex(), compareTotals::hist, BTVHLTOfflineSource_cfi::pathname, plotNamesToNormalize_, and reference_.

76  {
77  //std::cout << "<DQMHistNormalizer::endJob>:" << std::endl;
78 
79  //--- check that DQMStore service is available
80  if (!edm::Service<DQMStore>().isAvailable()) {
81  edm::LogError("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
82  return;
83  }
84 
86 
87  vector<MonitorElement*> allOurMEs = dqmStore.getAllContents("RecoTauV/");
88  std::regex refregex = std::regex(".*RecoTauV/.*/" + globToRegex(reference_), std::regex::nosubs);
89  vector<std::regex> toNormRegex;
90  for (std::vector<string>::const_iterator toNorm = plotNamesToNormalize_.begin();
91  toNorm != plotNamesToNormalize_.end();
92  ++toNorm)
93  toNormRegex.emplace_back(".*RecoTauV/.*/" + globToRegex(*toNorm), std::regex::nosubs);
94 
95  map<string, MonitorElement*> refsMap;
96  vector<MonitorElement*> toNormElements;
97  std::smatch path_match;
98 
99  for (vector<MonitorElement*>::const_iterator element = allOurMEs.begin(); element != allOurMEs.end(); ++element) {
100  string pathname = (*element)->getFullname();
101  //cout << pathname << endl;
102  //Matches reference
103  if (std::regex_match(pathname, path_match, refregex)) {
104  //cout << "Matched to ref" << endl;
105  string dir = pathname.substr(0, pathname.rfind('/'));
106  if (refsMap.find(dir) != refsMap.end()) {
107  edm::LogInfo("DQMHistNormalizer")
108  << "DQMHistNormalizer::endRun: Warning! found multiple normalizing references for dir: " << dir << "!";
109  edm::LogInfo("DQMHistNormalizer") << " " << (refsMap[dir])->getFullname();
110  edm::LogInfo("DQMHistNormalizer") << " " << pathname;
111  } else {
112  refsMap[dir] = *element;
113  }
114  }
115 
116  //Matches targets
117  for (const auto& reg : toNormRegex) {
118  if (std::regex_match(pathname, path_match, reg)) {
119  //cout << "Matched to target" << endl;
120  toNormElements.push_back(*element);
121  //cout << "Filled the collection" << endl;
122  }
123  }
124  }
125 
126  for (vector<MonitorElement*>::const_iterator matchingElement = toNormElements.begin();
127  matchingElement != toNormElements.end();
128  ++matchingElement) {
129  string meName = (*matchingElement)->getFullname();
130  string dir = meName.substr(0, meName.rfind('/'));
131 
132  if (refsMap.find(dir) == refsMap.end()) {
133  edm::LogInfo("DQMHistNormalizer") << "DQMHistNormalizer::endRun: Error! normalizing references for " << meName
134  << " not found! Skipping...";
135  continue;
136  }
137 
138  float norm = refsMap[dir]->getTH1()->GetEntries();
139  TH1* hist = (*matchingElement)->getTH1();
140  if (norm != 0.) {
141  if (!hist->GetSumw2N())
142  hist->Sumw2();
143  hist->Scale(1 / norm); //use option "width" to divide the bin contents and errors by the bin width?
144  } else {
145  edm::LogInfo("DQMHistNormalizer") << "DQMHistNormalizer::endRun: Error! Normalization failed in "
146  << hist->GetTitle() << "!";
147  }
148 
149  } // for(vector<MonitorElement *>::const_iterator matchingElement = matchingElemts.begin(); matchingElement = matchingElemts.end(); ++matchingElement)
150 }
vector< string > plotNamesToNormalize_
Log< level::Error, false > LogError
Log< level::Info, false > LogInfo
std::string globToRegex(const std::string &s)

Member Data Documentation

◆ plotNamesToNormalize_

vector<string> DQMHistNormalizer::plotNamesToNormalize_
private

Definition at line 57 of file DQMHistNormalizer.cc.

Referenced by endRun().

◆ reference_

string DQMHistNormalizer::reference_
private

Definition at line 58 of file DQMHistNormalizer.cc.

Referenced by endRun().