CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingVerboseAction.cc
Go to the documentation of this file.
1 // File: TrackingVerboseAction.cc
3 // Creation: P.Arce 09/01
4 // Modifications: porting to CMSSW by M. Stavrianakou 22/03/06
5 // Description:
7 
9 
16 
17 #include "G4Track.hh"
18 #include "G4Event.hh"
19 #include "G4ios.hh"
20 #include "G4TrackingManager.hh"
21 #include "G4EventManager.hh"
22 #include "G4VSteppingVerbose.hh"
23 #include "G4UnitsTable.hh"
24 
25 #include<algorithm>
26 
27 using namespace CLHEP;
28 
30  theTrackingManager(0), fVerbose(0) {
31 
32  fLarge = int(1E10);
33  fDEBUG = p.getUntrackedParameter<bool>("DEBUG",false);
34  fHighEtPhotons = p.getUntrackedParameter<bool>("CheckForHighEtPhotons",false);
35  fG4Verbose = p.getUntrackedParameter<bool>("G4Verbose",false);
36 
37  //----- Set which events are verbose
38  fTVEventMin = p.getUntrackedParameter<int>("EventMin",0);
39  fTVEventMax = p.getUntrackedParameter<int>("EventMax",fLarge);
40  fTVEventStep = p.getUntrackedParameter<int>("EventStep",1);
41 
42  //----- Set which tracks of those events are verbose
43  fTVTrackMin = p.getUntrackedParameter<int>("TrackMin",0);
44  fTVTrackMax = p.getUntrackedParameter<int>("TrackMax",fLarge);
45  fTVTrackStep = p.getUntrackedParameter<int>("TrackStep",1);
46 
47  //----- Set the verbosity level
48  fVerboseLevel = p.getUntrackedParameter<int>("VerboseLevel",1);
49  fPdgIds = p.getUntrackedParameter<std::vector<int> >("PDGids");
50  if (fDEBUG) {
51  G4cout << "TV: fTVTrackMin " << fTVTrackMin
52  << " fTVTrackMax " << fTVTrackMax
53  << " fTVTrackStep " << fTVTrackStep
54  << " fTVEventMin " << fTVEventMin
55  << " fTVEventMax " << fTVEventMax
56  << " fTVEventStep " << fTVEventStep
57  << " fVerboseLevel " << fVerboseLevel
58  << " fG4Verbose " << fG4Verbose
59  << " PDGIds " << fPdgIds.size() << G4endl;
60  for (unsigned int ii=0; ii<fPdgIds.size(); ++ii)
61  G4cout << "TV: PDGId[" << ii << "] = " << fPdgIds[ii] << G4endl;
62  }
63 
64  //----- Set verbosity off to start
65  fTrackingVerboseON = false;
66  fTkVerbThisEventON = false;
67 
68  G4cout << " TrackingVerbose constructed " << G4endl;
69 }
70 
72 
74  TrackingAction * ta =
75  dynamic_cast<TrackingAction*>(G4EventManager::GetEventManager()->GetUserTrackingAction());
77  fVerbose = G4VSteppingVerbose::GetInstance();
78  if (fDEBUG)
79  G4cout << " TV: Get the Tracking Manager: " << theTrackingManager
80  << " and the SteppingVerbose: " << fVerbose << G4endl;
81 }
82 
84  if (evt==0) return;
85  const G4Event * anEvent = (*evt)();
86  if (anEvent==0) return;
87 
88  //----------- Set /tracking/verbose for this event
89  int eventNo = anEvent->GetEventID();
90  if (fDEBUG) G4cout << "TV: trackID: NEW EVENT " << eventNo << G4endl;
91 
92  fTkVerbThisEventON = false;
93  //----- Check if event is in the selected range
94  if (eventNo >= fTVEventMin && eventNo <= fTVEventMax) {
95  if ((eventNo-fTVEventMin) % fTVEventStep == 0) fTkVerbThisEventON = true;
96  }
97 
98  if (fDEBUG)
99  G4cout << " TV: fTkVerbThisEventON " << fTkVerbThisEventON
100  << " fTrackingVerboseON " << fTrackingVerboseON
101  << " fTVEventMin " << fTVEventMin << " fTVEventMax " << fTVEventMax << G4endl;
102  //----- check if verbosity has to be changed
104  if (fTVTrackMin == 0 && fTVTrackMax == fLarge && fTVTrackStep != 1) {
106  fTrackingVerboseON = true;
107  if (fDEBUG) G4cout << "TV: VERBOSEet1 " << eventNo << G4endl;
108  }
109  } else if ((!fTkVerbThisEventON) && (fTrackingVerboseON) ) {
111  fTrackingVerboseON = false;
112  if (fDEBUG) G4cout << "TV: VERBOSEet0 " << eventNo << G4endl;
113  }
114 
115 }
116 
118  const G4Track * aTrack = (*trk)();
119 
120  //----- High ET photon printout
121  //---------- Set /tracking/verbose
122  //----- track is verbose only if event is verbose
123  double tkP = aTrack->GetMomentum().mag();
124  double tkPx = aTrack->GetMomentum().x();
125  double tkPy = aTrack->GetMomentum().y();
126  double tkPz = aTrack->GetMomentum().z();
127 
128  double tvtx = aTrack->GetVertexPosition().x();
129  double tvty = aTrack->GetVertexPosition().y();
130  double tvtz = aTrack->GetVertexPosition().z();
131 
132  double g4t_phi=atan2(tkPy,tkPx);
133 
134  double drpart=sqrt(tkPx*tkPx + tkPy*tkPy);
135 
136  double mythetapart=acos(tkPz/sqrt(drpart*drpart+tkPz*tkPz));
137 
138  double g4t_eta=-log(tan(mythetapart/2.));
139  G4int MytrackNo = aTrack->GetTrackID();
140 
141  if (fHighEtPhotons) {
142  if (aTrack->GetDefinition()->GetParticleName() == "gamma" && aTrack->GetParentID() !=0) {
143  if((tkPx*tkPx + tkPy*tkPy + tkPz*tkPz)>1000.0*1000.0 &&
144  aTrack->GetCreatorProcess()->GetProcessName() == "LCapture") {
145  G4cout << "MY NEW GAMMA " << G4endl;
146  G4cout << "**********************************************************************" << G4endl;
147  G4cout << "MY NEW TRACK ID = " << MytrackNo << "("
148  << aTrack->GetDefinition()->GetParticleName()
149  <<")"<< " PARENT ="<< aTrack->GetParentID() << G4endl;
150  G4cout << "Primary particle: "
151  << aTrack->GetDynamicParticle()->GetPrimaryParticle() << G4endl;
152  G4cout << "Process type: " << aTrack->GetCreatorProcess()->GetProcessType()
153  << " Process name: "
154  << aTrack->GetCreatorProcess()->GetProcessName() << G4endl;
155  G4cout << "ToT E = " << aTrack->GetTotalEnergy()
156  << " KineE = " << aTrack->GetKineticEnergy()
157  << " Tot P = " << tkP << " Pt = " << sqrt(tkPx*tkPx + tkPy*tkPy)
158  << " VTX=(" << tvtx << "," << tvty << "," << tvtz << ")" << G4endl;
159  if (aTrack->GetKineticEnergy() > 1.*GeV
160  && aTrack->GetCreatorProcess()->GetProcessName() != "LCapture")
161  G4cout << " KineE > 1 GeV !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
162  const G4VTouchable* touchable=aTrack->GetTouchable();
163  if (touchable!=0 && touchable->GetVolume()!=0 &&
164  touchable->GetVolume()->GetLogicalVolume()!=0) {
165  G4Material* material=touchable->GetVolume()->GetLogicalVolume()->GetMaterial();
166  G4cout << "G4LCapture Gamma E(GeV) "
167  << aTrack->GetTotalEnergy()/GeV << " "
168  << material->GetName()<< " "
169  << touchable->GetVolume()->GetName() << G4endl;
170  G4cout << "G4LCapture Gamma position(m): "
171  << aTrack->GetPosition()/m << G4endl;
172  G4cout << "G4LCapture created Gamma direction "
173  << aTrack->GetMomentumDirection() << G4endl;
174  G4cout << "G4LCapture gamma (eta,phi) = "
175  << "(" << g4t_eta << "," << g4t_phi << ")" << G4endl;
176  }
177  aTrack->GetUserInformation()->Print();
178  G4cout << "**********************************************************************" << G4endl;
179  }
180  }
181 
182  if (aTrack->GetDefinition()->GetParticleName() == "gamma") {
183  const G4VProcess * proc = aTrack->GetCreatorProcess();
184  double Tgamma = aTrack->GetKineticEnergy();
185  std::string ProcName;
186  const std::string nullstr ("Null_prc");
187  if (proc) ProcName = proc->GetProcessName();
188  else ProcName = nullstr;
189  if (Tgamma > 2.5*GeV ) { //&& ProcName!="Decay" && ProcName!="eBrem")
190  std::string volumeName("_Unknown_Vol_");
191  std::string materialName("_Unknown_Mat_");
192  G4Material * material = 0;
193  G4VPhysicalVolume * pvolume = 0;
194  G4LogicalVolume * lvolume = 0;
195  const G4VTouchable * touchable = aTrack->GetTouchable();
196  if (touchable) pvolume = touchable->GetVolume();
197  if (pvolume) {
198  volumeName = pvolume->GetName();
199  lvolume = pvolume->GetLogicalVolume();
200  }
201  if (lvolume) material = lvolume->GetMaterial();
202  if (material) materialName = material->GetName();
203  G4cout << "**** ALL photons > 2.5 GeV ****" << G4endl;
204  G4cout << ProcName << "**** ALL photons: gamma E(GeV) "
205  << aTrack->GetTotalEnergy()/GeV << " "
206  << materialName << " " << volumeName << G4endl;
207  G4cout << ProcName << "**** ALL photons: gamma position(m): "
208  << aTrack->GetPosition()/m << G4endl;
209  G4cout << ProcName << "**** ALL photons: gamma direction "
210  << aTrack->GetMomentumDirection() << G4endl;
211  G4cout << "**********************************************************************" << G4endl;
212  }
213  }
214  }
215 
216  //---------- Set /tracking/verbose
217  //----- track is verbose only if event is verbose
218  if (fTkVerbThisEventON) {
219  bool trackingVerboseThisTrack = checkTrackingVerbose(aTrack);
220 
221  //----- Set the /tracking/verbose for this track
222  if ((trackingVerboseThisTrack) && (!fTrackingVerboseON) ) {
224  fTrackingVerboseON = true;
225  if (fDEBUG) G4cout << "TV: VERBOSEtt1 " << aTrack->GetTrackID()
226  << G4endl;
227  printTrackInfo(aTrack);
228  } else if ((!trackingVerboseThisTrack) && ( fTrackingVerboseON )) {
230  fTrackingVerboseON = false;
231  if (fDEBUG) G4cout << "TV: VERBOSEtt0 " << aTrack->GetTrackID()
232  << G4endl;
233  }
234  }
235 }
236 
238  const G4Track * aTrack = (*trk)();
239  if (fTkVerbThisEventON) {
240  bool trackingVerboseThisTrack = checkTrackingVerbose(aTrack);
241  if ((trackingVerboseThisTrack) && (fTrackingVerboseON ) &&
242  (fTVTrackMax < fLarge || fTVTrackStep != 1)) {
244  fTrackingVerboseON = false;
245  if (fDEBUG) G4cout << "TV: VERBOSEtt0 " << aTrack->GetTrackID()
246  << G4endl;
247  }
248  }
249 }
250 
251 void TrackingVerboseAction::update(const G4Step* fStep) {
252 
253  if ((fG4Verbose) && (fTrackingVerboseON)) {
254  G4Track* fTrack = fStep->GetTrack();
255  G4cout << std::setw( 5) << fTrack->GetCurrentStepNumber() << " "
256  << std::setw( 8) << G4BestUnit(fTrack->GetPosition().x() , "Length") << " "
257  << std::setw( 8) << G4BestUnit(fTrack->GetPosition().y() , "Length") << " "
258  << std::setw( 8) << G4BestUnit(fTrack->GetPosition().z() , "Length") << " "
259  << std::setw( 9) << G4BestUnit(fTrack->GetKineticEnergy() , "Energy") << " "
260  << std::setw( 8) << G4BestUnit(fStep->GetTotalEnergyDeposit(), "Energy") << " "
261  << std::setw( 8) << G4BestUnit(fStep->GetStepLength() , "Length") << " "
262  << std::setw( 9) << G4BestUnit(fTrack->GetTrackLength() , "Length") << " "
263  << std::setw( 9) << G4BestUnit(fTrack->GetGlobalTime(), "Time") << " ";
264 
265  // Put cut comment here
266  if( fTrack->GetNextVolume() != 0 ) {
267  G4cout << std::setw(11) << fTrack->GetNextVolume()->GetName() << " ";
268  } else {
269  G4cout << std::setw(11) << "OutOfWorld" << " ";
270  }
271  if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != NULL){
272  G4cout << fStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
273  } else {
274  G4cout << "User Limit";
275  }
276  G4cout << G4endl;
277  }
278 }
279 
281  if (fDEBUG) G4cout << " setting verbose level " << verblev << G4endl;
282  if (theTrackingManager!=0) theTrackingManager->SetVerboseLevel(verblev);
283 }
284 
285 bool TrackingVerboseAction::checkTrackingVerbose(const G4Track* aTrack) {
286  int trackNo = aTrack->GetTrackID();
287  bool trackingVerboseThisTrack = false;
288  //----- Check if track is in the selected range
289  if (trackNo >= fTVTrackMin && trackNo <= fTVTrackMax) {
290  if ((trackNo-fTVTrackMin) % fTVTrackStep == 0) trackingVerboseThisTrack = true;
291  }
292  if (trackingVerboseThisTrack && (fPdgIds.size()>0)) {
293  int pdgId = aTrack->GetDefinition()->GetPDGEncoding();
294  if (std::count(fPdgIds.begin(),fPdgIds.end(),pdgId) == 0) trackingVerboseThisTrack = false;
295  }
296  return trackingVerboseThisTrack;
297 }
298 
299 void TrackingVerboseAction::printTrackInfo(const G4Track* aTrack) {
300  G4cout << G4endl
301  << "*******************************************************"
302  << "**************************************************" << G4endl
303  << "* G4Track Information: "
304  << " Particle = " << aTrack->GetDefinition()->GetParticleName()
305  << ","
306  << " Track ID = " << aTrack->GetTrackID()
307  << ","
308  << " Parent ID = " << aTrack->GetParentID() << G4endl
309  << "*******************************************************"
310  << "**************************************************"
311  << G4endl << G4endl;
312  if (fVerbose) fVerbose->TrackingStarted();
313 }
T getUntrackedParameter(std::string const &, T const &) const
const double GeV
Definition: MathUtil.h:16
TrainProcessor *const proc
Definition: MVATrainer.cc:101
std::vector< int > fPdgIds
bool checkTrackingVerbose(const G4Track *)
#define NULL
Definition: scimark2.h:8
void printTrackInfo(const G4Track *)
int ii
Definition: cuy.py:588
G4TrackingManager * theTrackingManager
G4TrackingManager * getTrackManager()
T sqrt(T t)
Definition: SSEVec.h:48
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
G4VSteppingVerbose * fVerbose
void update(const BeginOfRun *)
This routine will be called when the appropriate signal arrives.
void setTrackingVerbose(int verblev)
TrackingVerboseAction(edm::ParameterSet const &p)
tuple log
Definition: cmsBatch.py:347