Only one data source is supposed to be running at a time, so disable the run button...
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerDataHistogrammer.cxx
CommitLineData
10eb3d17 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 "AliMUONTrackerDataHistogrammer.h"
19
49419555 20#include "AliLog.h"
10eb3d17 21#include "AliMUONPainterGroup.h"
22#include "AliMUONSparseHisto.h"
23#include "AliMUONVPainter.h"
24#include "AliMUONVTrackerData.h"
25#include "AliMpBusPatch.h"
26#include "AliMpConstants.h"
27#include "AliMpDDLStore.h"
28#include "AliMpDEIterator.h"
29#include "AliMpDetElement.h"
30#include "AliMpManuUID.h"
49419555 31#include <TClass.h>
10eb3d17 32#include <TH1.h>
33#include <TObjArray.h>
49419555 34#include <TROOT.h>
1c4173b3 35#include <TMath.h>
10eb3d17 36
37///\class AliMUONTrackerDataHistogrammer
38///
39/// Class to generate histograms from AliMUONVTrackerData
40/// (and AliMUONVPainter) objects
41///
42/// \author Laurent Aphecetche, Subatech
43///
44
45///\cond CLASSIMP
46ClassImp(AliMUONTrackerDataHistogrammer)
47///\endcond CLASSIMP
48
49//_____________________________________________________________________________
50AliMUONTrackerDataHistogrammer::AliMUONTrackerDataHistogrammer(const AliMUONVTrackerData& data,
49419555 51 Int_t externalDim,
52 Int_t internalDim)
10eb3d17 53: TObject(),
54fData(data),
49419555 55fExternalDim(externalDim),
56fInternalDim(internalDim)
10eb3d17 57{
58 /// ctor
59}
60
61//_____________________________________________________________________________
62AliMUONTrackerDataHistogrammer::~AliMUONTrackerDataHistogrammer()
63{
64 /// dtor
65}
66
67//_____________________________________________________________________________
68void
69AliMUONTrackerDataHistogrammer::Add(TH1& h, const AliMUONSparseHisto& sh) const
70{
71 /// Add sparse histo content to histogram.
72
73 Double_t entries(h.GetEntries());
74
75 for ( Int_t i = 0; i < sh.GetNbins(); ++i )
76 {
77 Int_t count = sh.GetBinContent(i);
78
79 h.Fill(sh.GetBinCenter(i),count);
80
81 entries += count;
82 }
83
84 h.SetEntries(entries);
85
86 if (sh.HasUnderflow()) h.SetBinContent(0,1);
87 if (sh.HasOverflow()) h.SetBinContent(h.GetNbinsX()+1,1);
88}
89
90//_____________________________________________________________________________
91void
92AliMUONTrackerDataHistogrammer::AddBusPatchHisto(TH1& h, Int_t busPatchId) const
93{
94 /// Add data from one bus patch to the histogram
95
96 if ( fData.HasBusPatch(busPatchId ) )
97 {
98 AliMpBusPatch* busPatch = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
99 for ( Int_t i = 0; i < busPatch->GetNofManus(); ++i )
100 {
101 Int_t manuId = busPatch->GetManuId(i);
102 AddManuHisto(h,busPatch->GetDEId(),manuId);
103 }
104 }
105}
106//_____________________________________________________________________________
107void
108AliMUONTrackerDataHistogrammer::AddDEHisto(TH1& h, Int_t detElemId) const
109{
110 /// Add data from one detection element to the histogram
111
112 if ( fData.HasDetectionElement(detElemId) )
113 {
114 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
115 for ( Int_t i = 0; i < de->GetNofBusPatches(); ++ i )
116 {
117 Int_t busPatchId = de->GetBusPatchId(i);
118 AddBusPatchHisto(h,busPatchId);
119 }
120 }
121}
122
123//_____________________________________________________________________________
124void
125AliMUONTrackerDataHistogrammer::AddManuHisto(TH1& h, Int_t detElemId, Int_t manuId) const
126{
127 /// Add data from a given manu to histogram
128
129 if ( fData.HasManu(detElemId,manuId) )
130 {
131 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
132 {
133 if ( fData.HasChannel(detElemId,manuId,i) )
134 {
49419555 135 if ( IsInternalMode() )
136 {
137 h.Fill(fData.Channel(detElemId,manuId,i,fInternalDim));
138 }
139 else
140 {
141 AliMUONSparseHisto* sh = fData.GetChannelSparseHisto(detElemId,manuId,i);
10eb3d17 142
49419555 143 if ( sh )
144 {
145 Add(h,*sh);
146 }
10eb3d17 147 }
148 }
149 }
150 }
151}
152
10eb3d17 153//_____________________________________________________________________________
154TH1*
49419555 155AliMUONTrackerDataHistogrammer::CreateChannelHisto(Int_t detElemId,
156 Int_t manuId,
10eb3d17 157 Int_t manuChannel) const
158{
159 /// Create histogram of a given channel. Note that in order
160 /// to keep memory footprint as low as possible, you should delete
161 /// the returned pointer as soon as possible...
162
49419555 163 if ( fData.HasChannel(detElemId, manuId, manuChannel) && fData.IsHistogrammed(fExternalDim) )
10eb3d17 164 {
165 AliMUONSparseHisto* sh = fData.GetChannelSparseHisto(detElemId,manuId,manuChannel);
166
167 if ( sh )
168 {
49419555 169 Int_t nbins((1<<sh->Nbits()));
170 Double_t xmin,xmax;
171 fData.HistogramRange(xmin,xmax);
172
173 TH1* h = CreateHisto(Form("DE%04dMANU%04dCH%02d",detElemId,manuId,manuChannel),
174 nbins,xmin,xmax);
10eb3d17 175 if (h )
176 {
177 Add(*h,*sh);
178 }
179 return h;
180 }
181 }
182 return 0x0;
183}
184
185//_____________________________________________________________________________
186TH1*
49419555 187AliMUONTrackerDataHistogrammer::CreateHisto(const char* name,
188 Int_t nbins,
189 Double_t xmin,
190 Double_t xmax) const
10eb3d17 191{
49419555 192 /// Create a single histogram
10eb3d17 193
49419555 194 TH1* h(0);
10eb3d17 195
49419555 196 if ( xmin < xmax )
10eb3d17 197 {
49419555 198 h = new TH1F(name,name,nbins,xmin,xmax);
199 h->SetDirectory(gROOT);
10eb3d17 200 }
1c4173b3 201 else
202 {
203 AliError(Form("Cannot create histo for name=%s nbins=%d xmin=%e xmax=%e",name,nbins,xmin,xmax));
204 }
10eb3d17 205 return h;
206}
207
208//_____________________________________________________________________________
209TH1*
49419555 210AliMUONTrackerDataHistogrammer::CreateHisto(const AliMUONVPainter& painter,
1c4173b3 211 Int_t externalDim,
212 Int_t internalDim)
10eb3d17 213{
214 /// Create an histogram, from given dim of given data,
215 /// for all the channels handled by painter
216
217 AliMUONPainterGroup* group = painter.Master()->PlotterGroup();
218
219 if ( !group ) return 0x0; // no data to histogram in this painter
220
221 AliMUONVTrackerData* data = group->Data();
10eb3d17 222
49419555 223 if ( externalDim >= data->ExternalDimension() )
224 {
225 AliErrorClass(Form("externalDim %d is out of bounds",externalDim));
226 return 0x0;
227 }
228
229 if ( internalDim >= data->NumberOfDimensions() )
230 {
231 AliErrorClass(Form("internalDim %d is out of bounds",internalDim));
232 return 0x0;
233 }
234
235 if ( internalDim < 0 && externalDim < 0 )
236 {
237 AliErrorClass("Both internal and external dim are < 0 !!!");
238 return 0x0;
239 }
240
241 AliMUONTrackerDataHistogrammer tdh(*data,externalDim,internalDim);
10eb3d17 242
243 TObjArray manuArray;
244
245 painter.FillManuList(manuArray);
49419555 246
10eb3d17 247 AliMpManuUID* mid;
248 TIter next(&manuArray);
49419555 249
250 TString basename(Form("%s-%s",painter.PathName().Data(),painter.Attributes().GetName()));
251 TString ext;
252 Int_t nbins((1<<12));
253 Double_t xmin(0.0);
254 Double_t xmax(0.0);
10eb3d17 255
49419555 256 if ( !tdh.IsInternalMode() )
257 {
258 data->HistogramRange(xmin,xmax);
259
260 xmin -= 0.5;
261 xmax -= 0.5;
262
263 ext = data->ExternalDimensionName(externalDim).Data();
264 }
265 else
266 {
267 tdh.GetDataRange(manuArray,xmin,xmax);
268 ext = data->DimensionName(internalDim).Data();
269 nbins = 100;
270 }
10eb3d17 271
49419555 272 TString name(Form("%s-%s",basename.Data(),ext.Data()));
273
274 TH1* histo = tdh.CreateHisto(name.Data(),nbins,xmin,xmax);
275
276 if ( histo )
10eb3d17 277 {
49419555 278 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
10eb3d17 279 {
49419555 280 TH1* h = tdh.CreateManuHisto(mid->DetElemId(),mid->ManuId(),nbins,xmin,xmax);
281 if ( h )
282 {
283 histo->Add(h);
284 }
285 delete h;
10eb3d17 286 }
49419555 287 }
288 else
289 {
290 AliErrorClass(Form("Could not create histo for painter %s external dim %d internal dim %d",
291 painter.PathName().Data(),externalDim,internalDim));
10eb3d17 292 }
293
294 return histo;
295}
296
297//_____________________________________________________________________________
298TH1*
49419555 299AliMUONTrackerDataHistogrammer::CreateManuHisto(Int_t detElemId, Int_t manuId,
300 Int_t nbins,
301 Double_t xmin,
302 Double_t xmax) const
10eb3d17 303{
49419555 304 /// Create histogram of a given manu. Note that in order
305 /// to keep memory footprint as low as possible, you should delete
306 /// the returned pointer as soon as possible...
10eb3d17 307
308 TH1* h(0x0);
309
49419555 310 if ( !fData.HasManu(detElemId,manuId) ) return 0x0;
311
312 if ( ( fExternalDim >= 0 && fData.IsHistogrammed(fExternalDim) ) ||
313 ( fInternalDim >= 0 && fInternalDim < fData.NumberOfDimensions() ) )
10eb3d17 314 {
49419555 315 h = CreateHisto(Form("DE%04dMANU%04d",detElemId,manuId),
316 nbins,xmin,xmax);
317 if ( h ) AddManuHisto(*h,detElemId,manuId);
10eb3d17 318 }
49419555 319
10eb3d17 320 return h;
321}
322
10eb3d17 323//_____________________________________________________________________________
49419555 324void
325AliMUONTrackerDataHistogrammer::GetDataRange(const TObjArray& manuArray,
326 Double_t& xmin, Double_t& xmax) const
10eb3d17 327{
49419555 328 /// Get data range (in case of InternalMode() only) spanned by the manus in
329 /// manuArray
10eb3d17 330
49419555 331 xmin = FLT_MAX;
332 xmax = -FLT_MAX;
10eb3d17 333
49419555 334 if (!IsInternalMode())
10eb3d17 335 {
49419555 336 AliError("Cannot use this method for external mode !");
10eb3d17 337 }
49419555 338
339 AliMpManuUID* mid;
340 TIter next(&manuArray);
10eb3d17 341
49419555 342 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
343 {
344 Int_t detElemId = mid->DetElemId();
345 Int_t manuId = mid->ManuId();
346
347 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
348 {
349 if ( fData.HasChannel(detElemId,manuId,i) )
350 {
351 Double_t value = fData.Channel(detElemId,manuId,i,fInternalDim);
1c4173b3 352
353 if ( ! TMath::Finite(value) )
354 {
355 AliError(Form("Got a NaN for DE %d manu %d ch %d",detElemId,manuId,i));
356 }
357 else
358 {
359 xmin = TMath::Min(xmin,value);
360 xmax = TMath::Max(xmax,value);
361 }
49419555 362 }
363 }
364 }
365
10eb3d17 366}
367