]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSegFactory.cxx
Moving from base to calib, and adding packing interface (a packed value is simply...
[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"
94d085f8 36#include "AliMUONTriggerSegmentation.h"
fc337f2e 37
38#include "AliMpDEManager.h"
39#include "AliMpDEIterator.h"
b27e9585 40#include "AliMpSegmentation.h"
866c3232 41#include "AliMpDetElement.h"
42#include "AliMpCathodType.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);
866c3232 114 Int_t firstDE = it.CurrentDEId();
6080a225 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*
866c3232 141AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, AliMp::CathodType cath)
fc337f2e 142{
5398f946 143/// Create DE segmentation, operating in local DE reference frame
fc337f2e 144
145 // Check detElemId & cath
866c3232 146 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
fc337f2e 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;
866c3232 177 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
178 TString deSegName = detElement->GetSegName(cath);
179 TObject* objSegmentation = fDESegmentations.Get(deSegName);
fc337f2e 180 if ( objSegmentation )
181 deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;
182
183 if ( !deSegmentation ) {
184
b27e9585 185
186
fc337f2e 187 // Get/Create mapping segmentation via mapping manager
b27e9585 188 const AliMpVSegmentation* kmpSegmentation
189 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, cath);
fc337f2e 190 AliMpVSegmentation* mpSegmentation
b27e9585 191 = const_cast<AliMpVSegmentation*>(kmpSegmentation);
192
866c3232 193 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
194 AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
fc337f2e 195
196 switch (stationType) {
197
866c3232 198 case AliMp::kStation1:
199 case AliMp::kStation2:
fc337f2e 200 deSegmentation = new AliMUONSt12QuadrantSegmentation(
201 mpSegmentation, stationType, planeType);
202 //cout << " new AliMUONSt12QuadrantSegmentation "
203 // << StationTypeName(stationType) << " "
204 // << PlaneTypeName(planeType) << " "
205 // << deName << endl;
206
207 break;
208
866c3232 209 case AliMp::kStation345:
c3e6d1f3 210 deSegmentation = new AliMUONSt345SlatSegmentation(
fc337f2e 211 mpSegmentation, detElemId, planeType);
212 //cout << " new AliMUONSt345SlatSegmentationV2 "
213 // << StationTypeName(stationType) << " "
214 // << PlaneTypeName(planeType) << " "
215 // << deName << endl;
216 break;
217
866c3232 218 case AliMp::kStationTrigger:
94d085f8 219 deSegmentation = new AliMUONTriggerSegmentation(
fc337f2e 220 mpSegmentation, detElemId, planeType);
94d085f8 221 //cout << " new AliMUONTriggerSegmentation "
fc337f2e 222 // << StationTypeName(stationType) << " "
223 // << PlaneTypeName(planeType) << " "
224 // << deName << endl;
225 break;
226 }
227
228 // Map new DE segmentation
866c3232 229 fDESegmentations.Add(deSegName, deSegmentation);
fc337f2e 230 Segmentation()->AddDESegmentation(deSegmentation);
231 }
232
233 // Add DE segmentation to module
234 //
866c3232 235 moduleSegmentation->Add(detElemId, deSegName, deSegmentation);
fc337f2e 236
237 return deSegmentation;
238}
239
240
241//______________________________________________________________________________
6080a225 242void
866c3232 243AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, AliMp::CathodType cath)
fc337f2e 244{
6080a225 245/// Create module segmentation(s), operating in the global reference frame
5398f946 246/// Detection elements are defined via DE names map.
fc337f2e 247
866c3232 248 // Check module Id
249 if ( ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
fc337f2e 250
251 AliMpDEIterator it;
6080a225 252 for ( it.First(chamberId); ! it.IsDone(); it.Next() )
866c3232 253 CreateDESegmentation(it.CurrentDEId(), cath);
fc337f2e 254}
255
256//______________________________________________________________________________
257AliMUONSegmentation*
c3e6d1f3 258AliMUONSegFactory::CreateSegmentation()
fc337f2e 259{
260/// Create segmentations on all levels and return their container.
261
6080a225 262 for (Int_t chamberId = 0; chamberId<AliMUONConstants::NCh(); chamberId++)
866c3232 263 for (Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath++) {
6080a225 264 if ( IsGeometryDefined(chamberId) )
866c3232 265 CreateModuleSegmentations( chamberId, AliMp::GetCathodType(cath));
fc337f2e 266 }
fc337f2e 267
6080a225 268 return Segmentation();
fc337f2e 269}
270