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 (const std::vector< EBDetId > &passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap)
 
CLHEP::Hep3Vector CalculateTBPos (const std::vector< EBDetId > &passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap)
 
void computeRotation (int myCrystal, CLHEP::HepRotation &CMStoTB)
 
 TBPositionCalc (const 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 ( const 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 ( const std::vector< EBDetId > &  passedDetIds,
int  myCrystal,
EcalRecHitCollection const *  passedRecHitsMap 
)

Definition at line 59 of file TBPositionCalc.cc.

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

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

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

Definition at line 131 of file TBPositionCalc.cc.

References create_public_lumi_plots::exp, diffTwoXMLs::r1, and diffTwoXMLs::r2.

131  {
132 
133  // taking eta/phi of the crystal
134 
135  double myEta = 999.;
136  double myPhi = 999.;
137  double myTheta = 999.;
138  theTestMap->findCrystalAngles(MyCrystal, myEta, myPhi);
139  myTheta = 2.0*atan(exp(-myEta));
140 
141  // matrix
142  CLHEP::HepRotation * fromCMStoTB = new CLHEP::HepRotation();
143  double angle1 = 90.*deg - myPhi;
144  CLHEP::HepRotationZ * r1 = new CLHEP::HepRotationZ(angle1);
145  double angle2 = myTheta;
146  CLHEP::HepRotationX * r2 = new CLHEP::HepRotationX(angle2);
147  double angle3 = 90.*deg;
148  CLHEP::HepRotationZ * r3 = new CLHEP::HepRotationZ(angle3);
149  (*fromCMStoTB) *= (*r3);
150  (*fromCMStoTB) *= (*r2);
151  (*fromCMStoTB) *= (*r1);
152 
153  CMStoTB = (*fromCMStoTB);
154 
155  delete fromCMStoTB;
156  delete r1;
157  delete r2;
158  delete r3;
159 }
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.