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>
36 ///\class AliMUONTrackerDataHistogrammer
38 /// Class to generate histograms from AliMUONVTrackerData
39 /// (and AliMUONVPainter) objects
41 /// \author Laurent Aphecetche, Subatech
45 ClassImp(AliMUONTrackerDataHistogrammer)
48 //_____________________________________________________________________________
49 AliMUONTrackerDataHistogrammer::AliMUONTrackerDataHistogrammer(const AliMUONVTrackerData& data,
54 fExternalDim(externalDim),
55 fInternalDim(internalDim)
60 //_____________________________________________________________________________
61 AliMUONTrackerDataHistogrammer::~AliMUONTrackerDataHistogrammer()
66 //_____________________________________________________________________________
68 AliMUONTrackerDataHistogrammer::Add(TH1& h, const AliMUONSparseHisto& sh) const
70 /// Add sparse histo content to histogram.
72 Double_t entries(h.GetEntries());
74 for ( Int_t i = 0; i < sh.GetNbins(); ++i )
76 Int_t count = sh.GetBinContent(i);
78 h.Fill(sh.GetBinCenter(i),count);
83 h.SetEntries(entries);
85 if (sh.HasUnderflow()) h.SetBinContent(0,1);
86 if (sh.HasOverflow()) h.SetBinContent(h.GetNbinsX()+1,1);
89 //_____________________________________________________________________________
91 AliMUONTrackerDataHistogrammer::AddBusPatchHisto(TH1& h, Int_t busPatchId) const
93 /// Add data from one bus patch to the histogram
95 if ( fData.HasBusPatch(busPatchId ) )
97 AliMpBusPatch* busPatch = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
98 for ( Int_t i = 0; i < busPatch->GetNofManus(); ++i )
100 Int_t manuId = busPatch->GetManuId(i);
101 AddManuHisto(h,busPatch->GetDEId(),manuId);
105 //_____________________________________________________________________________
107 AliMUONTrackerDataHistogrammer::AddDEHisto(TH1& h, Int_t detElemId) const
109 /// Add data from one detection element to the histogram
111 if ( fData.HasDetectionElement(detElemId) )
113 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
114 for ( Int_t i = 0; i < de->GetNofBusPatches(); ++ i )
116 Int_t busPatchId = de->GetBusPatchId(i);
117 AddBusPatchHisto(h,busPatchId);
122 //_____________________________________________________________________________
124 AliMUONTrackerDataHistogrammer::AddManuHisto(TH1& h, Int_t detElemId, Int_t manuId) const
126 /// Add data from a given manu to histogram
128 if ( fData.HasManu(detElemId,manuId) )
130 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
132 if ( fData.HasChannel(detElemId,manuId,i) )
134 if ( IsInternalMode() )
136 h.Fill(fData.Channel(detElemId,manuId,i,fInternalDim));
140 AliMUONSparseHisto* sh = fData.GetChannelSparseHisto(detElemId,manuId,i);
152 //_____________________________________________________________________________
154 AliMUONTrackerDataHistogrammer::CreateChannelHisto(Int_t detElemId,
156 Int_t manuChannel) const
158 /// Create histogram of a given channel. Note that in order
159 /// to keep memory footprint as low as possible, you should delete
160 /// the returned pointer as soon as possible...
162 if ( fData.HasChannel(detElemId, manuId, manuChannel) && fData.IsHistogrammed(fExternalDim) )
164 AliMUONSparseHisto* sh = fData.GetChannelSparseHisto(detElemId,manuId,manuChannel);
168 Int_t nbins((1<<sh->Nbits()));
170 fData.HistogramRange(xmin,xmax);
172 TH1* h = CreateHisto(Form("DE%04dMANU%04dCH%02d",detElemId,manuId,manuChannel),
184 //_____________________________________________________________________________
186 AliMUONTrackerDataHistogrammer::CreateHisto(const char* name,
191 /// Create a single histogram
197 h = new TH1F(name,name,nbins,xmin,xmax);
198 h->SetDirectory(gROOT);
203 //_____________________________________________________________________________
205 AliMUONTrackerDataHistogrammer::CreateHisto(const AliMUONVPainter& painter,
209 /// Create an histogram, from given dim of given data,
210 /// for all the channels handled by painter
212 AliMUONPainterGroup* group = painter.Master()->PlotterGroup();
214 if ( !group ) return 0x0; // no data to histogram in this painter
216 AliMUONVTrackerData* data = group->Data();
218 if ( externalDim >= data->ExternalDimension() )
220 AliErrorClass(Form("externalDim %d is out of bounds",externalDim));
224 if ( internalDim >= data->NumberOfDimensions() )
226 AliErrorClass(Form("internalDim %d is out of bounds",internalDim));
230 if ( internalDim < 0 && externalDim < 0 )
232 AliErrorClass("Both internal and external dim are < 0 !!!");
236 AliMUONTrackerDataHistogrammer tdh(*data,externalDim,internalDim);
240 painter.FillManuList(manuArray);
243 TIter next(&manuArray);
245 TString basename(Form("%s-%s",painter.PathName().Data(),painter.Attributes().GetName()));
247 Int_t nbins((1<<12));
251 if ( !tdh.IsInternalMode() )
253 data->HistogramRange(xmin,xmax);
258 ext = data->ExternalDimensionName(externalDim).Data();
262 tdh.GetDataRange(manuArray,xmin,xmax);
263 ext = data->DimensionName(internalDim).Data();
267 TString name(Form("%s-%s",basename.Data(),ext.Data()));
269 TH1* histo = tdh.CreateHisto(name.Data(),nbins,xmin,xmax);
273 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
275 TH1* h = tdh.CreateManuHisto(mid->DetElemId(),mid->ManuId(),nbins,xmin,xmax);
285 AliErrorClass(Form("Could not create histo for painter %s external dim %d internal dim %d",
286 painter.PathName().Data(),externalDim,internalDim));
292 //_____________________________________________________________________________
294 AliMUONTrackerDataHistogrammer::CreateManuHisto(Int_t detElemId, Int_t manuId,
299 /// Create histogram of a given manu. Note that in order
300 /// to keep memory footprint as low as possible, you should delete
301 /// the returned pointer as soon as possible...
305 if ( !fData.HasManu(detElemId,manuId) ) return 0x0;
307 if ( ( fExternalDim >= 0 && fData.IsHistogrammed(fExternalDim) ) ||
308 ( fInternalDim >= 0 && fInternalDim < fData.NumberOfDimensions() ) )
310 h = CreateHisto(Form("DE%04dMANU%04d",detElemId,manuId),
312 if ( h ) AddManuHisto(*h,detElemId,manuId);
318 //_____________________________________________________________________________
320 AliMUONTrackerDataHistogrammer::GetDataRange(const TObjArray& manuArray,
321 Double_t& xmin, Double_t& xmax) const
323 /// Get data range (in case of InternalMode() only) spanned by the manus in
329 if (!IsInternalMode())
331 AliError("Cannot use this method for external mode !");
335 TIter next(&manuArray);
337 while ( ( mid = static_cast<AliMpManuUID*>(next()) ) )
339 Int_t detElemId = mid->DetElemId();
340 Int_t manuId = mid->ManuId();
342 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
344 if ( fData.HasChannel(detElemId,manuId,i) )
346 Double_t value = fData.Channel(detElemId,manuId,i,fInternalDim);
347 xmin = TMath::Min(xmin,value);
348 xmax = TMath::Max(xmax,value);