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>
34 #include "TClonesArray.h"
38 #include "AliMUONSegmentationDetectionElement.h"
39 #include "AliMUONSegmentManuIndex.h"
40 #include "AliMUONSegmentPosition.h"
41 #include "AliMUONSegmentIndex.h"
43 //___________________________________________
44 ClassImp(AliMUONSegmentationDetectionElement)
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";
55 //___________________________________________
57 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
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;
69 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
72 // fMapManuIndexIndex= 0x0;
73 // fMapIndexManuIndex= 0x0;
74 // fMapIndexPosition= 0x0;
77 //________________________________________________
78 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs)
80 // Protected copy constructor
82 Fatal("AliMUONSegmentationDetectionElementModule", "Not implemented.");
84 //_________________________________________________
85 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
87 fListOfIndexes->Delete();
88 fListOfManuIndexes->Delete();
89 fListOfPositions->Delete();
90 fMapManuIndexIndex->Clear();
91 fMapIndexManuIndex->Clear();
92 fMapIndexPosition->Clear();
93 fMapPositionIndex->Clear();
96 //__________________________________________________
97 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode)
99 // Finding x_wire corresponding to x
100 Float_t x_wire = GetAnod(x);
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
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());
107 AliMUONSegmentIndex * segmentindex =0x0;
108 AliMUONSegmentIndex * foundsegmentindex =0x0;
109 AliMUONSegmentPosition * segmentposition=0x0;
112 Float_t distance = 99999999.;
113 //printf("%d %d \n",ix_max, iy_max);
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;
131 if (!foundsegmentindex) {
132 Warning("FindIndexFromPosition","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
134 return foundsegmentindex;
137 //____________________________________________________-
138 Float_t AliMUONSegmentationDetectionElement::GetAnod(Float_t xhit) const
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;
146 //_________________________________________________
147 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
149 // Getting AliMUONSegmentIndex from ManuIndex
150 return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
152 //_________________________________________________
153 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
155 // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
156 if (fMapManuIndexIndex) return (AliMUONSegmentIndex*) fMapManuIndexIndex->GetValue(SegmentManuIndexName);
158 Warning("GetIndex","SegmentManuIndex %s out of DetectionElement Mapping %s",
159 SegmentManuIndexName,fDetectionElementType.Data());
163 //_________________________________________________
164 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex(Int_t padx, Int_t pady, Int_t cathode ) const
166 // Getting ManuIndex from Index
167 return GetManuIndex( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
169 //_________________________________________________
170 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
172 // Getting ManuIndex from manuname
173 if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
175 Warning("GetManuIndex","SegmentIndex %s out of Detection Element mapping %s",
176 SegmentIndexName,fDetectionElementType.Data());
180 //__________________________________________________
181 void AliMUONSegmentationDetectionElement::GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y )
183 x = GetPosition(ix,iy,cathode)->GetXlocal();
184 y = GetPosition(ix,iy,cathode)->GetYlocal();
186 //__________________________________________________
187 void AliMUONSegmentationDetectionElement::GetPadI(Float_t x, Float_t y, Int_t cathode, Int_t &padx, Int_t &pady)
190 AliMUONSegmentIndex * segmentindex = FindIndexFromPosition(x,y,cathode);
193 padx = segmentindex->GetPadX();
194 pady = segmentindex->GetPadX();
197 Warning("GetPadI","Not found Index for position x=%5.2f y=%5.2f \n",x,y);
200 //_________________________________________________
201 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
203 //Getting position from index
204 return GetPosition( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
206 //_________________________________________________
207 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
209 // Getting position from indexname
210 if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
212 Warning("GetPosition","SegmentIndex %s out of DetectionElement mapping %s",
213 SegmentIndexName, fDetectionElementType.Data());
217 //_________________________________________________
218 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
220 // Getting Index from position if position is a center pad position
221 return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
223 //_________________________________________________
224 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
226 // Getting index form positionname
227 if (fMapPositionIndex) return (AliMUONSegmentIndex*) fMapPositionIndex->GetValue(PositionName);
229 Warning("GetIndexFromPosition","SegmentPosition %s out of DetectionElement Mapping %s",
230 PositionName,fDetectionElementType.Data());
235 //_________________________________________________
236 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
238 // Getting AliMUONSegmentManuIndex objecto from manu index
239 if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
241 Warning("FindManuIndex","SegmentManuIndex %s out of DetectionElement mapping %s",
242 ManuIndexName,fDetectionElementType.Data());
247 //_________________________________________________
248 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
251 if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
253 Warning("FindIndex","SegmentIndex %s out of DetectionElement mapping %s",
254 IndexName,fDetectionElementType.Data());
258 //_________________________________________________
259 void AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
261 TString elementType(DetectionElementType);
262 fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
263 +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
264 fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
265 +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
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();
277 fListOfIndexes->Delete();
278 fListOfManuIndexes->Delete();
279 fListOfPositions->Delete();
280 fMapManuIndexIndex->Clear();
281 fMapIndexManuIndex->Clear();
282 fMapIndexPosition->Clear();
283 fMapPositionIndex->Clear();
288 Info("ReadingSegmentationMappingFile","%s", fSegmentationMappingFileBending.Data());
289 ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
292 Info("Init","Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data());
293 ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
296 //_______________________________________________________________
297 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
299 ifstream in( infile, ios::in);
301 Error("ReadingSegmentationMappingFile", "File not found.");
304 Int_t id, ix, iy, idmanu, idchannel;
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);
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);;
314 //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
315 //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
316 //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
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) );