#ifndef __PHUrParticle_h__
#define __PHUrParticle_h__


#include "TObject.h"
#include "TVector3.h"
#include "TLorentzVector.h"


#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;


class PHUrParticle : public TLorentzVector {

public:
    Int_t ind;                //   1      ind : index of particle
    Double_t t;               //   2      t   : computational frame time of particle in fm/c
    TVector3 fr;              //          x,y,z coordinate in fm
    Double_t mass;            //   10     m   : mass of particle in GeV
    Int_t id;                 //   11     ityp: particle-ID
    Int_t I3;                 //   12   2*I3  : isospin z-projection (doubled)
    Int_t chrg;               //   13     ch  : charge of particle
    Int_t ind_part;           //   14         : index of last collision partner
    Int_t ncoll;              //   15    Ncoll: number of collisions
    Int_t s;                  //   16     S   : strangeness
    Int_t parent_process;     //   17         : history information (parent process)
    Int_t pdg;                //   ==> compact id for pdg conversion

    Int_t instance;           // default -1 , 0 first n last appearance of the particle
    Int_t first;              // first apperance ==1
    Int_t last;               // last apearance

    vector<Int_t> listInCollIndex;     // list of collisions involing this particle
    vector<Int_t> listOutCollIndex;

    using TObject::Read;
    Bool_t Read(ifstream& in) {
	if(in.eof())   return kFALSE;
	if(!in.good()) return kFALSE;
        Double_t px, py, pz, E;
	Double_t rx, ry, rz;
	in >> ind >> t >> rx >> ry >> rz >> E >> px >> py >> pz >> mass >> id >> I3 >> 
	    chrg >> ind_part >> ncoll >> s >> parent_process;
	ind      -= 1;  // fortran ->C++
	ind_part -= 1;  // fortran ->C++

	if (id >= 0)
	    pdg =  1000 * (chrg + 2) + id;
	else
            pdg = -1000 * (chrg + 2) + id;

	SetPxPyPzE(px, py, pz, E);
	fr.SetXYZ(rx, ry, rz);

	if(!in.eof() && !in.good()) return kFALSE;
        return kTRUE;
    }

    Int_t GetFirstCollision() {
        Int_t ind = -1;
	if(listInCollIndex.size()  > 0) ind = listInCollIndex[0];
        if(listOutCollIndex.size() > 0 && (listOutCollIndex[0] < ind || ind < 0)) ind = listOutCollIndex[0];
	return ind;
    }

    Int_t GetFirstCollisionInput() {
        Int_t ind = -1;
	if(listInCollIndex.size() > 0) ind = listInCollIndex[0];
	return ind;
    }

    Int_t GetFirstCollisionOutput() {
        Int_t ind = -1;
        if(listOutCollIndex.size() > 0 ) ind = listOutCollIndex[0];
	return ind;
    }

    Int_t GetLastCollision() {
        Int_t ind = -1;
	if(listInCollIndex.size()  > 0) { ind = listInCollIndex[listInCollIndex.size()-1]; }
        if(listOutCollIndex.size() > 0 && listOutCollIndex[listOutCollIndex.size()-1] > ind) ind = listOutCollIndex[listOutCollIndex.size()-1];
	return ind;
    }

    Int_t GetLastCollisionInput() {
        Int_t ind = -1;
	if(listInCollIndex.size()  > 0) { ind = listInCollIndex[listInCollIndex.size()-1]; }
	return ind;
    }

    Int_t GetLastCollisionOutput() {
        Int_t ind = -1;
        if(listOutCollIndex.size() > 0 ) ind = listOutCollIndex[listOutCollIndex.size()-1];
	return ind;
    }

    Bool_t IsPrimary() {
        Int_t ind1 = -1;
        Int_t ind2 = -1;
	if(listInCollIndex.size()  > 0 ) ind1 = listInCollIndex [0];
        if(listOutCollIndex.size() > 0 ) ind2 = listOutCollIndex[0];

        if(ind1 ==-1 && ind2 ==-1)               return kTRUE;  // no collision
        if(ind1 !=-1 && ind2 !=-1 && ind1<=ind2) return kTRUE;  // first appearance in input
        if(ind1 !=-1 && ind2 ==-1 )              return kTRUE;  // only in input

        return kFALSE;
    }

    using TObject::Print;
    void Print(Option_t *) {
	cout << setw(5)  << dec << ind << " "
	     << setw(15) << scientific
	     << setw(15) << fr.X() << " "
	     << setw(15) << fr.Y() << " "
	     << setw(15) << fr.Z() << " "
	     << setw(15) << E()    << " "
	     << setw(15) << Px()   << " "
	     << setw(15) << Py()   << " "
	     << setw(15) << Pz()   << " "
	     << setw(15) << mass   << " "
	     << setw(5)  << dec << id << " "
	     << setw(5)  << I3   << " "
	     << setw(5)  << chrg << " "
	     << setw(5)  << ind_part << " "
	     << setw(5)  << ncoll << " "
	     << setw(5)  << s << " "
	     << setw(5)  << parent_process
	     << dec << endl;
    }

    using TObject::Clear;
    void  Clear(Option_t *) {
	ind            = -1;
	t              = -1;
	SetPxPyPzE(-1.,-1.,-1.,-1.);
        fr.SetXYZ(-1.,-1.,-1.);
	mass           = -1;
	id             = -1;
	I3             = -1;
	chrg           = -1;
	ind_part       = -1;
	ncoll          = -1;
	s              = -1;
	parent_process = -1;
	pdg            = -1;
	instance       = -1;
	first          = -1;
	last           = -1;

	listInCollIndex .clear();
        listOutCollIndex.clear();
    }

    PHUrParticle(){ Clear(NULL); }
    ~PHUrParticle(){}

    ClassDef(PHUrParticle, 0)
};


#endif
 PHUrParticle.h:1
 PHUrParticle.h:2
 PHUrParticle.h:3
 PHUrParticle.h:4
 PHUrParticle.h:5
 PHUrParticle.h:6
 PHUrParticle.h:7
 PHUrParticle.h:8
 PHUrParticle.h:9
 PHUrParticle.h:10
 PHUrParticle.h:11
 PHUrParticle.h:12
 PHUrParticle.h:13
 PHUrParticle.h:14
 PHUrParticle.h:15
 PHUrParticle.h:16
 PHUrParticle.h:17
 PHUrParticle.h:18
 PHUrParticle.h:19
 PHUrParticle.h:20
 PHUrParticle.h:21
 PHUrParticle.h:22
 PHUrParticle.h:23
 PHUrParticle.h:24
 PHUrParticle.h:25
 PHUrParticle.h:26
 PHUrParticle.h:27
 PHUrParticle.h:28
 PHUrParticle.h:29
 PHUrParticle.h:30
 PHUrParticle.h:31
 PHUrParticle.h:32
 PHUrParticle.h:33
 PHUrParticle.h:34
 PHUrParticle.h:35
 PHUrParticle.h:36
 PHUrParticle.h:37
 PHUrParticle.h:38
 PHUrParticle.h:39
 PHUrParticle.h:40
 PHUrParticle.h:41
 PHUrParticle.h:42
 PHUrParticle.h:43
 PHUrParticle.h:44
 PHUrParticle.h:45
 PHUrParticle.h:46
 PHUrParticle.h:47
 PHUrParticle.h:48
 PHUrParticle.h:49
 PHUrParticle.h:50
 PHUrParticle.h:51
 PHUrParticle.h:52
 PHUrParticle.h:53
 PHUrParticle.h:54
 PHUrParticle.h:55
 PHUrParticle.h:56
 PHUrParticle.h:57
 PHUrParticle.h:58
 PHUrParticle.h:59
 PHUrParticle.h:60
 PHUrParticle.h:61
 PHUrParticle.h:62
 PHUrParticle.h:63
 PHUrParticle.h:64
 PHUrParticle.h:65
 PHUrParticle.h:66
 PHUrParticle.h:67
 PHUrParticle.h:68
 PHUrParticle.h:69
 PHUrParticle.h:70
 PHUrParticle.h:71
 PHUrParticle.h:72
 PHUrParticle.h:73
 PHUrParticle.h:74
 PHUrParticle.h:75
 PHUrParticle.h:76
 PHUrParticle.h:77
 PHUrParticle.h:78
 PHUrParticle.h:79
 PHUrParticle.h:80
 PHUrParticle.h:81
 PHUrParticle.h:82
 PHUrParticle.h:83
 PHUrParticle.h:84
 PHUrParticle.h:85
 PHUrParticle.h:86
 PHUrParticle.h:87
 PHUrParticle.h:88
 PHUrParticle.h:89
 PHUrParticle.h:90
 PHUrParticle.h:91
 PHUrParticle.h:92
 PHUrParticle.h:93
 PHUrParticle.h:94
 PHUrParticle.h:95
 PHUrParticle.h:96
 PHUrParticle.h:97
 PHUrParticle.h:98
 PHUrParticle.h:99
 PHUrParticle.h:100
 PHUrParticle.h:101
 PHUrParticle.h:102
 PHUrParticle.h:103
 PHUrParticle.h:104
 PHUrParticle.h:105
 PHUrParticle.h:106
 PHUrParticle.h:107
 PHUrParticle.h:108
 PHUrParticle.h:109
 PHUrParticle.h:110
 PHUrParticle.h:111
 PHUrParticle.h:112
 PHUrParticle.h:113
 PHUrParticle.h:114
 PHUrParticle.h:115
 PHUrParticle.h:116
 PHUrParticle.h:117
 PHUrParticle.h:118
 PHUrParticle.h:119
 PHUrParticle.h:120
 PHUrParticle.h:121
 PHUrParticle.h:122
 PHUrParticle.h:123
 PHUrParticle.h:124
 PHUrParticle.h:125
 PHUrParticle.h:126
 PHUrParticle.h:127
 PHUrParticle.h:128
 PHUrParticle.h:129
 PHUrParticle.h:130
 PHUrParticle.h:131
 PHUrParticle.h:132
 PHUrParticle.h:133
 PHUrParticle.h:134
 PHUrParticle.h:135
 PHUrParticle.h:136
 PHUrParticle.h:137
 PHUrParticle.h:138
 PHUrParticle.h:139
 PHUrParticle.h:140
 PHUrParticle.h:141
 PHUrParticle.h:142
 PHUrParticle.h:143
 PHUrParticle.h:144
 PHUrParticle.h:145
 PHUrParticle.h:146
 PHUrParticle.h:147
 PHUrParticle.h:148
 PHUrParticle.h:149
 PHUrParticle.h:150
 PHUrParticle.h:151
 PHUrParticle.h:152
 PHUrParticle.h:153
 PHUrParticle.h:154
 PHUrParticle.h:155
 PHUrParticle.h:156
 PHUrParticle.h:157
 PHUrParticle.h:158
 PHUrParticle.h:159
 PHUrParticle.h:160
 PHUrParticle.h:161
 PHUrParticle.h:162
 PHUrParticle.h:163
 PHUrParticle.h:164
 PHUrParticle.h:165
 PHUrParticle.h:166
 PHUrParticle.h:167