57 XrayFluoAnalysisManager::XrayFluoAnalysisManager()
58 :outputFileName(
"xrayfluo"), visPlotter(false), phaseSpaceFlag(false), physicFlag (false), persistencyType(
"root"),
59 deletePersistencyFile(true), gunParticleEnergies(0), gunParticleTypes(0), analysisFactory(0), tree(0), treeDet(0), histogramFactory(0), plotter(0)
62 analisysMessenger =
new XrayFluoAnalysisMessenger(
this);
66 analysisFactory = AIDA_createAnalysisFactory();
68 CreatePersistency(outputFileName,persistencyType);
76 plotterFactory = analysisFactory->createPlotterFactory();
85 XrayFluoAnalysisManager::~XrayFluoAnalysisManager()
87 delete histogramFactory;
90 delete analysisFactory;
93 delete plotterFactory;
98 if ( gunParticleEnergies )
delete gunParticleEnergies;
99 gunParticleEnergies = 0;
100 if ( gunParticleTypes )
delete gunParticleTypes;
101 gunParticleTypes = 0;
111 XrayFluoAnalysisManager* XrayFluoAnalysisManager::getInstance()
120 void XrayFluoAnalysisManager::CreatePersistency(
G4String fileName,
G4String thePersistencyType,
132 if (histogramFactory) {
133 delete histogramFactory;
134 histogramFactory = 0;
141 if (tupleDetFactory) {
142 delete tupleDetFactory;
145 G4String fileNameDet = fileName+
"Detector";
147 AIDA::ITreeFactory* treeFactory = analysisFactory->createTreeFactory();
149 if (thePersistencyType ==
"hbook") {
150 fileName = fileName +
".hbk";
151 fileNameDet = fileNameDet +
".hbk";
153 else if (thePersistencyType ==
"xml"){
154 fileName = fileName +
".xml";
155 fileNameDet = fileNameDet +
".xml";
158 if (phaseSpaceFlag) {
160 tree = treeFactory->create(fileName,thePersistencyType,readOnly,createNew);
161 treeDet = treeFactory->create(fileNameDet,thePersistencyType,readOnly,createNew);
162 if(analysisFactory) {
164 tupleDetFactory = analysisFactory->createTupleFactory(*treeDet);
165 tupleFactory = analysisFactory->createTupleFactory(*tree);
173 tree = treeFactory->create(fileName,thePersistencyType,readOnly,createNew);
175 if(analysisFactory) {
177 histogramFactory = analysisFactory->createHistogramFactory(*tree);
187 void XrayFluoAnalysisManager::book()
190 if (phaseSpaceFlag) {
202 std::vector<std::string> columnNames;
203 columnNames.push_back(
"particle");
204 columnNames.push_back(
"energies");
205 columnNames.push_back(
"momentumTheta");
206 columnNames.push_back(
"momentumPhi");
207 columnNames.push_back(
"processes");
208 columnNames.push_back(
"material");
209 columnNames.push_back(
"origin");
210 columnNames.push_back(
"depth");
212 std::vector<std::string> columnTypes;
213 columnTypes.push_back(
"int");
214 columnTypes.push_back(
"double");
215 columnTypes.push_back(
"double");
216 columnTypes.push_back(
"double");
217 columnTypes.push_back(
"int");
218 columnTypes.push_back(
"int");
219 columnTypes.push_back(
"int");
220 columnTypes.push_back(
"double");
222 tupleFluo = tupleFactory->create(
"10",
"Total Tuple", columnNames, columnTypes,
"");
230 histo_1 = histogramFactory->createHistogram1D(
"1",
"Energy Deposit", 500,0.,10.);
231 histo_2 = histogramFactory->createHistogram1D(
"2",
"Gamma born in the sample", 100,0.,10.);
232 histo_3 = histogramFactory->createHistogram1D(
"3",
"Electrons born in the sample", 100,0.,10.);
233 histo_4 = histogramFactory->createHistogram1D(
"4",
"Gammas leaving the sample", 300,0.,10.);
234 histo_5 = histogramFactory->createHistogram1D(
"5",
"Electrons leaving the sample ",200000 ,0.,10.0);
235 histo_6 = histogramFactory->createHistogram1D(
"6",
"Gammas reaching the detector", 100,0.,10.);
236 histo_7 = histogramFactory->createHistogram1D(
"7",
"Spectrum of the incident particles", 100,0.,10.);
237 histo_8 = histogramFactory->createHistogram1D(
"8",
"Protons reaching the detector", 100,0.,10.);
238 histo_9 = histogramFactory->createHistogram1D(
"9",
"Protons leaving the sample", 100,0.,10.);
253 void XrayFluoAnalysisManager::LoadGunData(
G4String fileName,
G4bool raileighFlag) {
258 G4String ext = fileName.substr(fileName.size()-3,fileName.size()-1);
263 thePersistencyType =
"xml";
265 else if (ext ==
"hbk") {
267 thePersistencyType =
"hbook";
270 gunParticleEnergies =
new std::vector<G4double>;
271 gunParticleTypes =
new std::vector<G4String>;
275 AIDA::ITreeFactory* treeDataFactory = analysisFactory->createTreeFactory();
276 AIDA::ITree* treeData = treeDataFactory->create(fileName,thePersistencyType,
false,
false);
277 AIDA::IManagedObject* mo = treeData->find(
"10");
280 AIDA::ITuple* tupleData =
dynamic_cast<AIDA::ITuple*
>(mo);
289 G4int processesIndex = tupleData->findColumn(
"processes");
290 G4int energyIndex = tupleData->findColumn(
"energies");
291 G4int particleIndex = tupleData->findColumn(
"particle");
293 while (tupleData->next()) {
294 if (raileighFlag ^ (!raileighFlag && (tupleData->getInt(processesIndex) == 1 ||
295 tupleData->getInt(processesIndex) == 2)) ) {
296 gunParticleEnergies->push_back(tupleData->getDouble(energyIndex)*
MeV);
297 if (tupleData->getInt(particleIndex) == 1 ) gunParticleTypes->push_back(
"gamma");
298 if (tupleData->getInt(particleIndex) == 0 ) gunParticleTypes->push_back(
"e-");
302 G4cout <<
"Maximum mumber of events: "<< gunParticleEnergies->size() <<
G4endl;
307 std::vector<G4double>* XrayFluoAnalysisManager::GetEmittedParticleEnergies() {
309 return gunParticleEnergies;
313 std::vector<G4String>* XrayFluoAnalysisManager::GetEmittedParticleTypes() {
315 return gunParticleTypes;
320 void XrayFluoAnalysisManager::finish()
323 if (tupleFluo) {ExtractData();};
341 deletePersistencyFile =
false;
347 void XrayFluoAnalysisManager::InitializePlotter()
352 if(plotterFactory && visPlotter && deletePersistencyFile)
354 plotter = plotterFactory->create();
356 plotter->setParameter(
"pageTitle",
"XrayFluo");
359 if(plotter && visPlotter) {
366 void XrayFluoAnalysisManager::PlotCurrentResults()
374 AIDA::ICloud1D& cloud = *cloud_1;
375 AIDA::IFilter* filterGamma = tupleFactory->createFilter(
376 " Particle == std::string(\"gamma\") ");
377 AIDA::IEvaluator* evaluatorEnergy = tupleFactory->createEvaluator(
"Energies");
381 filterGamma->initialize(*tupleFluo);
382 evaluatorEnergy->initialize(*tupleFluo);
383 tupleFluo->project(cloud,*evaluatorEnergy,*filterGamma);
385 plotter->currentRegion().plot( cloud,
"Exiting Gammas " );
391 AIDA::IHistogram1D& histo1p = *histo_1;
392 plotter->currentRegion().plot( histo1p,
"Detector Energy Deposition" );
400 G4bool XrayFluoAnalysisManager::GetDeletePersistencyFileFlag()
402 return deletePersistencyFile;
407 void XrayFluoAnalysisManager::SetPhysicFlag(
G4bool val)
418 void XrayFluoAnalysisManager::analyseStepping(
const G4Step* aStep)
430 G4int isBornInTheSample=0;
455 if (physicFlag ^ (!physicFlag &&
468 if (creationPosVolume->
GetName() ==
"Sample" ) {
469 isBornInTheSample = 1;
483 if (parentProcess ==
"") parent = 0;
484 if (parentProcess ==
"IONI") parent = 1;
485 if (parentProcess ==
"LowEnPhotoElec") parent = 2;
486 if (parentProcess ==
"Transportation") parent = 3;
487 if (parentProcess ==
"initStep") parent = 4;
490 parentProcess =
"Not Known -- (primary generator + Rayleigh)";
496 if (sampleMaterial == (
"Dolorite" ||
"Anorthosite" ||
"Mars1" ||
"IceBasalt" ||
"HPGe")) sampleMat=1;
502 if (particleType ==
"gamma") part =1;
503 if (particleType ==
"e-") part = 0;
504 if (particleType ==
"proton") part = 2;
507 tupleFluo->fill(0,part);
508 tupleFluo->fill(1,particleEnergy);
509 tupleFluo->fill(2,momentum.theta());
510 tupleFluo->fill(3,momentum.phi());
511 tupleFluo->fill(4,parent);
512 tupleFluo->fill(5,sampleMat);
513 tupleFluo->fill(6,isBornInTheSample);
514 tupleFluo->fill(7,particleDepth);
589 histo_4->fill(gammaLeavingSample/
keV);
621 histo_5->fill(eleLeavingSample/
keV);
629 histo_9->fill(protonsLeavSam/
keV);
695 histo_2->fill(gammaBornInSample/
keV);
712 histo_3->fill(eleBornInSample/
keV);
733 histo_6->fill( gammaAtTheDetPre/
keV);
742 histo_8->fill( protonsAtTheDetPre/
keV);
753 void XrayFluoAnalysisManager::ExtractData(){
755 if (tupleFluo->rows()) {
762 AIDA::IFilter* filterAngle = tupleFactory->createFilter(
764 "(momentumPhi >= (220. * (3.1415926/180.) )) && (momentumPhi <= (230. * (3.1415926/180.) )) && (momentumTheta >= (130. * (3.1415926/180.) )) && (momentumTheta <= (140. * (3.1415926/180.) ))" );
769 filterAngle->initialize(*tupleFluo);
779 tupleDetFluo = tupleDetFactory->createFiltered(
"1", *tupleFluo, *filterAngle);
786 void XrayFluoAnalysisManager::analyseEnergyDep(
G4double energyDep)
791 histo_1->fill(energyDep/
keV);
797 void XrayFluoAnalysisManager::analysePrimaryGenerator(
G4double energy)
806 histo_7->fill(energy/
keV);
813 void XrayFluoAnalysisManager::SetOutputFileName(
G4String newName)
816 outputFileName = newName;
819 void XrayFluoAnalysisManager::SetOutputFileType(
G4String newType)
822 persistencyType = newType;
G4int GetParentID() const
CLHEP::Hep3Vector G4ThreeVector
const G4DynamicParticle * GetDynamicParticle() const
G4StepStatus GetStepStatus() const
const G4String & GetName() const
G4ParticleDefinition * GetDefinition() const
static XrayFluoDetectorConstruction * GetInstance()
const G4String & GetParticleName() const
G4VPhysicalVolume * GetNextVolume() const
G4StepPoint * GetPreStepPoint() const
const G4VProcess * GetCreatorProcess() const
G4GLOB_DLL std::ostream G4cout
G4int GetCurrentStepNumber() const
G4VPhysicalVolume * GetPhysicalVolume() const
const G4String & GetName() const
const G4String & GetProcessName() const
const G4ThreeVector & GetVertexPosition() const
G4Material * GetMaterial() const
G4LogicalVolume * GetLogicalVolume() const
G4double energy(const ThreeVector &p, const G4double m)
G4StepPoint * GetPostStepPoint() const
G4Navigator * GetGeometryNavigator()
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4VPhysicalVolume * GetVolume() const
static MCTruthManager * instance
G4double GetKineticEnergy() const
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
G4Track * GetTrack() const
G4VSolid * GetSolid() const
G4ThreeVector GetMomentum() const