New methods for retrieving QA histograms + coding conventions (F.Prino)
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDBase.cxx
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
28
29 ClassImp(AliITSOnlineSDDBase)
30 //______________________________________________________________________
31   AliITSOnlineSDDBase::AliITSOnlineSDDBase():AliITSOnlineSDD(),fNEvents(0),fMinBaseline(0.),fMaxBaseline(0.),fMinRawNoise(0.),fMaxRawNoise(0.),fNSigmaNoise(0.)
32 {
33   // default constructor
34   Reset();
35   SetMinBaseline();
36   SetMaxBaseline();
37   SetMinRawNoise();
38   SetMaxRawNoise();
39   SetNSigmaNoise();
40 }
41 //______________________________________________________________________
42   AliITSOnlineSDDBase::AliITSOnlineSDDBase(Int_t mod, Int_t sid):AliITSOnlineSDD(mod,sid),fNEvents(0),fMinBaseline(0.),fMaxBaseline(0.),fMinRawNoise(0.),fMaxRawNoise(0.),fNSigmaNoise(0.)
43 {
44   // default constructor
45   Reset();
46   SetMinBaseline();
47   SetMaxBaseline();
48   SetMinRawNoise();
49   SetMaxRawNoise();
50   SetNSigmaNoise();
51 }
52 //______________________________________________________________________
53 AliITSOnlineSDDBase::~AliITSOnlineSDDBase(){
54   // Destructor
55 }
56 //______________________________________________________________________
57 void AliITSOnlineSDDBase::Reset(){
58   //
59   fNEvents=0;
60   for(Int_t i=0;i<fgkNAnodes;i++){
61     fGoodAnode[i]=1;
62     fSumBaseline[i]=0.;
63     fSumRawNoise[i]=0.;
64     fSumCMN[i]=0.;
65   }
66 }
67 //______________________________________________________________________
68 void  AliITSOnlineSDDBase::ValidateAnodes(){
69   //
70   for(Int_t ian=0;ian<fgkNAnodes;ian++){
71     fGoodAnode[ian]=1;
72     if(GetAnodeBaseline(ian)>fMaxBaseline || GetAnodeBaseline(ian)<fMinBaseline) fGoodAnode[ian]=0;
73     if(GetAnodeRawNoise(ian)>fMaxRawNoise || GetAnodeRawNoise(ian)<fMinRawNoise) fGoodAnode[ian]=0;
74     if(GetAnodeRawNoise(ian)>fNSigmaNoise*CalcMeanRawNoise()) fGoodAnode[ian]=0;
75   }
76 }
77
78 //______________________________________________________________________
79 void AliITSOnlineSDDBase::AddEvent(TH2F* hrawd){
80   // 
81   fNEvents++;
82   const Int_t kTimeBins=fLastGoodTB-fFirstGoodTB+1;
83   Float_t sum[fgkNAnodes];
84   for(Int_t ian=0;ian<fgkNAnodes;ian++){
85     Float_t sumQ=0.;
86     sum[ian]=0.;
87     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
88       sum[ian]+=hrawd->GetBinContent(itb+1,ian+1);
89       sumQ+=TMath::Power(hrawd->GetBinContent(itb+1,ian+1),2);      
90     }
91     sum[ian]/=(Float_t)kTimeBins;
92     sumQ/=(Float_t)kTimeBins;
93     fSumBaseline[ian]+=sum[ian];
94     fSumRawNoise[ian]+=sumQ;
95     if(fNEvents==1) ValidateAnodes();
96   }
97
98
99   Float_t *cmnEven = new Float_t[kTimeBins];
100   Float_t *cmnOdd  = new Float_t[kTimeBins];
101   for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
102     Float_t sumEven=0., sumOdd=0.;
103     Int_t countEven=0,countOdd=0;
104     for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
105       if(!fGoodAnode[ian]) continue;
106       sumEven+=hrawd->GetBinContent(itb+1,ian+1)-sum[ian];
107       countEven++;
108     }
109     for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
110       if(!fGoodAnode[ian]) continue;
111       sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-sum[ian];
112       countOdd++;
113     }
114     if(countEven>0) cmnEven[itb]=sumEven/countEven;
115     if(countOdd>0) cmnOdd[itb]=sumOdd/countOdd;
116   }
117   for(Int_t ian=0;ian<fgkNAnodes;ian++){
118     Float_t num=0.,den=0.;
119     if(!fGoodAnode[ian]) continue;
120     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
121       Float_t cmnCoef=cmnOdd[itb];
122       if(ian%2==0) cmnCoef=cmnEven[itb];
123       num+=(hrawd->GetBinContent(itb+1,ian+1)-sum[ian])*cmnCoef;
124       den+=TMath::Power(cmnCoef,2);
125     }
126     if(den!=0) fSumCMN[ian]+=num/den;
127   }
128
129   delete [] cmnEven;
130   delete [] cmnOdd;
131 }
132 //______________________________________________________________________
133 Float_t AliITSOnlineSDDBase::CalcMeanRawNoise() const{
134   //
135   Float_t meanns=0.;
136   Int_t cnt=0;
137   for(Int_t ian=0;ian<fgkNAnodes;ian++){
138     if(!fGoodAnode[ian]) continue;  
139     meanns+=GetAnodeRawNoise(ian);
140     cnt++;
141   }
142   if(cnt>0) meanns/=(Float_t)cnt;
143   return meanns;
144 }
145 //______________________________________________________________________
146 void AliITSOnlineSDDBase::WriteToASCII(){
147   //
148   Char_t outfilnam[100];
149   sprintf(outfilnam,"SDDbase_step1_mod%03d_sid%d.data",fModuleId,fSide);
150   FILE* outf=fopen(outfilnam,"w");
151   Float_t corrnoise=2.;
152   for(Int_t ian=0;ian<fgkNAnodes;ian++){
153     fprintf(outf,"%d %d %11.6f %11.6f %11.6f %11.6f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),corrnoise);
154   }
155   fclose(outf);  
156 }