CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HiEgammaSCEnergyCorrectionAlgo.cc
Go to the documentation of this file.
1 //
2 // Author: David Evans, Bristol
3 //
6 #include <iostream>
7 #include <string>
8 #include <vector>
9 
12  const edm::ParameterSet& pSet,
14  )
15 {
18 
19  // Parameters
20  p_fBrem_ = pSet.getParameter< std::vector <double> > ("fBremVect");
21  p_fBremTh_ = pSet.getParameter< std::vector <double> > ("fBremThVect");
22  p_fEta_ = pSet.getParameter< std::vector <double> > ("fEtaVect");
23  p_fEtEta_ = pSet.getParameter< std::vector <double> > ("fEtEtaVect");
24 
25  // Min R9
26  minR9Barrel_ = pSet.getParameter<double>("minR9Barrel");
27  minR9Endcap_ = pSet.getParameter<double>("minR9Endcap");
28 
29  // Max R9
30  maxR9_ = pSet.getParameter<double>("maxR9");
31 
32 }
33 
34 
35 
40  const CaloTopology *topology, EcalClusterFunctionBaseClass* EnergyCorrection)
41 {
42 
43  // Print out a little bit of trivial info to be sure all is well
44  if (verbosity_ <= pINFO)
45  {
46  std::cout << " HiEgammaSCEnergyCorrectionAlgo::applyCorrection" << std::endl;
47  std::cout << " SC has energy " << cl.energy() << std::endl;
48  std::cout << " Will correct now.... " << std::endl;
49  }
50 
51  // Get the seed cluster
52  reco::CaloClusterPtr seedC = cl.seed();
53 
54  if (verbosity_ <= pINFO)
55  {
56  std::cout << " Seed cluster energy... " << seedC->energy() << std::endl;
57  }
58 
59  // Get the constituent clusters
60  reco::CaloClusterPtrVector clusters_v;
61 
62  if (verbosity_ <= pINFO) std::cout << " Constituent cluster energies... ";
63 
64  for(reco::CaloCluster_iterator cluster = cl.clustersBegin(); cluster != cl.clustersEnd(); cluster ++)
65  {
66  clusters_v.push_back(*cluster);
67  if (verbosity_ <= pINFO) std::cout << (*cluster)->energy() << ", ";
68  }
69  if (verbosity_ <= pINFO) std::cout << std::endl;
70 
71  // Find the algorithm used to construct the basic clusters making up the supercluster
72  if (verbosity_ <= pINFO)
73  {
74  std::cout << " The seed cluster used algo " << theAlgo;
75  }
76 
77  // Find the detector region of the supercluster
78  // where is the seed cluster?
79  std::vector<std::pair<DetId, float> > const & seedHits = seedC->hitsAndFractions();
80  EcalSubdetector theBase = EcalSubdetector(seedHits.at(0).first.subdetId());
81  if (verbosity_ <= pINFO)
82  {
83  std::cout << " seed cluster location == " << theBase << std::endl;
84  }
85 
86  // Get number of crystals 2sigma above noise in seed basiccluster
87  int nCryGT2Sigma = nCrystalsGT2Sigma(*seedC,rhc);
88  if (verbosity_ <= pINFO)
89  {
90  std::cout << " nCryGT2Sigma " << nCryGT2Sigma << std::endl;
91  }
92 
93  // Supercluster enery - seed basiccluster energy
94  float bremsEnergy = cl.energy() - seedC->energy();
95  if (verbosity_ <= pINFO)
96  {
97  std::cout << " bremsEnergy " << bremsEnergy << std::endl;
98  }
99 
100  // Create a SuperClusterShapeAlgo
101  // which calculates phiWidth and etaWidth
102  SuperClusterShapeAlgo SCShape(&rhc, geometry);
103 
104  double phiWidth = 0.;
105  double etaWidth = 0.;
106 
107  // Calculate phiWidth & etaWidth for SuperClusters
108  SCShape.Calculate_Covariances(cl);
109  phiWidth = SCShape.phiWidth();
110  etaWidth = SCShape.etaWidth();
111 
112  // Calculate r9 and 5x5 energy
113  float e3x3 = EcalClusterTools::e3x3( *(cl.seed()), &rhc, &(*topology));
114  float e5x5 = EcalClusterTools::e5x5( *(cl.seed()), &rhc, &(*topology));
115  float r9 = e3x3 / cl.rawEnergy();
116 
117  // Calculate the new supercluster energy
118  // as a function of number of crystals in the seed basiccluster for Endcap
119  // lslslsor apply new Enegry SCale correction
120  float newEnergy = 0;
121 
122  // if r9 > maxR9_ -> uncaptured brem.
123  if ((r9 < minR9Barrel_&&theBase == EcalBarrel) || (r9 < minR9Endcap_&&theBase == EcalEndcap)) {
124  // if r9 is greater than threshold, then use the SC raw energy
125  newEnergy = (cl.rawEnergy())/ fEta(cl.eta(), theAlgo, theBase) /
126  fBrem(phiWidth/etaWidth, theAlgo, theBase)
127  /fEtEta(cl.energy()/cosh(cl.eta()), cl.eta(), theAlgo, theBase);
128 
129  } else {
130  if (r9 < maxR9_) {
131  // use 5x5 energy if r9 < threshold
132  newEnergy = e5x5 / fEta(cl.eta(), theAlgo, theBase);
133  } else {
134  // it comes from a uncaptured brem, doesn't correct
135  newEnergy = cl.rawEnergy();
136  }
137  }
138 
139  if (newEnergy > 2* cl.rawEnergy()) newEnergy = cl.rawEnergy(); // avoid very large correction due to the uncaptured brem
140 
141  // Create a new supercluster with the corrected energy
142  if (verbosity_ <= pINFO)
143  {
144  std::cout << " UNCORRECTED SC has energy... " << cl.energy() << std::endl;
145  std::cout << " CORRECTED SC has energy... " << newEnergy << std::endl;
146  std::cout << " Size..." <<cl.size() << std::endl;
147  std::cout << " Seed nCryGT2Sigma Size..." <<nCryGT2Sigma << std::endl;
148  }
149 
150  reco::SuperCluster corrCl(newEnergy,
151  math::XYZPoint(cl.position().X(), cl.position().Y(), cl.position().Z()),
152  cl.seed(), clusters_v, cl.preshowerEnergy());
153 
154  //set the flags, although we should implement a ctor in SuperCluster
155  corrCl.setFlags(cl.flags());
156  corrCl.setPhiWidth(phiWidth);
157  corrCl.setEtaWidth(etaWidth);
158 
159  return corrCl;
160 }
161 
163 {
164  int offset = 0;
165  float factor;
166  if((theBase == EcalBarrel) && (theAlgo == reco::CaloCluster::island)) {
167  offset = 0;
168  } else if((theBase == EcalEndcap) && (theAlgo == reco::CaloCluster::island)) {
169  offset = 7;
170  }
171 
172  // Et dependent correction
173  factor = (p_fEtEta_[0+offset] + p_fEtEta_[1+offset]*sqrt(et));
174  // eta dependent correction
175  factor *= (p_fEtEta_[2+offset] + p_fEtEta_[3+offset]*fabs(eta) +
176  p_fEtEta_[4+offset]*eta*eta + p_fEtEta_[5+offset]*eta*eta*fabs(eta) + + p_fEtEta_[6+offset]*eta*eta*eta*eta);
177 
178  // Constraint correction factor
179  if (factor< 0.66f ) factor = 0.66f;
180  if (factor> 1.5f ) factor = 1.5f;
181 
182  return factor;
183 
184 }
185 
187 {
188  int offset = 0;
189  float factor;
190  if((theBase == EcalBarrel) && (theAlgo == reco::CaloCluster::island)) {
191  offset = 0;
192  } else if((theBase == EcalEndcap) && (theAlgo == reco::CaloCluster::island)) {
193  offset = 3;
194  }
195 
196  factor = (p_fEta_[0+offset] + p_fEta_[1+offset]*fabs(eta) + p_fEta_[2+offset]*eta*eta);
197 
198  // Constraint correction factor
199  if (factor< 0.66f ) factor = 0.66f;
200  if (factor> 1.5f ) factor = 1.5f;
201 
202  return factor;
203 }
204 
206 {
207  int det = 0;
208  int offset = 0;
209  float factor;
210  if((theBase == EcalBarrel) && (theAlgo == reco::CaloCluster::island)) {
211  det = 0;
212  offset = 0;
213  } else if((theBase == EcalEndcap) && (theAlgo == reco::CaloCluster::island)) {
214  det = 1;
215  offset = 6;
216  }
217 
218  if (brem < p_fBremTh_[det]) {
219  factor = p_fBrem_[0+offset] + p_fBrem_[1+offset]*brem + p_fBrem_[2+offset]*brem*brem;
220  } else {
221  factor = p_fBrem_[3+offset] + p_fBrem_[4+offset]*brem + p_fBrem_[5+offset]*brem*brem;
222  };
223 
224  // Constraint correction factor
225  if (factor< 0.66f ) factor = 0.66f;
226  if (factor> 1.5f ) factor = 1.5f;
227 
228  return factor;
229 }
230 
231 // char *var ="rawEnergy/cosh(genMatchedEta)/(1.01606-0.0162668*abs(eta))/genMatchedPt/(1.022-0.02812*phiWidth/etaWidth+0.001637*phiWidth*phiWidth/etaWidth/etaWidth)/((0.682554+0.0253013*scSize-(0.0007907)*scSize*scSize+(1.166e-5)*scSize*scSize*scSize-(6.7387e-8)*scSize*scSize*scSize*scSize)*(scSize<40)+(scSize>=40))/((1.016-0.009877*((clustersSize<=4)*clustersSize+(clustersSize>4)*4)))";
232 
234 {
235 
236  float x = (float) nCry;
237  float result =1.f;
238 
239  if((theBase == EcalBarrel) && (theAlgo == reco::CaloCluster::island)) {
240  float const p0 = 0.682554f;
241  float const p1 = 0.0253013f;
242  float const p2 = -0.0007907f;
243  float const p3 = 1.166e-5f;
244  float const p4 = -6.7387e-8f;
245  if (x < 10.f) x = 10.f;
246  if (x < 40.f) result = p0 + x*(p1 + x*(p2 + x*(p3 + x*p4))); else result = 1.f;
247  }
248 
249  else if((theBase == EcalEndcap) && (theAlgo == reco::CaloCluster::island)) {
250 
251  float const p0 = 0.712185f;
252  float const p1 = 0.0273609f;
253  float const p2 = -0.00103818f;
254  float const p3 = 2.01828e-05f;
255  float const p4 = -1.71438e-07f;
256  if (x < 10.f) x = 10.f;
257  if (x < 40.f) result = p0 + x*(p1 + x*(p2 + x*(p3 + x*p4))); else result = 1.f;
258  }
259 
260  else {
261  if (verbosity_ <= pINFO)
262  {
263  std::cout << "trying to correct unknown cluster!!!" << std::endl;
264  }
265  }
266 
267  if (result > 1.5f) result = 1.5f;
268  if (result < 0.5f) result = 0.5f;
269 
270  return result;
271 }
272 
274  // return number of crystals 2Sigma above
275  // electronic noise
276 
277  std::vector<std::pair<DetId,float > > const & hits = seed.hitsAndFractions();
278 
279  if (verbosity_ <= pINFO)
280  {
281  std::cout << " HiEgammaSCEnergyCorrectionAlgo::nCrystalsGT2Sigma" << std::endl;
282  std::cout << " Will calculate number of crystals above 2sigma noise" << std::endl;
283  std::cout << " sigmaElectronicNoise = " << sigmaElectronicNoise_ << std::endl;
284  std::cout << " There are " << hits.size() << " recHits" << std::endl;
285  }
286 
287  int nCry = 0;
288  for(std::vector<std::pair<DetId,float > >::const_iterator hit = hits.begin(); hit != hits.end(); ++hit)
289  {
290  // need to get hit by DetID in order to get energy
291  EcalRecHitCollection::const_iterator aHit = rhc.find((*hit).first);
292  // better the hit to exists....
293  if(aHit->energy()>2.f*sigmaElectronicNoise_) ++nCry;
294  }
295 
296  if (verbosity_ <= pINFO)
297  {
298  std::cout << " " << nCry << " of these above 2sigma noise" << std::endl;
299  }
300 
301  return nCry;
302 }
303 
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:126
void Calculate_Covariances(const reco::SuperCluster &passedCluster)
float fBrem(float widthRatio, reco::CaloCluster::AlgoId theAlgo, EcalSubdetector theBase) const
CaloTopology const * topology(0)
float fNCrystals(int nCry, reco::CaloCluster::AlgoId theAlgo, EcalSubdetector theBase) const
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:141
HiEgammaSCEnergyCorrectionAlgo(float noise, reco::CaloCluster::AlgoId theAlgo, const edm::ParameterSet &pSet, VerbosityLevel verbosity=pERROR)
reco::SuperCluster applyCorrection(const reco::SuperCluster &cl, const EcalRecHitCollection &rhc, reco::CaloCluster::AlgoId theAlgo, const CaloSubdetectorGeometry *geometry, const CaloTopology *topology, EcalClusterFunctionBaseClass *EnergyCorrectionClass)
std::vector< EcalRecHit >::const_iterator const_iterator
float fEta(float eta, reco::CaloCluster::AlgoId theAlgo, EcalSubdetector theBase) const
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:163
float fEtEta(float et, float eta, reco::CaloCluster::AlgoId theAlgo, EcalSubdetector theBase) const
void setFlags(uint32_t flags)
Definition: CaloCluster.h:176
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
tuple result
Definition: query.py:137
uint32_t flags() const
Definition: CaloCluster.h:175
int nCrystalsGT2Sigma(reco::BasicCluster const &seed, EcalRecHitCollection const &rhc) const
double f[11][100]
double energy() const
cluster energy
Definition: CaloCluster.h:121
double p2[4]
Definition: TauolaWrapper.h:90
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:47
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
ESHandle< TrackerGeometry > geometry
iterator find(key_type k)
size_t size() const
size in number of hits (e.g. in crystals for ECAL)
Definition: CaloCluster.h:169
double p1[4]
Definition: TauolaWrapper.h:89
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
tuple cout
Definition: gather_cfg.py:121
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
double preshowerEnergy() const
energy deposited in preshower
Definition: SuperCluster.h:50
EcalSubdetector
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78
double p3[4]
Definition: TauolaWrapper.h:91