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