]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/MakeTOFFullMisAlignment.C
AliAlignObjAngles becomes AliAlignObjParams (Raffaele)
[u/mrichter/AliRoot.git] / TOF / MakeTOFFullMisAlignment.C
1 void MakeTOFFullMisAlignment(){
2   // Create TClonesArray of full misalignment objects for TOF
3   // Expects to read objects for FRAME
4   // 
5   TClonesArray *array = new TClonesArray("AliAlignObjParams",2000);
6   const char* macroname = "MakeTOFFullMisAlignment.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 run 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 alignment 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 alignment objects");
69   }
70
71   //Produce objects for TOF supermodules
72   Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT
73   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
74   UShort_t dvoluid = AliGeomManager::LayerToVolUID(iLayer,iIndex); //dummy vol id 
75
76   Int_t nSMTOF = 18;
77   Int_t j=0;
78   Double_t smdx, smdy, smdz, dpsi, dtheta, dphi;
79   TRandom *rnd   = new TRandom(2345);
80   Double_t sigmatr = 0.4; // max shift in cm w.r.t. local ideal RS
81   Double_t sigmarot = 0.06; // max rot in deg w.r.t. local ideal RS (~ 1 mrad)
82   
83   for(Int_t i=0; i<nSMTOF; i++) {
84     TString symname(Form("TOF/sm%02d",i));
85     smdx = rnd->Gaus(0.,sigmatr);
86     smdy = rnd->Gaus(0.,sigmatr);
87     smdz =0;
88     dpsi = 0.;
89     dtheta = rnd->Gaus(0.,sigmarot);
90     dphi = 0.;
91     new((*array)[j++]) AliAlignObjParams(symname.Data(), dvoluid, smdx, smdy, smdz, dpsi, dtheta, dphi, kFALSE);
92   }
93   // Apply objects for TOF supermodules 
94   for(Int_t i=0; i<nSMTOF; i++){
95     AliAlignObjParams* smobj = (AliAlignObjParams*)array->UncheckedAt(i);
96     if(!smobj->ApplyToGeometry()){
97       cout<<"application of object "<<i<<" failed!"<<endl;
98       return;
99     }
100   }
101
102   //Produce objects for TOF strips (same sigmas as for residual misalignment)
103   AliGeomManager::ELayerID idTOF = AliGeomManager::kTOF;
104
105   Double_t sdx=0.; 
106   Double_t sdy=0.; 
107   Double_t sdz=0.;
108   Double_t sdpsi, sdtheta, sdphi;
109   TRandom *rnds   = new TRandom(4357);
110   sigmatr = 0.1; // max shift in cm w.r.t. local ideal RS
111
112   for(i=0; i<AliGeomManager::LayerSize(idTOF); i++) {
113     sdx = 0;
114     sdy = rnds->Gaus(0.,sigmatr);
115     sdz = rnds->Gaus(0.,sigmatr);
116     sdpsi = 0.;
117     sdtheta = 0.;
118     sdphi = 0.;
119     new((*array)[j++]) AliAlignObjParams(AliGeomManager::SymName(idTOF,i), AliGeomManager::LayerToVolUID(idTOF,i), sdx, sdy, sdz, sdpsi, sdtheta, sdphi, kFALSE);
120   }
121
122   if( gSystem->Getenv("TOCDB") != TString("kTRUE") ){
123     // save in file
124     const char* filename = "TOFfullMisalignment.root";
125     TFile f(filename,"RECREATE");
126     if(!f){
127       Error(macroname,"cannot open file for output\n");
128       return;
129     }
130     Info(macroname,"Saving alignment objects in file %s", filename);
131     f.cd();
132     f.WriteObject(array,"TOFAlignObjs","kSingleKey");
133     f.Close();
134   }else{
135     // save in CDB storage
136     Info(macroname,"Saving alignment objects in CDB storage %s",
137          Storage.Data());
138     AliCDBMetaData* md = new AliCDBMetaData();
139     md->SetResponsible("Silvia Arcelli");
140     md->SetComment("Full misalignment for TOF");
141     md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
142     AliCDBId id("TOF/Align/Data",0,AliCDBRunRange::Infinity());
143     storage->Put(array,id,md);
144   }
145
146   array->Delete();
147
148 }
149
150