]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Align.cxx
fit window increased
[u/mrichter/AliRoot.git] / T0 / AliT0Align.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: AliT0Align.cxx,v $
18  Revision   2008/01/30
19 Removing code violations 
20
21  Version 1.1  2006/10
22 Preliminary test version (T.Malkiewicz)
23 */
24
25 #include "AliT0Align.h"
26 #include "TROOT.h"
27 #include "Riostream.h"
28 #include "TFile.h"
29 #include "TMath.h"
30 #include "TSystem.h"
31 #include "TString.h"
32 #include "AliSurveyObj.h"
33 #include "AliAlignObjParams.h"
34 #include "AliCDBStorage.h"
35 #include <TClonesArray.h>
36 #include <TFile.h>
37 #include "AliLog.h"
38 #include "AliCDBManager.h"
39 #include "AliSurveyPoint.h" 
40
41 // Class creating the T0 aligmnent objects 
42 // from the surveys done by surveyers at Point2.
43 // Survey results are fetched from 
44 // Survey Depot, based on survey results 
45 // position of T0 alignment objects is computed.
46
47
48 ClassImp(AliT0Align)
49
50 AliT0Align::AliT0Align() :
51   TObject(),
52   fFileGlob(0x0),
53   fT0AAlignObj(0x0),
54   fT0CAlignObj(0x0),
55   fDebug(0),
56   fXPosC(0.),
57   fYPosC(0.),
58   fXPosA(0.),
59   fYPosA(0.),
60   fRepLoc(0),
61   fRepGlob(0),
62   fSide(0x0),
63   fUser(0x0)
64 {
65   //
66   //  default constructor
67   //
68 }   
69 //________________________________________________________________________
70 AliT0Align::AliT0Align(Int_t reportloc, Int_t side, Int_t reportglob) :
71   TObject(),
72   fFileGlob(0x0),
73   fT0AAlignObj(0x0),
74   fT0CAlignObj(0x0),
75   fDebug(0),
76   fXPosC(0.),
77   fYPosC(0.),
78   fXPosA(0.),
79   fYPosA(0.),
80   fRepLoc(0),
81   fRepGlob(0),
82   fSide(0x0),
83   fUser(0x0)
84 {
85   //
86   // constructor - defines data files
87   //
88   fRepLoc = reportloc;
89   fRepGlob = reportglob;
90   fSide = side;
91   // Char_t path[50];
92   TString path = Form("%s",gSystem->Getenv("ALICE_ROOT")) ;
93   // fFileGlob = new Char_t[80];
94   //  fUser = new Char_t[10];
95   fFileGlob = Form("%s/T0/Survey_%d_V0.txt",path.Data(),reportglob);
96   fUser = Form("%s/T0/Survey_%d_V0.txt",path.Data(),reportglob);
97   // sprintf(path,gSystem->Getenv("ALICE_ROOT")); 
98   //
99   // sprintf(fFileLoc,"%s/T0/Survey_%d_T0.txt",path,reportloc);
100   // sprintf(fFileGlob,"%s/T0/Survey_%d_V0.txt",path,reportglob);
101   //
102   // sprintf(fUser,gSystem->Getenv("alien_API_USER"));
103 }
104 //_________________________________________________________________________
105 AliT0Align::AliT0Align(const AliT0Align &align) :
106   TObject(),
107   fFileGlob(0x0),
108   fT0AAlignObj(0x0),
109   fT0CAlignObj(0x0),
110   fDebug(0),
111   fXPosC(0.),
112   fYPosC(0.),
113   fXPosA(0.),
114   fYPosA(0.),
115   fRepLoc(0),
116   fRepGlob(0),
117   fSide(0x0),
118   fUser(0x0)  
119 {
120   //
121   //  copy constructor - dummy
122   //
123   ((AliT0Align &) align).Copy(*this);
124
125 }
126 //__________________________________________________________________________
127 AliT0Align & AliT0Align::operator =(const AliT0Align & align)
128 {
129   //
130   // assignment operator - dummy
131   //
132   if (this != &align) ((AliT0Align &) align).Copy(*this);
133
134    return (*this);
135 }
136
137 //__________________________________________________________________________
138 AliT0Align::~AliT0Align()
139 {
140   //
141   // destructor
142   //
143   if(fT0AAlignObj) delete fT0AAlignObj;
144   if(fT0CAlignObj) delete fT0CAlignObj;
145   if(fFileGlob) delete[] fFileGlob;
146   if(fUser) delete[] fUser;
147 }
148 //__________________________________________________________________________
149 Bool_t AliT0Align::LoadSurveyData()
150 {
151   //
152   // Create a new survey object and fill it.
153  
154  AliSurveyObj * s1 = new AliSurveyObj();
155  const int numberPoints = 2;
156  TString pointNames[numberPoints]={"Flange_0","C67_6_Beamcircle"}; 
157  
158  if(fRepLoc == 0) 
159  { 
160    //
161    // Filling from DCDB (via GRID)
162    //
163    s1->SetGridUser(fUser);
164    if(fSide == 0) 
165    {
166      s1->Fill("T0", fRepGlob, fUser);
167    }
168    else if(fSide == 1)
169    {
170      s1->Fill("VZERO", fRepGlob, fUser);
171    }
172    else
173    {
174      cout<<"Enter the side properly: '0'- A side, '1'- C side'" <<endl;
175      return 0;
176    }
177  }
178  else
179  //
180  // Filling from local file
181  //
182  {
183    s1->FillFromLocalFile(fFileGlob);
184  }
185  //
186  Float_t surveyedPoints [numberPoints][2];
187  AliSurveyPoint *currPoint;
188
189  //
190  for(Int_t i=0;i<numberPoints;i++)
191  {
192    currPoint=0;
193    currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
194    //
195    if(currPoint)
196    {
197      surveyedPoints[i][0]=currPoint->GetX();
198      surveyedPoints[i][1]=currPoint->GetY();
199    //  surveyedPoints[i]=currPoint->GetZ();
200      if(fDebug)
201      Printf("INFO: Point %s coordinates read.\n", pointNames[i].Data() ) ;
202    }
203    else 
204    {
205      if(fDebug)
206      {
207        Printf("ERROR: Essential point missing: %s\n", pointNames[i].Data() ) ;
208        return 1;
209      }
210    }  
211  }
212  if(fSide == 0)
213  {
214    fXPosA = surveyedPoints[0][0];
215    fYPosA = surveyedPoints[0][1];
216  }
217  else if(fSide == 1)
218  {
219    fXPosC = surveyedPoints[1][0]; 
220    fYPosC = surveyedPoints[1][1];
221  }
222  //
223  delete s1;
224  //
225  return 0;
226 }
227 //_________________________________________________________________
228
229 Double_t AliT0Align::ComputePosition()
230 {
231  //  Float_t fZPos, shift;
232  //  fZPos = surveyedPoints[3] - shift;
233   return 0;
234 }
235 //_______________________________________________________________________
236 void AliT0Align::CreateAlignObj()
237 {
238   //
239   //  TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
240   // TClonesArray &alobj = *array;
241   
242   Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
243   dx=fXPosA;
244   dy=fYPosA;
245   fT0AAlignObj = new AliAlignObjParams("ALIC_1/0STL_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
246   
247   dx=fXPosC;
248   dy=fYPosC;
249   // dz=surveyedPoints[2];
250   dz=0.;
251   fT0CAlignObj = new AliAlignObjParams("ALIC_1/0STR_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
252   
253 }
254
255 //______________________________________________________________________
256 void AliT0Align::Run()
257 {
258   //
259   // runs the full chain
260   //
261   // SetDebug(0);
262   Bool_t flag = LoadSurveyData();
263     if(flag) 
264   {
265     cout<<"Missing points"<<endl;
266     return;
267   }
268   // ComputePosition();
269   CreateAlignObj();
270   StoreAlignObj();
271 }
272 //_________________________________________________________________________
273
274 void AliT0Align::StoreAlignObj()
275 {
276  //
277  // Storing T0 alignment objects 
278  //
279  AliCDBManager* cdb = AliCDBManager::Instance();
280  if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
281  //
282  TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
283 //
284  Double_t shifts[3];
285  Double_t rots[3];
286  //
287  fT0AAlignObj->GetPars(shifts,rots);
288  new((*array)[0]) AliAlignObjParams(fT0AAlignObj->GetSymName(),0,shifts[0],
289                    shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
290  fT0CAlignObj->GetPars(shifts,rots);
291  new((*array)[1]) AliAlignObjParams(fT0CAlignObj->GetSymName(),0,shifts[0],
292                    shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
293
294
295 //
296 // storing either in the OCDB or local file
297 //
298   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
299     // save on file
300     const char* filename = "T0SurveyMisalignment.root";
301     //  Char_t fullname[80];
302     //  sprintf(fullname,"%s/T0/Align/Data/%s",gSystem->Getenv("ALICE_ROOT"),filename);
303     TString fullname = Form("%s/T0/Align/Data/%s",gSystem->Getenv("ALICE_ROOT"), filename);
304     TFile *f = new TFile(fullname.Data(),"RECREATE");
305     if(!f){
306       AliError("cannot open file for output\n");
307       return;
308     }
309     AliInfo(Form("Saving alignment objects to the file %s", filename));
310     f->cd();
311     f->WriteObject(array,"T0AlignObjs","kSingleKey");
312     f->Close();
313   }else{
314     // save in CDB storage
315     AliCDBStorage* storage;
316     //
317    TString Storage = gSystem->Getenv("STORAGE");
318     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
319       AliError(Form(
320       "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
321       return;
322     }
323     storage = cdb->GetStorage(Storage.Data());
324     if(!storage){
325       AliError(Form("Unable to open storage %s\n",Storage.Data()));
326       return;
327     }
328     //
329     AliCDBMetaData* md = new AliCDBMetaData();
330     md->SetResponsible("Tomasz Malkiewicz");
331     md->SetComment("Position of T0-A and T0-C from survey");
332     AliCDBId id("T0/Align/Data",0,AliCDBRunRange::Infinity());
333     storage->Put(array,id,md);
334   }
335 }
336