2 #include "geant4reweight/src/ReweightBase/G4ReweightStep.hh" 7 G4ReweightTraj * theTraj) {
12 auto d_part = plist[d_index];
14 int d_PDG = d_part->PdgCode();
15 int d_ID = d_part->TrackId();
17 theTraj->AddChild(
new G4ReweightTraj(d_ID, d_PDG, part.
TrackId(),
23 std::map<size_t, std::string> proc_map;
24 for (
auto it = procs.begin(); it != procs.end(); ++it) {
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;
32 bool found_last =
false;
39 const TGeoMaterial * test_material = geo_serv->
Material(test_point);
41 if (!
strcmp(test_material->GetName(),
"LAr")) {
46 traj_PX.push_back(part.
Px(i));
47 traj_PY.push_back(part.
Py(i));
48 traj_PZ.push_back(part.
Pz(i));
50 auto itProc = proc_map.find(i);
51 if (itProc != proc_map.end() && itProc->second ==
"hadElastic") {
52 elastic_indices.push_back(i);
77 for (
size_t i = 1; i < traj_X.size(); ++i) {
79 if (found_last && i == traj_X.size() - 1) {
82 else if (std::find(elastic_indices.begin(), elastic_indices.end(), i) !=
83 elastic_indices.end()){
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];
91 double len = sqrt(dX*dX + dY*dY + dZ*dZ);
93 double preStepP[3] = {traj_PX[i-1]*1.e3,
97 double postStepP[3] = {traj_PX[i]*1.e3,
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));
107 0,
event, preStepP, postStepP,
109 theTraj->AddStep(step);
119 std::vector<G4ReweightTraj *> results;
124 std::map<size_t, std::string> proc_map;
125 for (
auto it = procs.begin(); it != procs.end(); ++it) {
129 std::vector<double> traj_X, traj_Y, traj_Z;
133 std::vector<std::pair<size_t, size_t>>
ranges;
136 bool found_material =
false;
137 size_t start = 0,
end = 0;
139 if (fVerbose) std::cout <<
"N traj pts: " <<
147 const TGeoMaterial * test_material = geo_serv->
Material(test_point);
148 if (!test_material)
continue;
152 std::cout << i <<
" " <<
"LAr: " << test_material->GetDensity() <<
" " <<
153 test_material->GetA() <<
" " << test_material->GetZ() <<
154 " " << x <<
" " << y <<
" " << z <<
158 if (!found_material) {
159 found_material =
true;
174 std::cout << i <<
" " << test_material->GetName() <<
" " <<
175 test_material->GetDensity() <<
" " <<
176 test_material->GetA() <<
" " << test_material->GetZ() <<
177 " " << x <<
" " << y <<
" " << z <<
180 if (found_material) {
181 found_material =
false;
183 ranges.push_back({start,
end});
190 if (found_material) {
198 double mass = part.
Mass()*1.e3;
222 for (
size_t i = 0; i < ranges.size(); ++i) {
224 G4ReweightTraj * theTraj =
new G4ReweightTraj(i, part.
PdgCode(), 0,
event, {0,0});
226 for (
size_t j = ranges[i].first; j < ranges[i].second; ++j) {
231 double len = sqrt(dx*dx + dy*dy + dz*dz);
233 double preStepP[3] = {part.
Px(j)*1.e3,
237 double postStepP[3] = {part.
Px(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));
247 auto itProc = proc_map.find(j);
248 if (itProc != proc_map.end() &&
250 proc = itProc->second;
261 G4ReweightStep *
step =
new G4ReweightStep(i, part.
PdgCode(),
262 0,
event, preStepP, postStepP,
264 theTraj->AddStep(step);
267 results.push_back(theTraj);
270 if (results.size()) {
274 auto d_part = plist[d_index];
276 int d_PDG = d_part->PdgCode();
277 int d_ID = d_part->TrackId();
279 results.back()->AddChild(
new G4ReweightTraj(d_ID, d_PDG,
280 results.size() - 1,
event, {0,0}));
287 const std::vector<G4ReweightTraj *> & trajs, G4MultiReweighter & rw) {
289 for (
size_t i = 0; i < trajs.size(); ++i) {
290 if (trajs[i]->GetNSteps() > 0)
291 weight *= rw.GetWeightFromSetParameters(*trajs[i]);
297 const std::vector<G4ReweightTraj *> & trajs, G4MultiReweighter & rw,
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;
311 std::vector<std::vector<G4ReweightTraj *>>
313 int ID,
int PDG,
const sim::ParticleList & plist,
317 std::deque<int> to_create = {ID};
318 std::vector<std::vector<G4ReweightTraj *>> full_created;
320 while (to_create.size()) {
321 auto part = plist[to_create[0]];
322 std::vector<G4ReweightTraj *> temp_trajs =
324 event, material_name, verbose);
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);
332 std::cout <<
"Adding daughter " << to_create.back() <<
std::endl;
337 if (temp_trajs.size()) {
338 auto last_traj = temp_trajs.back();
340 std::cout <<
"created " << last_traj->GetTrackID() <<
" " <<
343 if (temp_trajs[0]->GetPDG() == PDG) {
344 full_created.push_back(temp_trajs);
347 to_create.pop_front();
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
unsigned int NumberTrajectoryPoints() const
const TLorentzVector & Position(const int i=0) const
double Py(const int i=0) const
const simb::MCTrajectory & Trajectory() const
std::string KeyToProcess(unsigned char const &key) const
double Px(const int i=0) const
double GetNTrajWeightFromSetPars(const std::vector< G4ReweightTraj * > &trajs, G4MultiReweighter &rw)
int NumberDaughters() const
int Daughter(const int i) const
std::string EndProcess() const
bool CreateRWTraj(const simb::MCParticle &part, const sim::ParticleList &plist, art::ServiceHandle< geo::Geometry > geo_serv, int event, G4ReweightTraj *theTraj)
ProcessMap const & TrajectoryProcesses() const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
int strcmp(const String &s1, const String &s2)
double Pz(const int i=0) const
TGeoMaterial const * Material(geo::Point_t const &point) const
Returns the material at the specified position.
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::pair< double, double > GetNTrajPMSigmaWeights(const std::vector< G4ReweightTraj * > &trajs, G4MultiReweighter &rw, size_t iPar)
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)
QTextStream & endl(QTextStream &s)
Event finding and building.