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