Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

MaGeDecay0Interface.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * DISCLAIMER                                                       *
00004 // *                                                                  *
00005 // * Neither the authors of this software system, nor their employing *
00006 // * institutes,nor the agencies providing financial support for this *
00007 // * work  make  any representation or  warranty, express or implied, *
00008 // * regarding  this  software system or assume any liability for its *
00009 // * use.                                                             *
00010 // *                                                                  *
00011 // ********************************************************************
00012 // History:
00013 // --------
00014 // 25 Oct 2004   L.Pandola    First implementation
00015 // 04 Nov 2004   L.Pandola    Change: not necessary to give immediately the file name
00016 
00017 #include "generators/MaGeDecay0Interface.hh"
00018 #include "io/MJLogger.hh"
00019 #include "G4Event.hh"
00020 #include "G4PrimaryVertex.hh"
00021 #include "G4PrimaryParticle.hh"
00022 #include "generators/MaGeDecay0InterfaceMessenger.hh"
00023 #include "G4ThreeVector.hh"
00024 #include "G4ParticleTable.hh"
00025 #include <string.h>
00026 
00027 MaGeDecay0Interface::MaGeDecay0Interface(G4String File) :
00028   fFileName(File)
00029 {
00030   fTheMessenger = new MaGeDecay0InterfaceMessenger(this);
00031 
00032   G4ThreeVector zero;
00033   particle_position =  zero;
00034   particle_time = 0.0;
00035 }
00036 
00037 MaGeDecay0Interface::~MaGeDecay0Interface()
00038 {
00039   delete fTheMessenger;
00040   if (fInputFile.is_open()) fInputFile.close();
00041 }
00042 
00043 void MaGeDecay0Interface::OpenFile()
00044 {
00045   char header[160];
00046   fInputFile.open(fFileName);
00047 
00048   if (!(fInputFile.is_open())) {//not open correctly
00049     MJLog(error) << "File not valid!" << endlog;
00050     MJLog(fatal) << endlog;
00051   }
00052   G4int ifound;
00053   MJLog(debugging) << "Decay0 file " << fFileName << " found" << endlog;
00054   //Here one has to read the header
00055   //Problem: the header has not always the same lenght
00056   for (G4int j=0;;j++)
00057     {
00058       fInputFile.getline(header,160);
00059       ifound = strncmp (header," First",6);
00060       if (!ifound) break;
00061       if (j == 50) {
00062         MJLog(error) << "Corrupted file? " << endlog;
00063         MJLog(fatal) << endlog;
00064       }
00065     }
00066   //here one has 2 more lines to skip
00067   fInputFile.getline(header,160);
00068   fInputFile.getline(header,160);
00069   MJLog(trace) << "Decay0 file " << fFileName << " initialized" << endlog;
00070 }
00071 
00072 void MaGeDecay0Interface::ChangeFileName(G4String newFile)
00073 {
00074    if (fFileName != newFile) //check if the new file is equal to the other
00075     {
00076       if (fInputFile.is_open()) fInputFile.close(); //close the old file
00077       fFileName = newFile; 
00078       OpenFile(); //open the new one
00079     }
00080 }
00081 
00082 void MaGeDecay0Interface::GeneratePrimaryVertex(G4Event* evt)
00083 {
00084   if (!(fInputFile.is_open())) {
00085     MJLog(error) << "File must be set!" << endlog;
00086     MJLog(fatal) << endlog;
00087   }
00088   G4int nEntries=0;
00089   G4int nEvent=0;
00090   G4double time=0.0;
00091   G4String particleName;
00092   G4double px,py,pz,relativeTime;
00093   G4int particleCode;
00094 
00095   fInputFile >> nEvent >> time >> nEntries;
00096  
00097   if (fInputFile.eof())
00098     {
00099       fInputFile.close();
00100       MJLog(error) << "File over: not enough events!" << endlog;
00101       MJLog(fatal) << endlog;
00102       return;
00103     }
00104   
00105   
00106   particle_time = time*s;
00107 
00108   G4PrimaryVertex* vertex = new G4PrimaryVertex (particle_position,
00109                                                  particle_time);
00110 
00111   G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
00112 
00113   for (G4int i=0;i<nEntries;i++) //loop of the number of particles per event
00114     {
00115       fInputFile >> particleCode >> px >> py >> pz >> relativeTime;
00116       
00117       particleName = ConvertCodeToName(particleCode);
00118      
00119       //Create primary particle
00120       G4PrimaryParticle* particle = 
00121         new G4PrimaryParticle(theParticleTable->FindParticle(particleName),
00122                               px*MeV,py*MeV,pz*MeV);
00123      
00124       particle->SetProperTime(relativeTime*s+particle_time); 
00125 
00126       //Add particle to vertex
00127       vertex->SetPrimary(particle);
00128     }
00129 
00130   evt->AddPrimaryVertex(vertex);
00131 }
00132 
00133 G4String MaGeDecay0Interface::ConvertCodeToName(G4int code)
00134 {
00135   if (code == 1)
00136     return "gamma";
00137   else if (code == 2)
00138     return "e+";
00139   else if (code == 3)
00140     return "e-";
00141   else if (code == 47)
00142     return "alpha";
00143   else 
00144     MJLog(error) << "Unknown particle code" << endlog;
00145   return " ";
00146 }
00147       
00148  

Generated on Mon Nov 29 16:58:50 2004 for Majorana Simulation by  doxygen 1.3.9.1