CMS 3D CMS Logo

EcalEndcapSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalEndcapSimHitsValidation.cc
3  *
4  * \author C.Rovelli
5  *
6 */
7 
12 
13 using namespace cms;
14 using namespace edm;
15 using namespace std;
16 
18  g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
19  EEHitsCollection(ps.getParameter<std::string>("EEHitsCollection")),
20  ValidationCollection(ps.getParameter<std::string>("ValidationCollection")){
21 
22  EEHitsToken = consumes <edm::PCaloHitContainer> (edm::InputTag(std::string(g4InfoLabel),std::string(EEHitsCollection)));
24  // verbosity switch
25  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
26 
27  // get hold of back-end interface
28  dbe_ = 0;
29  dbe_ = edm::Service<DQMStore>().operator->();
30  if ( dbe_ ) {
31  if ( verbose_ ) { dbe_->setVerbose(1); }
32  else { dbe_->setVerbose(0); }
33  }
34 
35  if ( dbe_ ) {
36  if ( verbose_ ) dbe_->showDirStructure();
37  }
38 
39 
40  meEEzpHits_ = 0;
41  meEEzmHits_ = 0;
42  meEEzpCrystals_ = 0;
43  meEEzmCrystals_ = 0;
44  meEEzpOccupancy_ = 0;
45  meEEzmOccupancy_ = 0;
47  meEEHitEnergy_ = 0;
51  meEEHitEnergy2_ = 0;
54 
55  meEEe1_ = 0;
56  meEEe4_ = 0;
57  meEEe9_ = 0;
58  meEEe16_ = 0;
59  meEEe25_ = 0;
60 
61  meEEe1oe4_ = 0;
62  meEEe1oe9_ = 0;
63  meEEe4oe9_ = 0;
64  meEEe9oe16_ = 0;
65  meEEe1oe25_ = 0;
66  meEEe9oe25_ = 0;
67  meEEe16oe25_ = 0;
68 
69  myEntries = 0;
70  for ( int myStep = 0; myStep<26; myStep++) { eRLength[myStep] = 0.0; }
71 
72  Char_t histo[200];
73 
74  if ( dbe_ ) {
75  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
76 
77  sprintf (histo, "EE+ hits multiplicity" ) ;
78  meEEzpHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.) ;
79 
80  sprintf (histo, "EE- hits multiplicity" ) ;
81  meEEzmHits_ = dbe_->book1D(histo, histo, 50, 0., 5000.) ;
82 
83  sprintf (histo, "EE+ crystals multiplicity" ) ;
84  meEEzpCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.) ;
85 
86  sprintf (histo, "EE- crystals multiplicity" ) ;
87  meEEzmCrystals_ = dbe_->book1D(histo, histo, 200, 0., 2000.) ;
88 
89  sprintf (histo, "EE+ occupancy" ) ;
90  meEEzpOccupancy_ = dbe_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
91 
92  sprintf (histo, "EE- occupancy" ) ;
93  meEEzmOccupancy_ = dbe_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
94 
95  sprintf (histo, "EE longitudinal shower profile" ) ;
96  meEELongitudinalShower_ = dbe_->bookProfile(histo, histo, 26,0,26, 100, 0, 20000);
97 
98  sprintf (histo, "EE hits energy spectrum" );
99  meEEHitEnergy_ = dbe_->book1D(histo, histo, 4000, 0., 400.);
100 
101  sprintf (histo, "EE hits log10energy spectrum" );
102  meEEhitLog10Energy_ = dbe_->book1D(histo, histo, 140, -10., 4.);
103 
104  sprintf (histo, "EE hits log10energy spectrum vs normalized energy" );
105  meEEhitLog10EnergyNorm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
106 
107  sprintf (histo, "EE hits log10energy spectrum vs normalized energy25" );
108  meEEhitLog10Energy25Norm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
109 
110  sprintf (histo, "EE hits energy spectrum 2" );
111  meEEHitEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
112 
113  sprintf (histo, "EE crystal energy spectrum" );
114  meEEcrystalEnergy_ = dbe_->book1D(histo, histo, 5000, 0., 50.);
115 
116  sprintf (histo, "EE crystal energy spectrum 2" );
117  meEEcrystalEnergy2_ = dbe_->book1D(histo, histo, 1000, 0., 0.001);
118 
119  sprintf (histo, "EE E1" ) ;
120  meEEe1_ = dbe_->book1D(histo, histo, 400, 0., 400.);
121 
122  sprintf (histo, "EE E4" ) ;
123  meEEe4_ = dbe_->book1D(histo, histo, 400, 0., 400.);
124 
125  sprintf (histo, "EE E9" ) ;
126  meEEe9_ = dbe_->book1D(histo, histo, 400, 0., 400.);
127 
128  sprintf (histo, "EE E16" ) ;
129  meEEe16_ = dbe_->book1D(histo, histo, 400, 0., 400.);
130 
131  sprintf (histo, "EE E25" ) ;
132  meEEe25_ = dbe_->book1D(histo, histo, 400, 0., 400.);
133 
134  sprintf (histo, "EE E1oE4" ) ;
135  meEEe1oe4_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
136 
137  sprintf (histo, "EE E1oE9" ) ;
138  meEEe1oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
139 
140  sprintf (histo, "EE E4oE9" ) ;
141  meEEe4oe9_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
142 
143  sprintf (histo, "EE E9oE16" ) ;
144  meEEe9oe16_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
145 
146  sprintf (histo, "EE E1oE25" ) ;
147  meEEe1oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
148 
149  sprintf (histo, "EE E9oE25" ) ;
150  meEEe9oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
151 
152  sprintf (histo, "EE E16oE25" ) ;
153  meEEe16oe25_ = dbe_->book1D(histo, histo, 100, 0.4, 1.1);
154  }
155 }
156 
158 
159 }
160 
162 
163 }
164 
166 
167  //for ( int myStep = 0; myStep<26; myStep++){
168  // if (meEELongitudinalShower_) meEELongitudinalShower_->Fill(float(myStep), eRLength[myStep]/myEntries);
169  //}
170 
171 }
172 
174 
175  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
176 
178  e.getByToken(EEHitsToken,EcalHitsEE);
179 
180  // Do nothing if no EndCap data available
181  if( ! EcalHitsEE.isValid() ) return;
182 
183  edm::Handle<PEcalValidInfo> MyPEcalValidInfo;
184  e.getByToken(ValidationCollectionToken,MyPEcalValidInfo);
185 
186  std::vector<PCaloHit> theEECaloHits;
187  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
188 
189  myEntries++;
190 
191  std::map<unsigned int, std::vector<PCaloHit*>,std::less<unsigned int> > CaloHitMap;
192 
193  double EEetzp_ = 0.;
194  double EEetzm_ = 0.;
195 
196  double ee1 = 0.0;
197  double ee4 = 0.0;
198  double ee9 = 0.0;
199  double ee16 = 0.0;
200  double ee25 = 0.0;
201  std::vector<double> econtr(140, 0. );
202  std::vector<double> econtr25(140, 0. );
203 
204  MapType eemap;
205  MapType eemapzp;
206  MapType eemapzm;
207  uint32_t nEEzpHits = 0;
208  uint32_t nEEzmHits = 0;
209 
210  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin();
211  isim != theEECaloHits.end(); ++isim){
212 
213  if ( isim->time() > 500. ) { continue; }
214 
215  CaloHitMap[ isim->id()].push_back(&(*isim));
216 
217  EEDetId eeid (isim->id()) ;
218 
219  LogDebug("HitInfo")
220  << " CaloHit " << isim->getName() << "\n"
221  << " DetID = "<<isim->id()<< " EEDetId = " << eeid.ix() << " " << eeid.iy() << "\n"
222  << " Time = " << isim->time() << "\n"
223  << " Track Id = " << isim->geantTrackId() << "\n"
224  << " Energy = " << isim->energy();
225 
226  uint32_t crystid = eeid.rawId();
227 
228  if (eeid.zside() > 0 ) {
229  nEEzpHits++;
230  EEetzp_ += isim->energy();
231  eemapzp[crystid] += isim->energy();
232  if (meEEzpOccupancy_) meEEzpOccupancy_->Fill(eeid.ix(), eeid.iy());
233  }
234  else if (eeid.zside() < 0 ) {
235  nEEzmHits++;
236  EEetzm_ += isim->energy();
237  eemapzm[crystid] += isim->energy();
238  if (meEEzmOccupancy_) meEEzmOccupancy_->Fill(eeid.ix(), eeid.iy());
239  }
240 
241  if (meEEHitEnergy_) meEEHitEnergy_->Fill(isim->energy());
242  if( isim->energy() > 0 ) {
243  if( meEEhitLog10Energy_ ) meEEhitLog10Energy_->Fill(log10(isim->energy()));
244  int log10i = int( ( log10(isim->energy()) + 10. ) * 10. );
245  if( log10i >=0 && log10i < 140 ) econtr[log10i] += isim->energy();
246  }
247  if (meEEHitEnergy2_) meEEHitEnergy2_->Fill(isim->energy());
248  eemap[crystid] += isim->energy();
249 
250 
251  }
252 
253  if (meEEzpCrystals_) meEEzpCrystals_->Fill(eemapzp.size());
254  if (meEEzmCrystals_) meEEzmCrystals_->Fill(eemapzm.size());
255 
256  if (meEEcrystalEnergy_) {
257  for (std::map<uint32_t,float,std::less<uint32_t> >::iterator it = eemap.begin(); it != eemap.end(); ++it ) meEEcrystalEnergy_->Fill((*it).second);
258  }
259  if (meEEcrystalEnergy2_) {
260  for (std::map<uint32_t,float,std::less<uint32_t> >::iterator it = eemap.begin(); it != eemap.end(); ++it ) meEEcrystalEnergy2_->Fill((*it).second);
261  }
262 
263  if (meEEzpHits_) meEEzpHits_->Fill(nEEzpHits);
264  if (meEEzmHits_) meEEzmHits_->Fill(nEEzmHits);
265 
266 
267  int nEEHits = nEEzmHits + nEEzpHits;
268  if (nEEHits > 0) {
269 
270  uint32_t eecenterid = getUnitWithMaxEnergy(eemap);
271  EEDetId myEEid(eecenterid);
272  int bx = myEEid.ix();
273  int by = myEEid.iy();
274  int bz = myEEid.zside();
275  ee1 = energyInMatrixEE(1,1,bx,by,bz,eemap);
276  if (meEEe1_) meEEe1_->Fill(ee1);
277  ee9 = energyInMatrixEE(3,3,bx,by,bz,eemap);
278  if (meEEe9_) meEEe9_->Fill(ee9);
279  ee25= energyInMatrixEE(5,5,bx,by,bz,eemap);
280  if (meEEe25_) meEEe25_->Fill(ee25);
281 
282  std::vector<uint32_t> ids25; ids25 = getIdsAroundMax(5,5,bx,by,bz,eemap);
283 
284  for( unsigned i=0; i<25; i++ ) {
285  for( unsigned int j=0; j<CaloHitMap[ids25[i]].size(); j++ ) {
286  if( CaloHitMap[ids25[i]][j]->energy() > 0 ) {
287  int log10i = int( ( log10( CaloHitMap[ids25[i]][j]->energy()) + 10. ) * 10. );
288  if( log10i >=0 && log10i < 140 ) econtr25[log10i] += CaloHitMap[ids25[i]][j]->energy();
289  }
290  }
291  }
292 
293  MapType neweemap;
294  if( fillEEMatrix(3,3,bx,by,bz,neweemap, eemap)){
295  ee4 = eCluster2x2(neweemap);
296  if (meEEe4_) meEEe4_->Fill(ee4);
297  }
298  if( fillEEMatrix(5,5,bx,by,bz,neweemap, eemap)){
299  ee16 = eCluster4x4(ee9,neweemap);
300  if (meEEe16_) meEEe16_->Fill(ee16);
301  }
302 
303  if (meEEe1oe4_ && ee4 > 0.1 ) meEEe1oe4_ ->Fill(ee1/ee4);
304  if (meEEe1oe9_ && ee9 > 0.1 ) meEEe1oe9_ ->Fill(ee1/ee9);
305  if (meEEe4oe9_ && ee9 > 0.1 ) meEEe4oe9_ ->Fill(ee4/ee9);
306  if (meEEe9oe16_ && ee16 > 0.1 ) meEEe9oe16_ ->Fill(ee9/ee16);
307  if (meEEe16oe25_ && ee25 > 0.1 ) meEEe16oe25_->Fill(ee16/ee25);
308  if (meEEe1oe25_ && ee25 > 0.1 ) meEEe1oe25_ ->Fill(ee1/ee25);
309  if (meEEe9oe25_ && ee25 > 0.1 ) meEEe9oe25_ ->Fill(ee9/ee25);
310 
311  if( meEEhitLog10EnergyNorm_ && (EEetzp_+EEetzm_) != 0 ) {
312  for( int i=0; i<140; i++ ) {
313  meEEhitLog10EnergyNorm_->Fill( -10.+(float(i)+0.5)/10., econtr[i]/(EEetzp_+EEetzm_) );
314  }
315  }
316 
317  if( meEEhitLog10Energy25Norm_ && ee25 != 0 ) {
318  for( int i=0; i<140; i++ ) {
319  meEEhitLog10Energy25Norm_->Fill( -10.+(float(i)+0.5)/10., econtr25[i]/ee25 );
320  }
321  }
322 
323  }
324 
325  if( MyPEcalValidInfo.isValid() ) {
326  if ( MyPEcalValidInfo->ee1x1() > 0. ) {
327  std::vector<float> EX0 = MyPEcalValidInfo->eX0();
329  for (int myStep=0; myStep< 26; myStep++ ) {
330  eRLength[myStep] += EX0[myStep];
332  }
333  }
334  }
335 }
336 
337 float EcalEndcapSimHitsValidation::energyInMatrixEE(int nCellInX, int nCellInY,
338  int centralX, int centralY,
339  int centralZ, MapType& themap){
340 
341  int ncristals = 0;
342  float totalEnergy = 0.;
343 
344  int goBackInX = nCellInX/2;
345  int goBackInY = nCellInY/2;
346  int startX = centralX-goBackInX;
347  int startY = centralY-goBackInY;
348 
349  for (int ix=startX; ix<startX+nCellInX; ix++) {
350  for (int iy=startY; iy<startY+nCellInY; iy++) {
351  uint32_t index ;
352 
353  if(EEDetId::validDetId(ix,iy,centralZ)) {
354  index = EEDetId(ix,iy,centralZ).rawId();
355  }
356  else { continue; }
357 
358  totalEnergy += themap[index];
359  ncristals += 1;
360  }
361  }
362 
363  LogDebug("GeomInfo")
364  << nCellInX << " x " << nCellInY
365  << " EE matrix energy = " << totalEnergy
366  << " for " << ncristals << " crystals";
367  return totalEnergy;
368 
369 }
370 
371 std::vector<uint32_t> EcalEndcapSimHitsValidation::getIdsAroundMax( int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType& themap){
372 
373  int ncristals = 0;
374  std::vector<uint32_t> ids( nCellInX*nCellInY );
375 
376  int goBackInX = nCellInX/2;
377  int goBackInY = nCellInY/2;
378  int startX = centralX-goBackInX;
379  int startY = centralY-goBackInY;
380 
381  for (int ix=startX; ix<startX+nCellInX; ix++) {
382  for (int iy=startY; iy<startY+nCellInY; iy++) {
383  uint32_t index ;
384 
385  if(EEDetId::validDetId(ix,iy,centralZ)) {
386  index = EEDetId(ix,iy,centralZ).rawId();
387  }
388  else { continue; }
389 
390  ids[ncristals] = index;
391  ncristals += 1;
392  }
393  }
394 
395  return ids;
396 }
397 
398 bool EcalEndcapSimHitsValidation::fillEEMatrix(int nCellInX, int nCellInY,
399  int CentralX, int CentralY,int CentralZ,
400  MapType& fillmap, MapType& themap)
401 {
402  int goBackInX = nCellInX/2;
403  int goBackInY = nCellInY/2;
404 
405  int startX = CentralX - goBackInX;
406  int startY = CentralY - goBackInY;
407 
408  int i = 0 ;
409  for ( int ix = startX; ix < startX+nCellInX; ix ++ ) {
410 
411  for( int iy = startY; iy < startY + nCellInY; iy++ ) {
412 
413  uint32_t index ;
414 
415  if(EEDetId::validDetId(ix,iy,CentralZ)) {
416  index = EEDetId(ix,iy,CentralZ).rawId();
417  }
418  else { continue; }
419  fillmap[i++] = themap[index];
420  }
421  }
422  uint32_t centerid = getUnitWithMaxEnergy(themap);
423 
424  if ( fillmap[i/2] == themap[centerid] )
425  return true;
426  else
427  return false;
428 }
429 
430 
432  float E22=0.;
433  float e012 = themap[0]+themap[1]+themap[2];
434  float e036 = themap[0]+themap[3]+themap[6];
435  float e678 = themap[6]+themap[7]+themap[8];
436  float e258 = themap[2]+themap[5]+themap[8];
437 
438  if ( (e012>e678 || e012==e678) && (e036>e258 || e036==e258))
439  return E22=themap[0]+themap[1]+themap[3]+themap[4];
440  else if ( (e012>e678 || e012==e678) && (e036<e258 || e036==e258) )
441  return E22=themap[1]+themap[2]+themap[4]+themap[5];
442  else if ( (e012<e678 || e012==e678) && (e036>e258 || e036==e258))
443  return E22=themap[3]+themap[4]+themap[6]+themap[7];
444  else if ( (e012<e678|| e012==e678) && (e036<e258|| e036==e258) )
445  return E22=themap[4]+themap[5]+themap[7]+themap[8];
446  else {
447  return E22;
448  }
449 }
450 
452  float E44=0.;
453  float e0_4 = themap[0]+themap[1]+themap[2]+themap[3]+themap[4];
454  float e0_20 = themap[0]+themap[5]+themap[10]+themap[15]+themap[20];
455  float e4_24 = themap[4]+themap[9]+themap[14]+themap[19]+themap[24];
456  float e0_24 = themap[20]+themap[21]+themap[22]+themap[23]+themap[24];
457 
458  if ((e0_4>e0_24 || e0_4==e0_24) && (e0_20>e4_24|| e0_20==e4_24))
459  return E44=e33+themap[0]+themap[1]+themap[2]+themap[3]+themap[5]+themap[10]+themap[15];
460  else if ((e0_4>e0_24 || e0_4==e0_24) && (e0_20<e4_24 || e0_20==e4_24))
461  return E44=e33+themap[1]+themap[2]+themap[3]+themap[4]+themap[9]+themap[14]+themap[19];
462  else if ((e0_4<e0_24|| e0_4==e0_24) && (e0_20>e4_24 || e0_20==e4_24))
463  return E44=e33+themap[5]+themap[10]+themap[15]+themap[20]+themap[21]+themap[22]+themap[23];
464  else if ((e0_4<e0_24|| e0_4==e0_24) && (e0_20<e4_24 || e0_20==e4_24))
465  return E44=e33+themap[21]+themap[22]+themap[23]+themap[24]+themap[9]+themap[14]+themap[19];
466  else{
467  return E44;
468  }
469 }
470 
472 
473  //look for max
474  uint32_t unitWithMaxEnergy = 0;
475  float maxEnergy = 0.;
476 
477  MapType::iterator iter;
478  for (iter = themap.begin(); iter != themap.end(); iter++) {
479 
480  if (maxEnergy < (*iter).second) {
481  maxEnergy = (*iter).second;
482  unitWithMaxEnergy = (*iter).first;
483  }
484  }
485 
486  LogDebug("GeomInfo")
487  << " max energy of " << maxEnergy
488  << " GeV in Unit id " << unitWithMaxEnergy;
489  return unitWithMaxEnergy;
490 }
491 
492 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int ix() const
Definition: EEDetId.h:76
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
edm::EDGetTokenT< PEcalValidInfo > ValidationCollectionToken
virtual float energyInMatrixEE(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
float eCluster4x4(float e33, MapType &themap)
int zside() const
Definition: EEDetId.h:70
int iy() const
Definition: EEDetId.h:82
bool isValid() const
Definition: HandleBase.h:74
bool fillEEMatrix(int nCellInX, int nCellInY, int CentralX, int CentralY, int CentralZ, MapType &fillmap, MapType &themap)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsToken
edm::EventID id() const
Definition: EventBase.h:60
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
HLT enums.
uint32_t getUnitWithMaxEnergy(MapType &themap)
FloatVector eX0() const
std::map< uint32_t, float, std::less< uint32_t > > MapType
float ee1x1() const
void Reset(void)
reset ME (ie. contents, errors, etc)
std::vector< uint32_t > getIdsAroundMax(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
EcalEndcapSimHitsValidation(const edm::ParameterSet &ps)
Constructor.