Ideal 5-module PHOS geometry
[u/mrichter/AliRoot.git] / PHOS / macros / AlignmentDB / AliPHOSSetAlignment.C
CommitLineData
49c37ad8 1/* $Id$*/
2
3// Script to create alignment parameters and store them into CDB
a3a8cfad 4// Three sets of alignment parameters can be created:
5// 0) 1 PHOS module with ideal geometry
6// 1) 5 PHOS modules with small disalignments
7// 2) 5 PHOS modules with ideal geometry
49c37ad8 8
9#if !defined(__CINT__)
10#include "TControlBar.h"
11#include "TString.h"
12#include "TRandom.h"
49c37ad8 13
14#include "AliRun.h"
15#include "AliPHOSAlignData.h"
16#include "AliCDBMetaData.h"
17#include "AliCDBId.h"
18#include "AliCDBEntry.h"
19#include "AliCDBManager.h"
20#include "AliCDBStorage.h"
21#endif
22
23
24void AliPHOSSetAlignment()
25{
26 TControlBar *menu = new TControlBar("vertical","PHOS alignment control");
27 menu->AddButton("Help to run PHOS alignment control","Help()",
28 "Explains how to use PHOS alignment control menus");
a3a8cfad 29
49c37ad8 30 menu->AddButton("PHOS 2007","SetAlignment(0)",
31 "Set PHOS alignment for the LHC run 2007");
a3a8cfad 32 menu->AddButton("Full misaligned PHOS","SetAlignment(1)",
33 "Set all 5 modules with random displacement");
34 menu->AddButton("Full ideal PHOS","SetAlignment(2)",
49c37ad8 35 "Set all 5 modules with random displacement");
a3a8cfad 36
49c37ad8 37 menu->AddButton("Read PHOS 2007","GetAlignment(0)",
38 "Read PHOS geometry for the LHC run 2007");
a3a8cfad 39 menu->AddButton("Read full misaligned PHOS","GetAlignment(1)",
49c37ad8 40 "Read full PHOS geometry with random displacements");
a3a8cfad 41 menu->AddButton("Read full ideal PHOS","GetAlignment(2)",
42 "Read full PHOS geometry with random displacements");
43
49c37ad8 44 menu->Show();
45}
46
47//------------------------------------------------------------------------
48void Help()
49{
50 char *string =
51 "\nSet PHOS alignment parameters and write them into ALICE CDB.
52Press button \"PHOS 2007\" to create PHOS geometry for the first LHC run in 2007.
53Press button \"Full PHOS\" to create full PHOS geometry with radnomly displaced modules\n";
54 printf(string);
55}
56
57//------------------------------------------------------------------------
58void SetAlignment(Int_t flag=0)
59{
60 // Write alignment parameters into CDB
61 // Arguments:
62 // flag=0: ideal geometry with one module
63 // flag=1: disligned geometry with 5 modules
64 // Author: Yuri Kharlov
65
66 TString DBFolder;
67 Int_t firstRun = 0;
68 Int_t lastRun = 10;
69 Int_t beamPeriod = 1;
70 char* objFormat = "";
71 gRandom->SetSeed(0);
72
73 AliPHOSAlignData *alignda=new AliPHOSAlignData("PHOS");
74
75 switch (flag) {
76 case 0:
77 DBFolder ="local://InitAlignDB";
78 firstRun = 0;
79 lastRun = 0;
80 objFormat = "PHOS ideal geometry with 1 module";
81
82 alignda->SetNModules(1);
83
84 alignda->SetModuleCenter(0,0, 0.);
85 alignda->SetModuleCenter(0,1,-460.);
86 alignda->SetModuleCenter(0,2, 0.);
87
88 alignda->SetModuleAngle(0,0,0, 90.);
89 alignda->SetModuleAngle(0,0,1, 0.);
90 alignda->SetModuleAngle(0,1,0, 0.);
91 alignda->SetModuleAngle(0,1,1, 0.);
92 alignda->SetModuleAngle(0,2,0, 90.);
93 alignda->SetModuleAngle(0,2,1, 270.);
94 break;
95 case 1:
96 DBFolder ="local://DisAlignDB";
97 firstRun = 0;
98 lastRun = 10;
99 objFormat = "PHOS disaligned geometry with 5 modules";
100
101 Int_t nModules = 5;
102 alignda->SetNModules(nModules);
103
104 Float_t dAngle= 20;
105 Float_t r0 = 460.;
106 Float_t theta, phi;
107 for (Int_t iModule=0; iModule<nModules; iModule++) {
108 Float_t r = r0 + gRandom->Uniform(0.,40.);
109 Float_t angle = dAngle * ( iModule - nModules / 2.0 + 0.5 ) ;
110 angle += gRandom->Uniform(-0.1,+0.1);
111 Float_t x = r * TMath::Sin(angle * TMath::DegToRad() );
112 Float_t y =-r * TMath::Cos(angle * TMath::DegToRad() );
113 Float_t z = gRandom->Uniform(-0.05,0.05);
114
115 alignda->SetModuleCenter(iModule,0,x);
116 alignda->SetModuleCenter(iModule,1,y);
117 alignda->SetModuleCenter(iModule,2,z);
118
119 theta = 90 + gRandom->Uniform(-1.,1.);
120 phi = angle;
121 alignda->SetModuleAngle(iModule,0,0,theta);
122 alignda->SetModuleAngle(iModule,0,1,phi);
123 theta = 0;
124 phi = 0;
125 alignda->SetModuleAngle(iModule,1,0,theta);
126 alignda->SetModuleAngle(iModule,1,1,phi);
127 theta = 90 + gRandom->Uniform(-1.,1.);
128 phi = 270+angle;
129 alignda->SetModuleAngle(iModule,2,0,theta);
130 alignda->SetModuleAngle(iModule,2,1,phi);
131 }
a3a8cfad 132 case 2:
133 DBFolder ="local://AlignDB";
134 firstRun = 0;
135 lastRun = 10;
136 objFormat = "PHOS disaligned geometry with 5 modules";
137
138 Int_t nModules = 5;
139 alignda->SetNModules(nModules);
140
141 Float_t dAngle= 20;
142 Float_t r0 = 460.;
143 Float_t theta, phi;
144 for (Int_t iModule=0; iModule<nModules; iModule++) {
145 Float_t r = r0;
146 Float_t angle = dAngle * ( iModule - nModules / 2.0 + 0.5 ) ;
147 Float_t x = r * TMath::Sin(angle * TMath::DegToRad() );
148 Float_t y =-r * TMath::Cos(angle * TMath::DegToRad() );
149 Float_t z = 0.;
150
151 alignda->SetModuleCenter(iModule,0,x);
152 alignda->SetModuleCenter(iModule,1,y);
153 alignda->SetModuleCenter(iModule,2,z);
154
155 theta = 90;
156 phi = angle;
157 alignda->SetModuleAngle(iModule,0,0,theta);
158 alignda->SetModuleAngle(iModule,0,1,phi);
159 theta = 0;
160 phi = 0;
161 alignda->SetModuleAngle(iModule,1,0,theta);
162 alignda->SetModuleAngle(iModule,1,1,phi);
163 theta = 90;
164 phi = 270+angle;
165 alignda->SetModuleAngle(iModule,2,0,theta);
166 alignda->SetModuleAngle(iModule,2,1,phi);
167 }
49c37ad8 168 break;
169 default:
170 printf("Unknown flag %d, can be 0 or 1 only\n",flag);
171 return;
172 }
173
174
175 //Store calibration data into database
176
177 AliCDBMetaData md;
178 md.SetComment(objFormat);
179 md.SetBeamPeriod(beamPeriod);
180 md.SetResponsible("Yuri Kharlov");
181
182 AliCDBId id("PHOS/Alignment/Geometry",firstRun,lastRun);
183
184 AliCDBManager* man = AliCDBManager::Instance();
185 AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
186 loc->Put(alignda, id, &md);
187
188}
189
190//------------------------------------------------------------------------
191void GetAlignment(Int_t flag=0)
192{
193 // Read alignment parameters into CDB
194 // Arguments:
195 // flag=0: ideal geometry with one module
196 // flag=1: disligned geometry with 5 modules
197 // Author: Yuri Kharlov
198
199 TString DBFolder;
200 Int_t run = 0;
201 AliPHOSAlignData *alignda=new AliPHOSAlignData("PHOS");
202
203 switch (flag) {
204 case 0:
205 DBFolder ="local://InitAlignDB";
206 break;
207 case 1:
208 DBFolder ="local://DisAlignDB";
209 break;
a3a8cfad 210 case 2:
211 DBFolder ="local://AlignDB";
212 break;
49c37ad8 213 default:
214 printf("Unknown flag %d, can be 0 or 1 only\n",flag);
215 return;
216 }
217 AliPHOSAlignData* alignda = (AliPHOSAlignData*)
218 (AliCDBManager::Instance()
219 ->GetStorage(DBFolder.Data())
220 ->Get("PHOS/Alignment/Geometry",run)->GetObject());
221 alignda->Print();
222}