19{
20 RecEmcFractionMap::const_iterator cit;
23 double w,wsum=0;
24
25
26
28 ISvcLocator* svcLocator = Gaudi::svcLocator();
29 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
30 if(sc!=StatusCode::SUCCESS) {
31
32 }
33
35
37
38
39 double e5x5 = -99999;
42 for(cit=aShower.
Begin();cit!=aShower.
End();cit++){
43 w=offset+log((cit->second.getEnergy()/
etot)*cit->second.getFraction());
44 if(w>0){
45 wsum+=w;
47 possum+=pos*w;
48 }
49 }
51 double e3x3=aShower.
e3x3();
53 for(cit=fracMap3x3.begin();cit!=fracMap3x3.end();cit++) {
54 w=offset+log((cit->second.getEnergy()/e3x3)*cit->second.getFraction());
55 if(w>0){
56 wsum+=w;
58 possum+=pos*w;
59 }
60 }
61 } else {
64 for(cit=fracMap5x5.begin();cit!=fracMap5x5.end();cit++) {
65 w=offset+log((cit->second.getEnergy()/e5x5)*cit->second.getFraction());
66 if(w>0){
67 wsum+=w;
69 possum+=pos*w;
70 }
71 }
72 }
73 if(wsum<=0) {
74
75 }
76 pos=possum/wsum;
77
78
79
80
86
87 if(module==1) {
88
89
90 double IRShift=0, parTheta[5],parPhi[5];
91
92 unsigned int theModule;
93 if(thetaModule>21) {
94 theModule = 43 - thetaModule;
96 posCorr.setZ(-posCorr.z());
97 } else {
98 theModule = thetaModule;
99 }
100
101
102 if(theModule==21) {
103 IRShift = 0;
104 } else if(theModule==20) {
105 IRShift = 2.5;
106 } else {
107 IRShift = 5.;
108 }
110
111
112
114
115 for(int i=0;i<5;i++){
116 if(theModule==21) {
117 double par[5] = { 51.97, -0.1209, 6.175, -0.1431, -0.005497 };
118 parTheta[i] = par[i];
119 }else if(theModule==20){
120 double par[5] = { 56.31, -0.1135, 6.312, -1.216, -0.02978 };
121 parTheta[i] = par[i];
122 }else{
123 double par[5] = { 10.65, -0.2257, 2.216, -0.1562, -0.05552 };
124 parTheta[i] = par[i];
125 }
126 }
127
129
130 for(int i=0;i<5;i++){
131
133 else if(e5x5<=1.0 && e5x5>0.5) parTheta[i] = Para.
BarrLogThetaPara(theModule+22,i);
135
137 else if(e5x5<=1.0 && e5x5>0.5) parPhi[i] = Para.
BarrLogPhiPara(theModule+22,i);
138 else if(e5x5<=0.5) parPhi[i] = Para.
BarrLogPhiPara(theModule+44,i);
139
140
141 }
142
143 }
144
148
149 double theta01,theta23,length,d;
150 theta01 = (center01-IR).theta();
151 theta23 = (center23-IR).theta();
152 length = (center01-IR).mag();
153 d = length*
tan(theta01-theta23);
154
155 double xIn,xOut,deltaTheta;
156 xIn = length*
tan(theta01-(posCorr-IR).theta())-d/2;
157 xOut = xIn-( parTheta[0]*atan(xIn*parTheta[1]-parTheta[4])+ parTheta[2]*xIn + parTheta[3] );
158 deltaTheta = atan((xOut+d/2)/length)-atan((xIn+d/2)/length);
159
160
161
162 double yIn,deltaY,deltaPhi;
163
164
165 if(phiModule==0){
166 yIn = posCorr.phi()*180./CLHEP::pi -phiModule*3. - 1.843;
167 }else if (phiModule==119){
168 yIn = posCorr.phi()*180./CLHEP::pi + 360.-phiModule*3. -1.843;
169 }else {
170 yIn = posCorr.phi() < 0 ? posCorr.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
171 : posCorr.phi()*180./CLHEP::pi-phiModule*3.-1.843;
172 }
173
174
175 deltaY = parPhi[0]*atan(yIn*parPhi[1]-parPhi[4])+parPhi[2]*yIn+parPhi[3];
176 deltaPhi = deltaY*CLHEP::pi/180.;
177
179 rotateVector.rotateZ(center01.phi());
180 posCorr.setZ(posCorr.z()-IRShift);
181 posCorr.rotate(-deltaTheta,rotateVector);
182 posCorr.setZ(posCorr.z()+IRShift);
183
185 posCorr.rotateZ(-0.002994);
187 posCorr.rotateZ(-deltaPhi);
188 }
189
190 if(thetaModule>21) {
191 posCorr.setZ(-posCorr.z());
192 }
193
194 double lengthemc;
195 lengthemc =
abs(posCorr.z()/
cos(posCorr.theta()));
196
197 double posDataCorPar;
200 posCorr.setTheta(posCorr.theta()-posDataCorPar/lengthemc);
201 }
202
203
204 double posMCCorPar;
207 posCorr.setTheta(posCorr.theta()-posMCCorPar/lengthemc);
208 }
209
210 } else {
212
213 double IRShift=0, parTheta[5],parPhi[5];
214
215 if(module==0){
216
217 IRShift = 10;
218
219 for(int i=0;i<5;i++) {
220
221
223 else if(e5x5<=1.0 && e5x5>0.5) parTheta[i] = Para.
EastLogThetaPara(thetaModule+6,i);
225
227 else if(e5x5<=1.0 && e5x5>0.5) parPhi[i] = Para.
EastLogPhiPara(1,i);
229 }
230
231 }else if (module==2){
232 IRShift = -10;
233 for(int i=0;i<5;i++){
234
236 else if(e5x5<=1.0 && e5x5>0.5) parTheta[i] = Para.
WestLogThetaPara(thetaModule+6,i);
238
240 else if(e5x5<=1.0 && e5x5>0.5) parPhi[i] = Para.
WestLogPhiPara(1,i);
242
243 }
244
245 }
246
248
249 double theta12=-9999,theta03=-9999,theta23=-9999,theta14=-9999,delta=-9999;
250 double phi01=-9999,phi23=-9999,phi12=-9999,phi34=-9999,deltaphi=-9999;
251 double xIn,deltaX,deltaTheta,yIn,deltaY,deltaPhi;
252
253 double posphi=posCorr.phi();
254 if(phiModule==0){
255 posphi = posphi;
256 }else if( ((thetaModule==0||thetaModule==1)&&phiModule==63)
257 ||((thetaModule==2||thetaModule==3)&&phiModule==79)
258 ||((thetaModule==4||thetaModule==5)&&phiModule==95)
259 ){
260 posphi = posphi+2*CLHEP::pi;
261 }else {
262 posphi = posphi < 0 ? posphi+2*CLHEP::pi : posphi;
263 }
264
265 HepPoint3D center,center01, center23, center12,center03,center34,center14;
266
267
268 if( (thetaModule==1&&((phiModule+3)%4 == 0||(phiModule+2)%4 == 0))
269 ||(thetaModule==3&&((phiModule+4)%5 == 0||(phiModule+3)%5 == 0||(phiModule+2)%5 == 0)))
270 {
271
274 center=center23;
275 theta23 = (center23 - IR).theta();
276 theta14 = (center14 - IR).theta();
277 delta = theta14 - theta23;
278 xIn = (((posCorr-IR).theta() - theta23) - delta*0.5)/delta;
279
280
283 phi12 = center12.phi();
284 phi34 = center34.phi();
285
286 phi12 = phi12 <0 ? phi12+2*CLHEP::pi : phi12;
287 phi34 = phi34 <0 ? phi34+2*CLHEP::pi : phi34;
288 deltaphi = phi34 - phi12;
289 yIn = ((posphi - phi12) - deltaphi*0.5)/deltaphi;
290
291 } else {
292
295 center=center12;
296
297 theta12 = (center12 - IR).theta();
298 theta03 = (center03 - IR).theta();
299 delta = theta03 - theta12;
300 xIn = (((posCorr-IR).theta() - theta12) - delta*0.5)/delta;
301
302
305 phi01 = center01.phi();
306 phi23 = center23.phi();
307 phi01 = phi01 <0 ? phi01+2*CLHEP::pi : phi01;
308 phi23 = phi23 <0 ? phi23+2*CLHEP::pi : phi23;
309 deltaphi = phi23 - phi01;
310 yIn = ((posphi - phi01) - deltaphi*0.5)/deltaphi;
311
312 }
313
314 deltaX = parTheta[0]*atan(xIn*parTheta[1]-parTheta[4]) + parTheta[2]*xIn + parTheta[3] ;
315 deltaTheta = deltaX*delta;
316
317 deltaY = parPhi[0]*atan(yIn*parPhi[1]-parPhi[4]) + parPhi[2]*yIn + parPhi[3] ;
318 deltaPhi = deltaY*deltaphi;
319
321 rotateVector.rotateZ(center.phi());
322 posCorr.setZ(posCorr.z()-IRShift);
323 posCorr.rotate(-deltaTheta,rotateVector);
324 posCorr.setZ(posCorr.z()+IRShift);
325 posCorr.rotateZ(-deltaPhi);
326
327 double lengthemc;
328 lengthemc =
abs(posCorr.z()/
cos(posCorr.theta()));
329 double posDataCorPar;
331 if(module==0) posDataCorPar=Para.
EastPosDataCor(thetaModule,phiModule);
332 if(module==2) posDataCorPar=Para.
WestPosDataCor(thetaModule,phiModule);
333 posCorr.setTheta(posCorr.theta()-posDataCorPar/lengthemc);
334 }
335 }
336
337 }
338
339
340
341
343
346 }
347
348 if(aShower.
energy()<1e-5)
return;
349
350 double r,theta,phi;
351 double dtheta,dphi,dx,dy,dz;
352
353 r = posCorr.mag();
354 theta = posCorr.theta();
355 phi = posCorr.phi();
356
357
361 }
362 else {
363 dtheta = 0;
364 dphi = 0;
365 }
366
367
370 if(theta>0)
372 else
373 dz = 0;
374
375
378
379
380
381 HepSymMatrix matrix(3);
382 matrix[0][0]=0;
383 matrix[1][1]=dtheta*dtheta;
384 matrix[2][2]=dphi*dphi;
385 matrix[0][1]=0;
386 matrix[0][2]=0;
387 matrix[1][2]=0;
388
389
390 HepMatrix matrix1(3,3),matrix2(3,3);
391 matrix1[0][0]=
sin(theta)*
cos(phi);
392 matrix1[0][1]=r*
cos(theta)*
cos(phi);
393 matrix1[0][2]=-r*
sin(theta)*
sin(phi);
394 matrix1[1][0]=
sin(theta)*
sin(phi);
395 matrix1[1][1]=r*
cos(theta)*
sin(phi);
396 matrix1[1][2]=r*
sin(theta)*
cos(phi);
397 matrix1[2][0]=
cos(theta);
398 matrix1[2][1]=-r*
sin(theta);
399 matrix1[2][2]=0;
400
401
402 for(int i=0;i<3;i++) {
403 for(int j=0;j<3;j++) {
404 matrix2[i][j]=matrix1[j][i];
405 }
406 }
407
408
409 HepMatrix matrix4(3,3);
410 matrix4=matrix1*matrix*matrix2;
411
412
413 HepSymMatrix matrix5(3);
414 for(int i=0;i<3;i++) {
415 for(int j=0;j<=i;j++) {
416 matrix5[i][j]=matrix4[i][j];
417 }
418 }
419
420
422
423 if(matrix5[0][0]>0) dx=sqrt(matrix5[0][0]);
424 if(matrix5[1][1]>0) dy=sqrt(matrix5[1][1]);
425 if(matrix5[2][2]>0) dz=sqrt(matrix5[2][2]);
426}
map< RecEmcID, RecEmcFraction, less< RecEmcID > > RecEmcFractionMap
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
void setDtheta(double dt)
void setPosition(const HepPoint3D &pos)
void setErrorMatrix(const HepSymMatrix &error)
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static unsigned int theta_module(const Identifier &id)
static unsigned int phi_module(const Identifier &id)
double LogPosOffset() const
double BarrPosMCCor(int ntheta, int nphi) const
static EmcRecParameter & GetInstance()
double EastPosDataCor(int ntheta, int nphi) const
double WestPosDataCor(int ntheta, int nphi) const
double BarrLogPhiPara(int n, int m) const
double MethodMode() const
std::string PositionMode2() const
double SigTheta(int n) const
double WestLogThetaPara(int n, int m) const
double BarrPosDataCor(int ntheta, int nphi) const
double BarrLogThetaPara(int n, int m) const
double WestLogPhiPara(int n, int m) const
double EastLogPhiPara(int n, int m) const
double EastLogThetaPara(int n, int m) const
double SigPhi(int n) const
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
RecEmcFractionMap::const_iterator Begin() const
RecEmcEnergy getEAll() const
RecEmcFractionMap getFractionMap3x3() const