00001
00002
00004
00005
00006
00008
00034
00035 #include "stdlib.h"
00036 #include "ctype.h"
00037 #include "math.h"
00038 #include <cassert>
00039 #include <cstring>
00040 #include <iostream>
00041
00042 #include "StMCFilter.h"
00043 #include <map>
00044 #include "StHepParticle.h"
00045 #include "StG3Particle.h"
00046
00047 typedef std::map<std::string, StMCFilter *> myMap_t;
00048 static myMap_t myMap;
00049 StMCFilter *StMCFilter::fgSelected =0;
00050 StHepParticleMaster *StMCFilter::fgHepParticle =0;
00051 StG3ParticleMaster *StMCFilter::fgG3Particle =0;
00052
00053 extern void *gStarFiltAction;
00054
00055
00056 StMCFilter::StMCFilter(const char *name)
00057 {
00058 memset(fBeg,0,fEnd-fBeg+1);
00059 fName= name;
00060 std::string myName(fName);
00061 for (int i=0;i<(int)myName.size();i++) { myName[i]=tolower(myName[i]);}
00062
00063
00064 myMap_t::iterator it = myMap.find(myName);
00065 assert (it == myMap.end() && "Filter name must be unique");
00066 myMap[myName] = this;
00067 gStarFiltAction=(void*)&StMCFilter::Action;
00068 std::cout << "*** StMCFilter::StMCFilter(" << myName.c_str() << ") CREATED ***" << std::endl;
00069 }
00070
00071 StMCFilter::~StMCFilter()
00072 {
00073 myMap.clear();
00074 delete fgHepParticle; fgHepParticle=0;
00075 delete fgG3Particle ; fgG3Particle =0;
00076
00077 }
00078
00079 int StMCFilter::Select(const char *name)
00080 {
00081
00082 std::string myName(name);
00083 for (int i=0;i<(int)myName.size();i++) { myName[i]=tolower(myName[i]);}
00084 myMap_t::iterator it = myMap.find(std::string(myName));
00085 assert (it != myMap.end() && "Filter MUST be found");
00086 if (it == myMap.end()) return 1;
00087 fgSelected = (*it).second;
00088 std::cout << "*** StMCFilter::Select(" << myName.c_str() << ") SELCTED ***" << std::endl;
00089 return 0;
00090 }
00091
00092 void StMCFilter::SetEG(void *hepEvt)
00093 {
00094 if (fgHepParticle) return;
00095 fgHepParticle = new StHepParticleMaster(hepEvt);
00096 }
00097
00098 void StMCFilter::SetG3(void *gfKine,void *gfVert)
00099 {
00100 if (fgG3Particle) return;
00101 fgG3Particle = new StG3ParticleMaster((GFKINE_t)gfKine,(GFVERT_t)gfVert);
00102 }
00103
00104 int StMCFilter::REJECTEG()
00105 {
00106 if (!fgSelected || !fgHepParticle) return 0;
00107 fgSelected->fCnt[0][0]++;
00108 fgHepParticle->Update();
00109 int ans =fgSelected->RejectEG(*fgHepParticle);
00110 if (ans) fgSelected->fCnt[0][1]++;
00111 return ans;
00112 }
00113
00114 int StMCFilter::REJECTGT()
00115 {
00116 if (!fgSelected || !fgG3Particle) return 0;
00117 fgSelected->fCnt[1][0]++;
00118 fgG3Particle->Update();
00119 int ans = fgSelected->RejectGT(*fgG3Particle);
00120 if (ans) fgSelected->fCnt[1][1]++;
00121 return ans;
00122 }
00123
00124 int StMCFilter::REJECTGE()
00125 {
00126
00127 if (!fgSelected || !fgG3Particle) return 0;
00128 fgG3Particle->Update();
00129 fgSelected->fCnt[2][0]++;
00130 int ans = fgSelected->RejectGE(*fgG3Particle);
00131 if (ans) fgSelected->fCnt[2][1]++;
00132 return ans;
00133 }
00134
00136
00138 int StMCFilter::Action(int kase, void *par1,void *par2)
00139 {
00140 enum { kSelect=0,kEGInit=1, kEGReje=2
00141 ,kGTInit=3, kGTReje=4
00142 ,kGEInit=5, kGEReje=6,kFinish=7};
00143
00144 switch (kase) {
00145
00146 case kSelect: return StMCFilter::Select((char*)par1);
00147
00148 case kEGInit: StMCFilter::SetEG(par1 ); return 0;
00149 case kGTInit: StMCFilter::SetG3(par1,par2); return 0;
00150 case kGEInit: return 0;
00151
00152 case kEGReje: return StMCFilter::REJECTEG();
00153 case kGTReje: return StMCFilter::REJECTGT();
00154 case kGEReje: return StMCFilter::REJECTGE();
00155 case kFinish: StMCFilter::FINISH(); return 0;
00156 default: assert(0 && "StMCFilter::Action Wrong case");
00157 }
00158 return 0;
00159 }
00160
00161 void StMCFilter::FINISH()
00162 {
00163 static const char *filtName[] = {"RejectEG","RejectGT","RejectGE"};
00164 if (!fgSelected) return;
00165 std::cout << "*** Filter Finish(" << fgSelected->GetName().c_str() << ") ***" << std::endl;
00166 for (int i=0; i<3; i++)
00167 {
00168 if (!fgSelected->fCnt[i][0]) continue;
00169 std::cout << "*** Filter " << filtName[i] << " nTot=" << fgSelected->fCnt[i][0]
00170 << "\tnRej=" << fgSelected->fCnt[i][1] << std::endl;
00171 }
00172 fgSelected->Finish();
00173 }
00174
00175
00176