]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentation.cxx
Updates (N. Bastid)
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentation.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *      SigmaEffect_thetadegrees                                                                  *
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 purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // $Id$
17 //
18 // ----------------------------
19 // Class AliMUONSegmentation
20 // ----------------------------
21 // Manager class for geometry construction via geometry builders.
22 // Author: Ivana Hrivnacova, IPN Orsay
23
24 #include <iostream>
25
26 #include <TObjArray.h>
27
28 #include "AliMUONSegmentation.h"
29 #include "AliMUONVGeometryDESegmentation.h"
30 #include "AliMUONGeometrySegmentation.h"
31 #include "AliMUONGeometryStore.h"
32
33 #include "AliMpVSegmentation.h"
34
35 #include "AliLog.h"
36
37 /// \cond CLASSIMP
38 ClassImp(AliMUONSegmentation)
39 /// \endcond
40  
41 //______________________________________________________________________________
42 AliMUONSegmentation::AliMUONSegmentation(Int_t nofModules)
43   : TObject(),
44     fMpSegmentations(0),
45     fDESegmentations(0)
46 {
47 /// Standard constructor
48
49   // Create array for mapping segmentations
50   fMpSegmentations = new TObjArray();
51   fMpSegmentations->SetOwner(kTRUE);
52
53   // Create array for DE segmentations
54   fDESegmentations = new TObjArray();
55   fDESegmentations->SetOwner(kTRUE);
56
57   // Create array for modules segmentations
58   for (Int_t cathod = 0; cathod < 2; cathod++) {
59     fModuleSegmentations[cathod] = new TObjArray(nofModules);
60     fModuleSegmentations[cathod]->SetOwner(true);
61     
62     for (Int_t i=0; i<nofModules; i++)
63       fModuleSegmentations[cathod]->AddAt(0, i);
64   }  
65
66   AliDebug(1, Form("ctor this = %p", this) ); 
67 }
68
69 //______________________________________________________________________________
70 AliMUONSegmentation::AliMUONSegmentation() 
71   : TObject(),
72     fMpSegmentations(0),
73     fDESegmentations(0)
74 {
75 /// Default constructor
76
77   fModuleSegmentations[0] = 0;
78   fModuleSegmentations[1] = 0;
79
80   AliDebug(1, Form("default (empty) ctor this = %p", this));
81
82
83 //______________________________________________________________________________
84 AliMUONSegmentation::~AliMUONSegmentation()
85 {
86 /// Destructor
87
88   AliDebug(1, Form("dtor this = %p", this));
89
90   delete fMpSegmentations;
91   delete fDESegmentations;
92   delete fModuleSegmentations[0];
93   delete fModuleSegmentations[1];
94 }
95
96 //
97 // public functions
98 //
99
100 //_____________________________________________________________________________
101 void AliMUONSegmentation::AddMpSegmentation(AliMpVSegmentation* segmentation)
102 {
103 /// Add the mapping segmentation to the array if not present
104
105   Bool_t isPresent = false;
106   for (Int_t i=0; i<fMpSegmentations->GetEntries(); i++) 
107     if ( (AliMpVSegmentation*)fMpSegmentations->At(i) == segmentation ) {
108       isPresent = true;
109       break;
110     }  
111
112   if (!isPresent) fMpSegmentations->Add(segmentation);
113 }
114
115 //_____________________________________________________________________________
116 void AliMUONSegmentation::AddDESegmentation(
117                                 AliMUONVGeometryDESegmentation* segmentation)
118 {
119 /// Add the DE segmentation to the array
120
121   fDESegmentations->Add(segmentation);
122   
123   // Deregister the mapping segmentation contained in DE segmentation
124   // from fMpSegmentations, if present
125   const AliMpVSegmentation* kmpSeg = segmentation->GetMpSegmentation();
126   
127   for (Int_t i=0; i<fMpSegmentations->GetEntries(); i++) 
128     if ( (const AliMpVSegmentation*)fMpSegmentations->At(i) == kmpSeg ) {
129       fMpSegmentations->RemoveAt(i);
130       break;
131     }  
132 }
133
134 //_____________________________________________________________________________
135 void AliMUONSegmentation::AddModuleSegmentation(Int_t moduleId, Int_t cathod,
136                              AliMUONGeometrySegmentation* segmentation)
137 {
138 /// Add the module segmentation to the array
139
140   if (cathod < 0 || cathod >= 2) {
141       AliErrorStream() 
142         << "Cathod: " << cathod << " outside limits" << std::endl;
143       return;   
144   }                      
145
146   if (moduleId < 0 || moduleId >= fModuleSegmentations[cathod]->GetEntriesFast()) {
147     AliErrorStream() 
148         << "Module Id: " << moduleId << " outside limits" << std::endl;
149     return;  
150   }  
151
152   fModuleSegmentations[cathod]->AddAt(segmentation, moduleId);
153 }
154
155 //_____________________________________________________________________________
156 void  AliMUONSegmentation::Init()
157 {
158 /// Initialize all segmentations
159  
160   for (Int_t cathod = 0; cathod < 2; cathod++) {
161     for (Int_t i = 0; i < fModuleSegmentations[cathod]->GetEntriesFast(); i++) {
162     
163       AliMUONGeometrySegmentation* moduleSegmentation
164         = (AliMUONGeometrySegmentation*)fModuleSegmentations[cathod]->At(i);
165     
166       if (moduleSegmentation) moduleSegmentation->Init(i); 
167     }  
168   }  
169 }
170                             
171 //_____________________________________________________________________________
172 AliMUONGeometrySegmentation* 
173 AliMUONSegmentation::GetModuleSegmentation(
174                         Int_t moduleId, Int_t cathod, Bool_t warn) const
175 {
176 /// Return the geometry module segmentation specified by moduleId
177
178   if (cathod < 0 || cathod >= 2) {
179     if (warn) {
180       AliWarningStream() 
181         << "Cathod: " << cathod << " outside limits" << std::endl;
182     }                    
183     return 0;  
184   }  
185
186   if (moduleId < 0 || moduleId >= fModuleSegmentations[cathod]->GetEntriesFast()) {
187     if (warn) {
188       AliWarningStream() 
189         << "Index: " << moduleId << " outside limits" << std::endl;
190     }                    
191     return 0;  
192   }  
193
194   return (AliMUONGeometrySegmentation*) 
195             fModuleSegmentations[cathod]->At(moduleId);
196 }    
197
198 //_____________________________________________________________________________
199 AliMUONGeometrySegmentation* 
200 AliMUONSegmentation::GetModuleSegmentationByDEId(
201                         Int_t detElemId, Int_t cathod, Bool_t warn) const
202 {
203 /// Return the geometry module specified by detElemId/cathod
204
205   // Get moduleId 
206   Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
207
208   return GetModuleSegmentation(moduleId, cathod, warn);
209 }    
210
211 //_____________________________________________________________________________
212 const AliMUONVGeometryDESegmentation* 
213 AliMUONSegmentation::GetDESegmentation(
214                         Int_t detElemId, Int_t cathod, Bool_t warn) const
215 {
216 /// Return the DE segmentation specified by detElemId/cathod
217
218   // Get geometry segmentation 
219   AliMUONGeometrySegmentation* moduleSegmentation
220     = GetModuleSegmentationByDEId(detElemId, cathod, warn);
221     
222   if ( !moduleSegmentation ) return 0; 
223   
224   return moduleSegmentation->GetDESegmentation(detElemId, warn);
225 }    
226
227 //_____________________________________________________________________________
228 const AliMpVSegmentation*
229 AliMUONSegmentation::GetMpSegmentation(
230                      Int_t detElemId, Int_t cathod, Bool_t warn) const
231 {                    
232 /// Return the mapping segmentation specified by detElemId/cathod
233
234
235   // Get DE segmentation 
236   const AliMUONVGeometryDESegmentation* kdeSegmentation
237     = GetDESegmentation(detElemId, cathod, warn);
238     
239   if ( !kdeSegmentation ) return 0; 
240   
241   return kdeSegmentation->GetMpSegmentation();
242 }    
243
244 //_____________________________________________________________________________
245 Bool_t 
246 AliMUONSegmentation::HasDE(Int_t detElemId, Int_t cathod) const
247 {
248 /// Return true if segmentation for detElemId and cathod is defined.
249
250   const AliMUONVGeometryDESegmentation* kdeSegmentation
251     = GetDESegmentation(detElemId, cathod, false);
252     
253   return ( kdeSegmentation != 0 ); 
254   
255 }
256
257 //_____________________________________________________________________________
258 TString 
259 AliMUONSegmentation::GetDEName(Int_t detElemId, Int_t cathod) const
260 {
261 /// Get detection element name 
262
263   AliMUONGeometrySegmentation* moduleSegmentation
264     = GetModuleSegmentationByDEId(detElemId, cathod, true);
265     
266   return  moduleSegmentation->GetDEName(detElemId); 
267 }
268
269