StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_geant_Maker.h
1 // $Id: St_geant_Maker.h,v 1.60 2020/02/26 21:26:20 jwebb Exp $
2 // $Log: St_geant_Maker.h,v $
3 // Revision 1.60 2020/02/26 21:26:20 jwebb
4 // Accumulate and report total energy deposited in all active elements
5 // of the detector modules for the job.
6 //
7 // Revision 1.59 2020/02/04 17:46:23 jwebb
8 //
9 // Update to forward silicon geometry and associated changes to support.
10 //
11 // Revision 1.58 2019/09/30 14:13:27 jwebb
12 //
13 // Integrate HITS for forward tracking and forward calorimeter.
14 //
15 // n.b. deprecates the legacy HcalGeo RnD detector.
16 //
17 // Revision 1.57 2018/10/30 13:54:04 jwebb
18 //
19 // Implemented a templated method for creating and filling the g2t hit tables.
20 //
21 // This reduces the boilerplate code required when integrating a new detector
22 // subsystem, and streamlines maintanence.
23 //
24 // We also add a summary printout of the number of hits found in each subsystem,
25 // allowing nightly tests to keep track of changes in the geometry introduced
26 // at the hit level.
27 //
28 // Code was tested for the first cut and last production geometry in each run
29 // from 2005 to 2018. For 1k pythia event -4.5 < eta < 4.5, geant.root file
30 // size is nearly identical (~few to 50 bits/event) comparing old and new version
31 // of St_geant_Maker. When file compression is switched off, file size is identical.
32 //
33 // Revision 1.56 2017/04/26 20:23:53 perev
34 // Remove delete
35 //
36 // Revision 1.55 2014/08/06 11:43:54 jeromel
37 // Suffix on literals need to be space (later gcc compiler makes it an error) - first wave of fixes
38 //
39 // Revision 1.54 2012/11/26 18:45:55 jwebb
40 // Restoring to previous version of St_geant_Maker and adding in changes needed
41 // for new generator framework (i.e. exposing TGiant3 instance).
42 //
43 // Revision 1.52 2012/11/14 00:02:12 fisyak
44 // Add flux histograms, use Attributes intead of m_Mode
45 //
46 // Revision 1.51 2011/09/11 20:57:14 fisyak
47 // Add kinematics definition via MuDst, Clean up
48 //
49 // Revision 1.50 2010/08/10 16:35:33 fisyak
50 // Add initialization of starsim parameter tables after opening zebra-file
51 //
52 // Revision 1.49 2010/05/27 13:36:14 fisyak
53 // 3rd attemp to synchronize mag.field. Now take care that the maker can be not Active and do InitRun in Work
54 //
55 // Revision 1.47 2010/05/24 15:38:40 fisyak
56 // Move geometry and mag.field initialization from Init into InitRun in order to allow mag. field settings from StMagFMaker::InitRun
57 //
58 // Revision 1.45 2010/05/10 14:19:52 fisyak
59 // move geometry load from Init to InitRun in order to allow MagF maker to set mag.field
60 //
61 // Revision 1.44 2009/12/31 00:02:59 perev
62 // Add the material name to the volume name
63 //
64 // Revision 1.43 2008/07/30 15:04:36 fisyak
65 // Remove custom SetDebug, fix bug #1252
66 //
67 // Revision 1.42 2007/07/12 20:36:03 fisyak
68 // Add includes for ROOT 5.16
69 //
70 // Revision 1.41 2007/07/12 20:35:30 fisyak
71 // Add includes for ROOT 5.16
72 //
73 // Revision 1.40 2007/04/26 15:51:31 fisyak
74 // Move creation of TGiant3 in ctor (fix byg 942)
75 //
76 // Revision 1.39 2007/03/03 00:35:43 fine
77 // Fix the leak of the ROOT objects and introduce the method to return the source code filename for the arbitrary geometry node
78 //
79 // Revision 1.38 2005/11/22 23:13:24 fisyak
80 // Add default kinematics if there is no input fiels and if maker is active
81 //
82 // Revision 1.37 2005/10/06 19:23:07 fisyak
83 // Add set date/time from fz-file
84 //
85 // Revision 1.36 2005/08/29 21:47:09 fisyak
86 // Changes for VMC
87 //
88 // Revision 1.35 2005/04/13 22:27:11 fisyak
89 // Add Hit description extractor (AgstHits)
90 //
91 // Revision 1.34 2005/02/07 21:09:20 fisyak
92 // rename antique TGeant3 to TGiant3
93 //
94 // Revision 1.33 2004/02/10 23:16:34 potekhin
95 // First version of Ag2Geom
96 //
97 // Revision 1.32 2003/10/01 23:54:08 potekhin
98 // Added a declaration a a pointer to the structure geom_gdat,
99 // needed for the propagation the GEANT run data --
100 // geometry tag and field scale.
101 //
102 // Revision 1.31 2003/09/10 19:47:47 perev
103 // ansi corrs
104 //
105 // Revision 1.30 2002/11/01 03:17:42 fine
106 // the previous version has been restored. No need of the special flag
107 //
108 // Revision 1.28 2002/03/12 21:22:39 fisyak
109 // Set only one StEvtHddr as default option (due to Embedding)
110 //
111 // Revision 1.27 2001/06/01 03:03:57 perev
112 // overloaded GetDataSet -> FindDataSet
113 //
114 // Revision 1.26 2001/05/31 16:06:12 perev
115 // hiding
116 //
117 // Revision 1.25 2000/09/23 03:07:13 fine
118 // class TShape; statement introduced to fix a side aeffect of TDataSet clean up
119 //
120 // Revision 1.24 2000/03/26 02:43:22 fine
121 // adjusted to ROOT 2.24
122 //
123 // Revision 1.23 2000/02/07 18:58:38 fisyak
124 // Set default NwGeant = 20 000 000 words
125 //
126 // Revision 1.22 2000/02/03 19:34:42 fisyak
127 // Clean up St_geant_Maker::Init, move its parameters to ctor
128 //
129 // Revision 1.21 2000/02/03 16:15:54 fisyak
130 // Add Kathy's histograms
131 //
132 
133 #ifndef STAR_St_geant_Maker
134 #define STAR_St_geant_Maker
135 
137 // //
138 // St_geant_Maker virtual base class for Maker //
139 // //
141 #include "StMaker.h"
142 #include <string>
143 #include <functional>
144 //#define DetectorIndex
145 #ifdef DetectorIndex
146 #include "TArrayI.h"
147 #endif
148 #include "TGiant3.h"
149 class TVolume;
150 class TRotMatrix;
151 class TShape;
152 class TGeoVolume;
153 class St_geom_gdat;
154 class TFileSet;
155 class St_g2t_track;
156 class St_geant_Maker : public StMaker {
157 protected:
158  Int_t fNwGeant; // No. of words in GCBANK common block
159  Int_t fNwPaw; // No. of words in PAWC common block
160  Int_t fIwType; // HIGZ interface (=0 no HIGZ)
161  TDataSet* fVolume;
162  TGeoVolume* fTopGeoVolume;
163  TString fInputFile; //
164  TFileSet *fGeoDirectory; // the pointer the STAR geometry source code
165  StEvtHddr *fEvtHddr;
166  Bool_t fRemakeGeometry;// Flag whether we need to remake the geometry
167  virtual TShape *MakeShape(TString *name, Int_t ivo);
168  virtual TVolume *MakeVolume(TString *name, Int_t ivo, Int_t Nlevel, Int_t *Names, Int_t *Numbers);
169  virtual void ClearRootGeoms();
170  private:
171 
172  St_geom_gdat *m_geom_gdat;
173  public:
174  St_geant_Maker(const char *name="geant",
175  Int_t nwgeant=20,Int_t nwpaw=0, Int_t iwtype=0);
176  virtual ~St_geant_Maker(){};
177  virtual Int_t Finish();
178  virtual Int_t Init();
179  virtual Int_t InitRun(Int_t run);
180  virtual void SetDateTime(int idat=0,int itim=0);//
181  void SetFieldOpt(const char *opt) {mFieldOpt = opt;}
183  virtual void Do(const Char_t *option = "dcut cave x 0.1 10 10 0.03 0.03"); // *MENU
184  virtual void Draw(const char* opt="IN");
185  virtual Int_t Make();
187  virtual void LoadGeometry (const Char_t *option = "detp geometry field_only"); // *MENU
188  virtual void SetNwGEANT (Int_t n=2) {fNwGeant = n;}
189  virtual void SetNwPAW (Int_t n=0) {fNwPaw = n;}
190  virtual void SetIwtype (Int_t n=0) {fIwType = n;}
191  virtual Int_t GetNwGEANT () {return fNwGeant;}
192  virtual Int_t GetNwPAW () {return fNwPaw ;}
193  virtual Int_t GetIwtype () {return fIwType ;}
194  Bool_t Remake() const { return fRemakeGeometry;}
195  void SetRemake(Bool_t remake=kTRUE) {fRemakeGeometry=remake;}
196  virtual Int_t Skip(Int_t Nskip=1); // *MENU*
197  virtual TDataSet *Work();
198  virtual void Mark(TVolume *topvol);
199  virtual void Call(const Char_t *name); // *MENU
200  virtual TRotMatrix *GetMatrix(float theta1, float phi1,
201  float theta2, float phi2,
202  float theta3, float phi3);
203 
204 
205  Int_t SetInputFile(const char* file);
206 
207  TDataSet* GetVolume() { return fVolume; }
208  const TFileSet *GetGeoDirectory() const { return fGeoDirectory;}
209  TGeoVolume* GetTopGeoVolume() {return fTopGeoVolume;}
210  static void RootMapTable(Char_t *Cdest,Char_t *Table, Char_t* Spec,
211  Int_t &k, Char_t *iq);
212  virtual void Geometry();
213  virtual Int_t Agstroot();
214  virtual Int_t AgstHits();
215  virtual Int_t G2t_volume_id(const Char_t *name, Int_t *numbv);
216  virtual Int_t Agvolume(TVolume *&node,Float_t *&par,Float_t *&pos,Float_t *&mot,
217  Int_t &who, Int_t &copy,Float_t *&par1,Int_t &npar, char mat[21]);
218  virtual void Agnzgete (Int_t &ILK, Int_t &IDE,
219  Int_t &NPART, Int_t &IRUN,
220  Int_t &IEVT, const Char_t *CGNAM,
221  Float_t *VERT,Int_t &IWTFL,Float_t &WEIGH);
222 
223  virtual void Gfxzrm(Int_t & Nlevel,
224  Float_t &x, Float_t &y, Float_t &z,
225  Float_t &Theta1, Float_t & Phi1,
226  Float_t &Theta2, Float_t & Phi2,
227  Float_t &Theta3, Float_t & Phi3,
228  Float_t &Type);
229  virtual void Dzddiv(Int_t& idiv ,Int_t &Ldummy,
230  const Char_t* path,const Char_t* opt,
231  Int_t& one,Int_t &two,Int_t &three,Int_t& iw);
232 #ifdef DetectorIndex
233  void DetSetIndex();
234  void DumpIndex(const Char_t *name, const Char_t *vers, const Char_t *fmt, TArrayI &NVmax, TArrayI &Ids);
235 #endif
236  TString GetVolumeSrcFile(const char *volumeName) const;
237  Int_t KinematicsFromMuDst(Int_t flag=0);
238  Int_t SetDatimeFromMuDst();
239  static St_geant_Maker *instance() {return fgGeantMk;}
240  static void usflux();
241  static Int_t ipartx(Int_t id);
242  static Float_t dose(Float_t Z);
244  TGiant3 *Geant3(){ return geant3; }
245  protected:
246  virtual TDataSet *FindDataSet (const char* logInput,
247  const StMaker *uppMk=0,
248  const StMaker *dowMk=0) const ;
249  static TDataSet *fgGeom;
250  static TGiant3 *geant3;
251  static St_geant_Maker *fgGeantMk;
252  TString mInitialization; // !
253  TString mFieldOpt; // !
254  static Quest_t *cquest;
255  static Gclink_t *clink;
256  static Gcflag_t *cflag;
257  static Gcvolu_t *cvolu;
258  static Gcnum_t *cnum;
259  static Int_t *z_iq, *z_lq;
260  static Float_t *z_q;
261  static Gcsets_t *csets;
262  static Gckine_t *ckine;
263  static Gcking_t *cking;
264  static Gctrak_t *ctrak;
265  static Gcmate_t *cmate;
266  static Gccuts_t *ccuts;
267  static Gcphys_t *cphys;
268  static Int_t nlev;
269 
270 
271 
280  template<typename T, typename F>
281  int AddHits( std::string container, std::vector<std::string> volumes, std::string tablename, F g2t, bool verbose=false ){
282  int ntotal = 0, nhits = 0;
283  for ( auto v : volumes ) {
284  geant3->Gfnhit( container.c_str(), v.c_str(), nhits );
285  std::string key = container + ":" + v;
286  LOG_DEBUG << key << " found nhits=" << nhits << endm;
287  if (nhits) { mHitCounts[key] += nhits; mHitCounts["ALL"] += nhits; }
288  ntotal += nhits;
289  }
290  if ( ntotal <= 0 ) return ntotal;
291  T* table = new T( tablename.c_str(), ntotal );
292  double sum = 0.0;
293  auto* g2t_track = (St_g2t_track*)FindByName("g2t_track");
294  g2t( g2t_track, table );
295  AddData( table );
296  for ( auto hit : (*table) ) {
297  sum += hit.de;
298  }
299  mHitSum[container] = sum;
300  if ( Debug() > 1 || verbose ) table->Print(0,10);
301  return ntotal;
302  }
303  std::map<std::string, int> mHitCounts; // total number of hits per volume
304  std::map<std::string, double> mHitSum; // total energy deposition per table
305 
306  virtual const char *GetCVS() const
307  {static const char cvs[]="Tag $Name: $ $Id: St_geant_Maker.h,v 1.60 2020/02/26 21:26:20 jwebb Exp $ built " __DATE__ " " __TIME__ ; return cvs;}
308 ClassDef(St_geant_Maker,0) //StAF chain virtual base class for Makers
309 };
310 
311 #endif
312 
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
int AddHits(std::string container, std::vector< std::string > volumes, std::string tablename, F g2t, bool verbose=false)
virtual Int_t Finish()
TGiant3 * Geant3()
Returns a pointer to the GEANT3 VMC interface.
virtual void Do(const Char_t *option="dcut cave x 0.1 10 10 0.03 0.03")
Executes a KUIP command.
virtual Int_t Make()
Bool_t fRemakeGeometry
pointer to Event Header
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const
Definition: TDataSet.cxx:378
virtual void LoadGeometry(const Char_t *option="detp geometry field_only")
Specifies GEANT3 geometry command.