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.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/lAr_calorimeter/src/FCALPrimaryGeneratorAction.cc (Version 11.3.0) and /examples/advanced/lAr_calorimeter/src/FCALPrimaryGeneratorAction.cc (Version 8.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: FCALPrimaryGeneratorAction.cc,v 1.8 2006/06/29 16:03:10 gunter Exp $
                                                   >>  27 // GEANT4 tag $Name: geant4-08-01 $
 26 //                                                 28 //
 27 //                                                 29 // 
 28                                                    30 
 29 //....oooOO0OOooo........oooOO0OOooo........oo     31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 30 //....oooOO0OOooo........oooOO0OOooo........oo     32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 31                                                    33 
 32 #include <fstream>                             << 
 33 #include <cstdlib>                             << 
 34                                                << 
 35 #include "FCALPrimaryGeneratorAction.hh"           34 #include "FCALPrimaryGeneratorAction.hh"
 36                                                    35 
 37 #include "G4SystemOfUnits.hh"                  <<  36 
 38 #include "G4Event.hh"                              37 #include "G4Event.hh"
 39 #include "G4ParticleGun.hh"                        38 #include "G4ParticleGun.hh"
 40 #include "G4ParticleTable.hh"                      39 #include "G4ParticleTable.hh"
 41 #include "G4ParticleDefinition.hh"                 40 #include "G4ParticleDefinition.hh"
 42 #include "Randomize.hh"                            41 #include "Randomize.hh"
 43 #include "G4DataVector.hh"                     << 
 44 #include "G4AutoLock.hh"                       << 
 45                                                    42 
                                                   >>  43 #include <fstream>
                                                   >>  44 #include <cstdlib>
 46 //....oooOO0OOooo........oooOO0OOooo........oo     45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 47                                                    46 
                                                   >>  47 FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction()
                                                   >>  48 {
                                                   >>  49   X = new G4double[5001];
                                                   >>  50   Y = new G4double[5001];
                                                   >>  51   Z = new G4double[5001];
                                                   >>  52   Cos_X = new G4double[5001];
                                                   >>  53   Cos_Y = new G4double[5001];
                                                   >>  54   Cos_Z = new G4double[5001];
 48                                                    55 
 49 // Migration to MT: there is a single input fi << 
 50 // The idea is that the events are read by a s << 
 51 // by all threads. Threads ask for the next ID << 
 52 // events are all processed we start over from << 
 53 namespace {                                    << 
 54     G4bool isFileRead = false;                 << 
 55     G4Mutex mFileRead = G4MUTEX_INITIALIZER;   << 
 56     //Primary kinematics                       << 
 57     G4DataVector fX;                           << 
 58     G4DataVector fY;                           << 
 59     G4DataVector fZ;                           << 
 60     G4DataVector fCosX;                        << 
 61     G4DataVector fCosY;                        << 
 62     G4DataVector fCosZ;                        << 
 63     size_t nextEventId = 0;                    << 
 64     G4Mutex mNextEventId = G4MUTEX_INITIALIZER << 
 65                                                << 
 66     size_t GetNextId() {                       << 
 67         G4AutoLock l(&mNextEventId);           << 
 68         if ( nextEventId >= fX.size() ) //file << 
 69             {                                  << 
 70                 G4Exception("FCALPrimaryGenera << 
 71                             JustWarning,"Data  << 
 72                 nextEventId=0;                 << 
 73             }                                  << 
 74         return nextEventId++;                  << 
 75     }                                          << 
 76                                                << 
 77     void ReadKinematicFromFile(G4double energy << 
 78         //Only one thread shoud read input fil << 
 79         G4AutoLock l(&mFileRead);              << 
 80         if ( isFileRead ) return;              << 
 81         // Read Kinematics from file           << 
 82         G4String file_name = "data-tracks/trac << 
 83         if (energy < 30*GeV)                   << 
 84             file_name = "data-tracks/tracks-20 << 
 85         else if (energy < 50*GeV)              << 
 86             file_name = "data-tracks/tracks-40 << 
 87         else if (energy < 70*GeV)              << 
 88             file_name = "data-tracks/tracks-60 << 
 89         else if (energy < 90*GeV)              << 
 90             file_name = "data-tracks/tracks-80 << 
 91         else if (energy < 150*GeV)             << 
 92             file_name = "data-tracks/tracks-12 << 
 93         else                                   << 
 94             file_name = "data-tracks/tracks-20 << 
 95         std::ifstream Traks_file(file_name);   << 
 96         if(!Traks_file)                        << 
 97         {                                      << 
 98             G4ExceptionDescription ed;         << 
 99             ed << "Failed to open file " << fi << 
100             G4Exception("FCALPrimaryGeneratorA << 
101                         "lAr001",FatalExceptio << 
102         }                                      << 
103         G4double xx=0,yy=0,zz=0,c1=0,c2=0,c3=0 << 
104         G4int iev = 0;                         << 
105         while(!(Traks_file.eof())) {           << 
106             Traks_file >> iev >> xx >> yy >> z << 
107             fX.push_back(xx*cm);               << 
108             fY.push_back(yy*cm);               << 
109             fZ.push_back(zz*cm);               << 
110             fCosX.push_back(c1);               << 
111             fCosY.push_back(c2);               << 
112             fCosZ.push_back(c3);               << 
113         }                                      << 
114         G4cout << "Read " << fX.size() << " ev << 
115         isFileRead= true;                      << 
116         Traks_file.close();                    << 
117         return;                                << 
118     }                                          << 
119 }                                              << 
120                                                    56 
121 //....oooOO0OOooo........oooOO0OOooo........oo <<  57   G4int Nparticles = 1;
122                                                <<  58   particleGun  = new G4ParticleGun(Nparticles);
123 FCALPrimaryGeneratorAction::FCALPrimaryGenerat << 
124   fVerbosity(0)                                << 
125 {                                              << 
126   particleGun  = new G4ParticleGun();          << 
127                                                    59 
128   // default Particle                              60   // default Particle
129   G4String particleName;                           61   G4String particleName;
130   G4ParticleTable* particleTable = G4ParticleT     62   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();  
131   G4ParticleDefinition* particle = particleTab <<  63   G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e+");
132   particleGun->SetParticleDefinition(particle)     64   particleGun->SetParticleDefinition(particle);
                                                   >>  65  
133                                                    66 
134   // default Energy                                67   // default Energy
135   particleGun->SetParticleEnergy(20*GeV);      <<  68   particleGun->SetParticleEnergy(80*GeV);
136 }                                              <<  69 
                                                   >>  70   // Read Kinematics from file
                                                   >>  71   G4int InEvent = 0;
                                                   >>  72   G4String file_name = "data-tracks/tracks-80GeV.dat";
                                                   >>  73   std::ifstream Traks_file(file_name);
                                                   >>  74   if(!Traks_file) G4cerr << "WARNING:  Failed to open file " << file_name << G4endl;
                                                   >>  75   Traks_file.seekg(0);
                                                   >>  76   
                                                   >>  77   while(!(Traks_file.eof())) {
                                                   >>  78     InEvent++;
                                                   >>  79     Traks_file >> Ievent >> X[InEvent] >> Y[InEvent] >> Z[InEvent] 
                                                   >>  80    >> Cos_X[InEvent] >> Cos_Y[InEvent] >> Cos_Z[InEvent];
                                                   >>  81   };   
                                                   >>  82 
                                                   >>  83   Nevent = 2500;
                                                   >>  84 };
                                                   >>  85 
137                                                    86 
138 //....oooOO0OOooo........oooOO0OOooo........oo     87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
139                                                    88 
140 FCALPrimaryGeneratorAction::~FCALPrimaryGenera     89 FCALPrimaryGeneratorAction::~FCALPrimaryGeneratorAction()
141 {                                                  90 {
142   delete particleGun;                              91   delete particleGun;
                                                   >>  92   delete [] X; 
                                                   >>  93   delete [] Y;
                                                   >>  94   delete [] Z;
                                                   >>  95   delete [] Cos_X;
                                                   >>  96   delete [] Cos_Y;
                                                   >>  97   delete [] Cos_Z;
                                                   >>  98 
143 }                                                  99 }
144                                                   100 
145 //....oooOO0OOooo........oooOO0OOooo........oo    101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
146                                                   102 
147 void FCALPrimaryGeneratorAction::GeneratePrima    103 void FCALPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
148 {                                                 104 {
149   //this function is called at the begining of << 105        //this function is called at the begining of event
150   ReadKinematicFromFile(particleGun->GetPartic << 106 
151                                                << 107   Nevent++;
152     //Get next event to be processed           << 108   
153     size_t nEvent = GetNextId();               << 109   particleGun->SetParticlePosition(G4ThreeVector(X[Nevent]*cm,Y[Nevent]*cm,Z[Nevent]*cm));
154     particleGun->SetParticlePosition(G4ThreeVe << 110   particleGun->SetParticleMomentumDirection(G4ThreeVector(-Cos_X[Nevent],Cos_Y[Nevent],-Cos_Z[Nevent]));
155   particleGun->SetParticleMomentumDirection(G4 << 111   
156                 fCosY[nEvent],                 << 
157                 -1.0*fCosZ[nEvent]));          << 
158                                                   112 
159   particleGun->GeneratePrimaryVertex(anEvent);    113   particleGun->GeneratePrimaryVertex(anEvent);
160                                                   114 
161   if (fVerbosity)                              << 115   G4cout << "--------------------------------------------" << G4endl;
162     {                                          << 116   G4cout << " Event,  X,Y,Z Generated Vertex : " << G4endl;
163         G4cout<< " Event  "<<anEvent->GetEvent << 117   G4cout << Nevent << " " << X[Nevent] << " " << Y[Nevent] << " " << Z[Nevent]<< G4endl;
164             <<anEvent->GetEventID() <<" (x,y,z << 118   G4cout << "--------------------------------------------" << G4endl;
165             <<fY[nEvent] << "," << fZ[nEvent]< << 119  
166             << -1.*fCosX[nEvent] << "," << fCo << 
167             <<"," << -1.*fCosZ[nEvent] << ")"< << 
168     }                                          << 
169                                                   120 
170 }                                                 121 }
171                                                   122 
172 //....oooOO0OOooo........oooOO0OOooo........oo    123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
173                                                   124 
174                                                   125 
175                                                   126