<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 JetFinder Input preparation from simulated data 
//
//*-- Author: <NAME> (LBL/UCT)
//



#include "AliEMCALJetFinderInputSimPrep.h"

#include <TParticle.h>
#include <TParticlePDG.h>
#include <TPDGCode.h>
#include <TFile.h>
#include <TTree.h>
#include <TObjectTable.h>
#include <TMath.h>


#include "AliRun.h"
#include "AliMagF.h"
#include "AliEMCALFast.h"
#include "AliEMCAL.h"
#include "AliEMCALHit.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALGetter.h"
#include "AliGenEventHeader.h"
#include "AliGenPythiaEventHeader.h"
#include "AliGenerator.h"
#include "AliHeader.h"
#include "AliMC.h"


ClassImp(AliEMCALJetFinderInputSimPrep)
	
AliEMCALJetFinderInputSimPrep::AliEMCALJetFinderInputSimPrep()
{
	// Default constructor
if (fDebug > 0) Info("AliEMCALJetFinderInputSimPrep","Beginning Constructor");	
  
  fDebug = 0;
  fSmearType = kSmearEffic;
  fEMCALType = kHits;
  fTrackType = kCharged;
  fEfficiency = 0.90;
  
}
AliEMCALJetFinderInputSimPrep::~AliEMCALJetFinderInputSimPrep()
{
if (fDebug > 0) Info("~AliEMCALJetFinderInputSimPrep","Beginning Destructor");	
	
}

void AliEMCALJetFinderInputSimPrep::Reset(AliEMCALJetFinderResetType_t resettype)
{
	// Method to reset data
if (fDebug > 1) Info("Reset","Beginning Reset");
	switch (resettype){

	case kResetData:
		fInputObject.Reset(resettype);
		break;
	case kResetTracks:
		fInputObject.Reset(resettype);
		break;
	case kResetDigits:
		fInputObject.Reset(resettype);
		break;
	case kResetParameters:
		fSmearType = kSmearEffic;
	       	fEMCALType = kHits;
		fTrackType = kCharged;
		break;
	case kResetAll:
		fSmearType = kSmearEffic;
	       	fEMCALType = kHits;
		fTrackType = kCharged;
		fInputObject.Reset(resettype);
		break;
	case kResetPartons:
	  Warning("FillFromFile", "kResetPartons not implemented") ; 
	  break;
	case kResetParticles:
	  Warning("FillFromFile", "kResetParticles not implemented") ; 
	  break;
	case kResetJets:
	  Warning("FillFromFile", "kResetJets not implemented") ; 
	  break;
	}// end switch

}

Int_t AliEMCALJetFinderInputSimPrep::FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype,Int_t EventNumber)
{
  // gObjectTable->Print();
	// Test that file exists - Getter doesn't like bogus filenames	
if (fDebug > 1) Info("FillFromFile","Beginning FillFromFile");
   fFileType = filetype;	
   TFile file(filename->Data());
   if (!file.IsOpen()){ 
	   Error("FillFromFile","Could not open file in FillFromFile");
	   return -1;
   }
   file.Close();
   /*
   gAlice =  static_cast<AliRun *>(file.Get("gAlice"));
   AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL"); 
   if (gAlice->GetEvent(EventNumber) < 0){
	   Error("FillFromFile","Could not open event in FillFromFile");
	   file.Close();
	   return -1;
   }*/
   AliEMCALGetter *gime = AliEMCALGetter::Instance(filename->Data());
   gime->Event(EventNumber) ;
 
   if (	fEMCALType == kHits ||
	fEMCALType == kTimeCut )  FillHits();
   if ( fTrackType != kNoTracks  )  FillTracks();	
   if ( fFileType  != kData){
	   FillPartons();
//	   FillParticles();
   }
   //gime->CloseFile();
//   gObjectTable->Print();	
   delete gime;   
   return 0;	
}

void AliEMCALJetFinderInputSimPrep::FillHits()		
{
	// Fill from the hits to input object from simulation
if (fDebug > 1) Info("FillHits","Beginning FillHits");
	
// Access hit information
    AliEMCALHit *mHit;
    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
    Info("AliEMCALJetFinderInputSimPrep","Title of the geometry is %s",pEMCAL->GetTitle());
    AliEMCALGeometry* geom =  AliEMCALGetter::Instance()->EMCALGeometry();
//    Float_t samplingF = geom->GetSampling();
    Float_t samplingF = 11.6;
    Info("AliEMCALJetFinderInputSimPrep","Sampling fraction is %f",samplingF);  
    TTree *treeH = AliEMCALGetter::Instance()->TreeH();
    Int_t ntracks = (Int_t) treeH->GetEntries();
//
//   Loop over tracks
//
    Int_t nbytes = 0;
    Double_t etH = 0.0;

    for (Int_t track=0; track<ntracks;track++) {
        gAlice->ResetHits();
        nbytes += treeH->GetEvent(track);
//
//  Loop over hits
//
        for(mHit=(AliEMCALHit*) pEMCAL->FirstHit(-1);
            mHit;
            mHit=(AliEMCALHit*) pEMCAL->NextHit())
        {
                if (fEMCALType == kTimeCut && 
		    (mHit->GetTime()>fTimeCut) ) continue;
            Float_t x      =    mHit->X();         // x-pos of hit
            Float_t y      =    mHit->Y();         // y-pos
            Float_t z      =    mHit->Z();         // z-pos
            Float_t eloss  =    mHit->GetEnergy(); // deposited energy

            Float_t r      =    TMath::Sqrt(x*x+y*y);
            Float_t theta  =    TMath::ATan2(r,z);
            Float_t eta    =   -TMath::Log(TMath::Tan(theta/2.));
            Float_t phi    =    TMath::ATan2(y,x);
            etH = samplingF*eloss*TMath::Sin(theta);
	    if (fDebug > 10) Info("FillHits","Values of hit energy %i",Int_t(1e7*etH));
	    if (geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi) == -1) 
	    {
		    if (fDebug >5)  
		    {
			    Error("FillHits","Hit not inside EMCAL!");
			    mHit->Dump();
		    }
		    continue;<commit_msg>Removed sampling fraction from jet finder code - now in hits code<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 JetFinder Input preparation from simulated data 
//
//*-- Author: <NAME> (LBL/UCT)
//



#include "AliEMCALJetFinderInputSimPrep.h"

#include <TParticle.h>
#include <TParticlePDG.h>
#include <TPDGCode.h>
#include <TFile.h>
#include <TTree.h>
#include <TObjectTable.h>
#include <TMath.h>


#include "AliRun.h"
#include "AliMagF.h"
#include "AliEMCALFast.h"
#include "AliEMCAL.h"
#include "AliEMCALHit.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALGetter.h"
#include "AliGenEventHeader.h"
#include "AliGenPythiaEventHeader.h"
#include "AliGenerator.h"
#include "AliHeader.h"
#include "AliMC.h"


ClassImp(AliEMCALJetFinderInputSimPrep)
	
AliEMCALJetFinderInputSimPrep::AliEMCALJetFinderInputSimPrep()
{
	// Default constructor
if (fDebug > 0) Info("AliEMCALJetFinderInputSimPrep","Beginning Constructor");	
  
  fDebug = 0;
  fSmearType = kSmearEffic;
  fEMCALType = kHits;
  fTrackType = kCharged;
  fEfficiency = 0.90;
  
}
AliEMCALJetFinderInputSimPrep::~AliEMCALJetFinderInputSimPrep()
{
if (fDebug > 0) Info("~AliEMCALJetFinderInputSimPrep","Beginning Destructor");	
	
}

void AliEMCALJetFinderInputSimPrep::Reset(AliEMCALJetFinderResetType_t resettype)
{
	// Method to reset data
if (fDebug > 1) Info("Reset","Beginning Reset");
	switch (resettype){

	case kResetData:
		fInputObject.Reset(resettype);
		break;
	case kResetTracks:
		fInputObject.Reset(resettype);
		break;
	case kResetDigits:
		fInputObject.Reset(resettype);
		break;
	case kResetParameters:
		fSmearType = kSmearEffic;
	       	fEMCALType = kHits;
		fTrackType = kCharged;
		break;
	case kResetAll:
		fSmearType = kSmearEffic;
	       	fEMCALType = kHits;
		fTrackType = kCharged;
		fInputObject.Reset(resettype);
		break;
	case kResetPartons:
	  Warning("FillFromFile", "kResetPartons not implemented") ; 
	  break;
	case kResetParticles:
	  Warning("FillFromFile", "kResetParticles not implemented") ; 
	  break;
	case kResetJets:
	  Warning("FillFromFile", "kResetJets not implemented") ; 
	  break;
	}// end switch

}

Int_t AliEMCALJetFinderInputSimPrep::FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype,Int_t EventNumber)
{
  // gObjectTable->Print();
	// Test that file exists - Getter doesn't like bogus filenames	
if (fDebug > 1) Info("FillFromFile","Beginning FillFromFile");
   fFileType = filetype;	
   TFile file(filename->Data());
   if (!file.IsOpen()){ 
	   Error("FillFromFile","Could not open file in FillFromFile");
	   return -1;
   }
   file.Close();
   /*
   gAlice =  static_cast<AliRun *>(file.Get("gAlice"));
   AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL"); 
   if (gAlice->GetEvent(EventNumber) < 0){
	   Error("FillFromFile","Could not open event in FillFromFile");
	   file.Close();
	   return -1;
   }*/
   AliEMCALGetter *gime = AliEMCALGetter::Instance(filename->Data());
   gime->Event(EventNumber) ;
 
   if (	fEMCALType == kHits ||
	fEMCALType == kTimeCut )  FillHits();
   if ( fTrackType != kNoTracks  )  FillTracks();	
   if ( fFileType  != kData){
	   FillPartons();
//	   FillParticles();
   }
   //gime->CloseFile();
//   gObjectTable->Print();	
   delete gime;   
   return 0;	
}

void AliEMCALJetFinderInputSimPrep::FillHits()		
{
	// Fill from the hits to input object from simulation
if (fDebug > 1) Info("FillHits","Beginning FillHits");
	
// Access hit information
    AliEMCALHit *mHit;
    AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
    Info("AliEMCALJetFinderInputSimPrep","Title of the geometry is %s",pEMCAL->GetTitle());
    AliEMCALGeometry* geom =  AliEMCALGetter::Instance()->EMCALGeometry();
    TTree *treeH = AliEMCALGetter::Instance()->TreeH();
    Int_t ntracks = (Int_t) treeH->GetEntries();
//
//   Loop over tracks
//
    Int_t nbytes = 0;
    Double_t etH = 0.0;

    for (Int_t track=0; track<ntracks;track++) {
        gAlice->ResetHits();
        nbytes += treeH->GetEvent(track);
//
//  Loop over hits
//
        for(mHit=(AliEMCALHit*) pEMCAL->FirstHit(-1);
            mHit;
            mHit=(AliEMCALHit*) pEMCAL->NextHit())
        {
                if (fEMCALType == kTimeCut && 
		    (mHit->GetTime()>fTimeCut) ) continue;
            Float_t x      =    mHit->X();         // x-pos of hit
            Float_t y      =    mHit->Y();         // y-pos
            Float_t z      =    mHit->Z();         // z-pos
            Float_t eloss  =    mHit->GetEnergy(); // deposited energy

            Float_t r      =    TMath::Sqrt(x*x+y*y);
            Float_t theta  =    TMath::ATan2(r,z);
            Float_t eta    =   -TMath::Log(TMath::Tan(theta/2.));
            Float_t phi    =    TMath::ATan2(y,x);
            etH = eloss*TMath::Sin(theta);
	    if (fDebug > 10) Info("FillHits","Values of hit energy %i",Int_t(1e7*etH));
	    if (geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi) == -1) 
	    {
		    if (fDebug >5)  
		    {
			    Error("FillHits","Hit not inside EMCAL!");
			    mHit->Dump();
		    }
		    continue;
{'fraction_non_alphanumeric': 0.14708239820455274, 'fraction_numerical': 0.006492465533824944, 'mean_word_length': 3.0183574879227053, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 86, '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': '4318052', 'n_tokens_mistral': 4397, 'n_tokens_neox': 4044, 'n_words': 901}