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"
41 #include "AliMpDetElement.h"
42 #include "AliMpCathodType.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.CurrentDEId();
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, AliMp::CathodType cath)
143 /// Create DE segmentation, operating in local DE reference frame
145 // Check detElemId & cath
146 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, 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 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
178 TString deSegName = detElement->GetSegName(cath);
179 TObject* objSegmentation = fDESegmentations.Get(deSegName);
180 if ( objSegmentation )
181 deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;
183 if ( !deSegmentation ) {
187 // Get/Create mapping segmentation via mapping manager
188 const AliMpVSegmentation* kmpSegmentation
189 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, cath);
190 AliMpVSegmentation* mpSegmentation
191 = const_cast<AliMpVSegmentation*>(kmpSegmentation);
193 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
194 AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
196 switch (stationType) {
198 case AliMp::kStation1:
199 case AliMp::kStation2:
200 deSegmentation = new AliMUONSt12QuadrantSegmentation(
201 mpSegmentation, stationType, planeType);
202 //cout << " new AliMUONSt12QuadrantSegmentation "
203 // << StationTypeName(stationType) << " "
204 // << PlaneTypeName(planeType) << " "
205 // << deName << endl;
209 case AliMp::kStation345:
210 deSegmentation = new AliMUONSt345SlatSegmentation(
211 mpSegmentation, detElemId, planeType);
212 //cout << " new AliMUONSt345SlatSegmentationV2 "
213 // << StationTypeName(stationType) << " "
214 // << PlaneTypeName(planeType) << " "
215 // << deName << endl;
218 case AliMp::kStationTrigger:
219 deSegmentation = new AliMUONTriggerSegmentation(
220 mpSegmentation, detElemId, planeType);
221 //cout << " new AliMUONTriggerSegmentation "
222 // << StationTypeName(stationType) << " "
223 // << PlaneTypeName(planeType) << " "
224 // << deName << endl;
228 // Map new DE segmentation
229 fDESegmentations.Add(deSegName, deSegmentation);
230 Segmentation()->AddDESegmentation(deSegmentation);
233 // Add DE segmentation to module
235 moduleSegmentation->Add(detElemId, deSegName, deSegmentation);
237 return deSegmentation;
241 //______________________________________________________________________________
243 AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, AliMp::CathodType cath)
245 /// Create module segmentation(s), operating in the global reference frame
246 /// Detection elements are defined via DE names map.
249 if ( ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
252 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
253 CreateDESegmentation(it.CurrentDEId(), cath);
256 //______________________________________________________________________________
258 AliMUONSegFactory::CreateSegmentation()
260 /// Create segmentations on all levels and return their container.
262 for (Int_t chamberId = 0; chamberId<AliMUONConstants::NCh(); chamberId++)
263 for (Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath++) {
264 if ( IsGeometryDefined(chamberId) )
265 CreateModuleSegmentations( chamberId, AliMp::GetCathodType(cath));
268 return Segmentation();