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