BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
HeaderAnalysis.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSOutputROOTEventHeader.hh"
19#include "Header.hh"
20#include "HeaderAnalysis.hh"
21
22#include "TChain.h"
23#include "TFile.h"
24#include "TTree.h"
25
26#include <set>
27#include <stdexcept>
28#include <string>
29#include <vector>
30
31HeaderAnalysis::HeaderAnalysis(const std::vector<std::string>& filenamesIn,
32 Header* headerIn,
33 TChain* chainIn):
34 filenames(filenamesIn),
35 header(headerIn),
36 chain(chainIn)
37{;}
38
39HeaderAnalysis::~HeaderAnalysis() noexcept
40{;}
41
42unsigned long long int HeaderAnalysis::CountNOriginalEvents(unsigned long long int& nEventsInFileIn,
43 unsigned long long int& nEventsInFileSkippedIn,
44 unsigned long long int& nEventsRequestedIn,
45 unsigned int& distrFileLoopNTimesIn)
46{
47 unsigned long long int nOriginalEvents = 0;
48 nEventsInFileIn = 0;
49 nEventsInFileSkippedIn = 0;
50 nEventsRequestedIn = 0;
51 distrFileLoopNTimesIn = 0;
52
53 for (const auto& fn : filenames)
54 {
55 TFile* ft = nullptr;
56 try
57 {ft = new TFile(fn.c_str(), "READ");}
58 catch (const std::exception& e)
59 {continue;}
60 if (ft->IsZombie())
61 {
62 delete ft;
63 continue;
64 }
65 Header* ha = new Header();
66 TTree* ht = dynamic_cast<TTree*>(ft->Get("Header"));
67 if (!ht)
68 {
69 delete ft;
70 continue;
71 }
72 ha->SetBranchAddress(ht);
73 ht->GetEntry(ht->GetEntries()-1); // get the last entry
74
75 nOriginalEvents += ha->header->nOriginalEvents;
76 nEventsInFileIn += ha->header->nEventsInFile;
77 nEventsInFileSkippedIn += ha->header->nEventsInFileSkipped;
78 nEventsRequestedIn += ha->header->nEventsRequested;
79 distrFileLoopNTimesIn += ha->header->distrFileLoopNTimes;
80 ft->Close();
81 delete ft;
82 delete ha;
83 }
84 return nOriginalEvents;
85}
unsigned long long int nEventsRequested
Number of events requested to be simulated from the file.
unsigned int distrFileLoopNTimes
Number of times a distribution file was replayed.
unsigned long long int nEventsInFileSkipped
Number of events from distribution file that were skipped due to filters.
unsigned long long int nOriginalEvents
Number of original events if skimmed.
unsigned long long int nEventsInFile
Number of events in the input distribution file irrespective of filters.
unsigned long long int CountNOriginalEvents(unsigned long long int &nEventsInFileIn, unsigned long long int &nEventsInFileSkippedIn, unsigned long long int &nEventsRequestedIn, unsigned int &distrFileLoopNTimesIn)
HeaderAnalysis(const std::vector< std::string > &filenamesIn, Header *headerIn, TChain *chainIn)
Constructor intended for use to construct a model analysis object.
Header loader.
Definition Header.hh:33
BDSOutputROOTEventHeader * header
Member that ROOT can map file data to locally.
Definition Header.hh:43
void SetBranchAddress(TTree *t)
Set the branch addresses to address the contents of the file.
Definition Header.cc:40