Added AliGenHepMCEventHeader class and put it in STEERBase library. Updated AliGenRea...
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderHepMC.cxx
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"
8 #include "AliGenHepMCEventHeader.h"
9
10
11 ClassImp(AliGenReaderHepMC)
12
13
14 AliGenReaderHepMC& AliGenReaderHepMC::operator=(const  AliGenReaderHepMC& rhs)
15 {
16    // Assignment operator
17    rhs.Copy(*this);
18    return *this;
19 }
20
21 void AliGenReaderHepMC::Copy(TObject&) const
22 {
23    //
24    // Copy
25    //
26    Fatal("Copy","Not implemented!\n");
27 }
28
29 void AliGenReaderHepMC::Init()
30 {
31    // Initialisation
32    fEventsHandle = new HepMC::IO_GenEvent(fFileName, std::ios::in);
33    fParticleArray = new TClonesArray("TParticle");
34    fParticleIterator = new TIter(fParticleArray);
35 }
36
37 Int_t AliGenReaderHepMC::NextEvent()
38 {
39    // Read the next event
40    if ((fGenEvent = fEventsHandle->read_next_event())) {
41       THepMCParser::ParseGenEvent2TCloneArray(fGenEvent,fParticleArray,false);
42       fParticleIterator->Reset();
43       THepMCParser::HeavyIonHeader_t heavyIonHeader;
44       THepMCParser::PdfHeader_t pdfHeader;
45       THepMCParser::ParseGenEvent2HeaderStructs(fGenEvent,heavyIonHeader,pdfHeader,true,true);
46       fGenEventHeader = new AliGenHepMCEventHeader(
47             heavyIonHeader.Ncoll_hard,
48             heavyIonHeader.Npart_proj,
49             heavyIonHeader.Npart_targ,
50             heavyIonHeader.Ncoll,
51             heavyIonHeader.spectator_neutrons,
52             heavyIonHeader.spectator_protons,
53             heavyIonHeader.N_Nwounded_collisions,
54             heavyIonHeader.Nwounded_N_collisions,
55             heavyIonHeader.Nwounded_Nwounded_collisions,
56             heavyIonHeader.impact_parameter,
57             heavyIonHeader.event_plane_angle,
58             heavyIonHeader.eccentricity,
59             heavyIonHeader.sigma_inel_NN,
60             pdfHeader.id1,
61             pdfHeader.id2,
62             pdfHeader.pdf_id1,
63             pdfHeader.pdf_id2,
64             pdfHeader.x1,
65             pdfHeader.x2,
66             pdfHeader.scalePDF,
67             pdfHeader.pdf1,
68             pdfHeader.pdf2
69       );
70       return fGenEvent->particles_size();
71    }
72    return 0;
73 }
74
75 TParticle* AliGenReaderHepMC::NextParticle()
76 {
77    // Read next particle
78    TParticle * particle = (TParticle*)fParticleIterator->Next();
79    if (particle && particle->GetStatusCode()==1) {
80       particle->SetBit(kTransportBit);
81    }
82    return particle;
83 }
84
85 void AliGenReaderHepMC::RewindEvent()
86 {
87    fParticleIterator->Reset();
88 }