.so cleanup: more less-obvious cleanup
[u/mrichter/AliRoot.git] / TPC / MakeTPCResMisAlignment.C
CommitLineData
1895a097 1void MakeTPCResMisAlignment(){
2 // Create TClonesArray of residual misalignment objects for TPC
3 //
6fce62af 4 const char* macroname = "MakeTPCResMisAlignment.C";
5
6 // Activate CDB storage and load geometry from CDB
7 AliCDBManager* cdb = AliCDBManager::Instance();
162637e4 8 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
6fce62af 9 cdb->SetRun(0);
10
11 AliCDBStorage* storage;
12
a24be56b 13 if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
6fce62af 14 TString Storage = gSystem->Getenv("STORAGE");
15 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
16 Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
17 return;
18 }
19 storage = cdb->GetStorage(Storage.Data());
20 if(!storage){
21 Error(macroname,"Unable to open storage %s\n",Storage.Data());
22 return;
23 }
24 AliCDBPath path("GRP","Geometry","Data");
25 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
26 if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
27 entry->SetOwner(0);
28 TGeoManager* geom = (TGeoManager*) entry->GetObject();
29 AliGeomManager::SetGeometry(geom);
30 }else{
31 AliGeomManager::LoadGeometry(); //load geom from default CDB storage
32 }
1895a097 33
90dbf5fb 34 TClonesArray *array = new TClonesArray("AliAlignObjParams",100);
1895a097 35 TClonesArray &alobj = *array;
36
37 TRandom *rnd = new TRandom(4357);
1895a097 38 Double_t dx, dy, dz, dpsi, dtheta, dphi;
39 Int_t j = 0;
40
41 // RS = local
d3a9c52a 42 // sigma translation = 0.1 mm
43 // sigma rotation = 0.1 mrad
1895a097 44 Float_t sigmatr=0.01;
d3a9c52a 45 Float_t sigmarot = 0.006;
ae079791 46 for (Int_t iLayer = AliGeomManager::kTPC1; iLayer <= AliGeomManager::kTPC2; iLayer++) {
47 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
1895a097 48
5bd470e1 49 dx = rnd->Gaus(0,sigmatr);
50 dy = rnd->Gaus(0,sigmatr);
51 dz = rnd->Gaus(0,sigmatr);
52 dpsi = rnd->Gaus(0,sigmarot);
53 dtheta = rnd->Gaus(0,sigmarot);
54 dphi = rnd->Gaus(0,sigmarot);
1895a097 55
ae079791 56 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iModule);
57 const char *symname = AliGeomManager::SymName(volid);
90dbf5fb 58 new(alobj[j]) AliAlignObjParams(symname, volid, dx, dy, dz, dpsi, dtheta, dphi, kFALSE);
1895a097 59 j++;
60 }
61 }
62
a24be56b 63 if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
1895a097 64 // save on file
dfe9c69d 65 const char* filename = "TPCresidualMisalignment.root";
66 TFile f(filename,"RECREATE");
67 if(!f){
68 Error(macroname,"cannot open file for output\n");
69 return;
70 }
71 Info(macroname,"Saving alignment objects to the file %s", filename);
1895a097 72 f.cd();
73 f.WriteObject(array,"TPCAlignObjs","kSingleKey");
74 f.Close();
75 }else{
76 // save in CDB storage
1895a097 77 AliCDBMetaData* md = new AliCDBMetaData();
78 md->SetResponsible("Marian Ivanov");
79 md->SetComment("Residual misalignment for TPC, sigmatr=0.01 and sigmarot=0.6 in the local RS");
5bd470e1 80 md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
dfe9c69d 81 AliCDBId id("TPC/Align/Data",0,AliCDBRunRange::Infinity());
1895a097 82 storage->Put(array,id,md);
83 }
84
85 array->Delete();
86
87}
88