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 
26 
27  ebRHToken_ = token1;
28  eeRHToken_ = token2;
29 
30  getGeometry( es );
31  getTopology( es );
32  getEBRecHits( ev );
33  getEERecHits( ev );
35  getADCToGeV ( es );
36  getLaserDbService ( es );
37 }
38 
40 
41  ebRHToken_ = token1;
42  eeRHToken_ = token2;
43  esRHToken_ = token3;
44 
45  getGeometry( es );
46  getTopology( es );
47  getEBRecHits( ev );
48  getEERecHits( ev );
49  getESRecHits( ev );
51  getADCToGeV ( es );
52  getLaserDbService ( es );
53 }
54 
56 {}
57 
60  es.get<CaloGeometryRecord>().get(pGeometry);
61  geometry_ = pGeometry.product();
62 }
63 
66  es.get<CaloTopologyRecord>().get(pTopology);
67  topology_ = pTopology.product();
68 }
69 
72  ev.getByToken( ebRHToken_, pEBRecHits );
73  ebRecHits_ = pEBRecHits.product();
74 }
75 
78  ev.getByToken( eeRHToken_, pEERecHits );
79  eeRecHits_ = pEERecHits.product();
80 }
81 
84  ev.getByToken( esRHToken_, pESRecHits );
85  esRecHits_ = pESRecHits.product();
86  // make the map of rechits
87  rechits_map_.clear();
88  if (pESRecHits.isValid()) {
90  for (it = pESRecHits->begin(); it != pESRecHits->end(); ++it) {
91  // remove bad ES rechits
92  std::vector<int> badf = {
93  EcalRecHit::ESFlags::kESDead, // 1
94  EcalRecHit::ESFlags::kESTwoGoodRatios,
95  EcalRecHit::ESFlags::kESBadRatioFor12, // 5
96  EcalRecHit::ESFlags::kESBadRatioFor23Upper,
97  EcalRecHit::ESFlags::kESBadRatioFor23Lower,
98  EcalRecHit::ESFlags::kESTS1Largest,
99  EcalRecHit::ESFlags::kESTS3Largest,
100  EcalRecHit::ESFlags::kESTS3Negative, // 10
101  EcalRecHit::ESFlags::kESTS13Sigmas, // 14
102  };
103 
104  if (it->checkFlags(badf)) continue;
105 
106  //Make the map of DetID, EcalRecHit pairs
107  rechits_map_.insert(std::make_pair(it->id(), *it));
108  }
109  }
110 }
111 
112 
113 
115 {
116  // get IC's
118  icalMap = &ical->getMap();
119 }
120 
121 
122 
124 {
125  // get ADCtoGeV
126  es.get<EcalADCToGeVConstantRcd>().get(agc);
127 }
128 
129 
130 
132  // transp corrections
133  es.get<EcalLaserDbRecord>().get(laser);
134 }
135 
136 
138 {
139  if ( cluster.size() == 0 ) {
140  throw cms::Exception("InvalidCluster") << "The cluster has no crystals!";
141  }
142  DetId id = (cluster.hitsAndFractions()[0]).first; // size is by definition > 0 -- FIXME??
143  const EcalRecHitCollection *recHits = 0;
144  if ( id.subdetId() == EcalBarrel ) {
145  recHits = ebRecHits_;
146  } else if ( id.subdetId() == EcalEndcap ) {
147  recHits = eeRecHits_;
148  } else {
149  throw cms::Exception("InvalidSubdetector") << "The subdetId() " << id.subdetId() << " does not correspond to EcalBarrel neither EcalEndcap";
150  }
151  return recHits;
152 }
153 
154 
155 // get time of basic cluster seed crystal
157 {
158 
160 
161  DetId id = cluster.seed();
162  EcalRecHitCollection::const_iterator theSeedHit = recHits->find (id);
163  // std::cout << "the seed of the BC has time: "
164  //<< (*theSeedHit).time()
165  //<< "and energy: " << (*theSeedHit).energy() << " collection size: " << recHits->size()
166  //<< "\n" <<std::endl; // GF debug
167 
168  return (*theSeedHit).time();
169 }
170 
171 
172 // error-weighted average of time from constituents of basic cluster
174 {
175 
176  std::vector<std::pair<DetId, float> > clusterComponents = (cluster).hitsAndFractions() ;
177  //std::cout << "BC has this many components: " << clusterComponents.size() << std::endl; // GF debug
178 
180  //std::cout << "BasicClusterClusterTime - rechits are this many: " << recHits->size() << std::endl; // GF debug
181 
182 
183  float weightedTsum = 0;
184  float sumOfWeights = 0;
185 
186  for (std::vector<std::pair<DetId, float> >::const_iterator detitr = clusterComponents.begin(); detitr != clusterComponents.end(); detitr++ )
187  {
188  // EcalRecHitCollection::const_iterator theSeedHit = recHits->find (id); // trash this
189  EcalRecHitCollection::const_iterator oneHit = recHits->find( (detitr -> first) ) ;
190 
191  // in order to get back the ADC counts from the recHit energy, three ingredients are necessary:
192  // 1) get laser correction coefficient
193  float lasercalib = 1.;
194  lasercalib = laser->getLaserCorrection( detitr->first, ev.time());
195  // 2) get intercalibration
196  EcalIntercalibConstantMap::const_iterator icalit = icalMap->find(detitr->first);
197  EcalIntercalibConstant icalconst = 1.;
198  if( icalit!=icalMap->end() ) {
199  icalconst = (*icalit);
200  // std::cout << "icalconst set to: " << icalconst << std::endl;
201  } else {
202  edm::LogError("EcalClusterLazyTools") << "No intercalib const found for xtal " << (detitr->first).rawId() << "bailing out";
203  assert(0);
204  }
205  // 3) get adc2GeV
206  float adcToGeV = 1.;
207  if ( (detitr -> first).subdetId() == EcalBarrel ) adcToGeV = float(agc->getEBValue());
208  else if ( (detitr -> first).subdetId() == EcalEndcap ) adcToGeV = float(agc->getEEValue());
209  float adc = 2.;
210  if (icalconst>0 && lasercalib>0 && adcToGeV>0) adc= (*oneHit).energy()/(icalconst*lasercalib*adcToGeV);
211 
212  // don't consider recHits with too little amplitude; take sigma_noise_total into account
213  if( (detitr -> first).subdetId() == EcalBarrel && adc< (1.1*20) ) continue;
214  if( (detitr -> first).subdetId() == EcalEndcap && adc< (2.2*20) ) continue;
215 
216  // count only on rechits whose error is trusted by the method (ratio)
217  if(! (*oneHit).isTimeErrorValid()) continue;
218 
219  float timeError = (*oneHit).timeError();
220  // the constant used to build timeError is largely over-estimated ; remove in quadrature 0.6 and add 0.15 back.
221  // could be prettier if value of constant term was changed at recHit production level
222  if (timeError>0.6) timeError = sqrt( timeError*timeError - 0.6*0.6 + 0.15*0.15);
223  else timeError = sqrt( timeError*timeError + 0.15*0.15);
224 
225  // do the error weighting
226  weightedTsum += (*oneHit).time() / (timeError*timeError);
227  sumOfWeights += 1. / (timeError*timeError);
228 
229  }
230 
231  // what if no crytal is available for weighted average?
232  if ( sumOfWeights ==0 ) return -999;
233  else return ( weightedTsum / sumOfWeights);
234 
235 }
236 
237 
238 // get BasicClusterSeedTime of the seed basic cluser of the supercluster
240 
241  return BasicClusterSeedTime ( (*cluster.seed()) );
242 
243 }
244 
245 
246 // get BasicClusterTime of the seed basic cluser of the supercluster
248 
249  return BasicClusterTime ( (*cluster.seed()) , ev);
250 
251 }
252 
253 
254 // get Preshower effective sigmaIRIR
256 {
257  if (!(fabs(cluster.eta()) > 1.6 && fabs(cluster.eta()) < 3.)) return 0.;
258 
260  CaloSubdetectorTopology *topology_p = 0;
261  if (geometryES) topology_p = new EcalPreshowerTopology(geometry_);
262 
263  std::vector<float> phoESHitsIXIX = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 1);
264  std::vector<float> phoESHitsIYIY = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 2);
265  float phoESShapeIXIX = getESShape(phoESHitsIXIX);
266  float phoESShapeIYIY = getESShape(phoESHitsIYIY);
267 
268  return sqrt(phoESShapeIXIX*phoESShapeIXIX + phoESShapeIYIY*phoESShapeIYIY);
269 }
270 
271 // get Preshower effective sigmaIXIX
273 {
274  if (!(fabs(cluster.eta()) > 1.6 && fabs(cluster.eta()) < 3.)) return 0.;
275 
277  CaloSubdetectorTopology *topology_p = 0;
278  if (geometryES) topology_p = new EcalPreshowerTopology(geometry_);
279 
280  std::vector<float> phoESHitsIXIX = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 1);
281  float phoESShapeIXIX = getESShape(phoESHitsIXIX);
282 
283  return phoESShapeIXIX;
284 }
285 
286 // get Preshower effective sigmaIYIY
288 {
289  if (!(fabs(cluster.eta()) > 1.6 && fabs(cluster.eta()) < 3.)) return 0.;
290 
292  CaloSubdetectorTopology *topology_p = 0;
293  if (geometryES) topology_p = new EcalPreshowerTopology(geometry_);
294 
295  std::vector<float> phoESHitsIYIY = getESHits(cluster.x(), cluster.y(), cluster.z(), rechits_map_, geometry_, topology_p, 0, 2);
296  float phoESShapeIYIY = getESShape(phoESHitsIYIY);
297 
298  return phoESShapeIYIY;
299 }
300 
301 // get Preshower Rechits
302 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)
303 {
304  std::map<DetId, EcalRecHit> rechits_map = _rechits_map;
305  std::vector<float> esHits;
306 
307  const GlobalPoint point(X,Y,Z);
308 
309  const CaloSubdetectorGeometry *geometry_p ;
310  geometry_p = geometry->getSubdetectorGeometry (DetId::Ecal,EcalPreshower) ;
311 
312  DetId esId = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, plane);
313  ESDetId esDetId = (esId == DetId(0)) ? ESDetId(0) : ESDetId(esId);
314 
315  std::map<DetId, EcalRecHit>::iterator it;
316  ESDetId next;
317  ESDetId strip;
318  strip = esDetId;
319 
320  EcalPreshowerNavigator theESNav(strip, topology_p);
321  theESNav.setHome(strip);
322 
323  if (row == 1) {
324  if (plane==1 && strip != ESDetId(0)) strip = theESNav.north();
325  if (plane==2 && strip != ESDetId(0)) strip = theESNav.east();
326  } else if (row == -1) {
327  if (plane==1 && strip != ESDetId(0)) strip = theESNav.south();
328  if (plane==2 && strip != ESDetId(0)) strip = theESNav.west();
329  }
330 
331 
332  if (strip == ESDetId(0)) {
333  for (int i=0; i<31; ++i) esHits.push_back(0);
334  } else {
335  it = rechits_map.find(strip);
336  if (it != rechits_map.end() && it->second.energy() > 1.0e-10) esHits.push_back(it->second.energy());
337  else esHits.push_back(0);
338  //cout<<"center : "<<strip<<" "<<it->second.energy()<<endl;
339 
340  // Front Plane
341  if (plane==1) {
342  // east road
343  for (int i=0; i<15; ++i) {
344  next = theESNav.east();
345  if (next != ESDetId(0)) {
346  it = rechits_map.find(next);
347  if (it != rechits_map.end() && it->second.energy() > 1.0e-10) esHits.push_back(it->second.energy());
348  else esHits.push_back(0);
349  //cout<<"east "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
350  } else {
351  for (int j=i; j<15; j++) esHits.push_back(0);
352  break;
353  //cout<<"east "<<i<<" : "<<next<<" "<<0<<endl;
354  }
355  }
356 
357  // west road
358  theESNav.setHome(strip);
359  theESNav.home();
360  for (int i=0; i<15; ++i) {
361  next = theESNav.west();
362  if (next != ESDetId(0)) {
363  it = rechits_map.find(next);
364  if (it != rechits_map.end() && it->second.energy() > 1.0e-10) esHits.push_back(it->second.energy());
365  else esHits.push_back(0);
366  //cout<<"west "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
367  } else {
368  for (int j=i; j<15; j++) esHits.push_back(0);
369  break;
370  //cout<<"west "<<i<<" : "<<next<<" "<<0<<endl;
371  }
372  }
373  } // End of Front Plane
374 
375  // Rear Plane
376  if (plane==2) {
377  // north road
378  for (int i=0; i<15; ++i) {
379  next = theESNav.north();
380  if (next != ESDetId(0)) {
381  it = rechits_map.find(next);
382  if (it != rechits_map.end() && it->second.energy() > 1.0e-10) esHits.push_back(it->second.energy());
383  else esHits.push_back(0);
384  //cout<<"north "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
385  } else {
386  for (int j=i; j<15; j++) esHits.push_back(0);
387  break;
388  //cout<<"north "<<i<<" : "<<next<<" "<<0<<endl;
389  }
390  }
391 
392  // south road
393  theESNav.setHome(strip);
394  theESNav.home();
395  for (int i=0; i<15; ++i) {
396  next = theESNav.south();
397  if (next != ESDetId(0)) {
398  it = rechits_map.find(next);
399  if (it != rechits_map.end() && it->second.energy() > 1.0e-10) esHits.push_back(it->second.energy());
400  else esHits.push_back(0);
401  //cout<<"south "<<i<<" : "<<next<<" "<<it->second.energy()<<endl;
402  } else {
403  for (int j=i; j<15; j++) esHits.push_back(0);
404  break;
405  //cout<<"south "<<i<<" : "<<next<<" "<<0<<endl;
406  }
407  }
408  } // End of Rear Plane
409  } // Fill ES RecHits
410 
411  return esHits;
412 }
413 
414 
415 // get Preshower hit shape
416 float EcalClusterLazyToolsBase::getESShape(const std::vector<float>& ESHits0)
417 {
418  const int nBIN = 21;
419  float esRH[nBIN];
420  for (int idx=0; idx<nBIN; idx++) {
421  esRH[idx] = 0.;
422  }
423 
424  for(int ibin=0; ibin<((nBIN+1)/2); ibin++) {
425  if (ibin==0) {
426  esRH[(nBIN-1)/2] = ESHits0[ibin];
427  } else {
428  esRH[(nBIN-1)/2+ibin] = ESHits0[ibin];
429  esRH[(nBIN-1)/2-ibin] = ESHits0[ibin+15];
430  }
431  }
432 
433  // ---- Effective Energy Deposit Width ---- //
434  double EffWidthSigmaISIS = 0.;
435  double totalEnergyISIS = 0.;
436  double EffStatsISIS = 0.;
437  for (int id_X=0; id_X<21; id_X++) {
438  totalEnergyISIS += esRH[id_X];
439  EffStatsISIS += esRH[id_X]*(id_X-10)*(id_X-10);
440  }
441  EffWidthSigmaISIS = (totalEnergyISIS>0.) ? sqrt(fabs(EffStatsISIS / totalEnergyISIS)) : 0.;
442 
443  return EffWidthSigmaISIS;
444 }
int adc(sample_type sample)
get the ADC sample (12 bits)
const double Z[kNumberCalorimeter]
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_
edm::EDGetTokenT< EcalRecHitCollection > eeRHToken_
float SuperClusterSeedTime(const reco::SuperCluster &cluster)
float BasicClusterTime(const reco::BasicCluster &cluster, const edm::Event &ev)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
float SuperClusterTime(const reco::SuperCluster &cluster, const edm::Event &ev)
const EcalRecHitCollection * getEcalRecHitCollection(const reco::BasicCluster &cluster)
float getESShape(const std::vector< float > &ESHits0)
assert(m_qm.get())
std::vector< EcalRecHit >::const_iterator const_iterator
const EcalIntercalibConstantMap * icalMap
#define X(str)
Definition: MuonsGrabber.cc:48
void getADCToGeV(const edm::EventSetup &es)
bool ev
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:160
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:163
void setHome(const T &startingPoint)
set the starting position
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 west() const
move the navigator west
Definition: CaloNavigator.h:59
T sqrt(T t)
Definition: SSEVec.h:18
EcalClusterLazyToolsBase(const edm::Event &ev, const edm::EventSetup &es, edm::EDGetTokenT< EcalRecHitCollection > token1, edm::EDGetTokenT< EcalRecHitCollection > token2)
int j
Definition: DBlmapReader.cc:9
double x() const
x coordinate of cluster centroid
Definition: CaloCluster.h:154
T south() const
move the navigator south
Definition: CaloNavigator.h:45
void getESRecHits(const edm::Event &ev)
bool isValid() const
Definition: HandleBase.h:75
edm::EDGetTokenT< EcalRecHitCollection > esRHToken_
T east() const
move the navigator east
Definition: CaloNavigator.h:52
void home() const
move the navigator back to the starting point
Definition: DetId.h:18
float eseffsiyiy(const reco::SuperCluster &cluster)
T const * product() const
Definition: Handle.h:81
void getTopology(const edm::EventSetup &es)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const T & get() const
Definition: EventSetup.h:56
std::vector< Item >::const_iterator const_iterator
void getEBRecHits(const edm::Event &ev)
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< EcalRecHitCollection > ebRHToken_
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)
T north() const
move the navigator north
Definition: CaloNavigator.h:38
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:157
void getEERecHits(const edm::Event &ev)
std::map< DetId, EcalRecHit > rechits_map_
edm::ESHandle< EcalLaserDbService > laser
edm::Timestamp time() const
Definition: EventBase.h:60
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
const CaloTopology * topology_
float EcalIntercalibConstant
float eseffsirir(const reco::SuperCluster &cluster)