From b9ed82a5939036d911a6c03abc2cd1f6f848ffd6 Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Wed, 15 Dec 2021 12:08:12 -0500 Subject: [PATCH] Namespace encapsulated evb with name EventBuilder --- README.md | 4 +- include/EVBMainFrame.h | 2 +- src/evb/ChannelMap.cpp | 161 ++--- src/evb/ChannelMap.h | 121 ++-- src/evb/CompassFile.cpp | 288 ++++----- src/evb/CompassFile.h | 103 +-- src/evb/CompassHit.h | 24 +- src/evb/CompassRun.cpp | 1150 +++++++++++++++++----------------- src/evb/CompassRun.h | 100 +-- src/evb/CutHandler.cpp | 186 +++--- src/evb/CutHandler.h | 43 +- src/evb/EVBApp.cpp | 812 ++++++++++++------------ src/evb/EVBApp.h | 165 ++--- src/evb/FP_kinematics.cpp | 127 ++-- src/evb/FP_kinematics.h | 14 +- src/evb/FastSort.cpp | 241 +++---- src/evb/FastSort.h | 43 +- src/evb/FlagHandler.cpp | 198 +++--- src/evb/FlagHandler.h | 109 ++-- src/evb/MassLookup.cpp | 114 ++-- src/evb/MassLookup.h | 42 +- src/evb/OrderChecker.cpp | 54 +- src/evb/OrderChecker.h | 18 +- src/evb/RunCollector.cpp | 390 ++++++------ src/evb/RunCollector.h | 59 +- src/evb/SFPAnalyzer.cpp | 359 +++++------ src/evb/SFPAnalyzer.h | 55 +- src/evb/SFPPlotter.cpp | 528 ++++++++-------- src/evb/SFPPlotter.h | 54 +- src/evb/ShiftMap.cpp | 122 ++-- src/evb/ShiftMap.h | 40 +- src/evb/SlowSort.cpp | 318 +++++----- src/evb/SlowSort.h | 66 +- src/evb/Stopwatch.cpp | 52 +- src/evb/Stopwatch.h | 32 +- src/gui_main.cpp | 4 +- src/guidict/EVBMainFrame.cpp | 28 +- src/guidict/EVBMainFrame.h | 2 +- src/main.cpp | 10 +- 39 files changed, 3177 insertions(+), 3061 deletions(-) diff --git a/README.md b/README.md index 5de58cd..fb8a81a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ Then, in the `build` directory, run the following command to build and install t `cmake -DCMAKE_BUILD_TYPE=Release .. && make install` -This will compile and link all event builder programs and dependencies. The executables will be installed to the `bin` directory of the SPS_SABRE_EventBuilder directory, shared libraries for ROOT dictionaries will be in the `lib` directory (with necessary .pcm files), and the header files for the shared libraries will be installed to the `include` directory. +This will compile and link all event builder programs and dependencies. The executables will be installed to the `bin` directory of the SPS_SABRE_EventBuilder directory, shared libraries for ROOT dictionaries will be in the `lib` directory (with necessary .pcm files), and the header files for the shared libraries will be installed to the `include` directory. To rebuild the program after a change to the code (assuming no files were added), simply run + +`make clean && make install` ## GWMEVB vs. GWMEVB_CL 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. diff --git a/include/EVBMainFrame.h b/include/EVBMainFrame.h index 56322ad..27b56db 100644 --- a/include/EVBMainFrame.h +++ b/include/EVBMainFrame.h @@ -94,7 +94,7 @@ private: TGPopupMenu *fFileMenu; - EVBApp fBuilder; + EventBuilder::EVBApp fBuilder; int counter; UInt_t MAIN_W, MAIN_H; diff --git a/src/evb/ChannelMap.cpp b/src/evb/ChannelMap.cpp index 8295272..fcbdc8d 100644 --- a/src/evb/ChannelMap.cpp +++ b/src/evb/ChannelMap.cpp @@ -9,86 +9,89 @@ #include "EventBuilder.h" #include "ChannelMap.h" -ChannelMap::ChannelMap() : - m_validFlag(false) -{ -} +namespace EventBuilder { -ChannelMap::ChannelMap(const std::string& name) : - m_validFlag(false) -{ - FillMap(name); -} - -ChannelMap::~ChannelMap() {} - -bool ChannelMap::FillMap(const std::string& name) -{ - std::ifstream input(name); - if(!input.is_open()) + ChannelMap::ChannelMap() : + m_validFlag(false) { - m_validFlag = false; + } + + ChannelMap::ChannelMap(const std::string& name) : + m_validFlag(false) + { + FillMap(name); + } + + ChannelMap::~ChannelMap() {} + + bool ChannelMap::FillMap(const std::string& name) + { + std::ifstream input(name); + if(!input.is_open()) + { + m_validFlag = false; + return m_validFlag; + } + std::string junk, type, partname; + int gchan, id; + + std::getline(input, junk); + std::getline(input, junk); + Channel this_chan; + while(input>>gchan) + { + //Set default values + this_chan.type = DetType::NoneType; + this_chan.local_channel = -1; + this_chan.attribute = DetAttribute::NoneAttr; + input>>id>>type>>partname; + if(type == "SABRERING") + { + this_chan.type = DetType::Sabre; + switch(id) + { + case 0: this_chan.attribute = DetAttribute::SabreRing0; break; + case 1: this_chan.attribute = DetAttribute::SabreRing1; break; + case 2: this_chan.attribute = DetAttribute::SabreRing2; break; + case 3: this_chan.attribute = DetAttribute::SabreRing3; break; + case 4: this_chan.attribute = DetAttribute::SabreRing4; break; + } + this_chan.local_channel = std::stoi(partname); + } + else if(type == "SABREWEDGE") + { + this_chan.type = DetType::Sabre; + switch(id) + { + case 0: this_chan.attribute = DetAttribute::SabreWedge0; break; + case 1: this_chan.attribute = DetAttribute::SabreWedge1; break; + case 2: this_chan.attribute = DetAttribute::SabreWedge2; break; + case 3: this_chan.attribute = DetAttribute::SabreWedge3; break; + case 4: this_chan.attribute = DetAttribute::SabreWedge4; break; + } + this_chan.local_channel = std::stoi(partname); + } + else if (type == "FOCALPLANE") + { + this_chan.type = DetType::FocalPlane; + this_chan.local_channel = id; + if(partname == "SCINTRIGHT") this_chan.attribute = DetAttribute::ScintRight; + else if(partname == "SCINTLEFT") this_chan.attribute = DetAttribute::ScintLeft; + else if(partname == "DELAYFR") this_chan.attribute = DetAttribute::DelayFR; + else if(partname == "DELAYFL") this_chan.attribute = DetAttribute::DelayFL; + else if(partname == "DELAYBR") this_chan.attribute = DetAttribute::DelayBR; + else if(partname == "DELAYBL") this_chan.attribute = DetAttribute::DelayBL; + else if(partname == "CATHODE") this_chan.attribute = DetAttribute::Cathode; + else if(partname == "ANODEFRONT") this_chan.attribute = DetAttribute::AnodeFront; + else if(partname == "ANODEBACK") this_chan.attribute = DetAttribute::AnodeBack; + else if(partname == "MONITOR") this_chan.attribute = DetAttribute::Monitor; + } + + m_cmap[gchan] = this_chan; + } + + input.close(); + m_validFlag = true; return m_validFlag; } - std::string junk, type, partname; - int gchan, id; - - std::getline(input, junk); - std::getline(input, junk); - Channel this_chan; - while(input>>gchan) - { - //Set default values - this_chan.type = DetType::NoneType; - this_chan.local_channel = -1; - this_chan.attribute = DetAttribute::NoneAttr; - input>>id>>type>>partname; - if(type == "SABRERING") - { - this_chan.type = DetType::Sabre; - switch(id) - { - case 0: this_chan.attribute = DetAttribute::SabreRing0; break; - case 1: this_chan.attribute = DetAttribute::SabreRing1; break; - case 2: this_chan.attribute = DetAttribute::SabreRing2; break; - case 3: this_chan.attribute = DetAttribute::SabreRing3; break; - case 4: this_chan.attribute = DetAttribute::SabreRing4; break; - } - this_chan.local_channel = std::stoi(partname); - } - else if(type == "SABREWEDGE") - { - this_chan.type = DetType::Sabre; - switch(id) - { - case 0: this_chan.attribute = DetAttribute::SabreWedge0; break; - case 1: this_chan.attribute = DetAttribute::SabreWedge1; break; - case 2: this_chan.attribute = DetAttribute::SabreWedge2; break; - case 3: this_chan.attribute = DetAttribute::SabreWedge3; break; - case 4: this_chan.attribute = DetAttribute::SabreWedge4; break; - } - this_chan.local_channel = std::stoi(partname); - } - else if (type == "FOCALPLANE") - { - this_chan.type = DetType::FocalPlane; - this_chan.local_channel = id; - if(partname == "SCINTRIGHT") this_chan.attribute = DetAttribute::ScintRight; - else if(partname == "SCINTLEFT") this_chan.attribute = DetAttribute::ScintLeft; - else if(partname == "DELAYFR") this_chan.attribute = DetAttribute::DelayFR; - else if(partname == "DELAYFL") this_chan.attribute = DetAttribute::DelayFL; - else if(partname == "DELAYBR") this_chan.attribute = DetAttribute::DelayBR; - else if(partname == "DELAYBL") this_chan.attribute = DetAttribute::DelayBL; - else if(partname == "CATHODE") this_chan.attribute = DetAttribute::Cathode; - else if(partname == "ANODEFRONT") this_chan.attribute = DetAttribute::AnodeFront; - else if(partname == "ANODEBACK") this_chan.attribute = DetAttribute::AnodeBack; - else if(partname == "MONITOR") this_chan.attribute = DetAttribute::Monitor; - } - - m_cmap[gchan] = this_chan; - } - - input.close(); - m_validFlag = true; - return m_validFlag; -} +} \ No newline at end of file diff --git a/src/evb/ChannelMap.h b/src/evb/ChannelMap.h index d7b0171..1a19cab 100644 --- a/src/evb/ChannelMap.h +++ b/src/evb/ChannelMap.h @@ -9,66 +9,67 @@ #ifndef CHANNELMAP_H #define CHANNELMAP_H -//Detector part/type identifiers for use in the code -enum DetType -{ - Sabre, - FocalPlane, - NoneType -}; - -enum DetAttribute -{ - ScintLeft, - ScintRight, - AnodeFront, - AnodeBack, - DelayFR, - DelayFL, - DelayBR, - DelayBL, - Cathode, - Monitor, - SabreRing0, - SabreRing1, - SabreRing2, - SabreRing3, - SabreRing4, - SabreWedge0, - SabreWedge1, - SabreWedge2, - SabreWedge3, - SabreWedge4, - NoneAttr -}; - -struct Channel -{ - DetType type; - DetAttribute attribute; //What kind of detector we're looking at - int local_channel; //Which specific piece of detector we're looking at -}; - -class ChannelMap -{ +namespace EventBuilder { + //Detector part/type identifiers for use in the code + enum DetType + { + Sabre, + FocalPlane, + NoneType + }; -public: - typedef std::unordered_map Containter; - typedef std::unordered_map::iterator Iterator; - - ChannelMap(); - ChannelMap(const std::string& filename); - ~ChannelMap(); - bool FillMap(const std::string& filename); - inline const Containter* GetCMap() { return &m_cmap; }; - inline Iterator FindChannel(int key) { return m_cmap.find(key); }; - inline Iterator End() { return m_cmap.end(); }; - inline bool IsValid() { return m_validFlag; }; - -private: - Containter m_cmap; - bool m_validFlag; -}; - + enum DetAttribute + { + ScintLeft, + ScintRight, + AnodeFront, + AnodeBack, + DelayFR, + DelayFL, + DelayBR, + DelayBL, + Cathode, + Monitor, + SabreRing0, + SabreRing1, + SabreRing2, + SabreRing3, + SabreRing4, + SabreWedge0, + SabreWedge1, + SabreWedge2, + SabreWedge3, + SabreWedge4, + NoneAttr + }; + + struct Channel + { + DetType type; + DetAttribute attribute; //What kind of detector we're looking at + int local_channel; //Which specific piece of detector we're looking at + }; + + class ChannelMap + { + + public: + typedef std::unordered_map Containter; + typedef std::unordered_map::iterator Iterator; + + ChannelMap(); + ChannelMap(const std::string& filename); + ~ChannelMap(); + bool FillMap(const std::string& filename); + inline const Containter* GetCMap() { return &m_cmap; }; + inline Iterator FindChannel(int key) { return m_cmap.find(key); }; + inline Iterator End() { return m_cmap.end(); }; + inline bool IsValid() { return m_validFlag; }; + + private: + Containter m_cmap; + bool m_validFlag; + }; +} #endif diff --git a/src/evb/CompassFile.cpp b/src/evb/CompassFile.cpp index df2c32d..d632636 100644 --- a/src/evb/CompassFile.cpp +++ b/src/evb/CompassFile.cpp @@ -11,157 +11,161 @@ #include "EventBuilder.h" #include "CompassFile.h" -CompassFile::CompassFile() : - m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared()), eofFlag(false) -{ - m_buffersize = bufsize*hitsize; - hitBuffer.resize(m_buffersize); -} +namespace EventBuilder { -CompassFile::CompassFile(const std::string& filename) : - m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared()), eofFlag(false) -{ - m_buffersize = bufsize*hitsize; - hitBuffer.resize(m_buffersize); - Open(filename); -} - -CompassFile::CompassFile(const std::string& filename, int bsize) : - m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), - bufsize(bsize), m_file(std::make_shared()), eofFlag(false) -{ - m_buffersize = bufsize*hitsize; - hitBuffer.resize(m_buffersize); - Open(filename); -} - -CompassFile::~CompassFile() -{ - Close(); -} - -void CompassFile::Open(const std::string& filename) -{ - eofFlag = false; - 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(); - m_nHits = m_size/24; - if(m_size == 0) + CompassFile::CompassFile() : + m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared()), eofFlag(false) { - eofFlag = true; - } - else + m_buffersize = bufsize*hitsize; + hitBuffer.resize(m_buffersize); + } + + CompassFile::CompassFile(const std::string& filename) : + m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared()), eofFlag(false) { + m_buffersize = bufsize*hitsize; + hitBuffer.resize(m_buffersize); + Open(filename); + } + + CompassFile::CompassFile(const std::string& filename, int bsize) : + m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), + bufsize(bsize), m_file(std::make_shared()), eofFlag(false) + { + m_buffersize = bufsize*hitsize; + hitBuffer.resize(m_buffersize); + Open(filename); + } + + CompassFile::~CompassFile() + { + Close(); + } + + void CompassFile::Open(const std::string& filename) + { + eofFlag = false; + 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(); + m_nHits = m_size/24; + if(m_size == 0) + { + eofFlag = true; + } + else + { + m_file->seekg(0, std::ios_base::beg); + } + } + + void CompassFile::Close() + { + if(IsOpen()) + { + m_file->close(); + } + } + + int CompassFile::GetHitSize() + { + if(!IsOpen()) + { + std::cerr<<"Unable to get hit size due to file not being open!"<read(firstHit, 24); + + firstHit += 16; + int nsamples = *((uint32_t*) firstHit); + m_file->seekg(0, std::ios_base::beg); + + delete firstHit; + + return 24 + nsamples*16; + } -} - -void CompassFile::Close() -{ - if(IsOpen()) + + /* + GetNextHit() is the function which... gets the next hit + Has to check if the buffer needs refilled/filled for the first time + Upon pulling a hit, sets the UsedFlag to false, letting the next level know + that the hit should be free game. + + If the file cannot be opened, signals as though file is EOF + */ + bool CompassFile::GetNextHit() { - m_file->close(); + if(!IsOpen()) return true; + + if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF()) + { + GetNextBuffer(); + } + + if(!IsEOF()) + { + ParseNextHit(); + hitUsedFlag = false; + } + + return eofFlag; } -} - -int CompassFile::GetHitSize() -{ - if(!IsOpen()) + + /* + GetNextBuffer() ... self-explanatory name + Note tht this is where the EOF flag is set. The EOF is only singaled + after the LAST buffer is completely read (i.e literally no more data). ifstream sets its eof + bit upon pulling the last buffer, but this class waits until that entire + last buffer is read to singal EOF (the true end of file). + */ + void CompassFile::GetNextBuffer() { - std::cerr<<"Unable to get hit size due to file not being open!"<eof()) + { + eofFlag = true; + return; + } + + m_file->read(hitBuffer.data(), hitBuffer.size()); + + bufferIter = hitBuffer.data(); + bufferEnd = bufferIter + m_file->gcount(); //one past the last datum + } - - char* firstHit = new char[24]; //A compass hit by default has 24 bytes (at least in our setup) - - m_file->read(firstHit, 24); - - firstHit += 16; - int nsamples = *((uint32_t*) firstHit); - - m_file->seekg(0, std::ios_base::beg); - - delete firstHit; - - return 24 + nsamples*16; - -} - -/* - GetNextHit() is the function which... gets the next hit - Has to check if the buffer needs refilled/filled for the first time - Upon pulling a hit, sets the UsedFlag to false, letting the next level know - that the hit should be free game. - - If the file cannot be opened, signals as though file is EOF -*/ -bool CompassFile::GetNextHit() -{ - if(!IsOpen()) return true; - - if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF()) + + void CompassFile::ParseNextHit() { - GetNextBuffer(); + + m_currentHit.board = *((uint16_t*)bufferIter); + bufferIter += 2; + m_currentHit.channel = *((uint16_t*)bufferIter); + bufferIter += 2; + m_currentHit.timestamp = *((uint64_t*)bufferIter); + bufferIter += 8; + m_currentHit.lgate = *((uint16_t*)bufferIter); + bufferIter += 2; + m_currentHit.sgate = *((uint16_t*)bufferIter); + bufferIter += 2; + m_currentHit.flags = *((uint32_t*)bufferIter); + bufferIter += 4; + m_currentHit.Ns = *((uint32_t*)bufferIter); + bufferIter += 4; + + if(m_smap != nullptr) + { //memory safety + int gchan = m_currentHit.channel + m_currentHit.board*16; + m_currentHit.timestamp += m_smap->GetShift(gchan); + } + } - if(!IsEOF()) - { - ParseNextHit(); - hitUsedFlag = false; - } - - return eofFlag; -} - -/* - GetNextBuffer() ... self-explanatory name - Note tht this is where the EOF flag is set. The EOF is only singaled - after the LAST buffer is completely read (i.e literally no more data). ifstream sets its eof - bit upon pulling the last buffer, but this class waits until that entire - last buffer is read to singal EOF (the true end of file). -*/ -void CompassFile::GetNextBuffer() -{ - - if(m_file->eof()) - { - eofFlag = true; - return; - } - - m_file->read(hitBuffer.data(), hitBuffer.size()); - - bufferIter = hitBuffer.data(); - bufferEnd = bufferIter + m_file->gcount(); //one past the last datum - -} - -void CompassFile::ParseNextHit() -{ - - m_currentHit.board = *((uint16_t*)bufferIter); - bufferIter += 2; - m_currentHit.channel = *((uint16_t*)bufferIter); - bufferIter += 2; - m_currentHit.timestamp = *((uint64_t*)bufferIter); - bufferIter += 8; - m_currentHit.lgate = *((uint16_t*)bufferIter); - bufferIter += 2; - m_currentHit.sgate = *((uint16_t*)bufferIter); - bufferIter += 2; - m_currentHit.flags = *((uint32_t*)bufferIter); - bufferIter += 4; - m_currentHit.Ns = *((uint32_t*)bufferIter); - bufferIter += 4; - - if(m_smap != nullptr) - { //memory safety - int gchan = m_currentHit.channel + m_currentHit.board*16; - m_currentHit.timestamp += m_smap->GetShift(gchan); - } - -} +} \ No newline at end of file diff --git a/src/evb/CompassFile.h b/src/evb/CompassFile.h index 826e2d0..c39c5f0 100644 --- a/src/evb/CompassFile.h +++ b/src/evb/CompassFile.h @@ -15,57 +15,60 @@ #include "ShiftMap.h" #include -class CompassFile -{ +namespace EventBuilder { + + class CompassFile + { + + public: + CompassFile(); + CompassFile(const std::string& filename); + CompassFile(const std::string& filename, int bsize); + ~CompassFile(); + void Open(const std::string& filename); + void Close(); + bool GetNextHit(); -public: - CompassFile(); - CompassFile(const std::string& filename); - CompassFile(const std::string& filename, int bsize); - ~CompassFile(); - void Open(const std::string& filename); - void Close(); - bool GetNextHit(); - - inline bool IsOpen() const { return m_file->is_open(); }; - inline CompassHit GetCurrentHit() const { return m_currentHit; } - inline std::string GetName() const { return m_filename; } - inline bool CheckHitHasBeenUsed() const { return hitUsedFlag; } //query to find out if we've used the current hit - inline void SetHitHasBeenUsed() { hitUsedFlag = true; } //flip the flag to indicate the current hit has been used - inline bool IsEOF() const { return eofFlag; } //see if we've read all available data - inline bool* GetUsedFlagPtr() { return &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; } - - -private: - int GetHitSize(); - void ParseNextHit(); - void GetNextBuffer(); - - using Buffer = std::vector; - - using FilePointer = std::shared_ptr; //to make this class copy/movable - - std::string m_filename; - Buffer hitBuffer; - char* bufferIter; - char* bufferEnd; - ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete - - bool hitUsedFlag; - int bufsize = 200000; //size of the buffer in hits - int hitsize = 24; //size of a CompassHit in bytes (without alignment padding) - int m_buffersize; - - CompassHit m_currentHit; - FilePointer m_file; - bool eofFlag; - unsigned int m_size; //size of the file in bytes - unsigned int m_nHits; //number of hits in the file (m_size/24) - -}; + inline bool IsOpen() const { return m_file->is_open(); }; + inline CompassHit GetCurrentHit() const { return m_currentHit; } + inline std::string GetName() const { return m_filename; } + inline bool CheckHitHasBeenUsed() const { return hitUsedFlag; } //query to find out if we've used the current hit + inline void SetHitHasBeenUsed() { hitUsedFlag = true; } //flip the flag to indicate the current hit has been used + inline bool IsEOF() const { return eofFlag; } //see if we've read all available data + inline bool* GetUsedFlagPtr() { return &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; } + + + private: + int GetHitSize(); + void ParseNextHit(); + void GetNextBuffer(); + + using Buffer = std::vector; + + using FilePointer = std::shared_ptr; //to make this class copy/movable + + std::string m_filename; + Buffer hitBuffer; + char* bufferIter; + char* bufferEnd; + ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete + + bool hitUsedFlag; + int bufsize = 200000; //size of the buffer in hits + int hitsize = 24; //size of a CompassHit in bytes (without alignment padding) + int m_buffersize; + + CompassHit m_currentHit; + FilePointer m_file; + bool eofFlag; + unsigned int m_size; //size of the file in bytes + unsigned int m_nHits; //number of hits in the file (m_size/24) + + }; +} #endif diff --git a/src/evb/CompassHit.h b/src/evb/CompassHit.h index 10aca98..fd5c02f 100644 --- a/src/evb/CompassHit.h +++ b/src/evb/CompassHit.h @@ -1,15 +1,19 @@ #ifndef COMPASS_HIT_H #define COMPASS_HIT_H -struct CompassHit -{ - uint16_t board = 400; - uint16_t channel = 400; - uint64_t timestamp = 0; - uint16_t lgate = 0; - uint16_t sgate = 0; - uint32_t flags = 0; - uint32_t Ns = 0; -}; +namespace EventBuilder { + + struct CompassHit + { + uint16_t board = 400; + uint16_t channel = 400; + uint64_t timestamp = 0; + uint16_t lgate = 0; + uint16_t sgate = 0; + uint32_t flags = 0; + uint32_t Ns = 0; + }; + +} #endif diff --git a/src/evb/CompassRun.cpp b/src/evb/CompassRun.cpp index df005c1..8f87c30 100644 --- a/src/evb/CompassRun.cpp +++ b/src/evb/CompassRun.cpp @@ -17,593 +17,597 @@ #include "SFPAnalyzer.h" #include "FlagHandler.h" -CompassRun::CompassRun() : - m_directory(""), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_pb(nullptr) -{ - -} - -CompassRun::CompassRun(const std::string& dir) : - m_directory(dir), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_pb(nullptr) -{ - -} - -CompassRun::~CompassRun() {} - - -/*Load em into a map*/ -void CompassRun::SetScalers() -{ - std::ifstream input(m_scalerinput); - if(!input.is_open()) - return; - - m_scaler_flag = true; - std::string junk, filename, varname; - Long64_t init = 0; - std::getline(input, junk); - std::getline(input, junk); - m_scaler_map.clear(); - while(input>>filename) +namespace EventBuilder { + + CompassRun::CompassRun() : + m_directory(""), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_pb(nullptr) { - input>>varname; - filename = m_directory+filename+"_run_"+std::to_string(m_runNum)+".bin"; - m_scaler_map[filename] = TParameter(varname.c_str(), init); + } - input.close(); -} - -bool CompassRun::GetBinaryFiles() -{ - std::string prefix = ""; - 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.reserve(grabber.GetFileList().size()); - bool scalerd; - m_totalHits = 0; //reset total run size - - for(auto& entry : grabber.GetFileList()) + + CompassRun::CompassRun(const std::string& dir) : + m_directory(dir), m_scalerinput(""), m_runNum(0), m_scaler_flag(false), m_pb(nullptr) { - //Handle scaler files, if they exist - if(m_scaler_flag) + + } + + CompassRun::~CompassRun() {} + + + /*Load em into a map*/ + void CompassRun::SetScalers() + { + std::ifstream input(m_scalerinput); + if(!input.is_open()) + return; + + m_scaler_flag = true; + std::string junk, filename, varname; + Long64_t init = 0; + std::getline(input, junk); + std::getline(input, junk); + m_scaler_map.clear(); + while(input>>filename) { - scalerd = false; - for(auto& scaler_pair : m_scaler_map) + input>>varname; + filename = m_directory+filename+"_run_"+std::to_string(m_runNum)+".bin"; + m_scaler_map[filename] = TParameter(varname.c_str(), init); + } + input.close(); + } + + bool CompassRun::GetBinaryFiles() + { + std::string prefix = ""; + 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.reserve(grabber.GetFileList().size()); + bool scalerd; + m_totalHits = 0; //reset total run size + + for(auto& entry : grabber.GetFileList()) + { + //Handle scaler files, if they exist + if(m_scaler_flag) { - if(entry == scaler_pair.first) + scalerd = false; + for(auto& scaler_pair : m_scaler_map) { - ReadScalerData(entry); - scalerd = true; - break; + if(entry == scaler_pair.first) + { + ReadScalerData(entry); + scalerd = true; + break; + } + } + if(scalerd) + continue; + } + + m_datafiles.emplace_back(entry); + m_datafiles[m_datafiles.size()-1].AttachShiftMap(&m_smap); + //Any time we have a file that fails to be found, we terminate the whole process + if(!m_datafiles[m_datafiles.size() - 1].IsOpen()) + return false; + + m_totalHits += m_datafiles[m_datafiles.size()-1].GetNumberOfHits(); + } + + return true; + } + + /* + Pure counting of scalers. Potential upgrade path to something like + average count rate etc. + */ + void CompassRun::ReadScalerData(const std::string& filename) + { + if(!m_scaler_flag) + return; + + Long64_t count; + count = 0; + CompassFile file(filename); + auto& this_param = m_scaler_map[file.GetName()]; + while(true) + { + file.GetNextHit(); + if(file.IsEOF()) + break; + count++; + } + this_param.SetVal(count); + } + + /* + 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 + 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); + for(unsigned int i=startIndex; iBranch("Board", &hit.board); + outtree->Branch("Channel", &hit.channel); + outtree->Branch("Energy", &hit.lgate); + outtree->Branch("EnergyShort", &hit.sgate); + outtree->Branch("Timestamp", &hit.timestamp); + outtree->Branch("Flags", &hit.flags); + + if(!m_smap.IsValid()) + { + std::cerr<<"Bad shift map at CompassRun::Convert()."<Increment(count); + gSystem->ProcessEvents(); + count=0; + } + else + { + count = 0; + flush_count++; + std::cout<<"\rPercent of run built: "<Fill(); + } + + output->cd(); + outtree->Write(outtree->GetName(), TObject::kOverwrite); + for(auto& entry : m_scaler_map) + entry.second.Write(); + + output->Close(); + } + + void CompassRun::Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window) + { + TFile* output = TFile::Open(name.c_str(), "RECREATE"); + TTree* outtree = new TTree("SortTree", "SortTree"); + + outtree->Branch("event", &event); + + if(!m_smap.IsValid()) + { + std::cerr<<"Bad shift map at CompassRun::Convert()."<Increment(count); + gSystem->ProcessEvents(); + count=0; + } + else + { + count = 0; + flush_count++; + std::cout<<"\rPercent of run built: "< earliestHit = std::make_pair(CompassHit(), nullptr); - for(unsigned int i=startIndex; iBranch("Board", &hit.board); - outtree->Branch("Channel", &hit.channel); - outtree->Branch("Energy", &hit.lgate); - outtree->Branch("EnergyShort", &hit.sgate); - outtree->Branch("Timestamp", &hit.timestamp); - outtree->Branch("Flags", &hit.flags); - - if(!m_smap.IsValid()) - { - std::cerr<<"Bad shift map at CompassRun::Convert()."<Increment(count); - gSystem->ProcessEvents(); - count=0; - } - else - { - count = 0; - flush_count++; - std::cout<<"\rPercent of run built: "<Fill(); - } - - output->cd(); - outtree->Write(outtree->GetName(), TObject::kOverwrite); - for(auto& entry : m_scaler_map) - entry.second.Write(); - - output->Close(); -} - -void CompassRun::Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window) -{ - TFile* output = TFile::Open(name.c_str(), "RECREATE"); - TTree* outtree = new TTree("SortTree", "SortTree"); - - outtree->Branch("event", &event); - - if(!m_smap.IsValid()) - { - std::cerr<<"Bad shift map at CompassRun::Convert()."<Increment(count); - gSystem->ProcessEvents(); - count=0; - } - else - { - count = 0; - flush_count++; - std::cout<<"\rPercent of run built: "<Fill(); - if(killFlag) break; - } - } - - output->cd(); - outtree->Write(outtree->GetName(), TObject::kOverwrite); - for(auto& entry : m_scaler_map) - entry.second.Write(); - - coincidizer.GetEventStats()->Write(); - output->Close(); -} - -void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window) -{ - TFile* output = TFile::Open(name.c_str(), "RECREATE"); - TTree* outtree = new TTree("SortTree", "SortTree"); - - outtree->Branch("event", &event); - - if(!m_smap.IsValid()) - { - std::cerr<<"Bad shift map at CompassRun::Convert()."< fast_events; - SlowSort coincidizer(window, mapfile); - FastSort speedyCoincidizer(fsi_window, fic_window); - - FlagHandler flagger; - - bool killFlag = false; - unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; - if(flush == 0) - flush = 1; - while(true) - { - count++; - if(count == flush) - { - if(m_pb) - { - m_pb->Increment(count); - gSystem->ProcessEvents(); - count=0; - } - else - { - count = 0; - flush_count++; - std::cout<<"\rPercent of run built: "<Fill(); - } - if(killFlag) - break; - } - } - - output->cd(); - outtree->Write(outtree->GetName(), TObject::kOverwrite); - for(auto& entry : m_scaler_map) - entry.second.Write(); - coincidizer.GetEventStats()->Write(); - output->Close(); -} - - -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) -{ - - TFile* output = TFile::Open(name.c_str(), "RECREATE"); - TTree* outtree = new TTree("SPSTree", "SPSTree"); - - outtree->Branch("event", &pevent); - - if(!m_smap.IsValid()) - { - std::cerr<<"Bad shift map at CompassRun::Convert()."<> 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); - - bool killFlag = false; - unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; - if(flush == 0) - flush = 1; - while(true) - { - count++; - if(count == flush) - { - if(m_pb) + if(!GetHitsFromFiles()) { - m_pb->Increment(count); - gSystem->ProcessEvents(); - count=0; + coincidizer.FlushHitsToEvent(); + killFlag = true; } - else + else + coincidizer.AddHitToEvent(hit); + + if(coincidizer.IsEventReady()) { - count = 0; - flush_count++; - std::cout<<"\rPercent of run built: "<Fill(); - if(killFlag) - break; - } - } - - output->cd(); - outtree->Write(outtree->GetName(), TObject::kOverwrite); - for(auto& entry : m_scaler_map) - entry.second.Write(); - - for(auto& entry : parvec) - entry.Write(); - - coincidizer.GetEventStats()->Write(); - analyzer.GetHashTable()->Write(); - analyzer.ClearHashTable(); - 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) -{ - - TFile* output = TFile::Open(name.c_str(), "RECREATE"); - TTree* outtree = new TTree("SPSTree", "SPSTree"); - - outtree->Branch("event", &pevent); - - if(!m_smap.IsValid()) - { - std::cerr<<"Bad shift map at CompassRun::Convert()."< fast_events; - SlowSort coincidizer(window, mapfile); - FastSort speedyCoincidizer(fsi_window, fic_window); - SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); - - 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); - - FlagHandler flagger; - - bool killFlag = false; - unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; - if(flush == 0) - flush = 1; - while(true) - { - count++; - if(count == flush) - { - if(m_pb) - { - m_pb->Increment(count); - gSystem->ProcessEvents(); - count=0; - } - else - { - count = 0; - flush_count++; - std::cout<<"\rPercent of run built: "<Fill(); + if(killFlag) break; } - if(killFlag) - break; } + + output->cd(); + outtree->Write(outtree->GetName(), TObject::kOverwrite); + for(auto& entry : m_scaler_map) + entry.second.Write(); + + coincidizer.GetEventStats()->Write(); + output->Close(); + } + + void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window) + { + TFile* output = TFile::Open(name.c_str(), "RECREATE"); + TTree* outtree = new TTree("SortTree", "SortTree"); + + outtree->Branch("event", &event); + + if(!m_smap.IsValid()) + { + std::cerr<<"Bad shift map at CompassRun::Convert()."< fast_events; + SlowSort coincidizer(window, mapfile); + FastSort speedyCoincidizer(fsi_window, fic_window); + + FlagHandler flagger; + + bool killFlag = false; + unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; + if(flush == 0) + flush = 1; + while(true) + { + count++; + if(count == flush) + { + if(m_pb) + { + m_pb->Increment(count); + gSystem->ProcessEvents(); + count=0; + } + else + { + count = 0; + flush_count++; + std::cout<<"\rPercent of run built: "<Fill(); + } + if(killFlag) + break; + } + } + + output->cd(); + outtree->Write(outtree->GetName(), TObject::kOverwrite); + for(auto& entry : m_scaler_map) + entry.second.Write(); + + coincidizer.GetEventStats()->Write(); + output->Close(); + } + + + 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) + { + + TFile* output = TFile::Open(name.c_str(), "RECREATE"); + TTree* outtree = new TTree("SPSTree", "SPSTree"); + + outtree->Branch("event", &pevent); + + if(!m_smap.IsValid()) + { + std::cerr<<"Bad shift map at CompassRun::Convert()."<> 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); + + bool killFlag = false; + unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; + if(flush == 0) + flush = 1; + while(true) + { + count++; + if(count == flush) + { + if(m_pb) + { + m_pb->Increment(count); + gSystem->ProcessEvents(); + count=0; + } + else + { + count = 0; + flush_count++; + std::cout<<"\rPercent of run built: "<Fill(); + if(killFlag) + break; + } + } + + output->cd(); + outtree->Write(outtree->GetName(), TObject::kOverwrite); + for(auto& entry : m_scaler_map) + entry.second.Write(); + + for(auto& entry : parvec) + entry.Write(); + + coincidizer.GetEventStats()->Write(); + analyzer.GetHashTable()->Write(); + analyzer.ClearHashTable(); + 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) + { + + TFile* output = TFile::Open(name.c_str(), "RECREATE"); + TTree* outtree = new TTree("SPSTree", "SPSTree"); + + outtree->Branch("event", &pevent); + + if(!m_smap.IsValid()) + { + std::cerr<<"Bad shift map at CompassRun::Convert()."< fast_events; + SlowSort coincidizer(window, mapfile); + FastSort speedyCoincidizer(fsi_window, fic_window); + SFPAnalyzer analyzer(zt, at, zp, ap, ze, ae, bke, theta, b); + + 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); + + FlagHandler flagger; + + bool killFlag = false; + unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; + if(flush == 0) + flush = 1; + while(true) + { + count++; + if(count == flush) + { + if(m_pb) + { + m_pb->Increment(count); + gSystem->ProcessEvents(); + count=0; + } + else + { + count = 0; + flush_count++; + std::cout<<"\rPercent of run built: "<Fill(); + } + if(killFlag) + break; + } + } + + output->cd(); + outtree->Write(outtree->GetName(), TObject::kOverwrite); + for(auto& entry : m_scaler_map) + entry.second.Write(); + + for(auto& entry : parvec) + entry.Write(); + + coincidizer.GetEventStats()->Write(); + analyzer.GetHashTable()->Write(); + analyzer.ClearHashTable(); + output->Close(); + } + + void CompassRun::SetProgressBar() + { + m_pb->SetMax(m_totalHits); + m_pb->SetMin(0); + m_pb->SetPosition(0); + gSystem->ProcessEvents(); } - output->cd(); - outtree->Write(outtree->GetName(), TObject::kOverwrite); - for(auto& entry : m_scaler_map) - entry.second.Write(); - - for(auto& entry : parvec) - entry.Write(); - - coincidizer.GetEventStats()->Write(); - analyzer.GetHashTable()->Write(); - analyzer.ClearHashTable(); - output->Close(); -} - -void CompassRun::SetProgressBar() -{ - m_pb->SetMax(m_totalHits); - m_pb->SetMin(0); - m_pb->SetPosition(0); - gSystem->ProcessEvents(); -} +} \ No newline at end of file diff --git a/src/evb/CompassRun.h b/src/evb/CompassRun.h index 985d9fd..eed941d 100644 --- a/src/evb/CompassRun.h +++ b/src/evb/CompassRun.h @@ -18,54 +18,58 @@ #include #include -class CompassRun -{ +namespace EventBuilder { + + class CompassRun + { + + public: + CompassRun(); + CompassRun(const std::string& dir); + ~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); + + inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; } + + private: + bool GetBinaryFiles(); + bool GetHitsFromFiles(); + void SetScalers(); + void ReadScalerData(const std::string& filename); + void SetProgressBar(); + + 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; + + //what run is this + int m_runNum; + unsigned int m_totalHits; + + //Scaler switch + bool m_scaler_flag; + + //GUI progress bar, if attached + TGProgressBar* m_pb; + }; -public: - CompassRun(); - CompassRun(const std::string& dir); - ~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); - - inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; } - -private: - bool GetBinaryFiles(); - bool GetHitsFromFiles(); - void SetScalers(); - void ReadScalerData(const std::string& filename); - void SetProgressBar(); - - 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; - - //what run is this - int m_runNum; - unsigned int m_totalHits; - - //Scaler switch - bool m_scaler_flag; - - //GUI progress bar, if attached - TGProgressBar* m_pb; -}; +} #endif diff --git a/src/evb/CutHandler.cpp b/src/evb/CutHandler.cpp index 013eb15..7ec659b 100644 --- a/src/evb/CutHandler.cpp +++ b/src/evb/CutHandler.cpp @@ -1,104 +1,108 @@ #include "EventBuilder.h" #include "CutHandler.h" -CutHandler::CutHandler() : - validFlag(false) - { - InitVariableMap(); - } - -CutHandler::CutHandler(const std::string& filename) : - validFlag(false) -{ - SetCuts(filename); - InitVariableMap(); -} - -CutHandler::~CutHandler() -{ - for(unsigned int i=0; iIsOpen()) - file_array[i]->Close(); -} - -void CutHandler::SetCuts(const std::string& filename) -{ - std::ifstream cutlist(filename); - - if(!cutlist.is_open()) +namespace EventBuilder { + + CutHandler::CutHandler() : + validFlag(false) + { + InitVariableMap(); + } + + CutHandler::CutHandler(const std::string& filename) : + validFlag(false) { - validFlag = false; + SetCuts(filename); + InitVariableMap(); } - - std::string junk, name, fname, varx, vary; - cutlist>>junk>>junk>>junk>>junk; - - cut_array.clear(); - file_array.clear(); - - while(cutlist>>name) + + CutHandler::~CutHandler() { - cutlist>>fname>>varx>>vary; - TFile* file = TFile::Open(fname.c_str(), "READ"); - TCutG* cut = (TCutG*) file->Get("CUTG"); - if(cut) - { - cut->SetVarX(varx.c_str()); - cut->SetVarY(vary.c_str()); - cut->SetName(name.c_str()); - cut_array.push_back(cut); - file_array.push_back(file); - } - else + for(unsigned int i=0; iIsOpen()) + file_array[i]->Close(); + } + + void CutHandler::SetCuts(const std::string& filename) + { + std::ifstream cutlist(filename); + + if(!cutlist.is_open()) { validFlag = false; - std::cerr<<"CutHandler has encountered a bad cut at file: "< 0) - validFlag = true; - else - validFlag = false; -} - -/* - ADD MORE VARIABLES HERE! -*/ -void CutHandler::InitVariableMap() -{ - varmap["x1"] = &m_event.x1; - varmap["x2"] = &m_event.x2; - varmap["xavg"] = &m_event.xavg; - varmap["scintLeft"] = &m_event.scintLeft; - varmap["anodeBack"] = &m_event.anodeBack; - varmap["cathode"] = &m_event.cathode; -} - -bool CutHandler::IsInside(const ProcessedEvent* eaddress) -{ - m_event = *eaddress; - std::string x, y; - for(unsigned int i=0; iGetVarX(); - y = cut->GetVarY(); - auto xentry = varmap.find(x); - auto yentry = varmap.find(y); - if(xentry == varmap.end() || yentry == varmap.end()) + + std::string junk, name, fname, varx, vary; + cutlist>>junk>>junk>>junk>>junk; + + cut_array.clear(); + file_array.clear(); + + while(cutlist>>name) { - std::cerr<<"Unmapped variable called in CutHandler::IsInside()! Var names: "<first<<" , "<first<>fname>>varx>>vary; + TFile* file = TFile::Open(fname.c_str(), "READ"); + TCutG* cut = (TCutG*) file->Get("CUTG"); + if(cut) + { + cut->SetVarX(varx.c_str()); + cut->SetVarY(vary.c_str()); + cut->SetName(name.c_str()); + cut_array.push_back(cut); + file_array.push_back(file); + } + else + { + validFlag = false; + std::cerr<<"CutHandler has encountered a bad cut at file: "<IsInside(*(xentry->second), *(yentry->second))) - return false; - + + if(cut_array.size() > 0) + validFlag = true; + else + validFlag = false; + } + + /* + ADD MORE VARIABLES HERE! + */ + void CutHandler::InitVariableMap() + { + varmap["x1"] = &m_event.x1; + varmap["x2"] = &m_event.x2; + varmap["xavg"] = &m_event.xavg; + varmap["scintLeft"] = &m_event.scintLeft; + varmap["anodeBack"] = &m_event.anodeBack; + varmap["cathode"] = &m_event.cathode; + } + + bool CutHandler::IsInside(const ProcessedEvent* eaddress) + { + m_event = *eaddress; + std::string x, y; + for(unsigned int i=0; iGetVarX(); + y = cut->GetVarY(); + auto xentry = varmap.find(x); + auto yentry = varmap.find(y); + if(xentry == varmap.end() || yentry == varmap.end()) + { + std::cerr<<"Unmapped variable called in CutHandler::IsInside()! Var names: "<first<<" , "<first<IsInside(*(xentry->second), *(yentry->second))) + return false; + + } + + return true; } - return true; -} +} \ No newline at end of file diff --git a/src/evb/CutHandler.h b/src/evb/CutHandler.h index 0128709..55d3970 100644 --- a/src/evb/CutHandler.h +++ b/src/evb/CutHandler.h @@ -1,27 +1,30 @@ #ifndef CUTHANDLER_H #define CUTHANDLER_H -#include "DataStructs.h" +#include "../spsdict/DataStructs.h" -class CutHandler { -public: - CutHandler(); - CutHandler(const std::string& filename); - ~CutHandler(); - void SetCuts(const std::string& filename); - bool IsValid() { return validFlag; } - bool IsInside(const ProcessedEvent* eaddress); - std::vector GetCuts() { return cut_array; } +namespace EventBuilder { + + class CutHandler { + public: + CutHandler(); + CutHandler(const std::string& filename); + ~CutHandler(); + void SetCuts(const std::string& filename); + bool IsValid() { return validFlag; } + bool IsInside(const ProcessedEvent* eaddress); + std::vector GetCuts() { return cut_array; } + + private: + void InitVariableMap(); + + std::vector cut_array; + std::vector file_array; + std::unordered_map varmap; + bool validFlag; + ProcessedEvent m_event; + }; -private: - void InitVariableMap(); - - std::vector cut_array; - std::vector file_array; - std::unordered_map varmap; - bool validFlag; - ProcessedEvent m_event; - -}; +} #endif \ No newline at end of file diff --git a/src/evb/EVBApp.cpp b/src/evb/EVBApp.cpp index 0155d36..d5b8ae8 100644 --- a/src/evb/EVBApp.cpp +++ b/src/evb/EVBApp.cpp @@ -16,421 +16,425 @@ #include "SFPAnalyzer.h" #include "SFPPlotter.h" -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_workspace("none"), m_mapfile("none"), m_shiftfile("none"), - m_cutList("none"), m_SlowWindow(0), m_FastWindowIonCh(0), m_FastWindowSABRE(0), m_pb(nullptr) -{ -} - -EVBApp::~EVBApp() -{ -} - -bool EVBApp::ReadConfigFile(const std::string& fullpath) -{ - std::cout<<"Reading in configuration from file: "<>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(); - - std::cout<<"Completed."<>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(); + + std::cout<<"Completed."< -class EVBApp { -public: - EVBApp(); - ~EVBApp(); - - bool ReadConfigFile(const std::string& filename); - void WriteConfigFile(const std::string& filename); - - void PlotHistograms(); - void MergeROOTFiles(); - void Convert2SortedRoot(); - void Convert2FastSortedRoot(); - void Convert2RawRoot(); - void Convert2SlowAnalyzedRoot(); - void Convert2FastAnalyzedRoot(); - - inline void SetRunRange(int rmin, int rmax) { m_rmin = rmin; m_rmax = rmax; }; - inline void SetWorkDirectory(const std::string& fullpath) { m_workspace = fullpath; }; - inline void SetChannelMap(const std::string& name) { m_mapfile = name; }; - inline void SetBoardShiftFile(const std::string& name) { m_shiftfile = name; }; - inline void SetSlowCoincidenceWindow(double window) { m_SlowWindow = window; }; - inline void SetFastWindowIonChamber(double window) { m_FastWindowIonCh = window; }; - inline void SetFastWindowSABRE(double window) { m_FastWindowSABRE = window; }; - inline void SetCutList(const std::string& name) { m_cutList = name; }; - inline void SetScalerFile(const std::string& fullpath) { m_scalerfile = 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; } - - inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; } - - enum Operation - { - Convert, - ConvertSlow, - ConvertSlowA, - ConvertFast, - ConvertFastA, - Merge, - Plot +namespace EventBuilder { + + class EVBApp { + public: + EVBApp(); + ~EVBApp(); + + bool ReadConfigFile(const std::string& filename); + void WriteConfigFile(const std::string& filename); + + void PlotHistograms(); + void MergeROOTFiles(); + void Convert2SortedRoot(); + void Convert2FastSortedRoot(); + void Convert2RawRoot(); + void Convert2SlowAnalyzedRoot(); + void Convert2FastAnalyzedRoot(); + + inline void SetRunRange(int rmin, int rmax) { m_rmin = rmin; m_rmax = rmax; }; + inline void SetWorkDirectory(const std::string& fullpath) { m_workspace = fullpath; }; + inline void SetChannelMap(const std::string& name) { m_mapfile = name; }; + inline void SetBoardShiftFile(const std::string& name) { m_shiftfile = name; }; + inline void SetSlowCoincidenceWindow(double window) { m_SlowWindow = window; }; + inline void SetFastWindowIonChamber(double window) { m_FastWindowIonCh = window; }; + inline void SetFastWindowSABRE(double window) { m_FastWindowSABRE = window; }; + inline void SetCutList(const std::string& name) { m_cutList = name; }; + inline void SetScalerFile(const std::string& fullpath) { m_scalerfile = 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; } + + inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; } + + enum Operation + { + Convert, + ConvertSlow, + ConvertSlowA, + ConvertFast, + ConvertFastA, + Merge, + Plot + }; + + 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; + + 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; + + TGProgressBar* m_pb; + }; -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; - - 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; - - TGProgressBar* m_pb; - -}; - +} #endif diff --git a/src/evb/FP_kinematics.cpp b/src/evb/FP_kinematics.cpp index 377e4d1..337d36d 100644 --- a/src/evb/FP_kinematics.cpp +++ b/src/evb/FP_kinematics.cpp @@ -36,70 +36,73 @@ #include "MassLookup.h" #include "FP_kinematics.h" -//requires (Z,A) for T, P, and E, as well as energy of P, -// spectrograph angle of interest, and field value -double Delta_Z(int ZT, int AT, int ZP, int AP, int ZE, int AE, - double EP, double angle, double B) -{ +namespace EventBuilder { - /* CONSTANTS */ - const double UTOMEV = 931.4940954; //MeV per u; - const double MEVTOJ = 1.60218E-13; //J per MeV - const double RESTMASS_ELECTRON = 0.000548579909; //amu - const double UNIT_CHARGE = 1.602E-19; //Coulombs - const double C = 2.9979E8; //m/s - - /* SESPS-SPECIFIC */ - const double DISP = 1.96; //dispersion (x/rho) - const double MAG = 0.39; //magnification in x - const double DEGTORAD = M_PI/180.; - - int ZR = ZT + ZP - ZE, AR = AT + AP - AE; - double EE=0; //ejectile energy - - double MT=0, MP=0, ME=0, MR=0; //masses (MeV) - - B /= 10000; //convert to tesla - angle *= DEGTORAD; - - MT = MASS.FindMass(ZT, AT) - ZT*RESTMASS_ELECTRON*UTOMEV; - MP = MASS.FindMass(ZP, AP) - ZP*RESTMASS_ELECTRON*UTOMEV; - ME = MASS.FindMass(ZE, AE) - ZE*RESTMASS_ELECTRON*UTOMEV; - MR = MASS.FindMass(ZR, AR) - ZR*RESTMASS_ELECTRON*UTOMEV; - - if (MT*MP*ME*MR == 0) + //requires (Z,A) for T, P, and E, as well as energy of P, + // spectrograph angle of interest, and field value + double Delta_Z(int ZT, int AT, int ZP, int AP, int ZE, int AE, + double EP, double angle, double B) { - std::cerr << "***WARNING: error loading one or more masses; returning 0\n"; - return 0; - } - - double Q = MT + MP - ME - MR; //Q-value - //kinematics a la Iliadis p.590 - double term1 = sqrt(MP*ME*EP)/(ME + MR)*cos(angle); - double term2 = (EP*(MR - MP) + MR*Q)/(ME + MR); - - EE = term1 + sqrt(term1*term1 + term2); - EE *= EE; - - //momentum - double PE = sqrt(EE*(EE+2*ME)); - - //calculate rho from B a la B*rho = (proj. momentum)/(proj. charge) - double rho = (PE*MEVTOJ)/(ZE*UNIT_CHARGE*C*B)*100; //in cm - - double K; - - K = sqrt(MP*ME*EP/EE); - K *= sin(angle); - - double denom = ME + MR - sqrt(MP*ME*EP/EE)*cos(angle); - - K /= denom; - std::cout<<"Delta Z= "<<-1*rho*DISP*MAG*K< ionch_index) - { //Back anode required to move on` - - float anodeRelTime = fabs(slowEvent.focalPlane.anodeB[ionch_index].Time - slowEvent.focalPlane.scintL[scint_index].Time); - if(anodeRelTime > ion_coincWindow) - return; //Window check - - fastEvent.focalPlane.anodeB.push_back(slowEvent.focalPlane.anodeB[ionch_index]); - fastEvent.focalPlane.scintL.push_back(slowEvent.focalPlane.scintL[scint_index]); - if(slowEvent.focalPlane.delayFL.size() > ionch_index) - fastEvent.focalPlane.delayFL.push_back(slowEvent.focalPlane.delayFL[ionch_index]); - - if(slowEvent.focalPlane.delayFR.size() > ionch_index) - fastEvent.focalPlane.delayFR.push_back(slowEvent.focalPlane.delayFR[ionch_index]); - - if(slowEvent.focalPlane.delayBR.size() > ionch_index) - fastEvent.focalPlane.delayBR.push_back(slowEvent.focalPlane.delayBR[ionch_index]); - - if(slowEvent.focalPlane.delayBL.size() > ionch_index) - fastEvent.focalPlane.delayBL.push_back(slowEvent.focalPlane.delayBL[ionch_index]); - - if(slowEvent.focalPlane.scintR.size() > ionch_index) - fastEvent.focalPlane.scintR.push_back(slowEvent.focalPlane.scintR[ionch_index]); - - if(slowEvent.focalPlane.anodeF.size() > ionch_index) - fastEvent.focalPlane.anodeF.push_back(slowEvent.focalPlane.anodeF[ionch_index]); - - if(slowEvent.focalPlane.cathode.size() > ionch_index) - fastEvent.focalPlane.cathode.push_back(slowEvent.focalPlane.cathode[ionch_index]); - } -} - -/*Assign a set of SABRE data that falls within the coincidence window*/ -void FastSort::ProcessSABRE(unsigned int scint_index) -{ - for(int i=0; i<5; i++) - { //loop over SABRE silicons - std::vector rings; - std::vector wedges; - - if(slowEvent.sabreArray[i].rings.size() == 0 || slowEvent.sabreArray[i].wedges.size() == 0) - continue; //save some time on empties - - /*Dump sabre data that doesnt fall within the fast coincidence window with the scint*/ - for(unsigned int j=0; j FastSort::GetFastEvents(CoincEvent& event) -{ - slowEvent = event; - std::vector fast_events; - - unsigned int sizeArray[7]; - sizeArray[0] = slowEvent.focalPlane.delayFL.size(); - sizeArray[1] = slowEvent.focalPlane.delayFR.size(); - sizeArray[2] = slowEvent.focalPlane.delayBL.size(); - sizeArray[3] = slowEvent.focalPlane.delayBR.size(); - sizeArray[4] = slowEvent.focalPlane.anodeF.size(); - sizeArray[5] = slowEvent.focalPlane.anodeB.size(); - sizeArray[6] = slowEvent.focalPlane.cathode.size(); - unsigned int maxSize = *std::max_element(sizeArray, sizeArray+7); - //loop over scints - for(unsigned int i=0; i ionch_index) + { //Back anode required to move on` + + float anodeRelTime = fabs(slowEvent.focalPlane.anodeB[ionch_index].Time - slowEvent.focalPlane.scintL[scint_index].Time); + if(anodeRelTime > ion_coincWindow) + return; //Window check + + fastEvent.focalPlane.anodeB.push_back(slowEvent.focalPlane.anodeB[ionch_index]); + fastEvent.focalPlane.scintL.push_back(slowEvent.focalPlane.scintL[scint_index]); + if(slowEvent.focalPlane.delayFL.size() > ionch_index) + fastEvent.focalPlane.delayFL.push_back(slowEvent.focalPlane.delayFL[ionch_index]); + + if(slowEvent.focalPlane.delayFR.size() > ionch_index) + fastEvent.focalPlane.delayFR.push_back(slowEvent.focalPlane.delayFR[ionch_index]); + + if(slowEvent.focalPlane.delayBR.size() > ionch_index) + fastEvent.focalPlane.delayBR.push_back(slowEvent.focalPlane.delayBR[ionch_index]); + + if(slowEvent.focalPlane.delayBL.size() > ionch_index) + fastEvent.focalPlane.delayBL.push_back(slowEvent.focalPlane.delayBL[ionch_index]); + + if(slowEvent.focalPlane.scintR.size() > ionch_index) + fastEvent.focalPlane.scintR.push_back(slowEvent.focalPlane.scintR[ionch_index]); + + if(slowEvent.focalPlane.anodeF.size() > ionch_index) + fastEvent.focalPlane.anodeF.push_back(slowEvent.focalPlane.anodeF[ionch_index]); + + if(slowEvent.focalPlane.cathode.size() > ionch_index) + fastEvent.focalPlane.cathode.push_back(slowEvent.focalPlane.cathode[ionch_index]); } } - return fast_events; -} + + /*Assign a set of SABRE data that falls within the coincidence window*/ + void FastSort::ProcessSABRE(unsigned int scint_index) + { + for(int i=0; i<5; i++) + { //loop over SABRE silicons + std::vector rings; + std::vector wedges; + + if(slowEvent.sabreArray[i].rings.size() == 0 || slowEvent.sabreArray[i].wedges.size() == 0) + continue; //save some time on empties + + /*Dump sabre data that doesnt fall within the fast coincidence window with the scint*/ + for(unsigned int j=0; j FastSort::GetFastEvents(CoincEvent& event) + { + slowEvent = event; + std::vector fast_events; + + unsigned int sizeArray[7]; + sizeArray[0] = slowEvent.focalPlane.delayFL.size(); + sizeArray[1] = slowEvent.focalPlane.delayFR.size(); + sizeArray[2] = slowEvent.focalPlane.delayBL.size(); + sizeArray[3] = slowEvent.focalPlane.delayBR.size(); + sizeArray[4] = slowEvent.focalPlane.anodeF.size(); + sizeArray[5] = slowEvent.focalPlane.anodeB.size(); + sizeArray[6] = slowEvent.focalPlane.cathode.size(); + unsigned int maxSize = *std::max_element(sizeArray, sizeArray+7); + //loop over scints + for(unsigned int i=0; i -class FastSort -{ - -public: - FastSort(float si_windowSize, float ion_windowSize); - ~FastSort(); - std::vector GetFastEvents(CoincEvent& event); +namespace EventBuilder { -private: - void ResetSABRE(); - void ResetFocalPlane(); - void ProcessSABRE(unsigned int scint_index); - void ProcessFocalPlane(unsigned int scint_index, unsigned int ionch_index); - - float si_coincWindow, ion_coincWindow; - CoincEvent *event_address, slowEvent; - CoincEvent fastEvent, blank; - SabreDetector sblank; - FPDetector fpblank; - -}; + class FastSort + { + + public: + FastSort(float si_windowSize, float ion_windowSize); + ~FastSort(); + std::vector GetFastEvents(CoincEvent& event); + + private: + void ResetSABRE(); + void ResetFocalPlane(); + void ProcessSABRE(unsigned int scint_index); + void ProcessFocalPlane(unsigned int scint_index, unsigned int ionch_index); + + float si_coincWindow, ion_coincWindow; + CoincEvent *event_address, slowEvent; + CoincEvent fastEvent, blank; + SabreDetector sblank; + FPDetector fpblank; + + }; +} #endif diff --git a/src/evb/FlagHandler.cpp b/src/evb/FlagHandler.cpp index 831bc5a..52b0cb0 100644 --- a/src/evb/FlagHandler.cpp +++ b/src/evb/FlagHandler.cpp @@ -1,106 +1,108 @@ #include "EventBuilder.h" #include "FlagHandler.h" -FlagHandler::FlagHandler() : - log("./event_log.txt") -{ -} +namespace EventBuilder { -FlagHandler::FlagHandler(const std::string& filename) : - log(filename) -{ -} - -FlagHandler::~FlagHandler() -{ - WriteLog(); - log.close(); -} - -void FlagHandler::CheckFlag(int board, int channel, int flag) -{ - - int gchan = channel + board*16; - FlagCount& counter = event_count_map[gchan]; //yikes - - counter.total_counts++; - - if(flag & DeadTime) - counter.dead_time++; - - if(flag & TimeRollover) - counter.time_roll++; - - if(flag & TimeReset) - counter.time_reset++; - - if(flag & FakeEvent) - counter.fake_event++; - - if(flag & MemFull) - counter.mem_full++; - - if(flag & TrigLost) - counter.trig_lost++; - - if(flag & NTrigLost) - counter.n_trig_lost++; - - if(flag & SaturatingInGate) - counter.sat_in_gate++; - - if(flag & Trig1024Counted) - counter.trig_1024++;; - - if(flag & SaturatingInput) - counter.sat_input++; - - if(flag & NTrigCounted) - counter.n_trig_count++; - - if(flag & EventNotMatched) - counter.event_not_matched++; - - if(flag & PileUp) - counter.pile_up++; - - if(flag & PLLLockLoss) - counter.pll_lock_loss++; - - if(flag & OverTemp) - counter.over_temp++; - - if(flag & ADCShutdown) - counter.adc_shutdown++; - -} - -void FlagHandler::WriteLog() -{ - log<<"Event Flag Log"< -struct FlagCount -{ - long total_counts=0; - long dead_time=0; - long time_roll=0; - long time_reset=0; - long fake_event=0; - long mem_full=0; - long trig_lost=0; - long n_trig_lost=0; - long sat_in_gate=0; - long trig_1024=0; - long sat_input=0; - long n_trig_count=0; - long event_not_matched=0; - long fine_time=0; - long pile_up=0; - long pll_lock_loss=0; - long over_temp=0; - long adc_shutdown=0; -}; +namespace EventBuilder { -class FlagHandler -{ -public: - FlagHandler(); - FlagHandler(const std::string& filename); - ~FlagHandler(); - void CheckFlag(int board, int channel, int flag); - - const int DeadTime = 0x00000001; - const int TimeRollover = 0x00000002; - const int TimeReset = 0x00000004; - const int FakeEvent = 0x00000008; - const int MemFull = 0x00000010; - const int TrigLost = 0x00000020; - const int NTrigLost = 0x00000040; - const int SaturatingInGate = 0x00000080; - const int Trig1024Counted = 0x00000100; - const int SaturatingInput = 0x00000400; - const int NTrigCounted = 0x00000800; - const int EventNotMatched = 0x00001000; - const int FineTime = 0x00004000; - const int PileUp = 0x00008000; - const int PLLLockLoss = 0x00080000; - const int OverTemp = 0x00100000; - const int ADCShutdown = 0x00200000; - -private: - std::ofstream log; - std::map event_count_map; - - void WriteLog(); -}; + struct FlagCount + { + long total_counts=0; + long dead_time=0; + long time_roll=0; + long time_reset=0; + long fake_event=0; + long mem_full=0; + long trig_lost=0; + long n_trig_lost=0; + long sat_in_gate=0; + long trig_1024=0; + long sat_input=0; + long n_trig_count=0; + long event_not_matched=0; + long fine_time=0; + long pile_up=0; + long pll_lock_loss=0; + long over_temp=0; + long adc_shutdown=0; + }; + + class FlagHandler + { + public: + FlagHandler(); + FlagHandler(const std::string& filename); + ~FlagHandler(); + void CheckFlag(int board, int channel, int flag); + + const int DeadTime = 0x00000001; + const int TimeRollover = 0x00000002; + const int TimeReset = 0x00000004; + const int FakeEvent = 0x00000008; + const int MemFull = 0x00000010; + const int TrigLost = 0x00000020; + const int NTrigLost = 0x00000040; + const int SaturatingInGate = 0x00000080; + const int Trig1024Counted = 0x00000100; + const int SaturatingInput = 0x00000400; + const int NTrigCounted = 0x00000800; + const int EventNotMatched = 0x00001000; + const int FineTime = 0x00004000; + const int PileUp = 0x00008000; + const int PLLLockLoss = 0x00080000; + const int OverTemp = 0x00100000; + const int ADCShutdown = 0x00200000; + + private: + std::ofstream log; + std::map event_count_map; + + void WriteLog(); + }; +} #endif diff --git a/src/evb/MassLookup.cpp b/src/evb/MassLookup.cpp index e43d426..eea7030 100644 --- a/src/evb/MassLookup.cpp +++ b/src/evb/MassLookup.cpp @@ -11,65 +11,67 @@ Written by G.W. McCann Aug. 2020 #include "EventBuilder.h" #include "MassLookup.h" - -/* - Read in AMDC mass file, preformated to remove excess info. Here assumes that by default - the file is in a local directory etc/ -*/ -MassLookup::MassLookup() -{ - std::string filepath; - #ifdef ETC_DIR_PATH - filepath = ETC_DIR_PATH; - filepath += "mass.txt"; - #else - filepath = "./etc/mass.txt"; - #endif - std::ifstream massfile(filepath); - if(massfile.is_open()) +namespace EventBuilder { + + /* + Read in AMDC mass file, preformated to remove excess info. Here assumes that by default + the file is in a local directory etc/ + */ + MassLookup::MassLookup() { - int Z,A; - std::string junk, element, key; - double atomicMassBig, atomicMassSmall, isotopicMass; - std::getline(massfile,junk); - std::getline(massfile,junk); - while(massfile>>junk) + std::string filepath; + #ifdef ETC_DIR_PATH + filepath = ETC_DIR_PATH; + filepath += "mass.txt"; + #else + filepath = "./etc/mass.txt"; + #endif + std::ifstream massfile(filepath); + if(massfile.is_open()) { - massfile>>Z>>A>>element>>atomicMassBig>>atomicMassSmall; - isotopicMass = (atomicMassBig + atomicMassSmall*1e-6 - Z*electron_mass)*u_to_mev; - key = "("+std::to_string(Z)+","+A+")"; - massTable[key] = isotopicMass; - elementTable[Z] = element; + int Z,A; + std::string junk, element, key; + double atomicMassBig, atomicMassSmall, isotopicMass; + std::getline(massfile,junk); + std::getline(massfile,junk); + while(massfile>>junk) + { + massfile>>Z>>A>>element>>atomicMassBig>>atomicMassSmall; + isotopicMass = (atomicMassBig + atomicMassSmall*1e-6 - Z*electron_mass)*u_to_mev; + key = "("+std::to_string(Z)+","+A+")"; + massTable[key] = isotopicMass; + elementTable[Z] = element; + } + } + else + std::cerr<<"Unable to open mass.txt at MassLookup! Prepare for errors."<second; } - return data->second; -} - -//returns element symbol -std::string MassLookup::FindSymbol(int Z, int A) -{ - auto data = elementTable.find(Z); - if(data == elementTable.end()) + + //returns element symbol + std::string MassLookup::FindSymbol(int Z, int A) { - std::cerr<<"Invaild nucleus at MassLookup! Returning empty symbol"<second; + return fullsymbol; } - std::string fullsymbol = std::to_string(A) + data->second; - return fullsymbol; -} +} \ No newline at end of file diff --git a/src/evb/MassLookup.h b/src/evb/MassLookup.h index 5e6fea4..e6a0dc5 100644 --- a/src/evb/MassLookup.h +++ b/src/evb/MassLookup.h @@ -11,25 +11,29 @@ Written by G.W. McCann Aug. 2020 #ifndef MASS_LOOKUP_H #define MASS_LOOKUP_H -class MassLookup -{ +namespace EventBuilder { -public: - MassLookup(); - ~MassLookup(); - double FindMass(int Z, int A); - std::string FindSymbol(int Z, int A); + class MassLookup + { + + public: + MassLookup(); + ~MassLookup(); + double FindMass(int Z, int A); + std::string FindSymbol(int Z, int A); + + private: + std::unordered_map massTable; + std::unordered_map elementTable; + + //constants + static constexpr double u_to_mev = 931.4940954; + static constexpr double electron_mass = 0.000548579909; + + }; + + //static instance for use throught program + static MassLookup MASS; -private: - std::unordered_map massTable; - std::unordered_map elementTable; - - //constants - static constexpr double u_to_mev = 931.4940954; - static constexpr double electron_mass = 0.000548579909; - -}; - -//static instance for use throught program -static MassLookup MASS; +} #endif diff --git a/src/evb/OrderChecker.cpp b/src/evb/OrderChecker.cpp index 3548ab8..c08cdc6 100644 --- a/src/evb/OrderChecker.cpp +++ b/src/evb/OrderChecker.cpp @@ -8,33 +8,37 @@ #include "EventBuilder.h" #include "OrderChecker.h" -OrderChecker::OrderChecker() -{ -} - -OrderChecker::~OrderChecker() -{ -} - -bool OrderChecker::IsOrdered(const std::string& filename) -{ - TFile* file = TFile::Open(filename.c_str(), "READ"); - TTree* tree = (TTree*) file->Get("Data"); - - uint64_t ts; - tree->SetBranchAddress("Timestamp", &ts); - uint64_t prevStamp = 0; - - for(Long64_t i=0; iGetEntries(); i++) +namespace EventBuilder { + + OrderChecker::OrderChecker() { - tree->GetEntry(); - if(prevStamp >= ts) + } + + OrderChecker::~OrderChecker() + { + } + + bool OrderChecker::IsOrdered(const std::string& filename) + { + TFile* file = TFile::Open(filename.c_str(), "READ"); + TTree* tree = (TTree*) file->Get("Data"); + + uint64_t ts; + tree->SetBranchAddress("Timestamp", &ts); + uint64_t prevStamp = 0; + + for(Long64_t i=0; iGetEntries(); i++) { - std::cerr<<"Bad order at entry "<GetEntries()<GetEntry(); + if(prevStamp >= ts) + { + std::cerr<<"Bad order at entry "<GetEntries()<Close(); + return true; } - file->Close(); - return true; -} +} \ No newline at end of file diff --git a/src/evb/OrderChecker.h b/src/evb/OrderChecker.h index 09fc060..e36d4c5 100644 --- a/src/evb/OrderChecker.h +++ b/src/evb/OrderChecker.h @@ -8,12 +8,16 @@ #ifndef ORDERCHECKER_H #define ORDERCHECKER_H -class OrderChecker -{ -public: - OrderChecker(); - ~OrderChecker(); - bool IsOrdered(const std::string& filename); -}; +namespace EventBuilder { + + class OrderChecker + { + public: + OrderChecker(); + ~OrderChecker(); + bool IsOrdered(const std::string& filename); + }; + +} #endif diff --git a/src/evb/RunCollector.cpp b/src/evb/RunCollector.cpp index c300e2d..688c62b 100644 --- a/src/evb/RunCollector.cpp +++ b/src/evb/RunCollector.cpp @@ -7,127 +7,89 @@ #include #include -RunCollector::RunCollector(): - m_initFlag(false), m_directory(""), m_prefix(""), m_suffix(""), m_minRun(0), m_maxRun(0) -{ -} +namespace EventBuilder { -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 + RunCollector::RunCollector(): + m_initFlag(false), m_directory(""), m_prefix(""), m_suffix(""), m_minRun(0), m_maxRun(0) { - std::cerr<<"Unable to find any files in directory; check name given to the input.txt"<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)) + } + + 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 { - fname = m_directory+temp; - m_filelist.push_back(fname); - } - } - - delete flist; - if(m_filelist.size()>0) - return true; - else - { - std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<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)) + std::cerr<<"Unable to find any files in directory; check name given to the input.txt"<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 + { + std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<GetName(); if(temp.size() < m_prefix.size() || temp.size() < runno.size()) @@ -136,96 +98,138 @@ bool RunCollector::GrabFilesInRange() !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 + break; } } + + delete flist; + return fname; } - - delete flist; - if(m_filelist.size()>0) - return true; - else + + /*Grabs all files within a specified run range*/ + bool RunCollector::GrabFilesInRange() { - std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<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 + { + std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<Add(m_filelist[i].c_str()); - std::cout<<"Merging runs into single file..."<Merge(output,0,"fast"); - std::cout<<"Finished merging"<Add(m_filelist[i].c_str()); - std::cout<<"Merging runs "<Merge(output,0,"fast"); - std::cout<<"Finished merging"<Add(m_filelist[i].c_str()); + std::cout<<"Merging runs into single file..."<Merge(output,0,"fast"); + std::cout<<"Finished merging"<Add(m_filelist[i].c_str()); + std::cout<<"Merging runs "<Merge(output,0,"fast"); + std::cout<<"Finished merging"<IsOpen()) + output->Close(); + 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 index a4bb748..02822db 100644 --- a/src/evb/RunCollector.h +++ b/src/evb/RunCollector.h @@ -10,35 +10,38 @@ #ifndef RUNCOLLECTOR_H #define RUNCOLLECTOR_H -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; } +namespace EventBuilder { -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; + 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 1c89ddc..fec5cb2 100644 --- a/src/evb/SFPAnalyzer.cpp +++ b/src/evb/SFPAnalyzer.cpp @@ -12,194 +12,197 @@ #include "EventBuilder.h" #include "SFPAnalyzer.h" +namespace EventBuilder { -/*Constructor takes in kinematic parameters for generating focal plane weights*/ -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); - event_address = new CoincEvent(); - rootObj = new THashTable(); - GetWeights(); -} - -SFPAnalyzer::~SFPAnalyzer() -{ - rootObj->Clear(); - delete rootObj; - delete event_address; -} - -void SFPAnalyzer::Reset() -{ - pevent = blank; //set output back to blank -} - -/*Use functions from FP_kinematics to calculate weights for xavg - *While this seems kind of funny, it is mathematically equivalent to making a line - *from the two focal plane points and finding the intersection with - *the kinematic focal plane - */ -void SFPAnalyzer::GetWeights() -{ - w1 = (Wire_Dist()/2.0-zfp)/Wire_Dist(); - w2 = 1.0-w1; - std::cout<<"w1: "<FindObject(name.c_str()); - if(histo != nullptr) - histo->Fill(valuex, valuey); - else + /*Constructor takes in kinematic parameters for generating focal plane weights*/ + SFPAnalyzer::SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, + double angle, double b) { - TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); - h->Fill(valuex, valuey); - rootObj->Add(h); + zfp = Delta_Z(zt, at, zp, ap, ze, ae, ep, angle, b); + event_address = new CoincEvent(); + rootObj = new THashTable(); + GetWeights(); } -} - -/*1D histogram fill wrapper for use with THashTable (faster)*/ -void SFPAnalyzer::MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex) -{ - TH1F *histo = (TH1F*) rootObj->FindObject(name.c_str()); - if(histo != nullptr) - histo->Fill(valuex); - else + + SFPAnalyzer::~SFPAnalyzer() { - TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx); - h->Fill(valuex); - rootObj->Add(h); + rootObj->Clear(); + delete rootObj; + delete event_address; } -} - -void SFPAnalyzer::AnalyzeEvent(CoincEvent& event) -{ - Reset(); - if(!event.focalPlane.anodeF.empty()) + + void SFPAnalyzer::Reset() { - pevent.anodeFront = event.focalPlane.anodeF[0].Long; - pevent.anodeFrontTime = event.focalPlane.anodeF[0].Time; + pevent = blank; //set output back to blank } - if(!event.focalPlane.anodeB.empty()) + + /*Use functions from FP_kinematics to calculate weights for xavg + *While this seems kind of funny, it is mathematically equivalent to making a line + *from the two focal plane points and finding the intersection with + *the kinematic focal plane + */ + void SFPAnalyzer::GetWeights() { - pevent.anodeBack = event.focalPlane.anodeB[0].Long; - pevent.anodeBackTime = event.focalPlane.anodeB[0].Time; + w1 = (Wire_Dist()/2.0-zfp)/Wire_Dist(); + w2 = 1.0-w1; + std::cout<<"w1: "< 0) - pevent.theta = std::atan((pevent.x2-pevent.x1)/36.0); - else if((pevent.x2-pevent.x1) < 0) - pevent.theta = TMath::Pi() + std::atan((pevent.x2-pevent.x1)/36.0); + TH2F *histo = (TH2F*) rootObj->FindObject(name.c_str()); + if(histo != nullptr) + histo->Fill(valuex, valuey); else - pevent.theta = TMath::Pi()/2.0; - MyFill("xavg vs theta",600,-300,300,pevent.xavg,314,0,3.14,pevent.theta); - MyFill("x1 vs x2",600,-300,300,pevent.x1,600,-300,300,pevent.x2); + { + TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); + h->Fill(valuex, valuey); + rootObj->Add(h); + } + } + + /*1D histogram fill wrapper for use with THashTable (faster)*/ + void SFPAnalyzer::MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex) + { + TH1F *histo = (TH1F*) rootObj->FindObject(name.c_str()); + if(histo != nullptr) + histo->Fill(valuex); + else + { + TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx); + h->Fill(valuex); + rootObj->Add(h); + } + } + + void SFPAnalyzer::AnalyzeEvent(CoincEvent& event) + { + Reset(); + if(!event.focalPlane.anodeF.empty()) + { + pevent.anodeFront = event.focalPlane.anodeF[0].Long; + pevent.anodeFrontTime = event.focalPlane.anodeF[0].Time; + } + if(!event.focalPlane.anodeB.empty()) + { + pevent.anodeBack = event.focalPlane.anodeB[0].Long; + pevent.anodeBackTime = event.focalPlane.anodeB[0].Time; + } + if(!event.focalPlane.scintL.empty()) + { + pevent.scintLeft = event.focalPlane.scintL[0].Long; + pevent.scintLeftShort = event.focalPlane.scintL[0].Short; + pevent.scintLeftTime = event.focalPlane.scintL[0].Time; + } + if(!event.focalPlane.scintR.empty()) + { + pevent.scintRight = event.focalPlane.scintR[0].Long; + pevent.scintRightShort = event.focalPlane.scintR[0].Short; + pevent.scintRightTime = event.focalPlane.scintR[0].Time; + } + if(!event.focalPlane.cathode.empty()) + { + pevent.cathode = event.focalPlane.cathode[0].Long; + pevent.cathodeTime = event.focalPlane.cathode[0].Time; + } + if(!event.focalPlane.monitor.empty()) + { + pevent.monitorE = event.focalPlane.monitor[0].Long; + pevent.monitorShort = event.focalPlane.monitor[0].Short; + pevent.monitorTime = event.focalPlane.monitor[0].Time; + } + + /*Delay lines and all that*/ + if(!event.focalPlane.delayFR.empty()) + { + pevent.delayFrontRightE = event.focalPlane.delayFR[0].Long; + pevent.delayFrontRightTime = event.focalPlane.delayFR[0].Time; + pevent.delayFrontRightShort = event.focalPlane.delayFR[0].Short; + } + if(!event.focalPlane.delayFL.empty()) + { + pevent.delayFrontLeftE = event.focalPlane.delayFL[0].Long; + pevent.delayFrontLeftTime = event.focalPlane.delayFL[0].Time; + pevent.delayFrontLeftShort = event.focalPlane.delayFL[0].Short; + } + if(!event.focalPlane.delayBR.empty()) + { + pevent.delayBackRightE = event.focalPlane.delayBR[0].Long; + pevent.delayBackRightTime = event.focalPlane.delayBR[0].Time; + pevent.delayBackRightShort = event.focalPlane.delayBR[0].Short; + } + if(!event.focalPlane.delayBL.empty()) + { + pevent.delayBackLeftE = event.focalPlane.delayBL[0].Long; + pevent.delayBackLeftTime = event.focalPlane.delayBL[0].Time; + pevent.delayBackLeftShort = event.focalPlane.delayBL[0].Short; + } + if(!event.focalPlane.delayFL.empty() && !event.focalPlane.delayFR.empty()) + { + pevent.fp1_tdiff = (event.focalPlane.delayFL[0].Time-event.focalPlane.delayFR[0].Time)*0.5; + pevent.fp1_tsum = (event.focalPlane.delayFL[0].Time+event.focalPlane.delayFR[0].Time); + pevent.fp1_tcheck = (pevent.fp1_tsum)/2.0-pevent.anodeFrontTime; + pevent.delayFrontMaxTime = std::max(event.focalPlane.delayFL[0].Time, event.focalPlane.delayFR[0].Time); + pevent.x1 = pevent.fp1_tdiff*1.0/2.10; //position from time, based on total delay + MyFill("x1",1200,-300,300,pevent.x1); + MyFill("x1 vs anodeBack",600,-300,300,pevent.x1,512,0,4096,pevent.anodeBack); + } + if(!event.focalPlane.delayBL.empty() && !event.focalPlane.delayBR.empty()) + { + pevent.fp2_tdiff = (event.focalPlane.delayBL[0].Time-event.focalPlane.delayBR[0].Time)*0.5; + pevent.fp2_tsum = (event.focalPlane.delayBL[0].Time+event.focalPlane.delayBR[0].Time); + pevent.fp2_tcheck = (pevent.fp2_tsum)/2.0-pevent.anodeBackTime; + pevent.delayBackMaxTime = std::max(event.focalPlane.delayBL[0].Time, event.focalPlane.delayBR[0].Time); + pevent.x2 = pevent.fp2_tdiff*1.0/1.98; //position from time, based on total delay + MyFill("x2",1200,-300,300,pevent.x2); + MyFill("x2 vs anodeBack",600,-300,300,pevent.x2,512,0,4096,pevent.anodeBack); + } + /*SABRE data*/ + for(int j=0; j<5; j++) + { + if(!event.sabreArray[j].rings.empty()) + { + pevent.sabreRingE[j] = event.sabreArray[j].rings[0].Long; + pevent.sabreRingChannel[j] = event.sabreArray[j].rings[0].Ch; + pevent.sabreRingTime[j] = event.sabreArray[j].rings[0].Time; + } + if(!event.sabreArray[j].wedges.empty()) + { + pevent.sabreWedgeE[j] = event.sabreArray[j].wedges[0].Long; + pevent.sabreWedgeChannel[j] = event.sabreArray[j].wedges[0].Ch; + pevent.sabreWedgeTime[j] = event.sabreArray[j].wedges[0].Time; + } + /*Aaaand passes on all of the rest. 4/24/20 GWM*/ + pevent.sabreArray[j] = event.sabreArray[j]; + } + + /*Make some histograms and xavg*/ + MyFill("anodeBack vs scintLeft",512,0,4096,pevent.scintLeft,512,0,4096,pevent.anodeBack); + if(pevent.x1 != -1e6 && pevent.x2 != -1e6) + { + pevent.xavg = pevent.x1*w1+pevent.x2*w2; + MyFill("xavg",1200,-300,300,pevent.xavg); + if((pevent.x2-pevent.x1) > 0) + pevent.theta = std::atan((pevent.x2-pevent.x1)/36.0); + else if((pevent.x2-pevent.x1) < 0) + pevent.theta = TMath::Pi() + std::atan((pevent.x2-pevent.x1)/36.0); + else + pevent.theta = TMath::Pi()/2.0; + MyFill("xavg vs theta",600,-300,300,pevent.xavg,314,0,3.14,pevent.theta); + MyFill("x1 vs x2",600,-300,300,pevent.x1,600,-300,300,pevent.x2); + } + if(pevent.anodeFrontTime != -1 && pevent.scintRightTime != -1) + pevent.fp1_y = pevent.anodeFrontTime-pevent.scintRightTime; + if(pevent.anodeBackTime != -1 && pevent.scintRightTime != -1) + pevent.fp2_y = pevent.anodeBackTime-pevent.scintRightTime; + } + + ProcessedEvent SFPAnalyzer::GetProcessedEvent(CoincEvent& event) + { + AnalyzeEvent(event); + return pevent; } - if(pevent.anodeFrontTime != -1 && pevent.scintRightTime != -1) - pevent.fp1_y = pevent.anodeFrontTime-pevent.scintRightTime; - if(pevent.anodeBackTime != -1 && pevent.scintRightTime != -1) - pevent.fp2_y = pevent.anodeBackTime-pevent.scintRightTime; -} -ProcessedEvent SFPAnalyzer::GetProcessedEvent(CoincEvent& event) -{ - AnalyzeEvent(event); - return pevent; -} +} \ No newline at end of file diff --git a/src/evb/SFPAnalyzer.h b/src/evb/SFPAnalyzer.h index 59d957e..d70d3d4 100644 --- a/src/evb/SFPAnalyzer.h +++ b/src/evb/SFPAnalyzer.h @@ -13,33 +13,36 @@ #include "DataStructs.h" #include "FP_kinematics.h" +namespace EventBuilder { -class SFPAnalyzer -{ -public: - SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, double angle, - double b); - ~SFPAnalyzer(); - ProcessedEvent GetProcessedEvent(CoincEvent& event); - inline void ClearHashTable() { rootObj->Clear(); } - inline THashTable* GetHashTable() { return rootObj; } + class SFPAnalyzer + { + public: + SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, double angle, + double b); + ~SFPAnalyzer(); + ProcessedEvent GetProcessedEvent(CoincEvent& event); + inline void ClearHashTable() { rootObj->Clear(); } + inline THashTable* GetHashTable() { return rootObj; } + + private: + void Reset(); //Sets ouput structure back to "zero" + void GetWeights(); //weights for xavg + void AnalyzeEvent(CoincEvent& event); + + /*Fill wrappers for use with THashTable*/ + void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex, + int binsy, double miny, double maxy, double valuey); + void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex); + + CoincEvent *event_address; //Input branch address + ProcessedEvent pevent, blank; //output branch and reset + + double w1, w2, zfp; + + THashTable *rootObj; //root storage + }; -private: - void Reset(); //Sets ouput structure back to "zero" - void GetWeights(); //weights for xavg - void AnalyzeEvent(CoincEvent& event); - - /*Fill wrappers for use with THashTable*/ - void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex, - int binsy, double miny, double maxy, double valuey); - void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex); - - CoincEvent *event_address; //Input branch address - ProcessedEvent pevent, blank; //output branch and reset - - double w1, w2, zfp; - - THashTable *rootObj; //root storage -}; +} #endif diff --git a/src/evb/SFPPlotter.cpp b/src/evb/SFPPlotter.cpp index 1f7792b..a2254a9 100644 --- a/src/evb/SFPPlotter.cpp +++ b/src/evb/SFPPlotter.cpp @@ -10,287 +10,291 @@ #include "SFPPlotter.h" #include -/*Generates storage and initializes pointers*/ -SFPPlotter::SFPPlotter() -{ - event_address = new ProcessedEvent(); - m_pb = nullptr; -} +namespace EventBuilder { -SFPPlotter::~SFPPlotter() -{ - delete event_address; -} - -/*2D histogram fill wrapper*/ -void SFPPlotter::MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex, - int binsy, double miny, double maxy, double valuey) -{ - TH2F *histo = (TH2F*) table->FindObject(name.c_str()); - if(histo != nullptr) - histo->Fill(valuex, valuey); - else + /*Generates storage and initializes pointers*/ + SFPPlotter::SFPPlotter() { - TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); - h->Fill(valuex, valuey); - table->Add(h); + event_address = new ProcessedEvent(); + m_pb = nullptr; } -} - -/*1D histogram fill wrapper*/ -void SFPPlotter::MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex) -{ - TH1F *histo = (TH1F*) table->FindObject(name.c_str()); - if(histo != nullptr) - histo->Fill(valuex); - else - { - TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx); - h->Fill(valuex); - table->Add(h); - } -} - -/*Makes histograms where only rejection is unset data*/ -void SFPPlotter::MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table) -{ - MyFill(table,"x1NoCuts_bothplanes",600,-300,300,ev.x2); - MyFill(table,"x2NoCuts_bothplanes",600,-300,300,ev.x2); - MyFill(table,"xavgNoCuts_bothplanes",600,-300,300,ev.xavg); - MyFill(table,"xavgNoCuts_theta_bothplanes",600,-300,300,ev.xavg,100,0,TMath::Pi()/2.,ev.theta); - MyFill(table,"x1_delayBackRightE_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE); - MyFill(table,"x2_delayBackRightE_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE); - MyFill(table,"xavg_delayBackRightE_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE); - MyFill(table,"x1_x2_NoCuts",600,-300,300,ev.x1,600,-300,300,ev.x2); - - Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0; - MyFill(table,"x1_delayBackAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayBackAvgE); - MyFill(table,"x2_delayBackAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayBackAvgE); - MyFill(table,"xavg_delayBackAvgE_NoCuts",600,-300,300,ev.xavg,512,0,4096,delayBackAvgE); - Double_t delayFrontAvgE = (ev.delayFrontRightE+ev.delayFrontLeftE)/2.0; - MyFill(table,"x1_delayFrontAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE); - MyFill(table,"x2_delayFrontAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE); - MyFill(table,"xavg_delayFrontAvgE_NoCuts",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE); - - MyFill(table,"scintLeft_anodeBack_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack); - MyFill(table,"scintLeft_anodeFront_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront); - MyFill(table,"scintLeft_cathode_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode); - - MyFill(table,"x1_scintLeft_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.scintLeft); - MyFill(table,"x2_scintLeft_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.scintLeft); - MyFill(table,"xavg_scintLeft_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft); - - MyFill(table,"x1_anodeBack_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeBack); - MyFill(table,"x2_anodeBack_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeBack); - MyFill(table,"xavg_anodeBack_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack); - - MyFill(table,"x1_anodeFront_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeFront); - MyFill(table,"x2_anodeFront_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeFront); - MyFill(table,"xavg_anodeFront_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront); - - MyFill(table,"x1_cathode_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.cathode); - MyFill(table,"x2_cathode_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.cathode); - MyFill(table,"xavg_cathode_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.cathode); - - /****Timing relative to back anode****/ - if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1) + SFPPlotter::~SFPPlotter() { - Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime; - Double_t delayRelFT = ev.delayFrontMaxTime - ev.anodeBackTime; - Double_t delayRelBT = ev.delayBackMaxTime - ev.anodeBackTime; - Double_t anodeRelBT = ev.anodeBackTime - ev.scintLeftTime; - Double_t delayRelFT_toScint = ev.delayFrontMaxTime - ev.scintLeftTime; - Double_t delayRelBT_toScint = ev.delayBackMaxTime - ev.scintLeftTime; - MyFill(table,"anodeRelFrontTime_NoCuts",1000,-3000,3500, anodeRelFT); - MyFill(table,"delayRelFrontTime_NoCuts",1000,-3000,-3500,delayRelFT); - MyFill(table,"delayRelBackTime_NoCuts",1000,-3000,-3500,delayRelBT); + delete event_address; + } + + /*2D histogram fill wrapper*/ + void SFPPlotter::MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex, + int binsy, double miny, double maxy, double valuey) + { + TH2F *histo = (TH2F*) table->FindObject(name.c_str()); + if(histo != nullptr) + histo->Fill(valuex, valuey); + else + { + TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); + h->Fill(valuex, valuey); + table->Add(h); + } + } + + /*1D histogram fill wrapper*/ + void SFPPlotter::MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex) + { + TH1F *histo = (TH1F*) table->FindObject(name.c_str()); + if(histo != nullptr) + histo->Fill(valuex); + else + { + TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx); + h->Fill(valuex); + table->Add(h); + } + } + + /*Makes histograms where only rejection is unset data*/ + void SFPPlotter::MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table) + { + MyFill(table,"x1NoCuts_bothplanes",600,-300,300,ev.x2); + MyFill(table,"x2NoCuts_bothplanes",600,-300,300,ev.x2); + MyFill(table,"xavgNoCuts_bothplanes",600,-300,300,ev.xavg); + MyFill(table,"xavgNoCuts_theta_bothplanes",600,-300,300,ev.xavg,100,0,TMath::Pi()/2.,ev.theta); + + MyFill(table,"x1_delayBackRightE_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE); + MyFill(table,"x2_delayBackRightE_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE); + MyFill(table,"xavg_delayBackRightE_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE); + MyFill(table,"x1_x2_NoCuts",600,-300,300,ev.x1,600,-300,300,ev.x2); + + Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0; + MyFill(table,"x1_delayBackAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayBackAvgE); + MyFill(table,"x2_delayBackAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayBackAvgE); + MyFill(table,"xavg_delayBackAvgE_NoCuts",600,-300,300,ev.xavg,512,0,4096,delayBackAvgE); + Double_t delayFrontAvgE = (ev.delayFrontRightE+ev.delayFrontLeftE)/2.0; + MyFill(table,"x1_delayFrontAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE); + MyFill(table,"x2_delayFrontAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE); + MyFill(table,"xavg_delayFrontAvgE_NoCuts",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE); + + MyFill(table,"scintLeft_anodeBack_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack); + MyFill(table,"scintLeft_anodeFront_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront); + MyFill(table,"scintLeft_cathode_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode); + + MyFill(table,"x1_scintLeft_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.scintLeft); + MyFill(table,"x2_scintLeft_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.scintLeft); + MyFill(table,"xavg_scintLeft_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft); + + MyFill(table,"x1_anodeBack_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeBack); + MyFill(table,"x2_anodeBack_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeBack); + MyFill(table,"xavg_anodeBack_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack); + + MyFill(table,"x1_anodeFront_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeFront); + MyFill(table,"x2_anodeFront_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeFront); + MyFill(table,"xavg_anodeFront_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront); + + MyFill(table,"x1_cathode_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.cathode); + MyFill(table,"x2_cathode_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.cathode); + MyFill(table,"xavg_cathode_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.cathode); + + /****Timing relative to back anode****/ + if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1) + { + Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime; + Double_t delayRelFT = ev.delayFrontMaxTime - ev.anodeBackTime; + Double_t delayRelBT = ev.delayBackMaxTime - ev.anodeBackTime; + Double_t anodeRelBT = ev.anodeBackTime - ev.scintLeftTime; + Double_t delayRelFT_toScint = ev.delayFrontMaxTime - ev.scintLeftTime; + Double_t delayRelBT_toScint = ev.delayBackMaxTime - ev.scintLeftTime; + MyFill(table,"anodeRelFrontTime_NoCuts",1000,-3000,3500, anodeRelFT); + MyFill(table,"delayRelFrontTime_NoCuts",1000,-3000,-3500,delayRelFT); + MyFill(table,"delayRelBackTime_NoCuts",1000,-3000,-3500,delayRelBT); + for(int i=0; i<5; i++) + { + if(ev.sabreRingE[i] != -1) + { + Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime; + Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; + Double_t sabreRelRT_toScint = ev.sabreRingTime[i] - ev.scintLeftTime; + Double_t sabreRelWT_toScint = ev.sabreWedgeTime[i] - ev.scintLeftTime; + MyFill(table,"xavg_sabrefcoinc_NoCuts",600,-300,300, ev.xavg); + MyFill(table,"sabreRelRingTime_NoCuts",1000,-3000,3500, sabreRelRT); + MyFill(table,"sabreRelWedgeTime_NoCuts",1000,-3000,3500, sabreRelWT); + MyFill(table,"sabreRelRingTime_toScint",1000,-3000,3500,sabreRelRT_toScint); + MyFill(table,"sabreRelWedgeTime_toScint",1000,-3000,3500,sabreRelWT_toScint); + MyFill(table,"sabreRelRTScint_sabreRelRTAnode",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelRT); + MyFill(table,"sabreRelRTScint_sabreRingChannel",500,-3000,3500,sabreRelRT_toScint,144,0,144,ev.sabreRingChannel[i]); + MyFill(table,"sabreRelRTAnode_sabreRingChannel",500,-3000,3500,sabreRelRT,144,0,144,ev.sabreRingChannel[i]); + MyFill(table,"sabreRelWTScint_sabreWedgeChannel",500,-3000,3500,sabreRelWT_toScint,144,0,144,ev.sabreWedgeChannel[i]); + MyFill(table,"sabreRelRT_sabreRelWT",500,-3000,3500,sabreRelRT,500,-3000,3500,sabreRelWT); + MyFill(table,"sabreRelRT_sabreRelWT_scint",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelWT_toScint); + MyFill(table,"sabreRelRTScint_anodeRelT",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,anodeRelBT); + } + } + MyFill(table,"anodeBackRelTime_toScint",1000,-3000,3500,anodeRelBT); + MyFill(table,"delayRelBackTime_toScint",1000,-3000,3500,delayRelBT_toScint); + MyFill(table,"delayRelFrontTime_toScint",1000,-3000,3500,delayRelFT_toScint); + } + else + MyFill(table,"noscinttime_counter_NoCuts",2,0,1,1); + + for(int i=0; i<5; i++) + { + if(ev.sabreRingE[i] != -1) //Again, at this point front&back are required + { + MyFill(table,"sabreRingE_NoCuts",2000,0,20,ev.sabreRingE[i]); + MyFill(table,"sabreRingChannel_sabreRingE_NoCuts",144,0,144,ev.sabreRingChannel[i],200,0,20,ev.sabreRingE[i]); + MyFill(table,"sabreWedgeE_NoCuts",2000,0,20,ev.sabreWedgeE[i]); + MyFill(table,"sabreWedgeChannel_sabreWedgeE_NoCuts",144,0,144,ev.sabreWedgeChannel[i],200,0,20,ev.sabreWedgeE[i]); + } + } + + if(ev.x1 != -1e6 && ev.x2 == -1e6) + MyFill(table,"x1NoCuts_only1plane",600,-300,300,ev.x1); + else if(ev.x2 != -1e6 && ev.x1 == -1e6) + MyFill(table,"x2NoCuts_only1plane",600,-300,300,ev.x2); + else if(ev.x1 == -1e6 && ev.x2 == -1e6) + MyFill(table,"nopos_counter",2,0,1,1); + } + + /*Makes histograms with cuts & gates implemented*/ + void SFPPlotter::MakeCutHistograms(const ProcessedEvent& ev, THashTable* table) + { + if(!cutter.IsInside(&ev)) + return; + + MyFill(table,"x1_bothplanes_Cut",600,-300,300,ev.x1); + MyFill(table,"x2_bothplanes_Cut",600,-300,300,ev.x2); + MyFill(table,"xavg_bothplanes_Cut",600,-300,300,ev.xavg); + MyFill(table,"x1_x2_Cut",600,-300,300,ev.x1, 600,-300,300,ev.x2); + MyFill(table,"xavg_theta_Cut_bothplanes",600,-300,300,ev.xavg,100,0,TMath::Pi()/2.,ev.theta); + + MyFill(table,"x1_delayBackRightE_Cut",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE); + MyFill(table,"x2_delayBackRightE_Cut",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE); + MyFill(table,"xavg_delayBackRightE_Cut",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE); + + Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0; + MyFill(table,"x1_delayBackAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayBackAvgE); + MyFill(table,"x2_delayBackAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayBackAvgE); + MyFill(table,"xavg_delayBackAvgE_Cut",600,-300,300,ev.xavg,512,0,4096,delayBackAvgE); + Double_t delayFrontAvgE = (ev.delayFrontRightE+ev.delayFrontLeftE)/2.0; + MyFill(table,"x1_delayFrontAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE); + MyFill(table,"x2_delayFrontAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE); + MyFill(table,"xavg_delayFrontAvgE_Cut",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE); + + MyFill(table,"scintLeft_anodeBack_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack); + MyFill(table,"scintLeft_anodeFront_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront); + MyFill(table,"scintLeft_cathode_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode); + + MyFill(table,"x1_scintLeft_Cut",600,-300,300,ev.x1,512,0,4096,ev.scintLeft); + MyFill(table,"x2_scintLeft_Cut",600,-300,300,ev.x2,512,0,4096,ev.scintLeft); + MyFill(table,"xavg_scintLeft_Cut",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft); + + MyFill(table,"x1_anodeBack_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeBack); + MyFill(table,"x2_anodeBack_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeBack); + MyFill(table,"xavg_anodeBack_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack); + + MyFill(table,"x1_anodeFront_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeFront); + MyFill(table,"x2_anodeFront_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeFront); + MyFill(table,"xavg_anodeFront_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront); + + MyFill(table,"x1_cathode_Cut",600,-300,300,ev.x1,512,0,4096,ev.cathode); + MyFill(table,"x2_cathode_Cut",600,-300,300,ev.x2,512,0,4096,ev.cathode); + MyFill(table,"xavg_cathode_Cut",600,-300,300,ev.xavg,512,0,4096,ev.cathode); + + /****Timing relative to back anode****/ + if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1) + { + Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime; + Double_t anodeRelBT = ev.anodeBackTime - ev.anodeBackTime; + Double_t anodeRelFT_toScint = ev.anodeFrontTime-ev.scintLeftTime; + MyFill(table,"anodeRelBackTime_Cut",1000,-3000,3500, anodeRelBT); + MyFill(table,"anodeRelFrontTime_Cut",1000,-3000,3500, anodeRelFT); + MyFill(table,"anodeRelTime_toScint_Cut",1000,-3000,3500,anodeRelFT_toScint); + for(int i=0; i<5; i++) + { + if(ev.sabreRingE[i] != -1) + { + Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime; + Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; + MyFill(table,"sabreRelRingTime_Cut",1000,-3000,3500, sabreRelRT); + MyFill(table,"sabreRelWedgeTime_Cut",1000,-3000,3500, sabreRelWT); + } + } + } + else + { + MyFill(table,"noscinttime_counter_Cut",2,0,1,1); + } + for(int i=0; i<5; i++) { if(ev.sabreRingE[i] != -1) { - Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime; - Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; - Double_t sabreRelRT_toScint = ev.sabreRingTime[i] - ev.scintLeftTime; - Double_t sabreRelWT_toScint = ev.sabreWedgeTime[i] - ev.scintLeftTime; - MyFill(table,"xavg_sabrefcoinc_NoCuts",600,-300,300, ev.xavg); - MyFill(table,"sabreRelRingTime_NoCuts",1000,-3000,3500, sabreRelRT); - MyFill(table,"sabreRelWedgeTime_NoCuts",1000,-3000,3500, sabreRelWT); - MyFill(table,"sabreRelRingTime_toScint",1000,-3000,3500,sabreRelRT_toScint); - MyFill(table,"sabreRelWedgeTime_toScint",1000,-3000,3500,sabreRelWT_toScint); - MyFill(table,"sabreRelRTScint_sabreRelRTAnode",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelRT); - MyFill(table,"sabreRelRTScint_sabreRingChannel",500,-3000,3500,sabreRelRT_toScint,144,0,144,ev.sabreRingChannel[i]); - MyFill(table,"sabreRelRTAnode_sabreRingChannel",500,-3000,3500,sabreRelRT,144,0,144,ev.sabreRingChannel[i]); - MyFill(table,"sabreRelWTScint_sabreWedgeChannel",500,-3000,3500,sabreRelWT_toScint,144,0,144,ev.sabreWedgeChannel[i]); - MyFill(table,"sabreRelRT_sabreRelWT",500,-3000,3500,sabreRelRT,500,-3000,3500,sabreRelWT); - MyFill(table,"sabreRelRT_sabreRelWT_scint",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelWT_toScint); - MyFill(table,"sabreRelRTScint_anodeRelT",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,anodeRelBT); + MyFill(table,"sabreRingE_Cut",2000,0,20,ev.sabreRingE[i]); + MyFill(table,"xavg_Cut_sabrefcoinc",600,-300,300,ev.xavg); + MyFill(table,"xavg_sabreRingE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreRingE[i]); + MyFill(table,"sabreWedgeE_Cut",2000,0,20,ev.sabreWedgeE[i]); + MyFill(table,"xavg_sabreWedgeE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreWedgeE[i]); } } - MyFill(table,"anodeBackRelTime_toScint",1000,-3000,3500,anodeRelBT); - MyFill(table,"delayRelBackTime_toScint",1000,-3000,3500,delayRelBT_toScint); - MyFill(table,"delayRelFrontTime_toScint",1000,-3000,3500,delayRelFT_toScint); - } - else - MyFill(table,"noscinttime_counter_NoCuts",2,0,1,1); - - for(int i=0; i<5; i++) - { - if(ev.sabreRingE[i] != -1) //Again, at this point front&back are required - { - MyFill(table,"sabreRingE_NoCuts",2000,0,20,ev.sabreRingE[i]); - MyFill(table,"sabreRingChannel_sabreRingE_NoCuts",144,0,144,ev.sabreRingChannel[i],200,0,20,ev.sabreRingE[i]); - MyFill(table,"sabreWedgeE_NoCuts",2000,0,20,ev.sabreWedgeE[i]); - MyFill(table,"sabreWedgeChannel_sabreWedgeE_NoCuts",144,0,144,ev.sabreWedgeChannel[i],200,0,20,ev.sabreWedgeE[i]); - } } - if(ev.x1 != -1e6 && ev.x2 == -1e6) - MyFill(table,"x1NoCuts_only1plane",600,-300,300,ev.x1); - else if(ev.x2 != -1e6 && ev.x1 == -1e6) - MyFill(table,"x2NoCuts_only1plane",600,-300,300,ev.x2); - else if(ev.x1 == -1e6 && ev.x2 == -1e6) - MyFill(table,"nopos_counter",2,0,1,1); -} - -/*Makes histograms with cuts & gates implemented*/ -void SFPPlotter::MakeCutHistograms(const ProcessedEvent& ev, THashTable* table) -{ - if(!cutter.IsInside(&ev)) - return; - - MyFill(table,"x1_bothplanes_Cut",600,-300,300,ev.x1); - MyFill(table,"x2_bothplanes_Cut",600,-300,300,ev.x2); - MyFill(table,"xavg_bothplanes_Cut",600,-300,300,ev.xavg); - MyFill(table,"x1_x2_Cut",600,-300,300,ev.x1, 600,-300,300,ev.x2); - MyFill(table,"xavg_theta_Cut_bothplanes",600,-300,300,ev.xavg,100,0,TMath::Pi()/2.,ev.theta); - - MyFill(table,"x1_delayBackRightE_Cut",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE); - MyFill(table,"x2_delayBackRightE_Cut",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE); - MyFill(table,"xavg_delayBackRightE_Cut",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE); - - Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0; - MyFill(table,"x1_delayBackAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayBackAvgE); - MyFill(table,"x2_delayBackAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayBackAvgE); - MyFill(table,"xavg_delayBackAvgE_Cut",600,-300,300,ev.xavg,512,0,4096,delayBackAvgE); - Double_t delayFrontAvgE = (ev.delayFrontRightE+ev.delayFrontLeftE)/2.0; - MyFill(table,"x1_delayFrontAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE); - MyFill(table,"x2_delayFrontAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE); - MyFill(table,"xavg_delayFrontAvgE_Cut",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE); - - MyFill(table,"scintLeft_anodeBack_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack); - MyFill(table,"scintLeft_anodeFront_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront); - MyFill(table,"scintLeft_cathode_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode); - - MyFill(table,"x1_scintLeft_Cut",600,-300,300,ev.x1,512,0,4096,ev.scintLeft); - MyFill(table,"x2_scintLeft_Cut",600,-300,300,ev.x2,512,0,4096,ev.scintLeft); - MyFill(table,"xavg_scintLeft_Cut",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft); - - MyFill(table,"x1_anodeBack_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeBack); - MyFill(table,"x2_anodeBack_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeBack); - MyFill(table,"xavg_anodeBack_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack); - - MyFill(table,"x1_anodeFront_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeFront); - MyFill(table,"x2_anodeFront_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeFront); - MyFill(table,"xavg_anodeFront_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront); - - MyFill(table,"x1_cathode_Cut",600,-300,300,ev.x1,512,0,4096,ev.cathode); - MyFill(table,"x2_cathode_Cut",600,-300,300,ev.x2,512,0,4096,ev.cathode); - MyFill(table,"xavg_cathode_Cut",600,-300,300,ev.xavg,512,0,4096,ev.cathode); - - /****Timing relative to back anode****/ - if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1) + /*Runs a list of files given from a RunCollector class*/ + void SFPPlotter::Run(const std::vector& files, const std::string& output) { - Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime; - Double_t anodeRelBT = ev.anodeBackTime - ev.anodeBackTime; - Double_t anodeRelFT_toScint = ev.anodeFrontTime-ev.scintLeftTime; - MyFill(table,"anodeRelBackTime_Cut",1000,-3000,3500, anodeRelBT); - MyFill(table,"anodeRelFrontTime_Cut",1000,-3000,3500, anodeRelFT); - MyFill(table,"anodeRelTime_toScint_Cut",1000,-3000,3500,anodeRelFT_toScint); - for(int i=0; i<5; i++) + TFile *outfile = TFile::Open(output.c_str(), "RECREATE"); + TChain* chain = new TChain("SPSTree"); + for(unsigned int i=0; iAdd(files[i].c_str()); + chain->SetBranchAddress("event", &event_address); + THashTable* table = new THashTable(); + + long blentries = chain->GetEntries(); + if(m_pb) + SetProgressBar(blentries); + std::cout<<"Total number of events: "<GetEntries(); i++) { - if(ev.sabreRingE[i] != -1) + count++; + if(count == flush_val) { - Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime; - Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; - MyFill(table,"sabreRelRingTime_Cut",1000,-3000,3500, sabreRelRT); - MyFill(table,"sabreRelWedgeTime_Cut",1000,-3000,3500, sabreRelWT); - } + if(m_pb) { + m_pb->Increment(count); + gSystem->ProcessEvents(); + count = 0; + } else { + flush_count++; + count=0; + std::cout<<"\rPercent of data processed: "<GetEntry(i); + MakeUncutHistograms(*event_address, table); + if(cutter.IsValid()) MakeCutHistograms(*event_address, table); } - } - else - { - MyFill(table,"noscinttime_counter_Cut",2,0,1,1); + std::cout<cd(); + table->Write(); + if(cutter.IsValid()) + { + auto clist = cutter.GetCuts(); + for(unsigned int i=0; iWrite(); + } + delete table; + outfile->Close(); + delete outfile; } - for(int i=0; i<5; i++) + + void SFPPlotter::SetProgressBar(long total) { - if(ev.sabreRingE[i] != -1) - { - MyFill(table,"sabreRingE_Cut",2000,0,20,ev.sabreRingE[i]); - MyFill(table,"xavg_Cut_sabrefcoinc",600,-300,300,ev.xavg); - MyFill(table,"xavg_sabreRingE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreRingE[i]); - MyFill(table,"sabreWedgeE_Cut",2000,0,20,ev.sabreWedgeE[i]); - MyFill(table,"xavg_sabreWedgeE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreWedgeE[i]); - } + m_pb->SetMax(total); + m_pb->SetMin(0); + m_pb->SetPosition(0); + gSystem->ProcessEvents(); } -} -/*Runs a list of files given from a RunCollector class*/ -void SFPPlotter::Run(const std::vector& files, const std::string& output) -{ - TFile *outfile = TFile::Open(output.c_str(), "RECREATE"); - TChain* chain = new TChain("SPSTree"); - for(unsigned int i=0; iAdd(files[i].c_str()); - chain->SetBranchAddress("event", &event_address); - THashTable* table = new THashTable(); - - long blentries = chain->GetEntries(); - if(m_pb) - SetProgressBar(blentries); - std::cout<<"Total number of events: "<GetEntries(); i++) - { - count++; - if(count == flush_val) - { - if(m_pb) { - m_pb->Increment(count); - gSystem->ProcessEvents(); - count = 0; - } else { - flush_count++; - count=0; - std::cout<<"\rPercent of data processed: "<GetEntry(i); - MakeUncutHistograms(*event_address, table); - if(cutter.IsValid()) MakeCutHistograms(*event_address, table); - } - std::cout<cd(); - table->Write(); - if(cutter.IsValid()) - { - auto clist = cutter.GetCuts(); - for(unsigned int i=0; iWrite(); - } - delete table; - outfile->Close(); - delete outfile; -} - - -void SFPPlotter::SetProgressBar(long total) -{ - m_pb->SetMax(total); - m_pb->SetMin(0); - m_pb->SetPosition(0); - gSystem->ProcessEvents(); -} +} \ No newline at end of file diff --git a/src/evb/SFPPlotter.h b/src/evb/SFPPlotter.h index 3217093..3584aa5 100644 --- a/src/evb/SFPPlotter.h +++ b/src/evb/SFPPlotter.h @@ -13,33 +13,37 @@ #include "CutHandler.h" #include -class SFPPlotter -{ -public: - SFPPlotter(); - ~SFPPlotter(); - inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; } - inline void ApplyCutlist(const std::string& listname) { cutter.SetCuts(listname); } - void Run(const std::vector& files, const std::string& output); +namespace EventBuilder { -private: - void SetProgressBar(long total); - void Chain(const std::vector& files); //Form TChain - void MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table); - void MakeCutHistograms(const ProcessedEvent& ev, THashTable* table); - - /*Histogram fill wrapper functions*/ - void MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex, - int binsy, double miny, double maxy, double valuey); - void MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex); - - ProcessedEvent *event_address; - - /*Cuts*/ - CutHandler cutter; + class SFPPlotter + { + public: + SFPPlotter(); + ~SFPPlotter(); + inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; } + inline void ApplyCutlist(const std::string& listname) { cutter.SetCuts(listname); } + void Run(const std::vector& files, const std::string& output); - TGProgressBar* m_pb; //GUI progress + private: + void SetProgressBar(long total); + void Chain(const std::vector& files); //Form TChain + void MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table); + void MakeCutHistograms(const ProcessedEvent& ev, THashTable* table); + + /*Histogram fill wrapper functions*/ + void MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex, + int binsy, double miny, double maxy, double valuey); + void MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex); + + ProcessedEvent *event_address; + + /*Cuts*/ + CutHandler cutter; + + TGProgressBar* m_pb; //GUI progress + + }; -}; +} #endif diff --git a/src/evb/ShiftMap.cpp b/src/evb/ShiftMap.cpp index 36ff583..91b8eda 100644 --- a/src/evb/ShiftMap.cpp +++ b/src/evb/ShiftMap.cpp @@ -12,70 +12,74 @@ #include "EventBuilder.h" #include "ShiftMap.h" -ShiftMap::ShiftMap() : - m_filename(""), m_validFlag(false) -{ -} +namespace EventBuilder { -ShiftMap::ShiftMap(const std::string& filename) : - m_filename(filename), m_validFlag(false) -{ - ParseFile(); -} - -ShiftMap::~ShiftMap() {} - -void ShiftMap::SetFile(const std::string& filename) -{ - m_filename = filename; - ParseFile(); -} - -uint64_t ShiftMap::GetShift(int gchan) -{ - if(!m_validFlag) - return 0; - - auto iter = m_map.find(gchan); - if(iter == m_map.end()) - return 0; - else - return iter->second; -} - -void ShiftMap::ParseFile() -{ - m_validFlag = false; - std::ifstream input(m_filename); - if(!input.is_open()) - return; - - int board, channel, gchan; - uint64_t shift; - std::string junk, temp; - - std::getline(input, junk); - std::getline(input, junk); - - while(input>>board) + ShiftMap::ShiftMap() : + m_filename(""), m_validFlag(false) { - input>>temp; - input>>shift; - if(temp == "all") //keyword to set all channels in this board to same shift - { - for(int i=0; i<16; i++) + } + + ShiftMap::ShiftMap(const std::string& filename) : + m_filename(filename), m_validFlag(false) + { + ParseFile(); + } + + ShiftMap::~ShiftMap() {} + + void ShiftMap::SetFile(const std::string& filename) + { + m_filename = filename; + ParseFile(); + } + + uint64_t ShiftMap::GetShift(int gchan) + { + if(!m_validFlag) + return 0; + + auto iter = m_map.find(gchan); + if(iter == m_map.end()) + return 0; + else + return iter->second; + } + + void ShiftMap::ParseFile() + { + m_validFlag = false; + std::ifstream input(m_filename); + if(!input.is_open()) + return; + + int board, channel, gchan; + uint64_t shift; + std::string junk, temp; + + std::getline(input, junk); + std::getline(input, junk); + + while(input>>board) + { + input>>temp; + input>>shift; + if(temp == "all") //keyword to set all channels in this board to same shift + { + for(int i=0; i<16; i++) + { + gchan = board*16 + i; + m_map[gchan] = shift; + } + } + else { - gchan = board*16 + i; + channel = stoi(temp); + gchan = channel + board*16; m_map[gchan] = shift; } } - else - { - channel = stoi(temp); - gchan = channel + board*16; - m_map[gchan] = shift; - } + + m_validFlag = true; } - m_validFlag = true; -} +} \ No newline at end of file diff --git a/src/evb/ShiftMap.h b/src/evb/ShiftMap.h index 2d21eea..b13dfb5 100644 --- a/src/evb/ShiftMap.h +++ b/src/evb/ShiftMap.h @@ -12,25 +12,29 @@ #ifndef SHIFTMAP_H #define SHIFTMAP_H -class ShiftMap -{ -public: - ShiftMap(); - ShiftMap(const std::string& filename); - ~ShiftMap(); - void SetFile(const std::string& filename); - inline bool IsValid() { return m_validFlag; } - inline std::string GetFilename() { return m_filename; } - uint64_t GetShift(int gchan); +namespace EventBuilder { -private: - void ParseFile(); + class ShiftMap + { + public: + ShiftMap(); + ShiftMap(const std::string& filename); + ~ShiftMap(); + void SetFile(const std::string& filename); + inline bool IsValid() { return m_validFlag; } + inline std::string GetFilename() { return m_filename; } + uint64_t GetShift(int gchan); + + private: + void ParseFile(); + + std::string m_filename; + bool m_validFlag; + + std::unordered_map m_map; + + }; - std::string m_filename; - bool m_validFlag; - - std::unordered_map m_map; - -}; +} #endif diff --git a/src/evb/SlowSort.cpp b/src/evb/SlowSort.cpp index faff4c1..07ec53c 100644 --- a/src/evb/SlowSort.cpp +++ b/src/evb/SlowSort.cpp @@ -10,171 +10,175 @@ #include "EventBuilder.h" #include "SlowSort.h" -/*Sort the Sabre Data in order of descending energy*/ -bool SabreSort(const DetectorHit& i, const DetectorHit& j) { - return (i.Long>j.Long); -} +namespace EventBuilder { -/*Constructor takes input of coincidence window size, and fills sabre channel map*/ -SlowSort::SlowSort() : - m_coincWindow(-1.0), m_eventFlag(false) -{ - event_stats = new TH2F("coinc_event_stats","coinc_events_stats;global channel;number of coincident hits;counts",144,0,144,20,0,20); -} - -SlowSort::SlowSort(double windowSize, const std::string& mapfile) : - m_coincWindow(windowSize), m_eventFlag(false), m_event(), cmap(mapfile) -{ - event_stats = new TH2F("coinc_event_stats","coinc_events_stats;global channel;number of coincident hits;counts",144,0,144,20,0,20); - InitVariableMaps(); -} - -SlowSort::~SlowSort() {} - -/**EXPERIMENT MODS go here**/ -void SlowSort::InitVariableMaps() -{ - - /*For SABRE: Each SABRE det has ring&wedge, so add the detID to the - SABRERING/WEDGE attribute to differentiate*/ - varMap[DetAttribute::SabreRing0] = &m_event.sabreArray[0].rings; - varMap[DetAttribute::SabreRing1] = &m_event.sabreArray[1].rings; - varMap[DetAttribute::SabreRing2] = &m_event.sabreArray[2].rings; - varMap[DetAttribute::SabreRing3] = &m_event.sabreArray[3].rings; - varMap[DetAttribute::SabreRing4] = &m_event.sabreArray[4].rings; - varMap[DetAttribute::SabreWedge0] = &m_event.sabreArray[0].wedges; - varMap[DetAttribute::SabreWedge1] = &m_event.sabreArray[1].wedges; - varMap[DetAttribute::SabreWedge2] = &m_event.sabreArray[2].wedges; - varMap[DetAttribute::SabreWedge3] = &m_event.sabreArray[3].wedges; - varMap[DetAttribute::SabreWedge4] = &m_event.sabreArray[4].wedges; - - /*For focal plane: Only one focal plane, so each variable is uniquely - identified by its attribute - */ - varMap[DetAttribute::ScintLeft] = &m_event.focalPlane.scintL; - varMap[DetAttribute::ScintRight] = &m_event.focalPlane.scintR; - varMap[DetAttribute::Cathode] = &m_event.focalPlane.cathode; - varMap[DetAttribute::DelayFR] = &m_event.focalPlane.delayFR; - varMap[DetAttribute::DelayFL] = &m_event.focalPlane.delayFL; - varMap[DetAttribute::DelayBL] = &m_event.focalPlane.delayBL; - varMap[DetAttribute::DelayBR] = &m_event.focalPlane.delayBR; - varMap[DetAttribute::AnodeFront] = &m_event.focalPlane.anodeF; - varMap[DetAttribute::AnodeBack] = &m_event.focalPlane.anodeB; - varMap[DetAttribute::Monitor] = &m_event.focalPlane.monitor; - -} - -/*Reset output structure to blank*/ -void SlowSort::Reset() -{ - m_event = m_blank; -} - -bool SlowSort::AddHitToEvent(CompassHit& mhit) -{ - DPPChannel curHit; - curHit.Timestamp = mhit.timestamp; - curHit.Energy = mhit.lgate; - curHit.EnergyShort = mhit.sgate; - curHit.Channel = mhit.channel; - curHit.Board = mhit.board; - curHit.Flags = mhit.flags; - - if(m_hitList.empty()) - { - startTime = curHit.Timestamp; - m_hitList.push_back(curHit); - } - else if (curHit.Timestamp < previousHitTime) - return false; - else if ((curHit.Timestamp - startTime) < m_coincWindow) - m_hitList.push_back(curHit); - else - { - ProcessEvent(); - m_hitList.clear(); - startTime = curHit.Timestamp; - m_hitList.push_back(curHit); - m_eventFlag = true; + /*Sort the Sabre Data in order of descending energy*/ + bool SabreSort(const DetectorHit& i, const DetectorHit& j) { + return (i.Long>j.Long); } - - return true; -} - -void SlowSort::FlushHitsToEvent() -{ - if(m_hitList.empty()) + + /*Constructor takes input of coincidence window size, and fills sabre channel map*/ + SlowSort::SlowSort() : + m_coincWindow(-1.0), m_eventFlag(false) { - m_eventFlag = false; - return; + event_stats = new TH2F("coinc_event_stats","coinc_events_stats;global channel;number of coincident hits;counts",144,0,144,20,0,20); } - - ProcessEvent(); - m_hitList.clear(); - m_eventFlag = true; -} - -const CoincEvent& SlowSort::GetEvent() -{ - m_eventFlag = false; - return m_event; -} - -/*Function called when an event outside the coincidence window is detected - *Process all of the hits in the list, and write them to the sorted tree - */ -void SlowSort::ProcessEvent() -{ - Reset(); - DetectorHit dhit; - int gchan; - int size = m_hitList.size(); - for(DPPChannel& curHit: m_hitList) + + SlowSort::SlowSort(double windowSize, const std::string& mapfile) : + m_coincWindow(windowSize), m_eventFlag(false), m_event(), cmap(mapfile) { - gchan = curHit.Channel + curHit.Board*16; //global channel - event_stats->Fill(gchan, size); - dhit.Time = curHit.Timestamp/1.0e3; - dhit.Ch = gchan; - dhit.Long = curHit.Energy; - dhit.Short = curHit.EnergyShort; - auto channel_info = cmap.FindChannel(gchan); - - if(channel_info == cmap.End()) + event_stats = new TH2F("coinc_event_stats","coinc_events_stats;global channel;number of coincident hits;counts",144,0,144,20,0,20); + InitVariableMaps(); + } + + SlowSort::~SlowSort() {} + + /**EXPERIMENT MODS go here**/ + void SlowSort::InitVariableMaps() + { + + /*For SABRE: Each SABRE det has ring&wedge, so add the detID to the + SABRERING/WEDGE attribute to differentiate*/ + varMap[DetAttribute::SabreRing0] = &m_event.sabreArray[0].rings; + varMap[DetAttribute::SabreRing1] = &m_event.sabreArray[1].rings; + varMap[DetAttribute::SabreRing2] = &m_event.sabreArray[2].rings; + varMap[DetAttribute::SabreRing3] = &m_event.sabreArray[3].rings; + varMap[DetAttribute::SabreRing4] = &m_event.sabreArray[4].rings; + varMap[DetAttribute::SabreWedge0] = &m_event.sabreArray[0].wedges; + varMap[DetAttribute::SabreWedge1] = &m_event.sabreArray[1].wedges; + varMap[DetAttribute::SabreWedge2] = &m_event.sabreArray[2].wedges; + varMap[DetAttribute::SabreWedge3] = &m_event.sabreArray[3].wedges; + varMap[DetAttribute::SabreWedge4] = &m_event.sabreArray[4].wedges; + + /*For focal plane: Only one focal plane, so each variable is uniquely + identified by its attribute + */ + varMap[DetAttribute::ScintLeft] = &m_event.focalPlane.scintL; + varMap[DetAttribute::ScintRight] = &m_event.focalPlane.scintR; + varMap[DetAttribute::Cathode] = &m_event.focalPlane.cathode; + varMap[DetAttribute::DelayFR] = &m_event.focalPlane.delayFR; + varMap[DetAttribute::DelayFL] = &m_event.focalPlane.delayFL; + varMap[DetAttribute::DelayBL] = &m_event.focalPlane.delayBL; + varMap[DetAttribute::DelayBR] = &m_event.focalPlane.delayBR; + varMap[DetAttribute::AnodeFront] = &m_event.focalPlane.anodeF; + varMap[DetAttribute::AnodeBack] = &m_event.focalPlane.anodeB; + varMap[DetAttribute::Monitor] = &m_event.focalPlane.monitor; + + } + + /*Reset output structure to blank*/ + void SlowSort::Reset() + { + m_event = m_blank; + } + + bool SlowSort::AddHitToEvent(CompassHit& mhit) + { + DPPChannel curHit; + curHit.Timestamp = mhit.timestamp; + curHit.Energy = mhit.lgate; + curHit.EnergyShort = mhit.sgate; + curHit.Channel = mhit.channel; + curHit.Board = mhit.board; + curHit.Flags = mhit.flags; + + if(m_hitList.empty()) { - std::cout<second.type == DetType::FocalPlane) - { - auto variable = varMap.find(channel_info->second.attribute); - if(variable != varMap.end()) - variable->second->push_back(dhit); + startTime = curHit.Timestamp; + m_hitList.push_back(curHit); } - else if(channel_info->second.type == DetType::Sabre) - { - auto variable = varMap.find(channel_info->second.attribute); - if(variable != varMap.end()) - variable->second->push_back(dhit); - } + else if (curHit.Timestamp < previousHitTime) + return false; + else if ((curHit.Timestamp - startTime) < m_coincWindow) + m_hitList.push_back(curHit); else { - std::cout<second.type<<" attribute: "<second.attribute<Fill(gchan, size); + dhit.Time = curHit.Timestamp/1.0e3; + dhit.Ch = gchan; + dhit.Long = curHit.Energy; + dhit.Short = curHit.EnergyShort; + auto channel_info = cmap.FindChannel(gchan); + + if(channel_info == cmap.End()) + { + std::cout<second.type == DetType::FocalPlane) + { + auto variable = varMap.find(channel_info->second.attribute); + if(variable != varMap.end()) + variable->second->push_back(dhit); + } + else if(channel_info->second.type == DetType::Sabre) + { + auto variable = varMap.find(channel_info->second.attribute); + if(variable != varMap.end()) + variable->second->push_back(dhit); + } + else + { + std::cout<second.type<<" attribute: "<second.attribute< #include -class SlowSort -{ +namespace EventBuilder { -public: - SlowSort(); - SlowSort(double windowSize, const std::string& mapfile); - ~SlowSort(); - inline void SetWindowSize(double window) { m_coincWindow = window; } - inline bool SetMapFile(const std::string& mapfile) { return cmap.FillMap(mapfile); } - bool AddHitToEvent(CompassHit& mhit); - const CoincEvent& GetEvent(); - inline TH2F* GetEventStats() { return event_stats; } - void FlushHitsToEvent(); //For use with *last* hit list - inline bool IsEventReady() { return m_eventFlag; } - -private: - void InitVariableMaps(); - void Reset(); - void ProcessEvent(); - - double m_coincWindow; - std::vector m_hitList; - bool m_eventFlag; - CoincEvent m_event; - CoincEvent m_blank; + class SlowSort + { - double startTime, previousHitTime; - std::unordered_map*> varMap; + public: + SlowSort(); + SlowSort(double windowSize, const std::string& mapfile); + ~SlowSort(); + inline void SetWindowSize(double window) { m_coincWindow = window; } + inline bool SetMapFile(const std::string& mapfile) { return cmap.FillMap(mapfile); } + bool AddHitToEvent(CompassHit& mhit); + const CoincEvent& GetEvent(); + inline TH2F* GetEventStats() { return event_stats; } + void FlushHitsToEvent(); //For use with *last* hit list + inline bool IsEventReady() { return m_eventFlag; } + + private: + void InitVariableMaps(); + void Reset(); + void ProcessEvent(); + + double m_coincWindow; + std::vector m_hitList; + bool m_eventFlag; + CoincEvent m_event; + CoincEvent m_blank; + + double startTime, previousHitTime; + std::unordered_map*> varMap; + + TH2F* event_stats; + + ChannelMap cmap; + + }; - TH2F* event_stats; - - ChannelMap cmap; - -}; +} #endif diff --git a/src/evb/Stopwatch.cpp b/src/evb/Stopwatch.cpp index ba0a738..95feb6e 100644 --- a/src/evb/Stopwatch.cpp +++ b/src/evb/Stopwatch.cpp @@ -8,30 +8,34 @@ #include "EventBuilder.h" #include "Stopwatch.h" -Stopwatch::Stopwatch() -{ - start_time = Clock::now(); - stop_time = start_time; -} +namespace EventBuilder { -Stopwatch::~Stopwatch() {} + Stopwatch::Stopwatch() + { + start_time = Clock::now(); + stop_time = start_time; + } + + Stopwatch::~Stopwatch() {} + + void Stopwatch::Start() + { + start_time = Clock::now(); + } + + void Stopwatch::Stop() + { + stop_time = Clock::now(); + } + + double Stopwatch::GetElapsedSeconds() + { + return std::chrono::duration_cast>(stop_time-start_time).count(); + } + + double Stopwatch::GetElapsedMilliseconds() + { + return std::chrono::duration_cast>(stop_time-start_time).count()*1000.0; + } -void Stopwatch::Start() -{ - start_time = Clock::now(); -} - -void Stopwatch::Stop() -{ - stop_time = Clock::now(); -} - -double Stopwatch::GetElapsedSeconds() -{ - return std::chrono::duration_cast>(stop_time-start_time).count(); -} - -double Stopwatch::GetElapsedMilliseconds() -{ - return std::chrono::duration_cast>(stop_time-start_time).count()*1000.0; } \ No newline at end of file diff --git a/src/evb/Stopwatch.h b/src/evb/Stopwatch.h index 211a5fe..1242e46 100644 --- a/src/evb/Stopwatch.h +++ b/src/evb/Stopwatch.h @@ -10,21 +10,25 @@ #include -class Stopwatch -{ -public: - Stopwatch(); - ~Stopwatch(); - void Start(); - void Stop(); - double GetElapsedSeconds(); - double GetElapsedMilliseconds(); +namespace EventBuilder { -private: - using Time = std::chrono::high_resolution_clock::time_point; - using Clock = std::chrono::high_resolution_clock; + class Stopwatch + { + public: + Stopwatch(); + ~Stopwatch(); + void Start(); + void Stop(); + double GetElapsedSeconds(); + double GetElapsedMilliseconds(); + + private: + using Time = std::chrono::high_resolution_clock::time_point; + using Clock = std::chrono::high_resolution_clock; + + Time start_time, stop_time; + }; - Time start_time, stop_time; -}; +} #endif \ No newline at end of file diff --git a/src/gui_main.cpp b/src/gui_main.cpp index 145b4aa..1654109 100644 --- a/src/gui_main.cpp +++ b/src/gui_main.cpp @@ -1,7 +1,7 @@ -#include "EventBuilder.h" +#include "evb/EventBuilder.h" #include "spsdict/DataStructs.h" #include -#include "EVBMainFrame.h" +#include "guidict/EVBMainFrame.h" int main(int argc, char** argv) { diff --git a/src/guidict/EVBMainFrame.cpp b/src/guidict/EVBMainFrame.cpp index 1c33fca..bede627 100644 --- a/src/guidict/EVBMainFrame.cpp +++ b/src/guidict/EVBMainFrame.cpp @@ -142,13 +142,13 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) : TGLabel *typelabel = new TGLabel(RunFrame, "Operation Type:"); fTypeBox = new TGComboBox(RunFrame, TypeBox); //Needs modification for new conversion based sorting GWM -- Dec 2020 - fTypeBox->AddEntry("Convert Slow", EVBApp::Operation::ConvertSlow); - fTypeBox->AddEntry("Convert Fast", EVBApp::Operation::ConvertFast); - fTypeBox->AddEntry("Convert SlowA", EVBApp::Operation::ConvertSlowA); - fTypeBox->AddEntry("Convert FastA", EVBApp::Operation::ConvertFastA); - fTypeBox->AddEntry("Convert", EVBApp::Operation::Convert); - fTypeBox->AddEntry("Merge ROOT", EVBApp::Operation::Merge); - fTypeBox->AddEntry("Plot", EVBApp::Operation::Plot); + fTypeBox->AddEntry("Convert Slow", EventBuilder::EVBApp::Operation::ConvertSlow); + fTypeBox->AddEntry("Convert Fast", EventBuilder::EVBApp::Operation::ConvertFast); + fTypeBox->AddEntry("Convert SlowA", EventBuilder::EVBApp::Operation::ConvertSlowA); + fTypeBox->AddEntry("Convert FastA", EventBuilder::EVBApp::Operation::ConvertFastA); + fTypeBox->AddEntry("Convert", EventBuilder::EVBApp::Operation::Convert); + fTypeBox->AddEntry("Merge ROOT", EventBuilder::EVBApp::Operation::Merge); + fTypeBox->AddEntry("Plot", EventBuilder::EVBApp::Operation::Plot); fTypeBox->Resize(200,20); fTypeBox->Connect("Selected(Int_t, Int_t)","EVBMainFrame",this,"HandleTypeSelection(Int_t,Int_t)"); TGLabel *rminlabel = new TGLabel(RunFrame, "Min Run:"); @@ -256,37 +256,37 @@ void EVBMainFrame::DoRun() switch(type) { - case EVBApp::Operation::Plot : + case EventBuilder::EVBApp::Operation::Plot : { RunPlot(); break; } - case EVBApp::Operation::Convert : + case EventBuilder::EVBApp::Operation::Convert : { fBuilder.Convert2RawRoot(); break; } - case EVBApp::Operation::Merge : + case EventBuilder::EVBApp::Operation::Merge : { fBuilder.MergeROOTFiles(); break; } - case EVBApp::Operation::ConvertSlow : + case EventBuilder::EVBApp::Operation::ConvertSlow : { fBuilder.Convert2SortedRoot(); break; } - case EVBApp::Operation::ConvertFast : + case EventBuilder::EVBApp::Operation::ConvertFast : { fBuilder.Convert2FastSortedRoot(); break; } - case EVBApp::Operation::ConvertSlowA : + case EventBuilder::EVBApp::Operation::ConvertSlowA : { fBuilder.Convert2SlowAnalyzedRoot(); break; } - case EVBApp::Operation::ConvertFastA : + case EventBuilder::EVBApp::Operation::ConvertFastA : { fBuilder.Convert2FastAnalyzedRoot(); break; diff --git a/src/guidict/EVBMainFrame.h b/src/guidict/EVBMainFrame.h index 56322ad..27b56db 100644 --- a/src/guidict/EVBMainFrame.h +++ b/src/guidict/EVBMainFrame.h @@ -94,7 +94,7 @@ private: TGPopupMenu *fFileMenu; - EVBApp fBuilder; + EventBuilder::EVBApp fBuilder; int counter; UInt_t MAIN_W, MAIN_H; diff --git a/src/main.cpp b/src/main.cpp index 3b906df..8dda6fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ -#include "EventBuilder.h" +#include "evb/EventBuilder.h" #include "spsdict/DataStructs.h" -#include "EVBApp.h" -#include "Stopwatch.h" +#include "evb/EVBApp.h" +#include "evb/Stopwatch.h" int main(int argc, char** argv) { @@ -27,11 +27,11 @@ int main(int argc, char** argv) Plot (generate a default histogram file from analyzed data) */ - EVBApp theBuilder; + EventBuilder::EVBApp theBuilder; theBuilder.ReadConfigFile(filename); - Stopwatch timer; + EventBuilder::Stopwatch timer; timer.Start(); if(operation == "Convert") theBuilder.Convert2RawRoot();