//
// ********************************************************************
// * DISCLAIMER                                                       *
// *                                                                  *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in:                      *
// *   http://cern.ch/geant4/license                                  *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.                                                             *
// *                                                                  *
// * This  code  implementation is the  intellectual property  of the *
// * GEANT4 collaboration.                                            *
// * By copying,  distributing  or modifying the Program (or any work *
// * based  on  the Program)  you indicate  your  acceptance of  this *
// * statement, and all its terms.                                    *
// ********************************************************************
//
//
// $Id: SteppingAction.cc,v 1.1 2003/06/23 16:16:34 maire Exp $
// GEANT4 tag $Name: geant4-08-00-patch-01 $
//
// 

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

#include "SteppingAction.hh"
#include "EventAction.hh"
#include "G4SteppingManager.hh"
#include <stdio.h>
//#include "iostream.h"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//FILE *output;

	SteppingAction::SteppingAction(EventAction* EvAct)
:eventAction(EvAct),myVerbose(NULL)
{
//	output = fopen("out.dat", "w");
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

SteppingAction::~SteppingAction()
{ }

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

#include "G4PionZero.hh"
void SteppingAction::UserSteppingAction(const G4Step* aStep)
{
	if(aStep->GetTrack()->GetDefinition() == G4PionZero::PionZero() ) {
		G4double e = aStep->GetTrack()->GetTotalEnergy();
		G4ThreeVector p = aStep->GetPreStepPoint()->GetMomentum();
		G4ThreeVector x = aStep->GetPreStepPoint()->GetPosition();
		G4int pdgID = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
		G4double m = aStep->GetTrack()->GetDefinition()->GetPDGMass();
		//    fprintf(output,"%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",eventAction->GetEvtNb(),111,p.x()/GeV,p.y()/GeV,p.z()/GeV,e/GeV,x.getX()/cm,x.getY()/cm,x.getZ()/cm);
		eventAction->WriteParticle(pdgID,p.x()/GeV,p.y()/GeV,p.z()/GeV,e/GeV,m/GeV,x.getX()/mm,x.getY()/mm,x.getZ()/mm);

	}
	if( aStep->GetTrack()->GetNextVolume() != 0 ) {
		G4String PosVol = aStep->GetTrack()->GetNextVolume()->GetName();
		G4String PreVol = aStep->GetTrack()->GetVolume()->GetName();
		G4String pName = aStep->GetTrack()->GetDefinition()->GetParticleName();
		G4ThreeVector x = aStep->GetPostStepPoint()->GetPosition();
		G4double e = aStep->GetTrack()->GetTotalEnergy();
		G4double m = aStep->GetTrack()->GetDefinition()->GetPDGMass();
		G4ThreeVector p = aStep->GetTrack()->GetMomentum();

		G4int pdgID = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
		//int geantID = 0;

		if( PreVol == "TargetPhysical" && PosVol == "WorldPhysical" && e > 10.0 ) {
			if (pdgID < -100 || pdgID > 100) {
				//			  fprintf(output,"%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",eventAction->GetEvtNb(),pdgID,p.x()/GeV,p.y()/GeV,p.z()/GeV,e/GeV,x.getX()/cm,x.getY()/cm,x.getZ()/cm);
				eventAction->WriteParticle(pdgID,p.x()/GeV,p.y()/GeV,p.z()/GeV,e/GeV,m/GeV,x.getX()/mm,x.getY()/mm,x.getZ()/mm);
				//	fprintf(output,"%d %E %E %E\n",geantID,p.mag()/MeV,p.theta(),p.x()/e);
			}
			//G4cout << " " << p.x()/e << " " << p.y()/e << " " << p.z()/e << " " << e << " " << G4endl;
		} 
	}
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......


