]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALShishKebabTrd1Module.cxx
speed up with binary search
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALShishKebabTrd1Module.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2010, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 // Main class for TRD1 geometry of Shish-Kebab case.
20 // Author: Alexei Pavlinov(WSU).
21 // Sep 20004 - Nov 2006; Apr 2010
22 // See web page with description of Shish-Kebab geometries:
23 // http://pdsfweb01.nersc.gov/~pavlinov/ALICE/SHISHKEBAB/RES/shishkebabALICE.html
24 // Nov 9,2006 - added case of 3X3
25 //_________________________________________________________________________
26
27 #include "AliLog.h"
28 #include "AliEMCALShishKebabTrd1Module.h"
29 #include "AliEMCALEMCGeometry.h"
30
31 #include <cassert>
32
33 ClassImp(AliEMCALShishKebabTrd1Module)
34
35   //AliEMCALEMCGeometry *AliEMCALShishKebabTrd1Module::fgGeometry=0; 
36   Double_t AliEMCALShishKebabTrd1Module::fga=0.; 
37   Double_t AliEMCALShishKebabTrd1Module::fga2=0.; 
38   Double_t AliEMCALShishKebabTrd1Module::fgb=0.; 
39   Double_t AliEMCALShishKebabTrd1Module::fgr=0.; 
40   Double_t AliEMCALShishKebabTrd1Module::fgangle=0.;   // around one degree 
41   Double_t AliEMCALShishKebabTrd1Module::fgtanBetta=0; //
42
43 //_____________________________________________________________________________
44 AliEMCALShishKebabTrd1Module::AliEMCALShishKebabTrd1Module(Double_t theta, AliEMCALEMCGeometry *g) 
45   : TNamed(),
46     fGeometry(g),
47     fOK(),
48     fA(0.),
49     fB(0.),
50     fThetaA(0.),
51     fTheta(theta),
52     fOK1(),
53     fOK2(),
54     fOB(),
55     fOB1(),
56     fOB2(),
57     fThetaOB1(0.),
58     fThetaOB2(0.),
59     fOK3X3(),
60     fORB(), 
61     fORT()
62
63   // ctor
64   
65   TString snam(g->GetName());
66   Int_t key=0;
67   if     (snam.Contains("v1",TString::kIgnoreCase)) key=1; //EMCAL_COMPLETEV1 vs EMCAL_COMPLETEv1 (or other)
68   
69   if(GetParameters()) {
70     DefineFirstModule(key);
71   }
72   DefineName(fTheta);
73   AliDebug(10,Form("AliEMCALShishKebabTrd1Module - first module key=%i:  theta %1.4f geometry %s\n",key,fTheta, g->GetName()));
74 }
75
76 //_____________________________________________________________________________
77 AliEMCALShishKebabTrd1Module::AliEMCALShishKebabTrd1Module(AliEMCALShishKebabTrd1Module &leftNeighbor) 
78   : TNamed(),
79     fGeometry(leftNeighbor.fGeometry),
80     fOK(),
81     fA(0.),
82     fB(0.),
83     fThetaA(0.),
84     fTheta(0.),
85     fOK1(),
86     fOK2(),
87     fOB(),
88     fOB1(),
89     fOB2(),
90     fThetaOB1(0.),
91     fThetaOB2(0.),
92     fOK3X3(),
93     fORB(), 
94     fORT()
95
96   
97   // ctor
98   
99   //  printf("** Left Neighbor : %s **\n", leftNeighbor.GetName());
100   fTheta  = leftNeighbor.GetTheta() - fgangle; 
101
102   TObject::SetUniqueID(leftNeighbor.GetUniqueID()+1);
103
104   Init(leftNeighbor.GetA(),leftNeighbor.GetB());
105 }
106
107 //________________________________________________________________
108 AliEMCALShishKebabTrd1Module::AliEMCALShishKebabTrd1Module(const AliEMCALShishKebabTrd1Module& mod) 
109   : TNamed(mod.GetName(),mod.GetTitle()),
110     fGeometry(mod.fGeometry),
111     fOK(mod.fOK),
112     fA(mod.fA),
113     fB(mod.fB),
114     fThetaA(mod.fThetaA),
115     fTheta(mod.fTheta),
116     fOK1(mod.fOK1),
117     fOK2(mod.fOK2),
118     fOB(mod.fOB),
119     fOB1(mod.fOB1),
120     fOB2(mod.fOB2),
121     fThetaOB1(mod.fThetaOB1),
122     fThetaOB2(mod.fThetaOB2),
123     fORB(mod.fORB),
124     fORT(mod.fORT)
125 {
126   // copy ctor
127   
128   for (Int_t i=0; i<3; i++) fOK3X3[i] = mod.fOK3X3[i];
129 }
130
131 //________________________________________________________________
132 void AliEMCALShishKebabTrd1Module::Init(Double_t A, Double_t B)
133
134   // Define parameter module from parameters A,B from previos.
135   Double_t yl = (fgb/2)*TMath::Sin(fTheta) + (fga/2)*TMath::Cos(fTheta) + fgr, y = yl;
136   Double_t xl = (yl - B) / A;     // y=A*x+B
137
138   //  Double_t xp1 = (fga/2. + fgb/2.*fgtanBetta)/(TMath::Sin(fTheta) + fgtanBetta*TMath::Cos(fTheta));
139   //  printf(" xp1 %9.3f \n ", xp1);
140   // xp1 == xp => both methods give the same results - 3-feb-05
141   Double_t alpha = TMath::Pi()/2. + fgangle/2;
142   Double_t xt = (fga+fga2)*TMath::Tan(fTheta)*TMath::Tan(alpha)/(4.*(1.-TMath::Tan(fTheta)*TMath::Tan(alpha)));
143   Double_t yt = xt / TMath::Tan(fTheta), xp = TMath::Sqrt(xt*xt + yt*yt);
144   Double_t x  = xl + xp;
145   fOK.Set(x, y);
146   //  printf(" yl %9.3f | xl %9.3f | xp %9.3f \n", yl, xl, xp);
147
148   // have to define A and B; 
149   Double_t yCprev = fgr + fga*TMath::Cos(fTheta);
150   Double_t xCprev = (yCprev - B) / A;
151   Double_t xA     = xCprev + fga*TMath::Sin(fTheta), yA = fgr;
152
153   fThetaA = fTheta - fgangle/2.;
154   fA = TMath::Tan(fThetaA); // !!
155   fB = yA - fA*xA;
156
157   DefineAllStaff();
158 }
159
160 void AliEMCALShishKebabTrd1Module::DefineAllStaff()
161
162   //Define some parameters      
163   DefineName(fTheta);
164   // Centers of cells - 2X2 case
165   Double_t kk1 = (fga+fga2)/(2.*4.); // kk1=kk2 
166
167   Double_t xk1 = fOK.X() - kk1*TMath::Sin(fTheta);
168   Double_t yk1 = fOK.Y() + kk1*TMath::Cos(fTheta) - fgr;
169   fOK1.Set(xk1,yk1);
170
171   Double_t xk2 = fOK.X() + kk1*TMath::Sin(fTheta);
172   Double_t yk2 = fOK.Y() - kk1*TMath::Cos(fTheta) - fgr;
173   fOK2.Set(xk2,yk2);
174
175   // Centers of cells - 3X3 case; Nov 9,2006
176   fOK3X3[1].Set(fOK.X(), fOK.Y()-fgr); // coincide with module center
177
178   kk1 = ((fga+fga2)/4. + fga/6.)/2.; 
179
180   xk1 = fOK.X() - kk1*TMath::Sin(fTheta);
181   yk1 = fOK.Y() + kk1*TMath::Cos(fTheta) - fgr;
182   fOK3X3[0].Set(xk1,yk1);
183
184   xk2 = fOK.X() + kk1*TMath::Sin(fTheta);
185   yk2 = fOK.Y() - kk1*TMath::Cos(fTheta) - fgr;
186   fOK3X3[2].Set(xk2,yk2);
187
188   // May 15, 2006; position of module(cells) center face 
189   fOB.Set(fOK.X()-fgb/2.*TMath::Cos(fTheta),  fOK.Y()-fgb/2.*TMath::Sin(fTheta)-fgr);
190   fOB1.Set(fOB.X()-fga/4.*TMath::Sin(fTheta), fOB.Y()+fga/4.*TMath::Cos(fTheta));
191   fOB2.Set(fOB.X()+fga/4.*TMath::Sin(fTheta), fOB.Y()-fga/4.*TMath::Cos(fTheta));
192   // Jul 30, 2007 - for taking into account a position of shower maximum
193   fThetaOB1 = fTheta - fgangle/4.; // ??
194   fThetaOB2 = fTheta + fgangle/4.;
195
196   // Position of right/top point of module
197   // Gives the posibility to estimate SM size in z direction
198   Double_t xBottom     = (fgr - fB) / fA;
199   Double_t yBottom     = fgr;
200   fORB.Set(xBottom, yBottom);
201
202   Double_t l = fgb / TMath::Cos(fgangle/2.); // length of lateral module side
203   Double_t xTop = xBottom + l*TMath::Cos(TMath::ATan(fA));
204   Double_t yTop = fA*xTop + fB;
205   fORT.Set(xTop, yTop);
206 }
207
208 //_____________________________________________________________________________
209 void AliEMCALShishKebabTrd1Module::DefineFirstModule(const Int_t key)
210 {
211   //    Oct 23-25, 2010
212   //  key=0 - zero tilt of first module;
213   //  key=1 - angle=fgangle/2 = 0.75 degree.
214   //  This is what we have in produced SM. 
215
216   // Define first module
217   if(key==0) {
218     // theta in radians ; first object theta=pi/2.
219     fTheta = TMath::PiOver2();
220     fOK.Set(fga2/2., fgr + fgb/2.); // position the center of module vs o
221
222     // parameters of right line : y = A*z + B in system where zero point is IP.
223     fThetaA = fTheta - fgangle/2.;
224     fA      = TMath::Tan(fThetaA);
225     Double_t xA = fga/2. + fga2/2.;
226     Double_t yA = fgr;
227     fB = yA - fA*xA;
228
229   } else if(key==1) {
230     // theta in radians ; first object theta = 90-0.75 = 89.25 degree
231     fTheta = 89.25*TMath::DegToRad();
232     Double_t al1 = fgangle/2.;
233     Double_t x = 0.5*(fga*TMath::Cos(al1) + fgb*TMath::Sin(al1));
234     Double_t y = 0.5*(fgb + fga*TMath::Sin(al1))*TMath::Cos(al1);
235     fOK.Set(x, fgr + y);
236     // parameters of right line : y = A*z + B in system where zero point is IP.
237     fThetaA = fTheta - fgangle/2.;
238     fA      = TMath::Tan(fThetaA);
239     Double_t xA = fga*TMath::Cos(al1);
240     Double_t yA = fgr;
241     fB = yA - fA*xA;
242
243   } else {
244     printf("<E> key=%i : wrong case \n",key);
245     assert(0);
246   }
247   TObject::SetUniqueID(1); //
248
249   DefineAllStaff();
250 }
251
252 //_____________________________________________________________________________
253 void AliEMCALShishKebabTrd1Module::DefineName(Double_t theta)
254 {
255   // Define name of object
256   SetName(Form("%2i(%5.2f)", TObject::GetUniqueID(), theta*TMath::RadToDeg()));
257 }
258
259 //_____________________________________________________________________________
260 Bool_t AliEMCALShishKebabTrd1Module::GetParameters()
261 {
262   
263   // Get needing module parameters from EMCAL geometry
264   
265   if(!fGeometry) {
266     Warning("GetParameters()"," No geometry ");
267     return kFALSE; 
268   }  
269   
270   TString sn(fGeometry->GetName()); // 2-Feb-05
271   sn.ToUpper();
272   
273   fga        = (Double_t)fGeometry->GetEtaModuleSize();
274   fgb        = (Double_t)fGeometry->GetLongModuleSize();
275   fgangle    = Double_t(fGeometry->GetTrd1Angle())*TMath::DegToRad();
276   fgtanBetta = TMath::Tan(fgangle/2.);
277   fgr        = (Double_t)fGeometry->GetIPDistance();
278
279   fgr += fGeometry->GetSteelFrontThickness();
280
281   fga2       = Double_t(fGeometry->Get2Trd1Dx2());
282   //PH  PrintShish(0);
283   return kTRUE;
284 }
285
286 // service methods
287 //_____________________________________________________________________________
288 void AliEMCALShishKebabTrd1Module::PrintShish(int pri) const
289 {
290   // service method
291   if(pri>=0) { 
292     if(pri >= 1) {
293       printf("PrintShish() \n a %7.3f:%7.3f | b %7.2f | r %7.2f \n TRD1 angle %7.6f(%5.2f) | tanBetta %7.6f", 
294       fga, fga2, fgb, fgr, fgangle, fgangle*TMath::RadToDeg(), fgtanBetta);
295       printf(" fTheta %f : %5.2f : cos(theta) %f\n", 
296       fTheta, GetThetaInDegree(),TMath::Cos(fTheta)); 
297       printf(" OK : %i |%s| theta %f :  phi = %f(%5.2f) \n", 
298       GetUniqueID(), GetName(), fTheta, fOK.Phi(),fOK.Phi()*TMath::RadToDeg());
299     }
300     printf(" y %9.3f x %9.3f xrb %9.3f (right bottom on r=%9.3f ) \n", 
301            fOK.X(), fOK.Y(), fORB.X(),fORB.Y());
302     if(pri>=2) {
303       printf(" A %f B %f | fThetaA %7.6f(%5.2f)\n", fA,fB, fThetaA,fThetaA*TMath::RadToDeg());
304       printf(" fOK  : X %9.4f: Y %9.4f : eta  %5.3f\n",  fOK.X(), fOK.Y(), GetEtaOfCenterOfModule());
305       printf(" fOK1 : X %9.4f: Y %9.4f :   (local, ieta=2)\n", fOK1.X(), fOK1.Y());
306       printf(" fOK2 : X %9.4f: Y %9.4f :   (local, ieta=1)\n\n", fOK2.X(), fOK2.Y());
307       printf(" fOB  : X %9.4f: Y %9.4f \n", fOB.X(), fOB.Y());
308       printf(" fOB1 : X %9.4f: Y %9.4f (local, ieta=2)\n", fOB1.X(), fOB1.Y());
309       printf(" fOB2 : X %9.4f: Y %9.4f (local, ieta=1)\n", fOB2.X(), fOB2.Y());
310       // 3X3 
311       printf(" 3X3 \n");
312       for(int ieta=0; ieta<3; ieta++) {
313         printf(" fOK3X3[%i] : X %9.4f: Y %9.4f (local) \n", ieta, fOK3X3[ieta].X(), fOK3X3[ieta].Y());
314       }
315       //      fOK.Dump();
316       GetMaxEtaOfModule(pri);
317     }
318   }
319 }
320
321 //_____________________________________________________________________________
322 Double_t  AliEMCALShishKebabTrd1Module::GetThetaInDegree() const 
323 {
324   return fTheta*TMath::RadToDeg();
325 }
326
327 //_____________________________________________________________________________
328 Double_t  AliEMCALShishKebabTrd1Module::GetEtaOfCenterOfModule() const 
329
330   return -TMath::Log(TMath::Tan(fOK.Phi()/2.));
331 }
332
333 //_____________________________________________________________________________
334 void AliEMCALShishKebabTrd1Module::GetPositionAtCenterCellLine(Int_t ieta, Double_t dist, TVector2 &v)
335 {
336   // Jul 30, 2007
337   static Double_t theta=0., x=0., y=0.;
338   if(ieta==0) {    
339     v     = fOB2;
340     theta = fTheta;
341   } else if(ieta==1) {
342     v     = fOB1;
343     theta = fTheta;
344   } else {
345     assert(0);
346   }
347   
348   x = v.X() + TMath::Cos(theta) * dist;
349   y = v.Y() + TMath::Sin(theta) * dist;
350   //  printf(" GetPositionAtCenterCellLine() %s : dist %f : ieta %i : x %f %f v.X() | y %f %f v.Y() : cos %f sin %f \n", 
351   //GetName(), dist, ieta, v.X(),x, y,v.Y(),TMath::Cos(theta),TMath::Sin(theta));
352   v.Set(x,y);
353 }  
354
355
356 //_____________________________________________________________________________
357 Double_t  AliEMCALShishKebabTrd1Module::GetMaxEtaOfModule(int pri) const 
358
359   // Right bottom point of module
360   Double_t thetaBottom = TMath::ATan2(fORB.Y(),fORB.X());
361   Double_t etaBottom   = ThetaToEta(thetaBottom);
362   // Right top point of module
363   Double_t thetaTop = TMath::ATan2(fORT.Y(),fORT.X());
364   Double_t etaTop   = ThetaToEta(thetaTop);
365
366   if(pri) { 
367     printf(" Right bottom point of module : eta %5.4f : theta %6.4f (%6.2f) : x(zglob) %7.2f y(phi) %5.2f \n", 
368            etaBottom, thetaBottom, thetaBottom * TMath::RadToDeg(), fORB.X(), fORB.Y());
369     printf(" Right    top point of module : eta %5.4f : theta %6.4f (%6.2f) : x(zglob) %7.2f y(phi) %5.2f \n", 
370            etaTop, thetaTop, thetaTop * TMath::RadToDeg(), fORT.X(), fORT.Y());
371   }
372   return etaBottom>etaTop ? etaBottom : etaTop;
373 }