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