All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NCRadiativeResonant_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: NCRadiativeResonant
3 // Plugin Type: filter (art v2_05_00)
4 // File: NCRadiativeResonant_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 // Disable the FillTree function
10 // by Keng Jun. 2022
11 
12 
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Core/EDFilter.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "canvas/Utilities/InputTag.h"
20 #include "fhiclcpp/ParameterSet.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 
23 
24 #include "art_root_io/TFileService.h"
25 #include "art/Framework/Services/Registry/ServiceHandle.h"
26 #include "art_root_io/TFileDirectory.h"
27 
28 #include "nusimdata/SimulationBase/MCTruth.h"
29 
30 #include "TTree.h"
31 
32 #include <memory>
33 
34 class NCRadiativeResonant : public art::EDFilter {
35 
36  TTree * ftree;
37 
38  int frun;
39  int fsubrun;
40  int fevent;
41  int fnu_pdg;
42  int fccnc;
43  int fmode;
48 
49 public:
50  explicit NCRadiativeResonant(fhicl::ParameterSet const & p);
51 
52  NCRadiativeResonant(NCRadiativeResonant const &) = delete;
56 
57  void cout_stuff(art::Event & e, bool passed);
58  void FillTree(art::Event & e,
59  size_t const mct_index,
60  size_t const parent_index,
61  bool const is_nc_delta_radiative);
62  void Reset();
63  bool filter(art::Event & e) override;
64 
65 };
66 
67 
68 NCRadiativeResonant::NCRadiativeResonant(fhicl::ParameterSet const & p) :
69  art::EDFilter(p),
70  ftree(nullptr) {
71 
72  art::ServiceHandle<art::TFileService> tfs;
73  ftree = tfs->make<TTree>("NCRadiativeResonantFilter", "");
74 
75  ftree->Branch("run", &frun, "run/I");
76  ftree->Branch("subrun", &fsubrun, "subrun/I");
77  ftree->Branch("event", &fevent, "event/I");
78  ftree->Branch("nu_pdg", &fnu_pdg, "nu_pdg/I");
79  ftree->Branch("ccnc", &fccnc, "ccnc/I");
80  ftree->Branch("mode", &fmode, "mode/I");
81  ftree->Branch("is_nc_delta_radiative", &fis_nc_delta_radiative, "is_nc_delta_radiative/I");
82  ftree->Branch("parent_status_code", &fparent_status_code, "parent_status_code/I");
83  ftree->Branch("parent_pdg", &fparent_pdg, "parent_pdg/I");
84 
85 }
86 
87 
88 //select resonant events, it is not necessary a delta event.
89 void NCRadiativeResonant::cout_stuff(art::Event & e, bool passed = false) {
90 
91  art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct =
92  e.getValidHandle<std::vector<simb::MCTruth>>("generator");
93 
94  std::cout << passed << "\n"
95  << "===========Summary of Truth info===============\n";
96  for(simb::MCTruth const & mct : *ev_mct) {
97  std::cout<<std::setw(9)<<"track ID ";
98  std::cout<<std::setw(12)<<"Pdgcode ";
99  std::cout<<std::setw(11)<<"mother ID ";
100  std::cout<<std::setw(11)<<"Status code "<<std::endl;
101  std::cout << "----------------------------\n";
102  for(int i = 0; i < mct.NParticles(); ++i) {
103  simb::MCParticle const & mcp = mct.GetParticle(i);
104  std::cout<<std::setw(9)<< mcp.TrackId();
105  std::cout<<std::setw(12)<< mcp.PdgCode();
106  std::cout<<std::setw(11)<< mcp.Mother();
107  std::cout<<std::setw(11)<< mcp.StatusCode() << "\n";
108  }
109  }
110 
111 }
112 
113 
115 
116  frun = -1;
117  fsubrun = -1;
118  fevent = -1;
119  fnu_pdg = 0;
120  fccnc = -1;
121  fmode = -2;
122  finteraction_type = -2;
124  fparent_status_code = -1;
125  fparent_pdg = 0;
126 
127 }
128 
129 
130 void NCRadiativeResonant::FillTree(art::Event & e,
131  size_t mct_index,
132  size_t const parent_index,
133  bool const is_nc_delta_radiative) {
134 
135  Reset();
136 
137  frun = e.id().run();
138  fsubrun = e.id().subRun();
139  fevent = e.id().event();
140 
141  art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct =
142  e.getValidHandle<std::vector<simb::MCTruth>>("generator");
143  simb::MCNeutrino const & mcn = ev_mct->at(mct_index).GetNeutrino();
144 
145  fnu_pdg = mcn.Nu().PdgCode();
146  fccnc = mcn.CCNC();
147  fmode = mcn.Mode();
148  finteraction_type = mcn.InteractionType();
149 
150  fis_nc_delta_radiative = is_nc_delta_radiative;
151 
152  if(parent_index != SIZE_MAX) {
153  fparent_status_code = ev_mct->at(mct_index).GetParticle(parent_index).StatusCode();
154  fparent_pdg = ev_mct->at(mct_index).GetParticle(parent_index).PdgCode();
155  }
156 
157  ftree->Fill();
158 
159 }
160 
161 
162 //true - pass; false - reject;
163 bool NCRadiativeResonant::filter(art::Event & e) {
164 
165  art::ValidHandle<std::vector<simb::MCTruth>> const & ev_mct =
166  e.getValidHandle<std::vector<simb::MCTruth>>("generator");
167 
168 
169  //looking for resonant photons...
170  // - Particles from NC interaction
171  // - Particles contian photons with StatusCode 1
172  // - the parent of a photon is not delta0 & delta+ ---> pass
173  // - if the parent of a photon is a photon
174  // - the grandparent of a photon is not delta0 & delta+ ---> pass
175  for(size_t ith = 0; ith < ev_mct->size(); ++ith) {//loop through MCTruth
176 
177  simb::MCTruth const & mct = ev_mct->at(ith);
178 // std::cout<<"Looking at the "<<ith<<"th mctruth particle."<<std::endl;
179  if(mct.GetNeutrino().CCNC() != 1) continue;//only look at nc particles;
180 
181  std::vector<size_t> exiting_photon_parents;
182  for(int jth = 0; jth < mct.NParticles(); ++jth) {//loop through MCParticles
183  simb::MCParticle const & mcp = mct.GetParticle(jth);
184 
185  //CHEKC hardcode, TPC filter:
186  if(abs(mcp.Vx())>210 || abs(mcp.Vy())>210||mcp.Vz()>510 || mcp.Vz()<-1){
187  std::cout<<"OUTSIDE TPC x y z ="<<mcp.Vx()<<" "<<mcp.Vy()<<" "<<mcp.Vz()<<std::endl;
188  exit(0);
189  }
190 
191  if(mcp.TrackId() != jth) {
192  std::cout << "ERROR: " << __LINE__ << " " << __PRETTY_FUNCTION__ << "\nTrackId does not match index\n";
193  exit(1);
194  }
195  if(!(mcp.StatusCode() == 1 && mcp.PdgCode() == 22)) continue;//next, if this is not a photon with StatusCode 1
196  exiting_photon_parents.push_back(mcp.Mother());//collect photon's parents
197  }
198 
199  //looking for delta radiative decay, i.e. mother is a delta with statuscode 3 & daughter is a photon. We don't need exiting deltas.
200  std::vector<size_t> in_nucleus_photons;
201  for(size_t const s : exiting_photon_parents) {
202  simb::MCParticle const & mcp = mct.GetParticle(s);
203  //2114 delta0; 2214 delta+
204  if(abs(mcp.PdgCode()) != 2114 && abs(mcp.PdgCode()) != 2214 ) {//Want mcp as any particles but not delta0+
205 // if(ftree){
206 // FillTree(e, ith, mcp.Mother(), true);
207 // }
208  cout_stuff(e,true);
209  std::cout<<"\nYES a resonant evt: "<<mcp.PdgCode()<<std::endl;
210  return true;
211  }else if(mcp.PdgCode() == 22) {//collect photons;
212  in_nucleus_photons.push_back(mcp.Mother());
213  }
214  }
215 
216  for(size_t const s : in_nucleus_photons) {
217  simb::MCParticle const & mcp = mct.GetParticle(s);
218  if(abs(mcp.PdgCode()) != 2114 && abs(mcp.PdgCode()) != 2214) {
219 // if(ftree) FillTree(e, ith, s, true);
220  cout_stuff(e,true);
221  std::cout<<"\nYES a resonant evt with 2 photons: "<<mcp.PdgCode()<<std::endl;
222  return true;
223  }
224  }
225 
226  }
227 
228 // if(ftree) FillTree(e, 0, SIZE_MAX, false);
229  return false;
230 
231 }
232 
233 
234 DEFINE_ART_MODULE(NCRadiativeResonant)
NCRadiativeResonant & operator=(NCRadiativeResonant const &)=delete
bool filter(art::Event &e) override
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)
T abs(T value)
NCRadiativeResonant(fhicl::ParameterSet const &p)
void cout_stuff(art::Event &e, bool passed)
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
BEGIN_PROLOG could also be cout