Compare commits

..

11 Commits

47 changed files with 726 additions and 967 deletions

2
.gitignore vendored
View File

@ -4,6 +4,7 @@ images/
build/ build/
objs/ objs/
.vscode/ .vscode/
lib/
###file types to ignore### ###file types to ignore###
*.swp *.swp
@ -19,6 +20,7 @@ objs/
*.sublime-project *.sublime-project
*.sublime-workspace *.sublime-workspace
*.make *.make
*.yaml
Makefile Makefile
event_log.txt event_log.txt
.DS_Store .DS_Store

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "vendor/spdlog"] [submodule "vendor/spdlog"]
path = vendor/spdlog path = vendor/spdlog
url = https://github.com/gabime/spdlog.git url = https://github.com/gabime/spdlog.git
[submodule "vendor/yaml-cpp"]
path = vendor/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git

View File

@ -17,4 +17,5 @@ find_package(ROOT REQUIRED COMPONENTS Gui)
set(EVB_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin) set(EVB_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(EVB_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib) set(EVB_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_subdirectory(vendor/yaml-cpp)
add_subdirectory(src) add_subdirectory(src)

View File

@ -1,7 +1,7 @@
# SPS-SABRE Data Analysis Package # SPS-SABRE Data Analysis Package
Version 4 Version 4
This is a software package designed to help experimenters analyze data from SPS-SABRE at FSU. This is a software package designed to help experimenters analyze data from SPS-SABRE at FSU.
It can convert CoMPASS data to ROOT, sort the data in time, build events, perform preliminary analysis and provide basic plots. It can convert CoMPASS data to ROOT, sort the data in time, build events, perform preliminary analysis, and provide basic plots.
## Installation ## Installation
To build and install the event builder, the CMake build system is used. To build, simply run the following commands from the SPS_SABRE_EventBuilder directory: To build and install the event builder, the CMake build system is used. To build, simply run the following commands from the SPS_SABRE_EventBuilder directory:
@ -14,82 +14,20 @@ make
To clone the repository use `git clone --recursive https://github.com/sesps/SPS_SABRE_EventBuilder.git`. The recursive flag is important; this tells github to pull all submodules associated with the repository. To clone the repository use `git clone --recursive https://github.com/sesps/SPS_SABRE_EventBuilder.git`. The recursive flag is important; this tells github to pull all submodules associated with the repository.
The binaries are installed to the `bin` directory of the event builder, and should be run from the event builder directory (i.e. `./bin/EventBuilderGui`). The binaries are installed to the `bin` directory of the event builder, and should be run from the event builder directory (i.e. `./bin/EventBuilderGui`). THe `bin` directory also contains a shell script named `archivist` for transferring data from a CoMPASS project to the
event builder workspace.
In general, one should only build for Release (this is the default), for maximum optimization. However, it can be useful to run in Debug (change the cmake command to `cmake -DCMAKE_BUILD_TYPE=Debug ..`) when testing new features. In general, one should only build for Release (this is the default), for maximum optimization. However, it can be useful to run in Debug (change the cmake command to `cmake -DCMAKE_BUILD_TYPE=Debug ..`) when testing new features.
## EventBuilder vs. EventBuilderGui ## EventBuilder vs. EventBuilderGui
There are two programs provided. They are `EventBuilderGui` and `EventBuilder`. The first is a full GUI version of the event builder. The GUI supports all conversion methods and the plotting tool. There are two programs provided. They are `EventBuilderGui` and `EventBuilder`. The first is a full GUI version of the event builder. The GUI supports all conversion methods and the plotting tool.
### Building Events ## Details
The event building operation is the bulk of the analysis process. As files are being converted to ROOT from the raw CoMPASS binary, events are built using information given by the user. For more information see the [wiki](https://github.com/sesps/SPS_SABRE_EventBuilder/wiki), which describes the app in much more detail.
Additionally, check the [FAQ](https://github.com/sesps/SPS_SABRE_EventBuilder/wiki/FAQ) if you're having trouble with something.
#### Types of Event Building
1. Convert: simply sends data from CoMPASS format to ROOT format and time orders the data.
2. Slow Events: This perfoms the event building of slow events and then analyzes the slow data. Note that in this option, if there are unresolved multiplicities in data, the analyzer assumes the earliest datum is relevant one.
3. Fast Events: This performs the event building of fast events, assuming that slow event data has already been created and EXISTS in the proper directory. The fast event data is then analyzed.
4. Analyze Slow Events: This performs analysis of slow event data, without performing any fast sorting.
5. Analyze Fast Events: This performs analysis of fast event data.
#### Slow Sorting
The first stage is slow sorting the shifted data by timestamp and orgainizing detector hits into
large data events. Events are structures which contain all detector hits that occur within a given coincidence window with physical detector variables. This event data is then written to an output file. The goal of the slow sorting is to be as general as possible; slow sorting should change very little on a data set to data set basis, as this coincidence window is limited mostly be the time difference between an anode hit and the maximum delay line time if the correct shifts are applied to SABRE and the scintillator.
#### Fast Sorting
This is basically a secondary tier of event building, that is more user specific. It breaks down
data within the coincidence window into single focal plane events with asscoiated SABRE data. The
principle is that the scintillator provides very sharp timing resolution by which we can further
refine the built event. Currently, `FastSort` is desinged to take two windows: a coincidence window
for SABRE and the scintillator, and a coincidence window for the ion chamber and the scintillator.
For the ion chamber, the back anode was chosen to be the representative (it really doesn't matter
which part of the ion chamber is chosen). SABRE data is additionally filtered to contain only paired
hits (hits that have both a ring and a wedge). Fast sorting is where the user will have to make the
most changes to the actual event building. Any new detector or additional changes will require more
coincidence definitions and sorting depth.
#### Analyzing
Finally, the sorted event data is then converted into meaningful physical data, and saved to a
final analyzed file. This is where the digitizer parameters (charge/energy, time, etc.) are converted
into the actual paramters of interest such as focal plane position, SABRE energy, etc. In this way,
each raw data file gives four output files from the analysis: a shifted file, a slow sorted file,
a fast sorted file, and an analyzed file. The rationale behind the repetative writting is that
it helps the user isolate at which stage data issues occur at; this is especially useful for the
shifting and sorting stages, where the values for the shifts and coincidence window have to be
estimated by the user before running.
All of the user input is handled through an input file in the program directory named
`input.txt`. This file is preformated; all the user needs to do is update the names and
values. Everything from input and output directories, to shifts and coincidence windows should
be specified in this file. Note that directorires should be explicit fullpaths.
See the Plotter section for advice on which histograms are useful for choosing the correct shifts
and window sizes for the data set.
### Merging
The program is capable of merging several root files together using either `hadd` or the ROOT TChain class. Currently, only the TChain version is implemented in the API, however if you want the other method, it does exist in the RunCollector class.
### Plotting
The plotting is intended to be the final leg of the analysis pipeline. The goal of this program
is to take a collection of analyzed files and produce a file containing relevant histograms,
graphs, and other such data measures. As it is currently built, this program has no ability to
save any data of its own, it merely makes data measures. It is a quick and dirty analysis, and is not intended to be increased beyond merely checking some TCutGs and making some histograms. Cuts can be applied using a cut list. The cut list should contain a name for the cut, the name of the file containing the TCutG ROOT object (named CUTG), and then names for the x and y variables. The x and y variables must be initialized in the variable map. By default x1, x2, xavg, scintLeft, anodeBack, and cathode are all initialized. Any other variables will have to be added by the user by modifiying the CutHandler::InitVariableMap() function.
#### Determining Shifts and Windows
The plotting already provides most of the histograms one would need to determine the shifts and windows
for a data set. These, in general, come from plots of the relative time of various components of the
detector. The goal of the scintillator and si shifts are to make them occur in coincidence with the
anode (pick one of the focal plane anodes, they occur at essentially the same time). Included automatically are plots of the back anode relative to the scintillator (anodeB.Time-scintL.Time, gives scint offset), the is relative to the scint (SABRE fronts and backs... pick higher res one to make offsets and shifts), and maximum delay times relative to scint for both lines.
The method is the following:
Using the anode relative to the scint, one can determine the scint offset (center the peak on 0). Then,
by looking at the SABRE relative to scint plots one can determine the shift for si and the fast window
size (again center the peak on 0, the width of the peak becomes the fast window). Finally, if everything goes according to plan, now the maximum size of the slow coincidence window will be the relative time of the maximum delay line signal. Look at the plot of this and determine where you want to cut off. Run it again and check the results. You should look for, in general, reduced background and noise along with correct centering of the timing peaks.
### Scaler Support
Currently the pipeline supports declaring individual digitizer channels as scalers. These channels will be used a pure counting measures. To make a channel a scaler, put the CoMPASS formated name of the channel and board (check the given etc/ScalerFile.txt for an example) in a text file along with a parameter name for the scaler to be saved as. These files are then processed outside of the event building loop, which can greatly increase the computational speed. Future versions will include scaler rates as well.
## System Requirements ## System Requirements
- Requires ROOT >= 6.22.04 for C++17 support - Requires C++17
- Requires CMake > 3.16 for pch suport - Requires ROOT version which supports CMake dictionary generation and is C++17 compatible
- This version is for data from CAEN CoMPASS > 2.0. Data from older CoMPASS versions are not compatible. - Requires CMake >= 3.16
- This version is for data from CAEN CoMPASS >= 2.0. Data from older CoMPASS versions are not compatible.

View File

@ -1,4 +1,3 @@
Format: scaler_param_name assoc_binary_file_name_without_runID Format: scaler_param_name assoc_binary_file_name_without_runID
NOTE: As of this version, scalers are pure counting parameters (the total events will be counted and saved as a TParameter with the data) NOTE: As of this version, scalers are pure counting parameters (the total events will be counted and saved as a TParameter with the data)
CH0@V1730_89_Data t1 Data_CH5@V1730_89 beamint
CH5@V1730_89_Data t2

2
example/.gitignore vendored
View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

Binary file not shown.

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

Binary file not shown.

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,2 +0,0 @@
###Keep this dir###
!.gitignore

View File

@ -1,27 +0,0 @@
-------Data Location----------
WorkspaceDirectory: /media/gordon/GordonData/gwm17/9BFeb2021
-------------------------------
------Experimental Inputs------
ChannelMapFile: /home/gordon/SPS_SABRE_EventBuilder/etc/ChannelMap_Feb2021_SABRE.txt
ScalerFile: /home/gordon/SPS_SABRE_EventBuilder/etc/ScalerFile_Feb2021_SABRE.txt
CutListFile: /home/gordon/SPS_SABRE_EventBuilder/etc/CutList_Feb2021_10B3hea.txt
ZT: 5
AT: 10
ZP: 2
AP: 3
ZE: 2
AE: 4
BField(G): 8925
BeamKE(MeV): 24
Theta(deg): 15
-------------------------------
-------Timing Information------
BoardOffsetFile: /home/gordon/SPS_SABRE_EventBuilder/etc/ShiftMap_Feb2021_SABRE.txt
SlowCoincidenceWindow(ps): 1.5e+06
FastCoincidenceWindow_IonCh(ps): 250000
FastCoincidenceWindow_SABRE(ps): 150000
-------------------------------
--------Run Information--------
MinRun: 99
MaxRun: 99
-------------------------------

View File

@ -1,6 +1,6 @@
add_subdirectory(spsdict) add_subdirectory(spsdict)
add_subdirectory(guidict)
add_subdirectory(evb) add_subdirectory(evb)
add_subdirectory(guidict)
add_executable(EventBuilder) add_executable(EventBuilder)

View File

@ -11,7 +11,6 @@
#include <iomanip> #include <iomanip>
#include <cstdint> #include <cstdint>
//ROOT //ROOT
#include <TROOT.h> #include <TROOT.h>
#include <TFile.h> #include <TFile.h>

View File

@ -1,6 +1,10 @@
add_library(EventBuilderCore STATIC) add_library(EventBuilderCore STATIC)
target_include_directories(EventBuilderCore SYSTEM PUBLIC ../../vendor/spdlog/include ${ROOT_INCLUDE_DIRS} target_include_directories(EventBuilderCore
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../ SYSTEM PUBLIC ../../vendor/spdlog/include
${ROOT_INCLUDE_DIRS}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../
../vendor/yaml-cpp/include/
) )
target_precompile_headers(EventBuilderCore PRIVATE ../EventBuilder.h) target_precompile_headers(EventBuilderCore PRIVATE ../EventBuilder.h)
@ -30,23 +34,27 @@ target_sources(EventBuilderCore PRIVATE
CompassFile.h CompassFile.h
EVBApp.h EVBApp.h
Logger.cpp Logger.cpp
RunCollector.cpp
ShiftMap.h ShiftMap.h
CompassHit.h CompassHit.h
FastSort.cpp FastSort.cpp
Logger.h Logger.h
RunCollector.h
SlowSort.cpp SlowSort.cpp
CompassRun.cpp CompassRun.cpp
FastSort.h FastSort.h
MassLookup.cpp MassLookup.cpp
SFPAnalyzer.cpp SFPAnalyzer.cpp
SlowSort.h SlowSort.h
EVBWorkspace.cpp
EVBWorkspace.h
EVBParameters.h
) )
target_link_libraries(EventBuilderCore PUBLIC target_link_libraries(EventBuilderCore PUBLIC
SPSDict SPSDict
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
yaml-cpp
) )
set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR}) set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR})
target_compile_definitions(EventBuilderCore PRIVATE YAML_CPP_STATIC_DEFINE)

View File

@ -6,7 +6,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "ChannelMap.h" #include "ChannelMap.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -8,7 +8,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "CompassFile.h" #include "CompassFile.h"
namespace EventBuilder { namespace EventBuilder {
@ -44,7 +43,6 @@ namespace EventBuilder {
m_hitUsedFlag = true; m_hitUsedFlag = true;
m_filename = filename; m_filename = filename;
m_file->open(m_filename, std::ios::binary | std::ios::in); m_file->open(m_filename, std::ios::binary | std::ios::in);
m_file->seekg(0, std::ios_base::end); m_file->seekg(0, std::ios_base::end);
m_size = m_file->tellg(); m_size = m_file->tellg();
if(m_size == 2) if(m_size == 2)

View File

@ -35,7 +35,6 @@ namespace EventBuilder {
inline bool CheckHitHasBeenUsed() const { return m_hitUsedFlag; } //query to find out if we've used the current hit inline bool CheckHitHasBeenUsed() const { return m_hitUsedFlag; } //query to find out if we've used the current hit
inline void SetHitHasBeenUsed() { m_hitUsedFlag = true; } //flip the flag to indicate the current hit has been used inline void SetHitHasBeenUsed() { m_hitUsedFlag = true; } //flip the flag to indicate the current hit has been used
inline bool IsEOF() const { return m_eofFlag; } //see if we've read all available data inline bool IsEOF() const { return m_eofFlag; } //see if we've read all available data
inline bool* GetUsedFlagPtr() { return &m_hitUsedFlag; }
inline void AttachShiftMap(ShiftMap* map) { m_smap = map; } inline void AttachShiftMap(ShiftMap* map) { m_smap = map; }
inline unsigned int GetSize() const { return m_size; } inline unsigned int GetSize() const { return m_size; }
inline unsigned int GetNumberOfHits() const { return m_nHits; } inline unsigned int GetNumberOfHits() const { return m_nHits; }

View File

@ -9,25 +9,19 @@
Updated to also handle scaler data. -- GWM Oct. 2020 Updated to also handle scaler data. -- GWM Oct. 2020
*/ */
#include "EventBuilder.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "RunCollector.h"
#include "SlowSort.h" #include "SlowSort.h"
#include "FastSort.h" #include "FastSort.h"
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
#include "FlagHandler.h" #include "FlagHandler.h"
#include "EVBApp.h"
namespace EventBuilder { namespace EventBuilder {
CompassRun::CompassRun() : CompassRun::CompassRun(const EVBParameters& params, const std::shared_ptr<EVBWorkspace>& workspace) :
m_directory(""), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_progressFraction(0.1) m_params(params), m_workspace(workspace)
{ {
} m_smap.SetFile(m_params.timeShiftFile);
CompassRun::CompassRun(const std::string& dir) :
m_directory(dir), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_progressFraction(0.1)
{
} }
CompassRun::~CompassRun() {} CompassRun::~CompassRun() {}
@ -36,7 +30,7 @@ namespace EventBuilder {
/*Load em into a map*/ /*Load em into a map*/
void CompassRun::SetScalers() void CompassRun::SetScalers()
{ {
std::ifstream input(m_scalerinput); std::ifstream input(m_params.scalerFile);
if(!input.is_open()) if(!input.is_open())
return; return;
@ -49,7 +43,7 @@ namespace EventBuilder {
while(input>>filename) while(input>>filename)
{ {
input>>varname; input>>varname;
filename = m_directory+filename+"_run_"+std::to_string(m_runNum)+".BIN"; filename = m_workspace->GetTempDir()+filename+"_run_"+std::to_string(m_runNum)+".BIN";
m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init); m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init);
} }
input.close(); input.close();
@ -57,17 +51,14 @@ namespace EventBuilder {
bool CompassRun::GetBinaryFiles() bool CompassRun::GetBinaryFiles()
{ {
std::string prefix = ""; auto files = m_workspace->GetTempFiles();
std::string suffix = ".BIN"; //binaries
RunCollector grabber(m_directory, prefix, suffix);
grabber.GrabAllFiles();
m_datafiles.clear(); //so that the CompassRun can be reused m_datafiles.clear(); //so that the CompassRun can be reused
m_datafiles.reserve(grabber.GetFileList().size()); m_datafiles.reserve(files.size()); //NOTE: This line is mandatory. We need the memory preallocated to avoid any move semantics with the filestreams.
bool scalerd; bool scalerd;
m_totalHits = 0; //reset total run size m_totalHits = 0; //reset total run size
for(auto& entry : grabber.GetFileList()) for(auto& entry : files)
{ {
//Handle scaler files, if they exist //Handle scaler files, if they exist
if(m_scaler_flag) if(m_scaler_flag)
@ -123,42 +114,35 @@ namespace EventBuilder {
/* /*
GetHitsFromFiles() is the function which actually retrieves and sorts the data from the individual GetHitsFromFiles() is the function which actually retrieves and sorts the data from the individual
files. There are several tricks which allow this to happen. First is that, after sorting, it is impossible files. Once a file has gone EOF, we no longer need it. If this is the first file in the list, we can just skip
to determine which file the data originally came from (short of parsing the name of the file against board/channel).
However, we need to let the file know that we want it to pull the next hit. To do this, a pointer to the UsedFlag of the file
is retrieved along with the data. This flag is flipped so that on the next hit cycle a new hit is pulled. Second is the use
of a rolling start index. Once a file has gone EOF, we no longer need it. If this is the first file in the list, we can just skip
that index all together. In this way, the loop can go from N times to N-1 times. that index all together. In this way, the loop can go from N times to N-1 times.
*/ */
bool CompassRun::GetHitsFromFiles() bool CompassRun::GetHitsFromFiles()
{ {
std::pair<CompassHit, bool*> earliestHit = std::make_pair(CompassHit(), nullptr); //std::pair<CompassHit, bool*> earliestHit = std::make_pair(CompassHit(), nullptr);
CompassFile* earliestHit = nullptr;
for(unsigned int i=startIndex; i<m_datafiles.size(); i++) for(unsigned int i=startIndex; i<m_datafiles.size(); i++)
{ {
if(m_datafiles[i].CheckHitHasBeenUsed()) if(m_datafiles[i].CheckHitHasBeenUsed())
m_datafiles[i].GetNextHit(); m_datafiles[i].GetNextHit();
if(m_datafiles[i].IsEOF()) if(m_datafiles[i].IsEOF())
{ {
if(i == startIndex) if(i == startIndex)
startIndex++; startIndex++;
continue; continue;
}
else if(i == startIndex)
{
earliestHit = std::make_pair(m_datafiles[i].GetCurrentHit(), m_datafiles[i].GetUsedFlagPtr());
}
else if(m_datafiles[i].GetCurrentHit().timestamp < earliestHit.first.timestamp)
{
earliestHit = std::make_pair(m_datafiles[i].GetCurrentHit(), m_datafiles[i].GetUsedFlagPtr());
} }
else if(i == startIndex) //start with first in the list
earliestHit = &m_datafiles[i];
else if(m_datafiles[i].GetCurrentHit().timestamp < earliestHit->GetCurrentHit().timestamp) //if earlier
earliestHit = &m_datafiles[i];
} }
if(earliestHit.second == nullptr) if(earliestHit == nullptr)
return false; //Make sure that there actually was a hit return false; //Make sure that there actually was a hit
hit = earliestHit.first; m_hit = earliestHit->GetCurrentHit();
*earliestHit.second = true; earliestHit->SetHitHasBeenUsed();
return true; return true;
} }
@ -166,12 +150,12 @@ namespace EventBuilder {
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("Data", "Data"); TTree* outtree = new TTree("Data", "Data");
outtree->Branch("Board", &hit.board); outtree->Branch("Board", &m_hit.board);
outtree->Branch("Channel", &hit.channel); outtree->Branch("Channel", &m_hit.channel);
outtree->Branch("Energy", &hit.energy); outtree->Branch("Energy", &m_hit.energy);
outtree->Branch("EnergyShort", &hit.energyShort); outtree->Branch("EnergyShort", &m_hit.energyShort);
outtree->Branch("Timestamp", &hit.timestamp); outtree->Branch("Timestamp", &m_hit.timestamp);
outtree->Branch("Flags", &hit.flags); outtree->Branch("Flags", &m_hit.flags);
if(!m_smap.IsValid()) if(!m_smap.IsValid())
{ {
@ -214,11 +198,12 @@ namespace EventBuilder {
output->Close(); output->Close();
} }
void CompassRun::Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window) void CompassRun::Convert2SortedRoot(const std::string& name)
{ {
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SortTree", "SortTree"); TTree* outtree = new TTree("SortTree", "SortTree");
CoincEvent event;
outtree->Branch("event", &event); outtree->Branch("event", &event);
if(!m_smap.IsValid()) if(!m_smap.IsValid())
@ -237,7 +222,7 @@ namespace EventBuilder {
unsigned int count = 0, flush = m_totalHits*m_progressFraction, flush_count = 0; unsigned int count = 0, flush = m_totalHits*m_progressFraction, flush_count = 0;
startIndex = 0; startIndex = 0;
SlowSort coincidizer(window, mapfile); SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile);
bool killFlag = false; bool killFlag = false;
if(flush == 0) if(flush == 0)
flush = 1; flush = 1;
@ -257,13 +242,14 @@ namespace EventBuilder {
killFlag = true; killFlag = true;
} }
else else
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(m_hit);
if(coincidizer.IsEventReady()) if(coincidizer.IsEventReady())
{ {
event = coincidizer.GetEvent(); event = coincidizer.GetEvent();
outtree->Fill(); outtree->Fill();
if(killFlag) break; if(killFlag)
break;
} }
} }
@ -276,11 +262,12 @@ namespace EventBuilder {
output->Close(); output->Close();
} }
void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window) void CompassRun::Convert2FastSortedRoot(const std::string& name)
{ {
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SortTree", "SortTree"); TTree* outtree = new TTree("SortTree", "SortTree");
CoincEvent event;
outtree->Branch("event", &event); outtree->Branch("event", &event);
if(!m_smap.IsValid()) if(!m_smap.IsValid())
@ -301,8 +288,8 @@ namespace EventBuilder {
startIndex = 0; startIndex = 0;
CoincEvent this_event; CoincEvent this_event;
std::vector<CoincEvent> fast_events; std::vector<CoincEvent> fast_events;
SlowSort coincidizer(window, mapfile); SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile);
FastSort speedyCoincidizer(fsi_window, fic_window); FastSort speedyCoincidizer(m_params.fastCoincidenceWindowSABRE, m_params.fastCoincidenceWindowIonCh);
FlagHandler flagger; FlagHandler flagger;
@ -326,8 +313,8 @@ namespace EventBuilder {
} }
else else
{ {
flagger.CheckFlag(hit.board, hit.channel, hit.flags); flagger.CheckFlag(m_hit.board, m_hit.channel, m_hit.flags);
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(m_hit);
} }
if(coincidizer.IsEventReady()) if(coincidizer.IsEventReady())
@ -355,13 +342,13 @@ namespace EventBuilder {
} }
void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name)
int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta)
{ {
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SPSTree", "SPSTree"); TTree* outtree = new TTree("SPSTree", "SPSTree");
ProcessedEvent pevent;
outtree->Branch("event", &pevent); outtree->Branch("event", &pevent);
if(!m_smap.IsValid()) if(!m_smap.IsValid())
@ -381,20 +368,20 @@ namespace EventBuilder {
startIndex = 0; startIndex = 0;
CoincEvent this_event; CoincEvent this_event;
SlowSort coincidizer(window, mapfile); SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile);
SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); SFPAnalyzer analyzer(m_params.ZT, m_params.AT, m_params.ZP, m_params.AP, m_params.ZE, m_params.AE, m_params.beamEnergy, m_params.spsAngle, m_params.BField);
std::vector<TParameter<Double_t>> parvec; std::vector<TParameter<Double_t>> parvec;
parvec.reserve(9); parvec.reserve(9);
parvec.emplace_back("ZT", zt); parvec.emplace_back("ZT", m_params.ZT);
parvec.emplace_back("AT", at); parvec.emplace_back("AT", m_params.AT);
parvec.emplace_back("ZP", zp); parvec.emplace_back("ZP", m_params.ZP);
parvec.emplace_back("AP", ap); parvec.emplace_back("AP", m_params.AP);
parvec.emplace_back("ZE", ze); parvec.emplace_back("ZE", m_params.ZE);
parvec.emplace_back("AE", ae); parvec.emplace_back("AE", m_params.AE);
parvec.emplace_back("Bfield", b); parvec.emplace_back("Bfield", m_params.BField);
parvec.emplace_back("BeamKE", bke); parvec.emplace_back("BeamKE", m_params.beamEnergy);
parvec.emplace_back("Theta", theta); parvec.emplace_back("Theta", m_params.spsAngle);
bool killFlag = false; bool killFlag = false;
if(flush == 0) if(flush == 0)
@ -416,7 +403,7 @@ namespace EventBuilder {
} }
else else
{ {
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(m_hit);
} }
if(coincidizer.IsEventReady()) if(coincidizer.IsEventReady())
@ -443,13 +430,13 @@ namespace EventBuilder {
output->Close(); output->Close();
} }
void CompassRun::Convert2FastAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window, void CompassRun::Convert2FastAnalyzedRoot(const std::string& name)
int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta)
{ {
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SPSTree", "SPSTree"); TTree* outtree = new TTree("SPSTree", "SPSTree");
ProcessedEvent pevent;
outtree->Branch("event", &pevent); outtree->Branch("event", &pevent);
if(!m_smap.IsValid()) if(!m_smap.IsValid())
@ -470,21 +457,21 @@ namespace EventBuilder {
startIndex = 0; startIndex = 0;
CoincEvent this_event; CoincEvent this_event;
std::vector<CoincEvent> fast_events; std::vector<CoincEvent> fast_events;
SlowSort coincidizer(window, mapfile); SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile);
FastSort speedyCoincidizer(fsi_window, fic_window); FastSort speedyCoincidizer(m_params.fastCoincidenceWindowSABRE, m_params.fastCoincidenceWindowIonCh);
SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); SFPAnalyzer analyzer(m_params.ZT, m_params.AT, m_params.ZP, m_params.AP, m_params.ZE, m_params.AE, m_params.beamEnergy, m_params.spsAngle, m_params.BField);
std::vector<TParameter<Double_t>> parvec; std::vector<TParameter<Double_t>> parvec;
parvec.reserve(9); parvec.reserve(9);
parvec.emplace_back("ZT", zt); parvec.emplace_back("ZT", m_params.ZT);
parvec.emplace_back("AT", at); parvec.emplace_back("AT", m_params.AT);
parvec.emplace_back("ZP", zp); parvec.emplace_back("ZP", m_params.ZP);
parvec.emplace_back("AP", ap); parvec.emplace_back("AP", m_params.AP);
parvec.emplace_back("ZE", ze); parvec.emplace_back("ZE", m_params.ZE);
parvec.emplace_back("AE", ae); parvec.emplace_back("AE", m_params.AE);
parvec.emplace_back("Bfield", b); parvec.emplace_back("Bfield", m_params.BField);
parvec.emplace_back("BeamKE", bke); parvec.emplace_back("BeamKE", m_params.beamEnergy);
parvec.emplace_back("Theta", theta); parvec.emplace_back("Theta", m_params.spsAngle);
FlagHandler flagger; FlagHandler flagger;
@ -508,8 +495,8 @@ namespace EventBuilder {
} }
else else
{ {
flagger.CheckFlag(hit.board, hit.channel, hit.flags); flagger.CheckFlag(m_hit.board, m_hit.channel, m_hit.flags);
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(m_hit);
} }
if(coincidizer.IsEventReady()) if(coincidizer.IsEventReady())

View File

@ -12,9 +12,10 @@
#include "CompassFile.h" #include "CompassFile.h"
#include "DataStructs.h" #include "DataStructs.h"
#include "RunCollector.h"
#include "ShiftMap.h" #include "ShiftMap.h"
#include "ProgressCallback.h" #include "ProgressCallback.h"
#include "EVBWorkspace.h"
#include "EVBParameters.h"
#include <TParameter.h> #include <TParameter.h>
namespace EventBuilder { namespace EventBuilder {
@ -23,20 +24,14 @@ namespace EventBuilder {
{ {
public: public:
CompassRun(); CompassRun(const EVBParameters& params, const std::shared_ptr<EVBWorkspace>& workspace);
CompassRun(const std::string& dir);
~CompassRun(); ~CompassRun();
inline void SetDirectory(const std::string& dir) { m_directory = dir; }
inline void SetScalerInput(const std::string& filename) { m_scalerinput = filename; }
inline void SetRunNumber(int n) { m_runNum = n; } inline void SetRunNumber(int n) { m_runNum = n; }
inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); }
void Convert2RawRoot(const std::string& name); void Convert2RawRoot(const std::string& name);
void Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window); void Convert2SortedRoot(const std::string& name);
void Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window); void Convert2FastSortedRoot(const std::string& name);
void Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, void Convert2SlowAnalyzedRoot(const std::string& name);
int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta); void Convert2FastAnalyzedRoot(const std::string& name);
void Convert2FastAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window,
int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta);
inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; } inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; }
inline void SetProgressFraction(double frac) { m_progressFraction = frac; } inline void SetProgressFraction(double frac) { m_progressFraction = frac; }
@ -46,17 +41,17 @@ namespace EventBuilder {
bool GetHitsFromFiles(); bool GetHitsFromFiles();
void SetScalers(); void SetScalers();
void ReadScalerData(const std::string& filename); void ReadScalerData(const std::string& filename);
EVBParameters m_params;
std::shared_ptr<EVBWorkspace> m_workspace;
std::string m_directory, m_scalerinput;
std::vector<CompassFile> m_datafiles; std::vector<CompassFile> m_datafiles;
unsigned int startIndex; //this is the file we start looking at; increases as we finish files. unsigned int startIndex; //this is the file we start looking at; increases as we finish files.
ShiftMap m_smap; ShiftMap m_smap;
std::unordered_map<std::string, TParameter<Long64_t>> m_scaler_map; //maps scaler files to the TParameter to be saved std::unordered_map<std::string, TParameter<Long64_t>> m_scaler_map; //maps scaler files to the TParameter to be saved
//Potential branch variables //Raw hit
CompassHit hit; CompassHit m_hit;
CoincEvent event;
ProcessedEvent pevent;
//what run is this //what run is this
int m_runNum; int m_runNum;

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "CutHandler.h" #include "CutHandler.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -6,22 +6,16 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include <cstdlib> #include <cstdlib>
#include "EVBApp.h" #include "EVBApp.h"
#include "RunCollector.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "SlowSort.h"
#include "FastSort.h"
#include "SFPAnalyzer.h"
#include "SFPPlotter.h" #include "SFPPlotter.h"
#include "yaml-cpp/yaml.h"
namespace EventBuilder { namespace EventBuilder {
EVBApp::EVBApp() : EVBApp::EVBApp() :
m_rmin(0), m_rmax(0), m_ZT(0), m_AT(0), m_ZP(0), m_AP(0), m_ZE(0), m_AE(0), m_ZR(0), m_AR(0), m_workspace(nullptr), m_progressFraction(0.1)
m_B(0), m_Theta(0), m_BKE(0), m_progressFraction(0.1), m_workspace("none"), m_mapfile("none"), m_shiftfile("none"),
m_cutList("none"), m_scalerfile("none"), m_SlowWindow(0), m_FastWindowIonCh(0), m_FastWindowSABRE(0)
{ {
SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBApp::DefaultProgressCallback)); SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBApp::DefaultProgressCallback));
} }
@ -36,48 +30,59 @@ namespace EventBuilder {
EVB_INFO("Percent of run built: {0}", fraction*100); EVB_INFO("Percent of run built: {0}", fraction*100);
} }
void EVBApp::SetParameters(const EVBParameters& params)
{
if(m_params.workspaceDir != params.workspaceDir)
{
m_workspace.reset(new EVBWorkspace(params.workspaceDir));
if(!m_workspace->IsValid())
EVB_ERROR("Unable to process new parameters due to bad workspace");
}
m_params = params;
}
bool EVBApp::ReadConfigFile(const std::string& fullpath) bool EVBApp::ReadConfigFile(const std::string& fullpath)
{ {
EVB_INFO("Reading in EVB configuration from file {0}...", fullpath); EVB_INFO("Reading in EVB configuration from file {0}...", fullpath);
std::ifstream input(fullpath); YAML::Node data;
if(!input.is_open()) try
{ {
EVB_WARN("Read of EVB config failed, unable to open input file!"); data = YAML::LoadFile(fullpath);
}
catch(YAML::ParserException& e)
{
EVB_ERROR("Read of EVB config failed, unable to open input file!");
return false; return false;
} }
std::string junk; m_params.workspaceDir = data["WorkspaceDir"].as<std::string>();
m_params.channelMapFile = data["ChannelMap"].as<std::string>();
std::getline(input, junk); m_params.scalerFile = data["ScalerFile"].as<std::string>();
input>>junk>>m_workspace; m_params.cutListFile = data["CutListFile"].as<std::string>();
input>>junk; m_params.timeShiftFile = data["TimeShiftFile"].as<std::string>();
std::getline(input, junk); m_params.slowCoincidenceWindow = data["SlowCoincidenceWindow(ps)"].as<double>();
std::getline(input, junk); m_params.fastCoincidenceWindowIonCh = data["FastCoincidenceWinowIonCh(ps)"].as<double>();
input>>junk>>m_mapfile; m_params.fastCoincidenceWindowSABRE = data["FastCoincidenceWinowSABRE(ps)"].as<double>();
input>>junk>>m_scalerfile; m_params.ZT = data["ZT"].as<int>();
input>>junk>>m_cutList; m_params.AT = data["AT"].as<int>();
input>>junk>>m_ZT>>junk>>m_AT; m_params.ZP = data["ZP"].as<int>();
input>>junk>>m_ZP>>junk>>m_AP; m_params.AP = data["AP"].as<int>();
input>>junk>>m_ZE>>junk>>m_AE; m_params.ZE = data["ZE"].as<int>();
input>>junk>>m_B; m_params.AE = data["AE"].as<int>();
input>>junk>>m_BKE; m_params.BField = data["BField(kG)"].as<double>();
input>>junk>>m_Theta; m_params.beamEnergy = data["BeamEnergy(MeV)"].as<double>();
input>>junk; m_params.spsAngle = data["SPSAngle(deg)"].as<double>();
std::getline(input, junk); m_params.runMin = data["MinRun"].as<int>();
std::getline(input, junk); m_params.runMax = data["MaxRun"].as<int>();
input>>junk>>m_shiftfile;
input>>junk>>m_SlowWindow;
input>>junk>>m_FastWindowIonCh;
input>>junk>>m_FastWindowSABRE;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_rmin;
input>>junk>>m_rmax;
input.close();
EVB_INFO("Successfully loaded EVB config."); EVB_INFO("Successfully loaded EVB config.");
m_workspace.reset(new EVBWorkspace(m_params.workspaceDir));
if(!m_workspace->IsValid())
{
EVB_ERROR("Unable to process input configuration due to bad workspace.");
return false;
}
return true; return true;
} }
@ -91,35 +96,32 @@ namespace EventBuilder {
EVB_WARN("Failed to write to config to file {0}, unable to open file!", fullpath); EVB_WARN("Failed to write to config to file {0}, unable to open file!", fullpath);
return; return;
} }
output<<"-------Data Location----------"<<std::endl; YAML::Emitter yamlStream;
output<<"WorkspaceDirectory: "<<m_workspace<<std::endl; yamlStream << YAML::BeginMap;
output<<"-------------------------------"<<std::endl; yamlStream << YAML::Key << "WorkspaceDir" << YAML::Value << m_params.workspaceDir;
output<<"------Experimental Inputs------"<<std::endl; yamlStream << YAML::Key << "ChannelMap" << YAML::Value << m_params.channelMapFile;
output<<"ChannelMapFile: "<<m_mapfile<<std::endl; yamlStream << YAML::Key << "ScalerFile" << YAML::Value << m_params.scalerFile;
output<<"ScalerFile: "<<m_scalerfile<<std::endl; yamlStream << YAML::Key << "CutListFile" << YAML::Value << m_params.cutListFile;
output<<"CutListFile: "<<m_cutList<<std::endl; yamlStream << YAML::Key << "TimeShiftFile" << YAML::Value << m_params.timeShiftFile;
output<<"ZT: "<<m_ZT<<std::endl; yamlStream << YAML::Key << "SlowCoincidenceWindow(ps)" << YAML::Value << m_params.slowCoincidenceWindow;
output<<"AT: "<<m_AT<<std::endl; yamlStream << YAML::Key << "FastCoincidenceWinowIonCh(ps)" << YAML::Value << m_params.fastCoincidenceWindowIonCh;
output<<"ZP: "<<m_ZP<<std::endl; yamlStream << YAML::Key << "FastCoincidenceWinowSABRE(ps)" << YAML::Value << m_params.fastCoincidenceWindowSABRE;
output<<"AP: "<<m_AP<<std::endl; yamlStream << YAML::Key << "ZT" << YAML::Value << m_params.ZT;
output<<"ZE: "<<m_ZE<<std::endl; yamlStream << YAML::Key << "AT" << YAML::Value << m_params.AT;
output<<"AE: "<<m_AE<<std::endl; yamlStream << YAML::Key << "ZP" << YAML::Value << m_params.ZP;
output<<"BField(G): "<<m_B<<std::endl; yamlStream << YAML::Key << "AP" << YAML::Value << m_params.AP;
output<<"BeamKE(MeV): "<<m_BKE<<std::endl; yamlStream << YAML::Key << "ZE" << YAML::Value << m_params.ZE;
output<<"Theta(deg): "<<m_Theta<<std::endl; yamlStream << YAML::Key << "AE" << YAML::Value << m_params.AE;
output<<"-------------------------------"<<std::endl; yamlStream << YAML::Key << "BField(kG)" << YAML::Value << m_params.BField;
output<<"-------Timing Information------"<<std::endl; yamlStream << YAML::Key << "BeamEnergy(MeV)" << YAML::Value << m_params.beamEnergy;
output<<"BoardOffsetFile: "<<m_shiftfile<<std::endl; yamlStream << YAML::Key << "SPSAngle(deg)" << YAML::Value << m_params.spsAngle;
output<<"SlowCoincidenceWindow(ps): "<<m_SlowWindow<<std::endl; yamlStream << YAML::Key << "MinRun" << YAML::Value << m_params.runMin;
output<<"FastCoincidenceWindow_IonCh(ps): "<<m_FastWindowIonCh<<std::endl; yamlStream << YAML::Key << "MaxRun" << YAML::Value << m_params.runMax;
output<<"FastCoincidenceWindow_SABRE(ps): "<<m_FastWindowSABRE<<std::endl; yamlStream << YAML::EndMap;
output<<"-------------------------------"<<std::endl;
output<<"--------Run Information--------"<<std::endl; output << yamlStream.c_str();
output<<"MinRun: "<<m_rmin<<std::endl;
output<<"MaxRun: "<<m_rmax<<std::endl;
output<<"-------------------------------"<<std::endl;
output.close(); output.close();
EVB_INFO("Successfully wrote config to file."); EVB_INFO("Successfully wrote config to file.");
@ -128,19 +130,23 @@ namespace EventBuilder {
void EVBApp::PlotHistograms() void EVBApp::PlotHistograms()
{ {
std::string analyze_dir = m_workspace+"/analyzed/"; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string plot_file = m_workspace+"/histograms/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root"; {
EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string plot_file = m_workspace->GetHistogramDir()+"run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root";
SFPPlotter grammer; SFPPlotter grammer;
grammer.SetProgressCallbackFunc(m_progressCallback); grammer.SetProgressCallbackFunc(m_progressCallback);
grammer.SetProgressFraction(m_progressFraction); grammer.SetProgressFraction(m_progressFraction);
grammer.ApplyCutlist(m_cutList); grammer.ApplyCutlist(m_params.cutListFile);
EVB_INFO("Generating histograms from analyzed runs [{0}, {1}] with Cut List {2}...", m_rmin, m_rmax, m_cutList); EVB_INFO("Generating histograms from analyzed runs [{0}, {1}] with Cut List {2}...", m_params.runMin, m_params.runMax, m_params.cutListFile);
EVB_INFO("Output file will be named {0}",plot_file); EVB_INFO("Output file will be named {0}",plot_file);
grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax); auto files = m_workspace->GetAnalyzedRunRange(m_params.runMin, m_params.runMax);
if(grabber.GrabFilesInRange()) if(files.size() > 0)
{ {
grammer.Run(grabber.GetFileList(), plot_file); grammer.Run(files, plot_file);
EVB_INFO("Finished."); EVB_INFO("Finished.");
} }
else else
@ -151,56 +157,56 @@ namespace EventBuilder {
void EVBApp::Convert2RawRoot() void EVBApp::Convert2RawRoot()
{ {
int sys_return; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string rawroot_dir = m_workspace+"/raw_root/"; {
std::string unpack_dir = m_workspace+"/temp_binary/"; EVB_ERROR("Unable to preform event building request due to bad workspace.");
std::string binary_dir = m_workspace+"/raw_binary/"; }
EVB_INFO("Converting binary archives to ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string rawroot_dir = m_workspace->GetSortedDir();
EVB_INFO("Converting binary archives to ROOT files over run range [{0}, {1}]", m_params.runMin, m_params.runMax);
grabber.SetSearchParams(binary_dir, "", ".tar.gz",0,1000); std::string rawfile;
std::string rawfile, binfile; CompassRun converter(m_params, m_workspace);
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
for(int i=m_rmin; i<=m_rmax; i++) int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...", binfile);
rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root"; rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; EVB_INFO("Converting file {0}...", rawfile);
wipe_command = "rm -r "+unpack_dir+"*.BIN"; m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
sys_return = system(unpack_command.c_str()); {
converter.Convert2RawRoot(rawfile); converter.SetRunNumber(i);
sys_return = system(wipe_command.c_str()); converter.Convert2RawRoot(rawfile);
++count;
}
m_workspace->ClearTempDirectory();
} }
EVB_INFO("Conversion complete.");
if(count != 0)
EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
void EVBApp::MergeROOTFiles() void EVBApp::MergeROOTFiles()
{ {
std::string merge_file = m_workspace+"/merged/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root"; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string file_dir = m_workspace+"/analyzed/";
EVB_INFO("Merging ROOT files into single file for runs in range [{0}, {1}]", m_rmin, m_rmax);
EVB_INFO("Merged file will be named {0}", merge_file);
std::string prefix = "";
std::string suffix = ".root";
grabber.SetSearchParams(file_dir, prefix, suffix,m_rmin,m_rmax);
EVB_INFO("Starting merge...");
if(!grabber.Merge_TChain(merge_file))
{ {
EVB_ERROR("Unable to find files for merge at EVBApp::MergeROOTFiles()!"); EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string merge_file = m_workspace->GetMergedDir()+"run_"+std::to_string(m_params.runMin)+"_"+std::to_string(m_params.runMax)+".root";
EVB_INFO("Merging ROOT files into single file for runs in range [{0}, {1}]", m_params.runMin, m_params.runMax);
EVB_INFO("Merged file will be named {0}", merge_file);
EVB_INFO("Starting merge...");
if(!m_workspace->MergeAnalyzedFiles(merge_file, m_params.runMin, m_params.runMax))
{
EVB_ERROR("Unable to merge at EVBApp::MergeROOTFiles()!");
return; return;
} }
EVB_INFO("Finished."); EVB_INFO("Finished.");
@ -208,207 +214,157 @@ namespace EventBuilder {
void EVBApp::Convert2SortedRoot() void EVBApp::Convert2SortedRoot()
{ {
int sys_return; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string sortroot_dir = m_workspace+"/sorted/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_rmin; i<= m_rmax; i++)
{ {
binfile = grabber.GrabFile(i); EVB_ERROR("Unable to preform event building request due to bad workspace.");
if(binfile == "")
continue;
converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...",binfile);
sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow);
sys_return = system(wipe_command.c_str());
count++;
} }
if(count==0)
EVB_WARN("Conversion failed, no archives were found!");
else
EVB_INFO("Conversion complete.");
}
void EVBApp::Convert2FastSortedRoot() {
int sys_return;
std::string sortroot_dir = m_workspace+"/fast/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to fast event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count=0;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
EVB_INFO("Converting file {0}...",binfile);
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str());
converter.Convert2FastSortedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh);
sys_return = system(wipe_command.c_str());
count++;
}
if(count==0)
EVB_WARN("Conversion failed, no archives were found!");
else
EVB_INFO("Conversion complete.");
}
void EVBApp::Convert2SlowAnalyzedRoot() {
int sys_return;
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
EVB_INFO("Converting binary archives to analyzed event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin, m_rmax); std::string sortroot_dir = m_workspace->GetBuiltDir();
EVB_INFO("Converting binary archives to event built ROOT files over run range [{0}, {1}]", m_params.runMin, m_params.runMax);
std::string sortfile, binfile; std::string sortfile;
std::string unpack_command, wipe_command;
CompassRun converter(m_params, m_workspace);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
EVB_INFO("Converting file {0}...", sortfile);
m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
{
converter.SetRunNumber(i);
converter.Convert2SortedRoot(sortfile);
EVB_INFO("Finished converting");
++count;
}
m_workspace->ClearTempDirectory();
}
if(count != 0)
EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
}
CompassRun converter(unpack_dir); void EVBApp::Convert2FastSortedRoot()
converter.SetShiftMap(m_shiftfile); {
converter.SetScalerInput(m_scalerfile); if(m_workspace == nullptr || !m_workspace->IsValid())
{
EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string sortroot_dir = m_workspace->GetBuiltDir();
EVB_INFO("Converting binary archives to fast event built ROOT files over run range [{0}, {1}]", m_params.runMin, m_params.runMax);
std::string sortfile;
CompassRun converter(m_params, m_workspace);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
int count=0; int count = 0;
for(int i=m_rmin; i<=m_rmax; i++) for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i); sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
if(binfile == "") EVB_INFO("Converting file {0}...", sortfile);
continue; m_workspace->ClearTempDirectory(); //In case something weird happened
converter.SetRunNumber(i); if(m_workspace->UnpackBinaryRunToTemp(i))
EVB_INFO("Converting file {0}...",binfile); {
converter.SetRunNumber(i);
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root"; converter.Convert2FastSortedRoot(sortfile);
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; ++count;
wipe_command = "rm -r "+unpack_dir+"*.BIN"; }
m_workspace->ClearTempDirectory();
sys_return = system(unpack_command.c_str());
converter.Convert2SlowAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
sys_return = system(wipe_command.c_str());
count++;
} }
if(count==0)
EVB_WARN("Conversion failed, no archives were found!"); if(count != 0)
else
EVB_INFO("Conversion complete."); EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
}
void EVBApp::Convert2SlowAnalyzedRoot()
{
if(m_workspace == nullptr || !m_workspace->IsValid())
{
EVB_ERROR("Unable to preform event building request due to bad workspace.");
}
std::string sortroot_dir = m_workspace->GetAnalyzedDir();
EVB_INFO("Converting binary archives to analyzed event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
std::string sortfile;
CompassRun converter(m_params, m_workspace);
converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion...");
int count = 0;
for(int i=m_params.runMin; i<=m_params.runMax; i++)
{
sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
EVB_INFO("Converting file {0}...", sortfile);
m_workspace->ClearTempDirectory(); //In case something weird happened
if(m_workspace->UnpackBinaryRunToTemp(i))
{
converter.SetRunNumber(i);
converter.Convert2SlowAnalyzedRoot(sortfile);
++count;
}
m_workspace->ClearTempDirectory();
}
if(count != 0)
EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
void EVBApp::Convert2FastAnalyzedRoot() void EVBApp::Convert2FastAnalyzedRoot()
{ {
int sys_return; if(m_workspace == nullptr || !m_workspace->IsValid())
std::string sortroot_dir = m_workspace+"/analyzed/"; {
std::string unpack_dir = m_workspace+"/temp_binary/"; EVB_ERROR("Unable to preform event building request due to bad workspace.");
std::string binary_dir = m_workspace+"/raw_binary/"; }
EVB_INFO("Converting binary archives to analyzed fast event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax);
std::string sortroot_dir = m_workspace->GetAnalyzedDir();
EVB_INFO("Converting binary archives to analyzed fast event built ROOT files over run range [{0}, {1}]",m_params.runMin,m_params.runMax);
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::string sortfile, binfile; std::string sortfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir); CompassRun converter(m_params, m_workspace);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressCallbackFunc(m_progressCallback);
converter.SetProgressFraction(m_progressFraction); converter.SetProgressFraction(m_progressFraction);
EVB_INFO("Beginning conversion..."); EVB_INFO("Beginning conversion...");
int count=0; int count = 0;
for(int i=m_rmin; i<=m_rmax; i++) for(int i=m_params.runMin; i<=m_params.runMax; i++)
{ {
binfile = grabber.GrabFile(i); sortfile = sortroot_dir + "run_"+ std::to_string(i) + ".root";
if(binfile == "") EVB_INFO("Converting file {0}...", sortfile);
continue; m_workspace->ClearTempDirectory(); //In case something weird happened
converter.SetRunNumber(i); if(m_workspace->UnpackBinaryRunToTemp(i))
EVB_INFO("Converting file {0}...",binfile); {
converter.SetRunNumber(i);
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root"; converter.Convert2FastAnalyzedRoot(sortfile);
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; ++count;
wipe_command = "rm -r "+unpack_dir+"*.BIN"; }
m_workspace->ClearTempDirectory();
sys_return = system(unpack_command.c_str());
converter.Convert2FastAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
sys_return = system(wipe_command.c_str());
count++;
} }
if(count==0)
EVB_WARN("Conversion failed, no archives were found!"); if(count != 0)
else
EVB_INFO("Conversion complete."); EVB_INFO("Conversion complete.");
else
EVB_WARN("Nothing converted, no files found in the range [{0}, {1}]", m_params.runMin, m_params.runMax);
} }
bool EVBApp::SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke)
{
if((at + ap - ae) < 0 || (zt + zp - ze) < 0)
{
EVB_WARN("Invalid kinematic parameters, nucleon number not conserved! Parameters not set");
return false;
}
m_ZT = zt; m_AT = at; m_ZP = zp; m_AP = ap; m_ZE = ze; m_AE = ae;
m_B = b; m_Theta = theta; m_BKE = bke;
m_ZR = (zt + zp - ze);
m_AR = (at + ap - ae);
EVB_TRACE("Kinematic paramters updated.");
return true;
}
void EVBApp::SetRunRange(int rmin, int rmax) { EVB_TRACE("Min Run, max run set to [{0}, {1}]", rmin, rmax); m_rmin = rmin; m_rmax = rmax; }
void EVBApp::SetWorkDirectory(const std::string& fullpath) { EVB_TRACE("Workspace set to {0}", fullpath); m_workspace = fullpath; }
void EVBApp::SetChannelMap(const std::string& name) { EVB_TRACE("Channel map set to {0}",name); m_mapfile = name; }
void EVBApp::SetBoardShiftFile(const std::string& name) { EVB_TRACE("Shift file set to {0}", name); m_shiftfile = name; }
void EVBApp::SetSlowCoincidenceWindow(double window) { EVB_TRACE("Slow Coincidence Window set to {0}",window); m_SlowWindow = window; }
void EVBApp::SetFastWindowIonChamber(double window) { EVB_TRACE("Fast Coinc. Window Ion Ch. set to {0}",window); m_FastWindowIonCh = window; }
void EVBApp::SetFastWindowSABRE(double window) { EVB_TRACE("Fast Coinc. Window SABRE set to {0}",window); m_FastWindowSABRE = window; }
void EVBApp::SetCutList(const std::string& name) { EVB_TRACE("Cut List set to {0}", name); m_cutList = name; }
void EVBApp::SetScalerFile(const std::string& fullpath) { EVB_TRACE("Scaler file set to {0}", fullpath); m_scalerfile = fullpath; }
} }

View File

@ -9,7 +9,8 @@
#ifndef EVBAPP_H #ifndef EVBAPP_H
#define EVBAPP_H #define EVBAPP_H
#include "RunCollector.h" #include "EVBParameters.h"
#include "EVBWorkspace.h"
#include "ProgressCallback.h" #include "ProgressCallback.h"
namespace EventBuilder { namespace EventBuilder {
@ -25,44 +26,14 @@ namespace EventBuilder {
void PlotHistograms(); void PlotHistograms();
void MergeROOTFiles(); void MergeROOTFiles();
void Convert2RawRoot();
void Convert2SortedRoot(); void Convert2SortedRoot();
void Convert2FastSortedRoot(); void Convert2FastSortedRoot();
void Convert2RawRoot();
void Convert2SlowAnalyzedRoot(); void Convert2SlowAnalyzedRoot();
void Convert2FastAnalyzedRoot(); void Convert2FastAnalyzedRoot();
void SetRunRange(int rmin, int rmax); void SetParameters(const EVBParameters& params);
void SetWorkDirectory(const std::string& fullpath); inline EVBParameters& GetParameters() { return m_params; }
void SetChannelMap(const std::string& name);
void SetBoardShiftFile(const std::string& name);
void SetSlowCoincidenceWindow(double window);
void SetFastWindowIonChamber(double window);
void SetFastWindowSABRE(double window);
void SetCutList(const std::string& name);
void SetScalerFile(const std::string& fullpath);
bool SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke);
inline int GetRunMin() const { return m_rmin; }
inline int GetRunMax() const { return m_rmax; }
inline std::string GetWorkDirectory() const { return m_workspace; }
inline int GetTargetZ() const { return m_ZT; }
inline int GetTargetA() const { return m_AT; }
inline int GetProjectileZ() const { return m_ZP; }
inline int GetProjectileA() const { return m_AP; }
inline int GetEjectileZ() const { return m_ZE; }
inline int GetEjectileA() const { return m_AE; }
inline int GetResidualZ() const { return m_ZR; }
inline int GetResidualA() const { return m_AR; }
inline double GetBField() const { return m_B; }
inline double GetBeamKE() const { return m_BKE; }
inline double GetTheta() const { return m_Theta; }
inline double GetSlowCoincidenceWindow() const { return m_SlowWindow; }
inline double GetFastWindowIonChamber() const { return m_FastWindowIonCh; }
inline double GetFastWindowSABRE() const { return m_FastWindowSABRE; }
inline std::string GetChannelMap() const { return m_mapfile; }
inline std::string GetBoardShiftFile() const { return m_shiftfile; }
inline std::string GetCutList() const { return m_cutList; }
inline std::string GetScalerFile() const { return m_scalerfile; }
void DefaultProgressCallback(long curVal, long totalVal); void DefaultProgressCallback(long curVal, long totalVal);
inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; } inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; }
@ -80,23 +51,9 @@ namespace EventBuilder {
}; };
private: private:
EVBParameters m_params;
int m_rmin, m_rmax; std::shared_ptr<EVBWorkspace> m_workspace;
int m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_ZR, m_AR;
double m_B, m_Theta, m_BKE;
double m_progressFraction; double m_progressFraction;
std::string m_workspace;
std::string m_mapfile, m_shiftfile;
std::string m_cutList;
std::string m_scalerfile;
double m_SlowWindow;
double m_FastWindowIonCh;
double m_FastWindowSABRE;
RunCollector grabber;
ProgressCallbackFunc m_progressCallback; ProgressCallbackFunc m_progressCallback;
}; };

34
src/evb/EVBParameters.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef EVB_PARAMETERS_H
#define EVB_PARAMETERS_H
namespace EventBuilder {
struct EVBParameters
{
std::string workspaceDir = "";
std::string channelMapFile = "";
std::string timeShiftFile = "";
std::string cutListFile = "";
std::string scalerFile = "";
int runMin = 0;
int runMax = 0;
double slowCoincidenceWindow = 3.0e6;
double fastCoincidenceWindowIonCh = 0.0;
double fastCoincidenceWindowSABRE = 0.0;
int ZT = 6;
int AT = 12;
int ZP = 1;
int AP = 2;
int ZE = 1;
int AE = 1;
double BField = 7.8; //kG
double spsAngle = 15.0; //degrees
double beamEnergy = 16.0; //MeV
};
}
#endif

204
src/evb/EVBWorkspace.cpp Normal file
View File

@ -0,0 +1,204 @@
#include "EVBWorkspace.h"
#include <filesystem>
#include <TFile.h>
#include <TChain.h>
namespace EventBuilder {
static bool CheckSubDirectory(const std::string& path)
{
bool status = true;
EVB_TRACE("Checking subdirectory {0}", path);
if(!std::filesystem::exists(path))
{
status = std::filesystem::create_directory(path);
if(!status)
{
EVB_ERROR("Unable to create subdirectory {0}. Please check the pathing.", path);
return status;
}
EVB_INFO("Created subdirectory {0}", path);
}
else
EVB_INFO("Found subdirectory {0}", path);
return status;
}
EVBWorkspace::EVBWorkspace(const std::string& workspace) :
m_isValid(false), m_workspace(workspace)
{
Init();
}
EVBWorkspace::~EVBWorkspace() {}
void EVBWorkspace::Init()
{
m_isValid = true;
if(!std::filesystem::exists(m_workspace))
{
EVB_TRACE("Workspace {0} does not exist. Attempting to create the workspace directory...", m_workspace);
m_isValid = std::filesystem::create_directory(m_workspace);
if(!m_isValid)
{
EVB_ERROR("Unable to create workspace {0}. Please check the pathing.", m_workspace);
return;
}
EVB_INFO("Created workspace directory {0}.", m_workspace);
}
else
EVB_INFO("Found workspace directory {0}.", m_workspace);
EVB_TRACE("Looking for required workspace subdirectories...");
m_binaryDir = m_workspace + "raw_binary/";
m_tempDir = m_workspace + "temp_binary/";
m_sortedDir = m_workspace + "sorted/";
m_builtDir = m_workspace + "built/";
m_analyzedDir = m_workspace + "analyzed/";
m_histogramDir = m_workspace + "histograms/";
m_cutDir = m_workspace + "cuts/";
//Check all subdirectories. Terminate if any of them are bad
m_isValid = CheckSubDirectory(m_binaryDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_tempDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_sortedDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_builtDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_analyzedDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_histogramDir);
if(!m_isValid)
return;
m_isValid = CheckSubDirectory(m_cutDir);
}
std::string EVBWorkspace::GetBinaryRun(int run)
{
std::string file;
std::string runID = "run_" + std::to_string(run) + ".tar.gz";
for(auto& entry : std::filesystem::directory_iterator(m_binaryDir))
{
if(entry.is_regular_file() && entry.path().filename().string() == runID)
{
return entry.path().string();
}
}
return "";
}
std::string EVBWorkspace::GetAnalyzedRun(int run)
{
std::string file;
std::string runID = "run_" + std::to_string(run) + ".root";
for(auto& entry : std::filesystem::directory_iterator(m_analyzedDir))
{
if(entry.is_regular_file() && entry.path().filename().string() == runID)
{
return entry.path().string();
}
}
return "";
}
std::vector<std::string> EVBWorkspace::GetBinaryRunRange(int runMin, int runMax)
{
std::vector<std::string> list;
std::string temp;
for(int run=runMin; run<=runMax; run++)
temp = GetBinaryRun(run);
if(!temp.empty())
list.push_back(temp);
return list;
}
std::vector<std::string> EVBWorkspace::GetAnalyzedRunRange(int runMin, int runMax)
{
std::vector<std::string> list;
std::string temp;
for(int run=runMin; run<=runMax; run++)
temp = GetAnalyzedRun(run);
if(!temp.empty())
list.push_back(temp);
return list;
}
bool EVBWorkspace::UnpackBinaryRunToTemp(int run)
{
std::string runfile = GetBinaryRun(run);
std::string unpack_command = "tar -xzf "+runfile+" --directory "+m_tempDir;
int sys_return = system(unpack_command.c_str());
if(sys_return == 0)
return true;
else
return false;
}
std::vector<std::string> EVBWorkspace::GetTempFiles()
{
std::vector<std::string> list;
for(auto& entry : std::filesystem::directory_iterator(m_tempDir))
{
if(entry.is_regular_file() && entry.path().filename().extension().string() == ".BIN")
list.push_back(entry.path().string());
}
return list;
}
bool EVBWorkspace::ClearTempDirectory()
{
std::vector<std::filesystem::path> files;
for(auto& entry : std::filesystem::directory_iterator(m_tempDir))
{
if(entry.is_regular_file())
files.push_back(entry.path());
else
EVB_WARN("Detected non-file element in temp directory {0} named {1}", m_tempDir, entry.path().string());
}
for(size_t i=0; i<files.size(); i++)
{
if(!std::filesystem::remove(files[i]))
{
EVB_ERROR("Unable to clear temp directory {0}! File-like entry {1} could not be deleted. Please manually clear the directory.",
m_tempDir, files[i].string());
return false;
}
}
return true;
}
bool EVBWorkspace::MergeAnalyzedFiles(const std::string& outputname, int runMin, int runMax)
{
auto files = GetAnalyzedRunRange(runMin, runMax);
if(files.size() == 0)
return false;
TFile* output = TFile::Open(outputname.c_str(), "RECREATE");
if(!output->IsOpen())
{
EVB_ERROR("Could not open output file {0} for merge", outputname);
output->Close();
return false;
}
TChain* chain = new TChain("SPSTree", "SPSTree");
for(auto& entry : files)
chain->Add(entry.c_str());
chain->Merge(output, 0, "fast");
output->Close();
return true;
}
}

51
src/evb/EVBWorkspace.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef EVB_WORKSPACE_H
#define EVB_WORKSPACE_H
namespace EventBuilder {
class EVBWorkspace
{
public:
EVBWorkspace(const std::string& workspace);
~EVBWorkspace();
inline const bool IsValid() const { return m_isValid; }
inline std::string GetBinaryDir() const { return m_binaryDir; }
inline std::string GetTempDir() const { return m_tempDir; }
inline std::string GetSortedDir() const { return m_sortedDir; }
inline std::string GetBuiltDir() const { return m_builtDir; }
inline std::string GetAnalyzedDir() const { return m_analyzedDir; }
inline std::string GetHistogramDir() const { return m_histogramDir; }
inline std::string GetCutDir() const { return m_cutDir; }
inline std::string GetMergedDir() const { return m_mergedDir; }
std::vector<std::string> GetBinaryRunRange(int runMin, int runMax);
std::vector<std::string> GetAnalyzedRunRange(int runMin, int runMax);
bool UnpackBinaryRunToTemp(int run); //Currently Linux/MacOS only. Windows support to come.
std::vector<std::string> GetTempFiles();
bool ClearTempDirectory();
//Maybe offload to another class? Idk. Feel like EVBWorkspace shouldn't know about ROOT
bool MergeAnalyzedFiles(const std::string& outputname, int runMin, int runMax);
private:
void Init();
std::string GetBinaryRun(int run);
std::string GetAnalyzedRun(int run);
bool m_isValid;
std::string m_workspace;
std::string m_binaryDir;
std::string m_tempDir;
std::string m_sortedDir;
std::string m_builtDir;
std::string m_analyzedDir;
std::string m_histogramDir;
std::string m_cutDir;
std::string m_mergedDir;
};
}
#endif

View File

@ -31,7 +31,6 @@
*/ */
#include "EventBuilder.h"
#include <cmath> #include <cmath>
#include "MassLookup.h" #include "MassLookup.h"
#include "FP_kinematics.h" #include "FP_kinematics.h"

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "FastSort.h" #include "FastSort.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "FlagHandler.h" #include "FlagHandler.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -1,4 +1,3 @@
#include "EventBuilder.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -8,7 +8,6 @@ of this map (MASS) for use throughout code it is included into.
Written by G.W. McCann Aug. 2020 Written by G.W. McCann Aug. 2020
*/ */
#include "EventBuilder.h"
#include "MassLookup.h" #include "MassLookup.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -5,7 +5,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "OrderChecker.h" #include "OrderChecker.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -1,232 +0,0 @@
#include "EventBuilder.h"
#include "RunCollector.h"
#include <TSystemDirectory.h>
#include <TSystemFile.h>
#include <TCollection.h>
#include <TList.h>
#include <cstdlib>
#include <cstdio>
namespace EventBuilder {
RunCollector::RunCollector():
m_initFlag(false), m_directory(""), m_prefix(""), m_suffix(""), m_minRun(0), m_maxRun(0)
{
}
RunCollector::RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix) :
m_initFlag(true), m_directory(dirname), m_prefix(prefix), m_suffix(suffix), m_minRun(0), m_maxRun(0)
{
}
RunCollector::RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max) :
m_initFlag(true), m_directory(dirname), m_prefix(prefix), m_suffix(suffix), m_minRun(min), m_maxRun(max)
{
}
RunCollector::~RunCollector() {}
void RunCollector::SetSearchParams(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max)
{
m_directory = dirname.c_str();
m_prefix = prefix.c_str();
m_suffix = suffix.c_str();
m_minRun = min; m_maxRun = max;
m_initFlag = true;
}
bool RunCollector::GrabAllFiles()
{
if(!m_initFlag)
return false;
TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
TList *flist = sysdir.GetListOfFiles();
m_filelist.clear();
if(!flist) //Make sure list is real. If not, means no directory
{
EVB_WARN("RunCollector::GrabAllFiles() unable to find any files in directory {0}",m_directory);
return false;
}
TSystemFile *file;
std::string fname, temp;
TIter next_element(flist); //List iterator
while((file = (TSystemFile*)next_element()))
{
temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < m_suffix.size())
continue;
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) &&
!temp.compare(temp.size()-m_suffix.size(), m_suffix.size(), m_suffix))
{
fname = m_directory+temp;
m_filelist.push_back(fname);
}
}
delete flist;
if(m_filelist.size()>0)
return true;
else
{
EVB_WARN("RunCollector::GrabAllFiles() unable to find any files in directory {0} which match run pattern",m_directory);
return false;
}
}
std::string RunCollector::GrabFile(int runNum) {
if(!m_initFlag)
return "";
TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
TList* flist = sysdir.GetListOfFiles();
if(!flist)
return "";
TSystemFile *file;
std::string fname = "", temp;
std::string runno = "_"+std::to_string(runNum)+m_suffix;
TIter next_element(flist);
while((file = (TSystemFile*)next_element()))
{
temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < runno.size())
continue;
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) &&
!temp.compare(temp.size()-runno.size(),runno.size(), runno))
{
fname = m_directory+temp;
break;
}
}
delete flist;
return fname;
}
/*Grabs all files within a specified run range*/
bool RunCollector::GrabFilesInRange()
{
if(!m_initFlag)
return false;
TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
TList *flist = sysdir.GetListOfFiles();
m_filelist.clear();
if(!flist)
{
EVB_WARN("RunCollector::GrabFilesInRange() unable to find any files in directory {0}",m_directory);
return false;
}
TSystemFile *file;
std::string fname, temp;
std::string runno;
for(int i=m_minRun; i<=m_maxRun; i++) //loop over range
{
TIter next_element(flist);//list iterator
runno = "_"+std::to_string(i) + m_suffix; //suffix is now _#.suffix
while((file = (TSystemFile*)next_element())) //look through directory until file found
{
temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < runno.size())
continue;
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) &&
!temp.compare(temp.size()-runno.size(),runno.size(), runno))
{
fname = m_directory+temp;
m_filelist.push_back(fname);
break; //if we find the file, break out of iterator loop
}
}
}
delete flist;
if(m_filelist.size()>0)
return true;
else
{
EVB_WARN("RunCollector::GrabAllFiles() unable to find any files in directory {0} which match run pattern and were in run range",m_directory);
return false;
}
}
bool RunCollector::Merge_hadd(const std::string& outname)
{
int sys_return;
if(!m_initFlag)
return false;
if(m_maxRun == 0)
{
if(GrabAllFiles())
{
std::string clump = "hadd "+outname;
for(unsigned int i=0; i<m_filelist.size(); i++)
clump += " "+m_filelist[i];
sys_return = std::system(clump.c_str());
return true;
}
else
return false;
}
else
{
if(GrabFilesInRange())
{
std::string clump = "hadd "+outname;
for(unsigned int i=0; i<m_filelist.size(); i++)
clump += " "+m_filelist[i];
sys_return = std::system(clump.c_str());
return true;
}
else
return false;
}
if(!sys_return)
EVB_ERROR("How did i even get here?");
return false;
}
bool RunCollector::Merge_TChain(const std::string& outname)
{
if(!m_initFlag)
return false;
TFile *output = new TFile(outname.c_str(), "RECREATE");
TChain *chain = new TChain("SPSTree", "SPSTree");
if(m_maxRun == 0)
{
if(GrabAllFiles())
{
for(unsigned int i=0; i<m_filelist.size(); i++)
chain->Add(m_filelist[i].c_str());
chain->Merge(output,0,"fast");
return true;
}
else
return false;
}
else
{
if(GrabFilesInRange())
{
for(unsigned int i=0; i<m_filelist.size(); i++)
chain->Add(m_filelist[i].c_str());
chain->Merge(output,0,"fast");
return true;
} else
return false;
}
if(output->IsOpen())
output->Close();
return false;
}
}

View File

@ -1,47 +0,0 @@
/*RunCollector.h
*Class that searches through a directory looking for files of a specified format.
*Stores all filenames in a vector which can be accessed by other functions/classes for
*further use. Can also use Merge() to combine all files using hadd into a single file.
*Merge() is NOT RECOMMENDED in the analyzer program.
*
*Created Jan2020 by GWM
*/
#ifndef RUNCOLLECTOR_H
#define RUNCOLLECTOR_H
namespace EventBuilder {
class RunCollector
{
public:
RunCollector();
RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix);
RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
~RunCollector();
void SetSearchParams(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
bool Merge_hadd(const std::string& outname);
bool Merge_TChain(const std::string& outname);
bool GrabAllFiles();
bool GrabFilesInRange();
std::string GrabFile(int runNum);
inline std::string GetSearchDir() { return m_directory; }
inline std::string GetSearchPrefix() { return m_prefix; }
inline std::string GetSearchSuffix() { return m_suffix; }
inline int GetRunMin() { return m_minRun; }
inline int GetRunMax() { return m_maxRun; }
inline const std::vector<std::string>& GetFileList() { return m_filelist; }
private:
bool m_initFlag;
std::string m_directory;
std::string m_prefix;
std::string m_suffix;
int m_minRun, m_maxRun; //user run limits
const int m_maxAllowedRuns = 1000; //class run limit
std::vector<std::string> m_filelist;
};
}
#endif

View File

@ -9,7 +9,6 @@
* *
* Position calibrations swapped as of Aug. 2021 due to detector fixes -- GWM * Position calibrations swapped as of Aug. 2021 due to detector fixes -- GWM
*/ */
#include "EventBuilder.h"
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
namespace EventBuilder { namespace EventBuilder {
@ -18,7 +17,7 @@ namespace EventBuilder {
SFPAnalyzer::SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, SFPAnalyzer::SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep,
double angle, double b) double angle, double b)
{ {
zfp = Delta_Z(zt, at, zp, ap, ze, ae, ep, angle, b); zfp = Delta_Z(zt, at, zp, ap, ze, ae, ep, angle, b*1000.0); //Convert kG to G
event_address = new CoincEvent(); event_address = new CoincEvent();
rootObj = new THashTable(); rootObj = new THashTable();
GetWeights(); GetWeights();

View File

@ -6,7 +6,6 @@
*Created Jan 2020 by GWM *Created Jan 2020 by GWM
*/ */
#include "EventBuilder.h"
#include "SFPPlotter.h" #include "SFPPlotter.h"
#include <TSystem.h> #include <TSystem.h>

View File

@ -9,7 +9,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "ShiftMap.h" #include "ShiftMap.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -7,7 +7,6 @@
* *
*Refurbished and updated Jan 2020 GWM *Refurbished and updated Jan 2020 GWM
*/ */
#include "EventBuilder.h"
#include "SlowSort.h" #include "SlowSort.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -5,7 +5,6 @@
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#include "EventBuilder.h"
#include "Stopwatch.h" #include "Stopwatch.h"
namespace EventBuilder { namespace EventBuilder {

View File

@ -29,7 +29,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel* workLabel = new TGLabel(WorkFrame, "Workspace Directory:"); TGLabel* workLabel = new TGLabel(WorkFrame, "Workspace Directory:");
fWorkField = new TGTextEntry(WorkFrame, new TGTextBuffer(120), WorkDir); fWorkField = new TGTextEntry(WorkFrame, new TGTextBuffer(120), WorkDir);
fWorkField->Resize(w*0.25, fWorkField->GetDefaultHeight()); fWorkField->Resize(w*0.25, fWorkField->GetDefaultHeight());
fWorkField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateWorkdir()");
fOpenWorkButton = new TGTextButton(WorkFrame, "Open"); fOpenWorkButton = new TGTextButton(WorkFrame, "Open");
fOpenWorkButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenWorkdir()"); fOpenWorkButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenWorkdir()");
WorkFrame->AddFrame(workLabel, lhints); WorkFrame->AddFrame(workLabel, lhints);
@ -40,7 +39,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel* cmaplabel = new TGLabel(CMapFrame, "Channel Map File:"); TGLabel* cmaplabel = new TGLabel(CMapFrame, "Channel Map File:");
fCMapField = new TGTextEntry(CMapFrame, new TGTextBuffer(120), Cmap); fCMapField = new TGTextEntry(CMapFrame, new TGTextBuffer(120), Cmap);
fCMapField->Resize(w*0.25, fCMapField->GetDefaultHeight()); fCMapField->Resize(w*0.25, fCMapField->GetDefaultHeight());
fCMapField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateCMap()");
fOpenCMapButton = new TGTextButton(CMapFrame, "Open"); fOpenCMapButton = new TGTextButton(CMapFrame, "Open");
fOpenCMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCMapfile()"); fOpenCMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCMapfile()");
CMapFrame->AddFrame(cmaplabel, lhints); CMapFrame->AddFrame(cmaplabel, lhints);
@ -51,7 +49,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel* smaplabel = new TGLabel(SMapFrame, "Board Shift File:"); TGLabel* smaplabel = new TGLabel(SMapFrame, "Board Shift File:");
fSMapField = new TGTextEntry(SMapFrame, new TGTextBuffer(120), Smap); fSMapField = new TGTextEntry(SMapFrame, new TGTextBuffer(120), Smap);
fSMapField->Resize(w*0.25, fSMapField->GetDefaultHeight()); fSMapField->Resize(w*0.25, fSMapField->GetDefaultHeight());
fSMapField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateSMap()");
fOpenSMapButton = new TGTextButton(SMapFrame, "Open"); fOpenSMapButton = new TGTextButton(SMapFrame, "Open");
fOpenSMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenSMapfile()"); fOpenSMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenSMapfile()");
SMapFrame->AddFrame(smaplabel, lhints); SMapFrame->AddFrame(smaplabel, lhints);
@ -61,7 +58,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGHorizontalFrame *ScalerFrame = new TGHorizontalFrame(NameFrame, w, h*0.06); TGHorizontalFrame *ScalerFrame = new TGHorizontalFrame(NameFrame, w, h*0.06);
TGLabel* sclabel = new TGLabel(ScalerFrame, "Scaler File: "); TGLabel* sclabel = new TGLabel(ScalerFrame, "Scaler File: ");
fScalerField = new TGTextEntry(ScalerFrame, new TGTextBuffer(120), Scaler); fScalerField = new TGTextEntry(ScalerFrame, new TGTextBuffer(120), Scaler);
fScalerField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateScaler()");
fOpenScalerButton = new TGTextButton(ScalerFrame, "Open"); fOpenScalerButton = new TGTextButton(ScalerFrame, "Open");
fOpenScalerButton->Connect("Clicked()","EVBMainFrame", this, "DoOpenScalerfile()"); fOpenScalerButton->Connect("Clicked()","EVBMainFrame", this, "DoOpenScalerfile()");
ScalerFrame->AddFrame(sclabel, lhints); ScalerFrame->AddFrame(sclabel, lhints);
@ -71,7 +67,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGHorizontalFrame *CutFrame = new TGHorizontalFrame(NameFrame, w, h*0.06); TGHorizontalFrame *CutFrame = new TGHorizontalFrame(NameFrame, w, h*0.06);
TGLabel* clabel = new TGLabel(CutFrame, "Cut List: "); TGLabel* clabel = new TGLabel(CutFrame, "Cut List: ");
fCutField = new TGTextEntry(CutFrame, new TGTextBuffer(120), Cut); fCutField = new TGTextEntry(CutFrame, new TGTextBuffer(120), Cut);
fCutField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateCut()");
fOpenCutButton = new TGTextButton(CutFrame, "Open"); fOpenCutButton = new TGTextButton(CutFrame, "Open");
fOpenCutButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCutfile()"); fOpenCutButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCutfile()");
CutFrame->AddFrame(clabel, lhints); CutFrame->AddFrame(clabel, lhints);
@ -141,7 +136,7 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
beamFrame->AddFrame(bkelabel, lhints); beamFrame->AddFrame(bkelabel, lhints);
beamFrame->AddFrame(fBKEField, fhints); beamFrame->AddFrame(fBKEField, fhints);
TGHorizontalFrame* bfFrame = new TGHorizontalFrame(extraFrame, w*0.175, h*0.15); TGHorizontalFrame* bfFrame = new TGHorizontalFrame(extraFrame, w*0.175, h*0.15);
TGLabel *bfieldlabel = new TGLabel(bfFrame, "B-Field (G):"); TGLabel *bfieldlabel = new TGLabel(bfFrame, "B-Field (kG):");
fBField = new TGNumberEntryField(bfFrame, BField, 0, TGNumberEntry::kNESRealFour, TGNumberEntry::kNEANonNegative); fBField = new TGNumberEntryField(bfFrame, BField, 0, TGNumberEntry::kNESRealFour, TGNumberEntry::kNEANonNegative);
bfFrame->AddFrame(bfieldlabel, lhints); bfFrame->AddFrame(bfieldlabel, lhints);
bfFrame->AddFrame(fBField, fhints); bfFrame->AddFrame(fBField, fhints);
@ -250,8 +245,8 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
AddFrame(ParamFrame, new TGLayoutHints(kLHintsCenterX|kLHintsExpandY,5,5,5,5)); AddFrame(ParamFrame, new TGLayoutHints(kLHintsCenterX|kLHintsExpandY,5,5,5,5));
AddFrame(PBFrame, fpbhints); AddFrame(PBFrame, fpbhints);
fBuilder.SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBMainFrame::SetProgressBarPosition)); m_builder.SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBMainFrame::SetProgressBarPosition));
fBuilder.SetProgressFraction(0.01); m_builder.SetProgressFraction(0.01);
SetWindowName("GWM Event Builder"); SetWindowName("GWM Event Builder");
MapSubwindows(); MapSubwindows();
Resize(); Resize();
@ -291,7 +286,12 @@ void EVBMainFrame::HandleMenuSelection(int id)
void EVBMainFrame::DoOpenWorkdir() void EVBMainFrame::DoOpenWorkdir()
{ {
new FileViewFrame(gClient->GetRoot(), this, MAIN_W*0.5, MAIN_H, this, WorkDir); new TGFileDialog(gClient->GetRoot(), this, kDOpen, fInfo);
if(fInfo->fFilename)
{
std::string path_wtrailer = fInfo->fFilename + std::string("/");
DisplayWorkdir(path_wtrailer.c_str());
}
} }
void EVBMainFrame::DoOpenCMapfile() void EVBMainFrame::DoOpenCMapfile()
@ -335,37 +335,37 @@ void EVBMainFrame::DoRun()
{ {
case EventBuilder::EVBApp::Operation::Plot : case EventBuilder::EVBApp::Operation::Plot :
{ {
RunPlot(); m_builder.PlotHistograms();
break; break;
} }
case EventBuilder::EVBApp::Operation::Convert : case EventBuilder::EVBApp::Operation::Convert :
{ {
fBuilder.Convert2RawRoot(); m_builder.Convert2RawRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::Merge : case EventBuilder::EVBApp::Operation::Merge :
{ {
fBuilder.MergeROOTFiles(); m_builder.MergeROOTFiles();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertSlow : case EventBuilder::EVBApp::Operation::ConvertSlow :
{ {
fBuilder.Convert2SortedRoot(); m_builder.Convert2SortedRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertFast : case EventBuilder::EVBApp::Operation::ConvertFast :
{ {
fBuilder.Convert2FastSortedRoot(); m_builder.Convert2FastSortedRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertSlowA : case EventBuilder::EVBApp::Operation::ConvertSlowA :
{ {
fBuilder.Convert2SlowAnalyzedRoot(); m_builder.Convert2SlowAnalyzedRoot();
break; break;
} }
case EventBuilder::EVBApp::Operation::ConvertFastA : case EventBuilder::EVBApp::Operation::ConvertFastA :
{ {
fBuilder.Convert2FastAnalyzedRoot(); m_builder.Convert2FastAnalyzedRoot();
break; break;
} }
} }
@ -380,126 +380,97 @@ void EVBMainFrame::HandleTypeSelection(int box, int entry)
bool EVBMainFrame::SetParameters() bool EVBMainFrame::SetParameters()
{ {
fBuilder.SetRunRange(fRMinField->GetIntNumber(), fRMaxField->GetIntNumber()); m_parameters.runMin = fRMinField->GetIntNumber();
fBuilder.SetSlowCoincidenceWindow(fSlowWindowField->GetNumber()); m_parameters.runMax = fRMaxField->GetIntNumber();
fBuilder.SetFastWindowIonChamber(fFastICField->GetNumber()); m_parameters.slowCoincidenceWindow = fSlowWindowField->GetNumber();
fBuilder.SetFastWindowSABRE(fFastSABREField->GetNumber()); m_parameters.fastCoincidenceWindowIonCh = fFastICField->GetNumber();
UpdateWorkdir(); m_parameters.fastCoincidenceWindowSABRE = fFastSABREField->GetNumber();
UpdateSMap(); m_parameters.workspaceDir = fWorkField->GetText();
UpdateCMap(); m_parameters.channelMapFile = fCMapField->GetText();
UpdateScaler(); m_parameters.scalerFile = fScalerField->GetText();
UpdateCut(); m_parameters.timeShiftFile = fSMapField->GetText();
bool test = fBuilder.SetKinematicParameters(fZTField->GetIntNumber(), fATField->GetIntNumber(), m_parameters.cutListFile = fCutField->GetText();
fZPField->GetIntNumber(), fAPField->GetIntNumber(), m_parameters.ZT = fZTField->GetIntNumber();
fZEField->GetIntNumber(), fAEField->GetIntNumber(), m_parameters.AT = fATField->GetIntNumber();
fBField->GetNumber(), fThetaField->GetNumber(), m_parameters.ZP = fZPField->GetIntNumber();
fBKEField->GetNumber()); m_parameters.AP = fAPField->GetIntNumber();
return test; m_parameters.ZE = fZEField->GetIntNumber();
m_parameters.AE = fAEField->GetIntNumber();
m_parameters.BField = fBField->GetNumber();
m_parameters.beamEnergy = fBKEField->GetNumber();
m_parameters.spsAngle = fThetaField->GetNumber();
m_builder.SetParameters(m_parameters);
return true;
} }
void EVBMainFrame::DisplayWorkdir(const char* dir) void EVBMainFrame::DisplayWorkdir(const char* dir)
{ {
fWorkField->SetText(dir); fWorkField->SetText(dir);
fBuilder.SetWorkDirectory(dir); SetParameters();
} }
void EVBMainFrame::DisplayCMap(const char* file) void EVBMainFrame::DisplayCMap(const char* file)
{ {
fCMapField->SetText(file); fCMapField->SetText(file);
fBuilder.SetChannelMap(file); SetParameters();
} }
void EVBMainFrame::DisplaySMap(const char* file) void EVBMainFrame::DisplaySMap(const char* file)
{ {
fSMapField->SetText(file); fSMapField->SetText(file);
fBuilder.SetBoardShiftFile(file); SetParameters();
} }
void EVBMainFrame::DisplayScaler(const char* file) void EVBMainFrame::DisplayScaler(const char* file)
{ {
fScalerField->SetText(file); fScalerField->SetText(file);
fBuilder.SetScalerFile(file); SetParameters();
} }
void EVBMainFrame::DisplayCut(const char* file) void EVBMainFrame::DisplayCut(const char* file)
{ {
fCutField->SetText(file); fCutField->SetText(file);
fBuilder.SetCutList(file); SetParameters();
} }
void EVBMainFrame::SaveConfig(const char* file) void EVBMainFrame::SaveConfig(const char* file)
{ {
std::string filename = file; std::string filename = file;
fBuilder.WriteConfigFile(filename); m_builder.WriteConfigFile(filename);
} }
void EVBMainFrame::LoadConfig(const char* file) void EVBMainFrame::LoadConfig(const char* file)
{ {
std::string filename = file; std::string filename = file;
fBuilder.ReadConfigFile(filename); m_builder.ReadConfigFile(filename);
m_parameters = m_builder.GetParameters();
fWorkField->SetText(fBuilder.GetWorkDirectory().c_str()); fWorkField->SetText(m_parameters.workspaceDir.c_str());
fCMapField->SetText(fBuilder.GetChannelMap().c_str()); fCMapField->SetText(m_parameters.channelMapFile.c_str());
fSMapField->SetText(fBuilder.GetBoardShiftFile().c_str()); fSMapField->SetText(m_parameters.timeShiftFile.c_str());
fCutField->SetText(fBuilder.GetCutList().c_str()); fCutField->SetText(m_parameters.cutListFile.c_str());
fScalerField->SetText(fBuilder.GetScalerFile().c_str()); fScalerField->SetText(m_parameters.scalerFile.c_str());
fZTField->SetIntNumber(fBuilder.GetTargetZ()); fZTField->SetIntNumber(m_parameters.ZT);
fATField->SetIntNumber(fBuilder.GetTargetA()); fATField->SetIntNumber(m_parameters.AT);
fZPField->SetIntNumber(fBuilder.GetProjectileZ()); fZPField->SetIntNumber(m_parameters.ZP);
fAPField->SetIntNumber(fBuilder.GetProjectileA()); fAPField->SetIntNumber(m_parameters.AP);
fZEField->SetIntNumber(fBuilder.GetEjectileZ()); fZEField->SetIntNumber(m_parameters.ZE);
fAEField->SetIntNumber(fBuilder.GetEjectileA()); fAEField->SetIntNumber(m_parameters.AE);
fBKEField->SetNumber(fBuilder.GetBeamKE()); fBKEField->SetNumber(m_parameters.beamEnergy);
fBField->SetNumber(fBuilder.GetBField()); fBField->SetNumber(m_parameters.BField);
fThetaField->SetNumber(fBuilder.GetTheta()); fThetaField->SetNumber(m_parameters.spsAngle);
fSlowWindowField->SetNumber(fBuilder.GetSlowCoincidenceWindow()); fSlowWindowField->SetNumber(m_parameters.slowCoincidenceWindow);
fFastSABREField->SetNumber(fBuilder.GetFastWindowSABRE()); fFastSABREField->SetNumber(m_parameters.fastCoincidenceWindowSABRE);
fFastICField->SetNumber(fBuilder.GetFastWindowIonChamber()); fFastICField->SetNumber(m_parameters.fastCoincidenceWindowIonCh);
fRMaxField->SetIntNumber(fBuilder.GetRunMax()); fRMaxField->SetIntNumber(m_parameters.runMax);
fRMinField->SetIntNumber(fBuilder.GetRunMin()); fRMinField->SetIntNumber(m_parameters.runMin);
} }
void EVBMainFrame::UpdateWorkdir()
{
const char* dir = fWorkField->GetText();
fBuilder.SetWorkDirectory(dir);
}
void EVBMainFrame::UpdateSMap()
{
const char* file = fSMapField->GetText();
fBuilder.SetBoardShiftFile(file);
}
void EVBMainFrame::UpdateCMap()
{
const char* file = fCMapField->GetText();
fBuilder.SetChannelMap(file);
}
void EVBMainFrame::UpdateScaler()
{
const char* file = fScalerField->GetText();
fBuilder.SetScalerFile(file);
}
void EVBMainFrame::UpdateCut()
{
const char* file = fCutField->GetText();
fBuilder.SetCutList(file);
}
void EVBMainFrame::RunPlot()
{
fBuilder.PlotHistograms();
}
void EVBMainFrame::RunMerge(const char* file, const char* dir) {}
void EVBMainFrame::DisableAllInput() void EVBMainFrame::DisableAllInput()
{ {
fRunButton->SetState(kButtonDisabled); fRunButton->SetState(kButtonDisabled);

View File

@ -1,6 +1,7 @@
#ifndef EVBMAINFRAME_H #ifndef EVBMAINFRAME_H
#define EVBMAINFRAME_H #define EVBMAINFRAME_H
#include "../EventBuilder.h"
#include <TGClient.h> #include <TGClient.h>
#include <TGWindow.h> #include <TGWindow.h>
#include <TGFrame.h> #include <TGFrame.h>
@ -38,13 +39,6 @@ public:
void DisplayCut(const char* file); void DisplayCut(const char* file);
void SaveConfig(const char* file); void SaveConfig(const char* file);
void LoadConfig(const char* file); void LoadConfig(const char* file);
void UpdateWorkdir();
void UpdateCMap();
void UpdateSMap();
void UpdateScaler();
void UpdateCut();
void RunPlot();
void RunMerge(const char* dir, const char* file);
void DisableAllInput(); void DisableAllInput();
void EnableAllInput(); void EnableAllInput();
void SetProgressBarPosition(long value, long total); void SetProgressBarPosition(long value, long total);
@ -98,11 +92,10 @@ private:
TGFileInfo* fInfo; TGFileInfo* fInfo;
EventBuilder::EVBApp fBuilder; EventBuilder::EVBApp m_builder;
EventBuilder::EVBParameters m_parameters;
int counter; int counter;
UInt_t MAIN_W, MAIN_H; UInt_t MAIN_W, MAIN_H;
}; };
#endif #endif

1
vendor/yaml-cpp vendored Submodule

@ -0,0 +1 @@
Subproject commit c73ee34704c512ebe915b283645aefa9f424a22f