]>
Commit | Line | Data |
---|---|---|
20345ac5 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
20345ac5 | 15 | /* $Id$ */ |
c2fc1258 | 16 | /** @file AliFMDAlignFaker.cxx |
17 | @author Christian Holm Christensen <cholm@nbi.dk> | |
18 | @date Sun Mar 26 17:57:55 2006 | |
19 | @brief Implementation of AliFMDAlignFaker | |
20 | */ | |
20345ac5 | 21 | //____________________________________________________________________ |
02a27b50 | 22 | // |
23 | // Class | |
24 | // to | |
25 | // make | |
26 | // fake | |
27 | // alignment | |
28 | // parameters | |
29 | // | |
30 | //____________________________________________________________________ | |
20345ac5 | 31 | // |
32 | // Forward Multiplicity Detector based on Silicon wafers. | |
33 | // | |
9f662337 | 34 | // This task creates fake alignment. Which alignment, depends on |
20345ac5 | 35 | // the bit mask passed to the constructor, or added by `AddAlign'. |
36 | // | |
9f662337 | 37 | // The default is to write all alignment parameters to a local |
20345ac5 | 38 | // storage `local://cdb' which is a directory in the current |
39 | // directory. | |
40 | // | |
41 | #include "AliLog.h" // ALILOG_H | |
42 | #include "AliFMDAlignFaker.h" // ALIFMDALIGNFAKER_H | |
43 | #include <AliCDBManager.h> // ALICDBMANAGER_H | |
6e79feeb | 44 | #include <AliCDBStorage.h> // ALICDBSTORAGE_H |
20345ac5 | 45 | #include <AliCDBEntry.h> // ALICDBMANAGER_H |
02a27b50 | 46 | // #include <AliAlignObj.h> |
20345ac5 | 47 | #include <AliAlignObjAngles.h> |
02a27b50 | 48 | // #include <Riostream.h> |
49 | // #include <TSystem.h> | |
50 | // #include <TMath.h> | |
20345ac5 | 51 | #include <TRandom.h> |
52 | #include <TClonesArray.h> | |
53 | #include <TString.h> | |
54 | #include <TFile.h> | |
55 | #include <TGeoManager.h> | |
56 | #include <TGeoNode.h> | |
02a27b50 | 57 | // #include <TGeoVolume.h> |
58 | // #include <TROOT.h> | |
20345ac5 | 59 | |
60 | //==================================================================== | |
61 | ClassImp(AliFMDAlignFaker) | |
62 | #if 0 | |
63 | ; // This is here to keep Emacs for indenting the next line | |
64 | #endif | |
65 | ||
66 | //____________________________________________________________________ | |
67 | AliFMDAlignFaker::AliFMDAlignFaker(Int_t mask, const char* geo, | |
68 | const char* loc) | |
69 | : TTask(geo, loc), | |
70 | fMask(mask), | |
b5ee4425 | 71 | fSensorTransMin(0,0,0), |
72 | fSensorTransMax(0,0,0), | |
73 | fSensorRotMin(0,0,0), | |
74 | fSensorRotMax(0,0,0), | |
75 | fHalfTransMin(0,0,0), | |
76 | fHalfTransMax(0,0,0), | |
77 | fHalfRotMin(0,0,0), | |
78 | fHalfRotMax(0,0,0), | |
20345ac5 | 79 | fRunMin(0), |
6e79feeb | 80 | fRunMax(9999999), |
b5ee4425 | 81 | fArray(0), |
82 | fComment("") | |
20345ac5 | 83 | { |
84 | // Default constructor | |
85 | SetSensorDisplacement(); | |
86 | SetSensorRotation(); | |
87 | SetHalfDisplacement(); | |
88 | SetHalfRotation(); | |
9234535e | 89 | SetComment(); |
20345ac5 | 90 | } |
91 | ||
92 | //__________________________________________________________________ | |
93 | void | |
94 | AliFMDAlignFaker::SetSensorDisplacement(Double_t x1, Double_t y1, Double_t z1, | |
95 | Double_t x2, Double_t y2, Double_t z2) | |
96 | { | |
97 | // Set sensor displacement (unit is centimeters) | |
98 | fSensorTransMin.SetXYZ(x1, y1, z1); | |
99 | fSensorTransMax.SetXYZ(x2, y2, z2); | |
100 | } | |
101 | ||
102 | //__________________________________________________________________ | |
103 | void | |
104 | AliFMDAlignFaker::SetSensorRotation(Double_t x1, Double_t y1, Double_t z1, | |
105 | Double_t x2, Double_t y2, Double_t z2) | |
106 | { | |
107 | // Set sensor rotations (unit is degrees) | |
108 | fSensorRotMin.SetXYZ(x1, y1, z1); | |
109 | fSensorRotMax.SetXYZ(x2, y2, z2); | |
110 | } | |
111 | ||
112 | //__________________________________________________________________ | |
113 | void | |
114 | AliFMDAlignFaker::SetHalfDisplacement(Double_t x1, Double_t y1, Double_t z1, | |
115 | Double_t x2, Double_t y2, Double_t z2) | |
116 | { | |
117 | // Set half ring/cone displacement (unit is centimeters) | |
118 | fHalfTransMin.SetXYZ(x1, y1, z1); | |
119 | fHalfTransMax.SetXYZ(x2, y2, z2); | |
120 | } | |
121 | ||
122 | //__________________________________________________________________ | |
123 | void | |
124 | AliFMDAlignFaker::SetHalfRotation(Double_t x1, Double_t y1, Double_t z1, | |
125 | Double_t x2, Double_t y2, Double_t z2) | |
126 | { | |
127 | // Set half ring/cone rotations (unit is degrees) | |
128 | fHalfRotMin.SetXYZ(x1, y1, z1); | |
129 | fHalfRotMax.SetXYZ(x2, y2, z2); | |
130 | } | |
131 | ||
132 | //__________________________________________________________________ | |
133 | #define IS_NODE_HALF(name) \ | |
134 | (name[0] == 'F' && name[2] == 'M' && (name[3] == 'T' || name[3] == 'B')) | |
135 | #define IS_NODE_SENSOR(name) \ | |
136 | (name[0] == 'F' && name[2] == 'S' && name[3] == 'E') | |
137 | ||
138 | //__________________________________________________________________ | |
139 | void | |
140 | AliFMDAlignFaker::Exec(Option_t*) | |
141 | { | |
142 | // Make the objects. | |
143 | ||
144 | // Get geometry | |
145 | if (!gGeoManager) { | |
146 | if (!TGeoManager::Import(GetName())) { | |
147 | AliFatal(Form("Failed to import geometry from %s", GetName())); | |
148 | return; | |
149 | } | |
150 | } | |
151 | // Get top volume | |
152 | TGeoVolume* topVolume = gGeoManager->GetTopVolume(); | |
153 | if (!topVolume) { | |
154 | AliFatal("No top-level volume defined"); | |
155 | return; | |
156 | } | |
157 | // Make container of transforms | |
158 | if (!fArray) fArray = new TClonesArray("AliAlignObjAngles"); | |
159 | fArray->Clear(); | |
160 | ||
161 | // Make an iterator | |
162 | TGeoIterator next(topVolume); | |
163 | TGeoNode* node = 0; | |
164 | ||
165 | // Loop over all entries in geometry to find our nodes. | |
166 | while ((node = static_cast<TGeoNode*>(next()))) { | |
167 | const char* name = node->GetName(); | |
1e8f773e | 168 | if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) && |
169 | !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors))) | |
170 | continue; | |
171 | ||
172 | // Get the path | |
173 | TString path(Form("/%s", gGeoManager->GetNode(0)->GetName())); | |
174 | Int_t nLevel = next.GetLevel(); | |
175 | for (Int_t lvl = 0; lvl <= nLevel; lvl++) { | |
176 | TGeoNode* p = next.GetNode(lvl); | |
177 | if (!p) { | |
178 | if (lvl != 0) | |
179 | AliWarning(Form("No node at level %d in path %s",lvl,path.Data())); | |
180 | continue; | |
20345ac5 | 181 | } |
1e8f773e | 182 | if (!path.IsNull()) path.Append("/"); |
183 | path.Append(p->GetName()); | |
20345ac5 | 184 | } |
1e8f773e | 185 | Int_t id = node->GetVolume()->GetNumber(); |
186 | if (IS_NODE_HALF(name)) MakeAlignHalf(path, id); | |
187 | if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id); | |
20345ac5 | 188 | } |
189 | ||
190 | TString t(GetTitle()); | |
c2fc1258 | 191 | if (t.IsNull() || t.Contains("local://") || t.Contains("alien://")) |
20345ac5 | 192 | WriteToCDB(); |
193 | else | |
194 | WriteToFile(); | |
195 | } | |
196 | ||
197 | //__________________________________________________________________ | |
198 | Bool_t | |
199 | AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id, | |
200 | Double_t transX, Double_t transY, Double_t transZ, | |
201 | Double_t rotX, Double_t rotY, Double_t rotZ) | |
202 | { | |
02a27b50 | 203 | // make alignment for a path |
204 | // Params: | |
205 | // path Path to node | |
206 | // id Volume number | |
207 | // transX Translation in X | |
208 | // transZ Translation in Y | |
209 | // transZ Translation in Z | |
210 | // rotX Rotation about X-axis | |
211 | // rotY Rotation about Y-axis | |
212 | // rotZ Rotation about Z-axis | |
1e8f773e | 213 | AliDebug(1, Form("Make alignment for %s (volume %d): (%f,%f,%f) (%f,%f,%f)", |
214 | path.Data(), id, transX, transY, transZ, rotX, rotY, rotZ)); | |
20345ac5 | 215 | Int_t nAlign = fArray->GetEntries(); |
92dba02a | 216 | id = 0; |
20345ac5 | 217 | AliAlignObjAngles* obj = |
b760c02e | 218 | new ((*fArray)[nAlign]) AliAlignObjAngles(path.Data(), id,0,0,0,0,0,0,kTRUE); |
20345ac5 | 219 | if (!obj) { |
220 | AliError(Form("Failed to create alignment object for %s", path.Data())); | |
221 | return kFALSE; | |
222 | } | |
223 | if (!obj->SetLocalPars(transX, transY, transZ, rotX, rotY, rotZ)) { | |
224 | AliError(Form("Failed to set local transforms on %s", path.Data())); | |
225 | return kTRUE; | |
226 | } | |
227 | return kTRUE; | |
228 | } | |
229 | ||
230 | //__________________________________________________________________ | |
231 | Bool_t | |
232 | AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id) | |
233 | { | |
02a27b50 | 234 | // Make alignment of a half ring/cone |
1e8f773e | 235 | AliDebug(15, Form("Make alignment for half-ring/cone %s", path.Data())); |
20345ac5 | 236 | Double_t transX = gRandom->Uniform(fHalfTransMin.X(), fHalfTransMax.X()); |
237 | Double_t transY = gRandom->Uniform(fHalfTransMin.Y(), fHalfTransMax.Y()); | |
238 | Double_t transZ = gRandom->Uniform(fHalfTransMin.Z(), fHalfTransMax.Z()); | |
239 | Double_t rotX = gRandom->Uniform(fHalfRotMin.X(), fHalfRotMax.X()); | |
240 | Double_t rotY = gRandom->Uniform(fHalfRotMin.Y(), fHalfRotMax.Y()); | |
241 | Double_t rotZ = gRandom->Uniform(fHalfRotMin.Z(), fHalfRotMax.Z()); | |
242 | return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ); | |
243 | } | |
244 | ||
245 | ||
246 | //__________________________________________________________________ | |
247 | Bool_t | |
248 | AliFMDAlignFaker::MakeAlignSensor(const TString& path, Int_t id) | |
249 | { | |
02a27b50 | 250 | // Make alignment of a sensor |
1e8f773e | 251 | AliDebug(15, Form("Make alignment for sensor %s", path.Data())); |
20345ac5 | 252 | Double_t transX = gRandom->Uniform(fSensorTransMin.X(), fSensorTransMax.X()); |
253 | Double_t transY = gRandom->Uniform(fSensorTransMin.Y(), fSensorTransMax.Y()); | |
254 | Double_t transZ = gRandom->Uniform(fSensorTransMin.Z(), fSensorTransMax.Z()); | |
255 | Double_t rotX = gRandom->Uniform(fSensorRotMin.X(), fSensorRotMax.X()); | |
256 | Double_t rotY = gRandom->Uniform(fSensorRotMin.Y(), fSensorRotMax.Y()); | |
257 | Double_t rotZ = gRandom->Uniform(fSensorRotMin.Z(), fSensorRotMax.Z()); | |
258 | return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ); | |
259 | } | |
260 | ||
261 | //__________________________________________________________________ | |
262 | void | |
263 | AliFMDAlignFaker::WriteToCDB() | |
264 | { | |
265 | // Make the objects. | |
9234535e | 266 | AliCDBManager* cdb = AliCDBManager::Instance(); |
6e79feeb | 267 | AliCDBStorage* storage = cdb->GetStorage(GetTitle()); |
9234535e | 268 | AliCDBMetaData* meta = new AliCDBMetaData; |
20345ac5 | 269 | meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); |
270 | meta->SetAliRootVersion(gROOT->GetVersion()); | |
271 | meta->SetBeamPeriod(1); | |
9234535e | 272 | meta->SetComment(fComment.Data()); |
20345ac5 | 273 | |
274 | AliCDBId id("FMD/Align/Data", fRunMin, fRunMax); | |
6e79feeb | 275 | storage->Put(fArray, id, meta); |
20345ac5 | 276 | } |
277 | ||
278 | //__________________________________________________________________ | |
279 | void | |
280 | AliFMDAlignFaker::WriteToFile() | |
281 | { | |
02a27b50 | 282 | // Write to a local file |
20345ac5 | 283 | TFile* file = TFile::Open(GetTitle(), "RECREATE"); |
284 | if (!file) { | |
285 | AliFatal(Form("Failed to open file '%s' for output", GetTitle())); | |
286 | return; | |
287 | } | |
288 | file->cd(); | |
289 | fArray->Write("FMDAlignment"); | |
20345ac5 | 290 | file->Write(); |
9234535e | 291 | file->Close(); |
20345ac5 | 292 | } |
293 | ||
294 | ||
295 | ||
296 | //____________________________________________________________________ | |
297 | // | |
298 | // EOF | |
299 | // |