--- /dev/null
+/**************************************************************************
+ * Copyright(c) 1998-2007, 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. *
+ **************************************************************************/
+
+//-----------------------------------------------------------------------
+// Particle generator according to 4 correlated variables : here
+// z, ptot, r, theta. The input is a THnSparse object included in
+// the root file (path and name to be set via the SetTHnSparse method).
+// This class is similar to AliGenFunction.
+//-----------------------------------------------------------------------
+// Author : X. Lopez - LPC Clermont (fr)
+//-----------------------------------------------------------------------
+/*
+ Example for generation :
+
+ AliGenTHnSparse *gener = new AliGenTHnSparse();
+ gener->SetNumberParticles(10);
+ gener->SetPart(13);
+ gener->SetThnSparse("file_name","thn_name");
+ gener->Init();
+*/
+
+#include <TRandom.h>
+#include <TFile.h>
+#include "THnSparse.h"
+
+#include "AliGenTHnSparse.h"
+
+ClassImp(AliGenTHnSparse)
+
+//_______________________________________________________________________
+AliGenTHnSparse::AliGenTHnSparse():
+ AliGenerator(),
+ fHn(0),
+ fFile(0),
+ fIpart(0)
+{
+ // Default constructor
+ SetNumberParticles(1);
+}
+
+//_______________________________________________________________________
+AliGenTHnSparse::AliGenTHnSparse(const AliGenTHnSparse& func):
+ AliGenerator(),
+ fHn(func.fHn),
+ fFile(func.fFile),
+ fIpart(func.fIpart)
+{
+ // Copy constructor
+ SetNumberParticles(1);
+}
+
+//_______________________________________________________________________
+AliGenTHnSparse & AliGenTHnSparse::operator=(const AliGenTHnSparse& func)
+{
+ // Assigment operator
+ if(&func == this) return *this;
+ fHn = func.fHn;
+ fFile = func.fFile;
+ fIpart = func.fIpart;
+ return *this;
+}
+
+//_______________________________________________________________________
+AliGenTHnSparse::~AliGenTHnSparse()
+{
+ // Destructor
+ delete fFile;
+}
+
+//_______________________________________________________________________
+void AliGenTHnSparse::Generate()
+{
+
+ // Generate Npart of id Ipart
+
+ Double_t rand[4]; // z, ptot, r, theta
+ Float_t pos[3], phi, ptot, theta, pt, z, r;
+ Float_t mom[3];
+ Int_t pdg = fIpart;
+
+ for (Int_t ipart = 0; ipart < fNpart; ipart++) {
+
+ fHn->GetRandom(rand);
+ z=rand[0];
+ ptot=rand[1];
+ r=rand[2];
+ theta=rand[3];
+
+// Phi: same for position and momemtum
+
+ phi=(-180+gRandom->Rndm()*360)*TMath::Pi()/180;
+
+// position at production
+
+ pos[0] = r*TMath::Cos(phi);
+ pos[1] = r*TMath::Sin(phi);
+ pos[2] = z;
+
+// momentum at production
+
+ pt = ptot*TMath::Sin(theta);
+ mom[0] = pt*TMath::Cos(phi);
+ mom[1] = pt*TMath::Sin(phi);
+ mom[2] = ptot*TMath::Cos(theta);
+
+// propagation
+
+ Float_t polarization[3]= {0,0,0};
+ Int_t nt;
+ PushTrack(fTrackIt,-1,pdg,mom, pos, polarization,0,kPPrimary,nt);
+ }
+
+ return;
+}
+
+//_______________________________________________________________________
+void AliGenTHnSparse::Init()
+{
+
+ // Initialisation, check consistency of selected file
+ printf("************ AliGenTHnSparse ****************\n");
+ printf("*********************************************\n");
+ if (!fHn){
+ AliFatal("THnSparse file not specified");
+ }
+
+ return;
+}
+
+//_______________________________________________________________________
+void AliGenTHnSparse::SetThnSparse(char *file_name, char *thn_name)
+{
+
+ // Open the file and get object
+ TFile *fFile = new TFile(file_name);
+ fHn = (THnSparseF*)(fFile->Get(thn_name));
+
+}
--- /dev/null
+#ifndef ALIGENTHNSPARSE_H
+#define ALIGENTHNSPARSE_H
+/* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+// Particle generator according to 4 correlated variables : here
+// z, ptot, r, theta. The input is a THnSparse object included in
+// the root file (path and name to be set via the SetTHnSparse method).
+// This class is similar to AliGenFunction.
+
+#include "AliLog.h"
+#include "AliGenerator.h"
+#include "THnSparse.h"
+
+class AliGenTHnSparse : public AliGenerator
+{
+public:
+
+ AliGenTHnSparse();
+ AliGenTHnSparse(const AliGenTHnSparse& func);
+ AliGenTHnSparse &operator=(const AliGenTHnSparse& func);
+ virtual ~AliGenTHnSparse();
+ virtual void Generate();
+ virtual void Init();
+ virtual void SetPart(Int_t part) {fIpart=part;}
+ virtual void SetThnSparse(char *file_name, char *thn_name);
+
+private:
+
+ THnSparse *fHn; // Pointer to THnSparse object
+ TFile *fFile; // Pointer to input file
+ Int_t fIpart; // Particle type
+
+ ClassDef(AliGenTHnSparse,1)
+};
+
+#endif