CMS 3D CMS Logo

OffsetDQMPostProcessor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Validation/RecoParticleFlow
4 // Class: OffsetDQMPostProcessor.cc
5 //
6 // Original Author: "Kenichi Hatakeyama"
7 //
8 
15 
18 
19 //
20 // class decleration
21 //
22 
24 public:
26  ~OffsetDQMPostProcessor() override;
27 
28 private:
30 
33  float offsetR;
34  std::vector<std::string> pftypes;
35  std::vector<std::string> offsetVariableTypes;
36  int muHigh;
37  int npvHigh;
38 
39  bool debug = false;
40 };
41 
42 //
43 // constructors and destructor
44 //
46  offsetPlotBaseName = iConfig.getParameter<std::string>("offsetPlotBaseName");
47  offsetDir = iConfig.getParameter<std::string>("offsetDir");
48  offsetVariableTypes = iConfig.getParameter<std::vector<std::string> >("offsetVariableTypes");
49  offsetR = iConfig.getUntrackedParameter<double>("offsetR");
50  pftypes = iConfig.getParameter<std::vector<std::string> >("pftypes");
51  muHigh = iConfig.getUntrackedParameter<int>("muHigh");
52  npvHigh = iConfig.getUntrackedParameter<int>("npvHigh");
53 };
54 
56 
57 // ------------ method called right after a run ends ------------
60 
61  std::string stitle;
62  std::vector<MonitorElement*> vME;
63  std::vector<std::string> MEStrings = iget_.getMEs();
64  std::for_each(MEStrings.begin(), MEStrings.end(), [&](auto& s) { s.insert(0, offsetDir); });
65 
66  // temporary ME and root objects
67  MonitorElement* mtmp;
68  TProfile* hproftmp;
69  TH1F* htmp;
70  TH1F* hscaled;
71 
72  //
73  // Offset plots vs eta
74  //
75  for (std::vector<std::string>::const_iterator i = offsetVariableTypes.begin(); i != offsetVariableTypes.end(); ++i) {
76  //
77  // getting the average value for Npv and mu
78  //
79  stitle = offsetDir + (*i);
80  std::vector<std::string>::const_iterator it = std::find(MEStrings.begin(), MEStrings.end(), stitle);
81  if (it == MEStrings.end())
82  continue;
83  mtmp = iget_.get(stitle);
84  float avg = mtmp->getMean();
85  int iavg = int(avg + 0.5); // integer version for identifying correcping ME, in order to get the rounding correctly
86 
87  if (avg < 1.)
88  avg = 1.; // protection against this value going too low
89 
90  if (iavg < 0)
91  iavg = 0; // checking lower bound (avoid division by zero)
92  if (*i == "npv" && iavg >= npvHigh)
93  iavg = npvHigh - 1; // checking upper bound
94  else if (*i == "mu" && iavg >= muHigh)
95  iavg = muHigh - 1; //
96 
97  //
98  // storing the value
99  //
100  stitle = (*i) + "_mean";
101  MonitorElement* MEmean = ibook_.bookFloat(stitle);
102  MEmean->Fill(avg);
103  vME.push_back(MEmean);
104 
105  //
106  // for each pf types
107  //
108  for (std::vector<std::string>::const_iterator j = pftypes.begin(); j != pftypes.end(); ++j) {
109  // accessing profiles
110  std::string str_base = *i + std::to_string(iavg);
111  if ((*i) == "npv")
112  stitle = offsetDir + "npvPlots/" + str_base + "/" + offsetPlotBaseName + "_" + str_base + "_" + (*j);
113  else if ((*i) == "mu")
114  stitle = offsetDir + "muPlots/" + str_base + "/" + offsetPlotBaseName + "_" + str_base + "_" + (*j);
115  else
116  return;
117 
118  // making scaled plot and ME
119  mtmp = iget_.get(stitle);
120  hproftmp = (TProfile*)mtmp->getTProfile();
121  htmp = (TH1F*)hproftmp->ProjectionX();
122  TAxis* xaxis = (TAxis*)htmp->GetXaxis();
123  stitle = offsetPlotBaseName + "_" + str_base + "_" + *j;
124  hscaled = new TH1F(stitle.c_str(), stitle.c_str(), xaxis->GetNbins(), xaxis->GetXbins()->GetArray());
125 
126  htmp->Scale(pow(offsetR, 2) / 2. / float(avg)); // pi*R^2 / (deltaEta*2pi) / <mu or NPV>
127  for (int ibin = 1; ibin <= hscaled->GetNbinsX(); ibin++) { // 1/deltaEta part
128  hscaled->SetBinContent(ibin, htmp->GetBinContent(ibin) / htmp->GetBinWidth(ibin));
129  hscaled->SetBinError(ibin, htmp->GetBinError(ibin) / htmp->GetBinWidth(ibin));
130  }
131 
132  // storing new ME
133  stitle = offsetPlotBaseName + "_" + *i + "_" + *j;
134  mtmp = ibook_.book1D(stitle.c_str(), hscaled);
135  vME.push_back(mtmp);
136  }
137  }
138 
139  //
140  // Checks
141  //
142  if (debug) {
143  for (std::vector<MonitorElement*>::const_iterator i = vME.begin(); i != vME.end(); ++i)
144  (*i)->getTH1F()->Print();
145  }
146 }
147 
DQMEDHarvester.h
mps_fire.i
i
Definition: mps_fire.py:428
dqm::implementation::IBooker::bookFloat
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
LuminosityBlock.h
dqm::implementation::IGetter::getMEs
virtual std::vector< std::string > getMEs() const
Definition: DQMStore.cc:720
OffsetDQMPostProcessor::offsetVariableTypes
std::vector< std::string > offsetVariableTypes
Definition: OffsetDQMPostProcessor.cc:35
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
OffsetDQMPostProcessor::OffsetDQMPostProcessor
OffsetDQMPostProcessor(const edm::ParameterSet &)
Definition: OffsetDQMPostProcessor.cc:45
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
OffsetDQMPostProcessor::pftypes
std::vector< std::string > pftypes
Definition: OffsetDQMPostProcessor.cc:34
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
dqm::legacy::MonitorElement::getTH1F
virtual TH1F * getTH1F() const
Definition: MonitorElement.h:479
OffsetDQMPostProcessor::offsetR
float offsetR
Definition: OffsetDQMPostProcessor.cc:33
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
OffsetDQMPostProcessor::~OffsetDQMPostProcessor
~OffsetDQMPostProcessor() override
Definition: OffsetDQMPostProcessor.cc:55
Run.h
dqm::legacy::MonitorElement::getTProfile
virtual TProfile * getTProfile() const
Definition: MonitorElement.h:507
OffsetDQMPostProcessor::offsetDir
std::string offsetDir
Definition: OffsetDQMPostProcessor.cc:32
OffsetDQMPostProcessor
Definition: OffsetDQMPostProcessor.cc:23
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
OffsetDQMPostProcessor::offsetPlotBaseName
std::string offsetPlotBaseName
Definition: OffsetDQMPostProcessor.cc:31
createfilelist.int
int
Definition: createfilelist.py:10
OffsetDQMPostProcessor::muHigh
int muHigh
Definition: OffsetDQMPostProcessor.cc:36
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DQMEDHarvester
Definition: DQMEDHarvester.py:1
dqm::implementation::IGetter
Definition: DQMStore.h:484
OffsetDQMPostProcessor::dqmEndJob
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: OffsetDQMPostProcessor.cc:58
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
dqm::impl::MonitorElement::getMean
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:549
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm::implementation::IBooker
Definition: DQMStore.h:43
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
LaserClient_cfi.xaxis
xaxis
Definition: LaserClient_cfi.py:49
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
OffsetDQMPostProcessor::npvHigh
int npvHigh
Definition: OffsetDQMPostProcessor.cc:37
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
OffsetDQMPostProcessor::debug
bool debug
Definition: OffsetDQMPostProcessor.cc:39