added more detectors and write and file with the output

parent 976b9581
......@@ -34,6 +34,8 @@
#include "globals.hh"
#include <map>
#include "G4ParticleDefinition.hh"
#include <iostream>
#include <fstream>
class B1RunAction;
......@@ -48,8 +50,8 @@ class B1EventAction : public G4UserEventAction
virtual void BeginOfEventAction(const G4Event* event);
virtual void EndOfEventAction(const G4Event* event);
void PrintParticles(std::map<const G4String, int>& container);
void PrintParticles(std::map<const G4String, int>& container, std::ofstream& gamma, std::ofstream& mu_minus, std::ofstream& mu_plus, G4double position);
void WriteHistogram(const G4String name, G4int Detec);
void AddEdep(G4double edep) { fEdep += edep; };
private:
......
import matplotlib.pyplot as plt
import csv
x = []
y_gamma = []
y_mu_minus = []
y_mu_plus = []
with open("gamma.txt", "r") as csvfile:
plots = csv.reader(csvfile, delimiter=" ")
for row in plots:
y_gamma.append(float(row[0]))
x.append(float(row[1]))
with open("mu+.txt", "r") as csvfile:
plots = csv.reader(csvfile, delimiter=" ")
for row in plots:
y_mu_plus.append(float(row[0]))
with open("mu-.txt", "r") as csvfile:
plots = csv.reader(csvfile, delimiter=" ")
for row in plots:
y_mu_minus.append(float(row[0]))
plt.scatter(x, y_gamma)
plt.title("Geant4 hadronic shower graphs")
plt.ylabel("Nº gamma")
plt.xlabel("distance (km)")
plt.xlim(xmin=0)
plt.ylim(ymin=0)
plt.show()
line1 = plt.scatter(x, y_mu_plus, c='b', label='1')
line2 = plt.scatter(x,y_mu_minus, c='r', label='1')
plt.title("Geant4 hadronic shower graphs")
plt.ylabel("Nº muons")
plt.xlabel("distance (km)")
plt.xlim(xmin=0)
plt.ylim(ymin=0)
plt.legend((line1, line2), ('mu-', 'mu+'))
plt.show()
This diff is collapsed.
This diff is collapsed.
......@@ -79,7 +79,7 @@ void B1PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
fParticleGun->SetParticlePosition(G4ThreeVector(0,0,-100.*m));
fParticleGun->SetParticlePosition(G4ThreeVector(0,0,-9.*m));
fParticleGun->GeneratePrimaryVertex(anEvent);
}
......
......@@ -86,7 +86,7 @@ void B1RunAction::BeginOfRunAction(const G4Run*)
G4cout << "bbbb" << G4endl;
}
createHistogram();
// createHistogram();
// inform the runManager to save random number seed
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
......@@ -163,8 +163,8 @@ void B1RunAction::EndOfRunAction(const G4Run* run)
<< G4endl
<< G4endl;
WriteHistogram();
delete G4AnalysisManager::Instance();
// WriteHistogram();
// delete G4AnalysisManager::Instance();
//printando partículas criadas
std::map<const G4ParticleDefinition*, int>&
particlesCreatedInWorld = fptrackingAction->GetNParticlesCreatedInWorld();
......@@ -197,6 +197,7 @@ void B1RunAction::AddEdep(G4double edep)
void B1RunAction::createHistogram()
{
//Avisa que está criando
G4cout << "CRIANDO HISTOGRAMAS" << G4endl;
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
//mostrando o tipo
......@@ -208,7 +209,15 @@ void B1RunAction::createHistogram()
G4String filename = "air_shower";
analysisManager->OpenFile(filename);
analysisManager->CreateNtuple("air_shower", "physics");
analysisManager->CreateNtupleDColumn("mu_minus");
analysisManager->CreateNtupleDColumn("mu_plus");
analysisManager->CreateNtupleDColumn("gamma");
analysisManager->FinishNtuple();
//criando ntuples
/*
analysisManager->CreateNtuple("air_shower", "physics");
analysisManager->CreateNtupleDColumn("proton");
analysisManager->CreateNtupleDColumn("e_plus");
......@@ -220,7 +229,7 @@ void B1RunAction::createHistogram()
analysisManager->CreateNtupleDColumn("gamma");
analysisManager->CreateNtupleDColumn("z");
analysisManager->FinishNtuple();
*/
}
void B1RunAction::WriteHistogram()
......@@ -238,7 +247,6 @@ void B1RunAction::WriteHistogram()
//função para printar partículas
void B1RunAction::PrintParticles(std::map<const G4ParticleDefinition*, int>& container) {
std::map<const G4ParticleDefinition*, int>::iterator it;
G4cout << "aa" << G4endl;
for(it = container.begin() ;it != container.end(); it ++)
{
G4cout << "N " << it->first->GetParticleName() << " : " << it->second << G4endl;
......
......@@ -10,7 +10,7 @@
B1SD::B1SD(G4String SDname): G4VSensitiveDetector(SDname),
hitCollection(nullptr), HCID(-1) {
G4cout << "Criando Hit Collection com nome: " << SDname <<G4endl;
collectionName.insert("HitCollection");
collectionName.insert(SDname);
}
B1SD::~B1SD() {
......@@ -36,7 +36,6 @@ G4bool B1SD::ProcessHits(G4Step* step, G4TouchableHistory* ROhist) {
void B1SD::Initialize(G4HCofThisEvent* HCE) {
hitCollection = new B1HitsCollection(SensitiveDetectorName,collectionName[0]);
static G4int HCID = -1;
if (HCID < 0) HCID = GetCollectionID(0);
HCE->AddHitsCollection(HCID, hitCollection);
}
......@@ -78,51 +78,16 @@ void B1SteppingAction::UserSteppingAction(const G4Step* step)
//ATENÇÃO - Comments dentro dos else-if -> para histograma de particlas x z (BUG no Z=0 e resultado duvidoso -- MELHORAR)
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
// G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
//collect particle for each step
G4String particle = step->GetTrack()->GetDynamicParticle()->GetDefinition() ->GetParticleName();
G4double z =step->GetPreStepPoint()->GetPosition().z()/meter;
//G4double x =step->GetPreStepPoint()->GetPosition().x()/meter;// se quiser plotar com x e y
//G4double y =step->GetPreStepPoint()->GetPosition().y()/meter;
if (particle == "e-") {
e_minus = 1;
//analysisManager->FillNtupleDColumn(2, z);
} else if (particle == "e+") {
e_p = 1;
//analysisManager->FillNtupleDColumn(1, z);
}else if (particle == "proton") {
p = 1;
//analysisManager->FillNtupleDColumn(0, z);
}else if (particle == "pi-") {
pi_m = 1;
//analysisManager->FillNtupleDColumn(6, z);
}else if (particle == "pi+") {
pi_p = 1;
//analysisManager->FillNtupleDColumn(5, z);
}else if (particle == "mu-") {
mu_m = 1;
//analysisManager->FillNtupleDColumn(3, z);
}else if (particle == "mu+") {
mu_p = 1;
//analysisManager->FillNtupleDColumn(4, z);
}else if (particle == "gamma") {
gamma = 1;
//analysisManager->FillNtupleDColumn(7, z);
}
//Retire esse comment para histograma que leva em conta o numero de vezes que a particula foi identificado no evento. -> Por enquanto o mais confiável.
/*
analysisManager->FillNtupleDColumn(0, p);
analysisManager->FillNtupleDColumn(1, e_p);
analysisManager->FillNtupleDColumn(2, e_minus);
analysisManager->FillNtupleDColumn(3, mu_m);
analysisManager->FillNtupleDColumn(4, mu_p);
analysisManager->FillNtupleDColumn(5, pi_p);
analysisManager->FillNtupleDColumn(6, pi_m);
analysisManager->FillNtupleDColumn(7, gamma);
analysisManager->FillNtupleDColumn(8, z);
/**/
analysisManager->AddNtupleRow();
// analysisManager->AddNtupleRow();
// collect energy deposited in this step
G4double edepStep = step->GetTotalEnergyDeposit();
fEventAction->AddEdep(edepStep);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment