All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NCDeltaRadiative_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: NCDeltaRadiative
3 // Plugin Type: filter (art v2_05_00)
4 // File: NCDeltaRadiative_module.cc
5 //
6 // Generated at Fri Jun 23 10:33:44 2017 by Robert Murrells using cetskelgen
7 // from cetlib version v1_21_00.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDFilter.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 
20 #include "art_root_io/TFileService.h"
21 #include "art/Framework/Services/Registry/ServiceHandle.h"
22 #include "art_root_io/TFileDirectory.h"
23 
24 #include <memory>
25 
26 #include "nusimdata/SimulationBase/MCTruth.h"
27 
28 #include "TTree.h"
29 
30 class NCDeltaRadiative : public art::EDFilter {
31 
32  TTree * ftree;
33 
34  int frun;
35  int fsubrun;
36  int fevent;
37  int fnu_pdg;
38  int fccnc;
39  int fmode;
44 
45 public:
46  explicit NCDeltaRadiative(fhicl::ParameterSet const & p);
47 
48  NCDeltaRadiative(NCDeltaRadiative const &) = delete;
50  NCDeltaRadiative & operator = (NCDeltaRadiative const &) = delete;
52 
53  void cout_stuff(art::Event & e, bool passed);
54  void FillTree(art::Event & e,
55  size_t const mct_index,
56  size_t const parent_index,
57  bool const is_nc_delta_radiative);
58  void Reset();
59  bool filter(art::Event & e) override;
60 
61 };
62 
63 //modified
64 NCDeltaRadiative::NCDeltaRadiative(fhicl::ParameterSet const & p) :
65  art::EDFilter(p),
66  ftree(nullptr) {
67 
68  art::ServiceHandle<art::TFileService> tfs;
69  ftree = tfs->make<TTree>("NCDeltaRadiativeFilter", "");
70 
71  ftree->Branch("run", &frun, "run/I");
72  ftree->Branch("subrun", &fsubrun, "subrun/I");
73  ftree->Branch("event", &fevent, "event/I");
74  ftree->Branch("nu_pdg", &fnu_pdg, "nu_pdg/I");
75  ftree->Branch("ccnc", &fccnc, "ccnc/I");
76  ftree->Branch("mode", &fmode, "mode/I");
77  ftree->Branch("is_nc_delta_radiative", &fis_nc_delta_radiative, "is_nc_delta_radiative/I");
78  ftree->Branch("parent_status_code", &fparent_status_code, "parent_status_code/I");
79  ftree->Branch("parent_pdg", &fparent_pdg, "parent_pdg/I");
80 
81 }
82 
83 
84 void NCDeltaRadiative::cout_stuff(art::Event & e, bool passed = false) {
85 
86  art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct =
87  e.getValidHandle<std::vector<simb::MCTruth>>("generator");
88 
89  std::cout << passed << "\n"
90  << "==========================\n";
91  for(simb::MCTruth const & mct : *ev_mct) {
92  std::cout << "----------------------------\n";
93  for(int i = 0; i < mct.NParticles(); ++i) {
94  simb::MCParticle const & mcp = mct.GetParticle(i);
95  std::cout << mcp.TrackId() << " " << mcp.PdgCode() << " " << mcp.Mother() << " " << mcp.StatusCode() << "\n";
96  }
97  }
98 
99 }
100 
101 
103 
104  frun = -1;
105  fsubrun = -1;
106  fevent = -1;
107  fnu_pdg = 0;
108  fccnc = -1;
109  fmode = -2;
110  finteraction_type = -2;
112  fparent_status_code = -1;
113  fparent_pdg = 0;
114 
115 }
116 
117 
118 void NCDeltaRadiative::FillTree(art::Event & e,
119  size_t mct_index,
120  size_t const parent_index,
121  bool const is_nc_delta_radiative) {
122 
123  Reset();
124 
125  frun = e.id().run();
126  fsubrun = e.id().subRun();
127  fevent = e.id().event();
128 
129  art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct =
130  e.getValidHandle<std::vector<simb::MCTruth>>("generator");
131  simb::MCNeutrino const & mcn = ev_mct->at(mct_index).GetNeutrino();
132 
133  fnu_pdg = mcn.Nu().PdgCode();
134  fccnc = mcn.CCNC();
135  fmode = mcn.Mode();
136  finteraction_type = mcn.InteractionType();
137 
138  fis_nc_delta_radiative = is_nc_delta_radiative;
139  if(parent_index != SIZE_MAX) {
140  fparent_status_code = ev_mct->at(mct_index).GetParticle(parent_index).StatusCode();
141  fparent_pdg = ev_mct->at(mct_index).GetParticle(parent_index).PdgCode();
142  }
143 
144  ftree->Fill();
145 
146 }
147 
148 
149 bool NCDeltaRadiative::filter(art::Event & e) {
150 
151  art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct =
152  e.getValidHandle<std::vector<simb::MCTruth>>("generator");
153 
154  for(size_t i = 0; i < ev_mct->size(); ++i) {
155 
156  simb::MCTruth const & mct = ev_mct->at(i);
157  if(mct.GetNeutrino().CCNC() != 1) continue;
158 
159  std::vector<size_t> exiting_photon_parents;
160  for(int i = 0; i < mct.NParticles(); ++i) {
161  simb::MCParticle const & mcp = mct.GetParticle(i);
162  if(mcp.TrackId() != i) {
163  std::cout << "ERROR: " << __LINE__ << " " << __PRETTY_FUNCTION__ << "\nTrackId does not match index\n";
164  exit(1);
165  }
166  if(!(mcp.StatusCode() == 1 && mcp.PdgCode() == 22)) continue;
167  exiting_photon_parents.push_back(mcp.Mother());
168  }
169 
170  std::vector<size_t> in_nucleus_photons;
171  for(size_t const s : exiting_photon_parents) {
172  simb::MCParticle const & mcp = mct.GetParticle(s);
173  //CHEKC hardcode, TPC filter:
174  if(abs(mcp.Vx())>210 || abs(mcp.Vy())>210||mcp.Vz()>510 || mcp.Vz()<-1){
175  std::cout<<"OUTSIDE TPC x y z ="<<mcp.Vx()<<" "<<mcp.Vy()<<" "<<mcp.Vz()<<std::endl;
176  exit(0);
177  }
178  if(abs(mcp.PdgCode()) == 2114 || abs(mcp.PdgCode()) == 2214) {
179  if(ftree) FillTree(e, i, mcp.PdgCode(), true);
180  return true;
181  }
182  else if(mcp.PdgCode() == 22) {
183  in_nucleus_photons.push_back(mcp.Mother());
184  }
185  }
186 
187  for(size_t const s : in_nucleus_photons) {
188  simb::MCParticle const & mcp = mct.GetParticle(s);
189  if(abs(mcp.PdgCode()) == 2114 || abs(mcp.PdgCode()) == 2214) {
190  if(ftree) FillTree(e, i, s, true);
191  return true;
192  }
193  }
194 
195  }
196 
197  if(ftree) FillTree(e, 0, SIZE_MAX, false);
198  return false;
199 
200 }
201 
202 
203 DEFINE_ART_MODULE(NCDeltaRadiative)
void cout_stuff(art::Event &e, bool passed)
NCDeltaRadiative(fhicl::ParameterSet const &p)
pdgs p
Definition: selectors.fcl:22
void FillTree(art::Event &e, size_t const mct_index, size_t const parent_index, bool const is_nc_delta_radiative)
bool filter(art::Event &e) override
T abs(T value)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
do i e
art::ServiceHandle< art::TFileService > tfs
NCDeltaRadiative & operator=(NCDeltaRadiative const &)=delete
BEGIN_PROLOG could also be cout