10#include "EmcSim/BesEmcHit.hh"
11#include "G4DigiManager.hh"
12#include "MdcSim/BesMdcHit.hh"
13#include "MucSim/BesMucHit.hh"
14#include "TofSim/BesTofHit.hh"
15#include "TruSim/BesSensitiveManager.hh"
16#include "TruSim/BesTruthTrack.hh"
17#include "TruSim/BesTruthVertex.hh"
23#include "CLHEP/Geometry/Point3D.h"
24#include "CLHEP/Vector/LorentzVector.h"
25#include "GaudiKernel/Bootstrap.h"
26#include "GaudiKernel/IDataProviderSvc.h"
27#include "GaudiKernel/ISvcLocator.h"
28#include "GaudiKernel/MsgStream.h"
29#include "GaudiKernel/RegistryEntry.h"
31#include "McTruth/DecayMode.h"
32#include "McTruth/EmcMcHit.h"
33#include "McTruth/MdcMcHit.h"
34#include "McTruth/MucMcHit.h"
35#include "McTruth/TofMcHit.h"
37#include "Identifier/EmcID.h"
38#include "Identifier/Identifier.h"
39#include "Identifier/MdcID.h"
40#include "Identifier/MucID.h"
41#include "Identifier/TofID.h"
43#include "EventModel/EventModel.h"
44#include "McTruth/McEvent.h"
47#include "GaudiKernel/SmartDataPtr.h"
50 m_DigiMan = G4DigiManager::GetDMpointer();
58 ISvcLocator* svcLocator = Gaudi::svcLocator();
59 StatusCode sc = svcLocator->service(
"EventDataSvc", m_evtSvc );
60 if ( sc.isFailure() ) G4cout <<
"Could not accesss EventDataSvc!" << G4endl;
63 m_evtSvc->findObject(
"/Event/MC", aMcEvent );
64 if ( aMcEvent == NULL )
67 sc = m_evtSvc->registerObject(
"/Event/MC", aMcEvent );
68 if ( sc != StatusCode::SUCCESS ) G4cout <<
"Could not register McEvent" << G4endl;
81 vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
82 G4int nTrack = trackList->size();
85 vector<BesTruthVertex*>* vertexList = sensitiveManager->
GetVertexList();
86 G4int nVertex = vertexList->size();
90 for (
int i = 0; i < nTrack - 1; i++ )
91 for (
int j = i + 1; j < nTrack; j++ )
92 if ( ( *trackList )[i]->GetIndex() > ( *trackList )[j]->GetIndex() )
94 track = ( *trackList )[i];
95 ( *trackList )[i] = ( *trackList )[j];
96 ( *trackList )[j] = track;
102 for (
int i = 0; i < nTrack; i++ )
104 track = ( *trackList )[i];
107 bool isPrimary =
false;
108 bool startPointFound =
false;
111 for (
int i = 0; i < nVertex; i++ )
113 vertex = ( *vertexList )[i];
117 startPointFound =
true;
123 if ( !startPointFound )
124 std::cout <<
"error in finding the start point of a track" << std::endl;
126 bool endPointFound =
false;
128 for (
int i = 0; i < nVertex; i++ )
130 vertex = ( *vertexList )[i];
139 HepLorentzVector initialMomentum(
140 track->
GetP4().x() / 1000., track->
GetP4().y() / 1000.,
141 track->
GetP4().z() / 1000., track->
GetP4().t() / 1000. );
143 HepLorentzVector initialPosition(
161 if ( track->
GetSource() ==
"FromGenerator" )
163 else if ( track->
GetSource() ==
"FromG4" )
175 HepLorentzVector finalPosition( vertex->
GetPosition().x() / 10.,
178 mcParticle->
finalize( finalPosition );
181 particleCol->push_back( mcParticle );
183 endPointFound =
true;
188 if ( !endPointFound )
196 HepLorentzVector initialMomentum(
197 track->
GetP4().x() / 1000., track->
GetP4().y() / 1000., track->
GetP4().z() / 1000.,
198 track->
GetP4().t() / 1000. );
199 HepLorentzVector initialPosition(
219 if ( track->
GetSource() ==
"FromGenerator" )
221 else if ( track->
GetSource() ==
"FromG4" )
230 particleCol->push_back( mcParticle );
237 SmartRefVector<Event::McParticle> primaryParticleCol;
238 Event::McParticleCol::iterator iter_particle;
239 for ( iter_particle = particleCol->begin(); iter_particle != particleCol->end();
243 if ( ( *iter_particle )->primaryParticle() )
246 primaryParticleCol.push_back( mcPart );
250 if ( primaryParticleCol.empty() ) std::cout <<
"no primary particle found!" << std::endl;
253 SmartRefVector<Event::McParticle>::iterator iter_primary;
254 for ( iter_primary = primaryParticleCol.begin(); iter_primary != primaryParticleCol.end();
257 if ( !( ( *iter_primary )->leafParticle() ) )
AddMother( ( *iter_primary ), particleCol );
261 StatusCode sc = m_evtSvc->registerObject(
"/Event/MC/McParticleCol", particleCol );
262 if ( sc != StatusCode::SUCCESS )
263 G4cout <<
"Could not register McParticle collection" << G4endl;
292 Event::McParticleCol::iterator
iter;
294 for (
iter = particleCol->begin();
iter != particleCol->end();
iter++ )
296 if ( currentParticle->
vertexIndex1() == ( *iter )->vertexIndex0() )
299 ( *iter )->setMother( currentParticle );
304 if ( !found ) std::cout <<
"AddMother: inconsistency was found!" << std::endl;
308 SmartDataPtr<DecayMode> decayMode( m_evtSvc,
"/Event/MC/DecayMode" );
314 int dm[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
316 StatusCode scDM = m_evtSvc->registerObject(
"/Event/MC/DecayMode", aDecayMode );
317 if ( scDM != StatusCode::SUCCESS ) G4cout <<
"Could not register DecayMode" << G4endl;
326 HCID = m_DigiMan->GetHitsCollectionID(
"BesMdcTruthCollection" );
331 G4int n_hit = HC->entries();
336 vector<BesMdcHit*>* vecHC = HC->GetVector();
337 for (
int i = 0; i < n_hit - 1; i++ )
338 for (
int j = i + 1; j < n_hit; j++ )
339 if ( ( *vecHC )[i]->GetTrackID() > ( *vecHC )[j]->GetTrackID() )
342 ( *vecHC )[i] = ( *vecHC )[j];
347 for ( G4int i = 0; i < n_hit; i++ )
354 aMdcMcHitCol->push_back( mdcMcHit );
360 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/MC/MdcMcHitCol", aMdcMcHitCol );
361 if ( scMdc != StatusCode::SUCCESS )
362 G4cout <<
"Could not register MDC McTruth collection" << G4endl;
392 HCID = m_DigiMan->GetHitsCollectionID(
"BesTofHitsList" );
397 G4int n_hit = HC->entries();
402 vector<BesTofHit*>* vecHC = HC->GetVector();
403 for (
int i = 0; i < n_hit - 1; i++ )
405 for (
int j = i + 1; j < n_hit; j++ )
407 if ( ( *vecHC )[i]->GetTrackIndex() > ( *vecHC )[j]->GetTrackIndex() )
410 ( *vecHC )[i] = ( *vecHC )[j];
417 for ( G4int i = 0; i < n_hit; i++ )
421 unsigned int barrel_ec = hit->
GetPartId();
426 unsigned int layer = 0;
437 if ( barrel_ec == 3 || barrel_ec == 4 )
439 unsigned int endcap = 0;
441 unsigned int strip = hit->
GetStrip();
442 if ( barrel_ec == 4 )
449 if ( barrel_ec >= 0 && barrel_ec <= 4 )
455 aTofMcHitCol->push_back( tofMcHit );
462 StatusCode scTof = m_evtSvc->registerObject(
"/Event/MC/TofMcHitCol", aTofMcHitCol );
463 if ( scTof != StatusCode::SUCCESS )
464 G4cout <<
"Could not register TOF McTruth collection" << G4endl;
501 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcTruthHitsList" );
506 G4int n_hit = HC->entries();
511 vector<BesEmcTruthHit*>* vecHC = HC->GetVector();
512 for (
int i = 0; i < n_hit - 1; i++ )
514 for (
int j = i + 1; j < n_hit; j++ )
516 if ( ( *vecHC )[i]->GetTrackIndex() > ( *vecHC )[j]->GetTrackIndex() )
519 ( *vecHC )[i] = ( *vecHC )[j];
525 for ( G4int i = 0; i < n_hit; i++ )
530 std::map<Identifier, double> hitMap;
531 std::map<Identifier, double>::const_iterator iHitMap;
533 for ( iHitMap = hit->
Begin(); iHitMap != hit->
End(); iHitMap++ )
534 { hitMap[iHitMap->first] = iHitMap->second; }
547 aEmcMcHitCol->push_back( emcMcHit );
555 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcHitsList" );
560 G4int n_hit = HC->entries();
565 vector<BesEmcHit*>* vecHC = HC->GetVector();
566 for (
int i = 0; i < n_hit - 1; i++ )
567 for (
int j = i + 1; j < n_hit; j++ )
568 if ( ( *vecHC )[i]->GetTrackIndex() > ( *vecHC )[j]->GetTrackIndex() )
571 ( *vecHC )[i] = ( *vecHC )[j];
578 for ( G4int i = 0; i < n_hit; i++ )
584 std::map<Identifier, double> hitMap;
590 aEmcMcHitCol->push_back( emcMcHit );
597 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/MC/EmcMcHitCol", aEmcMcHitCol );
598 if ( scEmc != StatusCode::SUCCESS )
599 G4cout <<
"Could not register EMC McTruth collection" << G4endl;
632 HCID = m_DigiMan->GetHitsCollectionID(
"BesMucHitsList" );
637 G4int n_hit = HC->entries();
642 vector<BesMucHit*>* vecHC = HC->GetVector();
643 for (
int i = 0; i < n_hit - 1; i++ )
644 for (
int j = i + 1; j < n_hit; j++ )
645 if ( ( *vecHC )[i]->GetTrackIndex() > ( *vecHC )[j]->GetTrackIndex() )
648 ( *vecHC )[i] = ( *vecHC )[j];
652 for ( G4int i = 0; i < n_hit; i++ )
661 aMucMcHitCol->push_back( mucMcHit );
667 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/MC/MucMcHitCol", aMucMcHitCol );
668 if ( scMuc != StatusCode::SUCCESS )
669 G4cout <<
"Could not register MUC McTruth collection" << G4endl;
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesMucHit > BesMucHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
G4ThreeVector GetPosCrystal()
G4double GetEdepCrystal()
G4ThreeVector GetMomentum()
G4int GetNumThetaCrystal()
G4int GetTrackIndex() const
G4ThreeVector GetPosition() const
std::map< Identifier, G4double >::const_iterator End() const
G4double GetPDGCharge() const
std::map< Identifier, G4double >::const_iterator Begin() const
G4ThreeVector GetMomentum() const
Identifier GetIdentify() const
void AddMother(Event::McParticle *, Event::McParticleCol *)
G4ThreeVector GetMomentum()
std::vector< BesTruthVertex * > * GetVertexList()
std::vector< BesTruthTrack * > * GetTrackList()
static BesSensitiveManager * GetSensitiveManager()
G4ThreeVector GetMomentum()
HepLorentzVector GetP4() const
BesTruthVertex * GetTerminalVertex() const
BesTruthVertex * GetVertex() const
vector< int > GetDaughterIndexes() const
BesTruthTrack * GetParentTrack() const
G4ThreeVector GetPosition() const
void putData(int *data, unsigned int size)
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
void setPDGCode(int code)
void setPDGCharge(double charge)
void setTime(double time)
void setHitMap(std::map< Identifier, double > &hitMap)
void setVertexIndex0(int index0)
methods for setting and getting vertex indexes
@ DECAYFLT
Decayed by generator.
@ PRIMARY
Decayed in flight.
@ ERROR
this particle is a leaf in the particle tree
void initialize(StdHepId id, unsigned int statusBits, const HepLorentzVector &initialMomentum, const HepLorentzVector &initialPosition, const std::string process="")
Set the initial attributes of the McParticle.
bool leafParticle() const
Retrieve whether this is a leaf particle.
void addStatusFlag(unsigned int flag)
add a new flag to the status flags
void finalize(const HepLorentzVector &finalPosition)
Set the final attributes of the McParticle.
void setVertexIndex1(int index1)
void addDaughter(const SmartRef< McParticle > d)
add a daugther particle to this particle
void setTrackIndex(int trackIndex)
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
static Identifier channel_id(int barrel_ec, int segment, int layer, int channel)
For a single crystal.
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
static bool is_scin(const Identifier &id)
static value_type getPHI_BARREL_MAX()
static bool is_barrel(const Identifier &id)
Test for barrel.
ObjectVector< MucMcHit > MucMcHitCol
ObjectList< McParticle > McParticleCol
ObjectVector< EmcMcHit > EmcMcHitCol
ObjectVector< TofMcHit > TofMcHitCol
ObjectVector< MdcMcHit > MdcMcHitCol