|
| 1 | +//////////////////////////////////////////////////////////////////////// |
| 2 | +// Class: CCDeltaRadiative |
| 3 | +// Plugin Type: filter (art v2_05_00) |
| 4 | +// File: CCDeltaRadiative_module.cc |
| 5 | +// |
| 6 | +// Selects CC events with a photon from a Delta radiative decay. |
| 7 | +// Mirrors NCDeltaRadiative_module.cc but requires CCNC == 0 (charged |
| 8 | +// current) and checks all four Delta charge states (1114, 2114, 2214, 2224). |
| 9 | +//////////////////////////////////////////////////////////////////////// |
| 10 | + |
| 11 | +#include "art/Framework/Core/EDFilter.h" |
| 12 | +#include "art/Framework/Core/ModuleMacros.h" |
| 13 | +#include "art/Framework/Principal/Event.h" |
| 14 | +#include "art/Framework/Principal/Handle.h" |
| 15 | +#include "art/Framework/Principal/Run.h" |
| 16 | +#include "art/Framework/Principal/SubRun.h" |
| 17 | +#include "canvas/Utilities/InputTag.h" |
| 18 | +#include "fhiclcpp/ParameterSet.h" |
| 19 | +#include "messagefacility/MessageLogger/MessageLogger.h" |
| 20 | + |
| 21 | +#include "art_root_io/TFileService.h" |
| 22 | +#include "art/Framework/Services/Registry/ServiceHandle.h" |
| 23 | +#include "art_root_io/TFileDirectory.h" |
| 24 | + |
| 25 | +#include <memory> |
| 26 | + |
| 27 | +#include "nusimdata/SimulationBase/MCTruth.h" |
| 28 | + |
| 29 | +#include "TTree.h" |
| 30 | + |
| 31 | +class CCDeltaRadiative : public art::EDFilter { |
| 32 | + |
| 33 | + TTree * ftree; |
| 34 | + |
| 35 | + int frun; |
| 36 | + int fsubrun; |
| 37 | + int fevent; |
| 38 | + int fnu_pdg; |
| 39 | + int fccnc; |
| 40 | + int fmode; |
| 41 | + int finteraction_type; |
| 42 | + int fis_cc_delta_radiative; |
| 43 | + int fparent_status_code; |
| 44 | + int fparent_pdg; |
| 45 | + |
| 46 | +public: |
| 47 | + explicit CCDeltaRadiative(fhicl::ParameterSet const & p); |
| 48 | + |
| 49 | + CCDeltaRadiative(CCDeltaRadiative const &) = delete; |
| 50 | + CCDeltaRadiative(CCDeltaRadiative &&) = delete; |
| 51 | + CCDeltaRadiative & operator = (CCDeltaRadiative const &) = delete; |
| 52 | + CCDeltaRadiative & operator = (CCDeltaRadiative &&) = delete; |
| 53 | + |
| 54 | + void cout_stuff(art::Event & e, bool passed); |
| 55 | + void FillTree(art::Event & e, |
| 56 | + size_t const mct_index, |
| 57 | + size_t const parent_index, |
| 58 | + bool const is_cc_delta_radiative); |
| 59 | + void Reset(); |
| 60 | + bool filter(art::Event & e) override; |
| 61 | + |
| 62 | +}; |
| 63 | + |
| 64 | + |
| 65 | +CCDeltaRadiative::CCDeltaRadiative(fhicl::ParameterSet const & p) : |
| 66 | + art::EDFilter(p), |
| 67 | + ftree(nullptr) { |
| 68 | + |
| 69 | + art::ServiceHandle<art::TFileService> tfs; |
| 70 | + ftree = tfs->make<TTree>("CCDeltaRadiativeFilter", ""); |
| 71 | + |
| 72 | + ftree->Branch("run", &frun, "run/I"); |
| 73 | + ftree->Branch("subrun", &fsubrun, "subrun/I"); |
| 74 | + ftree->Branch("event", &fevent, "event/I"); |
| 75 | + ftree->Branch("nu_pdg", &fnu_pdg, "nu_pdg/I"); |
| 76 | + ftree->Branch("ccnc", &fccnc, "ccnc/I"); |
| 77 | + ftree->Branch("mode", &fmode, "mode/I"); |
| 78 | + ftree->Branch("is_cc_delta_radiative", &fis_cc_delta_radiative, "is_cc_delta_radiative/I"); |
| 79 | + ftree->Branch("parent_status_code", &fparent_status_code, "parent_status_code/I"); |
| 80 | + ftree->Branch("parent_pdg", &fparent_pdg, "parent_pdg/I"); |
| 81 | + |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +void CCDeltaRadiative::cout_stuff(art::Event & e, bool passed = false) { |
| 86 | + |
| 87 | + art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct = |
| 88 | + e.getValidHandle<std::vector<simb::MCTruth>>("generator"); |
| 89 | + |
| 90 | + std::cout << passed << "\n" |
| 91 | + << "==========================\n"; |
| 92 | + for(simb::MCTruth const & mct : *ev_mct) { |
| 93 | + std::cout << "----------------------------\n"; |
| 94 | + for(int i = 0; i < mct.NParticles(); ++i) { |
| 95 | + simb::MCParticle const & mcp = mct.GetParticle(i); |
| 96 | + std::cout << mcp.TrackId() << " " << mcp.PdgCode() << " " << mcp.Mother() << " " << mcp.StatusCode() << "\n"; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +void CCDeltaRadiative::Reset() { |
| 104 | + |
| 105 | + frun = -1; |
| 106 | + fsubrun = -1; |
| 107 | + fevent = -1; |
| 108 | + fnu_pdg = 0; |
| 109 | + fccnc = -1; |
| 110 | + fmode = -2; |
| 111 | + finteraction_type = -2; |
| 112 | + fis_cc_delta_radiative = -1; |
| 113 | + fparent_status_code = -1; |
| 114 | + fparent_pdg = 0; |
| 115 | + |
| 116 | +} |
| 117 | + |
| 118 | + |
| 119 | +void CCDeltaRadiative::FillTree(art::Event & e, |
| 120 | + size_t const mct_index, |
| 121 | + size_t const parent_index, |
| 122 | + bool const is_cc_delta_radiative) { |
| 123 | + |
| 124 | + Reset(); |
| 125 | + |
| 126 | + frun = e.id().run(); |
| 127 | + fsubrun = e.id().subRun(); |
| 128 | + fevent = e.id().event(); |
| 129 | + |
| 130 | + art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct = |
| 131 | + e.getValidHandle<std::vector<simb::MCTruth>>("generator"); |
| 132 | + simb::MCNeutrino const & mcn = ev_mct->at(mct_index).GetNeutrino(); |
| 133 | + |
| 134 | + fnu_pdg = mcn.Nu().PdgCode(); |
| 135 | + fccnc = mcn.CCNC(); |
| 136 | + fmode = mcn.Mode(); |
| 137 | + finteraction_type = mcn.InteractionType(); |
| 138 | + |
| 139 | + fis_cc_delta_radiative = is_cc_delta_radiative; |
| 140 | + if(parent_index != SIZE_MAX) { |
| 141 | + fparent_status_code = ev_mct->at(mct_index).GetParticle(parent_index).StatusCode(); |
| 142 | + fparent_pdg = ev_mct->at(mct_index).GetParticle(parent_index).PdgCode(); |
| 143 | + } |
| 144 | + |
| 145 | + ftree->Fill(); |
| 146 | + |
| 147 | +} |
| 148 | + |
| 149 | + |
| 150 | +// Returns true if |pdg| matches any Delta charge state (Δ-, Δ0, Δ+, Δ++). |
| 151 | +static bool isDelta(int pdg) { |
| 152 | + int apdg = std::abs(pdg); |
| 153 | + return apdg == 1114 || apdg == 2114 || apdg == 2214 || apdg == 2224; |
| 154 | +} |
| 155 | + |
| 156 | + |
| 157 | +bool CCDeltaRadiative::filter(art::Event & e) { |
| 158 | + |
| 159 | + art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct = |
| 160 | + e.getValidHandle<std::vector<simb::MCTruth>>("generator"); |
| 161 | + |
| 162 | + for(size_t i = 0; i < ev_mct->size(); ++i) { |
| 163 | + |
| 164 | + simb::MCTruth const & mct = ev_mct->at(i); |
| 165 | + // Require charged-current interaction (CCNC == 0). |
| 166 | + if(mct.GetNeutrino().CCNC() != 0) continue; |
| 167 | + |
| 168 | + std::vector<size_t> exiting_photon_parents; |
| 169 | + for(int j = 0; j < mct.NParticles(); ++j) { |
| 170 | + simb::MCParticle const & mcp = mct.GetParticle(j); |
| 171 | + if(mcp.TrackId() != j) { |
| 172 | + std::cout << "ERROR: " << __LINE__ << " " << __PRETTY_FUNCTION__ << "\nTrackId does not match index\n"; |
| 173 | + return false; |
| 174 | + } |
| 175 | + if(!(mcp.StatusCode() == 1 && mcp.PdgCode() == 22)) continue; |
| 176 | + exiting_photon_parents.push_back(mcp.Mother()); |
| 177 | + } |
| 178 | + |
| 179 | + std::vector<size_t> in_nucleus_photons; |
| 180 | + for(size_t const s : exiting_photon_parents) { |
| 181 | + simb::MCParticle const & mcp = mct.GetParticle(s); |
| 182 | + // Require parent vertex inside TPC. |
| 183 | + if(std::abs(mcp.Vx()) > 210 || std::abs(mcp.Vy()) > 210 || mcp.Vz() > 510 || mcp.Vz() < -1) { |
| 184 | + std::cout << "OUTSIDE TPC x y z =" << mcp.Vx() << " " << mcp.Vy() << " " << mcp.Vz() << std::endl; |
| 185 | + return false; |
| 186 | + } |
| 187 | + if(isDelta(mcp.PdgCode())) { |
| 188 | + if(ftree) FillTree(e, i, s, true); |
| 189 | + return true; |
| 190 | + } |
| 191 | + else if(mcp.PdgCode() == 22) { |
| 192 | + in_nucleus_photons.push_back(mcp.Mother()); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + for(size_t const s : in_nucleus_photons) { |
| 197 | + simb::MCParticle const & mcp = mct.GetParticle(s); |
| 198 | + if(isDelta(mcp.PdgCode())) { |
| 199 | + if(ftree) FillTree(e, i, s, true); |
| 200 | + return true; |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + } |
| 205 | + |
| 206 | + if(ftree) FillTree(e, 0, SIZE_MAX, false); |
| 207 | + return false; |
| 208 | + |
| 209 | +} |
| 210 | + |
| 211 | + |
| 212 | +DEFINE_ART_MODULE(CCDeltaRadiative) |
0 commit comments