CMS 3D CMS Logo

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