Extacting the OCDB in a separate module. The detectors have write permission in the...
[u/mrichter/AliRoot.git] / EMCAL / MakeEMCALResMisAlignment.C
CommitLineData
1895a097 1void MakeEMCALResMisAlignment(){
2 // Create TClonesArray of residual misalignment objects for EMCAL
3 //
6fce62af 4 const char* macroname = "MakeEMCALResMisAlignment.C";
9d9bbd17 5 const AliEMCALGeometry *emcalGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName(),"");
6 if(!emcalGeom) {
289cc8a7 7 Error("MakeEMCALResMisAlignment","Cannot obtain AliEMCALGeometry singleton\n");
8 return;
9 }
10
9d9bbd17 11 TClonesArray *array = new TClonesArray("AliAlignObjParams",emcalGeom->GetNumberOfSuperModules());
289cc8a7 12 TClonesArray &alobj = *array;
13
1895a097 14
6fce62af 15 // Activate CDB storage and load geometry from CDB
16 AliCDBManager* cdb = AliCDBManager::Instance();
162637e4 17 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
6fce62af 18 cdb->SetRun(0);
19
20 AliCDBStorage* storage;
21
a24be56b 22 if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
6fce62af 23 TString Storage = gSystem->Getenv("STORAGE");
24 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
25 Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
26 return;
27 }
28 storage = cdb->GetStorage(Storage.Data());
29 if(!storage){
30 Error(macroname,"Unable to open storage %s\n",Storage.Data());
31 return;
32 }
33 AliCDBPath path("GRP","Geometry","Data");
34 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
35 if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
36 entry->SetOwner(0);
37 TGeoManager* geom = (TGeoManager*) entry->GetObject();
38 AliGeomManager::SetGeometry(geom);
39 }else{
40 AliGeomManager::LoadGeometry(); //load geom from default CDB storage
41 }
1895a097 42
43 Double_t dx, dy, dz, dpsi, dtheta, dphi;
44
7e154d52 45 const TString basepath = "EMCAL/FullSupermodule";
d3a9c52a 46 const TString hbasepath = "EMCAL/HalfSupermodule";
1895a097 47 TString pathstr;
48
49 Int_t iIndex=0; // let all modules have index=0 in a layer with no LUT
ae079791 50 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
51 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
1895a097 52
53 Int_t i;
d3a9c52a 54 Int_t j=0;
1895a097 55
56 // RS = local
57 // sigma translation = 1mm
58 // sigma rotation = 0.1 degree
59 TRandom *rnd = new TRandom(4321);
289cc8a7 60 Double_t sigmatr = 0.05; // max shift in cm w.r.t. local RS
1895a097 61 Double_t sigmarot = 0.1; // max rot in degrees w.r.t. local RS
d3a9c52a 62
1895a097 63 for(i=0; i<10; i++){
64 dx = rnd->Gaus(0.,sigmatr);
65 dy = rnd->Gaus(0.,sigmatr);
66 dz = rnd->Gaus(0.,sigmatr);
67 dpsi = rnd->Gaus(0.,sigmarot);
68 dtheta = rnd->Gaus(0.,sigmarot);
69 dphi = rnd->Gaus(0.,sigmarot);
70 pathstr=basepath;
71 pathstr+=(i+1);
90dbf5fb 72 new(alobj[j++]) AliAlignObjParams(pathstr, volid, dx, dy, dz, dpsi, dtheta, dphi, kFALSE);
d3a9c52a 73 }
74
75 for(i=0; i<2; i++){
76 dx = rnd->Gaus(0.,sigmatr);
77 dy = rnd->Gaus(0.,sigmatr);
78 dz = rnd->Gaus(0.,sigmatr);
79 dpsi = rnd->Gaus(0.,sigmarot);
80 dtheta = rnd->Gaus(0.,sigmarot);
81 dphi = rnd->Gaus(0.,sigmarot);
82 pathstr=hbasepath;
83 pathstr+=(i+1);
90dbf5fb 84 new(alobj[j++]) AliAlignObjParams(pathstr, volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
1895a097 85 }
86
a24be56b 87 if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
1895a097 88 // save on file
dfe9c69d 89 const char* filename = "EMCALresidualMisalignment.root";
90 TFile f(filename,"RECREATE");
91 if(!f){
92 Error(macroname,"cannot open file for output\n");
93 return;
94 }
95 Info(macroname,"Saving alignment objects to the file %s", filename);
1895a097 96 f.cd();
dfe9c69d 97 f.WriteObject(array,"EMCALAlignObjs","kSingleKey");
1895a097 98 f.Close();
99 }else{
100 // save in CDB storage
1895a097 101 AliCDBMetaData* md = new AliCDBMetaData();
289cc8a7 102 md->SetResponsible("Jennifer Klay");
103 md->SetComment("Residual misalignment for EMCAL, produced with sigmatr=0.05 and sigmarot=0.1 in the local RS");
5bd470e1 104 md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
dfe9c69d 105 AliCDBId id("EMCAL/Align/Data",0,AliCDBRunRange::Infinity());
1895a097 106 storage->Put(array,id,md);
107 }
108
109 array->Delete();
110
111}
112