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 75 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().

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

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

402  {
403 
404  bool pmthit=false;
405 
406  if((hfr.flagField(HcalCaloFlagLabels::HFLongShort))&&(m_usePMTFlag)) pmthit=true;
407  if (!(m_isMC && !m_forcePulseFlagMC))
408  if((hfr.flagField(HcalCaloFlagLabels::HFDigiTime))&&(m_usePulseFlag)) pmthit=true;
409 
410  return pmthit;
411 
412 
413 }
bool m_forcePulseFlagMC
Definition: HFClusterAlgo.h:43
uint32_t flagField(int base, int width=1) const
Definition: CaloRecHit.cc:33
bool HFClusterAlgo::makeCluster ( const HcalDetId seedid,
const HFRecHitCollection hf,
const CaloGeometry geom,
reco::HFEMClusterShape clusShp,
reco::SuperCluster SClus 
)
private

Definition at line 171 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(), funct::log(), M_PI, max(), L1TEmulatorMonitor_cff::p, phi, PV3DBase< T, PVType, FrameType >::phi(), evf::utils::sid, python.multivaluedict::sort(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), PV3DBase< T, PVType, FrameType >::z(), and HcalDetId::zside().

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

References MCMaterialCorrections.

Referenced by HFEMClusterProducer::HFEMClusterProducer().

49  {
50  m_seedThreshold=seedThreshold;
51  m_minTowerEnergy=minTowerEnergy;
52  m_maximumSL=maximumSL;
53  m_usePMTFlag=usePMTflag;
54  m_usePulseFlag=usePulseflag;
55  m_forcePulseFlagMC=forcePulseFlagMC;
56  m_maximumRenergy=maximumRenergy;
57  m_correctionSet = correctionSet;
58 
59  for(int ii=0;ii<13;ii++){
60  m_cutByEta.push_back(-1);
61  }
62 
63  // always set all the corrections to one...
64  for (int ii=0; ii<13*2; ii++)
65  m_correctionByEta.push_back(1.0);
66 
67  if (m_correctionSet==1) { // corrections for material from MC
68  for (int ii=0; ii<13*2; ii++)
70  }
71 
72 }
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[]
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.