SND@LHC Software
Loading...
Searching...
No Matches
snd::analysis_tools Namespace Reference

Functions

std::string GetGeoPath (const std::string &csv_file_path, int run_number)
 
std::pair< Scifi *, MuFilter * > GetGeometry (std::string geometry_path)
 
std::pair< Scifi *, MuFilter * > GetGeometry (const std::string &csv_file_path, int run_number)
 
void getSciFiHitsPerStation (const TClonesArray *digiHits, std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits)
 
int getTotalSciFiHits (std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits)
 
int getTotalSciFiHits (const TClonesArray *digiHits)
 
std::vector< float > getFractionalHitsPerScifiPlane (std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits)
 
std::vector< float > getFractionalHitsPerScifiPlane (const TClonesArray *digiHits)
 
int findScifiStation (std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits, float threshold)
 
int findScifiStation (const TClonesArray *digiHits, float threshold)
 
float peakScifiTiming (const TClonesArray &digiHits, int bins, float min_x, float max_x, bool isMC=false)
 
std::unique_ptr< TClonesArray > getScifiHits (const TClonesArray &digiHits, int station, bool orientation)
 
std::unique_ptr< TClonesArray > selectScifiHits (const TClonesArray &digiHits, int station, bool orientation, int bins_x=52, float min_x=0.0, float max_x=26.0, float time_lower_range=1E9/(2 *ShipUnit::snd_freq), float time_upper_range=1.2E9/(ShipUnit::snd_freq/ShipUnit::hertz), bool make_selection=true, bool isMC=false)
 
std::unique_ptr< TClonesArray > selectScifiHits (const TClonesArray &digiHits, int station, bool orientation, const std::map< std::string, float > &selection_parameters, bool make_selection=true, bool isMC=false)
 
std::unique_ptr< TClonesArray > filterScifiHits (const TClonesArray &digiHits, const std::map< std::string, float > &selection_parameters, int method=0, std::string setup="TI18", bool isMC=false)
 
std::unique_ptr< TClonesArray > filterScifiHits (const TClonesArray &digiHits, int method=0, std::string setup="TI18", bool isMC=false)
 
int calculateSiPMNumber (int reference_SiPM)
 
int densityScifi (int reference_SiPM, const TClonesArray &digiHits, int radius, int min_hit_density, bool min_check)
 
bool densityCheck (const TClonesArray &digiHits, int radius=64, int min_hit_density=36, int station=1, bool orientation=false)
 
int showerInteractionWall (const TClonesArray &digiHits, const std::map< std::string, float > &selection_parameters, int method=0, std::string setup="TI18")
 
int showerInteractionWall (const TClonesArray &digiHits, int method=0, std::string setup="TI18")
 
std::pair< double, double > findCentreOfGravityPerStation (const TClonesArray *digiHits, int station, Scifi *ScifiDet)
 
std::unique_ptr< TChain > GetTChain (const std::string &csv_file_path, int run_number, int n_files=-1)
 
std::unique_ptr< TChain > GetTChain (std::string file_name)
 
std::string GetDataBasePath (const std::string &csv_file_path, int run_number)
 

Function Documentation

◆ calculateSiPMNumber()

int snd::analysis_tools::calculateSiPMNumber ( int  reference_SiPM)

Definition at line 374 of file sndSciFiTools.cxx.

375{
376
377 int ref_matAux = reference_SiPM % 100000;
378 int ref_mat = ref_matAux / 10000;
379 int ref_arrayAux = reference_SiPM % 10000;
380 int ref_array = ref_arrayAux / 1000;
381 int ref_channel = reference_SiPM % 1000;
382 int referenceChannel = ref_mat * 4 * 128 + ref_array * 128 + ref_channel;
383
384 return referenceChannel;
385}

◆ densityCheck()

bool snd::analysis_tools::densityCheck ( const TClonesArray &  digiHits,
int  radius = 64,
int  min_hit_density = 36,
int  station = 1,
bool  orientation = false 
)

Definition at line 426 of file sndSciFiTools.cxx.

428{
429
430 if (digiHits.GetEntries() <= 0) {
431 return false;
432 }
433
434 if (radius <= 0) {
435 LOG(FATAL) << "Radius<=0. Please provide a radius bigger than 0.";
436 return false;
437 }
438
439 if (min_hit_density < 0) {
440 LOG(FATAL) << "Min_hit_density < 0. Please provide a min_hit_density >= 0.";
441 return false;
442 }
443
444 if (min_hit_density > 2 * radius) {
445 LOG(warning) << "Warning! Radius of density check does not allow for the required minimum density!";
446 return false;
447 }
448
449 // Creating a vector that stores the fired SiPM channels (should already be ordered but we sort
450 // afterwards to make sure)
451 std::vector<int> fired_channels{};
452
453 // Only fill the set with hits from the same station and with the same orientation as given in
454 // argument (false==horizontal and true==vertical)
455 for (auto *p : digiHits) {
456 auto *hit = dynamic_cast<sndScifiHit *>(p);
457 if (!validateHit(hit, station, orientation)) {
458 continue;
459 }
460 fired_channels.push_back(calculateSiPMNumber(hit->GetChannelID()));
461 }
462
463 int n_fired_channels = fired_channels.size();
464
465 if (n_fired_channels < min_hit_density) {
466 return false;
467 }
468
469 // Looping over the ordered hits, checking whether within an interval of "min_hit_density" the
470 // difference between the channel IDs is smaller than "radius". If so, then we have the required
471 // density. Else, we check the next combination until we meet the criterion, or end the loop,
472 // returning false
473 std::sort(fired_channels.begin(), fired_channels.end());
474 for (int i = 0; i < n_fired_channels - min_hit_density; i++) {
475
476 if (fired_channels[i + min_hit_density - 1] - fired_channels[i] <= radius * 2) {
477 return true;
478 }
479 }
480 return false;
481}
int i
Definition ShipAna.py:86
int calculateSiPMNumber(int reference_SiPM)
bool validateHit(sndScifiHit *aHit, int ref_station, bool ref_orientation)

◆ densityScifi()

int snd::analysis_tools::densityScifi ( int  reference_SiPM,
const TClonesArray &  digiHits,
int  radius,
int  min_hit_density,
bool  min_check 
)

Definition at line 387 of file sndSciFiTools.cxx.

389{
390
391 int hit_density = 0;
392
393 bool orientation = false;
394 if (int(reference_SiPM / 100000) % 10 == 1) {
395 orientation = true;
396 }
397 int ref_station = reference_SiPM / 1000000;
398 int referenceChannel = calculateSiPMNumber(reference_SiPM);
399
400 for (auto *p : digiHits) {
401 auto *hit = dynamic_cast<sndScifiHit *>(p);
402 if (!validateHit(hit, ref_station, orientation)) {
403 continue;
404 }
405 int hitChannel = calculateSiPMNumber(hit->GetChannelID());
406 if (radius == -1) {
407 hit_density++;
408 } else {
409 if (hitChannel > referenceChannel + radius) {
410 break;
411 }
412 if (abs(referenceChannel - hitChannel) <= radius) {
413 hit_density++;
414 }
415 }
416
417 if (min_check && (hit_density >= min_hit_density)) {
418 break;
419 }
420 }
421
422 return hit_density;
423}

◆ filterScifiHits() [1/2]

std::unique_ptr< TClonesArray > snd::analysis_tools::filterScifiHits ( const TClonesArray &  digiHits,
const std::map< std::string, float > &  selection_parameters,
int  method = 0,
std::string  setup = "TI18",
bool  isMC = false 
)

Definition at line 300 of file sndSciFiTools.cxx.

303{
304 TClonesArray supportArray("sndScifiHit", 0);
305 auto filteredHits = std::make_unique<TClonesArray>("sndScifiHit", digiHits.GetEntries());
306 int filteredHitsIndex = 0;
307 int ScifiStations = 5;
308 if (setup == "H8") {
309 ScifiStations = 4;
310 } else {
311 LOG(info) << "\"TI18\" setup will be used by default, please provide \"H8\" for the Testbeam setup.";
312 }
313
314 sndScifiHit *hit;
315 TIter hitIterator(&supportArray);
316
317 if (method == 0) {
318
319 if ((selection_parameters.find("bins_x") == selection_parameters.end()) ||
320 (selection_parameters.find("min_x") == selection_parameters.end()) ||
321 (selection_parameters.find("max_x") == selection_parameters.end()) ||
322 (selection_parameters.find("time_lower_range") == selection_parameters.end())) {
323 LOG(FATAL) << "In order to use method 0 please provide the correct selection_parameters. Consider the default "
324 "= {{\"bins_x\", 52.}, {\"min_x\", 0.}, {\"max_x\", 26.}, {\"time_lower_range\", "
325 "1E9/(2*ShipUnit::snd_freq/ShipUnit::hertz)}, {\"time_upper_range\", "
326 "1.2E9/(ShipUnit::snd_freq/ShipUnit::hertz)}}";
327 }
328
329 // This is overwriting the previous arrays with the newest one
330 for (auto station : ROOT::MakeSeq(1, ScifiStations + 1)) {
331 for (auto orientation : {false, true}) {
332
333 auto supportArray = selectScifiHits(digiHits, station, orientation, selection_parameters, true, isMC);
334 for (auto *p : *supportArray) {
335 auto *hit = dynamic_cast<sndScifiHit *>(p);
336 if (hit->isValid()) {
337 new ((*filteredHits)[filteredHitsIndex++]) sndScifiHit(*hit);
338 }
339 }
340 }
341 }
342 } else {
343 LOG(error) << "Please provide a valid time filter method from:";
344 LOG(error) << "(0): Events within \\mp time_lower_range time_upper_range of the peak of the time distribution "
345 "for Scifi Hits within each station and orientation";
346 LOG(FATAL) << "selection_parameters = {bins_x, min_x, max_x, time_lower_range, time_upper_range}.";
347 }
348 return filteredHits;
349}
bool isValid() const
Definition sndScifiHit.h:30
std::unique_ptr< TClonesArray > selectScifiHits(const TClonesArray &digiHits, int station, bool orientation, int bins_x=52, float min_x=0.0, float max_x=26.0, float time_lower_range=1E9/(2 *ShipUnit::snd_freq), float time_upper_range=1.2E9/(ShipUnit::snd_freq/ShipUnit::hertz), bool make_selection=true, bool isMC=false)

◆ filterScifiHits() [2/2]

std::unique_ptr< TClonesArray > snd::analysis_tools::filterScifiHits ( const TClonesArray &  digiHits,
int  method = 0,
std::string  setup = "TI18",
bool  isMC = false 
)

Definition at line 352 of file sndSciFiTools.cxx.

353{
354
355 std::map<std::string, float> selection_parameters;
356
357 if (method == 0) {
358
359 selection_parameters["bins_x"] = 52.0;
360 selection_parameters["min_x"] = 0.0;
361 selection_parameters["max_x"] = 26.0;
362 selection_parameters["time_lower_range"] = 1E9 / (2 * ShipUnit::snd_freq / ShipUnit::hertz);
363 selection_parameters["time_upper_range"] = 1.2E9 / (ShipUnit::snd_freq / ShipUnit::hertz);
364
365 } else {
366 LOG(FATAL) << "Please use method=0. No other methods implemented so far.";
367 }
368
369 return filterScifiHits(digiHits, selection_parameters, method, setup, isMC);
370}

◆ findCentreOfGravityPerStation()

std::pair< double, double > snd::analysis_tools::findCentreOfGravityPerStation ( const TClonesArray *  digiHits,
int  station,
Scifi ScifiDet 
)

Definition at line 566 of file sndSciFiTools.cxx.

567{
568 if (!digiHits) {
569 LOG(ERROR) << "Error: digiHits is null in findCentreOfGravityPerStation";
570 }
571 std::vector<double> x_positions;
572 std::vector<double> y_positions;
573 TVector3 A, B;
574 for (auto* obj : *digiHits) {
575 auto* hit = dynamic_cast<sndScifiHit*>(obj);
576 if (!hit || !hit->isValid()) {
577 continue;
578 }
579 if (hit->GetStation() != station) {
580 continue;
581 }
582 ScifiDet->GetSiPMPosition(hit->GetDetectorID(), A, B);
583 if (hit->isVertical()) {
584 x_positions.push_back((A.X() + B.X()) * 0.5);
585 }
586 else {
587 y_positions.push_back((A.Y() + B.Y()) * 0.5);
588 }
589 }
590 if (x_positions.empty()) {
591 LOG(ERROR) << "Error: No hits enter.";
592 }
593 double meanX = computeMean(x_positions);
594 if (y_positions.empty()) {
595 LOG(ERROR) << "Error: No hits enter.";
596 }
597 double meanY = computeMean(y_positions);
598 return {meanX, meanY};
599}
void GetSiPMPosition(Int_t SiPMChan, TVector3 &A, TVector3 &B)
Definition Scifi.cxx:727
double computeMean(const std::vector< double > &values)

◆ findScifiStation() [1/2]

int snd::analysis_tools::findScifiStation ( const TClonesArray *  digiHits,
float  threshold 
)

Definition at line 94 of file sndSciFiTools.cxx.

95{
96 std::vector<int> horizontal_hits = std::vector<int>(5);
97 std::vector<int> vertical_hits = std::vector<int>(5);
98
99 getSciFiHitsPerStation(digiHits, horizontal_hits, vertical_hits);
100
101 return findScifiStation(horizontal_hits, vertical_hits, threshold);
102}
int findScifiStation(std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits, float threshold)
void getSciFiHitsPerStation(const TClonesArray *digiHits, std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits)

◆ findScifiStation() [2/2]

int snd::analysis_tools::findScifiStation ( std::vector< int > &  horizontal_hits,
std::vector< int > &  vertical_hits,
float  threshold 
)

Definition at line 78 of file sndSciFiTools.cxx.

80{
81
82 std::vector<float> frac = getFractionalHitsPerScifiPlane(horizontal_hits, vertical_hits);
83
84 std::vector<float> frac_sum = std::vector<float>(frac.size());
85
86 std::partial_sum(frac.begin(), frac.end(), frac_sum.begin());
87
88 std::vector<float>::iterator station =
89 std::find_if(frac_sum.begin(), frac_sum.end(), [&threshold](const auto &f) { return f > threshold; });
90
91 return station - frac_sum.begin() + 1;
92}
std::vector< float > getFractionalHitsPerScifiPlane(std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits)

◆ GetDataBasePath()

std::string snd::analysis_tools::GetDataBasePath ( const std::string &  csv_file_path,
int  run_number 
)

Definition at line 12 of file sndTchainGetter.cxx.

12 {
13 std::ifstream file(csv_file_path);
14 if (!file.is_open()) {
15 throw std::runtime_error("Could not open CSV file: " + csv_file_path);
16 }
17
18 std::string line;
19 std::getline(file, line); // skip header
20
21 while (std::getline(file, line)) {
22 std::istringstream ss(line);
23 std::string token;
24
25 std::getline(ss, token, ',');
26 int min_run = std::stoi(token);
27
28 std::getline(ss, token, ',');
29 int max_run = std::stoi(token);
30
31 std::getline(ss, token);
32 std::string path = token;
33
34 if (run_number >= min_run && run_number <= max_run) {
35 return path;
36 }
37 }
38 throw std::runtime_error("Run number not found in CSV mapping.");
39}

◆ getFractionalHitsPerScifiPlane() [1/2]

std::vector< float > snd::analysis_tools::getFractionalHitsPerScifiPlane ( const TClonesArray *  digiHits)

Definition at line 68 of file sndSciFiTools.cxx.

69{
70 std::vector<int> horizontal_hits = std::vector<int>(5);
71 std::vector<int> vertical_hits = std::vector<int>(5);
72
73 getSciFiHitsPerStation(digiHits, horizontal_hits, vertical_hits);
74
75 return getFractionalHitsPerScifiPlane(horizontal_hits, vertical_hits);
76}

◆ getFractionalHitsPerScifiPlane() [2/2]

std::vector< float > snd::analysis_tools::getFractionalHitsPerScifiPlane ( std::vector< int > &  horizontal_hits,
std::vector< int > &  vertical_hits 
)

Definition at line 54 of file sndSciFiTools.cxx.

55{
56
57 int total_hits = getTotalSciFiHits(horizontal_hits, vertical_hits);
58
59 std::vector<float> fractional_hits_per_station = std::vector<float>(horizontal_hits.size());
60
61 std::transform(horizontal_hits.begin(), horizontal_hits.end(), vertical_hits.begin(),
62 fractional_hits_per_station.begin(),
63 [&total_hits](const auto &hor, const auto &ver) { return ((float)hor + ver) / total_hits; });
64
65 return fractional_hits_per_station;
66}
int getTotalSciFiHits(std::vector< int > &horizontal_hits, std::vector< int > &vertical_hits)

◆ GetGeometry() [1/2]

std::pair< Scifi *, MuFilter * > snd::analysis_tools::GetGeometry ( const std::string &  csv_file_path,
int  run_number 
)

Definition at line 62 of file sndGeometryGetter.cxx.

63{
64 std::string geometry_path = GetGeoPath(csv_file_path, run_number);
65
66 return GetGeometry(geometry_path);
67}
std::pair< Scifi *, MuFilter * > GetGeometry(std::string geometry_path)
std::string GetGeoPath(const std::string &csv_file_path, int run_number)

◆ GetGeometry() [2/2]

std::pair< Scifi *, MuFilter * > snd::analysis_tools::GetGeometry ( std::string  geometry_path)

Definition at line 45 of file sndGeometryGetter.cxx.

46{
47 TPython::Exec("import SndlhcGeo");
48 TPython::Exec(("SndlhcGeo.GeoInterface('" + geometry_path + "')").c_str());
49
50 // Init detectors
51 Scifi *scifi = new Scifi("Scifi", kTRUE);
52 MuFilter *mufilter = new MuFilter("MuFilter", kTRUE);
53
54 // Retrieve the detectors from ROOT's global list
55 scifi = dynamic_cast<Scifi *>(gROOT->GetListOfGlobals()->FindObject("Scifi"));
56 mufilter = dynamic_cast<MuFilter *>(gROOT->GetListOfGlobals()->FindObject("MuFilter"));
57
58 return std::make_pair(scifi, mufilter);
59}
Definition Scifi.h:20

◆ GetGeoPath()

std::string snd::analysis_tools::GetGeoPath ( const std::string &  csv_file_path,
int  run_number 
)

Definition at line 14 of file sndGeometryGetter.cxx.

15{
16 std::ifstream file(csv_file_path);
17 if (!file.is_open()) {
18 throw std::runtime_error("Could not open CSV file: " + csv_file_path);
19 }
20
21 std::string line;
22 std::getline(file, line); // skip header
23
24 while (std::getline(file, line)) {
25 std::istringstream ss(line);
26 std::string token;
27
28 std::getline(ss, token, ',');
29 int min_run = std::stoi(token);
30
31 std::getline(ss, token, ',');
32 int max_run = std::stoi(token);
33
34 std::getline(ss, token);
35 std::string path = token;
36
37 if (run_number >= min_run && run_number <= max_run) {
38 return path;
39 }
40 }
41 throw std::runtime_error("Run number not found in CSV mapping.");
42}

◆ getScifiHits()

std::unique_ptr< TClonesArray > snd::analysis_tools::getScifiHits ( const TClonesArray &  digiHits,
int  station,
bool  orientation 
)

Definition at line 163 of file sndSciFiTools.cxx.

164{
165
166 auto selectedHits = std::make_unique<TClonesArray>("sndScifiHit");
167
168 int i = 0;
169 for (auto *p : digiHits) {
170 auto *hit = dynamic_cast<sndScifiHit *>(p);
171 if (!validateHit(hit, station, orientation)) {
172 continue;
173 }
174 new ((*selectedHits)[i++]) sndScifiHit(*hit);
175 }
176
177 return selectedHits;
178}

◆ getSciFiHitsPerStation()

void snd::analysis_tools::getSciFiHitsPerStation ( const TClonesArray *  digiHits,
std::vector< int > &  horizontal_hits,
std::vector< int > &  vertical_hits 
)

Definition at line 13 of file sndSciFiTools.cxx.

15{
16
17 // Clear hits per plane vectors
18 std::fill(horizontal_hits.begin(), horizontal_hits.end(), 0);
19 std::fill(vertical_hits.begin(), vertical_hits.end(), 0);
20
21 // Add valid hits to hits per plane vectors
22 sndScifiHit *hit;
23 TIter hitIterator(digiHits);
24
25 while (hit = dynamic_cast<sndScifiHit *>(hitIterator.Next())) {
26 if (hit->isValid()) {
27 int station = hit->GetStation();
28 if (hit->isVertical()) {
29 vertical_hits[station - 1]++;
30 } else {
31 horizontal_hits[station - 1]++;
32 }
33 }
34 }
35}
Int_t GetStation()
Definition sndScifiHit.h:31
bool isVertical()
Definition sndScifiHit.h:32

◆ GetTChain() [1/2]

std::unique_ptr< TChain > snd::analysis_tools::GetTChain ( const std::string &  csv_file_path,
int  run_number,
int  n_files = -1 
)

Definition at line 41 of file sndTchainGetter.cxx.

41 {
42 std::string base_folder = GetDataBasePath(csv_file_path, run_number);
43 auto tchain = std::make_unique<TChain>("rawConv");
44 if (n_files == -1) {
45 tchain->Add(Form("%srun_%06d/sndsw_raw-*", base_folder.c_str(), run_number));
46 }
47 else {
48 for (int i = 0; i<n_files; ++i){
49 tchain->Add(Form("%srun_%06d/sndsw_raw-%04d.root", base_folder.c_str(), run_number, i));
50 }
51 }
52 return tchain;
53};
std::string GetDataBasePath(const std::string &csv_file_path, int run_number)

◆ GetTChain() [2/2]

std::unique_ptr< TChain > snd::analysis_tools::GetTChain ( std::string  file_name)

Definition at line 55 of file sndTchainGetter.cxx.

55 {
56 auto tchain = std::make_unique<TChain>("rawConv");
57 tchain->Add(file_name.c_str());
58 return tchain;
59}

◆ getTotalSciFiHits() [1/2]

int snd::analysis_tools::getTotalSciFiHits ( const TClonesArray *  digiHits)

Definition at line 43 of file sndSciFiTools.cxx.

44{
45 std::vector<int> horizontal_hits = std::vector<int>(5);
46 std::vector<int> vertical_hits = std::vector<int>(5);
47
48 getSciFiHitsPerStation(digiHits, horizontal_hits, vertical_hits);
49
50 return getTotalSciFiHits(horizontal_hits, vertical_hits);
51}

◆ getTotalSciFiHits() [2/2]

int snd::analysis_tools::getTotalSciFiHits ( std::vector< int > &  horizontal_hits,
std::vector< int > &  vertical_hits 
)

Definition at line 37 of file sndSciFiTools.cxx.

38{
39 return std::accumulate(horizontal_hits.begin(), horizontal_hits.end(),
40 std::accumulate(vertical_hits.begin(), vertical_hits.end(), 0));
41}

◆ peakScifiTiming()

float snd::analysis_tools::peakScifiTiming ( const TClonesArray &  digiHits,
int  bins,
float  min_x,
float  max_x,
bool  isMC = false 
)

Definition at line 125 of file sndSciFiTools.cxx.

126{
127
128 if (digiHits.GetEntries() <= 0) {
129 LOG(warning) << "digiHits has no valid SciFi Hits and as such no maximum for the timing distribution.";
130 return -1.;
131 }
132
133 TH1F ScifiTiming("Timing", "Scifi Timing", bins, min_x, max_x);
134
135 int refStation = ((sndScifiHit *)digiHits.At(0))->GetStation();
136 bool refOrientation = ((sndScifiHit *)digiHits.At(0))->isVertical();
137 float hitTime = -1.0;
138 float timeConversion = 1.;
139 if (!isMC) {
140 timeConversion = 1E9 / (ShipUnit::snd_freq / ShipUnit::hertz);
141 }
142
143 for (auto *p : digiHits) {
144 auto *hit = dynamic_cast<sndScifiHit *>(p);
145 if (!validateHit(hit, refStation, refOrientation)) {
146 continue;
147 }
148 hitTime = hit->GetTime() * timeConversion;
149 if (hitTime < min_x || hitTime > max_x) {
150 continue;
151 }
152 ScifiTiming.Fill(hitTime);
153 hitTime = -1.0;
154 }
155
156 float peakTiming = (ScifiTiming.GetMaximumBin() - 0.5) * (max_x - min_x) / bins + min_x;
157
158 return peakTiming;
159}
Float_t GetTime(Int_t nChannel=0)
Definition SndlhcHit.cxx:32

◆ selectScifiHits() [1/2]

std::unique_ptr< TClonesArray > snd::analysis_tools::selectScifiHits ( const TClonesArray &  digiHits,
int  station,
bool  orientation,
const std::map< std::string, float > &  selection_parameters,
bool  make_selection = true,
bool  isMC = false 
)

Definition at line 270 of file sndSciFiTools.cxx.

273{
274
275 if ((selection_parameters.find("bins_x") == selection_parameters.end()) ||
276 (selection_parameters.find("min_x") == selection_parameters.end()) ||
277 (selection_parameters.find("max_x") == selection_parameters.end()) ||
278 (selection_parameters.find("time_lower_range") == selection_parameters.end())) {
279 LOG(FATAL) << "In order to use method 0 please provide the correct selection_parameters. Consider the default = "
280 "{{\"bins_x\", 52.}, {\"min_x\", 0.}, {\"max_x\", 26.}, {\"time_lower_range\", "
281 "1E9/(2*ShipUnit::snd_freq/ShipUnit::hertz))}, {\"time_upper_range\", "
282 "2E9/(ShipUnit::snd_freq/ShipUnit::hertz)}}";
283 }
284
285 float time_upper_range = -1.;
286
287 if (selection_parameters.find("time_upper_range") == selection_parameters.end()) {
288 time_upper_range = selection_parameters.at("time_lower_range");
289 } else {
290 time_upper_range = selection_parameters.at("time_upper_range");
291 }
292
293 return selectScifiHits(digiHits, station, orientation, int(selection_parameters.at("bins_x")),
294 selection_parameters.at("min_x"), selection_parameters.at("max_x"),
295 selection_parameters.at("time_lower_range"), time_upper_range, make_selection,
296 isMC);
297}

◆ selectScifiHits() [2/2]

std::unique_ptr< TClonesArray > snd::analysis_tools::selectScifiHits ( const TClonesArray &  digiHits,
int  station,
bool  orientation,
int  bins_x = 52,
float  min_x = 0.0,
float  max_x = 26.0,
float  time_lower_range = 1E9/(2*ShipUnit::snd_freq),
float  time_upper_range = 1.2E9/(ShipUnit::snd_freq/ShipUnit::hertz),
bool  make_selection = true,
bool  isMC = false 
)

Definition at line 187 of file sndSciFiTools.cxx.

192{
193
194 if (bins_x < 1) {
195 LOG(FATAL) << "bins_x in selection_parameters cannot be <1. Consider using the default value of 52 instead.";
196 }
197 if (min_x > max_x) {
198 LOG(warning) << "In selection_parameters min_x > max_x. Values will be swapped.";
199 float aux_float = min_x;
200 min_x = max_x;
201 max_x = aux_float;
202 }
203 if (min_x < 0.0) {
204 LOG(warning) << "In selection_parameters min_x < 0.0. Consider using the default value of 0.0.";
205 }
206 if (max_x < 0.0) {
207 LOG(FATAL) << "In selection_parameters max_x < 0.0. Consider using the default value of 26.0.";
208 }
209 if (time_lower_range <= 0.0) {
210 LOG(FATAL) << "In selection_parameters time_lower_range <= 0.0. Value should always be positive, in ns.";
211 }
212 if (time_upper_range <= 0.0) {
213 LOG(FATAL) << "In selection_parameters time_upper_range <= 0.0. Value should always be positive, in ns.";
214 }
215
216 auto filteredHits = std::make_unique<TClonesArray>("sndScifiHit", digiHits.GetEntries());
217
218 float peakTiming = -1.0;
219
220 float timeConversion = 1.;
221 if (!isMC) {
222 timeConversion = 1E9 / (ShipUnit::snd_freq / ShipUnit::hertz);
223 }
224
225 if (make_selection) {
226
227 auto selectedHits = getScifiHits(digiHits, station, orientation);
228
229 peakTiming = peakScifiTiming(*selectedHits, bins_x, min_x, max_x, isMC);
230
231 int i = 0;
232 for (auto *p : *selectedHits) {
233 auto *hit = dynamic_cast<sndScifiHit *>(p);
234 if (!validateHit(hit, station, orientation)) {
235 continue;
236 }
237 if ((peakTiming - time_lower_range > hit->GetTime() * timeConversion) ||
238 (hit->GetTime() * timeConversion > peakTiming + time_upper_range)) {
239 continue;
240 }
241 new ((*filteredHits)[i++]) sndScifiHit(*hit);
242 }
243
244 } else {
245 // Does not create selectedHits and just uses digiHits (not unique_ptr)
246
247 peakTiming = peakScifiTiming(digiHits, bins_x, min_x, max_x, isMC);
248
249 int i = 0;
250 for (auto *p : digiHits) {
251 auto *hit = dynamic_cast<sndScifiHit *>(p);
252 if (!validateHit(hit, station, orientation)) {
253 continue;
254 }
255 if ((peakTiming - time_lower_range > hit->GetTime() * timeConversion) ||
256 (hit->GetTime() * timeConversion > peakTiming + time_upper_range)) {
257 continue;
258 }
259 new ((*filteredHits)[i++]) sndScifiHit(*hit);
260 }
261 }
262
263 return filteredHits;
264}
float peakScifiTiming(const TClonesArray &digiHits, int bins, float min_x, float max_x, bool isMC=false)
std::unique_ptr< TClonesArray > getScifiHits(const TClonesArray &digiHits, int station, bool orientation)

◆ showerInteractionWall() [1/2]

int snd::analysis_tools::showerInteractionWall ( const TClonesArray &  digiHits,
const std::map< std::string, float > &  selection_parameters,
int  method = 0,
std::string  setup = "TI18" 
)

Definition at line 489 of file sndSciFiTools.cxx.

492{
493
494 int totalScifiStations = 5;
495 if (setup == "H8") {
496 totalScifiStations = 4;
497 } else {
498 LOG(info) << "\"TI18\" setup will be used by default, please provide \"H8\" for the Testbeam setup.";
499 }
500
501 // There is always 1 more Scifi Station than a target block. As such, showerStart == totalScifiStations
502 // means that the shower did not start developing in the target, before the last Scifi Station
503 int showerStart = totalScifiStations;
504
505 if (method == 0) {
506
507 if ((selection_parameters.find("radius") == selection_parameters.end()) ||
508 (selection_parameters.find("min_hit_density") == selection_parameters.end())) {
509 LOG(FATAL)
510 << "Argument of select_parameters is incorrect. Please provide a map with the arguments \"radius\" and "
511 "\"min_hit_density\". Consider using the default values of {{\"radius\",64}, {\"min_hit_density\",36}}.";
512 }
513
514 for (int scifiStation = 1; scifiStation <= totalScifiStations; scifiStation++) {
515
516 // For each ScifiStation we check whether we see clusters with the desired parameters
517 // By default, we require passing the check on both the horizontal and vertical mats
518 // In case selection_parameters["orientation"] was provided, we set the NOT CHOSEN orientation
519 // as true by default, so as to only need to pass the chosen orientation check
520 bool horizontalCheck = false;
521 bool verticalCheck = false;
522 if (selection_parameters.find("orientation") != selection_parameters.end()) {
523 if (int(selection_parameters.at("orientation")) == 0) {
524 verticalCheck = true;
525 }
526 if (int(selection_parameters.at("orientation")) == 1) {
527 horizontalCheck = true;
528 }
529 }
530 horizontalCheck = (densityCheck(digiHits, int(selection_parameters.at("radius")),
531 int(selection_parameters.at("min_hit_density")), scifiStation, false) ||
532 horizontalCheck);
533 verticalCheck = (densityCheck(digiHits, int(selection_parameters.at("radius")),
534 int(selection_parameters.at("min_hit_density")), scifiStation, true) ||
535 verticalCheck);
536 if ((horizontalCheck) && (verticalCheck)) {
537 showerStart = scifiStation - 1;
538 return showerStart;
539 }
540 }
541 }
542
543 return showerStart;
544}
bool densityCheck(const TClonesArray &digiHits, int radius=64, int min_hit_density=36, int station=1, bool orientation=false)

◆ showerInteractionWall() [2/2]

int snd::analysis_tools::showerInteractionWall ( const TClonesArray &  digiHits,
int  method = 0,
std::string  setup = "TI18" 
)

Definition at line 546 of file sndSciFiTools.cxx.

547{
548
549 if (method != 0) {
550 LOG(FATAL) << "Please use method=0. No other methods implemented so far.";
551 }
552
553 std::map<std::string, float> selection_parameters = {{"radius", 64.}, {"min_hit_density", 36.}};
554
555 return showerInteractionWall(digiHits, selection_parameters, method, setup);
556}
int showerInteractionWall(const TClonesArray &digiHits, const std::map< std::string, float > &selection_parameters, int method=0, std::string setup="TI18")