CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalHaloAlgo.cc
Go to the documentation of this file.
2 
3 /*
4  [class]: HcalHaloAlgo
5  [authors]: R. Remington, The University of Florida
6  [description]: See HcalHaloAlgo.h
7  [date]: October 15, 2009
8 */
9 
10 using namespace std;
11 using namespace edm;
12 using namespace reco;
13 
14 #include <iomanip>
15 bool CompareTime(const HBHERecHit* x, const HBHERecHit* y ){ return x->time() < y->time() ;}
16 bool CompareTowers(const CaloTower* x, const CaloTower* y ){
17  return x->iphi()*1000 + x->ieta() < y->iphi()*1000 + y->ieta();
18 }
19 
21 {
22  HBRecHitEnergyThreshold = 0.;
23  HERecHitEnergyThreshold = 0.;
24  SumEnergyThreshold = 0.;
25  NHitsThreshold = 0;
26 }
27 
30  return Calculate(TheCaloGeometry, TheHBHERecHits, TheCaloTowers);
31 }
32 
34 {
35  HcalHaloData TheHcalHaloData;
36 
37  // Store Energy sum of rechits as a function of iPhi (iPhi goes from 1 to 72)
38  float SumE[73];
39  // Store Number of rechits as a function of iPhi
40  int NumHits[73];
41  // Store minimum time of rechit as a function of iPhi
42  float MinTimeHits[73];
43  // Store maximum time of rechit as a function of iPhi
44  float MaxTimeHits[73];
45  for(unsigned int i = 0 ; i < 73 ; i++ )
46  {
47  SumE[i] = 0;
48  NumHits[i]= 0;
49  MinTimeHits[i] = 0.;
50  MaxTimeHits[i] = 0.;
51  }
52 
53  for( HBHERecHitCollection::const_iterator hit = TheHBHERecHits->begin() ; hit != TheHBHERecHits->end() ; hit++ )
54  {
55  HcalDetId id = HcalDetId(hit->id());
56  switch ( id.subdet() )
57  {
58  case HcalBarrel:
59  if(hit->energy() < HBRecHitEnergyThreshold )continue;
60  break;
61  case HcalEndcap:
62  if(hit->energy() < HERecHitEnergyThreshold ) continue;
63  break;
64  default:
65  continue;
66  }
67 
68  int iEta = id.ieta();
69  int iPhi = id.iphi();
70  if(iPhi < 73 && TMath::Abs(iEta) < 23 )
71  {
72  SumE[iPhi]+= hit->energy();
73  NumHits[iPhi] ++;
74 
75  float time = hit->time();
76  MinTimeHits[iPhi] = time < MinTimeHits[iPhi] ? time : MinTimeHits[iPhi];
77  MaxTimeHits[iPhi] = time > MaxTimeHits[iPhi] ? time : MaxTimeHits[iPhi];
78  }
79  }
80 
81  for( int iPhi = 1 ; iPhi < 73 ; iPhi++ )
82  {
83  if( SumE[iPhi] >= SumEnergyThreshold && NumHits[iPhi] > NHitsThreshold )
84  {
85  // Build PhiWedge and store to HcalHaloData if energy or #hits pass thresholds
86  PhiWedge wedge(SumE[iPhi], iPhi, NumHits[iPhi], MinTimeHits[iPhi], MaxTimeHits[iPhi]);
87 
88  // Loop over rechits again to calculate direction based on timing info
89  std::vector<const HBHERecHit*> Hits;
90  for( HBHERecHitCollection::const_iterator hit = TheHBHERecHits->begin() ; hit != TheHBHERecHits->end() ; hit++ )
91  {
92 
93  HcalDetId id = HcalDetId(hit->id());
94  if( id.iphi() != iPhi ) continue;
95  if( TMath::Abs(id.ieta() ) > 22 ) continue; // has to overlap geometrically w/ HB
96  switch ( id.subdet() )
97  {
98  case HcalBarrel:
99  if(hit->energy() < HBRecHitEnergyThreshold )continue;
100  break;
101  case HcalEndcap:
102  if(hit->energy() < HERecHitEnergyThreshold ) continue;
103  break;
104  default:
105  continue;
106  }
107  Hits.push_back(&(*hit));
108  }
109 
110  std::sort( Hits.begin() , Hits.end() , CompareTime);
111  float MinusToPlus = 0.;
112  float PlusToMinus = 0.;
113  for( unsigned int i = 0 ; i < Hits.size() ; i++ )
114  {
115  HcalDetId id_i = HcalDetId(Hits[i]->id() );
116  int ieta_i = id_i.ieta();
117  for( unsigned int j = (i+1) ; j < Hits.size() ; j++ )
118  {
119  HcalDetId id_j = HcalDetId(Hits[j]->id() );
120  int ieta_j = id_j.ieta();
121  if( ieta_i > ieta_j ) PlusToMinus += TMath::Abs(ieta_i - ieta_j ) ;
122  else MinusToPlus += TMath::Abs(ieta_i - ieta_j);
123  }
124  }
125  float PlusZOriginConfidence = (PlusToMinus + MinusToPlus )? PlusToMinus / ( PlusToMinus + MinusToPlus ) : -1. ;
126  wedge.SetPlusZOriginConfidence( PlusZOriginConfidence );
127  TheHcalHaloData.GetPhiWedges().push_back( wedge );
128  }
129  }
130 
131  // Don't use HF.
132  int maxAbsIEta = 29;
133  std::vector<const CaloTower*> sortedCaloTowers;
134  for(CaloTowerCollection::const_iterator tower = TheCaloTowers->begin(); tower != TheCaloTowers->end(); tower++) {
135  if(abs(tower->ieta()) <= maxAbsIEta && tower->numProblematicHcalCells() > 0)
136  sortedCaloTowers.push_back(&(*tower));
137  }
138 
139  // Sort towers such that lowest iphi and ieta are first, highest last, and towers
140  // with same iphi value are consecutive. Then we can do everything else in one loop.
141  std::sort(sortedCaloTowers.begin(), sortedCaloTowers.end(), CompareTowers);
142 
143  HaloTowerStrip strip;
144 
145  int prevIEta = -99, prevIPhi = -99;
146  float prevHadEt = 0.;
147  std::pair<uint8_t, CaloTowerDetId> prevPair, towerPair;
148  bool wasContiguous = true;
149  // Loop through and store a vector of pairs (problematicCells, DetId) for each contiguous strip we find
150  for(unsigned int i = 0; i < sortedCaloTowers.size(); i++) {
151  const CaloTower* tower = sortedCaloTowers[i];
152 
153  towerPair = std::make_pair((uint8_t)tower->numProblematicHcalCells(), tower->id());
154 
155  bool newIPhi = tower->iphi() != prevIPhi;
156  bool isContiguous = tower->ieta() == 1 ? tower->ieta() - 2 == prevIEta : tower->ieta() - 1 == prevIEta;
157 
158  isContiguous = isContiguous || (tower->ieta() == -maxAbsIEta);
159  if(newIPhi) isContiguous = false;
160 
161  if(!wasContiguous && isContiguous) {
162  strip.cellTowerIds.push_back(prevPair);
163  strip.cellTowerIds.push_back(towerPair);
164  strip.hadEt += prevHadEt + tower->hadEt();
165  }
166 
167  if(wasContiguous && isContiguous) {
168  strip.cellTowerIds.push_back(towerPair);
169  strip.hadEt += tower->hadEt();
170  }
171 
172  if((wasContiguous && !isContiguous) || i == sortedCaloTowers.size()-1) { //ended the strip, so flush it
173  if(strip.cellTowerIds.size() > 2) {
174  TheHcalHaloData.getProblematicStrips().push_back( strip );
175  }
176  strip = HaloTowerStrip();
177  }
178 
179  wasContiguous = isContiguous;
180  prevPair = towerPair;
181  prevIPhi = tower->iphi();
182  prevIEta = tower->ieta();
183  prevHadEt = tower->hadEt();
184  }
185 
186  return TheHcalHaloData;
187 
188 }
189 
190 
int i
Definition: DBlmapReader.cc:9
int ieta() const
Definition: CaloTower.h:184
double hadEt() const
Definition: CaloTower.h:115
std::vector< HBHERecHit >::const_iterator const_iterator
int iphi() const
Definition: CaloTower.h:186
float time() const
Definition: CaloRecHit.h:19
Helper class for the calculation of a top and a W boson mass estime.
Definition: TopDQMHelpers.h:67
T Abs(T a)
Definition: MathUtil.h:49
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
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
reco::HcalHaloData Calculate(const CaloGeometry &TheCaloGeometry, edm::Handle< HBHERecHitCollection > &TheHBHERecHits, edm::Handle< CaloTowerCollection > &TheCaloTowers)
Definition: HcalHaloAlgo.cc:33
unsigned int id
CaloTowerDetId id() const
Definition: CaloTower.h:102
unsigned int numProblematicHcalCells() const
Definition: CaloTower.h:201
bool CompareTowers(const CaloTower *x, const CaloTower *y)
Definition: HcalHaloAlgo.cc:16
const std::vector< HaloTowerStrip > & getProblematicStrips() const
Definition: HcalHaloData.h:44
bool CompareTime(const EcalRecHit *x, const EcalRecHit *y)
Definition: EcalHaloAlgo.cc:15
const std::vector< PhiWedge > & GetPhiWedges() const
Definition: HcalHaloData.h:40