16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Framework/Principal/Handle.h"
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "art_root_io/TFileService.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
22 #include "canvas/Persistency/Common/Ptr.h"
23 #include "canvas/Persistency/Common/PtrVector.h"
24 #include "fhiclcpp/ParameterSet.h"
36 #include "nug4/ParticleNavigation/EmEveIdCalculator.h"
37 #include "nug4/ParticleNavigation/ParticleList.h"
38 #include "nusimdata/SimulationBase/MCTruth.h"
40 #include "art/Framework/Core/EDAnalyzer.h"
102 , fDigitModuleLabel(pset.
get<
std::string>(
"DigitModuleLabel"))
103 , fHitsModuleLabel(pset.
get<
std::string>(
"HitsModuleLabel"))
104 , fLArG4ModuleLabel(pset.
get<
std::string>(
"LArGeantModuleLabel"))
105 , fClusterFinderModuleLabel(pset.
get<
std::string>(
"ClusterFinderModuleLabel"))
106 , fCalDataModuleLabel(pset.
get<
std::string>(
"CalDataModuleLabel"))
107 , fGenieGenModuleLabel(pset.
get<
std::string>(
"GenieGenModuleLabel"))
117 art::ServiceHandle<art::TFileService const>
tfs;
120 "fNoParticles_pdg_per_event",
"Average # of Particles per cluster for each event", 500, 0, 5);
122 "fNoParticles_pdg",
"Number of Particles in a Cluster for each cluster", 500, 0, 5);
124 "fNoParticles_trackid",
"Number of different TrackIDs in a Cluster", 300, 0, 30);
127 tfs->make<TH1F>(
"fNoParticles_trackid_mother",
128 "Number of different TrackIDs in a Cluster(using mother)for each cluster",
134 tfs->make<TH1F>(
"fNoParticles_trackid_per_event",
135 "Avg Number of different TrackIDs per Cluster per event",
140 tfs->make<TH1F>(
"fCl_for_Muon",
"Number of Clusters for Muon per plane (pdg)", 1500, 0, 15);
143 tfs->make<TH1F>(
"fNoClustersInEvent",
"Number of Clusters in an Event", 50, 0, 50);
146 tfs->make<TH1F>(
"fPercentNoise",
"% of hits that were marked as Noise by DBSCAN", 250, 0, 25);
149 "fno_of_clusters_per_track",
"Number of Clusters per TrackID per plane", 1500, 0, 15);
152 tfs->make<TH1F>(
"fPercent_lost_muon_hits",
153 "Number of muon hits excluded by dbscan in % (per Event)",
158 tfs->make<TH1F>(
"fPercent_lost_electron_hits",
159 "Number of electron hits excluded by dbscan in % (per Event)",
164 tfs->make<TH1F>(
"fPercent_lost_positron_hits",
165 "Number of positron hits excluded by dbscan in % (per Event)",
170 tfs->make<TH1F>(
"fPercent_lost_111_hits",
171 "Number of pion(111) hits excluded by dbscan in % (per Event)",
176 tfs->make<TH1F>(
"fPercent_lost_211_hits",
177 "Number of pion(211) hits excluded by dbscan in % (per Event)",
182 tfs->make<TH1F>(
"fPercent_lost_m211_hits",
183 "Number of pion(-211) hits excluded by dbscan in % (per Event)",
188 tfs->make<TH1F>(
"fPercent_lost_2212_hits",
189 "Number of proton hits excluded by dbscan in % (per Event)",
194 tfs->make<TH1F>(
"fPercent_lost_2112_hits",
195 "Number of neutron hits excluded by dbscan in % (per Event)",
201 " muon energy excluded by dbscan in % (per Event)",
206 tfs->make<TH1F>(
"fPercent_lost_electron_energy",
207 "electron energy excluded by dbscan in % (per Event)",
212 tfs->make<TH1F>(
"fPercent_lost_positron_energy",
213 " positron energy excluded by dbscan in % (per Event)",
218 tfs->make<TH1F>(
"fPercent_lost_111_energy",
219 "pion(111) energy excluded by dbscan in % (per Event)",
224 tfs->make<TH1F>(
"fPercent_lost_211_energy",
225 "pion(211) energy excluded by dbscan in % (per Event)",
230 tfs->make<TH1F>(
"fPercent_lost_m211_energy",
231 " pion(-211) energy excluded by dbscan in % (per Event)",
236 "proton energy excluded by dbscan in % (per Event)",
241 tfs->make<TH1F>(
"fPercent_lost_2112_energy",
242 "neutron energy excluded by dbscan in % (per Event)",
247 fEnergy = tfs->make<TH1F>(
"fEnergy",
"energy for each voxel", 100000, 0, 0.0005);
250 ";# Electrons deposited; # Electrons detected by hitfinder",
258 ";# Electrons deposited; # Electrons detected by hitfinder",
270 std::cout <<
"run : " << evt.run() << std::endl;
271 std::cout <<
"event : " << evt.id().event() << std::endl;
275 if (evt.isRealData()) {
276 std::cout <<
"**** DBclusterAna: Bailing. Don't call this module if you're not MC. "
281 art::ServiceHandle<geo::Geometry const> geom;
282 art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
283 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
285 art::Handle<std::vector<raw::RawDigit>> rdListHandle;
287 art::Handle<std::vector<recob::Hit>> hitListHandle;
289 art::Handle<std::vector<simb::MCTruth>> mctruthListHandle;
291 art::Handle<std::vector<recob::Cluster>> clusterListHandle;
293 art::Handle<std::vector<recob::Wire>> wireListHandle;
302 art::PtrVector<raw::RawDigit> rawdigits;
304 for (
size_t ii = 0; ii < rdListHandle->size(); ++ii) {
305 art::Ptr<raw::RawDigit> rawdigit(rdListHandle, ii);
306 rawdigits.push_back(rawdigit);
311 pi_serv->SetEveIdCalculator(
new sim::EmEveIdCalculator);
313 sim::ParticleList
const& _particleList = pi_serv->ParticleList();
315 std::vector<int> mc_trackids;
317 for (
auto i = _particleList.begin(); i != _particleList.end(); ++i) {
318 int trackID = (*i).first;
319 mc_trackids.push_back(trackID);
323 art::PtrVector<simb::MCTruth> mclist;
324 for (
size_t ii = 0; ii < mctruthListHandle->size(); ++ii) {
325 art::Ptr<simb::MCTruth> mctparticle(mctruthListHandle, ii);
326 mclist.push_back(mctparticle);
330 std::vector<art::Ptr<recob::Hit>> hits_vec;
333 std::vector<art::Ptr<recob::Hit>> hits;
334 art::fill_ptr_vector(hits, hitListHandle);
337 art::PtrVector<recob::Cluster> clusters;
338 for (
unsigned int ii = 0; ii < clusterListHandle->size(); ++ii) {
339 art::Ptr<recob::Cluster> clusterHolder(clusterListHandle, ii);
340 clusters.push_back(clusterHolder);
343 std::cout <<
"in Efficiency, clusters.size()= " << clusters.size() << std::endl;
346 art::PtrVector<recob::Wire> wirelist;
348 for (
size_t ii = 0; ii < wireListHandle->size(); ++ii) {
349 art::Ptr<recob::Wire> wireHolder(wireListHandle, ii);
351 wirelist.push_back(wireHolder);
365 double no_of_particles_in_cluster = 0;
366 double sum_vec_trackid = 0;
367 double no_of_clusters = 0;
368 double total_no_hits_in_clusters = 0;
369 std::vector<int> vec_pdg;
370 std::vector<int> vec_trackid, vec_trackid_mother, vec_trackid_mother_en;
371 std::vector<int> all_trackids;
372 std::vector<int> ids;
373 std::vector<int>::iterator it, it2, it3, it4, it5, it6, it7, it8;
374 int no_cl_for_muon = 0;
375 int no_cl_for_electron = 0;
376 int no_cl_for_positron = 0;
377 int no_cl_for_pion_111 = 0;
378 int no_cl_for_pion_211 = 0;
379 int no_cl_for_pion_m211 = 0;
380 int no_cl_for_proton = 0;
381 double noCluster = 0;
382 double _hit_13 = 0, _hit_11 = 0, _hit_m_11 = 0, _hit_111 = 0, _hit_211 = 0, _hit_m211 = 0,
383 _hit_2212 = 0, _hit_2112 = 0;
384 double _en_13 = 0, _en_11 = 0, _en_m11 = 0, _en_111 = 0, _en_211 = 0, _en_m211 = 0,
385 _en_2212 = 0, _en_2112 = 0;
386 std::vector<double> diff_vec;
388 double hit_energy = 0;
389 double total_Q_cluster_hits = 0;
391 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
392 if (clusters.size() != 0 && hits.size() != 0) {
393 for (
unsigned int plane = 0; plane < geom->Nplanes(); ++plane) {
395 for (
size_t j = 0; j < clusters.size(); ++j) {
397 if (clusters[j]->View() == view) {
399 std::vector<art::Ptr<recob::Hit>> _hits = fmh.at(j);
400 art::Ptr<recob::Hit> _hits_ptr;
402 for (
size_t p = 0;
p < _hits.size(); ++
p) {
403 _hits_ptr = _hits[
p];
404 hits_vec.push_back(_hits_ptr);
405 total_Q_cluster_hits += _hits[
p]->Integral();
408 std::vector<art::Ptr<recob::Hit>>::iterator itr = hits_vec.begin();
410 while (itr != hits_vec.end()) {
413 hit_energy = _hits[itr - hits_vec.begin()]->Integral();
415 std::vector<sim::TrackIDE> trackides = bt_serv->HitToTrackIDEs(clockData, *itr);
416 std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, *itr);
418 std::vector<sim::TrackIDE>::iterator idesitr = trackides.begin();
420 while (idesitr != trackides.end()) {
422 vec_trackid.push_back((*idesitr).trackID);
424 const simb::MCParticle* particle = _particleList.at((*idesitr).trackID);
425 int pdg = particle->PdgCode();
426 if (pdg == 13 || pdg == -13) {
428 _en_13 += hit_energy * ((*idesitr).energyFrac);
437 it = find(vec_pdg.begin(), vec_pdg.end(), 13);
438 if (it != vec_pdg.end()) { no_cl_for_muon++; }
440 it2 = find(vec_pdg.begin(), vec_pdg.end(), 11);
441 if (it2 != vec_pdg.end()) { no_cl_for_electron++; }
443 it3 = find(vec_pdg.begin(), vec_pdg.end(), -11);
444 if (it3 != vec_pdg.end()) { no_cl_for_positron++; }
446 it4 = find(vec_pdg.begin(), vec_pdg.end(), 111);
447 if (it4 != vec_pdg.end()) { no_cl_for_pion_111++; }
448 it6 = find(vec_pdg.begin(), vec_pdg.end(), 211);
449 if (it6 != vec_pdg.end()) { no_cl_for_pion_211++; }
450 it7 = find(vec_pdg.begin(), vec_pdg.end(), -211);
451 if (it7 != vec_pdg.end()) { no_cl_for_pion_m211++; }
452 it8 = find(vec_pdg.begin(), vec_pdg.end(), 2212);
453 if (it8 != vec_pdg.end()) { no_cl_for_proton++; }
455 sort(vec_pdg.begin(), vec_pdg.end());
456 vec_pdg.erase(unique(vec_pdg.begin(), vec_pdg.end()), vec_pdg.end());
460 sort(vec_trackid.begin(), vec_trackid.end());
461 vec_trackid.erase(unique(vec_trackid.begin(), vec_trackid.end()), vec_trackid.end());
462 for (
unsigned int ii = 0; ii < vec_trackid.size(); ++ii) {
463 all_trackids.push_back(vec_trackid[ii]);
469 sort(vec_trackid_mother.begin(), vec_trackid_mother.end());
470 vec_trackid_mother.erase(unique(vec_trackid_mother.begin(), vec_trackid_mother.end()),
471 vec_trackid_mother.end());
475 sort(vec_trackid_mother_en.begin(), vec_trackid_mother_en.end());
476 vec_trackid_mother_en.erase(
477 unique(vec_trackid_mother_en.begin(), vec_trackid_mother_en.end()),
478 vec_trackid_mother_en.end());
483 for (
unsigned int ii = 0; ii < mc_trackids.size(); ++ii) {
484 it5 = find(vec_trackid.begin(), vec_trackid.end(), mc_trackids[ii]);
485 if (it5 != vec_trackid.end()) {
486 ids.push_back(mc_trackids[ii]);
499 no_of_particles_in_cluster += vec_pdg.size();
500 sum_vec_trackid += vec_trackid_mother.size();
501 total_no_hits_in_clusters += _hits.size();
507 vec_trackid_mother.clear();
509 vec_trackid_mother_en.clear();
516 sort(all_trackids.begin(), all_trackids.end());
517 all_trackids.erase(unique(all_trackids.begin(), all_trackids.end()), all_trackids.end());
522 sort(ids.begin(), ids.end());
523 ids.erase(unique(ids.begin(), ids.end()), ids.end());
524 double no_of_clusters_per_track = noCluster / ids.size();
528 if (no_cl_for_muon != 0) {
fCl_for_Muon->Fill(no_cl_for_muon); }
533 no_cl_for_electron = 0;
534 no_cl_for_positron = 0;
535 no_cl_for_pion_111 = 0;
536 no_cl_for_pion_211 = 0;
537 no_cl_for_pion_m211 = 0;
538 no_cl_for_proton = 0;
543 double result = no_of_particles_in_cluster / no_of_clusters;
545 double no_noise_hits = hits.size() - total_no_hits_in_clusters;
546 double percent_noise = double(no_noise_hits / hits.size()) * 100;
548 double no_trackid_per_cl_per_event = sum_vec_trackid / no_of_clusters;
556 for (
unsigned int i = 0; i < mclist.size(); ++i) {
557 art::Ptr<simb::MCTruth> mc(mclist[i]);
559 for (
int ii = 0; ii < mc->NParticles(); ++ii) {
560 simb::MCParticle part(mc->GetParticle(ii));
561 std::cout <<
"FROM MC TRUTH,the particle's pdg code is: " << part.PdgCode() << std::endl;
562 std::cout <<
"with energy= " << part.E();
563 if (
abs(part.PdgCode()) == 13) {
std::cout <<
" I have a muon!!!" << std::endl; }
564 if (
abs(part.PdgCode()) == 111) {
std::cout <<
" I have a pi zero!!!" << std::endl; }
574 double hit_13 = 0, hit_11 = 0, hit_m_11 = 0, hit_111 = 0, hit_211 = 0, hit_m211 = 0,
575 hit_2212 = 0, hit_2112 = 0;
576 double en_13 = 0, en_11 = 0, en_m11 = 0, en_111 = 0, en_211 = 0, en_m211 = 0, en_2212 = 0,
579 std::vector<art::Ptr<recob::Hit>>::iterator itr = hits.begin();
580 while (itr != hits.end()) {
582 std::vector<sim::TrackIDE> trackides = bt_serv->HitToTrackIDEs(clockData, *itr);
583 std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, *itr);
585 std::vector<sim::TrackIDE>::iterator idesitr = trackides.begin();
587 hit_energy = hits[itr - hits.begin()]->Integral();
589 while (idesitr != trackides.end()) {
591 const simb::MCParticle* particle = _particleList.at((*idesitr).trackID);
593 int pdg = particle->PdgCode();
596 if (pdg == 13 || pdg == -13) {
598 en_13 += hit_energy * ((*idesitr).energyFrac);
618 std::cout <<
"****** mu E from clusters = " << _en_13 << std::endl;
619 std::cout <<
"****** mu E from hits = " << en_13 << std::endl;
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
std::string fCalDataModuleLabel
DBclusterAna(fhicl::ParameterSet const &pset)
TH1F * fPercent_lost_2212_energy
TH1F * fPercent_lost_muon_energy
TH1F * fNoParticles_trackid
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
TH1F * fno_of_clusters_per_track
TH1F * fPercent_lost_111_hits
Definition of basic raw digits.
std::string fGenieGenModuleLabel
void analyze(const art::Event &evt)
read access to event
TH1F * fNoClustersInEvent
TH1F * fPercent_lost_electron_energy
std::string fDigitModuleLabel
TH1F * fPercent_lost_111_energy
TH1F * fPercent_lost_2112_energy
TH1F * fPercent_lost_m211_hits
TH1F * fPercent_lost_positron_hits
TH1F * fPercent_lost_m211_energy
std::string fLArG4ModuleLabel
Declaration of cluster object.
TH1F * fNoParticles_trackid_per_event
TH1F * fPercent_lost_electron_hits
Encapsulate the construction of a single detector plane.
TH1F * fPercent_lost_muon_hits
TH1F * fNoParticles_pdg_per_event
TH1F * fPercent_lost_positron_energy
Declaration of basic channel signal object.
TH1F * fNoParticles_trackid_mother
std::string fHitsModuleLabel
TH1F * fPercent_lost_211_hits
art::ServiceHandle< art::TFileService > tfs
TH1F * fPercent_lost_2112_hits
TH1F * fPercent_lost_211_energy
TH1F * fPercent_lost_2212_hits
std::string fClusterFinderModuleLabel
art framework interface to geometry description
BEGIN_PROLOG could also be cout