1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include "AliITSOnlineSDDCMN.h"
22 ///////////////////////////////////////////////////////////////////
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 //
28 ///////////////////////////////////////////////////////////////////
31 ClassImp(AliITSOnlineSDDCMN)
32 //______________________________________________________________________
33 AliITSOnlineSDDCMN::AliITSOnlineSDDCMN():AliITSOnlineSDD(),fNEvents(0),fLowThreshold(0),fHighThreshold(0),fMinCorrNoise(0.),fMaxCorrNoise(0.),fNSigmaNoise(0.)
35 // default constructor
41 //______________________________________________________________________
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.)
44 // default constructor
50 //______________________________________________________________________
51 AliITSOnlineSDDCMN::~AliITSOnlineSDDCMN(){
54 //______________________________________________________________________
55 void AliITSOnlineSDDCMN::Reset(){
58 for(Int_t i=0;i<fgkNAnodes;i++){
67 //______________________________________________________________________
68 void AliITSOnlineSDDCMN::ReadBaselines(){
69 // assume baselines and good anodes are taken from previous run
71 basfilnam.Form("SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
72 FILE* basf=fopen(basfilnam.Data(),"r");
74 AliWarning(Form("Baseline file not present (ddl %d carlos %d side %d, Set all baselines to 50\n",fDDL,fCarlos,fSide));
75 for(Int_t ian=0;ian<fgkNAnodes;ian++){
78 fOffsetBaseline[ian]=0;
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");
87 Int_t n,ok,eqbase,offbase;
88 Float_t base,rms,cmn,corrnoi;
89 for(Int_t ian=0;ian<fgkNAnodes;ian++){
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");
94 fEqBaseline[ian]=eqbase;
95 fOffsetBaseline[ian]=offbase;
101 //______________________________________________________________________
102 void AliITSOnlineSDDCMN::ValidateAnodes(){
103 // Tag good/bad anodes
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;
111 //______________________________________________________________________
112 TH2F* AliITSOnlineSDDCMN::GetCleanEvent(const TH2F* hrawd) const {
113 // Fills an histogram with counts corrected for common mode noise
115 TH2F* hcorrd=new TH2F("hcorrd","",hrawd->GetNbinsX(),hrawd->GetXaxis()->GetXmin(),hrawd->GetXaxis()->GetXmax(),hrawd->GetNbinsY(),hrawd->GetYaxis()->GetXmin(),hrawd->GetYaxis()->GetXmax());
116 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
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];
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];
129 for(Int_t ian=0;ian<fgkNAnodes;ian++){
130 if(!fGoodAnode[ian]) continue;
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);
140 //______________________________________________________________________
141 void AliITSOnlineSDDCMN::AddEvent(TH2F* hrawd){
142 // analyzes one event and adds its ontribution to the various counters
145 TH2F* hcorrd=GetCleanEvent(hrawd);
147 for(Int_t ian=0;ian<fgkNAnodes;ian++){
148 if(!fGoodAnode[ian]) continue;
151 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
152 Float_t cntdiff=hcorrd->GetBinContent(itb+1,ian+1)-fBaseline[ian];
153 sumQ+=cntdiff*cntdiff;
156 if(cnt != 0)fSumCorrNoise[ian]+=TMath::Sqrt(sumQ/(Float_t)cnt);
160 //______________________________________________________________________
161 Float_t AliITSOnlineSDDCMN::CalcMeanNoise() const{
162 // compute average noise
166 for(Int_t ian=0;ian<fgkNAnodes;ian++){
167 if(!fGoodAnode[ian]) continue;
168 meanns+=GetAnodeCorrNoise(ian);
171 if(cnt>0) meanns/=(Float_t)cnt;
174 //______________________________________________________________________
175 void AliITSOnlineSDDCMN::WriteToASCII(){
176 // writes parameters of each channel into an ASCII file
177 // to be then read by the PULSER DA (AliITSOnlineSDDTP)
180 outfilnam.Form("SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
181 FILE* outf=fopen(outfilnam.Data(),"w");
182 fprintf(outf,"%d\n",fHighThreshold);
183 fprintf(outf,"%d\n",fLowThreshold);
184 for(Int_t ian=0;ian<fgkNAnodes;ian++){
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));
190 //______________________________________________________________________
191 TH1F* AliITSOnlineSDDCMN::GetBaselineAnodeHisto() const {
192 // produce histogram with baseline vs. anode number
194 hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
195 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
196 for(Int_t ian=0;ian<fgkNAnodes;ian++){
197 h->SetBinContent(ian+1,GetAnodeBaseline(ian));
201 //______________________________________________________________________
202 TH1F* AliITSOnlineSDDCMN::GetRawNoiseAnodeHisto() const {
203 // produce histogram with raw noise vs. anode number
205 hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
206 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
207 for(Int_t ian=0;ian<fgkNAnodes;ian++){
208 h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
212 //______________________________________________________________________
213 TH1F* AliITSOnlineSDDCMN::GetCorrNoiseAnodeHisto() const {
214 // produce histogram with corrected noise vs. anode number
216 hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
217 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
218 for(Int_t ian=0;ian<fgkNAnodes;ian++){
219 h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
223 //______________________________________________________________________
224 TH1F* AliITSOnlineSDDCMN::GetCMNCoefAnodeHisto() const {
225 // produce histogram with coefficients for common mode noise subtraction
227 hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
228 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
229 for(Int_t ian=0;ian<fgkNAnodes;ian++){
230 h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
234 //______________________________________________________________________
235 TH1F* AliITSOnlineSDDCMN::GetStatusAnodeHisto() const {
236 // produce histogram with status bit of each anode
238 hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
239 TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
240 for(Int_t ian=0;ian<fgkNAnodes;ian++){
241 h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
245 //______________________________________________________________________
246 TH1F* AliITSOnlineSDDCMN::GetBaselineHisto() const {
247 // produce histogram with baseline distribution
249 hisnam.Form("hdbd%02dc%02ds%d",fDDL,fCarlos,fSide);
250 TH1F* h=new TH1F(hisnam.Data(),"",100,0.,150.);
251 for(Int_t ian=0;ian<fgkNAnodes;ian++){
252 h->Fill(GetAnodeBaseline(ian));
256 //______________________________________________________________________
257 TH1F* AliITSOnlineSDDCMN::GetRawNoiseHisto() const {
258 // produce histogram with raw noise distribution
260 hisnam.Form("hdnd%02dc%02ds%d",fDDL,fCarlos,fSide);
261 TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
262 for(Int_t ian=0;ian<fgkNAnodes;ian++){
263 h->Fill(GetAnodeRawNoise(ian));
267 //______________________________________________________________________
268 TH1F* AliITSOnlineSDDCMN::GetCorrNoiseHisto() const {
269 // produce histogram with corrected noise distribution
271 hisnam.Form("hdcd%02dc%02ds%d",fDDL,fCarlos,fSide);
272 TH1F* h=new TH1F(hisnam.Data(),"",100,0.,8.);
273 for(Int_t ian=0;ian<fgkNAnodes;ian++){
274 h->Fill(GetAnodeCorrNoise(ian));
278 //______________________________________________________________________
279 Bool_t AliITSOnlineSDDCMN::WriteToROOT(TFile *fil){
280 // writes output into a root file
282 AliWarning("Invalid pointer to ROOT file");
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);
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));