new task to find jet trigger candidates (loop over EMCal L1 patches over threshold...
[u/mrichter/AliRoot.git] / ACORDE / AliACORDEAlign.cxx
CommitLineData
091f76f8 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#include "AliACORDEAlign.h"
17#include "TROOT.h"
18#include "Riostream.h"
19#include "TFile.h"
20#include "TMath.h"
21#include "TSystem.h"
22#include "AliSurveyObj.h"
23#include "AliAlignObjParams.h"
24#include "AliCDBStorage.h"
25#include <TClonesArray.h>
26#include <TFile.h>
27#include "AliLog.h"
28#include "AliCDBManager.h"
29#include "AliSurveyPoint.h"
30#include "AliACORDEConstants.h"
31
32// Class creating the ACORDE aligmnent objects
33// from the surveys done by surveyers at Point2.
34// Survey results are fetched from
35// Survey Depot, based on survey results
36// position of ACORDE alignment objects is computed.
840f6973 37using std::cout;
38using std::endl;
091f76f8 39ClassImp(AliACORDEAlign)
40
41
42//________________________________________________________________________
43AliACORDEAlign::AliACORDEAlign() :
44 TObject(),
45 fFileGlob(0x0),
46 fRepLoc(0),
47 fRepGlob(0),
48 fUser(0x0),
49 fX(),
50 fAlignACORDEObjArray(0x0),
51 fDebug(0)
52{
53 //
54 // default constructor
55 //
56}
57
8f63aa5d 58AliACORDEAlign::AliACORDEAlign(/*Int_t reportloc,*/Int_t reportglob):
091f76f8 59 TObject(),
8f63aa5d 60 fFileGlob(0x0),
61 fRepLoc(0),
62 fRepGlob(0),
63 fUser(0x0),
091f76f8 64 fX(120,4),
65 fAlignACORDEObjArray(0x0),
66 fDebug(0)
67{
68
69//
70 // constructor
71 //fRepLoc = new reportloc[80];
72 //fRepGlob = new reportglob[80];
73 Char_t path[50];
8f63aa5d 74 fFileGlob = new Char_t[80];
75 fUser = new Char_t[10];
85b94986 76 snprintf(path,50,"%s",gSystem->Getenv("ALICE_ROOT"));
091f76f8 77 //
78 snprintf(fFileGlob,80,"%s/ACORDE/Survey_%d_ACORDE.txt",path,reportglob);
79 //
85b94986 80 snprintf(fUser,10,"%s",gSystem->Getenv("alien_API_USER"));
091f76f8 81
82}
83
091f76f8 84//__________________________________________________________________________
85AliACORDEAlign::~AliACORDEAlign(){
86 //
87 // destructor
88 //
89if(fAlignACORDEObjArray) delete fAlignACORDEObjArray;
90 if(fFileGlob) delete[] fFileGlob;
91 if(fUser) delete[] fUser;
92}
93
94
95void AliACORDEAlign::LoadSurveyData()
96{
97
98//
99// Create a new survey object and fill it.
100
101AliSurveyObj * s1 = new AliSurveyObj();
102
103if(fRepLoc != 0)
104 {
105 // Filling from DCDB (via GRID)
106 s1->SetGridUser(fUser);
107 s1->Fill("ACORDE",1014872,1,fUser);
108 }
109 else
110 {
111 s1->FillFromLocalFile(fFileGlob);
112 }
113
114
115 //s1->GetEntries();
116 //s1->GetUnits();
0415bcff 117 //TObjArray* arr = s1->GetData();
091f76f8 118 //cout<< "number of entries " << arr->GetEntries() <<endl;
119 //arr->UncheckedAt(0)->ClassName();
120 //AliSurveyPoint *sp0 = (AliSurveyPoint*) arr->UncheckedAt(0);
121 //cout << "point name " << sp0->GetPointName() << endl ;
122
123
124//
125TString ML= "M" ;
126//TString PL= "P";
127TString underscore = "_";
128TString endInner = "_I";
129TString endOuter = "_O";
130TString endCenter = "_P";
131//
132TString surveyname;
133TString surveynameInner;
134TString surveynameOuter;
135TString surveynameCenter;
136
137//TString surveynameAngles;
138//
139TString pointNamesInner[60];
140TString pointNamesOuter[60];
141TString pointNamesCenter[60];
142
143//
144Int_t nid=0;
145//
146 //for regular modules
147 for (Int_t ncolum=0; ncolum<6; ncolum++)
148 {
149 for (Int_t nrow=0; nrow<10; nrow++)
150 {
151
152 surveyname=ML;
153 surveyname+=ncolum;
154 surveyname+=underscore;
155 surveyname+=nrow;
156
157 surveynameInner=surveyname;
158 surveynameInner+=endInner;
159
160 surveynameOuter=surveyname;
161 surveynameOuter+=endOuter;
162
163 surveynameCenter=surveyname;
164 surveynameCenter+=endCenter;
165
166 pointNamesInner[nid] = surveynameInner;
167 pointNamesOuter[nid] = surveynameOuter;
168 pointNamesCenter[nid] = surveynameCenter;
169 ++nid;
170 }
171 }
172
173
174//Read two points
175AliSurveyPoint *InnerPoint;
8f63aa5d 176AliSurveyPoint *OuterPoint
177;
091f76f8 178AliSurveyPoint *CenterPoint;
179
180
181 for(Int_t i=0;i<60;i++)
182 {
183
184 InnerPoint=0;
185 OuterPoint=0;
186 CenterPoint=0;
187
188 InnerPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesInner[i]);
189 OuterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesOuter[i]);
190 CenterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesCenter[i]);
191
192
193
194 if(InnerPoint && OuterPoint)
195 {
196 //Use center if it is available
197 if(CenterPoint)
198 {
199 fX(i+60,0) = CenterPoint->GetX()*100;
200 fX(i+60,1) = CenterPoint->GetY()*100;
201 fX(i+60,2) = CenterPoint->GetZ()*100;
202 }
203 else
204 {
205 //calculate center point
206 fX(i+60,0) = 100*(InnerPoint->GetX() + OuterPoint->GetX())/2.0;
207 fX(i+60,1) = 100*(InnerPoint->GetY() + OuterPoint->GetY())/2.0;
208 fX(i+60,2) = 100*(InnerPoint->GetZ() + OuterPoint->GetZ())/2.0;
209 }
210
211 fX(i,0) = OuterPoint->GetX()*100;
212 fX(i,1) = OuterPoint->GetY()*100;
213 fX(i,2) = OuterPoint->GetZ()*100;
214 }
215 else
216 {
217 if(InnerPoint && CenterPoint)
218 {
219
220 fX(i+60,0) = CenterPoint->GetX()*100;
221 fX(i+60,1) = CenterPoint->GetY()*100;
222 fX(i+60,2) = CenterPoint->GetZ()*100;
223
224 fX(i,0) = InnerPoint->GetX()*100;
225 fX(i,1) = InnerPoint->GetY()*100;
226 fX(i,2) = InnerPoint->GetZ()*100;
227 }
228 else
229 {
230 if(OuterPoint && CenterPoint)
231 {
232
233 fX(i+60,0) = CenterPoint->GetX()*100;
234 fX(i+60,1) = CenterPoint->GetY()*100;
235 fX(i+60,2) = CenterPoint->GetZ()*100;
236
237 fX(i,0) = OuterPoint->GetX()*100;
238 fX(i,1) = OuterPoint->GetY()*100;
239 fX(i,2) = OuterPoint->GetZ()*100;
240 }
241 else
242 {
243
244 fX(i+60,0) = -99.0;
245 fX(i+60,1) = -99.0;
246 fX(i+60,2) = -99.0;
247
248 fX(i,0) = -99.0;
249 fX(i,1) = -99.0;
250 fX(i,2) = -99.0;
251
252 }
253 }
254 }
255
256
257 }//ends for
258
259 delete s1;
260
261}
262
263void AliACORDEAlign::ComputePosition()
264{
265
266
267//Residuals for rotations
268
269Double_t theta;
270Double_t resphi[60];
271Double_t resiphi;
272
273for (Int_t imod=0; imod<60; imod++)
274 {
275 if(TMath::Abs(fX(imod+60,0)-fX(imod,0))>=0.000001)
276 {
277 theta = (fX(imod+60,1)-fX(imod,1))/(fX(imod+60,0)-fX(imod,0));
278 resiphi = TMath::ATan(theta)*(180.0/TMath::Pi());
279 // calculate the residuals special modules
280 if(imod==0 || imod==9 || imod==50 || imod==59 )
281 {
282 resphi[imod] = 0.0-resiphi;
283 continue;
284 }
285 // for module with no measurements
286 if(imod == 42 )
287 {
288 resphi[imod]= 0.0;
289 continue;
290 }
291 //face A
292 if(imod>0 && imod <20)
293 {
294 resphi[imod] = resiphi + 45.0;
295 }
296 //face B
297 if(imod>=20 && imod <40)
298 {
299 resphi[imod] = -resiphi;
300 }
301 //face C
302 if(imod>=40 && imod <60)
303 {
304 resphi[imod] = resiphi - 45.0;
305 }
306
307 }
308
309}
310
311
312//Get the residuals for translations
313
314AliCDBManager* cdb = AliCDBManager::Instance();
315if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
316cdb->SetRun(0);
317
318//AliCDBStorage* storage;
319AliGeomManager::LoadGeometry();
320
321
322TString symname;
323TString basename = "ACORDE/Array";
324
325
326// Get the ideal directly from the geometry
327 Double_t *tr;
328 TGeoHMatrix *matrix;
329 for (Int_t imod=0; imod<60; imod++)
330 {
331 symname = basename;
332 symname += imod;
333 cout<< symname << endl;
334 matrix = AliGeomManager::GetMatrix(symname);
335 tr=matrix->GetTranslation();
336
337 if(imod == 42)
338 {
339 fX(imod+60,0) = 0.0;
340 fX(imod+60,1) = 0.0;
341 fX(imod+60,2) = 0.0;
342 fX(imod,0) = 0.0;
343 fX(imod,1) = 0.0;
344 fX(imod,2) = 0.0;
345 continue;
346 }
347
348 fX(imod+60,0)=fX(imod+60,0)- tr[0];
349 fX(imod+60,1)=fX(imod+60,1)- tr[1]- 4.0;
350 fX(imod+60,2)=fX(imod+60,2)- tr[2];
351
352 fX(imod,0) = resphi[imod];
353 fX(imod,1) = 0.0;
354 fX(imod,2) = 0.0;
355
356 }
357
358
359
360
361}
362
363//______________________________________________________________________
364void AliACORDEAlign::Run(){
365 //
366 // runs the full chain
367 //
368
369 //if(!LoadSurveyFromAlienFile("ACORDE",999999,1))
370 //{
371 // cout<<"Missing points"<<endl;
372 //return;
373 //}
374 //else
375 //{
376 //LoadSurveyfromLocalFile("ACORDE",99999,1);
377 //}
378
379
380 LoadSurveyData();
381 ComputePosition();
382 //CreateACORDEAlignObjs();
383 StoreAlignObj();
384
385}
386
387//_________________________________________________________________________
388
389void AliACORDEAlign::StoreAlignObj()
390{
391 //
392 // Storing ACORDE alignment objects
393 //
394
395 AliCDBManager* cdb = AliCDBManager::Instance();
396 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
397
398 TClonesArray *array = new TClonesArray("AliAlignObjParams",60);
399 //
400 // storing either in the OCDB or local file
401 //
402
403 TString symname;
404 TString basename = "ACORDE/Array";
405 Int_t iIndex=0;
406
407 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
408 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
409
410 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.0;
411
412 for (Int_t imod=0; imod<60; imod++)
413 {
414
415 dphi = fX(imod,0);
416 dtheta = fX(imod,1);
417 dpsi = fX(imod,2);
418 dx = fX(imod+60,0);
419 dy = fX(imod+60,1);
420 dz = fX(imod+60,2);
421 symname = basename;
422 symname += imod;
423 new((*array)[imod]) AliAlignObjParams(symname,volid,dx,dy,dz,dpsi,dtheta,dphi,kFALSE);
424 }
425
426
427 if( TString(gSystem->Getenv("TOCDB"))!= TString("kTRUE") )
428 {
429
430
431
432 // save on file
433 const char* filename = "ACORDESurveyMisalignment.root";
434 Char_t fullname[80];
435
436
437
85b94986 438 snprintf(fullname,80,"%s",filename);
091f76f8 439
440
441 TFile *f = new TFile(fullname,"RECREATE");
442
443
444 if(!f)
445 {
446 AliError("cannot open file for output\n");
447 return;
448 }
449 AliInfo(Form("Saving alignment objects to the file %s", filename));
450 f->cd();
451 f->WriteObject(array,"ACORDEAlignObjs","kSingleKey");
452 f->Close();
453 }
454 else
455 {
456 // save in CDB storage
457 AliCDBStorage* storage;
458 //
459 TString Storage = gSystem->Getenv("STORAGE");
460 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://"))
461 {
462 AliError(Form("STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
463 return;
464 }
465 storage = cdb->GetStorage(Storage.Data());
466 if(!storage)
467 {
468 AliError(Form("Unable to open storage %s\n",Storage.Data()));
469 return;
470 }
471 //
472 AliCDBMetaData* md = new AliCDBMetaData();
473 md->SetResponsible("Pedro Podesta");
474 md->SetComment("Full misalignment of ACORDE from surveyors");
475 AliCDBId id("ACORDE/Align/Data",0,AliCDBRunRange::Infinity());
476 storage->Put(fAlignACORDEObjArray,id,md);
477 }
478
479}