bug fixed
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterPadStore.cxx
CommitLineData
0145e89a 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#include "AliMUONPainterPadStore.h"
19
20#include "AliMUONCalibParamND.h"
21#include "AliMUON2DMap.h"
22#include "AliMUONVStore.h"
23#include "AliMUONVDigit.h"
24#include "AliLog.h"
25#include <Riostream.h>
26#include <TArrayI.h>
27#include <TVector2.h>
28
29///\class AliMUONPainterPadStore
30///
31/// Container for pads
32///
33///\author Laurent Aphecetche, Subatech
34
35///\cond CLASSIMP
36ClassImp(AliMUONPainterPadStore)
37///\endcond
38
39//_____________________________________________________________________________
40AliMUONPainterPadStore::AliMUONPainterPadStore() : TObject(),
41 fPadStore(new AliMUON2DMap(kTRUE))
42{
43 /// ctor
44}
45
46//_____________________________________________________________________________
47AliMUONPainterPadStore::~AliMUONPainterPadStore()
48{
49 /// dtor
50 delete fPadStore;
51}
52
53//_____________________________________________________________________________
54Int_t
55AliMUONPainterPadStore::FindPadID(const TArrayI& pads, Double_t x, Double_t y) const
56{
57 /// Find, in array of pads, the one which contains (x,y). Returns -1 if not
58 /// found
59
60 for ( Int_t i = 0; i < pads.GetSize(); ++i )
61 {
62 Int_t id = pads.At(i);
63
64 TVector2 position;
65 TVector2 dimensions;
66
67 GetPadGeometry(id,position,dimensions);
68
69 TVector2 bl(position-dimensions);
70 TVector2 ur(position+dimensions);
71 if ( bl.X() <= x && ur.X() >= x && bl.Y() <= y && ur.Y() >= y )
72 {
73 return id;
74 }
75 }
76 return -1;
77}
78
79
80//_____________________________________________________________________________
81AliMUONVCalibParam*
82AliMUONPainterPadStore::Get(Int_t detElemId, Int_t manuId) const
83{
84 /// Get the pad container for a given manu
85
86 AliMUONVCalibParam* param =
87 static_cast<AliMUONVCalibParam*>(fPadStore->FindObject(detElemId,manuId));
88
89 if (!param)
90 {
91 param = new AliMUONCalibParamND(4,64,detElemId,manuId,-1.0);
92 fPadStore->Add(param);
93 }
94
95 return param;
96}
97
98//_____________________________________________________________________________
99void
100AliMUONPainterPadStore::GetBoundaries(const TArrayI& pads,
101 Double_t& xmin,
102 Double_t& ymin,
103 Double_t& xmax,
104 Double_t& ymax) const
105{
106 /// Get the area covered by an array of pads
107
108 xmin=ymin=1E9;
109 xmax=ymax=-1E9;
110
111 for ( Int_t i = 0; i < pads.GetSize(); ++i )
112 {
113 Int_t id = pads.At(i);
114
115 TVector2 position;
116 TVector2 dimensions;
117
118 GetPadGeometry(id,position,dimensions);
119
120 TVector2 bl(position-dimensions);
121 TVector2 ur(position+dimensions);
122 xmin = TMath::Min(xmin,bl.X());
123 ymin = TMath::Min(ymin,bl.Y());
124 xmax = TMath::Max(xmax,ur.X());
125 ymax = TMath::Max(ymax,ur.Y());
126 }
127}
128
129//_____________________________________________________________________________
130void
131AliMUONPainterPadStore::GetPadGeometry(Int_t padId,
132 TVector2& position,
133 TVector2& dimensions) const
134{
135 /// Get the geomtry of one pad
136
137 if ( padId < 0 )
138 {
139 AliError(Form("padId is < 0 : %d",padId));
140 position.Set(0.0,0.0);
141 dimensions.Set(-1.0,-1.0);
142 return;
143 }
144
145 Int_t detElemId = AliMUONVDigit::DetElemId(padId);
146 Int_t manuId = AliMUONVDigit::ManuId(padId);
147 Int_t manuChannel = AliMUONVDigit::ManuChannel(padId);
148
149 AliMUONVCalibParam* param =
150 static_cast<AliMUONVCalibParam*>(fPadStore->FindObject(detElemId,manuId));
151
152 if (!param)
153 {
154 AliError(Form("Could not find object DE %d manu %d",detElemId,manuId));
155 position.Set(0.0,0.0);
156 dimensions.Set(-1.0,-1.0);
157 return;
158 }
159
160 position.Set(param->ValueAsDouble(manuChannel,0),
161 param->ValueAsDouble(manuChannel,1));
162
163 dimensions.Set(param->ValueAsDouble(manuChannel,2),
164 param->ValueAsDouble(manuChannel,3));
165
166 AliDebug(3,Form("DE %4d Manu %4d Channel %2d Pos %e %e Dim %e %e",
167 detElemId,manuId,manuChannel,
168 position.X(),position.Y(),
169 dimensions.X(),dimensions.Y()));
170}
171
172//_____________________________________________________________________________
173Int_t
174AliMUONPainterPadStore::GetSize() const
175{
176 /// Get the number of pads we handle
177
178 TIter next(fPadStore->CreateIterator());
179 AliMUONVCalibParam* param;
180 Int_t n(0);
181
182 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
183 {
184 for ( Int_t i = 0; i < param->Size(); ++i )
185 {
186 if ( param->ValueAsDouble(i,2) >= 0 && param->ValueAsDouble(i,3) >= 0 )
187 {
188 ++n;
189 }
190 }
191 }
192
193 return n;
194}
195
196//_____________________________________________________________________________
197void
198AliMUONPainterPadStore::PrintPads(const TArrayI& pads) const
199{
200 /// Printout
201 cout << "n=" << pads.GetSize() << endl;
202
203 for ( Int_t i = 0; i < pads.GetSize(); ++i )
204 {
205 Int_t id = pads.At(i);
206 TVector2 position, dimensions;
207 GetPadGeometry(id,position,dimensions);
208 cout << Form("i %4d DE %4d ManuID %4d ManuChannel %2d (X,Y)=(%7.3f,%7.3f)"
209 " (DX,DY)=(%7.3f,%7.3f)",
210 i,
211 AliMUONVDigit::DetElemId(id),
212 AliMUONVDigit::ManuId(id),
213 AliMUONVDigit::ManuChannel(id),
214 position.X(),position.Y(),
215 dimensions.X(),dimensions.Y()) << endl;
216 }
217}
218