]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationDetectionElement.cxx
Coding violations corrected
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentationDetectionElement.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 /* $Id$ */
17 //===========================================================
18 //  Segmentation classes for MUON Detection Elements      
19 //        Gines MARTINEZ, SUBATECH July 04                
20 //  This class interfaces with the mapping and segmentation
21 //  files MUON.
22 //  This files are placed by default in 
23 //  $ALICE_ROOT/MUON/mapping/data/Stationxxx/yyy_plane/
24 //  There are in tracking 23 types of detection elements
25 //  8 SectorSt1, 8 SectorSt2, 2 122000SR1, 2 122000NR1, 4 112200SR2, 4 112200NR2 
26 //  4 122200S, 4 122200N, 8 222000N,8 220000N,  8 330000N, 4 122300N, 8 112230NR3 
27 //  8 112230N, 8 222330N, 8 223300N, 16 333000N, 4  122330N, 8 112233NR3, 8 112233N 
28 //  8 222333N, 8 223330N, 8 333300N 
29 //  Detailed information in Alice Technical Note xxxxxxxx (2004)
30 //===========================================================
31
32 #include <Riostream.h>
33
34 #include "TClonesArray.h"
35 #include "TMap.h"
36
37 #include "AliMUONSegmentationDetectionElement.h"
38 #include "AliMUONSegmentManuIndex.h"
39 #include "AliMUONSegmentPosition.h"
40 #include "AliMUONSegmentIndex.h"
41
42 //___________________________________________
43 ClassImp(AliMUONSegmentationDetectionElement)
44
45 //static data member
46 const TString AliMUONSegmentationDetectionElement::fgkDefaultTop =getenv("ALICE_ROOT") ;
47 const TString AliMUONSegmentationDetectionElement::fgkStationDir = "/MUON/mapping/data/station";
48 const TString AliMUONSegmentationDetectionElement::fgkBendingDir= "/bending_plane";  
49 const TString AliMUONSegmentationDetectionElement::fgkNonBendingDir= "/non-bending_plane";
50 const TString AliMUONSegmentationDetectionElement::fgkFileExt = ".map";
51 const TString AliMUONSegmentationDetectionElement::fgkBendingExt = ".Bending";
52 const TString AliMUONSegmentationDetectionElement::fgkNonBendingExt = ".NonBending";
53
54 //___________________________________________
55
56 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
57 {
58   //Default constructor
59   fMapManuIndexIndex= 0x0;
60   fMapIndexManuIndex= 0x0;
61   fMapIndexPosition= 0x0;
62   fMapPositionIndex=0X0;
63 }
64
65
66 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
67 // {
68   
69 //   fMapManuIndexIndex= 0x0;
70 //   fMapIndexManuIndex= 0x0;
71 //   fMapIndexPosition= 0x0;
72 // }
73
74 //________________________________________________
75 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs) 
76 {
77 // Protected copy constructor
78
79   Fatal("AliMUONSegmentationDetectionElementModule", "Not implemented.");
80 }
81 //_________________________________________________
82 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
83   //Class destructor
84   fListOfIndexes->Delete();
85   fListOfManuIndexes->Delete();
86   fListOfPositions->Delete();
87   fMapManuIndexIndex->Clear();
88   fMapIndexManuIndex->Clear();
89   fMapIndexPosition->Clear();
90   fMapPositionIndex->Clear();
91 }
92
93 //_________________________________________________
94 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
95 {
96   // Getting AliMUONSegmentIndex from ManuIndex
97   return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
98 }
99 //_________________________________________________
100 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
101 {
102   // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
103   if (fMapManuIndexIndex) return  (AliMUONSegmentIndex*)  fMapManuIndexIndex->GetValue(SegmentManuIndexName);
104   else {
105     Warning("GetIndex","SegmentManuIndex %s out of DetectionElement Mapping %s",
106             SegmentManuIndexName,fDetectionElementType.Data());
107     return 0x0;
108   }
109 }
110 //_________________________________________________
111 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex(Int_t padx, Int_t pady, Int_t cathode ) const
112 {
113   // Getting ManuIndex from Index
114   return GetManuIndex( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() ); 
115 }
116 //_________________________________________________
117 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
118 {
119   // Getting ManuIndex from manuname
120   if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
121   else {
122     Warning("GetManuIndex","SegmentIndex %s out of Detection Element mapping %s",
123             SegmentIndexName,fDetectionElementType.Data());
124     return 0x0;
125   }
126 }
127 //_________________________________________________
128 AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
129 {
130   //Getting position from index
131   return GetPosition(  AliMUONSegmentIndex::Name(padx, pady, cathode).Data() ); 
132 }
133 //_________________________________________________
134 AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
135 {
136   // Getting position from indexname
137   if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
138   else {
139     Warning("GetPosition","SegmentIndex %s out of DetectionElement mapping %s",
140             SegmentIndexName, fDetectionElementType.Data());
141     return 0x0;
142   }
143 }
144 //_________________________________________________
145 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
146 {
147   // Getting Index from position if position is a center pad position
148   return GetIndexFromPosition( AliMUONSegmentPosition::Name(x,y, cathode).Data() );
149 }
150 //_________________________________________________
151 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
152 {
153   // Getting index form positionname
154   if (fMapPositionIndex) return  (AliMUONSegmentIndex*)  fMapPositionIndex->GetValue(PositionName);
155   else {
156     Warning("GetIndexFromPosition","SegmentPosition %s out of DetectionElement Mapping %s",
157             PositionName,fDetectionElementType.Data());
158     return 0x0;
159   }
160 }
161
162 //_________________________________________________
163 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
164 {
165   // Getting AliMUONSegmentManuIndex objecto from manu index
166   if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
167   else  {
168     Warning("FindManuIndex","SegmentManuIndex %s out of DetectionElement mapping %s",
169             ManuIndexName,fDetectionElementType.Data());
170     return 0x0;
171   }
172 }
173
174 //_________________________________________________
175 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
176 {
177   // Getting 
178   if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
179   else {
180     Warning("FindIndex","SegmentIndex %s out of DetectionElement mapping %s",
181             IndexName,fDetectionElementType.Data());
182     return 0x0;
183   }
184 }
185 //_________________________________________________
186 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t /*x*/, Float_t /*y*/, Int_t /*cathode*/ ) const
187 {
188
189  //  char * name = AliMUONSegmentPosition::Name(x,y);
190
191 //   if (GetIndexFromPosition( AliMUONSegmentPosition::Name(x,y)) ) 
192 //     return GetIndexFromPosition( AliMUONSegmentPosition::Name(x,y) );
193   
194 //   Float_t xl= ((Int_t) x*10 )/10.;
195 //   Float_t yl= ((Int_t) y*10 )/10.;
196 //   Int_t ix,iy, ixp;
197   
198 //   for(ix=1; ix<4; ix++) {
199 //     xl = ((Int_t) 0.5+10.*(x +  ((Float_t) ix )*0.1))/10.; 
200 //     for(iy=-ix; iy<ix+1; iy++) {
201 //       printf("A %d and %d and %f and %f \n",ix,iy,xl,yl);
202 //       yl = ((Int_t) 10.*(y +  ((Float_t) iy )*0.1))/10. ;
203 //       sprintf(name,"%5.1f-%5.1f",xl, yl);
204 //       if (GetIndexFromPosition(name)) break;
205 //     }
206 //     if (GetIndexFromPosition(name)) break;
207     
208
209 //     for(ixp=ix-1; ixp>-ix-1; ixp--) {
210 //       xl = ((Int_t) 0.5+10.*(x +  ((Float_t) ixp )*0.1))/10. ;
211 //       printf("B %d and %d and %f and %f \n",ixp,ix, xl, yl);
212 //       sprintf(name,"%5.1f-%5.1f",xl, yl);
213 //       if (GetIndexFromPosition(name)) break;
214 //     }
215 //     if (GetIndexFromPosition(name)) break;
216     
217 //     for(iy=ix-1; iy>-ix-1; iy--) {
218 //       yl = ((Int_t) 0.5+10.*(y +  ((Float_t) iy )*0.1))/10. ;
219 //       printf("C %d and %d and %f and %f \n",-ix,iy,xl,yl);
220 //       sprintf(name,"%5.1f-%5.1f",xl, yl);
221 //       if (GetIndexFromPosition(name)) break;
222 //     }
223 //     if (GetIndexFromPosition(name)) break;
224     
225 //     for(ixp=-ix+1; ixp<ix+1; ixp++) {
226 //       xl = ((Int_t) 0.5+10.*(x +  ((Float_t) ixp )*0.1))/10. ;
227 //       printf("D %d and %d and %f and %f \n",ixp,-ix,xl,yl);
228 //       sprintf(name,"%5.1f-%5.1f",xl, yl);
229 //       if (GetIndexFromPosition(name)) break;
230 //     }
231 //     if (GetIndexFromPosition(name)) break;
232 //   }
233 //   return GetIndexFromPosition(name);
234   return 0x0;
235 }
236 //_________________________________________________
237 void    AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
238 {
239   TString elementType(DetectionElementType);
240   fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
241     +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
242   printf("file is %s\n", fSegmentationMappingFileBending.Data());
243   fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
244     +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
245
246   if (fMapManuIndexIndex==0x0) { 
247     fListOfIndexes = new TObjArray(15000);
248     fListOfManuIndexes =new TObjArray(15000);
249     fListOfPositions =new TObjArray(15000);
250     fMapManuIndexIndex= new TMap();
251     fMapIndexManuIndex = new TMap();
252     fMapIndexPosition = new TMap();
253     fMapPositionIndex = new TMap();
254   }
255   else {
256     fListOfIndexes->Delete();
257     fListOfManuIndexes->Delete();
258     fListOfPositions->Delete();
259     fMapManuIndexIndex->Clear();
260     fMapIndexManuIndex->Clear();
261     fMapIndexPosition->Clear();
262     fMapPositionIndex->Clear();
263   }
264   Int_t icathode;
265   //Bendingplane
266   icathode=0;
267   ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
268   //NonBendingplane
269   icathode=1;
270   ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
271   
272 }
273 //_______________________________________________________________
274 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
275
276   ifstream in( infile,  ios::in);
277   if (!in) {
278     //    Error("ReadingSegmentationMappingFile", "File not found.");
279   }
280   else {
281     Int_t id, ix, iy, idmanu, idchannel;
282     Float_t x, y;
283     while ( !in.eof()) {
284       in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
285       printf("id=%d ix=%d iy=%d x=%f y=%f idmanu=%d and idchannel=%d\n",id, ix, iy,  x, y,idmanu, idchannel);
286       
287       fListOfIndexes->AddAt(     new AliMUONSegmentIndex(id,ix,iy,cathode), id);
288       fListOfManuIndexes->AddAt( new AliMUONSegmentManuIndex(id,idmanu,0,idchannel), id);;
289       fListOfPositions->AddAt(   new AliMUONSegmentPosition(id, x, y,cathode), id);;
290
291       ( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
292       ( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
293       ( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
294      
295       fMapManuIndexIndex->Add( fListOfManuIndexes->At(id), fListOfIndexes->At(id));
296       fMapIndexManuIndex->Add( fListOfIndexes->At(id),     fListOfManuIndexes->At(id));
297       fMapIndexPosition->Add(  fListOfIndexes->At(id),     fListOfPositions->At(id));
298       fMapPositionIndex->Add(  fListOfPositions->At(id), fListOfIndexes->At(id) );
299     } 
300   }
301   in.close();
302 }