CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalClusterLazyTools.cc
Go to the documentation of this file.
2 
5 
8 
16 
20 
24 
25 //EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, const edm::InputTag& redEBRecHits, const edm::InputTag& redEERecHits,const edm::ParameterSet& config )
26 EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, const edm::InputTag& redEBRecHits, const edm::InputTag& redEERecHits)
27 {
28  getGeometry( es );
29  getTopology( es );
30  getEBRecHits( ev, redEBRecHits );
31  getEERecHits( ev, redEERecHits );
33  getADCToGeV ( es );
34  getLaserDbService ( es );
35 
36  //AA
37  //Flags and Severities to be excluded from photon calculations
38 /*
39  const std::vector<std::string> flagnames =
40  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
41 
42  flagsexcl_=
43  StringToEnumValue<EcalRecHit::Flags>(flagnames);
44 
45  const std::vector<std::string> severitynames =
46  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcluded");
47 
48  severitiesexcl_=
49  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
50  //AA
51 
52  //AA
53 */
54  //Get the severity level object
55 // edm::ESHandle<EcalSeverityLevelAlgo> sevLv;
56 // es.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
57  //
58 
59 }
60 
62 {
63  getGeometry( es );
64  getTopology( es );
65  getEBRecHits( ev, redEBRecHits );
66  getEERecHits( ev, redEERecHits );
68  getADCToGeV ( es );
69  getLaserDbService ( es );
70 
71 // edm::ESHandle<EcalSeverityLevelAlgo> sevLv;
72 // es.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
73 
74 }
75 
76 EcalClusterLazyToolsBase::EcalClusterLazyToolsBase( const edm::Event &ev, const edm::EventSetup &es, const edm::InputTag& redEBRecHits, const edm::InputTag& redEERecHits, const edm::InputTag& redESRecHits)
77 {
78  getGeometry( es );
79  getTopology( es );
80  getEBRecHits( ev, redEBRecHits );
81  getEERecHits( ev, redEERecHits );
82  getESRecHits( ev, redESRecHits );
84  getADCToGeV ( es );
85  getLaserDbService ( es );
86 
87 }
88 
90 {
91 }
92 
93 
94 
96 {
98  es.get<CaloGeometryRecord>().get(pGeometry);
99  geometry_ = pGeometry.product();
100 }
101 
102 
103 
105 {
106  edm::ESHandle<CaloTopology> pTopology;
107  es.get<CaloTopologyRecord>().get(pTopology);
108  topology_ = pTopology.product();
109 }
110 
111 
112 
114 {
116  ev.getByLabel( redEBRecHits, pEBRecHits );
117  ebRecHits_ = pEBRecHits.product();
118 }
119 
120 
121 
123 {
125  ev.getByLabel( redEERecHits, pEERecHits );
126  eeRecHits_ = pEERecHits.product();
127 }
128 
129 
130 
132 {
134  ev.getByLabel( redESRecHits, pESRecHits );
135  esRecHits_ = pESRecHits.product();
136 
137  // make the map of rechits
138  rechits_map_.clear();
139  if (pESRecHits.isValid()) {
141  for (it = pESRecHits->begin(); it != pESRecHits->end(); ++it) {
142  // remove bad ES rechits
143  if (it->recoFlag()==1 || it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
144  //Make the map of DetID, EcalRecHit pairs
145  rechits_map_.insert(std::make_pair(it->id(), *it));
146  }
147  }
148 
149 }
150 
151 
152 
154 {
155  // get IC's
157  icalMap = ical->getMap();
158 }
159 
160 
161 
163 {
164  // get ADCtoGeV
165  es.get<EcalADCToGeVConstantRcd>().get(agc);
166 }
167 
168 
169 
171  // transp corrections
172  es.get<EcalLaserDbRecord>().get(laser);
173 }
174 
175 
177 {
178  if ( cluster.size() == 0 ) {
179  throw cms::Exception("InvalidCluster") << "The cluster has no crystals!";
180  }
181  DetId id = (cluster.hitsAndFractions()[0]).first; // size is by definition > 0 -- FIXME??
182  const EcalRecHitCollection *recHits = 0;
183  if ( id.subdetId() == EcalBarrel ) {
184  recHits = ebRecHits_;
185  } else if ( id.subdetId() == EcalEndcap ) {
186  recHits = eeRecHits_;
187  } else {
188  throw cms::Exception("InvalidSubdetector") << "The subdetId() " << id.subdetId() << " does not correspond to EcalBarrel neither EcalEndcap";
189  }
190  return recHits;
191 }
192 
193 
194 // get time of basic cluster seed crystal
196 {
197 
198  const EcalRecHitCollection *recHits = getEcalRecHitCollection( cluster );
199 
200  DetId id = cluster.seed();
201  EcalRecHitCollection::const_iterator theSeedHit = recHits->find (id);
202  // std::cout << "the seed of the BC has time: "
203  //<< (*theSeedHit).time()
204  //<< "and energy: " << (*theSeedHit).energy() << " collection size: " << recHits->size()
205  //<< "\n" <<std::endl; // GF debug
206 
207  return (*theSeedHit).time();
208 }
209 
210 
211 // error-weighted average of time from constituents of basic cluster
213 {
214 
215  std::vector<std::pair<DetId, float> > clusterComponents = (cluster).hitsAndFractions() ;
216  //std::cout << "BC has this many components: " << clusterComponents.size() << std::endl; // GF debug
217 
218  const EcalRecHitCollection *recHits = getEcalRecHitCollection( cluster );
219  //std::cout << "BasicClusterClusterTime - rechits are this many: " << recHits->size() << std::endl; // GF debug
220 
221 
222  float weightedTsum = 0;
223  float sumOfWeights = 0;
224 
225  for (std::vector<std::pair<DetId, float> >::const_iterator detitr = clusterComponents.begin(); detitr != clusterComponents.end(); detitr++ )
226  {
227  // EcalRecHitCollection::const_iterator theSeedHit = recHits->find (id); // trash this
228  EcalRecHitCollection::const_iterator oneHit = recHits->find( (detitr -> first) ) ;
229 
230  // in order to get back the ADC counts from the recHit energy, three ingredients are necessary:
231  // 1) get laser correction coefficient
232  float lasercalib = 1.;
233  lasercalib = laser->getLaserCorrection( detitr->first, ev.time());
234  // 2) get intercalibration
236  EcalIntercalibConstant icalconst = 1.;
237  if( icalit!=icalMap.end() ) {
238  icalconst = (*icalit);
239  // std::cout << "icalconst set to: " << icalconst << std::endl;
240  } else {
241  edm::LogError("EcalClusterLazyTools") << "No intercalib const found for xtal " << (detitr->first).rawId() << "bailing out";
242  assert(0);
243  }
244  // 3) get adc2GeV
245  float adcToGeV = 1.;
246  if ( (detitr -> first).subdetId() == EcalBarrel ) adcToGeV = float(agc->getEBValue());
247  else if ( (detitr -> first).subdetId() == EcalEndcap ) adcToGeV = float(agc->getEEValue());
248  float adc = 2.;
249  if (icalconst>0 && lasercalib>0 && adcToGeV>0) adc= (*oneHit).energy()/(icalconst*lasercalib*adcToGeV);
250 
251  // don't consider recHits with too little amplitude; take sigma_noise_total into account
252  if( (detitr -> first).subdetId() == EcalBarrel && adc< (1.1*20) ) continue;
253  if( (detitr -> first).subdetId() == EcalEndcap && adc< (2.2*20) ) continue;
254 
255  // count only on rechits whose error is trusted by the method (ratio)
256  if(! (*oneHit).isTimeErrorValid()) continue;
257 
258  float timeError = (*oneHit).timeError();
259  // the constant used to build timeError is largely over-estimated ; remove in quadrature 0.6 and add 0.15 back.
260  // could be prettier if value of constant term was changed at recHit production level
261  if (timeError>0.6) timeError = sqrt( timeError*timeError - 0.6*0.6 + 0.15*0.15);
262  else timeError = sqrt( timeError*timeError + 0.15*0.15);
263 
264  // do the error weighting
265  weightedTsum += (*oneHit).time() / (timeError*timeError);
266  sumOfWeights += 1. / (timeError*timeError);
267 
268  }
269 
270  // what if no crytal is available for weighted average?
271  if ( sumOfWeights ==0 ) return -999;
272  else return ( weightedTsum / sumOfWeights);
273 
274 }
275 
276 
277 // get BasicClusterSeedTime of the seed basic cluser of the supercluster
279 
280  return BasicClusterSeedTime ( (*cluster.seed()) );
281 
282 }
283 
284 
285 // get BasicClusterTime of the seed basic cluser of the supercluster
287 
288  return BasicClusterTime ( (*cluster.seed()) , ev);
289 
290 }
291 
292 
293 // get Preshower effective sigmaIRIR
295 {
296  if (!(fabs(cluster.eta()) > 1.6 && fabs(cluster.eta()) < 3.)) return 0.;
297 
299  CaloSubdetectorTopology *topology_p = 0;
300  if (geometryES) topology_p = new EcalPreshowerTopology(geometry_);
301 
302  std::vector<float> phoESHitsIXIX = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 1);
303  std::vector<float> phoESHitsIYIY = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 2);
304  float phoESShapeIXIX = getESShape(phoESHitsIXIX);
305  float phoESShapeIYIY = getESShape(phoESHitsIYIY);
306 
307  return sqrt(phoESShapeIXIX*phoESShapeIXIX + phoESShapeIYIY*phoESShapeIYIY);
308 }
309 
310 // get Preshower effective sigmaIXIX
312 {
313  if (!(fabs(cluster.eta()) > 1.6 && fabs(cluster.eta()) < 3.)) return 0.;
314 
316  CaloSubdetectorTopology *topology_p = 0;
317  if (geometryES) topology_p = new EcalPreshowerTopology(geometry_);
318 
319  std::vector<float> phoESHitsIXIX = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 1);
320  float phoESShapeIXIX = getESShape(phoESHitsIXIX);
321 
322  return phoESShapeIXIX;
323 }
324 
325 // get Preshower effective sigmaIYIY
327 {
328  if (!(fabs(cluster.eta()) > 1.6 && fabs(cluster.eta()) < 3.)) return 0.;
329 
331  CaloSubdetectorTopology *topology_p = 0;
332  if (geometryES) topology_p = new EcalPreshowerTopology(geometry_);
333 
334  std::vector<float> phoESHitsIYIY = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 2);
335  float phoESShapeIYIY = getESShape(phoESHitsIYIY);
336 
337  return phoESShapeIYIY;
338 }
339 
340 // get Preshower Rechits
341 std::vector<float> EcalClusterLazyToolsBase::getESHits(double X, double Y, double Z, const std::map<DetId, EcalRecHit>& _rechits_map, const CaloGeometry* geometry, CaloSubdetectorTopology *topology_p, int row, int plane)
342 {
343  std::map<DetId, EcalRecHit> rechits_map = _rechits_map;
344  std::vector<float> esHits;
345 
346  const GlobalPoint point(X,Y,Z);
347 
348  const CaloSubdetectorGeometry *geometry_p ;
349  geometry_p = geometry->getSubdetectorGeometry (DetId::Ecal,EcalPreshower) ;
350 
351  DetId esId = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, plane);
352  ESDetId esDetId = (esId == DetId(0)) ? ESDetId(0) : ESDetId(esId);
353 
354  std::map<DetId, EcalRecHit>::iterator it;
355  ESDetId next;
356  ESDetId strip;
357  strip = esDetId;
358 
359  EcalPreshowerNavigator theESNav(strip, topology_p);
360  theESNav.setHome(strip);
361 
362  if (row == 1) {
363  if (plane==1 && strip != ESDetId(0)) strip = theESNav.north();
364  if (plane==2 && strip != ESDetId(0)) strip = theESNav.east();
365  } else if (row == -1) {
366  if (plane==1 && strip != ESDetId(0)) strip = theESNav.south();
367  if (plane==2 && strip != ESDetId(0)) strip = theESNav.west();
368  }
369 
370 
371  if (strip == ESDetId(0)) {
372  for (int i=0; i<31; ++i) esHits.push_back(0);
373  } else {
374  it = rechits_map.find(strip);
375  if (it->second.energy() > 1.0e-10 && it != rechits_map.end()) esHits.push_back(it->second.energy());
376  else esHits.push_back(0);
377  //cout<<"center : "<<strip<<" "<<it->second.energy()<<endl;
378 
379  // Front Plane
380  if (plane==1) {
381  // east road
382  for (int i=0; i<15; ++i) {
383  next = theESNav.east();
384  if (next != ESDetId(0)) {
385  it = rechits_map.find(next);
386  if (it->second.energy() > 1.0e-10 && it != rechits_map.end()) esHits.push_back(it->second.energy());
387  else esHits.push_back(0);
388  //cout<<"east "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
389  } else {
390  for (int j=i; j<15; j++) esHits.push_back(0);
391  break;
392  //cout<<"east "<<i<<" : "<<next<<" "<<0<<endl;
393  }
394  }
395 
396  // west road
397  theESNav.setHome(strip);
398  theESNav.home();
399  for (int i=0; i<15; ++i) {
400  next = theESNav.west();
401  if (next != ESDetId(0)) {
402  it = rechits_map.find(next);
403  if (it->second.energy() > 1.0e-10 && it != rechits_map.end()) esHits.push_back(it->second.energy());
404  else esHits.push_back(0);
405  //cout<<"west "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
406  } else {
407  for (int j=i; j<15; j++) esHits.push_back(0);
408  break;
409  //cout<<"west "<<i<<" : "<<next<<" "<<0<<endl;
410  }
411  }
412  } // End of Front Plane
413 
414  // Rear Plane
415  if (plane==2) {
416  // north road
417  for (int i=0; i<15; ++i) {
418  next = theESNav.north();
419  if (next != ESDetId(0)) {
420  it = rechits_map.find(next);
421  if (it->second.energy() > 1.0e-10 && it != rechits_map.end()) esHits.push_back(it->second.energy());
422  else esHits.push_back(0);
423  //cout<<"north "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
424  } else {
425  for (int j=i; j<15; j++) esHits.push_back(0);
426  break;
427  //cout<<"north "<<i<<" : "<<next<<" "<<0<<endl;
428  }
429  }
430 
431  // south road
432  theESNav.setHome(strip);
433  theESNav.home();
434  for (int i=0; i<15; ++i) {
435  next = theESNav.south();
436  if (next != ESDetId(0)) {
437  it = rechits_map.find(next);
438  if (it->second.energy() > 1.0e-10 && it != rechits_map.end()) esHits.push_back(it->second.energy());
439  else esHits.push_back(0);
440  //cout<<"south "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
441  } else {
442  for (int j=i; j<15; j++) esHits.push_back(0);
443  break;
444  //cout<<"south "<<i<<" : "<<next<<" "<<0<<endl;
445  }
446  }
447  } // End of Rear Plane
448  } // Fill ES RecHits
449 
450  return esHits;
451 }
452 
453 
454 // get Preshower hit shape
455 float EcalClusterLazyToolsBase::getESShape(const std::vector<float>& ESHits0)
456 {
457  const int nBIN = 21;
458  float esRH[nBIN];
459  for (int idx=0; idx<nBIN; idx++) {
460  esRH[idx] = 0.;
461  }
462 
463  for(int ibin=0; ibin<((nBIN+1)/2); ibin++) {
464  if (ibin==0) {
465  esRH[(nBIN-1)/2] = ESHits0[ibin];
466  } else {
467  esRH[(nBIN-1)/2+ibin] = ESHits0[ibin];
468  esRH[(nBIN-1)/2-ibin] = ESHits0[ibin+15];
469  }
470  }
471 
472  // ---- Effective Energy Deposit Width ---- //
473  double EffWidthSigmaISIS = 0.;
474  double totalEnergyISIS = 0.;
475  double EffStatsISIS = 0.;
476  for (int id_X=0; id_X<21; id_X++) {
477  totalEnergyISIS += esRH[id_X];
478  EffStatsISIS += esRH[id_X]*(id_X-10)*(id_X-10);
479  }
480  EffWidthSigmaISIS = (totalEnergyISIS>0.) ? sqrt(fabs(EffStatsISIS / totalEnergyISIS)) : 0.;
481 
482  return EffWidthSigmaISIS;
483 }
int adc(sample_type sample)
get the ADC sample (12 bits)
const double Z[kNumberCalorimeter]
CaloNavigator< ESDetId > EcalPreshowerNavigator
edm::ESHandle< EcalIntercalibConstants > ical
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
int i
Definition: DBlmapReader.cc:9
const CaloGeometry * geometry_
const EcalRecHitCollection * esRecHits_
float SuperClusterSeedTime(const reco::SuperCluster &cluster)
float BasicClusterTime(const reco::BasicCluster &cluster, const edm::Event &ev)
float SuperClusterTime(const reco::SuperCluster &cluster, const edm::Event &ev)
const EcalRecHitCollection * getEcalRecHitCollection(const reco::BasicCluster &cluster)
float getESShape(const std::vector< float > &ESHits0)
std::vector< EcalRecHit >::const_iterator const_iterator
#define X(str)
Definition: MuonsGrabber.cc:48
void getADCToGeV(const edm::EventSetup &es)
const EcalRecHitCollection * ebRecHits_
float eseffsixix(const reco::SuperCluster &cluster)
void getIntercalibConstants(const edm::EventSetup &es)
double z() const
z coordinate of cluster centroid
Definition: CaloCluster.h:158
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:161
edm::ESHandle< EcalADCToGeVConstant > agc
std::vector< float > getESHits(double X, double Y, double Z, const std::map< DetId, EcalRecHit > &rechits_map, const CaloGeometry *geometry, CaloSubdetectorTopology *topology_p, int row=0, int plane=1)
T sqrt(T t)
Definition: SSEVec.h:48
int j
Definition: DBlmapReader.cc:9
double x() const
x coordinate of cluster centroid
Definition: CaloCluster.h:152
bool first
Definition: L1TdeRCT.cc:79
bool isValid() const
Definition: HandleBase.h:76
void getESRecHits(const edm::Event &ev, const edm::InputTag &redESRecHits)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
Definition: DetId.h:18
float eseffsiyiy(const reco::SuperCluster &cluster)
void getTopology(const edm::EventSetup &es)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
EcalIntercalibConstantMap icalMap
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
void getEERecHits(const edm::Event &ev, const edm::InputTag &redEERecHits)
ESHandle< TrackerGeometry > geometry
iterator find(key_type k)
void getLaserDbService(const edm::EventSetup &es)
const EcalRecHitCollection * eeRecHits_
const_iterator find(uint32_t rawId) const
void getGeometry(const edm::EventSetup &es)
const_iterator end() const
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
double y() const
y coordinate of cluster centroid
Definition: CaloCluster.h:155
EcalClusterLazyToolsBase(const edm::Event &ev, const edm::EventSetup &es, const edm::InputTag &redEBRecHits, const edm::InputTag &redEERecHits, const edm::ParameterSet &config)
std::map< DetId, EcalRecHit > rechits_map_
edm::ESHandle< EcalLaserDbService > laser
edm::Timestamp time() const
Definition: EventBase.h:57
float BasicClusterSeedTime(const reco::BasicCluster &cluster)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
void getEBRecHits(const edm::Event &ev, const edm::InputTag &redEBRecHits)
const CaloTopology * topology_
float EcalIntercalibConstant
float eseffsirir(const reco::SuperCluster &cluster)