]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALShishKebabModule.cxx
Updated LUT for the TOF alignable volumes
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALShishKebabModule.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2004, 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 //*-- Author: Aleksei Pavlinov(WSU)
19 #include "AliEMCALShishKebabModule.h"
20 #include "AliEMCALGeometry.h"
21 #include <TMath.h>
22 #include <TGraph.h>
23
24 #include <assert.h>
25
26 ClassImp(AliEMCALShishKebabModule)
27
28   AliEMCALGeometry *AliEMCALShishKebabModule::fgGeometry=0; 
29   Double_t AliEMCALShishKebabModule::fga=0.; 
30   Double_t AliEMCALShishKebabModule::fgb=0.; 
31   Double_t AliEMCALShishKebabModule::fgr=0.; 
32
33 AliEMCALShishKebabModule::AliEMCALShishKebabModule(double theta) : TNamed()
34 { // theta in radians ; first object shold be with theta=pi/2.
35   fTheta = theta;
36   if(fgGeometry==0) {
37     if(GetParameters()) {
38       DefineFirstModule();
39     }
40   } else Warning("AliEMCALShishKebabModule(theta)","You should call this constractor just once !!");
41   DefineName(fTheta);
42 }
43
44 AliEMCALShishKebabModule::AliEMCALShishKebabModule(AliEMCALShishKebabModule &leftNeighbor) : TNamed()
45 { // 22-sep-04
46   TObject::SetUniqueID(leftNeighbor.GetUniqueID()+1);
47   Init(leftNeighbor.GetA(),leftNeighbor.GetB());
48 }
49
50 void AliEMCALShishKebabModule::Init(double A, double B)
51
52   Double_t thetaMin, thetaMax, par[4];
53   Int_t npar=0;
54   if(A<0){
55     //    DefineSecondModuleFirstAssumption();
56     thetaMax = TMath::ATan2(fgr, 1.4*fga);
57     thetaMin = TMath::ATan2(fgr, 1.6*fga);
58     fTheta   = Solve(AliEMCALShishKebabModule::Y2, thetaMin,thetaMax,npar,par);
59   } else{
60     npar = 4;
61     par[0] = fga;
62     par[1] = fgr;
63     par[2] = A;
64     par[3] = B;
65     Double_t x = fgr/A;
66     thetaMax = TMath::ATan2(fgr,x + 0.5*fga);
67     thetaMin = TMath::ATan2(fgr,x + 1.5*fga);
68     fTheta   = Solve(AliEMCALShishKebabModule::YALL, thetaMin,thetaMax,npar,par);
69   }
70
71   Double_t rOK = fgr / TMath::Sin(fTheta) + (fga/2.)/TMath::Tan(fTheta) + fgb/2.;
72   fOK.SetMagPhi(rOK, fTheta); 
73   // have to define A and B
74   fA = TMath::Tan(fTheta);
75   fB = -fga/(2.*TMath::Cos(fTheta));
76   DefineName(fTheta);
77 }
78
79 void AliEMCALShishKebabModule::DefineFirstModule()
80 {
81   fOK.Set(fga/2., fgr + fgb/2.); // position the center of module vs o
82
83   fB = fga/2.;    // z=fB
84   fA = -999.;     // fA=infinite in this case
85   TObject::SetUniqueID(1); //
86 }
87
88 void AliEMCALShishKebabModule::DefineSecondModuleFirstAssumption()
89 { // Keep for testing and checking
90   // cos(theta) << 1, theta ~ pi/2.; a/r = 11.4/462.54 = 0.0246465 << 1; 
91   // theta=1.53382  from this case; theta=1.533869 from TGraph::Zero 
92   Double_t x = (3.*fga)/(2.*fgr);
93   fTheta = TMath::ACos(x);
94   /*
95   Double_t rOK = fgr / TMath::Sin(fTheta) + (fga/2.)/TMath::Tan(fTheta) + fgb/2.;
96   fOK.SetMagPhi(rOK, fTheta); 
97   // have to define A and B
98   fA = TMath::Tan(fTheta);
99   fB = -fga/(2.*TMath::Cos(fTheta));
100   DefineName(fTheta);
101   */
102 }
103
104 Double_t AliEMCALShishKebabModule::Solve(Double_t (*fcn)(Double_t*,Double_t*), 
105 Double_t xmin, Double_t xmax, Int_t npar, Double_t *par, Double_t eps, Int_t maxIter)
106 {
107   if(npar); // unused now
108   TGraph gr;
109   double X,Y;
110   Int_t k = 0;
111   gr.Zero(k, xmin,xmax, eps, X,Y, maxIter); // remember initial interval
112   while(k!=2) {
113     Y = fcn(&X, par); 
114     gr.Zero(k, xmin,xmax, eps, X,Y, maxIter);
115   }
116   return X;
117 }
118
119 Double_t AliEMCALShishKebabModule::Y2(double *x, double *par)
120 { // For position calulation of second module
121   if(par);
122   Double_t theta = x[0];
123   Double_t cos = TMath::Cos(theta);
124   Double_t sin = TMath::Sin(theta);
125   Double_t y1  = fgr*cos/sin + fga/(2.*sin) - fga*sin;       
126   Double_t y2  = fga, y = y1-y2;;
127   //  printf(" theta %f Y %12.5e \n", theta, y);
128   return y;
129 }
130
131 Double_t AliEMCALShishKebabModule::YALL(double *x, double *par)
132 { // For position calulation of 3th, 4th to 30th modules
133   Double_t a=par[0], r=par[1], A=par[2], B=par[3]; 
134   Double_t theta = x[0];
135   Double_t cos = TMath::Cos(theta);
136   Double_t sin = TMath::Sin(theta);
137
138   Double_t y1  = r + a*cos;       
139   Double_t y2  = A*(r*cos/sin + a/(2.*sin) - a*sin) + B;
140   Double_t y   = y1-y2;
141   //  printf(" theta %f Y %12.5e \n", theta, y);
142   return y;
143 }
144
145 void AliEMCALShishKebabModule::DefineName(double theta)
146 {
147   char name[100];
148   // sprintf(name,"theta_%5.2f",theta*180./TMath::Pi());
149   sprintf(name,"%2i(%5.2f)", TObject::GetUniqueID(), theta*180./TMath::Pi());
150   SetName(name);
151 }
152
153 Bool_t AliEMCALShishKebabModule::GetParameters()
154 {
155   fgGeometry = AliEMCALGeometry::GetInstance();
156   //  if(!fgGeometry) assert(0);
157   if(!fgGeometry) {
158     Warning("GetParameters()"," No geometry ");
159     return kFALSE; 
160   }
161
162   fga = (Double_t)fgGeometry->GetPhiModuleSize();
163   fgb = (Double_t)fgGeometry->GetLongModuleSize();
164   fgr = (Double_t)(fgGeometry->GetIPDistance() + fgGeometry->GetSteelFrontThickness());
165   PrintShish(0);
166   return kTRUE;
167 }
168
169 // service methods
170 void AliEMCALShishKebabModule::PrintShish(int pri) const
171 {
172   if(pri>=0) {
173     Info("PrintShish()", " a %7.2f | b %7.2f | r %7.2f ", fga, fgb, fgr);
174     printf(" fTheta %f : %5.2f : cos(theta) %f\n", fTheta, GetThetaInDegree(),TMath::Cos(fTheta)); 
175     if(pri>0) {
176       printf("%i %s | theta %f -> %f\n", GetUniqueID(), GetName(), fTheta, fOK.Phi());
177       printf(" A %f B %f \n", fA, fB);
178
179       fOK.Dump();
180     }
181   }
182 }
183