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