BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMcTruthWriter Class Reference

#include <BesMcTruthWriter.hh>

Public Member Functions

 BesMcTruthWriter ()
 
 ~BesMcTruthWriter ()
 
void SaveMcTruth ()
 
void SaveMcParticle ()
 
void AddMother (Event::McParticle *, Event::McParticleCol *)
 
void SaveDecayMode ()
 
void SaveMdcTruth ()
 
void SaveTofTruth ()
 
void SaveEmcTruth ()
 
void SaveMucTruth ()
 
 BesMcTruthWriter ()
 
 ~BesMcTruthWriter ()
 
void SaveMcTruth ()
 
void SaveMcParticle ()
 
void AddMother (Event::McParticle *, Event::McParticleCol *)
 
void SaveDecayMode ()
 
void SaveMdcTruth ()
 
void SaveTofTruth ()
 
void SaveEmcTruth ()
 
void SaveMucTruth ()
 

Detailed Description

Constructor & Destructor Documentation

◆ BesMcTruthWriter() [1/2]

BesMcTruthWriter::BesMcTruthWriter ( )

Definition at line 49 of file BesMcTruthWriter.cc.

50{
51 m_DigiMan = G4DigiManager::GetDMpointer();
52 //mdcGeoPointer=BesMdcGeoParameter::GetGeo();
53}

◆ ~BesMcTruthWriter() [1/2]

BesMcTruthWriter::~BesMcTruthWriter ( )

Definition at line 55 of file BesMcTruthWriter.cc.

56{
57}

◆ BesMcTruthWriter() [2/2]

BesMcTruthWriter::BesMcTruthWriter ( )

◆ ~BesMcTruthWriter() [2/2]

BesMcTruthWriter::~BesMcTruthWriter ( )

Member Function Documentation

◆ AddMother() [1/2]

void BesMcTruthWriter::AddMother ( Event::McParticle currentParticle,
Event::McParticleCol particleCol 
)

Definition at line 288 of file BesMcTruthWriter.cc.

289{
290 if (currentParticle->leafParticle()) {
291 return;
292 }
293 Event::McParticleCol::iterator iter;
294 bool found = false;
295 for ( iter = particleCol->begin(); iter != particleCol->end(); iter++) {
296 if (currentParticle->vertexIndex1() == (*iter)->vertexIndex0()) {
297 found = true;
298 (*iter)->setMother(currentParticle);
299 currentParticle->addDaughter(*iter);
300 AddMother((*iter), particleCol);
301 }
302 }
303 if (!found) std::cout << "AddMother: inconsistency was found!" << std::endl;
304
305}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
void AddMother(Event::McParticle *, Event::McParticleCol *)
bool leafParticle() const
Retrieve whether this is a leaf particle.
Definition: McParticle.cxx:19
void addDaughter(const SmartRef< McParticle > d)
add a daugther particle to this particle

Referenced by AddMother(), and SaveMcParticle().

◆ AddMother() [2/2]

void BesMcTruthWriter::AddMother ( Event::McParticle ,
Event::McParticleCol  
)

◆ SaveDecayMode() [1/2]

void BesMcTruthWriter::SaveDecayMode ( )

Definition at line 307 of file BesMcTruthWriter.cc.

308{
309 SmartDataPtr<DecayMode> decayMode(m_evtSvc,"/Event/MC/DecayMode");
310 if(!decayMode)
311 {
312 //G4cout<<"Could not retrieve DecayMode"<<G4endl;
313 DecayMode* aDecayMode = new DecayMode;
314 //register Decay Mode to TDS
315 int dm[10]={0,0,0,0,0,0,0,0,0,0};
316 aDecayMode->putData(dm,10);
317 StatusCode scDM = m_evtSvc->registerObject("/Event/MC/DecayMode", aDecayMode);
318 if(scDM!=StatusCode::SUCCESS)
319 G4cout<< "Could not register DecayMode" <<G4endl;
320 }
321}
void putData(int *data, unsigned int size)

Referenced by SaveMcTruth().

◆ SaveDecayMode() [2/2]

void BesMcTruthWriter::SaveDecayMode ( )

◆ SaveEmcTruth() [1/2]

void BesMcTruthWriter::SaveEmcTruth ( )

Definition at line 487 of file BesMcTruthWriter.cc.

488{
489 //Emc McHit collection defined in BOSS
490 Event::EmcMcHitCol* aEmcMcHitCol = new Event::EmcMcHitCol;
491
492 G4int fullMc = 1;
493 if(fullMc==1) { //full Mc Truth
494 G4int HCID = -1;
495 HCID = m_DigiMan->GetHitsCollectionID("BesEmcTruthHitsList");
496 if(HCID>0)
497 {
499 HC = (BesEmcTruthHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
500 G4int n_hit = HC->entries();
501 if(n_hit>0)
502 {
503 //arrange hits in hits collection in order of trackIndex
504 BesEmcTruthHit* hit;
505 vector<BesEmcTruthHit*>* vecHC = HC->GetVector();
506 for(int i=0;i<n_hit-1;i++) {
507 for(int j=i+1;j<n_hit;j++) {
508 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
509 hit = (*vecHC)[i];
510 (*vecHC)[i] = (*vecHC)[j];
511 (*vecHC)[j] = hit;
512 }
513 }
514 }
515
516 for(G4int i=0;i<n_hit;i++)
517 {
518 BesEmcTruthHit* hit;
519 hit = (*HC)[i];
520
521 std::map<Identifier,double> hitMap;
522 std::map<Identifier,double>::const_iterator iHitMap;
523 hitMap.clear();
524 for(iHitMap=hit->Begin();iHitMap!=hit->End();iHitMap++) {
525 hitMap[iHitMap->first]=iHitMap->second;
526 }
527
528 Event::EmcMcHit* emcMcHit = new Event::EmcMcHit(hit->GetIdentify(), hit->GetTrackIndex(),
529 hit->GetPosition().x(), hit->GetPosition().y(), hit->GetPosition().z(),
530 hit->GetMomentum().x(), hit->GetMomentum().y(), hit->GetMomentum().z(),
531 hit->GetEDep() );
532
533 emcMcHit->setHitEmc(hit->GetHitEmc());
534 emcMcHit->setPDGCode(hit->GetPDGCode());
535 emcMcHit->setPDGCharge(hit->GetPDGCharge());
536 emcMcHit->setTime(hit->GetTime());
537 emcMcHit->setHitMap(hitMap);
538
539 aEmcMcHitCol->push_back(emcMcHit);
540 }
541 }
542 }
543 } else { //simple Mc Truth
544 G4int HCID = -1;
545 HCID = m_DigiMan->GetHitsCollectionID("BesEmcHitsList");
546 if(HCID>0)
547 {
548 BesEmcHitsCollection* HC = 0;
549 HC = (BesEmcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
550 G4int n_hit = HC->entries();
551 if(n_hit>0)
552 {
553 //arrange hits in hits collection in order of trackIndex
554 BesEmcHit* hit;
555 vector<BesEmcHit*>* vecHC = HC->GetVector();
556 for(int i=0;i<n_hit-1;i++)
557 for(int j=i+1;j<n_hit;j++)
558 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
559 {
560 hit = (*vecHC)[i];
561 (*vecHC)[i] = (*vecHC)[j];
562 (*vecHC)[j] = hit;
563 }
564
565 //Emc McHit collection defined in BOSS
566 Event::EmcMcHitCol* aEmcMcHitCol = new Event::EmcMcHitCol;
567
568 for(G4int i=0;i<n_hit;i++)
569 {
570 hit = (*HC)[i];
572
573 std::map<Identifier,double> hitMap;
574 Event::EmcMcHit* emcMcHit = new Event::EmcMcHit(ident, hit->GetTrackIndex(),
575 hit->GetPosCrystal().x(), hit->GetPosCrystal().y(), hit->GetPosCrystal().z(),
576 hit->GetMomentum().x(), hit->GetMomentum().y(), hit->GetMomentum().z(),
577 hit->GetEdepCrystal() );
578
579 aEmcMcHitCol->push_back(emcMcHit);
580 }
581 }
582 }
583 }
584
585 //register EMC McTruth collection to TDS
586 StatusCode scEmc = m_evtSvc->registerObject("/Event/MC/EmcMcHitCol", aEmcMcHitCol);
587 if(scEmc!=StatusCode::SUCCESS)
588 G4cout<< "Could not register EMC McTruth collection" <<G4endl;
589
590 //retrieve EMC McTruth from TDS
591 /*SmartDataPtr<Event::EmcMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/EmcMcHitCol");
592 if(!aMcHitCol)
593 G4cout<<"Could not retrieve EMC McTruth collection"<<G4endl;
594
595 Event::EmcMcHitCol::iterator iMcHitCol;
596 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
597 {
598 const Identifier ident = (*iMcHitCol)->identify();
599 G4cout<<(*iMcHitCol)->getTrackIndex();
600 G4cout<<" "<<EmcID::barrel_ec(ident);
601 G4cout<<" "<<EmcID::theta_module(ident);
602 G4cout<<" "<<EmcID::phi_module(ident);
603 G4cout<<" "<<(*iMcHitCol)->getPositionX();
604 G4cout<<" "<<(*iMcHitCol)->getPositionY();
605 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
606 G4cout<<" "<<(*iMcHitCol)->getPx();
607 G4cout<<" "<<(*iMcHitCol)->getPy();
608 G4cout<<" "<<(*iMcHitCol)->getPz();
609 G4cout<<" "<<(*iMcHitCol)->getDepositEnergy();
610 G4cout<<G4endl;
611 }
612 G4cout<<"end of retrieve EMC McTruth"<<G4endl;
613 */
614}
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
std::map< Identifier, G4double >::const_iterator End() const
Definition: BesEmcHit.cc:182
std::map< Identifier, G4double >::const_iterator Begin() const
Definition: BesEmcHit.cc:177
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition: EmcID.cxx:71
void setHitMap(std::map< Identifier, double > &hitMap)
ObjectVector< EmcMcHit > EmcMcHitCol

Referenced by SaveMcTruth().

◆ SaveEmcTruth() [2/2]

void BesMcTruthWriter::SaveEmcTruth ( )

◆ SaveMcParticle() [1/2]

void BesMcTruthWriter::SaveMcParticle ( )

Definition at line 84 of file BesMcTruthWriter.cc.

85{
87 vector<BesTruthTrack*>* trackList = sensitiveManager->GetTrackList();
88 G4int nTrack = trackList->size();
89 BesTruthTrack* track;
90
91 vector<BesTruthVertex*>* vertexList = sensitiveManager->GetVertexList();
92 G4int nVertex = vertexList->size();
93 BesTruthVertex* vertex;
94
95 //arrange TruthTrack in trackList in order of trackIndex
96 for(int i=0;i<nTrack-1;i++)
97 for(int j=i+1;j<nTrack;j++)
98 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
99 {
100 track=(*trackList)[i];
101 (*trackList)[i]=(*trackList)[j];
102 (*trackList)[j]=track;
103 }
104
106
107 //loop over tracks
108 for(int i=0;i<nTrack;i++)
109 {
110 track = (*trackList) [i];
111
112 // find out the start point
113 bool isPrimary = false;
114 bool startPointFound = false;
115 BesTruthVertex* startPoint;
116
117 for (int i=0;i<nVertex;i++)
118 {
119 vertex = (*vertexList) [i];
120 if ( track->GetVertex()->GetIndex() == vertex->GetIndex() )
121 {
122 if (!vertex->GetParentTrack()) isPrimary = true;
123 startPointFound = true;
124 startPoint = vertex;
125 break;
126 }
127 }
128
129 if (!startPointFound)
130 std::cout << "error in finding the start point of a track" <<std::endl;
131
132
133 bool endPointFound = false;
134 // find out the end point
135 for (int i=0;i<nVertex;i++)
136 {
137 vertex = (*vertexList) [i];
138 if( track->GetTerminalVertex() )
139 {
140 if (track->GetTerminalVertex()->GetIndex() == vertex->GetIndex() )
141 {
142 //create the mc particle
143 Event::McParticle* mcParticle = new Event::McParticle;
144
145 // initialization
146 HepLorentzVector initialMomentum(track->GetP4().x()/1000., track->GetP4().y()/1000., track->GetP4().z()/1000., track->GetP4().t()/1000.);
147
148 HepLorentzVector initialPosition(startPoint->GetPosition().x()/10., startPoint->GetPosition().y()/10., startPoint->GetPosition().z()/10.,startPoint->GetTime());
149
150 mcParticle->initialize(track->GetPDGCode(), 0, initialMomentum, initialPosition);
151
152 // Set track index
153 mcParticle->setTrackIndex( track->GetIndex() );
154
155 // Adding status flag
156 if (isPrimary ) mcParticle->addStatusFlag(Event::McParticle::PRIMARY);
157
158 if (track->GetDaughterIndexes().size()==0)
160
161 //std::cout<<"pdg:"<<track->GetPDGCode()<<" "
162 // <<"source:"<<track->GetSource()<<" "
163 // <<std::endl;
164 if (track->GetSource()=="FromGenerator")
166 else if(track->GetSource()=="FromG4")
168 else
170
171 //std::cout<<"status:"<<mcParticle->statusFlags()<<" "
172 // <<"FGN:"<<mcParticle->decayFromGenerator()<<" "
173 // <<"FG4:"<<mcParticle->decayInFlight()<<std::endl;
174 // Adding vertex index
175 mcParticle->setVertexIndex0(startPoint->GetIndex());
176 mcParticle->setVertexIndex1(vertex->GetIndex());
177
178 // Set the final position
179 HepLorentzVector finalPosition(vertex->GetPosition().x()/10., vertex->GetPosition().y()/10., vertex->GetPosition().z()/10., vertex->GetTime());
180 mcParticle->finalize(finalPosition);
181
182 // push back
183 particleCol->push_back(mcParticle);
184
185 endPointFound = true;
186 }
187 }
188 }
189
190 if (!endPointFound)
191 {
192 //std::cout << "warning in finding the end point of a track" <<std::endl;
193 if (track->GetDaughterIndexes().size()==0)
194 {
195 // create the mc particle
196 Event::McParticle* mcParticle = new Event::McParticle;
197 // initialization
198 HepLorentzVector initialMomentum( track->GetP4().x()/1000., track->GetP4().y()/1000., track->GetP4().z()/1000., track->GetP4().t()/1000.);
199 HepLorentzVector initialPosition(startPoint->GetPosition().x()/10., startPoint->GetPosition().y()/10., startPoint->GetPosition().z()/10., startPoint->GetTime());
200
201 mcParticle->initialize(track->GetPDGCode(), 0, initialMomentum, initialPosition);
202
203 // Set track index
204 mcParticle->setTrackIndex( track->GetIndex() );
205
206 // Adding status flag
208 if (isPrimary ) mcParticle->addStatusFlag(Event::McParticle::PRIMARY);
209
210 // Adding vertex index
211 mcParticle->setVertexIndex0( startPoint->GetIndex() );
212 mcParticle->setVertexIndex1( -99 );
213
214 //std::cout<<"pdg:"<<track->GetPDGCode()<<" "
215 // <<"source:"<<track->GetSource()<<" "
216 // <<std::endl;
217 if (track->GetSource()=="FromGenerator")
219 else if(track->GetSource()=="FromG4")
221 else
223
224 //std::cout<<"status:"<<mcParticle->statusFlags()<<" "
225 // <<"FGN:"<<mcParticle->decayFromGenerator()<<" "
226 // <<"FG4:"<<mcParticle->decayInFlight()<<std::endl;
227
228 // push back
229 particleCol->push_back(mcParticle);
230 continue;
231 }
232 }
233 }
234
235 // Get primary McParticles
236 SmartRefVector<Event::McParticle> primaryParticleCol;
237 Event::McParticleCol::iterator iter_particle;
238 for ( iter_particle = particleCol->begin();
239 iter_particle != particleCol->end(); iter_particle++) {
240
241 if ((*iter_particle)->primaryParticle()) {
242 Event::McParticle* mcPart = (Event::McParticle*)(*iter_particle);
243 primaryParticleCol.push_back(mcPart);
244 }
245 }
246
247 if (primaryParticleCol.empty())
248 std::cout << "no primary particle found!" << std::endl;
249
250 // Add mother particle recursively
251 SmartRefVector<Event::McParticle>::iterator iter_primary;
252 for ( iter_primary = primaryParticleCol.begin();
253 iter_primary != primaryParticleCol.end(); iter_primary++) {
254 if ( !((*iter_primary)->leafParticle()) )
255 AddMother((*iter_primary), particleCol);
256 }
257
258 //register McParticle collection to TDS
259 StatusCode sc = m_evtSvc->registerObject("/Event/MC/McParticleCol", particleCol);
260 if(sc!=StatusCode::SUCCESS)
261 G4cout<< "Could not register McParticle collection" <<G4endl;
262
263 //retrive McParticle from TDS
264 /*SmartDataPtr<Event::McParticleCol> mcParticleCol(m_evtSvc,"/Event/MC/McParticleCol");
265 if(!mcParticleCol)
266 G4cout<<"Could not retrieve McParticelCol"<<G4endl;
267 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
268 for (;iter_mc != mcParticleCol->end(); iter_mc++)
269 {
270 G4cout<<(*iter_mc)->getTrackIndex();
271 G4cout<<" "<<(*iter_mc)->particleProperty();
272 G4cout<<" "<<(*iter_mc)->getVertexIndex0();
273 G4cout<<" "<<(*iter_mc)->getVertexIndex1();
274 G4cout<<" "<<(*iter_mc)->initialFourMomentum().x();
275 G4cout<<" "<<(*iter_mc)->initialFourMomentum().y();
276 G4cout<<" "<<(*iter_mc)->initialFourMomentum().z();
277 G4cout<<" "<<(*iter_mc)->initialFourMomentum().t();
278 G4cout<<" "<<(*iter_mc)->initialPosition().x();
279 G4cout<<" "<<(*iter_mc)->initialPosition().y();
280 G4cout<<" "<<(*iter_mc)->initialPosition().z();
281 G4cout<<G4endl;
282 }
283 G4cout<<"end of retrieve McParticle from TDS"<<G4endl;
284 */
285
286}
void setVertexIndex0(int index0)
methods for setting and getting vertex indexes
@ 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.
Definition: McParticle.cxx:50
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.
Definition: McParticle.cxx:85
ObjectList< McParticle > McParticleCol

Referenced by SaveMcTruth().

◆ SaveMcParticle() [2/2]

void BesMcTruthWriter::SaveMcParticle ( )

◆ SaveMcTruth() [1/2]

void BesMcTruthWriter::SaveMcTruth ( )

Definition at line 59 of file BesMcTruthWriter.cc.

60{
61 //interface to event data service
62 ISvcLocator* svcLocator = Gaudi::svcLocator();
63 StatusCode sc=svcLocator->service("EventDataSvc", m_evtSvc);
64 if (sc.isFailure())
65 G4cout<<"Could not accesss EventDataSvc!"<<G4endl;
66
67 DataObject *aMcEvent;
68 m_evtSvc->findObject("/Event/MC",aMcEvent);
69 if(aMcEvent==NULL) {
70 McEvent* aMcEvent = new McEvent;
71 sc = m_evtSvc->registerObject("/Event/MC",aMcEvent);
72 if(sc!=StatusCode::SUCCESS)
73 G4cout<< "Could not register McEvent" <<G4endl;
74 }
75
82}

Referenced by BesTDSWriter::SaveAll().

◆ SaveMcTruth() [2/2]

void BesMcTruthWriter::SaveMcTruth ( )

◆ SaveMdcTruth() [1/2]

void BesMcTruthWriter::SaveMdcTruth ( )

Definition at line 323 of file BesMcTruthWriter.cc.

324{
325 //Mdc McHit collection defined in BOSS
326 Event::MdcMcHitCol* aMdcMcHitCol = new Event::MdcMcHitCol;
327
328 G4int HCID = -1;
329 HCID = m_DigiMan->GetHitsCollectionID("BesMdcTruthCollection");
330 if(HCID>0)
331 {
332 BesMdcHitsCollection* HC = 0;
333 HC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
334 G4int n_hit = HC->entries();
335 if(n_hit>0)
336 {
337 //arrange hits in hits collection in order of trackIndex
338 BesMdcHit* hit;
339 vector<BesMdcHit*>* vecHC = HC->GetVector();
340 for(int i=0;i<n_hit-1;i++)
341 for(int j=i+1;j<n_hit;j++)
342 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
343 {
344 hit = (*vecHC)[i];
345 (*vecHC)[i] = (*vecHC)[j];
346 (*vecHC)[j] = hit;
347 }
348
349 //push back MdcMcHits to MdcMcHitCol in TDS
350 for(G4int i=0;i<n_hit;i++)
351 {
352 hit = (*HC)[i];
353 const Identifier ident = MdcID::wire_id ( hit->GetLayerNo(), hit->GetCellNo() );
354 Event::MdcMcHit* mdcMcHit = new Event::MdcMcHit(ident, hit->GetTrackID(),
355 hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(),
356 hit->GetDriftD(), hit->GetEdep(),hit->GetPosFlag() );
357 aMdcMcHitCol->push_back(mdcMcHit);
358 }
359
360 }
361 }
362
363 //register MDC McTruth collection to TDS
364 StatusCode scMdc = m_evtSvc->registerObject("/Event/MC/MdcMcHitCol", aMdcMcHitCol);
365 if(scMdc!=StatusCode::SUCCESS)
366 G4cout<< "Could not register MDC McTruth collection" <<G4endl;
367
368 //retrieve MDC McTruth from TDS
369 /*SmartDataPtr<Event::MdcMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/MdcMcHitCol");
370 if(!aMcHitCol)
371 G4cout<<"Could not retrieve MDC McTruth collection"<<G4endl;
372
373 Event::MdcMcHitCol::iterator iMcHitCol;
374 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
375 {
376 const Identifier ident = (*iMcHitCol)->identify();
377 G4cout<<(*iMcHitCol)->getTrackIndex();
378 G4cout<<" "<<MdcID::layer(ident);
379 G4cout<<" "<<MdcID::wire(ident);
380 G4cout<<" "<<(*iMcHitCol)->getDepositEnergy();
381 G4cout<<" "<<(*iMcHitCol)->getDriftDistance();
382 G4cout<<" "<<(*iMcHitCol)->getPositionX();
383 G4cout<<" "<<(*iMcHitCol)->getPositionY();
384 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
385 G4cout<<G4endl;
386 }
387 G4cout<<"end of retrieve MDC McTruth collection"<<G4endl;
388 */
389}
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
Definition: MdcID.cxx:77
ObjectVector< MdcMcHit > MdcMcHitCol

Referenced by SaveMcTruth().

◆ SaveMdcTruth() [2/2]

void BesMcTruthWriter::SaveMdcTruth ( )

◆ SaveMucTruth() [1/2]

void BesMcTruthWriter::SaveMucTruth ( )

Definition at line 616 of file BesMcTruthWriter.cc.

617{
618 //Muc McHit collection defined in BOSS
619 Event::MucMcHitCol* aMucMcHitCol = new Event::MucMcHitCol;
620
621 G4int HCID = -1;
622 HCID = m_DigiMan->GetHitsCollectionID("BesMucHitsList");
623 if(HCID>0)
624 {
625 BesMucHitsCollection* HC = 0;
626 HC = (BesMucHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
627 G4int n_hit = HC->entries();
628 if(n_hit>0)
629 {
630 //arrange hits in hits collection in order of trackIndex
631 BesMucHit* hit;
632 vector<BesMucHit*>* vecHC = HC->GetVector();
633 for(int i=0;i<n_hit-1;i++)
634 for(int j=i+1;j<n_hit;j++)
635 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
636 {
637 hit = (*vecHC)[i];
638 (*vecHC)[i] = (*vecHC)[j];
639 (*vecHC)[j] = hit;
640 }
641
642 for(G4int i=0;i<n_hit;i++)
643 {
644 hit = (*HC)[i];
645 Identifier ident = MucID::channel_id ( hit->GetPart(), hit->GetSeg(), hit->GetGap(),
646 hit->GetStrip() );
647 Event::MucMcHit* mucMcHit = new Event::MucMcHit(ident, hit->GetTrackIndex(),
648 hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(), hit->GetMomentum().x(),
649 hit->GetMomentum().y(), hit->GetMomentum().z() );
650 aMucMcHitCol->push_back(mucMcHit);
651 }
652
653 }
654 }
655
656 //register MUC McTruth collection to TDS
657 StatusCode scMuc = m_evtSvc->registerObject("/Event/MC/MucMcHitCol", aMucMcHitCol);
658 if(scMuc!=StatusCode::SUCCESS)
659 G4cout<< "Could not register MUC McTruth collection" <<G4endl;
660
661 //retrieve MUC McTruth from TDS
662 /*SmartDataPtr<Event::MucMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/MucMcHitCol");
663 if(!aMcHitCol)
664 G4cout<<"Could not retrieve MUC McTruth collection"<<G4endl;
665
666 Event::MucMcHitCol::iterator iMcHitCol;
667 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
668 {
669 const Identifier ident = (*iMcHitCol)->identify();
670 G4cout<<(*iMcHitCol)->getTrackIndex();
671 G4cout<<" "<<MucID::part(ident);
672 G4cout<<" "<<MucID::seg(ident);
673 G4cout<<" "<<MucID::gap(ident);
674 G4cout<<" "<<MucID::strip(ident);
675 G4cout<<" "<<(*iMcHitCol)->getPositionX();
676 G4cout<<" "<<(*iMcHitCol)->getPositionY();
677 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
678 G4cout<<" "<<(*iMcHitCol)->getPx();
679 G4cout<<" "<<(*iMcHitCol)->getPy();
680 G4cout<<" "<<(*iMcHitCol)->getPz();
681 G4cout<<G4endl;
682 }
683 G4cout<<"end of retrieve MUC McTruth"<<G4endl;
684 */
685}
G4THitsCollection< BesMucHit > BesMucHitsCollection
static Identifier channel_id(int barrel_ec, int segment, int layer, int channel)
For a single crystal.
Definition: MucID.cxx:135
ObjectVector< MucMcHit > MucMcHitCol

Referenced by SaveMcTruth().

◆ SaveMucTruth() [2/2]

void BesMcTruthWriter::SaveMucTruth ( )

◆ SaveTofTruth() [1/2]

void BesMcTruthWriter::SaveTofTruth ( )

Definition at line 391 of file BesMcTruthWriter.cc.

392{
393 //Tof McHit collection defined in BOSS
394 Event::TofMcHitCol* aTofMcHitCol = new Event::TofMcHitCol;
395
396 G4int HCID = -1;
397 HCID = m_DigiMan->GetHitsCollectionID("BesTofHitsList");
398 if(HCID>0)
399 {
400 BesTofHitsCollection* HC = 0;
401 HC = (BesTofHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
402 G4int n_hit = HC->entries();
403 if(n_hit>0)
404 {
405 //arrange hits in hits collection in order of trackIndex
406 BesTofHit* hit;
407 vector<BesTofHit*>* vecHC = HC->GetVector();
408 for( int i=0; i<n_hit-1; i++ ) {
409 for( int j=i+1; j<n_hit; j++ ) {
410 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
411 hit = (*vecHC)[i];
412 (*vecHC)[i] = (*vecHC)[j];
413 (*vecHC)[j] = hit;
414 }
415 }
416 }
417
418 //push back TofMcHit collection to TDS
419 for( G4int i=0; i<n_hit; i++ ) {
420 hit = (*HC)[i];
421 Identifier ident;
422 unsigned int barrel_ec = hit->GetPartId();
423 // for Scintillator
424 if( TofID::is_scin( barrel_ec ) ) {
425 unsigned int scinNum = hit->GetScinNb();
426 unsigned int layer = 0;
427 if( TofID::is_barrel(barrel_ec) && scinNum>TofID::getPHI_BARREL_MAX()) {
428 layer = 1;
429 scinNum = scinNum - TofID::getPHI_BARREL_MAX() - 1;
430 }
431 ident = TofID::cell_id ( barrel_ec, layer, scinNum, 0);
432 }
433 // for ETF(MRPC)
434 else { // for ETF(MRPC)
435 if( barrel_ec==3 || barrel_ec==4 ) {
436 unsigned int endcap = 0;
437 unsigned int module = hit->GetModule();
438 unsigned int strip = hit->GetStrip();
439 if( barrel_ec==4 ) { // west end cap
440 endcap = 1;
441 }
442 ident = TofID::cell_id( 3, endcap, module, strip, 0 );
443 }
444 }
445 if( barrel_ec>=0 && barrel_ec<=4 ) {
446 Event::TofMcHit* tofMcHit = new Event::TofMcHit( ident, hit->GetTrackIndex(),
447 hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(), hit->GetMomentum().x(),
448 hit->GetMomentum().y(), hit->GetMomentum().z(), hit->GetTrackL(), hit->GetTime() );
449 aTofMcHitCol->push_back(tofMcHit);
450 }
451 }
452 }
453 }
454
455 //register TOF McTruth collection to TDS
456 StatusCode scTof = m_evtSvc->registerObject("/Event/MC/TofMcHitCol", aTofMcHitCol);
457 if(scTof!=StatusCode::SUCCESS)
458 G4cout<< "Could not register TOF McTruth collection" <<G4endl;
459
460 //retrieve TOF McTruth from TDS
461 /*SmartDataPtr<Event::TofMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/TofMcHitCol");
462 if(!aMcHitCol)
463 G4cout<<"Could not retrieve TOF McTruth collection"<<G4endl;
464
465 Event::TofMcHitCol::iterator iMcHitCol;
466 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
467 {
468 const Identifier ident = (*iMcHitCol)->identify();
469 G4cout<<(*iMcHitCol)->getTrackIndex();
470 G4cout<<" "<<TofID::barrel_ec(ident);;
471 G4cout<<" "<<TofID::layer(ident);
472 G4cout<<" "<<TofID::phi_module(ident);
473 G4cout<<" "<<(*iMcHitCol)->getPositionX();
474 G4cout<<" "<<(*iMcHitCol)->getPositionY();
475 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
476 G4cout<<" "<<(*iMcHitCol)->getPx();
477 G4cout<<" "<<(*iMcHitCol)->getPy();
478 G4cout<<" "<<(*iMcHitCol)->getPz();
479 G4cout<<" "<<(*iMcHitCol)->getTrackLength();
480 G4cout<<" "<<(*iMcHitCol)->getFlightTime();
481 G4cout<<G4endl;
482 }
483 G4cout<<"end of retrieve TOF McTruth"<<G4endl;
484 */
485}
G4THitsCollection< BesTofHit > BesTofHitsCollection
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
Definition: TofID.cxx:143
static bool is_scin(const Identifier &id)
Definition: TofID.cxx:102
static value_type getPHI_BARREL_MAX()
Definition: TofID.cxx:217
static bool is_barrel(const Identifier &id)
Test for barrel.
Definition: TofID.cxx:49
ObjectVector< TofMcHit > TofMcHitCol

Referenced by SaveMcTruth().

◆ SaveTofTruth() [2/2]

void BesMcTruthWriter::SaveTofTruth ( )

The documentation for this class was generated from the following files: