10#include "G4DigiManager.hh"
11#include "BesMdcHit.hh"
12#include "BesCgemHit.hh"
13#include "BesTofHit.hh"
14#include "BesEmcHit.hh"
15#include "BesMucHit.hh"
16#include "BesTruthTrack.hh"
17#include "BesTruthVertex.hh"
18#include "BesSensitiveManager.hh"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/ISvcLocator.h"
26#include "GaudiKernel/Bootstrap.h"
27#include "GaudiKernel/RegistryEntry.h"
28#include "GaudiKernel/MsgStream.h"
29#include "CLHEP/Vector/LorentzVector.h"
30#include "CLHEP/Geometry/Point3D.h"
32#include "McTruth/DecayMode.h"
33#include "McTruth/MdcMcHit.h"
34#include "McTruth/CgemMcHit.h"
35#include "McTruth/TofMcHit.h"
36#include "McTruth/EmcMcHit.h"
37#include "McTruth/MucMcHit.h"
39#include "Identifier/Identifier.h"
40#include "Identifier/MdcID.h"
41#include "Identifier/CgemID.h"
42#include "Identifier/TofID.h"
43#include "Identifier/EmcID.h"
44#include "Identifier/MucID.h"
47#include "TofSim/BesTofDigitizerEcV4.hh"
49#include "McTruth/McEvent.h"
50#include "EventModel/EventModel.h"
52#include "GaudiKernel/SmartDataPtr.h"
53#include "BesMcTruthWriter.hh"
59 m_DigiMan = G4DigiManager::GetDMpointer();
70 ISvcLocator* svcLocator = Gaudi::svcLocator();
71 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
73 G4cout<<
"Could not accesss EventDataSvc!"<<G4endl;
76 m_evtSvc->findObject(
"/Event/MC",aMcEvent);
79 sc = m_evtSvc->registerObject(
"/Event/MC",aMcEvent);
80 if(sc!=StatusCode::SUCCESS)
81 G4cout<<
"Could not register McEvent" <<G4endl;
96 vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
97 G4int nTrack = trackList->size();
100 vector<BesTruthVertex*>* vertexList = sensitiveManager->
GetVertexList();
101 G4int nVertex = vertexList->size();
105 for(
int i=0;i<nTrack-1;i++)
106 for(
int j=i+1;j<nTrack;j++)
107 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
109 track=(*trackList)[i];
110 (*trackList)[i]=(*trackList)[j];
111 (*trackList)[j]=track;
117 for(
int i=0;i<nTrack;i++)
119 track = (*trackList) [i];
122 bool isPrimary =
false;
123 bool startPointFound =
false;
126 for (
int i=0;i<nVertex;i++)
128 vertex = (*vertexList) [i];
132 startPointFound =
true;
138 if (!startPointFound)
139 std::cout <<
"error in finding the start point of a track" <<std::endl;
142 bool endPointFound =
false;
144 for (
int i=0;i<nVertex;i++)
146 vertex = (*vertexList) [i];
155 HepLorentzVector initialMomentum(track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
189 mcParticle->
finalize(finalPosition);
192 particleCol->push_back(mcParticle);
194 endPointFound =
true;
207 HepLorentzVector initialMomentum( track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
238 particleCol->push_back(mcParticle);
245 SmartRefVector<Event::McParticle> primaryParticleCol;
246 Event::McParticleCol::iterator iter_particle;
247 for ( iter_particle = particleCol->begin();
248 iter_particle != particleCol->end(); iter_particle++) {
250 if ((*iter_particle)->primaryParticle()) {
252 primaryParticleCol.push_back(mcPart);
256 if (primaryParticleCol.empty())
257 std::cout <<
"no primary particle found!" << std::endl;
260 SmartRefVector<Event::McParticle>::iterator iter_primary;
261 for ( iter_primary = primaryParticleCol.begin();
262 iter_primary != primaryParticleCol.end(); iter_primary++) {
263 if ( !((*iter_primary)->leafParticle()) )
268 StatusCode sc = m_evtSvc->registerObject(
"/Event/MC/McParticleCol", particleCol);
269 if(sc!=StatusCode::SUCCESS)
270 G4cout<<
"Could not register McParticle collection" <<G4endl;
302 Event::McParticleCol::iterator
iter;
304 for (
iter = particleCol->begin();
iter != particleCol->end();
iter++) {
305 if (currentParticle->
vertexIndex1() == (*iter)->vertexIndex0()) {
307 (*iter)->setMother(currentParticle);
312 if (!found) std::cout <<
"AddMother: inconsistency was found!" << std::endl;
318 SmartDataPtr<DecayMode> decayMode(m_evtSvc,
"/Event/MC/DecayMode");
324 int dm[10]={0,0,0,0,0,0,0,0,0,0};
326 StatusCode scDM = m_evtSvc->registerObject(
"/Event/MC/DecayMode", aDecayMode);
327 if(scDM!=StatusCode::SUCCESS)
328 G4cout<<
"Could not register DecayMode" <<G4endl;
338 HCID = m_DigiMan->GetHitsCollectionID(
"BesMdcTruthCollection");
343 G4int n_hit = HC->entries();
348 vector<BesMdcHit*>* vecHC = HC->GetVector();
349 for(
int i=0;i<n_hit-1;i++)
350 for(
int j=i+1;j<n_hit;j++)
351 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
354 (*vecHC)[i] = (*vecHC)[j];
359 for(G4int i=0;i<n_hit;i++)
366 aMdcMcHitCol->push_back(mdcMcHit);
373 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/MC/MdcMcHitCol", aMdcMcHitCol);
374 if(scMdc!=StatusCode::SUCCESS)
375 G4cout<<
"Could not register MDC McTruth collection" <<G4endl;
409 HCID = m_DigiMan->GetHitsCollectionID(
"BesCgemTruthCollection");
410 BESID = m_DigiMan->GetHitsCollectionID(
"BesCgemHitsCollection");
418 G4int n_hit = HC->entries();
419 G4int n_BEShit = BES->entries();
425 vector<BesCgemHit*>* vecHC = HC->GetVector();
426 for(
int i=0; i<n_hit-1; i++)
427 for(
int j=i+1; j<n_hit; j++)
428 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
431 (*vecHC)[i] = (*vecHC)[j];
462 for(G4int i=0;i<n_hit;i++)
489 for(G4int j=0;j<n_BEShit;j++)
495 for(
int ii = 0; ii < hit_ID.GetSize(); ii++){
496 if(hit_ID.GetAt(ii) != BEShit->
GetHitID())
continue;
500 for(
int jj = 0; jj < BES_Ident.GetSize(); jj++){
501 tmp[size] = BES_Ident.GetAt(jj);
509 aCgemMcHitCol->push_back(cgemMcHit);
517 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/MC/CgemMcHitCol", aCgemMcHitCol);
518 if(scCgem!=StatusCode::SUCCESS)
520 G4cout <<
"ERROR : BesSim::BesMcTruthWriter::SaveCgemTruth(), Could not register CGEM McTruth collection!" << G4endl;
554 HCID = m_DigiMan->GetHitsCollectionID(
"BesTofHitsList");
559 G4int n_hit = HC->entries();
564 vector<BesTofHit*>* vecHC = HC->GetVector();
565 for(
int i=0;i<n_hit-1;i++)
566 for(
int j=i+1;j<n_hit;j++)
567 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
570 (*vecHC)[i] = (*vecHC)[j];
575 for(G4int i=0;i<n_hit;i++)
578 unsigned int scinNum, barrel_ec, layer = 0;
595 if(barrel_ec==0 || barrel_ec==1 || barrel_ec==2 )
614 aTofMcHitCol->push_back(tofMcHit);
620 StatusCode scTof = m_evtSvc->registerObject(
"/Event/MC/TofMcHitCol", aTofMcHitCol);
621 if(scTof!=StatusCode::SUCCESS)
622 G4cout<<
"Could not register TOF McTruth collection" <<G4endl;
659 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcTruthHitsList");
664 G4int n_hit = HC->entries();
669 vector<BesEmcTruthHit*>* vecHC = HC->GetVector();
670 for(
int i=0;i<n_hit-1;i++) {
671 for(
int j=i+1;j<n_hit;j++) {
672 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
674 (*vecHC)[i] = (*vecHC)[j];
680 for(G4int i=0;i<n_hit;i++)
685 std::map<Identifier,double> hitMap;
686 std::map<Identifier,double>::const_iterator iHitMap;
688 for(iHitMap=hit->
Begin();iHitMap!=hit->
End();iHitMap++) {
689 hitMap[iHitMap->first]=iHitMap->second;
703 aEmcMcHitCol->push_back(emcMcHit);
709 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcHitsList");
714 G4int n_hit = HC->entries();
719 vector<BesEmcHit*>* vecHC = HC->GetVector();
720 for(
int i=0;i<n_hit-1;i++)
721 for(
int j=i+1;j<n_hit;j++)
722 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
725 (*vecHC)[i] = (*vecHC)[j];
732 for(G4int i=0;i<n_hit;i++)
737 std::map<Identifier,double> hitMap;
743 aEmcMcHitCol->push_back(emcMcHit);
750 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/MC/EmcMcHitCol", aEmcMcHitCol);
751 if(scEmc!=StatusCode::SUCCESS)
752 G4cout<<
"Could not register EMC McTruth collection" <<G4endl;
786 HCID = m_DigiMan->GetHitsCollectionID(
"BesMucHitsList");
791 G4int n_hit = HC->entries();
796 vector<BesMucHit*>* vecHC = HC->GetVector();
797 for(
int i=0;i<n_hit-1;i++)
798 for(
int j=i+1;j<n_hit;j++)
799 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
802 (*vecHC)[i] = (*vecHC)[j];
806 for(G4int i=0;i<n_hit;i++)
814 aMucMcHitCol->push_back(mucMcHit);
821 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/MC/MucMcHitCol", aMucMcHitCol);
822 if(scMuc!=StatusCode::SUCCESS)
823 G4cout<<
"Could not register MUC McTruth collection" <<G4endl;
G4THitsCollection< BesCgemHit > BesCgemHitsCollection
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesMucHit > BesMucHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
G4ThreeVector GetPositionOfPrePoint() const
G4ThreeVector GetMomentumOfPostPoint() const
TArrayI GetIdentifier() const
G4ThreeVector GetPositionOfPostPoint() const
G4double GetTotalEnergyDeposit() const
G4ThreeVector GetMomentumOfPrePoint() const
G4String GetCreatorProcess() const
G4int GetParentID() const
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()
static G4int Produce_unique_identifier(G4int module_mrpc_f, G4int readoutstripnumber_f)
static G4int Calculate_Readoutstrip_number_continuum(G4double x_mm, G4double y_mm, G4int partId_f, G4int module_mrpc_f)
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 AddIdentifier(Int_t f_ID_Identifier[2000], Int_t N_dim)
void SetCreatorProcess(string creatorProcess)
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 value_type getPHI_BARREL_MAX()
static bool is_barrel(const Identifier &id)
Test for barrel.
static Identifier cell_id_mrpc_mc(int partID, int scinNum)
ObjectVector< CgemMcHit > CgemMcHitCol
ObjectVector< MucMcHit > MucMcHitCol
ObjectList< McParticle > McParticleCol
ObjectVector< EmcMcHit > EmcMcHitCol
ObjectVector< TofMcHit > TofMcHitCol
ObjectVector< MdcMcHit > MdcMcHitCol