]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/MakeTOFFullMisAlignment.C
added a method to return number active channels
[u/mrichter/AliRoot.git] / TOF / MakeTOFFullMisAlignment.C
1 void MakeTOFFullMisAlignment() {
2   // 
3   // Create TClonesArray of full misalignment objects for TOF
4   // Expects to read objects for FRAME
5   // 
6
7   const char* macroname = "MakeTOFFullMisAlignment.C";
8
9   TClonesArray *array = new TClonesArray("AliAlignObjParams",2000);
10   
11   // Activate CDB storage and load geometry from CDB
12   AliCDBManager* cdb = AliCDBManager::Instance();
13   if (!cdb->IsDefaultStorageSet())
14     cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
15   cdb->SetRun(0);
16
17   AliCDBStorage* storage;
18   TString Storage;
19
20   if ( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ) {
21     Storage = gSystem->Getenv("STORAGE");
22     if (!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
23       Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
24       return;
25     }
26     storage = cdb->GetStorage(Storage.Data());
27     if (!storage) {
28       Error(macroname,"Unable to open storage %s\n",Storage.Data());
29       return;
30     }
31     AliCDBPath path("GRP","Geometry","Data");
32     AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
33     if (!entry)
34       Fatal(macroname,"Could not get the specified CDB entry!");
35     entry->SetOwner(0);
36     TGeoManager* geom = (TGeoManager*) entry->GetObject();
37     AliGeomManager::SetGeometry(geom);
38   } else
39     AliGeomManager::LoadGeometry(); //load geom from default CDB storage
40
41   // load FRAME full misalignment objects (if needed, the macro
42   // for FRAME has to be run in advance) and apply them to geometry
43   AliCDBPath fpath("GRP","Align","Data");
44   if ( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ) {
45     Info(macroname,"Loading FRAME alignment objects from CDB storage %s",
46          Storage.Data());
47     AliCDBEntry *eFrame = storage->Get(fpath.GetPath(),cdb->GetRun());
48   } else
49     AliCDBEntry *eFrame = cdb->Get(fpath.GetPath());
50
51   if (!eFrame)
52     Fatal(macroname,"Could not get the specified CDB entry!");
53
54   TClonesArray* arFrame = (TClonesArray*) eFrame->GetObject();
55   arFrame->Sort();
56   Int_t nvols = arFrame->GetEntriesFast();
57   Bool_t flag = kTRUE;
58   for(Int_t j=0; j<nvols; j++)
59   {
60     AliAlignObj* alobj = (AliAlignObj*) arFrame->UncheckedAt(j);
61     if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
62   }
63   if (!flag)
64     Fatal(macroname,"Error in the application of FRAME alignment objects");
65
66   //Produce objects for TOF supermodules
67   Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT
68   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
69   UShort_t dvoluid = AliGeomManager::LayerToVolUID(iLayer,iIndex); //dummy vol id 
70
71   Int_t nSMTOF = 18;
72   Int_t j=0;
73   Double_t smdx, smdy, smdz=0., dpsi=0., dtheta, dphi=0.;
74   TRandom *rnd   = new TRandom(2345);
75   Double_t sigmatr = 0.4; // max shift in cm w.r.t. local ideal RS
76   Double_t sigmarot = 0.06; // max rot in deg w.r.t. local ideal RS (~ 1 mrad)
77   
78   for (Int_t isect=0; isect<nSMTOF; isect++) {
79     TString symname(Form("TOF/sm%02d",isect));
80     smdx = rnd->Gaus(0.,sigmatr);
81     smdy = rnd->Gaus(0.,sigmatr);
82     dtheta = rnd->Gaus(0.,sigmarot);
83     new((*array)[j++]) AliAlignObjParams(symname.Data(),
84                                          dvoluid,
85                                          smdx, smdy, smdz, dpsi, dtheta, dphi, kFALSE);
86   }
87   // Apply objects for TOF supermodules 
88   Int_t smCounter=0;
89   for (Int_t isect=0; isect<nSMTOF; isect++) {
90     AliAlignObjParams* smobj = (AliAlignObjParams*)array->UncheckedAt(smCounter++);
91     //Info(macroname,Form("Applying object for sector %d ",isect));
92     if ( !smobj->ApplyToGeometry() )
93       Fatal(macroname,Form("application of full misalignment object for sector %d failed!",isect));
94
95   }
96
97   //Produce objects for TOF strips (same sigmas as for residual misalignment)
98   AliGeomManager::ELayerID idTOF = AliGeomManager::kTOF;
99   Int_t strId=-1;
100
101   Double_t sdx=0., sdy=0., sdz=0., sdpsi=0., sdtheta=0., sdphi=0.;
102   //TRandom *rnds   = new TRandom(4357);
103   sigmatr = 0.1; // max shift in cm w.r.t. local ideal RS
104
105   Int_t nstrA=15;
106   Int_t nstrB=19;
107   Int_t nstrC=19;
108   Int_t nSectors=18;
109   Int_t nStrips=nstrA+2*nstrB+2*nstrC;
110   Double_t cuty=0., cutz=0., cut=3*sigmatr;
111
112   for (Int_t isect = 0; isect < nSectors; isect++) {
113     for (Int_t istr = 1; istr <= nStrips; istr++) {
114     switch (istr) {
115     case 25:
116     case 29:
117     case 63:
118     case 67:
119       cuty = sigmatr*0.6;
120       sdy  = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty);
121       sdz  = AliMathBase::TruncatedGaus(0., sigmatr, cut);
122       strId++;
123       break;
124       /*
125     case 38:
126       cuty = sigmatr*2.5;
127       cutz = sigmatr*2.5;
128       sdy  = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty);
129       sdz  = AliMathBase::TruncatedGaus(0., sigmatr, cut, cutz);
130       strId++;
131       break;
132     case 54:
133       cuty = sigmatr*2.5;
134       cutz = sigmatr*2.5;
135       sdy  = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty);
136       sdz  = AliMathBase::TruncatedGaus(0., sigmatr, cutz, cut);
137       strId++;
138       break;
139       */
140     default:
141       sdy = AliMathBase::TruncatedGaus(0., sigmatr, cut);
142       sdz = AliMathBase::TruncatedGaus(0., sigmatr, cut);
143       strId++;
144       break;
145     }
146
147     if ((isect==13 || isect==14 || isect==15) && (istr >= 39 && istr <= 53)) continue;
148     new((*array)[j++]) AliAlignObjParams(AliGeomManager::SymName(idTOF,strId),
149                                          AliGeomManager::LayerToVolUID(idTOF,strId),
150                                          sdx, sdy, sdz, sdpsi, sdtheta, sdphi, kFALSE);
151     }
152   }
153
154   if ( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ) {
155     // save in file
156     const char* filename = "TOFfullMisalignment.root";
157     TFile f(filename,"RECREATE");
158     if(!f){
159       Error(macroname,"cannot open file for output\n");
160       return;
161     }
162     Info(macroname,"Saving alignment objects in file %s", filename);
163     f.cd();
164     f.WriteObject(array,"TOFAlignObjs","kSingleKey");
165     f.Close();
166   } else {
167     // save in CDB storage
168     Info(macroname,"Saving alignment objects in CDB storage %s",
169          Storage.Data());
170     AliCDBMetaData* md = new AliCDBMetaData();
171     md->SetResponsible("Silvia Arcelli");
172     md->SetComment("Full misalignment for TOF");
173     md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
174     AliCDBId id("TOF/Align/Data",0,AliCDBRunRange::Infinity());
175     storage->Put(array,id,md);
176   }
177
178   array->Delete();
179
180 }
181
182 /*
183 Double_t LocalTruncatedGaus(Double_t mean, Double_t sigma, Double_t cutatL, Double_t cutatR)
184 {
185   // return number generated according to a gaussian distribution N(mean,sigma) truncated at cutat
186   //
187   Double_t value;
188   do{
189     value=gRandom->Gaus(mean,sigma);
190   }while(value-mean<-cutatL || value-mean>cutatR);
191   return value;
192 }
193 */