]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSOnlineSDDTP.cxx
First version of the SDD DA calibration classes. AliITSOnlineSDDBase - for measuremen...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSDDTP.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 "AliITSOnlineSDDTP.h"
16 #include <TH2F.h>
17 #include <TMath.h>
18
19
20 ///////////////////////////////////////////////////////////////////
21 //                                                               //
22 // Implemetation of the class SDD Test Pulse analysis            //
23 // Origin: F.Prino, Torino, prino@to.infn.it                     //
24 //                                                               //
25 ///////////////////////////////////////////////////////////////////
26
27
28 ClassImp(AliITSOnlineSDDTP)
29
30 //______________________________________________________________________
31 AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fNEvents(0),fDAQ(0.),fNSigmaGain(0.)
32 {
33   // default constructor
34   Reset();
35   SetNSigmaGain();
36 }
37 //______________________________________________________________________
38 AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t mod, Int_t sid, Float_t xDAQ):AliITSOnlineSDD(mod,sid),fNEvents(0),fDAQ(xDAQ),fNSigmaGain(0.)
39 {
40   // standard constructor
41   Reset();
42   SetNSigmaGain();
43 }
44 //______________________________________________________________________
45 AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
46   // Destructor
47 }
48 //______________________________________________________________________
49 void AliITSOnlineSDDTP::Reset(){
50   fNEvents=0;
51   for(Int_t i=0;i<fgkNAnodes;i++){
52     fGoodAnode[i]=1;
53     fBaseline[i]=0.;
54     fSumTPPeak[i]=0.;
55     fTPPos[i]=0.;
56   }
57   ReadBaselines();
58 }
59
60 //______________________________________________________________________
61 void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
62   // 
63   fNEvents++;
64   Double_t tbmax=(Double_t)hrawd->GetNbinsX();
65   for(Int_t ian=0;ian<fgkNAnodes;ian++){
66     Float_t auxmax=0.;
67     Int_t auxtb=0;
68     if(!fGoodAnode[ian]) continue;
69     for(Int_t itb=0;itb<tbmax;itb++){
70       Float_t cnt=hrawd->GetBinContent(itb+1,ian+1);
71       if(cnt>auxmax){ 
72         auxmax=cnt;
73         auxtb=itb;
74       }
75     }
76     fSumTPPeak[ian]+=auxmax-fBaseline[ian];
77     fTPPos[ian]+=auxtb;
78   }
79 }
80 //______________________________________________________________________
81 void AliITSOnlineSDDTP::ReadBaselines(){
82   // assume baselines and good anodes are taken from previous run
83   Char_t basfilnam[100];
84   sprintf(basfilnam,"SDDbase_step1_mod%03d_sid%d.data",fModuleId,fSide);
85   FILE* basf=fopen(basfilnam,"r");
86   if(basf==0){
87     printf("Baselinefile not present, Set all baselines to 50\n");
88     for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
89       fBaseline[ian]=50.;
90       fGoodAnode[ian]=1;
91     }
92     return;
93   }
94   Int_t n,ok;
95   Float_t base,rms,cmn,corrnoi;
96   for(Int_t ian=0;ian<fgkNAnodes;ian++){
97     fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
98     fBaseline[ian]=base;
99     fGoodAnode[ian]=ok;
100   }
101   fclose(basf);
102 }
103
104 //______________________________________________________________________
105 void AliITSOnlineSDDTP::ValidateAnodes(){
106   Float_t meang,rmsg;
107   StatGain(meang,rmsg);
108   printf("<gain>=%f,rms=%f\n",meang,rmsg);
109   Float_t lowlim=meang-fNSigmaGain*rmsg;
110   Float_t hilim=meang+fNSigmaGain*rmsg;
111
112   for(Int_t ian=0;ian<fgkNAnodes;ian++){
113     if(!fGoodAnode[ian]) continue;
114     if(GetChannelGain(ian)<lowlim||GetChannelGain(ian)>hilim) fGoodAnode[ian]=0;
115   }
116 }
117
118
119 //______________________________________________________________________
120 void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t  &rms){
121   Float_t sum=0.,sumq=0.;
122   Int_t cnt=0;
123   for(Int_t ian=0;ian<fgkNAnodes;ian++){
124     if(!fGoodAnode[ian]) continue;
125     sum+=GetChannelGain(ian);
126     sumq+=TMath::Power(GetChannelGain(ian),2);
127     cnt++;
128   }
129   if(cnt>0){ 
130     mean=sum/(Float_t)cnt;
131     rms=TMath::Sqrt(sumq/(Float_t)cnt-mean*mean);
132   }else{ 
133     mean=0.;
134     rms=0.;
135   }
136   return;
137 }
138
139 //______________________________________________________________________
140 void AliITSOnlineSDDTP::WriteToFXS(){
141   //
142   Char_t basfilnam[100];
143   sprintf(basfilnam,"SDDbase_step1_mod%03d_sid%d.data",fModuleId,fSide);
144   FILE* basf=fopen(basfilnam,"r");
145   Int_t n,ok;
146   Float_t base,rms,cmn,corrnoi;
147   Float_t noise[fgkNAnodes],cmncoef[fgkNAnodes],corrnoise[fgkNAnodes];
148   for(Int_t ian=0;ian<fgkNAnodes;ian++){
149     fscanf(basf,"%d %d %f %f %f %f\n",&n,&ok,&base,&rms,&cmn,&corrnoi);
150     noise[ian]=rms;
151     cmncoef[ian]=cmn;
152     corrnoise[ian]=corrnoi;
153   }
154   fclose(basf);
155   printf("Read All******************\n");
156   Char_t outfilnam[100];
157   sprintf(outfilnam,"SDDbase_mod%03d_sid%d.data",fModuleId,fSide);
158   FILE* outf=fopen(outfilnam,"w");
159   for(Int_t ian=0;ian<fgkNAnodes;ian++){
160     fprintf(outf,"%d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n",ian,IsAnodeGood(ian),fBaseline[ian], noise[ian],cmncoef[ian],corrnoise[ian],GetChannelGain(ian));
161   }
162   fclose(outf);  
163 }
164