#include <RecoTBCalo/EcalTBAnalysisCoreTools/interface/TBPositionCalc.h>
Public Member Functions | |
Hep3Vector | CalculateCMSPos (std::vector< EBDetId > passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap) |
Hep3Vector | CalculateTBPos (std::vector< EBDetId > passedDetIds, int myCrystal, EcalRecHitCollection const *passedRecHitsMap) |
void | computeRotation (int myCrystal, HepRotation &CMStoTB) |
TBPositionCalc () | |
TBPositionCalc (std::map< std::string, double > providedParameters, const std::string &mapFile, const CaloSubdetectorGeometry *passedGeometry) | |
~TBPositionCalc () | |
Private Attributes | |
bool | param_LogWeighted_ |
Double32_t | param_T0_ |
Double32_t | param_W0_ |
Double32_t | param_X0_ |
const CaloSubdetectorGeometry * | theGeometry_ |
EcalTBCrystalMap * | theTestMap |
Definition at line 25 of file TBPositionCalc.h.
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, param_LogWeighted_, param_T0_, param_W0_, param_X0_, theGeometry_, and theTestMap.
00006 { 00007 // barrel geometry initialization 00008 if(passedGeometry == NULL) 00009 throw(std::runtime_error("\n\n TBPositionCalc: wrong initialization.\n\n")); 00010 theGeometry_ = passedGeometry; 00011 00012 // parameters initialization 00013 param_LogWeighted_ = providedParameters.find("LogWeighted")->second; 00014 param_X0_ = providedParameters.find("X0")->second; 00015 param_T0_ = providedParameters.find("T0")->second; 00016 param_W0_ = providedParameters.find("W0")->second; 00017 00018 theTestMap = new EcalTBCrystalMap(fullMapName); 00019 }
TBPositionCalc::TBPositionCalc | ( | ) | [inline] |
TBPositionCalc::~TBPositionCalc | ( | ) |
Definition at line 21 of file TBPositionCalc.cc.
References theTestMap.
00022 { 00023 if (theTestMap) delete theTestMap; 00024 }
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(), CaloSubdetectorGeometry::getGeometry(), funct::log(), max, param_LogWeighted_, param_T0_, param_W0_, param_X0_, PV3DBase< T, PVType, FrameType >::phi(), radius(), funct::sin(), EBDetId::SMCRYSTALMODE, funct::sqrt(), theGeometry_, PV3DBase< T, PVType, FrameType >::theta(), weight, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by CalculateTBPos().
00058 { 00059 00060 // Calculate the total energy 00061 double thisEne = 0; 00062 double eTot = 0; 00063 EBDetId myId; 00064 std::vector<EBDetId>::iterator myIt; 00065 for (myIt = passedDetIds.begin(); myIt != passedDetIds.end(); myIt++) { 00066 myId = (*myIt); 00067 EcalRecHitCollection::const_iterator itt = passedRecHitsMap->find(myId); 00068 thisEne = itt->energy(); 00069 eTot += thisEne; 00070 } 00071 00072 // Calculate shower depth 00073 float depth = 0.; 00074 if(eTot<=0.) { 00075 edm::LogError("NegativeClusterEnergy") << "cluster with negative energy: " << eTot << ", setting depth to 0."; 00076 } else { 00077 depth = param_X0_ * (param_T0_ + log(eTot)); 00078 } 00079 00080 // Get position of the central crystal from shower depth 00081 EBDetId maxId_ = EBDetId(1, myCrystal, EBDetId::SMCRYSTALMODE); 00082 const CaloCellGeometry* center_cell = theGeometry_ -> getGeometry(maxId_); 00083 GlobalPoint center_pos = 00084 (dynamic_cast<const TruncatedPyramid*>(center_cell))->getPosition(depth); 00085 00086 // Loop over the hits collection 00087 double weight = 0; 00088 double total_weight = 0; 00089 double cluster_theta = 0; 00090 double cluster_phi = 0; 00091 std::vector<EBDetId>::iterator myIt2; 00092 for (myIt2 = passedDetIds.begin(); myIt2 != passedDetIds.end(); myIt2++) { 00093 00094 // getting weights 00095 myId = (*myIt2); 00096 EcalRecHitCollection::const_iterator itj = passedRecHitsMap->find(myId); 00097 double ener = itj->energy(); 00098 00099 if (param_LogWeighted_) { 00100 if(eTot<=0.) { weight = 0.; } 00101 else { weight = std::max(0., param_W0_ + log( fabs(ener)/eTot) ); } 00102 } else { 00103 weight = ener/eTot; 00104 } 00105 total_weight += weight; 00106 00107 // weighted position of this detId 00108 const CaloCellGeometry* jth_cell = theGeometry_->getGeometry(myId); 00109 GlobalPoint jth_pos = dynamic_cast<const TruncatedPyramid*>(jth_cell)->getPosition(depth); 00110 cluster_theta += weight*jth_pos.theta(); 00111 cluster_phi += weight*jth_pos.phi(); 00112 } 00113 00114 // normalizing 00115 cluster_theta /= total_weight; 00116 cluster_phi /= total_weight; 00117 if (cluster_phi > M_PI) { cluster_phi -= 2.*M_PI; } 00118 if (cluster_phi < -M_PI){ cluster_phi += 2.*M_PI; } 00119 00120 // position in the cms frame 00121 double radius = sqrt(center_pos.x()*center_pos.x() + center_pos.y()*center_pos.y() + center_pos.z()*center_pos.z()); 00122 double xpos = radius*cos(cluster_phi)*sin(cluster_theta); 00123 double ypos = radius*sin(cluster_phi)*sin(cluster_theta); 00124 double zpos = radius*cos(cluster_theta); 00125 00126 return Hep3Vector(xpos, ypos, zpos); 00127 }
Hep3Vector TBPositionCalc::CalculateTBPos | ( | std::vector< EBDetId > | passedDetIds, | |
int | myCrystal, | |||
EcalRecHitCollection const * | passedRecHitsMap | |||
) |
Definition at line 26 of file TBPositionCalc.cc.
References CalculateCMSPos(), computeRotation(), edm::SortedCollection< T, SORT >::end(), edm::SortedCollection< T, SORT >::find(), iter, and NULL.
00026 { 00027 00028 // throw an error if the cluster was not initialized properly 00029 if(passedRecHitsMap == NULL) 00030 throw(std::runtime_error("\n\n TBPositionCalc::CalculateTBPos called uninitialized.\n\n")); 00031 00032 // check DetIds are nonzero 00033 std::vector<EBDetId> validDetIds; 00034 std::vector<EBDetId>::iterator iter; 00035 for (iter = passedDetIds.begin(); iter != passedDetIds.end(); iter++) { 00036 if (((*iter) != DetId(0)) 00037 && (passedRecHitsMap->find(*iter) != passedRecHitsMap->end())) 00038 validDetIds.push_back(*iter); 00039 } 00040 passedDetIds.clear(); 00041 passedDetIds = validDetIds; 00042 00043 // computing the position in the cms frame 00044 Hep3Vector cmsPos = CalculateCMSPos(passedDetIds, myCrystal, passedRecHitsMap); 00045 00046 // computing the rotation matrix (from CMS to TB) 00047 HepRotation *CMStoTB = new HepRotation(); 00048 computeRotation(myCrystal, (*CMStoTB)); 00049 00050 // moving to testbeam frame 00051 Hep3Vector tbPos = (*CMStoTB)*cmsPos; 00052 delete CMStoTB; 00053 00054 return tbPos; 00055 }
Definition at line 130 of file TBPositionCalc.cc.
References funct::exp(), EcalTBCrystalMap::findCrystalAngles(), r1, r2, r3, and theTestMap.
Referenced by CalculateTBPos().
00130 { 00131 00132 // taking eta/phi of the crystal 00133 00134 double myEta = 999.; 00135 double myPhi = 999.; 00136 double myTheta = 999.; 00137 theTestMap->findCrystalAngles(MyCrystal, myEta, myPhi); 00138 myTheta = 2.0*atan(exp(-myEta)); 00139 00140 // matrix 00141 HepRotation * fromCMStoTB = new HepRotation(); 00142 double angle1 = 90.*deg - myPhi; 00143 HepRotationZ * r1 = new HepRotationZ(angle1); 00144 double angle2 = myTheta; 00145 HepRotationX * r2 = new HepRotationX(angle2); 00146 double angle3 = 90.*deg; 00147 HepRotationZ * r3 = new HepRotationZ(angle3); 00148 (*fromCMStoTB) *= (*r3); 00149 (*fromCMStoTB) *= (*r2); 00150 (*fromCMStoTB) *= (*r1); 00151 00152 CMStoTB = (*fromCMStoTB); 00153 00154 delete fromCMStoTB; 00155 delete r1; 00156 delete r2; 00157 delete r3; 00158 }
bool TBPositionCalc::param_LogWeighted_ [private] |
Definition at line 43 of file TBPositionCalc.h.
Referenced by CalculateCMSPos(), and TBPositionCalc().
Double32_t TBPositionCalc::param_T0_ [private] |
Definition at line 45 of file TBPositionCalc.h.
Referenced by CalculateCMSPos(), and TBPositionCalc().
Double32_t TBPositionCalc::param_W0_ [private] |
Definition at line 46 of file TBPositionCalc.h.
Referenced by CalculateCMSPos(), and TBPositionCalc().
Double32_t TBPositionCalc::param_X0_ [private] |
Definition at line 44 of file TBPositionCalc.h.
Referenced by CalculateCMSPos(), and TBPositionCalc().
const CaloSubdetectorGeometry* TBPositionCalc::theGeometry_ [private] |
Definition at line 50 of file TBPositionCalc.h.
Referenced by CalculateCMSPos(), and TBPositionCalc().
EcalTBCrystalMap* TBPositionCalc::theTestMap [private] |
Definition at line 48 of file TBPositionCalc.h.
Referenced by computeRotation(), TBPositionCalc(), and ~TBPositionCalc().