<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// class for ZDC reconstruction                                              //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////


#include <TF1.h>

#include "AliRunLoader.h"
#include "AliRawReader.h"
#include "AliESDEvent.h"
#include "AliESDZDC.h"
#include "AliZDCDigit.h"
#include "AliZDCRawStream.h"
#include "AliZDCReco.h"
#include "AliZDCReconstructor.h"
#include "AliZDCPedestals.h"
#include "AliZDCCalib.h"
#include "AliZDCRecoParam.h"
#include "AliZDCRecoParampp.h"
#include "AliZDCRecoParamPbPb.h"


ClassImp(AliZDCReconstructor)
AliZDCRecoParam *AliZDCReconstructor::fRecoParam=0;  //reconstruction parameters

//_____________________________________________________________________________
AliZDCReconstructor:: AliZDCReconstructor() :
  fPedData(GetPedData()),
  fECalibData(GetECalibData())
{
  // **** Default constructor

}


//_____________________________________________________________________________
AliZDCReconstructor::~AliZDCReconstructor()
{
// destructor
   if(fRecoParam)  delete fRecoParam;
   if(fPedData)    delete fPedData;    
   if(fECalibData) delete fECalibData;
}

//_____________________________________________________________________________
void AliZDCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
{
  // *** Local ZDC reconstruction for digits
  // Works on the current event
    
  // Retrieving calibration data  
  Float_t meanPed[48];
  for(Int_t jj=0; jj<48; jj++) meanPed[jj] = fPedData->GetMeanPed(jj);

  // get digits
  AliZDCDigit digit;
  AliZDCDigit* pdigit = &digit;
  digitsTree->SetBranchAddress("ZDC", &pdigit);
  //printf("\n\t # of digits in tree: %d\n",(Int_t) digitsTree->GetEntries());

  // loop over digits
  Float_t tZN1Corr[10], tZP1Corr[10], tZN2Corr[10], tZP2Corr[10]; 
  Float_t dZEM1Corr[2], dZEM2Corr[2], PMRef1[2], PMRef2[2]; 
  for(Int_t i=0; i<10; i++){
     tZN1Corr[i] = tZP1Corr[i] = tZN2Corr[i] = tZP2Corr[i] = 0.;
     if(i<2) dZEM1Corr[i] = dZEM2Corr[i] = PMRef1[i] = PMRef2[i] = 0.;
  }  
  //
  for (Int_t iDigit = 0; iDigit < (digitsTree->GetEntries()/2); iDigit++) {
   digitsTree->GetEntry(iDigit);
   if (!pdigit) continue;
   //  
   Int_t det = digit.GetSector(0);
   Int_t quad = digit.GetSector(1);
   Int_t pedindex = -1, kNch = 24;
   //printf("\n\t Digit #%d det %d quad %d", iDigit, det, quad);
   //
   if(quad != 5){ // ZDC (not reference PTMs!)
    if(det == 1){ // *** ZNC
       pedindex = quad;
       tZN1Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZN1Corr[quad]<0.) tZN1Corr[quad] = 0.;
       tZN1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZN1Corr[quad+5]<0.) tZN1Corr[quad] = 0.;
       //printf("\t pedindex %d tZN1Corr[%d] = %1.0f tZN1Corr[%d] = %1.0f", 
       //	pedindex, quad, tZN1Corr[quad], quad+5, tZN1Corr[quad+5]);
    }
    else if(det == 2){ // *** ZP1
       pedindex = quad+5;
       tZP1Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZP1Corr[quad]<0.) tZP1Corr[quad] = 0.;
       tZP1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZP1Corr[quad+5]<0.) tZP1Corr[quad] = 0.;
       //printf("\t pedindex %d tZP1Corr[%d] = %1.0f tZP1Corr[%d] = %1.0f", 
       //	pedindex, quad, tZP1Corr[quad], quad+5, tZP1Corr[quad+5]);
    }
    else if(det == 3){
       pedindex = quad+9;
       if(quad == 1){	    // *** ZEM1  
         dZEM1Corr[0] += (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]); 
         if(dZEM1Corr[0]<0.) dZEM1Corr[0] = 0.;
         dZEM1Corr[1] += (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]); 
         if(dZEM1Corr[1]<0.) dZEM1Corr[1] = 0.;
         //printf("\t pedindex %d tZEM1Corr[%d] = %1.0f tZEM1Corr[%d] = %1.0f", 
         //	pedindex, quad, tZEM1Corr[quad], quad+1, tZEM1Corr[quad+1]);
       }
       else if(quad == 2){  // *** ZEM2
         dZEM2Corr[0] += (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]); 
         if(dZEM2Corr[0]<0.) dZEM2Corr[0] = 0.;
         dZEM2Corr[1] += (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]); 
         if(dZEM2Corr[1]<0.) dZEM2Corr[1] = 0.;
         //printf("\t pedindex %d tZEM2Corr[%d] = %1.0f tZEM2Corr[%d] = %1.0f", 
         //	pedindex, quad, tZEM2Corr[quad], quad+1, tZEM2Corr[quad+1]);
       }
    }
    else if(det == 4){  // *** ZN2
       pedindex = quad+12;
       tZN2Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZN2Corr[quad]<0.) tZN2Corr[quad] = 0.;
       tZN2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZN2Corr[quad+5]<0.) tZN2Corr[quad+5] = 0.;
       //printf("\t pedindex %d tZN2Corr[%d] = %1.0f tZN2Corr[%d] = %1.0f\n", 
       //	pedindex, quad, tZN2Corr[quad], quad+5, tZN2Corr[quad+5]);
    }
    else if(det == 5){  // *** ZP2 
       pedindex = quad+17;
       tZP2Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZP2Corr[quad]<0.) tZP2Corr[quad] = 0.;
       tZP2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZP2Corr[quad+5]<0.) tZP2Corr[quad+5] = 0.;
       //printf("\t pedindex %d tZP2Corr[%d] = %1.0f tZP2Corr[%d] = %1.0f\n", 
       //	pedindex, quad, tZP2Corr[quad], quad+5, tZP2Corr[quad+5]);
    }
   }
   else{ // Reference PMs
     pedindex = (det-1)/3+22;
     if(det == 1){
       PMRef1[0] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(PMRef1[0]<0.) PMRef1[0] = 0.;
       PMRef1[1] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(PMRef2[1]<0.) PMRef1[1] = 0.;
     }
     else if(det == 4){
       PMRef2[0] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(PMRef2[0]<0.) PMRef2[0] = 0.;
       PMRef2[1] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(PMRef2[1]<0.) PMRef2[1] = 0.;
     }
   }
  }

  // reconstruct the event
  ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
    	dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);

}

//_____________________________________________________________________________
void AliZDCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
{
  // *** ZDC raw data reconstruction
  // Works on the current event
  
  // Retrieving calibration data  
  Float_t meanPed[48];
  for(Int_t jj=0; jj<48; jj++) meanPed[jj] = fPedData->GetMeanPed(jj);

  rawReader->Reset();
  
  // loop over raw data
  Float_t tZN1Corr[10], tZP1Corr[10], tZN2Corr[10], tZP2Corr[10]; 
  Float_t dZEM1Corr[2], dZEM2Corr[2], PMRef1[2], PMRef2[2]; 
  for(Int_t i=0; i<10; i++){
     tZN1Corr[i] = tZP1Corr[i] = tZN2Corr[i] = tZP2Corr[i] = 0.;
     if(i<2) dZEM1Corr[i] = dZEM2Corr[i] = PMRef1[i] = PMRef2[i] = 0.;
  }  
  //
  AliZDCRawStream rawData(rawReader);
  Int_t kNch = 24;
  while (rawData.Next()) {
    if(rawData.IsADCDataWord()){
     Int_t det = rawData.GetSector(0);
     Int_t quad = rawData.GetSector(1);
     Int_t gain = rawData.GetADCGain();
     Int_t pedindex=0;
     //
     if(quad !=5){ // ZDCs (not reference PTMs)
      if(det == 1){    
        pedindex = quad;
        if(gain == 0) tZN1Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZN1Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      else if(det == 2){ 
        pedindex = quad+5;
        if(gain == 0) tZP1Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZP1Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      else if(det == 3){ 
        pedindex = quad+9;
        if(quad==1){	 
          if(gain == 0) dZEM1Corr[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
          else dZEM1Corr[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
        }
        else if(quad==2){ 
          if(gain == 0) dZEM2Corr[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
          else dZEM2Corr[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
        }
      }
      else if(det == 4){       
        pedindex = quad+12;
        if(gain == 0) tZN2Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZN2Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      else if(det == 5){
        pedindex = quad+17;
        if(gain == 0) tZP2Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZP2Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      //printf("\t AliZDCReconstructor - det %d quad %d res %d -> Ped[%d] = %1.0f\n", 
      //  det,quad,gain, pedindex, meanPed[pedindex]);
     }
     else{ // reference PM
       pedindex = (det-1)/3 + 22;
       if(det == 1){
         if(gain==0) PMRef1[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
	 else PMRef1[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
       }
       else if(det ==4){
         if(gain==0) PMRef2[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
	 else PMRef2[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
       }
     }
    }//IsADCDataWord
  }
    
  // reconstruct the event
  ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
    	dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);

}

//_____________________________________________________________________________
void AliZDCReconstructor::ReconstructEventpp(TTree *clustersTree, Float_t* ZN1ADCCorr, 
	Float_t* ZP1ADCCorr, Float_t* ZN2ADCCorr, Float_t* ZP2ADCCorr,
	Float_t* ZEM1ADCCorr, Float_t* ZEM2ADCCorr, Float_t* PMRef1, Float_t* PMRef2) const
{
  // ***** Reconstruct one event
  
  // *** RECONSTRUCTION FROM "REAL" DATA
  //
  // Retrieving calibration data
  // --- Equalization coefficients ---------------------------------------------
  Float_t equalCoeffZN1[5], equalCoeffZP1[5], equalCoeffZN2[5], equalCoeffZP2[5];
  for(Int_t ji=0; ji<5; ji++){
     equalCoeffZN1[ji] = fECalibData->GetZN1EqualCoeff(ji);
     equalCoeffZP1[ji] = fECalibData->GetZP1EqualCoeff(ji); 
     equalCoeffZN2[ji] = fECalibData->GetZN2EqualCoeff(ji); 
     equalCoeffZP2[ji] = fECalibData->GetZP2EqualCoeff(ji); 
  }
  // --- Energy calibration factors ------------------------------------
  Float_t calibEne[4];
  for(Int_t ij=0; ij<4; ij++) calibEne[ij] = fECalibData->GetEnCalib(ij);
  
  // Equalization of detector responses
  Float_t equalTowZN1[10], equalTowZN2[10], equalTowZP1[10], equalTowZP2[10];
  for(Int_t gi=0; gi<5; gi++){
     equalTowZN1[gi] = ZN1ADCCorr[gi]*equalCoeffZN1[gi];
     equalTowZN1[gi+5] = ZN1ADCCorr[gi+5]*equalCoeffZN1[gi];<commit_msg>Until beam type isn't known the E calibration coefficients are set to 1<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// class for ZDC reconstruction                                              //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////


#include <TF1.h>

#include "AliRunLoader.h"
#include "AliRawReader.h"
#include "AliESDEvent.h"
#include "AliESDZDC.h"
#include "AliZDCDigit.h"
#include "AliZDCRawStream.h"
#include "AliZDCReco.h"
#include "AliZDCReconstructor.h"
#include "AliZDCPedestals.h"
#include "AliZDCCalib.h"
#include "AliZDCRecoParam.h"
#include "AliZDCRecoParampp.h"
#include "AliZDCRecoParamPbPb.h"


ClassImp(AliZDCReconstructor)
AliZDCRecoParam *AliZDCReconstructor::fRecoParam=0;  //reconstruction parameters

//_____________________________________________________________________________
AliZDCReconstructor:: AliZDCReconstructor() :
  fPedData(GetPedData()),
  fECalibData(GetECalibData())
{
  // **** Default constructor

}


//_____________________________________________________________________________
AliZDCReconstructor::~AliZDCReconstructor()
{
// destructor
   if(fRecoParam)  delete fRecoParam;
   if(fPedData)    delete fPedData;    
   if(fECalibData) delete fECalibData;
}

//_____________________________________________________________________________
void AliZDCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
{
  // *** Local ZDC reconstruction for digits
  // Works on the current event
    
  // Retrieving calibration data  
  Float_t meanPed[48];
  for(Int_t jj=0; jj<48; jj++) meanPed[jj] = fPedData->GetMeanPed(jj);

  // get digits
  AliZDCDigit digit;
  AliZDCDigit* pdigit = &digit;
  digitsTree->SetBranchAddress("ZDC", &pdigit);
  //printf("\n\t # of digits in tree: %d\n",(Int_t) digitsTree->GetEntries());

  // loop over digits
  Float_t tZN1Corr[10], tZP1Corr[10], tZN2Corr[10], tZP2Corr[10]; 
  Float_t dZEM1Corr[2], dZEM2Corr[2], PMRef1[2], PMRef2[2]; 
  for(Int_t i=0; i<10; i++){
     tZN1Corr[i] = tZP1Corr[i] = tZN2Corr[i] = tZP2Corr[i] = 0.;
     if(i<2) dZEM1Corr[i] = dZEM2Corr[i] = PMRef1[i] = PMRef2[i] = 0.;
  }  
  //
  for (Int_t iDigit = 0; iDigit < (digitsTree->GetEntries()/2); iDigit++) {
   digitsTree->GetEntry(iDigit);
   if (!pdigit) continue;
   //  
   Int_t det = digit.GetSector(0);
   Int_t quad = digit.GetSector(1);
   Int_t pedindex = -1, kNch = 24;
   //printf("\n\t Digit #%d det %d quad %d", iDigit, det, quad);
   //
   if(quad != 5){ // ZDC (not reference PTMs!)
    if(det == 1){ // *** ZNC
       pedindex = quad;
       tZN1Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZN1Corr[quad]<0.) tZN1Corr[quad] = 0.;
       tZN1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZN1Corr[quad+5]<0.) tZN1Corr[quad] = 0.;
       //printf("\t pedindex %d tZN1Corr[%d] = %1.0f tZN1Corr[%d] = %1.0f", 
       //	pedindex, quad, tZN1Corr[quad], quad+5, tZN1Corr[quad+5]);
    }
    else if(det == 2){ // *** ZP1
       pedindex = quad+5;
       tZP1Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZP1Corr[quad]<0.) tZP1Corr[quad] = 0.;
       tZP1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZP1Corr[quad+5]<0.) tZP1Corr[quad] = 0.;
       //printf("\t pedindex %d tZP1Corr[%d] = %1.0f tZP1Corr[%d] = %1.0f", 
       //	pedindex, quad, tZP1Corr[quad], quad+5, tZP1Corr[quad+5]);
    }
    else if(det == 3){
       pedindex = quad+9;
       if(quad == 1){	    // *** ZEM1  
         dZEM1Corr[0] += (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]); 
         if(dZEM1Corr[0]<0.) dZEM1Corr[0] = 0.;
         dZEM1Corr[1] += (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]); 
         if(dZEM1Corr[1]<0.) dZEM1Corr[1] = 0.;
         //printf("\t pedindex %d tZEM1Corr[%d] = %1.0f tZEM1Corr[%d] = %1.0f", 
         //	pedindex, quad, tZEM1Corr[quad], quad+1, tZEM1Corr[quad+1]);
       }
       else if(quad == 2){  // *** ZEM2
         dZEM2Corr[0] += (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]); 
         if(dZEM2Corr[0]<0.) dZEM2Corr[0] = 0.;
         dZEM2Corr[1] += (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]); 
         if(dZEM2Corr[1]<0.) dZEM2Corr[1] = 0.;
         //printf("\t pedindex %d tZEM2Corr[%d] = %1.0f tZEM2Corr[%d] = %1.0f", 
         //	pedindex, quad, tZEM2Corr[quad], quad+1, tZEM2Corr[quad+1]);
       }
    }
    else if(det == 4){  // *** ZN2
       pedindex = quad+12;
       tZN2Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZN2Corr[quad]<0.) tZN2Corr[quad] = 0.;
       tZN2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZN2Corr[quad+5]<0.) tZN2Corr[quad+5] = 0.;
       //printf("\t pedindex %d tZN2Corr[%d] = %1.0f tZN2Corr[%d] = %1.0f\n", 
       //	pedindex, quad, tZN2Corr[quad], quad+5, tZN2Corr[quad+5]);
    }
    else if(det == 5){  // *** ZP2 
       pedindex = quad+17;
       tZP2Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(tZP2Corr[quad]<0.) tZP2Corr[quad] = 0.;
       tZP2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(tZP2Corr[quad+5]<0.) tZP2Corr[quad+5] = 0.;
       //printf("\t pedindex %d tZP2Corr[%d] = %1.0f tZP2Corr[%d] = %1.0f\n", 
       //	pedindex, quad, tZP2Corr[quad], quad+5, tZP2Corr[quad+5]);
    }
   }
   else{ // Reference PMs
     pedindex = (det-1)/3+22;
     if(det == 1){
       PMRef1[0] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(PMRef1[0]<0.) PMRef1[0] = 0.;
       PMRef1[1] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(PMRef2[1]<0.) PMRef1[1] = 0.;
     }
     else if(det == 4){
       PMRef2[0] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
       if(PMRef2[0]<0.) PMRef2[0] = 0.;
       PMRef2[1] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
       if(PMRef2[1]<0.) PMRef2[1] = 0.;
     }
   }
  }

  // reconstruct the event
  ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
    	dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);

}

//_____________________________________________________________________________
void AliZDCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
{
  // *** ZDC raw data reconstruction
  // Works on the current event
  
  // Retrieving calibration data  
  Float_t meanPed[48];
  for(Int_t jj=0; jj<48; jj++) meanPed[jj] = fPedData->GetMeanPed(jj);

  rawReader->Reset();
  
  // loop over raw data
  Float_t tZN1Corr[10], tZP1Corr[10], tZN2Corr[10], tZP2Corr[10]; 
  Float_t dZEM1Corr[2], dZEM2Corr[2], PMRef1[2], PMRef2[2]; 
  for(Int_t i=0; i<10; i++){
     tZN1Corr[i] = tZP1Corr[i] = tZN2Corr[i] = tZP2Corr[i] = 0.;
     if(i<2) dZEM1Corr[i] = dZEM2Corr[i] = PMRef1[i] = PMRef2[i] = 0.;
  }  
  //
  AliZDCRawStream rawData(rawReader);
  Int_t kNch = 24;
  while (rawData.Next()) {
    if(rawData.IsADCDataWord()){
     Int_t det = rawData.GetSector(0);
     Int_t quad = rawData.GetSector(1);
     Int_t gain = rawData.GetADCGain();
     Int_t pedindex=0;
     //
     if(quad !=5){ // ZDCs (not reference PTMs)
      if(det == 1){    
        pedindex = quad;
        if(gain == 0) tZN1Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZN1Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      else if(det == 2){ 
        pedindex = quad+5;
        if(gain == 0) tZP1Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZP1Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      else if(det == 3){ 
        pedindex = quad+9;
        if(quad==1){	 
          if(gain == 0) dZEM1Corr[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
          else dZEM1Corr[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
        }
        else if(quad==2){ 
          if(gain == 0) dZEM2Corr[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
          else dZEM2Corr[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
        }
      }
      else if(det == 4){       
        pedindex = quad+12;
        if(gain == 0) tZN2Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZN2Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      else if(det == 5){
        pedindex = quad+17;
        if(gain == 0) tZP2Corr[quad]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]); 
        else tZP2Corr[quad+5]  += (Float_t) (rawData.GetADCValue()-meanPed[pedindex+kNch]); 
      }
      //printf("\t AliZDCReconstructor - det %d quad %d res %d -> Ped[%d] = %1.0f\n", 
      //  det,quad,gain, pedindex, meanPed[pedindex]);
     }
     else{ // reference PM
       pedindex = (det-1)/3 + 22;
       if(det == 1){
         if(gain==0) PMRef1[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
	 else PMRef1[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
       }
       else if(det ==4){
         if(gain==0) PMRef2[0] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
	 else PMRef2[1] += (Float_t) (rawData.GetADCValue()-meanPed[pedindex]);
       }
     }
    }//IsADCDataWord
  }
    
  // reconstruct the event
  ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
    	dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);

}

//_____________________________________________________________________________
void AliZDCReconstructor::ReconstructEventpp(TTree *clustersTree, Float_t* ZN1ADCCorr, 
	Float_t* ZP1ADCCorr, Float_t* ZN2ADCCorr, Float_t* ZP2ADCCorr,
	Float_t* ZEM1ADCCorr, Float_t* ZEM2ADCCorr, Float_t* PMRef1, Float_t* PMRef2) const
{
  // ***** Reconstruct one event
  
  // *** RECONSTRUCTION FROM "REAL" DATA
  //
  // Retrieving calibration data
  // --- Equalization coefficients ---------------------------------------------
  Float_t equalCoeffZN1[5], equalCoeffZP1[5], equalCoeffZN2[5], equalCoeffZP2[5];
  for(Int_t ji=0; ji<5; ji++){
     equalCoeffZN1[ji] = fECalibData->GetZN1EqualCoeff(ji);
     equalCoeffZP1[ji] = fECalibData->GetZP1EqualCoeff(ji); 
     equalCoeffZN2[ji] = fECalibData->GetZN2EqualCoeff(ji); 
     equalCoeffZP2[ji] = fECalibData->GetZP2EqualCoeff(ji); 
  }
  // --- Energy calibration factors ------------------------------------
  Float_t calibEne[4];
  // *********************************************************************
  // **** Until the beam type info isn't known @ reconstruction level ****
  // **** the energy calibration coefficient are manually set to 1    ****
  // **** as it will be in real life for pp data taking               ****
  // *********************************************************************
  //for(Int_t ij=0; ij<4; ij++) calibEne[ij] = fECalibData->GetEnCalib(ij);
  for(Int_t ij=0; ij<4; ij++) calibEne[ij] = 1.;
  
  // Equalization of detector responses
  Float_t equalTowZN1[10], equalTowZN2[10], equalTowZP1[10], equalTowZP2[10];
  for(Int_t gi=0; gi<5; gi++){
     equalTowZN1[gi] = ZN1ADCCorr[gi]*equalCoeffZN1[gi];
     equalTowZN1[gi+5] = ZN1ADCCorr[gi+5]*equalCoeffZN1[gi];
{'fraction_non_alphanumeric': 0.19282034508136398, 'fraction_numerical': 0.03618447951590482, 'mean_word_length': 2.7635020772426526, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600407', 'n_tokens_mistral': 9903, 'n_tokens_neox': 9488, 'n_words': 1594}