]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALSurvey.cxx
Remove old pi0 calibration classes, new class in PWG4/CaloCalib/AliAnalysisTaskEMCALP...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALSurvey.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 // Objects of this class read txt file with survey data
19 // and convert the data into AliAlignObjParams of alignable EMCAL volumes.
20 // AliEMCALSurvey inherits TObject only to use AliLog "functions".
21 //
22 // This whole thing is just a dummy class with dummy variables until
23 // the actual survey points are determined.  For now I assumed that
24 // the x,y center and starting z value of each supermodule is the only
25 // surveyed point
26 //
27 // J.L. Klay - Cal Poly
28 // 28-Feb-2008
29 //
30
31 #include <fstream>
32
33 #include <TClonesArray.h>
34 #include <TGeoManager.h>
35 #include <TString.h>
36 #include <TMath.h>
37
38 #include "AliSurveyObj.h"
39
40 #include "AliAlignObjParams.h"
41 #include "AliEMCALGeometry.h"
42 #include "AliEMCALSurvey.h"
43 #include "AliLog.h"
44
45 ClassImp(AliEMCALSurvey)
46
47 //____________________________________________________________________________
48 AliEMCALSurvey::AliEMCALSurvey()
49                 : fNSuperModule(0),
50                   fSuperModuleData(0)
51 {
52   //Default constructor.
53 }
54
55 namespace {
56
57   //for now, measurements assumed to be taken at x,y center and
58   //nominal starting z value of each supermodule
59
60   struct AliEMCALSuperModuleCoords {
61     Double_t fX1; //x coordinate of the first supermodule point
62     Double_t fY1; //y coordinate of the first supermodule point
63     Double_t fZ1; //z coordinate of the first supermodule point
64   };
65
66 }
67
68 //____________________________________________________________________________
69 AliEMCALSurvey::AliEMCALSurvey(const TString &txtFileName)
70                 : fNSuperModule(0),
71                   fSuperModuleData(0)
72 {
73   //Read survey data from txt file.
74   const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
75   if (!geom) {
76     AliError("Cannot obtain AliEMCALGeometry instance.");
77     return;
78   }
79
80   std::ifstream inputFile(txtFileName.Data());
81   if (!inputFile) {
82     AliError(("Cannot open the survey file " + txtFileName).Data());
83     return;
84   }
85
86   fNSuperModule = geom->GetNumberOfSuperModules();
87
88   Int_t dummyInt = 0;
89   Double_t *xReal = new Double_t[fNSuperModule];
90   Double_t *yReal = new Double_t[fNSuperModule];
91   Double_t *zReal = new Double_t[fNSuperModule];
92
93   for (Int_t i = 0; i < fNSuperModule; ++i) {
94     if (!inputFile) {
95       AliError("Error while reading input file.");
96       delete [] xReal;
97       delete [] yReal;
98       delete [] zReal;
99       return;
100     }
101     inputFile>>dummyInt>>xReal[i]>>yReal[i]>>zReal[i];
102   }
103
104   InitSuperModuleData(xReal, yReal, zReal);
105
106   delete [] xReal;
107   delete [] yReal;
108   delete [] zReal;
109 }
110
111 //____________________________________________________________________________
112 AliEMCALSurvey::~AliEMCALSurvey()
113 {
114   delete [] fSuperModuleData;
115 }
116
117 //____________________________________________________________________________
118 void AliEMCALSurvey::CreateAliAlignObjParams(TClonesArray &array)
119 {
120   //Create AliAlignObjParams.
121   const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
122   if (!geom) {
123     AliError("Cannot obtain AliEMCALGeometry instance.");
124     return;
125   }
126
127   if (!gGeoManager) {
128     AliWarning("Cannot create local transformations for supermodules - gGeoManager does not exist.");
129     AliInfo("Null shifts and rotations will be created instead.");
130     return CreateNullObjects(array, geom);
131   }
132
133   Int_t arrayInd = array.GetEntries(), iIndex = 0;
134   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
135   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
136
137   for (Int_t smodnum = 0; smodnum < geom->GetNumberOfSuperModules(); ++smodnum) {
138     TString smodName(TString::Format("EMCAL/FullSupermodule%d", smodnum+1));
139     if(geom->GetKey110DEG() && smodnum >= 10) {
140       smodName = "EMCAL/HalfSupermodule";
141       smodName += (smodnum-10+1);
142     }    
143     AliEMCALSuperModuleDelta t(GetSuperModuleTransformation(smodnum));
144     new(array[arrayInd])
145       AliAlignObjParams(
146                         smodName.Data(), volid, 
147                         t.fXShift, t.fYShift, t.fZShift, 
148                         -t.fPsi, -t.fTheta, -t.fPhi, 
149                         false
150                         );
151     ++arrayInd;
152   }
153
154 }
155
156 //____________________________________________________________________________
157 void AliEMCALSurvey::CreateNullObjects(TClonesArray &array, const AliEMCALGeometry *geom)const
158 {
159   //Create null shifts and rotations.
160   Int_t arrayInd = array.GetEntries(), iIndex = 0;
161   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
162   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
163
164   for (Int_t smodnum = 0; smodnum < geom->GetNumberOfSuperModules(); ++smodnum) {
165     TString smodName(TString::Format("EMCAL/FullSupermodule%d", smodnum+1));
166     if(geom->GetKey110DEG() && smodnum >= 10) {
167       smodName = "EMCAL/HalfSupermodule";
168       smodName += (smodnum-10+1);
169     }
170     new(array[arrayInd]) AliAlignObjParams(smodName.Data(), volid, 0., 0., 0., 0., 0., 0., true);
171     ++arrayInd;
172   }
173 }
174
175 //____________________________________________________________________________
176 AliEMCALSurvey::AliEMCALSuperModuleDelta AliEMCALSurvey::GetSuperModuleTransformation(Int_t supModIndex)const
177 {
178   //Supermodule transformation.
179   AliEMCALSuperModuleDelta t = {0., 0., 0., 0., 0., 0.};
180   if (!fSuperModuleData)
181     return t;
182
183   return fSuperModuleData[supModIndex];
184 }
185
186 //____________________________________________________________________________
187 void AliEMCALSurvey::InitSuperModuleData(const Double_t *xReal, const Double_t *yReal, const Double_t *zReal)
188 {
189
190   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
191   //Center of supermodules
192   Float_t *pars = geom->GetSuperModulesPars();
193   Double_t rpos = (geom->GetEnvelop(0) + geom->GetEnvelop(1))/2.;
194   Double_t phi, phiRad, xpos, ypos, zpos;
195
196   AliEMCALSuperModuleCoords *idealSM = new AliEMCALSuperModuleCoords[fNSuperModule];
197   for (Int_t smodnum = 0; smodnum < geom->GetNumberOfSuperModules(); ++smodnum) {
198     AliEMCALSuperModuleCoords &smc = idealSM[smodnum];
199     phiRad = geom->GetPhiCenterOfSM(smodnum); //comes in radians
200     phi = phiRad*180./TMath::Pi(); //need degrees for AliAlignObjParams
201     xpos = rpos * TMath::Cos(phiRad);
202     ypos = rpos * TMath::Sin(phiRad);
203     zpos = pars[2];
204     if(geom->GetKey110DEG() && smodnum >= 10) {
205       xpos += (pars[1]/2. * TMath::Sin(phiRad));
206       ypos -= (pars[1]/2. * TMath::Cos(phiRad));
207     }
208     smc.fX1 = xpos;
209     smc.fY1 = ypos;
210     if(smodnum%2==0) {
211       smc.fZ1 = zpos;
212     } else {
213       smc.fZ1 = -zpos;
214     }
215
216   }
217
218   AliEMCALSuperModuleCoords *realSM = new AliEMCALSuperModuleCoords[fNSuperModule];
219   for (Int_t smodnum = 0; smodnum < geom->GetNumberOfSuperModules(); ++smodnum) {
220     AliEMCALSuperModuleCoords &smc = realSM[smodnum];
221     zpos = pars[2];
222     smc.fX1 = xReal[smodnum];  //x and y match
223     smc.fY1 = yReal[smodnum];  //x and y match
224     if(smodnum%2==0) {
225       smc.fZ1 = zReal[smodnum]-zpos;  //z measured is along end,
226     } else {                          //convert to middle of SM
227       smc.fZ1 = zReal[smodnum]+zpos;
228     }
229   }
230   
231   fSuperModuleData = new AliEMCALSuperModuleDelta[fNSuperModule];
232   
233   for (Int_t i = 0; i < fNSuperModule; ++i) {
234     const AliEMCALSuperModuleCoords &real = realSM[i];
235     const AliEMCALSuperModuleCoords &ideal = idealSM[i];
236     AliEMCALSuperModuleDelta &t = fSuperModuleData[i];
237     t.fTheta = TMath::ATan(real.fZ1  / real.fX1) - 
238                TMath::ATan(ideal.fZ1 / ideal.fX1);
239     t.fTheta *= TMath::RadToDeg();
240     t.fPsi = 0.;
241     t.fPhi = TMath::ATan(real.fY1 / real.fX1) - TMath::ATan(ideal.fY1 / ideal.fX1);
242     t.fPhi *= TMath::RadToDeg();
243     t.fXShift = real.fX1 - ideal.fX1;
244     t.fYShift = real.fY1 - ideal.fY1;
245     t.fZShift = real.fZ1 - ideal.fZ1;
246
247   }
248
249   delete [] realSM;
250   delete [] idealSM;
251 }