B1EventAction.cc 4.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
//
/// \file B1EventAction.cc
/// \brief Implementation of the B1EventAction class

#include "B1EventAction.hh"
#include "B1RunAction.hh"
#include "B1Hits.hh"
#include "B1DetectorConstruction.hh"
34
#include "G4SystemOfUnits.hh"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include "G4HCofThisEvent.hh"
#include "G4VHitsCollection.hh"
#include "G4SDManager.hh"
#include "G4ios.hh"
#include "G4Event.hh"
#include "G4RunManager.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

B1EventAction::B1EventAction(B1RunAction* runAction)
: G4UserEventAction(),
  fRunAction(runAction),
  fEdep1(0.),
  fEdep2(0.)
{} 

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

B1EventAction::~B1EventAction()
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void B1EventAction::BeginOfEventAction(const G4Event*)
{    
  fEdep1 = 0.;
61
  fEdep2 = 0.;
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void B1EventAction::EndOfEventAction(const G4Event* event)
{   
  // accumulate statistics in run action
  fRunAction->AddEdep1(fEdep1);
  fRunAction->AddEdep2(fEdep2);

 static int CHCID = -1;
if (CHCID < 0) {
    CHCID = G4SDManager::GetSDMpointer()->GetCollectionID("SD");//Descobrir isso
  }



 // pega as collections ID's
 
 G4SDManager * SDman = G4SDManager::GetSDMpointer();
 G4HCofThisEvent* HCE = event->GetHCofThisEvent();
83
 
84 85 86 87 88 89 90 91 92 93 94 95
 B1HitsCollection* HitsCol = 0;


  if(HCE) {
    HitsCol = (B1HitsCollection*)(HCE->GetHC(CHCID));
  }

 
    int n_hit = HitsCol->entries();
     G4cout << "My detector has " << n_hit << "hits" << G4endl;
     B1Hits* hit = new B1Hits;
     std::map<const G4String, int> fparticles;
96 97 98 99 100 101

     double n_mu_p = 0.0;
     double n_mu_m = 0.0;
     G4double total_energy_mu_p = 0;
     G4double total_energy_mu_m = 0;

102 103 104 105 106 107 108 109 110 111
    const B1PrimaryGeneratorAction* generatorAction
   = static_cast<const B1PrimaryGeneratorAction*>
     (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
 

   const G4ParticleGun* particleGun = generatorAction->GetParticleGun();


   G4double particleEnergy = particleGun->GetParticleEnergy();
     
112
     std::ofstream mu_p_pos("position_mu_p.dat",std::ios_base::app);
113
 
114
  std::ofstream mu_m_pos("position_mu_m.dat",std::ios_base::app);
115

116 117 118 119
     for(int i1 = 0; i1 < n_hit; i1++) {
      B1Hits* hit = (*HitsCol)[i1];
      const G4String name = hit->getParticleInTarget();
      G4cout << name << G4endl;
120 121 122 123 124
      if (name == "mu+" || name=="mu-") {
	 G4double energy = hit->getParticleEnergy();
         G4ThreeVector position = hit->getParticlePos();
	if (name == "mu+") {
	n_mu_p++;
125
        mu_p_pos << position.x()/(m) << "  " << position.y()/(m) << "\n";
126 127 128
 	total_energy_mu_p += energy;
	} else if (name=="mu-") {
        total_energy_mu_m += energy;
129
        mu_m_pos << position.x()/(m) << "  " << position.y()/(m) << "\n";
130 131 132 133 134
	n_mu_m++;

	}
    }
      
135 136
}

137 138 139 140
 mu_p_pos.close();
mu_m_pos.close();


141 142 143 144 145 146 147 148
 if(n_mu_p != 0.0) {
       G4double value = total_energy_mu_p/n_mu_p;
       G4cout << value/(GeV) << G4endl;
       fRunAction->AddE_mup(value);
    } else {fRunAction->AddE_mup(total_energy_mu_p);}
 
 if(n_mu_m != 0.0) {
       G4double value = total_energy_mu_m/n_mu_m;
149
       fRunAction->AddE_mum(value);
150
    } else {fRunAction->AddE_mum(total_energy_mu_m);}
151 152 153 154 155

} 


//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......