]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDGainDA.cxx
New features, summary plots etc. The DA's now write out calibration parameters in...
[u/mrichter/AliRoot.git] / FMD / AliFMDGainDA.cxx
CommitLineData
f631f26d 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 AliFMDGainDA.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Mon Mar 13 13:46:05 2008
19 @brief Derived class for the pulse gain detector algorithm.
20*/
cf291b42 21//____________________________________________________________________
22//
23// This class contains the implementation of the gain detector
24// algorithms (DA) for the FMD. The data is collected in histograms
25// that are reset for each pulse length after the mean and standard
26// deviation are put into a TGraphErrors object. After a certain
27// number of pulses (usually 8) the graph is fitted to a straight
28// line. The gain is then slope of this line as it combines the known
29// pulse and the response of the detector.
30//
f631f26d 31#include "AliFMDGainDA.h"
32#include "iostream"
33#include "fstream"
34#include "AliLog.h"
35#include "TF1.h"
36#include "TH1.h"
37#include "TMath.h"
38#include "TGraphErrors.h"
39#include "AliFMDParameters.h"
40
41//_____________________________________________________________________
42ClassImp(AliFMDGainDA)
cf291b42 43#if 0 // Do not delete - here to let Emacs indent properly
44;
45#endif
f631f26d 46
47//_____________________________________________________________________
cf291b42 48AliFMDGainDA::AliFMDGainDA()
49 : AliFMDBaseDA(),
50 fGainArray(),
427e8f99 51 //fPulseSize(32),
cf291b42 52 fHighPulse(256),
427e8f99 53 //fPulseLength(100),
54 fEventsPerChannel(16),
55 fCurrentPulse(16),
56 fCurrentChannel(16),
cf291b42 57 fNumberOfStripsPerChip(128)
f631f26d 58{
427e8f99 59 fCurrentPulse.Reset(0);
60 fCurrentChannel.Reset(0);
f631f26d 61 fOutputFile.open("gains.csv");
cf291b42 62 fGainArray.SetOwner();
f631f26d 63}
64
65//_____________________________________________________________________
cf291b42 66AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA)
67 : AliFMDBaseDA(gainDA),
68 fGainArray(gainDA.fGainArray),
427e8f99 69 //fPulseSize(gainDA.fPulseSize),
cf291b42 70 fHighPulse(gainDA.fHighPulse),
427e8f99 71 //fPulseLength(gainDA.fPulseLength),
cf291b42 72 fEventsPerChannel(gainDA.fEventsPerChannel),
73 fCurrentPulse(gainDA.fCurrentPulse),
74 fCurrentChannel(gainDA.fCurrentChannel),
75 fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip)
76{
427e8f99 77 fCurrentPulse.Reset(0);
78 fCurrentChannel.Reset(0);
f631f26d 79}
80
81//_____________________________________________________________________
cf291b42 82AliFMDGainDA::~AliFMDGainDA()
83{
f631f26d 84}
85
86//_____________________________________________________________________
cf291b42 87void AliFMDGainDA::Init()
88{
f631f26d 89
427e8f99 90
91 Int_t nEventsRequired = 0;
92 for(Int_t i=0;i<fEventsPerChannel.GetSize();i++)
93 {
94 Int_t nEvents = (fPulseLength.At(i)*fHighPulse) / fPulseSize.At(i);
95 fEventsPerChannel.AddAt(nEvents,i);
96 if(nEvents>nEventsRequired) nEventsRequired = nEvents * fNumberOfStripsPerChip;
97
98 }
99
100 std::cout<<nEventsRequired<<std::endl;
cf291b42 101 //8 pulser values * 128 strips * 100 samples
427e8f99 102
103
104 SetRequiredEvents(nEventsRequired);
f631f26d 105 TObjArray* detArray;
106 TObjArray* ringArray;
107 TObjArray* sectorArray;
108
109 for(UShort_t det=1;det<=3;det++) {
110 detArray = new TObjArray();
111 detArray->SetOwner();
112 fGainArray.AddAtAndExpand(detArray,det);
113 for (UShort_t ir = 0; ir < 2; ir++) {
114 Char_t ring = (ir == 0 ? 'O' : 'I');
115 UShort_t nsec = (ir == 0 ? 40 : 20);
116 UShort_t nstr = (ir == 0 ? 2 : 4);
117 ringArray = new TObjArray();
118 ringArray->SetOwner();
119 detArray->AddAtAndExpand(ringArray,ir);
120 for(UShort_t sec =0; sec < nsec; sec++) {
121 sectorArray = new TObjArray();
122 sectorArray->SetOwner();
123 ringArray->AddAtAndExpand(sectorArray,sec);
124 for(UShort_t strip = 0; strip < nstr; strip++) {
cf291b42 125 TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
126 Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
127 1024,0,1023);
f631f26d 128 hChannel->SetDirectory(0);
129 sectorArray->AddAtAndExpand(hChannel,strip);
130 }
131 }
132 }
133 }
134}
135
136//_____________________________________________________________________
137void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray,
cf291b42 138 UShort_t det ,
139 Char_t ring,
f631f26d 140 UShort_t sec,
cf291b42 141 UShort_t strip)
142{
f631f26d 143 TGraphErrors* hChannel = new TGraphErrors();
cf291b42 144 hChannel->SetName(Form("FMD%d%c[%02d,%03d]", det, ring, sec, strip));
145 hChannel->SetTitle(Form("FMD%d%c[%02d,%03d] ADC vs DAC",
146 det, ring, sec, strip));
f631f26d 147 sectorArray->AddAtAndExpand(hChannel,strip);
148}
149
150//_____________________________________________________________________
151void AliFMDGainDA::FillChannels(AliFMDDigit* digit) {
152
153 UShort_t det = digit->Detector();
154 Char_t ring = digit->Ring();
155 UShort_t sec = digit->Sector();
156 UShort_t strip = digit->Strip();
157
158
cf291b42 159 if(strip % fNumberOfStripsPerChip) return;
160 Int_t vaChip = strip / fNumberOfStripsPerChip;
161 TH1S* hChannel = GetChannelHistogram(det, ring, sec, vaChip);
f631f26d 162 hChannel->Fill(digit->Counts());
163 UpdatePulseAndADC(det,ring,sec,strip);
164}
165
166//_____________________________________________________________________
167void AliFMDGainDA::Analyse(UShort_t det,
e9c06036 168 Char_t ring,
f631f26d 169 UShort_t sec,
170 UShort_t strip) {
171 TGraphErrors* grChannel = GetChannel(det,ring,sec,strip);
172 if(!grChannel->GetN()) {
cf291b42 173 // AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
174 // det, ring , sec, strip));
f631f26d 175 return;
176 }
9c958f2b 177 TF1 fitFunc("fitFunc","pol1",-10,280);
178 fitFunc.SetParameters(100,3);
e9c06036 179 grChannel->Fit("fitFunc","Q0+","",0,fHighPulse);
f7f0b643 180
f631f26d 181 Float_t chi2ndf = 0;
9c958f2b 182 if(fitFunc.GetNDF())
183 chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
f7f0b643 184
185 fOutputFile << det << ','
186 << ring << ','
187 << sec << ','
188 << strip << ','
9c958f2b 189 << fitFunc.GetParameter(1) << ','
190 << fitFunc.GetParError(1) << ','
f631f26d 191 << chi2ndf <<"\n";
192
193
194 if(fSaveHistograms) {
e9c06036 195 gDirectory->cd(GetSectorPath(det,ring, sec, kTRUE));
196
197 TH1F* summary = dynamic_cast<TH1F*>(gDirectory->Get("Summary"));
198 if (!summary) {
199 Int_t nStr = (ring == 'I' ? 512 : 256);
200 summary = new TH1F("Summary", Form("Summary of gains in FMD%d%c[%02d]",
201 det, ring, sec),
202 nStr, -.5, nStr-.5);
203 summary->SetXTitle("Strip");
204 summary->SetYTitle("Gain [ADC/DAC]");
205 summary->SetDirectory(gDirectory);
206 }
207 summary->SetBinContent(strip+1, fitFunc.GetParameter(1));
208 summary->SetBinError(strip+1, fitFunc.GetParError(1));
209
210 gDirectory->cd(GetStripPath(det,ring,sec,strip, kTRUE));
211 grChannel->SetName(Form("FMD%d%c[%02d,%03d]",det,ring,sec,strip));
212 // grChannel->SetDirectory(gDirectory);
213 grChannel->Write();
214 // grChannel->Write(Form("grFMD%d%c_%d_%d",det,ring,sec,strip));
215 }
f631f26d 216}
217
218//_____________________________________________________________________
e9c06036 219void AliFMDGainDA::WriteHeaderToFile()
220{
9c958f2b 221 AliFMDParameters* pars = AliFMDParameters::Instance();
222 fOutputFile.write(Form("# %s \n",pars->GetGainShuttleID()),9);
f7f0b643 223 fOutputFile.write("# Detector, "
224 "Ring, "
225 "Sector, "
e9c06036 226 "Strip, "
227 "Gain, "
228 "Error, "
f7f0b643 229 "Chi2/NDF \n",56);
f631f26d 230
231}
232
233//_____________________________________________________________________
234TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det,
e9c06036 235 Char_t ring,
f631f26d 236 UShort_t sec,
e9c06036 237 UShort_t strip)
238{
f631f26d 239
240 UShort_t Ring = 1;
241 if(ring == 'O')
242 Ring = 0;
243
244
245 TObjArray* detArray = static_cast<TObjArray*>(fGainArray.At(det));
246 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(Ring));
247 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
248 TH1S* hChannel = static_cast<TH1S*>(secArray->At(strip));
249
250 return hChannel;
251}
252
253//_____________________________________________________________________
cf291b42 254TGraphErrors* AliFMDGainDA::GetChannel(UShort_t det,
e9c06036 255 Char_t ring,
cf291b42 256 UShort_t sec,
e9c06036 257 UShort_t strip)
258{
cf291b42 259 UShort_t iring = (ring == 'O' ? 0 : 1);
260 TObjArray* detArray = static_cast<TObjArray*>(fDetectorArray.At(det));
261 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(iring));
262 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
263 TGraphErrors* hChannel = static_cast<TGraphErrors*>(secArray->At(strip));
f631f26d 264
265 return hChannel;
266}
267
268//_____________________________________________________________________
cf291b42 269void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
270 Char_t ring,
271 UShort_t sec,
272 UShort_t strip)
273{
f7f0b643 274
427e8f99 275 AliFMDParameters* pars = AliFMDParameters::Instance();
276 UInt_t ddl, board,chip,ch;
277 pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch);
278 Int_t halfring = GetHalfringIndex(det,ring,board%16);
f7f0b643 279 if(GetCurrentEvent()> (fNumberOfStripsPerChip*fEventsPerChannel.At(halfring)))
280 return
cf291b42 281 if(strip % fNumberOfStripsPerChip) return;
427e8f99 282 if(((GetCurrentEvent()) % fPulseLength.At(halfring)) && GetCurrentEvent() > 0) return;
283
cf291b42 284 Int_t vaChip = strip/fNumberOfStripsPerChip;
285 TH1S* hChannel = GetChannelHistogram(det,ring,sec,vaChip);
f631f26d 286
287 if(!hChannel->GetEntries()) {
cf291b42 288 AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
289 det, ring , sec, strip));
f631f26d 290 return;
291 }
292 Double_t mean = hChannel->GetMean();
293 Double_t rms = hChannel->GetRMS();
427e8f99 294 Double_t pulse = Double_t(fCurrentPulse.At(halfring)) * fPulseSize.At(halfring);
cf291b42 295 Int_t firstBin = hChannel->GetXaxis()->GetFirst();
296 Int_t lastBin = hChannel->GetXaxis()->GetLast();
9c958f2b 297 hChannel->GetXaxis()->SetRangeUser(mean-4*rms,mean+4*rms);
f631f26d 298
cf291b42 299 mean = hChannel->GetMean();
300 rms = hChannel->GetRMS();
efd39294 301
302 hChannel->GetXaxis()->SetRange(firstBin,lastBin);
303
427e8f99 304 Int_t channelNumber = strip + (GetCurrentEvent()-1)/((fPulseLength.At(halfring)*fHighPulse)/fPulseSize.At(halfring));
f631f26d 305
306 TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber);
307
427e8f99 308 channel->SetPoint(fCurrentPulse.At(halfring),pulse,mean);
309 channel->SetPointError(fCurrentPulse.At(halfring),0,rms);
f631f26d 310
311 if(fSaveHistograms) {
f7f0b643 312 gDirectory->cd(GetStripPath(det,ring,sec,channelNumber));
313 hChannel->Write(Form("%s_pulse_%03d",hChannel->GetName(),(Int_t)pulse));
314
f631f26d 315 }
316
427e8f99 317
318
319
f631f26d 320 hChannel->Reset();
321
322}
323
324//_____________________________________________________________________
cf291b42 325void AliFMDGainDA::ResetPulseAndUpdateChannel()
326{
427e8f99 327 //for(Int_t i=0; i<fCurrentPulse.GetSize();i++)
328 fCurrentPulse.Reset(0);
f631f26d 329}
330
331//_____________________________________________________________________
cf291b42 332void AliFMDGainDA::FinishEvent()
333{
427e8f99 334 for(Int_t i = 0; i<fPulseLength.GetSize();i++) {
335 if(GetCurrentEvent()>0 && (GetCurrentEvent() % fPulseLength.At(i) == 0))
336 fCurrentPulse.AddAt(fCurrentPulse.At(i)+1,i);
337
338 if(GetCurrentEvent()>0 && (GetCurrentEvent()) % fEventsPerChannel.At(i) == 0)
339 fCurrentPulse.AddAt(0,i);
340 }
f631f26d 341}
342//_____________________________________________________________________
343//
344//EOF
345//