CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
MEtoMEComparitor Class Reference

#include <DQMOffline/MEtoMEComparitor/src/MEtoMEComparitor.cc>

Inheritance diagram for MEtoMEComparitor:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 MEtoMEComparitor (const edm::ParameterSet &)
 
 ~MEtoMEComparitor () 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

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void beginRun (const edm::Run &iRun, const edm::EventSetup &iSetup) override
 
template<class T >
void book (const std::string &directory, const std::string &type, const T *h)
 
template<class W , class T >
void compare (const W &where, const std::string &instance)
 
void endJob () override
 
void endLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) override
 
void endRun (const edm::Run &iRun, const edm::EventSetup &iSetup) override
 
template<class T >
void keepBadHistograms (const std::string &directory, const T *h_new, const T *h_ref)
 

Private Attributes

bool _autoProcess
 
DQMStore_dbe
 
double _diffgoodness
 
unsigned int _dirDepth
 
double _KSgoodness
 
std::string _lumiInstance
 
std::string _moduleLabel
 
double _overallgoodness
 
std::string _process_new
 
std::string _process_ref
 
std::string _runInstance
 

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

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 50 of file MEtoMEComparitor.h.

Constructor & Destructor Documentation

MEtoMEComparitor::MEtoMEComparitor ( const edm::ParameterSet iConfig)
explicit

Definition at line 27 of file MEtoMEComparitor.cc.

References _autoProcess, _dbe, _diffgoodness, _dirDepth, _KSgoodness, _lumiInstance, _moduleLabel, _overallgoodness, _process_new, _process_ref, _runInstance, edm::ParameterSet::getParameter(), Utilities::operator, AlCaHLTBitMon_QueryRunRegistry::string, and ~MEtoMEComparitor().

29 {
30  _moduleLabel = iConfig.getParameter<std::string>("MEtoEDMLabel");
31 
32  _lumiInstance = iConfig.getParameter<std::string>("lumiInstance");
33  _runInstance = iConfig.getParameter<std::string>("runInstance");
34 
35  _process_ref = iConfig.getParameter<std::string>("processRef");
36  _process_new = iConfig.getParameter<std::string>("processNew");
37 
38  _autoProcess=iConfig.getParameter<bool>("autoProcess");
39 
40  _KSgoodness = iConfig.getParameter<double>("KSgoodness");
41  _diffgoodness = iConfig.getParameter<double>("Diffgoodness");
42  _dirDepth = iConfig.getParameter<unsigned int>("dirDepth");
43  _overallgoodness = iConfig.getParameter<double>("OverAllgoodness");
44 
46 
47 
48 }
T getParameter(std::string const &) const
std::string _lumiInstance
std::string _process_ref
std::string _process_new
unsigned int _dirDepth
std::string _runInstance
std::string _moduleLabel
MEtoMEComparitor::~MEtoMEComparitor ( )
overridedefault

Referenced by MEtoMEComparitor().

Member Function Documentation

void MEtoMEComparitor::analyze ( const edm::Event ,
const edm::EventSetup  
)
inlineoverrideprivate
void MEtoMEComparitor::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 285 of file MEtoMEComparitor.cc.

286 {
287 }
void MEtoMEComparitor::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 63 of file MEtoMEComparitor.cc.

References _autoProcess, _process_new, _process_ref, gather_cfg::cout, edm::Run::processHistory(), and edm::ProcessHistory::rbegin().

Referenced by analyze().

64 {
65  if (_autoProcess)
66  {
67  const edm::ProcessHistory& iHistory=iRun.processHistory();
68 
69  auto hi=iHistory.rbegin();
70  _process_new=hi->processName();
71  hi++;
72  _process_ref=hi->processName();
73  std::cout<<_process_ref<<" vs "<<_process_new<<std::endl;
74  }
75 }
const_reverse_iterator rbegin() const
std::string _process_ref
ProcessHistory const & processHistory() const
Definition: Run.cc:121
std::string _process_new
template<class T >
void MEtoMEComparitor::book ( const std::string &  directory,
const std::string &  type,
const T h 
)
private

Definition at line 89 of file MEtoMEComparitor.cc.

References _dbe, DQMStore::book1D(), DQMStore::book1DD(), DQMStore::book1S(), h, and DQMStore::setCurrentFolder().

Referenced by analyze(), and keepBadHistograms().

89  {
91  std::type_info const & tp = typeid(*h);
92  if (tp == typeid(TH1S))
93  _dbe->book1S(h->GetName(),dynamic_cast<TH1S*>(const_cast<T*>(h)));
94  else if (tp == typeid(TH1F))
95  _dbe->book1D(h->GetName(),dynamic_cast<TH1F*>(const_cast<T*>(h)));
96  else if (tp == typeid(TH1D))
97  _dbe->book1DD(h->GetName(),dynamic_cast<TH1D*>(const_cast<T*>(h)));
98 }
type
Definition: HCALResponse.h:21
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:882
MonitorElement * book1DD(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:914
long double T
MonitorElement * book1S(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:898
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:588
template<class W , class T >
void MEtoMEComparitor::compare ( const W &  where,
const std::string &  instance 
)
private

Definition at line 125 of file MEtoMEComparitor.cc.

References _diffgoodness, _dirDepth, _KSgoodness, _moduleLabel, _overallgoodness, _process_new, _process_ref, funct::abs(), dir, cppFunctionSkipper::exception, edm::HandleBase::failedToGet(), dedxEstimators_cff::fraction, createfilelist::int, keepBadHistograms(), LogDebug, HPSPFTaus_cff::mapping, split, AlCaHLTBitMon_QueryRunRegistry::string, and heppy_report::summary.

Referenced by analyze().

125  {
126 
127  edm::Handle<MEtoEDM<T> > metoedm_ref;
128  edm::Handle<MEtoEDM<T> > metoedm_new;
129  where.getByLabel(edm::InputTag(_moduleLabel,
130  instance,
131  _process_ref),
132  metoedm_ref);
133  where.getByLabel(edm::InputTag(_moduleLabel,
134  instance,
135  _process_new),
136  metoedm_new);
137 
138  if (metoedm_ref.failedToGet() || metoedm_new.failedToGet()){
139  edm::LogError("ProductNotFound")<<"MEtoMEComparitor did not find his products.";
140  return;
141  }
142 
143  using MEtoEDMObject = typename MEtoEDM<T>::MEtoEDMObject;
144 
145  const std::vector<MEtoEDMObject> & metoedmobject_ref = metoedm_ref->getMEtoEdmObject();
146  const std::vector<MEtoEDMObject> & metoedmobject_new = metoedm_new->getMEtoEdmObject();
147 
148  typedef std::map<std::string, std::pair<const MEtoEDMObject*, const MEtoEDMObject*> > Mapping;
149  typedef typename std::map<std::string, std::pair<const MEtoEDMObject*, const MEtoEDMObject*> >::iterator Mapping_iterator;
150 
151  Mapping mapping;
152 
153  LogDebug("MEtoMEComparitor")<<"going to do the mapping from "<<metoedmobject_ref.size()<<" x "<<metoedmobject_new.size();
154  unsigned int countMe=0;
155  for (unsigned int i_new=0; i_new!= metoedmobject_new.size(); ++i_new){
156  const std::string & pathname = metoedmobject_new[i_new].name;
157  if (metoedmobject_new[i_new].object.GetEntries()==0 ||
158  metoedmobject_new[i_new].object.Integral()==0){
159  countMe--;
160  continue;
161  }
162  mapping[pathname]=std::make_pair(&metoedmobject_new[i_new],(const MEtoEDMObject*)nullptr);
163  }
164  for (unsigned int i_ref=0; i_ref!= metoedmobject_ref.size() ; ++i_ref){
165  const std::string & pathname = metoedmobject_ref[i_ref].name;
166  auto there = mapping.find(pathname);
167  if (there != mapping.end()){
168  there->second.second = &metoedmobject_ref[i_ref];
169  }
170  }
171 
172  LogDebug("MEtoMEComparitor")<<"found "<<mapping.size()<<" pairs of plots";
173  countMe=0;
174 
175  unsigned int nNoMatch=0;
176  unsigned int nEmpty=0;
177  unsigned int nHollow=0;
178  unsigned int nGoodKS=0;
179  unsigned int nBadKS=0;
180  unsigned int nBadDiff=0;
181  unsigned int nGoodDiff=0;
182 
183  typedef std::map<std::string, std::pair<unsigned int,unsigned int> > Subs;
184  Subs subSystems;
185 
186  for (auto it = mapping.begin();
187  it!=mapping.end();
188  ++it){
189  if (!it->second.second){
190  //this is expected by how the map was created
191  nNoMatch++;
192  continue;
193  }
194  const T * h_ref = &it->second.second->object;
195  const T * h_new = &it->second.first->object;
196 
197  lat::StringList dir = lat::StringOps::split(it->second.second->name,"/");
198  std::string subsystem = dir[0];
199  if (dir.size()>=_dirDepth)
200  for (unsigned int iD=1;iD!=_dirDepth;++iD) subsystem+="/"+dir[iD];
201  subSystems[subsystem].first++;
202 
203  if (h_ref->GetEntries()!=0 && h_ref->Integral()!=0){
204  double KS=0;
205  bool cannotComputeKS=false;
206  try {
207  KS = h_new->KolmogorovTest(h_ref);
208  }
209  catch( cms::Exception& exception ){
210  cannotComputeKS=true;
211  }
212  if (KS<_KSgoodness){
213 
214  unsigned int total_ref=0;
215  unsigned int absdiff=0;
216  for (unsigned int iBin=0;
217  iBin!=(unsigned int)h_new->GetNbinsX()+1 ;
218  ++iBin){
219  total_ref+=h_ref->GetBinContent(iBin);
220  absdiff=std::abs(h_new->GetBinContent(iBin) - h_ref->GetBinContent(iBin));
221  }
222  double relativediff=1;
223  if (total_ref!=0){
224  relativediff=absdiff / (double) total_ref;
225  }
226  if (relativediff > _diffgoodness ){
227  edm::LogWarning("MEtoMEComparitor")<<"for "<<h_new->GetName()
228  <<" in "<<it->first
229  <<" the KS is "<<KS*100.<<" %"
230  <<" and the relative diff is: "<<relativediff*100.<<" %"
231  <<" KS"<<((cannotComputeKS)?" not valid":" is valid");
232  //std::string(" KolmogorovTest is not happy on : ")+h_new->GetName() : "";
233  //there you want to output the plots somewhere
234  keepBadHistograms(subsystem,h_new,h_ref);
235 
236  nBadDiff++;
237  subSystems[subsystem].second++;
238  }else{
239  nGoodDiff++;
240  }
241  nBadKS++;
242  }
243  else
244  nGoodKS++;
245  }
246  else{
247  if (h_ref->GetEntries()==0)
248  nEmpty++;
249  else
250  nHollow++;
251  LogDebug("MEtoMEComparitor")<<h_new->GetName() <<" in "<<it->first <<" is empty";
252  countMe--;
253  }
254 
255  }
256 
257  if (!mapping.empty()){
258  std::stringstream summary;
259  summary<<" Summary :"
260  <<"\n not matched : "<<nNoMatch
261  <<"\n empty : "<<nEmpty
262  <<"\n integral zero : "<<nHollow
263  <<"\n good KS : "<<nGoodKS
264  <<"\n bad KS : "<<nBadKS
265  <<"\n bad diff : "<<nBadDiff
266  <<"\n godd diff : "<<nGoodDiff;
267  bool tell=false;
268  for (auto & subSystem : subSystems){
269  double fraction = 1-(subSystem.second.second / (double)subSystem.second.first);
270  summary<<std::endl<<"Subsytem: "<<subSystem.first<<" has "<< fraction*100<<" % goodness";
271  if (fraction < _overallgoodness)
272  tell=true;
273  }
274  if (tell)
275  edm::LogWarning("MEtoMEComparitor")<<summary.str();
276  else
277  edm::LogInfo("MEtoMEComparitor")<<summary.str();
278  }
279 
280 }
#define LogDebug(id)
static PFTauRenderPlugin instance
std::string _process_ref
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string _process_new
bool failedToGet() const
Definition: HandleBase.h:78
void keepBadHistograms(const std::string &directory, const T *h_new, const T *h_ref)
unsigned int _dirDepth
dbl *** dir
Definition: mlp_gen.cc:35
long double T
double split
Definition: MVATrainer.cc:139
std::string _moduleLabel
void MEtoMEComparitor::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 291 of file MEtoMEComparitor.cc.

Referenced by analyze().

291  {
292 }
void MEtoMEComparitor::endLuminosityBlock ( const edm::LuminosityBlock iLumi,
const edm::EventSetup  
)
overrideprivate

Definition at line 54 of file MEtoMEComparitor.cc.

References _lumiInstance.

Referenced by analyze().

55 {
56 
57  compare<edm::LuminosityBlock,TH1S>(iLumi,_lumiInstance);
58  compare<edm::LuminosityBlock,TH1F>(iLumi,_lumiInstance);
59  compare<edm::LuminosityBlock,TH1D>(iLumi,_lumiInstance);
60 }
std::string _lumiInstance
void MEtoMEComparitor::endRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 78 of file MEtoMEComparitor.cc.

References _runInstance.

Referenced by analyze().

79 {
80 
81  compare<edm::Run,TH1S>(iRun,_runInstance);
82  compare<edm::Run,TH1F>(iRun,_runInstance);
83  compare<edm::Run,TH1D>(iRun,_runInstance);
84 
85 }
std::string _runInstance
template<class T >
void MEtoMEComparitor::keepBadHistograms ( const std::string &  directory,
const T h_new,
const T h_ref 
)
private

Definition at line 100 of file MEtoMEComparitor.cc.

References book(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by analyze(), and compare().

100  {
101  //put it in a collection rather.
102 
103 
104  std::string d_n(h_new->GetName());
105  d_n+="_diff";
106  auto * difference = new T(d_n.c_str(),
107  h_new->GetTitle(),
108  h_new->GetNbinsX(),
109  h_new->GetXaxis()->GetXmin(),
110  h_new->GetXaxis()->GetXmax());
111  difference->Add(h_new);
112  difference->Add(h_ref,-1.);
113 
114  book(directory,"Ref",h_ref);
115  book(directory,"New",h_new);
116  book(directory,"Diff",difference);
117  delete difference;
118 
119 }
void book(const std::string &directory, const std::string &type, const T *h)
long double T

Member Data Documentation

bool MEtoMEComparitor::_autoProcess
private

Definition at line 76 of file MEtoMEComparitor.h.

Referenced by beginRun(), and MEtoMEComparitor().

DQMStore* MEtoMEComparitor::_dbe
private

Definition at line 68 of file MEtoMEComparitor.h.

Referenced by book(), and MEtoMEComparitor().

double MEtoMEComparitor::_diffgoodness
private

Definition at line 79 of file MEtoMEComparitor.h.

Referenced by compare(), and MEtoMEComparitor().

unsigned int MEtoMEComparitor::_dirDepth
private

Definition at line 80 of file MEtoMEComparitor.h.

Referenced by compare(), and MEtoMEComparitor().

double MEtoMEComparitor::_KSgoodness
private

Definition at line 78 of file MEtoMEComparitor.h.

Referenced by compare(), and MEtoMEComparitor().

std::string MEtoMEComparitor::_lumiInstance
private

Definition at line 71 of file MEtoMEComparitor.h.

Referenced by endLuminosityBlock(), and MEtoMEComparitor().

std::string MEtoMEComparitor::_moduleLabel
private

Definition at line 69 of file MEtoMEComparitor.h.

Referenced by compare(), and MEtoMEComparitor().

double MEtoMEComparitor::_overallgoodness
private

Definition at line 81 of file MEtoMEComparitor.h.

Referenced by compare(), and MEtoMEComparitor().

std::string MEtoMEComparitor::_process_new
private

Definition at line 75 of file MEtoMEComparitor.h.

Referenced by beginRun(), compare(), and MEtoMEComparitor().

std::string MEtoMEComparitor::_process_ref
private

Definition at line 74 of file MEtoMEComparitor.h.

Referenced by beginRun(), compare(), and MEtoMEComparitor().

std::string MEtoMEComparitor::_runInstance
private

Definition at line 72 of file MEtoMEComparitor.h.

Referenced by endRun(), and MEtoMEComparitor().