CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends
HFClusterAlgo Class Reference

#include <HFClusterAlgo.h>

Classes

struct  HFCompleteHit
 

Public Member Functions

void clusterize (const HFRecHitCollection &hf, const CaloGeometry &geom, reco::HFEMClusterShapeCollection &clusters, reco::SuperClusterCollection &SuperClusters)
 
 HFClusterAlgo ()
 
void isMC (bool isMC)
 
void setup (double minTowerEnergy, double seedThreshold, double maximumSL, double m_maximumRenergy, bool usePMTflag, bool usePulseflag, bool forcePulseFlagMC, int correctionSet)
 

Private Member Functions

bool isPMTHit (const HFRecHit &hfr)
 
bool makeCluster (const HcalDetId &seedid, const HFRecHitCollection &hf, const CaloGeometry &geom, reco::HFEMClusterShape &clusShp, reco::SuperCluster &SClus)
 

Private Attributes

std::vector< double > m_correctionByEta
 
int m_correctionSet
 
std::vector< double > m_cutByEta
 
bool m_forcePulseFlagMC
 
bool m_isMC
 
double m_maximumRenergy
 
double m_maximumSL
 
double m_minTowerEnergy
 
double m_seedThreshold
 
bool m_usePMTFlag
 
bool m_usePulseFlag
 

Friends

class CompareHFCompleteHitET
 
class CompareHFCore
 

Detailed Description

Author
K. Klapoetke – Minnesota
Kevin Klapoetke (Minnesota)

$Id:version 1.2

Definition at line 22 of file HFClusterAlgo.h.

Constructor & Destructor Documentation

HFClusterAlgo::HFClusterAlgo ( )

Definition at line 19 of file HFClusterAlgo.cc.

20 {
21  m_isMC=true; // safest
22 
23 }

Member Function Documentation

void HFClusterAlgo::clusterize ( const HFRecHitCollection hf,
const CaloGeometry geom,
reco::HFEMClusterShapeCollection clusters,
reco::SuperClusterCollection SuperClusters 
)

Analyze the hits

Definition at line 82 of file HFClusterAlgo.cc.

References edm::SortedCollection< T, SORT >::begin(), edm::SortedCollection< T, SORT >::end(), HFClusterAlgo::HFCompleteHit::energy, HFClusterAlgo::HFCompleteHit::et, eta(), edm::SortedCollection< T, SORT >::find(), relativeConstraints::geom, CaloGeometry::getPosition(), HcalForward, i, HFClusterAlgo::HFCompleteHit::id, indexByEta(), j, gen::k, and python.multivaluedict::sort().

Referenced by HFEMClusterProducer::produce().

85  {
86 
87  std::vector<HFCompleteHit> protoseeds, seeds;
89  std::vector<HFCompleteHit>::iterator i;
90  std::vector<HFCompleteHit>::iterator k;
91  int dP, dE, PWrap;
92  bool isok=true;
93  HFEMClusterShape clusShp;
94 
95  SuperCluster Sclus;
96  bool doCluster=false;
97 
98  for (j=hf.begin(); j!= hf.end(); j++) {
99  const int aieta=j->id().ietaAbs();
100  int iz=(aieta-29);
101  // only long fibers and not 29,40,41 allowed to be considered as seeds
102  if (j->id().depth()!=1) continue;
103  if (aieta==40 || aieta==41 || aieta==29) continue;
104 
105 
106  if (iz<0 || iz>12) {
107  edm::LogWarning("HFClusterAlgo") << "Strange invalid HF hit: " << j->id();
108  continue;
109  }
110 
111  if (m_cutByEta[iz]<0) {
112  double eta=geom.getPosition(j->id()).eta();
113  m_cutByEta[iz]=m_seedThreshold*cosh(eta); // convert ET to E for this ring
114  }
115  double elong=j->energy()*m_correctionByEta[indexByEta(j->id())];
116  if (elong>m_cutByEta[iz]) {
117  j2=hf.find(HcalDetId(HcalForward,j->id().ieta(),j->id().iphi(),2));
118  double eshort=(j2==hf.end())?(0):(j2->energy());
119  if (j2!=hf.end())
120  eshort*=m_correctionByEta[indexByEta(j2->id())];
121  if (((elong-eshort)/(elong+eshort))>m_maximumSL) continue;
122  //if ((m_usePMTFlag)&&(j->flagField(4,1))) continue;
123  //if ((m_usePulseFlag)&&(j->flagField(1,1))) continue;
124  if(isPMTHit(*j)) continue;
125 
126  HFCompleteHit ahit;
127  double eta=geom.getPosition(j->id()).eta();
128  ahit.id=j->id();
129  ahit.energy=elong;
130  ahit.et=ahit.energy/cosh(eta);
131  protoseeds.push_back(ahit);
132  }
133  }
134 
135  if(!protoseeds.empty()){
136  std::sort(protoseeds.begin(), protoseeds.end(), CompareHFCompleteHitET());
137  for (i=protoseeds.begin(); i!= protoseeds.end(); i++) {
138  isok=true;
139  doCluster=false;
140 
141  if ( (i==protoseeds.begin()) && (isok) ) {
142  doCluster=true;
143  }else {
144  // check for overlap with existing clusters
145  for (k=seeds.begin(); isok && k!=seeds.end(); k++) { //i->hits, k->seeds
146 
147  for (dE=-2; dE<=2; dE++)
148  for (dP=-4;dP<=4; dP+=2) {
149  PWrap=k->id.iphi()+dP;
150  if (PWrap<0)
151  PWrap+=72;
152  if (PWrap>72)
153  PWrap-=72;
154 
155  if ( (i->id.iphi()==PWrap) && (i->id.ieta()==k->id.ieta()+dE))
156  isok = false;
157  }
158  }
159  if (isok) {
160  doCluster=true;
161  }
162  }
163  if (doCluster) {
164  seeds.push_back(*i);
165 
166  bool clusterOk=makeCluster( i->id(),hf, geom,clusShp,Sclus);
167  if (clusterOk) { // cluster is _not_ ok if seed is rejected due to other cuts
168  clusterShapes.push_back(clusShp);
169  SuperClusters.push_back(Sclus);
170  }
171 
172  }
173  }//end protoseed loop
174  }//end if seeCount
175 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > m_cutByEta
Definition: HFClusterAlgo.h:46
double m_maximumSL
Definition: HFClusterAlgo.h:41
std::vector< double > m_correctionByEta
Definition: HFClusterAlgo.h:47
std::vector< T >::const_iterator const_iterator
friend class CompareHFCompleteHitET
Definition: HFClusterAlgo.h:38
T eta() const
bool makeCluster(const HcalDetId &seedid, const HFRecHitCollection &hf, const CaloGeometry &geom, reco::HFEMClusterShape &clusShp, reco::SuperCluster &SClus)
int j
Definition: DBlmapReader.cc:9
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
int k[5][pyjets_maxn]
const_iterator end() const
static int indexByEta(HcalDetId id)
iterator find(key_type k)
double m_seedThreshold
Definition: HFClusterAlgo.h:41
bool isPMTHit(const HFRecHit &hfr)
const_iterator begin() const
void HFClusterAlgo::isMC ( bool  isMC)
inline

Definition at line 28 of file HFClusterAlgo.h.

References isMC(), and m_isMC.

Referenced by isMC(), and HFEMClusterProducer::produce().

28 { m_isMC=isMC; }
void isMC(bool isMC)
Definition: HFClusterAlgo.h:28
bool HFClusterAlgo::isPMTHit ( const HFRecHit hfr)
private

Definition at line 409 of file HFClusterAlgo.cc.

References CaloRecHit::flagField(), HcalCaloFlagLabels::HFDigiTime, and HcalCaloFlagLabels::HFLongShort.

409  {
410 
411  bool pmthit=false;
412 
413  if((hfr.flagField(HcalCaloFlagLabels::HFLongShort))&&(m_usePMTFlag)) pmthit=true;
414  if (!(m_isMC && !m_forcePulseFlagMC))
415  if((hfr.flagField(HcalCaloFlagLabels::HFDigiTime))&&(m_usePulseFlag)) pmthit=true;
416 
417  return pmthit;
418 
419 
420 }
bool m_forcePulseFlagMC
Definition: HFClusterAlgo.h:43
uint32_t flagField(int base, int width=1) const
Definition: CaloRecHit.cc:31
bool HFClusterAlgo::makeCluster ( const HcalDetId seedid,
const HFRecHitCollection hf,
const CaloGeometry geom,
reco::HFEMClusterShape clusShp,
reco::SuperCluster SClus 
)
private

Definition at line 178 of file HFClusterAlgo.cc.

References abs, edm::SortedCollection< T, SORT >::end(), PV3DBase< T, PVType, FrameType >::eta(), eta(), edm::SortedCollection< T, SORT >::find(), CaloGeometry::getPosition(), HcalForward, i, HcalDetId::ieta(), HcalDetId::ietaAbs(), indexByEta(), HcalDetId::iphi(), create_public_lumi_plots::log, M_PI, max(), AlCaHLTBitMon_ParallelJobs::p, phi, PV3DBase< T, PVType, FrameType >::phi(), evf::utils::sid, python.multivaluedict::sort(), w(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), PV3DBase< T, PVType, FrameType >::z(), and HcalDetId::zside().

182  {
183 
184 
185  double w=0;//sum over all log E's
186  double wgt=0;
187  double w_e=0;//sum over ieat*energy
188  double w_x=0;
189  double w_y=0;
190  double w_z=0;
191  double wp_e=0;//sum over iphi*energy
192  double e_e=0;//nonwieghted eta sum
193  double e_ep=0; //nonweighted phi sum
194 
195  double l_3=0;//sum for enenergy in 3x3 long fibers etc.
196  double s_3=0;
197  double l_5=0;
198  double s_5=0;
199  double l_1=0;
200  double s_1=0;
201  int de, dp, phiWrap;
202  double l_1e=0;
203  GlobalPoint sp=geom.getPosition(seedid);
204  std::vector<double> coreCanid;
205  std::vector<double>::const_iterator ci;
207  std::vector<DetId> usedHits;
208 
210  HcalDetId sid(HcalForward,seedid.ieta(),seedid.iphi(),1);
211  si=hf.find(sid);
212 
213  bool clusterOk=true; // assume the best to start...
214 
215  // lots happens here
216  // edge type 1 has 40/41 in 3x3 and 5x5
217  bool edge_type1=seedid.ietaAbs()==39 && (seedid.iphi()%4)==3;
218 
219  double e_seed=si->energy()*m_correctionByEta[indexByEta(si->id())];
220 
221  for (de=-2; de<=2; de++)
222  for (dp=-4;dp<=4; dp+=2) {
223  phiWrap=seedid.iphi()+dp;
224  if (phiWrap<0)
225  phiWrap+=72;
226  if (phiWrap>72)
227  phiWrap-=72;
228 
229 
230  /* Handling of phi-width change problems */
231  if (edge_type1 && de==seedid.zside()) {
232  if (dp==-2) { // we want it in the 3x3
233  phiWrap-=2;
234  if (phiWrap<0)
235  phiWrap+=72;
236  }
237  else if (dp==-4) {
238  continue; // but not double counted in 5x5
239  }
240  }
241 
242  HcalDetId idl(HcalForward,seedid.ieta()+de,phiWrap,1);
243  HcalDetId ids(HcalForward,seedid.ieta()+de,phiWrap,2);
244 
245 
246  il=hf.find(idl);
247  is=hf.find(ids);
248 
249 
250 
251 
252  double e_long=1.0;
253  double e_short=0.0;
254  if (il!=hf.end()) e_long=il->energy()*m_correctionByEta[indexByEta(il->id())];
255  if (e_long <= m_minTowerEnergy) e_long=0.0;
256  if (is!=hf.end()) e_short=is->energy()*m_correctionByEta[indexByEta(is->id())];
257  if (e_short <= m_minTowerEnergy) e_short=0.0;
258  double eRatio=(e_long-e_short)/std::max(1.0,(e_long+e_short));
259 
260  // require S/L > a minimum amount for inclusion
261  if ((abs(eRatio) > m_maximumSL)&&(std::max(e_long,e_short) > m_maximumRenergy)) {
262  if (dp==0 && de==0) clusterOk=false; // somehow, the seed is hosed
263  continue;
264  }
265 
266  if((il!=hf.end())&&(isPMTHit(*il))){
267  if (dp==0 && de==0) clusterOk=false; // somehow, the seed is hosed
268  continue;//continue to next hit, do not include this one in cluster
269  }
270 
271 
272  /*
273 
274  old pmt code
275  // cut on "PMT HIT" flag
276  if ((il!=hf.end())&&(il->flagField(4,1))&&(m_usePMTFlag)) {//HFPET flag for lone/short doil->flagField(0,1)
277  if (dp==0 && de==0) clusterOk=false; // somehow, the seed is hosed
278  continue;//continue to next hit, do not include this one in cluster
279  }
280 
281  // cut on "Pulse shape HIT" flag
282  if ((il!=hf.end())&&(il->flagField(1,1))&&(m_usePulseFlag)) {//HF DIGI TIME flag
283  if (dp==0 && de==0) clusterOk=false; // somehow, the seed is hosed
284  continue;//continue to next hit, do not include this one in cluster
285  }
286  */
287 
288 
289 
290 
291  if (e_long > m_minTowerEnergy && il!=hf.end()) {
292 
293  // record usage
294  usedHits.push_back(idl.rawId());
295  // always in the 5x5
296  l_5+=e_long;
297  // maybe in the 3x3
298  if ((de>-2)&&(de<2)&&(dp>-4)&&(dp<4)) {
299  l_3+=e_long;
300  }
301  // sometimes in the 1x1
302  if ((dp==0)&&(de==0)) {
303  l_1=e_long;
304  }
305 
306  // maybe in the core?
307  if ((de>-2)&&(de<2)&&(dp>-4)&&(dp<4)&&(e_long>(.5*e_seed))) {
308  coreCanid.push_back(e_long);
309  }
310 
311  // position calculation
312  GlobalPoint p=geom.getPosition(idl);
313 
314  double d_p = p.phi()-sp.phi();
315  while (d_p < -M_PI)
316  d_p+=2*M_PI;
317  while (d_p > M_PI)
318  d_p-=2*M_PI;
319  double d_e = p.eta()-sp.eta();
320 
321  wgt=log((e_long));
322  if (wgt>0){
323  w+=wgt;
324  w_e+=(d_e)*wgt;
325  wp_e+=(d_p)*wgt;
326  e_e+=d_e;
327  e_ep+=d_p;
328 
329  w_x+=(p.x())*wgt;//(p.x()-sp.x())*wgt;
330  w_y+=(p.y())*wgt;
331  w_z+=(p.z())*wgt;
332  }
333  } else {
334  if (dp==0 && de==0) clusterOk=false; // somehow, the seed is hosed
335  }
336 
337  if (e_short > m_minTowerEnergy && is!=hf.end()) {
338  // record usage
339  usedHits.push_back(ids.rawId());
340  // always in the 5x5
341  s_5+=e_short;
342  // maybe in the 3x3
343  if ((de>-2)&&(de<2)&&(dp>-4)&&(dp<4)) {
344  s_3+=e_short;
345  }
346  // sometimes in the 1x1
347  if ((dp==0)&&(de==0)) {
348  s_1=e_short;
349  }
350  }
351  }
352 
353 
354  if (!clusterOk) return false;
355 
356  //Core sorting done here
357  std::sort(coreCanid.begin(), coreCanid.end(), CompareHFCore());
358  for (ci=coreCanid.begin();ci!=coreCanid.end();ci++){
359  if(ci==coreCanid.begin()){
360  l_1e=*ci;
361  }else if (*ci>.5*l_1e){
362  l_1e+=*ci;
363  }
364  }//core sorting end
365 
366  double z_=w_z/w;
367  double x_=w_x/w;
368  double y_=w_y/w;
369 
370  //calcualte position, final
371  double eta=w_e/w+sp.eta();
372 
373  double phi=(wp_e/w)+sp.phi();
374 
375  while (phi < -M_PI)
376  phi+=2*M_PI;
377  while (phi > M_PI)
378  phi-=2*M_PI;
379 
380  //calculate cell phi and cell eta
381  static const double HFEtaBounds[14] = {2.853, 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191};
382  double RcellEta = fabs(eta);
383  double Cphi = (phi>0.)?(fmod((phi),0.087*2)/(0.087*2)):((fmod((phi),0.087*2)/(0.087*2))+1.0);
384  double Rbin = -1.0;
385  for (int icell = 0; icell < 12; icell++ ){
386  if ( (RcellEta>HFEtaBounds[icell]) && (RcellEta<HFEtaBounds[icell+1]) )
387  Rbin = (RcellEta - HFEtaBounds[icell])/(HFEtaBounds[icell+1] - HFEtaBounds[icell]);
388  }
389  double Ceta=Rbin;
390 
391  while (phi< -M_PI)
392  phi+=2*M_PI;
393  while (phi > M_PI)
394  phi-=2*M_PI;
395 
396 
397  math::XYZPoint xyzclus(x_,y_,z_);
398 
399  //return HFEMClusterShape, SuperCluster
400  HFEMClusterShape myClusShp(l_1, s_1, l_3, s_3, l_5,s_5, l_1e,Ceta, Cphi,seedid);
401  clusShp = myClusShp;
402 
403  SuperCluster MySclus(l_3,xyzclus);
404  Sclus=MySclus;
405 
406  return clusterOk;
407 
408 }
double m_minTowerEnergy
Definition: HFClusterAlgo.h:41
int i
Definition: DBlmapReader.cc:9
double m_maximumRenergy
Definition: HFClusterAlgo.h:41
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:34
double m_maximumSL
Definition: HFClusterAlgo.h:41
std::vector< double > m_correctionByEta
Definition: HFClusterAlgo.h:47
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
std::vector< T >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
T eta() const
friend class CompareHFCore
Definition: HFClusterAlgo.h:39
const T & max(const T &a, const T &b)
T z() const
Definition: PV3DBase.h:63
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:36
const_iterator end() const
static int indexByEta(HcalDetId id)
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
#define M_PI
Definition: BFit3D.cc:3
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
T eta() const
Definition: PV3DBase.h:75
iterator find(key_type k)
T x() const
Definition: PV3DBase.h:61
bool isPMTHit(const HFRecHit &hfr)
T w() const
Definition: DDAxes.h:10
void HFClusterAlgo::setup ( double  minTowerEnergy,
double  seedThreshold,
double  maximumSL,
double  m_maximumRenergy,
bool  usePMTflag,
bool  usePulseflag,
bool  forcePulseFlagMC,
int  correctionSet 
)

Definition at line 51 of file HFClusterAlgo.cc.

References MCMaterialCorrections, and ZplusMC2010Corrections.

Referenced by HFEMClusterProducer::HFEMClusterProducer().

52  {
53  m_seedThreshold=seedThreshold;
54  m_minTowerEnergy=minTowerEnergy;
55  m_maximumSL=maximumSL;
56  m_usePMTFlag=usePMTflag;
57  m_usePulseFlag=usePulseflag;
58  m_forcePulseFlagMC=forcePulseFlagMC;
59  m_maximumRenergy=maximumRenergy;
60  m_correctionSet = correctionSet;
61 
62  for(int ii=0;ii<13;ii++){
63  m_cutByEta.push_back(-1);
64  }
65 
66  // always set all the corrections to one...
67  for (int ii=0; ii<13*2; ii++)
68  m_correctionByEta.push_back(1.0);
69 
70  if (m_correctionSet==1) { // corrections for material from MC
71  for (int ii=0; ii<13*2; ii++)
73  }
74  if (m_correctionSet==2) { // corrections for material from MC + 2010 Z-based ccalibration
75  for (int ii=0; ii<13*2; ii++)
77  }
78 
79 }
double m_minTowerEnergy
Definition: HFClusterAlgo.h:41
double m_maximumRenergy
Definition: HFClusterAlgo.h:41
bool m_forcePulseFlagMC
Definition: HFClusterAlgo.h:43
std::vector< double > m_cutByEta
Definition: HFClusterAlgo.h:46
double m_maximumSL
Definition: HFClusterAlgo.h:41
std::vector< double > m_correctionByEta
Definition: HFClusterAlgo.h:47
static const double MCMaterialCorrections[]
static const double ZplusMC2010Corrections[]
double m_seedThreshold
Definition: HFClusterAlgo.h:41

Friends And Related Function Documentation

friend class CompareHFCompleteHitET
friend

Definition at line 38 of file HFClusterAlgo.h.

friend class CompareHFCore
friend

Definition at line 39 of file HFClusterAlgo.h.

Member Data Documentation

std::vector<double> HFClusterAlgo::m_correctionByEta
private

Definition at line 47 of file HFClusterAlgo.h.

int HFClusterAlgo::m_correctionSet
private

Definition at line 45 of file HFClusterAlgo.h.

std::vector<double> HFClusterAlgo::m_cutByEta
private

Definition at line 46 of file HFClusterAlgo.h.

bool HFClusterAlgo::m_forcePulseFlagMC
private

Definition at line 43 of file HFClusterAlgo.h.

bool HFClusterAlgo::m_isMC
private

Definition at line 44 of file HFClusterAlgo.h.

Referenced by isMC().

double HFClusterAlgo::m_maximumRenergy
private

Definition at line 41 of file HFClusterAlgo.h.

double HFClusterAlgo::m_maximumSL
private

Definition at line 41 of file HFClusterAlgo.h.

double HFClusterAlgo::m_minTowerEnergy
private

Definition at line 41 of file HFClusterAlgo.h.

double HFClusterAlgo::m_seedThreshold
private

Definition at line 41 of file HFClusterAlgo.h.

bool HFClusterAlgo::m_usePMTFlag
private

Definition at line 42 of file HFClusterAlgo.h.

bool HFClusterAlgo::m_usePulseFlag
private

Definition at line 43 of file HFClusterAlgo.h.