LBNETrajectory.cc
Go to the documentation of this file.
1 //
2 // LBNETrajectory.cc
3 //
4 
5 #include "LBNETrajectory.hh"
6 
7 #include "G4ParticleTable.hh"
8 #include "G4ParticleTypes.hh"
9 #include "G4ParticleDefinition.hh"
10 #include "G4Polyline.hh"
11 #include "G4Circle.hh"
12 #include "G4Colour.hh"
13 #include "G4VisAttributes.hh"
14 #include "G4AttDefStore.hh"
15 #include "G4AttDef.hh"
16 #include "G4AttValue.hh"
17 #include "G4UIcommand.hh"
18 #include "G4VisAttributes.hh"
19 #include "G4VVisManager.hh"
20 #include "G4UnitsTable.hh"
21 #include "G4VProcess.hh"
22 #include "G4ProcessType.hh"
23 #include "G4HadronicProcess.hh"
24 
25 #include "LBNETrackInformation.hh"
26 
27 G4Allocator<LBNETrajectory> myTrajectoryAllocator;
28 
29 //-------------------------------------------------------------------------
31 {
33  fParticleName = "";
34  fPDGCharge = 0;
35  fPDGEncoding = 0;
36  fTrackID = 0;
37  fParentID = 0;
38  fPositionRecord = 0;
39  fMomentum = G4ThreeVector(0.,0.,0.);
40  fMomentumRecord = 0;
41  fVertexPosition = G4ThreeVector(0.,0.,0.);
42  fParticleMass = 0.;
43  fDecayCode = 0;
44  fTgen = 0;
45  fNImpWt = 1.;
46  fPreStepVolume = 0;
47  fStepLength = 0;
51  fTimeStart = 0.;
52  fPolarization = G4ThreeVector(0.,0.,0.);
53  fParentMomentumAtThisProduction = G4ThreeVector(0.,0.,0.); //for ppfx....A. Bashyal
54  fPDGNucleus = 0;
57 
58 }
59 //-------------------------------------------------------------------------
60 LBNETrajectory::LBNETrajectory(const G4Track* aTrack)
61 {
62  fParticleDefinition = aTrack->GetDefinition();
63  fParticleName = fParticleDefinition->GetParticleName();
64  fPDGCharge = fParticleDefinition->GetPDGCharge();
65  fPDGEncoding = fParticleDefinition->GetPDGEncoding();
66  fTrackID = aTrack->GetTrackID();
67  fParentID = aTrack->GetParentID();
69  fPositionRecord -> push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
71  fMomentumRecord -> push_back(aTrack->GetMomentum());
73  fPreStepVolume -> push_back(aTrack->GetVolume()->GetName());
75  fMaterialName -> push_back(aTrack->GetVolume()->GetLogicalVolume()->GetMaterial()->GetName());
76  fStepLength = new DVec();
77  fStepLength -> push_back(aTrack->GetStepLength());
78  fMomentum = aTrack->GetMomentum();
79  fVertexPosition = aTrack->GetPosition();
80  fParticleMass = aTrack->GetDefinition()->GetPDGMass();
81  if (!aTrack->GetLogicalVolumeAtVertex()) {
82 // std::cerr << " LBNETrajectory::LBNETrajectory No logical volume at vertex... ??? " << std::endl;
84  fMaterialName1rst = std::string("Unknown");
85  fVolName1rst = std::string("Unknown");
86  } else {
87  fMaterialNumber1rst = aTrack->GetLogicalVolumeAtVertex()->GetMaterial()->GetIndex();
88  fMaterialName1rst = aTrack->GetLogicalVolumeAtVertex()->GetMaterial()->GetName();
89  fVolName1rst = aTrack->GetLogicalVolumeAtVertex()->GetName();
90  }
91  fTimeStart = aTrack->GetGlobalTime();
92  fPolarization = aTrack->GetPolarization();
93 
94  LBNETrackInformation* info = (LBNETrackInformation*)(aTrack->GetUserInformation());
95  if (info!=0)
96  {
97  fDecayCode = info->GetDecayCode();
98  fTgen = info->GetTgen();
99  fNImpWt = info->GetNImpWt();
101 // std::cerr << " Transfering ImpWeight = " << fNImpWt << " from trInfo, track id " << aTrack->GetTrackID() << std::endl;
102  }
103  else
104  {
105  fDecayCode = 0;
106  fTgen = 0;
107  fNImpWt = 1.;
108  fParentMomentumAtThisProduction = G4ThreeVector(0.,0.,0.);
109  }
110  // Now the tricky bit: Dk2Nu package wants the process name and the nucleus
111  if (aTrack->GetCreatorProcess() != 0)
112  fProcessName = aTrack->GetCreatorProcess()->GetProcessName();
113  else fProcessName = std::string ("BeamParticle");
114  // Well, that one was indeed easy. The PDG of the target nucleus now..
115  fPDGNucleus = 0;
116 // if ((aTrack->GetCreatorProcess() != 0) && (aTrack->GetCreatorProcess()->GetProcessType() == fHadronic)) {
117 // std::cerr << " Hadronic interaction, what do I do to get the nucleus that got hit?!!!" << std::endl;
118 // exit(2);
119 // The goal is dig through the creator process ... but the info is lost..
120 //
121 // const G4HadronicProcess *hProc = static_cast<const G4HadronicProcess* >(aTrack->GetCreatorProcess());
122 // std::cerr << " Current interaction length " << hProc->GetCurrentInteractionLength()
123 // << " name " << hProc->GetProcessName() << " Process sub type " << hProc->GetProcessSubType() << std::endl;
124 // G4IsoParticleChange *ic = G4HadronicProcess::GetIsotopeProductionInfo();
125 // if (ic !=0) {
126 // std::cerr << " .... No Isotope production info.. " << std::endl;
127 // } else {
128 // std::cerr << " .... Isotope is " << ic->GetIsotope() << std::endl;
129 // This access actually causes a crash.. So, the trail is cold regarding getting info about the isotope in questions..
130 // Paul Lebrun, April 2014.
131 // }
132 // }
133 
134 }
135 
136 //-------------------------------------------------------------------------
138  : G4VTrajectory()
139 {
142  fPDGCharge = right.fPDGCharge;
143  fPDGEncoding = right.fPDGEncoding;
144  fTrackID = right.fTrackID;
145  fParentID = right.fParentID;
146  fMomentum = right.fMomentum;
149  fDecayCode = right.fDecayCode;
150  fTgen = right.fTgen;
151  fNImpWt = right.fNImpWt;
155  fStepLength = new DVec();
158 
159  for(size_t i=0;i<right.fPositionRecord->size();i++)
160  {
161  G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.fPositionRecord))[i]);
162  fPositionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
163  }
164  for(size_t i=0;i<right.fMomentumRecord->size();i++)
165  {
166  G4ThreeVector rightMomentum = (G4ThreeVector)((*(right.fMomentumRecord))[i]);
167  fMomentumRecord->push_back(rightMomentum);
168  }
169  for(size_t i=0;i<right.fPreStepVolume->size();i++)
170  {
171  G4String rightPreStepVolume=(G4String)((*(right.fPreStepVolume))[i]);
172  fPreStepVolume->push_back(rightPreStepVolume);
173  }
174  for(size_t i=0;i<right.fStepLength->size();i++)
175  {
176  G4double rightsteplength =(G4double)((*(right.fStepLength))[i]);
177  fStepLength->push_back(rightsteplength);
178  }
179  for(size_t i=0;i<right.fMaterialName->size();i++)
180  {
181  G4String rightMaterialName = (G4String)((*(right.fMaterialName))[i]);
182  fMaterialName->push_back(rightMaterialName);
183  }
185  fVolName1rst = right.fVolName1rst;
187  fTimeStart = right.fTimeStart;
189  fPDGNucleus = right.fPDGNucleus;
190  fProcessName = right.fProcessName;
193 
194 
195 }
196 
197 //----------------------------------------------------------------------
199  : G4VTrajectory()
200 {
201  fParticleName = right -> fParticleName;
203  fPDGCharge = right -> fPDGCharge;
204  fPDGEncoding = right -> fPDGEncoding;
205  fTrackID = right -> fTrackID;
206  fParentID = right -> fParentID;
207  fMomentum = right -> fMomentum;
208  fVertexPosition = right -> fVertexPosition;
209  fParticleMass = right -> fParticleMass;
210  fDecayCode = right -> fDecayCode;
211  fTgen = right -> fTgen;
212  fNImpWt = right -> fNImpWt;
215 
216 
218  for(size_t i=0; i < (right->fPositionRecord)->size(); ++i)
219  {
220  G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right->fPositionRecord))[i]);
221  fPositionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
222  }
223 
225  for(size_t i=0; i < (right->fMomentumRecord)->size(); ++i)
226  {
227  G4ThreeVector rightMomentum = (G4ThreeVector)((*(right->fMomentumRecord))[i]);
228  fMomentumRecord->push_back(rightMomentum);
229  }
230 
232  for(size_t i=0; i < (right->fPreStepVolume)->size(); ++i)
233  {
234  G4String rightPreStepVolume =(G4String)((*(right->fPreStepVolume))[i]);
235  fPreStepVolume->push_back(rightPreStepVolume);
236  }
237 
238  fStepLength = new DVec();
239  for(size_t i=0; i < (right->fStepLength)->size(); ++i)
240  {
241  G4double rightsteplength =(G4double)((*(right->fStepLength))[i]);
242  fStepLength->push_back(rightsteplength);
243  }
244  for(size_t i=0;i<right->fMaterialName->size();i++)
245  {
246  G4String rightMaterialName = (G4String)((*(right->fMaterialName))[i]);
247  fMaterialName->push_back(rightMaterialName);
248  }
249 
251  fVolName1rst = right->fVolName1rst;
253  fTimeStart = right->fTimeStart;
254  fPolarization = right->fPolarization;
255  fPDGNucleus = right->fPDGNucleus;
256  fProcessName = right->fProcessName;
258  fMaterialName = right->fMaterialName;
259 
260 
261 }
262 
263 //-------------------------------------------------------------------------
265 {
266  size_t i;
267  for(i=0;i<fPositionRecord->size();i++)
268  {
269  delete (*fPositionRecord)[i];
270  }
271  fPositionRecord->clear();
272  delete fPositionRecord;
273 
274 
275  fMomentumRecord->clear();
276  delete fMomentumRecord;
277 
278  fPreStepVolume->clear();
279  delete fPreStepVolume;
280 
281  fStepLength->clear();
282  delete fStepLength;
283 
284  fMaterialName->clear();
285  delete fMaterialName;
286 
287 }
288 
289 //-------------------------------------------------------------------------
291 {
292  G4cout << G4endl << "TrackID =" << fTrackID
293  << " : ParentID=" << fParentID << G4endl;
294  G4cout << "Particle name : " << fParticleName
295  << " Charge : " << fPDGCharge << G4endl;
296  G4cout << "Original momentum : " <<
297 G4BestUnit(fMomentum,"Energy") << G4endl;
298  G4cout << "Vertex : " << G4BestUnit(fVertexPosition,"Length") << G4endl;
299  G4cout << " Current trajectory has " << fPositionRecord->size()
300  << " points." << G4endl;
301 
302  for( size_t i=0 ; i < fPositionRecord->size() ; i++){
303  G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*fPositionRecord)[i]);
304  G4cout << "Point[" << i << "]"
305  << " Position= " << aTrajectoryPoint->GetPosition() << G4endl;
306  }
307 }
308 //-------------------------------------------------------------------------
309 void LBNETrajectory::ShowTrajectory(std::ostream& o) const
310 {
311  G4VTrajectory::ShowTrajectory(o);
312 }
313 //-------------------------------------------------------------------------
315 {
316  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
317  G4ThreeVector pos;
318 
319  G4Polyline pPolyline;
320  for (size_t i = 0; i < fPositionRecord->size() ; i++) {
321  G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*fPositionRecord)[i]);
322  pos = aTrajectoryPoint->GetPosition();
323  pPolyline.push_back( pos );
324  }
325 
326  G4Colour color(1.0,1.0,1.0); //white
327 
328  if(fPDGCharge == 0.) color = G4Colour::White();
329  if(fPDGCharge == 1.0) color = G4Colour(1.0, 0.5, 0.0); //orange
330  if(fPDGCharge == -1.0) color = G4Colour(0.5, 0.0, 0.5); //purple
331 
332 
333  if (fParticleDefinition==G4Proton::ProtonDefinition()) color = G4Color::Green();
334  if (fParticleDefinition==G4Neutron::NeutronDefinition()) color = G4Color::Grey();
335  if (fParticleDefinition==G4PionMinus::PionMinusDefinition()) color = G4Color::Cyan();
336  if (fParticleDefinition==G4PionPlus::PionPlusDefinition()) color = G4Color::Blue();
337  if (fParticleDefinition==G4KaonMinus::KaonMinusDefinition()) color = G4Color::Yellow();
338  if (fParticleDefinition==G4KaonPlus::KaonPlusDefinition()) color = G4Color::Yellow();
339  if (fParticleDefinition==G4MuonMinus::MuonMinusDefinition()) color = G4Color::Red();
340  if (fParticleDefinition==G4MuonPlus::MuonPlusDefinition()) color = G4Color::Red();
341 
342  if ((fParticleDefinition == G4NeutrinoE::NeutrinoEDefinition()) ||
343  (fParticleDefinition == G4NeutrinoMu::NeutrinoMuDefinition()) ||
344  (fParticleDefinition == G4NeutrinoTau::NeutrinoTauDefinition()) ||
345  (fParticleDefinition == G4AntiNeutrinoE::AntiNeutrinoEDefinition()) ||
346  (fParticleDefinition == G4AntiNeutrinoMu::AntiNeutrinoMuDefinition()) ||
347  (fParticleDefinition == G4AntiNeutrinoTau::AntiNeutrinoTauDefinition()))
348  color = G4Color::Magenta();
349 
350 
351 
352 
353 
354 
355 
356 G4VisAttributes attribs(color);
357  pPolyline.SetVisAttributes(attribs);
358  if(pVVisManager) pVVisManager->Draw(pPolyline);
359 
360 /*
361  G4Colour colour(0.2,0.2,0.2);
362  if(fParticleDefinition==G4Gamma::GammaDefinition())
363  colour = G4Colour(0.,0.,1.);
364  else if(fParticleDefinition==G4Electron::ElectronDefinition()
365  ||fParticleDefinition==G4Positron::PositronDefinition())
366  colour = G4Colour(1.,1.,0.);
367  else if(fParticleDefinition==G4MuonMinus::MuonMinusDefinition()
368  ||fParticleDefinition==G4MuonPlus::MuonPlusDefinition())
369  colour = G4Colour(0.,1.,0.);
370  else if(fParticleDefinition->GetParticleType()=="meson")
371  {
372  if(fPDGCharge!=0.)
373  colour = G4Colour(1.,0.,0.);
374  else
375  colour = G4Colour(0.5,0.,0.);
376  }
377  else if(fParticleDefinition->GetParticleType()=="baryon")
378  {
379  if(fPDGCharge!=0.)
380  colour = G4Colour(0.,1.,1.);
381  else
382  colour = G4Colour(0.,0.5,0.5);
383  }
384 
385  //
386 
387  //draw only protons,pi+ and pi-
388  G4VisAttributes attribs;
389  if (fParticleDefinition==G4Proton::ProtonDefinition()) {
390  colour=G4Colour(0.,0.,1.);
391  attribs=G4VisAttributes(colour);
392  pPolyline.SetVisAttributes(attribs);
393  if(pVVisManager) pVVisManager->Draw(pPolyline);
394  }
395  if (fParticleDefinition==G4PionMinus::PionMinusDefinition()) {
396  colour=G4Colour(1.,0.,0.);
397  attribs=G4VisAttributes(colour);
398  pPolyline.SetVisAttributes(attribs);
399  if(pVVisManager) pVVisManager->Draw(pPolyline);
400  }
401  if (fParticleDefinition==G4PionPlus::PionPlusDefinition()) {
402  colour=G4Colour(0.,1.,0.);
403  attribs=G4VisAttributes(colour);
404  pPolyline.SetVisAttributes(attribs);
405  if(pVVisManager) pVVisManager->Draw(pPolyline);
406  }
407 
408 */
409 
410 }
411 
412 //-------------------------------------------------------------------------
413 const std::map<G4String,G4AttDef>* LBNETrajectory::GetAttDefs() const
414 {
415  G4bool isNew;
416  std::map<G4String,G4AttDef>* store
417  = G4AttDefStore::GetInstance("LBNETrajectory",isNew);
418  if (isNew)
419  {
420 
421  G4String ID("TrkID");
422  (*store)[ID] = G4AttDef(ID,"Track ID","Physics","","G4int");
423 
424  G4String PID("ParTrkID");
425  (*store)[PID] = G4AttDef(PID,"Parent ID","Physics","","G4int");
426 
427  G4String PN("Name");
428  (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
429 
430  G4String Ch("Q");
431  (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
432 
433  G4String PDG("PDG");
434  (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
435 
436  G4String IMom("IMom");
437  (*store)[IMom] = G4AttDef(IMom, "Momentum at start of trajectory",
438  "Physics","G4BestUnit","G4ThreeVector");
439 
440  G4String IMag("IMomMag");
441  (*store)[IMag] =
442  G4AttDef(IMag, "Magnitude of momentum at start of trajectory",
443  "Physics","G4BestUnit","G4double");
444 
445  G4String NTP("NPts");
446  (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
447 
448  }
449  return store;
450 }
451 //-------------------------------------------------------------------------
452 std::vector<G4AttValue>* LBNETrajectory::CreateAttValues() const
453 {
454  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
455 
456  values->push_back
457  (G4AttValue("TrkID",G4UIcommand::ConvertToString(fTrackID),""));
458 
459  values->push_back
460  (G4AttValue("ParTrkID",G4UIcommand::ConvertToString(fParentID),""));
461 
462  values->push_back(G4AttValue("Name",fParticleName,""));
463 
464  values->push_back
465  (G4AttValue("Q",G4UIcommand::ConvertToString(fPDGCharge),""));
466 
467  values->push_back
468  (G4AttValue("PDG",G4UIcommand::ConvertToString(fPDGEncoding),""));
469 
470  values->push_back
471  (G4AttValue("IMom",G4BestUnit(GetInitialMomentum(),"Energy"),""));
472 
473  values->push_back
474  (G4AttValue("IMomMag",G4BestUnit((GetInitialMomentum()).mag(),"Energy"),""));
475 
476  values->push_back
477  (G4AttValue("NPts",G4UIcommand::ConvertToString(GetPointEntries()),""));
478 
479  return values;
480 }
481 
482 
483 //-------------------------------------------------------------------------
484 void LBNETrajectory::AppendStep(const G4Step* aStep)
485 {
487  ->push_back(new G4TrajectoryPoint(aStep->GetPostStepPoint()
488  ->GetPosition() ));
489  fMomentumRecord->push_back(aStep->GetPostStepPoint()->GetMomentum());
490 
491  G4Track* aTrack=aStep->GetTrack();
492  LBNETrackInformation* info=(LBNETrackInformation*)(aTrack->GetUserInformation());
493  if (info!=0) {
494  fDecayCode=info->GetDecayCode();
496  fTgen=info->GetTgen();
497  }
498  else {fDecayCode=-1;
499  fParentMomentumAtThisProduction = G4ThreeVector(0.,0.,0.);}
500  G4StepPoint * steppoint=aStep->GetPreStepPoint();
501  G4String PreVolumeName=steppoint->GetPhysicalVolume()->GetName();
502  G4String MaterialName =
503  steppoint->GetPhysicalVolume()->GetLogicalVolume()->GetMaterial()->GetName();
504  fPreStepVolume->push_back(PreVolumeName);
505  fStepLength->push_back(aStep->GetStepLength());
506  fMaterialName->push_back(MaterialName);
507 }
508 //-------------------------------------------------------------------------
510 {
511  return (G4ParticleTable::GetParticleTable()->FindParticle(fParticleName));
512 }
513 //-------------------------------------------------------------------------
514 void LBNETrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
515 {
516  if(!secondTrajectory) return;
517 
518  LBNETrajectory* seco = (LBNETrajectory*)secondTrajectory;
519  G4int ent = seco->GetPointEntries();
520  for(int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
521  {
522  fPositionRecord->push_back((*(seco->fPositionRecord))[i]);
523  }
524  delete (*seco->fPositionRecord)[0];
525  seco->fPositionRecord->clear();
526 
527 }
528 
G4Allocator< LBNETrajectory > myTrajectoryAllocator
std::vector< G4double > DVec
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4ParticleDefinition * GetParticleDefinition()
std::string string
Definition: nybbler.cc:12
unsigned int ID
LBNETrajectoryVolumeName * fPreStepVolume
virtual ~LBNETrajectory()
std::vector< G4VTrajectoryPoint * > LBNETrajectoryPointContainer
G4ParticleDefinition * fParticleDefinition
const uint PDG
Definition: qregexp.cpp:140
virtual void ShowTrajectory() const
virtual void DrawTrajectory() const
LBNETrajectoryMaterialName * fMaterialName
LBNETrajectoryMomentumContainer * fMomentumRecord
Q_UINT16 values[128]
G4ThreeVector GetInitialMomentum() const
G4String fMaterialName1rst
G4String fVolName1rst
G4double fParticleMass
G4ThreeVector fVertexPosition
std::size_t color(std::string const &procname)
G4ThreeVector fPolarization
std::vector< G4String > LBNETrajectoryVolumeName
std::vector< G4String > LBNETrajectoryMaterialName
G4double GetNImpWt() const
virtual void AppendStep(const G4Step *aStep)
LBNETrajectoryPointContainer * fPositionRecord
G4ThreeVector fMomentum
G4ThreeVector fParentMomentumAtThisProduction
virtual int GetPointEntries() const
G4String fParticleName
std::vector< G4ThreeVector > LBNETrajectoryMomentumContainer
G4String fProcessName
G4ThreeVector GetParentMomentumAtThisProduction() const