1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONTrackerDataHistogrammer.h"
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"
33 #include <TObjArray.h>
37 ///\class AliMUONTrackerDataHistogrammer
39 /// Class to generate histograms from AliMUONVTrackerData
40 /// (and AliMUONVPainter) objects
42 /// \author Laurent Aphecetche, Subatech
46 ClassImp(AliMUONTrackerDataHistogrammer)
49 //_____________________________________________________________________________
50 AliMUONTrackerDataHistogrammer::AliMUONTrackerDataHistogrammer(const AliMUONVTrackerData& data,
55 fExternalDim(externalDim),
56 fInternalDim(internalDim)
61 //_____________________________________________________________________________
62 AliMUONTrackerDataHistogrammer::~AliMUONTrackerDataHistogrammer()
67 //_____________________________________________________________________________
69 AliMUONTrackerDataHistogrammer::Add(TH1& h, const AliMUONSparseHisto& sh) const
71 /// Add sparse histo content to histogram.
73 Double_t entries(h.GetEntries());
75 for ( Int_t i = 0; i < sh.GetNbins(); ++i )
77 Int_t count = sh.GetBinContent(i);
79 h.Fill(sh.GetBinCenter(i),count);
84 h.SetEntries(entries);
86 if (sh.HasUnderflow()) h.SetBinContent(0,1);
87 if (sh.HasOverflow()) h.SetBinContent(h.GetNbinsX()+1,1);
90 //_____________________________________________________________________________
92 AliMUONTrackerDataHistogrammer::AddBusPatchHisto(TH1& h, Int_t busPatchId) const
94 /// Add data from one bus patch to the histogram
96 if ( fData.HasBusPatch(busPatchId ) )
98 AliMpBusPatch* busPatch = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
99 for ( Int_t i = 0; i < busPatch->GetNofManus(); ++i )
101 Int_t manuId = busPatch->GetManuId(i);
102 AddManuHisto(h,busPatch->GetDEId(),manuId);
106 //_____________________________________________________________________________
108 AliMUONTrackerDataHistogrammer::AddDEHisto(TH1& h, Int_t detElemId) const
110 /// Add data from one detection element to the histogram
112 if ( fData.HasDetectionElement(detElemId) )
114 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
115 for ( Int_t i = 0; i < de->GetNofBusPatches(); ++ i )
117 Int_t busPatchId = de->GetBusPatchId(i);
118 AddBusPatchHisto(h,busPatchId);
123 //_____________________________________________________________________________
125 AliMUONTrackerDataHistogrammer::AddManuHisto(TH1& h, Int_t detElemId, Int_t manuId) const
127 /// Add data from a given manu to histogram
129 if ( fData.HasManu(detElemId,manuId) )
131 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
133 if ( fData.HasChannel(detElemId,manuId,i) )
135 if ( IsInternalMode() )
137 h.Fill(fData.Channel(detElemId,manuId,i,fInternalDim));
141 AliMUONSparseHisto* sh = fData.GetChannelSparseHisto(detElemId,manuId,i);
153 //_____________________________________________________________________________
155 AliMUONTrackerDataHistogrammer::CreateChannelHisto(Int_t detElemId,
157 Int_t manuChannel) const
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...
163 if ( fData.HasChannel(detElemId, manuId, manuChannel) && fData.IsHistogrammed(fExternalDim) )
165 AliMUONSparseHisto* sh = fData.GetChannelSparseHisto(detElemId,manuId,manuChannel);
169 Int_t nbins((1<<sh->Nbits()));
171 fData.HistogramRange(xmin,xmax);
173 TH1* h = CreateHisto(Form("DE%04dMANU%04dCH%02d",detElemId,manuId,manuChannel),
185 //_____________________________________________________________________________
187 AliMUONTrackerDataHistogrammer::CreateHisto(const char* name,
192 /// Create a single histogram
198 h = new TH1F(name,name,nbins,xmin,xmax);
199 h->SetDirectory(gROOT);
203 AliError(Form("Cannot create histo for name=%s nbins=%d xmin=%e xmax=%e",name,nbins,xmin,xmax));
208 //_____________________________________________________________________________
210 AliMUONTrackerDataHistogrammer::CreateHisto(const AliMUONVPainter& painter,
214 /// Create an histogram, from given dim of given data,
215 /// for all the channels handled by painter
217 AliMUONPainterGroup* group = painter.Master()->PlotterGroup();
219 if ( !group ) return 0x0; // no data to histogram in this painter
221 AliMUONVTrackerData* data = group->Data();
223 if ( externalDim >= data->ExternalDimension() )
225 AliErrorClass(Form("externalDim %d is out of bounds",externalDim));
229 if ( internalDim >= data->NumberOfDimensions() )
231 AliErrorClass(Form("internalDim %d is out of bounds",internalDim));
235 if ( internalDim < 0 && externalDim < 0 )
237 AliErrorClass("Both internal and external dim are < 0 !!!");
241 AliMUONTrackerDataHistogrammer tdh(*data,externalDim,internalDim);
245 painter.FillManuList(manuArray);
248 TIter next(&manuArray);
250 TString basename(Form("%s-%s",painter.PathName().Data(),painter.Attributes().GetName()));
252 Int_t nbins((1<<12));
256 if ( !tdh.IsInternalMode() )
258 data->HistogramRange(xmin,xmax);
263 ext = data->ExternalDimensionName(externalDim).Data();
267 tdh.GetDataRange(manuArray,xmin,xmax);
268 ext = data->DimensionName(internalDim).Data();
272 TString name(Form("%s-%s",basename.Data(),ext.Data()));
274 TH1* histo = tdh.CreateHisto(name.Data(),nbins,xmin,xmax);
278 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
280 TH1* h = tdh.CreateManuHisto(mid->DetElemId(),mid->ManuId(),nbins,xmin,xmax);
290 AliErrorClass(Form("Could not create histo for painter %s external dim %d internal dim %d",
291 painter.PathName().Data(),externalDim,internalDim));
297 //_____________________________________________________________________________
299 AliMUONTrackerDataHistogrammer::CreateManuHisto(Int_t detElemId, Int_t manuId,
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...
310 if ( !fData.HasManu(detElemId,manuId) ) return 0x0;
312 if ( ( fExternalDim >= 0 && fData.IsHistogrammed(fExternalDim) ) ||
313 ( fInternalDim >= 0 && fInternalDim < fData.NumberOfDimensions() ) )
315 h = CreateHisto(Form("DE%04dMANU%04d",detElemId,manuId),
317 if ( h ) AddManuHisto(*h,detElemId,manuId);
323 //_____________________________________________________________________________
325 AliMUONTrackerDataHistogrammer::GetDataRange(const TObjArray& manuArray,
326 Double_t& xmin, Double_t& xmax) const
328 /// Get data range (in case of InternalMode() only) spanned by the manus in
334 if (!IsInternalMode())
336 AliError("Cannot use this method for external mode !");
340 TIter next(&manuArray);
342 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
344 Int_t detElemId = mid->DetElemId();
345 Int_t manuId = mid->ManuId();
347 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
349 if ( fData.HasChannel(detElemId,manuId,i) )
351 Double_t value = fData.Channel(detElemId,manuId,i,fInternalDim);
353 if ( ! TMath::Finite(value) )
355 AliError(Form("Got a NaN for DE %d manu %d ch %d",detElemId,manuId,i));
359 xmin = TMath::Min(xmin,value);
360 xmax = TMath::Max(xmax,value);