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;
std::string fCalDataModuleLabel
TH1F * fPercent_lost_2212_energy
TH1F * fPercent_lost_muon_energy
TH1F * fNoParticles_trackid
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
TH1F * fno_of_clusters_per_track
TH1F * fPercent_lost_111_hits
std::string fGenieGenModuleLabel
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
TH1F * fNoParticles_trackid_per_event
TH1F * fPercent_lost_electron_hits
TH1F * fPercent_lost_muon_hits
TH1F * fNoParticles_pdg_per_event
TH1F * fPercent_lost_positron_energy
TH1F * fNoParticles_trackid_mother
std::string fHitsModuleLabel
TH1F * fPercent_lost_211_hits
TH1F * fPercent_lost_2112_hits
TH1F * fPercent_lost_211_energy
TH1F * fPercent_lost_2212_hits
std::string fClusterFinderModuleLabel
BEGIN_PROLOG could also be cout