CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
bak_BesSim-00-04-14/src/BesMcTruthWriter.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool //
3////---------------------------------------------------------------------------//
4////Description:
5////Author: Dengzy
6////Created: Mar, 2004
7////Modified:
8////Comment:
9//
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"
19//#include "G4HCofThisEvent.hh"
20//#include "G4SDManager.hh"
21//#include "G4PrimaryVertex.hh"
22//#include "G4PrimaryParticle.hh"
23
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"
31
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"
38
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"
45
46
47#include "TofSim/BesTofDigitizerEcV4.hh"
48
49#include "McTruth/McEvent.h"
50#include "EventModel/EventModel.h"
51
52#include "GaudiKernel/SmartDataPtr.h"
53#include "BesMcTruthWriter.hh"
54
55#include "TArrayI.h"
56
58{
59 m_DigiMan = G4DigiManager::GetDMpointer();
60 //mdcGeoPointer=BesMdcGeoParameter::GetGeo();
61}
62
64{
65}
66
68{
69 //interface to event data service
70 ISvcLocator* svcLocator = Gaudi::svcLocator();
71 StatusCode sc=svcLocator->service("EventDataSvc", m_evtSvc);
72 if (sc.isFailure())
73 G4cout<<"Could not accesss EventDataSvc!"<<G4endl;
74
75 DataObject *aMcEvent;
76 m_evtSvc->findObject("/Event/MC",aMcEvent);
77 if(aMcEvent==NULL) {
78 McEvent* aMcEvent = new McEvent;
79 sc = m_evtSvc->registerObject("/Event/MC",aMcEvent);
80 if(sc!=StatusCode::SUCCESS)
81 G4cout<< "Could not register McEvent" <<G4endl;
82 }
83
91}
92
94{
96 vector<BesTruthTrack*>* trackList = sensitiveManager->GetTrackList();
97 G4int nTrack = trackList->size();
98 BesTruthTrack* track;
99
100 vector<BesTruthVertex*>* vertexList = sensitiveManager->GetVertexList();
101 G4int nVertex = vertexList->size();
102 BesTruthVertex* vertex;
103
104 //arrange TruthTrack in trackList in order of trackIndex
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())
108 {
109 track=(*trackList)[i];
110 (*trackList)[i]=(*trackList)[j];
111 (*trackList)[j]=track;
112 }
113
115
116 //loop over tracks
117 for(int i=0;i<nTrack;i++)
118 {
119 track = (*trackList) [i];
120
121 // find out the start point
122 bool isPrimary = false;
123 bool startPointFound = false;
124 BesTruthVertex* startPoint;
125
126 for (int i=0;i<nVertex;i++)
127 {
128 vertex = (*vertexList) [i];
129 if ( track->GetVertex()->GetIndex() == vertex->GetIndex() )
130 {
131 if (!vertex->GetParentTrack()) isPrimary = true;
132 startPointFound = true;
133 startPoint = vertex;
134 break;
135 }
136 }
137
138 if (!startPointFound)
139 std::cout << "error in finding the start point of a track" <<std::endl;
140
141
142 bool endPointFound = false;
143 // find out the end point
144 for (int i=0;i<nVertex;i++)
145 {
146 vertex = (*vertexList) [i];
147 if( track->GetTerminalVertex() )
148 {
149 if (track->GetTerminalVertex()->GetIndex() == vertex->GetIndex() )
150 {
151 //create the mc particle
152 Event::McParticle* mcParticle = new Event::McParticle;
153
154 // initialization
155 HepLorentzVector initialMomentum(track->GetP4().x()/1000., track->GetP4().y()/1000., track->GetP4().z()/1000., track->GetP4().t()/1000.);
156
157 HepLorentzVector initialPosition(startPoint->GetPosition().x()/10., startPoint->GetPosition().y()/10., startPoint->GetPosition().z()/10.,startPoint->GetTime());
158
159 mcParticle->initialize(track->GetPDGCode(), 0, initialMomentum, initialPosition);
160
161 // Set track index
162 mcParticle->setTrackIndex( track->GetIndex() );
163
164 // Adding status flag
165 if (isPrimary ) mcParticle->addStatusFlag(Event::McParticle::PRIMARY);
166
167 if (track->GetDaughterIndexes().size()==0)
169
170 //std::cout<<"pdg:"<<track->GetPDGCode()<<" "
171 // <<"source:"<<track->GetSource()<<" "
172 // <<std::endl;
173 if (track->GetSource()=="FromGenerator")
175 else if(track->GetSource()=="FromG4")
177 else
179
180 //std::cout<<"status:"<<mcParticle->statusFlags()<<" "
181 // <<"FGN:"<<mcParticle->decayFromGenerator()<<" "
182 // <<"FG4:"<<mcParticle->decayInFlight()<<std::endl;
183 // Adding vertex index
184 mcParticle->setVertexIndex0(startPoint->GetIndex());
185 mcParticle->setVertexIndex1(vertex->GetIndex());
186
187 // Set the final position
188 HepLorentzVector finalPosition(vertex->GetPosition().x()/10., vertex->GetPosition().y()/10., vertex->GetPosition().z()/10., vertex->GetTime());
189 mcParticle->finalize(finalPosition);
190
191 // push back
192 particleCol->push_back(mcParticle);
193
194 endPointFound = true;
195 }
196 }
197 }
198
199 if (!endPointFound)
200 {
201 //std::cout << "warning in finding the end point of a track" <<std::endl;
202 if (track->GetDaughterIndexes().size()==0)
203 {
204 // create the mc particle
205 Event::McParticle* mcParticle = new Event::McParticle;
206 // initialization
207 HepLorentzVector initialMomentum( track->GetP4().x()/1000., track->GetP4().y()/1000., track->GetP4().z()/1000., track->GetP4().t()/1000.);
208 HepLorentzVector initialPosition(startPoint->GetPosition().x()/10., startPoint->GetPosition().y()/10., startPoint->GetPosition().z()/10., startPoint->GetTime());
209
210 mcParticle->initialize(track->GetPDGCode(), 0, initialMomentum, initialPosition);
211
212 // Set track index
213 mcParticle->setTrackIndex( track->GetIndex() );
214
215 // Adding status flag
217 if (isPrimary ) mcParticle->addStatusFlag(Event::McParticle::PRIMARY);
218
219 // Adding vertex index
220 mcParticle->setVertexIndex0( startPoint->GetIndex() );
221 mcParticle->setVertexIndex1( -99 );
222
223 //std::cout<<"pdg:"<<track->GetPDGCode()<<" "
224 // <<"source:"<<track->GetSource()<<" "
225 // <<std::endl;
226 if (track->GetSource()=="FromGenerator")
228 else if(track->GetSource()=="FromG4")
230 else
232
233 //std::cout<<"status:"<<mcParticle->statusFlags()<<" "
234 // <<"FGN:"<<mcParticle->decayFromGenerator()<<" "
235 // <<"FG4:"<<mcParticle->decayInFlight()<<std::endl;
236
237 // push back
238 particleCol->push_back(mcParticle);
239 continue;
240 }
241 }
242 }
243
244 // Get primary McParticles
245 SmartRefVector<Event::McParticle> primaryParticleCol;
246 Event::McParticleCol::iterator iter_particle;
247 for ( iter_particle = particleCol->begin();
248 iter_particle != particleCol->end(); iter_particle++) {
249
250 if ((*iter_particle)->primaryParticle()) {
251 Event::McParticle* mcPart = (Event::McParticle*)(*iter_particle);
252 primaryParticleCol.push_back(mcPart);
253 }
254 }
255
256 if (primaryParticleCol.empty())
257 std::cout << "no primary particle found!" << std::endl;
258
259 // Add mother particle recursively
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()) )
264 AddMother((*iter_primary), particleCol);
265 }
266
267 //register McParticle collection to TDS
268 StatusCode sc = m_evtSvc->registerObject("/Event/MC/McParticleCol", particleCol);
269 if(sc!=StatusCode::SUCCESS)
270 G4cout<< "Could not register McParticle collection" <<G4endl;
271
272 //retrive McParticle from TDS
273 /*SmartDataPtr<Event::McParticleCol> mcParticleCol(m_evtSvc,"/Event/MC/McParticleCol");
274 if(!mcParticleCol)
275 G4cout<<"Could not retrieve McParticelCol"<<G4endl;
276 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
277 for (;iter_mc != mcParticleCol->end(); iter_mc++)
278 {
279 G4cout<<(*iter_mc)->getTrackIndex();
280 G4cout<<" "<<(*iter_mc)->particleProperty();
281 G4cout<<" "<<(*iter_mc)->getVertexIndex0();
282 G4cout<<" "<<(*iter_mc)->getVertexIndex1();
283 G4cout<<" "<<(*iter_mc)->initialFourMomentum().x();
284 G4cout<<" "<<(*iter_mc)->initialFourMomentum().y();
285 G4cout<<" "<<(*iter_mc)->initialFourMomentum().z();
286 G4cout<<" "<<(*iter_mc)->initialFourMomentum().t();
287 G4cout<<" "<<(*iter_mc)->initialPosition().x();
288 G4cout<<" "<<(*iter_mc)->initialPosition().y();
289 G4cout<<" "<<(*iter_mc)->initialPosition().z();
290 G4cout<<G4endl;
291 }
292 G4cout<<"end of retrieve McParticle from TDS"<<G4endl;
293 */
294
295}
296
298{
299 if (currentParticle->leafParticle()) {
300 return;
301 }
302 Event::McParticleCol::iterator iter;
303 bool found = false;
304 for ( iter = particleCol->begin(); iter != particleCol->end(); iter++) {
305 if (currentParticle->vertexIndex1() == (*iter)->vertexIndex0()) {
306 found = true;
307 (*iter)->setMother(currentParticle);
308 currentParticle->addDaughter(*iter);
309 AddMother((*iter), particleCol);
310 }
311 }
312 if (!found) std::cout << "AddMother: inconsistency was found!" << std::endl;
313
314}
315
317{
318 SmartDataPtr<DecayMode> decayMode(m_evtSvc,"/Event/MC/DecayMode");
319 if(!decayMode)
320 {
321 //G4cout<<"Could not retrieve DecayMode"<<G4endl;
322 DecayMode* aDecayMode = new DecayMode;
323 //register Decay Mode to TDS
324 int dm[10]={0,0,0,0,0,0,0,0,0,0};
325 aDecayMode->putData(dm,10);
326 StatusCode scDM = m_evtSvc->registerObject("/Event/MC/DecayMode", aDecayMode);
327 if(scDM!=StatusCode::SUCCESS)
328 G4cout<< "Could not register DecayMode" <<G4endl;
329 }
330}
331
333{
334 //Mdc McHit collection defined in BOSS
335 Event::MdcMcHitCol* aMdcMcHitCol = new Event::MdcMcHitCol;
336
337 G4int HCID = -1;
338 HCID = m_DigiMan->GetHitsCollectionID("BesMdcTruthCollection");
339 if(HCID>0)
340 {
341 BesMdcHitsCollection* HC = 0;
342 HC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
343 G4int n_hit = HC->entries();
344 if(n_hit>0)
345 {
346 //arrange hits in hits collection in order of trackIndex
347 BesMdcHit* hit;
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())
352 {
353 hit = (*vecHC)[i];
354 (*vecHC)[i] = (*vecHC)[j];
355 (*vecHC)[j] = hit;
356 }
357
358 //push back MdcMcHits to MdcMcHitCol in TDS
359 for(G4int i=0;i<n_hit;i++)
360 {
361 hit = (*HC)[i];
362 const Identifier ident = MdcID::wire_id ( hit->GetLayerNo(), hit->GetCellNo() );
363 Event::MdcMcHit* mdcMcHit = new Event::MdcMcHit(ident, hit->GetTrackID(),
364 hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(),
365 hit->GetDriftD(), hit->GetEdep(),hit->GetPosFlag() );
366 aMdcMcHitCol->push_back(mdcMcHit);
367 }
368
369 }
370 }
371
372 //register MDC McTruth collection to TDS
373 StatusCode scMdc = m_evtSvc->registerObject("/Event/MC/MdcMcHitCol", aMdcMcHitCol);
374 if(scMdc!=StatusCode::SUCCESS)
375 G4cout<< "Could not register MDC McTruth collection" <<G4endl;
376
377 //retrieve MDC McTruth from TDS
378 /*SmartDataPtr<Event::MdcMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/MdcMcHitCol");
379 if(!aMcHitCol)
380 G4cout<<"Could not retrieve MDC McTruth collection"<<G4endl;
381
382 Event::MdcMcHitCol::iterator iMcHitCol;
383 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
384 {
385 const Identifier ident = (*iMcHitCol)->identify();
386 G4cout<<(*iMcHitCol)->getTrackIndex();
387 G4cout<<" "<<MdcID::layer(ident);
388 G4cout<<" "<<MdcID::wire(ident);
389 G4cout<<" "<<(*iMcHitCol)->getDepositEnergy();
390 G4cout<<" "<<(*iMcHitCol)->getDriftDistance();
391 G4cout<<" "<<(*iMcHitCol)->getPositionX();
392 G4cout<<" "<<(*iMcHitCol)->getPositionY();
393 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
394 G4cout<<G4endl;
395 }
396 G4cout<<"end of retrieve MDC McTruth collection"<<G4endl;
397 */
398}
399
401{
402 //G4cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << G4endl;
403 //G4cout << "INFO : BesSim::BesMcTruthWriter::SaveCgemTruth(), Begin! " << G4endl;
404 /* Cgem McHit collection defined in BOSS */
405 Event::CgemMcHitCol* aCgemMcHitCol = new Event::CgemMcHitCol;
406
407 G4int HCID = -1;
408 G4int BESID = -1;
409 HCID = m_DigiMan->GetHitsCollectionID("BesCgemTruthCollection");
410 BESID = m_DigiMan->GetHitsCollectionID("BesCgemHitsCollection");
411 if (HCID > 0)
412 {
413 BesCgemHitsCollection *HC = 0;
414 HC = (BesCgemHitsCollection*)(m_DigiMan->GetHitsCollection(HCID));
415 BesCgemHitsCollection *BES = 0;
416 /*Add BEShit for Identifier by sunxh*/
417 BES = (BesCgemHitsCollection*)(m_DigiMan->GetHitsCollection(BESID));
418 G4int n_hit = HC->entries();
419 G4int n_BEShit = BES->entries();
420 if (n_hit > 0)
421 {
422 /* arrange hits in hits collection in order of trackIndex */
423 BesCgemHit* hit;
424 BesCgemHit* BEShit;
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())
429 {
430 hit = (*vecHC)[i];
431 (*vecHC)[i] = (*vecHC)[j];
432 (*vecHC)[j] = hit;
433 }
434
435 ///* push back CgemMcHits to CgemMcHitCol in TDS */
436 //for(G4int i=0;i<n_hit;i++)
437 //{
438 //hit = (*HC)[i];
439 //const Identifier ident = CgemID::chip_id ( hit->GetLayerID(), hit->GetSheetID(),
440 // hit->GetChipID(), hit->GetRow(),
441 // hit->GetCol() );
442
443 //ident.show();
444 //G4cout<<" "<<ident.get_valueMSB()<<" "<<ident.get_valueLSB()<<" "<<CgemID::layer(ident)<<" "<<CgemID::ladder(ident)
445 //<<" "<<CgemID::chip(ident) <<" "<<CgemID::row(ident)<<" "<<CgemID::column(ident)<<G4endl;
446
447 //Event::CgemMcHit* cgemMcHit = new Event::CgemMcHit(ident, hit->GetTrackID(),
448 // hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(), hit->GetEdep() );
449 //aCgemMcHitCol->push_back(cgemMcHit);
450 /*for(G4int j=0;j<n_BEShit;j++)
451 {
452 BEShit = (*BES)[j];
453
454 G4cout << "McWriter track_ID1 = "<< BEShit->GetTrackID() << G4endl;
455 G4cout << "McWriter HitID1 = "<< BEShit->GetHitID() << G4endl;
456 TArrayI BES_Ident = BEShit->GetIdentifier();
457 for(int jj = 0; jj < BES_Ident.GetSize(); jj++){
458 G4cout << "McWriter ident1["<<jj<<"] = "<< BES_Ident.GetAt(jj) << G4endl;
459 }
460 }*/
461 /* push back CgemMcHits to CgemMcHitCol in TDS */
462 for(G4int i=0;i<n_hit;i++)
463 {
464 hit = (*HC)[i];
465
466// cout<<"hitTrack_ID = "<<hit->GetTrackID()<<"\thitPDG = "<<hit->GetPDGCode()<<"\thitParent ID = "<<hit->GetParentID()<<endl;
467
468 /* Since no ID in Hit, create McHit without Identifier object */
469 Event::CgemMcHit *cgemMcHit = new Event::CgemMcHit(
470 hit->GetTrackID(), hit->GetLayerID() , hit->GetPDGCode(),
471 hit->GetParentID(), hit->GetTotalEnergyDeposit() ,
472 hit->GetPositionOfPrePoint().x() , hit->GetPositionOfPrePoint().y() ,
473 hit->GetPositionOfPrePoint().z() , hit->GetPositionOfPostPoint().x() ,
474 hit->GetPositionOfPostPoint().y() , hit->GetPositionOfPostPoint().z() ,
475 hit->GetMomentumOfPrePoint().x() , hit->GetMomentumOfPrePoint().y() ,
476 hit->GetMomentumOfPrePoint().z() , hit->GetMomentumOfPostPoint().x() ,
477 hit->GetMomentumOfPostPoint().y() , hit->GetMomentumOfPostPoint().z() );
478 /*
479 hit->GetPrePositionInCu().x() , hit->GetPrePositionInCu().y() ,
480 hit->GetPrePositionInCu().z() , hit->GetPostPositionInCu().x() ,
481 hit->GetPostPositionInCu().y() , hit->GetPostPositionInCu().z() ,
482 hit->GetMomentumOfCuPre().x() , hit->GetMomentumOfCuPre().y() ,
483 hit->GetMomentumOfCuPre().z() , hit->GetMomentumOfCuPost().x() ,
484 hit->GetMomentumOfCuPost().y() , hit->GetMomentumOfCuPost().z() );
485 */
486// G4cout << "McWriter track_ID = "<< hit->GetTrackID() << G4endl;
487 int tmp[2000];
488 int size(0);
489 for(G4int j=0;j<n_BEShit;j++)
490 {
491 BEShit = (*BES)[j];
492// cout<<"BEShitTrack_ID = "<<BEShit->GetTrackID()<<"\tBEShitPDG = "<<BEShit->GetPDGCode()<<"\tBEShitParent ID = "<<BEShit->GetParentID()<<endl;
493 if(BEShit->GetTrackID() != hit->GetTrackID())continue;
494 TArrayI hit_ID = hit->GetIdentifier();
495 for(int ii = 0; ii < hit_ID.GetSize(); ii++){
496 if(hit_ID.GetAt(ii) != BEShit->GetHitID())continue;
497// G4cout << "McWriter EneDp = "<< BEShit->GetTotalEnergyDeposit() << G4endl;
498
499 TArrayI BES_Ident = BEShit->GetIdentifier();
500 for(int jj = 0; jj < BES_Ident.GetSize(); jj++){
501 tmp[size] = BES_Ident.GetAt(jj);
502 size++;
503 }
504 }
505 }
506 cgemMcHit->AddIdentifier(tmp,size);
507 cgemMcHit->SetCreatorProcess(hit->GetCreatorProcess());
508
509 aCgemMcHitCol->push_back(cgemMcHit);
510
511 /*End Add*/
512
513 } /* End of 'for(G4int i=0;i<n_hit;i++)' */
514 } /* End of 'if (n_hit > 0)' */
515 } /* End of 'if (HCID > 0)' */
516 //register CGEM McTruth collection to TDS
517 StatusCode scCgem = m_evtSvc->registerObject("/Event/MC/CgemMcHitCol", aCgemMcHitCol);
518 if(scCgem!=StatusCode::SUCCESS)
519 {
520 G4cout << "ERROR : BesSim::BesMcTruthWriter::SaveCgemTruth(), Could not register CGEM McTruth collection!" << G4endl;
521 }
522
523/*
524 //retrieve CGEM McTruth from TDS
525 SmartDataPtr<Event::CgemMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/CgemMcHitCol");
526 if(!aMcHitCol)
527 G4cout<<"Could not retrieve CGEM McTruth collection"<<G4endl;
528
529 Event::CgemMcHitCol::iterator iMcHitCol;
530 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
531 {
532 cout<<"Track_ID = "<<(*iMcHitCol)->GetTrackID()<<"\tPDG = "<<(*iMcHitCol)->GetPDGCode()<<"\tParent ID = "<<(*iMcHitCol)->GetParentID()<<endl;
533// const Identifier ident = (*iMcHitCol)->identify();
534// G4cout<<(*iMcHitCol)->getTrackIndex();
535// G4cout<<" "<<CgemID::layer(ident);
536// G4cout<<" "<<CgemID::wire(ident);
537// G4cout<<" "<<(*iMcHitCol)->getDepositEnergy();
538// G4cout<<" "<<(*iMcHitCol)->getDriftDistance();
539// G4cout<<" "<<(*iMcHitCol)->getPositionX();
540// G4cout<<" "<<(*iMcHitCol)->getPositionY();
541// G4cout<<" "<<(*iMcHitCol)->getPositionZ();
542// G4cout<<G4endl;
543 }
544 G4cout<<"end of retrieve CGEM McTruth collection"<<G4endl;
545*/
546}
547
549{
550 //Tof McHit collection defined in BOSS
551 Event::TofMcHitCol* aTofMcHitCol = new Event::TofMcHitCol;
552
553 G4int HCID = -1;
554 HCID = m_DigiMan->GetHitsCollectionID("BesTofHitsList");
555 if(HCID>0)
556 {
557 BesTofHitsCollection* HC = 0;
558 HC = (BesTofHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
559 G4int n_hit = HC->entries();
560 if(n_hit>0)
561 {
562 //arrange hits in hits collection in order of trackIndex
563 BesTofHit* hit;
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())
568 {
569 hit = (*vecHC)[i];
570 (*vecHC)[i] = (*vecHC)[j];
571 (*vecHC)[j] = hit;
572 }
573
574 //push back TofMcHit collection to TDS
575 for(G4int i=0;i<n_hit;i++)
576 {
577 hit = (*HC)[i];
578 unsigned int scinNum, barrel_ec, layer = 0;
579 scinNum = hit->GetScinNb();
580 barrel_ec = hit->GetPartId();
581
582 //std::cout << "BesMcTruthWriter PartID | scinNum " << barrel_ec << " | " << scinNum << std::endl;
583 //std::cout << "BesMcTruthWriter is_barrel(barrel_ec) " << TofID::is_barrel(barrel_ec) << std::endl;
584
585
586 if (TofID::is_barrel(barrel_ec) && scinNum > TofID::getPHI_BARREL_MAX()) {
587 layer = 1;
588 scinNum = scinNum - TofID::getPHI_BARREL_MAX() - 1;
589 }
590
591
592
593 Identifier ident;
594
595 if(barrel_ec==0 || barrel_ec==1 || barrel_ec==2 ) //Old-Tof
596 {
597 ident = TofID::cell_id ( barrel_ec, layer, scinNum, 0);
598 }
599 else //MRPC Part
600 {
601 int help = BesTofDigitizerEcV4::Calculate_Readoutstrip_number_continuum(hit->GetPos().x()*mm,hit->GetPos().y()*mm, barrel_ec, scinNum);
603 //std::cout << "BesMcTruthWriter Readoutstrip " << help << std::endl;
604 //std::cout << "BesMcTruthWriter unique Identifier " << scinNum << std::endl;
605 ident = TofID::cell_id_mrpc_mc ( barrel_ec, scinNum);
606 }
607
608
609
610 Event::TofMcHit* tofMcHit = new Event::TofMcHit( ident, hit->GetTrackIndex(),
611 hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(), hit->GetMomentum().x(),
612 hit->GetMomentum().y(), hit->GetMomentum().z(), hit->GetTrackL(), hit->GetTime() );
613
614 aTofMcHitCol->push_back(tofMcHit);
615 }
616 }
617 }
618
619 //register TOF McTruth collection to TDS
620 StatusCode scTof = m_evtSvc->registerObject("/Event/MC/TofMcHitCol", aTofMcHitCol);
621 if(scTof!=StatusCode::SUCCESS)
622 G4cout<< "Could not register TOF McTruth collection" <<G4endl;
623
624 //retrieve TOF McTruth from TDS
625 /*SmartDataPtr<Event::TofMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/TofMcHitCol");
626 if(!aMcHitCol)
627 G4cout<<"Could not retrieve TOF McTruth collection"<<G4endl;
628
629 Event::TofMcHitCol::iterator iMcHitCol;
630 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
631 {
632 const Identifier ident = (*iMcHitCol)->identify();
633 G4cout<<(*iMcHitCol)->getTrackIndex();
634 G4cout<<" "<<TofID::barrel_ec(ident);;
635 G4cout<<" "<<TofID::layer(ident);
636 G4cout<<" "<<TofID::phi_module(ident);
637 G4cout<<" "<<(*iMcHitCol)->getPositionX();
638 G4cout<<" "<<(*iMcHitCol)->getPositionY();
639 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
640 G4cout<<" "<<(*iMcHitCol)->getPx();
641 G4cout<<" "<<(*iMcHitCol)->getPy();
642 G4cout<<" "<<(*iMcHitCol)->getPz();
643 G4cout<<" "<<(*iMcHitCol)->getTrackLength();
644 G4cout<<" "<<(*iMcHitCol)->getFlightTime();
645 G4cout<<G4endl;
646 }
647 G4cout<<"end of retrieve TOF McTruth"<<G4endl;
648 */
649}
650
652{
653 //Emc McHit collection defined in BOSS
654 Event::EmcMcHitCol* aEmcMcHitCol = new Event::EmcMcHitCol;
655
656 G4int fullMc = 1;
657 if(fullMc==1) { //full Mc Truth
658 G4int HCID = -1;
659 HCID = m_DigiMan->GetHitsCollectionID("BesEmcTruthHitsList");
660 if(HCID>0)
661 {
663 HC = (BesEmcTruthHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
664 G4int n_hit = HC->entries();
665 if(n_hit>0)
666 {
667 //arrange hits in hits collection in order of trackIndex
668 BesEmcTruthHit* hit;
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()) {
673 hit = (*vecHC)[i];
674 (*vecHC)[i] = (*vecHC)[j];
675 (*vecHC)[j] = hit;
676 }
677 }
678 }
679
680 for(G4int i=0;i<n_hit;i++)
681 {
682 BesEmcTruthHit* hit;
683 hit = (*HC)[i];
684
685 std::map<Identifier,double> hitMap;
686 std::map<Identifier,double>::const_iterator iHitMap;
687 hitMap.clear();
688 for(iHitMap=hit->Begin();iHitMap!=hit->End();iHitMap++) {
689 hitMap[iHitMap->first]=iHitMap->second;
690 }
691
692 Event::EmcMcHit* emcMcHit = new Event::EmcMcHit(hit->GetIdentify(), hit->GetTrackIndex(),
693 hit->GetPosition().x(), hit->GetPosition().y(), hit->GetPosition().z(),
694 hit->GetMomentum().x(), hit->GetMomentum().y(), hit->GetMomentum().z(),
695 hit->GetEDep() );
696
697 emcMcHit->setHitEmc(hit->GetHitEmc());
698 emcMcHit->setPDGCode(hit->GetPDGCode());
699 emcMcHit->setPDGCharge(hit->GetPDGCharge());
700 emcMcHit->setTime(hit->GetTime());
701 emcMcHit->setHitMap(hitMap);
702
703 aEmcMcHitCol->push_back(emcMcHit);
704 }
705 }
706 }
707 } else { //simple Mc Truth
708 G4int HCID = -1;
709 HCID = m_DigiMan->GetHitsCollectionID("BesEmcHitsList");
710 if(HCID>0)
711 {
712 BesEmcHitsCollection* HC = 0;
713 HC = (BesEmcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
714 G4int n_hit = HC->entries();
715 if(n_hit>0)
716 {
717 //arrange hits in hits collection in order of trackIndex
718 BesEmcHit* hit;
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())
723 {
724 hit = (*vecHC)[i];
725 (*vecHC)[i] = (*vecHC)[j];
726 (*vecHC)[j] = hit;
727 }
728
729 //Emc McHit collection defined in BOSS
730 Event::EmcMcHitCol* aEmcMcHitCol = new Event::EmcMcHitCol;
731
732 for(G4int i=0;i<n_hit;i++)
733 {
734 hit = (*HC)[i];
736
737 std::map<Identifier,double> hitMap;
738 Event::EmcMcHit* emcMcHit = new Event::EmcMcHit(ident, hit->GetTrackIndex(),
739 hit->GetPosCrystal().x(), hit->GetPosCrystal().y(), hit->GetPosCrystal().z(),
740 hit->GetMomentum().x(), hit->GetMomentum().y(), hit->GetMomentum().z(),
741 hit->GetEdepCrystal() );
742
743 aEmcMcHitCol->push_back(emcMcHit);
744 }
745 }
746 }
747 }
748
749 //register EMC McTruth collection to TDS
750 StatusCode scEmc = m_evtSvc->registerObject("/Event/MC/EmcMcHitCol", aEmcMcHitCol);
751 if(scEmc!=StatusCode::SUCCESS)
752 G4cout<< "Could not register EMC McTruth collection" <<G4endl;
753
754 //retrieve EMC McTruth from TDS
755 /*SmartDataPtr<Event::EmcMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/EmcMcHitCol");
756 if(!aMcHitCol)
757 G4cout<<"Could not retrieve EMC McTruth collection"<<G4endl;
758
759 Event::EmcMcHitCol::iterator iMcHitCol;
760 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
761 {
762 const Identifier ident = (*iMcHitCol)->identify();
763 G4cout<<(*iMcHitCol)->getTrackIndex();
764 G4cout<<" "<<EmcID::barrel_ec(ident);
765 G4cout<<" "<<EmcID::theta_module(ident);
766 G4cout<<" "<<EmcID::phi_module(ident);
767 G4cout<<" "<<(*iMcHitCol)->getPositionX();
768 G4cout<<" "<<(*iMcHitCol)->getPositionY();
769 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
770 G4cout<<" "<<(*iMcHitCol)->getPx();
771 G4cout<<" "<<(*iMcHitCol)->getPy();
772 G4cout<<" "<<(*iMcHitCol)->getPz();
773 G4cout<<" "<<(*iMcHitCol)->getDepositEnergy();
774 G4cout<<G4endl;
775 }
776 G4cout<<"end of retrieve EMC McTruth"<<G4endl;
777 */
778}
779
781{
782 //Muc McHit collection defined in BOSS
783 Event::MucMcHitCol* aMucMcHitCol = new Event::MucMcHitCol;
784
785 G4int HCID = -1;
786 HCID = m_DigiMan->GetHitsCollectionID("BesMucHitsList");
787 if(HCID>0)
788 {
789 BesMucHitsCollection* HC = 0;
790 HC = (BesMucHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
791 G4int n_hit = HC->entries();
792 if(n_hit>0)
793 {
794 //arrange hits in hits collection in order of trackIndex
795 BesMucHit* hit;
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())
800 {
801 hit = (*vecHC)[i];
802 (*vecHC)[i] = (*vecHC)[j];
803 (*vecHC)[j] = hit;
804 }
805
806 for(G4int i=0;i<n_hit;i++)
807 {
808 hit = (*HC)[i];
809 Identifier ident = MucID::channel_id ( hit->GetPart(), hit->GetSeg(), hit->GetGap(),
810 hit->GetStrip() );
811 Event::MucMcHit* mucMcHit = new Event::MucMcHit(ident, hit->GetTrackIndex(),
812 hit->GetPos().x(), hit->GetPos().y(), hit->GetPos().z(), hit->GetMomentum().x(),
813 hit->GetMomentum().y(), hit->GetMomentum().z() );
814 aMucMcHitCol->push_back(mucMcHit);
815 }
816
817 }
818 }
819
820 //register MUC McTruth collection to TDS
821 StatusCode scMuc = m_evtSvc->registerObject("/Event/MC/MucMcHitCol", aMucMcHitCol);
822 if(scMuc!=StatusCode::SUCCESS)
823 G4cout<< "Could not register MUC McTruth collection" <<G4endl;
824
825 //retrieve MUC McTruth from TDS
826 /*SmartDataPtr<Event::MucMcHitCol> aMcHitCol(m_evtSvc,"/Event/MC/MucMcHitCol");
827 if(!aMcHitCol)
828 G4cout<<"Could not retrieve MUC McTruth collection"<<G4endl;
829
830 Event::MucMcHitCol::iterator iMcHitCol;
831 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
832 {
833 const Identifier ident = (*iMcHitCol)->identify();
834 G4cout<<(*iMcHitCol)->getTrackIndex();
835 G4cout<<" "<<MucID::part(ident);
836 G4cout<<" "<<MucID::seg(ident);
837 G4cout<<" "<<MucID::gap(ident);
838 G4cout<<" "<<MucID::strip(ident);
839 G4cout<<" "<<(*iMcHitCol)->getPositionX();
840 G4cout<<" "<<(*iMcHitCol)->getPositionY();
841 G4cout<<" "<<(*iMcHitCol)->getPositionZ();
842 G4cout<<" "<<(*iMcHitCol)->getPx();
843 G4cout<<" "<<(*iMcHitCol)->getPy();
844 G4cout<<" "<<(*iMcHitCol)->getPz();
845 G4cout<<G4endl;
846 }
847 G4cout<<"end of retrieve MUC McTruth"<<G4endl;
848 */
849}
850
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::string help()
Definition: HelloServer.cpp:35
G4THitsCollection< BesCgemHit > BesCgemHitsCollection
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesMucHit > BesMucHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
std::map< Identifier, G4double >::const_iterator End() const
Definition: BesEmcHit.cc:182
std::map< Identifier, G4double >::const_iterator Begin() const
Definition: BesEmcHit.cc:177
void AddMother(Event::McParticle *, Event::McParticleCol *)
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)
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 setHitMap(std::map< Identifier, double > &hitMap)
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
bool leafParticle() const
Retrieve whether this is a leaf particle.
Definition: McParticle.cxx:19
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
void addDaughter(const SmartRef< McParticle > d)
add a daugther particle to this particle
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