]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationDetectionElement.cxx
2892a515119bb12e9b165a76e82b0ff486d21cee
[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 #include "TMath.h"
37
38 #include "AliMUONSegmentationDetectionElement.h"
39 #include "AliMUONSegmentManuIndex.h"
40 #include "AliMUONSegmentPosition.h"
41 #include "AliMUONSegmentIndex.h"
42
43 //___________________________________________
44 ClassImp(AliMUONSegmentationDetectionElement)
45
46 //static data member
47 const TString AliMUONSegmentationDetectionElement::fgkDefaultTop =getenv("ALICE_ROOT") ;
48 const TString AliMUONSegmentationDetectionElement::fgkStationDir = "/MUON/mapping/data/station";
49 const TString AliMUONSegmentationDetectionElement::fgkBendingDir= "/bending_plane";  
50 const TString AliMUONSegmentationDetectionElement::fgkNonBendingDir= "/non-bending_plane";
51 const TString AliMUONSegmentationDetectionElement::fgkFileExt = ".map";
52 const TString AliMUONSegmentationDetectionElement::fgkBendingExt = ".Bending";
53 const TString AliMUONSegmentationDetectionElement::fgkNonBendingExt = ".NonBending";
54
55 //___________________________________________
56
57 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
58 {
59   //Default constructor
60   fWireD  = 0.25; // wire pitch in cm
61   fWireX0 = 0.;  // X0 position of the 1st wire
62   fMapManuIndexIndex= 0x0;
63   fMapIndexManuIndex= 0x0;
64   fMapIndexPosition= 0x0;
65   fMapPositionIndex=0X0;
66 }
67
68
69 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
70 // {
71   
72 //   fMapManuIndexIndex= 0x0;
73 //   fMapIndexManuIndex= 0x0;
74 //   fMapIndexPosition= 0x0;
75 // }
76
77 //________________________________________________
78 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs) 
79 {
80 // Protected copy constructor
81
82   Fatal("AliMUONSegmentationDetectionElementModule", "Not implemented.");
83 }
84 //_________________________________________________
85 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
86   //Class destructor
87   fListOfIndexes->Delete();
88   fListOfManuIndexes->Delete();
89   fListOfPositions->Delete();
90   fMapManuIndexIndex->Clear();
91   fMapIndexManuIndex->Clear();
92   fMapIndexPosition->Clear();
93   fMapPositionIndex->Clear();
94 }
95
96 //__________________________________________________
97 AliMUONSegmentIndex *  AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode)
98 {
99   // Finding x_wire corresponding to x
100   Float_t x_wire = GetAnod(x);
101
102   //Finding pad corresponding to the position (x_wire, y) in a zone of size 3cm x 10cm or 10cm x 3cm depending on cathode plane
103   // 
104   Int_t ix_max = (cathode==0) ? TMath::Nint(5./AliMUONSegmentPosition::GetUnit())  :  TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit());
105   Int_t iy_max = (cathode==0) ? TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit()) :  TMath::Nint(5./AliMUONSegmentPosition::GetUnit());
106
107   AliMUONSegmentIndex * segmentindex =0x0;
108   AliMUONSegmentIndex * foundsegmentindex =0x0;
109   AliMUONSegmentPosition * segmentposition=0x0;
110   Int_t   ix, iy;
111   Float_t xt,yt;
112   Float_t distance = 99999999.;
113   //printf("%d %d \n",ix_max, iy_max);
114
115   for(ix=-ix_max; ix<ix_max; ix++) {
116     xt = x_wire + ((Float_t)ix)*AliMUONSegmentPosition::GetUnit();
117     for(iy=-iy_max; iy<iy_max; iy++) {
118       yt = y + ((Float_t)iy)*AliMUONSegmentPosition::GetUnit();
119       segmentindex = GetIndexFromPosition( xt, yt, cathode);
120       if ( segmentindex ) {
121         // segmentindex->Print();
122         segmentposition = GetPosition(segmentindex->GetName());
123         if ( segmentposition->Distance(x_wire, y) < distance ) {     
124           //printf("adfafa xt %f yt %f distance %f \n", xt, yt, segmentposition->Distance(xt,yt) );     
125           distance = segmentposition->Distance(x_wire,y);
126           foundsegmentindex = segmentindex;
127         }
128       }
129     }
130   }
131  if (!foundsegmentindex) {
132    Warning("FindIndexFromPosition","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
133  }    
134  return foundsegmentindex;
135 }
136
137 //____________________________________________________-
138 Float_t AliMUONSegmentationDetectionElement::GetAnod(Float_t xhit) const
139 {
140   // Returns for a hit position xhit the position of the nearest anode wire    
141   Float_t wire= ( (xhit- fWireX0)>0 ) ? 
142     Int_t( (xhit- fWireX0)/fWireD )+0.5 : 
143     Int_t( (xhit- fWireX0)/fWireD )-0.5;
144   return fWireD*wire+fWireX0; 
145 }
146 //_________________________________________________
147 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
148 {
149   // Getting AliMUONSegmentIndex from ManuIndex
150   return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
151 }
152 //_________________________________________________
153 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
154 {
155   // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
156   if (fMapManuIndexIndex) return  (AliMUONSegmentIndex*)  fMapManuIndexIndex->GetValue(SegmentManuIndexName);
157   else {
158     Warning("GetIndex","SegmentManuIndex %s out of DetectionElement Mapping %s",
159             SegmentManuIndexName,fDetectionElementType.Data());
160     return 0x0;
161   }
162 }
163 //_________________________________________________
164 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex(Int_t padx, Int_t pady, Int_t cathode ) const
165 {
166   // Getting ManuIndex from Index
167   return GetManuIndex( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() ); 
168 }
169 //_________________________________________________
170 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
171 {
172   // Getting ManuIndex from manuname
173   if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
174   else {
175     Warning("GetManuIndex","SegmentIndex %s out of Detection Element mapping %s",
176             SegmentIndexName,fDetectionElementType.Data());
177     return 0x0;
178   }
179 }
180 //__________________________________________________
181 void  AliMUONSegmentationDetectionElement::GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y )
182 {
183   x = GetPosition(ix,iy,cathode)->GetXlocal();
184   y = GetPosition(ix,iy,cathode)->GetYlocal();
185 }
186 //__________________________________________________
187 void  AliMUONSegmentationDetectionElement::GetPadI(Float_t x, Float_t y, Int_t cathode, Int_t &padx, Int_t &pady)
188 {
189
190   AliMUONSegmentIndex * segmentindex = FindIndexFromPosition(x,y,cathode);
191
192   if (segmentindex) {
193     padx = segmentindex->GetPadX();
194     pady = segmentindex->GetPadX();
195   }
196   else {
197     Warning("GetPadI","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
198   }    
199 }
200 //_________________________________________________
201 AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
202 {
203   //Getting position from index
204   return GetPosition(  AliMUONSegmentIndex::Name(padx, pady, cathode).Data() ); 
205 }
206 //_________________________________________________
207 AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
208 {
209   // Getting position from indexname
210   if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
211   else {
212     Warning("GetPosition","SegmentIndex %s out of DetectionElement mapping %s",
213             SegmentIndexName, fDetectionElementType.Data());
214     return 0x0;
215   }
216 }
217 //_________________________________________________
218 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
219 {
220   // Getting Index from position if position is a center pad position
221   return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
222 }
223 //_________________________________________________
224 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
225 {
226   // Getting index form positionname
227   if (fMapPositionIndex) return  (AliMUONSegmentIndex*)  fMapPositionIndex->GetValue(PositionName);
228   else {
229     Warning("GetIndexFromPosition","SegmentPosition %s out of DetectionElement Mapping %s",
230             PositionName,fDetectionElementType.Data());
231     return 0x0;
232   }
233 }
234
235 //_________________________________________________
236 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
237 {
238   // Getting AliMUONSegmentManuIndex objecto from manu index
239   if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
240   else  {
241     Warning("FindManuIndex","SegmentManuIndex %s out of DetectionElement mapping %s",
242             ManuIndexName,fDetectionElementType.Data());
243     return 0x0;
244   }
245 }
246
247 //_________________________________________________
248 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
249 {
250   // Getting 
251   if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
252   else {
253     Warning("FindIndex","SegmentIndex %s out of DetectionElement mapping %s",
254             IndexName,fDetectionElementType.Data());
255     return 0x0;
256   }
257 }
258 //_________________________________________________
259 void    AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
260 {
261   TString elementType(DetectionElementType);
262   fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
263     +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
264   fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
265     +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
266
267   if (fMapManuIndexIndex==0x0) { 
268     fListOfIndexes = new TObjArray(15000);
269     fListOfManuIndexes =new TObjArray(15000);
270     fListOfPositions =new TObjArray(15000);
271     fMapManuIndexIndex= new TMap();
272     fMapIndexManuIndex = new TMap();
273     fMapIndexPosition = new TMap();
274     fMapPositionIndex = new TMap();
275   }
276   else {
277     fListOfIndexes->Delete();
278     fListOfManuIndexes->Delete();
279     fListOfPositions->Delete();
280     fMapManuIndexIndex->Clear();
281     fMapIndexManuIndex->Clear();
282     fMapIndexPosition->Clear();
283     fMapPositionIndex->Clear();
284   }
285   Int_t icathode;
286   //Bendingplane
287   icathode=0;
288   Info("ReadingSegmentationMappingFile","%s", fSegmentationMappingFileBending.Data());
289   ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
290   //NonBendingplane
291   icathode=1;
292   Info("Init","Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data());
293   ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
294   
295 }
296 //_______________________________________________________________
297 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
298
299   ifstream in( infile,  ios::in);
300   if (!in) {
301     Error("ReadingSegmentationMappingFile", "File not found.");
302   }
303   else {
304     Int_t id, ix, iy, idmanu, idchannel;
305     Float_t x, y;
306     do {
307       in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
308       //     printf("id=%d ix=%d iy=%d x=%f y=%f idmanu=%d and idchannel=%d\n",id, ix, iy,  x, y,idmanu, idchannel);
309       
310       fListOfIndexes->AddAt(     new AliMUONSegmentIndex(id,ix,iy,cathode), id);
311       fListOfManuIndexes->AddAt( new AliMUONSegmentManuIndex(id,idmanu,0,idchannel), id);;
312       fListOfPositions->AddAt(   new AliMUONSegmentPosition(id, x, y,cathode), id);;
313
314       //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
315       //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
316       //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
317      
318       fMapManuIndexIndex->Add( fListOfManuIndexes->At(id), fListOfIndexes->At(id));
319       fMapIndexManuIndex->Add( fListOfIndexes->At(id),     fListOfManuIndexes->At(id));
320       fMapIndexPosition->Add(  fListOfIndexes->At(id),     fListOfPositions->At(id));
321       fMapPositionIndex->Add(  fListOfPositions->At(id),   fListOfIndexes->At(id) );
322     }  
323     while ( !in.eof()); 
324   }
325   in.close();
326 }