diff --git a/.gitignore b/.gitignore index ae28796..be05a33 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ images/ build/ objs/ .vscode/ +lib/ ###file types to ignore### *.swp @@ -19,6 +20,7 @@ objs/ *.sublime-project *.sublime-workspace *.make +*.yaml Makefile event_log.txt .DS_Store diff --git a/.gitmodules b/.gitmodules index 18a8e2a..9ff459d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/spdlog"] path = vendor/spdlog url = https://github.com/gabime/spdlog.git +[submodule "vendor/yaml-cpp"] + path = vendor/yaml-cpp + url = https://github.com/jbeder/yaml-cpp.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a6e47c..e7e8f74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,5 @@ find_package(ROOT REQUIRED COMPONENTS Gui) set(EVB_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin) set(EVB_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib) +add_subdirectory(vendor/yaml-cpp) add_subdirectory(src) \ No newline at end of file diff --git a/README.md b/README.md index c456f17..de858d5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # SPS-SABRE Data Analysis Package Version 4 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 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. -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. ## 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. -### Building Events -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. - -#### 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. +## Details +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. ## System Requirements -- Requires ROOT >= 6.22.04 for C++17 support -- Requires CMake > 3.16 for pch suport -- This version is for data from CAEN CoMPASS > 2.0. Data from older CoMPASS versions are not compatible. \ No newline at end of file +- Requires C++17 +- Requires ROOT version which supports CMake dictionary generation and is C++17 compatible +- Requires CMake >= 3.16 +- This version is for data from CAEN CoMPASS >= 2.0. Data from older CoMPASS versions are not compatible. diff --git a/etc/ScalerFile_Feb2021_SABRE.txt b/etc/ScalerFile_Feb2021_SABRE.txt index a2f4e92..f8682ba 100644 --- a/etc/ScalerFile_Feb2021_SABRE.txt +++ b/etc/ScalerFile_Feb2021_SABRE.txt @@ -1,4 +1,3 @@ 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) -CH0@V1730_89_Data t1 -CH5@V1730_89_Data t2 \ No newline at end of file +Data_CH5@V1730_89 beamint diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/EventBuilderGuide.pdf b/example/EventBuilderGuide.pdf deleted file mode 100644 index 4231741..0000000 Binary files a/example/EventBuilderGuide.pdf and /dev/null differ diff --git a/example/analyzed/.gitignore b/example/analyzed/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/analyzed/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/cuts/.gitignore b/example/cuts/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/cuts/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/fast/.gitignore b/example/fast/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/fast/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/histograms/.gitignore b/example/histograms/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/histograms/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/raw_binary/.gitignore b/example/raw_binary/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/raw_binary/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/raw_binary/run_75.tar.gz b/example/raw_binary/run_75.tar.gz deleted file mode 100644 index 4df59f4..0000000 Binary files a/example/raw_binary/run_75.tar.gz and /dev/null differ diff --git a/example/raw_root/.gitignore b/example/raw_root/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/raw_root/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/sorted/.gitignore b/example/sorted/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/sorted/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/example/temp_binary/.gitignore b/example/temp_binary/.gitignore deleted file mode 100644 index bf58d4e..0000000 --- a/example/temp_binary/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -###Keep this dir### -!.gitignore diff --git a/input.txt b/input.txt deleted file mode 100644 index d73fd22..0000000 --- a/input.txt +++ /dev/null @@ -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 -------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8937bc4..967f02a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(spsdict) -add_subdirectory(guidict) add_subdirectory(evb) +add_subdirectory(guidict) add_executable(EventBuilder) diff --git a/src/EventBuilder.h b/src/EventBuilder.h index 30379c7..ea5c218 100644 --- a/src/EventBuilder.h +++ b/src/EventBuilder.h @@ -11,7 +11,6 @@ #include #include - //ROOT #include #include diff --git a/src/evb/CMakeLists.txt b/src/evb/CMakeLists.txt index fd518ff..f505629 100644 --- a/src/evb/CMakeLists.txt +++ b/src/evb/CMakeLists.txt @@ -1,6 +1,10 @@ add_library(EventBuilderCore STATIC) -target_include_directories(EventBuilderCore SYSTEM PUBLIC ../../vendor/spdlog/include ${ROOT_INCLUDE_DIRS} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../ +target_include_directories(EventBuilderCore + 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) @@ -30,23 +34,27 @@ target_sources(EventBuilderCore PRIVATE CompassFile.h EVBApp.h Logger.cpp - RunCollector.cpp ShiftMap.h CompassHit.h FastSort.cpp Logger.h - RunCollector.h SlowSort.cpp CompassRun.cpp FastSort.h MassLookup.cpp SFPAnalyzer.cpp SlowSort.h + EVBWorkspace.cpp + EVBWorkspace.h + EVBParameters.h ) target_link_libraries(EventBuilderCore PUBLIC SPSDict ${ROOT_LIBRARIES} + yaml-cpp ) -set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR}) \ No newline at end of file +set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR}) + +target_compile_definitions(EventBuilderCore PRIVATE YAML_CPP_STATIC_DEFINE) \ No newline at end of file diff --git a/src/evb/ChannelMap.cpp b/src/evb/ChannelMap.cpp index fcbdc8d..943ba0b 100644 --- a/src/evb/ChannelMap.cpp +++ b/src/evb/ChannelMap.cpp @@ -6,7 +6,6 @@ Written by G.W. McCann Oct. 2020 */ -#include "EventBuilder.h" #include "ChannelMap.h" namespace EventBuilder { diff --git a/src/evb/CompassFile.cpp b/src/evb/CompassFile.cpp index 67e7313..80b1d9e 100644 --- a/src/evb/CompassFile.cpp +++ b/src/evb/CompassFile.cpp @@ -8,7 +8,6 @@ Written by G.W. McCann Oct. 2020 */ -#include "EventBuilder.h" #include "CompassFile.h" namespace EventBuilder { @@ -44,7 +43,6 @@ namespace EventBuilder { m_hitUsedFlag = true; m_filename = filename; m_file->open(m_filename, std::ios::binary | std::ios::in); - m_file->seekg(0, std::ios_base::end); m_size = m_file->tellg(); if(m_size == 2) diff --git a/src/evb/CompassFile.h b/src/evb/CompassFile.h index 193bb70..573c8a5 100644 --- a/src/evb/CompassFile.h +++ b/src/evb/CompassFile.h @@ -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 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* GetUsedFlagPtr() { return &m_hitUsedFlag; } inline void AttachShiftMap(ShiftMap* map) { m_smap = map; } inline unsigned int GetSize() const { return m_size; } inline unsigned int GetNumberOfHits() const { return m_nHits; } diff --git a/src/evb/CompassRun.cpp b/src/evb/CompassRun.cpp index 6b85425..35cd7e0 100644 --- a/src/evb/CompassRun.cpp +++ b/src/evb/CompassRun.cpp @@ -9,25 +9,19 @@ Updated to also handle scaler data. -- GWM Oct. 2020 */ -#include "EventBuilder.h" #include "CompassRun.h" -#include "RunCollector.h" #include "SlowSort.h" #include "FastSort.h" #include "SFPAnalyzer.h" #include "FlagHandler.h" +#include "EVBApp.h" namespace EventBuilder { - - CompassRun::CompassRun() : - m_directory(""), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_progressFraction(0.1) + + CompassRun::CompassRun(const EVBParameters& params, const std::shared_ptr& workspace) : + m_params(params), m_workspace(workspace) { - } - - CompassRun::CompassRun(const std::string& dir) : - m_directory(dir), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_progressFraction(0.1) - { - + m_smap.SetFile(m_params.timeShiftFile); } CompassRun::~CompassRun() {} @@ -36,7 +30,7 @@ namespace EventBuilder { /*Load em into a map*/ void CompassRun::SetScalers() { - std::ifstream input(m_scalerinput); + std::ifstream input(m_params.scalerFile); if(!input.is_open()) return; @@ -49,7 +43,7 @@ namespace EventBuilder { while(input>>filename) { 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(varname.c_str(), init); } input.close(); @@ -57,17 +51,14 @@ namespace EventBuilder { bool CompassRun::GetBinaryFiles() { - std::string prefix = ""; - std::string suffix = ".BIN"; //binaries - RunCollector grabber(m_directory, prefix, suffix); - grabber.GrabAllFiles(); - + auto files = m_workspace->GetTempFiles(); + 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; m_totalHits = 0; //reset total run size - for(auto& entry : grabber.GetFileList()) + for(auto& entry : files) { //Handle scaler files, if they exist if(m_scaler_flag) @@ -123,42 +114,35 @@ namespace EventBuilder { /* 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 - 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 + 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 that index all together. In this way, the loop can go from N times to N-1 times. */ bool CompassRun::GetHitsFromFiles() { - std::pair earliestHit = std::make_pair(CompassHit(), nullptr); + //std::pair earliestHit = std::make_pair(CompassHit(), nullptr); + CompassFile* earliestHit = nullptr; for(unsigned int i=startIndex; iGetCurrentHit().timestamp) //if earlier + earliestHit = &m_datafiles[i]; } - if(earliestHit.second == nullptr) + if(earliestHit == nullptr) return false; //Make sure that there actually was a hit - hit = earliestHit.first; - *earliestHit.second = true; + m_hit = earliestHit->GetCurrentHit(); + earliestHit->SetHitHasBeenUsed(); return true; } @@ -166,12 +150,12 @@ namespace EventBuilder { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("Data", "Data"); - outtree->Branch("Board", &hit.board); - outtree->Branch("Channel", &hit.channel); - outtree->Branch("Energy", &hit.energy); - outtree->Branch("EnergyShort", &hit.energyShort); - outtree->Branch("Timestamp", &hit.timestamp); - outtree->Branch("Flags", &hit.flags); + outtree->Branch("Board", &m_hit.board); + outtree->Branch("Channel", &m_hit.channel); + outtree->Branch("Energy", &m_hit.energy); + outtree->Branch("EnergyShort", &m_hit.energyShort); + outtree->Branch("Timestamp", &m_hit.timestamp); + outtree->Branch("Flags", &m_hit.flags); if(!m_smap.IsValid()) { @@ -214,11 +198,12 @@ namespace EventBuilder { 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"); TTree* outtree = new TTree("SortTree", "SortTree"); + CoincEvent event; outtree->Branch("event", &event); if(!m_smap.IsValid()) @@ -237,7 +222,7 @@ namespace EventBuilder { unsigned int count = 0, flush = m_totalHits*m_progressFraction, flush_count = 0; startIndex = 0; - SlowSort coincidizer(window, mapfile); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); bool killFlag = false; if(flush == 0) flush = 1; @@ -257,13 +242,14 @@ namespace EventBuilder { killFlag = true; } else - coincidizer.AddHitToEvent(hit); - + coincidizer.AddHitToEvent(m_hit); + if(coincidizer.IsEventReady()) { event = coincidizer.GetEvent(); outtree->Fill(); - if(killFlag) break; + if(killFlag) + break; } } @@ -276,11 +262,12 @@ namespace EventBuilder { 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"); TTree* outtree = new TTree("SortTree", "SortTree"); + CoincEvent event; outtree->Branch("event", &event); if(!m_smap.IsValid()) @@ -301,8 +288,8 @@ namespace EventBuilder { startIndex = 0; CoincEvent this_event; std::vector fast_events; - SlowSort coincidizer(window, mapfile); - FastSort speedyCoincidizer(fsi_window, fic_window); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); + FastSort speedyCoincidizer(m_params.fastCoincidenceWindowSABRE, m_params.fastCoincidenceWindowIonCh); FlagHandler flagger; @@ -326,8 +313,8 @@ namespace EventBuilder { } else { - flagger.CheckFlag(hit.board, hit.channel, hit.flags); - coincidizer.AddHitToEvent(hit); + flagger.CheckFlag(m_hit.board, m_hit.channel, m_hit.flags); + coincidizer.AddHitToEvent(m_hit); } if(coincidizer.IsEventReady()) @@ -355,13 +342,13 @@ namespace EventBuilder { } - void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, - int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta) + void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name) { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SPSTree", "SPSTree"); + ProcessedEvent pevent; outtree->Branch("event", &pevent); if(!m_smap.IsValid()) @@ -381,20 +368,20 @@ namespace EventBuilder { startIndex = 0; CoincEvent this_event; - SlowSort coincidizer(window, mapfile); - SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); + 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> parvec; parvec.reserve(9); - parvec.emplace_back("ZT", zt); - parvec.emplace_back("AT", at); - parvec.emplace_back("ZP", zp); - parvec.emplace_back("AP", ap); - parvec.emplace_back("ZE", ze); - parvec.emplace_back("AE", ae); - parvec.emplace_back("Bfield", b); - parvec.emplace_back("BeamKE", bke); - parvec.emplace_back("Theta", theta); + parvec.emplace_back("ZT", m_params.ZT); + parvec.emplace_back("AT", m_params.AT); + parvec.emplace_back("ZP", m_params.ZP); + parvec.emplace_back("AP", m_params.AP); + parvec.emplace_back("ZE", m_params.ZE); + parvec.emplace_back("AE", m_params.AE); + parvec.emplace_back("Bfield", m_params.BField); + parvec.emplace_back("BeamKE", m_params.beamEnergy); + parvec.emplace_back("Theta", m_params.spsAngle); bool killFlag = false; if(flush == 0) @@ -416,7 +403,7 @@ namespace EventBuilder { } else { - coincidizer.AddHitToEvent(hit); + coincidizer.AddHitToEvent(m_hit); } if(coincidizer.IsEventReady()) @@ -443,13 +430,13 @@ namespace EventBuilder { output->Close(); } - void CompassRun::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) + void CompassRun::Convert2FastAnalyzedRoot(const std::string& name) { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SPSTree", "SPSTree"); + ProcessedEvent pevent; outtree->Branch("event", &pevent); if(!m_smap.IsValid()) @@ -470,21 +457,21 @@ namespace EventBuilder { startIndex = 0; CoincEvent this_event; std::vector fast_events; - SlowSort coincidizer(window, mapfile); - FastSort speedyCoincidizer(fsi_window, fic_window); - SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); + SlowSort coincidizer(m_params.slowCoincidenceWindow, m_params.channelMapFile); + FastSort speedyCoincidizer(m_params.fastCoincidenceWindowSABRE, m_params.fastCoincidenceWindowIonCh); + 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> parvec; parvec.reserve(9); - parvec.emplace_back("ZT", zt); - parvec.emplace_back("AT", at); - parvec.emplace_back("ZP", zp); - parvec.emplace_back("AP", ap); - parvec.emplace_back("ZE", ze); - parvec.emplace_back("AE", ae); - parvec.emplace_back("Bfield", b); - parvec.emplace_back("BeamKE", bke); - parvec.emplace_back("Theta", theta); + parvec.emplace_back("ZT", m_params.ZT); + parvec.emplace_back("AT", m_params.AT); + parvec.emplace_back("ZP", m_params.ZP); + parvec.emplace_back("AP", m_params.AP); + parvec.emplace_back("ZE", m_params.ZE); + parvec.emplace_back("AE", m_params.AE); + parvec.emplace_back("Bfield", m_params.BField); + parvec.emplace_back("BeamKE", m_params.beamEnergy); + parvec.emplace_back("Theta", m_params.spsAngle); FlagHandler flagger; @@ -508,8 +495,8 @@ namespace EventBuilder { } else { - flagger.CheckFlag(hit.board, hit.channel, hit.flags); - coincidizer.AddHitToEvent(hit); + flagger.CheckFlag(m_hit.board, m_hit.channel, m_hit.flags); + coincidizer.AddHitToEvent(m_hit); } if(coincidizer.IsEventReady()) diff --git a/src/evb/CompassRun.h b/src/evb/CompassRun.h index 8651e4e..780f662 100644 --- a/src/evb/CompassRun.h +++ b/src/evb/CompassRun.h @@ -12,9 +12,10 @@ #include "CompassFile.h" #include "DataStructs.h" -#include "RunCollector.h" #include "ShiftMap.h" #include "ProgressCallback.h" +#include "EVBWorkspace.h" +#include "EVBParameters.h" #include namespace EventBuilder { @@ -23,20 +24,14 @@ namespace EventBuilder { { public: - CompassRun(); - CompassRun(const std::string& dir); + CompassRun(const EVBParameters& params, const std::shared_ptr& workspace); ~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 SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); } void Convert2RawRoot(const std::string& name); - void Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window); - void Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window); - void Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, - int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta); - 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); + void Convert2SortedRoot(const std::string& name); + void Convert2FastSortedRoot(const std::string& name); + void Convert2SlowAnalyzedRoot(const std::string& name); + void Convert2FastAnalyzedRoot(const std::string& name); inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; } inline void SetProgressFraction(double frac) { m_progressFraction = frac; } @@ -46,17 +41,17 @@ namespace EventBuilder { bool GetHitsFromFiles(); void SetScalers(); void ReadScalerData(const std::string& filename); + + EVBParameters m_params; + std::shared_ptr m_workspace; - std::string m_directory, m_scalerinput; std::vector m_datafiles; unsigned int startIndex; //this is the file we start looking at; increases as we finish files. ShiftMap m_smap; std::unordered_map> m_scaler_map; //maps scaler files to the TParameter to be saved - //Potential branch variables - CompassHit hit; - CoincEvent event; - ProcessedEvent pevent; + //Raw hit + CompassHit m_hit; //what run is this int m_runNum; diff --git a/src/evb/CutHandler.cpp b/src/evb/CutHandler.cpp index 520f98f..c3a4cbd 100644 --- a/src/evb/CutHandler.cpp +++ b/src/evb/CutHandler.cpp @@ -1,4 +1,3 @@ -#include "EventBuilder.h" #include "CutHandler.h" namespace EventBuilder { diff --git a/src/evb/EVBApp.cpp b/src/evb/EVBApp.cpp index 38fafdb..1347e25 100644 --- a/src/evb/EVBApp.cpp +++ b/src/evb/EVBApp.cpp @@ -6,22 +6,16 @@ Written by G.W. McCann Oct. 2020 */ -#include "EventBuilder.h" #include #include "EVBApp.h" -#include "RunCollector.h" #include "CompassRun.h" -#include "SlowSort.h" -#include "FastSort.h" -#include "SFPAnalyzer.h" #include "SFPPlotter.h" +#include "yaml-cpp/yaml.h" namespace EventBuilder { 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_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) + m_workspace(nullptr), m_progressFraction(0.1) { SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBApp::DefaultProgressCallback)); } @@ -36,48 +30,59 @@ namespace EventBuilder { 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) { EVB_INFO("Reading in EVB configuration from file {0}...", fullpath); - std::ifstream input(fullpath); - if(!input.is_open()) + YAML::Node data; + 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; } - std::string junk; - - std::getline(input, junk); - input>>junk>>m_workspace; - input>>junk; - std::getline(input, junk); - std::getline(input, junk); - input>>junk>>m_mapfile; - input>>junk>>m_scalerfile; - input>>junk>>m_cutList; - input>>junk>>m_ZT>>junk>>m_AT; - input>>junk>>m_ZP>>junk>>m_AP; - input>>junk>>m_ZE>>junk>>m_AE; - input>>junk>>m_B; - input>>junk>>m_BKE; - input>>junk>>m_Theta; - input>>junk; - std::getline(input, junk); - std::getline(input, junk); - 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(); + m_params.workspaceDir = data["WorkspaceDir"].as(); + m_params.channelMapFile = data["ChannelMap"].as(); + m_params.scalerFile = data["ScalerFile"].as(); + m_params.cutListFile = data["CutListFile"].as(); + m_params.timeShiftFile = data["TimeShiftFile"].as(); + m_params.slowCoincidenceWindow = data["SlowCoincidenceWindow(ps)"].as(); + m_params.fastCoincidenceWindowIonCh = data["FastCoincidenceWinowIonCh(ps)"].as(); + m_params.fastCoincidenceWindowSABRE = data["FastCoincidenceWinowSABRE(ps)"].as(); + m_params.ZT = data["ZT"].as(); + m_params.AT = data["AT"].as(); + m_params.ZP = data["ZP"].as(); + m_params.AP = data["AP"].as(); + m_params.ZE = data["ZE"].as(); + m_params.AE = data["AE"].as(); + m_params.BField = data["BField(kG)"].as(); + m_params.beamEnergy = data["BeamEnergy(MeV)"].as(); + m_params.spsAngle = data["SPSAngle(deg)"].as(); + m_params.runMin = data["MinRun"].as(); + m_params.runMax = data["MaxRun"].as(); 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; } @@ -91,35 +96,32 @@ namespace EventBuilder { EVB_WARN("Failed to write to config to file {0}, unable to open file!", fullpath); return; } - - output<<"-------Data Location----------"<IsValid()) + { + 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; grammer.SetProgressCallbackFunc(m_progressCallback); grammer.SetProgressFraction(m_progressFraction); - grammer.ApplyCutlist(m_cutList); - EVB_INFO("Generating histograms from analyzed runs [{0}, {1}] with Cut List {2}...", m_rmin, m_rmax, m_cutList); + grammer.ApplyCutlist(m_params.cutListFile); + 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); - grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax); - if(grabber.GrabFilesInRange()) + auto files = m_workspace->GetAnalyzedRunRange(m_params.runMin, m_params.runMax); + if(files.size() > 0) { - grammer.Run(grabber.GetFileList(), plot_file); + grammer.Run(files, plot_file); EVB_INFO("Finished."); } else @@ -151,56 +157,56 @@ namespace EventBuilder { void EVBApp::Convert2RawRoot() { - int sys_return; - std::string rawroot_dir = m_workspace+"/raw_root/"; - std::string unpack_dir = m_workspace+"/temp_binary/"; - 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); + if(m_workspace == nullptr || !m_workspace->IsValid()) + { + EVB_ERROR("Unable to preform event building request due to bad workspace."); + } + + 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; - std::string unpack_command, wipe_command; - - CompassRun converter(unpack_dir); - converter.SetShiftMap(m_shiftfile); - converter.SetScalerInput(m_scalerfile); + CompassRun converter(m_params, m_workspace); converter.SetProgressCallbackFunc(m_progressCallback); converter.SetProgressFraction(m_progressFraction); 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"; - unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; - wipe_command = "rm -r "+unpack_dir+"*.BIN"; - - sys_return = system(unpack_command.c_str()); - converter.Convert2RawRoot(rawfile); - sys_return = system(wipe_command.c_str()); - + EVB_INFO("Converting file {0}...", rawfile); + m_workspace->ClearTempDirectory(); //In case something weird happened + if(m_workspace->UnpackBinaryRunToTemp(i)) + { + converter.SetRunNumber(i); + 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() { - std::string merge_file = m_workspace+"/merged/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root"; - 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)) + if(m_workspace == nullptr || !m_workspace->IsValid()) { - 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; } EVB_INFO("Finished."); @@ -208,207 +214,157 @@ namespace EventBuilder { void EVBApp::Convert2SortedRoot() { - int sys_return; - 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++) + if(m_workspace == nullptr || !m_workspace->IsValid()) { - 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.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow); - sys_return = system(wipe_command.c_str()); - count++; + EVB_ERROR("Unable to preform event building request due to bad workspace."); } - 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 unpack_command, wipe_command; + 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.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); - converter.SetShiftMap(m_shiftfile); - converter.SetScalerInput(m_scalerfile); + void EVBApp::Convert2FastSortedRoot() + { + 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.SetProgressFraction(m_progressFraction); EVB_INFO("Beginning conversion..."); - int count=0; - 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); - - 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.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++; + 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.Convert2FastSortedRoot(sortfile); + ++count; + } + m_workspace->ClearTempDirectory(); } - if(count==0) - EVB_WARN("Conversion failed, no archives were found!"); - else + + 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::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() { - 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 fast event built ROOT files over run range [{0}, {1}]",m_rmin,m_rmax); + 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 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 unpack_command, wipe_command; + std::string sortfile; - CompassRun converter(unpack_dir); - converter.SetShiftMap(m_shiftfile); - converter.SetScalerInput(m_scalerfile); + 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_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); - - 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.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++; + 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.Convert2FastAnalyzedRoot(sortfile); + ++count; + } + m_workspace->ClearTempDirectory(); } - if(count==0) - EVB_WARN("Conversion failed, no archives were found!"); - else + + 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); } - - 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; } } \ No newline at end of file diff --git a/src/evb/EVBApp.h b/src/evb/EVBApp.h index fec4000..859bbf7 100644 --- a/src/evb/EVBApp.h +++ b/src/evb/EVBApp.h @@ -9,7 +9,8 @@ #ifndef EVBAPP_H #define EVBAPP_H -#include "RunCollector.h" +#include "EVBParameters.h" +#include "EVBWorkspace.h" #include "ProgressCallback.h" namespace EventBuilder { @@ -25,44 +26,14 @@ namespace EventBuilder { void PlotHistograms(); void MergeROOTFiles(); + void Convert2RawRoot(); void Convert2SortedRoot(); void Convert2FastSortedRoot(); - void Convert2RawRoot(); void Convert2SlowAnalyzedRoot(); void Convert2FastAnalyzedRoot(); - void SetRunRange(int rmin, int rmax); - void SetWorkDirectory(const std::string& fullpath); - 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 SetParameters(const EVBParameters& params); + inline EVBParameters& GetParameters() { return m_params; } void DefaultProgressCallback(long curVal, long totalVal); inline void SetProgressCallbackFunc(const ProgressCallbackFunc& function) { m_progressCallback = function; } @@ -80,23 +51,9 @@ namespace EventBuilder { }; private: - - int m_rmin, m_rmax; - int m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_ZR, m_AR; - double m_B, m_Theta, m_BKE; + EVBParameters m_params; + std::shared_ptr m_workspace; 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; }; diff --git a/src/evb/EVBParameters.h b/src/evb/EVBParameters.h new file mode 100644 index 0000000..551336c --- /dev/null +++ b/src/evb/EVBParameters.h @@ -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 \ No newline at end of file diff --git a/src/evb/EVBWorkspace.cpp b/src/evb/EVBWorkspace.cpp new file mode 100644 index 0000000..e0675b8 --- /dev/null +++ b/src/evb/EVBWorkspace.cpp @@ -0,0 +1,204 @@ +#include "EVBWorkspace.h" +#include +#include +#include + +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 EVBWorkspace::GetBinaryRunRange(int runMin, int runMax) + { + std::vector 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 EVBWorkspace::GetAnalyzedRunRange(int runMin, int runMax) + { + std::vector 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 EVBWorkspace::GetTempFiles() + { + std::vector 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 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; iIsOpen()) + { + 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; + } +} \ No newline at end of file diff --git a/src/evb/EVBWorkspace.h b/src/evb/EVBWorkspace.h new file mode 100644 index 0000000..91ee784 --- /dev/null +++ b/src/evb/EVBWorkspace.h @@ -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 GetBinaryRunRange(int runMin, int runMax); + std::vector GetAnalyzedRunRange(int runMin, int runMax); + + bool UnpackBinaryRunToTemp(int run); //Currently Linux/MacOS only. Windows support to come. + std::vector 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 \ No newline at end of file diff --git a/src/evb/FP_kinematics.cpp b/src/evb/FP_kinematics.cpp index 88b892b..5a6cdfa 100644 --- a/src/evb/FP_kinematics.cpp +++ b/src/evb/FP_kinematics.cpp @@ -31,7 +31,6 @@ */ -#include "EventBuilder.h" #include #include "MassLookup.h" #include "FP_kinematics.h" diff --git a/src/evb/FastSort.cpp b/src/evb/FastSort.cpp index 1452b70..3f8a7c4 100644 --- a/src/evb/FastSort.cpp +++ b/src/evb/FastSort.cpp @@ -1,4 +1,3 @@ -#include "EventBuilder.h" #include "FastSort.h" namespace EventBuilder { diff --git a/src/evb/FlagHandler.cpp b/src/evb/FlagHandler.cpp index 52b0cb0..5ae547a 100644 --- a/src/evb/FlagHandler.cpp +++ b/src/evb/FlagHandler.cpp @@ -1,4 +1,3 @@ -#include "EventBuilder.h" #include "FlagHandler.h" namespace EventBuilder { diff --git a/src/evb/Logger.cpp b/src/evb/Logger.cpp index b3b76e3..3fdcdee 100644 --- a/src/evb/Logger.cpp +++ b/src/evb/Logger.cpp @@ -1,4 +1,3 @@ -#include "EventBuilder.h" #include "spdlog/sinks/stdout_color_sinks.h" namespace EventBuilder { diff --git a/src/evb/MassLookup.cpp b/src/evb/MassLookup.cpp index 4352589..972f5de 100644 --- a/src/evb/MassLookup.cpp +++ b/src/evb/MassLookup.cpp @@ -8,7 +8,6 @@ of this map (MASS) for use throughout code it is included into. Written by G.W. McCann Aug. 2020 */ -#include "EventBuilder.h" #include "MassLookup.h" namespace EventBuilder { diff --git a/src/evb/OrderChecker.cpp b/src/evb/OrderChecker.cpp index 4beddb7..0032a30 100644 --- a/src/evb/OrderChecker.cpp +++ b/src/evb/OrderChecker.cpp @@ -5,7 +5,6 @@ Written by G.W. McCann Oct. 2020 */ -#include "EventBuilder.h" #include "OrderChecker.h" namespace EventBuilder { diff --git a/src/evb/RunCollector.cpp b/src/evb/RunCollector.cpp deleted file mode 100644 index 3c983e1..0000000 --- a/src/evb/RunCollector.cpp +++ /dev/null @@ -1,232 +0,0 @@ -#include "EventBuilder.h" -#include "RunCollector.h" -#include -#include -#include -#include -#include -#include - -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; iAdd(m_filelist[i].c_str()); - chain->Merge(output,0,"fast"); - return true; - } - else - return false; - } - else - { - if(GrabFilesInRange()) - { - for(unsigned int i=0; iAdd(m_filelist[i].c_str()); - chain->Merge(output,0,"fast"); - return true; - } else - return false; - } - - if(output->IsOpen()) - output->Close(); - return false; - } - -} \ No newline at end of file diff --git a/src/evb/RunCollector.h b/src/evb/RunCollector.h deleted file mode 100644 index 02822db..0000000 --- a/src/evb/RunCollector.h +++ /dev/null @@ -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& 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 m_filelist; - - }; - -} -#endif diff --git a/src/evb/SFPAnalyzer.cpp b/src/evb/SFPAnalyzer.cpp index a4524bc..2196563 100644 --- a/src/evb/SFPAnalyzer.cpp +++ b/src/evb/SFPAnalyzer.cpp @@ -9,7 +9,6 @@ * * Position calibrations swapped as of Aug. 2021 due to detector fixes -- GWM */ -#include "EventBuilder.h" #include "SFPAnalyzer.h" namespace EventBuilder { @@ -18,7 +17,7 @@ namespace EventBuilder { SFPAnalyzer::SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, 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(); rootObj = new THashTable(); GetWeights(); diff --git a/src/evb/SFPPlotter.cpp b/src/evb/SFPPlotter.cpp index b19da12..3752199 100644 --- a/src/evb/SFPPlotter.cpp +++ b/src/evb/SFPPlotter.cpp @@ -6,7 +6,6 @@ *Created Jan 2020 by GWM */ -#include "EventBuilder.h" #include "SFPPlotter.h" #include diff --git a/src/evb/ShiftMap.cpp b/src/evb/ShiftMap.cpp index 91b8eda..b7c56e5 100644 --- a/src/evb/ShiftMap.cpp +++ b/src/evb/ShiftMap.cpp @@ -9,7 +9,6 @@ Written by G.W. McCann Oct. 2020 */ -#include "EventBuilder.h" #include "ShiftMap.h" namespace EventBuilder { diff --git a/src/evb/SlowSort.cpp b/src/evb/SlowSort.cpp index c4e7489..e58b7c7 100644 --- a/src/evb/SlowSort.cpp +++ b/src/evb/SlowSort.cpp @@ -7,7 +7,6 @@ * *Refurbished and updated Jan 2020 GWM */ -#include "EventBuilder.h" #include "SlowSort.h" namespace EventBuilder { diff --git a/src/evb/Stopwatch.cpp b/src/evb/Stopwatch.cpp index 95feb6e..8447d56 100644 --- a/src/evb/Stopwatch.cpp +++ b/src/evb/Stopwatch.cpp @@ -5,7 +5,6 @@ Written by G.W. McCann Oct. 2020 */ -#include "EventBuilder.h" #include "Stopwatch.h" namespace EventBuilder { diff --git a/src/guidict/EVBMainFrame.cpp b/src/guidict/EVBMainFrame.cpp index 1e5203f..14ddf11 100644 --- a/src/guidict/EVBMainFrame.cpp +++ b/src/guidict/EVBMainFrame.cpp @@ -29,7 +29,6 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) : TGLabel* workLabel = new TGLabel(WorkFrame, "Workspace Directory:"); fWorkField = new TGTextEntry(WorkFrame, new TGTextBuffer(120), WorkDir); fWorkField->Resize(w*0.25, fWorkField->GetDefaultHeight()); - fWorkField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateWorkdir()"); fOpenWorkButton = new TGTextButton(WorkFrame, "Open"); fOpenWorkButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenWorkdir()"); 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:"); fCMapField = new TGTextEntry(CMapFrame, new TGTextBuffer(120), Cmap); fCMapField->Resize(w*0.25, fCMapField->GetDefaultHeight()); - fCMapField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateCMap()"); fOpenCMapButton = new TGTextButton(CMapFrame, "Open"); fOpenCMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCMapfile()"); 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:"); fSMapField = new TGTextEntry(SMapFrame, new TGTextBuffer(120), Smap); fSMapField->Resize(w*0.25, fSMapField->GetDefaultHeight()); - fSMapField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateSMap()"); fOpenSMapButton = new TGTextButton(SMapFrame, "Open"); fOpenSMapButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenSMapfile()"); 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); TGLabel* sclabel = new TGLabel(ScalerFrame, "Scaler File: "); fScalerField = new TGTextEntry(ScalerFrame, new TGTextBuffer(120), Scaler); - fScalerField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateScaler()"); fOpenScalerButton = new TGTextButton(ScalerFrame, "Open"); fOpenScalerButton->Connect("Clicked()","EVBMainFrame", this, "DoOpenScalerfile()"); 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); TGLabel* clabel = new TGLabel(CutFrame, "Cut List: "); fCutField = new TGTextEntry(CutFrame, new TGTextBuffer(120), Cut); - fCutField->Connect("ReturnPressed()","EVBMainFrame",this,"UpdateCut()"); fOpenCutButton = new TGTextButton(CutFrame, "Open"); fOpenCutButton->Connect("Clicked()","EVBMainFrame",this,"DoOpenCutfile()"); 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(fBKEField, fhints); 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); bfFrame->AddFrame(bfieldlabel, lhints); 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(PBFrame, fpbhints); - fBuilder.SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBMainFrame::SetProgressBarPosition)); - fBuilder.SetProgressFraction(0.01); + m_builder.SetProgressCallbackFunc(BIND_PROGRESS_CALLBACK_FUNCTION(EVBMainFrame::SetProgressBarPosition)); + m_builder.SetProgressFraction(0.01); SetWindowName("GWM Event Builder"); MapSubwindows(); Resize(); @@ -291,7 +286,12 @@ void EVBMainFrame::HandleMenuSelection(int id) 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() @@ -335,37 +335,37 @@ void EVBMainFrame::DoRun() { case EventBuilder::EVBApp::Operation::Plot : { - RunPlot(); + m_builder.PlotHistograms(); break; } case EventBuilder::EVBApp::Operation::Convert : { - fBuilder.Convert2RawRoot(); + m_builder.Convert2RawRoot(); break; } case EventBuilder::EVBApp::Operation::Merge : { - fBuilder.MergeROOTFiles(); + m_builder.MergeROOTFiles(); break; } case EventBuilder::EVBApp::Operation::ConvertSlow : { - fBuilder.Convert2SortedRoot(); + m_builder.Convert2SortedRoot(); break; } case EventBuilder::EVBApp::Operation::ConvertFast : { - fBuilder.Convert2FastSortedRoot(); + m_builder.Convert2FastSortedRoot(); break; } case EventBuilder::EVBApp::Operation::ConvertSlowA : { - fBuilder.Convert2SlowAnalyzedRoot(); + m_builder.Convert2SlowAnalyzedRoot(); break; } case EventBuilder::EVBApp::Operation::ConvertFastA : { - fBuilder.Convert2FastAnalyzedRoot(); + m_builder.Convert2FastAnalyzedRoot(); break; } } @@ -380,126 +380,97 @@ void EVBMainFrame::HandleTypeSelection(int box, int entry) bool EVBMainFrame::SetParameters() { - fBuilder.SetRunRange(fRMinField->GetIntNumber(), fRMaxField->GetIntNumber()); - fBuilder.SetSlowCoincidenceWindow(fSlowWindowField->GetNumber()); - fBuilder.SetFastWindowIonChamber(fFastICField->GetNumber()); - fBuilder.SetFastWindowSABRE(fFastSABREField->GetNumber()); - UpdateWorkdir(); - UpdateSMap(); - UpdateCMap(); - UpdateScaler(); - UpdateCut(); - bool test = fBuilder.SetKinematicParameters(fZTField->GetIntNumber(), fATField->GetIntNumber(), - fZPField->GetIntNumber(), fAPField->GetIntNumber(), - fZEField->GetIntNumber(), fAEField->GetIntNumber(), - fBField->GetNumber(), fThetaField->GetNumber(), - fBKEField->GetNumber()); - return test; + m_parameters.runMin = fRMinField->GetIntNumber(); + m_parameters.runMax = fRMaxField->GetIntNumber(); + m_parameters.slowCoincidenceWindow = fSlowWindowField->GetNumber(); + m_parameters.fastCoincidenceWindowIonCh = fFastICField->GetNumber(); + m_parameters.fastCoincidenceWindowSABRE = fFastSABREField->GetNumber(); + m_parameters.workspaceDir = fWorkField->GetText(); + m_parameters.channelMapFile = fCMapField->GetText(); + m_parameters.scalerFile = fScalerField->GetText(); + m_parameters.timeShiftFile = fSMapField->GetText(); + m_parameters.cutListFile = fCutField->GetText(); + m_parameters.ZT = fZTField->GetIntNumber(); + m_parameters.AT = fATField->GetIntNumber(); + m_parameters.ZP = fZPField->GetIntNumber(); + m_parameters.AP = fAPField->GetIntNumber(); + 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) { fWorkField->SetText(dir); - fBuilder.SetWorkDirectory(dir); + SetParameters(); } void EVBMainFrame::DisplayCMap(const char* file) { fCMapField->SetText(file); - fBuilder.SetChannelMap(file); + SetParameters(); } void EVBMainFrame::DisplaySMap(const char* file) { fSMapField->SetText(file); - fBuilder.SetBoardShiftFile(file); + SetParameters(); } void EVBMainFrame::DisplayScaler(const char* file) { fScalerField->SetText(file); - fBuilder.SetScalerFile(file); + SetParameters(); } void EVBMainFrame::DisplayCut(const char* file) { fCutField->SetText(file); - fBuilder.SetCutList(file); + SetParameters(); } void EVBMainFrame::SaveConfig(const char* file) { std::string filename = file; - fBuilder.WriteConfigFile(filename); + m_builder.WriteConfigFile(filename); } void EVBMainFrame::LoadConfig(const char* file) { std::string filename = file; - fBuilder.ReadConfigFile(filename); + m_builder.ReadConfigFile(filename); + m_parameters = m_builder.GetParameters(); - fWorkField->SetText(fBuilder.GetWorkDirectory().c_str()); - fCMapField->SetText(fBuilder.GetChannelMap().c_str()); - fSMapField->SetText(fBuilder.GetBoardShiftFile().c_str()); - fCutField->SetText(fBuilder.GetCutList().c_str()); - fScalerField->SetText(fBuilder.GetScalerFile().c_str()); + fWorkField->SetText(m_parameters.workspaceDir.c_str()); + fCMapField->SetText(m_parameters.channelMapFile.c_str()); + fSMapField->SetText(m_parameters.timeShiftFile.c_str()); + fCutField->SetText(m_parameters.cutListFile.c_str()); + fScalerField->SetText(m_parameters.scalerFile.c_str()); - fZTField->SetIntNumber(fBuilder.GetTargetZ()); - fATField->SetIntNumber(fBuilder.GetTargetA()); - fZPField->SetIntNumber(fBuilder.GetProjectileZ()); - fAPField->SetIntNumber(fBuilder.GetProjectileA()); - fZEField->SetIntNumber(fBuilder.GetEjectileZ()); - fAEField->SetIntNumber(fBuilder.GetEjectileA()); - fBKEField->SetNumber(fBuilder.GetBeamKE()); - fBField->SetNumber(fBuilder.GetBField()); - fThetaField->SetNumber(fBuilder.GetTheta()); + fZTField->SetIntNumber(m_parameters.ZT); + fATField->SetIntNumber(m_parameters.AT); + fZPField->SetIntNumber(m_parameters.ZP); + fAPField->SetIntNumber(m_parameters.AP); + fZEField->SetIntNumber(m_parameters.ZE); + fAEField->SetIntNumber(m_parameters.AE); + fBKEField->SetNumber(m_parameters.beamEnergy); + fBField->SetNumber(m_parameters.BField); + fThetaField->SetNumber(m_parameters.spsAngle); - fSlowWindowField->SetNumber(fBuilder.GetSlowCoincidenceWindow()); - fFastSABREField->SetNumber(fBuilder.GetFastWindowSABRE()); - fFastICField->SetNumber(fBuilder.GetFastWindowIonChamber()); + fSlowWindowField->SetNumber(m_parameters.slowCoincidenceWindow); + fFastSABREField->SetNumber(m_parameters.fastCoincidenceWindowSABRE); + fFastICField->SetNumber(m_parameters.fastCoincidenceWindowIonCh); - fRMaxField->SetIntNumber(fBuilder.GetRunMax()); - fRMinField->SetIntNumber(fBuilder.GetRunMin()); + fRMaxField->SetIntNumber(m_parameters.runMax); + 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() { fRunButton->SetState(kButtonDisabled); diff --git a/src/guidict/EVBMainFrame.h b/src/guidict/EVBMainFrame.h index 0afb519..afc510c 100644 --- a/src/guidict/EVBMainFrame.h +++ b/src/guidict/EVBMainFrame.h @@ -1,6 +1,7 @@ #ifndef EVBMAINFRAME_H #define EVBMAINFRAME_H +#include "../EventBuilder.h" #include #include #include @@ -38,13 +39,6 @@ public: void DisplayCut(const char* file); void SaveConfig(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 EnableAllInput(); void SetProgressBarPosition(long value, long total); @@ -98,11 +92,10 @@ private: TGFileInfo* fInfo; - EventBuilder::EVBApp fBuilder; + EventBuilder::EVBApp m_builder; + EventBuilder::EVBParameters m_parameters; int counter; UInt_t MAIN_W, MAIN_H; - - }; #endif diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000 index 0000000..c73ee34 --- /dev/null +++ b/vendor/yaml-cpp @@ -0,0 +1 @@ +Subproject commit c73ee34704c512ebe915b283645aefa9f424a22f