Upgrades in SDD event display macro
[u/mrichter/AliRoot.git] / FMD / AliFMDPedestalDA.cxx
CommitLineData
3bd993ba 1/**************************************************************************
2 * Copyright(c) 2004, 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/** @file AliFMDPedestalDA.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Mon Mar 10 09:46:05 2008
19 @brief Derived class for the pedestal detector algorithm.
20*/
21//
e9c06036 22// This class implements the virtual functions of the AliFMDBaseDA
23// class. The most important of these functions, FillChannels(..) and
24// Analyse(...) collect and analyse the data of each channel. The
25// resulting pedestal and noise values are written to a comma
26// separated values (csv) file on the go. The csv files produced in
27// this way are the basic input to the AliFMDPreprocessor.
3bd993ba 28//
29
30#include "AliFMDPedestalDA.h"
31#include "iostream"
32#include "fstream"
33#include "AliLog.h"
34#include "TF1.h"
f7f0b643 35#include "TObject.h"
93519ec4 36#include "TMath.h"
3bd993ba 37
38//_____________________________________________________________________
39ClassImp(AliFMDPedestalDA)
40
41//_____________________________________________________________________
f7f0b643 42AliFMDPedestalDA::AliFMDPedestalDA() : AliFMDBaseDA(),
f14ede67 43 fCurrentChannel(1),
f7f0b643 44 fPedSummary("PedestalSummary","pedestals",51200,0,51200),
45 fNoiseSummary("NoiseSummary","noise",51200,0,51200)
3bd993ba 46{
47 fOutputFile.open("peds.csv");
48
49}
50
51//_____________________________________________________________________
52AliFMDPedestalDA::AliFMDPedestalDA(const AliFMDPedestalDA & pedDA) :
f7f0b643 53 AliFMDBaseDA(pedDA),
f14ede67 54 fCurrentChannel(1),
f7f0b643 55 fPedSummary("PedestalSummary","pedestals",51200,0,51200),
56 fNoiseSummary("NoiseSummary","noise",51200,0,51200)
3bd993ba 57{
58
59}
60
61//_____________________________________________________________________
e9c06036 62AliFMDPedestalDA::~AliFMDPedestalDA()
63{
3bd993ba 64}
65
66//_____________________________________________________________________
e9c06036 67void AliFMDPedestalDA::Init()
68{
3bd993ba 69 SetRequiredEvents(1000);
70}
71
72//_____________________________________________________________________
73void AliFMDPedestalDA::AddChannelContainer(TObjArray* sectorArray,
74 UShort_t det,
e9c06036 75 Char_t ring,
3bd993ba 76 UShort_t sec,
e9c06036 77 UShort_t strip)
78{
79#ifdef USE_SAMPLES
80 AliFMDParameters* pars = AliFMDParameters::Instance();
81 Int_t samples = pars->GetSampleRate(det, ring, sec, strip);
82 TObjArray* sampleArray = new TObjArray(samples);
83 for (size_t sample = 0; sample < samples; sample++) {
84 TH1S* hSample = new TH1S(Form("FMD%d%c[%02d,03%d]_%d",
85 det,ring,sec,strip,sample),
86 Form("FMD%d%c[%02d,%03%d]_%d",
87 det,ring,sec,strip),
88 1024,-.5,1023.5);
89 hSample->SetXTitle("ADC");
90 hSample->SetYTitle("Events");
91 sampleArray->AddAt(hSample, sample);
92 }
93 sectorArray->AddAtAndExpand(sampleArray, strip);
94#else
3bd993ba 95 TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
96 Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
e9c06036 97 1024,-.5,1023.5);
3bd993ba 98
99 hChannel->SetDirectory(0);
100 sectorArray->AddAtAndExpand(hChannel,strip);
e9c06036 101#endif
102
3bd993ba 103}
104
105//_____________________________________________________________________
e9c06036 106void AliFMDPedestalDA::FillChannels(AliFMDDigit* digit)
107{
3bd993ba 108 UShort_t det = digit->Detector();
109 Char_t ring = digit->Ring();
110 UShort_t sec = digit->Sector();
111 UShort_t strip = digit->Strip();
e9c06036 112
113#ifdef USE_SAMPLES
114 AliFMDParameters* pars = AliFMDParameters::Instance();
115 Int_t samples = pars->GetSampleRate(det, ring, sec, strip);
116 for (size_t sample = 0; sample < samples; sample++) {
117 TH1S* hSample = GetChannel(det, ring, sec, strip, sample);
118 hSample->Fill(digit->Count(sample));
119 }
120#else
121 TH1S* hChannel = GetChannel(det, ring, sec, strip);
3bd993ba 122 hChannel->Fill(digit->Counts());
e9c06036 123#endif
3bd993ba 124}
125
126//_____________________________________________________________________
127void AliFMDPedestalDA::Analyse(UShort_t det,
e9c06036 128 Char_t ring,
3bd993ba 129 UShort_t sec,
f38b1653 130 UShort_t strip)
131{
3bd993ba 132
133 TH1S* hChannel = GetChannel(det, ring, sec, strip);
80fdb9f3 134 if(hChannel->GetEntries() == 0) {
e9c06036 135 // AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
136 // det,ring,sec,strip));
3bd993ba 137 return;
138 }
93519ec4 139
e9c06036 140 AliDebug(50, Form("Fitting FMD%d%c_%d_%d with %d entries",det,ring,sec,strip,
141 hChannel->GetEntries()));
93519ec4 142 TF1 fitFunc("fitFunc","gausn",0,300);
143 fitFunc.SetParameters(100,100,1);
144 hChannel->Fit("fitFunc","Q0+","",10,200);
3bd993ba 145
146 Float_t mean = hChannel->GetMean();
147 Float_t rms = hChannel->GetRMS();
148
93519ec4 149
150
151 hChannel->GetXaxis()->SetRangeUser(mean-5*rms,mean+5*rms);
3bd993ba 152
153 mean = hChannel->GetMean();
154 rms = hChannel->GetRMS();
155
e9c06036 156
93519ec4 157
158 Float_t chi2ndf = 0;
159 if(fitFunc.GetNDF())
160 chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
161
f7f0b643 162 fOutputFile << det << ','
163 << ring << ','
164 << sec << ','
165 << strip << ','
3bd993ba 166 << mean << ','
167 << rms << ','
93519ec4 168 << fitFunc.GetParameter(1) << ','
169 << fitFunc.GetParameter(2) << ','
3bd993ba 170 << chi2ndf <<"\n";
171
172 if(fSaveHistograms) {
e9c06036 173 gDirectory->cd(GetSectorPath(det, ring, sec, kTRUE));
174 TH1F* sumPed = dynamic_cast<TH1F*>(gDirectory->Get("Pedestals"));
175 TH1F* sumNoise = dynamic_cast<TH1F*>(gDirectory->Get("Noise"));
176 Int_t nStr = (ring == 'I' ? 512 : 256);
177 if (!sumPed) {
178 sumPed = new TH1F("Pedestals",
179 Form("Summary of pedestals in FMD%d%c[%02d]",
180 det, ring, sec),
181 nStr, -.5, nStr-.5);
182 sumPed->SetXTitle("Strip");
183 sumPed->SetYTitle("Pedestal [ADC]");
184 sumPed->SetDirectory(gDirectory);
185 }
186 if (!sumNoise) {
187 sumNoise = new TH1F("Noise",
188 Form("Summary of noise in FMD%d%c[%02d]",
189 det, ring, sec),
190 nStr, -.5, nStr-.5);
191 sumNoise->SetXTitle("Strip");
192 sumNoise->SetYTitle("Noise [ADC]");
f7f0b643 193
e9c06036 194 sumNoise->SetDirectory(gDirectory);
195 }
196 sumPed->SetBinContent(strip+1, mean);
197 sumPed->SetBinError(strip+1, rms);
198 sumNoise->SetBinContent(strip+1, rms);
f7f0b643 199
200 if(sumNoise->GetEntries() == nStr)
201 sumNoise->Write(sumNoise->GetName(),TObject::kOverwrite);
202 if(sumPed->GetEntries() == nStr)
203 sumPed->Write(sumPed->GetName(),TObject::kOverwrite);
204
205 fPedSummary.SetBinContent(fCurrentChannel,mean);
206 fNoiseSummary.SetBinContent(fCurrentChannel,rms);
207 fCurrentChannel++;
208
e9c06036 209 gDirectory->cd(GetStripPath(det, ring, sec, strip, kTRUE));
f7f0b643 210 hChannel->GetXaxis()->SetRange(1,1024);
211
3bd993ba 212 hChannel->Write();
e9c06036 213 }
93519ec4 214
3bd993ba 215}
216
217//_____________________________________________________________________
f7f0b643 218void AliFMDPedestalDA::Terminate(TFile* diagFile)
219{
220 diagFile->cd();
221
222 fPedSummary.Write();
223 fNoiseSummary.Write();
224
225}
226
227//_____________________________________________________________________
e9c06036 228void AliFMDPedestalDA::WriteHeaderToFile()
229{
80fdb9f3 230 AliFMDParameters* pars = AliFMDParameters::Instance();
231 fOutputFile.write(Form("# %s \n",pars->GetPedestalShuttleID()),13);
f7f0b643 232 fOutputFile.write("# Detector, "
233 "Ring, "
234 "Sector, "
e9c06036 235 "Strip, "
e9c06036 236 "Pedestal, "
237 "Noise, "
238 "Mu, "
239 "Sigma, "
f7f0b643 240 "Chi2/NDF \n", 71);
3bd993ba 241}
242
243//_____________________________________________________________________
e9c06036 244TH1S* AliFMDPedestalDA::GetChannel(UShort_t det,
245 Char_t ring,
246 UShort_t sec,
247 UShort_t strip)
248{
249 UShort_t iring = (ring == 'O' ? 0 : 1);
3bd993ba 250 TObjArray* detArray = static_cast<TObjArray*>(fDetectorArray.At(det));
e9c06036 251 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(iring));
3bd993ba 252 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
e9c06036 253#ifdef USE_SAMPLES
254 AliFMDParameters* pars = AliFMDParameters::Instance();
255 Int_t samples = pars->GetSampleRate(det, ring, sec, strip);
256 TObjArray* sampleArray = static_cast<TObjArray*>(secArray->At(strip));
257 TH1S* hSample = static_cast<TH1S*>(sampleArray->At(sample));
258 return hSample;
259#else
260 TH1S* hChannel = static_cast<TH1S*>(secArray->At(strip));
3bd993ba 261 return hChannel;
e9c06036 262#endif
3bd993ba 263}
93519ec4 264
3bd993ba 265//_____________________________________________________________________
266//
267//EOF
268//