1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //===========================================================
18 // Segmentation classes for MUON Detection Elements
19 // Gines MARTINEZ, SUBATECH July 04
20 // This class interfaces with the mapping and segmentation
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 //===========================================================
33 #include <Riostream.h>
36 #include "TClonesArray.h"
40 #include "AliMUONSegmentationDetectionElement.h"
41 #include "AliMUONSegmentManuIndex.h"
42 #include "AliMUONSegmentPosition.h"
43 #include "AliMUONSegmentIndex.h"
45 //___________________________________________
46 ClassImp(AliMUONSegmentationDetectionElement)
49 const TString AliMUONSegmentationDetectionElement::fgkDefaultTop =getenv("ALICE_ROOT") ;
50 const TString AliMUONSegmentationDetectionElement::fgkStationDir = "/MUON/mapping/data/station";
51 const TString AliMUONSegmentationDetectionElement::fgkBendingDir= "/bending_plane";
52 const TString AliMUONSegmentationDetectionElement::fgkNonBendingDir= "/non-bending_plane";
53 const TString AliMUONSegmentationDetectionElement::fgkFileExt = ".map";
54 const TString AliMUONSegmentationDetectionElement::fgkBendingExt = ".Bending";
55 const TString AliMUONSegmentationDetectionElement::fgkNonBendingExt = ".NonBending";
57 //___________________________________________
59 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
62 fWireD = 0.25; // wire pitch in cm
63 fWireX0 = 0.; // X0 position of the 1st wire
64 fMapManuIndexIndex= 0x0;
65 fMapIndexManuIndex= 0x0;
66 fMapIndexPosition= 0x0;
67 fMapPositionIndex=0X0;
71 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
74 // fMapManuIndexIndex= 0x0;
75 // fMapIndexManuIndex= 0x0;
76 // fMapIndexPosition= 0x0;
79 //________________________________________________
80 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs)
82 // Protected copy constructor
84 Fatal("AliMUONSegmentationDetectionElementModule", "Not implemented.");
86 //_________________________________________________
87 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
89 fListOfIndexes->Delete();
90 fListOfManuIndexes->Delete();
91 fListOfPositions->Delete();
92 fMapManuIndexIndex->Clear();
93 fMapIndexManuIndex->Clear();
94 fMapIndexPosition->Clear();
95 fMapPositionIndex->Clear();
98 //__________________________________________________
99 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode)
101 // Finding x_wire corresponding to x
102 Float_t x_wire = GetAnod(x);
104 //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 Int_t ix_max = (cathode==0) ? TMath::Nint(5./AliMUONSegmentPosition::GetUnit()) : TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit());
107 Int_t iy_max = (cathode==0) ? TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit()) : TMath::Nint(5./AliMUONSegmentPosition::GetUnit());
109 AliMUONSegmentIndex * segmentindex =0x0;
110 AliMUONSegmentIndex * foundsegmentindex =0x0;
111 AliMUONSegmentPosition * segmentposition=0x0;
114 Float_t distance = 99999999.;
115 //printf("%d %d \n",ix_max, iy_max);
117 for(ix=-ix_max; ix<ix_max; ix++) {
118 xt = x_wire + ((Float_t)ix)*AliMUONSegmentPosition::GetUnit();
119 for(iy=-iy_max; iy<iy_max; iy++) {
120 yt = y + ((Float_t)iy)*AliMUONSegmentPosition::GetUnit();
121 segmentindex = GetIndexFromPosition( xt, yt, cathode);
122 if ( segmentindex ) {
123 // segmentindex->Print();
124 segmentposition = GetPosition(segmentindex->GetName());
125 if ( segmentposition->Distance(x_wire, y) < distance ) {
126 //printf("adfafa xt %f yt %f distance %f \n", xt, yt, segmentposition->Distance(xt,yt) );
127 distance = segmentposition->Distance(x_wire,y);
128 foundsegmentindex = segmentindex;
133 if (!foundsegmentindex) {
134 Warning("FindIndexFromPosition","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
136 return foundsegmentindex;
139 //____________________________________________________-
140 Float_t AliMUONSegmentationDetectionElement::GetAnod(Float_t xhit) const
142 // Returns for a hit position xhit the position of the nearest anode wire
143 Float_t wire= ( (xhit- fWireX0)>0 ) ?
144 Int_t( (xhit- fWireX0)/fWireD )+0.5 :
145 Int_t( (xhit- fWireX0)/fWireD )-0.5;
146 return fWireD*wire+fWireX0;
148 //_________________________________________________
149 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
151 // Getting AliMUONSegmentIndex from ManuIndex
152 return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
154 //_________________________________________________
155 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
157 // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
158 if (fMapManuIndexIndex) return (AliMUONSegmentIndex*) fMapManuIndexIndex->GetValue(SegmentManuIndexName);
160 Warning("GetIndex","SegmentManuIndex %s out of DetectionElement Mapping %s",
161 SegmentManuIndexName,fDetectionElementType.Data());
165 //_________________________________________________
166 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex(Int_t padx, Int_t pady, Int_t cathode ) const
168 // Getting ManuIndex from Index
169 return GetManuIndex( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
171 //_________________________________________________
172 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
174 // Getting ManuIndex from manuname
175 if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
177 Warning("GetManuIndex","SegmentIndex %s out of Detection Element mapping %s",
178 SegmentIndexName,fDetectionElementType.Data());
182 //__________________________________________________
183 void AliMUONSegmentationDetectionElement::GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y )
185 x = GetPosition(ix,iy,cathode)->GetXlocal();
186 y = GetPosition(ix,iy,cathode)->GetYlocal();
188 //__________________________________________________
189 void AliMUONSegmentationDetectionElement::GetPadI(Float_t x, Float_t y, Int_t cathode, Int_t &padx, Int_t &pady)
192 AliMUONSegmentIndex * segmentindex = FindIndexFromPosition(x,y,cathode);
195 padx = segmentindex->GetPadX();
196 pady = segmentindex->GetPadX();
199 Warning("GetPadI","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
202 //_________________________________________________
203 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
205 //Getting position from index
206 return GetPosition( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
208 //_________________________________________________
209 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
211 // Getting position from indexname
212 if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
214 Warning("GetPosition","SegmentIndex %s out of DetectionElement mapping %s",
215 SegmentIndexName, fDetectionElementType.Data());
219 //_________________________________________________
220 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
222 // Getting Index from position if position is a center pad position
223 return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
225 //_________________________________________________
226 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
228 // Getting index form positionname
229 if (fMapPositionIndex) return (AliMUONSegmentIndex*) fMapPositionIndex->GetValue(PositionName);
231 Warning("GetIndexFromPosition","SegmentPosition %s out of DetectionElement Mapping %s",
232 PositionName,fDetectionElementType.Data());
237 //_________________________________________________
238 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
240 // Getting AliMUONSegmentManuIndex objecto from manu index
241 if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
243 Warning("FindManuIndex","SegmentManuIndex %s out of DetectionElement mapping %s",
244 ManuIndexName,fDetectionElementType.Data());
249 //_________________________________________________
250 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
253 if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
255 Warning("FindIndex","SegmentIndex %s out of DetectionElement mapping %s",
256 IndexName,fDetectionElementType.Data());
260 //_________________________________________________
261 void AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
263 TString elementType(DetectionElementType);
264 fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
265 +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
266 fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
267 +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
269 if (fMapManuIndexIndex==0x0) {
270 fListOfIndexes = new TObjArray(15000);
271 fListOfManuIndexes =new TObjArray(15000);
272 fListOfPositions =new TObjArray(15000);
273 fMapManuIndexIndex= new TMap();
274 fMapIndexManuIndex = new TMap();
275 fMapIndexPosition = new TMap();
276 fMapPositionIndex = new TMap();
279 fListOfIndexes->Delete();
280 fListOfManuIndexes->Delete();
281 fListOfPositions->Delete();
282 fMapManuIndexIndex->Clear();
283 fMapIndexManuIndex->Clear();
284 fMapIndexPosition->Clear();
285 fMapPositionIndex->Clear();
290 Info("ReadingSegmentationMappingFile","%s", fSegmentationMappingFileBending.Data());
291 ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
294 Info("Init","Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data());
295 ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
298 //_______________________________________________________________
299 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
301 ifstream in( infile, ios::in);
303 Error("ReadingSegmentationMappingFile", "File not found.");
306 Int_t id, ix, iy, idmanu, idchannel;
309 in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
310 // 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 fListOfIndexes->AddAt( new AliMUONSegmentIndex(id,ix,iy,cathode), id);
313 fListOfManuIndexes->AddAt( new AliMUONSegmentManuIndex(id,idmanu,0,idchannel), id);;
314 fListOfPositions->AddAt( new AliMUONSegmentPosition(id, x, y,cathode), id);;
316 //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
317 //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
318 //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
320 fMapManuIndexIndex->Add( fListOfManuIndexes->At(id), fListOfIndexes->At(id));
321 fMapIndexManuIndex->Add( fListOfIndexes->At(id), fListOfManuIndexes->At(id));
322 fMapIndexPosition->Add( fListOfIndexes->At(id), fListOfPositions->At(id));
323 fMapPositionIndex->Add( fListOfPositions->At(id), fListOfIndexes->At(id) );