coverity fix
[u/mrichter/AliRoot.git] / TPC / testRawReaderFastTPC.C
CommitLineData
a0918fa7 1#include <stdio.h>
2#include <TString.h>
3#include <TROOT.h>
4#include <TStopwatch.h>
5#include <TCanvas.h>
6#include <TFile.h>
7#include <TH2F.h>
8
9#include "AliLog.h"
10
11#include "AliRawReader.h"
12#include "AliRawReaderRoot.h"
13
14#include "AliTPCRawStream.h"
15#include "AliTPCRawStreamFast.h"
16
17#include "AliAltroRawStream.h"
18#include "AliAltroRawStreamFast.h"
19
20#include "AliTPCCalPad.h"
21#include "AliTPCCalROC.h"
22
23/*
24 .L testRawReaderFastTPC.C+
25 testRawReaderFastTPC()
26*/
27
28
29AliTPCCalPad *testRawReaderFastTPC(const Char_t *file="/data.local/data/06000002142000.1A.root")
30{
31
32 AliLog::SetGlobalDebugLevel(0) ;
33 AliLog::SetGlobalLogLevel(AliLog::kFatal);
34// TString filename("/d/alice05/testtpc/raw/pulser/06000002142000.1A.root"); //nfs
35// TString filename("root://lxfs35.gsi.de:1094//alice/testtpc/raw2006/06000001537001.001.root");
36 TString filename(file); //local
37 // on castor: /castor/cern.ch/alice/data/2006/09/18/15/06000002142000.1A.root
38
39
40 printf("File: %s\n", filename.Data());
41
42 AliRawReader *rawReader = new AliRawReaderRoot(filename);
43 if ( !rawReader ) return 0x0;
44 rawReader->RewindEvents();
45
46 AliTPCRawStreamFast *sf = new AliTPCRawStreamFast(rawReader);
47 AliTPCRawStream *s = new AliTPCRawStream(rawReader);
48
a0918fa7 49 s->SetNoAltroMapping(kFALSE);
50
51 Int_t ievent = 0;
52 Int_t ievent2 = 0;
53 Int_t count=0;
54
55 AliTPCCalPad *padOld = new AliTPCCalPad("old","old");
56 AliTPCCalPad *padNew = new AliTPCCalPad("new","new");
57 AliTPCCalPad *padSum = new AliTPCCalPad("sum","sum");
58 AliTPCCalPad *padhadd = new AliTPCCalPad("sum","sum");
59
60 for (Int_t sec=0; sec<72; sec++){
61 AliTPCCalROC *roc = padhadd->GetCalROC(sec);
62 for (UInt_t ch=0; ch<roc->GetNchannels(); ch++)
63 roc->SetValue(ch,-1);
64 }
65
66 TStopwatch timer1;
67 TStopwatch timer2;
68 TStopwatch timer3;
69
70 TCanvas *c1 = (TCanvas*)gROOT->FindObject("c1");
71 if ( !c1 ) c1 = new TCanvas("c1","c1");
72 c1->Clear();
73 c1->Divide(2,2);
74
75
76 while (rawReader->NextEvent()){
77 //old algorithm
78 printf("\nevent: %d (%d)\n",ievent, ievent2);
79
80 Bool_t input=kFALSE;
81
82// if ( ievent != 19 ) input=kTRUE;
83// else{
84 timer1.Start();timer2.Start(kFALSE);
85
86 Int_t sum1 = 0;
87 Int_t sum2 = 0;
88 while ( s->Next() ){
89 AliTPCCalROC *roc = padhadd->GetCalROC(s->GetSector());
90
91 //check if hwaddress gets overwritten
92 if ( roc->GetValue(s->GetRow(), s->GetPad()) == -1 )
93 roc->SetValue(s->GetRow(), s->GetPad(), s->GetHWAddress());
94 else
95 if ( roc->GetValue(s->GetRow(), s->GetPad()) != s->GetHWAddress()){
96 printf("#%.2d: %.2d.%.3d.%.2d,%.4d - old [%.4d] now[%.4d]",
97 ievent, s->GetSector(), s->GetRow(),s->GetPad(), s->GetTime(),
98 (Int_t)roc->GetValue(s->GetRow(), s->GetPad()), s->GetHWAddress());
99 }
100
101
102 Float_t val=padOld->GetCalROC(s->GetSector())->GetValue(s->GetRow(), s->GetPad());
103 padOld->GetCalROC(s->GetSector())->SetValue(s->GetRow(), s->GetPad(), s->GetSignal()+val);
104
105/* if ( ievent == 19 && s->GetSector() == 25 && s->GetRow() == 00 && s->GetPad()==9 ){
106 printf("old | (%.2d.%.3d.%.2d.%.4d | %.3d ): %.3d\n",
107 s->GetSector(), s->GetRow(), s->GetPad(), s->GetTime(), s->GetHWAddress(), s->GetSignal());
108 sum1+=s->GetSignal();
109 }
110*/
111
112 input=kTRUE;
113 count++;
114 }
115 timer1.Stop();timer2.Stop();
116 printf("old -- Time: %.4f (%.4f)\n", timer1.RealTime(), timer1.CpuTime());
117
118 rawReader->Reset();
119
120 //new algorithm
121 timer1.Start();timer3.Start(kFALSE);
122 while ( sf->NextDDL() ){
123 while ( sf->NextChannel() ){
124 UInt_t signal=0;
125 while ( sf->NextBunch() ){
126 for (UInt_t timebin=sf->GetStartTimeBin(); timebin<sf->GetEndTimeBin(); timebin++){
127
128 AliTPCCalROC *roc = padhadd->GetCalROC(sf->GetSector());
129// if ( roc->GetValue(sf->GetRow(), sf->GetPad()) == -1 )
130// roc->SetValue(sf->GetRow(), sf->GetPad(), sf->GetHWAddress());
131// else
132 if ( roc->GetValue(sf->GetRow(), sf->GetPad()) != sf->GetHWAddress()){
133 printf("#%.2d: %.2d.%.3d.%.2d,%.4d - old [%.4d] now[%.4d]",
134 ievent, sf->GetSector(), sf->GetRow(),sf->GetPad(), timebin+1,
135 (Int_t)roc->GetValue(sf->GetRow(), sf->GetPad()), sf->GetHWAddress());
136 }
137 /*
138 Int_t sig = sf->GetSignals()[timebin-sf->GetStartTimeBin()];
139 if ( ievent == 19 && sf->GetSector() == 25 && sf->GetRow() == 00 && sf->GetPad()==9 ){
140 printf("new | (%.2d.%.3d.%.2d.%.4d | %.3d ): %.3d\n",
141 sf->GetSector(), sf->GetRow(), sf->GetPad(), timebin+1, sf->GetHWAddress(), sig );
142 sum2+=sig;
143 }
144 */
145 signal+=sf->GetSignals()[timebin-sf->GetStartTimeBin()];
146 }
147 padNew->GetCalROC(sf->GetSector())->SetValue(sf->GetRow(),sf->GetPad(),signal);
148 }
149 }
150 }
151 timer1.Stop();timer3.Stop();
152 printf("new -- Time: %.4f (%.4f)\n", timer1.RealTime(), timer1.CpuTime());
153
154 printf("sum1: %d, sum2: %d, diff: %d\n",sum1,sum2,sum1-sum2);
155
156 AliTPCCalPad com(*padOld);
157 com.Add(padNew, -1);
158
159 c1->cd(1);
160 padOld->MakeHisto2D(1)->Draw("colz");
161 c1->cd(2);
162 padNew->MakeHisto2D(1)->Draw("colz");
163 c1->cd(3);
164 com.MakeHisto2D(1)->Draw("colz");
165
166 //loop over all sectors, rows, pads
167 for ( UInt_t iSec=0; iSec<72; iSec++ )
168 for ( UInt_t iRow=0; iRow<com.GetCalROC(iSec)->GetNrows(); iRow++ )
169 for ( UInt_t iPad=0; iPad<com.GetCalROC(iSec)->GetNPads(iRow); iPad++){
170 Float_t val = com.GetCalROC(iSec)->GetValue(iRow, iPad);
171 Float_t valo = padNew->GetCalROC(iSec)->GetValue(iRow, iPad);
172 Float_t valn = padOld->GetCalROC(iSec)->GetValue(iRow, iPad);
173 //check if values for old and new algorithm differ
174// if ( val != 0 ){
175 if ( (Int_t)valo != (Int_t)valn ){
176 Float_t hadd = padhadd->GetCalROC(iSec)->GetValue(iRow,iPad);
177 printf("Event: %.2d | (%.2d.%.3d.%.2d | %f ): %.3f\n", ievent, iSec, iRow, iPad, hadd, val);
178 padSum->GetCalROC(iSec)->SetValue(iRow, iPad, padSum->GetCalROC(iSec)->GetValue(iRow, iPad)+1);
179 }
180 com.GetCalROC(iSec)->SetValue(iRow, iPad, 0);
181 padOld->GetCalROC(iSec)->SetValue(iRow, iPad, 0);
182 padNew->GetCalROC(iSec)->SetValue(iRow, iPad, 0);
183 }
184
185
186 c1->cd(4);
187 padSum->MakeHisto2D(1)->Draw("colz");
188
189 c1->Modified();
190 c1->Update();
191 // }// end event sel
192 if (input) ievent++;
193 ievent2++;
194 }
195 TFile f("output.root","recreate");
196 padSum->Write();
197 f.Save();
198 f.Close();
199
200 printf("total old -- Time: %.4f (%.4f)\n", timer2.RealTime(), timer2.CpuTime());
201 printf("total new -- Time: %.4f (%.4f)\n", timer3.RealTime(), timer3.CpuTime());
202
203 delete rawReader;
204 return padSum;
205}
206