]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackerDataHistogrammer.cxx
Make 2013 the default OCDB
[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(),
72dae9ff 54fkData(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
72dae9ff 96 if ( fkData.HasBusPatch(busPatchId ) )
10eb3d17 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
72dae9ff 112 if ( fkData.HasDetectionElement(detElemId) )
10eb3d17 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
72dae9ff 129 if ( fkData.HasManu(detElemId,manuId) )
10eb3d17 130 {
72dae9ff 131 if ( fkData.IsChannelLevelEnabled() )
10eb3d17 132 {
0edb62c4 133 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
10eb3d17 134 {
72dae9ff 135 if ( fkData.HasChannel(detElemId,manuId,i) )
49419555 136 {
0edb62c4 137 if ( IsInternalMode() )
138 {
72dae9ff 139 h.Fill(fkData.Channel(detElemId,manuId,i,fInternalDim));
0edb62c4 140 }
141 else
142 {
72dae9ff 143 AliMUONSparseHisto* sh = fkData.GetChannelSparseHisto(detElemId,manuId,i,fExternalDim);
0edb62c4 144
145 if ( sh )
146 {
147 Add(h,*sh);
148 }
149 }
49419555 150 }
0edb62c4 151 }
152 }
153 else
154 {
155 if ( IsInternalMode() )
156 {
72dae9ff 157 h.Fill(fkData.Manu(detElemId,manuId,fInternalDim));
0edb62c4 158 }
159 else
160 {
72dae9ff 161 AliMUONSparseHisto* sh = fkData.GetManuSparseHisto(detElemId,manuId,fExternalDim);
0edb62c4 162 if (sh)
49419555 163 {
0edb62c4 164 Add(h,*sh);
10eb3d17 165 }
166 }
167 }
168 }
169}
170
10eb3d17 171//_____________________________________________________________________________
172TH1*
49419555 173AliMUONTrackerDataHistogrammer::CreateChannelHisto(Int_t detElemId,
174 Int_t manuId,
10eb3d17 175 Int_t manuChannel) const
176{
177 /// Create histogram of a given channel. Note that in order
178 /// to keep memory footprint as low as possible, you should delete
179 /// the returned pointer as soon as possible...
180
72dae9ff 181 if ( fkData.HasChannel(detElemId, manuId, manuChannel) && fkData.IsHistogrammed(fExternalDim) )
10eb3d17 182 {
72dae9ff 183 AliMUONSparseHisto* sh = fkData.GetChannelSparseHisto(detElemId,manuId,manuChannel);
10eb3d17 184
185 if ( sh )
186 {
49419555 187 Int_t nbins((1<<sh->Nbits()));
188 Double_t xmin,xmax;
72dae9ff 189 fkData.HistogramRange(xmin,xmax);
49419555 190
191 TH1* h = CreateHisto(Form("DE%04dMANU%04dCH%02d",detElemId,manuId,manuChannel),
192 nbins,xmin,xmax);
10eb3d17 193 if (h )
194 {
195 Add(*h,*sh);
196 }
197 return h;
198 }
199 }
200 return 0x0;
201}
202
203//_____________________________________________________________________________
204TH1*
49419555 205AliMUONTrackerDataHistogrammer::CreateHisto(const char* name,
206 Int_t nbins,
207 Double_t xmin,
208 Double_t xmax) const
10eb3d17 209{
49419555 210 /// Create a single histogram
10eb3d17 211
49419555 212 TH1* h(0);
10eb3d17 213
49419555 214 if ( xmin < xmax )
10eb3d17 215 {
49419555 216 h = new TH1F(name,name,nbins,xmin,xmax);
217 h->SetDirectory(gROOT);
10eb3d17 218 }
1c4173b3 219 else
220 {
221 AliError(Form("Cannot create histo for name=%s nbins=%d xmin=%e xmax=%e",name,nbins,xmin,xmax));
222 }
10eb3d17 223 return h;
224}
225
226//_____________________________________________________________________________
227TH1*
49419555 228AliMUONTrackerDataHistogrammer::CreateHisto(const AliMUONVPainter& painter,
1c4173b3 229 Int_t externalDim,
230 Int_t internalDim)
10eb3d17 231{
232 /// Create an histogram, from given dim of given data,
233 /// for all the channels handled by painter
234
235 AliMUONPainterGroup* group = painter.Master()->PlotterGroup();
236
237 if ( !group ) return 0x0; // no data to histogram in this painter
238
239 AliMUONVTrackerData* data = group->Data();
10eb3d17 240
49419555 241 if ( externalDim >= data->ExternalDimension() )
242 {
243 AliErrorClass(Form("externalDim %d is out of bounds",externalDim));
244 return 0x0;
245 }
246
247 if ( internalDim >= data->NumberOfDimensions() )
248 {
249 AliErrorClass(Form("internalDim %d is out of bounds",internalDim));
250 return 0x0;
251 }
252
253 if ( internalDim < 0 && externalDim < 0 )
254 {
255 AliErrorClass("Both internal and external dim are < 0 !!!");
256 return 0x0;
257 }
258
259 AliMUONTrackerDataHistogrammer tdh(*data,externalDim,internalDim);
10eb3d17 260
261 TObjArray manuArray;
262
263 painter.FillManuList(manuArray);
49419555 264
10eb3d17 265 AliMpManuUID* mid;
266 TIter next(&manuArray);
49419555 267
268 TString basename(Form("%s-%s",painter.PathName().Data(),painter.Attributes().GetName()));
269 TString ext;
270 Int_t nbins((1<<12));
271 Double_t xmin(0.0);
272 Double_t xmax(0.0);
10eb3d17 273
49419555 274 if ( !tdh.IsInternalMode() )
275 {
276 data->HistogramRange(xmin,xmax);
277
278 xmin -= 0.5;
279 xmax -= 0.5;
280
281 ext = data->ExternalDimensionName(externalDim).Data();
282 }
283 else
284 {
285 tdh.GetDataRange(manuArray,xmin,xmax);
286 ext = data->DimensionName(internalDim).Data();
287 nbins = 100;
288 }
10eb3d17 289
49419555 290 TString name(Form("%s-%s",basename.Data(),ext.Data()));
291
292 TH1* histo = tdh.CreateHisto(name.Data(),nbins,xmin,xmax);
293
294 if ( histo )
10eb3d17 295 {
49419555 296 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
10eb3d17 297 {
49419555 298 TH1* h = tdh.CreateManuHisto(mid->DetElemId(),mid->ManuId(),nbins,xmin,xmax);
299 if ( h )
300 {
301 histo->Add(h);
302 }
303 delete h;
10eb3d17 304 }
49419555 305 }
306 else
307 {
0edb62c4 308 AliErrorClass(Form("Could not create histo for painter %s (%p) data %s (%p) external dim %d internal dim %d",
309 painter.PathName().Data(),&painter,
310 data->GetName(),data,externalDim,internalDim));
10eb3d17 311 }
312
0edb62c4 313 if (histo) histo->SetDirectory(gROOT);
314
10eb3d17 315 return histo;
316}
317
318//_____________________________________________________________________________
319TH1*
49419555 320AliMUONTrackerDataHistogrammer::CreateManuHisto(Int_t detElemId, Int_t manuId,
321 Int_t nbins,
322 Double_t xmin,
323 Double_t xmax) const
10eb3d17 324{
49419555 325 /// Create histogram of a given manu. Note that in order
326 /// to keep memory footprint as low as possible, you should delete
327 /// the returned pointer as soon as possible...
10eb3d17 328
329 TH1* h(0x0);
330
72dae9ff 331 if ( !fkData.HasManu(detElemId,manuId) ) return 0x0;
49419555 332
72dae9ff 333 if ( ( fExternalDim >= 0 && fkData.IsHistogrammed(fExternalDim) ) ||
334 ( fInternalDim >= 0 && fInternalDim < fkData.NumberOfDimensions() ) )
10eb3d17 335 {
49419555 336 h = CreateHisto(Form("DE%04dMANU%04d",detElemId,manuId),
337 nbins,xmin,xmax);
338 if ( h ) AddManuHisto(*h,detElemId,manuId);
10eb3d17 339 }
49419555 340
10eb3d17 341 return h;
342}
343
10eb3d17 344//_____________________________________________________________________________
49419555 345void
346AliMUONTrackerDataHistogrammer::GetDataRange(const TObjArray& manuArray,
347 Double_t& xmin, Double_t& xmax) const
10eb3d17 348{
49419555 349 /// Get data range (in case of InternalMode() only) spanned by the manus in
350 /// manuArray
10eb3d17 351
49419555 352 xmin = FLT_MAX;
353 xmax = -FLT_MAX;
10eb3d17 354
49419555 355 if (!IsInternalMode())
10eb3d17 356 {
49419555 357 AliError("Cannot use this method for external mode !");
10eb3d17 358 }
49419555 359
360 AliMpManuUID* mid;
361 TIter next(&manuArray);
10eb3d17 362
49419555 363 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
364 {
365 Int_t detElemId = mid->DetElemId();
366 Int_t manuId = mid->ManuId();
367
368 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
369 {
72dae9ff 370 if ( fkData.HasChannel(detElemId,manuId,i) )
49419555 371 {
72dae9ff 372 Double_t value = fkData.Channel(detElemId,manuId,i,fInternalDim);
1c4173b3 373
374 if ( ! TMath::Finite(value) )
375 {
376 AliError(Form("Got a NaN for DE %d manu %d ch %d",detElemId,manuId,i));
377 }
378 else
379 {
380 xmin = TMath::Min(xmin,value);
381 xmax = TMath::Max(xmax,value);
382 }
49419555 383 }
384 }
385 }
386
10eb3d17 387}
388