1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 * @file AliFMDAlignFaker.cxx
18 * @author Christian Holm Christensen <cholm@nbi.dk>
19 * @date Sun Mar 26 17:57:55 2006
20 * @brief Implementation of AliFMDAlignFaker
22 //____________________________________________________________________
31 //____________________________________________________________________
33 // Forward Multiplicity Detector based on Silicon wafers.
35 // This task creates fake alignment. Which alignment, depends on
36 // the bit mask passed to the constructor, or added by `AddAlign'.
38 // The default is to write all alignment parameters to a local
39 // storage `local://cdb' which is a directory in the current
42 #include "AliFMDDebug.h" // ALIFMDDEBUG_H ALILOG_H
43 #include "AliFMDAlignFaker.h" // ALIFMDALIGNFAKER_H
44 #include <AliCDBManager.h> // ALICDBMANAGER_H
45 #include <AliCDBStorage.h> // ALICDBSTORAGE_H
46 #include <AliCDBEntry.h> // ALICDBMANAGER_H
47 // #include <AliAlignObj.h>
48 #include <AliAlignObjParams.h>
49 // #include <Riostream.h>
53 #include <TClonesArray.h>
56 #include <TGeoManager.h>
58 // #include <TGeoVolume.h>
62 //====================================================================
63 ClassImp(AliFMDAlignFaker)
65 ; // This is here to keep Emacs for indenting the next line
68 //____________________________________________________________________
69 AliFMDAlignFaker::AliFMDAlignFaker(Int_t mask, const char* geo,
73 fSensorTransMin(0,0,0),
74 fSensorTransMax(0,0,0),
82 fRunMax(AliCDBRunRange::Infinity()),
86 // Default constructor
88 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
89 if (!storage) AliFatal("Default Storage not set");
90 const TString& uri = storage->GetURI();
93 SetSensorDisplacement();
95 SetHalfDisplacement();
100 //__________________________________________________________________
102 AliFMDAlignFaker::SetSensorDisplacement(Double_t x1, Double_t y1, Double_t z1,
103 Double_t x2, Double_t y2, Double_t z2)
105 // Set sensor displacement (unit is centimeters)
106 fSensorTransMin.SetXYZ(x1, y1, z1);
107 fSensorTransMax.SetXYZ(x2, y2, z2);
110 //__________________________________________________________________
112 AliFMDAlignFaker::SetSensorRotation(Double_t x1, Double_t y1, Double_t z1,
113 Double_t x2, Double_t y2, Double_t z2)
115 // Set sensor rotations (unit is degrees)
116 fSensorRotMin.SetXYZ(x1, y1, z1);
117 fSensorRotMax.SetXYZ(x2, y2, z2);
120 //__________________________________________________________________
122 AliFMDAlignFaker::SetHalfDisplacement(Double_t x1, Double_t y1, Double_t z1,
123 Double_t x2, Double_t y2, Double_t z2)
125 // Set half ring/cone displacement (unit is centimeters)
126 fHalfTransMin.SetXYZ(x1, y1, z1);
127 fHalfTransMax.SetXYZ(x2, y2, z2);
130 //__________________________________________________________________
132 AliFMDAlignFaker::SetHalfRotation(Double_t x1, Double_t y1, Double_t z1,
133 Double_t x2, Double_t y2, Double_t z2)
135 // Set half ring/cone rotations (unit is degrees)
136 fHalfRotMin.SetXYZ(x1, y1, z1);
137 fHalfRotMax.SetXYZ(x2, y2, z2);
140 //__________________________________________________________________
141 #define IS_NODE_HALF(name) \
142 (name[0] == 'F' && name[2] == 'M' && (name[3] == 'T' || name[3] == 'B'))
143 #define IS_NODE_SENSOR(name) \
144 (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
146 //__________________________________________________________________
148 AliFMDAlignFaker::GetGeometry(Bool_t toCdb, const TString& storage)
154 // toCdb Whether to store in CDB
155 // storage Storage element to use
161 //load geom from default CDB storage
162 AliGeomManager::LoadGeometry();
165 if(!storage.BeginsWith("local://") &&
166 !storage.BeginsWith("alien://")) {
167 AliErrorClass(Form("STORAGE=\"%s\" invalid. Exiting\n", storage.Data()));
171 AliCDBManager* cdb = AliCDBManager::Instance();
172 AliCDBStorage* store = cdb->GetStorage(storage.Data());
174 AliErrorClass(Form("Unable to open storage %s\n", storage.Data()));
178 AliCDBPath path("GRP","Geometry","Data");
179 AliCDBEntry* entry = store->Get(path.GetPath(),cdb->GetRun());
181 AliErrorClass("Could not get the specified CDB entry!");
187 TGeoManager* geom = static_cast<TGeoManager*>(entry->GetObject());
188 AliGeomManager::SetGeometry(geom);
192 //__________________________________________________________________
194 AliFMDAlignFaker::Exec(Option_t*)
200 if (!TGeoManager::Import(GetName())) {
201 AliFatal(Form("Failed to import geometry from %s", GetName()));
206 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
208 AliFatal("No top-level volume defined");
211 // Make container of transforms
212 if (!fArray) fArray = new TClonesArray("AliAlignObjParams");
216 TGeoIterator next(topVolume);
217 next.SetTopName(Form("/%s_1", topVolume->GetName()));
220 Char_t currentDet = '\0';
221 Char_t currentHalf = '\0';
222 // Loop over all entries in geometry to find our nodes.
223 while ((node = static_cast<TGeoNode*>(next()))) {
224 const char* name = node->GetName();
225 if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) &&
226 !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors)))
229 TString path, alignName;
231 Int_t id = node->GetVolume()->GetNumber();
232 if (IS_NODE_HALF(name)) {
233 currentDet = name[1];
234 currentHalf = name[3];
235 alignName = Form("FMD/FMD%c_%c", currentDet, currentHalf);
237 if (IS_NODE_SENSOR(name)) {
238 Char_t ring = name[1];
239 Int_t lvl = next.GetLevel();
240 TGeoNode* parent = next.GetNode(lvl-1);
241 Int_t copy = parent->GetNumber();
242 alignName = Form("FMD/FMD%c_%c/FMD%c_%02d",
243 currentDet, currentHalf, ring, copy);
245 if (alignName.IsNull()) continue;
246 if (!gGeoManager->GetAlignableEntry(alignName.Data())) {
247 AliWarning(Form("No alignable entry for %s, using path %s",
248 alignName.Data(), path.Data()));
251 AliFMDDebug(1, ("Making alignment for %s -> %s (%d)",
252 alignName.Data(), path.Data(), id));
253 if (IS_NODE_HALF(name)) MakeAlignHalf(alignName, id);
254 if (IS_NODE_SENSOR(name)) MakeAlignSensor(alignName, id);
256 if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) &&
257 !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors)))
261 TString path(Form("/%s", gGeoManager->GetNode(0)->GetName()));
262 Int_t nLevel = next.GetLevel();
263 for (Int_t lvl = 0; lvl <= nLevel; lvl++) {
264 TGeoNode* p = next.GetNode(lvl);
267 AliWarning(Form("No node at level %d in path %s",lvl,path.Data()));
270 if (!path.IsNull()) path.Append("/");
271 path.Append(p->GetName());
273 Int_t id = node->GetVolume()->GetNumber();
274 if (IS_NODE_HALF(name)) MakeAlignHalf(path, id);
275 if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id);
279 TString t(GetTitle());
280 if (t.IsNull() || t.Contains("local://") || t.Contains("alien://"))
286 //__________________________________________________________________
288 AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id,
289 Double_t transX, Double_t transY, Double_t transZ,
290 Double_t rotX, Double_t rotY, Double_t rotZ)
292 // make alignment for a path
296 // transX Translation in X
297 // transZ Translation in Y
298 // transZ Translation in Z
299 // rotX Rotation about X-axis
300 // rotY Rotation about Y-axis
301 // rotZ Rotation about Z-axis
302 AliFMDDebug(3, ("Make alignment for %s (volume %d): (%f,%f,%f) (%f,%f,%f)",
303 path.Data(), id, transX, transY, transZ, rotX, rotY, rotZ));
304 Int_t nAlign = fArray->GetEntries();
306 AliAlignObjParams* obj =
307 new ((*fArray)[nAlign]) AliAlignObjParams(path.Data(),
308 id,0,0,0,0,0,0,kTRUE);
310 AliError(Form("Failed to create alignment object for %s", path.Data()));
313 if (!obj->SetLocalPars(transX, transY, transZ, rotX, rotY, rotZ)) {
314 AliError(Form("Failed to set local transforms on %s", path.Data()));
320 //__________________________________________________________________
322 AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id)
324 // Make alignment of a half ring/cone
325 AliFMDDebug(15, ("Make alignment for half-ring/cone %s", path.Data()));
326 Double_t transX = gRandom->Uniform(fHalfTransMin.X(), fHalfTransMax.X());
327 Double_t transY = gRandom->Uniform(fHalfTransMin.Y(), fHalfTransMax.Y());
328 Double_t transZ = gRandom->Uniform(fHalfTransMin.Z(), fHalfTransMax.Z());
329 Double_t rotX = gRandom->Uniform(fHalfRotMin.X(), fHalfRotMax.X());
330 Double_t rotY = gRandom->Uniform(fHalfRotMin.Y(), fHalfRotMax.Y());
331 Double_t rotZ = gRandom->Uniform(fHalfRotMin.Z(), fHalfRotMax.Z());
332 return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ);
336 //__________________________________________________________________
338 AliFMDAlignFaker::MakeAlignSensor(const TString& path, Int_t id)
340 // Make alignment of a sensor
341 AliFMDDebug(15, ("Make alignment for sensor %s", path.Data()));
342 Double_t transX = gRandom->Uniform(fSensorTransMin.X(), fSensorTransMax.X());
343 Double_t transY = gRandom->Uniform(fSensorTransMin.Y(), fSensorTransMax.Y());
344 Double_t transZ = gRandom->Uniform(fSensorTransMin.Z(), fSensorTransMax.Z());
345 Double_t rotX = gRandom->Uniform(fSensorRotMin.X(), fSensorRotMax.X());
346 Double_t rotY = gRandom->Uniform(fSensorRotMin.Y(), fSensorRotMax.Y());
347 Double_t rotZ = gRandom->Uniform(fSensorRotMin.Z(), fSensorRotMax.Z());
348 return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ);
351 //__________________________________________________________________
353 AliFMDAlignFaker::WriteToCDB()
356 const char* loc = GetTitle();
357 AliCDBManager* cdb = AliCDBManager::Instance();
358 AliCDBStorage* storage = cdb->GetStorage(!loc ? "" : loc);
359 AliCDBMetaData* meta = new AliCDBMetaData;
360 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data());
361 meta->SetAliRootVersion(gROOT->GetVersion());
362 meta->SetBeamPeriod(1);
363 meta->SetComment(fComment.Data());
365 AliCDBId id("FMD/Align/Data", fRunMin, fRunMax);
366 storage->Put(fArray, id, meta);
369 //__________________________________________________________________
371 AliFMDAlignFaker::WriteToFile()
373 // Write to a local file
374 TFile* file = TFile::Open(GetTitle(), "RECREATE");
376 AliFatal(Form("Failed to open file '%s' for output", GetTitle()));
380 fArray->Write("FMDAlignment",TObject::kSingleKey);
387 //____________________________________________________________________