]>
Commit | Line | Data |
---|---|---|
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 | //_____________________________________________________________________ | |
42 | ClassImp(AliFMDGainDA) | |
cf291b42 | 43 | #if 0 // Do not delete - here to let Emacs indent properly |
44 | ; | |
45 | #endif | |
f631f26d | 46 | |
47 | //_____________________________________________________________________ | |
cf291b42 | 48 | AliFMDGainDA::AliFMDGainDA() |
49 | : AliFMDBaseDA(), | |
50 | fGainArray(), | |
cf291b42 | 51 | fHighPulse(256), |
22017a7e | 52 | fEventsPerChannel(10), |
53 | fCurrentPulse(10), | |
54 | fCurrentChannel(10), | |
3bae5d02 | 55 | fNumberOfStripsPerChip(128), |
56 | fSummaryGains("GainsSummary","Summary of gains",51200,0,51200), | |
f14ede67 | 57 | fCurrentSummaryStrip(1) |
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 | 66 | AliFMDGainDA::AliFMDGainDA(const AliFMDGainDA & gainDA) |
67 | : AliFMDBaseDA(gainDA), | |
68 | fGainArray(gainDA.fGainArray), | |
cf291b42 | 69 | fHighPulse(gainDA.fHighPulse), |
cf291b42 | 70 | fEventsPerChannel(gainDA.fEventsPerChannel), |
71 | fCurrentPulse(gainDA.fCurrentPulse), | |
72 | fCurrentChannel(gainDA.fCurrentChannel), | |
3bae5d02 | 73 | fNumberOfStripsPerChip(gainDA.fNumberOfStripsPerChip), |
74 | fSummaryGains(gainDA.fSummaryGains), | |
75 | fCurrentSummaryStrip(gainDA.fCurrentSummaryStrip) | |
cf291b42 | 76 | { |
427e8f99 | 77 | fCurrentPulse.Reset(0); |
78 | fCurrentChannel.Reset(0); | |
f631f26d | 79 | } |
80 | ||
81 | //_____________________________________________________________________ | |
cf291b42 | 82 | AliFMDGainDA::~AliFMDGainDA() |
83 | { | |
f631f26d | 84 | } |
85 | ||
86 | //_____________________________________________________________________ | |
cf291b42 | 87 | void AliFMDGainDA::Init() |
88 | { | |
f631f26d | 89 | |
427e8f99 | 90 | |
91 | Int_t nEventsRequired = 0; | |
22017a7e | 92 | |
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++) | |
427e8f99 | 100 | { |
22017a7e | 101 | |
102 | Int_t nEvents = 0; | |
103 | if(fPulseSize.At(idx)) | |
104 | nEvents = (fPulseLength.At(idx)*fHighPulse) / fPulseSize.At(idx); | |
105 | fEventsPerChannel.AddAt(nEvents,idx); | |
427e8f99 | 106 | if(nEvents>nEventsRequired) nEventsRequired = nEvents * fNumberOfStripsPerChip; |
107 | ||
108 | } | |
22017a7e | 109 | //} |
110 | // } | |
54b167db | 111 | |
cf291b42 | 112 | //8 pulser values * 128 strips * 100 samples |
427e8f99 | 113 | |
114 | ||
115 | SetRequiredEvents(nEventsRequired); | |
22017a7e | 116 | |
f631f26d | 117 | TObjArray* detArray; |
118 | TObjArray* ringArray; | |
119 | TObjArray* sectorArray; | |
120 | ||
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++) { | |
cf291b42 | 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), | |
139 | 1024,0,1023); | |
f631f26d | 140 | hChannel->SetDirectory(0); |
141 | sectorArray->AddAtAndExpand(hChannel,strip); | |
142 | } | |
143 | } | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | //_____________________________________________________________________ | |
149 | void AliFMDGainDA::AddChannelContainer(TObjArray* sectorArray, | |
cf291b42 | 150 | UShort_t det , |
151 | Char_t ring, | |
f631f26d | 152 | UShort_t sec, |
cf291b42 | 153 | UShort_t strip) |
154 | { | |
f631f26d | 155 | TGraphErrors* hChannel = new TGraphErrors(); |
cf291b42 | 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)); | |
f631f26d | 159 | sectorArray->AddAtAndExpand(hChannel,strip); |
160 | } | |
161 | ||
162 | //_____________________________________________________________________ | |
163 | void AliFMDGainDA::FillChannels(AliFMDDigit* digit) { | |
164 | ||
165 | UShort_t det = digit->Detector(); | |
166 | Char_t ring = digit->Ring(); | |
167 | UShort_t sec = digit->Sector(); | |
168 | UShort_t strip = digit->Strip(); | |
169 | ||
22017a7e | 170 | //Strip is always seen as the first in a VA chip. All other strips are junk |
cf291b42 | 171 | if(strip % fNumberOfStripsPerChip) return; |
172 | Int_t vaChip = strip / fNumberOfStripsPerChip; | |
173 | TH1S* hChannel = GetChannelHistogram(det, ring, sec, vaChip); | |
22017a7e | 174 | |
f631f26d | 175 | hChannel->Fill(digit->Counts()); |
176 | UpdatePulseAndADC(det,ring,sec,strip); | |
177 | } | |
178 | ||
179 | //_____________________________________________________________________ | |
180 | void AliFMDGainDA::Analyse(UShort_t det, | |
e9c06036 | 181 | Char_t ring, |
f631f26d | 182 | UShort_t sec, |
183 | UShort_t strip) { | |
184 | TGraphErrors* grChannel = GetChannel(det,ring,sec,strip); | |
185 | if(!grChannel->GetN()) { | |
cf291b42 | 186 | // AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d", |
187 | // det, ring , sec, strip)); | |
f631f26d | 188 | return; |
189 | } | |
9c958f2b | 190 | TF1 fitFunc("fitFunc","pol1",-10,280); |
191 | fitFunc.SetParameters(100,3); | |
e9c06036 | 192 | grChannel->Fit("fitFunc","Q0+","",0,fHighPulse); |
f7f0b643 | 193 | |
f631f26d | 194 | Float_t chi2ndf = 0; |
9c958f2b | 195 | if(fitFunc.GetNDF()) |
196 | chi2ndf = fitFunc.GetChisquare() / fitFunc.GetNDF(); | |
f7f0b643 | 197 | |
198 | fOutputFile << det << ',' | |
199 | << ring << ',' | |
200 | << sec << ',' | |
201 | << strip << ',' | |
9c958f2b | 202 | << fitFunc.GetParameter(1) << ',' |
203 | << fitFunc.GetParError(1) << ',' | |
f631f26d | 204 | << chi2ndf <<"\n"; |
205 | ||
22017a7e | 206 | //due to RCU trouble, first strips on VAs are excluded |
207 | if(strip%128 != 0) { | |
208 | ||
209 | fSummaryGains.SetBinContent(fCurrentSummaryStrip,fitFunc.GetParameter(1)); | |
210 | fSummaryGains.SetBinError(fCurrentSummaryStrip,fitFunc.GetParError(1)); | |
211 | ||
212 | fCurrentSummaryStrip++; | |
213 | } | |
f631f26d | 214 | if(fSaveHistograms) { |
e9c06036 | 215 | gDirectory->cd(GetSectorPath(det,ring, sec, kTRUE)); |
216 | ||
217 | TH1F* summary = dynamic_cast<TH1F*>(gDirectory->Get("Summary")); | |
218 | if (!summary) { | |
219 | Int_t nStr = (ring == 'I' ? 512 : 256); | |
220 | summary = new TH1F("Summary", Form("Summary of gains in FMD%d%c[%02d]", | |
221 | det, ring, sec), | |
222 | nStr, -.5, nStr-.5); | |
223 | summary->SetXTitle("Strip"); | |
224 | summary->SetYTitle("Gain [ADC/DAC]"); | |
225 | summary->SetDirectory(gDirectory); | |
226 | } | |
227 | summary->SetBinContent(strip+1, fitFunc.GetParameter(1)); | |
228 | summary->SetBinError(strip+1, fitFunc.GetParError(1)); | |
229 | ||
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); | |
233 | grChannel->Write(); | |
234 | // grChannel->Write(Form("grFMD%d%c_%d_%d",det,ring,sec,strip)); | |
235 | } | |
f631f26d | 236 | } |
237 | ||
238 | //_____________________________________________________________________ | |
3bae5d02 | 239 | void AliFMDGainDA::Terminate(TFile* diagFile) |
240 | { | |
241 | diagFile->cd(); | |
242 | fSummaryGains.Write(); | |
243 | } | |
244 | ||
245 | //_____________________________________________________________________ | |
e9c06036 | 246 | void AliFMDGainDA::WriteHeaderToFile() |
247 | { | |
9c958f2b | 248 | AliFMDParameters* pars = AliFMDParameters::Instance(); |
249 | fOutputFile.write(Form("# %s \n",pars->GetGainShuttleID()),9); | |
f7f0b643 | 250 | fOutputFile.write("# Detector, " |
251 | "Ring, " | |
252 | "Sector, " | |
e9c06036 | 253 | "Strip, " |
254 | "Gain, " | |
255 | "Error, " | |
f7f0b643 | 256 | "Chi2/NDF \n",56); |
f631f26d | 257 | |
258 | } | |
259 | ||
260 | //_____________________________________________________________________ | |
261 | TH1S* AliFMDGainDA::GetChannelHistogram(UShort_t det, | |
e9c06036 | 262 | Char_t ring, |
f631f26d | 263 | UShort_t sec, |
e9c06036 | 264 | UShort_t strip) |
265 | { | |
f631f26d | 266 | |
267 | UShort_t Ring = 1; | |
268 | if(ring == 'O') | |
269 | Ring = 0; | |
270 | ||
271 | ||
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)); | |
276 | ||
277 | return hChannel; | |
278 | } | |
279 | ||
280 | //_____________________________________________________________________ | |
cf291b42 | 281 | TGraphErrors* AliFMDGainDA::GetChannel(UShort_t det, |
e9c06036 | 282 | Char_t ring, |
cf291b42 | 283 | UShort_t sec, |
e9c06036 | 284 | UShort_t strip) |
285 | { | |
cf291b42 | 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)); | |
f631f26d | 291 | |
292 | return hChannel; | |
293 | } | |
294 | ||
295 | //_____________________________________________________________________ | |
cf291b42 | 296 | void AliFMDGainDA::UpdatePulseAndADC(UShort_t det, |
297 | Char_t ring, | |
298 | UShort_t sec, | |
299 | UShort_t strip) | |
300 | { | |
f7f0b643 | 301 | |
427e8f99 | 302 | AliFMDParameters* pars = AliFMDParameters::Instance(); |
303 | UInt_t ddl, board,chip,ch; | |
304 | pars->Detector2Hardware(det,ring,sec,strip,ddl,board,chip,ch); | |
22017a7e | 305 | Int_t halfring = GetHalfringIndex(det,ring,board/16); |
306 | ||
f7f0b643 | 307 | if(GetCurrentEvent()> (fNumberOfStripsPerChip*fEventsPerChannel.At(halfring))) |
aea2699c | 308 | return; |
cf291b42 | 309 | if(strip % fNumberOfStripsPerChip) return; |
427e8f99 | 310 | if(((GetCurrentEvent()) % fPulseLength.At(halfring)) && GetCurrentEvent() > 0) return; |
311 | ||
cf291b42 | 312 | Int_t vaChip = strip/fNumberOfStripsPerChip; |
313 | TH1S* hChannel = GetChannelHistogram(det,ring,sec,vaChip); | |
f631f26d | 314 | |
315 | if(!hChannel->GetEntries()) { | |
cf291b42 | 316 | AliWarning(Form("No entries for FMD%d%c, sector %d, strip %d", |
317 | det, ring , sec, strip)); | |
f631f26d | 318 | return; |
319 | } | |
320 | Double_t mean = hChannel->GetMean(); | |
321 | Double_t rms = hChannel->GetRMS(); | |
427e8f99 | 322 | Double_t pulse = Double_t(fCurrentPulse.At(halfring)) * fPulseSize.At(halfring); |
cf291b42 | 323 | Int_t firstBin = hChannel->GetXaxis()->GetFirst(); |
324 | Int_t lastBin = hChannel->GetXaxis()->GetLast(); | |
9c958f2b | 325 | hChannel->GetXaxis()->SetRangeUser(mean-4*rms,mean+4*rms); |
f631f26d | 326 | |
cf291b42 | 327 | mean = hChannel->GetMean(); |
328 | rms = hChannel->GetRMS(); | |
efd39294 | 329 | |
330 | hChannel->GetXaxis()->SetRange(firstBin,lastBin); | |
331 | ||
427e8f99 | 332 | Int_t channelNumber = strip + (GetCurrentEvent()-1)/((fPulseLength.At(halfring)*fHighPulse)/fPulseSize.At(halfring)); |
f631f26d | 333 | |
334 | TGraphErrors* channel = GetChannel(det,ring,sec,channelNumber); | |
335 | ||
427e8f99 | 336 | channel->SetPoint(fCurrentPulse.At(halfring),pulse,mean); |
337 | channel->SetPointError(fCurrentPulse.At(halfring),0,rms); | |
f631f26d | 338 | |
339 | if(fSaveHistograms) { | |
f7f0b643 | 340 | gDirectory->cd(GetStripPath(det,ring,sec,channelNumber)); |
341 | hChannel->Write(Form("%s_pulse_%03d",hChannel->GetName(),(Int_t)pulse)); | |
342 | ||
f631f26d | 343 | } |
22017a7e | 344 | |
f631f26d | 345 | hChannel->Reset(); |
346 | ||
347 | } | |
348 | ||
349 | //_____________________________________________________________________ | |
cf291b42 | 350 | void AliFMDGainDA::ResetPulseAndUpdateChannel() |
351 | { | |
427e8f99 | 352 | fCurrentPulse.Reset(0); |
f631f26d | 353 | } |
354 | ||
355 | //_____________________________________________________________________ | |
cf291b42 | 356 | void AliFMDGainDA::FinishEvent() |
357 | { | |
22017a7e | 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); | |
364 | ||
365 | if( !fPulseLength.At(idx) || !fEventsPerChannel.At(idx)) | |
366 | continue; | |
367 | if(GetCurrentEvent()>0 && ((GetCurrentEvent() % fPulseLength.At(idx)) == 0)) | |
368 | fCurrentPulse.AddAt(fCurrentPulse.At(idx)+1,idx); | |
369 | ||
370 | if(GetCurrentEvent()>0 && ((GetCurrentEvent()) % fEventsPerChannel.At(idx)) == 0) | |
371 | fCurrentPulse.AddAt(0,idx); | |
372 | } | |
373 | } | |
427e8f99 | 374 | } |
f631f26d | 375 | } |
376 | //_____________________________________________________________________ | |
377 | // | |
378 | //EOF | |
379 | // |