]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCdataQA.cxx
Adding analysis task involving for TPC calibration
[u/mrichter/AliRoot.git] / TPC / AliTPCdataQA.cxx
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
17 /* $Id$ */
18
19
20 // stl includes
21 #include <iostream>
22
23 using namespace std;
24
25 //Root includes
26 #include <TH1F.h>
27 #include <TH2F.h>
28 #include <TString.h>
29 #include <TMath.h>
30 #include <TF1.h>
31 #include <TRandom.h>
32 #include <TDirectory.h>
33 #include <TFile.h>
34 //AliRoot includes
35 #include "AliRawReader.h"
36 #include "AliRawReaderRoot.h"
37 #include "AliRawReaderDate.h"
38 #include "AliTPCRawStream.h"
39 #include "AliTPCCalROC.h"
40 #include "AliTPCROC.h"
41 #include "AliMathBase.h"
42 #include "TTreeStream.h"
43 #include "AliTPCRawStreamFast.h"
44
45 //date
46 #include "event.h"
47 #include "AliTPCCalPad.h"
48
49 //header file
50 #include "AliTPCdataQA.h"
51
52 ClassImp(AliTPCdataQA)
53
54 AliTPCdataQA::AliTPCdataQA() : /*FOLD00*/
55   TObject(),
56   fFirstTimeBin(60),
57   fLastTimeBin(1000),
58   fAdcMin(1),
59   fAdcMax(100),
60   fOldRCUformat(kTRUE),
61   fROC(AliTPCROC::Instance()),
62   fMapping(NULL),
63   fPedestal(0),
64   fNoise(0),
65   fMaxCharge(0),
66   fMeanCharge(0),
67   fNoThreshold(0),
68   fOverThreshold0(0),
69   fOverThreshold5(0),
70   fOverThreshold10(0),
71   fOverThreshold20(0),
72   fOverThreshold30(0),
73   fEventCounter(0)
74 {
75   //
76   // default constructor
77   //
78
79   fSectorLast  = -1;
80   fRowLast     =  0;
81   fPadLast     =  0;
82   fTimeBinLast =  0;
83   fSignalLast  =  0;
84   fNAboveThreshold = 0;
85 }
86
87
88 //_____________________________________________________________________
89 AliTPCdataQA::AliTPCdataQA(const AliTPCdataQA &ped) : /*FOLD00*/
90   TObject(ped),
91   fFirstTimeBin(ped.GetFirstTimeBin()),
92   fLastTimeBin(ped.GetLastTimeBin()),
93   fAdcMin(ped.GetAdcMin()),
94   fAdcMax(ped.GetAdcMax()),
95   fOldRCUformat(ped.fOldRCUformat),
96   fROC(AliTPCROC::Instance()),
97   fMapping(NULL)
98 {
99   //
100   // copy constructor
101   //
102  
103 }
104
105
106 //_____________________________________________________________________
107 AliTPCdataQA& AliTPCdataQA::operator = (const  AliTPCdataQA &source)
108 {
109   //
110   // assignment operator
111   //
112   if (&source == this) return *this;
113   new (this) AliTPCdataQA(source);
114
115   return *this;
116 }
117
118
119 //_____________________________________________________________________
120 AliTPCdataQA::~AliTPCdataQA() /*FOLD00*/
121 {
122   //
123   // destructor
124   //
125
126   // do not delete fMapping, because we do not own it.
127
128 }
129
130
131
132
133 //_____________________________________________________________________
134 Bool_t AliTPCdataQA::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
135 {
136   //
137   // Event Processing loop - AliTPCRawStream
138   //
139   Bool_t withInput = kFALSE;
140
141   while ( rawStreamFast->NextDDL() ){
142       while ( rawStreamFast->NextChannel() ){
143           Int_t isector  = rawStreamFast->GetSector();                       //  current sector
144           Int_t iRow     = rawStreamFast->GetRow();                          //  current row
145           Int_t iPad     = rawStreamFast->GetPad();                          //  current pad
146
147           while ( rawStreamFast->NextBunch() ){
148             Int_t startTbin = (Int_t)rawStreamFast->GetStartTimeBin();
149             Int_t endTbin = (Int_t)rawStreamFast->GetEndTimeBin();
150
151               for (Int_t iTimeBin = startTbin; iTimeBin < endTbin; iTimeBin++){
152                   Float_t signal=(Float_t)rawStreamFast->GetSignals()[iTimeBin-startTbin];
153                   Update(isector,iRow,iPad,iTimeBin+1,signal);
154                   withInput = kTRUE;
155               }
156           }
157       }
158   }
159
160   return withInput;
161 }
162 //_____________________________________________________________________
163 Bool_t AliTPCdataQA::ProcessEventFast(AliRawReader *rawReader)
164 {
165   //
166   //  Event processing loop - AliRawReader
167   //
168   fEventCounter++;
169   fSectorLast  = -1;
170   AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
171   Bool_t res=ProcessEventFast(rawStreamFast);
172   delete rawStreamFast;
173   return res;
174 }
175
176 //_____________________________________________________________________
177 Bool_t AliTPCdataQA::ProcessEvent(AliTPCRawStream *rawStream)
178 {
179   //
180   // Event Processing loop - AliTPCRawStream
181   //
182
183   rawStream->SetOldRCUFormat(fOldRCUformat);
184
185   Bool_t withInput = kFALSE;
186
187   while (rawStream->Next()) {
188
189     Int_t iSector  = rawStream->GetSector();      //  current ROC
190     Int_t iRow     = rawStream->GetRow();         //  current row
191     Int_t iPad     = rawStream->GetPad();         //  current pad
192     Int_t iTimeBin = rawStream->GetTime();        //  current time bin
193     Float_t signal = rawStream->GetSignal();      //  current ADC signal
194     
195     Update(iSector,iRow,iPad,iTimeBin,signal);
196     withInput = kTRUE;
197   }
198
199   return withInput;
200 }
201
202
203 //_____________________________________________________________________
204 Bool_t AliTPCdataQA::ProcessEvent(AliRawReader *rawReader)
205 {
206   //
207   //  Event processing loop - AliRawReader
208   //
209
210   // if fMapping is NULL the rawstream will crate its own mapping
211   fEventCounter++;
212   fSectorLast  = -1;
213   AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
214   rawReader->Select("TPC");
215   return ProcessEvent(&rawStream);
216 }
217
218
219 //_____________________________________________________________________
220 Bool_t AliTPCdataQA::ProcessEvent(eventHeaderStruct *event)
221 {
222   //
223   //  process date event
224   //
225
226   AliRawReader *rawReader = new AliRawReaderDate((void*)event);
227   Bool_t result=ProcessEvent(rawReader);
228   delete rawReader;
229   return result;
230 }
231
232
233
234 //_____________________________________________________________________
235 void AliTPCdataQA::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
236 {
237   //
238   //  Write class to file
239   //
240
241   TString sDir(dir);
242   TString option;
243
244   if ( append )
245     option = "update";
246   else
247     option = "recreate";
248
249   TDirectory *backup = gDirectory;
250   TFile f(filename,option.Data());
251   f.cd();
252   if ( !sDir.IsNull() ){
253     f.mkdir(sDir.Data());
254     f.cd(sDir);
255   }
256   this->Write();
257   f.Close();
258
259   if ( backup ) backup->cd();
260 }
261
262
263 //_____________________________________________________________________
264 Int_t AliTPCdataQA::Update(const Int_t icsector, /*FOLD00*/
265                                   const Int_t icRow,
266                                   const Int_t icPad,
267                                   const Int_t icTimeBin,
268                                   const Float_t csignal)
269 {
270   //
271   // Signal filling method
272   //
273   if (icTimeBin<fFirstTimeBin) return 0;
274   if (icTimeBin>fLastTimeBin) return 0;
275
276   if (!fMaxCharge) fMaxCharge = new AliTPCCalPad("MaxCharge","MaxCharge");
277   if (!fMeanCharge) fMeanCharge = new AliTPCCalPad("MeanCharge","MeanCharge");
278   if (!fNoThreshold) fNoThreshold = new AliTPCCalPad("NoThreshold","NoThreshold");
279   if (!fOverThreshold0) fOverThreshold0 = new AliTPCCalPad("OverThreshold0","OverThreshold0");
280   if (!fOverThreshold5) fOverThreshold5 = new AliTPCCalPad("OverThreshold5","OverThreshold5");
281   if (!fOverThreshold10) fOverThreshold10 = new AliTPCCalPad("OverThreshold10","OverThreshold10");
282   if (!fOverThreshold20) fOverThreshold20 = new AliTPCCalPad("OverThreshold20","OverThreshold20");
283   if (!fOverThreshold30) fOverThreshold30 = new AliTPCCalPad("OverThreshold30","OverThreshold30");
284   //
285
286   Int_t signal = Int_t(csignal);
287
288   // if pedestal calibrations are loaded subtract pedestals
289   if(fPedestal) {
290
291     Int_t pedestal = Int_t(fPedestal->GetCalROC(icsector)->GetValue(icRow, icPad));
292     if(pedestal<10 || pedestal>90)
293       return 0;
294     signal -= pedestal;
295   }
296
297
298   if (signal >= 0) {
299     
300     Float_t count = fNoThreshold->GetCalROC(icsector)->GetValue(icRow, icPad);
301     fNoThreshold->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
302   }
303
304   // Require at least 3 ADC channels
305   if (signal < 3)
306     return 0;
307
308   // if noise calibrations are loaded require at least 3*sigmaNoise
309   if(fNoise) {
310   
311     Float_t noise = fNoise->GetCalROC(icsector)->GetValue(icRow, icPad);
312
313     if(signal<noise*3)
314       return 0;
315   }
316   //
317   // this signal is ok - now see if the previous signal was connected
318   // this is a bit ugly since the standard decoder goes down in time bins
319   // (10, 9, 8..) while the fast HLT decoder goes up in time bins (1, 2, 3..) 
320   //
321   if(fSectorLast==icsector && fRowLast==icRow && fPadLast==icPad &&
322      fTimeBinLast==icTimeBin+1 || fTimeBinLast==icTimeBin-1)
323     fNAboveThreshold++;
324   else
325     fNAboveThreshold = 1;
326     
327   if(fNAboveThreshold==2) {
328     
329     //
330     // This is the only special case, because before we did not know if we
331     // should store the information
332     //
333     UpdateSignalHistograms(fSectorLast, fRowLast, fPadLast, fTimeBinLast,
334                          fSignalLast);
335   }
336   
337   // keep the information for the next signal
338   fSectorLast  = icsector;
339   fRowLast     = icRow;
340   fPadLast     = icPad;
341   fTimeBinLast = icTimeBin;
342   fSignalLast  = signal;
343   
344   if(fNAboveThreshold==1) // we don't know if this information should be stored
345     return 1;
346   
347   UpdateSignalHistograms(fSectorLast, fRowLast, fPadLast, fTimeBinLast,
348                        fSignalLast);
349
350   return 1;
351 }
352 //_____________________________________________________________________
353 void AliTPCdataQA::UpdateSignalHistograms(const Int_t icsector, /*FOLD00*/
354                                         const Int_t icRow,
355                                         const Int_t icPad,
356                                         const Int_t icTimeBin,
357                                         const Float_t signal)
358 {
359   //
360   // Signal filling method
361   //
362   
363   {
364     Float_t charge = fMeanCharge->GetCalROC(icsector)->GetValue(icRow, icPad);
365     fMeanCharge->GetCalROC(icsector)->SetValue(icRow, icPad, charge + signal);
366   }
367   
368   if (signal>fMaxCharge->GetCalROC(icsector)->GetValue(icRow, icPad)){
369     fMaxCharge->GetCalROC(icsector)->SetValue(icRow, icPad,signal);
370   }
371   
372   if (signal>0){
373     Float_t count = fOverThreshold0->GetCalROC(icsector)->GetValue(icRow, icPad);
374     fOverThreshold0->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
375   };
376   //
377   if (signal>5){
378     Float_t count = fOverThreshold5->GetCalROC(icsector)->GetValue(icRow, icPad);
379     fOverThreshold5->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
380   };
381   if (signal>10){
382     Float_t count = fOverThreshold10->GetCalROC(icsector)->GetValue(icRow, icPad);
383     fOverThreshold10->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
384   };
385   if (signal>20){
386     Float_t count = fOverThreshold20->GetCalROC(icsector)->GetValue(icRow, icPad);
387     fOverThreshold20->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
388   };
389   if (signal>30){
390     Float_t count = fOverThreshold30->GetCalROC(icsector)->GetValue(icRow, icPad);
391     fOverThreshold30->GetCalROC(icsector)->SetValue(icRow, icPad,count+1);
392   };  
393 }
394
395 //_____________________________________________________________________
396 void AliTPCdataQA::Analyse()
397 {
398   //
399   //  Calculate calibration constants
400   //
401   
402   cout << "Analyse called" << endl;
403
404   if(fEventCounter==0) {
405
406     cout << "EventCounter == 0, Cannot analyse" << endl;
407     return;
408   }
409
410   Int_t nTimeBins = fLastTimeBin - fFirstTimeBin +1;
411   
412   cout << "Analyse called" << endl
413        << "EventCounter: " << fEventCounter << endl
414        << "TimeBins: " << nTimeBins << endl;
415
416   fMeanCharge->Divide(fNoThreshold);
417
418   Float_t normalization = 1.0 / Float_t(fEventCounter * nTimeBins);
419   fNoThreshold->Multiply(normalization);  
420   fOverThreshold0->Multiply(normalization);  
421   fOverThreshold5->Multiply(normalization);  
422   fOverThreshold10->Multiply(normalization);  
423   fOverThreshold20->Multiply(normalization);  
424   fOverThreshold30->Multiply(normalization);  
425 }