CMS 3D CMS Logo

EcalClusterLocal.cc
Go to the documentation of this file.
9 #include "TMath.h"
10 #include "TVector2.h"
11 
12 namespace egammaTools {
13 
14 void localEcalClusterCoordsEB( const reco::CaloCluster &bclus, const CaloGeometry & caloGeometry,
15  float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt )
16 {
17 
18  assert(bclus.hitsAndFractions().at(0).first.subdetId()==EcalBarrel);
19 
20  const CaloSubdetectorGeometry* geom=caloGeometry.getSubdetectorGeometry(DetId::Ecal,EcalBarrel);//EcalBarrel = 1
21 
22  const math::XYZPoint& position_ = bclus.position();
23  double Theta = -position_.theta()+0.5*TMath::Pi();
24  double Eta = position_.eta();
25  double Phi = TVector2::Phi_mpi_pi(position_.phi());
26 
27  //Calculate expected depth of the maximum shower from energy (like in PositionCalc::Calculate_Location()):
28  // The parameters X0 and T0 are hardcoded here because these values were used to calculate the corrections:
29  const float X0 = 0.89; const float T0 = 7.4;
30  double depth = X0 * (T0 + log(bclus.energy()));
31 
32  //find max energy crystal
33  std::vector< std::pair<DetId, float> > crystals_vector = bclus.hitsAndFractions();
34  float drmin = 999.;
35  EBDetId crystalseed;
36  //printf("starting loop over crystals, etot = %5f:\n",bclus.energy());
37  for (unsigned int icry=0; icry!=crystals_vector.size(); ++icry) {
38 
39  EBDetId crystal(crystals_vector[icry].first);
40 
41  auto cell=geom->getGeometry(crystal);
42  const TruncatedPyramid* cpyr = dynamic_cast<const TruncatedPyramid*>(cell.get());
43  GlobalPoint center_pos = cpyr->getPosition(depth);
44  double EtaCentr = center_pos.eta();
45  double PhiCentr = TVector2::Phi_mpi_pi(center_pos.phi());
46 
47  float dr = reco::deltaR(Eta,Phi,EtaCentr,PhiCentr);
48  if (dr<drmin) {
49  drmin = dr;
50  crystalseed = crystal;
51  }
52 
53  }
54 
55  ieta = crystalseed.ieta();
56  iphi = crystalseed.iphi();
57 
58  // Get center cell position from shower depth
59  auto cell=geom->getGeometry(crystalseed);
60  const TruncatedPyramid* cpyr = dynamic_cast<const TruncatedPyramid*>(cell.get());
61 
62  thetatilt = cpyr->getThetaAxis();
63  phitilt = cpyr->getPhiAxis();
64 
65  GlobalPoint center_pos = cpyr->getPosition(depth);
66 
67  double PhiCentr = TVector2::Phi_mpi_pi(center_pos.phi());
68  double PhiWidth = (TMath::Pi()/180.);
69  phicry = (TVector2::Phi_mpi_pi(Phi-PhiCentr))/PhiWidth;
70  //Some flips to take into account ECAL barrel symmetries:
71  if (ieta<0) phicry *= -1.;
72 
73  double ThetaCentr = -center_pos.theta()+0.5*TMath::Pi();
74  double ThetaWidth = (TMath::Pi()/180.)*TMath::Cos(ThetaCentr);
75  etacry = (Theta-ThetaCentr)/ThetaWidth;
76  //flip to take into account ECAL barrel symmetries:
77  if (ieta<0) etacry *= -1.;
78 
79  return;
80 
81 }
82 
83 void localEcalClusterCoordsEE( const reco::CaloCluster &bclus, const CaloGeometry & caloGeometry,
84  float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt )
85 {
86 
87  assert(bclus.hitsAndFractions().at(0).first.subdetId()==EcalEndcap);
88 
89  const CaloSubdetectorGeometry* geom=caloGeometry.getSubdetectorGeometry(DetId::Ecal,EcalEndcap);//EcalBarrel = 1
90 
91  const math::XYZPoint& position_ = bclus.position();
92  //double Theta = -position_.theta()+0.5*TMath::Pi();
93  double Eta = position_.eta();
94  double Phi = TVector2::Phi_mpi_pi(position_.phi());
95  double X = position_.x();
96  double Y = position_.y();
97 
98  //Calculate expected depth of the maximum shower from energy (like in PositionCalc::Calculate_Location()):
99  // The parameters X0 and T0 are hardcoded here because these values were used to calculate the corrections:
100  const float X0 = 0.89; float T0 = 1.2;
101  //different T0 value if outside of preshower coverage
102  if (TMath::Abs(bclus.eta())<1.653) T0 = 3.1;
103 
104  double depth = X0 * (T0 + log(bclus.energy()));
105 
106  //find max energy crystal
107  std::vector< std::pair<DetId, float> > crystals_vector = bclus.hitsAndFractions();
108  float drmin = 999.;
109  EEDetId crystalseed;
110  //printf("starting loop over crystals, etot = %5f:\n",bclus.energy());
111  for (unsigned int icry=0; icry!=crystals_vector.size(); ++icry) {
112 
113  EEDetId crystal(crystals_vector[icry].first);
114 
115  auto cell=geom->getGeometry(crystal);
116  const TruncatedPyramid* cpyr = dynamic_cast<const TruncatedPyramid*>(cell.get());
117  GlobalPoint center_pos = cpyr->getPosition(depth);
118  double EtaCentr = center_pos.eta();
119  double PhiCentr = TVector2::Phi_mpi_pi(center_pos.phi());
120 
121  float dr = reco::deltaR(Eta,Phi,EtaCentr,PhiCentr);
122  if (dr<drmin) {
123  drmin = dr;
124  crystalseed = crystal;
125  }
126 
127  }
128 
129  ix = crystalseed.ix();
130  iy = crystalseed.iy();
131 
132  // Get center cell position from shower depth
133  auto cell=geom->getGeometry(crystalseed);
134  const TruncatedPyramid* cpyr = dynamic_cast<const TruncatedPyramid*>(cell.get());
135 
136  thetatilt = cpyr->getThetaAxis();
137  phitilt = cpyr->getPhiAxis();
138 
139  GlobalPoint center_pos = cpyr->getPosition(depth);
140 
141  double XCentr = center_pos.x();
142  double XWidth = 2.59;
143  xcry = (X-XCentr)/XWidth;
144 
145 
146  double YCentr = center_pos.y();
147  double YWidth = 2.59;
148  ycry = (Y-YCentr)/YWidth;
149 
150  return;
151 
152 }
153 
154 }
const double Pi
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:131
GlobalPoint getPosition(CCGFloat depth) const override
void localEcalClusterCoordsEB(const reco::CaloCluster &bclus, const CaloGeometry &geom, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt)
int ix() const
Definition: EEDetId.h:77
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
#define X(str)
Definition: MuonsGrabber.cc:48
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:197
CCGFloat getPhiAxis() const
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:168
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
T Abs(T a)
Definition: MathUtil.h:49
double energy() const
cluster energy
Definition: CaloCluster.h:126
int iy() const
Definition: EEDetId.h:83
void localEcalClusterCoordsEE(const reco::CaloCluster &bclus, const CaloGeometry &geom, float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt)
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
CCGFloat getThetaAxis() const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
T eta() const
Definition: PV3DBase.h:76
static const double X0
T x() const
Definition: PV3DBase.h:62