CMS 3D CMS Logo

HFClusterAlgo.cc
Go to the documentation of this file.
1 #include "HFClusterAlgo.h"
2 #include <sstream>
3 #include <iostream>
4 #include <algorithm>
5 #include <list>
9 
10 using namespace std;
11 using namespace reco;
20  m_isMC = true; // safest
21 }
22 
24 public:
26  return h1.et > h2.et;
27  }
28 };
29 
31 public:
32  bool operator()(const double c1, const double c2) const { return c1 > c2; }
33 };
34 
35 static int indexByEta(HcalDetId id) { return (id.zside() > 0) ? (id.ietaAbs() - 29 + 13) : (41 - id.ietaAbs()); }
36 static const double MCMaterialCorrections_3XX[] = {1.000, 1.000, 1.105, 0.970, 0.965, 0.975, 0.956, 0.958, 0.981,
37  1.005, 0.986, 1.086, 1.000, 1.000, 1.086, 0.986, 1.005, 0.981,
38  0.958, 0.956, 0.975, 0.965, 0.970, 1.105, 1.000, 1.000};
39 
41  double seedThreshold,
42  double maximumSL,
43  double maximumRenergy,
44  bool usePMTflag,
45  bool usePulseflag,
46  bool forcePulseFlagMC,
47  int correctionSet) {
48  m_seedThreshold = seedThreshold;
49  m_minTowerEnergy = minTowerEnergy;
50  m_maximumSL = maximumSL;
51  m_usePMTFlag = usePMTflag;
52  m_usePulseFlag = usePulseflag;
53  m_forcePulseFlagMC = forcePulseFlagMC;
54  m_maximumRenergy = maximumRenergy;
55  m_correctionSet = correctionSet;
56 
57  for (int ii = 0; ii < 13; ii++) {
58  m_cutByEta.push_back(-1);
59  m_seedmnEta.push_back(99);
60  m_seedMXeta.push_back(-1);
61  }
62  for (int ii = 0; ii < 73; ii++) {
63  double minphi = 0.0872664 * (ii - 1);
64  double maxphi = 0.0872664 * (ii + 1);
65  while (minphi < -M_PI)
66  minphi += 2 * M_PI;
67  while (minphi > M_PI)
68  minphi -= 2 * M_PI;
69  while (maxphi < -M_PI)
70  maxphi += 2 * M_PI;
71  while (maxphi > M_PI)
72  maxphi -= 2 * M_PI;
73  if (ii == 37)
74  minphi = -3.1415904;
75  m_seedmnPhi.push_back(minphi);
76  m_seedMXphi.push_back(maxphi);
77  }
78 
79  // always set all the corrections to one...
80  for (int ii = 0; ii < 13 * 2; ii++)
81  m_correctionByEta.push_back(1.0);
82  if (m_correctionSet == 1) { // corrections for material from MC
83  for (int ii = 0; ii < 13 * 2; ii++)
84  m_correctionByEta[ii] = MCMaterialCorrections_3XX[ii];
85  }
86 }
87 
90  const CaloGeometry& geomO,
91  HFEMClusterShapeCollection& clusterShapes,
92  SuperClusterCollection& SuperClusters) {
93  const CaloGeometry* geom(&geomO);
94  std::vector<HFCompleteHit> protoseeds, seeds;
96  std::vector<HFCompleteHit>::iterator i;
97  std::vector<HFCompleteHit>::iterator k;
98  int dP, dE, PWrap;
99  bool isok = true;
100  HFEMClusterShape clusShp;
101 
102  SuperCluster Sclus;
103  bool doCluster = false;
104 
105  for (j = hf.begin(); j != hf.end(); j++) {
106  const int aieta = j->id().ietaAbs();
107  int iz = (aieta - 29);
108  // only long fibers and not 29,40,41 allowed to be considered as seeds
109  if (j->id().depth() != 1)
110  continue;
111  if (aieta == 40 || aieta == 41 || aieta == 29)
112  continue;
113 
114  if (iz < 0 || iz > 12) {
115  edm::LogWarning("HFClusterAlgo") << "Strange invalid HF hit: " << j->id();
116  continue;
117  }
118 
119  if (m_cutByEta[iz] < 0) {
120  double eta = geom->getPosition(j->id()).eta();
121  m_cutByEta[iz] = m_seedThreshold * cosh(eta); // convert ET to E for this ring
122  auto ccg = geom->getGeometry(j->id());
123  const CaloCellGeometry::CornersVec& CellCorners = ccg->getCorners();
124  for (size_t sc = 0; sc < CellCorners.size(); sc++) {
125  if (fabs(CellCorners[sc].z()) < 1200) {
126  if (fabs(CellCorners[sc].eta()) < m_seedmnEta[iz])
127  m_seedmnEta[iz] = fabs(CellCorners[sc].eta());
128  if (fabs(CellCorners[sc].eta()) > m_seedMXeta[iz])
129  m_seedMXeta[iz] = fabs(CellCorners[sc].eta());
130  }
131  }
132  }
133  double elong = j->energy() * m_correctionByEta[indexByEta(j->id())];
134  if (elong > m_cutByEta[iz]) {
135  j2 = hf.find(HcalDetId(HcalForward, j->id().ieta(), j->id().iphi(), 2));
136  double eshort = (j2 == hf.end()) ? (0) : (j2->energy());
137  if (j2 != hf.end())
138  eshort *= m_correctionByEta[indexByEta(j2->id())];
139  if (((elong - eshort) / (elong + eshort)) > m_maximumSL)
140  continue;
141  //if ((m_usePMTFlag)&&(j->flagField(4,1))) continue;
142  //if ((m_usePulseFlag)&&(j->flagField(1,1))) continue;
143  if (isPMTHit(*j))
144  continue;
145 
146  HFCompleteHit ahit;
147  double eta = geom->getPosition(j->id()).eta();
148  ahit.id = j->id();
149  ahit.energy = elong;
150  ahit.et = ahit.energy / cosh(eta);
151  protoseeds.push_back(ahit);
152  }
153  }
154 
155  if (!protoseeds.empty()) {
156  std::sort(protoseeds.begin(), protoseeds.end(), CompareHFCompleteHitET());
157  for (i = protoseeds.begin(); i != protoseeds.end(); i++) {
158  isok = true;
159  doCluster = false;
160 
161  if ((i == protoseeds.begin()) && (isok)) {
162  doCluster = true;
163  } else {
164  // check for overlap with existing clusters
165  for (k = seeds.begin(); isok && k != seeds.end(); k++) { //i->hits, k->seeds
166 
167  for (dE = -2; dE <= 2; dE++)
168  for (dP = -4; dP <= 4; dP += 2) {
169  PWrap = k->id.iphi() + dP;
170  if (PWrap < 0)
171  PWrap += 72;
172  if (PWrap > 72)
173  PWrap -= 72;
174 
175  if ((i->id.iphi() == PWrap) && (i->id.ieta() == k->id.ieta() + dE))
176  isok = false;
177  }
178  }
179  if (isok) {
180  doCluster = true;
181  }
182  }
183  if (doCluster) {
184  seeds.push_back(*i);
185 
186  bool clusterOk = makeCluster(i->id(), hf, geom, clusShp, Sclus);
187  if (clusterOk) { // cluster is _not_ ok if seed is rejected due to other cuts
188  clusterShapes.push_back(clusShp);
189  SuperClusters.push_back(Sclus);
190  }
191  }
192  } //end protoseed loop
193  } //end if seeCount
194 }
195 
197  const HFRecHitCollection& hf,
198  const CaloGeometry* geom,
199  HFEMClusterShape& clusShp,
200  SuperCluster& Sclus) {
201  double w = 0; //sum over all log E's
202  double wgt = 0;
203  double w_e = 0; //sum over ieat*energy
204  double w_x = 0;
205  double w_y = 0;
206  double w_z = 0;
207  double wp_e = 0; //sum over iphi*energy
208  double e_e = 0; //nonwieghted eta sum
209  double e_ep = 0; //nonweighted phi sum
210 
211  double l_3 = 0; //sum for enenergy in 3x3 long fibers etc.
212  double s_3 = 0;
213  double l_5 = 0;
214  double s_5 = 0;
215  double l_1 = 0;
216  double s_1 = 0;
217  int de, dp, phiWrap;
218  double l_1e = 0;
219  const GlobalPoint& sp = geom->getPosition(seedid);
220  std::vector<double> coreCanid;
221  std::vector<double>::const_iterator ci;
223  std::vector<DetId> usedHits;
224 
226  HcalDetId sid(HcalForward, seedid.ieta(), seedid.iphi(), 1);
227  si = hf.find(sid);
228 
229  bool clusterOk = true; // assume the best to start...
230 
231  // lots happens here
232  // edge type 1 has 40/41 in 3x3 and 5x5
233  bool edge_type1 = seedid.ietaAbs() == 39 && (seedid.iphi() % 4) == 3;
234 
235  double e_seed = si->energy() * m_correctionByEta[indexByEta(si->id())];
236 
237  for (de = -2; de <= 2; de++)
238  for (dp = -4; dp <= 4; dp += 2) {
239  phiWrap = seedid.iphi() + dp;
240  if (phiWrap < 0)
241  phiWrap += 72;
242  if (phiWrap > 72)
243  phiWrap -= 72;
244 
245  /* Handling of phi-width change problems */
246  if (edge_type1 && de == seedid.zside()) {
247  if (dp == -2) { // we want it in the 3x3
248  phiWrap -= 2;
249  if (phiWrap < 0)
250  phiWrap += 72;
251  } else if (dp == -4) {
252  continue; // but not double counted in 5x5
253  }
254  }
255 
256  HcalDetId idl(HcalForward, seedid.ieta() + de, phiWrap, 1);
257  HcalDetId ids(HcalForward, seedid.ieta() + de, phiWrap, 2);
258 
259  il = hf.find(idl);
260  is = hf.find(ids);
261 
262  double e_long = 1.0;
263  double e_short = 0.0;
264  if (il != hf.end())
265  e_long = il->energy() * m_correctionByEta[indexByEta(il->id())];
266  if (e_long <= m_minTowerEnergy)
267  e_long = 0.0;
268  if (is != hf.end())
269  e_short = is->energy() * m_correctionByEta[indexByEta(is->id())];
270  if (e_short <= m_minTowerEnergy)
271  e_short = 0.0;
272  double eRatio = (e_long - e_short) / std::max(1.0, (e_long + e_short));
273 
274  // require S/L > a minimum amount for inclusion
275  if ((abs(eRatio) > m_maximumSL) && (std::max(e_long, e_short) > m_maximumRenergy)) {
276  if (dp == 0 && de == 0)
277  clusterOk = false; // somehow, the seed is hosed
278  continue;
279  }
280 
281  if ((il != hf.end()) && (isPMTHit(*il))) {
282  if (dp == 0 && de == 0)
283  clusterOk = false; // somehow, the seed is hosed
284  continue; //continue to next hit, do not include this one in cluster
285  }
286 
287  if (e_long > m_minTowerEnergy && il != hf.end()) {
288  // record usage
289  usedHits.push_back(idl.rawId());
290  // always in the 5x5
291  l_5 += e_long;
292  // maybe in the 3x3
293  if ((de > -2) && (de < 2) && (dp > -4) && (dp < 4)) {
294  l_3 += e_long;
295 
296  // sometimes in the 1x1
297  if ((dp == 0) && (de == 0)) {
298  l_1 = e_long;
299  }
300 
301  // maybe in the core?
302  if ((de > -2) && (de < 2) && (dp > -4) && (dp < 4) && (e_long > (.5 * e_seed))) {
303  coreCanid.push_back(e_long);
304  }
305 
306  // position calculation
307  const GlobalPoint& p = geom->getPosition(idl);
308 
309  double d_p = p.phi() - sp.phi();
310  while (d_p < -M_PI)
311  d_p += 2 * M_PI;
312  while (d_p > M_PI)
313  d_p -= 2 * M_PI;
314  double d_e = p.eta() - sp.eta();
315 
316  wgt = log((e_long));
317  if (wgt > 0) {
318  w += wgt;
319  w_e += (d_e)*wgt;
320  wp_e += (d_p)*wgt;
321  e_e += d_e;
322  e_ep += d_p;
323 
324  w_x += (p.x()) * wgt; //(p.x()-sp.x())*wgt;
325  w_y += (p.y()) * wgt;
326  w_z += (p.z()) * wgt;
327  }
328  }
329  } else {
330  if (dp == 0 && de == 0)
331  clusterOk = false; // somehow, the seed is hosed
332  }
333 
334  if (e_short > m_minTowerEnergy && is != hf.end()) {
335  // record usage
336  usedHits.push_back(ids.rawId());
337  // always in the 5x5
338  s_5 += e_short;
339  // maybe in the 3x3
340  if ((de > -2) && (de < 2) && (dp > -4) && (dp < 4)) {
341  s_3 += e_short;
342  }
343  // sometimes in the 1x1
344  if ((dp == 0) && (de == 0)) {
345  s_1 = e_short;
346  }
347  }
348  }
349 
350  if (!clusterOk)
351  return false;
352 
353  //Core sorting done here
354  std::sort(coreCanid.begin(), coreCanid.end(), CompareHFCore());
355  for (ci = coreCanid.begin(); ci != coreCanid.end(); ci++) {
356  if (ci == coreCanid.begin()) {
357  l_1e = *ci;
358  } else if (*ci > .5 * l_1e) {
359  l_1e += *ci;
360  }
361  } //core sorting end
362 
363  double z_ = w_z / w;
364  double x_ = w_x / w;
365  double y_ = w_y / w;
366  math::XYZPoint xyzclus(x_, y_, z_);
367  //calcualte position, final
368  double eta = xyzclus.eta(); //w_e/w+sp.eta();
369 
370  double phi = xyzclus.phi(); //(wp_e/w)+sp.phi();
371 
372  while (phi < -M_PI)
373  phi += 2 * M_PI;
374  while (phi > M_PI)
375  phi -= 2 * M_PI;
376 
377  //calculate cell phi and cell eta
378  int idx = fabs(seedid.ieta()) - 29;
379  int ipx = seedid.iphi();
380  double Cphi = (phi - m_seedmnPhi[ipx]) / (m_seedMXphi[ipx] - m_seedmnPhi[ipx]);
381  double Ceta = (fabs(eta) - m_seedmnEta[idx]) / (m_seedMXeta[idx] - m_seedmnEta[idx]);
382 
383  //return HFEMClusterShape, SuperCluster
384  HFEMClusterShape myClusShp(l_1, s_1, l_3, s_3, l_5, s_5, l_1e, Ceta, Cphi, seedid);
385  clusShp = myClusShp;
386 
387  SuperCluster MySclus(l_3, xyzclus);
388  Sclus = MySclus;
389 
390  return clusterOk;
391 }
393  bool pmthit = false;
394 
395  if ((hfr.flagField(HcalCaloFlagLabels::HFLongShort)) && (m_usePMTFlag))
396  pmthit = true;
397  if (!(m_isMC && !m_forcePulseFlagMC))
398  if ((hfr.flagField(HcalCaloFlagLabels::HFDigiTime)) && (m_usePulseFlag))
399  pmthit = true;
400 
401  return pmthit;
402 }
404  edm::LogInfo("HFClusterAlgo") << "Resetting for Run!";
405  for (int ii = 0; ii < 13; ii++) {
406  m_cutByEta.push_back(-1);
407  m_seedmnEta.push_back(99);
408  m_seedMXeta.push_back(-1);
409  }
410 }
HFClusterAlgo::HFCompleteHit::energy
double energy
Definition: HFClusterAlgo.h:62
mps_fire.i
i
Definition: mps_fire.py:355
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
HFClusterAlgo::clusterize
void clusterize(const HFRecHitCollection &hf, const CaloGeometry &geom, reco::HFEMClusterShapeCollection &clusters, reco::SuperClusterCollection &SuperClusters)
Definition: HFClusterAlgo.cc:89
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
reco::SuperCluster
Definition: SuperCluster.h:18
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
hfClusterShapes_cfi.forcePulseFlagMC
forcePulseFlagMC
Definition: hfClusterShapes_cfi.py:11
reco::HFEMClusterShapeCollection
std::vector< HFEMClusterShape > HFEMClusterShapeCollection
Definition: HFEMClusterShapeFwd.h:8
CaloRecHit::flagField
constexpr uint32_t flagField(int base, int width=1) const
Definition: CaloRecHit.h:46
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::LogInfo
Definition: MessageLogger.h:254
HFClusterAlgo::HFCompleteHit
Definition: HFClusterAlgo.h:60
edm::SortedCollection
Definition: SortedCollection.h:49
hfClusterShapes_cfi.maximumRenergy
maximumRenergy
Definition: hfClusterShapes_cfi.py:9
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
EZArrayFL< GlobalPoint >
indexByEta
static int indexByEta(HcalDetId id)
Definition: HFClusterAlgo.cc:35
training_settings.idx
idx
Definition: training_settings.py:16
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
CaloGeometry
Definition: CaloGeometry.h:21
reco::HFEMClusterShape
Definition: HFEMClusterShape.h:20
photonIsolationHIProducer_cfi.hf
hf
Definition: photonIsolationHIProducer_cfi.py:9
HFRecHit
Definition: HFRecHit.h:11
Calorimetry_cff.dp
dp
Definition: Calorimetry_cff.py:157
PVValHelper::eta
Definition: PVValidationHelpers.h:69
w
const double w
Definition: UKUtility.cc:23
HcalCaloFlagLabels::HFDigiTime
Definition: HcalCaloFlagLabels.h:38
HFClusterAlgo::isPMTHit
bool isPMTHit(const HFRecHit &hfr)
Definition: HFClusterAlgo.cc:392
HFClusterAlgo::makeCluster
bool makeCluster(const HcalDetId &seedid, const HFRecHitCollection &hf, const CaloGeometry *geom, reco::HFEMClusterShape &clusShp, reco::SuperCluster &SClus)
Definition: HFClusterAlgo.cc:196
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
HFClusterAlgo::setup
void setup(double minTowerEnergy, double seedThreshold, double maximumSL, double m_maximumRenergy, bool usePMTflag, bool usePulseflag, bool forcePulseFlagMC, int correctionSet)
Definition: HFClusterAlgo.cc:40
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< float, GlobalTag >
HFClusterAlgo::HFClusterAlgo
HFClusterAlgo()
Definition: HFClusterAlgo.cc:19
HFClusterAlgo.h
hfClusterShapes_cfi.maximumSL
maximumSL
Definition: hfClusterShapes_cfi.py:8
CompareHFCore
Definition: HFClusterAlgo.cc:30
edm::LogWarning
Definition: MessageLogger.h:141
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:232
HFClusterAlgo::resetForRun
void resetForRun()
Definition: HFClusterAlgo.cc:403
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
HcalCaloFlagLabels.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
HcalDetId
Definition: HcalDetId.h:12
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
hfClusterShapes_cfi.minTowerEnergy
minTowerEnergy
Definition: hfClusterShapes_cfi.py:6
CompareHFCompleteHitET
Definition: HFClusterAlgo.cc:23
HcalForward
Definition: HcalAssistant.h:36
MCMaterialCorrections_3XX
static const double MCMaterialCorrections_3XX[]
Definition: HFClusterAlgo.cc:36
CompareHFCore::operator()
bool operator()(const double c1, const double c2) const
Definition: HFClusterAlgo.cc:32
CaloCellGeometry.h
HFClusterAlgo::HFCompleteHit::et
double et
Definition: HFClusterAlgo.h:62
std
Definition: JetResolutionObject.h:76
EZArrayFL::size
size_type size() const
Definition: EZArrayFL.h:67
HcalCaloFlagLabels::HFLongShort
Definition: HcalCaloFlagLabels.h:37
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HcalDetId::ietaAbs
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
CompareHFCompleteHitET::operator()
bool operator()(const HFClusterAlgo::HFCompleteHit &h1, const HFClusterAlgo::HFCompleteHit &h2) const
Definition: HFClusterAlgo.cc:25
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HcalDetId::zside
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
HFClusterAlgo::HFCompleteHit::id
HcalDetId id
Definition: HFClusterAlgo.h:61
cuy.ii
ii
Definition: cuy.py:590
UEAnalysisJets_cfi.seedThreshold
seedThreshold
Definition: UEAnalysisJets_cfi.py:8
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66