All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
shower::TCShowerAnalysis Class Reference
Inheritance diagram for shower::TCShowerAnalysis:

Public Member Functions

 TCShowerAnalysis (fhicl::ParameterSet const &pset)
 

Private Member Functions

void beginJob () override
 
void analyze (const art::Event &evt) override
 
void reset ()
 
void truthMatcher (detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> all_hits, std::vector< art::Ptr< recob::Hit >> shower_hits, const simb::MCParticle *&MCparticle, double &Efrac, double &Ecomplet)
 

Private Attributes

TTree * fTree
 
int run
 
int subrun
 
int event
 
int nuPDG_truth
 
int ccnc_truth
 
int mode_truth
 
int nshws
 
int shwid [kMaxShowers]
 
float shwdcosx [kMaxShowers]
 
float shwdcosy [kMaxShowers]
 
float shwdcosz [kMaxShowers]
 
float shwstartx [kMaxShowers]
 
float shwstarty [kMaxShowers]
 
float shwstartz [kMaxShowers]
 
double shwdedx [kMaxShowers][2]
 
int shwbestplane [kMaxShowers]
 
int highestHitsPDG
 
double highestHitsFrac
 
std::string fHitModuleLabel
 
std::string fShowerModuleLabel
 
std::string fGenieGenModuleLabel
 
std::string fDigitModuleLabel
 
calo::CalorimetryAlg fCalorimetryAlg
 

Detailed Description

Definition at line 33 of file TCShowerAnalysis_module.cc.

Constructor & Destructor Documentation

shower::TCShowerAnalysis::TCShowerAnalysis ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 86 of file TCShowerAnalysis_module.cc.

87  : EDAnalyzer(pset)
88  , fHitModuleLabel(pset.get<std::string>("HitModuleLabel", "trajcluster"))
89  , fShowerModuleLabel(pset.get<std::string>("ShowerModuleLabel", "tcshower"))
90  , fGenieGenModuleLabel(pset.get<std::string>("GenieGenModuleLabel", "generator"))
91  , fDigitModuleLabel(pset.get<std::string>("DigitModuleLabel", "largeant"))
92  , fCalorimetryAlg(pset.get<fhicl::ParameterSet>("CalorimetryAlg"))
93 {} // TCShowerTemplateMaker
calo::CalorimetryAlg fCalorimetryAlg

Member Function Documentation

void shower::TCShowerAnalysis::analyze ( const art::Event &  evt)
overrideprivate

Definition at line 131 of file TCShowerAnalysis_module.cc.

132 {
133 
134  run = evt.run();
135  subrun = evt.subRun();
136  event = evt.id().event();
137 
138  art::Handle<std::vector<recob::Hit>> hitListHandle;
139  std::vector<art::Ptr<recob::Hit>> hitlist;
140  if (evt.getByLabel(fHitModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
141 
142  art::Handle<std::vector<sim::SimChannel>> scListHandle;
143  std::vector<art::Ptr<sim::SimChannel>> simchanlist;
144  if (evt.getByLabel(fDigitModuleLabel, scListHandle))
145  art::fill_ptr_vector(simchanlist, scListHandle);
146 
147  art::Handle<std::vector<recob::Shower>> showerListHandle;
148  std::vector<art::Ptr<recob::Shower>> showerlist;
149  if (evt.getByLabel(fShowerModuleLabel, showerListHandle))
150  art::fill_ptr_vector(showerlist, showerListHandle);
151 
152  art::Handle<std::vector<simb::MCTruth>> mctruthListHandle;
153  std::vector<art::Ptr<simb::MCTruth>> mclist;
154  if (evt.getByLabel(fGenieGenModuleLabel, mctruthListHandle))
155  art::fill_ptr_vector(mclist, mctruthListHandle);
156 
157  art::FindManyP<recob::Hit> shwfm(showerListHandle, evt, fShowerModuleLabel);
158 
159  //shower information
160  if (showerListHandle.isValid()) {
161  nshws = showerlist.size();
162 
163  for (int i = 0; i < std::min(int(showerlist.size()), kMaxShowers); ++i) {
164  shwid[i] = showerlist[i]->ID();
165  shwdcosx[i] = showerlist[i]->Direction().X();
166  shwdcosy[i] = showerlist[i]->Direction().Y();
167  shwdcosz[i] = showerlist[i]->Direction().Z();
168  shwstartx[i] = showerlist[i]->ShowerStart().X();
169  shwstarty[i] = showerlist[i]->ShowerStart().Y();
170  shwstartz[i] = showerlist[i]->ShowerStart().Z();
171  for (size_t j = 0; j < (showerlist[i]->dEdx()).size(); ++j) {
172  shwdedx[i][j] = showerlist[i]->dEdx()[j];
173  }
174  shwbestplane[i] = showerlist[i]->best_plane();
175  }
176 
177  } // shower info
178 
179  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
180 
181  if (mclist.size()) {
182  art::Ptr<simb::MCTruth> mctruth = mclist[0];
183  if (mctruth->NeutrinoSet()) {
184 
185  nuPDG_truth = mctruth->GetNeutrino().Nu().PdgCode();
186  ccnc_truth = mctruth->GetNeutrino().CCNC();
187  mode_truth = mctruth->GetNeutrino().Mode();
188 
189  if (showerlist.size()) { // only looks at the first shower since this is
190  // for tcshower
191  std::vector<art::Ptr<recob::Hit>> showerhits = shwfm.at(0);
192  // get shower truth info
193  const simb::MCParticle* particle;
194  double tmpEfrac = 0.0;
195  double tmpEcomplet = 0;
196  truthMatcher(clockData, hitlist, showerhits, particle, tmpEfrac, tmpEcomplet);
197  if (particle) {
198  std::cout << "shower pdg: " << particle->PdgCode() << " efrac " << tmpEfrac << std::endl;
199 
200  highestHitsPDG = particle->PdgCode();
201  highestHitsFrac = tmpEfrac;
202  }
203  }
204  }
205  }
206 
207  fTree->Fill();
208 
209 } // analyze
double shwdedx[kMaxShowers][2]
unsigned int event
Definition: DataStructs.h:634
unsigned int run
Definition: DataStructs.h:635
void truthMatcher(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> all_hits, std::vector< art::Ptr< recob::Hit >> shower_hits, const simb::MCParticle *&MCparticle, double &Efrac, double &Ecomplet)
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
constexpr int kMaxShowers
unsigned int subRun
Definition: DataStructs.h:636
TCEvent evt
Definition: DataStructs.cxx:8
BEGIN_PROLOG could also be cout
void shower::TCShowerAnalysis::beginJob ( )
overrideprivate

Definition at line 98 of file TCShowerAnalysis_module.cc.

99 {
100 
101  art::ServiceHandle<art::TFileService const> tfs;
102 
103  fTree = tfs->make<TTree>("tcshowerana", "tcshowerana");
104  fTree->Branch("run", &run, "run/I");
105  fTree->Branch("subrun", &subrun, "subrun/I");
106  fTree->Branch("event", &event, "event/I");
107 
108  fTree->Branch("nuPDG_truth", &nuPDG_truth, "nuPDG_truth/I");
109  fTree->Branch("ccnc_truth", &ccnc_truth, "ccnc_truth/I");
110  fTree->Branch("mode_truth", &mode_truth, "mode_truth/I");
111 
112  fTree->Branch("nshws", &nshws, "nshws/I");
113  fTree->Branch("shwid", shwid, "shwid[nshws]/I");
114  fTree->Branch("shwdcosx", shwdcosx, "shwdcosx[nshws]/F");
115  fTree->Branch("shwdcosy", shwdcosy, "shwdcosy[nshws]/F");
116  fTree->Branch("shwdcosz", shwdcosz, "shwdcosz[nshws]/F");
117  fTree->Branch("shwstartx", shwstartx, "shwstartx[nshws]/F");
118  fTree->Branch("shwstarty", shwstarty, "shwstarty[nshws]/F");
119  fTree->Branch("shwstartz", shwstartz, "shwstartz[nshws]/F");
120  fTree->Branch("shwdedx", shwdedx, "shwdedx[nshws][2]/D");
121  fTree->Branch("shwbestplane", shwbestplane, "shwbestplane[nshws]/I");
122 
123  fTree->Branch("highestHitsPDG", &highestHitsPDG, "highestHitsPDG/I");
124  fTree->Branch("highestHitsFrac", &highestHitsFrac, "highestHitsFrac/D");
125 
126 } // beginJob
double shwdedx[kMaxShowers][2]
art::ServiceHandle< art::TFileService > tfs
void shower::TCShowerAnalysis::reset ( )
private

Definition at line 214 of file TCShowerAnalysis_module.cc.

215 {
216 
217  run = -99999;
218  subrun = -99999;
219  event = -99999;
220 
221  nuPDG_truth = -99999;
222  ccnc_truth = -99999;
223  mode_truth = -99999;
224 
225  nshws = 0;
226  for (int i = 0; i < kMaxShowers; ++i) {
227  shwid[i] = -99999;
228  shwdcosx[i] = -99999;
229  shwdcosy[i] = -99999;
230  shwdcosz[i] = -99999;
231  shwstartx[i] = -99999;
232  shwstarty[i] = -99999;
233  shwstartz[i] = -99999;
234  for (int j = 0; j < 2; ++j) {
235  shwdedx[i][j] = -99999;
236  }
237  shwbestplane[i] = -99999;
238  }
239 
240  highestHitsPDG = -99999;
241  highestHitsFrac = -99999;
242 
243 } // reset
double shwdedx[kMaxShowers][2]
constexpr int kMaxShowers
void shower::TCShowerAnalysis::truthMatcher ( detinfo::DetectorClocksData const &  clockData,
std::vector< art::Ptr< recob::Hit >>  all_hits,
std::vector< art::Ptr< recob::Hit >>  shower_hits,
const simb::MCParticle *&  MCparticle,
double &  Efrac,
double &  Ecomplet 
)
private

Definition at line 248 of file TCShowerAnalysis_module.cc.

254 {
255 
256  MCparticle = 0;
257  Efrac = 1.0;
258  Ecomplet = 0;
259 
260  art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
261  art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
262  std::map<int, double> trkID_E;
263  for (size_t j = 0; j < shower_hits.size(); ++j) {
264  art::Ptr<recob::Hit> hit = shower_hits[j];
265  // For know let's use collection plane to look at the shower reconstruction
266  if (hit->View() != 1) continue;
267  std::vector<sim::TrackIDE> TrackIDs = bt_serv->HitToEveTrackIDEs(clockData, hit);
268  for (size_t k = 0; k < TrackIDs.size(); k++) {
269  if (trkID_E.find(std::abs(TrackIDs[k].trackID)) == trkID_E.end())
270  trkID_E[std::abs(TrackIDs[k].trackID)] = 0;
271  trkID_E[std::abs(TrackIDs[k].trackID)] += TrackIDs[k].energy;
272  }
273  }
274  double max_E = -999.0;
275  double total_E = 0.0;
276  int TrackID = -999;
277  double partial_E = 0.0;
278 
279  if (!trkID_E.size()) return; // Ghost shower???
280  for (std::map<int, double>::iterator ii = trkID_E.begin(); ii != trkID_E.end(); ++ii) {
281  total_E += ii->second;
282  if ((ii->second) > max_E) {
283  partial_E = ii->second;
284  max_E = ii->second;
285  TrackID = ii->first;
286  }
287  }
288  MCparticle = pi_serv->TrackIdToParticle_P(TrackID);
289 
290  Efrac = partial_E / total_E;
291 
292  // completeness
293  double totenergy = 0;
294  for (size_t k = 0; k < all_hits.size(); ++k) {
295  art::Ptr<recob::Hit> hit = all_hits[k];
296  std::vector<sim::TrackIDE> TrackIDs = bt_serv->HitToEveTrackIDEs(clockData, hit);
297  for (size_t l = 0; l < TrackIDs.size(); ++l) {
298  if (std::abs(TrackIDs[l].trackID) == TrackID) { totenergy += TrackIDs[l].energy; }
299  }
300  }
301  Ecomplet = partial_E / totenergy;
302 
303 } // truthMatcher
std::vector< TrackID > TrackIDs
process_name hit
Definition: cheaterreco.fcl:51
T abs(T value)
pdgs k
Definition: selectors.fcl:22

Member Data Documentation

int shower::TCShowerAnalysis::ccnc_truth
private

Definition at line 55 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::event
private

Definition at line 53 of file TCShowerAnalysis_module.cc.

calo::CalorimetryAlg shower::TCShowerAnalysis::fCalorimetryAlg
private

Definition at line 78 of file TCShowerAnalysis_module.cc.

std::string shower::TCShowerAnalysis::fDigitModuleLabel
private

Definition at line 76 of file TCShowerAnalysis_module.cc.

std::string shower::TCShowerAnalysis::fGenieGenModuleLabel
private

Definition at line 75 of file TCShowerAnalysis_module.cc.

std::string shower::TCShowerAnalysis::fHitModuleLabel
private

Definition at line 73 of file TCShowerAnalysis_module.cc.

std::string shower::TCShowerAnalysis::fShowerModuleLabel
private

Definition at line 74 of file TCShowerAnalysis_module.cc.

TTree* shower::TCShowerAnalysis::fTree
private

Definition at line 50 of file TCShowerAnalysis_module.cc.

double shower::TCShowerAnalysis::highestHitsFrac
private

Definition at line 71 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::highestHitsPDG
private

Definition at line 70 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::mode_truth
private

Definition at line 56 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::nshws
private

Definition at line 57 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::nuPDG_truth
private

Definition at line 54 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::run
private

Definition at line 51 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::shwbestplane[kMaxShowers]
private

Definition at line 67 of file TCShowerAnalysis_module.cc.

float shower::TCShowerAnalysis::shwdcosx[kMaxShowers]
private

Definition at line 59 of file TCShowerAnalysis_module.cc.

float shower::TCShowerAnalysis::shwdcosy[kMaxShowers]
private

Definition at line 60 of file TCShowerAnalysis_module.cc.

float shower::TCShowerAnalysis::shwdcosz[kMaxShowers]
private

Definition at line 61 of file TCShowerAnalysis_module.cc.

double shower::TCShowerAnalysis::shwdedx[kMaxShowers][2]
private

Definition at line 65 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::shwid[kMaxShowers]
private

Definition at line 58 of file TCShowerAnalysis_module.cc.

float shower::TCShowerAnalysis::shwstartx[kMaxShowers]
private

Definition at line 62 of file TCShowerAnalysis_module.cc.

float shower::TCShowerAnalysis::shwstarty[kMaxShowers]
private

Definition at line 63 of file TCShowerAnalysis_module.cc.

float shower::TCShowerAnalysis::shwstartz[kMaxShowers]
private

Definition at line 64 of file TCShowerAnalysis_module.cc.

int shower::TCShowerAnalysis::subrun
private

Definition at line 52 of file TCShowerAnalysis_module.cc.


The documentation for this class was generated from the following file: