code, separation between detectors and output more automatic

parent d0929469
......@@ -34,12 +34,14 @@
#include "G4SDManager.hh"
#include "globals.hh"
#include "G4VisAttributes.hh"
#include <vector>
class B1SD;
class G4VPhysicalVolume;
class G4LogicalVolume;
class G4VSensitiveDetector;
using namespace std;
/// Detector construction class to define materials and geometry.
class B1DetectorConstruction : public G4VUserDetectorConstruction
......@@ -52,10 +54,19 @@ class B1DetectorConstruction : public G4VUserDetectorConstruction
G4LogicalVolume* GetScoringVolume() const { return fScoringVolume; }
G4LogicalVolume* GetScoringDetector() const { return fScoringDetector; }
G4double get_delta(){return delta;}
G4double get_size() {return size;}
G4double GetDetecPos(G4int num_detec);
std::vector<G4double>& GetPositions() {
return positions;}
protected:
G4LogicalVolume* fScoringVolume;
G4LogicalVolume* fScoringDetector;
std::vector<G4double> positions;
G4double delta;
G4double size;
};
......
......@@ -33,14 +33,16 @@
#include "G4UserEventAction.hh"
#include "globals.hh"
#include <map>
#include <vector>
#include "G4ParticleDefinition.hh"
#include <iostream>
#include <fstream>
class B1RunAction;
class B1DetectorConstruction;
/// Event action class
///
using namespace std;
class B1EventAction : public G4UserEventAction
{
......@@ -53,10 +55,15 @@ class B1EventAction : public G4UserEventAction
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; };
G4double SetPosition(G4int detec);
private:
B1RunAction* fRunAction;
G4double fEdep;
std::vector<G4double> dec_pos;
B1DetectorConstruction* detectorConstruction;
G4double half_height;
G4double variation;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......
......@@ -3,12 +3,14 @@
#include "G4VSensitiveDetector.hh"
#include "B1Hits.hh"
#include <vector>
class G4Step;
class G4HCofThisEvent;
class G4TouchableHistory;
class B1Hits;
using namespace std;
class B1SD: public G4VSensitiveDetector
{
public:
......@@ -25,7 +27,9 @@ public:
private:
B1HitsCollection* hitCollection;
G4int HCID;
std::vector<G4int> tracks;
G4int track_id;
G4String sdname;
};
#endif
This diff is collapsed.
......@@ -30,6 +30,7 @@
#include "B1EventAction.hh"
#include "B1RunAction.hh"
#include "B1Hits.hh"
#include "B1DetectorConstruction.hh"
#include "G4Event.hh"
#include "G4RunManager.hh"
......@@ -65,6 +66,8 @@ void B1EventAction::BeginOfEventAction(const G4Event* event)
{
fEdep = 0.;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -95,7 +98,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
auto Col16 = SDman->GetCollectionID("SD16");
auto Col17 = SDman->GetCollectionID("SD17");
auto Col18 = SDman->GetCollectionID("SD18");
auto Col19 = SDman->GetCollectionID("SD19");
// auto Col19 = SDman->GetCollectionID("SD19");
......@@ -118,7 +121,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
B1HitsCollection* HitsCol16 = 0;
B1HitsCollection* HitsCol17 = 0;
B1HitsCollection* HitsCol18 = 0;
B1HitsCollection* HitsCol19 = 0;
// B1HitsCollection* HitsCol19 = 0;
if(HCE) {
HitsCol1 = (B1HitsCollection*)(HCE->GetHC(Col1));
......@@ -139,7 +142,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
HitsCol16 = (B1HitsCollection*)(HCE->GetHC(Col16));
HitsCol17 = (B1HitsCollection*)(HCE->GetHC(Col17));
HitsCol18 = (B1HitsCollection*)(HCE->GetHC(Col18));
HitsCol19 = (B1HitsCollection*)(HCE->GetHC(Col19));
// HitsCol19 = (B1HitsCollection*)(HCE->GetHC(Col19));
}
//G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
......@@ -148,8 +151,17 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
std::ofstream mu_minusfile("mu-.txt");
detectorConstruction = (B1DetectorConstruction*) G4RunManager::GetRunManager()->GetUserDetectorConstruction();
G4cout << "tttttt" << G4endl;
dec_pos = detectorConstruction->GetPositions();
half_height = detectorConstruction->get_size();
variation = detectorConstruction->get_delta();
if(HitsCol1) {
G4double pos_detec = 0.01;
G4cout << "test" << G4endl;
G4double pos_detec = SetPosition(1);
G4cout << "RRRRRRR" << G4endl;
int n_hit = HitsCol1->entries();
G4cout << "My detector 1 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -166,7 +178,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol2) {
G4double pos_detec = 1.01;
G4double pos_detec = SetPosition(2);
int n_hit = HitsCol2->entries();
G4cout << "My detector 2 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -183,7 +195,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol3) {
G4double pos_detec = 2.01;
G4double pos_detec = SetPosition(3);
int n_hit = HitsCol3->entries();
G4cout << "My detector 3 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -200,7 +212,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol4) {
G4double pos_detec = 3.01;
G4double pos_detec = SetPosition(4);
int n_hit = HitsCol4->entries();
G4cout << "My detector 4 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -217,7 +229,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol5) {
G4double pos_detec = 4.01;
G4double pos_detec = SetPosition(5);
int n_hit = HitsCol5->entries();
G4cout << "My detector 5 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -234,7 +246,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol6) {
G4double pos_detec = 5.01;
G4double pos_detec = SetPosition(6);
int n_hit = HitsCol6->entries();
G4cout << "My detector 6 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -250,7 +262,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol7) {
G4double pos_detec = 6.01;
G4double pos_detec = SetPosition(7);
int n_hit = HitsCol7->entries();
G4cout << "My detector 7 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -266,7 +278,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol8) {
G4double pos_detec = 7.01;
G4double pos_detec = SetPosition(8);
int n_hit = HitsCol8->entries();
G4cout << "My detector 8 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -283,7 +295,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol9) {
G4double pos_detec = 8.01;
G4double pos_detec = SetPosition(9);
int n_hit = HitsCol9->entries();
G4cout << "My detector 9 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -300,7 +312,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol10) {
G4double pos_detec = 9.01;
G4double pos_detec = SetPosition(10);
int n_hit = HitsCol10->entries();
G4cout << "My detector 10 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -317,7 +329,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol11) {
G4double pos_detec = 10.01;
G4double pos_detec = SetPosition(11);
int n_hit = HitsCol11->entries();
G4cout << "My detector 11 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -333,7 +345,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol12) {
G4double pos_detec = 11.01;
G4double pos_detec = SetPosition(12);
int n_hit = HitsCol12->entries();
G4cout << "My detector 12 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -349,7 +361,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol13) {
G4double pos_detec = 12.01;
G4double pos_detec = SetPosition(13);
int n_hit = HitsCol13->entries();
G4cout << "My detector 13 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -365,9 +377,9 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol14) {
G4double pos_detec = 13.01;
G4double pos_detec = SetPosition(14);
int n_hit = HitsCol14->entries();
G4cout << "My detector 1 has " << n_hit << "hits" << G4endl;
G4cout << "My detector 14 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
std::map<const G4String, int> fparticles;
for(int i1 = 0; i1 < n_hit; i1++) {
......@@ -382,7 +394,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
}
if(HitsCol15) {
G4double pos_detec = 14.01;
G4double pos_detec = SetPosition(15);
int n_hit = HitsCol15->entries();
G4cout << "My detector 15 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -398,7 +410,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol16) {
G4double pos_detec = 15.01;
G4double pos_detec = SetPosition(16);
int n_hit = HitsCol16->entries();
G4cout << "My detector 16 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -414,7 +426,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol17) {
G4double pos_detec = 16.01;
G4double pos_detec = SetPosition(17);
int n_hit = HitsCol17->entries();
G4cout << "My detector 17 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -430,7 +442,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
if(HitsCol18) {
G4double pos_detec = 17.01;
G4double pos_detec = SetPosition(18);
int n_hit = HitsCol18->entries();
G4cout << "My detector 18 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -445,8 +457,9 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
PrintParticles(fparticles, gammafile, mu_plusfile, mu_minusfile, pos_detec);
fparticles.clear();
}
/*
if(HitsCol19) {
G4double pos_detec = 17.98;
G4double pos_detec = SetPosition(19);
int n_hit = HitsCol19->entries();
G4cout << "My detector 19 has " << n_hit << "hits" << G4endl;
B1Hits* hit = new B1Hits;
......@@ -462,6 +475,7 @@ void B1EventAction::EndOfEventAction(const G4Event* event)
fparticles.clear();
}
*/
gammafile.close();
mu_plusfile.close();
......@@ -514,4 +528,21 @@ void B1EventAction::WriteHistogram(const G4String name, G4int Detec) {
*/
}
G4double B1EventAction::SetPosition(G4int detec) {
G4int detec_index = detec - 1;
G4double first_value = dec_pos[0]/1000000;
G4cout << first_value << G4endl;
G4double value = dec_pos[detec_index];
G4double value_c = value/1000000;
G4double half_height_real = half_height/1000000;
G4double h_real = half_height_real*2;
G4double real_delta = variation/1000000;
G4double first_distance = half_height_real + first_value ;
if (detec_index == 0) {
return first_distance;
}
return (first_distance + detec_index*real_delta);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -8,9 +8,11 @@
#include "G4ios.hh"
B1SD::B1SD(G4String SDname): G4VSensitiveDetector(SDname),
hitCollection(nullptr), HCID(-1) {
hitCollection(nullptr), HCID(-1) {
G4cout << "Criando Hit Collection com nome: " << SDname <<G4endl;
collectionName.insert(SDname);
track_id = 0;
sdname = SDname;
}
B1SD::~B1SD() {
......@@ -22,14 +24,27 @@ G4bool B1SD::ProcessHits(G4Step* step, G4TouchableHistory* ROhist) {
const G4String particle_name = step->GetTrack()->GetDynamicParticle()->GetParticleDefinition()->GetParticleName();
//G4cout << particle_def->GetParticleName() << G4endl;
G4int track = step->GetTrack()->GetTrackID();
if (track != track_id) {
/*
G4cout << sdname << G4endl;
G4cout << track << G4endl;
G4cout << track_id << G4endl;
*/
if (track == track_id) {
if (track == 0) {
B1Hits* hit = new B1Hits();
hit->set_partdef(particle_name);
hitCollection->insert(hit);
track_id = track;
return true;
}
return true;
} else {
B1Hits* hit = new B1Hits();
hit->set_partdef(particle_name);
hitCollection->insert(hit);
track_id = track;
return true;
} else {
return true;
}
}
......
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