d110706b89d46ce3858d10d2a5ed99a2df37f535
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentationDetectionElement.cxx
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
32 #include <Riostream.h>
33
34 #include "TClonesArray.h"
35 #include "TMap.h"
36
37 #include "AliMUONSegmentationDetectionElement.h"
38 #include "AliMUONSegmentManuIndex.h"
39 #include "AliMUONSegmentPosition.h"
40 #include "AliMUONSegmentIndex.h"
41
42
43 //___________________________________________
44 ClassImp(AliMUONSegmentationDetectionElement)
45
46 //static data member
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";
54
55 //___________________________________________
56
57 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement() : TObject()
58 {
59   fMapManuIndexIndex= 0x0;
60   fMapIndexManuIndex= 0x0;
61   fMapIndexPosition= 0x0;
62   fXlocalSegmentPositions= 0x0;
63   fYlocalSegmentPositions= 0x0;
64 }
65
66
67 // AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const char* ElementType)
68 // {
69   
70 //   fMapManuIndexIndex= 0x0;
71 //   fMapIndexManuIndex= 0x0;
72 //   fMapIndexPosition= 0x0;
73 //   fXlocalSegmentPositions= 0x0;
74 //   fYlocalSegmentPositions= 0x0;
75 // }
76
77 //________________________________________________
78 AliMUONSegmentationDetectionElement::AliMUONSegmentationDetectionElement(const AliMUONSegmentationDetectionElement& rhs): TObject(rhs) 
79 {
80 // Protected copy constructor
81
82   Fatal("AliMUONSegmentationDetectionElementModule", "Not implemented.");
83 }
84 //_________________________________________________
85 AliMUONSegmentationDetectionElement::~AliMUONSegmentationDetectionElement(){
86   fListOfIndexes->Delete();
87   fListOfManuIndexes->Delete();
88   fListOfPositions->Delete();
89   fMapManuIndexIndex->Clear();
90   fMapIndexManuIndex->Clear();
91   fMapIndexPosition->Clear();
92 }
93 //_________________________________________________
94 AliMUONSegmentIndex * AliMUONSegmentationDetectionElement::GetIndex( const char * SegmentManuIndexName)
95 {
96   if (fMapManuIndexIndex) return  (AliMUONSegmentIndex*)  fMapManuIndexIndex->GetValue(SegmentManuIndexName);
97   else {
98     Warning("GetIndex","SegmentManuIndex %s out of DetectionElement Mapping %s",
99             SegmentManuIndexName,fDetectionElementType.Data());
100     return 0x0;
101   }
102 }
103
104 //_________________________________________________
105 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::GetManuIndex( const char * SegmentIndexName)
106 {
107   if (fMapIndexManuIndex) return (AliMUONSegmentManuIndex*) fMapIndexManuIndex->GetValue(SegmentIndexName);
108   else {
109     Warning("GetManuIndex","SegmentIndex %s out of Detection Element mapping %s",
110             SegmentIndexName,fDetectionElementType.Data());
111     return 0x0;
112   }
113 }
114
115 //_________________________________________________
116 AliMUONSegmentPosition  * AliMUONSegmentationDetectionElement::GetPosition( const char * SegmentIndexName)
117 {
118   if (fMapIndexPosition) return (AliMUONSegmentPosition*) fMapIndexPosition->GetValue(SegmentIndexName);
119   else {
120     Warning("GetPosition","SegmentIndex %s out of DetectionElement mapping %s",
121             SegmentIndexName, fDetectionElementType.Data());
122     return 0x0;
123   }
124 }
125
126 //_________________________________________________
127 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindManuIndex(const char* ManuIndexName)
128 {
129   if (fMapManuIndexIndex) return (AliMUONSegmentManuIndex*) fMapManuIndexIndex->FindObject(ManuIndexName);
130   else  {
131     Warning("FindManuIndex","SegmentManuIndex %s out of DetectionElement mapping %s",
132             ManuIndexName,fDetectionElementType.Data());
133     return 0x0;
134   }
135 }
136
137 //_________________________________________________
138 AliMUONSegmentManuIndex * AliMUONSegmentationDetectionElement::FindIndex(const char* IndexName)
139 {
140   if (fMapIndexPosition) return (AliMUONSegmentManuIndex *) fMapIndexPosition->FindObject(IndexName);
141   else {
142     Warning("FindIndex","SegmentIndex %s out of DetectionElement mapping %s",
143             IndexName,fDetectionElementType.Data());
144     return 0x0;
145   }
146 }
147
148 //_________________________________________________
149 void    AliMUONSegmentationDetectionElement::Init(const char * DetectionElementType)
150 {
151   TString ElementType(DetectionElementType);
152   fSegmentationMappingFile_Bending = fgkDefaultTop+fgkStationDir+"345"
153     +fgkBendingDir+"/"+ElementType+fgkBendingExt+fgkFileExt;
154   printf("file is %s\n", fSegmentationMappingFile_Bending.Data());
155   fSegmentationMappingFile_NonBending = fgkDefaultTop+fgkStationDir+"345"
156     +fgkNonBendingDir+"/"+ElementType+fgkNonBendingExt+fgkFileExt;
157
158   if (fMapManuIndexIndex==0x0) { 
159     fListOfIndexes = new TObjArray(10000);
160     fListOfManuIndexes =new TObjArray(10000);
161     fListOfPositions =new TObjArray(10000);
162     fMapManuIndexIndex= new TMap();
163     fMapIndexManuIndex = new TMap();
164     fMapIndexPosition = new TMap();
165   }
166   else {
167     fListOfIndexes->Delete();
168     fListOfManuIndexes->Delete();
169     fListOfPositions->Delete();
170     fMapManuIndexIndex->Clear();
171     fMapIndexManuIndex->Clear();
172     fMapIndexPosition->Clear();
173   }
174
175
176
177   Int_t icathode;
178   //Bendingplane
179   icathode=0;
180   ReadingSegmentationMappingFile(fSegmentationMappingFile_Bending ,icathode);
181   //NonBendingplane
182   icathode=1;
183   ReadingSegmentationMappingFile(fSegmentationMappingFile_NonBending,icathode);
184   
185 }
186 //_______________________________________________________________
187 void AliMUONSegmentationDetectionElement::ReadingSegmentationMappingFile(TString infile, Int_t cathode)
188
189   ifstream in( infile,  ios::in);
190   if (!in) {
191     //    Error("ReadingSegmentationMappingFile", "File not found.");
192   }
193   else {
194     Int_t id, ix, iy, idmanu, idchannel;
195     Float_t x, y;
196     while ( !in.eof()) {
197       in >> id >> ix >> iy >> x >> y >> idmanu >> idchannel;
198       char name[10];
199       sprintf(name,"%d%d",ix,iy);
200       printf("%s id=%d ix=%d iy=%d x=%f y=%f idmanu=%d and idchannel=%d\n",name,id, ix, iy,  x, y,idmanu, idchannel);
201       
202       fListOfIndexes->AddAt(     new AliMUONSegmentIndex(id,ix,iy,cathode), id);
203       fListOfManuIndexes->AddAt( new AliMUONSegmentManuIndex(id,idmanu,0,idchannel), id);;
204       fListOfPositions->AddAt(   new AliMUONSegmentPosition(id, x, y,cathode), id);;
205
206       ( (AliMUONSegmentIndex* )fListOfIndexes->At(id))->Print();
207       ( (AliMUONSegmentManuIndex*)fListOfManuIndexes->At(id))->Print();
208       ( (AliMUONSegmentPosition*)fListOfPositions->At(id))->Print();
209      
210       fMapManuIndexIndex->Add( fListOfManuIndexes->At(id), fListOfIndexes->At(id));
211       fMapIndexManuIndex->Add( fListOfIndexes->At(id),     fListOfManuIndexes->At(id));
212       fMapIndexPosition->Add(  fListOfIndexes->At(id),     fListOfPositions->At(id));
213     } 
214   }
215   in.close();
216 }