CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalHaloAlgo.cc
Go to the documentation of this file.
3 
4 /*
5  [class]: EcalHaloAlgo
6  [authors]: R. Remington, The University of Florida
7  [description]: See EcalHaloAlgo.h
8  [date]: October 15, 2009
9 */
10 
11 using namespace std;
12 using namespace reco;
13 using namespace edm;
14 
15 bool CompareTime(const EcalRecHit* x, const EcalRecHit* y){ return x->time() < y->time(); }
16 
18 {
19  RoundnessCut = 0 ;
20  AngleCut = 0 ;
21  EBRecHitEnergyThreshold = 0.;
22  EERecHitEnergyThreshold = 0.;
23  ESRecHitEnergyThreshold = 0.;
24  SumEnergyThreshold = 0.;
25  NHitsThreshold =0;
26 }
27 
29 {
30  EcalHaloData TheEcalHaloData;
31 
32  // Store energy sum of rechits as a function of iPhi (iphi goes from 1 to 72)
33  float SumE[361];
34  // Store number of rechits as a function of iPhi
35  int NumHits[361];
36  // Store minimum time of rechit as a function of iPhi
37  float MinTimeHits[361];
38  // Store maximum time of rechit as a function of iPhi
39  float MaxTimeHits[361];
40 
41  // initialize
42  for(int i = 0 ; i < 361 ; i++ )
43  {
44  SumE[i] = 0.;
45  NumHits[i] = 0 ;
46  MinTimeHits[i] = 9999.;
47  MaxTimeHits[i] = -9999.;
48  }
49 
50  // Loop over EB RecHits
51  for(EBRecHitCollection::const_iterator hit = TheEBRecHits->begin() ; hit != TheEBRecHits->end() ; hit++ )
52  {
53  // Arbitrary threshold to kill noise (needs to be optimized with data)
54  if (hit->energy() < EBRecHitEnergyThreshold ) continue;
55 
56  // Get Det Id of the rechit
57  DetId id = DetId(hit->id());
58  const CaloSubdetectorGeometry* TheSubGeometry = 0;
59  const CaloCellGeometry* cell = 0 ;
60 
61  // Get EB geometry
62  TheSubGeometry = TheCaloGeometry.getSubdetectorGeometry(DetId::Ecal, 1);
63  EBDetId EcalID(id.rawId());
64  if( TheSubGeometry )
65  cell = TheSubGeometry->getGeometry(id);
66 
67  if(cell)
68  {
69  // GlobalPoint globalpos = cell->getPosition();
70  // float r = TMath::Sqrt ( globalpos.y()*globalpos.y() + globalpos.x()*globalpos.x());
71  int iPhi = EcalID.iphi();
72 
73  if( iPhi < 361 ) // just to be safe
74  {
75  //iPhi = (iPhi-1)/5 +1; // convert ecal iphi to phiwedge iphi (e.g. there are 5 crystal per phi wedge, as in calotowers )
76  SumE[iPhi] += hit->energy();
77  NumHits[iPhi] ++;
78 
79  float time = hit->time();
80  MinTimeHits[iPhi] = time < MinTimeHits[iPhi] ? time : MinTimeHits[iPhi];
81  MaxTimeHits[iPhi] = time > MaxTimeHits[iPhi] ? time : MaxTimeHits[iPhi];
82  }
83  }
84  }
85 
86  //for( int iPhi = 1 ; iPhi < 73; iPhi++ )
87  for( int iPhi = 1 ; iPhi < 361; iPhi++ )
88  {
89  if( SumE[iPhi] >= SumEnergyThreshold && NumHits[iPhi] > NHitsThreshold )
90  {
91  // Build PhiWedge and store to EcalHaloData if energy or #hits pass thresholds
92  PhiWedge wedge(SumE[iPhi], iPhi, NumHits[iPhi], MinTimeHits[iPhi], MaxTimeHits[iPhi]);
93 
94  // Loop over rechits again to calculate direction based on timing info
95 
96  // Loop over EB RecHits
97  std::vector<const EcalRecHit*> Hits;
98  for(EBRecHitCollection::const_iterator hit = TheEBRecHits->begin() ; hit != TheEBRecHits->end() ; hit++ )
99  {
100  if (hit->energy() < EBRecHitEnergyThreshold ) continue;
101 
102  // Get Det Id of the rechit
103  DetId id = DetId(hit->id());
104  EBDetId EcalID(id.rawId());
105  int Hit_iPhi = EcalID.iphi();
106  //Hit_iPhi = (Hit_iPhi-1)/5 +1; // convert ecal iphi to phiwedge iphi
107  if( Hit_iPhi != iPhi ) continue;
108  Hits.push_back( &(*hit) );
109 
110  }
111  std::sort( Hits.begin() , Hits.end(), CompareTime);
112  float MinusToPlus = 0.;
113  float PlusToMinus = 0.;
114  for( unsigned int i = 0 ; i < Hits.size() ; i++ )
115  {
116  DetId id_i = DetId(Hits[i]->id());
117  EBDetId EcalID_i(id_i.rawId());
118  int ieta_i = EcalID_i.ieta();
119  for( unsigned int j = (i+1) ; j < Hits.size() ; j++ )
120  {
121  DetId id_j = DetId(Hits[j]->id() );
122  EBDetId EcalID_j(id_j.rawId());
123  int ieta_j = EcalID_j.ieta();
124  if( ieta_i > ieta_j ) PlusToMinus += TMath::Abs(ieta_j - ieta_i );
125  else MinusToPlus += TMath::Abs(ieta_j -ieta_i) ;
126  }
127  }
128 
129  float PlusZOriginConfidence = (PlusToMinus+MinusToPlus) ? PlusToMinus / (PlusToMinus+MinusToPlus) : -1.;
130  wedge.SetPlusZOriginConfidence(PlusZOriginConfidence);
131  TheEcalHaloData.GetPhiWedges().push_back(wedge);
132  }
133  }
134 
135  std::vector<float> vShowerShapes_Roundness;
136  std::vector<float> vShowerShapes_Angle ;
137  for(reco::SuperClusterCollection::const_iterator cluster = TheSuperClusters->begin() ; cluster != TheSuperClusters->end() ; cluster++ )
138  {
139  if( abs(cluster->eta()) <= 1.48 )
140  {
141  vector<float> shapes = EcalClusterTools::roundnessBarrelSuperClusters( *cluster, (*TheEBRecHits.product()));
142  float roundness = shapes[0];
143  float angle = shapes[1];
144 
145  // Check if supercluster belongs to photon and passes the cuts on roundness and angle, if so store the reference to it
146  if( (roundness >=0 && roundness < GetRoundnessCut()) && angle >= 0 && angle < GetAngleCut() )
147  {
148  edm::Ref<SuperClusterCollection> TheClusterRef( TheSuperClusters, cluster - TheSuperClusters->begin());
149  bool BelongsToPhoton = false;
150  if( ThePhotons.isValid() )
151  {
152  for(reco::PhotonCollection::const_iterator iPhoton = ThePhotons->begin() ; iPhoton != ThePhotons->end() ; iPhoton++ )
153  {
154  if(iPhoton->isEB())
155  if ( TheClusterRef == iPhoton->superCluster() )
156  {
157  BelongsToPhoton = true;
158  break;
159  }
160  }
161  }
162  //Only store refs to suspicious EB SuperClusters which belong to Photons
163  //Showershape variables are more discriminating for these cases
164  if( BelongsToPhoton )
165  {
166  TheEcalHaloData.GetSuperClusters().push_back( TheClusterRef ) ;
167  }
168  }
169  vShowerShapes_Roundness.push_back(shapes[0]);
170  vShowerShapes_Angle.push_back(shapes[1]);
171  }
172  else
173  {
174  vShowerShapes_Roundness.push_back(-1.);
175  vShowerShapes_Angle.push_back(-1.);
176  }
177  }
178 
179  edm::ValueMap<float>::Filler TheRoundnessFiller( TheEcalHaloData.GetShowerShapesRoundness() );
180  TheRoundnessFiller.insert( TheSuperClusters, vShowerShapes_Roundness.begin(), vShowerShapes_Roundness.end() );
181  TheRoundnessFiller.fill();
182 
183  edm::ValueMap<float>::Filler TheAngleFiller( TheEcalHaloData.GetShowerShapesAngle() );
184  TheAngleFiller.insert( TheSuperClusters, vShowerShapes_Angle.begin() , vShowerShapes_Angle.end() );
185  TheAngleFiller.fill();
186 
187  return TheEcalHaloData;
188 }
189 
190 
191 
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
edm::ValueMap< float > & GetShowerShapesRoundness()
Definition: EcalHaloData.h:41
const std::vector< PhiWedge > & GetPhiWedges() const
Definition: EcalHaloData.h:32
reco::EcalHaloData Calculate(const CaloGeometry &TheCaloGeometry, edm::Handle< reco::PhotonCollection > &ThePhotons, edm::Handle< reco::SuperClusterCollection > &TheSuperClusters, edm::Handle< EBRecHitCollection > &TheEBRecHits, edm::Handle< EERecHitCollection > &TheEERecHits, edm::Handle< ESRecHitCollection > &TheESRecHits)
Definition: EcalHaloAlgo.cc:28
edm::RefVector< reco::SuperClusterCollection > & GetSuperClusters()
Definition: EcalHaloData.h:36
edm::ValueMap< float > & GetShowerShapesAngle()
Definition: EcalHaloData.h:44
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< EcalRecHit >::const_iterator const_iterator
float time() const
Definition: EcalRecHit.h:70
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
T Abs(T a)
Definition: MathUtil.h:49
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
void SetPlusZOriginConfidence(float x)
Definition: PhiWedge.h:67
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
bool isValid() const
Definition: HandleBase.h:75
unsigned int id
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
bool CompareTime(const EcalRecHit *x, const EcalRecHit *y)
Definition: EcalHaloAlgo.cc:15
Definition: DDAxes.h:10
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11