LCOV - code coverage report
Current view: top level - ITS/ITSrec - AliITSOnlineSDDTP.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 190 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 22 4.5 %

          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 <TFile.h>
      16             : #include "AliITSOnlineSDDTP.h"
      17             : #include "AliLog.h"
      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             : 
      30         116 : ClassImp(AliITSOnlineSDDTP)
      31             : 
      32             : //______________________________________________________________________
      33           0 : AliITSOnlineSDDTP::AliITSOnlineSDDTP():AliITSOnlineSDD(),fDAC(0.),fLowThreshold(0),fHighThreshold(0),fValidateOption(1),fMinGain(0.001),fMaxGain(9.),fNSigmaGain(0.),fToleranceGain(0.3),fNSigmaNoise(0.)
      34           0 : {
      35             :   // default constructor
      36           0 :   Reset();
      37           0 :   SetValidationOption(1);
      38           0 :   SetMaxNSigmaForValid(9.);
      39           0 :   SetMaxRelDiffForValid(0.3);
      40           0 :   SetNSigmaNoise();
      41           0 : }
      42             : //______________________________________________________________________
      43           0 : AliITSOnlineSDDTP::AliITSOnlineSDDTP(Int_t nddl, Int_t ncarlos, Int_t sid, Float_t xDAC):AliITSOnlineSDD(nddl,ncarlos,sid),fDAC(xDAC),fLowThreshold(0),fHighThreshold(0),fValidateOption(1),fMinGain(0.001),fMaxGain(9.),fNSigmaGain(0.),fToleranceGain(0.3),fNSigmaNoise(0.)
      44           0 : {
      45             :   // standard constructor
      46           0 :   Reset();
      47           0 :   SetValidationOption(1);
      48           0 :   SetMaxNSigmaForValid(9.);
      49           0 :   SetMaxRelDiffForValid(0.3);
      50           0 :   SetNSigmaNoise();
      51           0 : }
      52             : //______________________________________________________________________
      53           0 : AliITSOnlineSDDTP::~AliITSOnlineSDDTP(){
      54             :   // Destructor
      55           0 : }
      56             : //______________________________________________________________________
      57             : void AliITSOnlineSDDTP::Reset(){
      58             :   // reset all counters
      59           0 :   for(Int_t i=0;i<fgkNAnodes;i++){
      60           0 :     fNEvents[i]=0;
      61           0 :     fGoodAnode[i]=1;
      62           0 :     fBaseline[i]=0.;
      63           0 :     fCMN[i]=0.;
      64           0 :     fRawNoise[i]=0.;
      65           0 :     fCorrNoise[i]=0.;
      66           0 :     fSumTPPeak[i]=0.;
      67           0 :     fTPPos[i]=0.;
      68             :   }
      69           0 :   ReadBaselines();
      70           0 : }
      71             : 
      72             : //______________________________________________________________________
      73             : void AliITSOnlineSDDTP::AddEvent(TH2F* hrawd){
      74             :   // analyzes current event and sum its contribution to the various counters
      75           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
      76             :     Float_t auxmax=0.;
      77             :     Int_t auxtb=0;
      78           0 :     if(!fGoodAnode[ian]) continue;
      79           0 :     for(Int_t itb=fFirstGoodTB;itb<=fLastGoodTB;itb++){
      80           0 :       Float_t cnt=hrawd->GetBinContent(itb+1,ian+1);
      81           0 :       if(cnt>auxmax){ 
      82             :         auxmax=cnt;
      83             :         auxtb=itb;
      84           0 :       }
      85             :     }
      86           0 :     if(auxmax>fBaseline[ian]+fNSigmaNoise*fRawNoise[ian]){
      87           0 :       fSumTPPeak[ian]+=auxmax-fBaseline[ian];
      88           0 :       fTPPos[ian]+=auxtb;
      89           0 :       fNEvents[ian]++;
      90           0 :     }
      91           0 :   }
      92           0 : }
      93             : //______________________________________________________________________
      94             : void AliITSOnlineSDDTP::ReadBaselines(){
      95             :   // assume baselines and good anodes are taken from previous run
      96           0 :   TString basfilnam;
      97           0 :   basfilnam.Form("SDDbase_step2_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
      98           0 :   FILE* basf=fopen(basfilnam.Data(),"r");
      99           0 :   if(basf==0){
     100           0 :     AliWarning(Form("Baseline file not present (ddl %d  carlos %d side %d, Set all baselines to 20",fDDL,fCarlos,fSide));
     101           0 :     for(Int_t ian=0;ian<fgkNAnodes;ian++){ 
     102           0 :       fBaseline[ian]=20.;
     103           0 :       fEqBaseline[ian]=20;
     104           0 :       fOffsetBaseline[ian]=0;
     105           0 :       fGoodAnode[ian]=1;
     106             :     }
     107           0 :     return;
     108             :   }
     109           0 :   Int_t check = fscanf(basf,"%d\n",&fHighThreshold);
     110           0 :   if(check<1)AliError("Error while reading file with baselines");
     111           0 :   check = fscanf(basf,"%d\n",&fLowThreshold);
     112           0 :   if(check<1)AliError("Error while reading file with baselines");
     113           0 :   Int_t n,ok,eqbase,offbase;
     114           0 :   Float_t base,rms,cmn,corrnoi;
     115           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     116           0 :     check = fscanf(basf,"%d %d %f %d %d %f %f %f\n",&n,&ok,&base,&eqbase,&offbase,&rms,&cmn,&corrnoi);
     117           0 :     if(check<1)AliError("Error while reading file with baselines");
     118           0 :     fBaseline[ian]=base;
     119           0 :     fEqBaseline[ian]=eqbase;
     120           0 :     fOffsetBaseline[ian]=offbase;
     121           0 :     fGoodAnode[ian]=ok;
     122           0 :     fRawNoise[ian]=rms;
     123           0 :     fCMN[ian]=cmn;
     124           0 :     fCorrNoise[ian]=corrnoi;
     125             :   }
     126           0 :   fclose(basf);
     127           0 : }
     128             : 
     129             : //______________________________________________________________________
     130             : Bool_t AliITSOnlineSDDTP::IsModuleGood() const{
     131             :   //
     132             :   // Check if there is at least 1 good anode
     133             :   //
     134           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     135           0 :     if(fGoodAnode[ian]) return kTRUE;
     136             :   }
     137           0 :   return kFALSE;
     138           0 : }
     139             : //______________________________________________________________________
     140             : void AliITSOnlineSDDTP::ValidateAnodes(){
     141             :   // tag good/bad channels
     142           0 :   Float_t meang,rmsg;
     143           0 :   StatGain(meang,rmsg);
     144           0 :   Float_t lowlim=fMinGain;
     145           0 :   Float_t hilim=fMaxGain;
     146           0 :   if(fValidateOption==1){
     147           0 :     lowlim=meang*(1-fToleranceGain);
     148           0 :     hilim=meang*(1+fToleranceGain);
     149           0 :   }else{
     150           0 :     lowlim=meang-fNSigmaGain*rmsg;
     151           0 :     hilim=meang+fNSigmaGain*rmsg;
     152             :   }
     153             : 
     154           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     155           0 :     if(!fGoodAnode[ian]) continue;
     156           0 :     if(GetChannelGain(ian)<lowlim||GetChannelGain(ian)>hilim) fGoodAnode[ian]=0;
     157             :   }
     158           0 : }
     159             : 
     160             : 
     161             : //______________________________________________________________________
     162             : void AliITSOnlineSDDTP::StatGain(Float_t &mean, Float_t  &rms) const {
     163             :   // compute average gain and rms
     164             :   Float_t sum=0.,sumq=0.;
     165             :   Int_t cnt=0;
     166           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     167           0 :     if(!fGoodAnode[ian]) continue;
     168           0 :     if(fNEvents[ian]==0) continue;
     169           0 :     Float_t chgain=GetChannelGain(ian);
     170           0 :     if(chgain>fMinGain && chgain<fMaxGain){
     171           0 :       sum+=chgain;
     172           0 :       sumq+=chgain*chgain;
     173           0 :       cnt++;
     174           0 :     }
     175           0 :   }
     176           0 :   if(cnt>0){ 
     177           0 :     mean=sum/(Float_t)cnt;
     178           0 :     Float_t variance=sumq/(Float_t)cnt-mean*mean;
     179           0 :     if(variance>0.) rms=TMath::Sqrt(variance);
     180           0 :     else rms = 0;
     181           0 :   }else{ 
     182           0 :     mean=0.;
     183           0 :     rms=0.;
     184             :   }
     185             :   return;
     186           0 : }
     187             : 
     188             : //______________________________________________________________________
     189             : void AliITSOnlineSDDTP::WriteToASCII(){
     190             :   // writes parameters of each channel into an ASCII file 
     191             :   // to be sent to FXS by the DA and processed by the SHUTTLE
     192             : 
     193           0 :   TString outfilnam;
     194           0 :   outfilnam.Form("SDDbase_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide);
     195           0 :   FILE* outf=fopen(outfilnam.Data(),"w");
     196           0 :   fprintf(outf,"%d %d %d\n",fCarlos,fSide,IsModuleGood());
     197           0 :   fprintf(outf,"%d\n",fHighThreshold);
     198           0 :   fprintf(outf,"%d\n",fLowThreshold);
     199           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     200           0 :     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));
     201             :   }
     202           0 :   fclose(outf);  
     203           0 : }
     204             : //______________________________________________________________________
     205             : TH1F* AliITSOnlineSDDTP::GetBaselineAnodeHisto() const {
     206             :   // produce histogram with baseline vs. anode number
     207           0 :   TString hisnam;  
     208           0 :   hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
     209           0 :   TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
     210           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     211           0 :     h->SetBinContent(ian+1,GetAnodeBaseline(ian));
     212             :   }
     213             :   return h;
     214           0 : }
     215             : //______________________________________________________________________
     216             : TH1F* AliITSOnlineSDDTP::GetRawNoiseAnodeHisto() const {
     217             :   // produce histogram with raw noise vs. anode number
     218           0 :   TString hisnam;  
     219           0 :   hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
     220           0 :   TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
     221           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     222           0 :     h->SetBinContent(ian+1,GetAnodeRawNoise(ian));
     223             :   }
     224             :   return h;
     225           0 : }
     226             : //______________________________________________________________________
     227             : TH1F* AliITSOnlineSDDTP::GetCorrNoiseAnodeHisto() const {
     228             :   // produce histogram with corrected noise vs. anode number
     229           0 :   TString hisnam;  
     230           0 :   hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
     231           0 :   TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
     232           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     233           0 :     h->SetBinContent(ian+1,GetAnodeCorrNoise(ian));
     234             :   }
     235             :   return h;
     236           0 : }
     237             : //______________________________________________________________________
     238             : TH1F* AliITSOnlineSDDTP::GetCMNCoefAnodeHisto() const {
     239             :   // produce histogram with coefficients for common mode noise subtraction
     240           0 :   TString hisnam;  
     241           0 :   hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
     242           0 :   TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
     243           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     244           0 :     h->SetBinContent(ian+1,GetAnodeCommonMode(ian));
     245             :   }
     246             :   return h;
     247           0 : }
     248             : //______________________________________________________________________
     249             : TH1F* AliITSOnlineSDDTP::GetStatusAnodeHisto() const {
     250             :   // produce histogram with status bit of each anode
     251           0 :   TString hisnam;  
     252           0 :   hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
     253           0 :   TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
     254           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     255           0 :     h->SetBinContent(ian+1,float(IsAnodeGood(ian)));
     256             :   }
     257             :   return h;
     258           0 : }
     259             : //______________________________________________________________________
     260             : TH1F* AliITSOnlineSDDTP::GetGainAnodeHisto() const {
     261             :   // produce histogram with gain vs. anode number
     262           0 :   TString hisnam;  
     263           0 :   hisnam.Form("hgain%02dc%02ds%d",fDDL,fCarlos,fSide);
     264           0 :   TH1F* h=new TH1F(hisnam.Data(),"",256,-0.5,255.5);
     265           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     266           0 :     h->SetBinContent(ian+1,GetChannelGain(ian));
     267             :   }
     268             :   return h;
     269           0 : }
     270             : //______________________________________________________________________
     271             : Bool_t AliITSOnlineSDDTP::WriteToROOT(TFile *fil){
     272             :   // writes output into a root file
     273           0 :   if(fil==0){ 
     274           0 :     AliWarning("Invalid pointer to ROOT file");
     275           0 :     return kFALSE;    
     276             :   }
     277           0 :   TString hisnam;  
     278           0 :   fil->cd();
     279           0 :   hisnam.Form("hgood%02dc%02ds%d",fDDL,fCarlos,fSide);
     280           0 :   TH1F hgood(hisnam.Data(),"",256,-0.5,255.5);
     281           0 :   hisnam.Form("hbase%02dc%02ds%d",fDDL,fCarlos,fSide);
     282           0 :   TH1F hbase(hisnam.Data(),"",256,-0.5,255.5);
     283           0 :   hisnam.Form("hnois%02dc%02ds%d",fDDL,fCarlos,fSide);
     284           0 :   TH1F hnois(hisnam.Data(),"",256,-0.5,255.5);
     285           0 :   hisnam.Form("hcmn%02dc%02ds%d",fDDL,fCarlos,fSide);
     286           0 :   TH1F hcmn(hisnam.Data(),"",256,-0.5,255.5);
     287           0 :   hisnam.Form("hcorn%02dc%02ds%d",fDDL,fCarlos,fSide);
     288           0 :   TH1F hcorn(hisnam.Data(),"",256,-0.5,255.5);
     289           0 :   hisnam.Form("hgain%02dc%02ds%d",fDDL,fCarlos,fSide);
     290           0 :   TH1F hgain(hisnam.Data(),"",256,-0.5,255.5);
     291           0 :   hisnam.Form("htptb%02dc%02ds%d",fDDL,fCarlos,fSide);
     292           0 :   TH1F htptb(hisnam.Data(),"",256,-0.5,255.5);
     293           0 :   for(Int_t ian=0;ian<fgkNAnodes;ian++){
     294           0 :     hgood.SetBinContent(ian+1,float(IsAnodeGood(ian)));
     295           0 :     hbase.SetBinContent(ian+1,GetAnodeBaseline(ian));
     296           0 :     hnois.SetBinContent(ian+1,GetAnodeRawNoise(ian));
     297           0 :     hcmn.SetBinContent(ian+1,GetAnodeCommonMode(ian));
     298           0 :     hcorn.SetBinContent(ian+1,GetAnodeCorrNoise(ian));
     299           0 :     hgain.SetBinContent(ian+1,GetChannelGain(ian));
     300           0 :     htptb.SetBinContent(ian+1,GetTimeBinTPPeak(ian));
     301             :   }
     302           0 :   hgood.Write();
     303           0 :   hbase.Write();
     304           0 :   hnois.Write();
     305           0 :   hcmn.Write();
     306           0 :   hcorn.Write();
     307           0 :   hgain.Write();
     308           0 :   htptb.Write();
     309             :   return kTRUE;
     310           0 : }
     311             : 

Generated by: LCOV version 1.11