SND@LHC Software
Loading...
Searching...
No Matches
sndSciFiTools.cxx File Reference
#include "sndSciFiTools.h"
#include <numeric>
#include <algorithm>
#include "TH1F.h"
#include "FairLogger.h"
#include "TClonesArray.h"
#include "sndScifiHit.h"
#include "ROOT/TSeq.hxx"
#include "Scifi.h"
#include "TROOT.h"
#include "ROOT/RRangeCast.hxx"
Include dependency graph for sndSciFiTools.cxx:

Go to the source code of this file.

Functions

bool validateHit (sndScifiHit *aHit, int ref_station, bool ref_orientation)
 
double computeMean (const std::vector< double > &values)
 
double hitWeightComputation (std::vector< double > hit_position)
 

Function Documentation

◆ computeMean()

double computeMean ( const std::vector< double > &  values)

Definition at line 565 of file sndSciFiTools.cxx.

566{
567 double sum = std::accumulate(values.begin(), values.end(), 0.0);
568 double mean = sum / values.size();
569 return mean;
570}

◆ hitWeightComputation()

double hitWeightComputation ( std::vector< double >  hit_position)

Definition at line 635 of file sndSciFiTools.cxx.

635 {
636 /* This function returns the summation of the hit weights
637 where a hit weight is the number of neighbouring hits within 1 cm position (default width).
638
639 Arguments:
640 hit_position: A vector containing the positions of the hits in a specific SciFi station.
641
642 Returns:
643 The sum of the weights of the hits in the vector.
644 Returns 0 if the vector is empty or if the sum of weights is 0.
645 */
646
647 if (hit_position.empty()) {
648 LOG(INFO) << "Warning: The hit position vector is empty." << std::endl;
649 return 0; // Return 0 if the vector is empty
650 }
651
652 int n_hits = hit_position.size();
653 double width = 1.0; // Width around the hit to consider as a neighbour, in cm
654 std::vector<double> weights; // Vector to store the weights of each hit
655
656 // Sorting the hits for efficient neighbour counting
657 std::sort(hit_position.begin(), hit_position.end());
658
659 // Initialize pointers for the sliding window.
660 // Both pointers will only move forward (or stay put) across the outer loop iterations.
661 int left_ptr = 0;
662 int right_ptr = 0;
663
664 // Loop through each hit position to calculate its neighbour count
665 for (int i = 0; i < n_hits; i++) {
666 double specific_hit = hit_position[i];
667
668 // Move right_ptr forward to include all hits within (specific_hit + width).
669 // It will point to the first element *just outside* the right boundary of the window.
670 while (right_ptr < n_hits && hit_position[right_ptr] <= specific_hit + width) {
671 right_ptr++;
672 }
673
674 // Move left_ptr forward to exclude all hits *less than* (specific_hit - width).
675 // It will point to the first element *just inside* or at the left boundary of the window.
676 while (left_ptr < n_hits && hit_position[left_ptr] < specific_hit - width) {
677 left_ptr++;
678 }
679
680 // Calculate neighbouring hits within the window:
681 // The number of hits in the current window is (right_ptr - left_ptr).
682 // This count includes the 'specific_hit' itself.
683 double count_in_window = right_ptr - left_ptr;
684
685 // Subtract 1 to exclude the 'specific_hit' itself from the neighbour count.
686 // We must ensure that 'specific_hit' (hit_position[i]) is actually within the window
687 // defined by left_ptr and right_ptr. Since the array is sorted and we are iterating
688 // through 'i', hit_position[i] will always be between hit_position[left_ptr] and
689 // hit_position[right_ptr-1] (if left_ptr <= i < right_ptr).
690 double neighbour_no_of_hits = count_in_window - 1;
691
692 // Ensure the neighbour count is non-negative
693 if (neighbour_no_of_hits < 0) {
694 neighbour_no_of_hits = 0;
695 }
696
697 weights.push_back(neighbour_no_of_hits);
698 }
699
700 // Calculate the sum of all computed weights
701 double sum_weights = std::accumulate(weights.begin(), weights.end(), 0.0);
702
703 return sum_weights;
704}
int i
Definition ShipAna.py:86
width(particle)
Definition rpvsusy.py:76

◆ validateHit()

bool validateHit ( sndScifiHit aHit,
int  ref_station,
bool  ref_orientation 
)

Definition at line 108 of file sndSciFiTools.cxx.

109{
110
111 if (!(aHit->isValid())) {
112 return false;
113 }
114 if (aHit->GetStation() != ref_station) {
115 return false;
116 }
117 if (aHit->isVertical() != ref_orientation) {
118 return false;
119 }
120
121 return true;
122}
Int_t GetStation()
Definition sndScifiHit.h:31
bool isValid() const
Definition sndScifiHit.h:30
bool isVertical()
Definition sndScifiHit.h:32