1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////////////
17 // Factory for muon chambers, segmentations and response //
18 ////////////////////////////////////////////////////////////
22 // --------------------------
23 // Class AliMUONSegFactory
24 // --------------------------
25 // New factory for building segmentations at all levels
26 // Authors: Ivana Hrivnacova, IPN Orsay
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 #include "AliMUONTriggerConstants.h"
41 #include "AliMpDEManager.h"
42 #include "AliMpDEIterator.h"
46 #include <Riostream.h>
48 #include <TObjString.h>
52 ClassImp(AliMUONSegFactory)
55 //______________________________________________________________________________
56 AliMUONSegFactory::AliMUONSegFactory(const AliMUONGeometryTransformer* geometry)
61 fkTransformer(geometry)
63 /// Standard constructor
67 //______________________________________________________________________________
68 AliMUONSegFactory::AliMUONSegFactory(const TString& volPathsFileName,
69 const TString& transformsFileName)
76 /// Standard constructor
79 AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(true);
80 transformer->ReadGeometryData(volPathsFileName, transformsFileName);
81 fkTransformer = transformer;
84 //______________________________________________________________________________
85 AliMUONSegFactory::AliMUONSegFactory()
92 /// Default constructor
95 //______________________________________________________________________________
97 AliMUONSegFactory::~AliMUONSegFactory()
101 //delete fSegmentation;
102 // The segmentation is supposed to be deleted in the client code
109 //______________________________________________________________________________
110 Bool_t AliMUONSegFactory::IsGeometryDefined(Int_t ichamberId)
112 /// Return true, if det elements for the chamber with the given ichamber Id
113 /// are defined in geometry (the geometry builder for this chamber was activated)
116 it.First(ichamberId);
117 Int_t firstDE = it.CurrentDE();
119 if ( ! fkTransformer ||
120 ! fkTransformer->GetModuleTransformerByDEId(firstDE, false) )
127 //__________________________________________________________________________
128 AliMUONSegmentation* AliMUONSegFactory::Segmentation()
130 /// Return the segmentation container, create it if it does not yet exist
132 if ( ! fSegmentation )
133 fSegmentation = new AliMUONSegmentation(AliMUONConstants::NGeomModules());
135 return fSegmentation;
142 //______________________________________________________________________________
144 AliMUONSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
146 /// Create mapping segmentation for given detElemId and cath
147 /// using mapping manager
149 AliMpVSegmentation* mpSegmentation
150 = fMpSegFactory.CreateMpSegmentation(detElemId, cath);
152 Segmentation()->AddMpSegmentation(mpSegmentation);
154 return mpSegmentation;
157 //______________________________________________________________________________
158 AliMUONVGeometryDESegmentation*
159 AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, Int_t cath)
161 /// Create DE segmentation, operating in local DE reference frame
163 // Check detElemId & cath
164 if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
166 // Check if transformer is defined
167 if ( ! fkTransformer) {
168 AliErrorStream() << "Geometry transformer not defined" << endl;
172 // Only return it, if DE segmentation for this detElemId and cath
173 // was already defined
175 const AliMUONVGeometryDESegmentation* kdeSegmentation
176 = Segmentation()->GetDESegmentation(detElemId, cath, false);
177 if ( kdeSegmentation )
178 return const_cast<AliMUONVGeometryDESegmentation*>(kdeSegmentation);
180 // Get module, create it if it does not exist
182 AliMUONGeometrySegmentation* moduleSegmentation
183 = Segmentation()->GetModuleSegmentationByDEId(detElemId, cath, false);
184 if (! moduleSegmentation) {
185 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
187 = new AliMUONGeometrySegmentation(
188 fkTransformer->GetModuleTransformer(moduleId));
189 Segmentation()->AddModuleSegmentation(moduleId, cath, moduleSegmentation);
192 // Get DE segmentation for this DE type, create it if it does not exist
194 AliMUONVGeometryDESegmentation* deSegmentation = 0;
195 TString deName = AliMpDEManager::GetDEName(detElemId, cath);
196 TObject* objSegmentation = fDESegmentations.Get(deName);
197 if ( objSegmentation )
198 deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;
200 if ( !deSegmentation ) {
202 // Get/Create mapping segmentation via mapping manager
203 AliMpVSegmentation* mpSegmentation
204 = CreateMpSegmentation(detElemId, cath);
206 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
207 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
209 switch (stationType) {
213 deSegmentation = new AliMUONSt12QuadrantSegmentation(
214 mpSegmentation, stationType, planeType);
215 //cout << " new AliMUONSt12QuadrantSegmentation "
216 // << StationTypeName(stationType) << " "
217 // << PlaneTypeName(planeType) << " "
218 // << deName << endl;
223 deSegmentation = new AliMUONSt345SlatSegmentationV2(
224 mpSegmentation, detElemId, planeType);
225 //cout << " new AliMUONSt345SlatSegmentationV2 "
226 // << StationTypeName(stationType) << " "
227 // << PlaneTypeName(planeType) << " "
228 // << deName << endl;
231 case kStationTrigger:
232 deSegmentation = new AliMUONTriggerSegmentationV2(
233 mpSegmentation, detElemId, planeType);
234 //cout << " new AliMUONTriggerSegmentationV2 "
235 // << StationTypeName(stationType) << " "
236 // << PlaneTypeName(planeType) << " "
237 // << deName << endl;
241 // Map new DE segmentation
242 fDESegmentations.Add(deName, deSegmentation);
243 Segmentation()->AddDESegmentation(deSegmentation);
246 // Add DE segmentation to module
248 moduleSegmentation->Add(detElemId, deName, deSegmentation);
250 return deSegmentation;
254 //______________________________________________________________________________
256 AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, Int_t cath)
258 /// Create module segmentation(s), operating in the global reference frame
259 /// Detection elements are defined via DE names map.
261 // Check cathod & module Id
262 if ( ! AliMpDEManager::IsValidCathod(cath, true) ||
263 ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
266 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
267 CreateDESegmentation(it.CurrentDE(), cath);
270 //______________________________________________________________________________
272 AliMUONSegFactory::CreateSegmentation(const TString& option)
274 /// Create segmentations on all levels and return their container.
277 if ( option != "default" &&
278 option != "FactoryV2" &&
279 option != "FactoryV3" &&
280 option != "FactoryV4" &&
283 AliErrorStream() << "Option " << option << " not defined." << endl;
287 if ( option == "FactoryV2" || option == "FactoryV3" ) {
290 << "Option " << option << " not supported anymore." << endl;
294 for (Int_t chamberId = 0; chamberId<AliMUONConstants::NCh(); chamberId++)
295 for (Int_t cath = 0; cath < 2; cath++) {
296 if ( IsGeometryDefined(chamberId) )
297 CreateModuleSegmentations( chamberId, cath);
300 return Segmentation();