1 /**************************************************************************
2 * Copyright(c) 2004, 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 **************************************************************************/
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.
21 //____________________________________________________________________
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.
31 #include "AliFMDGainDA.h"
38 #include "TGraphErrors.h"
39 #include "AliFMDParameters.h"
41 //_____________________________________________________________________
42 ClassImp(AliFMDGainDA)
43 #if 0 // Do not delete - here to let Emacs indent properly
47 //_____________________________________________________________________
48 AliFMDGainDA::AliFMDGainDA()
52 fEventsPerChannel(10),
55 fNumberOfStripsPerChip(128),
56 fSummaryGains("GainsSummary","Summary of gains",51200,0,51200),
57 fCurrentSummaryStrip(1)
59 fCurrentPulse.Reset(0);
60 fCurrentChannel.Reset(0);
61 fOutputFile.open("gains.csv");
62 fGainArray.SetOwner();
65 //_____________________________________________________________________
66 AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA)
67 : AliFMDBaseDA(gainDA),
68 fGainArray(gainDA.fGainArray),
69 fHighPulse(gainDA.fHighPulse),
70 fEventsPerChannel(gainDA.fEventsPerChannel),
71 fCurrentPulse(gainDA.fCurrentPulse),
72 fCurrentChannel(gainDA.fCurrentChannel),
73 fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip),
74 fSummaryGains(gainDA.fSummaryGains),
75 fCurrentSummaryStrip(gainDA.fCurrentSummaryStrip)
77 fCurrentPulse.Reset(0);
78 fCurrentChannel.Reset(0);
81 //_____________________________________________________________________
82 AliFMDGainDA::~AliFMDGainDA()
86 //_____________________________________________________________________
87 void AliFMDGainDA::Init()
91 Int_t nEventsRequired = 0;
93 //for(UShort_t det=1; det<=3;det++) {
94 // UShort_t firstring = (det == 1 ? 1 : 0);
95 // for(UShort_t iring = firstring; iring <=1;iring++) {
96 // Char_t ring = (iring == 1 ? 'I' : 'O');
97 // for(UShort_t board =0 ; board <=1; board++) {
98 // Int_t idx = GetHalfringIndex(det,ring,board);
99 for(Int_t idx = 0;idx<fEventsPerChannel.GetSize();idx++)
103 if(fPulseSize.At(idx))
104 nEvents = (fPulseLength.At(idx)*fHighPulse) / fPulseSize.At(idx);
105 fEventsPerChannel.AddAt(nEvents,idx);
106 if(nEvents>nEventsRequired) nEventsRequired = nEvents * fNumberOfStripsPerChip;
112 //8 pulser values * 128 strips * 100 samples
115 SetRequiredEvents(nEventsRequired);
118 TObjArray* ringArray;
119 TObjArray* sectorArray;
121 for(UShort_t det=1;det<=3;det++) {
122 detArray = new TObjArray();
123 detArray->SetOwner();
124 fGainArray.AddAtAndExpand(detArray,det);
125 for (UShort_t ir = 0; ir < 2; ir++) {
126 Char_t ring = (ir == 0 ? 'O' : 'I');
127 UShort_t nsec = (ir == 0 ? 40 : 20);
128 UShort_t nstr = (ir == 0 ? 2 : 4);
129 ringArray = new TObjArray();
130 ringArray->SetOwner();
131 detArray->AddAtAndExpand(ringArray,ir);
132 for(UShort_t sec =0; sec < nsec; sec++) {
133 sectorArray = new TObjArray();
134 sectorArray->SetOwner();
135 ringArray->AddAtAndExpand(sectorArray,sec);
136 for(UShort_t strip = 0; strip < nstr; strip++) {
137 TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
138 Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
140 hChannel->SetDirectory(0);
141 sectorArray->AddAtAndExpand(hChannel,strip);
148 //_____________________________________________________________________
149 void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray,
155 TGraphErrors* hChannel = new TGraphErrors();
156 hChannel->SetName(Form("FMD%d%c[%02d,%03d]", det, ring, sec, strip));
157 hChannel->SetTitle(Form("FMD%d%c[%02d,%03d] ADC vs DAC",
158 det, ring, sec, strip));
159 sectorArray->AddAtAndExpand(hChannel,strip);
162 //_____________________________________________________________________
163 void AliFMDGainDA::FillChannels(AliFMDDigit* digit) {
165 UShort_t det = digit->Detector();
166 Char_t ring = digit->Ring();
167 UShort_t sec = digit->Sector();
168 UShort_t strip = digit->Strip();
170 //Strip is always seen as the first in a VA chip. All other strips are junk
171 if(strip % fNumberOfStripsPerChip) return;
172 Int_t vaChip = strip / fNumberOfStripsPerChip;
173 TH1S* hChannel = GetChannelHistogram(det, ring, sec, vaChip);
175 hChannel->Fill(digit->Counts());
176 UpdatePulseAndADC(det,ring,sec,strip);
179 //_____________________________________________________________________
180 void AliFMDGainDA::Analyse(UShort_t det,
184 TGraphErrors* grChannel = GetChannel(det,ring,sec,strip);
185 if(!grChannel->GetN()) {
186 // AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
187 // det, ring , sec, strip));
190 TF1 fitFunc("fitFunc","pol1",-10,280);
191 fitFunc.SetParameters(100,3);
192 grChannel->Fit("fitFunc","Q0+","",0,fHighPulse);
196 chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
198 fOutputFile << det << ','
202 << fitFunc.GetParameter(1) << ','
203 << fitFunc.GetParError(1) << ','
206 //due to RCU trouble, first strips on VAs are excluded
209 fSummaryGains.SetBinContent(fCurrentSummaryStrip,fitFunc.GetParameter(1));
210 fSummaryGains.SetBinError(fCurrentSummaryStrip,fitFunc.GetParError(1));
212 fCurrentSummaryStrip++;
214 if(fSaveHistograms) {
215 gDirectory->cd(GetSectorPath(det,ring, sec, kTRUE));
217 TH1F* summary = dynamic_cast<TH1F*>(gDirectory->Get("Summary"));
219 Int_t nStr = (ring == 'I' ? 512 : 256);
220 summary = new TH1F("Summary", Form("Summary of gains in FMD%d%c[%02d]",
223 summary->SetXTitle("Strip");
224 summary->SetYTitle("Gain [ADC/DAC]");
225 summary->SetDirectory(gDirectory);
227 summary->SetBinContent(strip+1, fitFunc.GetParameter(1));
228 summary->SetBinError(strip+1, fitFunc.GetParError(1));
230 gDirectory->cd(GetStripPath(det,ring,sec,strip, kTRUE));
231 grChannel->SetName(Form("FMD%d%c[%02d,%03d]",det,ring,sec,strip));
232 // grChannel->SetDirectory(gDirectory);
234 // grChannel->Write(Form("grFMD%d%c_%d_%d",det,ring,sec,strip));
238 //_____________________________________________________________________
239 void AliFMDGainDA::Terminate(TFile* diagFile)
242 fSummaryGains.Write();
245 //_____________________________________________________________________
246 void AliFMDGainDA::WriteHeaderToFile()
248 AliFMDParameters* pars = AliFMDParameters::Instance();
249 fOutputFile.write(Form("# %s \n",pars->GetGainShuttleID()),9);
250 fOutputFile.write("# Detector, "
260 //_____________________________________________________________________
261 TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det,
272 TObjArray* detArray = static_cast<TObjArray*>(fGainArray.At(det));
273 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(Ring));
274 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
275 TH1S* hChannel = static_cast<TH1S*>(secArray->At(strip));
280 //_____________________________________________________________________
281 TGraphErrors* AliFMDGainDA::GetChannel(UShort_t det,
286 UShort_t iring = (ring == 'O' ? 0 : 1);
287 TObjArray* detArray = static_cast<TObjArray*>(fDetectorArray.At(det));
288 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(iring));
289 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
290 TGraphErrors* hChannel = static_cast<TGraphErrors*>(secArray->At(strip));
295 //_____________________________________________________________________
296 void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
302 AliFMDParameters* pars = AliFMDParameters::Instance();
303 UInt_t ddl, board,chip,ch;
304 pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch);
305 Int_t halfring = GetHalfringIndex(det,ring,board/16);
307 if(GetCurrentEvent()> (fNumberOfStripsPerChip*fEventsPerChannel.At(halfring)))
309 if(strip % fNumberOfStripsPerChip) return;
310 if(((GetCurrentEvent()) % fPulseLength.At(halfring)) && GetCurrentEvent() > 0) return;
312 Int_t vaChip = strip/fNumberOfStripsPerChip;
313 TH1S* hChannel = GetChannelHistogram(det,ring,sec,vaChip);
315 if(!hChannel->GetEntries()) {
316 AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
317 det, ring , sec, strip));
320 Double_t mean = hChannel->GetMean();
321 Double_t rms = hChannel->GetRMS();
322 Double_t pulse = Double_t(fCurrentPulse.At(halfring)) * fPulseSize.At(halfring);
323 Int_t firstBin = hChannel->GetXaxis()->GetFirst();
324 Int_t lastBin = hChannel->GetXaxis()->GetLast();
325 hChannel->GetXaxis()->SetRangeUser(mean-4*rms,mean+4*rms);
327 mean = hChannel->GetMean();
328 rms = hChannel->GetRMS();
330 hChannel->GetXaxis()->SetRange(firstBin,lastBin);
332 Int_t channelNumber = strip + (GetCurrentEvent()-1)/((fPulseLength.At(halfring)*fHighPulse)/fPulseSize.At(halfring));
334 TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber);
336 channel->SetPoint(fCurrentPulse.At(halfring),pulse,mean);
337 channel->SetPointError(fCurrentPulse.At(halfring),0,rms);
339 if(fSaveHistograms) {
340 gDirectory->cd(GetStripPath(det,ring,sec,channelNumber));
341 hChannel->Write(Form("%s_pulse_%03d",hChannel->GetName(),(Int_t)pulse));
349 //_____________________________________________________________________
350 void AliFMDGainDA::ResetPulseAndUpdateChannel()
352 fCurrentPulse.Reset(0);
355 //_____________________________________________________________________
356 void AliFMDGainDA::FinishEvent()
358 for(UShort_t det=1; det<=3;det++) {
359 UShort_t firstring = (det == 1 ? 1 : 0);
360 for(UShort_t iring = firstring; iring <=1;iring++) {
361 Char_t ring = (iring == 1 ? 'I' : 'O');
362 for(UShort_t board =0 ; board <=1; board++) {
363 Int_t idx = GetHalfringIndex(det,ring,board);
365 if( !fPulseLength.At(idx) || !fEventsPerChannel.At(idx))
367 if(GetCurrentEvent()>0 && ((GetCurrentEvent() % fPulseLength.At(idx)) == 0))
368 fCurrentPulse.AddAt(fCurrentPulse.At(idx)+1,idx);
370 if(GetCurrentEvent()>0 && ((GetCurrentEvent()) % fEventsPerChannel.At(idx)) == 0)
371 fCurrentPulse.AddAt(0,idx);
376 //_____________________________________________________________________