LCOV - code coverage report
Current view: top level - ITS/ITSrec - AliITSOnlineSDDBase.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 130 0.8 %
Date: 2016-06-14 17:26:59 Functions: 1 15 6.7 %

          Line data    Source code
       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             : /*  $Id$   */
      29             : 
      30             : const Int_t AliITSOnlineSDDBase::fgkMaxCorr=63; // 6 but correction
      31             : 
      32         116 : ClassImp(AliITSOnlineSDDBase)
      33             : //______________________________________________________________________
      34           0 :   AliITSOnlineSDDBase::AliITSOnlineSDDBase():AliITSOnlineSDD(),fNEvents(0),fMinBaseline(0.),fMaxBaseline(0.),fMinRawNoise(0.),fMaxRawNoise(0.),fNSigmaNoise(0.),fGoldenBaseline(0.),fLowThrFact(0.),fHighThrFact(0.)
      35           0 : {
      36             :   // default constructor
      37           0 :   Reset();
      38           0 :   SetMinBaseline();
      39           0 :   SetMaxBaseline();
      40           0 :   SetMinRawNoise();
      41           0 :   SetMaxRawNoise();
      42           0 :   SetNSigmaNoise();
      43           0 :   SetGoldenBaselineValue();
      44           0 :   SetZeroSuppThresholds();
      45           0 : }
      46             : //______________________________________________________________________
      47           0 : AliITSOnlineSDDBase::AliITSOnlineSDDBase(Int_t nddl, Int_t ncarlos, Int_t sid):AliITSOnlineSDD(nddl,ncarlos,sid),fNEvents(0),fMinBaseline(0.),fMaxBaseline(0.),fMinRawNoise(0.),fMaxRawNoise(0.),fNSigmaNoise(0.),fGoldenBaseline(0.),fLowThrFact(0.),fHighThrFact(0.)
      48           0 : {
      49             :   // default constructor
      50           0 :   Reset();
      51           0 :   SetMinBaseline();
      52           0 :   SetMaxBaseline();
      53           0 :   SetMinRawNoise();
      54           0 :   SetMaxRawNoise();
      55           0 :   SetNSigmaNoise();
      56           0 :   SetGoldenBaselineValue();
      57           0 :   SetZeroSuppThresholds();
      58           0 : }
      59             : //______________________________________________________________________
      60           0 : AliITSOnlineSDDBase::~AliITSOnlineSDDBase(){
      61             :   // Destructor
      62           0 : }
      63             : //______________________________________________________________________
      64             : void AliITSOnlineSDDBase::Reset(){
      65             :   // reset all counters
      66           0 :   fNEvents=0;
      67           0 :   for(Int_t i=0;i<fgkNAnodes;i++){
      68           0 :     fGoodAnode[i]=1;
      69           0 :     fSumBaseline[i]=0.;
      70           0 :     fSumRawNoise[i]=0.;
      71           0 :     fSumCMN[i]=0.;
      72             :   }
      73           0 : }
      74             : //______________________________________________________________________
      75             : void  AliITSOnlineSDDBase::ValidateAnodes(){
      76             :   // tag good/bad channels
      77           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
      78           0 :     fGoodAnode[ian]=1;
      79           0 :     Float_t basel=GetAnodeBaseline(ian);
      80           0 :     Float_t rawn=GetAnodeRawNoise(ian);
      81             :     Float_t ratio=0.;
      82           0 :     if(rawn>0) ratio=basel/rawn;
      83           0 :     if(basel>fMaxBaseline || basel<fMinBaseline) fGoodAnode[ian]=0;
      84           0 :     else if(rawn>fMaxRawNoise || rawn<fMinRawNoise) fGoodAnode[ian]=0;
      85           0 :     else if(rawn>fNSigmaNoise*CalcMeanRawNoise()) fGoodAnode[ian]=0;
      86           0 :     else if(ratio<3.) fGoodAnode[ian]=0;
      87             :   }
      88           0 : }
      89             : 
      90             : //______________________________________________________________________
      91             : void AliITSOnlineSDDBase::AddEvent(TH2F* hrawd){
      92             :   // analyzes one event and adds its ontribution to the various counters
      93             : 
      94           0 :   fNEvents++;
      95           0 :   const Int_t kTimeBins=fLastGoodTB+1;
      96           0 :   Float_t sum[fgkNAnodes];
      97           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
      98             :     Float_t sumQ=0.;
      99           0 :     sum[ian]=0.;
     100             :     Int_t cnt=0;
     101           0 :     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
     102           0 :       Float_t cbin=hrawd->GetBinContent(itb+1,ian+1);
     103           0 :       sum[ian]+=cbin;
     104           0 :       sumQ+=cbin*cbin;
     105           0 :       cnt++;
     106             :     }
     107           0 :     if(cnt != 0){
     108           0 :       sum[ian]/=(Float_t)cnt;
     109           0 :       sumQ/=(Float_t)cnt;
     110           0 :     }
     111           0 :     fSumBaseline[ian]+=sum[ian];
     112           0 :     fSumRawNoise[ian]+=sumQ;
     113             :   }
     114           0 :   if(fNEvents==1) ValidateAnodes();
     115             : 
     116           0 :   Float_t *cmnEven = new Float_t[kTimeBins];
     117           0 :   Float_t *cmnOdd  = new Float_t[kTimeBins];
     118           0 :   for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
     119             :     Float_t sumEven=0., sumOdd=0.;
     120             :     Int_t countEven=0,countOdd=0;
     121           0 :     for(Int_t ian=0;ian<fgkNAnodes;ian+=2){
     122           0 :       if(!fGoodAnode[ian]) continue;
     123           0 :       sumEven+=hrawd->GetBinContent(itb+1,ian+1)-sum[ian];
     124           0 :       countEven++;
     125           0 :     }
     126           0 :     for(Int_t ian=1;ian<fgkNAnodes;ian+=2){
     127           0 :       if(!fGoodAnode[ian]) continue;
     128           0 :       sumOdd+=hrawd->GetBinContent(itb+1,ian+1)-sum[ian];
     129           0 :       countOdd++;
     130           0 :     }
     131           0 :     if(countEven>0) cmnEven[itb]=sumEven/countEven;
     132           0 :     if(countOdd>0) cmnOdd[itb]=sumOdd/countOdd;
     133             :   }
     134           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     135             :     Float_t num=0.,den=0.;
     136           0 :     if(!fGoodAnode[ian]) continue;
     137           0 :     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
     138           0 :       Float_t cmnCoef=cmnOdd[itb];
     139           0 :       if(ian%2==0) cmnCoef=cmnEven[itb];
     140           0 :       num+=(hrawd->GetBinContent(itb+1,ian+1)-sum[ian])*cmnCoef;
     141           0 :       den+=cmnCoef*cmnCoef;
     142             :     }
     143           0 :     if(den!=0) fSumCMN[ian]+=num/den;
     144           0 :   }
     145             : 
     146           0 :   delete [] cmnEven;
     147           0 :   delete [] cmnOdd;
     148           0 : }
     149             : //______________________________________________________________________
     150             : void AliITSOnlineSDDBase::GetMinAndMaxBaseline(Float_t &basMin, Float_t &basMax) const {
     151             :   // fills mininum and maximum baseline values
     152           0 :   basMin=1008.;
     153           0 :   basMax=0.;
     154           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     155           0 :     if(!fGoodAnode[ian]) continue;
     156           0 :     Float_t bas=GetAnodeBaseline(ian);
     157           0 :     if(bas>0 && bas < basMin) basMin=bas;
     158           0 :     if(bas>0 && bas > basMax) basMax=bas;
     159           0 :   }
     160           0 : }
     161             : //______________________________________________________________________
     162             : Float_t AliITSOnlineSDDBase::GetMinimumBaseline() const {
     163             :   // returns anode with minum baseline value in hybrid
     164             :   Float_t basMin=1008.;
     165           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     166           0 :     if(!fGoodAnode[ian]) continue;
     167           0 :     Float_t bas=GetAnodeBaseline(ian);
     168           0 :     if(bas>0 && bas < basMin) basMin=bas;
     169           0 :   }
     170           0 :   return basMin;
     171             : }
     172             : //______________________________________________________________________
     173             : Float_t AliITSOnlineSDDBase::CalcMeanRawNoise() const{
     174             :   // compute mean value of raw noise
     175             :   Float_t meanns=0.;
     176             :   Int_t cnt=0;
     177           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     178           0 :     if(!fGoodAnode[ian]) continue;  
     179           0 :     meanns+=GetAnodeRawNoise(ian);
     180           0 :     cnt++;
     181           0 :   }
     182           0 :   if(cnt>0) meanns/=(Float_t)cnt;
     183           0 :   return meanns;
     184             : }
     185             : //______________________________________________________________________
     186             : void AliITSOnlineSDDBase::WriteToASCII(){
     187             :   // writes parameters of each channel into an ASCII file 
     188             :   // to be then read in the successive step for common mode noise
     189             :   // correction (AliITSOnlineSDDCMN)
     190             : 
     191           0 :   TString outfilnam;
     192           0 :   Float_t basMin,basMax;
     193           0 :   GetMinAndMaxBaseline(basMin,basMax);
     194           0 :   Float_t finalVal=basMin;
     195           0 :   if(basMin>fGoldenBaseline && basMax<fGoldenBaseline+fgkMaxCorr) finalVal=fGoldenBaseline;
     196           0 :   if(basMax<basMin+fgkMaxCorr && basMax>fGoldenBaseline+fgkMaxCorr) finalVal=basMax-fgkMaxCorr;
     197             : 
     198           0 :   Float_t avNoise=CalcMeanRawNoise();
     199           0 :   Int_t thrL=(Int_t)(finalVal+fLowThrFact*avNoise+0.5);
     200           0 :   Int_t thrH=(Int_t)(finalVal+fHighThrFact*avNoise+0.5);
     201           0 :   if(CountGoodAnodes()==0) thrH=255;
     202             : 
     203           0 :   outfilnam.Form("SDDbase_step1_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
     204           0 :   FILE* outf=fopen(outfilnam.Data(),"w");
     205           0 :   fprintf(outf,"%d\n",thrH);
     206           0 :   fprintf(outf,"%d\n",thrL);
     207             :   Float_t corrnoise=2.;
     208           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     209           0 :     Float_t bas=GetAnodeBaseline(ian);
     210           0 :     Int_t corr=(Int_t)(bas-finalVal+0.5);
     211           0 :     if(corr>fgkMaxCorr) corr=fgkMaxCorr; // only 6 bits in jtag for correction
     212           0 :     if(corr<0) corr=0; // avoid negative numbers
     213           0 :     fprintf(outf,"%d %d %11.6f %d %d %11.6f %11.6f %11.6f\n",ian,IsAnodeGood(ian),GetAnodeBaseline(ian),(Int_t)finalVal,corr,GetAnodeRawNoise(ian),GetAnodeCommonMode(ian),corrnoise);
     214             :   }
     215           0 :   fclose(outf);  
     216           0 : }

Generated by: LCOV version 1.11