Public Member Functions | Private Member Functions | Private Attributes | List of all members
proto::HadCal Class Reference
Inheritance diagram for proto::HadCal:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 HadCal (fhicl::ParameterSet const &p)
 
 HadCal (HadCal const &)=delete
 
 HadCal (HadCal &&)=delete
 
HadCaloperator= (HadCal const &)=delete
 
HadCaloperator= (HadCal &&)=delete
 
void analyze (art::Event const &e) override
 
void beginJob () override
 
void endJob () override
 
void reconfigure (fhicl::ParameterSet const &p)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

double GetEdepHitsMeV (detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::Hit > &hits) const
 
double GetEhitMeV (const recob::Hit &hit) const
 
double GetEhitMeVcorrel (detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const recob::Hit &hit) const
 
double GetEkinMeV (detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit > > &hits, const std::vector< recob::TrackHitMeta const * > &data)
 
double GetEdepEM_MC (art::Event const &e) const
 
double GetEdepEMAtt_MC (art::Event const &e) const
 
double GetEdepEMhAtt_MC (art::Event const &e, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::Hit > &hits) const
 
double GetEdepHAD_MC (art::Event const &e) const
 
double GetEdepHADAtt_MC (art::Event const &e) const
 
double GetEdepHADhAtt_MC (art::Event const &e, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::Hit > &hits) const
 
void ResetVars ()
 

Private Attributes

double fEdepEM_MC
 
double fEdepEMAtt_MC
 
double fEdepEMhAtt_MC
 
double fEdepEM_reco
 
double fEdepEMcorr_ellifetime_reco
 
double fEdepHAD_MC
 
double fEdepHADAtt_MC
 
double fEdepHADhAtt_MC
 
double fEdepHAD_reco
 
double fEdepHADcorr_ellifetime_reco
 
double fMissEn_MC
 
geo::GeometryCore const * fGeometry
 
TTree * fTree
 
TTree * fTreeEntries
 
int fRun
 
int fEvent
 
int fBestView
 
int fNumberOfTracks
 
double fdQdx
 
double fdEdx
 
double fdQ
 
double fdx
 
double fEdepSum
 
double fEdepAllhits
 
double fElectronsToGeV
 
double fResRange
 
double fEnGen
 
double fEkGen
 
double fT0
 
std::ofstream file
 
art::InputTag fNNetModuleLabel
 
std::string fHitModuleLabel
 
std::string fClusterModuleLabel
 
std::string fTrackModuleLabel
 
std::string fCalorimetryModuleLabel
 
std::string fSimulationLabel
 
calo::CalorimetryAlg fCalorimetryAlg
 
std::unordered_map< int, const simb::MCParticle * > fParticleMap
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 60 of file HadCal_module.cc.

Constructor & Destructor Documentation

proto::HadCal::HadCal ( fhicl::ParameterSet const &  p)
explicit

Definition at line 166 of file HadCal_module.cc.

167  :
168  EDAnalyzer(p),
169  fCalorimetryAlg(p.get<fhicl::ParameterSet>("CalorimetryAlg"))
170  // More initializers here.
171 {
172  reconfigure(p);
173  // get a pointer to the geometry service provider
175  file.open("dump.txt");
176 }
geo::GeometryCore const * fGeometry
std::ofstream file
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
void reconfigure(fhicl::ParameterSet const &p)
p
Definition: test.py:223
calo::CalorimetryAlg fCalorimetryAlg
proto::HadCal::HadCal ( HadCal const &  )
delete
proto::HadCal::HadCal ( HadCal &&  )
delete

Member Function Documentation

void proto::HadCal::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 237 of file HadCal_module.cc.

238 {
239  // Implementation of required member function here.
240  ResetVars();
241 
242  fRun = e.run();
243  fEvent = e.id().event();
244 
245  // MC particle list
246  auto particleHandle = e.getValidHandle< std::vector<simb::MCParticle> >(fSimulationLabel);
247  bool flag = true;
248 
249  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(e);
250  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataFor(e, clockData);
251 
252  for (auto const& p : *particleHandle)
253  {
254  fParticleMap[p.TrackId()] = &p;
255  if ((p.Process() == "primary") && flag)
256  {
257  fEnGen = p.P();
258  fEkGen = (std::sqrt(p.P()*p.P() + p.Mass()*p.Mass()) - p.Mass()) * 1000; // MeV
259  fT0 = p.T();
260  flag = false;
261  }
262  }
263 
266 
269 
270  // hits
271  const auto& hitListHandle = *e.getValidHandle< std::vector<recob::Hit> >(fHitModuleLabel);
272  fEdepAllhits = GetEdepHitsMeV(clockData, detProp, hitListHandle);
273 
274  // MC associated with a hit
275  fEdepEMhAtt_MC = GetEdepEMhAtt_MC(e, clockData, detProp, hitListHandle);
276  fEdepHADhAtt_MC = GetEdepHADhAtt_MC(e, clockData, detProp, hitListHandle);
277 
278  // MC missing energy
280 
281  // clusters
283 
284  std::unordered_map<int, bool> hitIDE;
285  if (cluResults)
286  {
287  const art::FindManyP< recob::Hit > hitsFromCluster(cluResults->dataHandle(), e, cluResults->dataTag());
288 
289  for (size_t c = 0; c < cluResults->size(); ++c)
290  {
291  for (size_t h = 0; h < hitsFromCluster.at(c).size(); ++h)
292  {
293  if (hitsFromCluster.at(c)[h]->View() == fBestView)
294  {
295  hitIDE[hitsFromCluster.at(c)[h].key()] = false;
296  }
297  }
298  }
299  }
300 
301  // tracks
302  fNumberOfTracks = 0;
303  auto trkHandle = e.getValidHandle< std::vector<recob::Track> >(fTrackModuleLabel);
304  art::FindManyP< recob::PFParticle > pfpFromTrack(trkHandle, e, fTrackModuleLabel);
305 
306  const art::FindManyP< anab::Calorimetry > calFromTracks(trkHandle, e, fCalorimetryModuleLabel);
307  const art::FindManyP< recob::Hit > hitsFromTracks(trkHandle, e, fTrackModuleLabel);
308  const art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trkHandle, e, fTrackModuleLabel);
309 
310  if (fmthm.isValid())
311  {
312  // loop over tracks
313  for (size_t t = 0; t < trkHandle->size(); ++t)
314  {
315  auto vhit = fmthm.at(t);
316  auto vmeta = fmthm.data(t);
317 
318  // mark that hits have been used
319  for (size_t h = 0; h < hitsFromTracks.at(t).size(); ++h)
320  {
321  if (hitsFromTracks.at(t)[h]->View() == fBestView)
322  {
323  hitIDE[hitsFromTracks.at(t)[h].key()] = true;
324  }
325  }
326 
327  int nplanes = calFromTracks.at(t).size();
328 
329  for (size_t p = 0; p < pfpFromTrack.at(t).size(); ++p)
330  {
331  int pdg = pfpFromTrack.at(t)[p]->PdgCode();
332  // condition for tracks
333  if ((pdg != 11) && (pdg != -11))
334  {
335  fNumberOfTracks++;
336 
337  // for now it work for 3 planes and only collection view
338  if (nplanes == 3)
339  {
340  // fHadEnSum += GetEkinMeV(vhit, vmeta);
341  for (size_t h = 0; h < hitsFromTracks.at(t).size(); ++h)
342  {
343  if (hitsFromTracks.at(t)[h]->View() == fBestView)
344  {
345  fEdepHAD_reco += GetEhitMeV(*hitsFromTracks.at(t)[h]);
346  fEdepHADcorr_ellifetime_reco += GetEhitMeVcorrel(clockData, detProp, *hitsFromTracks.at(t)[h]);
347  }
348  }
349  }
350  }
351  else // ... and condition for em showers
352  {
353  for (size_t h = 0; h < hitsFromTracks.at(t).size(); ++h)
354  {
355  // kinetic energy without correction for recombination,
356  // only one view is considered
357  if (hitsFromTracks.at(t)[h]->View() == fBestView)
358  {
359  fEdepEM_reco += GetEhitMeV(*hitsFromTracks.at(t)[h]);
360  fEdepEMcorr_ellifetime_reco += GetEhitMeVcorrel(clockData, detProp, *hitsFromTracks.at(t)[h]);
361  }
362  }
363  }
364  }
365  }
366  }
367 
368  // output from cnn's
369  if (cluResults)
370  {
371  const art::FindManyP< recob::Hit > hitsFromCluster(cluResults->dataHandle(), e, cluResults->dataTag());
372 
373  // loop over clusters
374  for (size_t c = 0; c < cluResults->size(); ++c)
375  {
376  if (cluResults->item(c).View() == fBestView)
377  {
378  std::array< float, MVA_LENGTH > cnn_out = cluResults->getOutput(c);
379  double p_trk_or_sh = cnn_out[0] + cnn_out[1];
380  double pdg = 1;
381  if (p_trk_or_sh > 0) pdg = cnn_out[1] / p_trk_or_sh;
382 
383  for (size_t h = 0; h < hitsFromCluster.at(c).size(); ++h)
384  {
385  if (hitIDE[hitsFromCluster.at(c)[h].key()] == false)
386  {
387  hitIDE[hitsFromCluster.at(c)[h].key()] = true;
388 
389  if (pdg < 0.63)
390  {
391  fEdepHAD_reco += GetEhitMeV(*hitsFromCluster.at(c)[h]);
392  fEdepHADcorr_ellifetime_reco += GetEhitMeVcorrel(clockData, detProp, *hitsFromCluster.at(c)[h]);
393  }
394  else
395  {
396  fEdepEM_reco += GetEhitMeV(*hitsFromCluster.at(c)[h]);
397  fEdepEMcorr_ellifetime_reco += GetEhitMeVcorrel(clockData, detProp, *hitsFromCluster.at(c)[h]);
398  }
399  }
400 
401  fEdepSum += GetEhitMeV(*hitsFromCluster.at(c)[h]);
402  }
403  }
404  }
405  }
406 
407  /*file << fEvent << " " << fEkGen << " " << fEdepEM_MC << " " << fEdepHAD_MC << " " << fMissEn_MC
408  << " " << fEdepEMAtt_MC << " " << fEdepEMhAtt_MC
409  << " " << fEdepHADAtt_MC << " " << fEdepHADhAtt_MC
410  << " " << fEdepHADcorr_ellifetime_reco << " " << fEdepEMcorr_ellifetime_reco << std::endl;*/
411  fTree->Fill();
412 }
std::string fHitModuleLabel
double GetEdepHitsMeV(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::Hit > &hits) const
std::string fTrackModuleLabel
double fEdepEMhAtt_MC
double fEdepHADhAtt_MC
std::string fSimulationLabel
double fEdepHAD_reco
double fEdepHADcorr_ellifetime_reco
std::string fCalorimetryModuleLabel
art::InputTag fNNetModuleLabel
double GetEhitMeVcorrel(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const recob::Hit &hit) const
const double e
double GetEdepHADAtt_MC(art::Event const &e) const
p
Definition: test.py:223
double fEdepEMAtt_MC
double GetEhitMeV(const recob::Hit &hit) const
double GetEdepEM_MC(art::Event const &e) const
std::unordered_map< int, const simb::MCParticle * > fParticleMap
double GetEdepHADhAtt_MC(art::Event const &e, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::Hit > &hits) const
double fEdepHADAtt_MC
double GetEdepEMhAtt_MC(art::Event const &e, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::Hit > &hits) const
double GetEdepHAD_MC(art::Event const &e) const
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
double GetEdepEMAtt_MC(art::Event const &e) const
double fEdepEMcorr_ellifetime_reco
void proto::HadCal::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 178 of file HadCal_module.cc.

179 {
181  fElectronsToGeV = 1./larParameters->GeVToElectrons();
182 
183  // access art's TFileService, which will handle creating and writing hists
185 
186  fTree = tfs->make<TTree>("calibration","calibration tree");
187  fTree->Branch("fRun", &fRun, "fRun/I");
188  fTree->Branch("fEvent", &fEvent, "fEvent/I");
189  fTree->Branch("fEnGen", &fEnGen, "fEnGen/D");
190  fTree->Branch("fEkGen", &fEkGen, "fEkGeb/D");
191 
192  fTree->Branch("fEdepEM_MC", &fEdepEM_MC, "fEdepEM_MC/D");
193  fTree->Branch("fEdepEMAtt_MC", &fEdepEMAtt_MC, "fEdepEMAtt_MC/D");
194  fTree->Branch("fEdepEMhAtt_MC", &fEdepEMhAtt_MC, "fEdepEMhAtt_MC/D");
195 
196  fTree->Branch("fEdepEM_reco", &fEdepEM_reco, "fEdepEM_reco/D");
197  fTree->Branch("fEdepEMcorr_ellifetime_reco", &fEdepEMcorr_ellifetime_reco, "fEdepEMcorr_ellifetime_reco/D");
198 
199  fTree->Branch("fEdepHAD_MC", &fEdepHAD_MC, "fEdepHAD_MC/D");
200  fTree->Branch("fEdepHADAtt_MC", &fEdepHADAtt_MC, "fEdepHADAtt_MC/D");
201  fTree->Branch("fEdepHADhAtt_MC", &fEdepHADhAtt_MC, "fEdepHADhAtt_MC/D");
202 
203  fTree->Branch("fEdepHAD_reco", &fEdepHAD_reco, "fEdepHAD_reco/D");
204  fTree->Branch("fEdepHADcorr_ellifetime_reco", &fEdepHADcorr_ellifetime_reco, "fEdepHADcorr_ellifetime_reco/D");
205 
206  fTree->Branch("fMissEn_MC", &fMissEn_MC, "fMissEn_MC/D");
207 
208  fTree->Branch("fNumberOfTracks", &fNumberOfTracks, "fNumberOfTracks/I");
209 
210  fTree->Branch("fEdepSum", &fEdepSum, "fEdepSum/D");
211  fTree->Branch("fEdepAllhits", &fEdepAllhits, "fEdepAllhits/D");
212  fTree->Branch("fT0", &fT0, "fT0/D");
213 
214  fTreeEntries = tfs->make<TTree>("entries","entries tree");
215  fTreeEntries->Branch("fdQdx", &fdQdx, "fdQdx/D");
216  fTreeEntries->Branch("fdEdx", &fdEdx, "fdEdx/D");
217  fTreeEntries->Branch("fdQ", &fdQ, "fdQ/D");
218  fTreeEntries->Branch("fdx", &fdx, "fdx/D");
219 
220 }
double fEdepEMhAtt_MC
double fEdepHADhAtt_MC
double fEdepHAD_reco
double fEdepHADcorr_ellifetime_reco
double fEdepEMAtt_MC
double fElectronsToGeV
TTree * fTreeEntries
double fEdepHADAtt_MC
double GeVToElectrons() const
double fEdepEMcorr_ellifetime_reco
void proto::HadCal::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 222 of file HadCal_module.cc.

223 {
224  file.close();
225 }
std::ofstream file
double proto::HadCal::GetEdepEM_MC ( art::Event const &  e) const
private

Definition at line 531 of file HadCal_module.cc.

532 {
533  double enEM = 0.0;
534 
535  auto simchannelHandle = e.getHandle< std::vector<sim::SimChannel> >(fSimulationLabel);
536  if (simchannelHandle)
537  {
538  for ( auto const& channel : (*simchannelHandle) )
539  {
540  if (fGeometry->View(channel.Channel()) == fBestView)
541  {
542  // for every time slice in this channel:
543  auto const& timeSlices = channel.TDCIDEMap();
544  for ( auto const& timeSlice : timeSlices )
545  {
546  // loop over the energy deposits.
547  auto const& energyDeposits = timeSlice.second;
548 
549  for ( auto const& energyDeposit : energyDeposits )
550  {
551  double energy = energyDeposit.energy; // energy not attenuated
552  int trackID = energyDeposit.trackID;
553 
554  if (trackID < 0)
555  {
556  enEM += energy;
557  }
558  else if (trackID > 0)
559  {
560  auto search = fParticleMap.find(trackID);
561  bool found = true;
562  if (search == fParticleMap.end())
563  {
564  mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND";
565  found = false;
566  }
567 
568  int pdg = 0;
569  if (found)
570  {
571  const simb::MCParticle& particle = *((*search).second);
572  if (!pdg) pdg = particle.PdgCode(); // not EM activity so read what PDG it is
573  }
574 
575  if ((pdg == 11) || (pdg == -11) || (pdg == 22)) enEM += energy;
576  }
577 
578  }
579  }
580  }
581  }
582  }
583 
584  return enEM;
585 }
int PdgCode() const
Definition: MCParticle.h:212
geo::GeometryCore const * fGeometry
uint8_t channel
Definition: CRTFragment.hh:201
std::string fSimulationLabel
const double e
Definition: search.py:1
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::unordered_map< int, const simb::MCParticle * > fParticleMap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double proto::HadCal::GetEdepEMAtt_MC ( art::Event const &  e) const
private

Definition at line 589 of file HadCal_module.cc.

590 {
591  double enEM = 0.0;
592 
593  auto simchannelHandle = e.getHandle< std::vector<sim::SimChannel> >(fSimulationLabel);
594  if (simchannelHandle)
595  {
596  for ( auto const& channel : (*simchannelHandle) )
597  {
598  if (fGeometry->View(channel.Channel()) == fBestView)
599  {
600  // for every time slice in this channel:
601  auto const& timeSlices = channel.TDCIDEMap();
602  for ( auto const& timeSlice : timeSlices )
603  {
604  // loop over the energy deposits.
605  auto const& energyDeposits = timeSlice.second;
606 
607  for ( auto const& energyDeposit : energyDeposits )
608  {
609  double energy = energyDeposit.numElectrons * fElectronsToGeV * 1000; // attenuated
610  int trackID = energyDeposit.trackID;
611 
612  if (trackID < 0)
613  {
614  enEM += energy;
615  }
616  else if (trackID > 0)
617  {
618  auto search = fParticleMap.find(trackID);
619  bool found = true;
620  if (search == fParticleMap.end())
621  {
622  mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND";
623  found = false;
624  }
625 
626  int pdg = 0;
627  if (found)
628  {
629  const simb::MCParticle& particle = *((*search).second);
630  if (!pdg) pdg = particle.PdgCode(); // not EM activity so read what PDG it is
631  }
632 
633  if ((pdg == 11) || (pdg == -11) || (pdg == 22)) enEM += energy;
634  }
635 
636  }
637  }
638  }
639  }
640  }
641  return enEM;
642 }
int PdgCode() const
Definition: MCParticle.h:212
geo::GeometryCore const * fGeometry
uint8_t channel
Definition: CRTFragment.hh:201
std::string fSimulationLabel
const double e
double fElectronsToGeV
Definition: search.py:1
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::unordered_map< int, const simb::MCParticle * > fParticleMap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double proto::HadCal::GetEdepEMhAtt_MC ( art::Event const &  e,
detinfo::DetectorClocksData const &  clockData,
detinfo::DetectorPropertiesData const &  detProp,
const std::vector< recob::Hit > &  hits 
) const
private

Definition at line 647 of file HadCal_module.cc.

651 {
652  double totemhit = 0.0;
653 
654  auto simChannelHandle = e.getValidHandle< std::vector<sim::SimChannel> >(fSimulationLabel);
655  const std::vector< sim::SimChannel > & channels = *simChannelHandle;
656 
657  for (auto const & hit: hits)
658  {
659  // the channel associate with this hit.
660  auto hitChannelNumber = hit.Channel();
661 
662  double hitEn = 0.0; double hitEnSh = 0;
663 
664  for (auto const & channel: channels)
665  {
666  if (channel.Channel() != hitChannelNumber) continue;
667  if (fGeometry->View(channel.Channel()) != fBestView) continue;
668 
669  // for every time slice in this channel:
670  auto const& timeSlices = channel.TDCIDEMap();
671  for ( auto const& timeSlice : timeSlices )
672  {
673  int time = timeSlice.first;
674  if (std::abs(hit.TimeDistanceAsRMS(time)) < 1.0)
675  {
676  // loop over the energy deposits.
677  auto const& energyDeposits = timeSlice.second;
678 
679  for ( auto const& energyDeposit : energyDeposits )
680  {
681  int trackID = energyDeposit.trackID;
682  double energy = energyDeposit.numElectrons * fElectronsToGeV * 1000; // attenuated
683  hitEn += energy;
684 
685  if (trackID < 0)
686  {
687  hitEnSh += energy;
688  }
689  else if (trackID > 0)
690  {
691  auto search = fParticleMap.find(trackID);
692  bool found = true;
693  if (search == fParticleMap.end())
694  {
695  mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND";
696  found = false;
697  }
698 
699  int pdg = 0;
700  if (found)
701  {
702  const simb::MCParticle& particle = *((*search).second);
703  if (!pdg) pdg = particle.PdgCode(); // not EM activity so read what PDG it is
704  }
705 
706  if ((pdg == 11) || (pdg == -11) || (pdg == 22)) hitEnSh += energy;
707  }
708  }
709  }
710  }
711  }
712 
713  double ratio = 0.0;
714  if (hitEn > 0)
715  {
716  ratio = hitEnSh / hitEn;
717  }
718 
719  // use energy of hit corrected for electron lifetime
720  if (ratio > 0.5)
721  {
722  totemhit += GetEhitMeVcorrel(clockData, detProp, hit);
723  }
724  }
725 
726  return totemhit;
727 }
int PdgCode() const
Definition: MCParticle.h:212
geo::GeometryCore const * fGeometry
uint8_t channel
Definition: CRTFragment.hh:201
std::string fSimulationLabel
double GetEhitMeVcorrel(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const recob::Hit &hit) const
T abs(T value)
const double e
double fElectronsToGeV
Definition: search.py:1
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Detector simulation of raw signals on wires.
std::unordered_map< int, const simb::MCParticle * > fParticleMap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double proto::HadCal::GetEdepHAD_MC ( art::Event const &  e) const
private

Definition at line 731 of file HadCal_module.cc.

732 {
733  double enHAD = 0.0;
734 
735  auto simchannelHandle = e.getHandle< std::vector<sim::SimChannel> >(fSimulationLabel);
736  if (simchannelHandle)
737  {
738 
739  for (auto const & channel : (*simchannelHandle) )
740  {
741  if (fGeometry->View(channel.Channel()) != fBestView) continue;
742 
743  // for every time slice in this channel:
744  auto const& timeSlices = channel.TDCIDEMap();
745  for (auto const& timeSlice : timeSlices)
746  {
747  // loop over the energy deposits.
748  auto const & energyDeposits = timeSlice.second;
749 
750  for (auto const & energyDeposit : energyDeposits)
751  {
752  double energy = energyDeposit.energy; // energy not attenuated
753  int trackID = energyDeposit.trackID;
754 
755  if (trackID < 0) { } // EM activity
756  else if (trackID > 0)
757  {
758  auto search = fParticleMap.find(trackID);
759 
760  if (search != fParticleMap.end())
761  {
762  const simb::MCParticle & particle = *((*search).second);
763  int pdg = particle.PdgCode(); // not EM activity so read what PDG it is
764 
765  if ((pdg == 11) || (pdg == -11) || (pdg == 22)) {}
766  else
767  {
768  enHAD += energy;
769  }
770  }
771  else { mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND"; }
772  }
773  }
774  }
775  }
776  }
777 
778  return enHAD;
779 }
int PdgCode() const
Definition: MCParticle.h:212
geo::GeometryCore const * fGeometry
uint8_t channel
Definition: CRTFragment.hh:201
std::string fSimulationLabel
const double e
Definition: search.py:1
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::unordered_map< int, const simb::MCParticle * > fParticleMap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double proto::HadCal::GetEdepHADAtt_MC ( art::Event const &  e) const
private

Definition at line 783 of file HadCal_module.cc.

784 {
785  double enHAD = 0.0;
786 
787  auto simchannelHandle = e.getHandle< std::vector<sim::SimChannel> >(fSimulationLabel);
788  if (simchannelHandle)
789  {
790 
791  for (auto const & channel : (*simchannelHandle) )
792  {
793  if (fGeometry->View(channel.Channel()) != fBestView) continue;
794 
795  // for every time slice in this channel:
796  auto const& timeSlices = channel.TDCIDEMap();
797  for (auto const& timeSlice : timeSlices)
798  {
799  // loop over the energy deposits.
800  auto const & energyDeposits = timeSlice.second;
801 
802  for (auto const & energyDeposit : energyDeposits)
803  {
804  double energy = energyDeposit.numElectrons * fElectronsToGeV * 1000; // attenuated
805  int trackID = energyDeposit.trackID;
806 
807  if (trackID < 0) { } // EM activity
808  else if (trackID > 0)
809  {
810  auto search = fParticleMap.find(trackID);
811 
812  if (search != fParticleMap.end())
813  {
814  const simb::MCParticle & particle = *((*search).second);
815  int pdg = particle.PdgCode(); // not EM activity so read what PDG it is
816 
817  if ((pdg == 11) || (pdg == -11) || (pdg == 22)) {}
818  else
819  {
820  enHAD += energy;
821  }
822  }
823  else { mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND"; }
824  }
825  }
826  }
827  }
828  }
829 
830  return enHAD;
831 }
int PdgCode() const
Definition: MCParticle.h:212
geo::GeometryCore const * fGeometry
uint8_t channel
Definition: CRTFragment.hh:201
std::string fSimulationLabel
const double e
double fElectronsToGeV
Definition: search.py:1
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::unordered_map< int, const simb::MCParticle * > fParticleMap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double proto::HadCal::GetEdepHADhAtt_MC ( art::Event const &  e,
detinfo::DetectorClocksData const &  clockData,
detinfo::DetectorPropertiesData const &  detProp,
const std::vector< recob::Hit > &  hits 
) const
private

Definition at line 835 of file HadCal_module.cc.

839 {
840  double tothadhit = 0.0;
841 
842  auto simChannelHandle = e.getValidHandle< std::vector<sim::SimChannel> >(fSimulationLabel);
843  const std::vector< sim::SimChannel > & channels = *simChannelHandle;
844 
845  for (auto const & hit: hits)
846  {
847  // the channel associated with this hit.
848  auto hitChannelNumber = hit.Channel();
849 
850  double hitEn = 0.0; double hitEnTrk = 0;
851 
852  for (auto const & channel : channels)
853  {
854  if (channel.Channel() != hitChannelNumber) continue;
855  if (fGeometry->View(channel.Channel()) != fBestView) continue;
856 
857  // for every time slice in this channel:
858  auto const& timeSlices = channel.TDCIDEMap();
859  for (auto const& timeSlice : timeSlices)
860  {
861  int time = timeSlice.first;
862  if (std::abs(hit.TimeDistanceAsRMS(time)) < 1.0)
863  {
864  // loop over the energy deposits.
865  auto const & energyDeposits = timeSlice.second;
866 
867  for (auto const & energyDeposit : energyDeposits)
868  {
869  int trackID = energyDeposit.trackID;
870 
871  double energy = energyDeposit.numElectrons * fElectronsToGeV * 1000; // attenuated
872  hitEn += energy;
873 
874  if (trackID < 0) { } // EM activity
875  else if (trackID > 0)
876  {
877  auto search = fParticleMap.find(trackID);
878  if (search != fParticleMap.end())
879  {
880  const simb::MCParticle & particle = *((*search).second);
881  int pdg = particle.PdgCode(); // not EM activity so read what PDG it is
882 
883  if ((pdg == 11) || (pdg == -11) || (pdg == 22)) {}
884  else {hitEnTrk += energy;}
885  }
886  else { mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND"; }
887  }
888  }
889  }
890  }
891  }
892 
893  double ratio = 0.0;
894  if (hitEn > 0)
895  {
896  ratio = hitEnTrk / hitEn;
897  }
898  // use energy of hit corrected for electron lifetime
899  if (ratio > 0.5)
900  {
901  tothadhit += GetEhitMeVcorrel(clockData, detProp, hit);
902  }
903  }
904 
905  return tothadhit;
906 }
int PdgCode() const
Definition: MCParticle.h:212
geo::GeometryCore const * fGeometry
uint8_t channel
Definition: CRTFragment.hh:201
std::string fSimulationLabel
double GetEhitMeVcorrel(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const recob::Hit &hit) const
T abs(T value)
const double e
double fElectronsToGeV
Definition: search.py:1
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Detector simulation of raw signals on wires.
std::unordered_map< int, const simb::MCParticle * > fParticleMap
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double proto::HadCal::GetEdepHitsMeV ( detinfo::DetectorClocksData const &  clockData,
detinfo::DetectorPropertiesData const &  detProp,
const std::vector< recob::Hit > &  hits 
) const
private

Definition at line 461 of file HadCal_module.cc.

464 {
465  if (!hits.size()) return 0.0;
466 
467  double dqsum = 0.0;
468  for (size_t h = 0; h < hits.size(); ++h)
469  {
470  double dqadc = hits[h].Integral();
471  if (!std::isnormal(dqadc) || (dqadc < 0)) continue;
472 
473  unsigned short plane = hits[h].WireID().Plane;
474  if (plane == fBestView)
475  {
476  double tdrift = hits[h].PeakTime();
477  double dqel = fCalorimetryAlg.ElectronsFromADCArea(dqadc, plane);
478 
479  double correllifetime = fCalorimetryAlg.LifetimeCorrection(clockData, detProp, tdrift, fT0);
480  double dq = dqel * correllifetime * fElectronsToGeV * 1000;
481 
482  if (!std::isnormal(dq) || (dq < 0)) continue;
483 
484  dqsum += dq;
485  }
486  }
487 
488  return dqsum;
489 }
double ElectronsFromADCArea(double area, unsigned short plane) const
double fElectronsToGeV
calo::CalorimetryAlg fCalorimetryAlg
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
double proto::HadCal::GetEhitMeV ( const recob::Hit hit) const
private

Definition at line 513 of file HadCal_module.cc.

514 {
515  double dqadc = hit.Integral();
516  if (!std::isnormal(dqadc) || (dqadc < 0)) dqadc = 0.0;
517 
518  unsigned short plane = hit.WireID().Plane;
519  // double tdrift = hit.PeakTime();
520  double dqel = fCalorimetryAlg.ElectronsFromADCArea(dqadc, plane);
521 
522  double correllifetime = 1; // fCalorimetryAlg.LifetimeCorrection(tdrift, fT0);
523  double dq = dqel * correllifetime * fElectronsToGeV * 1000;
524  if (!std::isnormal(dq) || (dq < 0)) dq = 0.0;
525 
526  return dq;
527 }
geo::WireID WireID() const
Definition: Hit.h:233
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
double ElectronsFromADCArea(double area, unsigned short plane) const
double fElectronsToGeV
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
calo::CalorimetryAlg fCalorimetryAlg
double proto::HadCal::GetEhitMeVcorrel ( detinfo::DetectorClocksData const &  clockData,
detinfo::DetectorPropertiesData const &  detProp,
const recob::Hit hit 
) const
private

Definition at line 493 of file HadCal_module.cc.

496 {
497  double dqadc = hit.Integral();
498  if (!std::isnormal(dqadc) || (dqadc < 0)) dqadc = 0.0;
499 
500  unsigned short plane = hit.WireID().Plane;
501  double tdrift = hit.PeakTime();
502  double dqel = fCalorimetryAlg.ElectronsFromADCArea(dqadc, plane);
503 
504  double correllifetime = fCalorimetryAlg.LifetimeCorrection(clockData, detProp, tdrift, fT0);
505  double dq = dqel * correllifetime * fElectronsToGeV * 1000;
506  if (!std::isnormal(dq) || (dq < 0)) dq = 0.0;
507 
508  return dq;
509 }
geo::WireID WireID() const
Definition: Hit.h:233
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
double ElectronsFromADCArea(double area, unsigned short plane) const
double fElectronsToGeV
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
calo::CalorimetryAlg fCalorimetryAlg
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
double proto::HadCal::GetEkinMeV ( detinfo::DetectorClocksData const &  clockData,
detinfo::DetectorPropertiesData const &  detProp,
const std::vector< art::Ptr< recob::Hit > > &  hits,
const std::vector< recob::TrackHitMeta const * > &  data 
)
private

Definition at line 418 of file HadCal_module.cc.

422 {
423  double ekin = 0.0;
424 
425  if (!hits.size()) return ekin;
426 
427 
428  for (size_t h = 0; h < hits.size(); ++h)
429  {
430  double dqadc = hits[h]->Integral();
431  if (!std::isnormal(dqadc) || (dqadc < 0)) dqadc = 0.0;
432 
433  unsigned short plane = hits[h]->WireID().Plane;
434  unsigned short time = hits[h]->PeakTime();
435  double t0 = 0;
436 
437  fdQdx = 0.0;
438  fdQ = dqadc;
439  fdx = data[h]->Dx();
440  if ((fdx > 0) && (fdQ > 0))
441  {
442  fdQdx = fdQ/fdx;
443  fdEdx = fCalorimetryAlg.dEdx_AREA(clockData, detProp, fdQdx, time, plane, t0);
444  if (fdEdx > 35) fdEdx = 35;
445 
446  ekin += ( fdEdx * fdx );
447  }
448  else if ((fdx == 0) && (fdQ > 0))
449  {
450 
451  }
452 
453  fTreeEntries->Fill();
454  }
455 
456  return ekin;
457 }
code to link reconstructed objects back to the MC truth information
TTree * fTreeEntries
calo::CalorimetryAlg fCalorimetryAlg
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
HadCal& proto::HadCal::operator= ( HadCal const &  )
delete
HadCal& proto::HadCal::operator= ( HadCal &&  )
delete
void proto::HadCal::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 227 of file HadCal_module.cc.

228 {
229  fHitModuleLabel = p.get< std::string >("HitModuleLabel");
230  fClusterModuleLabel = p.get< std::string >("ClusterModuleLabel");
231  fTrackModuleLabel = p.get< std::string >("TrackModuleLabel");
232  fCalorimetryModuleLabel = p.get< std::string >("CalorimetryModuleLabel");
233  fSimulationLabel = p.get< std::string >("SimulationLabel");
234  fNNetModuleLabel = p.get< std::string >("NNetModuleLabel");
235 }
std::string fHitModuleLabel
std::string string
Definition: nybbler.cc:12
std::string fTrackModuleLabel
std::string fSimulationLabel
std::string fCalorimetryModuleLabel
art::InputTag fNNetModuleLabel
std::string fClusterModuleLabel
p
Definition: test.py:223
void proto::HadCal::ResetVars ( void  )
private

Definition at line 910 of file HadCal_module.cc.

911 {
912  fRun = 0;
913  fEvent = 0;
914  fBestView = 2;
915  fNumberOfTracks = 0;
916 
917  fEdepEM_MC = 0.0;
918  fEdepEMAtt_MC = 0.0;
919  fEdepEMhAtt_MC = 0.0;
920 
921  fEdepHAD_MC = 0.0;
922  fEdepHADAtt_MC = 0.0;
923  fEdepHADhAtt_MC = 0.0;
924 
925  fMissEn_MC = 0.0;
926 
927  fEdepEM_reco = 0.0;
929  fEdepHAD_reco = 0.0;
931 
932  fEnGen = 0.0;
933  fEkGen = 0.0;
934 
935  fEdepSum = 0.0;
936  fEdepAllhits = 0.0;
937 
938  fdQdx = 0.0;
939  fdEdx = 0.0;
940  fdQ = 0.0;
941  fdx = 0.0;
942  fResRange = 0.0;
943  fT0 = 0.0;
944  fParticleMap.clear();
945 }
double fEdepEMhAtt_MC
double fEdepHADhAtt_MC
double fEdepHAD_reco
double fEdepHADcorr_ellifetime_reco
double fEdepEMAtt_MC
std::unordered_map< int, const simb::MCParticle * > fParticleMap
double fEdepHADAtt_MC
double fEdepEMcorr_ellifetime_reco

Member Data Documentation

int proto::HadCal::fBestView
private

Definition at line 135 of file HadCal_module.cc.

calo::CalorimetryAlg proto::HadCal::fCalorimetryAlg
private

Definition at line 160 of file HadCal_module.cc.

std::string proto::HadCal::fCalorimetryModuleLabel
private

Definition at line 158 of file HadCal_module.cc.

std::string proto::HadCal::fClusterModuleLabel
private

Definition at line 156 of file HadCal_module.cc.

double proto::HadCal::fdEdx
private

Definition at line 140 of file HadCal_module.cc.

double proto::HadCal::fdQ
private

Definition at line 141 of file HadCal_module.cc.

double proto::HadCal::fdQdx
private

Definition at line 139 of file HadCal_module.cc.

double proto::HadCal::fdx
private

Definition at line 142 of file HadCal_module.cc.

double proto::HadCal::fEdepAllhits
private

Definition at line 144 of file HadCal_module.cc.

double proto::HadCal::fEdepEM_MC
private

Definition at line 102 of file HadCal_module.cc.

double proto::HadCal::fEdepEM_reco
private

Definition at line 106 of file HadCal_module.cc.

double proto::HadCal::fEdepEMAtt_MC
private

Definition at line 103 of file HadCal_module.cc.

double proto::HadCal::fEdepEMcorr_ellifetime_reco
private

Definition at line 107 of file HadCal_module.cc.

double proto::HadCal::fEdepEMhAtt_MC
private

Definition at line 104 of file HadCal_module.cc.

double proto::HadCal::fEdepHAD_MC
private

Definition at line 117 of file HadCal_module.cc.

double proto::HadCal::fEdepHAD_reco
private

Definition at line 121 of file HadCal_module.cc.

double proto::HadCal::fEdepHADAtt_MC
private

Definition at line 118 of file HadCal_module.cc.

double proto::HadCal::fEdepHADcorr_ellifetime_reco
private

Definition at line 122 of file HadCal_module.cc.

double proto::HadCal::fEdepHADhAtt_MC
private

Definition at line 119 of file HadCal_module.cc.

double proto::HadCal::fEdepSum
private

Definition at line 143 of file HadCal_module.cc.

double proto::HadCal::fEkGen
private

Definition at line 148 of file HadCal_module.cc.

double proto::HadCal::fElectronsToGeV
private

Definition at line 145 of file HadCal_module.cc.

double proto::HadCal::fEnGen
private

Definition at line 147 of file HadCal_module.cc.

int proto::HadCal::fEvent
private

Definition at line 134 of file HadCal_module.cc.

geo::GeometryCore const* proto::HadCal::fGeometry
private

Definition at line 129 of file HadCal_module.cc.

std::string proto::HadCal::fHitModuleLabel
private

Definition at line 155 of file HadCal_module.cc.

std::ofstream proto::HadCal::file
private

Definition at line 151 of file HadCal_module.cc.

double proto::HadCal::fMissEn_MC
private

Definition at line 125 of file HadCal_module.cc.

art::InputTag proto::HadCal::fNNetModuleLabel
private

Definition at line 154 of file HadCal_module.cc.

int proto::HadCal::fNumberOfTracks
private

Definition at line 136 of file HadCal_module.cc.

std::unordered_map< int, const simb::MCParticle* > proto::HadCal::fParticleMap
private

Definition at line 162 of file HadCal_module.cc.

double proto::HadCal::fResRange
private

Definition at line 146 of file HadCal_module.cc.

int proto::HadCal::fRun
private

Definition at line 133 of file HadCal_module.cc.

std::string proto::HadCal::fSimulationLabel
private

Definition at line 159 of file HadCal_module.cc.

double proto::HadCal::fT0
private

Definition at line 149 of file HadCal_module.cc.

std::string proto::HadCal::fTrackModuleLabel
private

Definition at line 157 of file HadCal_module.cc.

TTree* proto::HadCal::fTree
private

Definition at line 131 of file HadCal_module.cc.

TTree* proto::HadCal::fTreeEntries
private

Definition at line 132 of file HadCal_module.cc.


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