]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSOnlineSDDTP.cxx
correcting AliHLTGlobalTriggerDecision::Clear(): using Delete instead of Clear for...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDTP.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 **************************************************************************/
3083967f 15#include <TFile.h>
348f80b7 16#include "AliITSOnlineSDDTP.h"
7f347565 17#include "AliLog.h"
348f80b7 18#include <TH2F.h>
19#include <TMath.h>
20
21
22///////////////////////////////////////////////////////////////////
23// //
24// Implemetation of the class SDD Test Pulse analysis //
25// Origin: F.Prino, Torino, prino@to.infn.it //
26// //
27///////////////////////////////////////////////////////////////////
28
29
30ClassImp(AliITSOnlineSDDTP)
31
32//______________________________________________________________________
e7610d19 33AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fDAC(0.),fLowThreshold(0),fHighThreshold(0),fNSigmaGain(0.),fNSigmaNoise(0.)
348f80b7 34{
35 // default constructor
36 Reset();
37 SetNSigmaGain();
750296dd 38 SetNSigmaNoise();
348f80b7 39}
40//______________________________________________________________________
e7610d19 41AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t nddl, Int_t ncarlos, Int_t sid, Float_t xDAC):AliITSOnlineSDD(nddl,ncarlos,sid),fDAC(xDAC),fLowThreshold(0),fHighThreshold(0),fNSigmaGain(0.),fNSigmaNoise(0.)
348f80b7 42{
43 // standard constructor
44 Reset();
45 SetNSigmaGain();
750296dd 46 SetNSigmaNoise();
348f80b7 47}
48//______________________________________________________________________
49AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
50 // Destructor
51}
52//______________________________________________________________________
53void AliITSOnlineSDDTP::Reset(){
beb262b4 54 //
348f80b7 55 for(Int_t i=0;i<fgkNAnodes;i++){
750296dd 56 fNEvents[i]=0;
348f80b7 57 fGoodAnode[i]=1;
58 fBaseline[i]=0.;
3083967f 59 fCMN[i]=0.;
60 fRawNoise[i]=0.;
61 fCorrNoise[i]=0.;
348f80b7 62 fSumTPPeak[i]=0.;
63 fTPPos[i]=0.;
64 }
65 ReadBaselines();
66}
67
68//______________________________________________________________________
69void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
70 //
348f80b7 71 for(Int_t ian=0;ian<fgkNAnodes;ian++){
72 Float_t auxmax=0.;
73 Int_t auxtb=0;
74 if(!fGoodAnode[ian]) continue;
750296dd 75 for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
348f80b7 76 Float_t cnt=hrawd->GetBinContent(itb+1,ian+1);
77 if(cnt>auxmax){
78 auxmax=cnt;
79 auxtb=itb;
80 }
81 }
750296dd 82 if(auxmax>fBaseline[ian]+fNSigmaNoise*fRawNoise[ian]){
83 fSumTPPeak[ian]+=auxmax-fBaseline[ian];
84 fTPPos[ian]+=auxtb;
85 fNEvents[ian]++;
86 }
348f80b7 87 }
88}
89//______________________________________________________________________
90void AliITSOnlineSDDTP::ReadBaselines(){
91 // assume baselines and good anodes are taken from previous run
92 Char_t basfilnam[100];
979b5a5f 93 sprintf(basfilnam,"SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
348f80b7 94 FILE* basf=fopen(basfilnam,"r");
95 if(basf==0){
2f0c3b74 96 AliWarning(Form("Baseline file not present (ddl %d carlos %d side %d, Set all baselines to 20",fDDL,fCarlos,fSide));
348f80b7 97 for(Int_t ian=0;ian<fgkNAnodes;ian++){
2f0c3b74 98 fBaseline[ian]=20.;
99 fEqBaseline[ian]=20;
d8303ac8 100 fOffsetBaseline[ian]=0;
348f80b7 101 fGoodAnode[ian]=1;
102 }
103 return;
104 }
e7610d19 105 fscanf(basf,"%d\n",&fHighThreshold);
106 fscanf(basf,"%d\n",&fLowThreshold);
d8303ac8 107 Int_t n,ok,eqbase,offbase;
348f80b7 108 Float_t base,rms,cmn,corrnoi;
109 for(Int_t ian=0;ian<fgkNAnodes;ian++){
d8303ac8 110 fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
348f80b7 111 fBaseline[ian]=base;
d8303ac8 112 fEqBaseline[ian]=eqbase;
113 fOffsetBaseline[ian]=offbase;
348f80b7 114 fGoodAnode[ian]=ok;
3083967f 115 fRawNoise[ian]=rms;
116 fCMN[ian]=cmn;
117 fCorrNoise[ian]=corrnoi;
348f80b7 118 }
119 fclose(basf);
120}
121
3083967f 122//______________________________________________________________________
123Bool_t AliITSOnlineSDDTP::IsModuleGood() const{
124 //
125 // Check if there is at least 1 good anode
126 //
127 for(Int_t ian=0;ian<fgkNAnodes;ian++){
128 if(fGoodAnode[ian]) return kTRUE;
129 }
130 return kFALSE;
131}
348f80b7 132//______________________________________________________________________
133void AliITSOnlineSDDTP::ValidateAnodes(){
beb262b4 134 //
348f80b7 135 Float_t meang,rmsg;
136 StatGain(meang,rmsg);
348f80b7 137 Float_t lowlim=meang-fNSigmaGain*rmsg;
138 Float_t hilim=meang+fNSigmaGain*rmsg;
139
140 for(Int_t ian=0;ian<fgkNAnodes;ian++){
141 if(!fGoodAnode[ian]) continue;
142 if(GetChannelGain(ian)<lowlim||GetChannelGain(ian)>hilim) fGoodAnode[ian]=0;
143 }
144}
145
146
147//______________________________________________________________________
148void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t &rms){
beb262b4 149 //
348f80b7 150 Float_t sum=0.,sumq=0.;
151 Int_t cnt=0;
152 for(Int_t ian=0;ian<fgkNAnodes;ian++){
153 if(!fGoodAnode[ian]) continue;
750296dd 154 if(fNEvents[ian]==0) continue;
a8cd2ab2 155 Float_t chgain=GetChannelGain(ian);
156 sum+=chgain;
157 sumq+=chgain*chgain;
348f80b7 158 cnt++;
159 }
160 if(cnt>0){
161 mean=sum/(Float_t)cnt;
9b8481e1 162 Float_t variance=sumq/(Float_t)cnt-mean*mean;
163 if(variance>0.) rms=TMath::Sqrt(variance);
164 else rms = 0;
348f80b7 165 }else{
166 mean=0.;
167 rms=0.;
168 }
169 return;
170}
171
172//______________________________________________________________________
e44f571c 173void AliITSOnlineSDDTP::WriteToASCII(){
348f80b7 174 //
348f80b7 175 Char_t outfilnam[100];
979b5a5f 176 sprintf(outfilnam,"SDDbase_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
348f80b7 177 FILE* outf=fopen(outfilnam,"w");
979b5a5f 178 fprintf(outf,"%d %d %d\n",fCarlos,fSide,IsModuleGood());
e7610d19 179 fprintf(outf,"%d\n",fHighThreshold);
180 fprintf(outf,"%d\n",fLowThreshold);
348f80b7 181 for(Int_t ian=0;ian<fgkNAnodes;ian++){
d8303ac8 182 fprintf(outf,"%d %d %8.3f %d %d %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeEqualizedBaseline(ian),GetAnodeBaselineOffset(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),GetAnodeCorrNoise(ian),GetChannelGain(ian));
348f80b7 183 }
184 fclose(outf);
185}
3083967f 186//______________________________________________________________________
e5b2f7f2 187TH1F* AliITSOnlineSDDTP::GetBaselineAnodeHisto() const {
188 //
189 Char_t hisnam[20];
190 sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
191 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
192 for(Int_t ian=0;ian<fgkNAnodes;ian++){
193 h->SetBinContent(ian+1,GetAnodeBaseline(ian));
194 }
195 return h;
196}
197//______________________________________________________________________
198TH1F* AliITSOnlineSDDTP::GetRawNoiseAnodeHisto() const {
199 //
200 Char_t hisnam[20];
201 sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
202 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
203 for(Int_t ian=0;ian<fgkNAnodes;ian++){
204 h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
205 }
206 return h;
207}
208//______________________________________________________________________
209TH1F* AliITSOnlineSDDTP::GetCorrNoiseAnodeHisto() const {
210 //
211 Char_t hisnam[20];
212 sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
213 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
214 for(Int_t ian=0;ian<fgkNAnodes;ian++){
215 h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
216 }
217 return h;
218}
219//______________________________________________________________________
220TH1F* AliITSOnlineSDDTP::GetCMNCoefAnodeHisto() const {
221//
222 Char_t hisnam[20];
223 sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
224 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
225 for(Int_t ian=0;ian<fgkNAnodes;ian++){
226 h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
227 }
228 return h;
229}
230//______________________________________________________________________
231TH1F* AliITSOnlineSDDTP::GetStatusAnodeHisto() const {
232//
233 Char_t hisnam[20];
234 sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
235 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
236 for(Int_t ian=0;ian<fgkNAnodes;ian++){
237 h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
238 }
239 return h;
240}
241//______________________________________________________________________
242TH1F* AliITSOnlineSDDTP::GetGainAnodeHisto() const {
243//
244 Char_t hisnam[20];
245 sprintf(hisnam,"hgain%02dc%02ds%d",fDDL,fCarlos,fSide);
246 TH1F* h=new TH1F(hisnam,"",256,-0.5,255.5);
247 for(Int_t ian=0;ian<fgkNAnodes;ian++){
248 h->SetBinContent(ian+1,GetChannelGain(ian));
249 }
250 return h;
251}
252//______________________________________________________________________
3083967f 253Bool_t AliITSOnlineSDDTP::WriteToROOT(TFile *fil){
254 //
255 if(fil==0){
256 AliWarning("Invalid pointer to ROOT file");
257 return kFALSE;
258 }
259 Char_t hisnam[20];
260 fil->cd();
979b5a5f 261 sprintf(hisnam,"hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
3083967f 262 TH1F hgood(hisnam,"",256,-0.5,255.5);
979b5a5f 263 sprintf(hisnam,"hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
3083967f 264 TH1F hbase(hisnam,"",256,-0.5,255.5);
979b5a5f 265 sprintf(hisnam,"hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
3083967f 266 TH1F hnois(hisnam,"",256,-0.5,255.5);
979b5a5f 267 sprintf(hisnam,"hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
3083967f 268 TH1F hcmn(hisnam,"",256,-0.5,255.5);
979b5a5f 269 sprintf(hisnam,"hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
3083967f 270 TH1F hcorn(hisnam,"",256,-0.5,255.5);
979b5a5f 271 sprintf(hisnam,"hgain%02dc%02ds%d",fDDL,fCarlos,fSide);
3083967f 272 TH1F hgain(hisnam,"",256,-0.5,255.5);
a7996467 273 sprintf(hisnam,"htptb%02dc%02ds%d",fDDL,fCarlos,fSide);
274 TH1F htptb(hisnam,"",256,-0.5,255.5);
3083967f 275 for(Int_t ian=0;ian<fgkNAnodes;ian++){
276 hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
277 hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
278 hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
279 hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
280 hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
281 hgain.SetBinContent(ian+1,GetChannelGain(ian));
a7996467 282 htptb.SetBinContent(ian+1,GetTimeBinTPPeak(ian));
3083967f 283 }
284 hgood.Write();
285 hbase.Write();
286 hnois.Write();
287 hcmn.Write();
288 hcorn.Write();
289 hgain.Write();
a7996467 290 htptb.Write();
3083967f 291 return kTRUE;
292}
348f80b7 293