<commit_before>// $Id$
//
// Jet model task to merge to existing branches
// only implemented for track branches
//
// Author: <NAME>

#include "AliJetFastSimulation.h"

#include <TClonesArray.h>
#include <TFolder.h>
#include <TLorentzVector.h>
#include <TParticle.h>
#include <TParticlePDG.h>
#include <TRandom3.h>
#include <TProfile.h>
#include <TGrid.h>
#include <TFile.h>
#include <TF1.h>
#include "AliAnalysisManager.h"
#include "AliEMCALDigit.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALRecPoint.h"
#include "AliGenerator.h"
#include "AliHeader.h"
#include "AliLog.h"
#include "AliPicoTrack.h"
#include "AliRun.h"
#include "AliRunLoader.h"
#include "AliStack.h"
#include "AliStack.h"
#include "AliVCluster.h"
#include "AliVEvent.h"

ClassImp(AliJetFastSimulation)

//________________________________________________________________________
AliJetFastSimulation::AliJetFastSimulation() : 
AliAnalysisTaskEmcal("AliJetFastSimulation",kTRUE),
  fTracksOutName(""),
  fTracksOut(0x0),
  fNTrackClasses(2),
  fRandom(0),
  fEfficiencyFixed(1.),
  fMomResH1(0x0),
  fMomResH2(0x0),
  fMomResH3(0x0),
  fMomResH1Fit(0x0),
  fMomResH2Fit(0x0),
  fMomResH3Fit(0x0),
  fhEffH1(0x0),
  fhEffH2(0x0),
  fhEffH3(0x0),
  fUseTrPtResolutionSmearing(kFALSE),
  fUseDiceEfficiency(kFALSE),
  fDiceEfficiencyMinPt(-1.),
  fUseTrPtResolutionFromOADB(kFALSE),
  fUseTrEfficiencyFromOADB(kFALSE),
  fPathTrPtResolution(""),
  fPathTrEfficiency(""),
  fHistPtDet(0),
  fh2PtGenPtSmeared(0),
  fp1Efficiency(0),
  fp1PtResolution(0)
{
  // Default constructor.
  SetMakeGeneralHistograms(kTRUE);
}

//________________________________________________________________________
AliJetFastSimulation::AliJetFastSimulation(const char *name) : 
  AliAnalysisTaskEmcal(name,kTRUE),
  fTracksOutName(""),
  fTracksOut(0x0),
  fNTrackClasses(2),
  fRandom(0),
  fEfficiencyFixed(1.),
  fMomResH1(0x0),
  fMomResH2(0x0),
  fMomResH3(0x0),
  fMomResH1Fit(0x0),
  fMomResH2Fit(0x0),
  fMomResH3Fit(0x0),
  fhEffH1(0x0),
  fhEffH2(0x0),
  fhEffH3(0x0),
  fUseTrPtResolutionSmearing(kFALSE),
  fUseDiceEfficiency(kFALSE),
  fDiceEfficiencyMinPt(-1.),
  fUseTrPtResolutionFromOADB(kFALSE),
  fUseTrEfficiencyFromOADB(kFALSE),
  fPathTrPtResolution(""),
  fPathTrEfficiency(""),
  fHistPtDet(0),
  fh2PtGenPtSmeared(0),
  fp1Efficiency(0),
  fp1PtResolution(0)
{
  // Standard constructor.
  SetMakeGeneralHistograms(kTRUE);
}

//________________________________________________________________________
AliJetFastSimulation::~AliJetFastSimulation()
{
  // Destructor

  delete fRandom;
}

//________________________________________________________________________
void AliJetFastSimulation::ExecOnce() 
{
  // Exec only once.

  AliAnalysisTaskEmcal::ExecOnce();

  if(!fRandom) fRandom = new TRandom3(0);

  if (!fTracksOutName.IsNull()) {
    fTracksOut = new TClonesArray("AliPicoTrack");
    fTracksOut->SetName(fTracksOutName);
    if (InputEvent()->FindListObject(fTracksOutName)) {
      AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fTracksOutName.Data()));
      return;
    }
    else {
      InputEvent()->AddObject(fTracksOut);
    }
  }
}
//________________________________________________________________________
void AliJetFastSimulation::LocalInit() {
  //initialize track response
  if(fUseTrPtResolutionFromOADB) LoadTrPtResolutionRootFileFromOADB();
  if(fUseTrEfficiencyFromOADB)   LoadTrEfficiencyRootFileFromOADB();
  FitMomentumResolution();
}

//________________________________________________________________________
void AliJetFastSimulation::UserCreateOutputObjects() 
{
  AliAnalysisTaskEmcal::UserCreateOutputObjects();

  const Int_t nBinPt = 100;
  Double_t binLimitsPt[nBinPt+1];
  for(Int_t iPt = 0;iPt <= nBinPt;iPt++){
    if(iPt == 0){
      binLimitsPt[iPt] = 0.0;
    } else {// 1.0
      binLimitsPt[iPt] =  binLimitsPt[iPt-1] + 1.0;
    }
  }

  fHistPtDet = new TH1F("fHistpt","fHistPtDet;#it{p}_{T};N",nBinPt,binLimitsPt);
  fOutput->Add(fHistPtDet);

  fh2PtGenPtSmeared = new TH2F("fh2PtGenPtSmeared","fh2PtGenPtSmeared",nBinPt,binLimitsPt,nBinPt,binLimitsPt);
  fOutput->Add(fh2PtGenPtSmeared);

  fp1Efficiency = new TProfile("fp1Efficiency","fp1Efficiency",nBinPt,binLimitsPt);
  fOutput->Add(fp1Efficiency);

  fp1PtResolution = new TProfile("fp1PtResolution","fp1PtResolution",nBinPt,binLimitsPt);
  fOutput->Add(fp1PtResolution);

  PostData(1, fOutput); // Post data for ALL output slots > 0 here.
}


//________________________________________________________________________
Bool_t AliJetFastSimulation::Run() 
{
  //Check if information is provided detector level effects
  if(!fMomResH1 && fNTrackClasses>0 ) 
    fUseTrPtResolutionSmearing = 0;
  if(!fMomResH2 && fNTrackClasses>1 ) 
    fUseTrPtResolutionSmearing = 0;
  if(!fMomResH3 && fNTrackClasses>2 ) 
    fUseTrPtResolutionSmearing = 0;

  if(fEfficiencyFixed < 1. && !fUseDiceEfficiency)
    fUseDiceEfficiency = 1; // 1 is the default; 2 can be set by user but not implemented
  else {
    if(!fhEffH1 && fNTrackClasses>0 ) 
      fUseDiceEfficiency = 0;
    if(!fhEffH2 && fNTrackClasses>1 ) 
      fUseDiceEfficiency = 0;
    if(!fhEffH3 && fNTrackClasses>2 ) 
      fUseDiceEfficiency = 0;
  }

  fTracksOut->Delete();
  SimulateTracks();
  return kTRUE;
}

//________________________________________________________________________
void AliJetFastSimulation::SimulateTracks()
{
  //Apply toy detector simulation to tracks
  Int_t it = 0;
  const Int_t nTracks = fTracks->GetEntriesFast();
   for (Int_t i = 0; i < nTracks; ++i) {
    AliPicoTrack *picotrack = static_cast<AliPicoTrack*>(fTracks->At(i));
    if (!picotrack)
      continue;

    Bool_t accept = kTRUE;<commit_msg>bug fix fast simulation<commit_after>// $Id$
//
// Jet model task to merge to existing branches
// only implemented for track branches
//
// Author: <NAME>

#include "AliJetFastSimulation.h"

#include <TClonesArray.h>
#include <TFolder.h>
#include <TLorentzVector.h>
#include <TParticle.h>
#include <TParticlePDG.h>
#include <TRandom3.h>
#include <TProfile.h>
#include <TGrid.h>
#include <TFile.h>
#include <TF1.h>
#include "AliAnalysisManager.h"
#include "AliEMCALDigit.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALRecPoint.h"
#include "AliGenerator.h"
#include "AliHeader.h"
#include "AliLog.h"
#include "AliPicoTrack.h"
#include "AliRun.h"
#include "AliRunLoader.h"
#include "AliStack.h"
#include "AliStack.h"
#include "AliVCluster.h"
#include "AliVEvent.h"

ClassImp(AliJetFastSimulation)

//________________________________________________________________________
AliJetFastSimulation::AliJetFastSimulation() : 
AliAnalysisTaskEmcal("AliJetFastSimulation",kTRUE),
  fTracksOutName(""),
  fTracksOut(0x0),
  fNTrackClasses(2),
  fRandom(0),
  fEfficiencyFixed(1.1),
  fMomResH1(0x0),
  fMomResH2(0x0),
  fMomResH3(0x0),
  fMomResH1Fit(0x0),
  fMomResH2Fit(0x0),
  fMomResH3Fit(0x0),
  fhEffH1(0x0),
  fhEffH2(0x0),
  fhEffH3(0x0),
  fUseTrPtResolutionSmearing(kFALSE),
  fUseDiceEfficiency(kFALSE),
  fDiceEfficiencyMinPt(-1.),
  fUseTrPtResolutionFromOADB(kFALSE),
  fUseTrEfficiencyFromOADB(kFALSE),
  fPathTrPtResolution(""),
  fPathTrEfficiency(""),
  fHistPtDet(0),
  fh2PtGenPtSmeared(0),
  fp1Efficiency(0),
  fp1PtResolution(0)
{
  // Default constructor.
  SetMakeGeneralHistograms(kTRUE);
}

//________________________________________________________________________
AliJetFastSimulation::AliJetFastSimulation(const char *name) : 
  AliAnalysisTaskEmcal(name,kTRUE),
  fTracksOutName(""),
  fTracksOut(0x0),
  fNTrackClasses(2),
  fRandom(0),
  fEfficiencyFixed(1.1),
  fMomResH1(0x0),
  fMomResH2(0x0),
  fMomResH3(0x0),
  fMomResH1Fit(0x0),
  fMomResH2Fit(0x0),
  fMomResH3Fit(0x0),
  fhEffH1(0x0),
  fhEffH2(0x0),
  fhEffH3(0x0),
  fUseTrPtResolutionSmearing(kFALSE),
  fUseDiceEfficiency(kFALSE),
  fDiceEfficiencyMinPt(-1.),
  fUseTrPtResolutionFromOADB(kFALSE),
  fUseTrEfficiencyFromOADB(kFALSE),
  fPathTrPtResolution(""),
  fPathTrEfficiency(""),
  fHistPtDet(0),
  fh2PtGenPtSmeared(0),
  fp1Efficiency(0),
  fp1PtResolution(0)
{
  // Standard constructor.
  SetMakeGeneralHistograms(kTRUE);
}

//________________________________________________________________________
AliJetFastSimulation::~AliJetFastSimulation()
{
  // Destructor

  delete fRandom;
}

//________________________________________________________________________
void AliJetFastSimulation::ExecOnce() 
{
  // Exec only once.

  AliAnalysisTaskEmcal::ExecOnce();

  if(!fRandom) fRandom = new TRandom3(0);

  if (!fTracksOutName.IsNull()) {
    fTracksOut = new TClonesArray("AliPicoTrack");
    fTracksOut->SetName(fTracksOutName);
    if (InputEvent()->FindListObject(fTracksOutName)) {
      AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fTracksOutName.Data()));
      return;
    }
    else {
      InputEvent()->AddObject(fTracksOut);
    }
  }
}
//________________________________________________________________________
void AliJetFastSimulation::LocalInit() {
  //initialize track response
  if(fUseTrPtResolutionFromOADB) LoadTrPtResolutionRootFileFromOADB();
  if(fUseTrEfficiencyFromOADB)   LoadTrEfficiencyRootFileFromOADB();
  FitMomentumResolution();
}

//________________________________________________________________________
void AliJetFastSimulation::UserCreateOutputObjects() 
{
  AliAnalysisTaskEmcal::UserCreateOutputObjects();

  const Int_t nBinPt = 100;
  Double_t binLimitsPt[nBinPt+1];
  for(Int_t iPt = 0;iPt <= nBinPt;iPt++){
    if(iPt == 0){
      binLimitsPt[iPt] = 0.0;
    } else {// 1.0
      binLimitsPt[iPt] =  binLimitsPt[iPt-1] + 1.0;
    }
  }

  fHistPtDet = new TH1F("fHistpt","fHistPtDet;#it{p}_{T};N",nBinPt,binLimitsPt);
  fOutput->Add(fHistPtDet);

  fh2PtGenPtSmeared = new TH2F("fh2PtGenPtSmeared","fh2PtGenPtSmeared",nBinPt,binLimitsPt,nBinPt,binLimitsPt);
  fOutput->Add(fh2PtGenPtSmeared);

  fp1Efficiency = new TProfile("fp1Efficiency","fp1Efficiency",nBinPt,binLimitsPt);
  fOutput->Add(fp1Efficiency);

  fp1PtResolution = new TProfile("fp1PtResolution","fp1PtResolution",nBinPt,binLimitsPt);
  fOutput->Add(fp1PtResolution);

  PostData(1, fOutput); // Post data for ALL output slots > 0 here.
}


//________________________________________________________________________
Bool_t AliJetFastSimulation::Run() 
{
  //Check if information is provided detector level effects
  if(!fMomResH1 && fNTrackClasses>0 ) 
    fUseTrPtResolutionSmearing = 0;
  if(!fMomResH2 && fNTrackClasses>1 ) 
    fUseTrPtResolutionSmearing = 0;
  if(!fMomResH3 && fNTrackClasses>2 ) 
    fUseTrPtResolutionSmearing = 0;

  if(fEfficiencyFixed < 1.)
    fUseDiceEfficiency = 1; // 1 is the default; 2 can be set by user but not implemented
  else {
    if(!fhEffH1 && fNTrackClasses>0 ) 
      fUseDiceEfficiency = 0;
    if(!fhEffH2 && fNTrackClasses>1 ) 
      fUseDiceEfficiency = 0;
    if(!fhEffH3 && fNTrackClasses>2 ) 
      fUseDiceEfficiency = 0;
  }

  fTracksOut->Delete();
  SimulateTracks();
  return kTRUE;
}

//________________________________________________________________________
void AliJetFastSimulation::SimulateTracks()
{
  //Apply toy detector simulation to tracks
  Int_t it = 0;
  const Int_t nTracks = fTracks->GetEntriesFast();
   for (Int_t i = 0; i < nTracks; ++i) {
    AliPicoTrack *picotrack = static_cast<AliPicoTrack*>(fTracks->At(i));
    if (!picotrack)
      continue;

    Bool_t accept = kTRUE;
{'fraction_non_alphanumeric': 0.123410227173055, 'fraction_numerical': 0.024208402771686694, 'mean_word_length': 5.636786961583236, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206792', 'n_tokens_mistral': 4392, 'n_tokens_neox': 4143, 'n_words': 625}