Dear all,
I am trying to save my some results of a Geant4 simulation in a ROOT ntuple, with data storage through a class inheriting from TObject. Methods of the class need Geant4 types as input. For example, I use my class to take a G4Track and store its associated momentum in the ntuple.
I create my own class: here’s the header file
[code]
#if !defined Targ01Storage_H
#define Targ01Storage_H
// Root components
#include <Rtypes.h>
#include <TString.h>
#include <TObject.h>
#include <TList.h>
// G4
#include “G4Track.hh”
#include “G4TrackStatus.hh”
#include “G4ParticleDefinition.hh”
#include “G4ParticleTypes.hh”
class Targ01Storage : public TObject
{
private:
public:
// Special member functions
Targ01Storage();
~Targ01Storage();
// Variables with stored information
Int_t partNo;
Int_t partId;
TString partName;
Double_t part4Momentum[4];
Double_t partKinEn;
//Double_t partMass;
//Targ01Storage specific methods
void PartNo(Int_t no);
void PartId(const G4Track* aTrack);
void Part4Momentum(const G4Track* aTrack);
// Cint preprocessor token
ClassDef(Targ01Storage, 1)
};
#endif[/code]
and the source is here:
[code]
#include “Targ01Storage.hh”
#include “G4Track.hh”
#include “TString.h”
// CINT Preprocessor class import definition
ClassImp(Targ01Storage)
//______________________________________________________________________________
Targ01Storage::Targ01Storage()
{
// Sets up the default event
partNo = -9999;
partId = -9999;
partName = “”;
for (Int_t jj = 0; jj<4; jj++) part4Momentum[jj] = -9999;
partKinEn = -9999;
}
//______________________________________________________________________________
Targ01Storage::~Targ01Storage()
{
// Default destructor.
std::cout<<“Targ01Storage::Targ01Storage: default destructor\n”;
// Deletes the root object
}
//______________________________________________________________________________
void Targ01Storage::PartNo(Int_t no)
{
// Sets the particle number through a counter
partNo = no;
}
//______________________________________________________________________________
void Targ01Storage::PartId(const G4Track* aTrack)
{
// Sets the particle PDG encoding
partId = aTrack->GetDefinition()->GetPDGEncoding();
partName = TString(aTrack->GetDefinition()->GetParticleName());
}
//______________________________________________________________________________
void Targ01Storage::Part4Momentum(const G4Track* aTrack)
{
// Sets the particle kinematics
partKinEn = aTrack->GetKineticEnergy();
part4Momentum[0] = aTrack->GetTotalEnergy();
part4Momentum[1] = (aTrack->GetMomentum()).x();
part4Momentum[1] = (aTrack->GetMomentum()).y();
part4Momentum[1] = (aTrack->GetMomentum()).z();
}[/code]
Then, I provide a linkdef file to link my own class
[code]
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class Targ01Storage+;
#endif[/code]
I use the Geant4 makefile (the one provided with G4 example/novice/N01) with recursive calls to other .gmk files. I put in it the dictionary generation instructions
[code]
name := targ01
G4TARGET := $(name)
G4EXLIB := true
ifndef G4INSTALL
G4INSTALL = /home/pozzobon/geant4/9.2
endif
.PHONY: all
all: custom lib bin
custom:
@echo “Generating dictionary …”
@rootcint -f Targ01Dictionary.cc -c -Iinclude Targ01Storage.hh Targ01LinkDef.hh
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS = -Iinclude $(shell root-config --cflags)
LDFLAGS = $(shell root-config --glibs --libs) -L$(G4INSTALL)/lib/Linux-g++ Targ01Dictionary.cc
include $(G4INSTALL)/config/binmake.gmk[/code]
but when I compile, I get
[quote]Generating dictionary …
Error: cannot open file “G4Track.hh” include/Targ01Storage.hh:13:
Error: cannot open file “G4TrackStatus.hh” include/Targ01Storage.hh:14:
Error: cannot open file “G4ParticleDefinition.hh” include/Targ01Storage.hh:15:
Error: cannot open file “G4ParticleTypes.hh” include/Targ01Storage.hh:16:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing Targ01Dictionary.cc Targ01Dictionary.h !!!
Error: rootcint: error loading headers…
make: *** [custom] Error 1[/quote]
so that I put all the G4 includes listed in the called binmake.gmk file
ifndef G4INSTALL
G4INSTALL = /home/pozzobon/geant4/9.2
endif
[code]
… (omissis)
DICTFLAGS :=
-I/home/pozzobon/geant4/9.2/source/global/management/include
… (omissis)
-I/home/pozzobon/geant4/9.2/source/intercoms/include
… (omissis)
custom:
@echo “Generating dictionary …”
@rootcint -f Targ01Dictionary.cc -c -Iinclude $(DICTFLAGS) Targ01Storage.hh Targ01LinkDef.hh[/code]
This way, my compilation still fails because of an error loading headers:
[quote]Error: Symbol ostreamG4cout is not defined in current scope /home/pozzobon/geant4/9.2/source/global/management/include/G4ios.hh:48:
Error: Symbol ostreamG4cerr is not defined in current scope /home/pozzobon/geant4/9.2/source/global/management/include/G4ios.hh:49:
Error: cannot open file “CLHEP/Units/PhysicalConstants.h” /home/pozzobon/geant4/9.2/source/global/management/include/G4PhysicalConstants.hh:28:
Error: cannot open file “CLHEP/Units/SystemOfUnits.h” /home/pozzobon/geant4/9.2/source/global/management/include/G4SystemOfUnits.hh:28:
Error: cannot open file “CLHEP/Vector/ThreeVector.h” /home/pozzobon/geant4/9.2/source/global/management/include/G4ThreeVector.hh:42:
Error: class,struct,union or type CLHEP not defined /home/pozzobon/geant4/9.2/source/global/management/include/G4ThreeVector.hh:43:
Error: class,struct,union or type CLHEP not defined /home/pozzobon/geant4/9.2/source/global/management/include/G4ThreeVector.hh:43:
Error: cannot open file “CLHEP/Vector/Rotation.h” /home/pozzobon/geant4/9.2/source/global/management/include/G4RotationMatrix.hh:43:
Error: class,struct,union or type CLHEP not defined /home/pozzobon/geant4/9.2/source/global/management/include/G4RotationMatrix.hh:44:
Error: class,struct,union or type CLHEP not defined /home/pozzobon/geant4/9.2/source/global/management/include/G4RotationMatrix.hh:44:
Error: cannot open file “CLHEP/Vector/LorentzVector.h” /home/pozzobon/geant4/9.2/source/global/HEPGeometry/include/G4LorentzVector.hh:35:
Error: class,struct,union or type CLHEP not defined /home/pozzobon/geant4/9.2/source/global/HEPGeometry/include/G4LorentzVector.hh:36:
Error: class,struct,union or type CLHEP not defined /home/pozzobon/geant4/9.2/source/global/HEPGeometry/include/G4LorentzVector.hh:36:
Error: Symbol G4DLLIMPORTG4Allocator is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4ElectronOccupancy.hh:107:
Error: Symbol G4ElectronOccupancy is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4ElectronOccupancy.hh:107:
Error: Symbol aElectronOccupancyAllocator is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4ElectronOccupancy.hh:107:
Error: Symbol G4DLLIMPORTG4Allocator is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4PrimaryParticle.hh:213:
Error: Symbol G4PrimaryParticle is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4PrimaryParticle.hh:213:
Error: Symbol aPrimaryParticleAllocator is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4PrimaryParticle.hh:213:
Error: Symbol G4DLLIMPORTG4Allocator is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4DynamicParticle.icc:41:
Error: Symbol G4DynamicParticle is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4DynamicParticle.icc:41:
Error: Symbol aDynamicParticleAllocator is not defined in current scope /home/pozzobon/geant4/9.2/source/particles/management/include/G4DynamicParticle.icc:41:
Error: G4CountedObject::aCountedObjectAllocator already declared as different type /home/pozzobon/geant4/9.2/source/global/management/include/G4ReferenceCountedHandle.hh:316:
Error: G4CountedObject::aCountedObjectAllocator not allocated(2), maybe duplicate declaration /home/pozzobon/geant4/9.2/source/global/management/include/G4ReferenceCountedHandle.hh:316:
Error: G4ReferenceCountedHandle::aRCHAllocator already declared as different type /home/pozzobon/geant4/9.2/source/global/management/include/G4ReferenceCountedHandle.hh:320:
Error: G4ReferenceCountedHandle::aRCHAllocator not allocated(2), maybe duplicate declaration /home/pozzobon/geant4/9.2/source/global/management/include/G4ReferenceCountedHandle.hh:320:
Error: Symbol STP_Temperature is not defined in current scope /home/pozzobon/geant4/9.2/source/materials/include/G4Material.hh:115:
Error: Symbol STP_Pressure is not defined in current scope /home/pozzobon/geant4/9.2/source/materials/include/G4Material.hh:116:
Error: Symbol STP_Temperature is not defined in current scope /home/pozzobon/geant4/9.2/source/materials/include/G4Material.hh:126:
Error: Symbol STP_Pressure is not defined in current scope /home/pozzobon/geant4/9.2/source/materials/include/G4Material.hh:127:
Error: Symbol G4DLLIMPORTG4Allocator is not defined in current scope /home/pozzobon/geant4/9.2/source/track/include/G4Track.icc:38:
Error: Symbol G4Track is not defined in current scope /home/pozzobon/geant4/9.2/source/track/include/G4Track.icc:38:
Error: Symbol aTrackAllocator is not defined in current scope /home/pozzobon/geant4/9.2/source/track/include/G4Track.icc:38:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing Targ01Dictionary.cc Targ01Dictionary.h !!!
Error: rootcint: error loading headers…
make: *** [custom] Error 1[/quote]
I found other people had similar problems http://root.cern.ch/phpBB2/viewtopic.php?t=3493 but I couldn’t find any solution in this topic (and in many other topics in this RootTalk)
I already spent all my ideas about how to fix this, without any success… Did anyone ever manage to make ROOT and Geant4 talk to each other? Does anyone know the solution?
Thank you very much!
Nicola