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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 7.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
                                                   >>  23 // $Id: FCALPrimaryGeneratorAction.cc,v 1.6 2004/11/29 18:03:06 ribon Exp $
                                                   >>  24 // GEANT4 tag $Name: geant4-07-00-patch-01 $
 26 //                                                 25 //
 27 //                                                 26 // 
 28                                                    27 
 29 //....oooOO0OOooo........oooOO0OOooo........oo     28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 30 //....oooOO0OOooo........oooOO0OOooo........oo     29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 31                                                    30 
 32 #include <fstream>                             << 
 33 #include <cstdlib>                             << 
 34                                                << 
 35 #include "FCALPrimaryGeneratorAction.hh"           31 #include "FCALPrimaryGeneratorAction.hh"
 36                                                    32 
 37 #include "G4SystemOfUnits.hh"                  <<  33 
 38 #include "G4Event.hh"                              34 #include "G4Event.hh"
 39 #include "G4ParticleGun.hh"                        35 #include "G4ParticleGun.hh"
 40 #include "G4ParticleTable.hh"                      36 #include "G4ParticleTable.hh"
 41 #include "G4ParticleDefinition.hh"                 37 #include "G4ParticleDefinition.hh"
 42 #include "Randomize.hh"                            38 #include "Randomize.hh"
 43 #include "G4DataVector.hh"                     << 
 44 #include "G4AutoLock.hh"                       << 
 45                                                    39 
                                                   >>  40 #include "fstream.h"
                                                   >>  41 #include "stdlib.h"
 46 //....oooOO0OOooo........oooOO0OOooo........oo     42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 47                                                    43 
                                                   >>  44 FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction()
                                                   >>  45 {
                                                   >>  46   X = new G4double[5001];
                                                   >>  47   Y = new G4double[5001];
                                                   >>  48   Z = new G4double[5001];
                                                   >>  49   Cos_X = new G4double[5001];
                                                   >>  50   Cos_Y = new G4double[5001];
                                                   >>  51   Cos_Z = new G4double[5001];
 48                                                    52 
 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                                                << 
121 //....oooOO0OOooo........oooOO0OOooo........oo << 
122                                                    53 
123 FCALPrimaryGeneratorAction::FCALPrimaryGenerat <<  54   G4int Nparticles = 1;
124   fVerbosity(0)                                <<  55   particleGun  = new G4ParticleGun(Nparticles);
125 {                                              << 
126   particleGun  = new G4ParticleGun();          << 
127                                                    56 
128   // default Particle                              57   // default Particle
129   G4String particleName;                           58   G4String particleName;
130   G4ParticleTable* particleTable = G4ParticleT     59   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();  
131   G4ParticleDefinition* particle = particleTab <<  60   G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e+");
132   particleGun->SetParticleDefinition(particle)     61   particleGun->SetParticleDefinition(particle);
                                                   >>  62  
133                                                    63 
134   // default Energy                                64   // default Energy
135   particleGun->SetParticleEnergy(20*GeV);      <<  65   particleGun->SetParticleEnergy(80*GeV);
136 }                                              <<  66 
                                                   >>  67   // Read Kinematics from file
                                                   >>  68   G4int InEvent = 0;
                                                   >>  69   G4String file_name = "data-tracks/tracks-80GeV.dat";
                                                   >>  70   ifstream Traks_file(file_name);
                                                   >>  71   if(!Traks_file) G4cerr << "WARNING:  Failed to open file " << file_name << G4endl;
                                                   >>  72   Traks_file.seekg(0);
                                                   >>  73   
                                                   >>  74   while(!(Traks_file.eof())) {
                                                   >>  75     InEvent++;
                                                   >>  76     Traks_file >> Ievent >> X[InEvent] >> Y[InEvent] >> Z[InEvent] 
                                                   >>  77    >> Cos_X[InEvent] >> Cos_Y[InEvent] >> Cos_Z[InEvent];
                                                   >>  78   };   
                                                   >>  79 
                                                   >>  80   Nevent = 2500;
                                                   >>  81 };
                                                   >>  82 
137                                                    83 
138 //....oooOO0OOooo........oooOO0OOooo........oo     84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
139                                                    85 
140 FCALPrimaryGeneratorAction::~FCALPrimaryGenera     86 FCALPrimaryGeneratorAction::~FCALPrimaryGeneratorAction()
141 {                                                  87 {
142   delete particleGun;                              88   delete particleGun;
                                                   >>  89   delete [] X; 
                                                   >>  90   delete [] Y;
                                                   >>  91   delete [] Z;
                                                   >>  92   delete [] Cos_X;
                                                   >>  93   delete [] Cos_Y;
                                                   >>  94   delete [] Cos_Z;
                                                   >>  95 
143 }                                                  96 }
144                                                    97 
145 //....oooOO0OOooo........oooOO0OOooo........oo     98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
146                                                    99 
147 void FCALPrimaryGeneratorAction::GeneratePrima    100 void FCALPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
148 {                                                 101 {
149   //this function is called at the begining of << 102        //this function is called at the begining of event
150   ReadKinematicFromFile(particleGun->GetPartic << 103 
151                                                << 104   Nevent++;
152     //Get next event to be processed           << 105   
153     size_t nEvent = GetNextId();               << 106   particleGun->SetParticlePosition(G4ThreeVector(X[Nevent]*cm,Y[Nevent]*cm,Z[Nevent]*cm));
154     particleGun->SetParticlePosition(G4ThreeVe << 107   particleGun->SetParticleMomentumDirection(G4ThreeVector(-Cos_X[Nevent],Cos_Y[Nevent],-Cos_Z[Nevent]));
155   particleGun->SetParticleMomentumDirection(G4 << 108   
156                 fCosY[nEvent],                 << 
157                 -1.0*fCosZ[nEvent]));          << 
158                                                   109 
159   particleGun->GeneratePrimaryVertex(anEvent);    110   particleGun->GeneratePrimaryVertex(anEvent);
160                                                   111 
161   if (fVerbosity)                              << 112   G4cout << "--------------------------------------------" << G4endl;
162     {                                          << 113   G4cout << " Event,  X,Y,Z Generated Vertex : " << G4endl;
163         G4cout<< " Event  "<<anEvent->GetEvent << 114   G4cout << Nevent << " " << X[Nevent] << " " << Y[Nevent] << " " << Z[Nevent]<< G4endl;
164             <<anEvent->GetEventID() <<" (x,y,z << 115   G4cout << "--------------------------------------------" << G4endl;
165             <<fY[nEvent] << "," << fZ[nEvent]< << 116  
166             << -1.*fCosX[nEvent] << "," << fCo << 
167             <<"," << -1.*fCosZ[nEvent] << ")"< << 
168     }                                          << 
169                                                   117 
170 }                                                 118 }
171                                                   119 
172 //....oooOO0OOooo........oooOO0OOooo........oo    120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
173                                                   121 
174                                                   122 
175                                                   123