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

HepEvt.cxx

Go to the documentation of this file.
00001 // -*- C++ -*-  $Id: HepEvt.cxx,v 1.1.1.1 1999/12/20 22:28:41 burnett Exp $
00002 //
00003 // This file is part of Gismo 2
00004 // inmplement HepEvt class
00005 #include "gismo/HepEvt.h"
00006 #include "facilities/error.h"
00007 #include "gismo/Units.h"
00008 #include "gismo/PDT.h"
00009 
00010 #include <vector>
00011 #include <string.h>
00012 #include <stdio.h>
00013 #include <assert.h>
00014 
00015 static char line[133];
00016 
00017 
00018 HepEvt::HepEvt(std::istream & in)
00019 : Generator() // make a default something
00020 , inputFile(in)
00021 {
00022         if( !in || in.bad() )
00023                  FATAL("HepEvt: input file not open!");
00024         _hasVertices=false;
00025         for(;;)
00026         {
00027                 in.getline(line,sizeof(line)-1);
00028                 if(in.eof()){ nevhep()=-1; break;}
00029                 if( strstr(line,"Event listing (HEP format"))
00030                 {
00031                         nevhep()=0;
00032                         if( strstr(line, " with vertices"))
00033                            _hasVertices = true;
00034                         break;
00035                 }
00036         }
00037         // readEvent();
00038         if( in.eof() )
00039                 WARNING("HepEvt: no event data found!");
00040 
00041 }
00042 
00043 /*   start of record to decode:
00044                                                 Event listing (HEP format with vertices)            Event:        1
00045          I  particle/jet     ISTHEP  IDHEP     JMOHEP      JDAHEP    PHEP(1,I)   PHEP(2,I)   PHEP(3,I)   PHEP(4,I)   PHEP(5,I)
00046                                                                                                                                                                           VHEP(1,I)   VHEP(2,I)   VHEP(3,I)   VHEP(4,I)
00047 
00048          1  (upsilon(4S))         2  70553     0     0     2     3      .00000      .00000     5.90889    12.11822    10.58000
00049                                                                                                                                                                                 .000        .000        .000        .000
00050 */
00051 int
00052  HepEvt::readEvent()
00053 {
00054         char line[140];
00055         nhep() = 0;
00056         int i;
00057         for(;;)  // read forward until find line starting with  1
00058         {
00059                 inputFile.getline(line,sizeof(line)-1);
00060                 if( inputFile.eof() )
00061                         return 1;
00062                 if( strlen(line)==0 ) continue;
00063                 if( (i =atoi(line)) ==1 ) break;
00064         }
00065         // found event: now fill the Fortran common block
00066         char name[20];
00067         for(;atoi(line)>0;i++)
00068         {  int index;
00069 
00070                 sscanf(line,"%d %s %D %D %D %D %D %D %g %g %g %g %g",
00071                                 &index, &name, &isthep(i), &idhep(i),
00072                                 jmohep(i),jmohep(i)+1, jdahep(i), jdahep(i)+1,
00073                                 phep(i), phep(i)+1, phep(i)+2, phep(i)+3,  phep(i)+4);
00074                 if( index!=i )
00075                         FATAL("Bad input data for HepEvt ");
00076 
00077                 if( _hasVertices){
00078                   inputFile.getline(line,sizeof(line)-1);
00079                   sscanf(line,"%g %g %g %g", vhep(i),vhep(i)+1, vhep(i)+2, vhep(i)+3);
00080                 }else{
00081                   vhep(i)[0]=vhep(i)[1]=vhep(i)[2]=vhep(i)[3];
00082                 }
00083 
00084                 inputFile.getline(line,sizeof(line)-1);
00085 
00086                 // add the particle to the PDT, if not there
00087                 PData* data = thePDT()->lookUp(idhep(i));
00088                 if( !data )
00089                 {
00090                   float mass = phep(i)[4];
00091                   char* pname=name;
00092                   if( name[0]=='(' && strlen(name)>0)
00093                   {
00094                           name[strlen(name)-1]='\0';
00095                           pname++;
00096                   }
00097                   thePDT()->addParticle(pname, idhep(i), 99, 99, mass );
00098                 }
00099         }
00100         nhep() = i;
00101         nevhep()++;
00102         return (i==0); //nonzero means failure
00103 }
00104 
00105 static MCParticle* primary;
00106 static void setupParticle(MCParticle& q, float* p, float * v)
00107 {
00108   q.setMomentum(Vector(p[0],p[1],p[2]));
00109   double conv = Units::from_mm(1);
00110   q.setPosition( Point(conv*v[0],conv*v[1],conv*v[2]) );
00111   q.setT(Units::from_mm(v[3]));
00112 }
00113 MCParticle *
00114 HepEvt::getEvent()
00115 {
00116   removeChildren();
00117 
00118   //HepAList<MCParticle>
00119   std::vector<MCParticle*>  plist(20);  // corresponding list of created particles
00120   if( readEvent() )
00121          return 0;
00122   long primaryid = idhep(1);
00123   pData = thePDT()->lookUp(primaryid);
00124   setMass( phep(1)[4]);
00125   //THB: why?? _parent = 0;
00126   setupParticle(*this, phep(1),vhep(1));
00127   setStatus(MCParticle::DECAYED);
00128   plist.push_back(this);
00129 
00130   unsigned numsecond = unsigned(nhep());
00131   for( unsigned i=2; i<=numsecond; i++)
00132   {
00133           int statusCode = isthep(i);
00134 //        if( statusCode !=1)
00135 //                      continue;
00136           if( statusCode==0 ) continue;
00137           PData* data = thePDT()->lookUp(idhep(i));
00138           float mass = phep(i)[4];
00139           int parentIndex = static_cast<int>(jmohep(i)[0]-1);
00140           MCParticle* child = dynamic_cast<MCParticle*>
00141                           (plist[parentIndex]->addChild( data ,mass) );
00142           setupParticle(*child, phep(i),vhep(i));
00143           if( statusCode==2)
00144                   child->setStatus(MCParticle::DECAYED);
00145           plist.push_back(child);
00146   }
00147   return this;
00148 }
00149 
00150 void
00151 HepEvt::propagate(const Medium * med)
00152 {
00153         MCParticle::propagate(med);
00154 }
00155 

Generated at Wed Nov 21 12:20:25 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000