StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMCFilter.cxx
1 // @(#)root/eg:$Id: StMCFilter.cxx,v 1.10 2018/02/21 02:04:41 perev Exp $
2 // Author: Victor Perev 17/03/2009
4 // //
5 // StMCFilter Class //
6 // //
8 
34 //______________________________________________________________________________
35 #include "stdlib.h"
36 #include "ctype.h"
37 #include "math.h"
38 #include <cassert>
39 #include <cstring>
40 #include <iostream>
41 
42 #include "StMCFilter.h"
43 #include <map>
44 #include "StHepParticle.h"
45 #include "StG3Particle.h"
46 
47 StMCFilter *StMCFilter::fgSelected =0;
48 StHepParticleMaster *StMCFilter::fgHepParticle =0;
49 StG3ParticleMaster *StMCFilter::fgG3Particle =0;
50 myMap_t *StMCFilter::mgMap=0;
51 
52 extern void *gStarFiltAction; //
53 extern void *gStarFiltConfig; //
54 
55 //______________________________________________________________________________
56 StMCFilter::StMCFilter(const char *name)
57 {
58  if(!mgMap) mgMap = new myMap_t;
59  memset(fBeg,0,fEnd-fBeg+1);
60  fName= name;
61  std::string myName(fName);
62  for (int i=0;i<(int)myName.size();i++) { myName[i]=tolower(myName[i]);}
63 
64 
65  myMap_t::iterator it = mgMap->find(myName);
66  assert (it == mgMap->end() && "Filter name must be unique");
67  (*mgMap)[myName] = this;
68  gStarFiltAction=(void*)&StMCFilter::Action;
69  gStarFiltConfig=(void*)&StMCFilter::Config;
70  std::cout << "*** StMCFilter::StMCFilter(" << myName.c_str() << ") CREATED ***" << std::endl;
71 }
72 //______________________________________________________________________________
73 StMCFilter::~StMCFilter()
74 {
75  mgMap->clear();
76  delete fgHepParticle; fgHepParticle=0;
77  delete fgG3Particle ; fgG3Particle =0;
78 
79 }
80 //______________________________________________________________________________
81 int StMCFilter::Select(const char *name)
82 {
83 //VP assert(!fgSelected && "Only one filter is allowed");
84  std::string myName(name);
85  for (int i=0;i<(int)myName.size();i++) { myName[i]=tolower(myName[i]);}
86  myMap_t::iterator it = mgMap->find(std::string(myName));
87  assert (it != mgMap->end() && "Filter MUST be found");
88  if (it == mgMap->end()) return 1;
89  fgSelected = (*it).second;
90  std::cout << "*** StMCFilter::Select(" << myName.c_str() << ") SELCTED ***" << std::endl;
91  return 0;
92 }
93 //______________________________________________________________________________
94 void StMCFilter::SetEG(void *hepEvt)
95 {
96  if (fgHepParticle) return;
97  fgHepParticle = new StHepParticleMaster(hepEvt);
98 }
99 //______________________________________________________________________________
100 void StMCFilter::SetG3(void *gfKine,void *gfVert)
101 {
102  if (fgG3Particle) return;
103  fgG3Particle = new StG3ParticleMaster((GFKINE_t)gfKine,(GFVERT_t)gfVert);
104 }
105 //______________________________________________________________________________
106 int StMCFilter::REJECTEG()
107 {
108  if (!fgSelected || !fgHepParticle) return 0;
109  fgSelected->fCnt[0][0]++;
110  fgHepParticle->Update();
111  int ans =fgSelected->RejectEG(*fgHepParticle);
112  if (ans) fgSelected->fCnt[0][1]++;
113  return ans;
114 }
115 //______________________________________________________________________________
116 int StMCFilter::REJECTGT()
117 {
118  if (!fgSelected || !fgG3Particle) return 0;
119  fgSelected->fCnt[1][0]++;
120  fgG3Particle->Update();
121  int ans = fgSelected->RejectGT(*fgG3Particle);
122  if (ans) fgSelected->fCnt[1][1]++;
123  return ans;
124 }
125 //______________________________________________________________________________
126 int StMCFilter::REJECTGE()
127 {
128 
129  if (!fgSelected || !fgG3Particle) return 0;
130  fgG3Particle->Update();
131  fgSelected->fCnt[2][0]++;
132  int ans = fgSelected->RejectGE(*fgG3Particle);
133  if (ans) fgSelected->fCnt[2][1]++;
134  return ans;
135 }
136 //______________________________________________________________________________
138 // Perform calls of filter from fortran world, called only in starsim //
140 int StMCFilter::Action(int kase, void *par1,void *par2)
141 {
142  enum { kSelect=0,kEGInit=1, kEGReje=2
143  ,kGTInit=3, kGTReje=4
144  ,kGEInit=5, kGEReje=6,kFinish=7};
145 
146  switch (kase) {
147 
148  case kSelect: return StMCFilter::Select((char*)par1);
149 
150  case kEGInit: StMCFilter::SetEG(par1 ); return 0;
151  case kGTInit: StMCFilter::SetG3(par1,par2); return 0;
152  case kGEInit: return 0;
153 
154  case kEGReje: return StMCFilter::REJECTEG();
155  case kGTReje: return StMCFilter::REJECTGT();
156  case kGEReje: return StMCFilter::REJECTGE();
157  case kFinish: StMCFilter::FINISH(); return 0;
158  default: assert(0 && "StMCFilter::Action Wrong case");
159  }
160  return 0;
161 }
162 //______________________________________________________________________________
163 int StMCFilter::Config( std::string key, const float value )
164 {
165  if ( !fgSelected ) return 0; // should issue warning here
166  fgSelected->parseConfig( key, value );
167  return 1;
168 }
169 
170 
171 //______________________________________________________________________________
173 {
174 static const char *filtName[] = {"RejectEG","RejectGT","RejectGE"};
175  if (!fgSelected) return;
176  std::cout << "*** Filter Finish(" << fgSelected->GetName().c_str() << ") ***" << std::endl;
177  for (int i=0; i<3; i++)
178  {
179  if (!fgSelected->fCnt[i][0]) continue;
180  std::cout << "*** Filter " << filtName[i] << " nTot=" << fgSelected->fCnt[i][0]
181  << "\tnRej=" << fgSelected->fCnt[i][1] << std::endl;
182  }
183  fgSelected->Finish();
184 }
185 
186 
187 
Master class for StGimParticle filled from GEANT3 internal structures.
Definition: StG3Particle.h:26
virtual int RejectGT(const StGenParticleMaster &ptl) const
Rejection of GEANT Tracking.
Definition: StMCFilter.h:32
virtual int RejectGE(const StGenParticleMaster &ptl) const
Rejection at GEANT End, No GEANT output.
Definition: StMCFilter.h:34
virtual void parseConfig(std::string key, float value)
Definition: StMCFilter.h:47
virtual int RejectEG(const StGenParticleMaster &ptl) const
Rejection inside of EventGenerator (Pythia)
Definition: StMCFilter.h:30
virtual void Finish() const
Finish called at the end of GEANT.
Definition: StMCFilter.h:36
static void FINISH()
Print of numbers above at the end of STARSIM.
Definition: StMCFilter.cxx:172