]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSegFactory.cxx
Former V2 renamed
[u/mrichter/AliRoot.git] / MUON / AliMUONSegFactory.cxx
CommitLineData
fc337f2e 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 **************************************************************************/
15
16////////////////////////////////////////////////////////////
17// Factory for muon chambers, segmentations and response //
18////////////////////////////////////////////////////////////
19
20/* $Id$ */
21
f7006443 22// --------------------------
23// Class AliMUONSegFactory
24// --------------------------
25// New factory for building segmentations at all levels
26// Authors: Ivana Hrivnacova, IPN Orsay
27
fc337f2e 28#include "AliMUONSegFactory.h"
29#include "AliMUONConstants.h"
fc337f2e 30#include "AliMUONGeometryTransformer.h"
31#include "AliMUONGeometryModule.h"
32#include "AliMUONSegmentation.h"
33#include "AliMUONGeometrySegmentation.h"
34#include "AliMUONSt12QuadrantSegmentation.h"
35#include "AliMUONSt345SlatSegmentation.h"
36#include "AliMUONSt345SlatSegmentationV2.h"
fc337f2e 37#include "AliMUONTriggerSegmentationV2.h"
fc337f2e 38
39#include "AliMpDEManager.h"
40#include "AliMpDEIterator.h"
b27e9585 41#include "AliMpSegmentation.h"
fc337f2e 42
43#include "AliLog.h"
44
45#include <Riostream.h>
46#include <TSystem.h>
47#include <TObjString.h>
48#include <TMap.h>
49
5398f946 50/// \cond CLASSIMP
fc337f2e 51ClassImp(AliMUONSegFactory)
5398f946 52/// \endcond
fc337f2e 53
54//______________________________________________________________________________
55AliMUONSegFactory::AliMUONSegFactory(const AliMUONGeometryTransformer* geometry)
56 : TObject(),
fc337f2e 57 fDESegmentations(),
58 fSegmentation(0),
59 fkTransformer(geometry)
60{
61/// Standard constructor
62
63}
64
65//______________________________________________________________________________
4f27ddd4 66AliMUONSegFactory::AliMUONSegFactory(const TString& volPathsFileName,
67 const TString& transformsFileName)
fc337f2e 68 : TObject(),
fc337f2e 69 fDESegmentations(),
70 fSegmentation(0),
71 fkTransformer(0)
72{
73/// Standard constructor
74
75 // Transformer
76 AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(true);
4f27ddd4 77 transformer->ReadGeometryData(volPathsFileName, transformsFileName);
fc337f2e 78 fkTransformer = transformer;
79}
80
81//______________________________________________________________________________
82 AliMUONSegFactory::AliMUONSegFactory()
83 : TObject(),
fc337f2e 84 fDESegmentations(),
85 fSegmentation(0),
86 fkTransformer(0)
87{
88/// Default constructor
89}
90
fc337f2e 91//______________________________________________________________________________
92
93AliMUONSegFactory::~AliMUONSegFactory()
94{
95/// Destructor
96
97 //delete fSegmentation;
98 // The segmentation is supposed to be deleted in the client code
99}
100
fc337f2e 101//
102// Private methods
103//
104
105//______________________________________________________________________________
6080a225 106Bool_t AliMUONSegFactory::IsGeometryDefined(Int_t ichamberId)
fc337f2e 107{
5398f946 108/// Return true, if det elements for the chamber with the given ichamber Id
109/// are defined in geometry (the geometry builder for this chamber was activated)
fc337f2e 110
6080a225 111 AliMpDEIterator it;
112 it.First(ichamberId);
113 Int_t firstDE = it.CurrentDE();
114
fc337f2e 115 if ( ! fkTransformer ||
6080a225 116 ! fkTransformer->GetModuleTransformerByDEId(firstDE, false) )
fc337f2e 117
118 return kFALSE;
119
120 return kTRUE;
121}
122
123//__________________________________________________________________________
124AliMUONSegmentation* AliMUONSegFactory::Segmentation()
125{
126/// Return the segmentation container, create it if it does not yet exist
127
128 if ( ! fSegmentation )
6080a225 129 fSegmentation = new AliMUONSegmentation(AliMUONConstants::NGeomModules());
fc337f2e 130
131 return fSegmentation;
132}
133
134//
135// public methods
136//
137
fc337f2e 138//______________________________________________________________________________
139AliMUONVGeometryDESegmentation*
140AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, Int_t cath)
141{
5398f946 142/// Create DE segmentation, operating in local DE reference frame
fc337f2e 143
144 // Check detElemId & cath
145 if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
146
147 // Check if transformer is defined
148 if ( ! fkTransformer) {
149 AliErrorStream() << "Geometry transformer not defined" << endl;
150 return 0;
151 }
152
153 // Only return it, if DE segmentation for this detElemId and cath
154 // was already defined
155 //
156 const AliMUONVGeometryDESegmentation* kdeSegmentation
157 = Segmentation()->GetDESegmentation(detElemId, cath, false);
158 if ( kdeSegmentation )
159 return const_cast<AliMUONVGeometryDESegmentation*>(kdeSegmentation);
160
161 // Get module, create it if it does not exist
162 //
fc337f2e 163 AliMUONGeometrySegmentation* moduleSegmentation
6080a225 164 = Segmentation()->GetModuleSegmentationByDEId(detElemId, cath, false);
fc337f2e 165 if (! moduleSegmentation) {
6080a225 166 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
fc337f2e 167 moduleSegmentation
168 = new AliMUONGeometrySegmentation(
169 fkTransformer->GetModuleTransformer(moduleId));
170 Segmentation()->AddModuleSegmentation(moduleId, cath, moduleSegmentation);
171 }
172
173 // Get DE segmentation for this DE type, create it if it does not exist
174 //
175 AliMUONVGeometryDESegmentation* deSegmentation = 0;
176 TString deName = AliMpDEManager::GetDEName(detElemId, cath);
177 TObject* objSegmentation = fDESegmentations.Get(deName);
178 if ( objSegmentation )
179 deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;
180
181 if ( !deSegmentation ) {
182
b27e9585 183
184
fc337f2e 185 // Get/Create mapping segmentation via mapping manager
b27e9585 186 const AliMpVSegmentation* kmpSegmentation
187 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, cath);
fc337f2e 188 AliMpVSegmentation* mpSegmentation
b27e9585 189 = const_cast<AliMpVSegmentation*>(kmpSegmentation);
190
fc337f2e 191 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
192 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
193
194 switch (stationType) {
195
196 case kStation1:
197 case kStation2:
198 deSegmentation = new AliMUONSt12QuadrantSegmentation(
199 mpSegmentation, stationType, planeType);
200 //cout << " new AliMUONSt12QuadrantSegmentation "
201 // << StationTypeName(stationType) << " "
202 // << PlaneTypeName(planeType) << " "
203 // << deName << endl;
204
205 break;
206
207 case kStation345:
208 deSegmentation = new AliMUONSt345SlatSegmentationV2(
209 mpSegmentation, detElemId, planeType);
210 //cout << " new AliMUONSt345SlatSegmentationV2 "
211 // << StationTypeName(stationType) << " "
212 // << PlaneTypeName(planeType) << " "
213 // << deName << endl;
214 break;
215
216 case kStationTrigger:
217 deSegmentation = new AliMUONTriggerSegmentationV2(
218 mpSegmentation, detElemId, planeType);
219 //cout << " new AliMUONTriggerSegmentationV2 "
220 // << StationTypeName(stationType) << " "
221 // << PlaneTypeName(planeType) << " "
222 // << deName << endl;
223 break;
224 }
225
226 // Map new DE segmentation
227 fDESegmentations.Add(deName, deSegmentation);
228 Segmentation()->AddDESegmentation(deSegmentation);
229 }
230
231 // Add DE segmentation to module
232 //
233 moduleSegmentation->Add(detElemId, deName, deSegmentation);
234
235 return deSegmentation;
236}
237
238
239//______________________________________________________________________________
6080a225 240void
241AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, Int_t cath)
fc337f2e 242{
6080a225 243/// Create module segmentation(s), operating in the global reference frame
5398f946 244/// Detection elements are defined via DE names map.
fc337f2e 245
246 // Check cathod & module Id
247 if ( ! AliMpDEManager::IsValidCathod(cath, true) ||
6080a225 248 ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
fc337f2e 249
250 AliMpDEIterator it;
6080a225 251 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
fc337f2e 252 CreateDESegmentation(it.CurrentDE(), cath);
fc337f2e 253}
254
255//______________________________________________________________________________
256AliMUONSegmentation*
257AliMUONSegFactory::CreateSegmentation(const TString& option)
258{
259/// Create segmentations on all levels and return their container.
260
261 // Check options
262 if ( option != "default" &&
263 option != "FactoryV2" &&
264 option != "FactoryV3" &&
265 option != "FactoryV4" &&
266 option != "new") {
267
268 AliErrorStream() << "Option " << option << " not defined." << endl;
269 return 0;
270 }
271
6080a225 272 if ( option == "FactoryV2" || option == "FactoryV3" ) {
fc337f2e 273
6080a225 274 AliErrorStream()
275 << "Option " << option << " not supported anymore." << endl;
276 return 0;
277 }
fc337f2e 278
6080a225 279 for (Int_t chamberId = 0; chamberId<AliMUONConstants::NCh(); chamberId++)
280 for (Int_t cath = 0; cath < 2; cath++) {
281 if ( IsGeometryDefined(chamberId) )
282 CreateModuleSegmentations( chamberId, cath);
fc337f2e 283 }
fc337f2e 284
6080a225 285 return Segmentation();
fc337f2e 286}
287