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"
46 //___________________________________________
47 ClassImp(AliMUONSegmentationDetectionElement)
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";
58 //___________________________________________
60 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
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;
72 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
75 // fMapManuIndexIndex= 0x0;
76 // fMapIndexManuIndex= 0x0;
77 // fMapIndexPosition= 0x0;
80 //________________________________________________
81 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs)
83 // Protected copy constructor
85 AliFatal("Not implemented.");
87 //_________________________________________________
88 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
90 fListOfIndexes->Delete();
91 fListOfManuIndexes->Delete();
92 fListOfPositions->Delete();
93 fMapManuIndexIndex->Clear();
94 fMapIndexManuIndex->Clear();
95 fMapIndexPosition->Clear();
96 fMapPositionIndex->Clear();
99 //__________________________________________________
100 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndexFromPosition(Float_t x, Float_t y, Int_t cathode)
102 // Finding x_wire corresponding to x
103 Float_t x_wire = GetAnod(x);
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
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());
110 AliMUONSegmentIndex * segmentindex =0x0;
111 AliMUONSegmentIndex * foundsegmentindex =0x0;
112 AliMUONSegmentPosition * segmentposition=0x0;
115 Float_t distance = 99999999.;
116 //printf("%d %d \n",ix_max, iy_max);
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;
134 if (!foundsegmentindex) {
135 AliWarning(Form("Not found Index for position x=%5.2f y=%5.2f \n",x,y));
137 return foundsegmentindex;
140 //____________________________________________________-
141 Float_t AliMUONSegmentationDetectionElement::GetAnod(Float_t xhit) const
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;
149 //_________________________________________________
150 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
152 // Getting AliMUONSegmentIndex from ManuIndex
153 return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
155 //_________________________________________________
156 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
158 // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
159 if (fMapManuIndexIndex) return (AliMUONSegmentIndex*) fMapManuIndexIndex->GetValue(SegmentManuIndexName);
161 AliWarning(Form("SegmentManuIndex %s out of DetectionElement Mapping %s",
162 SegmentManuIndexName,fDetectionElementType.Data()));
166 //_________________________________________________
167 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex(Int_t padx, Int_t pady, Int_t cathode ) const
169 // Getting ManuIndex from Index
170 return GetManuIndex( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
172 //_________________________________________________
173 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
175 // Getting ManuIndex from manuname
176 if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
178 AliWarning(Form("SegmentIndex %s out of Detection Element mapping %s",
179 SegmentIndexName,fDetectionElementType.Data()));
183 //__________________________________________________
184 void AliMUONSegmentationDetectionElement::GetPadC(Int_t ix, Int_t iy, Int_t cathode, Float_t &x, Float_t &y )
186 x = GetPosition(ix,iy,cathode)->GetXlocal();
187 y = GetPosition(ix,iy,cathode)->GetYlocal();
189 //__________________________________________________
190 void AliMUONSegmentationDetectionElement::GetPadI(Float_t x, Float_t y, Int_t cathode, Int_t &padx, Int_t &pady)
193 AliMUONSegmentIndex * segmentindex = FindIndexFromPosition(x,y,cathode);
196 padx = segmentindex->GetPadX();
197 pady = segmentindex->GetPadY();
200 AliWarning(Form("Not found Index for position x=%5.2f y=%5.2f \n",x,y));
203 //_________________________________________________
204 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition(Int_t padx, Int_t pady, Int_t cathode ) const
206 //Getting position from index
207 return GetPosition( AliMUONSegmentIndex::Name(padx, pady, cathode).Data() );
209 //_________________________________________________
210 AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
212 // Getting position from indexname
213 if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
215 AliWarning(Form("SegmentIndex %s out of DetectionElement mapping %s",
216 SegmentIndexName, fDetectionElementType.Data()));
220 //_________________________________________________
221 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition(Float_t x, Float_t y, Int_t cathode) const
223 // Getting Index from position if position is a center pad position
224 return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
226 //_________________________________________________
227 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
229 // Getting index form positionname
230 if (fMapPositionIndex) return (AliMUONSegmentIndex*) fMapPositionIndex->GetValue(PositionName);
232 AliWarning(Form("SegmentPosition %s out of DetectionElement Mapping %s",
233 PositionName,fDetectionElementType.Data()));
238 //_________________________________________________
239 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
241 // Getting AliMUONSegmentManuIndex objecto from manu index
242 if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
244 AliWarning(Form("SegmentManuIndex %s out of DetectionElement mapping %s",
245 ManuIndexName,fDetectionElementType.Data()));
250 //_________________________________________________
251 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
254 if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
256 AliWarning(Form("SegmentIndex %s out of DetectionElement mapping %s",
257 IndexName,fDetectionElementType.Data()));
261 //_________________________________________________
262 void AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
264 TString elementType(DetectionElementType);
265 fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
266 +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
267 fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
268 +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
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();
280 fListOfIndexes->Delete();
281 fListOfManuIndexes->Delete();
282 fListOfPositions->Delete();
283 fMapManuIndexIndex->Clear();
284 fMapIndexManuIndex->Clear();
285 fMapIndexPosition->Clear();
286 fMapPositionIndex->Clear();
291 AliInfo(Form("%s", fSegmentationMappingFileBending.Data()));
292 ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
295 AliInfo(Form("Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data()));
296 ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
299 //_______________________________________________________________
300 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
302 ifstream in( infile, ios::in);
304 AliError("File not found.");
307 Int_t id, ix, iy, idmanu, idchannel;
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);
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);;
317 //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
318 //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
319 //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
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) );