StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMcEventMaker.cxx
1 
280 #include "Stiostream.h"
281 #include <stdlib.h>
282 #include <string>
283 #include <algorithm>
284 #ifndef ST_NO_NAMESPACES
285 using std::string;
286 using std::sort;
287 using std::find;
288 #endif
289 
290 #include "TStyle.h"
291 #include "TCanvas.h"
292 #include "StMcEventMaker.h"
293 
294 #include "PhysicalConstants.h"
295 #include "SystemOfUnits.h"
296 #include "StGlobals.hh"
297 #include "StMessMgr.h"
298 #include "StMemoryInfo.hh"
299 #include "StTimer.hh"
300 
301 #include "StThreeVectorF.hh"
302 #include "StParticleDefinition.hh"
303 
304 #include "St_DataSet.h"
305 #include "St_DataSetIter.h"
306 
307 #include "tables/St_g2t_event_Table.h"
308 #include "tables/St_g2t_ftp_hit_Table.h"
309 #include "tables/St_g2t_rch_hit_Table.h"
310 #include "tables/St_g2t_ctf_hit_Table.h"
311 #include "tables/St_g2t_mtd_hit_Table.h"
312 #include "tables/St_g2t_svt_hit_Table.h"
313 #include "tables/St_g2t_ssd_hit_Table.h"
314 #include "tables/St_g2t_tpc_hit_Table.h"
315 #include "tables/St_g2t_emc_hit_Table.h"
316 #include "tables/St_g2t_pix_hit_Table.h"
317 #include "tables/St_g2t_ist_hit_Table.h"
318 #include "tables/St_g2t_fgt_hit_Table.h"
319 #include "tables/St_g2t_etr_hit_Table.h"
320 #include "tables/St_g2t_track_Table.h"
321 #include "tables/St_g2t_vertex_Table.h"
322 #include "tables/St_particle_Table.h"
323 
324 #include "StMcEventTypes.hh"
325 
326 #include "StEmcUtil/geometry/StEmcGeom.h" // For Barrel Emc
327 
328 //#include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h" // For Endcap Emc
329 #include "StEEmcUtil/EEmcMC/EEmcMCData.h" // geant unpacker, EEmcHit
330 
331 static double vertexCut = .0000025; // 25 nm (lifetime of the pi0)
332 struct vertexFlag {
333  StMcVertex* vtx;
334  int primaryFlag; };
335 
336 static const char rcsid[] = "$Id: StMcEventMaker.cxx,v 1.79 2016/08/04 01:54:33 perev Exp $";
337 static long NTracks = 0;
338 
339 ClassImp(StMcEventMaker)
340 #define AddHit2Track(G2Type,DET) \
341  Int_t iTrkId = ( G2Type ## HitTable[ihit].track_p) - 1; \
342  if (iTrkId >= 0 && iTrkId < NTracks ) { \
343  th->setParentTrack(ttemp[iTrkId]); \
344  ttemp[iTrkId]->add ## DET ## Hit(th); \
345  }
346 #define AddHits(G2Type,det,DET) \
347  if (doUse ## DET) { \
348  if (g2t_ ## G2Type ## _hitTablePointer) { \
349  StMc ## DET ## Hit* th = 0; \
350  Int_t NHits = g2t_ ## G2Type ## _hitTablePointer->GetNRows(); \
351  for(Int_t ihit=0; ihit<NHits; ihit++) { \
352  th = new StMc ## DET ## Hit(& G2Type ## HitTable[ihit]); \
353  mCurrentMcEvent-> det ## HitCollection()->addHit(th); \
354  AddHit2Track(G2Type,DET); \
355  } \
356  if (Debug()) cout << "Filled " << mCurrentMcEvent-> det ## HitCollection()->numberOfHits() << #DET << " Hits" << endl; \
357  } else if (Debug()) cout << "No " << #DET << "/" << #det << " Hits in this event" << endl; \
358  }
359 //_____________________________________________________________________________
360 
361 
362 //_____________________________________________________________________________
363 StMcEventMaker::StMcEventMaker(const char*name, const char * title) :
364  StMaker(name,title),
365  doPrintEventInfo (kFALSE),
366  doPrintMemoryInfo(kFALSE),
367  doPrintCpuInfo (kFALSE),
368  doUseTpc (kTRUE),
369  doUseSvt (kTRUE),
370  doUseSsd (kTRUE),
371  doUseFtpc (kTRUE),
372  doUseRich (kTRUE),
373  doUseBemc (kTRUE),
374  doUseBsmd (kTRUE),
375  doUseCtb (kTRUE),
376  doUseTofp (kFALSE),
377  doUseTof (kTRUE),
378  doUseMtd (kTRUE),
379  doUseEemc (kTRUE),
380  doUseFpd (kTRUE),
381  doUseFsc (kTRUE),
382  doUsePxl (kTRUE),
383  doUseIst (kTRUE),
384  doUseFgt (kTRUE),
385  doUseEtr (kTRUE),
386  ttemp(),
387  ttempParticle(),
388  mCurrentMcEvent(0)
389 {
390  // StMcEventMaker - constructor
391  // - set all pointers defined in the header file to zero
392 
393 }
394 //_____________________________________________________________________________
395 StMcEventMaker::~StMcEventMaker()
396 {
397  // StMcEventMaker - destructor
398  if (Debug()>=2) cout << "Inside ReaderMaker Destructor" << endl;
399  // SafeDelete(mCurrentMcEvent); //
400 
401 }
402 
403 
404 
405 //_____________________________________________________________________________
406 void StMcEventMaker::Clear(const char*)
407 {
408  if (doPrintMemoryInfo) StMemoryInfo::instance()->snapshot();
409  // StMcEventMaker - Clear,
410  if (mCurrentMcEvent) {
411  // delete mCurrentMcEvent;
412  mCurrentMcEvent = 0;
413  }
414  if (doPrintMemoryInfo) {
415  StMemoryInfo::instance()->snapshot();
416  StMemoryInfo::instance()->print();
417  }
418  StMaker::Clear();
419 }
420 
421 
422 //_____________________________________________________________________________
424 {
425  // StMcEventMaker - Finish, Draw histograms if SetDraw true
426 
427  // Right now I'm not doing any histograms, later on, I would need to uncomment
428  // the next line, and add a DrawHists() method. Look in St_QA_Maker.cxx
429  //if (drawinit) DrawHists();
430  return StMaker::Finish();
431 }
432 
433 
434 //_____________________________________________________________________________
435 Int_t StMcEventMaker::Init()
436 {
437  if (Debug()>=1) cout << "This is StMcEventMaker::Init() - by Ming" << endl;
438  return StMaker::Init();
439 }
440 
441 //_____________________________________________________________________________
443 {
444  // StMcEventMaker - Make; fill StMcEvent objects
445  StTimer timer;
446  if (doPrintCpuInfo) timer.start();
447  if (doPrintMemoryInfo) StMemoryInfo::instance()->snapshot();
448 
449  if (Debug()>=1) cout << "Inside StMcEventMaker::Make()" << endl;
450  // We're supposed to get the dataset from the chain. I don't know how yet. I think it is:
451 
452  const Char_t* geaTmp[3]={"geant","event/geant/Event","bfcTree/geantBranch"};
453  St_DataSet* dsGeant = 0;
454  for(UInt_t i=0; i<3; i++){
455  dsGeant = GetDataSet(geaTmp[i]);
456  if(!dsGeant || !dsGeant->GetList()) {
457  gMessMgr->Warning() << "Could not find dataset " << geaTmp[i] << endm;
458  dsGeant = GetDataSet("event/geant/Event");
459  } else {
460  if (Debug()) gMessMgr->Info() << "Get Geant info from dataset " << geaTmp[i] << endm;
461  break;
462  }
463  }
464  if(!dsGeant) return kStWarn;;
465  /*
466  if(!dsGeant || !dsGeant->GetList()) {
467  gMessMgr->Warning() << "Could not find dataset geant" << endm;
468  dsGeant = GetDataSet("event/geant/Event");
469  if(!dsGeant || !dsGeant->GetList()) { // Try direct output from Geant
470  gMessMgr->Warning() << "Could not find dataset event/geant/Event" << endm;
471  dsGeant = GetDataSet("bfcTree/geantBranch");
472  if(!dsGeant || !dsGeant->GetList()) { // Try output from bfc forGeant
473  gMessMgr->Warning() << "Could not find dataset bfcTree/geantBranch" << endm;
474  return kStWarn;
475  } else cout<< "Find dataset bfcTree/geantBranch "<<endl;
476  }
477  }
478  */
479  // This is done only for one file, though. I haven't put functionality for
480  // multiple file handling. If needed, it should start in the StMcEventReadMacro
481  // and try to follow the doEvents.C macro to read in multiple files.
482  // Then, we would need to mimic the nextRootFile() methods and so on.
483 
484 
485  // Now we have the DataSet, but for some reason, we need the Iterator to navigate
486 
487  St_DataSetIter geantDstI(dsGeant);
488 
489  // Now the Iterator is set up, and this allows us to access the tables
490  // This is done like so:
491  // TableClass *instanceOfTableClassPointer = cast to TableClassPointer instanceOfDataSetIter("actual name of table in data set");
492 
493  St_g2t_event *g2t_eventTablePointer = (St_g2t_event *) geantDstI("g2t_event");
494  St_g2t_vertex *g2t_vertexTablePointer = (St_g2t_vertex *) geantDstI("g2t_vertex");
495  St_g2t_track *g2t_trackTablePointer = (St_g2t_track *) geantDstI("g2t_track");
496  St_g2t_tpc_hit *g2t_tpc_hitTablePointer = (St_g2t_tpc_hit *) geantDstI("g2t_tpc_hit");
497  St_g2t_svt_hit *g2t_svt_hitTablePointer = (St_g2t_svt_hit *) geantDstI("g2t_svt_hit");
498  St_g2t_ssd_hit *g2t_ssd_hitTablePointer = (St_g2t_ssd_hit *) geantDstI("g2t_ssd_hit");
499  St_g2t_ftp_hit *g2t_ftp_hitTablePointer = (St_g2t_ftp_hit *) geantDstI("g2t_ftp_hit");
500  St_g2t_rch_hit *g2t_rch_hitTablePointer = (St_g2t_rch_hit *) geantDstI("g2t_rch_hit");
501  St_g2t_emc_hit *g2t_emc_hitTablePointer = (St_g2t_emc_hit *) geantDstI("g2t_emc_hit");
502  St_g2t_emc_hit *g2t_smd_hitTablePointer = (St_g2t_emc_hit *) geantDstI("g2t_smd_hit");
503  St_g2t_ctf_hit *g2t_ctb_hitTablePointer = (St_g2t_ctf_hit *) geantDstI("g2t_ctb_hit"); // Added CTB Hits
504  St_g2t_ctf_hit *g2t_tof_hitTablePointer = (St_g2t_ctf_hit *) geantDstI("g2t_tof_hit");
505  St_g2t_ctf_hit *g2t_tfr_hitTablePointer = (St_g2t_ctf_hit *) geantDstI("g2t_tfr_hit");
506  St_g2t_mtd_hit *g2t_mtd_hitTablePointer = (St_g2t_mtd_hit *) geantDstI("g2t_mtd_hit");
507  St_g2t_emc_hit *g2t_eem_hitTablePointer = (St_g2t_emc_hit *) geantDstI("g2t_eem_hit");
508  St_g2t_emc_hit *g2t_esm_hitTablePointer = (St_g2t_emc_hit *) geantDstI("g2t_esm_hit");
509  St_g2t_emc_hit *g2t_fpd_hitTablePointer = (St_g2t_emc_hit *) geantDstI("g2t_fpd_hit"); // Added FPD Hits
510  St_g2t_emc_hit *g2t_fsc_hitTablePointer = (St_g2t_emc_hit *) geantDstI("g2t_fsc_hit"); // Added FSC Hits
511  St_g2t_pix_hit *g2t_pix_hitTablePointer = (St_g2t_pix_hit *) geantDstI("g2t_pix_hit");
512  St_g2t_ist_hit *g2t_ist_hitTablePointer = (St_g2t_ist_hit *) geantDstI("g2t_ist_hit");
513  St_g2t_fgt_hit *g2t_fgt_hitTablePointer = (St_g2t_fgt_hit *) geantDstI("g2t_fgt_hit");
514  St_g2t_etr_hit *g2t_etr_hitTablePointer = (St_g2t_etr_hit *) geantDstI("g2t_etr_hit");
515  St_particle *particleTablePointer = (St_particle *) geantDstI("particle");
516 
517  // For backwards compatibility, look for the rch and particle tables also in the dstBranch
518  TDataSet *dst = GetDataSet("dst");
519  if (dst) {
520  St_DataSetIter dstDstI(dst);
521  if (!particleTablePointer)
522  particleTablePointer = (St_particle *) dstDstI("particle");
523  if (!g2t_rch_hitTablePointer)
524  g2t_rch_hitTablePointer = (St_g2t_rch_hit *) dstDstI("g2t_rch_hit");
525  }
526  // Now we check if we have the pointer, if we do, then we can access the tables!
527 
528  if (g2t_vertexTablePointer && g2t_trackTablePointer){
529  long NVertices = g2t_vertexTablePointer->GetNRows();
530  NTracks = g2t_trackTablePointer->GetNRows();
531  if (NVertices > 0 && NTracks > 0) {
532  //
533  // g2t_event Table
534  //
535  g2t_event_st *eventTable = 0;
536 
537  // Check Pointer
538  if (g2t_eventTablePointer)
539  eventTable = g2t_eventTablePointer->GetTable();
540  else
541  if (Debug()) cerr << "Table g2t_event Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
542 
543  // Check Table
544  if(!g2t_eventTablePointer->GetNRows()) {
545  cout << "Event Table is EMPTY!! " << endl;
546  PR(g2t_eventTablePointer->GetNRows());
547  PR(eventTable)
548  }
549  //
550  // Vertex, Track and table don't have problems normally.
551  //
552  g2t_vertex_st *vertexTable = g2t_vertexTablePointer->GetTable();
553  g2t_track_st *trackTable = g2t_trackTablePointer->GetTable();
554 
555  //
556  // Tpc Hit Table (might not be there for photon events
557  //
558  g2t_tpc_hit_st *tpcHitTable = 0;
559  if (g2t_tpc_hitTablePointer)
560  tpcHitTable = g2t_tpc_hitTablePointer->GetTable();
561  else
562  if (Debug()) cerr << "Table g2t_tpc_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
563  //
564  // Ftpc Hit Table
565  //
566  g2t_ftp_hit_st *ftpHitTable = 0;
567  if (g2t_ftp_hitTablePointer)
568  ftpHitTable = g2t_ftp_hitTablePointer->GetTable();
569  else
570  if (Debug()) cerr << "Table g2t_ftp_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
571 
572  //
573  // Svt Hit Table
574  //
575  g2t_svt_hit_st *svtHitTable = 0;
576  if (g2t_svt_hitTablePointer)
577  svtHitTable = g2t_svt_hitTablePointer->GetTable();
578  else
579  if (Debug()) cerr << "Table g2t_svt_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
580 
581  //
582  // Ssd Hit Table
583  //
584  g2t_ssd_hit_st *ssdHitTable = 0;
585  if (g2t_ssd_hitTablePointer)
586  ssdHitTable = g2t_ssd_hitTablePointer->GetTable();
587  else
588  if (Debug()) cerr << "Table g2t_ssd_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
589 
590  //
591  // Rich Hit Table
592  //
593  g2t_rch_hit_st *rchHitTable = 0;
594  if (g2t_rch_hitTablePointer)
595  rchHitTable = g2t_rch_hitTablePointer->GetTable();
596  else
597  if (Debug()) cerr << "Table g2t_rch_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
598  //
599  // Ctb Hit Table
600  //
601  g2t_ctf_hit_st *ctbHitTable = 0;
602  if (g2t_ctb_hitTablePointer)
603  ctbHitTable = g2t_ctb_hitTablePointer->GetTable();
604  else
605  if (Debug()) cerr << "Table g2t_rch_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
606 
607  // TOF Hit Tables
608  //
609  g2t_ctf_hit_st *tofHitTable = 0;
610  if (g2t_tof_hitTablePointer)
611  tofHitTable = g2t_tof_hitTablePointer->GetTable();
612  else
613  if (Debug()) cerr << "Table g2t_tof_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
614 
615  g2t_ctf_hit_st *tfrHitTable = 0;
616  if (g2t_tfr_hitTablePointer)
617  tfrHitTable = g2t_tfr_hitTablePointer->GetTable();
618  else
619  if (Debug()) cerr << "Table g2t_tfr_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
620 
621  // MTD Hit Tables
622  //
623  g2t_mtd_hit_st *mtdHitTable = 0;
624  if (g2t_mtd_hitTablePointer)
625  mtdHitTable = g2t_mtd_hitTablePointer->GetTable();
626  else
627  if (Debug()) cerr << "Table g2t_mtd_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
628 
629  //
630  // BEMC and BPRS Hit Table
631  //
632  g2t_emc_hit_st *emcHitTable = 0;
633  if (g2t_emc_hitTablePointer)
634  emcHitTable = g2t_emc_hitTablePointer->GetTable();
635  else
636  if (Debug()) cerr << "Table g2t_emc_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
637 
638  //
639  // BSMDE and BSMDP Hit Table
640  //
641  g2t_emc_hit_st *smdHitTable = 0;
642  if (g2t_smd_hitTablePointer)
643  smdHitTable = g2t_smd_hitTablePointer->GetTable();
644  else
645  if (Debug()) cerr << "Table g2t_smd_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
646 
647  //
648  // EEMC and EPRS Hit Table
649  //
650  g2t_emc_hit_st *eemHitTable = 0;
651  if (g2t_eem_hitTablePointer)
652  eemHitTable = g2t_eem_hitTablePointer->GetTable();
653  else
654  if (Debug()) cerr << "Table g2t_eem_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
655 
656  //
657  // ESMDU and ESMDV Hit Table
658  //
659  g2t_emc_hit_st *esmHitTable = 0;
660  if (g2t_esm_hitTablePointer)
661  esmHitTable = g2t_esm_hitTablePointer->GetTable();
662  else
663  if (Debug()) cerr << "Table g2t_esm_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
664 
665  //
666  // FPD Hit Table
667  //
668  g2t_emc_hit_st* fpdHitTable = 0;
669  if (g2t_fpd_hitTablePointer)
670  fpdHitTable = g2t_fpd_hitTablePointer->GetTable();
671  else
672  if (Debug()) cout << "Table g2t_fpd_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
673 
674  //
675  // FSC Hit Table
676  //
677  g2t_emc_hit_st* fscHitTable = 0;
678  if (g2t_fsc_hitTablePointer)
679  fscHitTable = g2t_fsc_hitTablePointer->GetTable();
680  else
681  if (Debug()) cout << "Table g2t_fsc_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
682 
683  //
684  // Pxl Hit Table
685  //
686  g2t_pix_hit_st *pixHitTable=0;
687  if (g2t_pix_hitTablePointer)
688  pixHitTable = g2t_pix_hitTablePointer->GetTable();
689  else
690  if (Debug()) cerr << "Table g2t_pix_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
691 
692  //
693  // Ist Hit Table
694  //
695  g2t_ist_hit_st *istHitTable=0;
696  if (g2t_ist_hitTablePointer)
697  istHitTable = g2t_ist_hitTablePointer->GetTable();
698  else
699  if (Debug()) cerr << "Table g2t_ist_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
700  //
701  // Fgt Hit Table
702  //
703  g2t_fgt_hit_st *fgtHitTable=0;
704  if (g2t_fgt_hitTablePointer)
705  fgtHitTable = g2t_fgt_hitTablePointer->GetTable();
706  else
707  if (Debug()) cerr << "Table g2t_fgt_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
708 
709  //
710  // Etr Hit Table
711  //
712  g2t_etr_hit_st *etrHitTable=0;
713  if (g2t_etr_hitTablePointer)
714  etrHitTable = g2t_etr_hitTablePointer->GetTable();
715  if (Debug()) cerr << "Table g2t_etr_hit found in Dataset " << geantDstI.Pwd()->GetName() << endl;
716  else
717  if (Debug()) cerr << "Table g2t_etr_hit Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
718 
719  //
720  // particle Table
721  //
722  particle_st *particleTable = 0;
723  if (particleTablePointer)
724  particleTable = particleTablePointer->GetTable();
725  else
726  if (Debug()) cerr << "Table particle Not found in Dataset " << geantDstI.Pwd()->GetName() << endl;
727 
728  // Before filling StMcEvent, we can check whether we can actually
729  // access the tables.
730 
731 // cout << "Event Table Examples: " << endl;
732 // cout << "eg_label: " << eventTable->eg_label << endl;
733 // cout << "n_event : " << eventTable->n_event << endl;
734 // cout << "n_run : " << eventTable->n_run << endl;
735 // cout << "n_part_prot_west: " << eventTable->n_part_prot_west << endl;
736 // cout << "n_part_neut_west: " << eventTable->n_part_neut_west << endl;
737 // cout << "n_part_prot_east: " << eventTable->n_part_prot_east << endl;
738 // cout << "n_part_neut_east: " << eventTable->n_part_neut_east << endl;
739 
740 // cout << "Vertex Table Examples:" << endl;
741 // cout << "ge_x[0] :" << vertexTable[0].ge_x[0] << endl;
742 // cout << "ge_x[1] :" << vertexTable[0].ge_x[1] << endl;
743 // cout << "ge_x[2] :" << vertexTable[0].ge_x[2] << endl;
744 
745 // cout << "Track Table Examples:" << endl;
746 // cout << "p[0] :" << trackTable[0].p[0] << endl;
747 // cout << "p[1] :" << trackTable[0].p[1] << endl;
748 // cout << "p[2] :" << trackTable[0].p[2] << endl;
749 
750 // cout << "Tpc Hit Table Examples:" << endl;
751 // cout << "p[0] :" << tpcHitTable[0].p[0] << endl;
752 // cout << "p[1] :" << tpcHitTable[0].p[1] << endl;
753 // cout << "p[2] :" << tpcHitTable[0].p[2] << endl;
754 
755 // cout << "Svt Hit Table Examples:" << endl;
756 // cout << "p[0] :" << svtHitTable[0].p[0] << endl;
757 // cout << "p[1] :" << svtHitTable[0].p[1] << endl;
758 // cout << "p[2] :" << svtHitTable[0].p[2] << endl;
759 
760 // cout << "Ftpc Hit Table Examples:" << endl;
761 // cout << "p[0] :" << ftpHitTable[0].p[0] << endl;
762 // cout << "p[1] :" << ftpHitTable[0].p[1] << endl;
763 // cout << "p[2] :" << ftpHitTable[0].p[2] << endl;
764 
765 // cout << "Rich Hit Table Examples:" << endl;
766 // cout << "p[0] :" << rchHitTable[0].p[0] << endl;
767 // cout << "p[1] :" << rchHitTable[0].p[1] << endl;
768 // cout << "p[2] :" << rchHitTable[0].p[2] << endl;
769 
770  // Ok, now we have the g2t tables for this event, now we can create the
771  // StMcEvent with them.
772 
773  // Now Here goes the scheme Mike Lisa and I cooked up
774 
775  //______________________________________________________________________
776  // Step 1 - fill the StMcEvent, already created in the header file
777 
778  if (eventTable)
779  mCurrentMcEvent = new StMcEvent(eventTable);
780  else {
781  gMessMgr->Warning() << "StMcEventMaker::Make(): g2t_event Table not found. Using default constructor." << endm;
782  mCurrentMcEvent = new StMcEvent;
783  }
784 
785  if (mCurrentMcEvent) {
786  if (Debug()) cout << "**** Created new StMcEvent, Event No. " << mCurrentMcEvent->eventNumber() << endl;
787  }
788  else {
789  gMessMgr->Warning() << "Could not create StMcEvent! Exit from StMcEventMaker." << endm;
790  return kStWarn;
791  }
792  AddData(mCurrentMcEvent);
793  //______________________________________________________________________
794  // Step 2 - Fill Vertices - we do not fill parent/daughters until Step 3
795 
796 
797  vector<vertexFlag> vtemp(NVertices); // Temporary array for Step 3
798 
799  if (Debug()>=1) cout << "Preparing to process and fill VERTEX information ....." << endl;
800  StMcVertex* v = 0;
801 
802 
803  // First vertex is PRIMARY
804 
805  v = new StMcVertex(&(vertexTable[0]));
806  mCurrentMcEvent->vertices().push_back(v);
807  vtemp[vertexTable[0].id - 1].vtx = v;
808  vtemp[vertexTable[0].id - 1].primaryFlag = 1;
809  mCurrentMcEvent->setPrimaryVertex(v);
810 
811  StThreeVectorF primVertexPos = v->position();
812 
813  StThreeVectorF testVertexPos;
814  int nThrownVertices = 0;
815  for (long ivtx=1; ivtx<NVertices; ivtx++)
816  {
817  v = new StMcVertex(&(vertexTable[ivtx]));
818 
819  // get the position of the current vertex
820  testVertexPos = v->position();
821 
822  if (vertexTable[ivtx].eg_label == 0 ||
823  abs(primVertexPos - testVertexPos) > vertexCut ) {
824  // GEANT vertex or (generator vertex that satisfies cut) ...
825  mCurrentMcEvent->vertices().push_back(v); // adds vertex v to master collection
826  vtemp[vertexTable[ivtx].id - 1].primaryFlag = 0;
827  vtemp[vertexTable[ivtx].id - 1].vtx = v;
828  }
829  else { // These "vertices" are the same as primary, so flag them
830  nThrownVertices++;
831  vtemp[vertexTable[ivtx].id - 1].primaryFlag = 1;
832 
833  delete v;
834  vtemp[vertexTable[ivtx].id - 1].vtx = mCurrentMcEvent->primaryVertex();
835  }
836  }
837  if (nThrownVertices)
838  gMessMgr->Warning() << "StMcEventMaker::Make(): Throwing " << nThrownVertices
839  << " that are the same as the primary vertex." << endm;
840 
841  //______________________________________________________________________
842  // Step 3 - Fill Tracks - we do not fill associated hits until Step 4
843 
844  size_t usedTracksG2t = 0;
845  long NGeneratorTracks = (particleTablePointer) ? particleTablePointer->GetNRows() : 0;
846  size_t usedTracksEvGen = 0;
847  ttemp.resize(NTracks);
848  ttempParticle.resize(NGeneratorTracks);
849  if (Debug()>=1) cout << "Preparing to process and fill TRACK information ....." << endl;
850  StMcTrack* egTrk = 0;
851  size_t nParticlesInBothTables = 0;
852  if (Debug()>=1) cout << "Event Generator Tracks..." << endl;
853 
854  // The filling of the event generator track assumes that if we encounter a particle that
855  // has a mother, the mother should ALREADY HAVE BEEN CREATED, i.e. that the mother indices
856  // of the particles in the particle table is never more than the current index.
857 
858  long motherIndex = -1; // Set it to some unused number.
859  {for (long gtrk=0; gtrk<NGeneratorTracks; gtrk++) {
860  // if (particleTable[gtrk].isthep > 3) continue; // skip comment fields
861  egTrk = new StMcTrack(&(particleTable[gtrk]));
862  egTrk->setEventGenLabel(gtrk+1);
863  egTrk->setPrimary(0);
864  ttempParticle[gtrk] = egTrk;
865  mCurrentMcEvent->tracks().push_back(egTrk); // adds track egTrk to master collection
866  usedTracksEvGen++;
867 
868  }} // Generator Tracks Loop
869 
870  StMcTrack* t = 0;
871  long iStartVtxId = 0;
872  long iStopVtxId = 0;
873  long iItrmdVtxId = 0;
874 
875  int nThrownTracks = 0;
876  if (Debug()>=1) cout << "g2t Tracks..." << endl;
877 
878  {for (long itrk=0; itrk<NTracks; itrk++) {
879  iStopVtxId = (trackTable[itrk].stop_vertex_p) - 1;
880 
881  if (iStopVtxId >= 0) {
882  if (vtemp[iStopVtxId].primaryFlag == 1) {
883 
884  nThrownTracks++;
885  continue; // This skips until the next itrk
886 
887  }
888  }
889 // Fix(hack) garbage (VP)
890  if (trackTable[itrk].e<trackTable[itrk].ptot)
891  trackTable[itrk].ptot=trackTable[itrk].e;
892 // Fix(hack) tracks with garbage geand id(VP)
893  if (trackTable[itrk].ge_pid<0) trackTable[itrk].ge_pid=0;
894  if (trackTable[itrk].ge_pid>0xffff) trackTable[itrk].ge_pid=0;
895 
896  t = new StMcTrack(&(trackTable[itrk]));
897  usedTracksG2t++;
898  ttemp[ trackTable[itrk].id - 1 ] = t; // This we do for all accepted tracks
899 
900 
901  mCurrentMcEvent->tracks().push_back(t); // adds track t to master collection
902 
903  // point track to its stop vertex,
904  // and tell stop vertex that this is its parent
905  if (iStopVtxId >= 0) {
906  t->setStopVertex(vtemp[iStopVtxId].vtx);
907  vtemp[iStopVtxId].vtx->setParent(t);
908  }
909  //cout << "Established relation btw track & STOP vertex" << endl;
910 
911  // point track to its parent vertex,
912  // and tell parent vertex that this is its daughter
913 
914  iStartVtxId = trackTable[itrk].start_vertex_p - 1;
915 
916  v = vtemp[iStartVtxId].vtx; // This should already know the right vertex.
917 
918  t->setStartVertex(v);
919  t->setPrimary(t->startVertex() == mCurrentMcEvent->primaryVertex() ? kTRUE : kFALSE);
920  v->addDaughter(t);
921  //cout << "Established relation btw track & START vertex" << endl;
922 
923  // now fill track's intermediate vertex collection,
924  // and tell those vertices their parents
925 
926  iItrmdVtxId = (trackTable[itrk].itrmd_vertex_p) - 1;
927 
928  if (iItrmdVtxId >= 0) {
929  t->intermediateVertices().push_back(vtemp[iItrmdVtxId].vtx);
930 
931  vtemp[iItrmdVtxId].vtx->setParent(t);
932 
933  // follow the "linked list" of g2t_vertex table to get the rest
934 
935  while(vertexTable[iItrmdVtxId].next_itrmd_p != 0) {
936  iItrmdVtxId = (vertexTable[iItrmdVtxId].next_itrmd_p) - 1;
937  t->intermediateVertices().push_back(vtemp[iItrmdVtxId].vtx);
938  vtemp[iItrmdVtxId].vtx->setParent(t);
939  }
940 
941 
942  } // Intermediate vertices
943 
944  // Look in the particle table
945  // for particles from event generator
946  long iEventGeneratorLabel = (trackTable[itrk].eg_label) - 1;
947  if (iEventGeneratorLabel >=0 ) {
948 
949  // Now make sure that this track is really from the table,
950  // When embedding, the particle got an eg_label = 99999 even
951  // though there was only one entry in the particle table.
952  if (iEventGeneratorLabel < NGeneratorTracks) {
953  // Track should already be loaded from the particle table
954  // i.e. t & ttempParticle[iEventGeneratorLabel] are the same tracks,
955  // obtained from different tables.
956  // We should rather keep the one in the g2t table, but we
957  // need to keep the information of its parentage.
958  nParticlesInBothTables++;
959  if (Debug()>=2) {
960  if (particleTable[iEventGeneratorLabel].jmohep[0] && !(ttempParticle[particleTable[iEventGeneratorLabel].jmohep[0]])) {
961  cout << "There should be a parent and there isn't one!\n";
962  PR(iEventGeneratorLabel);
963  PR(particleTable[iEventGeneratorLabel].jmohep[0]);
964  PR(ttempParticle[particleTable[iEventGeneratorLabel].jmohep[0]]);
965 
966  }
967  }
968  if (particleTable[iEventGeneratorLabel].jmohep[0])
969  t->setParent(ttempParticle[particleTable[iEventGeneratorLabel].jmohep[0]]);
970  StMcTrackIterator trkToErase = find (mCurrentMcEvent->tracks().begin(),
971  mCurrentMcEvent->tracks().end(),
972  ttempParticle[iEventGeneratorLabel]);
973 //??????????????????Why delete(VP)????
974  delete *trkToErase; // if we delete using the iterator, deleting should be done before erasing!
975  mCurrentMcEvent->tracks().erase(trkToErase);
976 
977  ttempParticle[iEventGeneratorLabel] = t;
978  }
979 
980  }
981  else {
982  // Track from GEANT, use next_parent_p to get to the parent
983  // track. Use the same scheme as for the particle table.
984  motherIndex = trackTable[itrk].next_parent_p;
985  if ((motherIndex > 0) && (motherIndex <= NTracks)) {
986  if (motherIndex > itrk+1) {
987  if (Debug()) {
988  gMessMgr->Warning()
989  << "Wrong ordering! Track " << itrk+1 << "from particle table: "
990  << "Can't assign mother track " << motherIndex
991  << "because it has not been created yet!" << endm;
992  }
993  }
994  else {t->setParent(ttemp[motherIndex-1]);}
995  } }
996 
997  }} // Track loop
998  {for (long gtrk=0; gtrk<NGeneratorTracks; gtrk++) {
999  // Find Mother...
1000  motherIndex = particleTable[gtrk].jmohep[0];
1001  if ((motherIndex > 0) && (motherIndex <= NGeneratorTracks)) {
1002  if (motherIndex > gtrk+1) {
1003  if (Debug()) {
1004  gMessMgr->Warning()
1005  << "Wrong ordering! Track " << gtrk+1 << " from particle table: "
1006  << "Can't assign mother track " << motherIndex
1007  << " to track with index " << gtrk << endm;
1008  }
1009  }
1010  else ttempParticle[gtrk]->setParent(ttempParticle[motherIndex-1]);
1011  if (Debug()>=2) {
1012  cout << "Particle table (generator) track " << gtrk << ", key " << ttempParticle[gtrk]->key() << endl;
1013  cout << "Mother Index-1 (off-by-1) " << motherIndex-1 << endl;
1014  cout << "PDG ID of generator track " << particleTable[gtrk].idhep << endl;
1015  cout << "PDG ID of mother track " << particleTable[motherIndex-1].idhep << endl;
1016  if (ttempParticle[gtrk]->particleDefinition())
1017  cout << "particle " << ttempParticle[gtrk]->particleDefinition()->name() << endl;
1018  if (ttempParticle[gtrk]->parent() && ttempParticle[gtrk]->parent()->particleDefinition())
1019  cout << "parent " << ttempParticle[gtrk]->parent()->particleDefinition()->name() << endl;
1020 
1021  if (motherIndex && !(ttempParticle[gtrk]->parent())) {
1022  cout << "Error in assigning parent to particle table!\n There should be a parent and there isn't one!\n";
1023  PR(particleTable[gtrk].jmohep[0]);
1024  PR(ttempParticle[gtrk]->parent());
1025  }
1026  }
1027  }
1028  }}
1029  if (nThrownTracks)
1030  gMessMgr->Warning() << "StMcEventMaker::Make(): Throwing " << nThrownTracks
1031  << " whose stop vertex is the same as primary vertex." << endm;
1032  if (Debug()>=2) {
1033  // Check the whole ttempParticle for entries with problems
1034  for (long gtrk=0; gtrk<NGeneratorTracks; gtrk++)
1035  if (ttempParticle[gtrk]->parent() && ttempParticle[gtrk]->parent() != ttempParticle[particleTable[gtrk].jmohep[0]-1]) {
1036  cout << "The indexing got screwed up!" << endl;
1037  PR(ttempParticle[gtrk]->eventGenLabel());
1038  PR(ttempParticle[gtrk]->key());
1039  PR(ttempParticle[gtrk]->parent());
1040  PR(ttempParticle[particleTable[gtrk].jmohep[0]-1]);
1041  if (ttempParticle[gtrk]->particleDefinition()) cout << "particle " << ttempParticle[gtrk]->particleDefinition()->name() << endl;
1042  if (ttempParticle[gtrk]->parent() && ttempParticle[gtrk]->parent()->particleDefinition()) cout << "parent " << ttempParticle[gtrk]->parent()->particleDefinition()->name() << endl;
1043 
1044  }
1045  cout << "Used tracks from g2t_track table: " << usedTracksG2t << endl;
1046  cout << "Avail. tracks from g2t_track table: " << NTracks << endl;
1047  cout << "Used tracks from particle table: " << usedTracksEvGen << endl;
1048  cout << "Avail. tracks from particle table: " << NGeneratorTracks << endl;
1049  cout << "Tracks appearing in both tables : " << nParticlesInBothTables << endl;
1050  cout << "Total tracks in StMcEvent : " << mCurrentMcEvent->tracks().size() << endl;
1051  }
1052  vtemp.clear();
1053  ttempParticle.clear();
1054 
1055  //______________________________________________________________________
1056  // Step 4 - Fill Hits
1057 
1058  if (Debug()) cout << "Preparing to process and fill HIT information ....." << endl;
1059 
1060 
1061  //
1062  // TPC Hits
1063  //
1064  if (doUseTpc) {
1065  if (g2t_tpc_hitTablePointer) {
1066  StMcTpcHit* th = 0;
1067  long NHits = g2t_tpc_hitTablePointer->GetNRows();
1068  long nBadVolId = 0;
1069  long nPseudoPadrow = 0;
1070  long ihit;
1071  for(ihit=0; ihit<NHits; ihit++) {
1072 #if 0 /* keep all tpc hits => Inner TPC sector upgrade */
1073  if (tpcHitTable[ihit].volume_id < 101 || tpcHitTable[ihit].volume_id > 2472) {
1074  if (tpcHitTable[ihit].volume_id <= 202472 &&
1075  tpcHitTable[ihit].volume_id > 2472) nPseudoPadrow++;
1076  else nBadVolId++;
1077  continue;
1078  }
1079 #endif
1080  // g2t_tpc_hitTablePointer->Print(ihit,1);
1081  th = new StMcTpcHit(&tpcHitTable[ihit]);
1082  // cout << "McTpcHit\t" << ihit << *th << endl;
1083  if(!mCurrentMcEvent->tpcHitCollection()->addHit(th)) {// adds hit th to collection
1084  nBadVolId++;
1085  delete th;
1086  th = 0;
1087  continue;
1088  }
1089  // point hit to its parent and add it to collection
1090  // of the appropriate track
1091  AddHit2Track(tpc,Tpc);
1092  } // hit loop
1093  if (Debug()) {
1094  cout << "Filled " << mCurrentMcEvent->tpcHitCollection()->numberOfHits() << " TPC Hits" << endl;
1095  cout << "Found " << nPseudoPadrow << " Hits in Pseudo-Padrows." << endl;
1096  if (nBadVolId) {gMessMgr->Warning() << "StMcEventMaker::Make(): cannot store " << nBadVolId
1097  << " TPC hits, wrong Volume Id." << endm;}
1098  }
1099  // Sort the hits
1100  for (unsigned int iSector=0;
1101  iSector<mCurrentMcEvent->tpcHitCollection()->numberOfSectors(); iSector++)
1102  for (unsigned int iPadrow=0;
1103  iPadrow<mCurrentMcEvent->tpcHitCollection()->sector(iSector)->numberOfPadrows();
1104  iPadrow++) {
1105  StSPtrVecMcTpcHit& tpcHits = mCurrentMcEvent->tpcHitCollection()->sector(iSector)->padrow(iPadrow)->hits();
1106  if (Debug() > 2) {
1107  Int_t nhits = tpcHits.size();
1108  cout << "Tpc hits before sort" << endl;
1109  for (int i = 0; i < nhits; i++) {
1110  cout << *(tpcHits[i]) << endl;
1111  }
1112  }
1113  sort (tpcHits.begin(), tpcHits.end(), compMcHit() );
1114  if (Debug() > 2) {
1115  Int_t nhits = tpcHits.size();
1116  cout << "Tpc hits after sort" << endl;
1117  for (int i = 0; i < nhits; i++) {
1118  cout << *(tpcHits[i]) << endl;
1119  }
1120  }
1121 
1122  }
1123  } // pointer exists
1124  else {
1125  if (Debug()) cout << "No TPC Hits in this event" << endl;
1126  }
1127  } // doUseTpc
1128 
1129  //
1130  // SVT Hits
1131  //
1132  if (doUseSvt) {
1133  if (g2t_svt_hitTablePointer) {
1134  StMcSvtHit* th = 0;
1135  long NHits = g2t_svt_hitTablePointer->GetNRows();
1136  long nBadVolId = 0;
1137  long ihit;
1138  for(ihit=0; ihit<NHits; ihit++) {
1139  if (svtHitTable[ihit].volume_id < 1101 || svtHitTable[ihit].volume_id > 9000) {
1140  nBadVolId++;
1141  continue;
1142  }
1143  th = new StMcSvtHit(&svtHitTable[ihit]);
1144  if (!mCurrentMcEvent->svtHitCollection()->addHit(th)) {// adds hit th to collection
1145  nBadVolId++;
1146  delete th; // If the hit couldn't be assigned, delete it.
1147  th = 0;
1148  continue;
1149  }
1150 
1151  // point hit to its parent and add it to collection
1152  // of the appropriate track
1153  AddHit2Track(svt,Svt);
1154  }
1155  if (Debug()) {
1156  cout << "Filled " << mCurrentMcEvent->svtHitCollection()->numberOfHits() << " SVT Hits" << endl;
1157  cout << "Nhits, " << NHits << " rows from table" << endl;
1158  if (nBadVolId)
1159  gMessMgr->Warning() << "StMcEventMaker::Make(): cannot store " << nBadVolId
1160  << " SVT hits, wrong Volume Id." << endm;
1161  }
1162  // Sort the hits
1163  for (unsigned int iBarrel=0;
1164  iBarrel<mCurrentMcEvent->svtHitCollection()->numberOfBarrels(); iBarrel++)
1165  for (unsigned int iLadder=0;
1166  iLadder<mCurrentMcEvent->svtHitCollection()->barrel(iBarrel)->numberOfLadders();
1167  iLadder++)
1168  for (unsigned int iWafer=0;
1169  iWafer<mCurrentMcEvent->svtHitCollection()->barrel(iBarrel)->ladder(iLadder)->numberOfWafers();
1170  iWafer++) {
1171  StSPtrVecMcSvtHit& svtHits = mCurrentMcEvent->svtHitCollection()->barrel(iBarrel)->ladder(iLadder)->wafer(iWafer)->hits();
1172  sort (svtHits.begin(), svtHits.end(), compMcHit() );
1173 
1174  }
1175 
1176  }
1177  else {
1178  if (Debug()) cout << "No SVT Hits in this event" << endl;
1179  }
1180  } // do use svt
1181 
1182  //
1183  // SSD Hits
1184  //
1185  if (doUseSsd) {
1186  if (g2t_ssd_hitTablePointer) {
1187  StMcSsdHit* th = 0;
1188  long NHits = g2t_ssd_hitTablePointer->GetNRows();
1189  long nBadVolId = 0;
1190  long ihit;
1191  for(ihit=0; ihit<NHits; ihit++) {
1192  if (ssdHitTable[ihit].volume_id < 7000 || ssdHitTable[ihit].volume_id > 9000) {
1193  nBadVolId++;
1194  continue;
1195  }
1196  th = new StMcSsdHit(&ssdHitTable[ihit]);
1197  if (!mCurrentMcEvent->ssdHitCollection()->addHit(th)) {// adds hit th to collection
1198  nBadVolId++;
1199  delete th; // If the hit couldn't be assigned, delete it.
1200  th = 0;
1201  continue;
1202  }
1203 
1204  // point hit to its parent and add it to collection
1205  // of the appropriate track
1206  AddHit2Track(ssd,Ssd);
1207  }
1208  if (Debug()) {
1209  cout << "Filled " << mCurrentMcEvent->ssdHitCollection()->numberOfHits() << " SSD Hits" << endl;
1210  cout << "Nhits, " << NHits << " rows from table" << endl;
1211  if (nBadVolId)
1212  gMessMgr->Warning() << "StMcEventMaker::Make(): cannot store " << nBadVolId
1213  << " SSD hits, wrong Volume Id." << endm;
1214  }
1215 
1216  }
1217  else {
1218  if (Debug()) cout << "No SSD Hits in this event" << endl;
1219  }
1220  } // do use ssd
1221 
1222 
1223  //
1224  // FTPC Hits
1225  //
1226  if (doUseFtpc) {
1227  if (g2t_ftp_hitTablePointer) {
1228  StMcFtpcHit* th = 0;
1229  long NHits = g2t_ftp_hitTablePointer->GetNRows();
1230  long nBadVolId = 0;
1231  long ihit;
1232  for(ihit=0; ihit<NHits; ihit++) {
1233  // old volume id scheme, 101 - 209
1234  // changed in oct 2003
1235  // planes are included, valid volume id's are from 1000 - 2906
1236  // keep the checks from 101 to 2906 for backward compatibility.
1237  if (ftpHitTable[ihit].volume_id < 101 || ftpHitTable[ihit].volume_id > 2906) {
1238  nBadVolId++;
1239  continue;
1240  }
1241 
1242  th = new StMcFtpcHit(&ftpHitTable[ihit]);
1243 
1244  if (!mCurrentMcEvent->ftpcHitCollection()->addHit(th)){ // adds hit th to collection
1245  nBadVolId++;
1246  delete th;
1247  th = 0;
1248  continue;
1249  }
1250  // point hit to its parent and add it to collection
1251  // of the appropriate track
1252  AddHit2Track(ftp,Ftpc);
1253  }
1254  if (Debug()) {
1255  cout << "Filled " << mCurrentMcEvent->ftpcHitCollection()->numberOfHits() << " FTPC Hits" << endl;
1256  if (nBadVolId)
1257  gMessMgr->Warning() << "StMcEventMaker::Make(): cannot store " << nBadVolId
1258  << " FTPC hits, wrong Volume Id." << endm;
1259  }
1260  // Sort the hits
1261  for (unsigned int iPlane=0;
1262  iPlane<mCurrentMcEvent->ftpcHitCollection()->numberOfPlanes(); iPlane++) {
1263  StSPtrVecMcFtpcHit& ftpcHits = mCurrentMcEvent->ftpcHitCollection()->plane(iPlane)->hits();
1264  sort (ftpcHits.begin(), ftpcHits.end(), compMcFtpcHit() );
1265 
1266  }
1267  }
1268  else {
1269  if (Debug()) cout << "No FTPC Hits in this event" << endl;
1270  }
1271  }// do use ftpc
1272  AddHits(rch,rich,Rich);
1273  AddHits(ctb,ctb,Ctb);
1274  AddHits(tof,tof,Tof);
1275  AddHits(tfr,tof,Tof);
1276  AddHits(mtd,mtd,Mtd);
1277  AddHits(pix,pxl,Pxl);
1278  AddHits(ist,ist,Ist);
1279  AddHits(fgt,fgt,Fgt);
1280  AddHits(etr,etr,Etr);
1281 
1282  // BEMC and BPRS Hits
1283  if (doUseBemc) fillBemc(g2t_emc_hitTablePointer);
1284 
1285  // BSMDE and BSMDP Hits
1286  if (doUseBsmd) fillBsmd(g2t_smd_hitTablePointer);
1287 
1288  // EEMC and EPRS Hits, ESMDU & ESMDV Hits
1289  if (doUseEemc) fillEemc(g2t_eem_hitTablePointer,g2t_esm_hitTablePointer);
1290 
1291  // FPD Hits
1292  if (doUseFpd) fillFpd(g2t_fpd_hitTablePointer);
1293 
1294  // FSC Hits
1295  if (doUseFsc) fillFsc(g2t_fsc_hitTablePointer);
1296 
1297  ttemp.clear();
1298 
1299  //_______________________________________________________________
1300  // At this point StMcEvent should be loaded.
1301 
1302  }
1303  }
1304 
1305 
1306  if (!g2t_vertexTablePointer)
1307  gMessMgr->Warning() << "StMcEventMaker: g2t_vertex Table Not found " << endm;
1308  if (!g2t_trackTablePointer)
1309  gMessMgr->Warning() << "StMcEventMaker: g2t_track Table Not found " << endm;
1310  if (!g2t_tpc_hitTablePointer)
1311  gMessMgr->Info() << "StMcEventMaker: g2t_tpc_hit Table Not found " << endm;
1312  if (!particleTablePointer)
1313  gMessMgr->Info() << "StMcEventMaker: particle Table Not found " << endm;
1314 
1315  if (doPrintEventInfo) printEventInfo();
1316  if (doPrintMemoryInfo) {
1317  StMemoryInfo::instance()->snapshot();
1318  StMemoryInfo::instance()->print();
1319  }
1320  if (doPrintCpuInfo) {
1321  timer.stop();
1322  cout << "CPU time for StMcEventMaker::Make(): "
1323  << timer.elapsedTime() << " sec\n" << endl;
1324  }
1325 
1326  return kStOK;
1327 
1328 }
1329 
1330 //_____________________________________________________________________________
1331 void StMcEventMaker::fillBemc(St_g2t_emc_hit* g2t_emc_hitTablePointer)
1332 {
1333  if (g2t_emc_hitTablePointer == 0) {
1334  if (Debug()) cout << "No BEMC and BPRS Hits in this event" << endl;
1335  return;
1336  }
1337 
1338  g2t_emc_hit_st* emcHitTable = g2t_emc_hitTablePointer->GetTable();
1339  StEmcGeom *geomBemc = StEmcGeom::getEmcGeom(1);
1340  int module, eta, sub, detector;
1341  float de;
1342  StMcTrack *tr;
1343  StMcCalorimeterHit *emchBemc, *emchBprs;
1344 
1345  StMcEmcHitCollection *bemcColl=mCurrentMcEvent->bemcHitCollection();
1346  StMcEmcHitCollection *bprsColl=mCurrentMcEvent->bprsHitCollection();
1347  long NHits = g2t_emc_hitTablePointer->GetNRows();
1348 
1349  for(long ihit=0; ihit<NHits; ihit++,emcHitTable++) {
1350 
1351  geomBemc->getVolIdBemc(emcHitTable->volume_id, module,eta,sub,detector); // Must check ??
1352 // cout << "hit " << ihit << endl;
1353 // cout << "volume id " << emcHitTable->volume_id << endl;
1354 // cout << "module " << module << endl;
1355 // cout << "eta " << eta << endl;
1356 // cout << "sub " << sub << endl;
1357 // cout << "detector " << detector << endl;
1358  if (emcHitTable->track_p <= 0 || emcHitTable->track_p > NTracks) continue;
1359  tr = ttemp[emcHitTable->track_p - 1];
1360  de = emcHitTable->de;
1361 
1362  if (detector == 1 || detector == 2) {
1363  emchBemc = new StMcCalorimeterHit(module,eta,sub,de, tr);
1364  emchBprs = 0; // For safety
1365  StMcEmcHitCollection::EAddHit bemcNew = bemcColl->addHit(emchBemc);
1366 
1367  if (bemcNew == StMcEmcHitCollection::kNew){
1368  tr->addBemcHit(emchBemc);
1369  if(detector == 2) emchBprs = new StMcCalorimeterHit(module,eta,sub,de, tr);
1370  }
1371  else if(bemcNew == StMcEmcHitCollection::kAdd){
1372  emchBprs = emchBemc;
1373  }
1374  else if(bemcNew == StMcEmcHitCollection::kErr){
1375  delete emchBemc;
1376  emchBemc = 0;
1377  gMessMgr->Warning()<<"<E> Bad hit in Bemc collection " << endm;
1378  }
1379  else { // Unused branch
1380  delete emchBemc;
1381  emchBemc = 0;
1382  emchBprs = 0;
1383  gMessMgr->Warning()<<"<E> Funny return value! EAddHit = " << static_cast<int>(bemcNew) <<endm;
1384  }
1385 
1386  if (detector == 2 && emchBprs) {
1387  StMcEmcHitCollection::EAddHit bprsNew = bprsColl->addHit(emchBprs);
1388  if (bprsNew == StMcEmcHitCollection::kNew) {
1389  tr->addBprsHit(emchBprs);
1390  }
1391  else {
1392  delete emchBprs;
1393  emchBprs = 0;
1394  }
1395  }
1396  else if(emchBprs) {
1397  delete emchBprs;
1398  emchBprs = 0;
1399  }
1400  }
1401  else {
1402  gMessMgr->Warning() << "<E> Bad EMC detector number " << detector << " volume_id "
1403  << emcHitTable->volume_id << " detector "<< detector << endm;
1404  }
1405  }
1406  if (Debug()) {
1407  cout << "Filled " << mCurrentMcEvent->bemcHitCollection()->numberOfHits() << " BEMC Hits" << endl;
1408  cout << "Filled " << mCurrentMcEvent->bprsHitCollection()->numberOfHits() << " BPRS Hits" << endl;
1409  }
1410 }
1411 
1412 //_____________________________________________________________________________
1413 void StMcEventMaker::fillBsmd(St_g2t_emc_hit* g2t_smd_hitTablePointer)
1414 {
1415  if (g2t_smd_hitTablePointer == 0) {
1416  if (Debug()) cout << "No BSMDE and BSMDP Hits in this event" << endl;
1417  return;
1418  }
1419 
1420  g2t_emc_hit_st* smdHitTable = g2t_smd_hitTablePointer->GetTable();
1421  StEmcGeom *geomBsmd = StEmcGeom::getEmcGeom(3);
1422  int module, eta, sub, detector;
1423  float de;
1424  StMcTrack *tr;
1425  StMcCalorimeterHit *emchBsmde, *emchBsmdp;
1426 
1427  StMcEmcHitCollection *bsmdeColl=mCurrentMcEvent->bsmdeHitCollection();
1428  StMcEmcHitCollection *bsmdpColl=mCurrentMcEvent->bsmdpHitCollection();
1429  long NHits = g2t_smd_hitTablePointer->GetNRows();
1430  for(long ihit=0; ihit<NHits; ihit++,smdHitTable++) {
1431  geomBsmd->getVolIdBsmd(smdHitTable->volume_id, module,eta,sub,detector); // Must check ??
1432  if (smdHitTable->track_p <= 0 || smdHitTable->track_p > NTracks) continue;
1433  tr = ttemp[smdHitTable->track_p - 1];
1434  de = smdHitTable->de;
1435 
1436  if (detector == 3) {
1437  emchBsmde = new StMcCalorimeterHit(module,eta,sub,de, tr);
1438  StMcEmcHitCollection::EAddHit bsmdeNew = bsmdeColl->addHit(emchBsmde);
1439  if (bsmdeNew == StMcEmcHitCollection::kNew) {
1440  tr->addBsmdeHit(emchBsmde);
1441  }
1442  else {
1443  delete emchBsmde;
1444  emchBsmde = 0;
1445  }
1446  }
1447  else if (detector == 4) {
1448  emchBsmdp = new StMcCalorimeterHit(module,eta,sub,de, tr);
1449  StMcEmcHitCollection::EAddHit bsmdpNew = bsmdpColl->addHit(emchBsmdp);
1450  if (bsmdpNew == StMcEmcHitCollection::kNew) {
1451  tr->addBsmdpHit(emchBsmdp);
1452  }
1453  else {
1454  delete emchBsmdp;
1455  emchBsmdp = 0;
1456  }
1457  }
1458  else {
1459  gMessMgr->Warning() << "<E> Bad SMD detector number " << detector << " volume_id "
1460  << smdHitTable->volume_id << " detector "<< detector << endm;
1461  }
1462  }
1463  if (Debug()) {
1464  cout << "Filled " << mCurrentMcEvent->bsmdeHitCollection()->numberOfHits() << " BSMDE Hits" << endl;
1465  cout << "Filled " << mCurrentMcEvent->bsmdpHitCollection()->numberOfHits() << " BSMDP Hits" << endl;
1466  }
1467 }
1468 
1469 //_____________________________________________________________________________
1470 void StMcEventMaker::fillEemc(St_g2t_emc_hit* g2t_tile, St_g2t_emc_hit* g2t_smd){
1471  if (Debug()) {
1472  gMessMgr->Info() << GetName() << "fillEemc() called" << endm;
1473  }
1474  EEmcMCData mEemcGeant;
1475  mEemcGeant.unpackGeantHits(g2t_tile, g2t_smd);
1476  if (Debug()>1) {
1477  mEemcGeant.print();
1478  }
1479 
1480  StMcEmcHitCollection *eemcColl=mCurrentMcEvent->eemcHitCollection();
1481  StMcEmcHitCollection *eprsColl=mCurrentMcEvent->eprsHitCollection();
1482  StMcEmcHitCollection *esmduColl=mCurrentMcEvent->esmduHitCollection();
1483  StMcEmcHitCollection *esmdvColl=mCurrentMcEvent->esmdvHitCollection();
1484 
1485  if (!eemcColl || !eprsColl || !esmduColl || !esmdvColl) {
1486  gMessMgr->Warning()<<GetName() <<"::fillEemc(), sth wrong with StMcEEmcCollection,\n skip EEMC GEANT hits"<<endm;
1487  return;
1488  }
1489 
1490 
1491  int nHit;
1492  const EEmcMCHit *h = mEemcGeant.getGeantHits(nHit);
1493  for(Int_t i=0; i<nHit; i++,h++) {
1494  int detId=h->detector;
1495  if (h->track_p <= 0 || h->track_p > NTracks) continue;
1496  StMcTrack *tr = ttemp[h->track_p - 1];
1497  int Beta=0,Bsub=0,Bmodule=0; // barrel indexes
1498  /* barrel indexes are used to lable eemc hits
1499  B-names are misleading but preserved for consistency
1500  The mapping must follow the exactly the scheme as at
1501  /StRoot/StEEmcSimulatorMaker/StEEmcFastMaker::mEE2ST()
1502  Otherwise internal indexing in EmcCollection can overwrite
1503  adrresses and/or association will be broken. Jan Balewski
1504  */
1505  Bmodule=h->sector;
1506  int off=0; // used only for pres1,pres2, and postshower
1507  StMcCalorimeterHit * stMcHit=0;
1508  StMcEmcHitCollection::EAddHit addRet=StMcEmcHitCollection::kErr;
1509  if (Debug()>1) printf("StMcAdd:detID=%d iHit=%d de=%g\n",detId,i,h->de);
1510 
1511  switch(detId) { // covers all 6 layers of EEMCS
1512 
1513  case EEmcMCData::kEEmcMCTowerId:
1514  Beta=h->tower.eta;
1515  Bsub=h->tower.ssec;
1516  stMcHit = new StMcCalorimeterHit(Bmodule,Beta,Bsub,h->de,tr);
1517  addRet = eemcColl->addHit(stMcHit);
1518  if(addRet==StMcEmcHitCollection::kNew) tr->addEemcHit(stMcHit);
1519  break;
1520 
1521  // pre/post hits are stored in the same container
1522  case EEmcMCData::kEEmcMCPostShowerId: off++;
1523  case EEmcMCData::kEEmcMCPreShower2Id: off++;
1524  case EEmcMCData::kEEmcMCPreShower1Id:
1525  Beta=h->tower.eta;
1526  Bsub=h->tower.ssec +5*off;
1527  stMcHit = new StMcCalorimeterHit(Bmodule,Beta,Bsub,h->de,tr);
1528  addRet = eprsColl->addHit(stMcHit);
1529  if(addRet==StMcEmcHitCollection::kNew) tr->addEprsHit(stMcHit);
1530  break;
1531 
1532  case EEmcMCData::kEEmcMCSmdUStripId:
1533  Beta=h->strip;
1534  Bsub=1;
1535  stMcHit = new StMcCalorimeterHit(Bmodule,Beta,Bsub,h->de,tr);
1536  addRet = esmduColl->addHit(stMcHit);
1537  if(addRet==StMcEmcHitCollection::kNew) tr->addEsmduHit(stMcHit);
1538  break;
1539 
1540  case EEmcMCData::kEEmcMCSmdVStripId:
1541  Beta=h->strip;
1542  Bsub=1;
1543  stMcHit = new StMcCalorimeterHit(Bmodule,Beta,Bsub,h->de,tr);
1544  addRet = esmdvColl->addHit(stMcHit);
1545  if(addRet==StMcEmcHitCollection::kNew) tr->addEsmdvHit(stMcHit);
1546  break;
1547  default:
1548  gMessMgr->Warning()<<GetName() <<"::fillEemc(), wrong detectorId=" << detId << " from EEmcMCHit. iHit="<<i<<"\n It is fatal - bug in the code, fix it, JB"<<endm;
1549  assert(1==2);
1550  break;
1551  }
1552 
1553  // garbage collector
1554  switch (addRet ){
1555  case StMcEmcHitCollection::kNew: break;
1556  case StMcEmcHitCollection::kAdd: delete stMcHit; break; // delete used but not needed anymore hit
1557  case StMcEmcHitCollection::kErr:
1558  gMessMgr->Warning()<<"<E> Bad hit in Eemc collection" << endm;
1559  delete stMcHit;
1560  break;
1561  default:
1562  gMessMgr->Warning()<<"<E> Funny return value! EAddHit = " << static_cast<int>(addRet) << endm;
1563  delete stMcHit;
1564  break;
1565  }
1566  }// end of loop over GEANT hits
1567  if (Debug()) gMessMgr->Info()<<GetName() <<"::fillEemc() done, nHit="<<nHit<<endm;
1568 }
1569 
1570 //_____________________________________________________________________________
1571 void StMcEventMaker::fillFpd(St_g2t_emc_hit* g2t_fpd_hitTablePointer)
1572 {
1573  if (!g2t_fpd_hitTablePointer) {
1574  if (Debug()) cout << "No FPD Hits in this event" << endl;
1575  return;
1576  }
1577 
1578  g2t_emc_hit_st* fpdHitTable = g2t_fpd_hitTablePointer->GetTable();
1579  StMcEmcHitCollection* fpdColl = mCurrentMcEvent->fpdHitCollection();
1580 
1581  for (int iHit = 0; iHit < g2t_fpd_hitTablePointer->GetNRows(); ++iHit) {
1582  g2t_emc_hit_st& hit = fpdHitTable[iHit];
1583  // volume_id = ew*10000+nstb*1000+ch
1584  int volume_id = hit.volume_id;
1585  int ch = volume_id % 1000;
1586  volume_id /= 1000;
1587  int nstb = volume_id % 10;
1588  int ew = volume_id / 10;
1589  if (hit.track_p <= 0 || hit.track_p > NTracks) continue;
1590  StMcTrack* track = ttemp[hit.track_p - 1];
1591  // Store ew in module, nstb in sub, and ch in eta
1592  StMcCalorimeterHit* fpdHit = new StMcCalorimeterHit(ew,ch,nstb,hit.de,track);
1593  StMcEmcHitCollection::EAddHit fpdNew = fpdColl->addHit(fpdHit);
1594  if (fpdNew == StMcEmcHitCollection::kNew) {
1595  track->addFpdHit(fpdHit);
1596  } else {
1597  delete fpdHit; fpdHit = 0;
1598  }
1599  }
1600 
1601  if (Debug()) cout << "Filled " << mCurrentMcEvent->fpdHitCollection()->numberOfHits() << " FPD Hits" << endl;
1602 }
1603 
1604 //_____________________________________________________________________________
1605 void StMcEventMaker::fillFsc(St_g2t_emc_hit* g2t_fsc_hitTablePointer)
1606 {
1607  if (!g2t_fsc_hitTablePointer) {
1608  if (Debug()) cout << "No FSC Hits in this event" << endl;
1609  return;
1610  }
1611 
1612  g2t_emc_hit_st* fscHitTable = g2t_fsc_hitTablePointer->GetTable();
1613  StMcEmcHitCollection* fscColl = mCurrentMcEvent->fscHitCollection();
1614 
1615  for (int iHit = 0; iHit < g2t_fsc_hitTablePointer->GetNRows(); ++iHit) {
1616  g2t_emc_hit_st& hit = fscHitTable[iHit];
1617 // volume_id = ew*10000+nstb*1000+ch
1618  int volume_id = hit.volume_id;
1619 // std::cout << "FSC vol_id: " << volume_id << "\n";
1620  int module = 1; // only one FSC exists at the moment :)
1621  int eta = floor(float(volume_id) / float(80)); // X coordinate
1622  int sub = volume_id % 80; // Y coordinate
1623  if (hit.track_p <= 0 || hit.track_p > NTracks) continue;
1624  StMcTrack* track = ttemp[hit.track_p - 1];
1625  // Store ew in module, nstb in sub, and ch in eta
1626  StMcCalorimeterHit* fscHit = new StMcCalorimeterHit(module,eta,sub,hit.de,track);
1627  StMcEmcHitCollection::EAddHit fscNew = fscColl->addHit(fscHit);
1628  if (fscNew == StMcEmcHitCollection::kNew) {
1629  track->addFscHit(fscHit);
1630  } else {
1631  delete fscHit; fscHit = 0;
1632  }
1633  }
1634 
1635  if (Debug()) cout << "Filled " << mCurrentMcEvent->fscHitCollection()->numberOfHits() << " FSC Hits" << endl;
1636 }
1637 
1638 
1639 //_____________________________________________________________________________
1640 void StMcEventMaker::printEventInfo()
1641 {
1642  cout << "---------------------------------------------------------" << endl;
1643  cout << "StMcEvent at " << (void*) mCurrentMcEvent << endl;
1644  cout << "---------------------------------------------------------" << endl;
1645  if (! mCurrentMcEvent) return;
1646  cout << *mCurrentMcEvent << endl;
1647  mCurrentMcEvent->Print("");
1648 }
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Definition: tof.h:15
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
Definition: StMcTrack.hh:144
virtual Int_t Make()
Filling of all StMcEvent classes from g2t tables Transform all the data in the g2t tables into the co...
Bool_t doPrintMemoryInfo
lots of screen output
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776
virtual Int_t Finish()
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169