CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcRecShowerPosLog.cxx
Go to the documentation of this file.
1//
2// Logarithmic weighted position attribute reconstruction
3//
4// Created by Zhe Wang 2004, 5, 16
5//
7
8#include <iostream>
9
11#include "GaudiKernel/Bootstrap.h"
12#include "GaudiKernel/ISvcLocator.h"
13
15
17{
18 RecEmcFractionMap::const_iterator cit;
19 HepPoint3D pos(0,0,0);
20 HepPoint3D possum(0,0,0);
21 double w,wsum=0;
22
23 //cout<<"EmcRecShowerPosLog::Position Begin"<<endl;
24
25 IEmcRecGeoSvc* iGeoSvc;
26 ISvcLocator* svcLocator = Gaudi::svcLocator();
27 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
28 if(sc!=StatusCode::SUCCESS) {
29 //cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
30 }
31
33 double offset=Para.LogPosOffset();
34 //cout<<offset<<endl;
35
36
37 if(Para.PositionMode2()=="all") {
38 double etot=aShower.getEAll();
39 for(cit=aShower.Begin();cit!=aShower.End();cit++){
40 w=offset+log((cit->second.getEnergy()/etot)*cit->second.getFraction());
41 if(w>0){
42 wsum+=w;
43 pos=iGeoSvc->GetCFrontCenter(cit->second.getCellId());
44 possum+=pos*w;
45 }
46 }
47 } else if(Para.PositionMode2()=="3x3") {
48 double e3x3=aShower.e3x3();
49 RecEmcFractionMap fracMap3x3=aShower.getFractionMap3x3();
50 for(cit=fracMap3x3.begin();
51 cit!=fracMap3x3.end();
52 cit++) {
53 w=offset+log((cit->second.getEnergy()/e3x3)*cit->second.getFraction());
54 if(w>0){
55 wsum+=w;
56 pos=iGeoSvc->GetCFrontCenter(cit->second.getCellId());
57 possum+=pos*w;
58 }
59 }
60 } else {
61 double e5x5=aShower.e5x5();
62 RecEmcFractionMap fracMap5x5=aShower.getFractionMap5x5();
63 for(cit=fracMap5x5.begin();
64 cit!=fracMap5x5.end();
65 cit++) {
66 w=offset+log((cit->second.getEnergy()/e5x5)*cit->second.getFraction());
67 if(w>0){
68 wsum+=w;
69 pos=iGeoSvc->GetCFrontCenter(cit->second.getCellId());
70 possum+=pos*w;
71 }
72 }
73 }
74 if(wsum<=0) {
75 //cout<<"[[[[[[[[[[[[[[["<<wsum<<endl;
76 }
77 pos=possum/wsum;
78 //aShower.setPosition(pos);
79
80 //----------------------------------------------------------------------
81 //position correction
82 RecEmcID id = aShower.getShowerId();
83 const unsigned int module = EmcID::barrel_ec(id);;
84 const unsigned int thetaModule = EmcID::theta_module(id);
85 const unsigned int phiModule = EmcID::phi_module(id);
86 HepPoint3D posCorr(pos);
87
88 if(module==1) { //barrel
89 unsigned int theModule;
90 if(thetaModule>21) {
91 theModule = 43 - thetaModule;
92 id = EmcID::crystal_id(module,theModule,phiModule);
93 posCorr.setZ(-posCorr.z());
94 } else {
95 theModule = thetaModule;
96 }
97
98 double IRShift, parTheta[5];
99 if(theModule==21) {
100 IRShift = 0;
101 double par[5] = { 51.97, -0.1209, 6.175, -0.1431, -0.005497 };
102 for(int i=0;i<5;i++) {
103 parTheta[i] = par[i];
104 }
105 } else if(theModule==20) {
106 IRShift = 2.5;
107 double par[5] = { 56.31, -0.1135, 6.312, -1.216, -0.02978 };
108 for(int i=0;i<5;i++) {
109 parTheta[i] = par[i];
110 }
111 } else {
112 IRShift = 5.;
113 double par[5] = { 10.65, -0.2257, 2.216, -0.1562, -0.05552 };
114 for(int i=0;i<5;i++) {
115 parTheta[i] = par[i];
116 }
117 }
118
119 HepPoint3D IR(0,0,IRShift);
120 HepPoint3D center01, center23; //center of point0,1 and point2,3 in crystal
121 center01 = (iGeoSvc->GetCrystalPoint(id,0)+iGeoSvc->GetCrystalPoint(id,1))/2;
122 center23 = (iGeoSvc->GetCrystalPoint(id,2)+iGeoSvc->GetCrystalPoint(id,3))/2;
123
124 double theta01,theta23,length,d;
125 theta01 = (center01-IR).theta();
126 theta23 = (center23-IR).theta();
127 length = (center01-IR).mag();
128 d = length*tan(theta01-theta23); //length in x direction
129
130 double xIn,xOut,deltaTheta;
131 xIn = length*tan(theta01-(posCorr-IR).theta())-d/2;
132 xOut = xIn-( parTheta[0]*atan(xIn*parTheta[1]-parTheta[4])
133 + parTheta[2]*xIn + parTheta[3] );
134 deltaTheta = atan((xOut+d/2)/length)-atan((xIn+d/2)/length);
135 //cout<<"xIn: "<<xIn<<" xOut: "<<xOut<<" deltaTheta: "<<deltaTheta<<endl;
136 //cout<<"dx: "<<parTheta[0]*atan(xIn*parTheta[1]-parTheta[4])
137 // + parTheta[2]*xIn + parTheta[3] <<endl;
138
139 //obtained by photon, not used, just for comparison
140 double parPhi[5] = { 51.1, -0.1499, 7.62, 0.1301, 0.005581 };
141 double yIn,yOut,deltaPhi;
142 yIn = posCorr.phi() < 0 ? posCorr.phi()*180./CLHEP::pi+360.-phiModule*3.-1.1537
143 : posCorr.phi()*180./CLHEP::pi-phiModule*3.-1.1537;
144 yOut = parPhi[0]*atan(yIn*parPhi[1]-parPhi[4])+parPhi[2]*yIn+parPhi[3];
145 deltaPhi = yOut*CLHEP::pi/180.;
146 //
147
148 HepPoint3D rotateVector(0,1,0); //y axis
149 rotateVector.rotateZ(center01.phi());
150 posCorr.setZ(posCorr.z()-IRShift);
151 posCorr.rotate(-deltaTheta,rotateVector);
152 posCorr.setZ(posCorr.z()+IRShift);
153 //phi parameter is gotten by the average of e+ e- peak
154 posCorr.rotateZ(-0.002994);
155 //posCorr.rotateZ(-deltaPhi);
156
157 if(thetaModule>21) {
158 posCorr.setZ(-posCorr.z());
159 }
160 }
161
162 aShower.setPosition(posCorr);
163 ////////////////////////////
164 if(aShower.energy()<1e-5) return;
165
166 double r,theta,phi;
167 double dtheta,dphi,dx,dy,dz;
168
169 r = posCorr.mag();
170 theta = posCorr.theta();
171 phi = posCorr.phi();
172 //cout<<"energy: "<<aShower.energy()<<" theta: "<<theta<<" phi: "<<phi<<endl;
173
174 if(aShower.energy()>0) {
175 dtheta = Para.SigTheta(0)/sqrt(aShower.energy())+Para.SigTheta(1);
176 dphi = Para.SigPhi(0)/sqrt(aShower.energy())+Para.SigPhi(1);
177 }
178 else {
179 dtheta = 0;
180 dphi = 0;
181 }
182 //cout<<"dtheta: "<<dtheta<<" dphi: "<<dphi<<endl;
183
184 dx = fabs(iGeoSvc->GetBarrelR()*sin(phi)*dphi);
185 dy = fabs(iGeoSvc->GetBarrelR()*cos(phi)*dphi);
186 if(theta>0)
187 dz = fabs(iGeoSvc->GetBarrelR()*dtheta/(sin(theta)*sin(theta)));
188 else
189 dz = 0;
190 //cout<<" dx: "<<dx<<" dy: "<<dy<<" dz: "<<dz<<endl;
191
192 aShower.setDtheta(dtheta);
193 aShower.setDphi(dphi);
194
195 //----------------------------------------------------------------------
196 // Error matrix
197 HepSymMatrix matrix(3); //error matrix of r, theta, phi
198 matrix[0][0]=0;
199 matrix[1][1]=dtheta*dtheta;
200 matrix[2][2]=dphi*dphi;
201 matrix[0][1]=0;
202 matrix[0][2]=0;
203 matrix[1][2]=0;
204 //cout<<"matrix:\n"<<matrix<<endl;
205
206 HepMatrix matrix1(3,3),matrix2(3,3);
207 matrix1[0][0]=sin(theta)*cos(phi);
208 matrix1[0][1]=r*cos(theta)*cos(phi);
209 matrix1[0][2]=-r*sin(theta)*sin(phi);
210 matrix1[1][0]=sin(theta)*sin(phi);
211 matrix1[1][1]=r*cos(theta)*sin(phi);
212 matrix1[1][2]=r*sin(theta)*cos(phi);
213 matrix1[2][0]=cos(theta);
214 matrix1[2][1]=-r*sin(theta);
215 matrix1[2][2]=0;
216 //cout<<"matrix1:\n"<<matrix1<<endl;
217
218 for(int i=0;i<3;i++) {
219 for(int j=0;j<3;j++) {
220 matrix2[i][j]=matrix1[j][i];
221 }
222 }
223 //cout<<"matrix2:\n"<<matrix2<<endl;
224
225 HepMatrix matrix4(3,3);
226 matrix4=matrix1*matrix*matrix2;
227 //cout<<"matrix4:\n"<<matrix4<<endl;
228
229 HepSymMatrix matrix5(3); //error matrix of x, y, z
230 for(int i=0;i<3;i++) {
231 for(int j=0;j<=i;j++) {
232 matrix5[i][j]=matrix4[i][j];
233 }
234 }
235 //cout<<"matrix5:\n"<<matrix5<<endl;
236
237 aShower.setErrorMatrix(matrix5);
238
239 if(matrix5[0][0]>0) dx=sqrt(matrix5[0][0]);
240 if(matrix5[1][1]>0) dy=sqrt(matrix5[1][1]);
241 if(matrix5[2][2]>0) dz=sqrt(matrix5[2][2]);
242}
243
double tan(const BesAngle a)
Definition: BesAngle.h:216
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double length
Double_t etot
map< RecEmcID, RecEmcFraction, less< RecEmcID > > RecEmcFractionMap
void setDphi(double dpi)
Definition: DstEmcShower.h:66
double e3x3() const
Definition: DstEmcShower.h:48
void setDtheta(double dt)
Definition: DstEmcShower.h:65
double e5x5() const
Definition: DstEmcShower.h:49
void setPosition(const HepPoint3D &pos)
Definition: DstEmcShower.h:62
double energy() const
Definition: DstEmcShower.h:45
void setErrorMatrix(const HepSymMatrix &error)
Definition: DstEmcShower.h:75
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition: EmcID.cxx:71
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
double LogPosOffset() const
static EmcRecParameter & GetInstance()
std::string PositionMode2() const
double SigTheta(int n) const
double SigPhi(int n) const
virtual void Position(RecEmcShower &aShower)
virtual double GetBarrelR() const =0
virtual HepPoint3D GetCFrontCenter(const Identifier &id) const =0
virtual HepPoint3D GetCrystalPoint(const Identifier &id, const int i) const =0
RecEmcFractionMap::const_iterator End() const
RecEmcFractionMap getFractionMap5x5() const
RecEmcID getShowerId() const
Definition: RecEmcShower.h:55
RecEmcFractionMap::const_iterator Begin() const
RecEmcEnergy getEAll() const
Definition: RecEmcShower.h:92
RecEmcFractionMap getFractionMap3x3() const