Functions
protoana::G4ReweightUtils Namespace Reference

Functions

bool CreateRWTraj (const simb::MCParticle &part, const sim::ParticleList &plist, art::ServiceHandle< geo::Geometry > geo_serv, int event, G4ReweightTraj *theTraj)
 
std::vector< G4ReweightTraj * > CreateNRWTrajs (const simb::MCParticle &part, const sim::ParticleList &plist, art::ServiceHandle< geo::Geometry > geo_serv, int event, std::string material_name="LAr", bool fVerbose=false)
 
std::vector< std::vector< G4ReweightTraj * > > BuildHierarchy (int ID, int PDG, const sim::ParticleList &plist, art::ServiceHandle< geo::Geometry > geo_serv, int event, std::string material_name="LAr", bool fVerbose=false)
 
double GetNTrajWeightFromSetPars (const std::vector< G4ReweightTraj * > &trajs, G4MultiReweighter &rw)
 
std::pair< double, double > GetNTrajPMSigmaWeights (const std::vector< G4ReweightTraj * > &trajs, G4MultiReweighter &rw, size_t iPar)
 

Function Documentation

std::vector< std::vector< G4ReweightTraj * > > protoana::G4ReweightUtils::BuildHierarchy ( int  ID,
int  PDG,
const sim::ParticleList &  plist,
art::ServiceHandle< geo::Geometry geo_serv,
int  event,
std::string  material_name = "LAr",
bool  fVerbose = false 
)

Definition at line 312 of file G4ReweightUtils.cxx.

315  {
316 
317  std::deque<int> to_create = {ID};
318  std::vector<std::vector<G4ReweightTraj *>> full_created;
319 
320  while (to_create.size()) {
321  auto part = plist[to_create[0]];
322  std::vector<G4ReweightTraj *> temp_trajs =
323  CreateNRWTrajs(*part, plist, geo_serv,
325  for (int i = 0; i < part->NumberDaughters(); ++i) {
326  int daughter_ID = part->Daughter(i);
327  auto d_part = plist[daughter_ID];
328  if ((d_part->PdgCode() == 2212) || (d_part->PdgCode() == 2112) ||
329  (abs(d_part->PdgCode()) == 211)) {
330  to_create.push_back(daughter_ID);
331  if (verbose)
332  std::cout << "Adding daughter " << to_create.back() << std::endl;
333  }
334  }
335 
336 
337  if (temp_trajs.size()) {
338  auto last_traj = temp_trajs.back();
339  if (verbose)
340  std::cout << "created " << last_traj->GetTrackID() << " " <<
341  last_traj->GetPDG() << std::endl;
342 
343  if (temp_trajs[0]->GetPDG() == PDG) {
344  full_created.push_back(temp_trajs);
345  }
346  }
347  to_create.pop_front();
348  }
349 
350  return full_created;
351 }
unsigned int ID
const uint PDG
Definition: qregexp.cpp:140
T abs(T value)
verbose
Definition: train.py:477
std::vector< G4ReweightTraj * > CreateNRWTrajs(const simb::MCParticle &part, const sim::ParticleList &plist, art::ServiceHandle< geo::Geometry > geo_serv, int event, std::string material_name="LAr", bool fVerbose=false)
QTextStream & endl(QTextStream &s)
Event finding and building.
std::vector< G4ReweightTraj * > protoana::G4ReweightUtils::CreateNRWTrajs ( const simb::MCParticle part,
const sim::ParticleList &  plist,
art::ServiceHandle< geo::Geometry geo_serv,
int  event,
std::string  material_name = "LAr",
bool  fVerbose = false 
)

Definition at line 115 of file G4ReweightUtils.cxx.

118  {
119  std::vector<G4ReweightTraj *> results;
120 
121 
122  //Create process map
123  auto procs = part.Trajectory().TrajectoryProcesses();
124  std::map<size_t, std::string> proc_map;
125  for (auto it = procs.begin(); it != procs.end(); ++it) {
126  proc_map[it->first] = part.Trajectory().KeyToProcess(it->second);
127  }
128 
129  std::vector<double> traj_X, traj_Y, traj_Z;
130  //std::vector<double> traj_PX, traj_PY, traj_PZ;
131  //std::vector<size_t> elastic_indices;
132 
133  std::vector<std::pair<size_t, size_t>> ranges;
134 
135  //bool found_last = false;
136  bool found_material = false;
137  size_t start = 0, end = 0;
138  //G4ReweightTraj theTraj(part.TrackId(), part.PdgCode(), 0, event, {0,0});
139  if (fVerbose) std::cout << "N traj pts: " <<
141  for (size_t i = 0; i < part.NumberTrajectoryPoints(); ++i) {
142  double x = part.Position(i).X();
143  double y = part.Position(i).Y();
144  double z = part.Position(i).Z();
145 
146  geo::Point_t test_point{x, y, z};
147  const TGeoMaterial * test_material = geo_serv->Material(test_point);
148  if (!test_material) continue;
149  //if (!strcmp(test_material->GetName(), material_name)) {
150  if (test_material->GetName() == material_name) {
151  if (fVerbose) {
152  std::cout << i << " " << "LAr: " << test_material->GetDensity() << " " <<
153  test_material->GetA() << " " << test_material->GetZ() <<
154  " " << x << " " << y << " " << z <<
155  std::endl;
156  }
157 
158  if (!found_material) {
159  found_material = true;
160  start = i;
161  }
162 
163  //traj_PX.push_back(part.Px(i));
164  //traj_PY.push_back(part.Py(i));
165  //traj_PZ.push_back(part.Pz(i));
166 
167  //auto itProc = proc_map.find(i);
168  //if (itProc != proc_map.end() && itProc->second == "hadElastic") {
169  // elastic_indices.push_back(i);
170  //}
171  }
172  else {
173  if (fVerbose) {
174  std::cout << i << " " << test_material->GetName() << " " <<
175  test_material->GetDensity() << " " <<
176  test_material->GetA() << " " << test_material->GetZ() <<
177  " " << x << " " << y << " " << z <<
178  std::endl;
179  }
180  if (found_material) {
181  found_material = false;
182  end = i;
183  ranges.push_back({start, end});
184  }
185  }
186 
187  //if (i == part.NumberTrajectoryPoints() - 1)
188  // found_last = true;
189  }
190  if (found_material) {
191  //size_t np = part.NumberTrajectoryPoints();
192  ranges.push_back({start, part.NumberTrajectoryPoints() - 1});
193  //double x = part.Position(np - 1).X();
194  //double y = part.Position(np - 1).Y();
195  //double z = part.Position(np - 1).Z();
196  }
197 
198  double mass = part.Mass()*1.e3;
199 
200  /*switch (abs(part.PdgCode())) {
201  case 211: {
202  mass = 139.57;
203  break;
204  }
205  case 2212: {
206  mass = 938.28;
207  break;
208  }
209  case 2112: {
210  mass = 939.57;
211  break;
212  }
213  case 321: {
214 
215  }
216  default: {
217  return results;
218  break;
219  }
220  }*/
221 
222  for (size_t i = 0; i < ranges.size(); ++i) {
223  //std::cout << ranges[i].first << " " << ranges[i].second << std::endl;
224  G4ReweightTraj * theTraj = new G4ReweightTraj(i, part.PdgCode(), 0, event, {0,0});
225 
226  for (size_t j = ranges[i].first; j < ranges[i].second; ++j) {
227  double dx = part.Position(j+1).X() - part.Position(j).X();
228  double dy = part.Position(j+1).Y() - part.Position(j).Y();
229  double dz = part.Position(j+1).Z() - part.Position(j).Z();
230 
231  double len = sqrt(dx*dx + dy*dy + dz*dz);
232 
233  double preStepP[3] = {part.Px(j)*1.e3,
234  part.Py(j)*1.e3,
235  part.Pz(j)*1.e3};
236 
237  double postStepP[3] = {part.Px(j + 1)*1.e3,
238  part.Py(j + 1)*1.e3,
239  part.Pz(j + 1)*1.e3};
240  if (j == ranges[i].first) {
241  double p_squared = preStepP[0]*preStepP[0] + preStepP[1]*preStepP[1] +
242  preStepP[2]*preStepP[2];
243  theTraj->SetEnergy(sqrt(p_squared + mass*mass));
244  }
245 
246  std::string proc = "default";
247  auto itProc = proc_map.find(j);
248  if (itProc != proc_map.end() &&
249  j != (part.NumberTrajectoryPoints() - 2)) {
250  proc = itProc->second;
251 
252  /*if (proc == "Unknown" ) {
253  proc = "CoulombScat";
254  }*/
255  }
256  //- 2 because the last element is the end of the last step
257  else if (j == (part.NumberTrajectoryPoints() - 2)) {
258  proc = part.EndProcess();
259  }
260  //std::cout << j << " Proc: " << proc << std::endl;
261  G4ReweightStep * step = new G4ReweightStep(i, part.PdgCode(),
262  0, event, preStepP, postStepP,
263  len, proc);
264  theTraj->AddStep(step);
265  }
266 
267  results.push_back(theTraj);
268  }
269 
270  if (results.size()) {
271  //Loop over daughters
272  for (int i = 0; i < part.NumberDaughters(); ++i) {
273  int d_index = part.Daughter(i);
274  auto d_part = plist[d_index];
275 
276  int d_PDG = d_part->PdgCode();
277  int d_ID = d_part->TrackId();
278 
279  results.back()->AddChild(new G4ReweightTraj(d_ID, d_PDG,
280  results.size() - 1, event, {0,0}));
281  }
282  }
283  return results;
284 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
int PdgCode() const
Definition: MCParticle.h:212
double Py(const int i=0) const
Definition: MCParticle.h:231
std::string string
Definition: nybbler.cc:12
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:253
double Mass() const
Definition: MCParticle.h:239
std::string KeyToProcess(unsigned char const &key) const
double Px(const int i=0) const
Definition: MCParticle.h:230
int NumberDaughters() const
Definition: MCParticle.h:217
int Daughter(const int i) const
Definition: MCParticle.cxx:112
std::string EndProcess() const
Definition: MCParticle.h:216
ProcessMap const & TrajectoryProcesses() const
Definition: MCTrajectory.h:188
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
double Pz(const int i=0) const
Definition: MCParticle.h:232
TGeoMaterial const * Material(geo::Point_t const &point) const
Returns the material at the specified position.
list x
Definition: train.py:276
QTextStream & endl(QTextStream &s)
bool protoana::G4ReweightUtils::CreateRWTraj ( const simb::MCParticle part,
const sim::ParticleList &  plist,
art::ServiceHandle< geo::Geometry geo_serv,
int  event,
G4ReweightTraj *  theTraj 
)

Definition at line 4 of file G4ReweightUtils.cxx.

7  {
8 
9  //Loop over daughters
10  for (int i = 0; i < part.NumberDaughters(); ++i) {
11  int d_index = part.Daughter(i);
12  auto d_part = plist[d_index];
13 
14  int d_PDG = d_part->PdgCode();
15  int d_ID = d_part->TrackId();
16 
17  theTraj->AddChild(new G4ReweightTraj(d_ID, d_PDG, part.TrackId(),
18  event, {0,0}));
19  }
20 
21  //Create process map
22  auto procs = part.Trajectory().TrajectoryProcesses();
23  std::map<size_t, std::string> proc_map;
24  for (auto it = procs.begin(); it != procs.end(); ++it) {
25  proc_map[it->first] = part.Trajectory().KeyToProcess(it->second);
26  }
27 
28  std::vector<double> traj_X, traj_Y, traj_Z;
29  std::vector<double> traj_PX, traj_PY, traj_PZ;
30  std::vector<size_t> elastic_indices;
31 
32  bool found_last = false;
33  for (size_t i = 0; i < part.NumberTrajectoryPoints(); ++i) {
34  double x = part.Position(i).X();
35  double y = part.Position(i).Y();
36  double z = part.Position(i).Z();
37 
38  geo::Point_t test_point{x, y, z};
39  const TGeoMaterial * test_material = geo_serv->Material(test_point);
40 
41  if (!strcmp(test_material->GetName(), "LAr")) {
42  traj_X.push_back(x);
43  traj_Y.push_back(y);
44  traj_Z.push_back(z);
45 
46  traj_PX.push_back(part.Px(i));
47  traj_PY.push_back(part.Py(i));
48  traj_PZ.push_back(part.Pz(i));
49 
50  auto itProc = proc_map.find(i);
51  if (itProc != proc_map.end() && itProc->second == "hadElastic") {
52  elastic_indices.push_back(i);
53  }
54  }
55 
56  if (i == part.NumberTrajectoryPoints() - 1)
57  found_last = true;
58  }
59 
60  double mass = 0.;
61 
62  switch (abs(part.PdgCode())) {
63  case 211: {
64  mass = 139.57;
65  break;
66  }
67  case 2212: {
68  mass = 938.28;
69  break;
70  }
71  default: {
72  return false;
73  break;
74  }
75  }
76 
77  for (size_t i = 1; i < traj_X.size(); ++i) {
78  std::string proc = "default";
79  if (found_last && i == traj_X.size() - 1) {
80  proc = part.EndProcess();
81  }
82  else if (std::find(elastic_indices.begin(), elastic_indices.end(), i) !=
83  elastic_indices.end()){
84  proc = "hadElastic";
85  }
86 
87  double dX = traj_X[i] - traj_X[i-1];
88  double dY = traj_Y[i] - traj_Y[i-1];
89  double dZ = traj_Z[i] - traj_Z[i-1];
90 
91  double len = sqrt(dX*dX + dY*dY + dZ*dZ);
92 
93  double preStepP[3] = {traj_PX[i-1]*1.e3,
94  traj_PY[i-1]*1.e3,
95  traj_PZ[i-1]*1.e3};
96 
97  double postStepP[3] = {traj_PX[i]*1.e3,
98  traj_PY[i]*1.e3,
99  traj_PZ[i]*1.e3};
100  if (i == 1) {
101  double p_squared = preStepP[0]*preStepP[0] + preStepP[1]*preStepP[1] +
102  preStepP[2]*preStepP[2];
103  theTraj->SetEnergy(sqrt(p_squared + mass*mass));
104  }
105 
106  G4ReweightStep * step = new G4ReweightStep(part.TrackId(), part.PdgCode(),
107  0, event, preStepP, postStepP,
108  len, proc);
109  theTraj->AddStep(step);
110  }
111 
112  return true;
113 }
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
int PdgCode() const
Definition: MCParticle.h:212
double Py(const int i=0) const
Definition: MCParticle.h:231
std::string string
Definition: nybbler.cc:12
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:253
std::string KeyToProcess(unsigned char const &key) const
double Px(const int i=0) const
Definition: MCParticle.h:230
int NumberDaughters() const
Definition: MCParticle.h:217
int TrackId() const
Definition: MCParticle.h:210
int Daughter(const int i) const
Definition: MCParticle.cxx:112
T abs(T value)
std::string EndProcess() const
Definition: MCParticle.h:216
ProcessMap const & TrajectoryProcesses() const
Definition: MCTrajectory.h:188
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
int strcmp(const String &s1, const String &s2)
Definition: relates.cpp:14
double Pz(const int i=0) const
Definition: MCParticle.h:232
TGeoMaterial const * Material(geo::Point_t const &point) const
Returns the material at the specified position.
list x
Definition: train.py:276
std::pair< double, double > protoana::G4ReweightUtils::GetNTrajPMSigmaWeights ( const std::vector< G4ReweightTraj * > &  trajs,
G4MultiReweighter &  rw,
size_t  iPar 
)

Definition at line 296 of file G4ReweightUtils.cxx.

298  {
299  std::pair<double, double> results = {1., 1.};
300  for (size_t i = 0; i < trajs.size(); ++i) {
301  if (trajs[i]->GetNSteps() > 0) {
302  std::pair<double, double> temp_weight
303  = rw.GetPlusMinusSigmaParWeight(*trajs[i], iPar);
304  results.first *= temp_weight.first;
305  results.second *= temp_weight.second;
306  }
307  }
308  return results;
309 }
double protoana::G4ReweightUtils::GetNTrajWeightFromSetPars ( const std::vector< G4ReweightTraj * > &  trajs,
G4MultiReweighter &  rw 
)

Definition at line 286 of file G4ReweightUtils.cxx.

287  {
288  double weight = 1.;
289  for (size_t i = 0; i < trajs.size(); ++i) {
290  if (trajs[i]->GetNSteps() > 0)
291  weight *= rw.GetWeightFromSetParameters(*trajs[i]);
292  }
293  return weight;
294 }
weight
Definition: test.py:257