ATO-98 AliTPCRocVoltError3D::AddCorrectionCompact implmented and test included
[u/mrichter/AliRoot.git] / TPC / Base / test / UnitTest.C
CommitLineData
7b83b139 1/*
e7463b27 2 Unit test for some functions classes used in the $ALICE_ROOT/TPC/Base directory:
7b83b139 3 gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/ -I$ALICE_ROOT/include -I$ALICE_ROOT/STEER\
4 -I$ALICE_ROOT/TPC -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD -I$ALICE_ROOT/TOF -I$ALICE_ROOT/RAW -I$ALICE_ROOT/PWG1 -I$ALICE_ROOT/STAT -I$ALICE_ROOT/TPC/Base -I$ALICE_ROOT/TPC/Calib");
5
6 .L $ALICE_ROOT/TPC/Base/test/UnitTest.C+
92e31745 7 UnitTestAliTPCCalPadTree();
69d03c4d 8 TestCorrection_AliTPCExBTwistAddCorrectionCompact();
e7463b27 9 TestCorrection_AliTPCFCVoltError3DAddCorrectionCompact();
10 TestCorrection_AliTPCRocVoltError3DAddCorrectionCompact();
92e31745 11
7b83b139 12*/
13
14#include "TF1.h"
15#include "TMath.h"
16#include "TLinearFitter.h"
17#include "TFile.h"
18#include "AliSysInfo.h"
19#include "TTree.h"
20#include "AliLog.h"
21#include "THn.h"
22#include "TRandom.h"
23#include "AliTPCCalPad.h"
24#include "AliTPCCalibViewer.h"
25#include "AliTPCcalibDButil.h"
69d03c4d 26#include "AliTPCCorrection.h"
27#include "AliTPCComposedCorrection.h"
28#include "AliTPCExBTwist.h"
29#include "AliTPCFCVoltError3D.h"
e7463b27 30#include "AliTPCROCVoltError3D.h"
69d03c4d 31//#include "AliTPCBoundaryVoltError.h"
7b83b139 32
33//
92e31745 34// PARAMETERS to set from outside:
7b83b139 35//
69d03c4d 36TString baseDir="/hera/alice/wiechula/calib/guiTrees"; // TO FIX specification of inout data
7b83b139 37//
38//
39
40
41void UnitTestAliTPCCalPadTree(){
42 //
92e31745 43 // Make a UnitTest of the AliTPCCalPad
44 // a.) TTree functionaility
45 // b.) MedianFilterFunctionality
46 // c.) LTMFilterFunctionality
47 //
7b83b139 48 TObjArray *fArray = new TObjArray(100);
49 TTree * treePad=AliTPCcalibDButil::ConnectGainTrees(baseDir);
92e31745 50 for (Int_t i=0; i<5; i+=2){
69d03c4d 51 AliTPCCalPad * padLx = AliTPCCalPad::MakePadFromTree(treePad,"lx.fElements","Lx",kTRUE);
52 AliTPCCalPad * padLy = AliTPCCalPad::MakePadFromTree(treePad,"ly.fElements","Ly",kTRUE);
53 AliTPCCalPad * padLLx = AliTPCCalPad::MakePadFromTree(treePad,"lx.fElements","LLx",kTRUE);
54 AliTPCCalPad * padLLy = AliTPCCalPad::MakePadFromTree(treePad,"ly.fElements","LLy",kTRUE);
55 AliTPCCalPad * padMax = AliTPCCalPad::MakePadFromTree(treePad,"QA.2010.LHC10d.MaxCharge.fElements","QMax",kTRUE);
56 AliTPCCalPad * padMean = AliTPCCalPad::MakePadFromTree(treePad,"QA.2010.LHC10d.MeanCharge.fElements","QTot",kTRUE);
57 AliTPCCalPad * padMaxL = AliTPCCalPad::MakePadFromTree(treePad,"QA.2010.LHC10d.MaxCharge.fElements","QMax",kTRUE);
58 AliTPCCalPad * padMeanL = AliTPCCalPad::MakePadFromTree(treePad,"QA.2010.LHC10d.MeanCharge.fElements","QTot",kTRUE);
7b83b139 59 if (i>0) {
60 padLx->MedianFilter(i,2*i);
61 padLy->MedianFilter(i,2*i);
92e31745 62 padLLx->LTMFilter(i,2*i,1.00, 0);
63 padLLy->LTMFilter(i,2*i,1.00, 0);
7b83b139 64 padMax->MedianFilter(i,2*i);
65 padMean->MedianFilter(i,2*i);
92e31745 66 padMaxL->LTMFilter(i,2*i,0.8,0);
67 padMeanL->LTMFilter(i,2*i,0.8,0);
7b83b139 68 }
92e31745 69 padLx->SetName(TString::Format("Lx%d",i).Data());
70 padLy->SetName(TString::Format("Ly%d",i).Data());
71 padLLx->SetName(TString::Format("LLx%d",i).Data());
72 padLLy->SetName(TString::Format("LLy%d",i).Data());
7b83b139 73 padMax->SetName(TString::Format("QMax%d",i).Data());
74 padMean->SetName(TString::Format("QTot%d",i).Data());
92e31745 75 padMaxL->SetName(TString::Format("QMaxL%d",i).Data());
76 padMeanL->SetName(TString::Format("QTotL%d",i).Data());
7b83b139 77 fArray->AddLast(padLx);
78 fArray->AddLast(padLy);
92e31745 79 fArray->AddLast(padLLx);
80 fArray->AddLast(padLLy);
7b83b139 81 fArray->AddLast(padMax);
82 fArray->AddLast(padMean);
92e31745 83 fArray->AddLast(padMaxL);
84 fArray->AddLast(padMeanL);
7b83b139 85 }
86 AliTPCCalibViewer::MakeTree("QAtest.root", fArray,0);
87 //
92e31745 88 // 2.) Check invariants
89 //
7b83b139 90 TFile*fout= TFile::Open("QAtest.root");
91 TTree * tree = (TTree*)fout->Get("calPads");
92e31745 92 Int_t isOutM0 = tree->Draw("(Ly2.fElements-Ly0.fElements)>>his0(100,-10,10)","abs((Ly2.fElements-Ly0.fElements))>2","goff");
93 Int_t isOutM1=tree->Draw("(Lx2.fElements-Lx0.fElements)/0.75>>his1(100,-10,10)","abs((Lx2.fElements-Lx0.fElements))>0","goff");
94 printf("IsOut=%d\t%d\n",isOutM0,isOutM1);
95 if ((isOutM0+isOutM1)==0) ::Info("UnitTestAliTPCCalPadTree","MedianTest OK");
96 if (isOutM0||isOutM1) ::Fatal("UnitTestAliTPCCalPadTree","MedianTest FAILED");
97 //
98 Int_t isOutL0 = tree->Draw("(LLy2.fElements-Ly0.fElements)>>his0(100,-10,10)","abs((LLy2.fElements-LLy0.fElements))>0","goff");
99 Int_t isOutL1=tree->Draw("(LLx2.fElements-Lx0.fElements)/0.75>>his1(100,-10,10)","abs((LLx2.fElements-LLx0.fElements))>0","goff");
100 printf("IsOut=%d\t%d\n",isOutL0,isOutL1);
101 if ((isOutL0+isOutL1)==0) ::Info("UnitTestAliTPCCalPadTree","LTMTest OK");
102 if (isOutL0||isOutL1) ::Fatal("UnitTestAliTPCCalPadTree","LTMTest FAILED");
7b83b139 103}
69d03c4d 104
105
106Bool_t TestCorrection_AliTPCExBTwistAddCorrectionCompact(){
107 //
108 //
69d03c4d 109 // 1.) Test ExB twist AddCorrectionCompact
110 //
e7463b27 111 Bool_t isOK[10]={kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
69d03c4d 112 AliTPCComposedCorrection *compCorrTwist = new AliTPCComposedCorrection();
113 AliTPCExBTwist *twistX = new AliTPCExBTwist;
114 AliTPCExBTwist *twistY = new AliTPCExBTwist;
115 twistX->SetXTwist(0.001); // 1 mrad twist in x
116 twistY->SetYTwist(0.001); // 1 mrad twist in x
e7463b27 117 isOK[0]&=compCorrTwist->AddCorrectionCompact(twistX,1);
118 isOK[0]&=compCorrTwist->AddCorrectionCompact(twistY,1);
119 isOK[0]&=compCorrTwist->AddCorrectionCompact(twistY,-1);
120 isOK[0]&=compCorrTwist->AddCorrectionCompact(twistX,-1);
121 isOK[1]=compCorrTwist->GetCorrections()->GetEntries()==1;
69d03c4d 122 AliTPCExBTwist *twistRes=0;
e7463b27 123 if (isOK[1]==kFALSE){
124 isOK[2]=kFALSE;
125 isOK[3]=kFALSE;
126 isOK[4]=kFALSE;
69d03c4d 127 }else{
128 twistRes= dynamic_cast<AliTPCExBTwist *>(compCorrTwist->GetSubCorrection(0));
129 if (twistRes==NULL){
e7463b27 130 isOK[2]=kFALSE;
131 isOK[3]=kFALSE;
132 isOK[4]=kFALSE;
69d03c4d 133 }else{
e7463b27 134 isOK[3] &= (twistRes->GetXTwist()==0);
135 isOK[4] &= (twistRes->GetYTwist()==0);
69d03c4d 136 }
137 }
138 Bool_t res=kTRUE;
e7463b27 139 for (Int_t i=0; i<5; i++) res&=isOK[i];
69d03c4d 140 {
e7463b27 141 if (isOK[0]==kFALSE){
69d03c4d 142 ::Error("TestCorrection_AddCorrectionCompact","AliTPCExBTwist -ADD FAILED");
143 }else{
144 ::Info("TestCorrection_AddCorrectionCompact","AliTPCExBTwist -ADD OK");
145 }
e7463b27 146 if (isOK[1]==kFALSE){
69d03c4d 147 ::Error("TestCorrection_AddCorrectionCompact","AliTPCExBTwist - wrong entries FAILED");
148 }else{
149 ::Info("TestCorrection_AddCorrectionCompact","AliTPCExBTwist - entries OK");
150 }
e7463b27 151 if (isOK[2]==kFALSE || isOK[3]==kFALSE ||isOK[4]==kFALSE ){
69d03c4d 152 ::Error("TestCorrection_AddCorrectionCompact","AliTPCExBTwist - inconsitent entries FAILED");
153 }else{
154 ::Info("TestCorrection_AddCorrectionCompact","AliTPCExBTwist - consistent entries OK");
155 }
156 }
157 return res;
158}
159
160
161Bool_t TestCorrection_AliTPCFCVoltError3DAddCorrectionCompact(){
69d03c4d 162 //
e7463b27 163 // TestCorrection_AliTPCFCVoltError3DAddCorrectionCompact
69d03c4d 164 //
e7463b27 165 const Float_t kEpsilon=0.000001;
69d03c4d 166 Bool_t isOK[10]={kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
167 AliTPCComposedCorrection *compCorrComp = new AliTPCComposedCorrection();
168 AliTPCFCVoltError3D *corr0 = new AliTPCFCVoltError3D;
169 AliTPCFCVoltError3D *corr1 = new AliTPCFCVoltError3D;
170 for (Int_t isec=0; isec<36; isec++){
171 corr0->SetRodVoltShiftA(isec,TMath::Cos(TMath::Pi()*isec/36),kFALSE);
172 corr0->SetRodVoltShiftC(isec,TMath::Cos(TMath::Pi()*isec/36),kFALSE);
173 corr1->SetRodVoltShiftA(isec,TMath::Sin(TMath::Pi()*isec/36),kFALSE);
174 corr1->SetRodVoltShiftC(isec,TMath::Sin(TMath::Pi()*isec/36),kFALSE);
175 corr1->SetCopperRodShiftA(isec,TMath::Sin(TMath::Pi()*isec/36),kFALSE);
176 corr1->SetCopperRodShiftC(isec,TMath::Sin(TMath::Pi()*isec/36),kFALSE);
177 }
178 //
179 isOK[0]&=compCorrComp->AddCorrectionCompact(corr0,1);
180 isOK[0]&=compCorrComp->AddCorrectionCompact(corr1,1);
181 isOK[0]&=compCorrComp->AddCorrectionCompact(corr1,-1);
182 isOK[0]&=compCorrComp->AddCorrectionCompact(corr0,-1);
183 isOK[1]=compCorrComp->GetCorrections()->GetEntries()==1;
184 AliTPCFCVoltError3D *corrRes=0;
185 if (isOK[1]==kFALSE){
186 isOK[2]=kFALSE;
187 isOK[3]=kFALSE;
188 isOK[4]=kFALSE;
189 }else{
190 corrRes= dynamic_cast<AliTPCFCVoltError3D *>(compCorrComp->GetSubCorrection(0));
191 if (corrRes==NULL){
192 isOK[2]=kFALSE;
193 isOK[3]=kFALSE;
194 isOK[4]=kFALSE;
195 }else{
196 for (Int_t isec=0; isec<36; isec++){
197 isOK[3] &=( TMath::Abs(corrRes->GetRodVoltShiftA(isec))<kEpsilon);
198 isOK[4] &=( TMath::Abs(corrRes->GetRodVoltShiftC(isec))<kEpsilon);
199 isOK[5] &=( TMath::Abs(corrRes->GetCopperRodShiftA(isec))<kEpsilon);
200 isOK[6] &=( TMath::Abs(corrRes->GetCopperRodShiftC(isec))<kEpsilon);
201 }
202 }
203 }
204 Bool_t res=kTRUE;
205 for (Int_t i=0; i<5; i++) res&=isOK[i];
206 {
207 if (isOK[0]==kFALSE){
208 ::Error("TestCorrection_AddCorrectionCompact","AliTPCFCVoltError3D -ADD FAILED");
209 }else{
210 ::Info("TestCorrection_AddCorrectionCompact","AliTPCFCVoltError3D -ADD OK");
211 }
212 if (isOK[1]==kFALSE){
213 ::Error("TestCorrection_AddCorrectionCompact","AliTPCFCVoltError3D - wrong entries FAILED");
214 }else{
215 ::Info("TestCorrection_AddCorrectionCompact","AliTPCFCVoltError3D - entries OK");
216 }
217 if (isOK[2]==kFALSE || isOK[3]==kFALSE ||isOK[4]==kFALSE ){
218 ::Error("TestCorrection_AddCorrectionCompact","AliTPCFCVoltError3D - inconsitent entries FAILED");
219 }else{
220 ::Info("TestCorrection_AddCorrectionCompact","AliTPCFCVoltError3D - consistent entries OK");
221 }
222 }
223 return res;
224}
e7463b27 225
226
227
228Bool_t TestCorrection_AliTPCRocVoltError3DAddCorrectionCompact(){
229 //
230 // AliTPCRocVoltError3DAddCorrectionCompact
231 //
232 const Float_t kEpsilon=0.00000001;
233 Bool_t isOK[10]={kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
234 AliTPCComposedCorrection *compCorrROCVoltError3D = new AliTPCComposedCorrection();
235 AliTPCROCVoltError3D *corr0 = new AliTPCROCVoltError3D;
236 AliTPCROCVoltError3D *corr1 = new AliTPCROCVoltError3D;
237 TMatrixD matrixDz(72,3);
238 for (Int_t isec=0; isec<72; isec++){
239 matrixDz(isec,0)=gRandom->Rndm()*0.1;
240 matrixDz(isec,1)=gRandom->Rndm()*0.001;
241 matrixDz(isec,2)=gRandom->Rndm()*0.001;
242 }
243 corr0->SetROCData(&matrixDz);
244 matrixDz*=0.5;
245 corr1->SetROCData(&matrixDz);
246 //
247 isOK[0]&=compCorrROCVoltError3D->AddCorrectionCompact(corr0,1);
248 isOK[0]&=compCorrROCVoltError3D->AddCorrectionCompact(corr1,1);
249 isOK[0]&=compCorrROCVoltError3D->AddCorrectionCompact(corr1,-1);
250 isOK[0]&=compCorrROCVoltError3D->AddCorrectionCompact(corr0,-1);
251 isOK[1]=compCorrROCVoltError3D->GetCorrections()->GetEntries()==1;
252 AliTPCROCVoltError3D *corrRes=0;
253 if (isOK[1]==kFALSE){
254 isOK[2]=kFALSE;
255 isOK[3]=kFALSE;
256 isOK[4]=kFALSE;
257 }else{
258 corrRes= dynamic_cast<AliTPCROCVoltError3D *>(compCorrROCVoltError3D->GetSubCorrection(0));
259 if (corrRes==NULL){
260 isOK[2]=kFALSE;
261 isOK[3]=kFALSE;
262 isOK[4]=kFALSE;
263 }else{
264 isOK[3]=TMath::Abs(corrRes->GetMatrix()->Sum())<kEpsilon;
265 }
266 }
267 Bool_t res=kTRUE;
268 for (Int_t i=0; i<5; i++) res&=isOK[i];
269 {
270 if (isOK[0]==kFALSE){
271 ::Error("TestCorrection_AddCorrectionCompact","AliTPCROCVoltError3D -ADD FAILED");
272 }else{
273 ::Info("TestCorrection_AddCorrectionCompact","AliTPCROCVoltError3D -ADD OK");
274 }
275 if (isOK[1]==kFALSE){
276 ::Error("TestCorrection_AddCorrectionCompact","AliTPCROCVoltError3D - wrong entries FAILED");
277 }else{
278 ::Info("TestCorrection_AddCorrectionCompact","AliTPCROCVoltError3D - entries OK");
279 }
280 if (isOK[2]==kFALSE || isOK[3]==kFALSE ||isOK[4]==kFALSE ){
281 ::Error("TestCorrection_AddCorrectionCompact","AliTPCROCVoltError3D - inconsitent entries FAILED");
282 }else{
283 ::Info("TestCorrection_AddCorrectionCompact","AliTPCROCVoltError3D - consistent entries OK");
284 }
285 }
286 return res;
287}