]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegFactory.cxx
New classes for shuttle (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONSegFactory.cxx
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
22 // --------------------------
23 // Class AliMUONSegFactory
24 // --------------------------
25 // New factory for building segmentations at all levels
26 // Authors: Ivana Hrivnacova, IPN Orsay
27
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"
40
41 #include "AliMpDEManager.h"
42 #include "AliMpDEIterator.h"
43
44 #include "AliLog.h"
45
46 #include <Riostream.h>
47 #include <TSystem.h>
48 #include <TObjString.h>
49 #include <TMap.h>
50
51 /// \cond CLASSIMP
52 ClassImp(AliMUONSegFactory)
53 /// \endcond
54
55 //______________________________________________________________________________
56 AliMUONSegFactory::AliMUONSegFactory(const AliMUONGeometryTransformer* geometry)
57     : TObject(),
58       fMpSegFactory(),
59       fDESegmentations(),
60       fSegmentation(0),
61       fkTransformer(geometry)
62 {  
63 /// Standard constructor
64
65 }
66
67 //______________________________________________________________________________
68 AliMUONSegFactory::AliMUONSegFactory(const TString& volPathsFileName,
69                                      const TString& transformsFileName)
70     : TObject(),
71       fMpSegFactory(),
72       fDESegmentations(),
73       fSegmentation(0),
74       fkTransformer(0)
75 {  
76 /// Standard constructor
77
78   // Transformer
79   AliMUONGeometryTransformer* transformer = new AliMUONGeometryTransformer(true);
80   transformer->ReadGeometryData(volPathsFileName, transformsFileName);
81   fkTransformer = transformer;  
82 }
83
84 //______________________________________________________________________________
85   AliMUONSegFactory::AliMUONSegFactory()
86     : TObject(),      
87       fMpSegFactory(),
88       fDESegmentations(),
89       fSegmentation(0),
90       fkTransformer(0)
91 {
92 /// Default constructor
93 }
94
95 //______________________________________________________________________________
96
97 AliMUONSegFactory::~AliMUONSegFactory()
98 {
99 /// Destructor
100
101   //delete fSegmentation;
102         // The segmentation is supposed to be deleted in the client code
103 }
104
105 //
106 // Private methods
107 //
108
109 //______________________________________________________________________________
110 Bool_t AliMUONSegFactory::IsGeometryDefined(Int_t ichamberId)
111 {
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)
114
115   AliMpDEIterator it;
116   it.First(ichamberId);
117   Int_t firstDE = it.CurrentDE(); 
118   
119   if ( ! fkTransformer ||
120        ! fkTransformer->GetModuleTransformerByDEId(firstDE, false) )
121        
122     return kFALSE;
123   
124   return kTRUE;
125 }  
126
127 //__________________________________________________________________________
128 AliMUONSegmentation* AliMUONSegFactory::Segmentation()
129
130 /// Return the segmentation container, create it if it does not yet exist
131
132   if ( ! fSegmentation ) 
133     fSegmentation = new AliMUONSegmentation(AliMUONConstants::NGeomModules());
134
135   return fSegmentation; 
136 }
137
138 //
139 // public methods
140 //
141
142 //______________________________________________________________________________
143 AliMpVSegmentation* 
144 AliMUONSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
145 {
146 /// Create mapping segmentation for given detElemId and cath
147 /// using mapping manager
148
149   AliMpVSegmentation* mpSegmentation 
150     = fMpSegFactory.CreateMpSegmentation(detElemId, cath);
151
152   Segmentation()->AddMpSegmentation(mpSegmentation);
153   
154   return mpSegmentation;
155
156     
157 //______________________________________________________________________________
158 AliMUONVGeometryDESegmentation*  
159 AliMUONSegFactory::CreateDESegmentation(Int_t detElemId, Int_t cath)
160
161 /// Create DE segmentation, operating in local DE reference frame
162
163   // Check detElemId & cath  
164   if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
165   
166   // Check if transformer is defined
167   if ( ! fkTransformer) {
168     AliErrorStream() << "Geometry transformer not defined" << endl;
169     return 0;
170   }  
171
172   // Only return it, if DE segmentation for this detElemId and cath
173   // was already defined
174   //
175   const AliMUONVGeometryDESegmentation* kdeSegmentation
176     = Segmentation()->GetDESegmentation(detElemId, cath, false);
177   if ( kdeSegmentation ) 
178     return const_cast<AliMUONVGeometryDESegmentation*>(kdeSegmentation);
179   
180   // Get module, create it if it does not exist 
181   //
182   AliMUONGeometrySegmentation* moduleSegmentation
183     = Segmentation()->GetModuleSegmentationByDEId(detElemId, cath, false);
184   if (! moduleSegmentation) {
185     Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);               
186     moduleSegmentation 
187       = new AliMUONGeometrySegmentation(
188                fkTransformer->GetModuleTransformer(moduleId));
189     Segmentation()->AddModuleSegmentation(moduleId, cath, moduleSegmentation);
190   }        
191    
192   // Get DE segmentation for this DE type, create it if it does not exist 
193   // 
194   AliMUONVGeometryDESegmentation* deSegmentation = 0;
195   TString deName = AliMpDEManager::GetDEName(detElemId, cath);
196   TObject* objSegmentation = fDESegmentations.Get(deName);
197   if ( objSegmentation ) 
198     deSegmentation = (AliMUONVGeometryDESegmentation*)objSegmentation;  
199     
200   if ( !deSegmentation ) {
201
202     // Get/Create mapping segmentation via mapping manager
203     AliMpVSegmentation* mpSegmentation 
204       = CreateMpSegmentation(detElemId, cath);
205  
206     AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
207     AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
208     
209     switch (stationType) {
210
211       case kStation1:
212       case kStation2:
213         deSegmentation = new AliMUONSt12QuadrantSegmentation(
214                                  mpSegmentation, stationType, planeType);
215         //cout << "   new AliMUONSt12QuadrantSegmentation "
216         //     << StationTypeName(stationType) << "  "  
217         //     << PlaneTypeName(planeType) << "  "
218         //     << deName << endl;
219                                           
220         break;
221         
222       case kStation345:                   
223         deSegmentation = new AliMUONSt345SlatSegmentationV2(
224                                  mpSegmentation, detElemId, planeType); 
225         //cout << "   new AliMUONSt345SlatSegmentationV2 "                        
226         //     << StationTypeName(stationType) << "  "  
227         //     << PlaneTypeName(planeType) << "  "
228         //     << deName << endl;                                 
229         break;
230     
231       case kStationTrigger:               
232         deSegmentation = new AliMUONTriggerSegmentationV2(
233                                  mpSegmentation, detElemId, planeType); 
234         //cout << "   new AliMUONTriggerSegmentationV2 "                          
235         //     << StationTypeName(stationType) << "  "  
236         //     << PlaneTypeName(planeType) << "  "                        
237         //     << deName << endl;                                 
238         break;
239     }
240     
241     // Map new DE segmentation
242     fDESegmentations.Add(deName, deSegmentation);
243     Segmentation()->AddDESegmentation(deSegmentation);
244   }
245   
246   // Add  DE segmentation to module
247   //
248   moduleSegmentation->Add(detElemId, deName, deSegmentation);  
249   
250   return deSegmentation;
251 }        
252   
253
254 //______________________________________________________________________________
255 void
256 AliMUONSegFactory::CreateModuleSegmentations(Int_t chamberId, Int_t cath)
257
258 /// Create module segmentation(s), operating in the global reference frame
259 /// Detection elements are defined via DE names map.
260
261   // Check cathod & module Id 
262   if ( ! AliMpDEManager::IsValidCathod(cath, true) || 
263        ! AliMpDEManager::IsValidChamberId(chamberId, true) ) return;
264
265   AliMpDEIterator it;
266   for ( it.First(chamberId); ! it.IsDone(); it.Next() )
267     CreateDESegmentation(it.CurrentDE(), cath);
268 }  
269     
270 //______________________________________________________________________________
271 AliMUONSegmentation*  
272 AliMUONSegFactory::CreateSegmentation(const TString& option)
273 {
274 /// Create segmentations on all levels and return their container.
275
276   // Check options
277   if ( option != "default"   && 
278        option != "FactoryV2" && 
279        option != "FactoryV3" &&
280        option != "FactoryV4" &&
281        option != "new") {
282
283     AliErrorStream() << "Option " << option << " not defined." << endl;
284     return 0;
285   }         
286  
287   if ( option == "FactoryV2" || option == "FactoryV3" ) { 
288
289     AliErrorStream() 
290       << "Option " << option << " not supported anymore." << endl;
291     return 0;
292   }         
293
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);
298   }
299
300   return Segmentation();
301 }
302