CMS 3D CMS Logo

FFTJetPileupEstimator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoJets/FFTJetProducers
4 // Class: FFTJetPileupEstimator
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Wed Apr 20 13:52:23 CDT 2011
16 //
17 //
18 
19 #include <cmath>
20 
21 // Framework include files
26 
27 // Data formats
30 // #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
33 
35 
36 // Loader for the lookup tables
38 
39 #define init_param(type, varname) varname(ps.getParameter<type>(#varname))
40 
41 using namespace fftjetcms;
42 
43 //
44 // class declaration
45 //
47 public:
49  ~FFTJetPileupEstimator() override;
50 
51 protected:
52  // methods
53  void beginJob() override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55  void endJob() override;
56 
57 private:
58  FFTJetPileupEstimator() = delete;
60  FFTJetPileupEstimator& operator=(const FFTJetPileupEstimator&) = delete;
61 
62  std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromConfig(double uncalibrated) const;
63 
64  std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromDB(double uncalibrated, const edm::EventSetup& iSetup) const;
65 
66  template <class Ptr>
67  inline void checkConfig(const Ptr& ptr, const char* message) {
68  if (ptr.get() == nullptr)
69  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
70  }
71 
74 
76  double cdfvalue;
78  unsigned filterNumber;
79  std::vector<double> uncertaintyZones;
80  std::unique_ptr<fftjet::Functor1<double, double> > calibrationCurve;
81  std::unique_ptr<fftjet::Functor1<double, double> > uncertaintyCurve;
82 
83  // Alternative method to calibrate the pileup.
84  // We will fetch three lookup tables from the database:
85  //
86  // 1. calibration curve table
87  //
88  // 2. uncertainty curve table
89  //
90  // 3. the table that will lookup the uncertainty code
91  // given the uncalibrated pileup value
92  //
93  // It will be assumed that all these tables will have
94  // the same record and category but different names.
95  //
102 };
103 
104 //
105 // constructors and destructor
106 //
110  init_param(double, cdfvalue),
111  init_param(double, ptToDensityFactor),
112  init_param(unsigned, filterNumber),
113  init_param(std::vector<double>, uncertaintyZones),
121  checkConfig(calibrationCurve, "bad calibration curve definition");
122 
124  checkConfig(uncertaintyCurve, "bad uncertainty curve definition");
125 
126  inputToken = consumes<reco::DiscretizedEnergyFlow>(inputLabel);
127 
128  produces<reco::FFTJetPileupSummary>(outputLabel);
129 }
130 
132 
133 //
134 // member functions
135 //
136 
137 // ------------ method called to for each event ------------
140  iEvent.getByToken(inputToken, input);
141 
143  const unsigned nScales = h.nEtaBins();
144  const unsigned nCdfvalues = h.nPhiBins();
145 
146  const unsigned fixedCdfvalueBin = static_cast<unsigned>(std::floor(cdfvalue * nCdfvalues));
147  if (fixedCdfvalueBin >= nCdfvalues) {
148  throw cms::Exception("FFTJetBadConfig") << "Bad cdf value" << std::endl;
149  }
150  if (filterNumber >= nScales) {
151  throw cms::Exception("FFTJetBadConfig") << "Bad filter number" << std::endl;
152  }
153 
154  // Simple fixed-point pile-up estimate
155  const double curve = h.data()[filterNumber * nCdfvalues + fixedCdfvalueBin];
156 
157  std::unique_ptr<reco::FFTJetPileupSummary> summary;
158  if (loadCalibFromDB)
159  summary = calibrateFromDB(curve, iSetup);
160  else
161  summary = calibrateFromConfig(curve);
163 }
164 
166 
168 
169 std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromConfig(const double curve) const {
170  const double pileupRho = ptToDensityFactor * (*calibrationCurve)(curve);
171  const double rhoUncert = ptToDensityFactor * (*uncertaintyCurve)(curve);
172 
173  // Determine the uncertainty zone of the estimate. The "curve"
174  // has to be above or equal to uncertaintyZones[i] but below
175  // uncertaintyZones[i + 1] (the second condition is also satisfied
176  // by i == uncertaintyZones.size() - 1). Of course, it is assumed
177  // that the vector of zones is configured appropriately -- the zone
178  // boundaries must be presented in the increasing order.
179  int uncertaintyCode = -1;
180  if (!uncertaintyZones.empty()) {
181  const unsigned nZones = uncertaintyZones.size();
182  for (unsigned i = 0; i < nZones; ++i)
183  if (curve >= uncertaintyZones[i]) {
184  if (i == nZones - 1U) {
185  uncertaintyCode = i;
186  break;
187  } else if (curve < uncertaintyZones[i + 1]) {
188  uncertaintyCode = i;
189  break;
190  }
191  }
192  }
193 
194  return std::make_unique<reco::FFTJetPileupSummary>(curve, pileupRho, rhoUncert, uncertaintyCode);
195 }
196 
197 std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromDB(const double curve,
198  const edm::EventSetup& iSetup) const {
201  std::shared_ptr<npstat::StorableMultivariateFunctor> uz = (*h)[calibTableCategory][uncertaintyZonesName];
202  std::shared_ptr<npstat::StorableMultivariateFunctor> cc = (*h)[calibTableCategory][calibrationCurveName];
203  std::shared_ptr<npstat::StorableMultivariateFunctor> uc = (*h)[calibTableCategory][uncertaintyCurveName];
204 
205  const double pileupRho = ptToDensityFactor * (*cc)(&curve, 1U);
206  const double rhoUncert = ptToDensityFactor * (*uc)(&curve, 1U);
207  const int uncertaintyCode = round((*uz)(&curve, 1U));
208 
209  return std::make_unique<reco::FFTJetPileupSummary>(curve, pileupRho, rhoUncert, uncertaintyCode);
210 }
211 
212 //define this as a plug-in
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
input
static const std::string input
Definition: EdmProvDump.cc:48
fftjetpileupestimator_calo_cfi.uncertaintyZonesName
uncertaintyZonesName
Definition: fftjetpileupestimator_calo_cfi.py:36
fftjetcms
Definition: AbsPileupCalculator.h:15
fftjetcommon_cfi.nScales
nScales
Definition: fftjetcommon_cfi.py:111
EDProducer.h
fftjetpileupestimator_calo_cfi.ptToDensityFactor
ptToDensityFactor
Definition: fftjetpileupestimator_calo_cfi.py:18
FFTJetPileupEstimator::checkConfig
void checkConfig(const Ptr &ptr, const char *message)
Definition: FFTJetPileupEstimator.cc:67
edm::EDGetTokenT< reco::DiscretizedEnergyFlow >
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
FFTJetPileupEstimator::outputLabel
std::string outputLabel
Definition: FFTJetPileupEstimator.cc:75
FFTJetLookupTableSequenceLoader.h
recoTrackAccumulator_cfi.outputLabel
outputLabel
Definition: recoTrackAccumulator_cfi.py:13
FFTJetPileupEstimator::calibrateFromDB
std::unique_ptr< reco::FFTJetPileupSummary > calibrateFromDB(double uncalibrated, const edm::EventSetup &iSetup) const
Definition: FFTJetPileupEstimator.cc:197
fftjetcms::fftjet_Function_parser
std::unique_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
Definition: FFTJetParameterParser.cc:708
FFTJetPileupEstimator::uncertaintyCurveName
std::string uncertaintyCurveName
Definition: FFTJetPileupEstimator.cc:100
fftjetpileupestimator_calo_cfi.uncertaintyCurveName
uncertaintyCurveName
Definition: fftjetpileupestimator_calo_cfi.py:38
edm::Handle
Definition: AssociativeIterator.h:50
FFTJetPileupEstimator::inputLabel
edm::InputTag inputLabel
Definition: FFTJetPileupEstimator.cc:72
cc
MakerMacros.h
h
FFTJetPileupEstimator
Definition: FFTJetPileupEstimator.cc:46
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FFTJetPileupEstimator::beginJob
void beginJob() override
Definition: FFTJetPileupEstimator.cc:165
FFTJetPileupEstimator::loadCalibFromDB
bool loadCalibFromDB
Definition: FFTJetPileupEstimator.cc:101
fftjetpileupestimator_calo_cfi.calibrationCurveName
calibrationCurveName
Definition: fftjetpileupestimator_calo_cfi.py:37
fftjetpileupestimator_calo_cfi.loadCalibFromDB
loadCalibFromDB
Definition: fftjetpileupestimator_calo_cfi.py:39
FFTJetPileupEstimator::endJob
void endJob() override
Definition: FFTJetPileupEstimator.cc:167
edm::ESHandle
Definition: DTSurvey.h:22
FFTJetPileupEstimator::FFTJetPileupEstimator
FFTJetPileupEstimator()=delete
fftjetpileupestimator_calo_cfi.calibTableCategory
calibTableCategory
Definition: fftjetpileupestimator_calo_cfi.py:35
fftjetpileupestimator_calo_cfi.calibTableRecord
calibTableRecord
Definition: fftjetpileupestimator_calo_cfi.py:34
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
FFTJetPileupSummary.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fftjetpileupestimator_calo_cfi.filterNumber
filterNumber
Definition: fftjetpileupestimator_calo_cfi.py:24
fftjetpileupestimator_calo_cfi.uncertaintyZones
uncertaintyZones
Definition: fftjetpileupestimator_calo_cfi.py:27
FFTJetPileupEstimator::uncertaintyCurve
std::unique_ptr< fftjet::Functor1< double, double > > uncertaintyCurve
Definition: FFTJetPileupEstimator.cc:81
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
FFTJetPileupEstimator::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: FFTJetPileupEstimator.cc:138
FFTJetPileupEstimator::cdfvalue
double cdfvalue
Definition: FFTJetPileupEstimator.cc:76
FFTJetPileupEstimator::calibrationCurve
std::unique_ptr< fftjet::Functor1< double, double > > calibrationCurve
Definition: FFTJetPileupEstimator.cc:80
FFTJetPileupEstimator::uncertaintyZones
std::vector< double > uncertaintyZones
Definition: FFTJetPileupEstimator.cc:79
StaticFFTJetRcdMapper::instance
static const Mapper & instance()
Definition: FFTJetRcdMapper.h:86
iEvent
int iEvent
Definition: GenABIO.cc:224
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
edm::EventSetup
Definition: EventSetup.h:57
FFTJetPileupEstimator::~FFTJetPileupEstimator
~FFTJetPileupEstimator() override
Definition: FFTJetPileupEstimator.cc:131
DataMixerDataOnData_cff.inputLabel
inputLabel
Definition: DataMixerDataOnData_cff.py:44
reco::DiscretizedEnergyFlow
Definition: DiscretizedEnergyFlow.h:20
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
fftjetpileupestimator_calo_cfi.cdfvalue
cdfvalue
Definition: fftjetpileupestimator_calo_cfi.py:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
FFTJetPileupEstimator::calibTableRecord
std::string calibTableRecord
Definition: FFTJetPileupEstimator.cc:96
FFTJetPileupEstimator::ptToDensityFactor
double ptToDensityFactor
Definition: FFTJetPileupEstimator.cc:77
Exception
Definition: hltDiff.cc:246
FFTJetParameterParser.h
FFTJetPileupEstimator::uncertaintyZonesName
std::string uncertaintyZonesName
Definition: FFTJetPileupEstimator.cc:98
FFTJetPileupEstimator::calibrationCurveName
std::string calibrationCurveName
Definition: FFTJetPileupEstimator.cc:99
FFTJetPileupEstimator::filterNumber
unsigned filterNumber
Definition: FFTJetPileupEstimator.cc:78
FFTJetPileupEstimator::calibTableCategory
std::string calibTableCategory
Definition: FFTJetPileupEstimator.cc:97
edm::EDProducer
Definition: EDProducer.h:36
FFTJetPileupEstimator::inputToken
edm::EDGetTokenT< reco::DiscretizedEnergyFlow > inputToken
Definition: FFTJetPileupEstimator.cc:73
DiscretizedEnergyFlow.h
cms::Exception
Definition: Exception.h:70
View.h
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
init_param
#define init_param(type, varname)
Definition: FFTJetPileupEstimator.cc:39
FFTJetPileupEstimator::calibrateFromConfig
std::unique_ptr< reco::FFTJetPileupSummary > calibrateFromConfig(double uncalibrated) const
Definition: FFTJetPileupEstimator.cc:169