52 XrayFluoAnalysisManager* XrayFluoAnalysisManager::instance = 0;
56 XrayFluoAnalysisManager::XrayFluoAnalysisManager()
57 :outputFileName(
"xrayfluo"), visPlotter(false), phaseSpaceFlag(false), physicFlag (false), persistencyType(
"root"),
58 deletePersistencyFile(true), gunParticleEnergies(0), gunParticleTypes(0), analysisFactory(0),
tree(0), treeDet(0), histogramFactory(0), plotter(0)
61 analisysMessenger =
new XrayFluoAnalysisMessenger(
this);
65 analysisFactory = AIDA_createAnalysisFactory();
67 CreatePersistency(outputFileName,persistencyType);
75 plotterFactory = analysisFactory->createPlotterFactory();
84 XrayFluoAnalysisManager::~XrayFluoAnalysisManager()
86 delete histogramFactory;
89 delete analysisFactory;
92 delete plotterFactory;
97 if ( gunParticleEnergies )
delete gunParticleEnergies;
98 gunParticleEnergies = 0;
99 if ( gunParticleTypes )
delete gunParticleTypes;
100 gunParticleTypes = 0;
110 XrayFluoAnalysisManager* XrayFluoAnalysisManager::getInstance()
113 if (instance == 0) {instance =
new XrayFluoAnalysisManager;}
119 void XrayFluoAnalysisManager::CreatePersistency(
G4String fileName,
G4String persistencyType,
131 if (histogramFactory) {
132 delete histogramFactory;
133 histogramFactory = 0;
140 if (tupleDetFactory) {
141 delete tupleDetFactory;
144 G4String fileNameDet = fileName+
"Detector";
146 AIDA::ITreeFactory* treeFactory = analysisFactory->createTreeFactory();
148 if (persistencyType ==
"hbook") {
149 fileName = fileName +
".hbk";
150 fileNameDet = fileNameDet +
".hbk";
152 else if (persistencyType ==
"xml"){
153 fileName = fileName +
".xml";
154 fileNameDet = fileNameDet +
".xml";
157 if (phaseSpaceFlag) {
159 tree = treeFactory->create(fileName,persistencyType,readOnly,createNew);
160 treeDet = treeFactory->create(fileNameDet,persistencyType,readOnly,createNew);
161 if(analysisFactory) {
163 tupleDetFactory = analysisFactory->createTupleFactory(*treeDet);
164 tupleFactory = analysisFactory->createTupleFactory(*
tree);
172 tree = treeFactory->create(fileName,persistencyType,readOnly,createNew);
174 if(analysisFactory) {
176 histogramFactory = analysisFactory->createHistogramFactory(*
tree);
186 void XrayFluoAnalysisManager::book()
189 if (phaseSpaceFlag) {
201 std::vector<std::string> columnNames;
202 columnNames.push_back(
"particle");
203 columnNames.push_back(
"energies");
204 columnNames.push_back(
"momentumTheta");
205 columnNames.push_back(
"momentumPhi");
206 columnNames.push_back(
"processes");
207 columnNames.push_back(
"material");
208 columnNames.push_back(
"origin");
209 columnNames.push_back(
"depth");
211 std::vector<std::string> columnTypes;
212 columnTypes.push_back(
"int");
213 columnTypes.push_back(
"double");
214 columnTypes.push_back(
"double");
215 columnTypes.push_back(
"double");
216 columnTypes.push_back(
"int");
217 columnTypes.push_back(
"int");
218 columnTypes.push_back(
"int");
219 columnTypes.push_back(
"double");
221 tupleFluo = tupleFactory->create(
"10",
"Total Tuple", columnNames, columnTypes,
"");
229 histo_1 = histogramFactory->createHistogram1D(
"1",
"Energy Deposit", 500,0.,10.);
230 histo_2 = histogramFactory->createHistogram1D(
"2",
"Gamma born in the sample", 100,0.,10.);
231 histo_3 = histogramFactory->createHistogram1D(
"3",
"Electrons born in the sample", 100,0.,10.);
232 histo_4 = histogramFactory->createHistogram1D(
"4",
"Gammas leaving the sample", 300,0.,10.);
233 histo_5 = histogramFactory->createHistogram1D(
"5",
"Electrons leaving the sample ",200000 ,0.,10.0);
234 histo_6 = histogramFactory->createHistogram1D(
"6",
"Gammas reaching the detector", 100,0.,10.);
235 histo_7 = histogramFactory->createHistogram1D(
"7",
"Spectrum of the incident particles", 100,0.,10.);
236 histo_8 = histogramFactory->createHistogram1D(
"8",
"Protons reaching the detector", 100,0.,10.);
237 histo_9 = histogramFactory->createHistogram1D(
"9",
"Protons leaving the sample", 100,0.,10.);
252 void XrayFluoAnalysisManager::LoadGunData(
G4String fileName,
G4bool raileighFlag) {
257 G4String ext = fileName.substr(fileName.size()-3,fileName.size()-1);
262 persistencyType =
"xml";
264 else if (ext ==
"hbk") {
266 persistencyType =
"hbook";
269 gunParticleEnergies =
new std::vector<G4double>;
270 gunParticleTypes =
new std::vector<G4String>;
274 AIDA::ITreeFactory* treeDataFactory = analysisFactory->createTreeFactory();
275 AIDA::ITree* treeData = treeDataFactory->create(fileName,persistencyType,
false,
false);
276 AIDA::IManagedObject* mo = treeData->find(
"10");
279 AIDA::ITuple* tupleData =
dynamic_cast<AIDA::ITuple*
>(mo);
288 G4int processesIndex = tupleData->findColumn(
"processes");
289 G4int energyIndex = tupleData->findColumn(
"energies");
290 G4int particleIndex = tupleData->findColumn(
"particle");
292 while (tupleData->next()) {
293 if (raileighFlag ^ (!raileighFlag && (tupleData->getInt(processesIndex) == 1 ||
294 tupleData->getInt(processesIndex) == 2)) ) {
295 gunParticleEnergies->push_back(tupleData->getDouble(energyIndex)*
MeV);
296 if (tupleData->getInt(particleIndex) == 1 ) gunParticleTypes->push_back(
"gamma");
297 if (tupleData->getInt(particleIndex) == 0 ) gunParticleTypes->push_back(
"e-");
301 G4cout <<
"Maximum mumber of events: "<< gunParticleEnergies->size() <<
G4endl;
306 std::vector<G4double>* XrayFluoAnalysisManager::GetEmittedParticleEnergies() {
308 return gunParticleEnergies;
312 std::vector<G4String>* XrayFluoAnalysisManager::GetEmittedParticleTypes() {
314 return gunParticleTypes;
319 void XrayFluoAnalysisManager::finish()
322 if (tupleFluo) {ExtractData();};
340 deletePersistencyFile =
false;
346 void XrayFluoAnalysisManager::InitializePlotter()
351 if(plotterFactory && visPlotter && deletePersistencyFile)
353 plotter = plotterFactory->create();
355 plotter->setParameter(
"pageTitle",
"XrayFluo");
358 if(plotter && visPlotter) {
365 void XrayFluoAnalysisManager::PlotCurrentResults()
373 AIDA::ICloud1D& cloud = *cloud_1;
374 AIDA::IFilter* filterGamma = tupleFactory->createFilter(
375 " Particle == std::string(\"gamma\") ");
376 AIDA::IEvaluator* evaluatorEnergy = tupleFactory->createEvaluator(
"Energies");
380 filterGamma->initialize(*tupleFluo);
381 evaluatorEnergy->initialize(*tupleFluo);
382 tupleFluo->project(cloud,*evaluatorEnergy,*filterGamma);
384 plotter->currentRegion().plot( cloud,
"Exiting Gammas " );
390 AIDA::IHistogram1D& histo1p = *histo_1;
391 plotter->currentRegion().plot( histo1p,
"Detector Energy Deposition" );
399 G4bool XrayFluoAnalysisManager::GetDeletePersistencyFileFlag()
401 return deletePersistencyFile;
406 void XrayFluoAnalysisManager::SetPhysicFlag(
G4bool val)
417 void XrayFluoAnalysisManager::analyseStepping(
const G4Step* aStep)
429 G4int isBornInTheSample=0;
454 if (physicFlag ^ (!physicFlag &&
467 if (creationPosVolume->
GetName() ==
"Sample" ) {
468 isBornInTheSample = 1;
482 if (parentProcess ==
"") parent = 0;
483 if (parentProcess ==
"IONI") parent = 1;
484 if (parentProcess ==
"LowEnPhotoElec") parent = 2;
485 if (parentProcess ==
"Transportation") parent = 3;
486 if (parentProcess ==
"initStep") parent = 4;
489 parentProcess =
"Not Known -- (primary generator + Rayleigh)";
495 if (sampleMaterial == (
"Dolorite" ||
"Anorthosite" ||
"Mars1" ||
"IceBasalt" ||
"HPGe")) sampleMat=1;
501 if (particleType ==
"gamma") part =1;
502 if (particleType ==
"e-") part = 0;
503 if (particleType ==
"proton") part = 2;
506 tupleFluo->fill(0,part);
507 tupleFluo->fill(1,particleEnergy);
508 tupleFluo->fill(2,momentum.theta());
509 tupleFluo->fill(3,momentum.phi());
510 tupleFluo->fill(4,parent);
511 tupleFluo->fill(5,sampleMat);
512 tupleFluo->fill(6,isBornInTheSample);
513 tupleFluo->fill(7,particleDepth);
588 histo_4->fill(gammaLeavingSample/
keV);
620 histo_5->fill(eleLeavingSample/
keV);
628 histo_9->fill(protonsLeavSam/
keV);
694 histo_2->fill(gammaBornInSample/
keV);
711 histo_3->fill(eleBornInSample/
keV);
732 histo_6->fill( gammaAtTheDetPre/
keV);
741 histo_8->fill( protonsAtTheDetPre/
keV);
752 void XrayFluoAnalysisManager::ExtractData(){
754 if (tupleFluo->rows()) {
761 AIDA::IFilter* filterAngle = tupleFactory->createFilter(
763 "(momentumPhi >= (220. * (3.1415926/180.) )) && (momentumPhi <= (230. * (3.1415926/180.) )) && (momentumTheta >= (130. * (3.1415926/180.) )) && (momentumTheta <= (140. * (3.1415926/180.) ))" );
768 filterAngle->initialize(*tupleFluo);
778 tupleDetFluo = tupleDetFactory->createFiltered(
"1", *tupleFluo, *filterAngle);
779 assert(tupleDetFluo);
785 void XrayFluoAnalysisManager::analyseEnergyDep(
G4double energyDep)
790 histo_1->fill(energyDep/
keV);
796 void XrayFluoAnalysisManager::analysePrimaryGenerator(
G4double energy)
805 histo_7->fill(energy/
keV);
812 void XrayFluoAnalysisManager::SetOutputFileName(
G4String newName)
815 outputFileName = newName;
818 void XrayFluoAnalysisManager::SetOutputFileType(
G4String newType)
821 persistencyType = newType;