]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/MakeTRDFullMisAlignment.C
Bug fix by Theodor
[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/OCDB");
11   cdb->SetRun(0);
12   
13   AliCDBStorage* storage;
14   TString Storage;
15   
16   if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
17     Storage = gSystem->Getenv("STORAGE");
18     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
19       Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
20       return;
21     }
22     storage = cdb->GetStorage(Storage.Data());
23     if(!storage){
24       Error(macroname,"Unable to open storage %s\n",Storage.Data());
25       return;
26     }
27     AliCDBPath path("GRP","Geometry","Data");
28     AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
29     if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
30     entry->SetOwner(0);
31     TGeoManager* geom = (TGeoManager*) entry->GetObject();
32     AliGeomManager::SetGeometry(geom);
33   }else{
34     AliGeomManager::LoadGeometry(); //load geom from default CDB storage
35   }    
36                   
37   // load FRAME full misalignment objects (if needed, the macro
38   // for FRAME has to be ran in advance) and apply them to geometry
39   AliCDBPath fpath("GRP","Align","Data");
40   AliCDBEntry *eFrame;
41   if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
42     Info(macroname,"Loading FRAME alignment objects from CDB storage %s",
43       Storage.Data());
44     eFrame = storage->Get(fpath.GetPath(),cdb->GetRun());
45   }else{
46     eFrame = cdb->Get(fpath.GetPath());
47   }
48   if(!eFrame) Fatal(macroname,"Could not get the specified CDB entry!");
49   TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject();
50   arFrame->Sort();
51   Int_t nvols = arFrame->GetEntriesFast();
52   Bool_t flag = kTRUE;
53   for(Int_t j=0; j<nvols; j++)
54   {
55     AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j);
56     if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
57   }
58   if(!flag) Fatal(macroname,"Error in the application of FRAME objects");
59
60   // Sigmas for the chambers
61   Double_t smdx    = 0.3; // 3 mm
62   Double_t smdy    = 0.3; // 3 mm
63   Double_t smdz    = 0.3; // 3 mm
64   Double_t smrx    = 0.4 / 1000.0 / TMath::Pi()*180; // 0.4 mrad
65   Double_t smry    = 2.0 / 1000.0 / TMath::Pi()*180; // 2.0 mrad
66   Double_t smrz    = 0.4 / 1000.0 / TMath::Pi()*180; // 0.4 mrad
67   // Truncation for the chambers
68   Double_t cutSmdx = 3.0 * smdx;
69   Double_t cutSmdy = 3.0 * smdy;
70   Double_t cutSmdz = 3.0 * smdz;
71
72   // Sigmas for the chambers
73   Double_t chdx    = 0.05;  // 0.5 mm
74   Double_t chdy    = 0.1;   // 1.0 mm
75   Double_t chdz    = 0.007; // 70  microns
76   Double_t chrx    = 0.0005 / 1000.0 / TMath::Pi()*180; // 0 mrad
77   Double_t chry    = 0.0005 / 1000.0 / TMath::Pi()*180; // 0 mrad
78   Double_t chrz    = 0.3    / 1000.0 / TMath::Pi()*180; // 0.3 mrad
79   // Truncation for the chambers
80   Double_t cutChdx = 1.0  * chdx;
81   Double_t cutChdy = 1.0  * chdy;
82   Double_t cutChdz = 0.14 * chdz;
83
84   Int_t sActive[18]={1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1};
85   Double_t dx,dy,dz,rx,ry,rz;
86
87   Int_t j=0;
88   UShort_t volid;
89   const char *symname;
90
91   // create the supermodules' alignment objects
92   for (int iSect; iSect<18; iSect++) {
93     TString sm_symname(Form("TRD/sm%02d",iSect));
94     dx = AliMathBase::TruncatedGaus(0.0,smdx,cutSmdx); 
95     dy = AliMathBase::TruncatedGaus(0.0,smdy,cutSmdy); 
96     dz = AliMathBase::TruncatedGaus(0.0,smdz,cutSmdz); 
97     rx = gRandom->Rndm() * 2.0*smrx - smrx;
98     ry = gRandom->Rndm() * 2.0*smry - smry;
99     rz = gRandom->Rndm() * 2.0*smrz - smrz;
100     if( (TString(gSystem->Getenv("REALSETUP")) == TString("kTRUE")) && !sActive[iSect] ) continue;
101     new((*array)[j++]) AliAlignObjParams(sm_symname.Data(),0,dx,dy,dz,rx,ry,rz,kFALSE);
102   }
103   // apply supermodules' alignment objects
104   Int_t smCounter=0;
105   for(Int_t iSect=0; iSect<18; iSect++){
106     if( (TString(gSystem->Getenv("REALSETUP")) == TString("kTRUE")) && !sActive[iSect] ) continue;
107     AliAlignObjParams* smobj =
108       (AliAlignObjParams*)array->UncheckedAt(smCounter++);
109     if(!smobj->ApplyToGeometry()){
110       Fatal(macroname,Form("application of full misalignment object for sector %d failed!",iSect));
111       return;
112     }
113   }
114
115   // create the chambers' alignment objects
116   ran = new TRandom(4357);
117   Int_t chId;
118   for (Int_t iLayer = AliGeomManager::kTRD1; iLayer <= AliGeomManager::kTRD6; iLayer++) {
119     chId=-1;
120     for (Int_t iSect = 0; iSect < 18; iSect++){
121       for (Int_t iCh = 0; iCh < 5; iCh++) {
122         dx = AliMathBase::TruncatedGaus(0.0,chdx,cutChdx); 
123         dy = AliMathBase::TruncatedGaus(0.0,chdy,cutChdy); 
124         dz = AliMathBase::TruncatedGaus(0.0,chdz,cutChdz); 
125         rx = gRandom->Rndm() * 2.0*chrx - chrx;
126         ry = gRandom->Rndm() * 2.0*chry - chry;
127         rz = gRandom->Rndm() * 2.0*chrz - chrz;
128         chId++;
129         if ((iSect==13 || iSect==14 || iSect==15) && iCh==2) continue;
130         volid = AliGeomManager::LayerToVolUID(iLayer,chId);
131         if( (TString(gSystem->Getenv("REALSETUP")) == TString("kTRUE")) && !sActive[iSect] ) continue;
132         symname = AliGeomManager::SymName(volid);
133         new((*array)[j++]) AliAlignObjParams(symname,volid,dx,dy,dz,rx,ry,rz,kFALSE);
134       }
135     }
136   }
137
138   if( TString(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