]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGeometry.cxx
New data members: distance to bad channels from the center of a reconstructed cluster...
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometry.cxx
CommitLineData
75678bb3 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * SigmaEffect_thetadegrees *
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 purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17//
f7006443 18// ----------------------------
75678bb3 19// Class AliMUONGeometry
20// ----------------------------
21// Manager class for geometry construction via geometry builders.
75678bb3 22// Author: Ivana Hrivnacova, IPN Orsay
23
75678bb3 24#include "AliMUONGeometry.h"
25#include "AliMUONGeometryTransformer.h"
26#include "AliMUONGeometryModule.h"
7ecf374b 27#include "AliMUONStringIntMap.h"
c0a65a0e 28
29#include "AliMpDEManager.h"
7ecf374b 30
75678bb3 31#include "AliLog.h"
32
7ecf374b 33#include <TObjArray.h>
34#include <Riostream.h>
35#include <TSystem.h>
36
37#include <iostream>
75678bb3 38
a9aad96e 39/// \cond CLASSIMP
75678bb3 40ClassImp(AliMUONGeometry)
a9aad96e 41/// \endcond
75678bb3 42
43//______________________________________________________________________________
44AliMUONGeometry::AliMUONGeometry(Bool_t isOwner)
45 : TObject(),
46 fModules(0),
47 fTransformer(0)
48
49{
50/// Standard constructor
51
52 // Create array for geometry modules
53 fModules = new TObjArray();
54 fModules->SetOwner(isOwner);
55
56 // Geometry parametrisation
57 fTransformer = new AliMUONGeometryTransformer(false);
58}
59
60//______________________________________________________________________________
61AliMUONGeometry::AliMUONGeometry()
62 : TObject(),
63 fModules(0),
64 fTransformer(0)
65{
66/// Default constructor
67}
68
75678bb3 69//______________________________________________________________________________
70AliMUONGeometry::~AliMUONGeometry()
71{
72/// Destructor
73
74 delete fModules;
75 delete fTransformer;
76}
77
75678bb3 78//
79// private methods
80//
81
82//______________________________________________________________________________
83TString AliMUONGeometry::ComposePath(const TString& volName,
84 Int_t copyNo) const
85{
a9aad96e 86/// Compose path from given volName and copyNo
75678bb3 87
88 TString path(volName);
89 path += ".";
90 path += copyNo;
91
92 return path;
93}
94
95//______________________________________________________________________________
96void AliMUONGeometry::FillData3(const TString& sensVolumePath,
97 Int_t detElemId)
98{
a9aad96e 99/// Fill the mapping of the sensitive volume path to the detection element.
75678bb3 100
101 // Module Id
c0a65a0e 102 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
75678bb3 103
104 // Get module
105 AliMUONGeometryModule* module
106 = (AliMUONGeometryModule*)fModules->At(moduleId);
107
108 if ( !module ) {
109 AliWarningStream()
110 << "Geometry module for det element " << detElemId << " not defined."
111 << endl;
112 return;
113 }
114
115 // Get module sensitive volumes map
7ecf374b 116 AliMUONStringIntMap* svMap = module->GetSVMap();
75678bb3 117
118 // Map the sensitive volume to detection element
119 svMap->Add(sensVolumePath, detElemId);
120}
121
122//______________________________________________________________________________
123TString AliMUONGeometry::ReadData3(ifstream& in)
124{
a9aad96e 125/// Read SV maps from a file.
126/// Return true, if reading finished correctly.
75678bb3 127
128 TString key("SV");
129 while ( key == TString("SV") ) {
130
131 // Input data
132 TString volumePath;
133 Int_t detElemId;
134
135 in >> volumePath;
136 in >> detElemId;
137
138 //cout << "volumePath=" << volumePath << " "
139 // << "detElemId=" << detElemId
140 // << endl;
141
142 // Fill data
143 FillData3(volumePath, detElemId);
144
145 // Go to next line
146 in >> key;
147 }
148
149 return key;
150}
151
152//______________________________________________________________________________
153void AliMUONGeometry::WriteData3(ofstream& out) const
154{
a9aad96e 155/// Write association of sensitive volumes and detection elements
156/// from the sensitive volume map
75678bb3 157
158 for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
159 AliMUONGeometryModule* geometry
160 = (AliMUONGeometryModule*)fModules->At(i);
7ecf374b 161 AliMUONStringIntMap* svMap
75678bb3 162 = geometry->GetSVMap();
163
7ecf374b 164 svMap->Print("SV", out);
75678bb3 165 out << endl;
166 }
167}
168
169//
170// public functions
171//
172
173//_____________________________________________________________________________
174void AliMUONGeometry::AddModule(AliMUONGeometryModule* module)
175{
a9aad96e 176/// Add the geometry module to the array
75678bb3 177
178 fModules->Add(module);
179
180 if (module)
181 fTransformer->AddModuleTransformer(module->GetTransformer());
182}
183
184//______________________________________________________________________________
185Bool_t
186AliMUONGeometry::ReadSVMap(const TString& fileName)
187{
a9aad96e 188/// Read the sensitive volume maps from a file.
189/// Return true, if reading finished correctly.
75678bb3 190
191 // No reading
192 // if builder is not associated with any geometry module
193 if (fModules->GetEntriesFast() == 0) return false;
194
195 // File path
196 TString filePath = gSystem->Getenv("ALICE_ROOT");
197 filePath += "/MUON/data/";
198 filePath += fileName;
199
200 // Open input file
201 ifstream in(filePath, ios::in);
202 if (!in) {
203 cerr << filePath << endl;
204 AliFatal("File not found.");
205 return false;
206 }
207
208 TString key;
209 in >> key;
210 while ( !in.eof() ) {
211 if (key == TString("SV"))
212 key = ReadData3(in);
213 else {
214 AliFatal(Form("%s key not recognized", key.Data()));
215 return false;
216 }
217 }
218
219 return true;
220}
221
222//______________________________________________________________________________
223Bool_t
224AliMUONGeometry::WriteSVMap(const TString& fileName) const
225{
a9aad96e 226/// Write sensitive volume map into a file.
227/// Return true, if writing finished correctly.
75678bb3 228
229 // No writing
230 // if builder is not associated with any geometry module
231 if (fModules->GetEntriesFast() == 0) return false;
232
233 // File path
234 TString filePath = gSystem->Getenv("ALICE_ROOT");
235 filePath += "/MUON/data/";
236 filePath += fileName;
237
238 // Open input file
239 ofstream out(filePath, ios::out);
240 if (!out) {
241 cerr << filePath << endl;
242 AliError("File not found.");
243 return false;
244 }
245#if !defined (__DECCXX)
246 out.setf(std::ios::fixed);
247#endif
248 WriteData3(out);
249
250 return true;
251}
252
253//_____________________________________________________________________________
254const AliMUONGeometryModule*
255AliMUONGeometry::GetModule(Int_t index, Bool_t warn) const
256{
257/// Return the geometry module specified by index
258
259 if (index < 0 || index >= fModules->GetEntriesFast()) {
260 if (warn) {
261 AliWarningStream()
262 << "Index: " << index << " outside limits" << std::endl;
263 }
264 return 0;
265 }
266
267 return (const AliMUONGeometryModule*) fModules->At(index);
268}
269
270//_____________________________________________________________________________
271const AliMUONGeometryModule*
272AliMUONGeometry::GetModuleByDEId(Int_t detElemId, Bool_t warn) const
273{
a9aad96e 274/// Return the geometry module specified by detElemId
75678bb3 275
276 // Get module index
c0a65a0e 277 Int_t index = AliMpDEManager::GetGeomModuleId(detElemId);
75678bb3 278
279 return GetModule(index, warn);
280}