]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSegFactory.cxx
- Removing AliMpSegFactory -> using AliMpSegmentation instead
[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"
b27e9585 42#include "AliMpSegmentation.h"
fc337f2e 43
44#include "AliLog.h"
45
46#include <Riostream.h>
47#include <TSystem.h>
48#include <TObjString.h>
49#include <TMap.h>
50
5398f946 51/// \cond CLASSIMP
fc337f2e 52ClassImp(AliMUONSegFactory)
5398f946 53/// \endcond
fc337f2e 54
55//______________________________________________________________________________
56AliMUONSegFactory::AliMUONSegFactory(const AliMUONGeometryTransformer* geometry)
57 : TObject(),
fc337f2e 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(),
fc337f2e 70 fDESegmentations(),
71 fSegmentation(0),
72 fkTransformer(0)
73{
74/// Standard constructor
75
76 // Transformer
77 AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(true);
4f27ddd4 78 transformer->ReadGeometryData(volPathsFileName, transformsFileName);
fc337f2e 79 fkTransformer = transformer;
80}
81
82//______________________________________________________________________________
83 AliMUONSegFactory::AliMUONSegFactory()
84 : TObject(),
fc337f2e 85 fDESegmentations(),
86 fSegmentation(0),
87 fkTransformer(0)
88{
89/// Default constructor
90}
91
fc337f2e 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
fc337f2e 102//
103// Private methods
104//
105
106//______________________________________________________________________________
6080a225 107Bool_t AliMUONSegFactory::IsGeometryDefined(Int_t ichamberId)
fc337f2e 108{
5398f946 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)
fc337f2e 111
6080a225 112 AliMpDEIterator it;
113 it.First(ichamberId);
114 Int_t firstDE = it.CurrentDE();
115
fc337f2e 116 if ( ! fkTransformer ||
6080a225 117 ! fkTransformer->GetModuleTransformerByDEId(firstDE, false) )
fc337f2e 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 )
6080a225 130 fSegmentation = new AliMUONSegmentation(AliMUONConstants::NGeomModules());
fc337f2e 131
132 return fSegmentation;
133}
134
135//
136// public methods
137//
138
fc337f2e 139//______________________________________________________________________________
140AliMUONVGeometryDESegmentation*
141AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, Int_t cath)
142{
5398f946 143/// Create DE segmentation, operating in local DE reference frame
fc337f2e 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 //
fc337f2e 164 AliMUONGeometrySegmentation* moduleSegmentation
6080a225 165 = Segmentation()->GetModuleSegmentationByDEId(detElemId, cath, false);
fc337f2e 166 if (! moduleSegmentation) {
6080a225 167 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
fc337f2e 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
b27e9585 184
185
fc337f2e 186 // Get/Create mapping segmentation via mapping manager
b27e9585 187 const AliMpVSegmentation* kmpSegmentation
188 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, cath);
fc337f2e 189 AliMpVSegmentation* mpSegmentation
b27e9585 190 = const_cast<AliMpVSegmentation*>(kmpSegmentation);
191
fc337f2e 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//______________________________________________________________________________
6080a225 241void
242AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, Int_t cath)
fc337f2e 243{
6080a225 244/// Create module segmentation(s), operating in the global reference frame
5398f946 245/// Detection elements are defined via DE names map.
fc337f2e 246
247 // Check cathod & module Id
248 if ( ! AliMpDEManager::IsValidCathod(cath, true) ||
6080a225 249 ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
fc337f2e 250
251 AliMpDEIterator it;
6080a225 252 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
fc337f2e 253 CreateDESegmentation(it.CurrentDE(), cath);
fc337f2e 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
6080a225 273 if ( option == "FactoryV2" || option == "FactoryV3" ) {
fc337f2e 274
6080a225 275 AliErrorStream()
276 << "Option " << option << " not supported anymore." << endl;
277 return 0;
278 }
fc337f2e 279
6080a225 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);
fc337f2e 284 }
fc337f2e 285
6080a225 286 return Segmentation();
fc337f2e 287}
288