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 // This class contains the implementation of the gain detector algorithms (DA) for the FMD.
22 // The data is collected in histograms that are reset for each pulse length after the
23 // mean and standard deviation are put into a TGraphErrors object. After a certain number of pulses
24 // (usually 8) the graph is fitted to a straight line. The gain is then slope of this line as
25 // it combines the known pulse and the response of the detector.
28 #include "AliFMDGainDA.h"
35 #include "TGraphErrors.h"
36 #include "AliFMDParameters.h"
38 //_____________________________________________________________________
39 ClassImp(AliFMDGainDA)
41 //_____________________________________________________________________
42 AliFMDGainDA::AliFMDGainDA() : AliFMDBaseDA(),
50 fNumberOfStripsPerChip(128)
52 fOutputFile.open("gains.csv");
53 fGainArray.SetOwner();
57 //_____________________________________________________________________
58 AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA) :
60 fGainArray(gainDA.fGainArray),
61 fPulseSize(gainDA.fPulseSize),
62 fHighPulse(gainDA.fHighPulse),
63 fPulseLength(gainDA.fPulseLength),
64 fEventsPerChannel(gainDA.fEventsPerChannel),
65 fCurrentPulse(gainDA.fCurrentPulse),
66 fCurrentChannel(gainDA.fCurrentChannel),
67 fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip)
72 //_____________________________________________________________________
73 AliFMDGainDA::~AliFMDGainDA() {
79 //_____________________________________________________________________
80 void AliFMDGainDA::Init() {
82 fEventsPerChannel = (fPulseLength*fHighPulse) / fPulseSize ;
84 SetRequiredEvents(fEventsPerChannel*fNumberOfStripsPerChip); //8 pulser values * 128 strips * 100 samples
87 TObjArray* sectorArray;
89 for(UShort_t det=1;det<=3;det++) {
90 detArray = new TObjArray();
92 fGainArray.AddAtAndExpand(detArray,det);
93 for (UShort_t ir = 0; ir < 2; ir++) {
94 Char_t ring = (ir == 0 ? 'O' : 'I');
95 UShort_t nsec = (ir == 0 ? 40 : 20);
96 UShort_t nstr = (ir == 0 ? 2 : 4);
97 ringArray = new TObjArray();
98 ringArray->SetOwner();
99 detArray->AddAtAndExpand(ringArray,ir);
100 for(UShort_t sec =0; sec < nsec; sec++) {
101 sectorArray = new TObjArray();
102 sectorArray->SetOwner();
103 ringArray->AddAtAndExpand(sectorArray,sec);
104 for(UShort_t strip = 0; strip < nstr; strip++) {
105 TH1S* hChannel = new TH1S(Form("hFMD%d%c_%d_%d",det,ring,sec,strip),Form("hFMD%d%c_%d_%d",det,ring,sec,strip),1024,0,1023);
106 hChannel->SetDirectory(0);
107 sectorArray->AddAtAndExpand(hChannel,strip);
114 //_____________________________________________________________________
115 void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray,
121 TGraphErrors* hChannel = new TGraphErrors();
122 sectorArray->AddAtAndExpand(hChannel,strip);
125 //_____________________________________________________________________
126 void AliFMDGainDA::FillChannels(AliFMDDigit* digit) {
128 UShort_t det = digit->Detector();
129 Char_t ring = digit->Ring();
130 UShort_t sec = digit->Sector();
131 UShort_t strip = digit->Strip();
134 if(strip%fNumberOfStripsPerChip) return;
135 Int_t VAchip = strip / fNumberOfStripsPerChip;
136 TH1S* hChannel = GetChannelHistogram(det,ring,sec,VAchip);
137 hChannel->Fill(digit->Counts());
138 UpdatePulseAndADC(det,ring,sec,strip);
141 //_____________________________________________________________________
142 void AliFMDGainDA::Analyse(UShort_t det,
146 TGraphErrors* grChannel = GetChannel(det,ring,sec,strip);
147 if(!grChannel->GetN()) {
148 AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",det, ring , sec, strip));
151 TF1* fitFunc = new TF1("fitFunc","pol1",-10,280);
152 fitFunc->SetParameters(100,3);
153 grChannel->Fit("fitFunc","Q","Q",0,fHighPulse);
154 AliFMDParameters* pars = AliFMDParameters::Instance();
155 UInt_t ddl, board,chip,channel;
156 pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,channel);
159 if(fitFunc->GetNDF())
160 chi2ndf = fitFunc->GetChisquare() / fitFunc->GetNDF();
161 ddl = ddl + kBaseDDL;
163 Int_t relStrip = strip%fNumberOfStripsPerChip;
165 fOutputFile << ddl << ','
170 << fitFunc->GetParameter(1) << ','
171 << fitFunc->GetParError(1) << ','
175 if(fSaveHistograms) {
177 gDirectory->cd(Form("%s:FMD%d%c/sector_%d/strip_%d",fDiagnosticsFilename,det,ring,sec,strip));
178 grChannel->Write(Form("grFMD%d%c_%d_%d",det,ring,sec,strip));
185 //_____________________________________________________________________
186 void AliFMDGainDA::WriteHeaderToFile() {
187 fOutputFile.write("# Gains \n",9);
188 fOutputFile.write("# Rcu, Board, Chip, Channel, Strip, Gain, Error, Chi2/NDF \n",59);
192 //_____________________________________________________________________
193 TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det,
203 TObjArray* detArray = static_cast<TObjArray*>(fGainArray.At(det));
204 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(Ring));
205 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
206 TH1S* hChannel = static_cast<TH1S*>(secArray->At(strip));
211 //_____________________________________________________________________
212 TGraphErrors* AliFMDGainDA::GetChannel(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip) {
219 TObjArray* detArray = static_cast<TObjArray*>(fDetectorArray.At(det));
220 TObjArray* ringArray = static_cast<TObjArray*>(detArray->At(Ring));
221 TObjArray* secArray = static_cast<TObjArray*>(ringArray->At(sec));
222 TGraphErrors* hChannel = static_cast<TGraphErrors*>(secArray->At(strip));
227 //_____________________________________________________________________
228 void AliFMDGainDA::UpdatePulseAndADC(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip) {
230 if(strip%fNumberOfStripsPerChip) return;
231 if(((GetCurrentEvent())%fPulseLength) && GetCurrentEvent()>0) return;
233 Int_t VAchip = strip/fNumberOfStripsPerChip;
234 TH1S* hChannel = GetChannelHistogram(det,ring,sec,VAchip);
236 if(!hChannel->GetEntries()) {
237 AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d",det, ring , sec, strip));
240 Double_t mean = hChannel->GetMean();
241 Double_t rms = hChannel->GetRMS();
242 Double_t pulse = (Double_t)fCurrentPulse*fPulseSize;
244 for(Int_t i=1;i<hChannel->GetNbinsX();i++)
245 if(hChannel->GetBinCenter(i)>mean+5*rms || hChannel->GetBinCenter(i)<mean-5*rms)
246 hChannel->SetBinContent(i,0);
248 mean = hChannel->GetMean();
249 rms = hChannel->GetRMS();
251 Int_t channelNumber = strip + (GetCurrentEvent()-1)/800;
253 TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber);
255 channel->SetPoint(fCurrentPulse,pulse,mean);
256 channel->SetPointError(fCurrentPulse,0,rms);
258 if(fSaveHistograms) {
259 gDirectory->cd(Form("%s:FMD%d%c/sector_%d/strip_%d",fDiagnosticsFilename,det,ring,sec,channelNumber));
260 hChannel->Write(Form("hFMD%d%c_%d_%d_pulse_%d",det,ring,sec,channelNumber,fCurrentPulse));
267 //_____________________________________________________________________
268 void AliFMDGainDA::ResetPulseAndUpdateChannel() {
274 //_____________________________________________________________________
275 void AliFMDGainDA::FinishEvent() {
277 if(GetCurrentEvent()>0 && (GetCurrentEvent()%fPulseLength==0))
280 if(GetCurrentEvent()>0 && (GetCurrentEvent())%fEventsPerChannel==0)
285 //_____________________________________________________________________