]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSSurveyToAlignSSD.cxx
compilation warnings
[u/mrichter/AliRoot.git] / ITS / AliITSSurveyToAlignSSD.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 /*
17 $Log$
18 Revision 1.1  2007/10/01 14:12:45  pchrist
19 Class creating the aligmnent object fro the surveyor measurements.
20
21 */ 
22
23 //
24 //  Creates the SSD align object
25 //
26 //
27 #include "Riostream.h"
28 #include "TFile.h"
29 #include "TSystem.h"
30 #include "TClonesArray.h"
31 #include "TGeoManager.h"
32 #include "TGeoMatrix.h"
33 #include "TGeoPhysicalNode.h"
34
35 #include "AliITSSurveyToAlignSSD.h"
36 #include "AliSurveyObj.h"
37 #include "AliSurveyPoint.h"
38 #include "AliAlignObjParams.h"
39
40 #include "AliLog.h"
41
42 #include "AliCDBManager.h"
43 #include "AliCDBEntry.h"
44 #include "AliCDBStorage.h"
45
46 ClassImp(AliITSSurveyToAlignSSD)
47
48 //________________________________________________________________________
49 AliITSSurveyToAlignSSD::AliITSSurveyToAlignSSD() :
50   TObject(),
51   fRun(0),
52   fFileLoc(0x0),
53   fFileGlob(0x0),
54   fSurveyPoints(0),
55   fSSDAlignObj(new TClonesArray("AliAlignObjParams",100)),
56   fSSDAlignObjParam(0),
57   fDebug(0) {
58   //
59   //  default constructor
60   //
61 }   
62
63 //________________________________________________________________________
64 AliITSSurveyToAlignSSD::AliITSSurveyToAlignSSD(Int_t /* run */, Int_t reportloc, Int_t reportglob) :
65   TObject(),
66   fRun(0),
67   fFileLoc(0x0),
68   fFileGlob(0x0),
69   fSurveyPoints(0),
70   fSSDAlignObj(new TClonesArray("AliAlignObjParams",100)),
71   fSSDAlignObjParam(0),
72   fDebug(0) {
73   //
74   // constructor - defines data files
75   //
76   fFileLoc = new Char_t[80];
77   fFileGlob = new Char_t[80];
78   Char_t path[50];
79   sprintf(path,gSystem->Getenv("ALICE_ROOT")); 
80   //
81   sprintf(fFileLoc,"%s/ITS/Survey_SSD_%d.txt",path,reportloc);  
82   sprintf(fFileGlob,"%s/ITS/Survey_SSD_%d.txt",path,reportglob);
83   //
84
85 }
86 //_________________________________________________________________________
87 AliITSSurveyToAlignSSD::AliITSSurveyToAlignSSD(const AliITSSurveyToAlignSSD &align) :
88   TObject(),
89   fRun(0),
90   fFileLoc(0x0),
91   fFileGlob(0x0),
92   fSurveyPoints(0),
93   fSSDAlignObj(new TClonesArray("AliAlignObjParams",100)),
94   fSSDAlignObjParam(0),
95   fDebug(0) {
96   //
97   //  copy constructor - dummy
98   
99   fDebug = align.fDebug;
100 }
101
102 //__________________________________________________________________________
103 AliITSSurveyToAlignSSD & AliITSSurveyToAlignSSD::operator =(const AliITSSurveyToAlignSSD & align) {
104   //
105   // assignment operator - dummy
106   //
107   fDebug = align.fDebug;
108   return (*this);
109 }
110
111 //__________________________________________________________________________
112 AliITSSurveyToAlignSSD::~AliITSSurveyToAlignSSD() {
113   //
114   // destructor
115   //
116   if(fSurveyPoints) delete fSurveyPoints;
117   if(fSSDAlignObj) delete fSSDAlignObj;
118   if(fSSDAlignObjParam) delete fSSDAlignObjParam;
119 }
120
121 //______________________________________________________________________
122 void AliITSSurveyToAlignSSD::Run() { 
123   //
124   // runs the full chain
125   //
126   SetDebug(0);
127   Bool_t flag = LoadSurveyData();
128   if(!flag) {
129     cout<<"Missing points"<<endl;
130     return;
131   }
132   CreateAlignObj();
133   StoreAlignObj();
134   //
135 }
136
137 //__________________________________________________________________________
138 Bool_t AliITSSurveyToAlignSSD::LoadSurveyData() {
139   //
140   // for a time being it loads from the local file the surveyed point
141   // and has the ideal points hardwired. I am waiting until Ricardo
142   // completes his job
143   // 
144   
145   //Load survey data from the local file
146   AliSurveyObj * s1 = new AliSurveyObj();
147   if(s1->FillFromLocalFile(fFileGlob))
148     fSurveyPoints = s1->GetData();
149   else 
150     return kFALSE;
151   
152   cout<<"Number of SSD survey points: "<<fSurveyPoints->GetEntries()<<endl;  
153   
154   return kTRUE;
155 }
156
157 //_______________________________________________________________________
158 void AliITSSurveyToAlignSSD::CreateAlignObj(){
159   //
160   // This method creates AliAlignObj and fills it with Euler angles
161   // and shifts. The units are degrees and cm.
162   // 
163   TClonesArray &alobj = *fSSDAlignObj;
164
165   //load ideal geometry from the OCDB
166   AliCDBManager *cdb = AliCDBManager::Instance();
167   cdb->SetDefaultStorage("local://$ALICE_ROOT");
168   cdb->SetRun(fRun);
169   AliCDBEntry* entry = cdb->Get("GRP/Geometry/Data");
170   AliGeomManager::SetGeometry(gGeoManager);
171
172   AliSurveyPoint* pt = 0;
173   TGeoHMatrix* hm = 0;
174   TGeoPNEntry* pne = 0;
175   Double_t* tr;
176   Int_t uid;
177   const char* symname;
178   Double_t sx, sy, sz;
179   Int_t ilayer, imodule;
180
181   for(Int_t imod = 0; imod < fSurveyPoints->GetEntries(); imod++) {
182     pt = (AliSurveyPoint*) fSurveyPoints->At(imod);
183     if(!pt) continue;
184     sx = pt->GetX();
185     sy = pt->GetY();
186     sz = pt->GetZ();
187
188     ilayer = (imod < 748) ? AliGeomManager::kSSD1 : AliGeomManager::kSSD2;
189     imodule = (imod < 748) ? imod : imod - 748;
190
191     uid = AliGeomManager::LayerToVolUID(ilayer,imodule);
192     symname = AliGeomManager::SymName(uid);
193     pne = gGeoManager->GetAlignableEntryByUID(uid);
194     hm = pne->GetGlobalOrig();
195     tr = hm->GetTranslation();
196
197     //Printf("symname %s", symname);
198     //Printf("x,y,z from survey: %f %f %f", sx, sy, sz);
199     //Printf("x,y,z from ideal : %f %f %f", tr[0], tr[1], tr[2]);
200     
201    new(alobj[imod]) AliAlignObjParams(symname, uid, sx-tr[0], sy-tr[1], sz-tr[2], 0., 0., 0., kTRUE);
202   }//module loop
203
204   delete entry;
205 }
206
207 //_________________________________________________________________________
208 void AliITSSurveyToAlignSSD::StoreAlignObj(){
209   // Stores the TClonesArray of AliAlignObj in
210   // $ALICE_ROOT/ITS/Align/Data/SSDfromSurvey.root
211   // In a later version these objects will be merged 
212   // with the SDD ones and will be put in the OCDB
213   const char* filename = "$ALICE_ROOT/ITS/Align/Data/SSDfromSurvey.root";
214   TFile *f = TFile::Open(filename,"RECREATE");
215   if(!f){
216     Error(filename,"cannot open file for output\n");
217     return;
218   }
219   cout<<"Saving alignment objects to the file "<<filename<<endl;
220   f->cd();
221   f->WriteObject(fSSDAlignObj,"SSDAlignObjs","kSingleKey");
222   f->Close();
223
224 }