adding libAliHLTTRD.so as dependency for libAliHLTTrigger.so
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibRaw.cxx
CommitLineData
ddeb9c4f 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id: $ */
17
18////////////////////////////////////////////////////////////////////////////////////////
19// //
20// Implementation of the TPC Raw drift velocity and Altro L1 Phase calibration //
21// //
22// Origin: Jens Wiechula, J.Wiechula@gsi.de //
23// //
24////////////////////////////////////////////////////////////////////////////////////////
25//
26//
27// *************************************************************************************
28// * Class Description *
29// *************************************************************************************
30/*
31
32----example---
33TFile f("CalibAltro.root");
34AliTPCCalibRaw *al=(AliTPCCalibRaw*)f.Get(f.GetListOfKeys()->At(0)->GetName())
35{
36TCanvas *c1=(TCanvas*)gROOT->FindObject("c1");
37if (!c1) c1=new TCanvas("c1","c1");
38c1->Clear();
39
40TH2F h2f("h2","h2;RCU;fail",216,0,216,al->GetNevents(),0,al->GetNevents());
41Bool_t first=kTRUE;
42Int_t i,iev;
43for (i=0;i<216;++i) {
44 TVectorF *v=al->GetALTROL1PhaseFailEventsRCU(i);
45 if (!v) continue;
46 for (iev=0;iev<al->GetNevents();++iev) {
47 h2f->SetBinContent(i+1,iev+1,(*v)(iev));
48 }
49// TH1F h(*v);
50// h.SetLineColor(i/216.*50+50);
51// ((TH1F*)h.Clone(Form("h%d",i)))->Draw(first?"":"same");
52// c1->Modified();
53// c1->Update();
54 first=kFALSE;
55}
56h2f->Draw("col");
57}
58
59*/
60
61
62
63//Root includes
64#include <TH2C.h>
be3dbaa0 65#include <TH1F.h>
f113dfeb 66#include <TMap.h>
67#include <TObjString.h>
ddeb9c4f 68
69//AliRoot includes
70#include "AliTPCCalROC.h"
71#include "AliAltroRawStream.h"
72#include "AliLog.h"
ddeb9c4f 73//class header
74#include "AliTPCCalibRaw.h"
75
76ClassImp(AliTPCCalibRaw)
77
78AliTPCCalibRaw::AliTPCCalibRaw() :
79 AliTPCCalibRawBase(),
80 fPeakDetMinus(1),
81 fPeakDetPlus(2),
82 fNFailL1Phase(0),
be3dbaa0 83 fNFailL1PhaseEvent(0),
ddeb9c4f 84 fFirstTimeStamp(0),
85 fNSecTime(600), //default 10 minutes
86 fNBinsTime(60), //default 60*10 minutes = 10 hours
87 fPadProcessed(kFALSE),
88 fCurrentChannel(-1),
89 fCurrentSector(-1),
90 fLastSector(-2),
91 fCurrentRow(-1),
92 fCurrentPad(-1),
93 fLastTimeBinProc(0),
94 fPeakTimeBin(0),
95 fLastSignal(0),
96 fNOkPlus(0),
97 fNOkMinus(0),
98 fArrCurrentPhaseDist(4),
be3dbaa0 99 fArrCurrentPhase(kNRCU),
100 fArrFailEventNumber(100),
ddeb9c4f 101 fArrALTROL1Phase(1000),
be3dbaa0 102 fArrALTROL1PhaseEvent(kNRCU),
103 fArrALTROL1PhaseFailEvent(kNRCU),
ddeb9c4f 104 fHnDrift(0x0)
105{
106 //
107 // Default ctor
108 //
109 SetNameTitle("AliTPCCalibRaw","AliTPCCalibRaw");
110 CreateDVhist();
be3dbaa0 111 for (Int_t ircu=0;ircu<kNRCU;++ircu) fArrCurrentPhase.GetMatrixArray()[ircu]=-1;
ddeb9c4f 112 fFirstTimeBin=850;
f113dfeb 113 fLastTimeBin=1020;
ddeb9c4f 114}
115//_____________________________________________________________________
f113dfeb 116AliTPCCalibRaw::AliTPCCalibRaw(const TMap *config) :
117AliTPCCalibRawBase(),
118fPeakDetMinus(1),
119fPeakDetPlus(2),
120fNFailL1Phase(0),
be3dbaa0 121fNFailL1PhaseEvent(0),
f113dfeb 122fFirstTimeStamp(0),
123fNSecTime(600), //default 10 minutes
124fNBinsTime(60), //default 60*10 minutes = 10 hours
125fPadProcessed(kFALSE),
126fCurrentChannel(-1),
127fCurrentSector(-1),
128fLastSector(-2),
129fCurrentRow(-1),
130fCurrentPad(-1),
131fLastTimeBinProc(0),
132fPeakTimeBin(0),
133fLastSignal(0),
134fNOkPlus(0),
135fNOkMinus(0),
136fArrCurrentPhaseDist(4),
be3dbaa0 137fArrCurrentPhase(kNRCU),
138fArrFailEventNumber(100),
f113dfeb 139fArrALTROL1Phase(1000),
be3dbaa0 140fArrALTROL1PhaseEvent(kNRCU),
141fArrALTROL1PhaseFailEvent(kNRCU),
f113dfeb 142fHnDrift(0x0)
143{
144 //
145 // Default ctor
146 //
147 SetNameTitle("AliTPCCalibRaw","AliTPCCalibRaw");
148 CreateDVhist();
be3dbaa0 149 for (Int_t ircu=0;ircu<kNRCU;++ircu) fArrCurrentPhase.GetMatrixArray()[ircu]=-1;
f113dfeb 150 fFirstTimeBin=850;
151 fLastTimeBin=1020;
152 if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
153 if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
154}
155
156//_____________________________________________________________________
ddeb9c4f 157AliTPCCalibRaw::~AliTPCCalibRaw()
158{
159 //
160 // dtor
161 //
162 delete fHnDrift;
163}
164//_____________________________________________________________________
165// AliTPCCalibRaw& AliTPCCalibRaw::operator = (const AliTPCCalibRaw &source)
166// {
167// //
168// // assignment operator
169// //
170// if (&source == this) return *this;
171// new (this) AliTPCCalibRaw(source);
172//
173// return *this;
174// }
175
176//_____________________________________________________________________
177Int_t AliTPCCalibRaw::Update(const Int_t isector, const Int_t iRow, const Int_t iPad,
178 const Int_t iTimeBin, const Float_t signal)
179{
180 //
181 // Data filling method
182 //
183 if (iRow<0) return 0;
184 if (iPad<0) return 0;
185 if (iTimeBin<0) return 0;
186 if (!fFirstTimeStamp) fFirstTimeStamp=GetTimeStamp();
ddeb9c4f 187 if ( (iTimeBin>fLastTimeBin) || (iTimeBin<fFirstTimeBin) ) return 0;
188 //don't process edge pads
189 if (IsEdgePad(isector,iRow,iPad)) return 0;
190// Double_t x[kHnBinsDV]={1,isector,0};
191// fHnDrift->Fill(x);
192 Int_t iChannel = fROC->GetRowIndexes(isector)[iRow]+iPad; // global pad position in sector
193 if (fCurrentChannel==iChannel){
194 if (fPadProcessed) return 0;
195 } else {
196 fPadProcessed=kFALSE;
197 fNOkPlus=0;
198 fNOkMinus=0;
199 fPeakTimeBin=0;
200 fLastSignal=0;
201 }
202// Double_t x2[kHnBinsDV]={2,isector,0};
203// fHnDrift->Fill(x2);
204
205
206 if (signal>fLastSignal) ++fNOkPlus;
207 else if(signal<fLastSignal && fNOkPlus>=fPeakDetPlus){
208 ++fNOkMinus;
209 if (!fPeakTimeBin) fPeakTimeBin=fLastTimeBinProc;
210 if ( fNOkMinus>=fPeakDetMinus ) {
211 Double_t x[kHnBinsDV]={fPeakTimeBin,isector,(fTimeStamp-fFirstTimeStamp)/fNSecTime};
212 fHnDrift->Fill(x);
213 }
214 } else {
215 fNOkPlus=0;
216 fNOkMinus=0;
217 fPeakTimeBin=0;
218 fLastSignal=0;
219 }
220
221 fLastTimeBinProc=iTimeBin;
222 fLastSignal=TMath::Nint(signal);
223 fCurrentChannel = iChannel;
224 return 0;
225}
226//_____________________________________________________________________
5312f439 227void AliTPCCalibRaw::UpdateDDL(){
228 //
229 // fill ALTRO L1 information
230 //
be3dbaa0 231
232 // current phase
233 Int_t phase=(Int_t)(GetL1PhaseTB()*4.);
234 //Fill pahse information of current rcu and event
235 fArrCurrentPhase.GetMatrixArray()[fCurrDDLNum]=phase;
236 //increase phase counter
237 ++((fArrCurrentPhaseDist.GetMatrixArray())[phase]);
5312f439 238
239}
240//_____________________________________________________________________
ddeb9c4f 241void AliTPCCalibRaw::ResetEvent()
242{
243 //
244 // Reset event counters
245 //
246
247 fCurrentChannel=-1;
248 fArrCurrentPhaseDist.Zero();
249}
250//_____________________________________________________________________
251void AliTPCCalibRaw::EndEvent()
252{
253 //
254 // End event analysis
255 //
256
257
258 //find phase of the current event
259 Int_t phaseMaxEntries=-1;
260 Int_t maxEntries=0;
261 for (Int_t i=0;i<fArrCurrentPhaseDist.GetNrows();++i){
262 Int_t entries=(Int_t)fArrCurrentPhaseDist[i];
263 if (maxEntries<entries) {
264 maxEntries=entries;
265 phaseMaxEntries=i;
266 }
267 }
268 // store phase of current event
269 if (fArrALTROL1Phase.GetNrows()<=GetNevents())
270 fArrALTROL1Phase.ResizeTo(GetNevents()+1000);
271 (fArrALTROL1Phase.GetMatrixArray())[GetNevents()]=phaseMaxEntries;
272
273 //loop over RCUs and test failures
be3dbaa0 274 UInt_t fail=0;
275 for (Int_t ircu=0;ircu<kNRCU;++ircu){
276 Int_t phase=(Int_t)fArrCurrentPhase[ircu];
277 if (phase<0) continue;
278 if (phase!=phaseMaxEntries){
279 TVectorF *arr=MakeArrL1PhaseRCU(fCurrDDLNum,kTRUE);
280 if (arr->GetNrows()<=(Int_t)fNFailL1PhaseEvent) arr->ResizeTo(arr->GetNrows()+100);
281 (arr->GetMatrixArray())[fNFailL1PhaseEvent]=phase;
ddeb9c4f 282 ++fNFailL1Phase;
be3dbaa0 283 fail=1;
ddeb9c4f 284 }
be3dbaa0 285 //reset current phase information
286 fArrCurrentPhase[ircu]=-1;
287 }
288 if (fail){
289 if (fArrFailEventNumber.GetNrows()<=(Int_t)fNFailL1PhaseEvent) fArrFailEventNumber.ResizeTo(fArrFailEventNumber.GetNrows()+100);
290 fArrFailEventNumber.GetMatrixArray()[fNFailL1PhaseEvent]=GetNevents();
ddeb9c4f 291 }
be3dbaa0 292 fNFailL1PhaseEvent+=fail;
ddeb9c4f 293 IncrementNevents();
294}
295//_____________________________________________________________________
296TH2C *AliTPCCalibRaw::MakeHistL1RCUEvents(Int_t type)
297{
298 // Create a 2D histo RCU:Events indicating the there was a deviation
299 // from the mean L1 phase of the event
300 //
301 //type: 0=Failures, 1=Phases
be3dbaa0 302
303 //number of relavant events, depending on version
304 Int_t nevents=GetNevents();
305 //check version
306 Bool_t newVersion=kFALSE;
307 for (Int_t ircu=0; ircu<kNRCU; ++ircu){
308 const TVectorF *v=GetALTROL1PhaseEventsRCU(ircu);
309 if (!v) continue;
310 if (v->GetNrows()==fNFailL1PhaseEvent){
311 newVersion=kTRUE;
312 nevents=fNFailL1PhaseEvent;
313 }
314 break;
315 }
316 TH2C *h2 = new TH2C("hL1FailRCUEvents","L1 Failures;RCU;Event",kNRCU,0,kNRCU,nevents,0,nevents);
5312f439 317 Int_t add=0;
be3dbaa0 318 for (Int_t ircu=0;ircu<kNRCU;++ircu) {
319 const TVectorF *v=GetALTROL1PhaseEventsRCU(ircu);
5312f439 320 if (type==0){
5312f439 321 add=1;
322 h2->SetMinimum(0);
323 h2->SetMaximum(2);
324 } else if (type==1) {
5312f439 325 add=0;
326 h2->SetMinimum(0);
327 h2->SetMaximum(4);
328 }
ddeb9c4f 329 if (!v) continue;
be3dbaa0 330 for (Int_t iev=0;iev<nevents;++iev) {
331 Float_t val=(*v)(iev);
332 Float_t phase=fArrALTROL1Phase.GetMatrixArray()[iev];
333 if (newVersion) {
334 Int_t event=(Int_t)fArrFailEventNumber.GetMatrixArray()[iev];
335 phase=fArrALTROL1Phase.GetMatrixArray()[event];
336 }
337 if (type==0) val=(val!=phase);
338 h2->SetBinContent(ircu+1,iev+1,val+add);
ddeb9c4f 339 }
340 }
341 return h2;
342}
343//_____________________________________________________________________
be3dbaa0 344TH1F *AliTPCCalibRaw::MakeHistL1PhaseDist()
345{
346 //
347 // L1 phase distribution. Should be flat in ideal case
348 //
349 TH1F *h=new TH1F("L1phaseDist","Normalized L1 phase distribution;phase;fraction of events",4,0,4);
350 h->Sumw2();
351 for (Int_t iev=0;iev<GetNevents();++iev) h->Fill(fArrALTROL1Phase.GetMatrixArray()[iev]);
352 if (GetNevents()>0) h->Scale(1./GetNevents());
353 h->SetMinimum(0);
354 h->SetMaximum(1);
355 return h;
356}
357//_____________________________________________________________________
358TVectorF *AliTPCCalibRaw::MakeVectL1PhaseDist()
359{
360 //
361 // L1 phase distribution. Should be flat in ideal case
362 //
363 TVectorF *v=new TVectorF(4);
364 for (Int_t iev=0;iev<GetNevents();++iev) {
365 Int_t phase=(Int_t)fArrALTROL1Phase.GetMatrixArray()[iev];
366 ((v->GetMatrixArray())[phase])+=1./GetNevents();
367 }
368 return v;
369}
370//_____________________________________________________________________
ddeb9c4f 371TH2C *AliTPCCalibRaw::MakeHistL1RCUEventsIROC(Int_t type)
372{
373 //
374 // Create a 2D histo RCU:Events indicating the there was a deviation
375 // from the mean L1 phase of the event
376 //
377 TH2C *h2 = new TH2C("hL1FailRCUEventsIROC","L1 Failures IROCs;RCU;Event",72,0,36,GetNevents(),0,GetNevents());
378 for (Int_t ircu=0;ircu<72;++ircu) {
379 const TVectorF *v=0;
380 if (type==0) v=GetALTROL1PhaseFailEventsRCU(ircu);
381 else if (type==1) v=GetALTROL1PhaseEventsRCU(ircu);
382 if (!v) continue;
383 for (Int_t iev=0;iev<GetNevents();++iev) {
5312f439 384 h2->SetBinContent(ircu+1,iev+1,(*v)(iev));
ddeb9c4f 385 }
386 }
387 return h2;
388}
389//_____________________________________________________________________
390TH2C *AliTPCCalibRaw::MakeHistL1RCUEventsOROC(Int_t type)
391{
392 //
393 // Create a 2D histo RCU:Events indicating the there was a deviation
394 // from the mean L1 phase of the event
395 //
396 TH2C *h2 = new TH2C("hL1FailRCUEventsOROC","L1 Failures OROCs;RCU;Event",144,0,36,GetNevents(),0,GetNevents());
be3dbaa0 397 for (Int_t ircu=72;ircu<kNRCU;++ircu) {
ddeb9c4f 398 const TVectorF *v=0;
399 if (type==0) v=GetALTROL1PhaseFailEventsRCU(ircu);
400 else if (type==1) v=GetALTROL1PhaseEventsRCU(ircu);
401 if (!v) continue;
402 for (Int_t iev=0;iev<GetNevents();++iev) {
5312f439 403 h2->SetBinContent(ircu-72+1,iev+1,(*v)(iev));
ddeb9c4f 404 }
405 }
406 return h2;
407}
408//_____________________________________________________________________
409void AliTPCCalibRaw::CreateDVhist()
410{
411 //
412 // Setup the HnSparse for the drift velocity determination
413 //
414 if (fHnDrift) return;
415 //HnSparse bins
416 //time bin, roc, time
f113dfeb 417 Int_t bins[kHnBinsDV] = {fLastTimeBin-fFirstTimeBin, 72, fNBinsTime};
418 Double_t xmin[kHnBinsDV] = {fFirstTimeBin,0,0};
419 Double_t xmax[kHnBinsDV] = {fLastTimeBin,72,fNBinsTime};
ddeb9c4f 420 fHnDrift=new THnSparseI("fHnDrift",Form("Drift velocity using last time bin;time bin[#times 100ns];ROC;Time bin [#times %us]",fNSecTime),kHnBinsDV, bins, xmin, xmax);
421
422}
423//_____________________________________________________________________
424void AliTPCCalibRaw::Analyse()
425{
426 //
427 // Analyse Data
428 //
429
430 //resize arrays
431 fArrALTROL1Phase.ResizeTo(GetNevents());
be3dbaa0 432 for (Int_t ircu=0;ircu<kNRCU;++ircu){
ddeb9c4f 433 TVectorF *arr=MakeArrL1PhaseRCU(ircu);//MakeArrL1PhaseRCU(ircu);
434 if (!arr) continue;
be3dbaa0 435 arr->ResizeTo(fNFailL1PhaseEvent);
436 fArrFailEventNumber.ResizeTo(fNFailL1PhaseEvent);
437// TVectorF *arrF=MakeArrL1PhaseFailRCU(ircu);
438// arrF->ResizeTo(1);
ddeb9c4f 439 }
440
441 //Analyse drift velocity
442
443}
444