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 566 of file sndSciFiTools.cxx.

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

◆ hitWeightComputation()

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

Definition at line 636 of file sndSciFiTools.cxx.

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