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 **************************************************************************/
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
21 //____________________________________________________________________
23 // Forward Multiplicity Detector based on Silicon wafers.
25 // This task creates fake alignment. Which alignment, depends on
26 // the bit mask passed to the constructor, or added by `AddAlign'.
28 // The default is to write all alignment parameters to a local
29 // storage `local://cdb' which is a directory in the current
32 #include "AliLog.h" // ALILOG_H
33 #include "AliFMDAlignFaker.h" // ALIFMDALIGNFAKER_H
34 #include <AliCDBManager.h> // ALICDBMANAGER_H
35 #include <AliCDBEntry.h> // ALICDBMANAGER_H
36 #include <AliAlignObj.h>
37 #include <AliAlignObjAngles.h>
38 #include <Riostream.h>
42 #include <TClonesArray.h>
45 #include <TGeoManager.h>
47 #include <TGeoVolume.h>
50 //====================================================================
51 ClassImp(AliFMDAlignFaker)
53 ; // This is here to keep Emacs for indenting the next line
56 //____________________________________________________________________
57 AliFMDAlignFaker::AliFMDAlignFaker(Int_t mask, const char* geo,
65 // Default constructor
66 SetSensorDisplacement();
68 SetHalfDisplacement();
72 //__________________________________________________________________
74 AliFMDAlignFaker::SetSensorDisplacement(Double_t x1, Double_t y1, Double_t z1,
75 Double_t x2, Double_t y2, Double_t z2)
77 // Set sensor displacement (unit is centimeters)
78 fSensorTransMin.SetXYZ(x1, y1, z1);
79 fSensorTransMax.SetXYZ(x2, y2, z2);
82 //__________________________________________________________________
84 AliFMDAlignFaker::SetSensorRotation(Double_t x1, Double_t y1, Double_t z1,
85 Double_t x2, Double_t y2, Double_t z2)
87 // Set sensor rotations (unit is degrees)
88 fSensorRotMin.SetXYZ(x1, y1, z1);
89 fSensorRotMax.SetXYZ(x2, y2, z2);
92 //__________________________________________________________________
94 AliFMDAlignFaker::SetHalfDisplacement(Double_t x1, Double_t y1, Double_t z1,
95 Double_t x2, Double_t y2, Double_t z2)
97 // Set half ring/cone displacement (unit is centimeters)
98 fHalfTransMin.SetXYZ(x1, y1, z1);
99 fHalfTransMax.SetXYZ(x2, y2, z2);
102 //__________________________________________________________________
104 AliFMDAlignFaker::SetHalfRotation(Double_t x1, Double_t y1, Double_t z1,
105 Double_t x2, Double_t y2, Double_t z2)
107 // Set half ring/cone rotations (unit is degrees)
108 fHalfRotMin.SetXYZ(x1, y1, z1);
109 fHalfRotMax.SetXYZ(x2, y2, z2);
112 //__________________________________________________________________
113 #define IS_NODE_HALF(name) \
114 (name[0] == 'F' && name[2] == 'M' && (name[3] == 'T' || name[3] == 'B'))
115 #define IS_NODE_SENSOR(name) \
116 (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
118 //__________________________________________________________________
120 AliFMDAlignFaker::Exec(Option_t*)
126 if (!TGeoManager::Import(GetName())) {
127 AliFatal(Form("Failed to import geometry from %s", GetName()));
132 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
134 AliFatal("No top-level volume defined");
137 // Make container of transforms
138 if (!fArray) fArray = new TClonesArray("AliAlignObjAngles");
142 TGeoIterator next(topVolume);
145 // Loop over all entries in geometry to find our nodes.
146 while ((node = static_cast<TGeoNode*>(next()))) {
147 const char* name = node->GetName();
148 if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) &&
149 !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors)))
153 TString path(Form("/%s", gGeoManager->GetNode(0)->GetName()));
154 Int_t nLevel = next.GetLevel();
155 for (Int_t lvl = 0; lvl <= nLevel; lvl++) {
156 TGeoNode* p = next.GetNode(lvl);
159 AliWarning(Form("No node at level %d in path %s",lvl,path.Data()));
162 if (!path.IsNull()) path.Append("/");
163 path.Append(p->GetName());
165 Int_t id = node->GetVolume()->GetNumber();
166 if (IS_NODE_HALF(name)) MakeAlignHalf(path, id);
167 if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id);
170 TString t(GetTitle());
171 if (t.IsNull() || t.Contains("local://") || t.Contains("alien://"))
177 //__________________________________________________________________
179 AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id,
180 Double_t transX, Double_t transY, Double_t transZ,
181 Double_t rotX, Double_t rotY, Double_t rotZ)
183 AliDebug(1, Form("Make alignment for %s (volume %d): (%f,%f,%f) (%f,%f,%f)",
184 path.Data(), id, transX, transY, transZ, rotX, rotY, rotZ));
185 Int_t nAlign = fArray->GetEntries();
186 AliAlignObjAngles* obj =
187 new ((*fArray)[nAlign]) AliAlignObjAngles(path.Data(), id,0,0,0,0,0,0);
189 AliError(Form("Failed to create alignment object for %s", path.Data()));
192 if (!obj->SetLocalPars(transX, transY, transZ, rotX, rotY, rotZ)) {
193 AliError(Form("Failed to set local transforms on %s", path.Data()));
199 //__________________________________________________________________
201 AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id)
203 AliDebug(15, Form("Make alignment for half-ring/cone %s", path.Data()));
204 Double_t transX = gRandom->Uniform(fHalfTransMin.X(), fHalfTransMax.X());
205 Double_t transY = gRandom->Uniform(fHalfTransMin.Y(), fHalfTransMax.Y());
206 Double_t transZ = gRandom->Uniform(fHalfTransMin.Z(), fHalfTransMax.Z());
207 Double_t rotX = gRandom->Uniform(fHalfRotMin.X(), fHalfRotMax.X());
208 Double_t rotY = gRandom->Uniform(fHalfRotMin.Y(), fHalfRotMax.Y());
209 Double_t rotZ = gRandom->Uniform(fHalfRotMin.Z(), fHalfRotMax.Z());
210 return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ);
214 //__________________________________________________________________
216 AliFMDAlignFaker::MakeAlignSensor(const TString& path, Int_t id)
218 AliDebug(15, Form("Make alignment for sensor %s", path.Data()));
219 Double_t transX = gRandom->Uniform(fSensorTransMin.X(), fSensorTransMax.X());
220 Double_t transY = gRandom->Uniform(fSensorTransMin.Y(), fSensorTransMax.Y());
221 Double_t transZ = gRandom->Uniform(fSensorTransMin.Z(), fSensorTransMax.Z());
222 Double_t rotX = gRandom->Uniform(fSensorRotMin.X(), fSensorRotMax.X());
223 Double_t rotY = gRandom->Uniform(fSensorRotMin.Y(), fSensorRotMax.Y());
224 Double_t rotZ = gRandom->Uniform(fSensorRotMin.Z(), fSensorRotMax.Z());
225 return MakeAlign(path, id, transX, transY, transZ, rotX, rotY, rotZ);
228 //__________________________________________________________________
230 AliFMDAlignFaker::WriteToCDB()
233 AliCDBManager* cdb = AliCDBManager::Instance();
234 if (GetTitle() && GetTitle()[0] != '\0')
235 cdb->SetDefaultStorage(GetTitle());
237 AliCDBMetaData* meta = new AliCDBMetaData;
238 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data());
239 meta->SetAliRootVersion(gROOT->GetVersion());
240 meta->SetBeamPeriod(1);
241 meta->SetComment("Dummy data for testing");
243 AliCDBId id("FMD/Align/Data", fRunMin, fRunMax);
244 cdb->Put(fArray, id, meta);
248 //__________________________________________________________________
250 AliFMDAlignFaker::WriteToFile()
252 TFile* file = TFile::Open(GetTitle(), "RECREATE");
254 AliFatal(Form("Failed to open file '%s' for output", GetTitle()));
258 fArray->Write("FMDAlignment");
265 //____________________________________________________________________