]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONManuPainter.cxx
First big commit of the mchview program and its accompanying library,
[u/mrichter/AliRoot.git] / MUON / AliMUONManuPainter.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 "AliMUONManuPainter.h"
19
20 #include "AliMUONManuPadPainter.h"
21 #include "AliMUONPainterContour.h"
22 #include "AliMUONPainterHelper.h"
23 #include "AliMUONVCalibParam.h"
24 #include "AliMUONVDigit.h"
25 #include "AliMUONVTrackerData.h"
26 #include "AliMpDEManager.h"
27 #include "AliMpMotifPosition.h"
28 #include "AliMpMotifType.h"
29 #include "AliMpSlat.h"
30 #include "AliMpStationType.h"
31 #include "AliMpVMotif.h"
32 #include "AliMpVPadIterator.h"
33 #include "AliLog.h"
34 #include <TArrayI.h>
35 #include <float.h>
36
37 ///\class AliMUONManuPainter
38 ///
39 /// Implementation of AliMUONVPainter for one manu (not the pads, only the manu
40 /// itself).
41 ///
42 ///\author Laurent Aphecetche, Subatech
43
44 ///\cond CLASSIMP
45 ClassImp(AliMUONManuPainter)
46 ///\endcond
47
48 //_____________________________________________________________________________
49 AliMUONManuPainter::AliMUONManuPainter()
50 : AliMUONVPainter(),
51 fDetElemId(-1),
52 fManuId(-1)
53 {
54   /// ctor
55 }
56
57 //_____________________________________________________________________________
58 AliMUONManuPainter::AliMUONManuPainter(const AliMUONAttPainter& att,
59                                        Int_t detElemId,
60                                        Int_t manuId)
61 : AliMUONVPainter("MANU"),
62   fDetElemId(detElemId),
63   fManuId(manuId)
64 {
65     /// ctor
66     
67     SetAttributes(att);
68     
69     AliMUONPainterHelper* h = AliMUONPainterHelper::Instance();
70     
71     SetID(detElemId,manuId);
72     SetName(h->ManuName(manuId));
73     SetPathName(h->ManuPathName(detElemId,manuId));
74     
75     AliMpMotifPosition* mp = h->GetMotifPosition(detElemId,manuId);
76     
77     if (!mp)
78     {
79       AliFatal(Form("Could not get manuId %04d from DE %04d",manuId,detElemId));
80     }
81     
82     Double_t x,y,z;
83     
84     AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
85
86     if ( stationType == AliMp::kStation345 ) 
87     {
88       const AliMpSlat* slat = AliMUONPainterHelper::Instance()->GetSlat(detElemId,manuId);
89
90       h->Local2Global(fDetElemId,
91                                                    mp->Position().X() -slat->Position().X(),
92                                                    mp->Position().Y() -slat->Position().Y(),
93                                                    0,
94                                                    x,y,z);
95     }
96     else if ( stationType != AliMp::kStationTrigger ) 
97     {
98       h->Local2Global(fDetElemId,
99                                                      mp->Position().X(),
100                                                      mp->Position().Y(),
101                                                      0,
102                                                      x,y,z);      
103     }
104     else
105     {
106       AliError("Hu ho. Not supposed to be used for trigger !");
107       Invalidate();
108       return;
109     }
110     
111     AliMUONPainterContour* contour = h->GetContour(ContourName());
112
113     if (!contour)
114     {
115       contour = h->GenerateManuContour(fDetElemId,
116                                                                       fManuId,
117                                                                       Attributes(),
118                                                                       ContourName());
119     }
120     SetContour(contour);
121     
122     Add(new AliMUONManuPadPainter(*this,fDetElemId,fManuId));
123 }
124
125 //_____________________________________________________________________________
126 AliMUONManuPainter::AliMUONManuPainter(const AliMUONManuPainter& rhs)
127 : AliMUONVPainter(rhs), fDetElemId(-1), fManuId(-1)
128 {
129   /// copy ctor
130   rhs.Copy(*this);
131 }
132
133 //_____________________________________________________________________________
134 AliMUONManuPainter&
135 AliMUONManuPainter::operator=(const AliMUONManuPainter& rhs)
136 {
137   /// assignment operator
138   if ( this != &rhs ) 
139   {
140     rhs.Copy(*this);
141   }
142   return *this;
143 }
144
145 //_____________________________________________________________________________
146 AliMUONManuPainter::~AliMUONManuPainter()
147 {
148   /// dtor
149 }
150
151 //_____________________________________________________________________________
152 void 
153 AliMUONManuPainter::ComputeDataRange(const AliMUONVTrackerData& data, Int_t dataIndex, 
154                                      Double_t& dataMin, Double_t& dataMax) const
155 {
156   /// Compute data range spanned by this manu
157   dataMin = dataMax = data.Manu(fDetElemId, fManuId, dataIndex);
158 }
159
160
161 //_____________________________________________________________________________
162 void
163 AliMUONManuPainter::Copy(TObject& object) const
164 {
165   /// copyy this to object
166   AliMUONVPainter::Copy((AliMUONVPainter&)(object));
167   ((AliMUONManuPainter&)(object)).fDetElemId = fDetElemId;
168   ((AliMUONManuPainter&)(object)).fManuId = fManuId;
169 }
170
171 //_____________________________________________________________________________
172 TString
173 AliMUONManuPainter::Describe(const AliMUONVTrackerData& data, Int_t dataIndex,
174                              Double_t, Double_t)
175 {
176   /// Describe data at this manu
177   
178   if (!data.HasManu(fDetElemId,fManuId)) return "";
179   
180   Double_t value = data.Manu(fDetElemId,fManuId,dataIndex);
181   
182   return AliMUONPainterHelper::Instance()->FormatValue(data.DimensionName(dataIndex).Data(),value);
183 }
184
185 //_____________________________________________________________________________
186 void
187 AliMUONManuPainter::PaintArea(const AliMUONVTrackerData& data, Int_t dataIndex,
188                               Double_t min, Double_t max)
189 {
190   /// Paint area of this manu according to data
191   
192   if (!data.HasManu(fDetElemId,fManuId)) return;
193
194   Double_t value = data.Manu(fDetElemId,fManuId,dataIndex);
195   
196   if ( value >= AliMUONVCalibParam::InvalidFloatValue() ) return;
197   
198   Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,min,max);
199   
200   Contour()->PaintArea(color);
201 }
202
203 //_____________________________________________________________________________
204 AliMUONAttPainter
205 AliMUONManuPainter::Validate(const AliMUONAttPainter& attributes) const
206 {
207   /// Normalize the attributes
208   
209   /// check that cathode and plane are up-to-date, and that they are legal
210   
211   AliMUONAttPainter norm(attributes);
212
213   norm.SetValid(kFALSE);
214   
215   if ( norm.IsCathodeDefined() ) 
216   {
217     if ( norm.IsCathode0() != Attributes().IsCathode0() ) return norm;
218   }
219   
220   if ( norm.IsPlaneDefined() ) 
221   {
222     if ( norm.IsBendingPlane() != Attributes().IsBendingPlane() ) return norm;
223   }
224   
225   norm.SetValid(kTRUE);
226   
227   if ( norm.IsCathodeDefined() && !norm.IsPlaneDefined() ) 
228   {
229     // derive plane from cathode
230     
231     AliMp::CathodType cathode = ( norm.IsCathode0() ? AliMp::kCath0 : AliMp::kCath1 ) ;
232
233     AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(fDetElemId,cathode);
234     
235     Bool_t bending = ( planeType == AliMp::kBendingPlane );
236     
237     norm.SetPlane(bending,!bending);    
238   }
239   else if ( norm.IsPlaneDefined() && !norm.IsCathodeDefined() )
240   {
241     // derive cathode from plane
242
243     AliMp::PlaneType planeType = ( norm.IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
244
245     AliMp::CathodType cathode = AliMpDEManager::GetCathod(fDetElemId,planeType);
246           
247     Bool_t cath0 = ( cathode == AliMp::kCath0 );
248     
249     norm.SetCathode(cath0,!cath0);    
250   }
251   else if ( norm.IsPlaneDefined() && norm.IsCathodeDefined() ) 
252   {
253     // check that cathode and plane matches
254     
255     AliMp::CathodType cathode = ( norm.IsCathode0() ? AliMp::kCath0 : AliMp::kCath1 ) ;
256
257     AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(fDetElemId,cathode);
258     
259     Bool_t bending = ( planeType == AliMp::kBendingPlane );
260     
261     if ( bending != norm.IsBendingPlane() ) 
262     {
263       norm.SetValid(kFALSE);
264     }
265   }
266   
267   return norm;
268 }
269
270