CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FFTJetPileupEstimator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FFTJetProducers
4 // Class: FFTJetPileupEstimator
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Wed Apr 20 13:52:23 CDT 2011
16 // $Id: FFTJetPileupEstimator.cc,v 1.1 2011/04/27 00:57:01 igv Exp $
17 //
18 //
19 
20 #include <cmath>
21 
22 // Framework include files
27 
28 // Data formats
33 
35 
36 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
37 
38 using namespace fftjetcms;
39 
40 //
41 // class declaration
42 //
44 {
45 public:
48 
49 protected:
50  // methods
51  void beginJob();
52  void produce(edm::Event&, const edm::EventSetup&);
53  void endJob();
54 
55 private:
59 
60  template<class Ptr>
61  inline void checkConfig(const Ptr& ptr, const char* message)
62  {
63  if (ptr.get() == NULL)
64  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
65  }
66 
68  std::string outputLabel;
69  double cdfvalue;
71  unsigned filterNumber;
72  std::vector<double> uncertaintyZones;
73  std::auto_ptr<fftjet::Functor1<double,double> > calibrationCurve;
74  std::auto_ptr<fftjet::Functor1<double,double> > uncertaintyCurve;
75 };
76 
77 //
78 // constructors and destructor
79 //
81  : init_param(edm::InputTag, inputLabel),
82  init_param(std::string, outputLabel),
83  init_param(double, cdfvalue),
84  init_param(double, ptToDensityFactor),
85  init_param(unsigned, filterNumber),
86  init_param(std::vector<double>, uncertaintyZones)
87 {
89  ps.getParameter<edm::ParameterSet>("calibrationCurve"));
90  checkConfig(calibrationCurve, "bad calibration curve definition");
91 
93  ps.getParameter<edm::ParameterSet>("uncertaintyCurve"));
94  checkConfig(uncertaintyCurve, "bad uncertainty curve definition");
95 
96  produces<reco::FFTJetPileupSummary>(outputLabel);
97 }
98 
99 
101 {
102 }
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to for each event ------------
110  const edm::EventSetup& iSetup)
111 {
113  iEvent.getByLabel(inputLabel, input);
114 
115  const TH2D& h(*input);
116  const unsigned nScales = h.GetXaxis()->GetNbins();
117  const unsigned nCdfvalues = h.GetYaxis()->GetNbins();
118 
119  const unsigned fixedCdfvalueBin = static_cast<unsigned>(
120  std::floor(cdfvalue*nCdfvalues));
121  if (fixedCdfvalueBin >= nCdfvalues)
122  {
123  throw cms::Exception("FFTJetBadConfig")
124  << "Bad cdf value" << std::endl;
125  }
126  if (filterNumber >= nScales)
127  {
128  throw cms::Exception("FFTJetBadConfig")
129  << "Bad filter number" << std::endl;
130  }
131 
132  // Simple fixed-point pile-up estimate
133  const double curve = h.GetBinContent(filterNumber+1U,
134  fixedCdfvalueBin+1U);
135  const double pileupRho = ptToDensityFactor*(*calibrationCurve)(curve);
136  const double rhoUncert = ptToDensityFactor*(*uncertaintyCurve)(curve);
137 
138  // Determine the uncertainty zone of the estimate. The "curve"
139  // has to be above or equal to uncertaintyZones[i] but below
140  // uncertaintyZones[i + 1] (the second condition is also satisfied
141  // by i == uncertaintyZones.size() - 1). Of course, it is assumed
142  // that the vector of zones is configured appropriately -- the zone
143  // boundaries must be presented in the increasing order.
144  int uncertaintyCode = -1;
145  if (!uncertaintyZones.empty())
146  {
147  const unsigned nZones = uncertaintyZones.size();
148  for (unsigned i = 0; i < nZones; ++i)
149  if (curve >= uncertaintyZones[i])
150  {
151  if (i == nZones - 1U)
152  {
153  uncertaintyCode = i;
154  break;
155  }
156  else if (curve < uncertaintyZones[i + 1])
157  {
158  uncertaintyCode = i;
159  break;
160  }
161  }
162  }
163 
164  std::auto_ptr<reco::FFTJetPileupSummary> summary(
165  new reco::FFTJetPileupSummary(curve, pileupRho,
166  rhoUncert, uncertaintyCode));
167  iEvent.put(summary, outputLabel);
168 }
169 
170 
172 {
173 }
174 
175 
177 {
178 }
179 
180 
181 //define this as a plug-in
nocap nocap const skelname & operator=(const skelname &)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define NULL
Definition: scimark2.h:8
Summary info for pile-up determined by Gaussian filtering.
std::auto_ptr< fftjet::Functor1< double, double > > calibrationCurve
void beginJob()
Definition: Breakpoints.cc:15
int iEvent
Definition: GenABIO.cc:243
void produce(edm::Event &, const edm::EventSetup &)
std::auto_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
std::vector< double > uncertaintyZones
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::auto_ptr< fftjet::Functor1< double, double > > uncertaintyCurve
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define init_param(type, varname)
void checkConfig(const Ptr &ptr, const char *message)