20 #include "art_root_io/TFileService.h" 23 #include "geant4reweight/src/ReweightBase/G4ReweighterFactory.hh" 24 #include "geant4reweight/src/ReweightBase/G4Reweighter.hh" 25 #include "geant4reweight/src/ReweightBase/G4ReweightTraj.hh" 26 #include "geant4reweight/src/PropBase/G4ReweightParameterMaker.hh" 27 #include "geant4reweight/src/ReweightBase/G4MultiReweighter.hh" 28 #include "geant4reweight/src/ReweightBase/G4ReweightManager.hh" 41 class G4RWExampleAnalyzer;
43 TFile * theFile = 0x0;
47 theFile =
new TFile(filename.c_str());
48 if (!theFile ||theFile->IsZombie() || !theFile->IsOpen()) {
55 mf::LogInfo(
"pduneana::OpenFile") <<
"File does not exist here. Searching FW_SEARCH_PATH";
58 auto found = sp.find_file(filename, found_filename);
63 mf::LogInfo(
"pduneana::OpenFile") <<
"Found file " << found_filename;
64 theFile =
new TFile(found_filename.c_str());
65 if (!theFile ||theFile->IsZombie() || !theFile->IsOpen()) {
68 throw cet::exception(
"PDSPAnalyzer_module.cc") <<
"Could not open " << found_filename;
163 ParSet(
p.get<std::vector<fhicl::ParameterSet>>(
"ParameterSet")),
181 const sim::ParticleList & plist = pi_serv->
ParticleList();
188 if (!true_beam_particle) {
196 true_beam_len = true_beam_particle->Trajectory().TotalLength();
205 (true_beam_particle->NumberTrajectoryPoints() - 2));
208 for (
int i = 0; i < true_beam_particle->NumberDaughters(); ++i) {
209 int daughterID = true_beam_particle->Daughter(i);
210 auto part = plist[ daughterID ];
211 int pdg = part->PdgCode();
213 if (part->Process().find(
"Inelastic") != std::string::npos) {
217 else if (pdg == -211) {
220 else if (pdg == 111) {
223 else if (pdg == 2212) {
226 else if (pdg == 2112) {
235 if (view2_IDEs.size() > 1) {
236 std::sort(view2_IDEs.begin(), view2_IDEs.end(),
238 {
return (i1->
z < i2->z);});
239 for (
size_t i = 0; i < view2_IDEs.size()-1; ++i) {
240 const sim::IDE * i1 = view2_IDEs[i];
241 const sim::IDE * i2 = view2_IDEs[i+1];
244 double len = sqrt(
std::pow((i1->
x - i2->
x), 2) +
285 std::cout <<
"No reco info. Moving on" <<
std::endl;
289 true_beam_particle->Trajectory();
292 std::map<size_t, std::string> proc_map;
293 for (
auto itProc = true_beam_proc_map.begin();
294 itProc != true_beam_proc_map.end(); ++itProc) {
297 proc_map[itProc->first] =
process;
299 if (process ==
"hadElastic") {
309 1.e3*(true_beam_trajectory.
E(0) - true_beam_particle->Mass()));
310 double p_mag = sqrt(true_beam_trajectory.
Px(0)*true_beam_trajectory.
Px(0) +
311 true_beam_trajectory.
Py(0)*true_beam_trajectory.
Py(0) +
312 true_beam_trajectory.
Pz(0)*true_beam_trajectory.
Pz(0));
316 if (proc_map.find(0) != proc_map.end()) {
323 double x0 = true_beam_trajectory.
X(i-1);
324 double x1 = true_beam_trajectory.
X(i);
325 double y0 = true_beam_trajectory.
Y(i-1);
326 double y1 = true_beam_trajectory.
Y(i);
327 double z0 = true_beam_trajectory.
Z(i-1);
328 double z1 = true_beam_trajectory.
Z(i);
331 (y1 - y0)*(y1 - y0) +
332 (z1 - z0)*(z1 - z0)));
337 1.e3*(true_beam_trajectory.
E(i) - true_beam_particle->Mass()));
338 double p_mag = sqrt(true_beam_trajectory.
Px(i)*true_beam_trajectory.
Px(i) +
339 true_beam_trajectory.
Py(i)*true_beam_trajectory.
Py(i) +
340 true_beam_trajectory.
Pz(i)*true_beam_trajectory.
Pz(i));
344 if (proc_map.find(i) != proc_map.end()) {
353 event = e.id().event();
401 *true_beam_particle, plist,
402 fGeometryService,
event,
"LAr");
404 for (
size_t i = 0; i < trajs.size(); ++i) {
405 if (trajs[i]->GetNSteps() > 0) {
407 for (
size_t j = 0; j <
ParSet.size(); ++j) {
408 std::pair<double, double> pm_weights =
409 MultiRW->GetPlusMinusSigmaParWeight((*trajs[i]), j);
426 for (
size_t i = 0; i <
ParSet.size(); ++i) {
433 bool set_values =
MultiRW->SetAllParameterValues(input);
447 std::vector<std::vector<G4ReweightTraj *>> created;
448 while (to_create.size()) {
449 auto part = plist[to_create[0]];
450 std::vector<G4ReweightTraj *> temp_trajs =
453 if (temp_trajs.size()) {
454 auto last_traj = temp_trajs.back();
455 for (
size_t i = 0; i < last_traj->GetNChilds(); ++i) {
456 if ((last_traj->GetChild(i)->GetPDG() == 2212) ||
457 (last_traj->GetChild(i)->GetPDG() == 2112) ||
458 (
abs(last_traj->GetChild(i)->GetPDG()) == 211) ) {
459 to_create.push_back(last_traj->GetChild(i)->GetTrackID());
463 if (temp_trajs[0]->GetPDG() ==
RW_PDG) {
464 created.push_back(temp_trajs);
467 to_create.erase(to_create.begin());
471 bool new_added =
false;
472 for (
size_t i = 0; i < created.size(); ++i) {
473 std::vector<G4ReweightTraj *> temp_trajs = created[i];
474 for (
size_t j = 0; j < temp_trajs.size(); ++j) {
475 G4ReweightTraj * this_traj = temp_trajs[j];
476 if (this_traj->GetNSteps() > 0) {
477 for (
size_t k = 0;
k <
ParSet.size(); ++
k) {
478 std::pair<double, double> pm_weights =
479 MultiRW->GetPlusMinusSigmaParWeight((*this_traj),
k);
502 fTree = tfs->make<TTree>(
"tree",
"output tree");
552 fTree->Branch(
"g4rw_alt_primary_plus_sigma_weight",
554 fTree->Branch(
"g4rw_alt_primary_minus_sigma_weight",
556 fTree->Branch(
"g4rw_test_primary_plus_sigma_weight",
558 fTree->Branch(
"g4rw_test_primary_minus_sigma_weight",
561 fTree->Branch(
"g4rw_full_primary_plus_sigma_weight",
563 fTree->Branch(
"g4rw_full_primary_minus_sigma_weight",
int true_beam_nPiMinus_daughter
double Z(const size_type i) const
double X(const size_type i) const
std::vector< std::string > g4rw_primary_var
std::vector< double > g4rw_full_primary_minus_sigma_weight
float z
z position of ionization [cm]
std::vector< double > reco_beam_endX
G4ReweightParameterMaker ParMaker
std::vector< double > true_beam_traj_Y
G4ReweightManager RWManager
G4RWExampleAnalyzer & operator=(G4RWExampleAnalyzer const &)=delete
std::vector< double > reco_beam_endZ
const simb::MCParticle * GetGeantGoodParticle(const simb::MCTruth &genTruth, const art::Event &evt) const
G4RWExampleAnalyzer(fhicl::ParameterSet const &p)
double E(const size_type i) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< double > reco_beam_startZ
double Pz(const size_type i) const
std::string KeyToProcess(unsigned char const &key) const
std::vector< double > true_beam_traj_ry
std::string true_beam_endProcess
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
double GetNTrajWeightFromSetPars(const std::vector< G4ReweightTraj * > &trajs, G4MultiReweighter &rw)
int true_beam_nNeutron_daughter
EDAnalyzer(fhicl::ParameterSet const &pset)
std::vector< fhicl::ParameterSet > ParSet
float x
x position of ionization [cm]
int true_beam_nPi0_daughter
std::vector< double > g4rw_alt_primary_minus_sigma_weight
double g4rw_primary_singular_weight
std::vector< double > true_beam_traj_X
double Length(size_t p=0) const
Access to various track properties.
double Y(const size_type i) const
std::vector< double > g4rw_primary_weights
std::vector< double > g4rw_full_primary_plus_sigma_weight
#define DEFINE_ART_MODULE(klass)
std::vector< double > g4rw_primary_plus_sigma_weight
std::vector< double > true_beam_traj_rx
Point_t const & Start() const
Access to track position at different points.
Ionization at a point of the TPC sensitive volume.
const recob::Track * GetPFParticleTrack(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the track associated to this particle. Returns a null pointer if not found.
float energy
energy deposited by ionization by this track ID and time [MeV]
std::vector< double > g4rw_primary_minus_sigma_weight
std::vector< double > reco_beam_len
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
int true_beam_nProton_daughter
std::vector< double > true_beam_dEdX
bool CreateRWTraj(const simb::MCParticle &part, const sim::ParticleList &plist, art::ServiceHandle< geo::Geometry > geo_serv, int event, G4ReweightTraj *theTraj)
std::vector< int > reco_beam_nDaughters
ProcessMap const & TrajectoryProcesses() const
std::vector< double > g4rw_test_primary_minus_sigma_weight
std::string fPFParticleTag
const sim::ParticleList & ParticleList() const
float y
y position of ionization [cm]
G4MultiReweighter * MultiRW
std::string fGeneratorTag
std::vector< double > true_beam_traj_rz
Hierarchical representation of particle flow.
void analyze(art::Event const &e) override
std::vector< double > reco_beam_startY
std::vector< double > true_beam_traj_KE
std::vector< std::string > true_beam_traj_procs
std::vector< double > g4rw_set_weights
std::vector< double > reco_beam_startX
Point_t const & End() const
std::vector< double > g4rw_alt_primary_plus_sigma_weight
double Px(const size_type i) const
bool file_exists(std::string const &qualified_filename)
int true_beam_nElasticScatters
std::vector< double > true_beam_traj_Z
#define MF_LOG_WARNING(category)
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)
TFile * OpenFile(const std::string filename)
int true_beam_nPiPlus_daughter
std::vector< double > true_beam_traj_dx
double Py(const size_type i) const
std::vector< double > g4rw_test_primary_plus_sigma_weight
std::vector< double > reco_beam_endY
std::pair< double, double > GetNTrajPMSigmaWeights(const std::vector< G4ReweightTraj * > &trajs, G4MultiReweighter &rw, size_t iPar)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
std::vector< int > reco_beam_ID
QTextStream & endl(QTextStream &s)
Event finding and building.