]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/MakeTRDFullMisAlignment.C
d60f2928926db7ecccac2180b129745ca28649e5
[u/mrichter/AliRoot.git] / TRD / MakeTRDFullMisAlignment.C
1 void MakeTRDFullMisAlignment(){
2   // Create TClonesArray of full misalignment objects for TRD
3   // Expects to read objects for FRAME
4   // 
5   TClonesArray *array = new TClonesArray("AliAlignObjParams",1000);
6   const char* macroname = "MakeTRDFullMisAlignment.C";
7
8   // Activate CDB storage and load geometry from CDB
9   AliCDBManager* cdb = AliCDBManager::Instance();
10   if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
11   cdb->SetRun(0);
12   
13   AliCDBStorage* storage;
14   
15   if( gSystem->Getenv("TOCDB") == TString("kTRUE") ){
16     TString Storage = gSystem->Getenv("STORAGE");
17     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
18       Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
19       return;
20     }
21     storage = cdb->GetStorage(Storage.Data());
22     if(!storage){
23       Error(macroname,"Unable to open storage %s\n",Storage.Data());
24       return;
25     }
26     AliCDBPath path("GRP","Geometry","Data");
27     AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
28     if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
29     entry->SetOwner(0);
30     TGeoManager* geom = (TGeoManager*) entry->GetObject();
31     AliGeomManager::SetGeometry(geom);
32   }else{
33     AliGeomManager::LoadGeometry(); //load geom from default CDB storage
34   }    
35                   
36   // load FRAME full misalignment objects (if needed, the macro
37   // for FRAME has to be ran in advance) and apply them to geometry
38   Info(macroname,"Loading FRAME alignment objects from CDB storage %s",
39       Storage.Data());
40   AliCDBPath fpath("GRP","Align","Data");
41   if( gSystem->Getenv("TOCDB") == TString("kTRUE") ){
42     AliCDBEntry *eFrame = storage->Get(fpath.GetPath(),cdb->GetRun());
43     if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
44     TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject();
45     arFrame->Sort();
46     Int_t nvols = arFrame->GetEntriesFast();
47     Bool_t flag = kTRUE;
48     for(Int_t j=0; j<nvols; j++)
49       {
50         AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j);
51         if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
52       }
53     if(!flag)
54       Fatal(macroname,"Error in the application of FRAME objects");
55   }else{
56     AliCDBEntry *eFrame = cdb->Get(fpath.GetPath());
57     if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
58     TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject();
59     arFrame->Sort();
60     Int_t nvols = arFrame->GetEntriesFast();
61     Bool_t flag = kTRUE;
62     for(Int_t j=0; j<nvols; j++)
63       {
64         AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j);
65         if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
66       }
67     if(!flag)
68       Fatal(macroname,"Error in the application of FRAME objects");
69   }
70
71    
72   // sigmas for the supermodules
73   Double_t smdx=0.3; // 3 mm
74   Double_t smdy=0.3; // 3 mm
75   Double_t smdz=0.3; // 3 mm
76   Double_t smrx=0.4/1000/TMath::Pi()*180; // 0.4 mrad
77   Double_t smry=2.0/1000/TMath::Pi()*180; // 2 mrad
78   Double_t smrz=0.4/1000/TMath::Pi()*180; // 0.4 mrad
79
80
81   // sigmas for the chambers
82   Double_t chdx=0.1; // 1 mm
83   Double_t chdy=0.1; // 1 mm
84   Double_t chdz=0.1; // 1 mm
85   Double_t chrx=1.0/1000/TMath::Pi()*180; // 1 mrad
86   Double_t chry=1.0/1000/TMath::Pi()*180; // 1 mrad
87   Double_t chrz=0.7/1000/TMath::Pi()*180; // 0.7 mrad
88
89   Double_t dx,dy,dz,rx,ry,rz;
90
91   Int_t j=0;
92   TRandom *ran = new TRandom(4357);
93   UShort_t volid;
94   const char *symname;
95
96   // create the supermodules' alignment objects
97   for (int i; i<18; i++) {
98     TString sm_symname(Form("TRD/sm%02d",i));
99     ran->Rannor(dx,rx);
100     ran->Rannor(dy,ry);
101     ran->Rannor(dz,rz);
102     dx*=smdx;
103     dy*=smdy;
104     dz*=smdz;
105     rx*=smrx;
106     ry*=smry;
107     rz*=smrz;
108     new((*array)[j++]) AliAlignObjParams(sm_symname.Data(),0,dx,dy,dz,rx,ry,rz,kFALSE);
109   }
110
111   for(Int_t k=0; k<18; k++){
112     AliAlignObjParams* smobj = (AliAlignObjParams*)array->UncheckedAt(k);
113     if(!smobj->ApplyToGeometry()){
114       cout<<"application of object "<<k<<" failed!"<<endl;
115       return;
116     }
117   }
118
119   // create the chambers' alignment objects
120   ran = new TRandom(4357);
121   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
122     for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer); iModule++) {
123       ran->Rannor(dx,rx);
124       ran->Rannor(dy,ry);
125       ran->Rannor(dz,rz);
126       dx*=chdx;
127       dy*=chdy;
128       dz*=chdz;
129       rx*=chrx;
130       ry*=chry;
131       rz*=chrz;
132       volid = AliGeomManager::LayerToVolUID(iLayer,iModule);
133       symname = AliGeomManager::SymName(volid);
134       new((*array)[j++]) AliAlignObjParams(symname,volid,dx,dy,dz,rx,ry,rz,kFALSE);
135     }
136   }
137
138   if( gSystem->Getenv("TOCDB") != TString("kTRUE") ){
139     // save on file
140     const char* filename = "TRDfullMisalignment.root";
141     TFile f(filename,"RECREATE");
142     if(!f){
143       Error(macroname,"cannot open file for output\n");
144       return;
145     }
146     Info(macroname,"Saving alignment objects to the file %s", filename);
147     f.cd();
148     f.WriteObject(array,"TRDAlignObjs","kSingleKey");
149     f.Close();
150   }else{
151     // save in CDB storage
152     Info(macroname,"Saving alignment objects in CDB storage %s",
153          Storage.Data());
154     AliCDBMetaData* md = new AliCDBMetaData();
155     md->SetResponsible("Dariusz Miskowiec");
156     md->SetComment("Full misalignment for TRD");
157     md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
158     AliCDBId id("TRD/Align/Data",0,AliCDBRunRange::Infinity());
159     storage->Put(array,id,md);
160   }
161
162   array->Delete();
163 }
164
165