LCOV - code coverage report
Current view: top level - PMD/PMDrec - AliPMDCalibPedestal.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 205 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 11 9.1 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, 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             : 
      17             : //Root includes
      18             : #include <TObjArray.h>
      19             : #include <TH1F.h>
      20             : #include <TString.h>
      21             : #include <TMath.h>
      22             : #include <TF1.h>
      23             : #include <TRandom.h>
      24             : #include <TDirectory.h>
      25             : #include <TFile.h>
      26             : #include "TTreeStream.h"
      27             : 
      28             : //AliRoot includes
      29             : #include "AliDAQ.h"
      30             : #include "AliLog.h"
      31             : #include "AliRawReader.h"
      32             : #include "AliPMDRawStream.h"
      33             : #include "AliPMDddldata.h"
      34             : #include "AliBitPacking.h"
      35             : //header file
      36             : #include "AliPMDCalibPedestal.h"
      37             : 
      38             : 
      39          12 : ClassImp(AliPMDCalibPedestal)
      40             : 
      41             : 
      42             : AliPMDCalibPedestal::AliPMDCalibPedestal() :
      43           0 :   TObject(),
      44           0 :   fRunNumber(-1),
      45           0 :   fEventNumber(0)
      46           0 : {
      47             :     //
      48             :     // default constructor
      49             :     //
      50             : 
      51           0 :     for (int i = 0; i < kDet; i++)
      52             :     {
      53           0 :         for (int j = 0; j < kMaxSMN; j++)
      54             :         {
      55           0 :             for (int k = 0; k < kMaxRow; k++)
      56             :             {
      57           0 :                 for (int l = 0; l < kMaxCol; l++)
      58             :                 {
      59           0 :                     fPedVal[i][j][k][l]   = 0.;
      60           0 :                     fPedValSq[i][j][k][l] = 0.;
      61           0 :                     fPedCount[i][j][k][l] = 0.;
      62             :                 }
      63             :             }
      64             :         }
      65             :     }
      66             : 
      67           0 :     for (int i = 0; i < 6; i++)
      68             :     {
      69           0 :         for (int j = 0; j < 51; j++)
      70             :         {
      71           0 :             for (int k = 0; k < 25; k++)
      72             :             {
      73           0 :                 for (int l = 0; l < 64; l++)
      74             :                 {
      75           0 :                     fPedChain[i][j][k][l] = -1;
      76             :                 }
      77             :             }
      78             :         }
      79             :     }
      80             : 
      81             : 
      82           0 : }
      83             : //_____________________________________________________________________
      84             : AliPMDCalibPedestal::AliPMDCalibPedestal(const AliPMDCalibPedestal &ped) :
      85           0 :   TObject(ped),
      86           0 :   fRunNumber(ped.fRunNumber),
      87           0 :   fEventNumber(ped.fEventNumber)
      88           0 : {
      89             :     //
      90             :     // copy constructor
      91             :     //
      92           0 :     for (int i = 0; i < kDet; i++)
      93             :     {
      94           0 :         for (int j = 0; j < kMaxSMN; j++)
      95             :         {
      96           0 :             for (int k = 0; k < kMaxRow; k++)
      97             :             {
      98           0 :                 for (int l = 0; l < kMaxCol; l++)
      99             :                 {
     100           0 :                     fPedVal[i][j][k][l]   = ped.fPedVal[i][j][k][l];
     101           0 :                     fPedValSq[i][j][k][l] = ped.fPedValSq[i][j][k][l];
     102           0 :                     fPedCount[i][j][k][l] = ped.fPedCount[i][j][k][l];
     103             :                 }
     104             :             }
     105             :         }
     106             :     }
     107             : 
     108           0 :     for (int i = 0; i < 6; i++)
     109             :     {
     110           0 :         for (int j = 0; j < 51; j++)
     111             :         {
     112           0 :             for (int k = 0; k < 25; k++)
     113             :             {
     114           0 :                 for (int l = 0; l < 64; l++)
     115             :                 {
     116           0 :                     fPedChain[i][j][k][l] = -1;
     117             :                 }
     118             :             }
     119             :         }
     120             :     }
     121             :     
     122           0 : }
     123             : //_____________________________________________________________________
     124             : AliPMDCalibPedestal& AliPMDCalibPedestal::operator = (const  AliPMDCalibPedestal &source)
     125             : {
     126             :   //
     127             :   // assignment operator
     128             :   //
     129           0 :   if (&source == this) return *this;
     130           0 :   new (this) AliPMDCalibPedestal(source);
     131             : 
     132           0 :   return *this;
     133           0 : }
     134             : //_____________________________________________________________________
     135             : AliPMDCalibPedestal::~AliPMDCalibPedestal()
     136           0 : {
     137             :     //
     138             :     // destructor
     139             :     //
     140           0 : }
     141             : //_____________________________________________________________________
     142             : Bool_t AliPMDCalibPedestal::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont)
     143             : {
     144             :   //
     145             :   //  Event processing loop - AliRawReader
     146             :   //
     147             : 
     148           0 :     const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
     149             : 
     150           0 :     UInt_t detsmnrowcol = 0;
     151             :     UInt_t pbus = 0, mcm = 0, chno = 0;
     152             : 
     153           0 :     fRunNumber = rawReader->GetRunNumber();
     154             : 
     155           0 :     AliPMDRawStream rawStream(rawReader);
     156             : 
     157           0 :     fEventNumber++;
     158             : 
     159             :     Int_t iddl = -1;
     160             :     Int_t numberofDDLs = 0;
     161             : 
     162           0 :     while ((iddl = rawStream.DdlData(pmdddlcont)) >=0) {
     163           0 :       numberofDDLs++;
     164           0 :       Int_t ientries = pmdddlcont->GetEntries();
     165             :       //printf("iddl = %d ientries = %d\n",iddl, ientries);
     166           0 :       for (Int_t ient = 0; ient < ientries; ient++)
     167             :         {
     168           0 :             AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont->UncheckedAt(ient);
     169             :             
     170           0 :             Int_t det = pmdddl->GetDetector();
     171           0 :             Int_t smn = pmdddl->GetSMN();
     172           0 :             Int_t row = pmdddl->GetRow();
     173           0 :             Int_t col = pmdddl->GetColumn();
     174           0 :             Float_t sig = (Float_t) pmdddl->GetSignal();
     175             : 
     176           0 :             pbus = (UInt_t) pmdddl->GetPatchBusId();
     177           0 :             mcm  = (UInt_t) pmdddl->GetMCM();
     178           0 :             chno = (UInt_t) pmdddl->GetChannel();
     179             : 
     180           0 :             detsmnrowcol = 0;
     181           0 :             AliBitPacking::PackWord(det,detsmnrowcol,0,7);
     182           0 :             AliBitPacking::PackWord(smn,detsmnrowcol,8,15);
     183           0 :             AliBitPacking::PackWord(row,detsmnrowcol,16,23);
     184           0 :             AliBitPacking::PackWord(col,detsmnrowcol,24,31);
     185             : 
     186           0 :             if (fPedChain[iddl][pbus][mcm][chno] == -1)
     187           0 :                 fPedChain[iddl][pbus][mcm][chno] = (Int_t)detsmnrowcol;
     188             : 
     189             : 
     190           0 :             fPedVal[det][smn][row][col]   += sig;
     191           0 :             fPedValSq[det][smn][row][col] += sig*sig;
     192           0 :             fPedCount[det][smn][row][col]++;
     193             :         }
     194           0 :       pmdddlcont->Delete();
     195             :     }
     196             : 
     197           0 :     if (numberofDDLs < kDDL)
     198           0 :       return kFALSE;
     199           0 :     return kTRUE;
     200           0 : }
     201             : //_____________________________________________________________________
     202             : 
     203             : void AliPMDCalibPedestal::Analyse(TTree *pedtree)
     204             : {
     205             :     //
     206             :     //  Calculate pedestal Mean and RMS
     207             :     //
     208             : 
     209             :     UInt_t  detsmnrowcol = 0;
     210           0 :     Int_t   det = 0, sm = 0, row = 0, col = 0;
     211             :     Int_t   idet = 0, ism = 0, irow = 0, icol = 0;
     212           0 :     Float_t mean = 0., rms = 0., meanoff = 0.;
     213             :     Double_t meansq = 0., diff = 0.;
     214             : 
     215           0 :     FILE *fpw0 = fopen("pedestal2304.ped","w");
     216           0 :     FILE *fpw1 = fopen("pedestal2305.ped","w");
     217           0 :     FILE *fpw2 = fopen("pedestal2306.ped","w");
     218           0 :     FILE *fpw3 = fopen("pedestal2307.ped","w");
     219           0 :     FILE *fpw4 = fopen("pedestal2308.ped","w");
     220           0 :     FILE *fpw5 = fopen("pedestal2309.ped","w");
     221             : 
     222           0 :     fprintf(fpw0,"//=============================================\n");
     223           0 :     fprintf(fpw0,"//     Pedestal file Calculated by Online DA\n");
     224           0 :     fprintf(fpw0,"//=============================================\n");
     225           0 :     fprintf(fpw0,"//     RUN             :%d\n",fRunNumber);
     226           0 :     fprintf(fpw0,"//     Statistics      :%d\n",fEventNumber);
     227           0 :     fprintf(fpw0,"//---------------------------------------------\n");
     228           0 :     fprintf(fpw0,"//format:CHAIN_NO  FEE_ID  CHANNEL  MEAN  SIGMA\n");
     229           0 :     fprintf(fpw0,"//---------------------------------------------\n");
     230             : 
     231           0 :     fprintf(fpw1,"//=============================================\n");
     232           0 :     fprintf(fpw1,"//     Pedestal file Calculated by Online DA\n");
     233           0 :     fprintf(fpw1,"//=============================================\n");
     234           0 :     fprintf(fpw1,"//     RUN             :%d\n",fRunNumber);
     235           0 :     fprintf(fpw1,"//     Statistics      :%d\n",fEventNumber);
     236           0 :     fprintf(fpw1,"//---------------------------------------------\n");
     237           0 :     fprintf(fpw1,"//format:CHAIN_NO  FEE_ID  CHANNEL  MEAN  SIGMA\n");
     238             : 
     239           0 :     fprintf(fpw2,"//=============================================\n");
     240           0 :     fprintf(fpw2,"//     Pedestal file Calculated by Online DA\n");
     241           0 :     fprintf(fpw2,"//=============================================\n");
     242           0 :     fprintf(fpw2,"//     RUN             :%d\n",fRunNumber);
     243           0 :     fprintf(fpw2,"//     Statistics      :%d\n",fEventNumber);
     244           0 :     fprintf(fpw2,"//---------------------------------------------\n");
     245           0 :     fprintf(fpw2,"//format:CHAIN_NO  FEE_ID  CHANNEL  MEAN  SIGMA\n");
     246           0 :     fprintf(fpw2,"//---------------------------------------------\n");
     247             : 
     248           0 :     fprintf(fpw3,"//=============================================\n");
     249           0 :     fprintf(fpw3,"//     Pedestal file Calculated by Online DA\n");
     250           0 :     fprintf(fpw3,"//=============================================\n");
     251           0 :     fprintf(fpw3,"//     RUN             :%d\n",fRunNumber);
     252           0 :     fprintf(fpw3,"//     Statistics      :%d\n",fEventNumber);
     253           0 :     fprintf(fpw3,"//---------------------------------------------\n");
     254           0 :     fprintf(fpw3,"//format:CHAIN_NO  FEE_ID  CHANNEL  MEAN  SIGMA\n");
     255           0 :     fprintf(fpw3,"//---------------------------------------------\n");
     256             : 
     257           0 :     fprintf(fpw4,"//=============================================\n");
     258           0 :     fprintf(fpw4,"//     Pedestal file Calculated by Online DA\n");
     259           0 :     fprintf(fpw4,"//=============================================\n");
     260           0 :     fprintf(fpw4,"//     RUN             :%d\n",fRunNumber);
     261           0 :     fprintf(fpw4,"//     Statistics      :%d\n",fEventNumber);
     262           0 :     fprintf(fpw4,"//---------------------------------------------\n");
     263           0 :     fprintf(fpw4,"//format:CHAIN_NO  FEE_ID  CHANNEL  MEAN  SIGMA\n");
     264           0 :     fprintf(fpw4,"//---------------------------------------------\n");
     265             : 
     266           0 :     fprintf(fpw5,"//=============================================\n");
     267           0 :     fprintf(fpw5,"//     Pedestal file Calculated by Online DA\n");
     268           0 :     fprintf(fpw5,"//=============================================\n");
     269           0 :     fprintf(fpw5,"//     RUN             :%d\n",fRunNumber);
     270           0 :     fprintf(fpw5,"//     Statistics      :%d\n",fEventNumber);
     271           0 :     fprintf(fpw5,"//---------------------------------------------\n");
     272           0 :     fprintf(fpw5,"//format:CHAIN_NO  FEE_ID  CHANNEL  MEAN  SIGMA\n");
     273           0 :     fprintf(fpw5,"//---------------------------------------------\n");
     274             : 
     275             : 
     276           0 :     for(Int_t iddl = 0; iddl < 6; iddl++)
     277             :       {
     278           0 :         for(Int_t ibus = 1; ibus < 51; ibus++)
     279             :           {
     280           0 :             for(Int_t imcm = 1; imcm < 25; imcm++)
     281             :               {
     282           0 :                 for(Int_t ich = 0; ich < 64; ich++)
     283             :                   {
     284             : 
     285           0 :                     if (fPedChain[iddl][ibus][imcm][ich] != -1)
     286             :                       {
     287             :                         detsmnrowcol = (UInt_t)fPedChain[iddl][ibus][imcm][ich];
     288             : 
     289           0 :                         idet =  detsmnrowcol & 0x00FF;
     290           0 :                         ism  = (detsmnrowcol >> 8) & 0x00FF;
     291           0 :                         irow = (detsmnrowcol >> 16) & 0x00FF;
     292           0 :                         icol = (detsmnrowcol >> 24) & 0x00FF;
     293             :                         
     294           0 :                         mean = 0.;
     295           0 :                         rms  = 0.;
     296           0 :                         if (fPedCount[idet][ism][irow][icol] > 0)
     297             :                           {
     298           0 :                             mean = fPedVal[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
     299             :                             // Fix for 2015 data sjena
     300             :                             // should be used for pedestal
     301             :                             meanoff = mean; // Variable kept to add an offset - it is off now   
     302           0 :                             meansq  = fPedValSq[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
     303             :                             
     304           0 :                             diff = meansq - mean*mean;
     305           0 :                             if (diff > 0.)
     306             :                               {
     307           0 :                                 rms  = sqrt(diff);
     308           0 :                               }
     309             :                             else
     310             :                               {
     311           0 :                                 rms = 0.;
     312             :                               }
     313             : 
     314           0 :                             if (iddl == 0)
     315             :                               {
     316           0 :                                 fprintf(fpw0,"%d %d %d %f %f\n",
     317           0 :                                         ibus, imcm, ich, meanoff, rms);
     318           0 :                               }
     319           0 :                             else if (iddl == 1)
     320             :                               {
     321           0 :                                 fprintf(fpw1,"%d %d %d %f %f\n",
     322           0 :                                         ibus, imcm, ich, meanoff, rms);
     323           0 :                               }
     324           0 :                             else if (iddl == 2)
     325             :                               {
     326           0 :                                 fprintf(fpw2,"%d %d %d %f %f\n",
     327           0 :                                         ibus, imcm, ich, meanoff, rms);
     328           0 :                               }
     329           0 :                             else if (iddl == 3)
     330             :                               {
     331           0 :                                 fprintf(fpw3,"%d %d %d %f %f\n",
     332           0 :                                         ibus, imcm, ich, meanoff, rms);
     333           0 :                               }
     334           0 :                             else if (iddl == 4)
     335             :                               {
     336           0 :                                 fprintf(fpw4,"%d %d %d %f %f\n",
     337           0 :                                         ibus, imcm, ich, meanoff, rms);
     338           0 :                               }
     339           0 :                             else if (iddl == 5)
     340             :                               {
     341           0 :                                 fprintf(fpw5,"%d %d %d %f %f\n",
     342           0 :                                         ibus, imcm, ich, meanoff, rms);
     343           0 :                               }
     344             :                           }
     345             :                       }
     346             :                   }
     347             :               }
     348             :           }
     349             :       }
     350             :     
     351             : 
     352           0 :     fclose(fpw0);
     353           0 :     fclose(fpw1);
     354           0 :     fclose(fpw2);
     355           0 :     fclose(fpw3);
     356           0 :     fclose(fpw4);
     357           0 :     fclose(fpw5);
     358             : 
     359           0 :     pedtree->Branch("det",&det,"det/I");
     360           0 :     pedtree->Branch("sm",&sm,"sm/I");
     361           0 :     pedtree->Branch("row",&row,"row/I");
     362           0 :     pedtree->Branch("col",&col,"col/I");
     363           0 :     pedtree->Branch("mean",&mean,"mean/F");
     364           0 :     pedtree->Branch("rms",&rms,"rms/F");
     365             : 
     366           0 :     for (idet = 0; idet < kDet; idet++)
     367             :       {
     368           0 :         for (ism = 0; ism < kMaxSMN; ism++)
     369             :           {
     370           0 :             for (irow = 0; irow < kMaxRow; irow++)
     371             :               {
     372           0 :                 for (icol = 0; icol < kMaxCol; icol++)
     373             :                   {
     374           0 :                     det  = idet;
     375           0 :                     sm   = ism;
     376           0 :                     row  = irow;
     377           0 :                     col  = icol;
     378           0 :                     mean = 0.;
     379           0 :                     rms  = 0.;
     380             :                     
     381           0 :                     if (fPedCount[idet][ism][irow][icol] > 0)
     382             :                       {
     383           0 :                         mean = fPedVal[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
     384             :                         
     385           0 :                         meansq = fPedValSq[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
     386             :                         
     387           0 :                         diff = meansq - mean*mean;
     388           0 :                         if (diff > 0.)
     389             :                           {
     390           0 :                             rms  = sqrt(diff);
     391           0 :                           }
     392             :                         else
     393             :                           {
     394           0 :                             rms = 0.;
     395             :                           }
     396           0 :                         pedtree->Fill();
     397           0 :                       }
     398             :                     
     399             :                   }
     400             :               }
     401             :           }
     402             :       }
     403           0 : }
     404             : // -------------------------------------------------------------------

Generated by: LCOV version 1.11