CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFJetDQMPostProcessor Class Reference
Inheritance diagram for PFJetDQMPostProcessor:
DQMEDHarvester edm::one::EDProducer< edm::Accumulator, edm::EndLuminosityBlockProducer, edm::EndRunProducer, edm::one::WatchLuminosityBlocks, edm::one::WatchRuns, edm::one::SharedResources > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PFJetDQMPostProcessor (const edm::ParameterSet &)
 
 ~PFJetDQMPostProcessor () override
 
- Public Member Functions inherited from DQMEDHarvester
void accumulate (edm::Event const &ev, edm::EventSetup const &es) final
 
void beginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) final
 
void beginRun (edm::Run const &, edm::EventSetup const &) override
 
 DQMEDHarvester ()
 
virtual void dqmEndLuminosityBlock (DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
 
void endJob () final
 
void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) final
 
void endLuminosityBlockProduce (edm::LuminosityBlock &, edm::EventSetup const &) final
 
void endRun (edm::Run const &, edm::EventSetup const &) override
 
void endRunProduce (edm::Run &run, edm::EventSetup const &setup) override
 
 ~DQMEDHarvester () override=default
 
- Public Member Functions inherited from edm::one::EDProducer< edm::Accumulator, edm::EndLuminosityBlockProducer, edm::EndRunProducer, edm::one::WatchLuminosityBlocks, edm::one::WatchRuns, edm::one::SharedResources >
 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)
 

Private Member Functions

void dqmEndJob (DQMStore::IBooker &, DQMStore::IGetter &) override
 
void fitResponse (TH1F *hreso, TH1F *h_genjet_pt, int ptbinlow, int ietahigh, double recoptcut, double &resp, double &resp_err, double &reso, double &reso_err)
 
double getRespUnc (double width, double width_err, double mean, double mean_err)
 
std::string seta (double eta)
 
std::string spt (double ptmin, double ptmax)
 

Private Attributes

bool debug = false
 
std::vector< double > etaBins
 
std::string genjetDir
 
std::string jetResponseDir
 
std::vector< double > ptBins
 
double recoptcut
 

Additional Inherited Members

- Public Types inherited from DQMEDHarvester
typedef dqm::harvesting::DQMStore DQMStore
 
typedef dqm::harvesting::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 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)
 
- Protected Attributes inherited from DQMEDHarvester
edm::EDPutTokenT< DQMTokenlumiToken_
 
edm::EDPutTokenT< DQMTokenrunToken_
 

Detailed Description

Definition at line 26 of file PFJetDQMPostProcessor.cc.

Constructor & Destructor Documentation

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

Definition at line 70 of file PFJetDQMPostProcessor.cc.

References etaBins, genjetDir, edm::ParameterSet::getParameter(), jetResponseDir, ptBins, recoptcut, and AlCaHLTBitMon_QueryRunRegistry::string.

70  {
71  jetResponseDir = iConfig.getParameter<std::string>("jetResponseDir");
72  genjetDir = iConfig.getParameter<std::string>("genjetDir");
73  ptBins = iConfig.getParameter<std::vector<double> >("ptBins");
74  etaBins = iConfig.getParameter<std::vector<double> >("etaBins");
75  recoptcut = iConfig.getParameter<double>("recoPtCut");
76 }
T getParameter(std::string const &) const
std::vector< double > etaBins
std::vector< double > ptBins
PFJetDQMPostProcessor::~PFJetDQMPostProcessor ( )
override

Definition at line 78 of file PFJetDQMPostProcessor.cc.

78 {}

Member Function Documentation

void PFJetDQMPostProcessor::dqmEndJob ( DQMStore::IBooker ibook_,
DQMStore::IGetter iget_ 
)
overrideprivatevirtual

Implements DQMEDHarvester.

Definition at line 81 of file PFJetDQMPostProcessor.cc.

References dqm::dqmstoreimpl::DQMStore::IBooker::book1D(), filterCSVwithJSON::copy, debug, runTheMatrix::err, etaBins, spr::find(), fitResponse(), genjetDir, dqm::dqmstoreimpl::DQMStore::IGetter::get(), dqm::dqmstoreimpl::DQMStore::IGetter::getMEs(), getRespUnc(), dqm::legacy::MonitorElement::getTH1F(), mps_fire::i, LEDCalibrationChannels::ieta, jetResponseDir, hlt_dqm_clientPB-live_cfg::me, SiStripPI::mean, HLTTauDQMOffline_cfi::nPtBins, ptBins, recoptcut, alignCSCRings::s, seta(), dqm::dqmstoreimpl::DQMStore::IGetter::setCurrentFolder(), spt(), and AlCaHLTBitMon_QueryRunRegistry::string.

81  {
82  //
83  iget_.setCurrentFolder(genjetDir);
84  std::vector<std::string> sME_genjets = iget_.getMEs();
85  std::for_each(sME_genjets.begin(), sME_genjets.end(), [&](auto& s) { s.insert(0, genjetDir.c_str()); });
86  //for (unsigned int i=0; i<sME_genjets.size(); i++) std::cout << sME_genjets[i] << std::endl;
87 
88  iget_.setCurrentFolder(jetResponseDir);
89  std::vector<std::string> sME_response = iget_.getMEs();
90  std::for_each(sME_response.begin(), sME_response.end(), [&](auto& s) { s.insert(0, jetResponseDir); });
91  //for (unsigned int i=0; i<sME_response.size(); i++) std::cout << sME_response[i] << std::endl;
92 
93  iget_.setCurrentFolder(jetResponseDir);
94 
95  double ptBinsArray[ptBins.size()];
96  unsigned int nPtBins = ptBins.size() - 1;
97  std::copy(ptBins.begin(), ptBins.end(), ptBinsArray);
98  //for(unsigned int ipt = 0; ipt < ptBins.size(); ++ipt) std::cout << ptBins[ipt] << std::endl;
99 
100  std::string stitle;
101  char ctitle[50];
102  std::vector<MonitorElement*> vME_presponse;
103  std::vector<MonitorElement*> vME_preso;
104  std::vector<MonitorElement*> vME_preso_rms;
105 
107  TH1F* h_resp;
108  TH1F* h_genjet_pt;
109 
110  //
111  // Response distributions
112  //
113  for (unsigned int ieta = 1; ieta < etaBins.size(); ++ieta) {
114  stitle = genjetDir + "genjet_pt" + "_eta" + seta(etaBins[ieta]);
115  //std::cout << ieta << " " << stitle << std::endl;
116  std::vector<std::string>::const_iterator it = std::find(sME_genjets.begin(), sME_genjets.end(), stitle);
117  if (it == sME_genjets.end())
118  continue;
119  me = iget_.get(stitle);
120  h_genjet_pt = (TH1F*)me->getTH1F();
121 
122  stitle = "presponse_eta" + seta(etaBins[ieta]);
123  sprintf(ctitle, "Jet pT response, %4.1f<|#eta|<%4.1f", etaBins[ieta - 1], etaBins[ieta]);
124  TH1F* h_presponse = new TH1F(stitle.c_str(), ctitle, nPtBins, ptBinsArray);
125 
126  stitle = "preso_eta" + seta(etaBins[ieta]);
127  sprintf(ctitle, "Jet pT resolution, %4.1f<|#eta|<%4.1f", etaBins[ieta - 1], etaBins[ieta]);
128  TH1F* h_preso = new TH1F(stitle.c_str(), ctitle, nPtBins, ptBinsArray);
129 
130  stitle = "preso_eta" + seta(etaBins[ieta]) + "_rms";
131  sprintf(ctitle, "Jet pT resolution using RMS, %4.1f<|#eta|<%4.1f", etaBins[ieta - 1], etaBins[ieta]);
132  TH1F* h_preso_rms = new TH1F(stitle.c_str(), ctitle, nPtBins, ptBinsArray);
133 
134  for (unsigned int ipt = 0; ipt < ptBins.size() - 1; ++ipt) {
135  stitle = jetResponseDir + "reso_dist_" + spt(ptBins[ipt], ptBins[ipt + 1]) + "_eta" + seta(etaBins[ieta]);
136  std::vector<std::string>::const_iterator it = std::find(sME_response.begin(), sME_response.end(), stitle);
137  if (it == sME_response.end())
138  continue;
139  me = iget_.get(stitle);
140  h_resp = (TH1F*)me->getTH1F();
141 
142  // Fit-based
143  double resp = 1.0, resp_err = 0.0, reso = 0.0, reso_err = 0.0;
144  fitResponse(h_resp, h_genjet_pt, ipt, ieta, recoptcut, resp, resp_err, reso, reso_err);
145 
146  h_presponse->SetBinContent(ipt + 1, resp);
147  h_presponse->SetBinError(ipt + 1, resp_err);
148  h_preso->SetBinContent(ipt + 1, reso);
149  h_preso->SetBinError(ipt + 1, reso_err);
150 
151  // RMS-based
152  double std = h_resp->GetStdDev();
153  double std_error = h_resp->GetStdDevError();
154 
155  // Scale each bin with mean response
156  double mean = 1.0;
157  double mean_error = 0.0;
158  double err = 0.0;
159  if (h_resp->GetMean() > 0) {
160  mean = h_resp->GetMean();
161  mean_error = h_resp->GetMeanError();
162 
163  // Scale resolution by response.
164  std /= mean;
165  std_error /= mean;
166 
167  err = getRespUnc(std, std_error, mean, mean_error);
168  }
169 
170  h_preso_rms->SetBinContent(ipt + 1, std);
171  h_preso_rms->SetBinError(ipt + 1, err);
172 
173  } // ipt
174 
175  stitle = "presponse_eta" + seta(etaBins[ieta]);
176  me = ibook_.book1D(stitle.c_str(), h_presponse);
177  vME_presponse.push_back(me);
178 
179  stitle = "preso_eta" + seta(etaBins[ieta]);
180  me = ibook_.book1D(stitle.c_str(), h_preso);
181  vME_preso.push_back(me);
182 
183  stitle = "preso_eta" + seta(etaBins[ieta]) + "_rms";
184  me = ibook_.book1D(stitle.c_str(), h_preso_rms);
185  vME_preso_rms.push_back(me);
186 
187  } // ieta
188 
189  //
190  // Checks
191  //
192  if (debug) {
193  for (std::vector<MonitorElement*>::const_iterator i = vME_presponse.begin(); i != vME_presponse.end(); ++i)
194  (*i)->getTH1F()->Print();
195  for (std::vector<MonitorElement*>::const_iterator i = vME_preso.begin(); i != vME_preso.end(); ++i)
196  (*i)->getTH1F()->Print();
197  for (std::vector<MonitorElement*>::const_iterator i = vME_preso_rms.begin(); i != vME_preso_rms.end(); ++i)
198  (*i)->getTH1F()->Print();
199  }
200 }
virtual TH1F * getTH1F() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::string spt(double ptmin, double ptmax)
std::vector< double > etaBins
void fitResponse(TH1F *hreso, TH1F *h_genjet_pt, int ptbinlow, int ietahigh, double recoptcut, double &resp, double &resp_err, double &reso, double &reso_err)
std::vector< double > ptBins
std::string seta(double eta)
double getRespUnc(double width, double width_err, double mean, double mean_err)
void PFJetDQMPostProcessor::fitResponse ( TH1F *  hreso,
TH1F *  h_genjet_pt,
int  ptbinlow,
int  ietahigh,
double  recoptcut,
double &  resp,
double &  resp_err,
double &  reso,
double &  reso_err 
)
private

Definition at line 202 of file PFJetDQMPostProcessor.cc.

References etaBins, getRespUnc(), Max(), ptBins, and seta().

Referenced by dqmEndJob().

210  {
211  // This 'smartfitter' is converted from the original Python smart_fit() -function
212  // implemented in test/helperFunctions.py. See that file for more commentary.
213  // Juska 23 May 2019
214 
215  // Only do plots if needed for debugging
216  // NOTE a directory called 'debug' must exist in the working directory
217  //
218  bool doPlots = false;
219 
220  double ptlow = ptBins[ptbinlow];
221  double pthigh = ptBins[ptbinlow + 1];
222 
223  // Take range by Mikko's advice: -1.5 and + 1.5 * RMS width
224 
225  double rmswidth = hreso->GetStdDev();
226  double rmsmean = hreso->GetMean();
227  double fitlow = rmsmean - 1.5 * rmswidth;
228  fitlow = TMath::Max(recoptcut / ptlow, fitlow);
229  double fithigh = rmsmean + 1.5 * rmswidth;
230 
231  TF1* fg = new TF1("mygaus", "gaus", fitlow, fithigh);
232  TF1* fg2 = new TF1("fg2", "TMath::Gaus(x,[0],[1],true)*[2]", fitlow, fithigh);
233 
234  hreso->Fit("mygaus", "RQN");
235 
236  fg2->SetParameter(0, fg->GetParameter(1));
237  fg2->SetParameter(1, fg->GetParameter(2));
238 
239  // Extract ngenjet in the current pT bin from the genjet histo
240  float ngenjet = h_genjet_pt->GetBinContent(ptbinlow + 1);
241 
242  // Here the fit is forced to take the area of ngenjets.
243  // The area is further normalized for the response histogram x-axis length
244  // (3) and number of bins (100)
245  fg2->FixParameter(2, ngenjet * 3. / 100.);
246 
247  hreso->Fit("fg2", "RQN");
248 
249  fitlow = fg2->GetParameter(0) - 1.5 * fg2->GetParameter(1);
250  fitlow = TMath::Max(15. / ptlow, fitlow);
251  fithigh = fg2->GetParameter(0) + 1.5 * fg2->GetParameter(1);
252 
253  fg2->SetRange(fitlow, fithigh);
254 
255  hreso->Fit("fg2", "RQ");
256 
257  fg->SetRange(0, 3);
258  fg2->SetRange(0, 3);
259  fg->SetLineWidth(2);
260  fg2->SetLineColor(kGreen + 2);
261 
262  hreso->GetXaxis()->SetRangeUser(0, 2);
263 
264  // Save plots to a subdirectory if asked (debug-directory must exist!)
265  if (doPlots & (hreso->GetEntries() > 0)) {
266  TCanvas* cfit = new TCanvas(Form("respofit_%i", int(ptlow)), "respofit", 600, 600);
267  hreso->Draw("ehist");
268  fg->Draw("same");
269  fg2->Draw("same");
270  cfit->SaveAs(
271  Form("debug/respo_smartfit_%04d_%i_eta%s.pdf", (int)ptlow, (int)pthigh, seta(etaBins[ietahigh]).c_str()));
272  }
273 
274  resp = fg2->GetParameter(0);
275  resp_err = fg2->GetParError(0);
276 
277  // Scale resolution by response. Avoid division by zero.
278  if (0 == resp)
279  reso = 0;
280  else
281  reso = fg2->GetParameter(1) / resp;
282  reso_err = fg2->GetParError(1) / resp;
283 
284  reso_err = getRespUnc(reso, reso_err, resp, resp_err);
285 }
std::vector< double > etaBins
T Max(T a, T b)
Definition: MathUtil.h:44
std::vector< double > ptBins
std::string seta(double eta)
double getRespUnc(double width, double width_err, double mean, double mean_err)
double PFJetDQMPostProcessor::getRespUnc ( double  width,
double  width_err,
double  mean,
double  mean_err 
)
private

Definition at line 288 of file PFJetDQMPostProcessor.cc.

References DEFINE_FWK_MODULE, funct::pow(), and ApeEstimator_cff::width.

Referenced by dqmEndJob(), and fitResponse().

288  {
289  if (0 == width || 0 == mean)
290  return 0;
291  return TMath::Sqrt(pow(width_err, 2) / pow(width, 2) + pow(mean_err, 2) / pow(mean, 2)) * width;
292 }
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
std::string PFJetDQMPostProcessor::seta ( double  eta)
inlineprivate

Definition at line 53 of file PFJetDQMPostProcessor.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by dqmEndJob(), and fitResponse().

53  {
54  std::string seta = std::to_string(int(eta * 10.));
55  if (seta.length() < 2)
56  seta = "0" + seta;
57  return seta;
58  }
std::string seta(double eta)
std::string PFJetDQMPostProcessor::spt ( double  ptmin,
double  ptmax 
)
inlineprivate

Definition at line 60 of file PFJetDQMPostProcessor.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by dqmEndJob().

60  {
61  std::string spt = std::to_string(int(ptmin)) + "_" + std::to_string(int(ptmax));
62  return spt;
63  }
std::string spt(double ptmin, double ptmax)
double ptmin
Definition: HydjetWrapper.h:84

Member Data Documentation

bool PFJetDQMPostProcessor::debug = false
private

Definition at line 51 of file PFJetDQMPostProcessor.cc.

Referenced by dqmEndJob().

std::vector<double> PFJetDQMPostProcessor::etaBins
private

Definition at line 47 of file PFJetDQMPostProcessor.cc.

Referenced by dqmEndJob(), fitResponse(), and PFJetDQMPostProcessor().

std::string PFJetDQMPostProcessor::genjetDir
private

Definition at line 45 of file PFJetDQMPostProcessor.cc.

Referenced by dqmEndJob(), and PFJetDQMPostProcessor().

std::string PFJetDQMPostProcessor::jetResponseDir
private

Definition at line 44 of file PFJetDQMPostProcessor.cc.

Referenced by dqmEndJob(), and PFJetDQMPostProcessor().

std::vector<double> PFJetDQMPostProcessor::ptBins
private

Definition at line 46 of file PFJetDQMPostProcessor.cc.

Referenced by dqmEndJob(), fitResponse(), and PFJetDQMPostProcessor().

double PFJetDQMPostProcessor::recoptcut
private

Definition at line 49 of file PFJetDQMPostProcessor.cc.

Referenced by dqmEndJob(), and PFJetDQMPostProcessor().