CMS 3D CMS Logo

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

#include <TBPositionCalc.h>

Public Member Functions

CLHEP::Hep3Vector CalculateCMSPos (std::vector< EBDetId > passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap)
 
CLHEP::Hep3Vector CalculateTBPos (std::vector< EBDetId > passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap)
 
void computeRotation (int myCrystal, CLHEP::HepRotation &CMStoTB)
 
 TBPositionCalc (std::map< std::string, double > providedParameters, const std::string &mapFile, const CaloSubdetectorGeometry *passedGeometry)
 
 TBPositionCalc ()
 
 ~TBPositionCalc ()
 

Private Attributes

bool param_LogWeighted_
 
Double32_t param_T0_
 
Double32_t param_W0_
 
Double32_t param_X0_
 
const CaloSubdetectorGeometrytheGeometry_
 
EcalTBCrystalMaptheTestMap
 

Detailed Description

Definition at line 26 of file TBPositionCalc.h.

Constructor & Destructor Documentation

TBPositionCalc::TBPositionCalc ( std::map< std::string, double >  providedParameters,
const std::string &  mapFile,
const CaloSubdetectorGeometry passedGeometry 
)

Definition at line 5 of file TBPositionCalc.cc.

References NULL.

6 {
7  // barrel geometry initialization
8  if(passedGeometry == NULL)
9  throw(std::runtime_error("\n\n TBPositionCalc: wrong initialization.\n\n"));
10  theGeometry_ = passedGeometry;
11 
12  // parameters initialization
13  param_LogWeighted_ = providedParameters.find("LogWeighted")->second;
14  param_X0_ = providedParameters.find("X0")->second;
15  param_T0_ = providedParameters.find("T0")->second;
16  param_W0_ = providedParameters.find("W0")->second;
17 
18  theTestMap = new EcalTBCrystalMap(fullMapName);
19 }
Double32_t param_X0_
Double32_t param_W0_
#define NULL
Definition: scimark2.h:8
const CaloSubdetectorGeometry * theGeometry_
EcalTBCrystalMap * theTestMap
Double32_t param_T0_
TBPositionCalc::TBPositionCalc ( )
inline

Definition at line 32 of file TBPositionCalc.h.

32 { };
TBPositionCalc::~TBPositionCalc ( )

Definition at line 21 of file TBPositionCalc.cc.

22 {
23  if (theTestMap) delete theTestMap;
24 }
EcalTBCrystalMap * theTestMap

Member Function Documentation

CLHEP::Hep3Vector TBPositionCalc::CalculateCMSPos ( std::vector< EBDetId passedDetIds,
int  myCrystal,
EcalRecHitCollection const *  passedRecHitsMap 
)

Definition at line 58 of file TBPositionCalc.cc.

References funct::cos(), edm::SortedCollection< T, SORT >::find(), funct::log(), M_PI, max(), PV3DBase< T, PVType, FrameType >::phi(), CosmicsPD_Skims::radius, funct::sin(), EBDetId::SMCRYSTALMODE, mathSSE::sqrt(), PV3DBase< T, PVType, FrameType >::theta(), CommonMethods::weight(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

58  {
59 
60  // Calculate the total energy
61  double thisEne = 0;
62  double eTot = 0;
63  EBDetId myId;
64  std::vector<EBDetId>::iterator myIt;
65  for (myIt = passedDetIds.begin(); myIt != passedDetIds.end(); myIt++) {
66  myId = (*myIt);
67  EcalRecHitCollection::const_iterator itt = passedRecHitsMap->find(myId);
68  thisEne = itt->energy();
69  eTot += thisEne;
70  }
71 
72  // Calculate shower depth
73  float depth = 0.;
74  if(eTot<=0.) {
75  edm::LogError("NegativeClusterEnergy") << "cluster with negative energy: " << eTot << ", setting depth to 0.";
76  } else {
77  depth = param_X0_ * (param_T0_ + log(eTot));
78  }
79 
80  // Get position of the central crystal from shower depth
81  EBDetId maxId_ = EBDetId(1, myCrystal, EBDetId::SMCRYSTALMODE);
82  const CaloCellGeometry* center_cell = theGeometry_ -> getGeometry(maxId_);
83  GlobalPoint center_pos =
84  (dynamic_cast<const TruncatedPyramid*>(center_cell))->getPosition(depth);
85 
86  // Loop over the hits collection
87  double weight = 0;
88  double total_weight = 0;
89  double cluster_theta = 0;
90  double cluster_phi = 0;
91  std::vector<EBDetId>::iterator myIt2;
92  for (myIt2 = passedDetIds.begin(); myIt2 != passedDetIds.end(); myIt2++) {
93 
94  // getting weights
95  myId = (*myIt2);
96  EcalRecHitCollection::const_iterator itj = passedRecHitsMap->find(myId);
97  double ener = itj->energy();
98 
99  if (param_LogWeighted_) {
100  if(eTot<=0.) { weight = 0.; }
101  else { weight = std::max(0., param_W0_ + log( fabs(ener)/eTot) ); }
102  } else {
103  weight = ener/eTot;
104  }
105  total_weight += weight;
106 
107  // weighted position of this detId
108  const CaloCellGeometry* jth_cell = theGeometry_->getGeometry(myId);
109  GlobalPoint jth_pos = dynamic_cast<const TruncatedPyramid*>(jth_cell)->getPosition(depth);
110  cluster_theta += weight*jth_pos.theta();
111  cluster_phi += weight*jth_pos.phi();
112  }
113 
114  // normalizing
115  cluster_theta /= total_weight;
116  cluster_phi /= total_weight;
117  if (cluster_phi > M_PI) { cluster_phi -= 2.*M_PI; }
118  if (cluster_phi < -M_PI){ cluster_phi += 2.*M_PI; }
119 
120  // position in the cms frame
121  double radius = sqrt(center_pos.x()*center_pos.x() + center_pos.y()*center_pos.y() + center_pos.z()*center_pos.z());
122  double xpos = radius*cos(cluster_phi)*sin(cluster_theta);
123  double ypos = radius*sin(cluster_phi)*sin(cluster_theta);
124  double zpos = radius*cos(cluster_theta);
125 
126  return CLHEP::Hep3Vector(xpos, ypos, zpos);
127 }
Double32_t param_X0_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
std::vector< T >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:57
Double32_t param_W0_
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:69
const T & max(const T &a, const T &b)
const CaloSubdetectorGeometry * theGeometry_
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define M_PI
Definition: BFit3D.cc:3
Log< T >::type log(const T &t)
Definition: Log.h:22
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
Double32_t param_T0_
static const int SMCRYSTALMODE
Definition: EBDetId.h:146
T x() const
Definition: PV3DBase.h:56
CLHEP::Hep3Vector TBPositionCalc::CalculateTBPos ( std::vector< EBDetId passedDetIds,
int  myCrystal,
EcalRecHitCollection const *  passedRecHitsMap 
)

Definition at line 26 of file TBPositionCalc.cc.

References edm::SortedCollection< T, SORT >::end(), edm::SortedCollection< T, SORT >::find(), and NULL.

26  {
27 
28  // throw an error if the cluster was not initialized properly
29  if(passedRecHitsMap == NULL)
30  throw(std::runtime_error("\n\n TBPositionCalc::CalculateTBPos called uninitialized.\n\n"));
31 
32  // check DetIds are nonzero
33  std::vector<EBDetId> validDetIds;
34  std::vector<EBDetId>::iterator iter;
35  for (iter = passedDetIds.begin(); iter != passedDetIds.end(); iter++) {
36  if (((*iter) != DetId(0))
37  && (passedRecHitsMap->find(*iter) != passedRecHitsMap->end()))
38  validDetIds.push_back(*iter);
39  }
40  passedDetIds.clear();
41  passedDetIds = validDetIds;
42 
43  // computing the position in the cms frame
44  CLHEP::Hep3Vector cmsPos = CalculateCMSPos(passedDetIds, myCrystal, passedRecHitsMap);
45 
46  // computing the rotation matrix (from CMS to TB)
47  CLHEP::HepRotation *CMStoTB = new CLHEP::HepRotation();
48  computeRotation(myCrystal, (*CMStoTB));
49 
50  // moving to testbeam frame
51  CLHEP::Hep3Vector tbPos = (*CMStoTB)*cmsPos;
52  delete CMStoTB;
53 
54  return tbPos;
55 }
void computeRotation(int myCrystal, CLHEP::HepRotation &CMStoTB)
#define NULL
Definition: scimark2.h:8
Definition: DetId.h:20
CLHEP::Hep3Vector CalculateCMSPos(std::vector< EBDetId > passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap)
void TBPositionCalc::computeRotation ( int  myCrystal,
CLHEP::HepRotation &  CMStoTB 
)

Definition at line 130 of file TBPositionCalc.cc.

References funct::exp().

130  {
131 
132  // taking eta/phi of the crystal
133 
134  double myEta = 999.;
135  double myPhi = 999.;
136  double myTheta = 999.;
137  theTestMap->findCrystalAngles(MyCrystal, myEta, myPhi);
138  myTheta = 2.0*atan(exp(-myEta));
139 
140  // matrix
141  CLHEP::HepRotation * fromCMStoTB = new CLHEP::HepRotation();
142  double angle1 = 90.*deg - myPhi;
143  CLHEP::HepRotationZ * r1 = new CLHEP::HepRotationZ(angle1);
144  double angle2 = myTheta;
145  CLHEP::HepRotationX * r2 = new CLHEP::HepRotationX(angle2);
146  double angle3 = 90.*deg;
147  CLHEP::HepRotationZ * r3 = new CLHEP::HepRotationZ(angle3);
148  (*fromCMStoTB) *= (*r3);
149  (*fromCMStoTB) *= (*r2);
150  (*fromCMStoTB) *= (*r1);
151 
152  CMStoTB = (*fromCMStoTB);
153 
154  delete fromCMStoTB;
155  delete r1;
156  delete r2;
157  delete r3;
158 }
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
EcalTBCrystalMap * theTestMap
void findCrystalAngles(const int thisCrysIndex, double &thisEta, double &thisPhi)

Member Data Documentation

bool TBPositionCalc::param_LogWeighted_
private

Definition at line 44 of file TBPositionCalc.h.

Double32_t TBPositionCalc::param_T0_
private

Definition at line 46 of file TBPositionCalc.h.

Double32_t TBPositionCalc::param_W0_
private

Definition at line 47 of file TBPositionCalc.h.

Double32_t TBPositionCalc::param_X0_
private

Definition at line 45 of file TBPositionCalc.h.

const CaloSubdetectorGeometry* TBPositionCalc::theGeometry_
private

Definition at line 51 of file TBPositionCalc.h.

EcalTBCrystalMap* TBPositionCalc::theTestMap
private

Definition at line 49 of file TBPositionCalc.h.