//
// D.Cussol 
//
// 21/10/2002:
// Implementation of an Event class relative to the INDRA experiments
// ROOT beginners course
//

#include <math.h>
#include <stdio.h>
#include "Event.h"
#include "TMath.h"

ClassImp(Event)

int	Event::nb=0;
int	Event::nb_crea=0;
int	Event::nb_dest=0;
TClonesArray *Event::sfrags=0;

//============================================================================
// Basic methods
//============================================================================
 void Event::initEvent(void)
	{
//
// Initialisation of the Event fields
// This private method is called by the constructors
//
        nb++;
	mult=0;
	if(!sfrags) 
	 {
	 sfrags=new TClonesArray("Fragment",100);
	 for(int i=0;i<100;i++)
	 	Fragment *tmp = new((*sfrags)[i]) Fragment();

	 }
	frags=sfrags;
	nb_crea++;
	}

 Event::Event(void):TNamed()
	{
//
// Default constructeur
//
	char	*nom=new char[80];

	initEvent();
	sprintf(nom,"Event_%d",nb);
	SetName(nom);
	SetTitle(nom);

	delete [] nom;
	}
	
 Event::Event(char *nom)
	{
//
// Constructor with a name
//
	initEvent();
	SetName(nom);
	SetTitle(nom);
	}

 Event::~Event(void)
       {
// 
// Destructor
//
        nb--;
	if(nb==0) 
	 {
	 delete sfrags;
	 }
	nb_dest++;
       }

//============================================================================
// Event management
//============================================================================
 void Event::AddFragment(Fragment *f)
	{
//
// Add a fragment to the event
//
	TClonesArray &ltca=*frags;
	Fragment *tmp=(Fragment *)ltca[mult];
	if(tmp)
	 {
	 tmp->Set(f->GetA(),f->GetZ(),f->GetVit());
	 mult++;
	 }
	}

 void Event::Reset(void)
	{
//
// Clear the event and the fragments in it
//
	if(frags) frags->Clear();
	mult=0;
	}

 int Event::GetMult(void)
	{
//
// Number of fragments in the event (multiplicity)
//
	return mult;
	}

 Fragment *Event::GetFragment(int i)
	{
//
// Gets the pointer of the ith fragment in the event
//
	Fragment *f=0;
	if(frags)
	 if(i > 0 && i <= mult) 
	  {
	  f=(Fragment *)frags->At(i-1);
	  }
	 else
	  {
	  cerr << "The i index has to be in between 1 and " << mult << "." <<
	  endl;
	  }
	else
	 {
	 cerr << "Le TClonesArray est null..." << endl;
	 }
	return f;
	}
	
//============================================================================
// Computed quantities
//============================================================================
 int Event::GetZtot(void)
	{
//
// Sum of fragments charges
//
	Fragment *f;
	int Z=0;
	if(frags)
	 for(int i=0;i<mult;i++)
	  {
	  f=(Fragment *)frags->At(i);
	  Z+=f->GetZ();
	  }
	return Z;
	}

 TVector3 Event::GetPtot(void)
	{
//
// Sum of fragments momenta
//	
	Fragment *f;
	TVector3 pt(0.,0.,0.);
	for(int i=0;i<mult;i++)
	 {
	 f=(Fragment *)frags->At(i);
	 pt+=(f->GetZ())*(f->GetVit());
	 }
	return pt;
	}

 double Event::GetEcin(void)
	{
// 
// Kinetic energy
//
	Fragment *f;
	double ect=0;
	if(frags)
	 for(int i=0;i<mult;i++)
	  {
	  f=(Fragment *)frags->At(i);
	  ect+=f->GetEcin();
	  }
	return ect;
	}

 double Event::GetEperp(void)
	{
//
// Tranverse kinetic energy
//
	Fragment *f;
	double ept=0;
	if(frags)
	 for(int i=0;i<mult;i++)
	  {
	  f=(Fragment *)frags->At(i);
	  ept+=f->GetEperp();
	  }
	return ept;
	}

 void Event::Print(Option_t* option) const
	{
//
// Printout
//
	cout << "=====================================================" << endl;
	cout << "Mult : " << mult << endl;
	if(frags)
	 for(int i=0;i<mult;i++)
	  {
	  cout << i+1 << " -> ";
	  ((Fragment *)frags->At(i))->Print();
	  }
	cout << endl;
	}



ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.