]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSegmentationDetectionElement.cxx
Initialize arrays in constructor (Ivana)
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentationDetectionElement.cxx
CommitLineData
74f8c8e3 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
8fe7187d 32#include <stdlib.h>
74f8c8e3 33#include <Riostream.h>
9d936539 34#include <stdlib.h>
74f8c8e3 35
36#include "TClonesArray.h"
37#include "TMap.h"
6b74910d 38#include "TMath.h"
74f8c8e3 39
40#include "AliMUONSegmentationDetectionElement.h"
41#include "AliMUONSegmentManuIndex.h"
42#include "AliMUONSegmentPosition.h"
43#include "AliMUONSegmentIndex.h"
8c343c7c 44#include "AliLog.h"
74f8c8e3 45
74f8c8e3 46//___________________________________________
47ClassImp(AliMUONSegmentationDetectionElement)
48
49//static data member
50const TString AliMUONSegmentationDetectionElement::fgkDefaultTop =getenv("ALICE_ROOT") ;
51const TString AliMUONSegmentationDetectionElement::fgkStationDir = "/MUON/mapping/data/station";
52const TString AliMUONSegmentationDetectionElement::fgkBendingDir= "/bending_plane";
53const TString AliMUONSegmentationDetectionElement::fgkNonBendingDir= "/non-bending_plane";
54const TString AliMUONSegmentationDetectionElement::fgkFileExt = ".map";
55const TString AliMUONSegmentationDetectionElement::fgkBendingExt = ".Bending";
56const TString AliMUONSegmentationDetectionElement::fgkNonBendingExt = ".NonBending";
57
58//___________________________________________
59
60AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
61{
212bb69d 62 //Default constructor
6b74910d 63 fWireD = 0.25; // wire pitch in cm
64 fWireX0 = 0.; // X0 position of the 1st wire
74f8c8e3 65 fMapManuIndexIndex= 0x0;
66 fMapIndexManuIndex= 0x0;
67 fMapIndexPosition= 0x0;
212bb69d 68 fMapPositionIndex=0X0;
74f8c8e3 69}
70
71
72// AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
73// {
74
75// fMapManuIndexIndex= 0x0;
76// fMapIndexManuIndex= 0x0;
77// fMapIndexPosition= 0x0;
74f8c8e3 78// }
79
80//________________________________________________
81AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs)
82{
83// Protected copy constructor
84
8c343c7c 85 AliFatal("Not implemented.");
74f8c8e3 86}
87//_________________________________________________
88AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
212bb69d 89 //Class destructor
74f8c8e3 90 fListOfIndexes->Delete();
91 fListOfManuIndexes->Delete();
92 fListOfPositions->Delete();
93 fMapManuIndexIndex->Clear();
94 fMapIndexManuIndex->Clear();
95 fMapIndexPosition->Clear();
212bb69d 96 fMapPositionIndex->Clear();
97}
98
6b74910d 99//__________________________________________________
100AliMUONSegmentIndex * 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 ) {
66657aef 124 // segmentindex->Print();
6b74910d 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) {
8c343c7c 135 AliWarning(Form("Not found Index for position x=%5.2f y=%5.2f \n",x,y));
6b74910d 136 }
137 return foundsegmentindex;
138}
139
140//____________________________________________________-
141Float_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}
212bb69d 149//_________________________________________________
150AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex(Int_t manu, Int_t channel) const
151{
152 // Getting AliMUONSegmentIndex from ManuIndex
153 return GetIndex( AliMUONSegmentManuIndex::Name(manu, channel).Data() ) ;
74f8c8e3 154}
155//_________________________________________________
212bb69d 156AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName) const
74f8c8e3 157{
212bb69d 158 // Getting AliMUONSegmentIndex from name of AliMUONSegmentManuIndex
74f8c8e3 159 if (fMapManuIndexIndex) return (AliMUONSegmentIndex*) fMapManuIndexIndex->GetValue(SegmentManuIndexName);
160 else {
8c343c7c 161 AliWarning(Form("SegmentManuIndex %s out of DetectionElement Mapping %s",
162 SegmentManuIndexName,fDetectionElementType.Data()));
74f8c8e3 163 return 0x0;
164 }
165}
74f8c8e3 166//_________________________________________________
212bb69d 167AliMUONSegmentManuIndex * 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//_________________________________________________
173AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName) const
74f8c8e3 174{
212bb69d 175 // Getting ManuIndex from manuname
74f8c8e3 176 if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
177 else {
8c343c7c 178 AliWarning(Form("SegmentIndex %s out of Detection Element mapping %s",
179 SegmentIndexName,fDetectionElementType.Data()));
74f8c8e3 180 return 0x0;
181 }
182}
6b74910d 183//__________________________________________________
184void 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//__________________________________________________
190void 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();
66657aef 197 pady = segmentindex->GetPadY();
6b74910d 198 }
199 else {
8c343c7c 200 AliWarning(Form("Not found Index for position x=%5.2f y=%5.2f \n",x,y));
6b74910d 201 }
202}
74f8c8e3 203//_________________________________________________
212bb69d 204AliMUONSegmentPosition * 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//_________________________________________________
210AliMUONSegmentPosition * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName) const
74f8c8e3 211{
212bb69d 212 // Getting position from indexname
74f8c8e3 213 if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
214 else {
8c343c7c 215 AliWarning(Form("SegmentIndex %s out of DetectionElement mapping %s",
216 SegmentIndexName, fDetectionElementType.Data()));
74f8c8e3 217 return 0x0;
218 }
219}
212bb69d 220//_________________________________________________
221AliMUONSegmentIndex * 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
6b74910d 224 return GetIndexFromPosition( AliMUONSegmentPosition::Name(x, y, cathode).Data() );
212bb69d 225}
226//_________________________________________________
227AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndexFromPosition( const char * PositionName) const
228{
229 // Getting index form positionname
230 if (fMapPositionIndex) return (AliMUONSegmentIndex*) fMapPositionIndex->GetValue(PositionName);
231 else {
8c343c7c 232 AliWarning(Form("SegmentPosition %s out of DetectionElement Mapping %s",
233 PositionName,fDetectionElementType.Data()));
212bb69d 234 return 0x0;
235 }
236}
74f8c8e3 237
238//_________________________________________________
212bb69d 239AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex( const char* ManuIndexName)const
74f8c8e3 240{
212bb69d 241 // Getting AliMUONSegmentManuIndex objecto from manu index
74f8c8e3 242 if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
243 else {
8c343c7c 244 AliWarning(Form("SegmentManuIndex %s out of DetectionElement mapping %s",
245 ManuIndexName,fDetectionElementType.Data()));
74f8c8e3 246 return 0x0;
247 }
248}
249
250//_________________________________________________
212bb69d 251AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName) const
74f8c8e3 252{
212bb69d 253 // Getting
254 if (fMapIndexPosition) return (AliMUONSegmentIndex *) fMapIndexPosition->FindObject(IndexName);
74f8c8e3 255 else {
8c343c7c 256 AliWarning(Form("SegmentIndex %s out of DetectionElement mapping %s",
257 IndexName,fDetectionElementType.Data()));
74f8c8e3 258 return 0x0;
259 }
260}
212bb69d 261//_________________________________________________
74f8c8e3 262void AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
263{
212bb69d 264 TString elementType(DetectionElementType);
265 fSegmentationMappingFileBending = fgkDefaultTop+fgkStationDir+"345"
266 +fgkBendingDir+"/"+elementType+fgkBendingExt+fgkFileExt;
212bb69d 267 fSegmentationMappingFileNonBending = fgkDefaultTop+fgkStationDir+"345"
268 +fgkNonBendingDir+"/"+elementType+fgkNonBendingExt+fgkFileExt;
74f8c8e3 269
270 if (fMapManuIndexIndex==0x0) {
212bb69d 271 fListOfIndexes = new TObjArray(15000);
272 fListOfManuIndexes =new TObjArray(15000);
273 fListOfPositions =new TObjArray(15000);
74f8c8e3 274 fMapManuIndexIndex= new TMap();
275 fMapIndexManuIndex = new TMap();
276 fMapIndexPosition = new TMap();
212bb69d 277 fMapPositionIndex = new TMap();
74f8c8e3 278 }
279 else {
280 fListOfIndexes->Delete();
281 fListOfManuIndexes->Delete();
282 fListOfPositions->Delete();
283 fMapManuIndexIndex->Clear();
284 fMapIndexManuIndex->Clear();
285 fMapIndexPosition->Clear();
212bb69d 286 fMapPositionIndex->Clear();
74f8c8e3 287 }
74f8c8e3 288 Int_t icathode;
289 //Bendingplane
290 icathode=0;
8c343c7c 291 AliInfo(Form("%s", fSegmentationMappingFileBending.Data()));
212bb69d 292 ReadingSegmentationMappingFile(fSegmentationMappingFileBending ,icathode);
74f8c8e3 293 //NonBendingplane
294 icathode=1;
8c343c7c 295 AliInfo(Form("Reading mapping file is %s\n", fSegmentationMappingFileNonBending.Data()));
212bb69d 296 ReadingSegmentationMappingFile(fSegmentationMappingFileNonBending,icathode);
74f8c8e3 297
298}
299//_______________________________________________________________
300void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
301{
302 ifstream in( infile, ios::in);
303 if (!in) {
8c343c7c 304 AliError("File not found.");
74f8c8e3 305 }
306 else {
307 Int_t id, ix, iy, idmanu, idchannel;
308 Float_t x, y;
6b74910d 309 do {
74f8c8e3 310 in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
6b74910d 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);
74f8c8e3 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
6b74910d 317 //( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
318 //( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
319 //( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
74f8c8e3 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));
6b74910d 324 fMapPositionIndex->Add( fListOfPositions->At(id), fListOfIndexes->At(id) );
325 }
326 while ( !in.eof());
74f8c8e3 327 }
328 in.close();
329}