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"
32 // #include <iostream>
38 #include "TGraphErrors.h"
39 #include "AliFMDParameters.h"
40 #include "AliFMDAltroMapping.h"
43 //_____________________________________________________________________
44 ClassImp(AliFMDGainDA)
45 #if 0 // Do not delete - here to let Emacs indent properly
49 //_____________________________________________________________________
50 AliFMDGainDA::AliFMDGainDA()
54 fEventsPerChannel(10),
57 fNumberOfStripsPerChip(128),
58 fSummaryGains("GainsSummary","Summary of gains",51200,0,51200),
59 fCurrentSummaryStrip(1)
65 fCurrentPulse.Reset(0);
66 fCurrentChannel.Reset(0);
67 fOutputFile.open("gains.csv");
68 fGainArray.SetOwner();
71 //_____________________________________________________________________
72 AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA)
73 : AliFMDBaseDA(gainDA),
74 fGainArray(gainDA.fGainArray),
75 fHighPulse(gainDA.fHighPulse),
76 fEventsPerChannel(gainDA.fEventsPerChannel),
77 fCurrentPulse(gainDA.fCurrentPulse),
78 fCurrentChannel(gainDA.fCurrentChannel),
79 fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip),
80 fSummaryGains(gainDA.fSummaryGains),
81 fCurrentSummaryStrip(gainDA.fCurrentSummaryStrip)
86 // gainDA Object to copy from
87 fCurrentPulse.Reset(0);
88 fCurrentChannel.Reset(0);
91 //_____________________________________________________________________
92 AliFMDGainDA::~AliFMDGainDA()
100 //_____________________________________________________________________
101 void AliFMDGainDA::Init()
107 Int_t nEventsRequired = 0;
109 for(Int_t idx = 0;idx<fEventsPerChannel.GetSize();idx++) {
111 if(fPulseSize.At(idx))
112 nEvents = (fPulseLength.At(idx)*fHighPulse) / fPulseSize.At(idx);
113 fEventsPerChannel.AddAt(nEvents,idx);
114 if(nEvents>nEventsRequired)
115 nEventsRequired = nEvents * fNumberOfStripsPerChip;
119 SetRequiredEvents(nEventsRequired);
122 TObjArray* ringArray;
123 TObjArray* sectorArray;
125 for(UShort_t det=1;det<=3;det++) {
126 detArray = new TObjArray();
127 detArray->SetOwner();
128 fGainArray.AddAtAndExpand(detArray,det);
129 for (UShort_t ir = 0; ir < 2; ir++) {
130 Char_t ring = (ir == 0 ? 'O' : 'I');
131 UShort_t nsec = (ir == 0 ? 40 : 20);
132 UShort_t nstr = (ir == 0 ? 2 : 4);
133 ringArray = new TObjArray();
134 ringArray->SetOwner();
135 detArray->AddAtAndExpand(ringArray,ir);
136 for(UShort_t sec =0; sec < nsec; sec++) {
137 sectorArray = new TObjArray();
138 sectorArray->SetOwner();
139 ringArray->AddAtAndExpand(sectorArray,sec);
140 for(UShort_t strip = 0; strip < nstr; strip++) {
141 TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
142 Form("hFMD%d%c_%d_%d",det,ring,sec,strip),
144 hChannel->SetDirectory(0);
145 sectorArray->AddAtAndExpand(hChannel,strip);
152 //_____________________________________________________________________
153 void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray,
159 // Make a channel container
162 // sectorArray Sectors
163 // det Detector number
164 // ring Ring identifier
166 // strip Strip number
167 TGraphErrors* hChannel = new TGraphErrors();
168 hChannel->SetName(Form("FMD%d%c[%02d,%03d]", det, ring, sec, strip));
169 hChannel->SetTitle(Form("FMD%d%c[%02d,%03d] ADC vs DAC",
170 det, ring, sec, strip));
171 sectorArray->AddAtAndExpand(hChannel,strip);
174 //_____________________________________________________________________
175 void AliFMDGainDA::FillChannels(AliFMDDigit* digit)
177 // Fill data into histogram
180 // digit Digit to get the data from
182 UShort_t det = digit->Detector();
183 Char_t ring = digit->Ring();
184 UShort_t sec = digit->Sector();
185 UShort_t strip = digit->Strip();
187 //Strip is always seen as the first in a VA chip. All other strips are junk.
188 //Strips are counted from zero on even sectors and from 511 on odd sectors...
190 if((sec%2) && ((strip+1) % fNumberOfStripsPerChip)) return;
191 if(((sec+1)%2) && (strip % fNumberOfStripsPerChip)) return;
193 Int_t vaChip = strip / fNumberOfStripsPerChip;
194 TH1S* hChannel = GetChannelHistogram(det, ring, sec, vaChip);
195 hChannel->Fill(digit->Counts());
196 UpdatePulseAndADC(det,ring,sec,strip);
199 //_____________________________________________________________________
200 void AliFMDGainDA::Analyse(UShort_t det,
205 // Analyse result of a single strip
208 // det Detector number
209 // ring Ring identifier
211 // strip Strip number
212 TGraphErrors* grChannel = GetChannel(det,ring,sec,strip);
213 if(!grChannel->GetN()) {
214 AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
215 det, ring , sec, strip));
218 TF1 fitFunc("fitFunc","pol1",-10,280);
219 fitFunc.SetParameters(100,3);
220 grChannel->Fit("fitFunc","Q0+","",0,fHighPulse);
224 Float_t chi2ndf = -1;
225 if((fitFunc.GetParameter(1)) == (fitFunc.GetParameter(1))) {
226 gain = fitFunc.GetParameter(1);
227 error = fitFunc.GetParError(1);
229 chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF();
232 fOutputFile << det << ','
240 //due to RCU trouble, first strips on VAs are excluded
241 // if(strip%128 != 0) {
243 fSummaryGains.SetBinContent(fCurrentSummaryStrip,fitFunc.GetParameter(1));
244 fSummaryGains.SetBinError(fCurrentSummaryStrip,fitFunc.GetParError(1));
246 fCurrentSummaryStrip++;
248 if(fSaveHistograms) {
249 gDirectory->cd(GetSectorPath(det,ring, sec, kTRUE));
251 TH1F* summary = dynamic_cast<TH1F*>(gDirectory->Get("Summary"));
253 Int_t nStr = (ring == 'I' ? 512 : 256);
254 summary = new TH1F("Summary", Form("Summary of gains in FMD%d%c[%02d]",
257 summary->SetXTitle("Strip");
258 summary->SetYTitle("Gain [ADC/DAC]");
259 summary->SetDirectory(gDirectory);
261 summary->SetBinContent(strip+1, fitFunc.GetParameter(1));
262 summary->SetBinError(strip+1, fitFunc.GetParError(1));
264 gDirectory->cd(GetStripPath(det,ring,sec,strip, kTRUE));
265 grChannel->SetName(Form("FMD%d%c[%02d,%03d]",det,ring,sec,strip));
266 // grChannel->SetDirectory(gDirectory);
268 // grChannel->Write(Form("grFMD%d%c_%d_%d",det,ring,sec,strip));
272 //_____________________________________________________________________
273 void AliFMDGainDA::Terminate(TFile* diagFile)
281 fSummaryGains.Write();
285 //_____________________________________________________________________
286 void AliFMDGainDA::WriteHeaderToFile()
288 // Write header to the output file
292 AliFMDParameters* pars = AliFMDParameters::Instance();
293 fOutputFile.write(Form("# %s \n",pars->GetGainShuttleID()),9);
295 fOutputFile << "# This file created from run # " << fRunno
296 << " @ " << now.AsString() << std::endl;
297 fOutputFile.write("# Detector, "
307 //_____________________________________________________________________
308 TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det,
313 // Get the current histogram of a single strip
316 // det Detector number
317 // ring Ring identifier
319 // strip Strip number
326 TObjArray* detArray = static_cast<TObjArray*>(fGainArray.At(det));
327 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(lRing));
328 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
329 TH1S* hChannel = static_cast<TH1S*>(secArray->At(strip));
334 //_____________________________________________________________________
335 TGraphErrors* AliFMDGainDA::GetChannel(UShort_t det,
340 // Get the graph of a single strip
343 // det Detector number
344 // ring Ring identifier
346 // strip Strip number
347 UShort_t iring = (ring == 'O' ? 0 : 1);
348 TObjArray* detArray = static_cast<TObjArray*>(fDetectorArray.At(det));
349 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(iring));
350 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
351 TGraphErrors* hChannel = static_cast<TGraphErrors*>(secArray->At(strip));
356 //_____________________________________________________________________
357 void AliFMDGainDA::UpdatePulseAndADC(UShort_t det,
362 // Go to next pulse size
365 // det Detector number
366 // ring Ring identifier
368 // strip Strip number
370 AliFMDParameters* pars = AliFMDParameters::Instance();
371 // UInt_t ddl, board,chip,ch;
372 UShort_t board = pars->GetAltroMap()->Sector2Board(ring, sec);
373 // pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch);
374 /// pars->GetAltroMap()->Strip2Channel(
375 Int_t halfring = GetHalfringIndex(det,ring,board/16);
377 if(GetCurrentEvent()> (fNumberOfStripsPerChip*fEventsPerChannel.At(halfring)))
380 if((sec%2) && ((strip+1) % fNumberOfStripsPerChip)) return;
382 if(((sec+1)%2) && (strip % fNumberOfStripsPerChip)) return;
384 if(((GetCurrentEvent()) % fPulseLength.At(halfring))
385 && GetCurrentEvent() > 0) return;
387 Int_t vaChip = strip/fNumberOfStripsPerChip;
388 TH1S* hChannel = GetChannelHistogram(det,ring,sec,vaChip);
390 if(!hChannel->GetEntries()) {
391 AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",
392 det, ring , sec, strip));
395 Double_t mean = hChannel->GetMean();
396 Double_t rms = hChannel->GetRMS();
397 Double_t pulse = (Double_t(fCurrentPulse.At(halfring))
398 * fPulseSize.At(halfring));
399 Int_t firstBin = hChannel->GetXaxis()->GetFirst();
400 Int_t lastBin = hChannel->GetXaxis()->GetLast();
401 hChannel->GetXaxis()->SetRangeUser(mean-4*rms,mean+4*rms);
403 mean = hChannel->GetMean();
404 rms = hChannel->GetRMS();
406 hChannel->GetXaxis()->SetRange(firstBin,lastBin);
408 Int_t channelNumber = (strip +
409 (GetCurrentEvent()-1)
410 / ((fPulseLength.At(halfring)*fHighPulse)
411 / fPulseSize.At(halfring)));
413 channelNumber = (strip -
414 (GetCurrentEvent()-1)
415 / ((fPulseLength.At(halfring)*fHighPulse)
416 / fPulseSize.At(halfring)));
418 TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber);
420 channel->SetPoint(fCurrentPulse.At(halfring),pulse,mean);
421 channel->SetPointError(fCurrentPulse.At(halfring),0,rms);
423 if(fSaveHistograms) {
424 gDirectory->cd(GetStripPath(det,ring,sec,channelNumber));
425 hChannel->Write(Form("%s_pulse_%03d",hChannel->GetName(),(Int_t)pulse));
433 //_____________________________________________________________________
434 void AliFMDGainDA::ResetPulseAndUpdateChannel()
440 fCurrentPulse.Reset(0);
443 //_____________________________________________________________________
444 void AliFMDGainDA::FinishEvent()
450 for(UShort_t det=1; det<=3;det++) {
451 UShort_t firstring = (det == 1 ? 1 : 0);
452 for(UShort_t iring = firstring; iring <=1;iring++) {
453 Char_t ring = (iring == 1 ? 'I' : 'O');
454 for(UShort_t board =0 ; board <=1; board++) {
455 Int_t idx = GetHalfringIndex(det,ring,board);
457 if(!fPulseLength.At(idx) || !fEventsPerChannel.At(idx))
459 if(GetCurrentEvent()>0 &&
460 ((GetCurrentEvent() % fPulseLength.At(idx)) == 0))
461 fCurrentPulse.AddAt(fCurrentPulse.At(idx)+1,idx);
463 if(GetCurrentEvent()>0 &&
464 ((GetCurrentEvent()) % fEventsPerChannel.At(idx)) == 0)
465 fCurrentPulse.AddAt(0,idx);
470 //_____________________________________________________________________