CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CheckSecondary.cc
Go to the documentation of this file.
4 
7 
11 
13 
14 #include "G4Step.hh"
15 #include "G4Track.hh"
16 #include "G4VProcess.hh"
17 #include "G4HCofThisEvent.hh"
18 #include "CLHEP/Units/GlobalSystemOfUnits.h"
19 #include "CLHEP/Units/GlobalPhysicalConstants.h"
20 
21 #include <cmath>
22 #include <iostream>
23 #include <iomanip>
24 
26  typeEnumerator(0),
27  nsec(0),procids(0),
28  px(0),py(0),pz(0),
29  mass(0),deltae(0),
30  procs(0),file(0),
31  tree(0) {
32 
33  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("CheckSecondary");
34  std::string saveFile = m_p.getUntrackedParameter<std::string>("SaveInFile", "None");
35  treatSecondary = new TreatSecondary(m_p);
37 
38  nsec = new std::vector<int>();
39  px = new std::vector<double>();
40  py = new std::vector<double>();
41  pz = new std::vector<double>();
42  mass = new std::vector<double>();
43  deltae = new std::vector<double>();
44  procids = new std::vector<int>();
45  procs = new std::vector<std::string>();
46 
47  if (saveFile != "None") {
48  saveToTree = true;
49  tree = bookTree (saveFile);
50  edm::LogInfo("CheckSecondary") << "Instantiate CheckSecondary with first"
51  << " hadronic interaction information"
52  << " to be saved in file " << saveFile;
53  } else {
54  saveToTree = false;
55  edm::LogInfo("CheckSecondary") << "Instantiate CheckSecondary with first"
56  << " hadronic interaction information"
57  << " not saved";
58  }
59 }
60 
62  if (saveToTree) endTree();
63  if (nsec) delete nsec;
64  if (px) delete px;
65  if (py) delete py;
66  if (pz) delete pz;
67  if (mass) delete mass;
68  if (deltae) delete deltae;
69  if (procs) delete procs;
70  if (procids) delete procids;
71  if (typeEnumerator) delete typeEnumerator;
72  if (treatSecondary) delete treatSecondary;
73 }
74 
76 
77  file = new TFile (fileName.c_str(), "RECREATE");
78  file->cd();
79 
80  TTree * t1 = new TTree("T1", "Secondary Particle Information");
81  t1->Branch("SecondaryPx", "std::vector<double>", &px);
82  t1->Branch("SecondaryPy", "std::vector<double>", &py);
83  t1->Branch("SecondaryPz", "std::vector<double>", &pz);
84  t1->Branch("SecondaryMass", "std::vector<double>", &mass);
85  t1->Branch("NumberSecondaries", "std::vector<int>", &nsec);
86  t1->Branch("DeltaEinInteract", "std::vector<double>", &deltae);
87  t1->Branch("ProcessID", "std::vector<int>", &procids);
88  t1->Branch("ProcessNames", "std::vector<std::string>", &procs);
89  return t1;
90 }
91 
93 
94  edm::LogInfo("CheckSecondary") << "Save the Secondary Tree "
95  << tree->GetName() << " (" << tree
96  << ") in file " << file->GetName() << " ("
97  << file << ")";
98  file->cd();
99  tree->Write();
100  file->Close();
101  delete file;
102 }
103 
105 
106  int iev = (*evt)()->GetEventID();
107  LogDebug("CheckSecondary") << "CheckSecondary::=====> Begin of event = "
108  << iev;
109 
110  (*nsec).clear();
111  (*procs).clear();
112  (*procids).clear();
113  (*deltae).clear();
114  (*px).clear();
115  (*py).clear();
116  (*pz).clear();
117  (*mass).clear();
118 }
119 
121 
122  const G4Track * thTk = (*trk)();
123  treatSecondary->initTrack(thTk);
124  if (thTk->GetParentID() <= 0) storeIt = true;
125  else storeIt = false;
126  nHad = 0;
127  LogDebug("CheckSecondary") << "CheckSecondary:: Track " << thTk->GetTrackID()
128  << " Parent " << thTk->GetParentID() << " Flag "
129  << storeIt;
130 }
131 
132 void CheckSecondary::update(const G4Step * aStep) {
133 
135  int procID;
136  bool hadrInt;
137  double deltaE;
138  std::vector<int> charge;
139  std::vector<math::XYZTLorentzVector> tracks = treatSecondary->tracks(aStep,
140  name,
141  procID,
142  hadrInt,
143  deltaE,
144  charge);
145  if (storeIt && hadrInt) {
146  double pInit = (aStep->GetPreStepPoint()->GetMomentum()).mag();
147  double pEnd = (aStep->GetPostStepPoint()->GetMomentum()).mag();
148  nHad++;
149  int sec = (int)(tracks.size());
150  LogDebug("CheckSecondary") << "CheckSecondary:: Hadronic Interaction "
151  << nHad << " of type " << name << " ID "
152  << procID << " with " << sec << " secondaries "
153  << " and Momentum (MeV/c) at start " << pInit
154  << " and at end " << pEnd;
155  (*nsec).push_back(sec);
156  (*procs).push_back(name);
157  (*procids).push_back(procID);
158  (*deltae).push_back(deltaE);
159  if (nHad == 1) {
160  for (int i=0; i<sec; i++) {
161  double m = tracks[i].M();
162  if (charge[i]<0) m = -m;
163  (*px).push_back(tracks[i].Px());
164  (*py).push_back(tracks[i].Py());
165  (*pz).push_back(tracks[i].Pz());
166  (*mass).push_back(m);
167  }
168  }
169  }
170 }
171 
173 
174  LogDebug("CheckSecondary") << "CheckSecondary::EndofEvent =====> Event "
175  << (*evt)()->GetEventID() << " with "
176  << (*nsec).size() << " hadronic collisions with"
177  << " secondaries produced in each step";
178  for (unsigned int i= 0; i < (*nsec).size(); i++)
179  LogDebug("CheckSecondary") << " " << (*nsec)[i] << " from " << (*procs)[i]
180  << " ID " << (*procids)[i] << " ("
182  << ") deltaE = " << (*deltae)[i] << " MeV";
183  LogDebug("CheckSecondary") << "And " << (*mass).size() << " secondaries "
184  << "produced in the first interactions";
185  for (unsigned int i= 0; i < (*mass).size(); i++)
186  LogDebug("CheckSecondary") << "Secondary " << i << " (" << (*px)[i] << ", "
187  << (*py)[i] << ", " << (*pz)[i] << ", "
188  << (*mass)[i] << ")";
189 
190  if (saveToTree) tree->Fill();
191 }
#define LogDebug(id)
T getParameter(std::string const &) const
std::vector< std::string > * procs
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< double > * pz
std::vector< double > * deltae
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::vector< math::XYZTLorentzVector > tracks(const G4Step *step, std::string &procName, int &procID, bool &intr, double &deltaE, std::vector< int > &charges)
std::vector< int > * nsec
G4ProcessTypeEnumerator * typeEnumerator
TTree * bookTree(std::string)
tuple tracks
Definition: testEve_cfg.py:39
void initTrack(const G4Track *trk)
void update(const BeginOfEvent *evt)
This routine will be called when the appropriate signal arrives.
virtual ~CheckSecondary()
std::vector< double > * py
CheckSecondary(const edm::ParameterSet &p)
std::vector< int > * procids
std::vector< double > * px
TreatSecondary * treatSecondary
std::vector< double > * mass