]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/MakeTOFFullMisAlignment.C
Merging THbtp and HBTP in one library. Comiplation on Windows/Cygwin
[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   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 run in advance) and apply them to geometry
39   AliCDBPath fpath("GRP","Align","Data");
40   if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
41     Info(macroname,"Loading FRAME alignment objects from CDB storage %s",
42         Storage.Data());
43     AliCDBEntry *eFrame = storage->Get(fpath.GetPath(),cdb->GetRun());
44   }else{
45     AliCDBEntry *eFrame = cdb->Get(fpath.GetPath());
46   }
47   if(!eFrame) Fatal(macroname,"Could not get the specified CDB entry!");
48   TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject();
49   arFrame->Sort();
50   Int_t nvols = arFrame->GetEntriesFast();
51   Bool_t flag = kTRUE;
52   for(Int_t j=0; j<nvols; j++)
53   {
54     AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j);
55     if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
56   }
57   if(!flag) Fatal(macroname,"Error in the application of FRAME alignment objects");
58
59   //Produce objects for TOF supermodules
60   Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT
61   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
62   UShort_t dvoluid = AliGeomManager::LayerToVolUID(iLayer,iIndex); //dummy vol id 
63
64   Int_t nSMTOF = 18;
65   Int_t sActive[18]={0,1,1,0,0,0,1,1,0,1,1,1,1,0,0,1,1,1};
66   Int_t j=0;
67   Double_t smdx, smdy, smdz=0., dpsi=0., dtheta, dphi=0.;
68   TRandom *rnd   = new TRandom(2345);
69   Double_t sigmatr = 0.4; // max shift in cm w.r.t. local ideal RS
70   Double_t sigmarot = 0.06; // max rot in deg w.r.t. local ideal RS (~ 1 mrad)
71   
72   for(Int_t isect=0; isect<nSMTOF; isect++) {
73     TString symname(Form("TOF/sm%02d",isect));
74     smdx = rnd->Gaus(0.,sigmatr);
75     smdy = rnd->Gaus(0.,sigmatr);
76     dtheta = rnd->Gaus(0.,sigmarot);
77     if( (TString(gSystem->Getenv("PARTGEOM")) == TString("kTRUE")) && !sActive[isect] ) continue;
78     new((*array)[j++]) AliAlignObjParams(symname.Data(), dvoluid, smdx, smdy, smdz, dpsi, dtheta, dphi, kFALSE);
79   }
80   // Apply objects for TOF supermodules 
81   Int_t smCounter=0;
82   for(Int_t isect=0; isect<nSMTOF; isect++){
83     if( (TString(gSystem->Getenv("PARTGEOM")) == TString("kTRUE")) && !sActive[isect] ) continue;
84     AliAlignObjParams* smobj = (AliAlignObjParams*)array->UncheckedAt(smCounter++);
85     Info(macroname,Form("Applying object for sector %d ",isect));
86     if(!smobj->ApplyToGeometry()){
87       Fatal(macroname,Form("application of full misalignment object for sector %d failed!",isect));
88       return;
89     }
90   }
91
92   //Produce objects for TOF strips (same sigmas as for residual misalignment)
93   AliGeomManager::ELayerID idTOF = AliGeomManager::kTOF;
94   Int_t strId=-1;
95
96   Double_t sdx=0., sdy=0., sdz=0., sdpsi=0., sdtheta=0., sdphi=0.;
97   TRandom *rnds   = new TRandom(4357);
98   sigmatr = 0.1; // max shift in cm w.r.t. local ideal RS
99
100   Int_t nstrA=15;
101   Int_t nstrB=19;
102   Int_t nstrC=19;
103   Int_t nSectors=18;
104   Int_t nStrips=nstrA+2*nstrB+2*nstrC;
105
106   for (Int_t isect = 0; isect < nSectors; isect++) {
107     for (Int_t istr = 1; istr <= nStrips; istr++) {
108     sdy = rnds->Gaus(0.,sigmatr);
109     sdz = rnds->Gaus(0.,sigmatr);
110     strId++;
111     if ((isect==13 || isect==14 || isect==15) && (istr >= 39 && istr <= 53)) continue;
112     if( (TString(gSystem->Getenv("PARTGEOM")) == TString("kTRUE")) && !sActive[isect] ) continue;
113     new((*array)[j++]) AliAlignObjParams(AliGeomManager::SymName(idTOF,strId),AliGeomManager::LayerToVolUID(idTOF,strId), sdx, sdy, sdz, sdpsi, sdtheta, sdphi, kFALSE);
114     }
115   }
116
117   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
118     // save in file
119     const char* filename = "TOFfullMisalignment.root";
120     TFile f(filename,"RECREATE");
121     if(!f){
122       Error(macroname,"cannot open file for output\n");
123       return;
124     }
125     Info(macroname,"Saving alignment objects in file %s", filename);
126     f.cd();
127     f.WriteObject(array,"TOFAlignObjs","kSingleKey");
128     f.Close();
129   }else{
130     // save in CDB storage
131     Info(macroname,"Saving alignment objects in CDB storage %s",
132          Storage.Data());
133     AliCDBMetaData* md = new AliCDBMetaData();
134     md->SetResponsible("Silvia Arcelli");
135     md->SetComment("Full misalignment for TOF");
136     md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
137     AliCDBId id("TOF/Align/Data",0,AliCDBRunRange::Infinity());
138     storage->Put(array,id,md);
139   }
140
141   array->Delete();
142
143 }
144
145