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 **************************************************************************/
18 //____________________________________________________________________
20 // Forward Multiplicity Detector based on Silicon wafers.
22 // This task creates fake alignrations. Which alignration, depends on
23 // the bit mask passed to the constructor, or added by `AddAlign'.
25 // The default is to write all alignration parameters to a local
26 // storage `local://cdb' which is a directory in the current
29 #include "AliLog.h" // ALILOG_H
30 #include "AliFMDAlignFaker.h" // ALIFMDALIGNFAKER_H
31 #include <AliCDBManager.h> // ALICDBMANAGER_H
32 #include <AliCDBEntry.h> // ALICDBMANAGER_H
33 #include <AliAlignObj.h>
34 #include <AliAlignObjAngles.h>
35 #include <Riostream.h>
39 #include <TClonesArray.h>
42 #include <TGeoManager.h>
44 #include <TGeoVolume.h>
46 //====================================================================
47 ClassImp(AliFMDAlignFaker)
49 ; // This is here to keep Emacs for indenting the next line
52 //____________________________________________________________________
53 AliFMDAlignFaker::AliFMDAlignFaker(Int_t mask, const char* geo,
61 // Default constructor
62 SetSensorDisplacement();
64 SetHalfDisplacement();
68 //__________________________________________________________________
70 AliFMDAlignFaker::SetSensorDisplacement(Double_t x1, Double_t y1, Double_t z1,
71 Double_t x2, Double_t y2, Double_t z2)
73 // Set sensor displacement (unit is centimeters)
74 fSensorTransMin.SetXYZ(x1, y1, z1);
75 fSensorTransMax.SetXYZ(x2, y2, z2);
78 //__________________________________________________________________
80 AliFMDAlignFaker::SetSensorRotation(Double_t x1, Double_t y1, Double_t z1,
81 Double_t x2, Double_t y2, Double_t z2)
83 // Set sensor rotations (unit is degrees)
84 fSensorRotMin.SetXYZ(x1, y1, z1);
85 fSensorRotMax.SetXYZ(x2, y2, z2);
88 //__________________________________________________________________
90 AliFMDAlignFaker::SetHalfDisplacement(Double_t x1, Double_t y1, Double_t z1,
91 Double_t x2, Double_t y2, Double_t z2)
93 // Set half ring/cone displacement (unit is centimeters)
94 fHalfTransMin.SetXYZ(x1, y1, z1);
95 fHalfTransMax.SetXYZ(x2, y2, z2);
98 //__________________________________________________________________
100 AliFMDAlignFaker::SetHalfRotation(Double_t x1, Double_t y1, Double_t z1,
101 Double_t x2, Double_t y2, Double_t z2)
103 // Set half ring/cone rotations (unit is degrees)
104 fHalfRotMin.SetXYZ(x1, y1, z1);
105 fHalfRotMax.SetXYZ(x2, y2, z2);
108 //__________________________________________________________________
109 #define IS_NODE_HALF(name) \
110 (name[0] == 'F' && name[2] == 'M' && (name[3] == 'T' || name[3] == 'B'))
111 #define IS_NODE_SENSOR(name) \
112 (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
114 //__________________________________________________________________
116 AliFMDAlignFaker::Exec(Option_t*)
122 if (!TGeoManager::Import(GetName())) {
123 AliFatal(Form("Failed to import geometry from %s", GetName()));
128 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
130 AliFatal("No top-level volume defined");
133 // Make container of transforms
134 if (!fArray) fArray = new TClonesArray("AliAlignObjAngles");
138 TGeoIterator next(topVolume);
141 // Loop over all entries in geometry to find our nodes.
142 while ((node = static_cast<TGeoNode*>(next()))) {
143 const char* name = node->GetName();
144 if (IS_NODE_HALF(name) && TESTBIT(fMask, kHalves) ||
145 IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors)) {
147 TString path(Form("/%s", gGeoManager->GetNode(0)->GetName()));
148 Int_t nLevel = next.GetLevel();
149 for (Int_t lvl = 0; lvl <= nLevel; lvl++) {
150 TGeoNode* p = next.GetNode(lvl);
151 if (!p && lvl != 0) {
152 AliWarning(Form("No node at level %d in path %s", lvl, path.Data()));
155 if (!path.IsNull()) path.Append("/");
156 path.Append(p->GetName());
158 Int_t id = node->GetVolume()->GetNumber();
159 if (IS_NODE_HALF(name)) MakeAlignHalf(path, id);
160 if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id);
164 TString t(GetTitle());
165 if (t.Contains("local://") || t.Contains("alien://"))
171 //__________________________________________________________________
173 AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id,
174 Double_t transX, Double_t transY, Double_t transZ,
175 Double_t rotX, Double_t rotY, Double_t rotZ)
177 AliDebug(1, Form("Make alignment for %s (volume %d)", path.Data(), id));
178 Int_t nAlign = fArray->GetEntries();
179 AliAlignObjAngles* obj =
180 new ((*fArray)[nAlign]) AliAlignObjAngles(path.Data(), id,0,0,0,0,0,0);
182 AliError(Form("Failed to create alignment object for %s", path.Data()));
185 if (!obj->SetLocalPars(transX, transY, transZ, rotX, rotY, rotZ)) {
186 AliError(Form("Failed to set local transforms on %s", path.Data()));
192 //__________________________________________________________________
194 AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id)
196 AliDebug(1, Form("Make alignment for half-ring/cone %s", path.Data()));
197 Double_t transX = gRandom->Uniform(fHalfTransMin.X(), fHalfTransMax.X());
198 Double_t transY = gRandom->Uniform(fHalfTransMin.Y(), fHalfTransMax.Y());
199 Double_t transZ = gRandom->Uniform(fHalfTransMin.Z(), fHalfTransMax.Z());
200 Double_t rotX = gRandom->Uniform(fHalfRotMin.X(), fHalfRotMax.X());
201 Double_t rotY = gRandom->Uniform(fHalfRotMin.Y(), fHalfRotMax.Y());
202 Double_t rotZ = gRandom->Uniform(fHalfRotMin.Z(), fHalfRotMax.Z());
203 return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ);
207 //__________________________________________________________________
209 AliFMDAlignFaker::MakeAlignSensor(const TString& path, Int_t id)
211 AliDebug(1, Form("Make alignment for sensor %s", path.Data()));
212 Double_t transX = gRandom->Uniform(fSensorTransMin.X(), fSensorTransMax.X());
213 Double_t transY = gRandom->Uniform(fSensorTransMin.Y(), fSensorTransMax.Y());
214 Double_t transZ = gRandom->Uniform(fSensorTransMin.Z(), fSensorTransMax.Z());
215 Double_t rotX = gRandom->Uniform(fSensorRotMin.X(), fSensorRotMax.X());
216 Double_t rotY = gRandom->Uniform(fSensorRotMin.Y(), fSensorRotMax.Y());
217 Double_t rotZ = gRandom->Uniform(fSensorRotMin.Z(), fSensorRotMax.Z());
218 return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ);
221 //__________________________________________________________________
223 AliFMDAlignFaker::WriteToCDB()
226 AliCDBManager* cdb = AliCDBManager::Instance();
227 if (GetTitle()) cdb->SetDefaultStorage(GetTitle());
229 AliCDBMetaData* meta = new AliCDBMetaData;
230 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data());
231 meta->SetAliRootVersion(gROOT->GetVersion());
232 meta->SetBeamPeriod(1);
233 meta->SetComment("Dummy data for testing");
235 AliCDBId id("FMD/Align/Data", fRunMin, fRunMax);
236 cdb->Put(fArray, id, meta);
240 //__________________________________________________________________
242 AliFMDAlignFaker::WriteToFile()
244 TFile* file = TFile::Open(GetTitle(), "RECREATE");
246 AliFatal(Form("Failed to open file '%s' for output", GetTitle()));
250 fArray->Write("FMDAlignment");
257 //____________________________________________________________________