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