]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenReaderHepMC.cxx
correcting DDL bit for AD and HLT
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderHepMC.cxx
CommitLineData
b897d37f 1#include <TVirtualMC.h>
2#include <TDatabasePDG.h>
3#include <TParticle.h>
4
5#include "AliGenReaderHepMC.h"
6#include "AliRun.h"
7#include "AliStack.h"
c91e57e4 8#include "AliGenHepMCEventHeader.h"
b897d37f 9
71c3b2be 10#include "HepMC/IO_BaseClass.h"
11#include "HepMC/GenEvent.h"
12#include "HepMC/IO_GenEvent.h"
b897d37f 13
14ClassImp(AliGenReaderHepMC)
15
71c3b2be 16AliGenReaderHepMC::AliGenReaderHepMC():fEventsHandle(0), fGenEvent(0), fParticleArray(0), fParticleIterator(0), fGenEventHeader(0) {;}
17
18AliGenReaderHepMC::AliGenReaderHepMC(const AliGenReaderHepMC &reader)
19 :AliGenReader(reader), fEventsHandle(0), fGenEvent(0), fParticleArray(0), fParticleIterator(0), fGenEventHeader(0) {reader.Copy(*this);}
20
b897d37f 21
22AliGenReaderHepMC& AliGenReaderHepMC::operator=(const AliGenReaderHepMC& rhs)
23{
24 // Assignment operator
25 rhs.Copy(*this);
26 return *this;
27}
28
71c3b2be 29AliGenReaderHepMC::~AliGenReaderHepMC(){ delete fEventsHandle; delete fGenEvent; delete fParticleArray; delete fParticleIterator;} // not deleting fGenEventHeader as it is returned out
30
b897d37f 31void AliGenReaderHepMC::Copy(TObject&) const
32{
33 //
34 // Copy
35 //
36 Fatal("Copy","Not implemented!\n");
37}
38
39void AliGenReaderHepMC::Init()
40{
ec86c0b3 41 // check if file exists, using FILE to avoid (the otherwise faster) POSIX dependencies
42 if (FILE *file = fopen(fFileName,"r")) {
43 printf("File %s opened \n", fFileName);
44 fclose(file);
45 } else {
46 printf("Couldn't open input file: %s \n", fFileName);
47 }
b897d37f 48 // Initialisation
49 fEventsHandle = new HepMC::IO_GenEvent(fFileName, std::ios::in);
50 fParticleArray = new TClonesArray("TParticle");
51 fParticleIterator = new TIter(fParticleArray);
b897d37f 52}
53
54Int_t AliGenReaderHepMC::NextEvent()
55{
df67ce44 56 // Clean memory
57 if (fGenEvent) delete fGenEvent;
b897d37f 58 // Read the next event
59 if ((fGenEvent = fEventsHandle->read_next_event())) {
cedc6926 60 THepMCParser::ParseGenEvent2TCloneArray(fGenEvent,fParticleArray,"GEV","CM",false);
b897d37f 61 fParticleIterator->Reset();
c91e57e4 62 THepMCParser::HeavyIonHeader_t heavyIonHeader;
63 THepMCParser::PdfHeader_t pdfHeader;
64 THepMCParser::ParseGenEvent2HeaderStructs(fGenEvent,heavyIonHeader,pdfHeader,true,true);
65 fGenEventHeader = new AliGenHepMCEventHeader(
66 heavyIonHeader.Ncoll_hard,
67 heavyIonHeader.Npart_proj,
68 heavyIonHeader.Npart_targ,
69 heavyIonHeader.Ncoll,
70 heavyIonHeader.spectator_neutrons,
71 heavyIonHeader.spectator_protons,
72 heavyIonHeader.N_Nwounded_collisions,
73 heavyIonHeader.Nwounded_N_collisions,
74 heavyIonHeader.Nwounded_Nwounded_collisions,
75 heavyIonHeader.impact_parameter,
76 heavyIonHeader.event_plane_angle,
77 heavyIonHeader.eccentricity,
78 heavyIonHeader.sigma_inel_NN,
79 pdfHeader.id1,
80 pdfHeader.id2,
81 pdfHeader.pdf_id1,
82 pdfHeader.pdf_id2,
83 pdfHeader.x1,
84 pdfHeader.x2,
85 pdfHeader.scalePDF,
86 pdfHeader.pdf1,
87 pdfHeader.pdf2
88 );
eafbfaae 89 printf("Parsed event %d with %d particles.\n", fGenEvent->event_number(), fGenEvent->particles_size());
b897d37f 90 return fGenEvent->particles_size();
91 }
ec86c0b3 92 printf("No more events in the file.\n");
b897d37f 93 return 0;
94}
95
96TParticle* AliGenReaderHepMC::NextParticle()
97{
98 // Read next particle
99 TParticle * particle = (TParticle*)fParticleIterator->Next();
100 if (particle && particle->GetStatusCode()==1) {
101 particle->SetBit(kTransportBit);
102 }
103 return particle;
104}
105
106void AliGenReaderHepMC::RewindEvent()
107{
108 fParticleIterator->Reset();
109}