| [807] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | // ********************************************************************
|
|---|
| 27 | // * *
|
|---|
| 28 | // * cosmicray_charging advanced example for Geant4 *
|
|---|
| 29 | // * (adapted simulation of test-mass charging in the LISA mission) *
|
|---|
| 30 | // * *
|
|---|
| 31 | // * Henrique Araujo (h.araujo@imperial.ac.uk) & Peter Wass *
|
|---|
| 32 | // * Imperial College London *
|
|---|
| 33 | // * *
|
|---|
| 34 | // * LISAEventAction class *
|
|---|
| 35 | // * *
|
|---|
| 36 | // ********************************************************************
|
|---|
| 37 | //
|
|---|
| 38 | // HISTORY
|
|---|
| 39 | // 22/02/2004: migrated from LISA-V04
|
|---|
| 40 | //
|
|---|
| 41 | // ********************************************************************
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | #include "LISAEventAction.hh"
|
|---|
| 45 |
|
|---|
| 46 | #include "LISAPrimaryGeneratorAction.hh"
|
|---|
| 47 | #include "LISASteppingAction.hh"
|
|---|
| 48 |
|
|---|
| 49 | #ifdef G4ANALYSIS_USE
|
|---|
| 50 | #include "LISAAnalysisManager.hh"
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | #include "G4Event.hh"
|
|---|
| 54 | #include "G4EventManager.hh"
|
|---|
| 55 | #include "G4TrajectoryContainer.hh"
|
|---|
| 56 | #include "G4Trajectory.hh"
|
|---|
| 57 | #include "G4ParticleDefinition.hh"
|
|---|
| 58 | #include "G4VVisManager.hh"
|
|---|
| 59 | #include "G4UImanager.hh"
|
|---|
| 60 | #include "G4Polyline.hh"
|
|---|
| 61 | #include "G4Colour.hh"
|
|---|
| 62 | #include "G4VisAttributes.hh"
|
|---|
| 63 | #include "G4UnitsTable.hh"
|
|---|
| 64 | #include "G4ios.hh"
|
|---|
| 65 |
|
|---|
| 66 | #include <fstream>
|
|---|
| 67 | #include <iomanip>
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 71 | LISAEventAction::LISAEventAction(LISAPrimaryGeneratorAction* generatorAction,
|
|---|
| 72 | LISASteppingAction* steppingAction)
|
|---|
| 73 | : genAction(generatorAction),stepAction(steppingAction) {
|
|---|
| 74 |
|
|---|
| 75 | energy_pri = 0;
|
|---|
| 76 | charge_in[0] = 0;
|
|---|
| 77 | charge_in[1] = 0;
|
|---|
| 78 | charge_out[0] = 0;
|
|---|
| 79 | charge_out[1] = 0;
|
|---|
| 80 | charge_tot[0] = 0;
|
|---|
| 81 | charge_tot[1] = 0;
|
|---|
| 82 | seeds = NULL;
|
|---|
| 83 | filename = G4String();
|
|---|
| 84 |
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 89 | LISAEventAction::~LISAEventAction() {;}
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 93 | void LISAEventAction::BeginOfEventAction(const G4Event* evt) {
|
|---|
| 94 |
|
|---|
| 95 | // reset event charges
|
|---|
| 96 | stepAction->Discharge();
|
|---|
| 97 |
|
|---|
| 98 | // grab event seeds
|
|---|
| 99 | seeds = genAction->GetEventSeeds();
|
|---|
| 100 | // G4cout << " 1st seed: " << *seeds << G4endl;;
|
|---|
| 101 | // G4cout << " 2nd seed: " << *(seeds+1) << G4endl;
|
|---|
| 102 | // HepRandom::showEngineStatus();
|
|---|
| 103 |
|
|---|
| 104 | // grab energy of primary
|
|---|
| 105 | energy_pri = genAction->GetEnergyPrimary();
|
|---|
| 106 |
|
|---|
| 107 | event_id = evt->GetEventID();
|
|---|
| 108 | if(event_id%1000==0 || (event_id%100==0 && event_id<1000))
|
|---|
| 109 | G4cout << "\n---> Begin of event: " << event_id << G4endl;
|
|---|
| 110 |
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 115 | void LISAEventAction::EndOfEventAction(const G4Event* evt) {
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | // Look at TM0 and TM1
|
|---|
| 119 | for(int tm=0; tm<=1; ++tm) {
|
|---|
| 120 |
|
|---|
| 121 | charge_in[tm] = stepAction->GetChargeIn(tm);
|
|---|
| 122 | charge_out[tm] = stepAction->GetChargeOut(tm);
|
|---|
| 123 | charge_tot[tm] = charge_in[tm] - charge_out[tm];
|
|---|
| 124 |
|
|---|
| 125 | // save if changed
|
|---|
| 126 | if(charge_tot[tm]) {
|
|---|
| 127 |
|
|---|
| 128 | // printout
|
|---|
| 129 | G4cout << " *** Evt: " << event_id
|
|---|
| 130 | << "\tTM: " << tm
|
|---|
| 131 | << "\tE: " << energy_pri
|
|---|
| 132 | << "\tQnet: " << charge_tot[tm]
|
|---|
| 133 | << "\tQin: " << charge_in[tm]
|
|---|
| 134 | << "\tQout: " << charge_out[tm]
|
|---|
| 135 | << G4endl;
|
|---|
| 136 |
|
|---|
| 137 | // append to file
|
|---|
| 138 | std::ofstream chargefile(filename,std::ios::app);
|
|---|
| 139 | chargefile << event_id << "\t"
|
|---|
| 140 | << tm << "\t"
|
|---|
| 141 | << energy_pri << "\t"
|
|---|
| 142 | << charge_tot[tm] << "\t"
|
|---|
| 143 | << charge_in[tm] << "\t"
|
|---|
| 144 | << charge_out[tm] << "\t"
|
|---|
| 145 | << *seeds << "\t"
|
|---|
| 146 | << *(seeds+1) << "\t"
|
|---|
| 147 | << G4endl;
|
|---|
| 148 |
|
|---|
| 149 | // Write event information to HBOOK NTuple if using analysis
|
|---|
| 150 | #ifdef G4ANALYSIS_USE
|
|---|
| 151 | LISAAnalysisManager* analysis = LISAAnalysisManager::getInstance();
|
|---|
| 152 | analysis->analyseRun(event_id,
|
|---|
| 153 | tm,
|
|---|
| 154 | energy_pri,
|
|---|
| 155 | charge_tot[tm],
|
|---|
| 156 | charge_in[tm],
|
|---|
| 157 | charge_out[tm],
|
|---|
| 158 | *seeds,
|
|---|
| 159 | *(seeds+1));
|
|---|
| 160 | #endif
|
|---|
| 161 |
|
|---|
| 162 | } // if(charge_tot[tm])
|
|---|
| 163 |
|
|---|
| 164 | } // for(int tm=0; tm<=1; ++tm)
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | // draw trajectories
|
|---|
| 169 | // colours by particle type
|
|---|
| 170 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
|
|---|
| 171 | if(pVVisManager) {
|
|---|
| 172 |
|
|---|
| 173 | G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
|
|---|
| 174 | G4int n_trajectories = 0;
|
|---|
| 175 | if (trajectoryContainer)
|
|---|
| 176 | n_trajectories = trajectoryContainer->entries();
|
|---|
| 177 |
|
|---|
| 178 | for (G4int i=0; i<n_trajectories; i++) {
|
|---|
| 179 | G4Trajectory* trj = 0;
|
|---|
| 180 | trj = dynamic_cast<G4Trajectory*>((*trajectoryContainer)[i]);
|
|---|
| 181 |
|
|---|
| 182 | G4String name = trj->GetParticleDefinition()->GetParticleName();
|
|---|
| 183 | G4Colour colour = G4Colour(1.0, 1.0, 1.0);
|
|---|
| 184 | G4Polyline pPolyline;
|
|---|
| 185 |
|
|---|
| 186 | if (trj) {
|
|---|
| 187 |
|
|---|
| 188 | for (int i=0; i<trj->GetPointEntries(); i++)
|
|---|
| 189 | pPolyline.push_back( trj->GetPoint(i)->GetPosition() );
|
|---|
| 190 |
|
|---|
| 191 | if(name=="proton") colour=G4Colour(0.0, 0.0, 1.0);
|
|---|
| 192 | else if(name=="alpha") colour=G4Colour(0.0, 0.0, 0.5);
|
|---|
| 193 | else if(name=="He3") colour=G4Colour(1.0, 0.0, 1.0);
|
|---|
| 194 | else if(name=="pi+") colour=G4Colour(0.5, 0.5, 0.5);
|
|---|
| 195 | else if(name=="pi-") colour=G4Colour(0.5, 0.5, 0.5);
|
|---|
| 196 | else if(name=="e+") colour=G4Colour(0.0, 1.0, 1.0);
|
|---|
| 197 | else if(name=="e-") colour=G4Colour(1.0, 0.0, 0.0);
|
|---|
| 198 | else if(name=="gamma") colour=G4Colour(0.0, 1.0, 0.0);
|
|---|
| 199 | else if(name=="neutron") colour=G4Colour(1.0, 1.0, 0.0);
|
|---|
| 200 | else colour=G4Colour(1.0, 1.0, 1.0);
|
|---|
| 201 |
|
|---|
| 202 | G4VisAttributes attribs(colour);
|
|---|
| 203 | pPolyline.SetVisAttributes(attribs);
|
|---|
| 204 | if(pVVisManager) pVVisManager->Draw(pPolyline);
|
|---|
| 205 |
|
|---|
| 206 | } else
|
|---|
| 207 | G4cerr << "EndOfEventAction: Failed to dynamic cast to G4Trajectory!"
|
|---|
| 208 | << G4endl;
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|