]>
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 | |
44 | #include <AliCDBEntry.h> // ALICDBMANAGER_H | |
02a27b50 | 45 | // #include <AliAlignObj.h> |
20345ac5 | 46 | #include <AliAlignObjAngles.h> |
02a27b50 | 47 | // #include <Riostream.h> |
48 | // #include <TSystem.h> | |
49 | // #include <TMath.h> | |
20345ac5 | 50 | #include <TRandom.h> |
51 | #include <TClonesArray.h> | |
52 | #include <TString.h> | |
53 | #include <TFile.h> | |
54 | #include <TGeoManager.h> | |
55 | #include <TGeoNode.h> | |
02a27b50 | 56 | // #include <TGeoVolume.h> |
57 | // #include <TROOT.h> | |
20345ac5 | 58 | |
59 | //==================================================================== | |
60 | ClassImp(AliFMDAlignFaker) | |
61 | #if 0 | |
62 | ; // This is here to keep Emacs for indenting the next line | |
63 | #endif | |
64 | ||
65 | //____________________________________________________________________ | |
66 | AliFMDAlignFaker::AliFMDAlignFaker(Int_t mask, const char* geo, | |
67 | const char* loc) | |
68 | : TTask(geo, loc), | |
69 | fMask(mask), | |
70 | fRunMin(0), | |
71 | fRunMax(10), | |
72 | fArray(0) | |
73 | { | |
74 | // Default constructor | |
75 | SetSensorDisplacement(); | |
76 | SetSensorRotation(); | |
77 | SetHalfDisplacement(); | |
78 | SetHalfRotation(); | |
9234535e | 79 | SetComment(); |
20345ac5 | 80 | } |
81 | ||
82 | //__________________________________________________________________ | |
83 | void | |
84 | AliFMDAlignFaker::SetSensorDisplacement(Double_t x1, Double_t y1, Double_t z1, | |
85 | Double_t x2, Double_t y2, Double_t z2) | |
86 | { | |
87 | // Set sensor displacement (unit is centimeters) | |
88 | fSensorTransMin.SetXYZ(x1, y1, z1); | |
89 | fSensorTransMax.SetXYZ(x2, y2, z2); | |
90 | } | |
91 | ||
92 | //__________________________________________________________________ | |
93 | void | |
94 | AliFMDAlignFaker::SetSensorRotation(Double_t x1, Double_t y1, Double_t z1, | |
95 | Double_t x2, Double_t y2, Double_t z2) | |
96 | { | |
97 | // Set sensor rotations (unit is degrees) | |
98 | fSensorRotMin.SetXYZ(x1, y1, z1); | |
99 | fSensorRotMax.SetXYZ(x2, y2, z2); | |
100 | } | |
101 | ||
102 | //__________________________________________________________________ | |
103 | void | |
104 | AliFMDAlignFaker::SetHalfDisplacement(Double_t x1, Double_t y1, Double_t z1, | |
105 | Double_t x2, Double_t y2, Double_t z2) | |
106 | { | |
107 | // Set half ring/cone displacement (unit is centimeters) | |
108 | fHalfTransMin.SetXYZ(x1, y1, z1); | |
109 | fHalfTransMax.SetXYZ(x2, y2, z2); | |
110 | } | |
111 | ||
112 | //__________________________________________________________________ | |
113 | void | |
114 | AliFMDAlignFaker::SetHalfRotation(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 rotations (unit is degrees) | |
118 | fHalfRotMin.SetXYZ(x1, y1, z1); | |
119 | fHalfRotMax.SetXYZ(x2, y2, z2); | |
120 | } | |
121 | ||
122 | //__________________________________________________________________ | |
123 | #define IS_NODE_HALF(name) \ | |
124 | (name[0] == 'F' && name[2] == 'M' && (name[3] == 'T' || name[3] == 'B')) | |
125 | #define IS_NODE_SENSOR(name) \ | |
126 | (name[0] == 'F' && name[2] == 'S' && name[3] == 'E') | |
127 | ||
128 | //__________________________________________________________________ | |
129 | void | |
130 | AliFMDAlignFaker::Exec(Option_t*) | |
131 | { | |
132 | // Make the objects. | |
133 | ||
134 | // Get geometry | |
135 | if (!gGeoManager) { | |
136 | if (!TGeoManager::Import(GetName())) { | |
137 | AliFatal(Form("Failed to import geometry from %s", GetName())); | |
138 | return; | |
139 | } | |
140 | } | |
141 | // Get top volume | |
142 | TGeoVolume* topVolume = gGeoManager->GetTopVolume(); | |
143 | if (!topVolume) { | |
144 | AliFatal("No top-level volume defined"); | |
145 | return; | |
146 | } | |
147 | // Make container of transforms | |
148 | if (!fArray) fArray = new TClonesArray("AliAlignObjAngles"); | |
149 | fArray->Clear(); | |
150 | ||
151 | // Make an iterator | |
152 | TGeoIterator next(topVolume); | |
153 | TGeoNode* node = 0; | |
154 | ||
155 | // Loop over all entries in geometry to find our nodes. | |
156 | while ((node = static_cast<TGeoNode*>(next()))) { | |
157 | const char* name = node->GetName(); | |
1e8f773e | 158 | if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) && |
159 | !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors))) | |
160 | continue; | |
161 | ||
162 | // Get the path | |
163 | TString path(Form("/%s", gGeoManager->GetNode(0)->GetName())); | |
164 | Int_t nLevel = next.GetLevel(); | |
165 | for (Int_t lvl = 0; lvl <= nLevel; lvl++) { | |
166 | TGeoNode* p = next.GetNode(lvl); | |
167 | if (!p) { | |
168 | if (lvl != 0) | |
169 | AliWarning(Form("No node at level %d in path %s",lvl,path.Data())); | |
170 | continue; | |
20345ac5 | 171 | } |
1e8f773e | 172 | if (!path.IsNull()) path.Append("/"); |
173 | path.Append(p->GetName()); | |
20345ac5 | 174 | } |
1e8f773e | 175 | Int_t id = node->GetVolume()->GetNumber(); |
176 | if (IS_NODE_HALF(name)) MakeAlignHalf(path, id); | |
177 | if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id); | |
20345ac5 | 178 | } |
179 | ||
180 | TString t(GetTitle()); | |
c2fc1258 | 181 | if (t.IsNull() || t.Contains("local://") || t.Contains("alien://")) |
20345ac5 | 182 | WriteToCDB(); |
183 | else | |
184 | WriteToFile(); | |
185 | } | |
186 | ||
187 | //__________________________________________________________________ | |
188 | Bool_t | |
189 | AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id, | |
190 | Double_t transX, Double_t transY, Double_t transZ, | |
191 | Double_t rotX, Double_t rotY, Double_t rotZ) | |
192 | { | |
02a27b50 | 193 | // make alignment for a path |
194 | // Params: | |
195 | // path Path to node | |
196 | // id Volume number | |
197 | // transX Translation in X | |
198 | // transZ Translation in Y | |
199 | // transZ Translation in Z | |
200 | // rotX Rotation about X-axis | |
201 | // rotY Rotation about Y-axis | |
202 | // rotZ Rotation about Z-axis | |
1e8f773e | 203 | AliDebug(1, Form("Make alignment for %s (volume %d): (%f,%f,%f) (%f,%f,%f)", |
204 | path.Data(), id, transX, transY, transZ, rotX, rotY, rotZ)); | |
20345ac5 | 205 | Int_t nAlign = fArray->GetEntries(); |
92dba02a | 206 | id = 0; |
20345ac5 | 207 | AliAlignObjAngles* obj = |
208 | new ((*fArray)[nAlign]) AliAlignObjAngles(path.Data(), id,0,0,0,0,0,0); | |
209 | if (!obj) { | |
210 | AliError(Form("Failed to create alignment object for %s", path.Data())); | |
211 | return kFALSE; | |
212 | } | |
213 | if (!obj->SetLocalPars(transX, transY, transZ, rotX, rotY, rotZ)) { | |
214 | AliError(Form("Failed to set local transforms on %s", path.Data())); | |
215 | return kTRUE; | |
216 | } | |
217 | return kTRUE; | |
218 | } | |
219 | ||
220 | //__________________________________________________________________ | |
221 | Bool_t | |
222 | AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id) | |
223 | { | |
02a27b50 | 224 | // Make alignment of a half ring/cone |
1e8f773e | 225 | AliDebug(15, Form("Make alignment for half-ring/cone %s", path.Data())); |
20345ac5 | 226 | Double_t transX = gRandom->Uniform(fHalfTransMin.X(), fHalfTransMax.X()); |
227 | Double_t transY = gRandom->Uniform(fHalfTransMin.Y(), fHalfTransMax.Y()); | |
228 | Double_t transZ = gRandom->Uniform(fHalfTransMin.Z(), fHalfTransMax.Z()); | |
229 | Double_t rotX = gRandom->Uniform(fHalfRotMin.X(), fHalfRotMax.X()); | |
230 | Double_t rotY = gRandom->Uniform(fHalfRotMin.Y(), fHalfRotMax.Y()); | |
231 | Double_t rotZ = gRandom->Uniform(fHalfRotMin.Z(), fHalfRotMax.Z()); | |
232 | return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ); | |
233 | } | |
234 | ||
235 | ||
236 | //__________________________________________________________________ | |
237 | Bool_t | |
238 | AliFMDAlignFaker::MakeAlignSensor(const TString& path, Int_t id) | |
239 | { | |
02a27b50 | 240 | // Make alignment of a sensor |
1e8f773e | 241 | AliDebug(15, Form("Make alignment for sensor %s", path.Data())); |
20345ac5 | 242 | Double_t transX = gRandom->Uniform(fSensorTransMin.X(), fSensorTransMax.X()); |
243 | Double_t transY = gRandom->Uniform(fSensorTransMin.Y(), fSensorTransMax.Y()); | |
244 | Double_t transZ = gRandom->Uniform(fSensorTransMin.Z(), fSensorTransMax.Z()); | |
245 | Double_t rotX = gRandom->Uniform(fSensorRotMin.X(), fSensorRotMax.X()); | |
246 | Double_t rotY = gRandom->Uniform(fSensorRotMin.Y(), fSensorRotMax.Y()); | |
247 | Double_t rotZ = gRandom->Uniform(fSensorRotMin.Z(), fSensorRotMax.Z()); | |
248 | return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ); | |
249 | } | |
250 | ||
251 | //__________________________________________________________________ | |
252 | void | |
253 | AliFMDAlignFaker::WriteToCDB() | |
254 | { | |
255 | // Make the objects. | |
9234535e | 256 | AliCDBManager* cdb = AliCDBManager::Instance(); |
257 | AliCDBMetaData* meta = new AliCDBMetaData; | |
20345ac5 | 258 | meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); |
259 | meta->SetAliRootVersion(gROOT->GetVersion()); | |
260 | meta->SetBeamPeriod(1); | |
9234535e | 261 | meta->SetComment(fComment.Data()); |
20345ac5 | 262 | |
263 | AliCDBId id("FMD/Align/Data", fRunMin, fRunMax); | |
264 | cdb->Put(fArray, id, meta); | |
265 | cdb->Destroy(); | |
266 | } | |
267 | ||
268 | //__________________________________________________________________ | |
269 | void | |
270 | AliFMDAlignFaker::WriteToFile() | |
271 | { | |
02a27b50 | 272 | // Write to a local file |
20345ac5 | 273 | TFile* file = TFile::Open(GetTitle(), "RECREATE"); |
274 | if (!file) { | |
275 | AliFatal(Form("Failed to open file '%s' for output", GetTitle())); | |
276 | return; | |
277 | } | |
278 | file->cd(); | |
279 | fArray->Write("FMDAlignment"); | |
20345ac5 | 280 | file->Write(); |
9234535e | 281 | file->Close(); |
20345ac5 | 282 | } |
283 | ||
284 | ||
285 | ||
286 | //____________________________________________________________________ | |
287 | // | |
288 | // EOF | |
289 | // |