CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
PFClusterEMEnergyCorrector Class Reference

#include <PFClusterEMEnergyCorrector.h>

Public Member Functions

void correctEnergies (const edm::Event &evt, const edm::EventSetup &es, const reco::PFCluster::EEtoPSAssociation &assoc, reco::PFClusterCollection &cs)
 
PFClusterEMEnergyCorrectoroperator= (const PFClusterEMEnergyCorrector &)=delete
 
 PFClusterEMEnergyCorrector (const edm::ParameterSet &conf, edm::ConsumesCollector &&cc)
 
 PFClusterEMEnergyCorrector (const PFClusterEMEnergyCorrector &)=delete
 

Private Attributes

bool _applyCrackCorrections
 
bool _applyMVACorrections
 
std::unique_ptr
< PFEnergyCalibration
_calibrator
 
std::vector< std::string > _condnames_mean_25ns
 
std::vector< std::string > _condnames_mean_50ns
 
std::vector< std::string > _condnames_sigma_25ns
 
std::vector< std::string > _condnames_sigma_50ns
 
edm::EDGetTokenT
< EcalRecHitCollection
_recHitsEB
 
edm::EDGetTokenT
< EcalRecHitCollection
_recHitsEE
 
edm::EDGetTokenT
< reco::VertexCollection
_vertices
 
bool autoDetectBunchSpacing_
 
edm::EDGetTokenT< int > bunchSpacing_
 
int bunchSpacingManual_
 

Detailed Description

Definition at line 17 of file PFClusterEMEnergyCorrector.h.

Constructor & Destructor Documentation

PFClusterEMEnergyCorrector::PFClusterEMEnergyCorrector ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  cc 
)

Definition at line 16 of file PFClusterEMEnergyCorrector.cc.

References _applyCrackCorrections, _applyMVACorrections, _condnames_mean_25ns, _condnames_mean_50ns, _condnames_sigma_25ns, _condnames_sigma_50ns, _recHitsEB, _recHitsEE, _vertices, autoDetectBunchSpacing_, bunchSpacing_, bunchSpacingManual_, and edm::ParameterSet::getParameter().

16  :
18 
19  _applyCrackCorrections = conf.getParameter<bool>("applyCrackCorrections");
20  _applyMVACorrections = conf.getParameter<bool>("applyMVACorrections");
21 
22 
23  if (_applyMVACorrections) {
24  _recHitsEB = cc.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsEBLabel"));
25  _recHitsEE = cc.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsEELabel"));
27 
28  autoDetectBunchSpacing_ = conf.getParameter<bool>("autoDetectBunchSpacing");
29 
31  bunchSpacing_ = cc.consumes<int>(edm::InputTag("addPileupInfo","bunchSpacing"));
33  }
34  else {
35  bunchSpacingManual_ = conf.getParameter<int>("bunchSpacing");
36  }
37 
38  _condnames_mean_50ns.push_back("ecalPFClusterCor_EB_pfSize1_mean_50ns");
39  _condnames_mean_50ns.push_back("ecalPFClusterCor_EB_pfSize2_mean_50ns");
40  _condnames_mean_50ns.push_back("ecalPFClusterCor_EB_pfSize3_mean_50ns");
41  _condnames_mean_50ns.push_back("ecalPFClusterCor_EE_pfSize1_mean_50ns");
42  _condnames_mean_50ns.push_back("ecalPFClusterCor_EE_pfSize2_mean_50ns");
43  _condnames_mean_50ns.push_back("ecalPFClusterCor_EE_pfSize3_mean_50ns");
44 
45  _condnames_sigma_50ns.push_back("ecalPFClusterCor_EB_pfSize1_sigma_50ns");
46  _condnames_sigma_50ns.push_back("ecalPFClusterCor_EB_pfSize2_sigma_50ns");
47  _condnames_sigma_50ns.push_back("ecalPFClusterCor_EB_pfSize3_sigma_50ns");
48  _condnames_sigma_50ns.push_back("ecalPFClusterCor_EE_pfSize1_sigma_50ns");
49  _condnames_sigma_50ns.push_back("ecalPFClusterCor_EE_pfSize2_sigma_50ns");
50  _condnames_sigma_50ns.push_back("ecalPFClusterCor_EE_pfSize3_sigma_50ns");
51 
52  _condnames_mean_25ns.push_back("ecalPFClusterCor_EB_pfSize1_mean_25ns");
53  _condnames_mean_25ns.push_back("ecalPFClusterCor_EB_pfSize2_mean_25ns");
54  _condnames_mean_25ns.push_back("ecalPFClusterCor_EB_pfSize3_mean_25ns");
55  _condnames_mean_25ns.push_back("ecalPFClusterCor_EE_pfSize1_mean_25ns");
56  _condnames_mean_25ns.push_back("ecalPFClusterCor_EE_pfSize2_mean_25ns");
57  _condnames_mean_25ns.push_back("ecalPFClusterCor_EE_pfSize3_mean_25ns");
58 
59  _condnames_sigma_25ns.push_back("ecalPFClusterCor_EB_pfSize1_sigma_25ns");
60  _condnames_sigma_25ns.push_back("ecalPFClusterCor_EB_pfSize2_sigma_25ns");
61  _condnames_sigma_25ns.push_back("ecalPFClusterCor_EB_pfSize3_sigma_25ns");
62  _condnames_sigma_25ns.push_back("ecalPFClusterCor_EE_pfSize1_sigma_25ns");
63  _condnames_sigma_25ns.push_back("ecalPFClusterCor_EE_pfSize2_sigma_25ns");
64  _condnames_sigma_25ns.push_back("ecalPFClusterCor_EE_pfSize3_sigma_25ns");
65  }
66 
67 
68 
69 }
std::vector< std::string > _condnames_mean_50ns
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::vector< std::string > _condnames_sigma_25ns
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::vector< std::string > _condnames_mean_25ns
edm::EDGetTokenT< int > bunchSpacing_
edm::EDGetTokenT< EcalRecHitCollection > _recHitsEB
std::unique_ptr< PFEnergyCalibration > _calibrator
edm::EDGetTokenT< reco::VertexCollection > _vertices
edm::EDGetTokenT< EcalRecHitCollection > _recHitsEE
std::vector< std::string > _condnames_sigma_50ns
PFClusterEMEnergyCorrector::PFClusterEMEnergyCorrector ( const PFClusterEMEnergyCorrector )
delete

Member Function Documentation

void PFClusterEMEnergyCorrector::correctEnergies ( const edm::Event evt,
const edm::EventSetup es,
const reco::PFCluster::EEtoPSAssociation assoc,
reco::PFClusterCollection cs 
)

Definition at line 72 of file PFClusterEMEnergyCorrector.cc.

References _applyCrackCorrections, _applyMVACorrections, _calibrator, _condnames_mean_25ns, _condnames_mean_50ns, _condnames_sigma_25ns, _condnames_sigma_50ns, _recHitsEB, _recHitsEE, _vertices, autoDetectBunchSpacing_, bunchSpacing_, alignCSCRings::e, PFLayer::ECAL_BARREL, reco::PFCluster::energy(), reco::CaloCluster::eta(), eta(), edm::EventSetup::get(), edm::Event::getByToken(), GBRForestD::GetResponse(), customizeTrackingMonitorSeedNumber::idx, edm::EventBase::isRealData(), reco::PFCluster::layer(), timingPdfMaker::mean, min(), phi, reco::CaloCluster::phi(), PFLayer::PS1, PFLayer::PS2, DTTTrigCorrFirst::run, edm::Event::run(), reco::CaloCluster::setCorrectedEnergy(), reco::CaloCluster::setCorrectedEnergyUncertainty(), and findQualityFiles::size.

72  {
73 
74  //legacy corrections
75  if (!_applyMVACorrections) {
76  for (unsigned int idx = 0; idx<cs.size(); ++idx) {
77  reco::PFCluster &cluster = cs[idx];
78  bool iseb = cluster.layer() == PFLayer::ECAL_BARREL;
79 
80  //compute preshower energies for endcap clusters
81  double ePS1=0, ePS2=0;
82  if(!iseb) {
83  auto ee_key_val = std::make_pair(idx,edm::Ptr<reco::PFCluster>());
84  const auto clustops = std::equal_range(assoc.begin(),
85  assoc.end(),
86  ee_key_val,
87  sortByKey);
88  for( auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
89  edm::Ptr<reco::PFCluster> psclus(i_ps->second);
90  switch( psclus->layer() ) {
91  case PFLayer::PS1:
92  ePS1 += psclus->energy();
93  break;
94  case PFLayer::PS2:
95  ePS2 += psclus->energy();
96  break;
97  default:
98  break;
99  }
100  }
101  }
102 
103  double correctedEnergy = _calibrator->energyEm(cluster,ePS1,ePS2,_applyCrackCorrections);
104  cluster.setCorrectedEnergy(correctedEnergy);
105 
106  }
107  return;
108  }
109 
110  int bunchspacing = 450;
111 
113  if (evt.isRealData()) {
114  edm::RunNumber_t run = evt.run();
115  if (run == 178003 ||
116  run == 178004 ||
117  run == 209089 ||
118  run == 209106 ||
119  run == 209109 ||
120  run == 209146 ||
121  run == 209148 ||
122  run == 209151) {
123  bunchspacing = 25;
124  }
125  else {
126  bunchspacing = 50;
127  }
128  }
129  else {
130  edm::Handle<int> bunchSpacingH;
131  evt.getByToken(bunchSpacing_,bunchSpacingH);
132  bunchspacing = *bunchSpacingH;
133  }
134  }
135 
136  const unsigned int ncor = 6;
137 
138  std::vector<edm::ESHandle<GBRForestD> > forestH_mean(ncor);
139  std::vector<edm::ESHandle<GBRForestD> > forestH_sigma(ncor);
140 
141  const std::vector<std::string> condnames_mean = (bunchspacing == 25) ? _condnames_mean_25ns : _condnames_mean_50ns;
142  const std::vector<std::string> condnames_sigma = (bunchspacing == 25) ? _condnames_sigma_25ns : _condnames_sigma_50ns;
143 
144  for (unsigned int icor=0; icor<ncor; ++icor) {
145  es.get<GBRDWrapperRcd>().get(condnames_mean[icor],forestH_mean[icor]);
146  es.get<GBRDWrapperRcd>().get(condnames_sigma[icor],forestH_sigma[icor]);
147  }
148 
149  std::array<float,11> eval;
150 
151  EcalClusterLazyTools lazyTool(evt, es, _recHitsEB, _recHitsEE);
152 
153  //count number of primary vertices for pileup correction
155  evt.getByToken(_vertices,vtxH);
156  int nvtx = 0;
157  for (const reco::Vertex &vtx : *vtxH) {
158  if (!vtx.isFake()) {
159  ++nvtx;
160  }
161  }
162 
163  //magic numbers for MINUIT-like transformation of BDT output onto limited range
164  //(These should be stored inside the conditions object in the future as well)
165  const double meanlimlow = 1./1.4;
166  const double meanlimhigh = 1./0.4;
167  const double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
168  const double meanscale = 0.5*(meanlimhigh-meanlimlow);
169 
170  const double sigmalimlow = 0.003;
171  const double sigmalimhigh = 0.5;
172  const double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
173  const double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
174 
175  for (unsigned int idx = 0; idx<cs.size(); ++idx) {
176 
177  reco::PFCluster &cluster = cs[idx];
178 
179  double e = cluster.energy();
180  double eta = cluster.eta();
181  double phi = cluster.phi();
182 
183  double invE = (e == 0.) ? 0. : 1./e; //guard against dividing by 0.
184 
185  int size = lazyTool.n5x5(cluster);
186 
187  bool iseb = cluster.layer() == PFLayer::ECAL_BARREL;
188 
189  //find index of corrections (0-2 for EB, 3-5 for EE, depending on cluster size)
190  int coridx = std::min(size,3)-1;
191  if (!iseb) {
192  coridx += 3;
193  }
194 
195  const GBRForestD &meanforest = *forestH_mean[coridx].product();
196  const GBRForestD &sigmaforest = *forestH_sigma[coridx].product();
197 
198  double e1x3 = lazyTool.e1x3(cluster);
199  double e2x2 = lazyTool.e2x2(cluster);
200  double e2x5max = lazyTool.e2x5Max(cluster);
201  double e3x3 = lazyTool.e3x3(cluster);
202  double e5x5 = lazyTool.e5x5(cluster);
203 
204 
205  //compute preshower energies for endcap clusters
206  double ePS1=0, ePS2=0;
207  if(!iseb) {
208  auto ee_key_val = std::make_pair(idx,edm::Ptr<reco::PFCluster>());
209  const auto clustops = std::equal_range(assoc.begin(),
210  assoc.end(),
211  ee_key_val,
212  sortByKey);
213  for( auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
214  edm::Ptr<reco::PFCluster> psclus(i_ps->second);
215  switch( psclus->layer() ) {
216  case PFLayer::PS1:
217  ePS1 += psclus->energy();
218  break;
219  case PFLayer::PS2:
220  ePS2 += psclus->energy();
221  break;
222  default:
223  break;
224  }
225  }
226  }
227 
228  //fill array for forest evaluation
229  eval[0] = e;
230  eval[1] = eta;
231  eval[2] = phi;
232 
233  if (size==1) {
234  eval[3] = nvtx;
235  if (!iseb) {
236  eval[4] = ePS1*invE;
237  eval[5] = ePS2*invE;
238  }
239  }
240  else if (size==2) {
241  eval[3] = e1x3*invE;
242  eval[4] = nvtx;
243  if (!iseb) {
244  eval[5] = ePS1*invE;
245  eval[6] = ePS2*invE;
246  }
247  }
248  else if (size>2) {
249  eval[3] = e1x3*invE;
250  eval[4] = e2x2*invE;
251  eval[5] = e2x5max*invE;
252  eval[6] = e3x3*invE;
253  eval[7] = e5x5*invE;
254  eval[8] = nvtx;
255  if (!iseb) {
256  eval[9] = ePS1*invE;
257  eval[10] = ePS2*invE;
258  }
259  }
260 
261  //these are the actual BDT responses
262  double rawmean = meanforest.GetResponse(eval.data());
263  double rawsigma = sigmaforest.GetResponse(eval.data());
264 
265  //apply transformation to limited output range (matching the training)
266  double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
267  double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
268 
269  cluster.setCorrectedEnergy(mean*e);
270  cluster.setCorrectedEnergyUncertainty(sigma*e);
271 
272  }
273 
274 }
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:86
std::vector< std::string > _condnames_mean_50ns
double GetResponse(const float *vector) const
Definition: GBRForestD.h:51
auto_ptr< ClusterSequence > cs
std::vector< std::string > _condnames_sigma_25ns
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:47
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
std::vector< std::string > _condnames_mean_25ns
T eta() const
bool isRealData() const
Definition: EventBase.h:60
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:163
edm::EDGetTokenT< int > bunchSpacing_
edm::EDGetTokenT< EcalRecHitCollection > _recHitsEB
std::unique_ptr< PFEnergyCalibration > _calibrator
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:109
RunNumber_t run() const
Definition: Event.h:85
T min(T a, T b)
Definition: MathUtil.h:58
double energy() const
cluster energy
Definition: PFCluster.h:79
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const T & get() const
Definition: EventSetup.h:55
edm::EDGetTokenT< reco::VertexCollection > _vertices
edm::EDGetTokenT< EcalRecHitCollection > _recHitsEE
std::vector< std::string > _condnames_sigma_50ns
unsigned int RunNumber_t
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:166
void setCorrectedEnergyUncertainty(float energyerr)
Definition: CaloCluster.h:110
tuple size
Write out results.
Definition: DDAxes.h:10
PFClusterEMEnergyCorrector& PFClusterEMEnergyCorrector::operator= ( const PFClusterEMEnergyCorrector )
delete

Member Data Documentation

bool PFClusterEMEnergyCorrector::_applyCrackCorrections
private

Definition at line 26 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

bool PFClusterEMEnergyCorrector::_applyMVACorrections
private

Definition at line 27 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

std::unique_ptr<PFEnergyCalibration> PFClusterEMEnergyCorrector::_calibrator
private

Definition at line 43 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<std::string> PFClusterEMEnergyCorrector::_condnames_mean_25ns
private

Definition at line 40 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

std::vector<std::string> PFClusterEMEnergyCorrector::_condnames_mean_50ns
private

Definition at line 38 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

std::vector<std::string> PFClusterEMEnergyCorrector::_condnames_sigma_25ns
private

Definition at line 41 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

std::vector<std::string> PFClusterEMEnergyCorrector::_condnames_sigma_50ns
private

Definition at line 39 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

edm::EDGetTokenT<EcalRecHitCollection> PFClusterEMEnergyCorrector::_recHitsEB
private

Definition at line 34 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

edm::EDGetTokenT<EcalRecHitCollection> PFClusterEMEnergyCorrector::_recHitsEE
private

Definition at line 35 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

edm::EDGetTokenT<reco::VertexCollection> PFClusterEMEnergyCorrector::_vertices
private

Definition at line 36 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

bool PFClusterEMEnergyCorrector::autoDetectBunchSpacing_
private

Definition at line 29 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

edm::EDGetTokenT<int> PFClusterEMEnergyCorrector::bunchSpacing_
private

Definition at line 32 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies(), and PFClusterEMEnergyCorrector().

int PFClusterEMEnergyCorrector::bunchSpacingManual_
private

Definition at line 30 of file PFClusterEMEnergyCorrector.h.

Referenced by PFClusterEMEnergyCorrector().