398 {
399 LOG(info) << " * Start of event loop" << std::endl;
401
403 LOG(error) <<
" ** Trying to start from event " <<
fstartEvt
404 << " which is greater than the tree entries: "
405 <<
ftree->GetEntries() <<
". Doing nothing...";
406 return;
407 }
408
412 :
ftree->GetEntries();
413 LOG(info) <<
" - Processing event " <<
fstartEvt <<
" to event "
415
416 unsigned nplus = 0;
417 unsigned nminus = 0;
418 unsigned skipMu_pmin = 0;
419 unsigned skipMu_acc = 0;
420 unsigned skipEvt = 0;
421 double wplus = 0.;
422 double wminus = 0.;
423 double skipMu_pminW = 0.;
424 double skipMu_accW = 0.;
425 double skipMu_pathW = 0.;
426
427 struct PathTotals {
428 Long64_t muons = 0;
430 double length = 0.;
431 double weightedLength = 0.;
432 void Add(double w, double l) {
433 ++muons;
435 length += l;
436 weightedLength +=
w * l;
437 }
438 };
439 PathTotals pathTotals;
440 std::array<PathTotals, nMats> pathTotalsByMat = {};
441
444 LOG(
debug) <<
" --- Processing event " <<
iEvent << std::endl;
445 if (iEvent % 100 == 0)
446 LOG(info) <<
" --- Processing event " <<
iEvent << std::endl;
447 if (!
finEv.PrepareEntry(
ftree, iEvent) ||
ftree->GetEntry(iEvent) <= 0) {
448 LOG(error) <<
" --- Error reading tree entry: " <<
iEvent;
449 skipEvt++;
450 continue;
451 }
452
453 if (
finEv.MCTrack ==
nullptr) {
454 skipEvt++;
455 continue;
456 }
457
458 unsigned nTr = (*
finEv.MCTrack).size();
459 if (nTr == 0) {
460 skipEvt++;
461 continue;
462 }
463
464
465
466 Int_t muIdx = 0;
467
468 ShipMCTrack& track = (*
finEv.MCTrack)[
static_cast<unsigned>(muIdx)];
471
472 double mup = track.
GetP();
473
475 LOG(
debug) <<
iEvent <<
" skipped: muon momentum " << mup
477 skipMu_pmin++;
478 skipMu_pminW += muW;
479 continue;
480 }
481
482 std::string targetType;
483 if (pid == -13) {
484 nplus++;
485 wplus += muW;
486 targetType = "gamma/mu+";
487 } else if (pid == 13) {
488 nminus++;
489 wminus += muW;
490 targetType = "gamma/mu-";
491 } else {
492 LOG(warning) <<
iEvent <<
" skipped: "
493 << " nTracks= " << nTr
494 <<
" -- 1st track pid not a muon: " <<
pid << std::endl;
495 skipEvt++;
496 continue;
497 }
498
505
506
507
508
509
510
511 if (
foutEv.ubtPt.size() == 0 &&
foutEv.sbtPt.size() == 0 &&
513 LOG(
debug) <<
" Counting muon event with no hit " <<
iEvent
514 <<
" UBT Hits: " <<
foutEv.ubtPt.size()
515 <<
", SBT Hits: " <<
foutEv.sbtPt.size()
516 <<
", SST Hits: " <<
foutEv.sstPt.size()
517 <<
", TD Hits: " <<
foutEv.tdPt.size() << std::endl;
518 skipMu_acc++;
519 skipMu_accW += muW;
520
521
522 }
523
524 LOG(
debug) <<
" -- size of hits collections: " << std::endl
525 <<
" ---- mcTracks: " <<
foutEv.mcTrks.size() << std::endl
526 <<
" ---- UBT Hits: " <<
foutEv.ubtPt.size() << std::endl
527 <<
" ---- SBT Hits: " <<
foutEv.sbtPt.size() << std::endl
528 <<
" ---- SST Hits: " <<
foutEv.sstPt.size() << std::endl;
529
530
531
533 skipEvt++;
534 skipMu_pathW += muW;
535 continue;
536 }
537 std::map<std::string, MuonPath>& lPathMap =
fGeoProcessor.FillMuonPath();
538
539 if (lPathMap.size() == 0) {
540 LOG(error) << " -- No elements in path... Not doing anything...";
541 skipEvt++;
542 skipMu_pathW += muW;
543 continue;
544 }
545
546
547
548 for (
unsigned i = 0;
i < nMats; ++
i) {
550 if (path == lPathMap.end() ||
path->second.GetNSlices() < 1)
continue;
551
552 foutEv.br[
i].nDISevtsGenerated = 0;
554 path->second.GetLength() - DISMinLength(
path->first,
path->second);
556 if (
foutEv.pathLengthByMat[i] > 0.)
557 pathTotalsByMat[
i].Add(muW,
foutEv.pathLengthByMat[i]);
558 }
559
560
561
562
563
564
565
566 for (
unsigned i(0);
i < nMats - 1; ++
i) {
567 if (lPathMap.find(
MatTypeStr[i].Data()) != lPathMap.end())
571 }
572
574 pathTotals.Add(muW,
foutEv.pathLength);
575
576 }
577
578 LOG(info) << "Found " << nplus << " mu+ and " << nminus << " mu-."
579 << std::endl
580 << "Skipped: " << skipEvt << " events and " << skipMu_pmin
581 << " muons with too low p" << std::endl
582 << "Counted: " << skipMu_acc
583 << " muons with no recorded hits in UBT,SBT,SST,TD.";
584 LOG(info) << "Weighted counts (sum MCTrack[0].fW): " << wplus << " mu+ and "
585 << wminus << " mu- (after momentum cut)." << std::endl
586 << "Skipped (sum MCTrack[0].fW): " << skipMu_pminW
587 << " with too low p, " << skipMu_pathW
588 << " muons with invalid or empty paths." << std::endl
589 << "Counted (sum MCTrack[0].fW): " << skipMu_accW
590 << " muons with no recorded hits in UBT,SBT,SST,TD.";
592
593 LOG(info) << std::setprecision(17)
594 << "Muon path totals (cm, excluding REST): output muons = "
595 << pathTotals.muons << ", sum(fW) = " << pathTotals.weight
596 << ", sum(L) = " << pathTotals.length
597 << ", sum(fW*L) = " << pathTotals.weightedLength;
598 for (
unsigned i = 0;
i < nMats; ++
i) {
599 const auto& totals = pathTotalsByMat[
i];
600 LOG(info) << std::setprecision(17) <<
"Muon path totals " <<
MatTypeStr[
i]
601 << " (cm): crossing muons = " << totals.muons
602 << ", sum(fW) = " << totals.weight
603 << ", sum(L) = " << totals.length
604 << ", sum(fW*L) = " << totals.weightedLength;
605 }
606}
void fillMCTracks(const Int_t aIdx)
void fillSSTHits(const Int_t aIdx)
void fillTDHits(const Int_t aIdx)
void fillSBTHits(const Int_t aIdx)
void generateDISevents(const std::string &tType, const double &amuonW, const std::string &aLabel, const MuonPath &aPath, ShipMuDIS::MuonDISBranches &aDISBr)
void fillUBTHits(const Int_t aIdx)
Double_t GetWeight() const
const std::array< TString, nMats > MatTypeStr