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