classes for alignment from Tomek
[u/mrichter/AliRoot.git] / T0 / AliT0Align.cxx
CommitLineData
a4c640e1 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// Class creating the T0 aligmnent objects from the surveys.
17
18//
19// Creates the T0 align object
20//
21
22#include "AliT0Align.h"
23//
24#include "TROOT.h"
25#include "Riostream.h"
26#include "TFile.h"
27#include "TMath.h"
28#include "TSystem.h"
29#include "AliSurveyObj.h"
30#include "AliAlignObjParams.h"
31#include "AliCDBStorage.h"
32#include <TClonesArray.h>
33#include <TFile.h>
34#include "AliLog.h"
35#include "AliCDBManager.h"
36
37ClassImp(AliT0Align)
38
39AliT0Align::AliT0Align() :
40 TObject(),
41 fT0AAlignObj(0x0),
42 fT0CAlignObj(0x0),
43 fFileGlob(0x0),
44 fXPos(0.),
45 fYPos(0.),
46 fDebug(0),
47 fRepLoc(0)
48{
49 //
50 // default constructor
51 //
52}
53//________________________________________________________________________
54AliT0Align::AliT0Align(Int_t reportloc, Int_t reportglob) :
55 TObject(),
56 fT0AAlignObj(0x0),
57 fT0CAlignObj(0x0),
58 fFileGlob(0x0),
59 fXPos(0.),
60 fYPos(0.),
61 fDebug(0),
62 fRepLoc(0)
63{
64 //
65 // constructor - defines data files
66 //
67 fRepLoc = reportloc;
68 Char_t path[50];
69 fFileGlob = new Char_t[80];
70 sprintf(path,gSystem->Getenv("ALICE_ROOT"));
71 //
72 // sprintf(fFileLoc,"%s/T0/Survey_%d_T0.txt",path,reportloc);
73 sprintf(fFileGlob,"%s/T0/Survey_%d_V0.txt",path,reportglob);
74 //
75
76}
77//_________________________________________________________________________
78AliT0Align::AliT0Align(const AliT0Align &align) :
79 TObject(),
80 fT0AAlignObj(0x0),
81 fT0CAlignObj(0x0),
82 fFileGlob(0x0),
83 fXPos(0.),
84 fYPos(0.),
85 fDebug(0),
86 fRepLoc(0)
87{
88 //
89 // copy constructor - dummy
90 //
91 fDebug = align.fDebug;
92}
93//__________________________________________________________________________
94AliT0Align & AliT0Align::operator =(const AliT0Align & align)
95{
96 //
97 // assignment operator - dummy
98 //
99 fDebug=align.fDebug;
100 return (*this);
101}
102
103//__________________________________________________________________________
104AliT0Align::~AliT0Align(){
105 //
106 // destructor
107 //
108 if(fT0AAlignObj) delete fT0AAlignObj;
109 if(fT0CAlignObj) delete fT0CAlignObj;
110
111}
112//__________________________________________________________________________
113Bool_t AliT0Align::LoadSurveyData()
114{
115 //
116 // Create a new survey object and fill it.
117
118 AliSurveyObj * s1 = new AliSurveyObj();
119
120 if(fRepLoc == 0)
121 //
122 // Filling from DCDB (via GRID)
123 //
124 {
125 s1->SetGridUser("tomatkie");
126 s1->Fill("V0", 835615, "tomatkie");
127 }
128
129 else
130 //
131 // Filling from local file
132 //
133 {
134 s1->FillFromLocalFile(fFileGlob);
135 }
136 //
137 Int_t numberPoints = 3;
138 //
139 TString pointNames[3] = {"C67_6_Beamcircle", "T0A", "VERTEX"};
140 //
141 Float_t surveyedPoints [3][2];
142 AliSurveyPoint *currPoint;
143
144 //
145 for(Int_t i=0;i<numberPoints;i++)
146 {
147 currPoint=0;
148 currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
149 //
150 if(currPoint)
151 {
152 surveyedPoints[i][0]=currPoint->GetX();
153 surveyedPoints[i][1]=currPoint->GetY();
154 // surveyedPoints[i]=currPoint->GetZ();
155 if(fDebug)
156 Printf(Form("INFO: Point \"%s\" coordinates read.", pointNames[i].Data()));
157 }
158 else
159 {
160 if(fDebug)
161 {
162 Printf(Form("ERROR: Essential point missing: \"%s\"", pointNames[i].Data()));
163 return 1;
164 }
165 }
166 }
167 fXPos = surveyedPoints[0][0];
168 fYPos = surveyedPoints[0][1];
169 //
170 delete s1;
171 //
172 return 0;
173}
174//_________________________________________________________________
175
176Double_t AliT0Align::ComputePosition()
177{
178 // Float_t fZPos, shift;
179 // fZPos = surveyedPoints[3] - shift;
180
181}
182//_______________________________________________________________________
183void AliT0Align::CreateAlignObj(){
184 //
185 TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
186 // TClonesArray &alobj = *array;
187
188
189 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
190 fT0AAlignObj = new AliAlignObjParams("ALIC_1/0STL_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
191
192 dx=fXPos;
193 dy=fYPos;
194 // dz=surveyedPoints[2];
195 dz=0.;
196 fT0CAlignObj = new AliAlignObjParams("ALIC_1/0STR_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
197}
198
199//______________________________________________________________________
200void AliT0Align::Run(){
201 //
202 // runs the full chain
203 //
204 SetDebug(0);
205 Bool_t flag = LoadSurveyData();
206 if(flag)
207 {
208 cout<<"Missing points"<<endl;
209 return;
210 }
211 // ComputePosition();
212 CreateAlignObj();
213 StoreAlignObj();
214}
215//_________________________________________________________________________
216
217void AliT0Align::StoreAlignObj()
218{
219 AliCDBManager* cdb = AliCDBManager::Instance();
220 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
221 //
222 TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
223//
224 Double_t shifts[3];
225 Double_t rots[3];
226 //
227 fT0AAlignObj->GetPars(shifts,rots);
228 new((*array)[0]) AliAlignObjParams(fT0AAlignObj->GetSymName(),0,shifts[0],
229 shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
230 fT0CAlignObj->GetPars(shifts,rots);
231 new((*array)[1]) AliAlignObjParams(fT0CAlignObj->GetSymName(),0,shifts[0],
232 shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
233
234
235//
236// storing either in the OCDB or local file
237//
238 if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
239 // save on file
240 const char* filename = "T0SurveyMisalignment.root";
241 Char_t fullname[80];
242 sprintf(fullname,"%s/T0/Align/Data/%s",gSystem->Getenv("ALICE_ROOT"),filename);
243 TFile *f = new TFile(fullname,"RECREATE");
244 if(!f){
245 AliError("cannot open file for output\n");
246 return;
247 }
248 AliInfo(Form("Saving alignment objects to the file %s", filename));
249 f->cd();
250 f->WriteObject(array,"T0AlignObjs","kSingleKey");
251 f->Close();
252 }else{
253 // save in CDB storage
254 AliCDBStorage* storage;
255 //
256 TString Storage = gSystem->Getenv("STORAGE");
257 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
258 AliError(Form(
259 "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
260 return;
261 }
262 storage = cdb->GetStorage(Storage.Data());
263 if(!storage){
264 AliError(Form("Unable to open storage %s\n",Storage.Data()));
265 return;
266 }
267 //
268 AliCDBMetaData* md = new AliCDBMetaData();
269 md->SetResponsible("Tomasz Malkiewicz");
270 md->SetComment("Full misalignment of T0-C from surveyors");
271 AliCDBId id("T0/Align/Data",0,AliCDBRunRange::Infinity());
272 storage->Put(array,id,md);
273 }
274}
275