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 "AliMUONTriggerSegmentation.h"
38 #include "AliMpDEManager.h"
39 #include "AliMpDEIterator.h"
40 #include "AliMpSegmentation.h"
44 #include <Riostream.h>
46 #include <TObjString.h>
50 ClassImp(AliMUONSegFactory)
53 //______________________________________________________________________________
54 AliMUONSegFactory::AliMUONSegFactory(const AliMUONGeometryTransformer* geometry)
58 fkTransformer(geometry)
60 /// Standard constructor
64 //______________________________________________________________________________
65 AliMUONSegFactory::AliMUONSegFactory(const TString& volPathsFileName,
66 const TString& transformsFileName)
72 /// Standard constructor
75 AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(true);
76 transformer->ReadGeometryData(volPathsFileName, transformsFileName);
77 fkTransformer = transformer;
80 //______________________________________________________________________________
81 AliMUONSegFactory::AliMUONSegFactory()
87 /// Default constructor
90 //______________________________________________________________________________
92 AliMUONSegFactory::~AliMUONSegFactory()
96 //delete fSegmentation;
97 // The segmentation is supposed to be deleted in the client code
104 //______________________________________________________________________________
105 Bool_t AliMUONSegFactory::IsGeometryDefined(Int_t ichamberId)
107 /// Return true, if det elements for the chamber with the given ichamber Id
108 /// are defined in geometry (the geometry builder for this chamber was activated)
111 it.First(ichamberId);
112 Int_t firstDE = it.CurrentDE();
114 if ( ! fkTransformer ||
115 ! fkTransformer->GetModuleTransformerByDEId(firstDE, false) )
122 //__________________________________________________________________________
123 AliMUONSegmentation* AliMUONSegFactory::Segmentation()
125 /// Return the segmentation container, create it if it does not yet exist
127 if ( ! fSegmentation )
128 fSegmentation = new AliMUONSegmentation(AliMUONConstants::NGeomModules());
130 return fSegmentation;
137 //______________________________________________________________________________
138 AliMUONVGeometryDESegmentation*
139 AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, Int_t cath)
141 /// Create DE segmentation, operating in local DE reference frame
143 // Check detElemId & cath
144 if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
146 // Check if transformer is defined
147 if ( ! fkTransformer) {
148 AliErrorStream() << "Geometry transformer not defined" << endl;
152 // Only return it, if DE segmentation for this detElemId and cath
153 // was already defined
155 const AliMUONVGeometryDESegmentation* kdeSegmentation
156 = Segmentation()->GetDESegmentation(detElemId, cath, false);
157 if ( kdeSegmentation )
158 return const_cast<AliMUONVGeometryDESegmentation*>(kdeSegmentation);
160 // Get module, create it if it does not exist
162 AliMUONGeometrySegmentation* moduleSegmentation
163 = Segmentation()->GetModuleSegmentationByDEId(detElemId, cath, false);
164 if (! moduleSegmentation) {
165 Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
167 = new AliMUONGeometrySegmentation(
168 fkTransformer->GetModuleTransformer(moduleId));
169 Segmentation()->AddModuleSegmentation(moduleId, cath, moduleSegmentation);
172 // Get DE segmentation for this DE type, create it if it does not exist
174 AliMUONVGeometryDESegmentation* deSegmentation = 0;
175 TString deName = AliMpDEManager::GetDESegName(detElemId, cath);
176 TObject* objSegmentation = fDESegmentations.Get(deName);
177 if ( objSegmentation )
178 deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;
180 if ( !deSegmentation ) {
184 // Get/Create mapping segmentation via mapping manager
185 const AliMpVSegmentation* kmpSegmentation
186 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, cath);
187 AliMpVSegmentation* mpSegmentation
188 = const_cast<AliMpVSegmentation*>(kmpSegmentation);
190 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
191 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
193 switch (stationType) {
197 deSegmentation = new AliMUONSt12QuadrantSegmentation(
198 mpSegmentation, stationType, planeType);
199 //cout << " new AliMUONSt12QuadrantSegmentation "
200 // << StationTypeName(stationType) << " "
201 // << PlaneTypeName(planeType) << " "
202 // << deName << endl;
207 deSegmentation = new AliMUONSt345SlatSegmentation(
208 mpSegmentation, detElemId, planeType);
209 //cout << " new AliMUONSt345SlatSegmentationV2 "
210 // << StationTypeName(stationType) << " "
211 // << PlaneTypeName(planeType) << " "
212 // << deName << endl;
215 case kStationTrigger:
216 deSegmentation = new AliMUONTriggerSegmentation(
217 mpSegmentation, detElemId, planeType);
218 //cout << " new AliMUONTriggerSegmentation "
219 // << StationTypeName(stationType) << " "
220 // << PlaneTypeName(planeType) << " "
221 // << deName << endl;
225 // Map new DE segmentation
226 fDESegmentations.Add(deName, deSegmentation);
227 Segmentation()->AddDESegmentation(deSegmentation);
230 // Add DE segmentation to module
232 moduleSegmentation->Add(detElemId, deName, deSegmentation);
234 return deSegmentation;
238 //______________________________________________________________________________
240 AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, Int_t cath)
242 /// Create module segmentation(s), operating in the global reference frame
243 /// Detection elements are defined via DE names map.
245 // Check cathod & module Id
246 if ( ! AliMpDEManager::IsValidCathod(cath, true) ||
247 ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
250 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
251 CreateDESegmentation(it.CurrentDE(), cath);
254 //______________________________________________________________________________
256 AliMUONSegFactory::CreateSegmentation()
258 /// Create segmentations on all levels and return their container.
260 for (Int_t chamberId = 0; chamberId<AliMUONConstants::NCh(); chamberId++)
261 for (Int_t cath = 0; cath < 2; cath++) {
262 if ( IsGeometryDefined(chamberId) )
263 CreateModuleSegmentations( chamberId, cath);
266 return Segmentation();