CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Protected Member Functions | Private Attributes
OffsetAnalyzerDQM Class Reference
Inheritance diagram for OffsetAnalyzerDQM:
DQMEDAnalyzer edm::stream::EDProducer< edm::GlobalCache< DQMEDAnalyzerGlobalCache >, edm::EndRunProducer, edm::EndLuminosityBlockProducer, edm::Accumulator >

Classes

struct  Plot1D
 
struct  PlotProfile
 

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
 OffsetAnalyzerDQM (const edm::ParameterSet &)
 
- Public Member Functions inherited from DQMEDAnalyzer
void accumulate (edm::Event const &event, edm::EventSetup const &setup) final
 
void beginLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
 
void beginRun (edm::Run const &run, edm::EventSetup const &setup) final
 
void beginStream (edm::StreamID id) final
 
virtual void dqmBeginRun (edm::Run const &, edm::EventSetup const &)
 
 DQMEDAnalyzer ()
 
void endLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
 
void endRun (edm::Run const &run, edm::EventSetup const &setup) final
 
virtual bool getCanSaveByLumi ()
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< DQMEDAnalyzerGlobalCache >, edm::EndRunProducer, edm::EndLuminosityBlockProducer, edm::Accumulator >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Protected Member Functions

void bookHistograms (DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
 
int getEtaIndex (float eta)
 
- Protected Member Functions inherited from DQMEDAnalyzer
uint64_t meId () const
 

Private Attributes

std::vector< double > etabins
 
int muHigh
 
edm::EDGetTokenT< edm::View< PileupSummaryInfo > > muToken
 
int npvHigh
 
std::string offsetPlotBaseName
 
std::map< std::string, PlotProfileoffsetPlots
 
std::map< int, std::string > pdgMap
 
edm::EDGetTokenT< edm::View< pat::PackedCandidate > > pfToken
 
std::vector< std::string > pftypes
 
edm::EDGetTokenT< edm::View< reco::Vertex > > pvToken
 
std::map< std::string, Plot1Dth1dPlots
 

Additional Inherited Members

- Public Types inherited from DQMEDAnalyzer
typedef dqm::reco::DQMStore DQMStore
 
typedef dqm::reco::MonitorElement MonitorElement
 
- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< DQMEDAnalyzerGlobalCache >, edm::EndRunProducer, edm::EndLuminosityBlockProducer, edm::Accumulator >
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 
- Static Public Member Functions inherited from DQMEDAnalyzer
static void globalEndJob (DQMEDAnalyzerGlobalCache const *)
 
static void globalEndLuminosityBlockProduce (edm::LuminosityBlock &lumi, edm::EventSetup const &setup, LuminosityBlockContext const *context)
 
static void globalEndRunProduce (edm::Run &run, edm::EventSetup const &setup, RunContext const *context)
 
static std::unique_ptr< DQMEDAnalyzerGlobalCacheinitializeGlobalCache (edm::ParameterSet const &)
 
- Protected Attributes inherited from DQMEDAnalyzer
edm::EDPutTokenT< DQMTokenlumiToken_
 
edm::EDPutTokenT< DQMTokenrunToken_
 
unsigned int streamId_
 

Detailed Description

Definition at line 16 of file OffsetAnalyzerDQM.cc.

Constructor & Destructor Documentation

◆ OffsetAnalyzerDQM()

OffsetAnalyzerDQM::OffsetAnalyzerDQM ( const edm::ParameterSet iConfig)

Definition at line 96 of file OffsetAnalyzerDQM.cc.

References DeadROC_duringRun::dir, etabins, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, muHigh, muToken, dqmiodumpmetadata::n, Skims_PA_cff::name, npvHigh, offsetPlotBaseName, offsetPlots, offsetAnalyzerDQM_cff::pdgKeys, pdgMap, offsetAnalyzerDQM_cff::pdgStrs, pfToken, pftypes, Plot1D, muonDTDigis_cfi::pset, pvToken, AlCaHLTBitMon_QueryRunRegistry::string, th1dPlots, runGCPTkAlMap::title, testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::y1.

96  {
97  offsetPlotBaseName = iConfig.getParameter<std::string>("offsetPlotBaseName");
98 
99  pvToken = consumes<edm::View<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvTag"));
100  muToken = consumes<edm::View<PileupSummaryInfo>>(iConfig.getParameter<edm::InputTag>("muTag"));
101  pfToken = consumes<edm::View<pat::PackedCandidate>>(iConfig.getParameter<edm::InputTag>("pfTag"));
102 
103  etabins = iConfig.getParameter<std::vector<double>>("etabins");
104  pftypes = iConfig.getParameter<std::vector<std::string>>("pftypes");
105 
106  muHigh = iConfig.getUntrackedParameter<int>("muHigh");
107  npvHigh = iConfig.getUntrackedParameter<int>("npvHigh");
108 
109  //initialize offset plots
110  const auto& offset_psets = iConfig.getParameter<std::vector<edm::ParameterSet>>("offsetPlots");
111  for (auto& pset : offset_psets) {
112  std::string name = pset.getParameter<std::string>("name");
113  std::string title = pset.getParameter<std::string>("title");
114  std::string dir = pset.getParameter<std::string>("dir");
115  std::vector<double> vx = pset.getParameter<std::vector<double>>("vx");
116  int ny = pset.getParameter<uint32_t>("ny");
117  double y0 = pset.getParameter<double>("y0");
118  double y1 = pset.getParameter<double>("y1");
119 
120  offsetPlots[name] = PlotProfile(name, title, dir, 0, 0, 0, vx, ny, y0, y1);
121  }
122 
123  //initialize th1d
124  const auto& th1d_psets = iConfig.getParameter<std::vector<edm::ParameterSet>>("th1dPlots");
125  for (auto& pset : th1d_psets) {
126  std::string name = pset.getParameter<std::string>("name");
127  std::string title = pset.getParameter<std::string>("title");
128  std::string dir = pset.getParameter<std::string>("dir");
129  int nx = pset.getParameter<uint32_t>("nx");
130  double x0 = pset.getParameter<double>("x0");
131  double x1 = pset.getParameter<double>("x1");
132 
133  th1dPlots[name] = Plot1D(name, title, dir, nx, x0, x1);
134  }
135 
136  //create pdg map
137  std::vector<uint32_t> pdgKeys = iConfig.getParameter<std::vector<uint32_t>>("pdgKeys");
138  std::vector<std::string> pdgStrs = iConfig.getParameter<std::vector<std::string>>("pdgStrs");
139  for (int i = 0, n = pdgKeys.size(); i < n; i++)
140  pdgMap[pdgKeys[i]] = pdgStrs[i];
141 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::View< PileupSummaryInfo > > muToken
std::map< int, std::string > pdgMap
std::map< std::string, Plot1D > th1dPlots
std::vector< double > etabins
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< edm::View< pat::PackedCandidate > > pfToken
std::string offsetPlotBaseName
std::map< std::string, PlotProfile > offsetPlots
edm::EDGetTokenT< edm::View< reco::Vertex > > pvToken
std::vector< std::string > pftypes

Member Function Documentation

◆ analyze()

void OffsetAnalyzerDQM::analyze ( const edm::Event iEvent,
const edm::EventSetup  
)
overridevirtual

Reimplemented from DQMEDAnalyzer.

Definition at line 153 of file OffsetAnalyzerDQM.cc.

References funct::abs(), PVValHelper::eta, etabins, getEtaIndex(), mps_fire::i, iEvent, amptDefaultParameters_cff::mu, muHigh, muToken, dqmiodumpmetadata::n, HLT_2022v12_cff::nEta, npvHigh, offsetPlotBaseName, offsetPlots, pdgMap, pfToken, pftypes, MetAnalyzer::pv(), pvToken, alignCSCRings::s, AlCaHLTBitMon_QueryRunRegistry::string, edmLumisInFiles::summary, th1dPlots, and cond::impl::to_string().

153  {
154  //npv//
156  iEvent.getByToken(pvToken, vertexHandle);
157 
158  unsigned int nPVall = vertexHandle->size();
159  bool isGoodPV[nPVall];
160  for (size_t i = 0; i < nPVall; ++i)
161  isGoodPV[i] = false;
162 
163  int npv = 0;
164  for (unsigned int i = 0; i < nPVall; i++) {
165  const auto& pv = vertexHandle->at(i);
166 
167  if (!pv.isFake() && pv.ndof() >= 4 && fabs(pv.z()) <= 24.0 && fabs(pv.position().rho()) <= 2.0) {
168  npv++;
169  isGoodPV[i] = true;
170  }
171  }
172  th1dPlots["npv"].fill(npv);
173  int npv_in_range = npv;
174  if (npv_in_range < 0)
175  npv_in_range = 0;
176  else if (npv_in_range >= npvHigh)
177  npv_in_range = npvHigh - 1; // make sure int_mu won't lead to non-existing ME
178 
179  //mu//
180  int int_mu = -1;
182  if (iEvent.getByToken(muToken, muHandle)) {
183  const auto& summary = *muHandle;
184  auto it = std::find_if(summary.begin(), summary.end(), [](const auto& s) { return s.getBunchCrossing() == 0; });
185 
186  if (it->getBunchCrossing() != 0) {
187  edm::LogError("OffsetAnalyzerDQM") << "Cannot find the in-time pileup info " << it->getBunchCrossing();
188  } else {
189  float mu = it->getTrueNumInteractions();
190  th1dPlots["mu"].fill(mu);
191  int_mu = mu + 0.5;
192  }
193  }
194  if (int_mu >= muHigh)
195  int_mu = muHigh - 1; // make sure int_mu won't lead to non-existing ME
196 
197  //create map of pftypes vs total energy / eta
198  std::map<std::string, std::vector<double>> m_pftype_etaE;
199  int nEta = etabins.size() - 1;
200  for (const auto& pftype : pftypes)
201  m_pftype_etaE[pftype].assign(nEta, 0.0);
202 
203  //pf particles//
205  iEvent.getByToken(pfToken, pfHandle);
206 
207  for (unsigned int i = 0, n = pfHandle->size(); i < n; i++) {
208  const auto& cand = pfHandle->at(i);
209 
210  int etaIndex = getEtaIndex(cand.eta());
211  std::string pftype = pdgMap[abs(cand.pdgId())];
212  if (etaIndex == -1 || pftype.empty())
213  continue;
214 
215  if (pftype == "chm") { //check charged hadrons ONLY
216  bool attached = false;
217 
218  for (unsigned int ipv = 0; ipv < nPVall && !attached; ipv++) {
219  if (isGoodPV[ipv] && cand.fromPV(ipv) == 3)
220  attached = true; //pv used in fit
221  }
222  if (!attached)
223  pftype = "chu"; //unmatched charged hadron
224  }
226  /*
227  reco::TrackRef candTrkRef( cand.trackRef() );
228  if ( pftype == "chm" && !candTrkRef.isNull() ) { //check charged hadrons ONLY
229  bool attached = false;
230 
231  for (auto ipv=vertexHandle->begin(), endpv=vertexHandle->end(); ipv != endpv && !attached; ++ipv) {
232  if ( !ipv->isFake() && ipv->ndof() >= 4 && fabs(ipv->z()) < 24 ) { //must be attached to a good pv
233 
234  for(auto ivtrk=ipv->tracks_begin(), endvtrk=ipv->tracks_end(); ivtrk != endvtrk && !attached; ++ivtrk) {
235  reco::TrackRef pvTrkRef(ivtrk->castTo<reco::TrackRef>());
236  if (pvTrkRef == candTrkRef) attached = true;
237  }
238  }
239  }
240  if (!attached) pftype = "chu"; //unmatched charged hadron
241  }
242 */
244  m_pftype_etaE[pftype][etaIndex] += cand.et();
245  }
246 
247  for (const auto& pair : m_pftype_etaE) {
248  std::string pftype = pair.first;
249  std::vector<double> etaE = pair.second;
250 
251  std::string offset_name_npv = offsetPlotBaseName + "_npv" + std::to_string(npv_in_range) + "_" + pftype;
252  if (offsetPlots.find(offset_name_npv) == offsetPlots.end())
253  return; //npv is out of range ()
254 
255  for (int i = 0; i < nEta; i++) {
256  double eta = 0.5 * (etabins[i] + etabins[i + 1]);
257  offsetPlots[offset_name_npv].fill2D(eta, etaE[i]);
258  }
259 
260  if (int_mu != -1) {
261  std::string offset_name_mu = offsetPlotBaseName + "_mu" + std::to_string(int_mu) + "_" + pftype;
262  if (offsetPlots.find(offset_name_mu) == offsetPlots.end())
263  return; //mu is out of range
264 
265  for (int i = 0; i < nEta; i++) {
266  double eta = 0.5 * (etabins[i] + etabins[i + 1]);
267  offsetPlots[offset_name_mu].fill2D(eta, etaE[i]);
268  }
269  }
270  }
271 }
edm::EDGetTokenT< edm::View< PileupSummaryInfo > > muToken
std::map< int, std::string > pdgMap
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::map< std::string, Plot1D > th1dPlots
Log< level::Error, false > LogError
std::vector< double > etabins
edm::EDGetTokenT< edm::View< pat::PackedCandidate > > pfToken
int iEvent
Definition: GenABIO.cc:224
int getEtaIndex(float eta)
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string offsetPlotBaseName
std::map< std::string, PlotProfile > offsetPlots
edm::EDGetTokenT< edm::View< reco::Vertex > > pvToken
std::vector< std::string > pftypes

◆ bookHistograms()

void OffsetAnalyzerDQM::bookHistograms ( DQMStore::IBooker booker,
edm::Run const &  ,
edm::EventSetup const &   
)
overrideprotectedvirtual

Implements DQMEDAnalyzer.

Definition at line 143 of file OffsetAnalyzerDQM.cc.

References offsetPlots, and th1dPlots.

143  {
144  //std::cout << "OffsetAnalyzerDQM booking offset histograms" << std::endl;
145  for (auto& pair : offsetPlots) {
146  pair.second.book(booker);
147  }
148  for (auto& pair : th1dPlots) {
149  pair.second.book(booker);
150  }
151 }
std::map< std::string, Plot1D > th1dPlots
std::map< std::string, PlotProfile > offsetPlots

◆ getEtaIndex()

int OffsetAnalyzerDQM::getEtaIndex ( float  eta)
protected

Definition at line 273 of file OffsetAnalyzerDQM.cc.

References PVValHelper::eta, etabins, mps_fire::i, and HLT_2022v12_cff::nEta.

Referenced by analyze().

273  {
274  int nEta = etabins.size() - 1;
275 
276  for (int i = 0; i < nEta; i++) {
277  if (etabins[i] <= eta && eta < etabins[i + 1])
278  return i;
279  }
280  if (eta == etabins[nEta])
281  return nEta - 1;
282  else
283  return -1;
284 }
std::vector< double > etabins

Member Data Documentation

◆ etabins

std::vector<double> OffsetAnalyzerDQM::etabins
private

Definition at line 86 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), getEtaIndex(), and OffsetAnalyzerDQM().

◆ muHigh

int OffsetAnalyzerDQM::muHigh
private

Definition at line 88 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ muToken

edm::EDGetTokenT<edm::View<PileupSummaryInfo> > OffsetAnalyzerDQM::muToken
private

Definition at line 92 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ npvHigh

int OffsetAnalyzerDQM::npvHigh
private

Definition at line 89 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ offsetPlotBaseName

std::string OffsetAnalyzerDQM::offsetPlotBaseName
private

Definition at line 84 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ offsetPlots

std::map<std::string, PlotProfile> OffsetAnalyzerDQM::offsetPlots
private

Definition at line 81 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), bookHistograms(), and OffsetAnalyzerDQM().

◆ pdgMap

std::map<int, std::string> OffsetAnalyzerDQM::pdgMap
private

Definition at line 82 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ pfToken

edm::EDGetTokenT<edm::View<pat::PackedCandidate> > OffsetAnalyzerDQM::pfToken
private

Definition at line 93 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ pftypes

std::vector<std::string> OffsetAnalyzerDQM::pftypes
private

Definition at line 85 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ pvToken

edm::EDGetTokenT<edm::View<reco::Vertex> > OffsetAnalyzerDQM::pvToken
private

Definition at line 91 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

◆ th1dPlots

std::map<std::string, Plot1D> OffsetAnalyzerDQM::th1dPlots
private

Definition at line 80 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), bookHistograms(), and OffsetAnalyzerDQM().