CMS 3D CMS Logo

OffsetAnalyzerDQM.cc
Go to the documentation of this file.
8 
12 
13 #include <vector>
14 #include <map>
15 
17 public:
19  void analyze(const edm::Event&, const edm::EventSetup&) override;
20 
21 protected:
22  //Book histograms
23  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
24  int getEtaIndex(float eta);
25 
26 private:
27  struct Plot1D {
29  int nxbins;
30  double xlow, xhigh;
32 
33  Plot1D() : name(""), title(""), dir(""), nxbins(0), xlow(0), xhigh(0), plot(nullptr) {}
34  Plot1D(const std::string& n, const std::string& t, const std::string& d, int nx, double x0, double x1)
35  : name(n), title(t), dir(d), nxbins(nx), xlow(x0), xhigh(x1), plot(nullptr) {}
36 
37  virtual void book(DQMStore::IBooker& booker) {
38  booker.setCurrentFolder(dir);
39  plot = booker.book1D(name, title, nxbins, xlow, xhigh);
40  }
41 
42  virtual void fill(float value) {
43  assert(plot != nullptr);
44  plot->Fill(value);
45  }
46 
47  virtual ~Plot1D() {}
48  };
49 
50  struct PlotProfile : public Plot1D {
51  std::vector<double> xbins;
52  int nybins;
53  double ylow, yhigh;
54  PlotProfile() : Plot1D(), xbins(0), nybins(0), ylow(0), yhigh(0) {}
56  const std::string& t,
57  const std::string& d,
58  int nx,
59  double x0,
60  double x1,
61  const std::vector<double>& vx,
62  int ny,
63  double y0,
64  double y1)
65  : Plot1D(n, t, d, nx, x0, x1), xbins(vx), nybins(ny), ylow(y0), yhigh(y1) {}
66 
67  void book(DQMStore::IBooker& booker) override {
68  booker.setCurrentFolder(dir);
69  plot = booker.bookProfile(name, title, xbins.size() - 1, &xbins[0], nybins, ylow, yhigh, " ");
70  }
71  //make other booker methods for uniform binning
72 
73  void fill2D(double value1, double value2) {
74  assert(plot != nullptr);
76  }
77  };
78 
79  std::map<std::string, Plot1D> th1dPlots;
80  std::map<std::string, PlotProfile> offsetPlots;
81  std::map<int, std::string> pdgMap;
82 
84  std::vector<std::string> pftypes;
85  std::vector<double> etabins;
86 
87  int muHigh;
88  int npvHigh;
89 
93 };
94 
96  offsetPlotBaseName = iConfig.getParameter<std::string>("offsetPlotBaseName");
97 
98  pvToken = consumes<edm::View<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvTag"));
99  muToken = consumes<edm::View<PileupSummaryInfo>>(iConfig.getParameter<edm::InputTag>("muTag"));
100  pfToken = consumes<edm::View<pat::PackedCandidate>>(iConfig.getParameter<edm::InputTag>("pfTag"));
101 
102  etabins = iConfig.getParameter<std::vector<double>>("etabins");
103  pftypes = iConfig.getParameter<std::vector<std::string>>("pftypes");
104 
105  muHigh = iConfig.getUntrackedParameter<int>("muHigh");
106  npvHigh = iConfig.getUntrackedParameter<int>("npvHigh");
107 
108  //initialize offset plots
109  const auto& offset_psets = iConfig.getParameter<std::vector<edm::ParameterSet>>("offsetPlots");
110  for (auto& pset : offset_psets) {
111  std::string name = pset.getParameter<std::string>("name");
112  std::string title = pset.getParameter<std::string>("title");
113  std::string dir = pset.getParameter<std::string>("dir");
114  std::vector<double> vx = pset.getParameter<std::vector<double>>("vx");
115  int ny = pset.getParameter<uint32_t>("ny");
116  double y0 = pset.getParameter<double>("y0");
117  double y1 = pset.getParameter<double>("y1");
118 
119  offsetPlots[name] = PlotProfile(name, title, dir, 0, 0, 0, vx, ny, y0, y1);
120  }
121 
122  //initialize th1d
123  const auto& th1d_psets = iConfig.getParameter<std::vector<edm::ParameterSet>>("th1dPlots");
124  for (auto& pset : th1d_psets) {
125  std::string name = pset.getParameter<std::string>("name");
126  std::string title = pset.getParameter<std::string>("title");
127  std::string dir = pset.getParameter<std::string>("dir");
128  int nx = pset.getParameter<uint32_t>("nx");
129  double x0 = pset.getParameter<double>("x0");
130  double x1 = pset.getParameter<double>("x1");
131 
132  th1dPlots[name] = Plot1D(name, title, dir, nx, x0, x1);
133  }
134 
135  //create pdg map
136  std::vector<uint32_t> pdgKeys = iConfig.getParameter<std::vector<uint32_t>>("pdgKeys");
137  std::vector<std::string> pdgStrs = iConfig.getParameter<std::vector<std::string>>("pdgStrs");
138  for (int i = 0, n = pdgKeys.size(); i < n; i++)
139  pdgMap[pdgKeys[i]] = pdgStrs[i];
140 }
141 
143  //std::cout << "OffsetAnalyzerDQM booking offset histograms" << std::endl;
144  for (auto& pair : offsetPlots) {
145  pair.second.book(booker);
146  }
147  for (auto& pair : th1dPlots) {
148  pair.second.book(booker);
149  }
150 }
151 
153  //npv//
155  iEvent.getByToken(pvToken, vertexHandle);
156 
157  unsigned int nPVall = vertexHandle->size();
158  bool isGoodPV[nPVall];
159  for (size_t i = 0; i < nPVall; ++i)
160  isGoodPV[i] = false;
161 
162  int npv = 0;
163  for (unsigned int i = 0; i < nPVall; i++) {
164  const auto& pv = vertexHandle->at(i);
165 
166  if (!pv.isFake() && pv.ndof() >= 4 && fabs(pv.z()) <= 24.0 && fabs(pv.position().rho()) <= 2.0) {
167  npv++;
168  isGoodPV[i] = true;
169  }
170  }
171  th1dPlots["npv"].fill(npv);
172  int npv_in_range = npv;
173  if (npv_in_range < 0)
174  npv_in_range = 0;
175  else if (npv_in_range >= npvHigh)
176  npv_in_range = npvHigh - 1; // make sure int_mu won't lead to non-existing ME
177 
178  //mu//
179  int int_mu = -1;
181  if (iEvent.getByToken(muToken, muHandle)) {
182  const auto& summary = *muHandle;
183  auto it = std::find_if(summary.begin(), summary.end(), [](const auto& s) { return s.getBunchCrossing() == 0; });
184 
185  if (it->getBunchCrossing() != 0) {
186  edm::LogError("OffsetAnalyzerDQM") << "Cannot find the in-time pileup info " << it->getBunchCrossing();
187  } else {
188  float mu = it->getTrueNumInteractions();
189  th1dPlots["mu"].fill(mu);
190  int_mu = mu + 0.5;
191  }
192  }
193  if (int_mu >= muHigh)
194  int_mu = muHigh - 1; // make sure int_mu won't lead to non-existing ME
195 
196  //create map of pftypes vs total energy / eta
197  std::map<std::string, std::vector<double>> m_pftype_etaE;
198  int nEta = etabins.size() - 1;
199  for (const auto& pftype : pftypes)
200  m_pftype_etaE[pftype].assign(nEta, 0.0);
201 
202  //pf particles//
204  iEvent.getByToken(pfToken, pfHandle);
205 
206  for (unsigned int i = 0, n = pfHandle->size(); i < n; i++) {
207  const auto& cand = pfHandle->at(i);
208 
209  int etaIndex = getEtaIndex(cand.eta());
210  std::string pftype = pdgMap[abs(cand.pdgId())];
211  if (etaIndex == -1 || pftype.empty())
212  continue;
213 
214  if (pftype == "chm") { //check charged hadrons ONLY
215  bool attached = false;
216 
217  for (unsigned int ipv = 0; ipv < nPVall && !attached; ipv++) {
218  if (isGoodPV[ipv] && cand.fromPV(ipv) == 3)
219  attached = true; //pv used in fit
220  }
221  if (!attached)
222  pftype = "chu"; //unmatched charged hadron
223  }
225  /*
226  reco::TrackRef candTrkRef( cand.trackRef() );
227  if ( pftype == "chm" && !candTrkRef.isNull() ) { //check charged hadrons ONLY
228  bool attached = false;
229 
230  for (auto ipv=vertexHandle->begin(), endpv=vertexHandle->end(); ipv != endpv && !attached; ++ipv) {
231  if ( !ipv->isFake() && ipv->ndof() >= 4 && fabs(ipv->z()) < 24 ) { //must be attached to a good pv
232 
233  for(auto ivtrk=ipv->tracks_begin(), endvtrk=ipv->tracks_end(); ivtrk != endvtrk && !attached; ++ivtrk) {
234  reco::TrackRef pvTrkRef(ivtrk->castTo<reco::TrackRef>());
235  if (pvTrkRef == candTrkRef) attached = true;
236  }
237  }
238  }
239  if (!attached) pftype = "chu"; //unmatched charged hadron
240  }
241 */
243  m_pftype_etaE[pftype][etaIndex] += cand.et();
244  }
245 
246  for (const auto& pair : m_pftype_etaE) {
247  std::string pftype = pair.first;
248  std::vector<double> etaE = pair.second;
249 
250  std::string offset_name_npv = offsetPlotBaseName + "_npv" + std::to_string(npv_in_range) + "_" + pftype;
251  if (offsetPlots.find(offset_name_npv) == offsetPlots.end())
252  return; //npv is out of range ()
253 
254  for (int i = 0; i < nEta; i++) {
255  double eta = 0.5 * (etabins[i] + etabins[i + 1]);
256  offsetPlots[offset_name_npv].fill2D(eta, etaE[i]);
257  }
258 
259  if (int_mu != -1) {
260  std::string offset_name_mu = offsetPlotBaseName + "_mu" + std::to_string(int_mu) + "_" + pftype;
261  if (offsetPlots.find(offset_name_mu) == offsetPlots.end())
262  return; //mu is out of range
263 
264  for (int i = 0; i < nEta; i++) {
265  double eta = 0.5 * (etabins[i] + etabins[i + 1]);
266  offsetPlots[offset_name_mu].fill2D(eta, etaE[i]);
267  }
268  }
269  }
270 }
271 
273  int nEta = etabins.size() - 1;
274 
275  for (int i = 0; i < nEta; i++) {
276  if (etabins[i] <= eta && eta < etabins[i + 1])
277  return i;
278  }
279  if (eta == etabins[nEta])
280  return nEta - 1;
281  else
282  return -1;
283 }
284 
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
PileupSummaryInfo.h
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
OffsetAnalyzerDQM::Plot1D::fill
virtual void fill(float value)
Definition: OffsetAnalyzerDQM.cc:42
HLT_FULL_cff.nEta
nEta
Definition: HLT_FULL_cff.py:6586
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
OffsetAnalyzerDQM::pftypes
std::vector< std::string > pftypes
Definition: OffsetAnalyzerDQM.cc:84
OffsetAnalyzerDQM::PlotProfile::nybins
int nybins
Definition: OffsetAnalyzerDQM.cc:52
Matchers.h
OffsetAnalyzerDQM::Plot1D::Plot1D
Plot1D()
Definition: OffsetAnalyzerDQM.cc:33
offsetAnalyzerDQM_cff.pdgKeys
pdgKeys
Definition: offsetAnalyzerDQM_cff.py:70
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
cms::cuda::assert
assert(be >=bs)
DQMStore.h
OffsetAnalyzerDQM
Definition: OffsetAnalyzerDQM.cc:16
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
OffsetAnalyzerDQM::pfToken
edm::EDGetTokenT< edm::View< pat::PackedCandidate > > pfToken
Definition: OffsetAnalyzerDQM.cc:92
OffsetAnalyzerDQM::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: OffsetAnalyzerDQM.cc:152
edm::Handle
Definition: AssociativeIterator.h:50
OffsetAnalyzerDQM::Plot1D::Plot1D
Plot1D(const std::string &n, const std::string &t, const std::string &d, int nx, double x0, double x1)
Definition: OffsetAnalyzerDQM.cc:34
OffsetAnalyzerDQM::Plot1D::plot
MonitorElement * plot
Definition: OffsetAnalyzerDQM.cc:31
MakerMacros.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
alignCSCRings.s
s
Definition: alignCSCRings.py:92
OffsetAnalyzerDQM::PlotProfile::fill2D
void fill2D(double value1, double value2)
Definition: OffsetAnalyzerDQM.cc:73
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
OffsetAnalyzerDQM::pdgMap
std::map< int, std::string > pdgMap
Definition: OffsetAnalyzerDQM.cc:81
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
OffsetAnalyzerDQM::Plot1D::xhigh
double xhigh
Definition: OffsetAnalyzerDQM.cc:30
PVValHelper::eta
Definition: PVValidationHelpers.h:69
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
OffsetAnalyzerDQM::Plot1D
Definition: OffsetAnalyzerDQM.cc:27
OffsetAnalyzerDQM::Plot1D::dir
std::string dir
Definition: OffsetAnalyzerDQM.cc:28
dqm::implementation::IBooker::bookProfile
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
OffsetAnalyzerDQM::PlotProfile::xbins
std::vector< double > xbins
Definition: OffsetAnalyzerDQM.cc:51
DQMEDAnalyzer.h
OffsetAnalyzerDQM::PlotProfile
Definition: OffsetAnalyzerDQM.cc:50
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
OffsetAnalyzerDQM::etabins
std::vector< double > etabins
Definition: OffsetAnalyzerDQM.cc:85
OffsetAnalyzerDQM::PlotProfile::ylow
double ylow
Definition: OffsetAnalyzerDQM.cc:53
OffsetAnalyzerDQM::OffsetAnalyzerDQM
OffsetAnalyzerDQM(const edm::ParameterSet &)
Definition: OffsetAnalyzerDQM.cc:95
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
Plot1D
Definition: PlotTypes.h:4
HLT_FULL_cff.value2
value2
Definition: HLT_FULL_cff.py:9868
PackedCandidate.h
cand
Definition: decayParser.h:32
OffsetAnalyzerDQM::Plot1D::nxbins
int nxbins
Definition: OffsetAnalyzerDQM.cc:29
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
value
Definition: value.py:1
OffsetAnalyzerDQM::Plot1D::~Plot1D
virtual ~Plot1D()
Definition: OffsetAnalyzerDQM.cc:47
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
InputTag.h
offsetAnalyzerDQM_cff.pdgStrs
pdgStrs
Definition: offsetAnalyzerDQM_cff.py:71
OffsetAnalyzerDQM::PlotProfile::yhigh
double yhigh
Definition: OffsetAnalyzerDQM.cc:53
OffsetAnalyzerDQM::getEtaIndex
int getEtaIndex(float eta)
Definition: OffsetAnalyzerDQM.cc:272
OffsetAnalyzerDQM::Plot1D::title
std::string title
Definition: OffsetAnalyzerDQM.cc:28
HLT_FULL_cff.value1
value1
Definition: HLT_FULL_cff.py:9869
OffsetAnalyzerDQM::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: OffsetAnalyzerDQM.cc:142
Frameworkfwd.h
OffsetAnalyzerDQM::muHigh
int muHigh
Definition: OffsetAnalyzerDQM.cc:87
OffsetAnalyzerDQM::Plot1D::name
std::string name
Definition: OffsetAnalyzerDQM.cc:28
OffsetAnalyzerDQM::npvHigh
int npvHigh
Definition: OffsetAnalyzerDQM.cc:88
OffsetAnalyzerDQM::PlotProfile::PlotProfile
PlotProfile()
Definition: OffsetAnalyzerDQM.cc:54
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
OffsetAnalyzerDQM::offsetPlotBaseName
std::string offsetPlotBaseName
Definition: OffsetAnalyzerDQM.cc:83
dqm::implementation::IBooker
Definition: DQMStore.h:43
OffsetAnalyzerDQM::muToken
edm::EDGetTokenT< edm::View< PileupSummaryInfo > > muToken
Definition: OffsetAnalyzerDQM.cc:91
ztail.d
d
Definition: ztail.py:151
OffsetAnalyzerDQM::PlotProfile::PlotProfile
PlotProfile(const std::string &n, const std::string &t, const std::string &d, int nx, double x0, double x1, const std::vector< double > &vx, int ny, double y0, double y1)
Definition: OffsetAnalyzerDQM.cc:55
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
OffsetAnalyzerDQM::offsetPlots
std::map< std::string, PlotProfile > offsetPlots
Definition: OffsetAnalyzerDQM.cc:80
OffsetAnalyzerDQM::PlotProfile::book
void book(DQMStore::IBooker &booker) override
Definition: OffsetAnalyzerDQM.cc:67
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
OffsetAnalyzerDQM::pvToken
edm::EDGetTokenT< edm::View< reco::Vertex > > pvToken
Definition: OffsetAnalyzerDQM.cc:90
edm::InputTag
Definition: InputTag.h:15
OffsetAnalyzerDQM::Plot1D::book
virtual void book(DQMStore::IBooker &booker)
Definition: OffsetAnalyzerDQM.cc:37
OffsetAnalyzerDQM::Plot1D::xlow
double xlow
Definition: OffsetAnalyzerDQM.cc:30
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
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
OffsetAnalyzerDQM::th1dPlots
std::map< std::string, Plot1D > th1dPlots
Definition: OffsetAnalyzerDQM.cc:79
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23