TRD nSigma OADB related new codes and modifications and OADB root file -- Xianguo Lu
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDCMN.cxx
CommitLineData
7f347565 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 **************************************************************************/
e44f571c 15#include <TFile.h>
7f347565 16#include "AliITSOnlineSDDCMN.h"
17#include "AliLog.h"
18#include <TH2F.h>
19#include <TMath.h>
20
21
22///////////////////////////////////////////////////////////////////
23// //
24// Implementation of the class used for analysis of SDD noise //
25// corrected for common mode //
26// Origin: F.Prino, Torino, prino@to.infn.it //
27// //
28///////////////////////////////////////////////////////////////////
29
30
31ClassImp(AliITSOnlineSDDCMN)
32//______________________________________________________________________
e7610d19 33 AliITSOnlineSDDCMN::AliITSOnlineSDDCMN():AliITSOnlineSDD(),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
7f347565 34{
35 // default constructor
36 Reset();
37 SetMinNoise();
38 SetMaxNoise();
39 SetNSigmaNoise();
40}
41//______________________________________________________________________
e7610d19 42 AliITSOnlineSDDCMN::AliITSOnlineSDDCMN(Int_t nddl, Int_t ncarlos, Int_t sid):AliITSOnlineSDD(nddl,ncarlos,sid),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
7f347565 43{
44 // default constructor
45 Reset();
46 SetMinNoise();
47 SetMaxNoise();
48 SetNSigmaNoise();
49}
50//______________________________________________________________________
51AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
52 // Destructor
53}
54//______________________________________________________________________
55void AliITSOnlineSDDCMN::Reset(){
776c19a3 56 // Reset counters
7f347565 57 fNEvents=0;
58 for(Int_t i=0;i<fgkNAnodes;i++){
59 fGoodAnode[i]=1;
60 fBaseline[i]=0.;
3083967f 61 fRawNoise[i]=0.;
7f347565 62 fCMN[i]=0.;
63 fSumCorrNoise[i]=0.;
64 }
65 ReadBaselines();
66}
67//______________________________________________________________________
68void AliITSOnlineSDDCMN::ReadBaselines(){
69 // assume baselines and good anodes are taken from previous run
2c4e6a6a 70 TString basfilnam;
71 basfilnam.Form("SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
72 FILE* basf=fopen(basfilnam.Data(),"r");
7f347565 73 if(basf==0){
e7610d19 74 AliWarning(Form("Baseline file not present (ddl %d carlos %d side %d, Set all baselines to 50\n",fDDL,fCarlos,fSide));
7f347565 75 for(Int_t ian=0;ian<fgkNAnodes;ian++){
76 fBaseline[ian]=50.;
d8303ac8 77 fEqBaseline[ian]=50;
78 fOffsetBaseline[ian]=0;
7f347565 79 fGoodAnode[ian]=1;
80 }
81 return;
82 }
c28423fc 83 Int_t check = fscanf(basf,"%d\n",&fHighThreshold);
84 if(check<1)AliError("Error while reading file with baselines");
85 check = fscanf(basf,"%d\n",&fLowThreshold);
86 if(check<1)AliError("Error while reading file with baselines");
d8303ac8 87 Int_t n,ok,eqbase,offbase;
7f347565 88 Float_t base,rms,cmn,corrnoi;
89 for(Int_t ian=0;ian<fgkNAnodes;ian++){
c28423fc 90 check = fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
91 if(check<1)AliError("Error while reading file with baselines");
7f347565 92 fGoodAnode[ian]=ok;
93 fBaseline[ian]=base;
d8303ac8 94 fEqBaseline[ian]=eqbase;
95 fOffsetBaseline[ian]=offbase;
7f347565 96 fRawNoise[ian]=rms;
97 fCMN[ian]=cmn;
98 }
99 fclose(basf);
100}
101//______________________________________________________________________
102void AliITSOnlineSDDCMN::ValidateAnodes(){
776c19a3 103 // Tag good/bad anodes
7f347565 104 for(Int_t ian=0;ian<fgkNAnodes;ian++){
105 if(!fGoodAnode[ian]) continue;
106 if(GetAnodeCorrNoise(ian)>fMaxCorrNoise || GetAnodeCorrNoise(ian)<fMinCorrNoise) fGoodAnode[ian]=0;
107 if(GetAnodeCorrNoise(ian)>fNSigmaNoise*CalcMeanNoise()) fGoodAnode[ian]=0;
108 }
109}
110
111//______________________________________________________________________
b34fed4e 112TH2F* AliITSOnlineSDDCMN::GetCleanEvent(const TH2F* hrawd) const {
776c19a3 113 // Fills an histogram with counts corrected for common mode noise
114
7f347565 115 TH2F* hcorrd=new TH2F("hcorrd","",hrawd->GetNbinsX(),hrawd->GetXaxis()->GetXmin(),hrawd->GetXaxis()->GetXmax(),hrawd->GetNbinsY(),hrawd->GetYaxis()->GetXmin(),hrawd->GetYaxis()->GetXmax());
750296dd 116 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
7f347565 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)-fBaseline[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)-fBaseline[ian];
127 countOdd++;
128 }
129 for(Int_t ian=0;ian<fgkNAnodes;ian++){
130 if(!fGoodAnode[ian]) continue;
131 Float_t meanN;
132 if(ian%2==0) meanN=sumEven/(Float_t)countEven;
133 else meanN=sumOdd/(Float_t)countOdd;
134 Float_t cntCorr=hrawd->GetBinContent(itb+1,ian+1)-fCMN[ian]*meanN;
135 hcorrd->SetBinContent(itb+1,ian+1,cntCorr);
136 }
137 }
b255f56d 138 return hcorrd;
139}
140//______________________________________________________________________
141void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
776c19a3 142 // analyzes one event and adds its ontribution to the various counters
143
b255f56d 144 fNEvents++;
145 TH2F* hcorrd=GetCleanEvent(hrawd);
7f347565 146
147 for(Int_t ian=0;ian<fgkNAnodes;ian++){
148 if(!fGoodAnode[ian]) continue;
149 Float_t sumQ=0.;
b255f56d 150 Int_t cnt=0;
750296dd 151 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
a8cd2ab2 152 Float_t cntdiff=hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
153 sumQ+=cntdiff*cntdiff;
b255f56d 154 cnt++;
7f347565 155 }
282c838b 156 if(cnt != 0)fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)cnt);
7f347565 157 }
158 delete hcorrd;
159}
160//______________________________________________________________________
beb262b4 161Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
776c19a3 162 // compute average noise
163
7f347565 164 Float_t meanns=0.;
165 Int_t cnt=0;
166 for(Int_t ian=0;ian<fgkNAnodes;ian++){
167 if(!fGoodAnode[ian]) continue;
168 meanns+=GetAnodeCorrNoise(ian);
169 cnt++;
170 }
171 if(cnt>0) meanns/=(Float_t)cnt;
172 return meanns;
173}
174//______________________________________________________________________
e44f571c 175void AliITSOnlineSDDCMN::WriteToASCII(){
776c19a3 176 // writes parameters of each channel into an ASCII file
177 // to be then read by the PULSER DA (AliITSOnlineSDDTP)
178
2c4e6a6a 179 TString outfilnam;
180 outfilnam.Form("SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
181 FILE* outf=fopen(outfilnam.Data(),"w");
e7610d19 182 fprintf(outf,"%d\n",fHighThreshold);
183 fprintf(outf,"%d\n",fLowThreshold);
7f347565 184 for(Int_t ian=0;ian<fgkNAnodes;ian++){
d8303ac8 185 fprintf(outf,"%d %d %8.3f %d %d %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeEqualizedBaseline(ian),GetAnodeBaselineOffset(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),GetAnodeCorrNoise(ian));
7f347565 186 }
187 fclose(outf);
188}
4ff6aa93 189
190//______________________________________________________________________
191TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
776c19a3 192 // produce histogram with baseline vs. anode number
2c4e6a6a 193 TString hisnam;
194 hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
195 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
4ff6aa93 196 for(Int_t ian=0;ian<fgkNAnodes;ian++){
197 h->SetBinContent(ian+1,GetAnodeBaseline(ian));
198 }
199 return h;
200}
201//______________________________________________________________________
202TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
776c19a3 203 // produce histogram with raw noise vs. anode number
2c4e6a6a 204 TString hisnam;
205 hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
206 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
4ff6aa93 207 for(Int_t ian=0;ian<fgkNAnodes;ian++){
208 h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
209 }
210 return h;
211}
212//______________________________________________________________________
213TH1F* AliITSOnlineSDDCMN::GetCorrNoiseAnodeHisto() const {
776c19a3 214 // produce histogram with corrected noise vs. anode number
2c4e6a6a 215 TString hisnam;
216 hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
217 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
4ff6aa93 218 for(Int_t ian=0;ian<fgkNAnodes;ian++){
219 h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
220 }
221 return h;
222}
223//______________________________________________________________________
e5b2f7f2 224TH1F* AliITSOnlineSDDCMN::GetCMNCoefAnodeHisto() const {
776c19a3 225 // produce histogram with coefficients for common mode noise subtraction
2c4e6a6a 226 TString hisnam;
227 hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
228 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
e5b2f7f2 229 for(Int_t ian=0;ian<fgkNAnodes;ian++){
230 h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
231 }
232 return h;
233}
234//______________________________________________________________________
235TH1F* AliITSOnlineSDDCMN::GetStatusAnodeHisto() const {
776c19a3 236 // produce histogram with status bit of each anode
2c4e6a6a 237 TString hisnam;
238 hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
239 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
e5b2f7f2 240 for(Int_t ian=0;ian<fgkNAnodes;ian++){
241 h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
242 }
243 return h;
244}
245//______________________________________________________________________
4ff6aa93 246TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
776c19a3 247 // produce histogram with baseline distribution
2c4e6a6a 248 TString hisnam;
249 hisnam.Form("hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
250 TH1F* h=new TH1F(hisnam.Data(),"",100,0.,150.);
4ff6aa93 251 for(Int_t ian=0;ian<fgkNAnodes;ian++){
252 h->Fill(GetAnodeBaseline(ian));
253 }
254 return h;
255}
256//______________________________________________________________________
257TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
776c19a3 258 // produce histogram with raw noise distribution
2c4e6a6a 259 TString hisnam;
260 hisnam.Form("hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
261 TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
4ff6aa93 262 for(Int_t ian=0;ian<fgkNAnodes;ian++){
263 h->Fill(GetAnodeRawNoise(ian));
264 }
265 return h;
266}
267//______________________________________________________________________
268TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
776c19a3 269 // produce histogram with corrected noise distribution
2c4e6a6a 270 TString hisnam;
271 hisnam.Form("hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
272 TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
4ff6aa93 273 for(Int_t ian=0;ian<fgkNAnodes;ian++){
274 h->Fill(GetAnodeCorrNoise(ian));
275 }
276 return h;
277}
e44f571c 278//______________________________________________________________________
279Bool_t AliITSOnlineSDDCMN::WriteToROOT(TFile *fil){
776c19a3 280 // writes output into a root file
e44f571c 281 if(fil==0){
282 AliWarning("Invalid pointer to ROOT file");
283 return kFALSE;
284 }
2c4e6a6a 285 TString hisnam;
e44f571c 286 fil->cd();
2c4e6a6a 287 hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
288 TH1F hgood(hisnam.Data(),"",256,-0.5,255.5);
289 hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
290 TH1F hbase(hisnam.Data(),"",256,-0.5,255.5);
291 hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
292 TH1F hnois(hisnam.Data(),"",256,-0.5,255.5);
293 hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
294 TH1F hcmn(hisnam.Data(),"",256,-0.5,255.5);
295 hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
296 TH1F hcorn(hisnam.Data(),"",256,-0.5,255.5);
e44f571c 297 for(Int_t ian=0;ian<fgkNAnodes;ian++){
298 hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
299 hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
300 hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
301 hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
302 hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
303 }
304 hgood.Write();
305 hbase.Write();
306 hnois.Write();
307 hcmn.Write();
308 hcorn.Write();
309 return kTRUE;
310}