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::one::EDProducer< edm::EndRunProducer, edm::one::WatchRuns, edm::EndLuminosityBlockProducer, edm::one::WatchLuminosityBlocks, edm::Accumulator > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

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
 
virtual void analyze (edm::Event const &, edm::EventSetup const &)
 
void beginLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
 
void beginRun (edm::Run const &run, edm::EventSetup const &setup) final
 
virtual void dqmBeginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &)
 
virtual void dqmBeginRun (edm::Run const &, edm::EventSetup const &)
 
 DQMEDAnalyzer ()
 
virtual void dqmEndLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &)
 
virtual void dqmEndRun (edm::Run const &, edm::EventSetup const &)
 
void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) final
 
void endLuminosityBlockProduce (edm::LuminosityBlock &lumi, edm::EventSetup const &setup) final
 
void endRun (edm::Run const &, edm::EventSetup const &) final
 
void endRunProduce (edm::Run &run, edm::EventSetup const &setup) final
 
virtual bool getCanSaveByLumi ()
 
- Public Member Functions inherited from edm::one::EDProducer< edm::EndRunProducer, edm::one::WatchRuns, edm::EndLuminosityBlockProducer, edm::one::WatchLuminosityBlocks, edm::Accumulator >
 EDProducer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) 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
 
ESProxyIndex const * esGetTokenIndices (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::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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

void bookHistograms (DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
 
void dqmBeginRun (const edm::Run &, const edm::EventSetup &) override
 
void dqmEndRun (const edm::Run &, const edm::EventSetup &) override
 
int getEtaIndex (float eta)
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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)
 

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::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Attributes inherited from DQMEDAnalyzer
edm::EDPutTokenT< DQMTokenlumiToken_
 
edm::EDPutTokenT< DQMTokenrunToken_
 

Detailed Description

Definition at line 16 of file OffsetAnalyzerDQM.cc.

Constructor & Destructor Documentation

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

Definition at line 97 of file OffsetAnalyzerDQM.cc.

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

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

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

Definition at line 154 of file OffsetAnalyzerDQM.cc.

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

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

Implements DQMEDAnalyzer.

Definition at line 144 of file OffsetAnalyzerDQM.cc.

References offsetPlots, and th1dPlots.

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

Definition at line 24 of file OffsetAnalyzerDQM.cc.

24 {}
void OffsetAnalyzerDQM::dqmEndRun ( const edm::Run ,
const edm::EventSetup  
)
inlineoverrideprotected

Definition at line 25 of file OffsetAnalyzerDQM.cc.

References PVValHelper::eta, and getEtaIndex().

25 {}
int OffsetAnalyzerDQM::getEtaIndex ( float  eta)
protected

Definition at line 274 of file OffsetAnalyzerDQM.cc.

References DEFINE_FWK_MODULE, etabins, mps_fire::i, and HLT_2018_cff::nEta.

Referenced by analyze(), and dqmEndRun().

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

Member Data Documentation

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

Definition at line 87 of file OffsetAnalyzerDQM.cc.

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

int OffsetAnalyzerDQM::muHigh
private

Definition at line 89 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

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

Definition at line 93 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

int OffsetAnalyzerDQM::npvHigh
private

Definition at line 90 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

std::string OffsetAnalyzerDQM::offsetPlotBaseName
private

Definition at line 85 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

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

Definition at line 82 of file OffsetAnalyzerDQM.cc.

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

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

Definition at line 83 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

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

Definition at line 94 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

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

Definition at line 86 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

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

Definition at line 92 of file OffsetAnalyzerDQM.cc.

Referenced by analyze(), and OffsetAnalyzerDQM().

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

Definition at line 81 of file OffsetAnalyzerDQM.cc.

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