Update for Ds
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDBase.cxx
CommitLineData
348f80b7 1/**************************************************************************
2 * Copyright(c) 2007-2009, 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#include "AliITSOnlineSDDBase.h"
16#include <TH2F.h>
17#include <TMath.h>
18
19
20///////////////////////////////////////////////////////////////////
21// //
22// Implementation of the class used for SDD baselines //
23// and noise analysis //
24// Origin: F.Prino, Torino, prino@to.infn.it //
25// //
26///////////////////////////////////////////////////////////////////
27
e7610d19 28/* $Id$ */
29
30const Int_t AliITSOnlineSDDBase::fgkMaxCorr=63; // 6 but correction
348f80b7 31
32ClassImp(AliITSOnlineSDDBase)
33//______________________________________________________________________
e7610d19 34 AliITSOnlineSDDBase::AliITSOnlineSDDBase():AliITSOnlineSDD(),fNEvents(0),fMinBaseline(0.),fMaxBaseline(0.),fMinRawNoise(0.),fMaxRawNoise(0.),fNSigmaNoise(0.),fGoldenBaseline(0.),fLowThrFact(0.),fHighThrFact(0.)
348f80b7 35{
36 // default constructor
37 Reset();
38 SetMinBaseline();
39 SetMaxBaseline();
40 SetMinRawNoise();
41 SetMaxRawNoise();
42 SetNSigmaNoise();
e7610d19 43 SetGoldenBaselineValue();
44 SetZeroSuppThresholds();
348f80b7 45}
46//______________________________________________________________________
e7610d19 47AliITSOnlineSDDBase::AliITSOnlineSDDBase(Int_t nddl, Int_t ncarlos, Int_t sid):AliITSOnlineSDD(nddl,ncarlos,sid),fNEvents(0),fMinBaseline(0.),fMaxBaseline(0.),fMinRawNoise(0.),fMaxRawNoise(0.),fNSigmaNoise(0.),fGoldenBaseline(0.),fLowThrFact(0.),fHighThrFact(0.)
348f80b7 48{
49 // default constructor
50 Reset();
51 SetMinBaseline();
52 SetMaxBaseline();
53 SetMinRawNoise();
54 SetMaxRawNoise();
55 SetNSigmaNoise();
e7610d19 56 SetGoldenBaselineValue();
57 SetZeroSuppThresholds();
348f80b7 58}
59//______________________________________________________________________
60AliITSOnlineSDDBase::~AliITSOnlineSDDBase(){
61 // Destructor
62}
63//______________________________________________________________________
64void AliITSOnlineSDDBase::Reset(){
776c19a3 65 // reset all counters
348f80b7 66 fNEvents=0;
67 for(Int_t i=0;i<fgkNAnodes;i++){
68 fGoodAnode[i]=1;
69 fSumBaseline[i]=0.;
70 fSumRawNoise[i]=0.;
71 fSumCMN[i]=0.;
72 }
73}
74//______________________________________________________________________
75void AliITSOnlineSDDBase::ValidateAnodes(){
776c19a3 76 // tag good/bad channels
348f80b7 77 for(Int_t ian=0;ian<fgkNAnodes;ian++){
78 fGoodAnode[ian]=1;
e236b0eb 79 Float_t basel=GetAnodeBaseline(ian);
80 Float_t rawn=GetAnodeRawNoise(ian);
81 Float_t ratio=0.;
82 if(rawn>0) ratio=basel/rawn;
83 if(basel>fMaxBaseline || basel<fMinBaseline) fGoodAnode[ian]=0;
84 else if(rawn>fMaxRawNoise || rawn<fMinRawNoise) fGoodAnode[ian]=0;
85 else if(rawn>fNSigmaNoise*CalcMeanRawNoise()) fGoodAnode[ian]=0;
86 else if(ratio<3.) fGoodAnode[ian]=0;
348f80b7 87 }
88}
89
90//______________________________________________________________________
91void AliITSOnlineSDDBase::AddEvent(TH2F* hrawd){
776c19a3 92 // analyzes one event and adds its ontribution to the various counters
93
348f80b7 94 fNEvents++;
0ddb8c41 95 const Int_t kTimeBins=fLastGoodTB+1;
348f80b7 96 Float_t sum[fgkNAnodes];
97 for(Int_t ian=0;ian<fgkNAnodes;ian++){
98 Float_t sumQ=0.;
99 sum[ian]=0.;
8db9741f 100 Int_t cnt=0;
750296dd 101 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
a8cd2ab2 102 Float_t cbin=hrawd->GetBinContent(itb+1,ian+1);
103 sum[ian]+=cbin;
104 sumQ+=cbin*cbin;
8db9741f 105 cnt++;
348f80b7 106 }
8db9741f 107 sum[ian]/=(Float_t)cnt;
108 sumQ/=(Float_t)cnt;
348f80b7 109 fSumBaseline[ian]+=sum[ian];
110 fSumRawNoise[ian]+=sumQ;
348f80b7 111 }
f2c71038 112 if(fNEvents==1) ValidateAnodes();
348f80b7 113
4ff6aa93 114 Float_t *cmnEven = new Float_t[kTimeBins];
115 Float_t *cmnOdd = new Float_t[kTimeBins];
750296dd 116 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
348f80b7 117 Float_t sumEven=0., sumOdd=0.;
118 Int_t countEven=0,countOdd=0;
119 for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
120 if(!fGoodAnode[ian]) continue;
121 sumEven+=hrawd->GetBinContent(itb+1,ian+1)-sum[ian];
122 countEven++;
123 }
124 for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
125 if(!fGoodAnode[ian]) continue;
126 sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-sum[ian];
127 countOdd++;
128 }
750296dd 129 if(countEven>0) cmnEven[itb]=sumEven/countEven;
130 if(countOdd>0) cmnOdd[itb]=sumOdd/countOdd;
348f80b7 131 }
132 for(Int_t ian=0;ian<fgkNAnodes;ian++){
133 Float_t num=0.,den=0.;
134 if(!fGoodAnode[ian]) continue;
750296dd 135 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
348f80b7 136 Float_t cmnCoef=cmnOdd[itb];
137 if(ian%2==0) cmnCoef=cmnEven[itb];
138 num+=(hrawd->GetBinContent(itb+1,ian+1)-sum[ian])*cmnCoef;
a8cd2ab2 139 den+=cmnCoef*cmnCoef;
348f80b7 140 }
141 if(den!=0) fSumCMN[ian]+=num/den;
142 }
143
144 delete [] cmnEven;
145 delete [] cmnOdd;
146}
147//______________________________________________________________________
e7610d19 148void AliITSOnlineSDDBase::GetMinAndMaxBaseline(Float_t &basMin, Float_t &basMax) const {
149 // fills mininum and maximum baseline values
150 basMin=1008.;
151 basMax=0.;
152 for(Int_t ian=0;ian<fgkNAnodes;ian++){
153 if(!fGoodAnode[ian]) continue;
154 Float_t bas=GetAnodeBaseline(ian);
155 if(bas>0 && bas < basMin) basMin=bas;
156 if(bas>0 && bas > basMax) basMax=bas;
157 }
158}
159//______________________________________________________________________
d8303ac8 160Float_t AliITSOnlineSDDBase::GetMinimumBaseline() const {
3f8beb0b 161 // returns anode with minum baseline value in hybrid
d8303ac8 162 Float_t basMin=1008.;
163 for(Int_t ian=0;ian<fgkNAnodes;ian++){
3f8beb0b 164 if(!fGoodAnode[ian]) continue;
d8303ac8 165 Float_t bas=GetAnodeBaseline(ian);
166 if(bas>0 && bas < basMin) basMin=bas;
167 }
168 return basMin;
169}
170//______________________________________________________________________
beb262b4 171Float_t AliITSOnlineSDDBase::CalcMeanRawNoise() const{
776c19a3 172 // compute mean value of raw noise
348f80b7 173 Float_t meanns=0.;
174 Int_t cnt=0;
175 for(Int_t ian=0;ian<fgkNAnodes;ian++){
176 if(!fGoodAnode[ian]) continue;
177 meanns+=GetAnodeRawNoise(ian);
178 cnt++;
179 }
180 if(cnt>0) meanns/=(Float_t)cnt;
181 return meanns;
182}
183//______________________________________________________________________
e44f571c 184void AliITSOnlineSDDBase::WriteToASCII(){
776c19a3 185 // writes parameters of each channel into an ASCII file
186 // to be then read in the successive step for common mode noise
187 // correction (AliITSOnlineSDDCMN)
188
2c4e6a6a 189 TString outfilnam;
e7610d19 190 Float_t basMin,basMax;
191 GetMinAndMaxBaseline(basMin,basMax);
192 Float_t finalVal=basMin;
193 if(basMin>fGoldenBaseline && basMax<fGoldenBaseline+fgkMaxCorr) finalVal=fGoldenBaseline;
194 if(basMax<basMin+fgkMaxCorr && basMax>fGoldenBaseline+fgkMaxCorr) finalVal=basMax-fgkMaxCorr;
116c6c50 195
e7610d19 196 Float_t avNoise=CalcMeanRawNoise();
197 Int_t thrL=(Int_t)(finalVal+fLowThrFact*avNoise+0.5);
198 Int_t thrH=(Int_t)(finalVal+fHighThrFact*avNoise+0.5);
116c6c50 199 if(CountGoodAnodes()==0) thrH=255;
e7610d19 200
2c4e6a6a 201 outfilnam.Form("SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
202 FILE* outf=fopen(outfilnam.Data(),"w");
e7610d19 203 fprintf(outf,"%d\n",thrH);
204 fprintf(outf,"%d\n",thrL);
348f80b7 205 Float_t corrnoise=2.;
206 for(Int_t ian=0;ian<fgkNAnodes;ian++){
d8303ac8 207 Float_t bas=GetAnodeBaseline(ian);
e7610d19 208 Int_t corr=(Int_t)(bas-finalVal+0.5);
209 if(corr>fgkMaxCorr) corr=fgkMaxCorr; // only 6 bits in jtag for correction
3f8beb0b 210 if(corr<0) corr=0; // avoid negative numbers
e7610d19 211 fprintf(outf,"%d %d %11.6f %d %d %11.6f %11.6f %11.6f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),(Int_t)finalVal,corr,GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),corrnoise);
348f80b7 212 }
213 fclose(outf);
214}