<commit_before>
/**************************************************************************
 * Copyright(c) 1998-2000, 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.                  *
 **************************************************************************/


#include <TTree.h> 
#include <TVector.h>
#include <TObjArray.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TRandom.h>
#include <TArrayI.h>
#include <TH1.h>


#include "AliSTARTDigitizer.h"
#include "AliSTART.h"
#include "AliSTARThit.h"
#include "AliSTARThitPhoton.h"
#include "AliSTARTdigit.h"
#include "AliRunDigitizer.h"
#include "AliHeader.h"
#include "AliGenEventHeader.h"
#include "AliRun.h"
#include "AliPDG.h"
#include "AliLoader.h"
#include "AliRunLoader.h"
#include "AliSTARTLoader.h"

#include <stdlib.h>
#include <Riostream.h>
#include <Riostream.h>

ClassImp(AliSTARTDigitizer)

//___________________________________________
  AliSTARTDigitizer::AliSTARTDigitizer()  :AliDigitizer()
{
// Default ctor - don't use it
  ;
}

//___________________________________________
AliSTARTDigitizer::AliSTARTDigitizer(AliRunDigitizer* manager) 
    :AliDigitizer(manager) 
{
	cout<<"AliSTARTDigitizer::AliSTARTDigitizer"<<endl;
// ctor which should be used
//  fDebug =0;
 // if (GetDebug()>2)
  //  cerr<<"AliSTARTDigitizer::AliSTARTDigitizer"
   //     <<"(AliRunDigitizer* manager) was processed"<<endl;

}

//------------------------------------------------------------------------
AliSTARTDigitizer::~AliSTARTDigitizer()
{
// Destructor


}

 //------------------------------------------------------------------------
Bool_t AliSTARTDigitizer::Init()
{
// Initialization
 cout<<"AliSTARTDigitizer::Init"<<endl;
 return kTRUE;
}
 

//---------------------------------------------------------------------

void AliSTARTDigitizer::Exec(Option_t* /*option*/)
{


  AliRunLoader *inRL, *outRL;//in and out Run Loaders
  AliLoader *ingime, *outgime;// in and out ITSLoaders

  outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
  outgime = outRL->GetLoader("STARTLoader");

#ifdef DEBUG
  cout<<"AliSTARTDigitizer::>SDigits2Digits start...\n";
#endif
  //
  // From hits to digits
  //
  Int_t hit, nhits;
  Int_t CountEr[13],CountEl[13];							//!!!
  Int_t volume,pmt,tr,tl,sumRight;
  Float_t timediff,timeav;
  Float_t besttimeright,besttimeleft,meanTime;
  Int_t  bestRightADC,bestLeftADC;
  Float_t besttimeleftGaus, besttimerightGaus;
  Float_t timeright[13]={13*0};
  Float_t timeleft[13]={13*0};
  Float_t channelWidth=2.5; //ps
  Int_t channelWidthADC=1; //ps
  //  Int_t thresholdAmpl=10;

  ftimeRightTDC = new TArrayI(12); 
  ftimeLeftTDC = new TArrayI(12); 
  fRightADC = new TArrayI(12); 
  fLeftADC = new TArrayI(12); 
  
  inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
  inRL->LoadgAlice();
  
  //  fHits = new TClonesArray ("AliSTARThit", 1000);
  fPhotons = new TClonesArray ("AliSTARThitPhoton", 10000);			//!!!
  AliSTART *START  = (AliSTART*) gAlice->GetDetector("START");
  AliSTARThit  *startHit;
  //use if Cherenkov photons
  //  AliSTARThitPhoton  *startHitPhoton;						//!!!
  TBranch *brHits=0;
  TBranch *brHitPhoton=0;
  fdigits= new AliSTARTdigit();

  Int_t nFiles=fManager->GetNinputs();
  for (Int_t inputFile=0; inputFile<nFiles;  inputFile++) {

    besttimeright=9999.;
    besttimeleft=9999.;
    Int_t timeDiff=0;
    Int_t timeAv=0;
    sumRight=0;
    for (Int_t i0=0; i0<13; i0++)
      {
	timeright[i0]=0; timeleft[i0]=0;
	CountEr[i0]=0;   CountEl[i0]=0;
      }

    inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
    ingime = inRL->GetLoader("STARTLoader");
    ingime->LoadHits("READ");//probably it is necessary to load them before
    ingime->LoadDigits("UPDATE");//probably it is necessary to load them before
    //use if Cherenkov photons
    //  TClonesArray *STARThitsPhotons = START->Photons ();
    TClonesArray *fHits = START->Hits ();
    //    cout<<" Load  "<<AliSTARTLoader::LoadDigits()<<endl;

    TTree *th = ingime->TreeH();
    brHits = th->GetBranch("START");
    brHitPhoton = th->GetBranch("STARThitPhoton");
    if (brHits) {
      START->SetHitsAddressBranch(brHits,brHitPhoton);
    }else{
      cerr<<"EXEC Branch START hit not found"<<endl;
      exit(111);
    } 
    Int_t ntracks    = (Int_t) th->GetEntries();
    cout<<" ntracks "<<ntracks<<endl;
    if (ntracks<=0) return;
    // Start loop on tracks in the photon hits containers 
    // for amplitude
    /*
    if(brHitPhoton) {
      cout<<"brHitPhoton "<<endl; 
      for (Int_t track=0; track<ntracks;track++) {
	brHitPhoton -> GetEntry(track);;
	nhits = STARThitsPhotons->GetEntriesFast();
	for (hit=0;hit<nhits;hit++) {
	  startHitPhoton   = (AliSTARThitPhoton*) 
	   STARThitsPhotons ->UncheckedAt(hit);
	  pmt=startHitPhoton->fPmt;
	  volume = startHitPhoton->fArray;
	  if(RegisterPhotoE(startHitPhoton)) 
	    {
	      if (volume == 1) CountEr[pmt]++;
	      if (volume == 2) CountEl[pmt]++;
	    }
	} //hit photons
      } //track photons
    } // was photons
    */
    // Start loop on tracks in the hits containers
    for (Int_t track=0; track<ntracks;track++) {
      brHits->GetEntry(track);
      nhits = fHits->GetEntriesFast();
      //  cout<<" brHits hits "<<nhits<<endl;
      for (hit=0;hit<nhits;hit++) {
	startHit   = (AliSTARThit*) fHits->UncheckedAt(hit);
	pmt=startHit->Pmt();
	volume = startHit->Volume();
	if(volume==1){
	  timeright[pmt] = startHit->Time();
	  if(timeright[pmt]<besttimeright)
	    //&&CountEr[pmt-1]>thresholdAmpl)
	    {<commit_msg>Protection in case of missing hit (alpha)<commit_after>
/**************************************************************************
 * Copyright(c) 1998-2000, 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.                  *
 **************************************************************************/


#include <TTree.h> 
#include <TVector.h>
#include <TObjArray.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TRandom.h>
#include <TArrayI.h>
#include <TH1.h>
#include <TError.h>


#include "AliSTARTDigitizer.h"
#include "AliSTART.h"
#include "AliSTARThit.h"
#include "AliSTARThitPhoton.h"
#include "AliSTARTdigit.h"
#include "AliRunDigitizer.h"
#include "AliHeader.h"
#include "AliGenEventHeader.h"
#include "AliRun.h"
#include "AliPDG.h"
#include "AliLoader.h"
#include "AliRunLoader.h"
#include "AliSTARTLoader.h"

#include <stdlib.h>
#include <Riostream.h>
#include <Riostream.h>

ClassImp(AliSTARTDigitizer)

//___________________________________________
  AliSTARTDigitizer::AliSTARTDigitizer()  :AliDigitizer()
{
// Default ctor - don't use it
  ;
}

//___________________________________________
AliSTARTDigitizer::AliSTARTDigitizer(AliRunDigitizer* manager) 
    :AliDigitizer(manager) 
{
	cout<<"AliSTARTDigitizer::AliSTARTDigitizer"<<endl;
// ctor which should be used
//  fDebug =0;
 // if (GetDebug()>2)
  //  cerr<<"AliSTARTDigitizer::AliSTARTDigitizer"
   //     <<"(AliRunDigitizer* manager) was processed"<<endl;

}

//------------------------------------------------------------------------
AliSTARTDigitizer::~AliSTARTDigitizer()
{
// Destructor


}

 //------------------------------------------------------------------------
Bool_t AliSTARTDigitizer::Init()
{
// Initialization
 cout<<"AliSTARTDigitizer::Init"<<endl;
 return kTRUE;
}
 

//---------------------------------------------------------------------

void AliSTARTDigitizer::Exec(Option_t* /*option*/)
{


  AliRunLoader *inRL, *outRL;//in and out Run Loaders
  AliLoader *ingime, *outgime;// in and out ITSLoaders

  outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
  outgime = outRL->GetLoader("STARTLoader");

#ifdef DEBUG
  cout<<"AliSTARTDigitizer::>SDigits2Digits start...\n";
#endif
  //
  // From hits to digits
  //
  Int_t hit, nhits;
  Int_t CountEr[13],CountEl[13];							//!!!
  Int_t volume,pmt,tr,tl,sumRight;
  Float_t timediff,timeav;
  Float_t besttimeright,besttimeleft,meanTime;
  Int_t  bestRightADC,bestLeftADC;
  Float_t besttimeleftGaus, besttimerightGaus;
  Float_t timeright[13]={13*0};
  Float_t timeleft[13]={13*0};
  Float_t channelWidth=2.5; //ps
  Int_t channelWidthADC=1; //ps
  //  Int_t thresholdAmpl=10;

  ftimeRightTDC = new TArrayI(12); 
  ftimeLeftTDC = new TArrayI(12); 
  fRightADC = new TArrayI(12); 
  fLeftADC = new TArrayI(12); 
  
  inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
  inRL->LoadgAlice();
  
  //  fHits = new TClonesArray ("AliSTARThit", 1000);
  fPhotons = new TClonesArray ("AliSTARThitPhoton", 10000);			//!!!
  AliSTART *START  = (AliSTART*) gAlice->GetDetector("START");
  AliSTARThit  *startHit;
  //use if Cherenkov photons
  //  AliSTARThitPhoton  *startHitPhoton;						//!!!
  TBranch *brHits=0;
  TBranch *brHitPhoton=0;
  fdigits= new AliSTARTdigit();

  Int_t nFiles=fManager->GetNinputs();
  for (Int_t inputFile=0; inputFile<nFiles;  inputFile++) {

    besttimeright=9999.;
    besttimeleft=9999.;
    Int_t timeDiff=0;
    Int_t timeAv=0;
    sumRight=0;
    for (Int_t i0=0; i0<13; i0++)
      {
	timeright[i0]=0; timeleft[i0]=0;
	CountEr[i0]=0;   CountEl[i0]=0;
      }

    inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
    ingime = inRL->GetLoader("STARTLoader");
    ingime->LoadHits("READ");//probably it is necessary to load them before
    ingime->LoadDigits("UPDATE");//probably it is necessary to load them before
    //use if Cherenkov photons
    //  TClonesArray *STARThitsPhotons = START->Photons ();
    TClonesArray *fHits = START->Hits ();
    //    cout<<" Load  "<<AliSTARTLoader::LoadDigits()<<endl;

    TTree *th = ingime->TreeH();
    brHits = th->GetBranch("START");
    brHitPhoton = th->GetBranch("STARThitPhoton");
    if (brHits) {
      START->SetHitsAddressBranch(brHits,brHitPhoton);
    }else{
      cerr<<"EXEC Branch START hit not found"<<endl;
      exit(111);
    } 
    Int_t ntracks    = (Int_t) th->GetEntries();
    cout<<" ntracks "<<ntracks<<endl;
    if (ntracks<=0) return;
    // Start loop on tracks in the photon hits containers 
    // for amplitude
    /*
    if(brHitPhoton) {
      cout<<"brHitPhoton "<<endl; 
      for (Int_t track=0; track<ntracks;track++) {
	brHitPhoton -> GetEntry(track);;
	nhits = STARThitsPhotons->GetEntriesFast();
	for (hit=0;hit<nhits;hit++) {
	  startHitPhoton   = (AliSTARThitPhoton*) 
	   STARThitsPhotons ->UncheckedAt(hit);
	  pmt=startHitPhoton->fPmt;
	  volume = startHitPhoton->fArray;
	  if(RegisterPhotoE(startHitPhoton)) 
	    {
	      if (volume == 1) CountEr[pmt]++;
	      if (volume == 2) CountEl[pmt]++;
	    }
	} //hit photons
      } //track photons
    } // was photons
    */
    // Start loop on tracks in the hits containers
    for (Int_t track=0; track<ntracks;track++) {
      brHits->GetEntry(track);
      nhits = fHits->GetEntriesFast();
      //  cout<<" brHits hits "<<nhits<<endl;
      for (hit=0;hit<nhits;hit++) {
	startHit   = (AliSTARThit*) fHits->UncheckedAt(hit);
	if (!startHit) {
	  ::Error("Exec","The unchecked hit doesn't exist");
	  break;
	}
	pmt=startHit->Pmt();
	volume = startHit->Volume();
	if(volume==1){
	  timeright[pmt] = startHit->Time();
	  if(timeright[pmt]<besttimeright)
	    //&&CountEr[pmt-1]>thresholdAmpl)
	    {
{'fraction_non_alphanumeric': 0.1862828768717511, 'fraction_numerical': 0.013810225773915743, 'mean_word_length': 2.9857761286332716, 'pattern_counts': {'":': 0, '<': 126, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2854919', 'n_tokens_mistral': 4502, 'n_tokens_neox': 4215, 'n_words': 894}