BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
rebdsimOrbit.cc
Go to the documentation of this file.
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*/
22#include <iostream>
23#include <string>
24
25#include "DataLoader.hh"
26#include "EventAnalysisOrbit.hh"
27#include "RBDSException.hh"
28
29#include "BDSOutputROOTEventHeader.hh"
30
31#include "TFile.h"
32#include "TTree.h"
33
34void usage()
35{
36 std::cout << "usage: rebdsimOrbit <dataFile> <outputfile> <index>" << std::endl;
37 std::cout << " <datafile> - root file to operate on ie run1.root" << std::endl;
38 std::cout << " <outputfile> - name of output file ie optics.root" << std::endl;
39 std::cout << " <index> - index of orbit to pull from file (default 1)" << std::endl;
40 std::cout << "This only works on a single file - no wildcards." << std::endl;
41}
42
43int main(int argc, char* argv[])
44{
45 if (argc < 3 || argc >= 5)
46 {
47 usage();
48 return 1;
49 }
50
51 std::string inputFileName = std::string(argv[1]);
52 std::string outputFileName = std::string(argv[2]);
53 int index = 0;
54 try
55 {
56 if (argc == 4)
57 {index = std::stoi(argv[3]);}
58
59 DataLoader dl = DataLoader(inputFileName, false, true, true);
60 EventAnalysisOrbit* evtAnalysis = new EventAnalysisOrbit(dl.GetEvent(),
61 dl.GetEventTree(),
62 true, true);
63 evtAnalysis->ExtractOrbit(index);
64
65 TFile* outputFile = new TFile(outputFileName.c_str(), "RECREATE");
66
67 // add header for file type and version details
68 outputFile->cd();
70 headerOut->Fill(dl.GetFileNames()); // updates time stamp
71 headerOut->SetFileType("REBDSIM");
72 TTree* headerTree = new TTree("Header", "REBDSIM Header");
73 headerTree->Branch("Header.", "BDSOutputROOTEventHeader", headerOut);
74 headerTree->Fill();
75 headerTree->Write();
76
77 evtAnalysis->WriteOrbit(outputFile);
78 outputFile->Close();
79 std::cout << "Result written to: " << outputFileName << std::endl;
80 delete outputFile;
81 delete evtAnalysis;
82 }
83 catch (const RBDSException& error)
84 {std::cerr << error.what() << std::endl; return 1;}
85 catch (const std::exception& error)
86 {std::cerr << error.what() << std::endl; return 1;}
87
88 return 0;
89}
Information about the software and the file.
void SetFileType(const std::string &fileTypeIn)
Update the file type.
void Fill(const std::vector< std::string > &analysedFilesIn=std::vector< std::string >(), const std::vector< std::string > &combinedFilesIn=std::vector< std::string >())
Loader for a ROOT file using classes used to generate the file.
Definition DataLoader.hh:46
std::vector< std::string > GetFileNames()
Accessor.
Definition DataLoader.hh:81
Event * GetEvent()
Accessor.
Definition DataLoader.hh:93
TChain * GetEventTree()
Accessor.
Simple analysis to pull out first hit in each sampler.
void ExtractOrbit(int index)
Extract an orbit from the data.
void WriteOrbit(TFile *f)
Write orbit to a ROOT file.
General exception with possible name of object and message.
const char * what() const noexcept override
Override message in std::exception.