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() = delete;
51  FFTJetPileupEstimator& operator=(const FFTJetPileupEstimator&) = delete;
52  ~FFTJetPileupEstimator() override;
53 
54 protected:
55  // methods
56  void beginJob() override;
57  void produce(edm::Event&, const edm::EventSetup&) override;
58  void endJob() override;
59 
60 private:
61  std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromConfig(double uncalibrated) const;
62 
63  std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromDB(double uncalibrated, const edm::EventSetup& iSetup) const;
64 
65  template <class Ptr>
66  inline void checkConfig(const Ptr& ptr, const char* message) {
67  if (ptr.get() == nullptr)
68  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
69  }
70 
73 
75  double cdfvalue;
77  unsigned filterNumber;
78  std::vector<double> uncertaintyZones;
79  std::unique_ptr<fftjet::Functor1<double, double> > calibrationCurve;
80  std::unique_ptr<fftjet::Functor1<double, double> > uncertaintyCurve;
81 
82  // Alternative method to calibrate the pileup.
83  // We will fetch three lookup tables from the database:
84  //
85  // 1. calibration curve table
86  //
87  // 2. uncertainty curve table
88  //
89  // 3. the table that will lookup the uncertainty code
90  // given the uncalibrated pileup value
91  //
92  // It will be assumed that all these tables will have
93  // the same record and category but different names.
94  //
101 };
102 
103 //
104 // constructors and destructor
105 //
109  init_param(double, cdfvalue),
110  init_param(double, ptToDensityFactor),
111  init_param(unsigned, filterNumber),
120  checkConfig(calibrationCurve, "bad calibration curve definition");
121 
123  checkConfig(uncertaintyCurve, "bad uncertainty curve definition");
124 
125  inputToken = consumes<reco::DiscretizedEnergyFlow>(inputLabel);
126 
127  produces<reco::FFTJetPileupSummary>(outputLabel);
128 }
129 
131 
132 //
133 // member functions
134 //
135 
136 // ------------ method called to for each event ------------
139  iEvent.getByToken(inputToken, input);
140 
142  const unsigned nScales = h.nEtaBins();
143  const unsigned nCdfvalues = h.nPhiBins();
144 
145  const unsigned fixedCdfvalueBin = static_cast<unsigned>(std::floor(cdfvalue * nCdfvalues));
146  if (fixedCdfvalueBin >= nCdfvalues) {
147  throw cms::Exception("FFTJetBadConfig") << "Bad cdf value" << std::endl;
148  }
149  if (filterNumber >= nScales) {
150  throw cms::Exception("FFTJetBadConfig") << "Bad filter number" << std::endl;
151  }
152 
153  // Simple fixed-point pile-up estimate
154  const double curve = h.data()[filterNumber * nCdfvalues + fixedCdfvalueBin];
155 
156  std::unique_ptr<reco::FFTJetPileupSummary> summary;
157  if (loadCalibFromDB)
158  summary = calibrateFromDB(curve, iSetup);
159  else
160  summary = calibrateFromConfig(curve);
162 }
163 
165 
167 
168 std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromConfig(const double curve) const {
169  const double pileupRho = ptToDensityFactor * (*calibrationCurve)(curve);
170  const double rhoUncert = ptToDensityFactor * (*uncertaintyCurve)(curve);
171 
172  // Determine the uncertainty zone of the estimate. The "curve"
173  // has to be above or equal to uncertaintyZones[i] but below
174  // uncertaintyZones[i + 1] (the second condition is also satisfied
175  // by i == uncertaintyZones.size() - 1). Of course, it is assumed
176  // that the vector of zones is configured appropriately -- the zone
177  // boundaries must be presented in the increasing order.
178  int uncertaintyCode = -1;
179  if (!uncertaintyZones.empty()) {
180  const unsigned nZones = uncertaintyZones.size();
181  for (unsigned i = 0; i < nZones; ++i)
182  if (curve >= uncertaintyZones[i]) {
183  if (i == nZones - 1U) {
184  uncertaintyCode = i;
185  break;
186  } else if (curve < uncertaintyZones[i + 1]) {
187  uncertaintyCode = i;
188  break;
189  }
190  }
191  }
192 
193  return std::make_unique<reco::FFTJetPileupSummary>(curve, pileupRho, rhoUncert, uncertaintyCode);
194 }
195 
196 std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromDB(const double curve,
197  const edm::EventSetup& iSetup) const {
200  std::shared_ptr<npstat::StorableMultivariateFunctor> uz = (*h)[calibTableCategory][uncertaintyZonesName];
201  std::shared_ptr<npstat::StorableMultivariateFunctor> cc = (*h)[calibTableCategory][calibrationCurveName];
202  std::shared_ptr<npstat::StorableMultivariateFunctor> uc = (*h)[calibTableCategory][uncertaintyCurveName];
203 
204  const double pileupRho = ptToDensityFactor * (*cc)(&curve, 1U);
205  const double rhoUncert = ptToDensityFactor * (*uc)(&curve, 1U);
206  const int uncertaintyCode = round((*uz)(&curve, 1U));
207 
208  return std::make_unique<reco::FFTJetPileupSummary>(curve, pileupRho, rhoUncert, uncertaintyCode);
209 }
210 
211 //define this as a plug-in
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
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:66
edm::EDGetTokenT< reco::DiscretizedEnergyFlow >
edm
HLT enums.
Definition: AlignableModifier.h:19
FFTJetPileupEstimator::outputLabel
std::string outputLabel
Definition: FFTJetPileupEstimator.cc:74
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
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:196
fftjetcms::fftjet_Function_parser
std::unique_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
Definition: FFTJetParameterParser.cc:707
h
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
FFTJetPileupEstimator::uncertaintyCurveName
std::string uncertaintyCurveName
Definition: FFTJetPileupEstimator.cc:99
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:71
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:164
FFTJetPileupEstimator::loadCalibFromDB
bool loadCalibFromDB
Definition: FFTJetPileupEstimator.cc:100
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:166
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
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:80
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
FFTJetPileupEstimator::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: FFTJetPileupEstimator.cc:137
FFTJetPileupEstimator::cdfvalue
double cdfvalue
Definition: FFTJetPileupEstimator.cc:75
FFTJetPileupEstimator::calibrationCurve
std::unique_ptr< fftjet::Functor1< double, double > > calibrationCurve
Definition: FFTJetPileupEstimator.cc:79
FFTJetPileupEstimator::uncertaintyZones
std::vector< double > uncertaintyZones
Definition: FFTJetPileupEstimator.cc:78
StaticFFTJetRcdMapper::instance
static const Mapper & instance()
Definition: FFTJetRcdMapper.h:85
iEvent
int iEvent
Definition: GenABIO.cc:224
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
FFTJetPileupEstimator::~FFTJetPileupEstimator
~FFTJetPileupEstimator() override
Definition: FFTJetPileupEstimator.cc:130
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DataMixerDataOnData_cff.inputLabel
inputLabel
Definition: DataMixerDataOnData_cff.py:44
reco::DiscretizedEnergyFlow
Definition: DiscretizedEnergyFlow.h:20
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:95
FFTJetPileupEstimator::ptToDensityFactor
double ptToDensityFactor
Definition: FFTJetPileupEstimator.cc:76
Exception
Definition: hltDiff.cc:245
FFTJetParameterParser.h
FFTJetPileupEstimator::uncertaintyZonesName
std::string uncertaintyZonesName
Definition: FFTJetPileupEstimator.cc:97
FFTJetPileupEstimator::calibrationCurveName
std::string calibrationCurveName
Definition: FFTJetPileupEstimator.cc:98
FFTJetPileupEstimator::filterNumber
unsigned filterNumber
Definition: FFTJetPileupEstimator.cc:77
FFTJetPileupEstimator::calibTableCategory
std::string calibTableCategory
Definition: FFTJetPileupEstimator.cc:96
edm::EDProducer
Definition: EDProducer.h:35
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
FFTJetPileupEstimator::inputToken
edm::EDGetTokenT< reco::DiscretizedEnergyFlow > inputToken
Definition: FFTJetPileupEstimator.cc:72
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:168