Fixing compilation problem due to missing include file in Make*Table.C macros.
[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),
7bce699b 45 fNoiseSummary("NoiseSummary","noise",51200,0,51200),
46 fZSfileFMD1(),
47 fZSfileFMD2(),
48 fZSfileFMD3()
3bd993ba 49{
50 fOutputFile.open("peds.csv");
7bce699b 51 fZSfileFMD1.open("ddl3072.csv");
52 fZSfileFMD2.open("ddl3073.csv");
53 fZSfileFMD3.open("ddl3074.csv");
3bd993ba 54}
55
56//_____________________________________________________________________
57AliFMDPedestalDA::AliFMDPedestalDA(const AliFMDPedestalDA & pedDA) :
f7f0b643 58 AliFMDBaseDA(pedDA),
f14ede67 59 fCurrentChannel(1),
f7f0b643 60 fPedSummary("PedestalSummary","pedestals",51200,0,51200),
7bce699b 61 fNoiseSummary("NoiseSummary","noise",51200,0,51200),
62 fZSfileFMD1(),
63 fZSfileFMD2(),
64 fZSfileFMD3()
3bd993ba 65{
66
67}
68
69//_____________________________________________________________________
e9c06036 70AliFMDPedestalDA::~AliFMDPedestalDA()
71{
3bd993ba 72}
73
74//_____________________________________________________________________
e9c06036 75void AliFMDPedestalDA::Init()
76{
3bd993ba 77 SetRequiredEvents(1000);
15e37b0a 78
79
3bd993ba 80}
81
82//_____________________________________________________________________
83void AliFMDPedestalDA::AddChannelContainer(TObjArray* sectorArray,
84 UShort_t det,
e9c06036 85 Char_t ring,
3bd993ba 86 UShort_t sec,
e9c06036 87 UShort_t strip)
88{
e9c06036 89 AliFMDParameters* pars = AliFMDParameters::Instance();
7bce699b 90 UInt_t samples = pars->GetSampleRate(det, ring, sec, strip);
e9c06036 91 TObjArray* sampleArray = new TObjArray(samples);
7bce699b 92 sampleArray->SetOwner();
93 for (UInt_t sample = 0; sample < samples; sample++) {
e9c06036 94 TH1S* hSample = new TH1S(Form("FMD%d%c[%02d,03%d]_%d",
95 det,ring,sec,strip,sample),
96 Form("FMD%d%c[%02d,%03%d]_%d",
97 det,ring,sec,strip),
98 1024,-.5,1023.5);
99 hSample->SetXTitle("ADC");
100 hSample->SetYTitle("Events");
7bce699b 101 hSample->SetDirectory(0);
e9c06036 102 sampleArray->AddAt(hSample, sample);
103 }
104 sectorArray->AddAtAndExpand(sampleArray, strip);
3bd993ba 105
e9c06036 106
3bd993ba 107}
108
109//_____________________________________________________________________
e9c06036 110void AliFMDPedestalDA::FillChannels(AliFMDDigit* digit)
111{
3bd993ba 112 UShort_t det = digit->Detector();
113 Char_t ring = digit->Ring();
114 UShort_t sec = digit->Sector();
115 UShort_t strip = digit->Strip();
15e37b0a 116
e9c06036 117 AliFMDParameters* pars = AliFMDParameters::Instance();
7bce699b 118 UInt_t samples = pars->GetSampleRate(det, ring, sec, strip);
119 for (UInt_t sample = 0; sample < samples; sample++) {
e9c06036 120 TH1S* hSample = GetChannel(det, ring, sec, strip, sample);
121 hSample->Fill(digit->Count(sample));
122 }
7bce699b 123
3bd993ba 124}
125
126//_____________________________________________________________________
127void AliFMDPedestalDA::Analyse(UShort_t det,
e9c06036 128 Char_t ring,
3bd993ba 129 UShort_t sec,
7bce699b 130 UShort_t strip) {
3bd993ba 131
7bce699b 132 AliFMDParameters* pars = AliFMDParameters::Instance();
133 UInt_t samples = pars->GetSampleRate(det, ring, sec, strip);
134 for (UShort_t sample = 0; sample < samples; sample++) {
3bd993ba 135
7bce699b 136 TH1S* hChannel = GetChannel(det, ring, sec, strip,sample);
137 if(hChannel->GetEntries() == 0) {
138 //AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
139 // det,ring,sec,strip));
140 return;
e9c06036 141 }
f7f0b643 142
7bce699b 143 AliDebug(50, Form("Fitting FMD%d%c_%d_%d with %d entries",det,ring,sec,strip,
144 hChannel->GetEntries()));
145 TF1 fitFunc("fitFunc","gausn",0,300);
146 fitFunc.SetParameters(100,100,1);
147 hChannel->Fit("fitFunc","Q0+","",10,200);
148
149 Float_t mean = hChannel->GetMean();
150 Float_t rms = hChannel->GetRMS();
151
f7f0b643 152
f7f0b643 153
7bce699b 154 hChannel->GetXaxis()->SetRangeUser(mean-5*rms,mean+5*rms);
f7f0b643 155
7bce699b 156 mean = hChannel->GetMean();
157 rms = hChannel->GetRMS();
93519ec4 158
7bce699b 159
160 UShort_t ddl, board, altro, channel;
161 UShort_t timebin;
162
163 pars->Detector2Hardware(det,ring,sec,strip,sample,ddl,board,altro,channel,timebin);
164
165 switch(det) {
166 case 1:
167 fZSfileFMD1 << board << ',' << altro << ',' << channel << ',' << timebin << ','
168 << mean << ',' << rms << "\n"; break;
169 case 2:
170 fZSfileFMD2 << board << ',' << altro << ',' << channel << ',' << timebin << ','
171 << mean << ',' << rms << "\n"; break;
172 case 3:
173 fZSfileFMD3 << board << ',' << altro << ',' << channel << ',' << timebin << ','
174 << mean << ',' << rms << "\n"; break;
175 default:
176 AliWarning("Unknown sample!"); break;
177
178 }
179
180 Float_t chi2ndf = 0;
15e37b0a 181
182
7bce699b 183 if(fitFunc.GetNDF())
184 chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
185
15e37b0a 186 Int_t sampleToWrite = 2;
187
188 if(pars->GetSampleRate(det,ring,sec,strip)==2)
189 sampleToWrite = 1;
190
191 if(pars->GetSampleRate(det,ring,sec,strip)<2)
192 sampleToWrite = 0;
193
194 if(sample==sampleToWrite) {
7bce699b 195
196 fOutputFile << det << ','
197 << ring << ','
198 << sec << ','
199 << strip << ','
200 << mean << ','
201 << rms << ','
202 << fitFunc.GetParameter(1) << ','
203 << fitFunc.GetParameter(2) << ','
204 << chi2ndf <<"\n";
205
206 if(fSaveHistograms ) {
207 gDirectory->cd(GetSectorPath(det, ring, sec, kTRUE));
208 TH1F* sumPed = dynamic_cast<TH1F*>(gDirectory->Get("Pedestals"));
209 TH1F* sumNoise = dynamic_cast<TH1F*>(gDirectory->Get("Noise"));
210 Int_t nStr = (ring == 'I' ? 512 : 256);
211 if (!sumPed) {
212 sumPed = new TH1F("Pedestals",
213 Form("Summary of pedestals in FMD%d%c[%02d]",
214 det, ring, sec),
215 nStr, -.5, nStr-.5);
216 sumPed->SetXTitle("Strip");
217 sumPed->SetYTitle("Pedestal [ADC]");
218 sumPed->SetDirectory(gDirectory);
219 }
220 if (!sumNoise) {
221 sumNoise = new TH1F("Noise",
222 Form("Summary of noise in FMD%d%c[%02d]",
223 det, ring, sec),
224 nStr, -.5, nStr-.5);
225 sumNoise->SetXTitle("Strip");
226 sumNoise->SetYTitle("Noise [ADC]");
227
228 sumNoise->SetDirectory(gDirectory);
229 }
230 sumPed->SetBinContent(strip+1, mean);
231 sumPed->SetBinError(strip+1, rms);
232 sumNoise->SetBinContent(strip+1, rms);
233
234 if(sumNoise->GetEntries() == nStr)
235 sumNoise->Write(sumNoise->GetName(),TObject::kOverwrite);
236 if(sumPed->GetEntries() == nStr)
237 sumPed->Write(sumPed->GetName(),TObject::kOverwrite);
238
239 fPedSummary.SetBinContent(fCurrentChannel,mean);
240
241 fNoiseSummary.SetBinContent(fCurrentChannel,rms);
242 fCurrentChannel++;
243
244 gDirectory->cd(GetStripPath(det, ring, sec, strip, kTRUE));
245 hChannel->GetXaxis()->SetRange(1,1024);
246
247 hChannel->Write();
248 }
249 }
250 }
3bd993ba 251}
252
253//_____________________________________________________________________
f7f0b643 254void AliFMDPedestalDA::Terminate(TFile* diagFile)
255{
7bce699b 256 if(fSaveHistograms) {
257 diagFile->cd();
258
259 fPedSummary.Write();
260 fNoiseSummary.Write();
261 }
f7f0b643 262
7bce699b 263 if(fZSfileFMD1.is_open()) {
264 fZSfileFMD1.write("# EOF\n",6);
265 fZSfileFMD1.close(); }
266 if(fZSfileFMD2.is_open()) {
267 fZSfileFMD2.write("# EOF\n",6);
268 fZSfileFMD2.close(); }
269 if(fZSfileFMD3.is_open()) {
270 fZSfileFMD3.write("# EOF\n",6);
271 fZSfileFMD3.close(); }
f7f0b643 272
273}
274
275//_____________________________________________________________________
e9c06036 276void AliFMDPedestalDA::WriteHeaderToFile()
277{
80fdb9f3 278 AliFMDParameters* pars = AliFMDParameters::Instance();
279 fOutputFile.write(Form("# %s \n",pars->GetPedestalShuttleID()),13);
f7f0b643 280 fOutputFile.write("# Detector, "
281 "Ring, "
282 "Sector, "
e9c06036 283 "Strip, "
e9c06036 284 "Pedestal, "
285 "Noise, "
286 "Mu, "
287 "Sigma, "
f7f0b643 288 "Chi2/NDF \n", 71);
7bce699b 289 fZSfileFMD1.write("# FMD 1 pedestals \n",19);
290 fZSfileFMD1.write("# board, "
291 "altro, "
292 "channel, "
293 "timebin, "
294 "pedestal, "
295 "noise \n", 51);
296 fZSfileFMD2.write("# FMD 2 pedestals \n",19);
297 fZSfileFMD2.write("# board, "
298 "altro, "
299 "channel, "
300 "timebin, "
301 "pedestal, "
302 "noise \n", 51);
303 fZSfileFMD3.write("# FMD 3 pedestals \n",19);
304 fZSfileFMD3.write("# board, "
305 "altro, "
306 "channel, "
307 "timebin, "
308 "pedestal, "
309 "noise \n", 51);
310
3bd993ba 311}
312
313//_____________________________________________________________________
e9c06036 314TH1S* AliFMDPedestalDA::GetChannel(UShort_t det,
315 Char_t ring,
316 UShort_t sec,
7bce699b 317 UShort_t strip,
318 UInt_t sample)
e9c06036 319{
320 UShort_t iring = (ring == 'O' ? 0 : 1);
3bd993ba 321 TObjArray* detArray = static_cast<TObjArray*>(fDetectorArray.At(det));
e9c06036 322 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(iring));
3bd993ba 323 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
e9c06036 324 TObjArray* sampleArray = static_cast<TObjArray*>(secArray->At(strip));
325 TH1S* hSample = static_cast<TH1S*>(sampleArray->At(sample));
326 return hSample;
7bce699b 327
3bd993ba 328}
93519ec4 329
3bd993ba 330//_____________________________________________________________________
331//
332//EOF
333//