LCOV - code coverage report
Current view: top level - PHOS/PHOSbase - AliPHOSCpvRawDigiProducer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 59 156 37.8 %
Date: 2016-06-14 17:26:59 Functions: 8 14 57.1 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 2007, 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             : 
      16             : // --- ROOT system ---
      17             : #include "TClonesArray.h"
      18             : 
      19             : // --- AliRoot header files ---
      20             : #include "AliPHOSCpvRawDigiProducer.h"
      21             : #include "AliPHOSCpvRawStream.h"
      22             : #include "AliPHOSDigit.h"
      23             : #include "AliPHOSGeometry.h"
      24             : #include "AliLog.h"
      25             : #include<iostream>
      26             : using namespace std;
      27             : 
      28          22 : ClassImp(AliPHOSCpvRawDigiProducer);
      29             : 
      30             : //--------------------------------------------------------------------------------------
      31             : AliPHOSCpvRawDigiProducer::AliPHOSCpvRawDigiProducer():
      32           0 :   TObject(),
      33           0 :   fGeom(0),
      34           0 :   fTurbo(kFALSE),
      35           0 :   fCpvMinE(10.),
      36           0 :   fRawStream(0),
      37           0 :   fhErrors(0),
      38           0 :   fPedFilesRLoaded(kFALSE),
      39           0 :   fCalibData(0x0)
      40           0 : {
      41           0 :   fGeom=AliPHOSGeometry::GetInstance() ;
      42           0 :   if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
      43             : 
      44           0 :   CreateErrHist();
      45             :   // create a 2d array to store the pedestals                                        
      46           0 :   for (Int_t iDDL=0;iDDL<2*AliPHOSCpvParam::kNDDL;iDDL++){
      47           0 :     fPermanentBadMap[iDDL]=0x0;
      48           0 :     fPed[0][iDDL] = new Int_t *[AliPHOSCpvParam::kPadPcX];
      49           0 :     fPed[1][iDDL] = new Int_t *[AliPHOSCpvParam::kPadPcX];
      50           0 :     for(Int_t ix=0; ix<AliPHOSCpvParam::kPadPcX; ix++) {
      51           0 :       fPed[0][iDDL][ix] = new Int_t [AliPHOSCpvParam::kPadPcY];
      52           0 :       fPed[1][iDDL][ix] = new Int_t [AliPHOSCpvParam::kPadPcY];
      53             :     }
      54             :   }
      55           0 : }
      56             : //-------------------------------------------------------------------------------------
      57             : AliPHOSCpvRawDigiProducer::AliPHOSCpvRawDigiProducer(AliRawReader * rawReader):
      58           4 :   TObject(),
      59           4 :   fGeom(0),
      60           4 :   fTurbo(kFALSE),
      61           4 :   fCpvMinE(10.),
      62           4 :   fRawStream(0),
      63           4 :   fhErrors(0),
      64           4 :   fPedFilesRLoaded(kFALSE),
      65           4 :   fCalibData(0x0)
      66          20 : {
      67           8 :   fGeom=AliPHOSGeometry::GetInstance() ;
      68           4 :   if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
      69             : 
      70          12 :   fRawStream = new AliPHOSCpvRawStream(rawReader);
      71           4 :   fRawStream->SetTurbo(fTurbo);
      72           4 :   CreateErrHist();
      73             :   // create a 2d array to store the pedestals                                               
      74          88 :   for (Int_t iDDL=0;iDDL<2*AliPHOSCpvParam::kNDDL;iDDL++) {
      75          40 :     fPermanentBadMap[iDDL]=0x0;
      76          80 :     fPed[0][iDDL] = new Int_t *[AliPHOSCpvParam::kPadPcX];
      77          80 :     fPed[1][iDDL] = new Int_t *[AliPHOSCpvParam::kPadPcX];
      78       10320 :     for(Int_t ix=0; ix<AliPHOSCpvParam::kPadPcX; ix++) {
      79       10240 :       fPed[0][iDDL][ix] = new Int_t [AliPHOSCpvParam::kPadPcY];
      80       10240 :       fPed[1][iDDL][ix] = new Int_t [AliPHOSCpvParam::kPadPcY];
      81             :     }
      82             :   }
      83           8 : }
      84             : //--------------------------------------------------------------------------------------
      85             : AliPHOSCpvRawDigiProducer::~AliPHOSCpvRawDigiProducer()
      86          16 : {
      87          12 :   if(fRawStream) delete fRawStream;
      88          12 :   if(fhErrors) delete fhErrors; 
      89          88 :   for(Int_t iDDL = 0;iDDL<2*AliPHOSCpvParam::kNDDL;iDDL++) {
      90       10320 :     for(Int_t ix=0; ix<AliPHOSCpvParam::kPadPcX; ix++) { 
      91       10240 :       delete [] fPed[0][iDDL][ix];
      92       10240 :       delete [] fPed[1][iDDL][ix];
      93             :     }
      94          80 :     delete [] fPed[0][iDDL];
      95          80 :     delete [] fPed[1][iDDL];
      96             :   }
      97           8 : }
      98             : //--------------------------------------------------------------------------------------
      99             : void AliPHOSCpvRawDigiProducer::SetPermanentBadMap(TH2I* badMap,int iDDL=0){
     100           0 :   if(badMap!=0x0){
     101           0 :     if(iDDL>=0&&iDDL<2*AliPHOSCpvParam::kNDDL){
     102           0 :       fPermanentBadMap[iDDL] = (TH2I*)badMap->Clone();
     103           0 :     }
     104             :     else
     105           0 :       AliError(Form("DDL number %d is not valid",iDDL));
     106             :   }
     107             : 
     108           0 : }
     109             : //--------------------------------------------------------------------------------------
     110             : Bool_t AliPHOSCpvRawDigiProducer::LoadPedFiles() {
     111             :   // read pedestals from file                                             
     112           0 :   for(Int_t iDDL = 0;iDDL<2*AliPHOSCpvParam::kNDDL;iDDL+=2)
     113           0 :     for(Int_t iCC=0; iCC<AliPHOSCpvParam::kNRows; iCC++) {
     114             :       FILE * pedFile;
     115           0 :       pedFile = fopen(Form("thr%d_%02d.dat",iDDL,iCC),"r");
     116           0 :       if(!pedFile) {
     117             :         //Printf("AliPHOSCpvRawDigiProducer::LoadPedFiles: Error, file thr%d_%02d.dat could not be open",iDDL,iCC);
     118           0 :         continue;
     119             :       }
     120             :       Int_t i3g = 0, iPad = 0;
     121             :       Int_t lineCnt = 0;
     122           0 :       while(!feof(pedFile)) {
     123           0 :         Int_t abs = AliPHOSCpvParam::Abs(iDDL,iCC,i3g,iPad);
     124           0 :         if(iPad<48&&i3g<10){
     125           0 :           if(AliPHOSCpvParam::A2DDL(abs)!=iDDL)
     126           0 :             AliError(Form("wrong connection table! abs = %d, DDL = %d, A2DDL",abs,iDDL,AliPHOSCpvParam::A2DDL(abs)));
     127           0 :           if(AliPHOSCpvParam::A2CC(abs)!=iCC)
     128           0 :             AliError(Form("wrong connection table! abs = %d, CC = %d, A2CC = %d",abs,iCC,AliPHOSCpvParam::A2CC(abs)));
     129           0 :           if(AliPHOSCpvParam::A23G(abs)!=i3g)
     130           0 :             AliError(Form("wrong connection table! abs = %d, 3G = %d, A23G = %d",abs,i3g,AliPHOSCpvParam::A23G(abs)));
     131           0 :           if(AliPHOSCpvParam::A2Pad(abs)!=iPad)
     132           0 :             AliError(Form("wrong connection table! abs = %d, pad = %d, A2Pad = %d",abs,iPad,AliPHOSCpvParam::A2Pad(abs)));
     133             :         }
     134           0 :         Int_t thr;
     135           0 :         fscanf(pedFile,"%x",&thr);
     136           0 :         if(AliPHOSCpvParam::IsValidAbs(abs)) {
     137           0 :           Int_t s = thr & 0x1ff;
     138           0 :           Int_t p = thr >> 9;
     139           0 :           fPed[0][iDDL][AliPHOSCpvParam::A2X(abs)][AliPHOSCpvParam::A2Y(abs)] = p-s;
     140           0 :           fPed[1][iDDL][AliPHOSCpvParam::A2X(abs)][AliPHOSCpvParam::A2Y(abs)] = s;
     141           0 :           int testAbs = AliPHOSCpvParam::XY2A(iDDL,AliPHOSCpvParam::A2X(abs),AliPHOSCpvParam::A2Y(abs));
     142           0 :           if(abs!=testAbs)
     143           0 :             AliError(Form("wrong connection table! abs = %d, testAbs = %d",abs,testAbs));
     144           0 :         }
     145           0 :         iPad++;
     146           0 :         if(iPad == 64) {iPad = 0; i3g++;}
     147           0 :         lineCnt++;
     148           0 :       }
     149           0 :       fclose(pedFile);
     150           0 :       if(lineCnt < AliPHOSCpvParam::kN3GAdd * 64) return kFALSE;
     151           0 :     }
     152           0 :   fPedFilesRLoaded = kTRUE;
     153           0 :   return kTRUE;
     154           0 : }
     155             : //--------------------------------------------------------------------------------------
     156             : void AliPHOSCpvRawDigiProducer::SetTurbo(Bool_t turbo) 
     157             : {
     158           4 :   fTurbo = turbo;
     159           8 :   if(fRawStream) fRawStream->SetTurbo(fTurbo);
     160           4 : }
     161             : //--------------------------------------------------------------------------------------
     162             : Bool_t AliPHOSCpvRawDigiProducer::LoadNewEvent(AliRawReader * rawReader)
     163             : {
     164           0 :   if(fRawStream) delete fRawStream;
     165           0 :   fRawStream = new AliPHOSCpvRawStream(rawReader);
     166           0 :   if(fRawStream) {
     167           0 :     fRawStream->SetTurbo(fTurbo);
     168           0 :     return kTRUE;
     169             :   }
     170           0 :   fhErrors->Fill(0);
     171           0 :   return kFALSE;
     172           0 : }
     173             : //--------------------------------------------------------------------------------------
     174             : void AliPHOSCpvRawDigiProducer::MakeDigits(TClonesArray * digits) const
     175             : {
     176             :   // Fills TClonesArray of AliPHOSDigits and 
     177             :   // returns histogram of error types
     178             : 
     179           8 :   Int_t relId[4], absId=-1;
     180           4 :   Int_t iDigit = digits->GetEntriesFast(); 
     181             :   // Int_t iDigit = 0;
     182           8 :   while (fRawStream->Next()) {
     183           0 :     for (Int_t iPad=0; iPad<fRawStream->GetNPads(); iPad++) {
     184           0 :       Float_t charge = fRawStream->GetChargeArray()[iPad];
     185           0 :       Int_t aPad     = fRawStream->GetPadArray()[iPad];
     186           0 :       Int_t ix       = AliPHOSCpvParam::A2X(aPad);
     187           0 :       Int_t iy       = AliPHOSCpvParam::A2Y(aPad);
     188           0 :       Int_t iddl     = AliPHOSCpvParam::A2DDL(aPad);
     189             :       
     190           0 :       if(fPermanentBadMap[iddl])
     191           0 :         if(fPermanentBadMap[iddl]->GetBinContent(ix+1,iy+1)>0) continue;//bad channels exclusion
     192             : 
     193           0 :       relId[0] = AliPHOSCpvParam::DDL2Mod(iddl) ; // counts from 1 to 5
     194           0 :       relId[1] = -1;      // -1=CPV
     195           0 :       relId[2] = ix + 1; // counts from 1 to 128
     196           0 :       relId[3] = iy + 1; // counts from 1 to 60
     197           0 :       fGeom->RelToAbsNumbering(relId, absId);
     198             : 
     199           0 :       AliDebug(2,Form("CPV digit: pad=%d, (x,z)=(%3d,%2d), DDL=%d, charge=%.0f",
     200             :                       aPad,ix,iy,iddl,charge)); 
     201             : 
     202           0 :       if(fPedFilesRLoaded) {
     203           0 :         if (charge > fPed[0][iddl][ix][iy] + fPed[1][iddl][ix][iy])
     204           0 :           charge -= fPed[0][iddl][ix][iy];
     205             :         else 
     206             :           charge  = 0;
     207             :       }
     208           0 :       if(fCalibData) {
     209           0 :         if(fCalibData->IsBadChannelCpv(relId[0],relId[2],relId[3]))
     210           0 :           charge=0;
     211           0 :         Float_t pedestal = fCalibData->GetADCpedestalCpv(relId[0],relId[2],relId[3]);
     212           0 :         charge -= pedestal;
     213           0 :       }
     214           0 :       if (charge < fCpvMinE) charge = 0;
     215           0 :       if (charge>0) new((*digits)[iDigit++]) AliPHOSDigit(-1,absId,charge,0.);
     216             :       
     217           0 :     }
     218             :   } // while(fRawStream->Next())
     219           4 :   digits->Sort() ;
     220         224 :   for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) { 
     221         108 :     AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ; 
     222         108 :     digit->SetIndexInList(i) ;     
     223             :   }
     224             : 
     225          12 :   AliDebug(1,Form("Array of %d CPV digits is created",digits->GetEntriesFast())); 
     226             : 
     227             :   // fill histogram of errors
     228          88 :   for(Int_t iDDL=0; iDDL<2*AliPHOSCpvParam::kNDDL; iDDL++) {
     229          40 :     Int_t nErrors = AliPHOSCpvRawStream::GetNErrors();
     230        1120 :     for(Int_t iType=0; iType<nErrors; iType++) { // iType - type of error
     231         520 :       fhErrors -> Fill(iType+1,fRawStream -> GetErrors(iDDL,iType));
     232             :     }
     233             :   }
     234           4 : }
     235             : //--------------------------------------------------------------------------------------
     236             : void AliPHOSCpvRawDigiProducer::CreateErrHist()
     237             : {
     238           8 :   Int_t nErrors = AliPHOSCpvRawStream::GetNErrors();
     239           4 :   const char * errNames[nErrors];
     240         112 :   for(Int_t i=0; i<nErrors; i++) {
     241          52 :     errNames[i] = AliPHOSCpvRawStream::GetErrName(i);
     242             :   }
     243           8 :   fhErrors = new TH1I("errorTypes","Errors occured during processing",nErrors+1,0,nErrors+1);
     244           4 :   TAxis* x = fhErrors->GetXaxis();
     245           4 :   x->SetBinLabel(1, "Can't get event");
     246         112 :   for(Int_t i=0; i<nErrors; i++) {
     247          52 :     x->SetBinLabel(i+2,errNames[i]);
     248             :   }
     249             : 
     250           4 : }
     251             : //--------------------------------------------------------------------------------------

Generated by: LCOV version 1.11