Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

shower.cxx

Go to the documentation of this file.
00001 // Simple test of showering
00002 //
00003 //  Try to contain a gamma ray in a very large medium
00004 // $Id: shower.cxx,v 1.1 2000/09/01 20:25:16 burnett Exp $
00005 #include "BaseApp.h"
00006 #include "SlabWorld.h"
00007 #include "SmplStat.h"
00008 
00009 #include "gismo/Interactor.h"
00010 #include "geometry/Box.h"
00011 #include "gismo/EGSInteractor.h"
00012 #include "gismo/GheishaInteractor.h"
00013 
00014 #  include <iomanip>
00015 
00016 #ifdef _MSC_VER
00017   using namespace std;
00018 #endif
00019 
00020 const char*     particleName=   "gamma";
00021 const char*     materialName=   "Pb";
00022 unsigned long   numberOfEvents= 10;  // default number of events
00023 float           pBeam =         2.0f; //2.0;  // initial momentem
00024 float           cut   =         0.00001f; //2.0;  // k.e. cutOff
00025 float           thick =         10000.0f;  // thickness of slab
00026 
00027 SampleStatistic energyStat;
00028 
00029 void WARNING(const char * text)
00030 {  cerr << "WARNING: " << text << '\n';}
00031 void FATAL(const char * text){
00032    cerr << "FATAL error: " <<text << '\n';
00033    cerr << "use parameter \"help\" for instructions\n";
00034    exit(-1);}
00035 
00036 const char* help=
00037 "Help for the test program shower:\n\n"
00038 "   shower [[[[particleName] materialName] eventCount] pBeam]keCutOff]\n\n"
00039 "where:\n"
00040 "   particleName [default gamma] is the name of a particle to interact:\n"
00041 "                 (\"decay list\" for a list)\n"
00042 "   materialName [Al] the name of a PEGS4 material file, e.g. Al.mat\n"
00043 "   eventCount [10] number of events to generate\n"
00044 "   pBeam      [2.0 GeV] the beam momentum\n"
00045 "   keCutOff   [.00001 GeV] the kinetic energy cutoff\n";
00046 
00047 class ShowerDetector : public Detector
00048 {
00049 public:
00050  ShowerDetector():Detector(){}
00051  void score(MCParticle*);
00052  void clear(){e_dedx = 0; e_gamma = 0; e_nucl = 0; e_neutr = 0; e_stop=0;}
00053  static int   evtNum;   // event counter
00054  static float e_dedx;   // de/dx energy deposited
00055  static float e_gamma;  // gamma energy (interacted or stopped)
00056  static float e_nucl;   // nuclear energy (interacted)
00057  static float e_neutr;  // neutrino energy (not rejestered)
00058  static float e_stop;   // stopped particle energy (not rejestered)
00059 private:
00060  int mult;     // count no of hits in this event
00061 
00062 };
00063 int   ShowerDetector::evtNum = 0;
00064 float ShowerDetector::e_dedx=0;
00065 float ShowerDetector::e_gamma=0;
00066 float ShowerDetector::e_nucl=0;
00067 float ShowerDetector::e_neutr=0;
00068 float ShowerDetector::e_stop=0;
00069 
00070 #include "gismo/PDT.h"
00071 void ShowerDetector::score( MCParticle *p)
00072 {
00073     static long gammaId = -1;
00074     static long eplusId, eminusId, pId, nId, deutrId, tritnId, alphaId, nueId, numId;
00075 
00076     if(gammaId == -1) {
00077        PDT *thePDT = GParticle::thePDT();
00078        gammaId = (thePDT->lookUp("gamma"))->idCode();
00079        eplusId = (thePDT->lookUp("e+"))->idCode();
00080        eminusId= (thePDT->lookUp("e-"))->idCode();
00081        nueId   = (thePDT->lookUp("nu_e"))->idCode();
00082        numId   = (thePDT->lookUp("nu_mu"))->idCode();
00083        pId =     (thePDT->lookUp("p"))->idCode();
00084        nId =     (thePDT->lookUp("n"))->idCode();
00085        deutrId = (thePDT->lookUp("deutron"))->idCode();
00086        tritnId = (thePDT->lookUp("triton"))->idCode();
00087        alphaId = (thePDT->lookUp("alpha"))->idCode();
00088    }
00089    long trackId = p->idCode();
00090    float eLoss = 0.;
00091    int numProd = p->numChildren();
00092 
00093 // Get the energy loss due neutrino's which leave
00094   if(trackId == nueId || trackId == numId) {
00095       e_neutr += p->e();
00096       return;
00097    }
00098 
00099 // Get the energy loss due to ionization (dE/dX).
00100    if( p->charge())  e_dedx += p->energyLoss();
00101 
00102 // Get the energy loss due to stopped particles (mostly masses)
00103    if(p->status() == MCParticle::STOPPED) {
00104       if(trackId == nId )  e_stop += p->e() - p->mass();
00105       else if(trackId != pId      && trackId != deutrId &&
00106               trackId != tritnId  && trackId != alphaId &&
00107               trackId != eminusId && trackId != eplusId)
00108               e_stop += p->e();
00109    }
00110 // Get the energy loss due to gamma's which  stop via photo-electric.
00111    if(trackId == gammaId) {
00112         if(p->status() == MCParticle::INTERACTED && numProd == 1) {
00113            GParticle *kid = p->child(0);
00114            e_gamma += p->e() - (kid->e() - kid->mass());
00115       }
00116    }
00117 
00118 
00119 // If its a interacting hadron correct for nuclear fragments. The correction is
00120 // done by adding the kinetic energy of the incomming paritcle to the energy loss
00121 // and then subtracting the energy (or kinetic energy in the case of p or n) of all
00122 // daughters recognized by gismo.
00123 // NOTE: remove this code whennuclear fragmenets are tracked by gismo
00124 // Deutrons, tritons, and alphas now tracked... wba 15-june-95
00125 
00126     if(trackId != eplusId && trackId != eminusId && trackId != gammaId
00127        && p->status() == MCParticle::INTERACTED) { // Must be hadronic
00128 
00129          if(trackId == pId     || trackId == nId     ||
00130             trackId == deutrId || trackId == tritnId ||
00131             trackId == alphaId )                 e_nucl += p->e() - p->mass();
00132          else                                    e_nucl += p->e();
00133 
00134       for(int i=0; i<numProd; i++) {
00135          GParticle *prod = p->child(i);
00136          if(!prod) break;
00137 
00138          long prodId = prod->idCode();
00139          if(prodId == pId     || prodId == nId     ||
00140             prodId == deutrId || prodId == tritnId ||
00141             prodId == alphaId )   e_nucl -= prod->e() - prod->mass();
00142          else                     e_nucl -= prod->e();
00143        }
00144      }
00145    return;
00146   }
00147 //-------------------------------------------------------
00148 
00149 
00150 class ShowerTest :  public BaseApp
00151 {
00152   public:
00153    void endEvent();  // override virtual base class
00154    void init(ostream& =cout);
00155    void last(ostream& = cout);
00156 
00157 };
00158 
00159 void ShowerTest::init(ostream& cout)
00160 {
00161         Material::addPath("../PEGS4:.");
00162 
00163 
00164         // start the particle in the middle of the layer
00165         setBeam(particleName, Vector(0,0,pBeam), Point(0,0,thick/2));
00166 
00167         // define the geometry
00168         SlabWorld* w = new SlabWorld;
00169         setWorld(w);
00170         w->addSlab(thick,materialName,new ShowerDetector());
00171 
00172 
00173         // create particle and medium just to print out parameters
00174         MCParticle p(particleName);
00175         p.setMomentum(Vector(0,0,pBeam));
00176         Medium med(0,new Box(1,1,1),materialName);
00177         Material& mat = med.material();
00178 
00179 
00180         cout << "\tGismo Showering test\n";
00181         cout << "particle: " << particleName
00182              << "\n     momentum\t" << p.pTot() << " GeV "
00183              << "\n            E\t" << p.e() << " GeV"
00184              << "\n           KE\t" << p.e()-p.mass() << " GeV"
00185              ;
00186         Material::printAll(cout);
00187         cout << "\nmaterial: " << materialName
00188              << "\n   Rad length\t" << mat.radiationLength() << '\n'
00189              ;
00190         Interactor& itr = *p.interactor();
00191         float ecutMin = itr.ecut(&p,&med) - p.mass();
00192         if(med.kECutOff() > ecutMin) ecutMin = med.kECutOff();
00193         cout << "Interactions performed by the class \"" << itr.className() <<'"'
00194              << "\n   Int length\t" << itr.interactionLength(&p,&med) << " cm"
00195              << "\n      maxStep\t" << itr.maxStepSize(&p,&med) << " cm"
00196              << "\n   k.e.cutOff\t" << ecutMin << " GeV"
00197              ;
00198 
00199         cout << "\n\nbegin run for "<< numberOfEvents<< " events "<< '\n';
00200         cout << "\n\n\t\t Energy Audit Table \n";
00201         cout << "Evt.No.  \tdE/dX   \tGamma   \tNeutrino   \tNuclear   \tStopped  \tTotal \n";
00202 }
00203 void ShowerTest::endEvent()
00204 {
00205     ShowerDetector::evtNum++;
00206 
00207     float e_tot = ShowerDetector::e_dedx  + ShowerDetector::e_gamma +
00208                   ShowerDetector::e_neutr + ShowerDetector::e_nucl  +
00209                   ShowerDetector::e_stop;
00210 
00211     energyStat += e_tot;
00212     int old_flags = cout.flags(ios::fixed);
00213     int old_precision = cout.precision(3);
00214     cout << setw(5) << ShowerDetector::evtNum
00215          << setw(16) << ShowerDetector::e_dedx
00216          << setw(16) << ShowerDetector::e_gamma
00217          << setw(16) << ShowerDetector::e_neutr
00218          << setw(16) << ShowerDetector::e_nucl
00219          << setw(16) << ShowerDetector::e_stop
00220          << setw(16) << e_tot << endl;
00221     cout.flush();
00222     cout.flags(old_flags);
00223     cout.precision(old_precision);
00224 
00225 }
00226 void ShowerTest::last(ostream& cout)
00227 {
00228    if( energyStat.samples()>0)
00229    {
00230         cout << "\nenergy: \tmean = "<< energyStat.mean() << '\n'
00231              <<       "\t\trms  = "<< energyStat.stdDev()
00232              <<'\n';
00233         cout.flush();
00234    }
00235 }
00236 
00237 
00238 int main(int argc, char* argv[])
00239 {
00240 
00241         if( argc>1 ) particleName = argv[1];
00242         if( strcmp(particleName, "help")==0 ) {cout << help; return 0;}
00243         if( argc>2 ) materialName = argv[2];
00244         if( argc>3 ) numberOfEvents = atoi(argv[3]);
00245         if( argc>4 ) pBeam = atof(argv[4]);
00246         if( argc>5 ) cut = atof(argv[5]);
00247 
00248   ShowerTest tester;
00249   tester.addInteractor(new EGSInteractor("electromagnetic") );
00250 #ifndef NOGHEISHA
00251   tester.addInteractor(new GheishaInteractor("hadronic") );
00252 #endif
00253   tester.init();
00254   tester.world().setKECutOff(cut);
00255 
00256   tester.run(numberOfEvents);
00257   tester.last();
00258 
00259 
00260   return 0;
00261 }
00262 
00263 

Generated at Mon Nov 26 18:18:34 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000