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"
40 #include "AliMpDEManager.h"
41 #include "AliMpDEIterator.h"
42 #include "AliMpSegmentation.h"
46 #include <Riostream.h>
48 #include <TObjString.h>
52 ClassImp(AliMUONSegFactory)
55 //______________________________________________________________________________
56 AliMUONSegFactory::AliMUONSegFactory(const AliMUONGeometryTransformer* geometry)
60 fkTransformer(geometry)
62 /// Standard constructor
66 //______________________________________________________________________________
67 AliMUONSegFactory::AliMUONSegFactory(const TString& volPathsFileName,
68 const TString& transformsFileName)
74 /// Standard constructor
77 AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(true);
78 transformer->ReadGeometryData(volPathsFileName, transformsFileName);
79 fkTransformer = transformer;
82 //______________________________________________________________________________
83 AliMUONSegFactory::AliMUONSegFactory()
89 /// Default constructor
92 //______________________________________________________________________________
94 AliMUONSegFactory::~AliMUONSegFactory()
98 //delete fSegmentation;
99 // The segmentation is supposed to be deleted in the client code
106 //______________________________________________________________________________
107 Bool_t AliMUONSegFactory::IsGeometryDefined(Int_t ichamberId)
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)
113 it.First(ichamberId);
114 Int_t firstDE = it.CurrentDE();
116 if ( ! fkTransformer ||
117 ! fkTransformer->GetModuleTransformerByDEId(firstDE, false) )
124 //__________________________________________________________________________
125 AliMUONSegmentation* AliMUONSegFactory::Segmentation()
127 /// Return the segmentation container, create it if it does not yet exist
129 if ( ! fSegmentation )
130 fSegmentation = new AliMUONSegmentation(AliMUONConstants::NGeomModules());
132 return fSegmentation;
139 //______________________________________________________________________________
140 AliMUONVGeometryDESegmentation*
141 AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, Int_t cath)
143 /// Create DE segmentation, operating in local DE reference frame
145 // Check detElemId & cath
146 if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
148 // Check if transformer is defined
149 if ( ! fkTransformer) {
150 AliErrorStream() << "Geometry transformer not defined" << endl;
154 // Only return it, if DE segmentation for this detElemId and cath
155 // was already defined
157 const AliMUONVGeometryDESegmentation* kdeSegmentation
158 = Segmentation()->GetDESegmentation(detElemId, cath, false);
159 if ( kdeSegmentation )
160 return const_cast<AliMUONVGeometryDESegmentation*>(kdeSegmentation);
162 // Get module, create it if it does not exist
164 AliMUONGeometrySegmentation* moduleSegmentation
165 = Segmentation()->GetModuleSegmentationByDEId(detElemId, cath, false);
166 if (! moduleSegmentation) {
167 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
169 = new AliMUONGeometrySegmentation(
170 fkTransformer->GetModuleTransformer(moduleId));
171 Segmentation()->AddModuleSegmentation(moduleId, cath, moduleSegmentation);
174 // Get DE segmentation for this DE type, create it if it does not exist
176 AliMUONVGeometryDESegmentation* deSegmentation = 0;
177 TString deName = AliMpDEManager::GetDEName(detElemId, cath);
178 TObject* objSegmentation = fDESegmentations.Get(deName);
179 if ( objSegmentation )
180 deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;
182 if ( !deSegmentation ) {
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);
192 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
193 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
195 switch (stationType) {
199 deSegmentation = new AliMUONSt12QuadrantSegmentation(
200 mpSegmentation, stationType, planeType);
201 //cout << " new AliMUONSt12QuadrantSegmentation "
202 // << StationTypeName(stationType) << " "
203 // << PlaneTypeName(planeType) << " "
204 // << deName << endl;
209 deSegmentation = new AliMUONSt345SlatSegmentationV2(
210 mpSegmentation, detElemId, planeType);
211 //cout << " new AliMUONSt345SlatSegmentationV2 "
212 // << StationTypeName(stationType) << " "
213 // << PlaneTypeName(planeType) << " "
214 // << deName << endl;
217 case kStationTrigger:
218 deSegmentation = new AliMUONTriggerSegmentationV2(
219 mpSegmentation, detElemId, planeType);
220 //cout << " new AliMUONTriggerSegmentationV2 "
221 // << StationTypeName(stationType) << " "
222 // << PlaneTypeName(planeType) << " "
223 // << deName << endl;
227 // Map new DE segmentation
228 fDESegmentations.Add(deName, deSegmentation);
229 Segmentation()->AddDESegmentation(deSegmentation);
232 // Add DE segmentation to module
234 moduleSegmentation->Add(detElemId, deName, deSegmentation);
236 return deSegmentation;
240 //______________________________________________________________________________
242 AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, Int_t cath)
244 /// Create module segmentation(s), operating in the global reference frame
245 /// Detection elements are defined via DE names map.
247 // Check cathod & module Id
248 if ( ! AliMpDEManager::IsValidCathod(cath, true) ||
249 ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
252 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
253 CreateDESegmentation(it.CurrentDE(), cath);
256 //______________________________________________________________________________
258 AliMUONSegFactory::CreateSegmentation(const TString& option)
260 /// Create segmentations on all levels and return their container.
263 if ( option != "default" &&
264 option != "FactoryV2" &&
265 option != "FactoryV3" &&
266 option != "FactoryV4" &&
269 AliErrorStream() << "Option " << option << " not defined." << endl;
273 if ( option == "FactoryV2" || option == "FactoryV3" ) {
276 << "Option " << option << " not supported anymore." << endl;
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);
286 return Segmentation();