| 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 | // $Id: G4KaonMinusAbsorptionAtRestTest.cc,v 1.5 2008/12/18 13:02:38 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $
|
|---|
| 29 | //
|
|---|
| 30 | // KaonMinusAtRestTest.cc
|
|---|
| 31 | // -------------------------------------------------------------------
|
|---|
| 32 | // GEANT 4 class file --- Copyright CERN 1998
|
|---|
| 33 | // CERN Geneva Switzerland
|
|---|
| 34 | //
|
|---|
| 35 | //
|
|---|
| 36 | // File name: G4KaonMinusAbsorptionAtRestTest.cc
|
|---|
| 37 | //
|
|---|
| 38 | // Author: Christian Voelcker (from M. Maire)
|
|---|
| 39 | //
|
|---|
| 40 | // Creation date: ?
|
|---|
| 41 | //
|
|---|
| 42 | // Modifications:
|
|---|
| 43 | //
|
|---|
| 44 | // Maria Grazia Pia 30 Jun 1998 Added histograms (with CLHEP)
|
|---|
| 45 | // Maria Grazia Pia 6 Jul 1998 Modified handling of ProcessManager
|
|---|
| 46 | // to be consistent with changes in
|
|---|
| 47 | // ParticleDefinition
|
|---|
| 48 | //
|
|---|
| 49 | // -------------------------------------------------------------------
|
|---|
| 50 |
|
|---|
| 51 | #include "G4ios.hh"
|
|---|
| 52 | #include <fstream>
|
|---|
| 53 | #include <iomanip>
|
|---|
| 54 |
|
|---|
| 55 | #include "G4Material.hh"
|
|---|
| 56 |
|
|---|
| 57 | #include "G4ProcessManager.hh"
|
|---|
| 58 | #include "G4KaonMinusAbsorptionAtRest.hh"
|
|---|
| 59 |
|
|---|
| 60 | #include "G4DynamicParticle.hh"
|
|---|
| 61 | #include "G4KaonMinus.hh"
|
|---|
| 62 |
|
|---|
| 63 | #include "G4Box.hh"
|
|---|
| 64 | #include "G4PVPlacement.hh"
|
|---|
| 65 |
|
|---|
| 66 | #include "G4Step.hh"
|
|---|
| 67 | #include "G4GRSVolume.hh"
|
|---|
| 68 |
|
|---|
| 69 | #include "CLHEP/Hist/TupleManager.h"
|
|---|
| 70 | #include "CLHEP/Hist/HBookFile.h"
|
|---|
| 71 | #include "CLHEP/Hist/Histogram.h"
|
|---|
| 72 | #include "CLHEP/Hist/Tuple.h"
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | // it tests the G4ComptonScattering process ----------------
|
|---|
| 76 | // ---------- M.Maire on 19/04/96 --------------------------
|
|---|
| 77 | //
|
|---|
| 78 | // Modifs:
|
|---|
| 79 | // 19-02-97, Modifs in DoIt for new physic scheme
|
|---|
| 80 | // 25-02-97, 'simplified' version for the process manager
|
|---|
| 81 | // 12-03-97, GetMeanFreePath and PostStepDoIt
|
|---|
| 82 | // 21-03-97, calling sequence of AddProcess modified
|
|---|
| 83 |
|
|---|
| 84 | int main()
|
|---|
| 85 | {
|
|---|
| 86 | //-------- set output format-------
|
|---|
| 87 | G4cout.setf( std::ios::scientific, std::ios::floatfield );
|
|---|
| 88 | //-------- write results onto a file --------
|
|---|
| 89 | std::ofstream outFile( "KaonMinusAbsorptionAtRest.out", std::ios::out);
|
|---|
| 90 | outFile.setf( std::ios::scientific, std::ios::floatfield );
|
|---|
| 91 |
|
|---|
| 92 | // -------------------------------------------------------------------
|
|---|
| 93 | // MGP ---- HBOOK initialization
|
|---|
| 94 | HepTupleManager* hbookManager;
|
|---|
| 95 | hbookManager = new HBookFile("mgkaon.hbook", 58);
|
|---|
| 96 | assert (hbookManager != 0);
|
|---|
| 97 |
|
|---|
| 98 | // MGP ---- Book a histogram
|
|---|
| 99 | HepHistogram* hEKin;
|
|---|
| 100 | hEKin = hbookManager->histogram("Kinetic Energy", 100,0.,200.);
|
|---|
| 101 | assert (hEKin != 0);
|
|---|
| 102 |
|
|---|
| 103 | // HepHistogram* hE;
|
|---|
| 104 | // hE = hbookManager->histogram("Energy", 100,0.,2000.);
|
|---|
| 105 | // assert (hE != 0);
|
|---|
| 106 |
|
|---|
| 107 | HepHistogram* hP;
|
|---|
| 108 | hP = hbookManager->histogram("Momentum", 100,0.,1000.);
|
|---|
| 109 | assert (hP != 0);
|
|---|
| 110 |
|
|---|
| 111 | HepHistogram* hNSec;
|
|---|
| 112 | hNSec = hbookManager->histogram("Number of secondaries", 40,0.,40.);
|
|---|
| 113 | assert (hNSec != 0);
|
|---|
| 114 |
|
|---|
| 115 | HepHistogram* hDebug;
|
|---|
| 116 | hDebug = hbookManager->histogram("Debug", 100,0.,200.);
|
|---|
| 117 | assert (hDebug != 0);
|
|---|
| 118 |
|
|---|
| 119 | // MGP ---- Book a ntuple
|
|---|
| 120 | HepTuple* ntuple;
|
|---|
| 121 | ntuple = hbookManager->ntuple("Pion absorption at rest Ntuple");
|
|---|
| 122 | assert (ntuple != 0);
|
|---|
| 123 |
|
|---|
| 124 | G4int niter=10;
|
|---|
| 125 | G4int imat=3;
|
|---|
| 126 | G4int verboseLevel=1;
|
|---|
| 127 | G4int processID=1;
|
|---|
| 128 | G4cout << " How many absorptions? [10], Which material? [3], which Verbose Level? [1]" << G4endl;
|
|---|
| 129 | G4cin >> niter >> imat >> verboseLevel;
|
|---|
| 130 | G4cout << " which process? (1)=G4KaonMinusAbsorptionAtRest, (2)=G4HadronAtRest [1]" << G4endl;
|
|---|
| 131 | G4cin >> processID;
|
|---|
| 132 |
|
|---|
| 133 | G4int hnt;
|
|---|
| 134 | G4cout << "Enter histo (0) or ntuple (1) " << G4endl;
|
|---|
| 135 | G4cin >> hnt;
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | //
|
|---|
| 139 | //--------- Materials definition ---------
|
|---|
| 140 | //
|
|---|
| 141 | G4Material* Al = new G4Material("Aluminium", 13., 26.98*g/mole, 2.7 *g/cm3 );
|
|---|
| 142 | G4Material* Fe = new G4Material("Iron", 26., 55.85*g/mole, 7.87*g/cm3 );
|
|---|
| 143 | G4Material* Pb = new G4Material("Lead", 82., 207.19*g/mole, 11.35*g/cm3 );
|
|---|
| 144 | G4Material* Graphite = new G4Material("Graphite",6., 12.00*g/mole, 2.265*g/cm3 );
|
|---|
| 145 |
|
|---|
| 146 | G4Element* H = new G4Element ("Hydrogen", "H", 1. , 1.01*g/mole);
|
|---|
| 147 | G4Element* O = new G4Element ("Oxygen" , "O", 8. , 16.00*g/mole);
|
|---|
| 148 | G4Element* C = new G4Element ("Carbon" , "C", 6. , 12.00*g/mole);
|
|---|
| 149 | G4Element* Cs = new G4Element ("Cesium" , "Cs", 55. , 132.905*g/mole);
|
|---|
| 150 | G4Element* I = new G4Element ("Iodide" , "I", 53. , 126.9044*g/mole);
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | G4Material* water = new G4Material ("Water" , 1.*g/cm3, 2);
|
|---|
| 154 | water->AddElement(H,2);
|
|---|
| 155 | water->AddElement(O,1);
|
|---|
| 156 |
|
|---|
| 157 | G4Material* ethane = new G4Material ("Ethane" , 0.4241*g/cm3, 2);
|
|---|
| 158 | ethane->AddElement(H,6);
|
|---|
| 159 | ethane->AddElement(C,2);
|
|---|
| 160 |
|
|---|
| 161 | G4Material* csi = new G4Material ("CsI" , 4.53*g/cm3, 2);
|
|---|
| 162 | csi->AddElement(Cs,1);
|
|---|
| 163 | csi->AddElement(I,1);
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 | // G4Element::DumpInfo();
|
|---|
| 167 | // G4Material::DumpInfo();
|
|---|
| 168 |
|
|---|
| 169 | static const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
|
|---|
| 170 |
|
|---|
| 171 | // fix a material
|
|---|
| 172 | // G4int imat = 0; // graphite
|
|---|
| 173 |
|
|---|
| 174 | // Geometry definitions
|
|---|
| 175 | //
|
|---|
| 176 | G4Box* theFrame = new G4Box ("Frame",1*m, 1*m, 1*m);
|
|---|
| 177 |
|
|---|
| 178 | G4LogicalVolume* LogicalFrame = new G4LogicalVolume(theFrame,
|
|---|
| 179 | (*theMaterialTable)(imat),
|
|---|
| 180 | "LFrame", 0, 0, 0);
|
|---|
| 181 |
|
|---|
| 182 | G4PVPlacement* PhysicalFrame = new G4PVPlacement(0,G4ThreeVector(),
|
|---|
| 183 | "PFrame",LogicalFrame,0,false,0);
|
|---|
| 184 |
|
|---|
| 185 | // the center-of-mass of the cube should be located at the origin!
|
|---|
| 186 |
|
|---|
| 187 | //--------- Particle definition ---------
|
|---|
| 188 | //
|
|---|
| 189 | G4ParticleDefinition* kaonMinus = G4KaonMinus::KaonMinusDefinition();
|
|---|
| 190 |
|
|---|
| 191 | //--------- Processes definition ---------
|
|---|
| 192 | //
|
|---|
| 193 |
|
|---|
| 194 | G4ProcessManager* theKaonProcessManager = new G4ProcessManager(kaonMinus);
|
|---|
| 195 | kaonMinus->SetProcessManager(theKaonProcessManager);
|
|---|
| 196 |
|
|---|
| 197 | // G4ProcessManager* theKaonProcessManager = kaonMinus->GetProcessManager();
|
|---|
| 198 |
|
|---|
| 199 | G4KaonMinusAbsorptionAtRest kaonMinusAbsorptionAtRest;
|
|---|
| 200 | // G4HadronAtRest hadronAtRest;
|
|---|
| 201 |
|
|---|
| 202 | G4KaonMinusAbsorptionAtRest theKaonAbsorptionProcess;
|
|---|
| 203 | theKaonProcessManager->AddProcess(&theKaonAbsorptionProcess,-1,-1,0);
|
|---|
| 204 | // G4HadronAtRest theHadronAbsorptionProcess;
|
|---|
| 205 | // theKaonProcessManager->AddProcess(&theHadronAbsorptionProcess,-1,-1,0);
|
|---|
| 206 |
|
|---|
| 207 | G4ForceCondition* condition;
|
|---|
| 208 |
|
|---|
| 209 | // ------- set cut and Build CrossSection Tables -------
|
|---|
| 210 | //
|
|---|
| 211 | kaonMinus->SetCuts(1.*mm);
|
|---|
| 212 |
|
|---|
| 213 | // -------- create 1 Dynamic Particle ----
|
|---|
| 214 |
|
|---|
| 215 | G4double kaonEnergy = 0.*MeV;
|
|---|
| 216 | G4ParticleMomentum kaonDirection(0.,0.,1.);
|
|---|
| 217 | G4DynamicParticle aKaonMinus(G4KaonMinus::KaonMinus(),kaonDirection,kaonEnergy);
|
|---|
| 218 |
|
|---|
| 219 | //--------- track definition (for this test ONLY!)------------
|
|---|
| 220 | //
|
|---|
| 221 | G4ThreeVector aPosition(0.,0.,0.);
|
|---|
| 222 | G4double aTime = 0. ;
|
|---|
| 223 |
|
|---|
| 224 | G4Track* ptrack = new G4Track(&aKaonMinus,aTime,aPosition) ;
|
|---|
| 225 | G4Track& aTrack = (*ptrack) ;
|
|---|
| 226 |
|
|---|
| 227 | //ptrack->SetVolume(PhysicalFrame);
|
|---|
| 228 |
|
|---|
| 229 | // do I really need this?
|
|---|
| 230 | G4GRSVolume* touche = new G4GRSVolume(PhysicalFrame, NULL, aPosition);
|
|---|
| 231 | ptrack->SetTouchable(touche);
|
|---|
| 232 |
|
|---|
| 233 | // -------- create 1 Step (for this test only)----
|
|---|
| 234 |
|
|---|
| 235 | G4Step* Step = new G4Step(); G4Step& aStep = (*Step);
|
|---|
| 236 | Step->SetTrack(ptrack);
|
|---|
| 237 |
|
|---|
| 238 | //
|
|---|
| 239 | // --------- check applicability
|
|---|
| 240 | //
|
|---|
| 241 | G4ParticleDefinition* KaonMinusDefinition=aKaonMinus.GetDefinition();
|
|---|
| 242 | if(!theKaonAbsorptionProcess.IsApplicable(*KaonMinusDefinition)) {
|
|---|
| 243 | G4cout
|
|---|
| 244 | << KaonMinusDefinition->GetParticleName()
|
|---|
| 245 | << " is not a KaonMinus!" << G4endl;
|
|---|
| 246 | G4Exception("FAIL: *** exit program ***\n");
|
|---|
| 247 | // return ;
|
|---|
| 248 | }
|
|---|
| 249 | //
|
|---|
| 250 | // --------- Test the DoIt for the Kaon Absorption
|
|---|
| 251 | //
|
|---|
| 252 | G4Material* apttoMaterial ;
|
|---|
| 253 | apttoMaterial = (*theMaterialTable)(imat) ;
|
|---|
| 254 |
|
|---|
| 255 | LogicalFrame->SetMaterial(apttoMaterial);
|
|---|
| 256 | aKaonMinus.SetKineticEnergy(0.*MeV);
|
|---|
| 257 | aKaonMinus.SetMomentumDirection(0., 0., 1.);
|
|---|
| 258 | G4VParticleChange* aParticleChange;
|
|---|
| 259 | G4Track* aFinalParticle;
|
|---|
| 260 | G4String aParticleName;
|
|---|
| 261 |
|
|---|
| 262 | theKaonAbsorptionProcess.SetVerboseLevel(verboseLevel);
|
|---|
| 263 |
|
|---|
| 264 | G4int iteration = 0;
|
|---|
| 265 | do {
|
|---|
| 266 |
|
|---|
| 267 | if(processID==1){
|
|---|
| 268 | aParticleChange = theKaonAbsorptionProcess.AtRestDoIt(aTrack, aStep);
|
|---|
| 269 | } else if(processID==2) {
|
|---|
| 270 | // aParticleChange = theHadronAbsorptionProcess.AtRestDoIt(aTrack, aStep);
|
|---|
| 271 | } else {
|
|---|
| 272 | G4Exception("No such process!\n");
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | // outFile << "! ---------------------------------------------------------------" << G4endl;
|
|---|
| 277 | // outFile << "! Energy deposit = " << aParticleChange->GetLocalEnergyDeposit() << G4endl;
|
|---|
| 278 | //
|
|---|
| 279 | // G4double E = 0., Px = 0., Py = 0., Pz = 0., Edep = 0. ;
|
|---|
| 280 | //
|
|---|
| 281 | // outFile << "! Name Px Py Pz Etot" << G4endl;
|
|---|
| 282 | // outFile << "! ---------------------------------------------------------------" << G4endl
|
|---|
| 283 | // loop over final particle List.
|
|---|
| 284 |
|
|---|
| 285 | G4double e = 0;
|
|---|
| 286 | G4double eKin = 0;
|
|---|
| 287 | G4double Px = 0;
|
|---|
| 288 | G4double Py = 0;
|
|---|
| 289 | G4double Pz = 0;
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | hNSec->accumulate(aParticleChange->GetNumberOfSecondaries());
|
|---|
| 293 | hDebug->accumulate(aParticleChange->GetLocalEnergyDeposit());
|
|---|
| 294 |
|
|---|
| 295 | G4int i;
|
|---|
| 296 | for (i=0; i<(aParticleChange->GetNumberOfSecondaries()); i++)
|
|---|
| 297 | {
|
|---|
| 298 | // The following two items should be filled per event, not
|
|---|
| 299 | // per secondary; filled here just for convenience, to avoid
|
|---|
| 300 | // complicated logic to dump ntuple when there are no secondaries
|
|---|
| 301 | ntuple->column("nsec",aParticleChange->GetNumberOfSecondaries());
|
|---|
| 302 | ntuple->column("deposit",aParticleChange->GetLocalEnergyDeposit());
|
|---|
| 303 |
|
|---|
| 304 | aFinalParticle = aParticleChange->GetSecondary(i) ;
|
|---|
| 305 |
|
|---|
| 306 | e = aFinalParticle->GetTotalEnergy();
|
|---|
| 307 | eKin = aFinalParticle->GetKineticEnergy();
|
|---|
| 308 | Px = (aFinalParticle->GetMomentum()).x() ;
|
|---|
| 309 | Py = (aFinalParticle->GetMomentum()).y() ;
|
|---|
| 310 | Pz = (aFinalParticle->GetMomentum()).z() ;
|
|---|
| 311 |
|
|---|
| 312 | aParticleName = aFinalParticle->GetDefinition()->GetParticleName();
|
|---|
| 313 |
|
|---|
| 314 | hEKin->accumulate(eKin);
|
|---|
| 315 | hP->accumulate(std::sqrt(Px*Px+Py*Py+Pz*Pz));
|
|---|
| 316 |
|
|---|
| 317 | ntuple->column("px", Px);
|
|---|
| 318 | ntuple->column("py", Py);
|
|---|
| 319 | ntuple->column("pz", Pz);
|
|---|
| 320 | ntuple->column("p", std::sqrt(Px*Px+Py*Py+Pz*Pz));
|
|---|
| 321 | ntuple->column("e", e);
|
|---|
| 322 | ntuple->column("ekin", eKin);
|
|---|
| 323 |
|
|---|
| 324 | // MGP ---- Dump the ntuple content at the end of current iteration
|
|---|
| 325 | if (hnt == 1) { ntuple->dumpData(); }
|
|---|
| 326 | delete aParticleChange->GetSecondary(i);
|
|---|
| 327 |
|
|---|
| 328 | // outFile << " " << aParticleName
|
|---|
| 329 | // << " " << Px
|
|---|
| 330 | // << " " << Py
|
|---|
| 331 | // << " " << Pz
|
|---|
| 332 | // << " " << E
|
|---|
| 333 | // << G4endl ;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | aParticleChange->Clear();
|
|---|
| 337 | iteration++;
|
|---|
| 338 | G4cout << "******* Iteration = " << iteration << G4endl;
|
|---|
| 339 |
|
|---|
| 340 | } while (iteration < niter) ;
|
|---|
| 341 |
|
|---|
| 342 | hbookManager->write();
|
|---|
| 343 |
|
|---|
| 344 | delete aFinalParticle;
|
|---|
| 345 |
|
|---|
| 346 | // delete materials and elements
|
|---|
| 347 | delete Al;
|
|---|
| 348 | delete Fe;
|
|---|
| 349 | delete Pb;
|
|---|
| 350 | delete Graphite;
|
|---|
| 351 | delete H;
|
|---|
| 352 | delete O;
|
|---|
| 353 | delete C;
|
|---|
| 354 | delete Cs;
|
|---|
| 355 | delete I;
|
|---|
| 356 | delete water;
|
|---|
| 357 | delete ethane;
|
|---|
| 358 | delete csi;
|
|---|
| 359 |
|
|---|
| 360 | return EXIT_SUCCESS;
|
|---|
| 361 | }
|
|---|