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 //===========================================================
32 #include <Riostream.h>
35 #include "TClonesArray.h"
39 #include "AliMUONSegmentationDetectionElement.h"
40 #include "AliMUONSegmentManuIndex.h"
41 #include "AliMUONSegmentPosition.h"
42 #include "AliMUONSegmentIndex.h"
44 //___________________________________________
45 ClassImp(AliMUONSegmentationDetectionElement)
48 const TString AliMUONSegmentationDetectionElement::fgkDefaultTop =getenv("ALICE_ROOT") ;
49 const TString AliMUONSegmentationDetectionElement::fgkStationDir = "/MUON/mapping/data/station";
50 const TString AliMUONSegmentationDetectionElement::fgkBendingDir= "/bending_plane";
51 const TString AliMUONSegmentationDetectionElement::fgkNonBendingDir= "/non-bending_plane";
52 const TString AliMUONSegmentationDetectionElement::fgkFileExt = ".map";
53 const TString AliMUONSegmentationDetectionElement::fgkBendingExt = ".Bending";
54 const TString AliMUONSegmentationDetectionElement::fgkNonBendingExt = ".NonBending";
56 //___________________________________________
58 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
61 fWireD = 0.25; // wire pitch in cm
62 fWireX0 = 0.; // X0 position of the 1st wire
63 fMapManuIndexIndex= 0x0;
64 fMapIndexManuIndex= 0x0;
65 fMapIndexPosition= 0x0;
66 fMapPositionIndex=0X0;
70 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
73 // fMapManuIndexIndex= 0x0;
74 // fMapIndexManuIndex= 0x0;
75 // fMapIndexPosition= 0x0;
78 //________________________________________________
79 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs)
81 // Protected copy constructor
83 Fatal("AliMUONSegmentationDetectionElementModule", "Not implemented.");
85 //_________________________________________________
86 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
88 fListOfIndexes->Delete();
89 fListOfManuIndexes->Delete();
90 fListOfPositions->Delete();
91 fMapManuIndexIndex->Clear();
92 fMapIndexManuIndex->Clear();
93 fMapIndexPosition->Clear();
94 fMapPositionIndex->Clear();
97 //__________________________________________________
98 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode)
100 // Finding x_wire corresponding to x
101 Float_t x_wire = GetAnod(x);
103 //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
105 Int_t ix_max = (cathode==0) ? TMath::Nint(5./AliMUONSegmentPosition::GetUnit()) : TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit());
106 Int_t iy_max = (cathode==0) ? TMath::Nint(1.5/AliMUONSegmentPosition::GetUnit()) : TMath::Nint(5./AliMUONSegmentPosition::GetUnit());
108 AliMUONSegmentIndex * segmentindex =0x0;
109 AliMUONSegmentIndex * foundsegmentindex =0x0;
110 AliMUONSegmentPosition * segmentposition=0x0;
113 Float_t distance = 99999999.;
114 //printf("%d %d \n",ix_max, iy_max);
116 for(ix=-ix_max; ix<ix_max; ix++) {
117 xt = x_wire + ((Float_t)ix)*AliMUONSegmentPosition::GetUnit();
118 for(iy=-iy_max; iy<iy_max; iy++) {
119 yt = y + ((Float_t)iy)*AliMUONSegmentPosition::GetUnit();
120 segmentindex = GetIndexFromPosition( xt, yt, cathode);
121 if ( segmentindex ) {
122 // segmentindex->Print();
123 segmentposition = GetPosition(segmentindex->GetName());
124 if ( segmentposition->Distance(x_wire, y) < distance ) {
125 //printf("adfafa xt %f yt %f distance %f \n", xt, yt, segmentposition->Distance(xt,yt) );
126 distance = segmentposition->Distance(x_wire,y);
127 foundsegmentindex = segmentindex;
132 if (!foundsegmentindex) {
133 Warning("FindIndexFromPosition","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
135 return foundsegmentindex;
138 //____________________________________________________-
139 Float_t AliMUONSegmentationDetectionElement::GetAnod(Float_t xhit) const
141 // Returns for a hit position xhit the position of the nearest anode wire
142 Float_t wire= ( (xhit- fWireX0)>0 ) ?
143 Int_t( (xhit- fWireX0)/fWireD )+0.5 :
144 Int_t( (xhit- fWireX0)/fWireD )-0.5;
145 return fWireD*wire+fWireX0;
147 //_________________________________________________
148 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
150 // Getting AliMUONSegmentIndex from ManuIndex
151 return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
153 //_________________________________________________
154 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
156 // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
157 if (fMapManuIndexIndex) return (AliMUONSegmentIndex*) fMapManuIndexIndex->GetValue(SegmentManuIndexName);
159 Warning("GetIndex","SegmentManuIndex %s out of DetectionElement Mapping %s",
160 SegmentManuIndexName,fDetectionElementType.Data());
164 //_________________________________________________
165 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex(Int_t padx, Int_t pady, Int_t cathode ) const
167 // Getting ManuIndex from Index
168 return GetManuIndex( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
170 //_________________________________________________
171 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
173 // Getting ManuIndex from manuname
174 if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
176 Warning("GetManuIndex","SegmentIndex %s out of Detection Element mapping %s",
177 SegmentIndexName,fDetectionElementType.Data());
181 //__________________________________________________
182 void AliMUONSegmentationDetectionElement::GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y )
184 x = GetPosition(ix,iy,cathode)->GetXlocal();
185 y = GetPosition(ix,iy,cathode)->GetYlocal();
187 //__________________________________________________
188 void AliMUONSegmentationDetectionElement::GetPadI(Float_t x, Float_t y, Int_t cathode, Int_t &padx, Int_t &pady)
191 AliMUONSegmentIndex * segmentindex = FindIndexFromPosition(x,y,cathode);
194 padx = segmentindex->GetPadX();
195 pady = segmentindex->GetPadX();
198 Warning("GetPadI","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
201 //_________________________________________________
202 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
204 //Getting position from index
205 return GetPosition( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
207 //_________________________________________________
208 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
210 // Getting position from indexname
211 if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
213 Warning("GetPosition","SegmentIndex %s out of DetectionElement mapping %s",
214 SegmentIndexName, fDetectionElementType.Data());
218 //_________________________________________________
219 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
221 // Getting Index from position if position is a center pad position
222 return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
224 //_________________________________________________
225 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
227 // Getting index form positionname
228 if (fMapPositionIndex) return (AliMUONSegmentIndex*) fMapPositionIndex->GetValue(PositionName);
230 Warning("GetIndexFromPosition","SegmentPosition %s out of DetectionElement Mapping %s",
231 PositionName,fDetectionElementType.Data());
236 //_________________________________________________
237 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
239 // Getting AliMUONSegmentManuIndex objecto from manu index
240 if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
242 Warning("FindManuIndex","SegmentManuIndex %s out of DetectionElement mapping %s",
243 ManuIndexName,fDetectionElementType.Data());
248 //_________________________________________________
249 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
252 if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
254 Warning("FindIndex","SegmentIndex %s out of DetectionElement mapping %s",
255 IndexName,fDetectionElementType.Data());
259 //_________________________________________________
260 void AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
262 TString elementType(DetectionElementType);
263 fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
264 +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
265 fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
266 +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
268 if (fMapManuIndexIndex==0x0) {
269 fListOfIndexes = new TObjArray(15000);
270 fListOfManuIndexes =new TObjArray(15000);
271 fListOfPositions =new TObjArray(15000);
272 fMapManuIndexIndex= new TMap();
273 fMapIndexManuIndex = new TMap();
274 fMapIndexPosition = new TMap();
275 fMapPositionIndex = new TMap();
278 fListOfIndexes->Delete();
279 fListOfManuIndexes->Delete();
280 fListOfPositions->Delete();
281 fMapManuIndexIndex->Clear();
282 fMapIndexManuIndex->Clear();
283 fMapIndexPosition->Clear();
284 fMapPositionIndex->Clear();
289 Info("ReadingSegmentationMappingFile","%s", fSegmentationMappingFileBending.Data());
290 ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
293 Info("Init","Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data());
294 ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
297 //_______________________________________________________________
298 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
300 ifstream in( infile, ios::in);
302 Error("ReadingSegmentationMappingFile", "File not found.");
305 Int_t id, ix, iy, idmanu, idchannel;
308 in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
309 // printf("id=%d ix=%d iy=%d x=%f y=%f idmanu=%d and idchannel=%d\n",id, ix, iy, x, y,idmanu, idchannel);
311 fListOfIndexes->AddAt( new AliMUONSegmentIndex(id,ix,iy,cathode), id);
312 fListOfManuIndexes->AddAt( new AliMUONSegmentManuIndex(id,idmanu,0,idchannel), id);;
313 fListOfPositions->AddAt( new AliMUONSegmentPosition(id, x, y,cathode), id);;
315 //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
316 //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
317 //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
319 fMapManuIndexIndex->Add( fListOfManuIndexes->At(id), fListOfIndexes->At(id));
320 fMapIndexManuIndex->Add( fListOfIndexes->At(id), fListOfManuIndexes->At(id));
321 fMapIndexPosition->Add( fListOfIndexes->At(id), fListOfPositions->At(id));
322 fMapPositionIndex->Add( fListOfPositions->At(id), fListOfIndexes->At(id) );