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