]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/MakeT0ResMisAlignment.C
Using AliGeomManager in the macros (Raffaele)
[u/mrichter/AliRoot.git] / T0 / MakeT0ResMisAlignment.C
1 void MakeT0ResMisAlignment(){
2   // Create TClonesArray of residual misalignment objects for T0
3   //
4   TClonesArray *array = new TClonesArray("AliAlignObjAngles",30);
5   TClonesArray &alobj = *array;
6
7   if(!AliGeomManager::GetGeometry()){
8     if(!(AliCDBManager::Instance())->IsDefaultStorageSet())
9       AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
10       AliCDBManager::Instance()->SetRun(0);
11     AliGeomManager::LoadGeometry();
12   }
13   // needed for the constructors with local coordinates not to fail
14
15   AliAlignObjAngles a;
16
17   Double_t dx, dy, dz, dpsi, dtheta, dphi;
18   TRandom *rnd   = new TRandom(4321);
19   Double_t sigmatr = 0.05; // max shift in cm
20   Double_t sigmarot = 0.3; // max rot in degrees
21
22   TString symName, sn;
23
24   Int_t iIndex=0;
25   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
26   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
27
28   Int_t j=0;
29   for (Int_t imod=0; imod<24; imod++){
30     if (imod < 12){
31       sn="T0/C/PMT";
32     }else{
33       sn="T0/A/PMT";
34     }
35     symName = sn;
36     symName += imod+1;
37     
38     dx = rnd->Gaus(0.,sigmatr);
39     dy = rnd->Gaus(0.,sigmatr);
40     dz = rnd->Gaus(0.,sigmatr);
41     dpsi = rnd->Gaus(0.,sigmarot);
42     dtheta = rnd->Gaus(0.,sigmarot);
43     dphi = rnd->Gaus(0.,sigmarot);
44     
45     new(alobj[j++]) AliAlignObjAngles(symName.Data(), volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
46   }
47   
48   const char* macroname = "MakeT0ResMisAlignment.C";
49   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
50     // save on file
51     const char* filename = "T0residualMisalignment.root";
52     TFile f(filename,"RECREATE");
53     if(!f){
54       Error(macroname,"cannot open file for output\n");
55       return;
56     }
57     Info(macroname,"Saving alignment objects to the file %s", filename);
58     f.cd();
59     f.WriteObject(array,"T0AlignObjs","kSingleKey");
60     f.Close();
61   }else{
62     // save in CDB storage
63     TString Storage = gSystem->Getenv("STORAGE");
64     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
65       Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
66       return;
67     }
68     Info(macroname,"Saving alignment objects in CDB storage %s",
69          Storage.Data());
70     AliCDBManager* cdb = AliCDBManager::Instance();
71     AliCDBStorage* storage = cdb->GetStorage(Storage.Data());
72     if(!storage){
73       Error(macroname,"Unable to open storage %s\n",Storage.Data());
74       return;
75     }
76     AliCDBMetaData* md = new AliCDBMetaData();
77     md->SetResponsible("Tomasz Malkiewicz");
78     md->SetComment("Residual misalignment for T0, produced with sigmatr=0.05 and sigmarot=0.3 in the local RS");
79     md->SetAliRootVersion(gSystem->Getenv("$ARVERSION"));
80     AliCDBId id("T0/Align/Data",0,AliCDBRunRange::Infinity());
81     storage->Put(array,id,md);
82   }
83
84   array->Delete();
85
86 }
87