Namespace encapsulated evb with name EventBuilder

This commit is contained in:
Gordon McCann 2021-12-15 12:08:12 -05:00
parent 1c6addb941
commit b9ed82a593
39 changed files with 3177 additions and 3061 deletions

View File

@ -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` `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 ## 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. 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.

View File

@ -94,7 +94,7 @@ private:
TGPopupMenu *fFileMenu; TGPopupMenu *fFileMenu;
EVBApp fBuilder; EventBuilder::EVBApp fBuilder;
int counter; int counter;
UInt_t MAIN_W, MAIN_H; UInt_t MAIN_W, MAIN_H;

View File

@ -9,86 +9,89 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "ChannelMap.h" #include "ChannelMap.h"
ChannelMap::ChannelMap() : namespace EventBuilder {
m_validFlag(false)
{
}
ChannelMap::ChannelMap(const std::string& name) : ChannelMap::ChannelMap() :
m_validFlag(false) 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; }
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; 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;
} }

View File

@ -9,66 +9,67 @@
#ifndef CHANNELMAP_H #ifndef CHANNELMAP_H
#define CHANNELMAP_H #define CHANNELMAP_H
//Detector part/type identifiers for use in the code namespace EventBuilder {
enum DetType //Detector part/type identifiers for use in the code
{ enum DetType
Sabre, {
FocalPlane, Sabre,
NoneType FocalPlane,
}; NoneType
};
enum DetAttribute enum DetAttribute
{ {
ScintLeft, ScintLeft,
ScintRight, ScintRight,
AnodeFront, AnodeFront,
AnodeBack, AnodeBack,
DelayFR, DelayFR,
DelayFL, DelayFL,
DelayBR, DelayBR,
DelayBL, DelayBL,
Cathode, Cathode,
Monitor, Monitor,
SabreRing0, SabreRing0,
SabreRing1, SabreRing1,
SabreRing2, SabreRing2,
SabreRing3, SabreRing3,
SabreRing4, SabreRing4,
SabreWedge0, SabreWedge0,
SabreWedge1, SabreWedge1,
SabreWedge2, SabreWedge2,
SabreWedge3, SabreWedge3,
SabreWedge4, SabreWedge4,
NoneAttr NoneAttr
}; };
struct Channel struct Channel
{ {
DetType type; DetType type;
DetAttribute attribute; //What kind of detector we're looking at DetAttribute attribute; //What kind of detector we're looking at
int local_channel; //Which specific piece of detector we're looking at int local_channel; //Which specific piece of detector we're looking at
}; };
class ChannelMap class ChannelMap
{ {
public: public:
typedef std::unordered_map<int, Channel> Containter; typedef std::unordered_map<int, Channel> Containter;
typedef std::unordered_map<int, Channel>::iterator Iterator; typedef std::unordered_map<int, Channel>::iterator Iterator;
ChannelMap(); ChannelMap();
ChannelMap(const std::string& filename); ChannelMap(const std::string& filename);
~ChannelMap(); ~ChannelMap();
bool FillMap(const std::string& filename); bool FillMap(const std::string& filename);
inline const Containter* GetCMap() { return &m_cmap; }; inline const Containter* GetCMap() { return &m_cmap; };
inline Iterator FindChannel(int key) { return m_cmap.find(key); }; inline Iterator FindChannel(int key) { return m_cmap.find(key); };
inline Iterator End() { return m_cmap.end(); }; inline Iterator End() { return m_cmap.end(); };
inline bool IsValid() { return m_validFlag; }; inline bool IsValid() { return m_validFlag; };
private:
Containter m_cmap;
bool m_validFlag;
};
private:
Containter m_cmap;
bool m_validFlag;
};
}
#endif #endif

View File

@ -11,157 +11,161 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "CompassFile.h" #include "CompassFile.h"
CompassFile::CompassFile() : namespace EventBuilder {
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared<std::ifstream>()), eofFlag(false)
{
m_buffersize = bufsize*hitsize;
hitBuffer.resize(m_buffersize);
}
CompassFile::CompassFile(const std::string& filename) : CompassFile::CompassFile() :
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared<std::ifstream>()), eofFlag(false) m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared<std::ifstream>()), 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<std::ifstream>()), 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; m_buffersize = bufsize*hitsize;
hitBuffer.resize(m_buffersize);
} }
else
CompassFile::CompassFile(const std::string& filename) :
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared<std::ifstream>()), 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<std::ifstream>()), 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!"<<std::endl;
return 0;
}
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); m_file->seekg(0, std::ios_base::beg);
}
}
void CompassFile::Close() delete firstHit;
{
if(IsOpen()) 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()
{ {
m_file->close(); if(!IsOpen()) return true;
}
}
int CompassFile::GetHitSize() if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF())
{ {
if(!IsOpen()) GetNextBuffer();
}
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()
{ {
std::cerr<<"Unable to get hit size due to file not being open!"<<std::endl;
return 0; 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
} }
char* firstHit = new char[24]; //A compass hit by default has 24 bytes (at least in our setup) void CompassFile::ParseNextHit()
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())
{ {
GetNextBuffer();
}
if(!IsEOF()) m_currentHit.board = *((uint16_t*)bufferIter);
{ bufferIter += 2;
ParseNextHit(); m_currentHit.channel = *((uint16_t*)bufferIter);
hitUsedFlag = false; 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;
return eofFlag; if(m_smap != nullptr)
} { //memory safety
int gchan = m_currentHit.channel + m_currentHit.board*16;
m_currentHit.timestamp += m_smap->GetShift(gchan);
}
/*
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);
} }
} }

View File

@ -15,57 +15,60 @@
#include "ShiftMap.h" #include "ShiftMap.h"
#include <memory> #include <memory>
class CompassFile namespace EventBuilder {
{
public: class CompassFile
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(); }; public:
inline CompassHit GetCurrentHit() const { return m_currentHit; } CompassFile();
inline std::string GetName() const { return m_filename; } CompassFile(const std::string& filename);
inline bool CheckHitHasBeenUsed() const { return hitUsedFlag; } //query to find out if we've used the current hit CompassFile(const std::string& filename, int bsize);
inline void SetHitHasBeenUsed() { hitUsedFlag = true; } //flip the flag to indicate the current hit has been used ~CompassFile();
inline bool IsEOF() const { return eofFlag; } //see if we've read all available data void Open(const std::string& filename);
inline bool* GetUsedFlagPtr() { return &hitUsedFlag; } void Close();
inline void AttachShiftMap(ShiftMap* map) { m_smap = map; } bool GetNextHit();
inline unsigned int GetSize() const { return m_size; }
inline unsigned int GetNumberOfHits() const { return m_nHits; } 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: private:
int GetHitSize(); int GetHitSize();
void ParseNextHit(); void ParseNextHit();
void GetNextBuffer(); void GetNextBuffer();
using Buffer = std::vector<char>; using Buffer = std::vector<char>;
using FilePointer = std::shared_ptr<std::ifstream>; //to make this class copy/movable using FilePointer = std::shared_ptr<std::ifstream>; //to make this class copy/movable
std::string m_filename; std::string m_filename;
Buffer hitBuffer; Buffer hitBuffer;
char* bufferIter; char* bufferIter;
char* bufferEnd; char* bufferEnd;
ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete
bool hitUsedFlag; bool hitUsedFlag;
int bufsize = 200000; //size of the buffer in hits int bufsize = 200000; //size of the buffer in hits
int hitsize = 24; //size of a CompassHit in bytes (without alignment padding) int hitsize = 24; //size of a CompassHit in bytes (without alignment padding)
int m_buffersize; int m_buffersize;
CompassHit m_currentHit; CompassHit m_currentHit;
FilePointer m_file; FilePointer m_file;
bool eofFlag; bool eofFlag;
unsigned int m_size; //size of the file in bytes unsigned int m_size; //size of the file in bytes
unsigned int m_nHits; //number of hits in the file (m_size/24) unsigned int m_nHits; //number of hits in the file (m_size/24)
}; };
}
#endif #endif

View File

@ -1,15 +1,19 @@
#ifndef COMPASS_HIT_H #ifndef COMPASS_HIT_H
#define COMPASS_HIT_H #define COMPASS_HIT_H
struct CompassHit namespace EventBuilder {
{
uint16_t board = 400; struct CompassHit
uint16_t channel = 400; {
uint64_t timestamp = 0; uint16_t board = 400;
uint16_t lgate = 0; uint16_t channel = 400;
uint16_t sgate = 0; uint64_t timestamp = 0;
uint32_t flags = 0; uint16_t lgate = 0;
uint32_t Ns = 0; uint16_t sgate = 0;
}; uint32_t flags = 0;
uint32_t Ns = 0;
};
}
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -18,54 +18,58 @@
#include <TGProgressBar.h> #include <TGProgressBar.h>
#include <TSystem.h> #include <TSystem.h>
class CompassRun namespace EventBuilder {
{
public: class CompassRun
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; } 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);
private: inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; }
bool GetBinaryFiles();
bool GetHitsFromFiles();
void SetScalers();
void ReadScalerData(const std::string& filename);
void SetProgressBar();
std::string m_directory, m_scalerinput; private:
std::vector<CompassFile> m_datafiles; bool GetBinaryFiles();
unsigned int startIndex; //this is the file we start looking at; increases as we finish files. bool GetHitsFromFiles();
ShiftMap m_smap; void SetScalers();
std::unordered_map<std::string, TParameter<Long64_t>> m_scaler_map; //maps scaler files to the TParameter to be saved void ReadScalerData(const std::string& filename);
void SetProgressBar();
//Potential branch variables std::string m_directory, m_scalerinput;
CompassHit hit; std::vector<CompassFile> m_datafiles;
CoincEvent event; unsigned int startIndex; //this is the file we start looking at; increases as we finish files.
ProcessedEvent pevent; ShiftMap m_smap;
std::unordered_map<std::string, TParameter<Long64_t>> m_scaler_map; //maps scaler files to the TParameter to be saved
//what run is this //Potential branch variables
int m_runNum; CompassHit hit;
unsigned int m_totalHits; CoincEvent event;
ProcessedEvent pevent;
//Scaler switch //what run is this
bool m_scaler_flag; int m_runNum;
unsigned int m_totalHits;
//GUI progress bar, if attached //Scaler switch
TGProgressBar* m_pb; bool m_scaler_flag;
};
//GUI progress bar, if attached
TGProgressBar* m_pb;
};
}
#endif #endif

View File

@ -1,104 +1,108 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "CutHandler.h" #include "CutHandler.h"
CutHandler::CutHandler() : namespace EventBuilder {
validFlag(false)
{
InitVariableMap();
}
CutHandler::CutHandler(const std::string& filename) : CutHandler::CutHandler() :
validFlag(false) validFlag(false)
{ {
SetCuts(filename); InitVariableMap();
InitVariableMap(); }
}
CutHandler::~CutHandler() CutHandler::CutHandler(const std::string& filename) :
{ validFlag(false)
for(unsigned int i=0; i<file_array.size(); i++)
if(file_array[i]->IsOpen())
file_array[i]->Close();
}
void CutHandler::SetCuts(const std::string& filename)
{
std::ifstream cutlist(filename);
if(!cutlist.is_open())
{ {
validFlag = false; SetCuts(filename);
InitVariableMap();
} }
std::string junk, name, fname, varx, vary; CutHandler::~CutHandler()
cutlist>>junk>>junk>>junk>>junk;
cut_array.clear();
file_array.clear();
while(cutlist>>name)
{ {
cutlist>>fname>>varx>>vary; for(unsigned int i=0; i<file_array.size(); i++)
TFile* file = TFile::Open(fname.c_str(), "READ"); if(file_array[i]->IsOpen())
TCutG* cut = (TCutG*) file->Get("CUTG"); file_array[i]->Close();
if(cut) }
{
cut->SetVarX(varx.c_str()); void CutHandler::SetCuts(const std::string& filename)
cut->SetVarY(vary.c_str()); {
cut->SetName(name.c_str()); std::ifstream cutlist(filename);
cut_array.push_back(cut);
file_array.push_back(file); if(!cutlist.is_open())
}
else
{ {
validFlag = false; validFlag = false;
std::cerr<<"CutHandler has encountered a bad cut at file: "<<file<<"."<<std::endl;
std::cerr<<"The file either does not exist or does not contain a TCutG named CUTG"<<std::endl;
std::cerr<<"Cuts will not be used."<<std::endl;
return;
} }
}
if(cut_array.size() > 0) std::string junk, name, fname, varx, vary;
validFlag = true; cutlist>>junk>>junk>>junk>>junk;
else
validFlag = false;
}
/* cut_array.clear();
ADD MORE VARIABLES HERE! file_array.clear();
*/
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) while(cutlist>>name)
{
m_event = *eaddress;
std::string x, y;
for(unsigned int i=0; i<cut_array.size(); i++)
{
TCutG* cut = cut_array[i];
x = cut->GetVarX();
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: "<<xentry->first<<" , "<<yentry->first<<std::endl; cutlist>>fname>>varx>>vary;
return false; 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: "<<file<<"."<<std::endl;
std::cerr<<"The file either does not exist or does not contain a TCutG named CUTG"<<std::endl;
std::cerr<<"Cuts will not be used."<<std::endl;
return;
}
} }
if(!cut->IsInside(*(xentry->second), *(yentry->second))) if(cut_array.size() > 0)
return false; 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; i<cut_array.size(); i++)
{
TCutG* cut = cut_array[i];
x = cut->GetVarX();
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: "<<xentry->first<<" , "<<yentry->first<<std::endl;
return false;
}
if(!cut->IsInside(*(xentry->second), *(yentry->second)))
return false;
}
return true;
} }
return true;
} }

View File

@ -1,27 +1,30 @@
#ifndef CUTHANDLER_H #ifndef CUTHANDLER_H
#define CUTHANDLER_H #define CUTHANDLER_H
#include "DataStructs.h" #include "../spsdict/DataStructs.h"
class CutHandler { namespace EventBuilder {
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<TCutG*> GetCuts() { return cut_array; }
private: class CutHandler {
void InitVariableMap(); 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<TCutG*> GetCuts() { return cut_array; }
std::vector<TCutG*> cut_array; private:
std::vector<TFile*> file_array; void InitVariableMap();
std::unordered_map<std::string, double*> varmap;
bool validFlag;
ProcessedEvent m_event;
}; std::vector<TCutG*> cut_array;
std::vector<TFile*> file_array;
std::unordered_map<std::string, double*> varmap;
bool validFlag;
ProcessedEvent m_event;
};
}
#endif #endif

View File

@ -16,421 +16,425 @@
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
#include "SFPPlotter.h" #include "SFPPlotter.h"
EVBApp::EVBApp() : namespace EventBuilder {
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() 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)
bool EVBApp::ReadConfigFile(const std::string& fullpath)
{
std::cout<<"Reading in configuration from file: "<<fullpath<<std::endl;
std::ifstream input(fullpath);
if(!input.is_open())
{ {
std::cout<<"Read failed! Unable to open input file!"<<std::endl;
return false;
}
std::string junk;
std::getline(input, junk);
input>>junk>>m_workspace;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_mapfile;
input>>junk>>m_scalerfile;
input>>junk>>m_cutList;
input>>junk>>m_ZT>>junk>>m_AT;
input>>junk>>m_ZP>>junk>>m_AP;
input>>junk>>m_ZE>>junk>>m_AE;
input>>junk>>m_B;
input>>junk>>m_BKE;
input>>junk>>m_Theta;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_shiftfile;
input>>junk>>m_SlowWindow;
input>>junk>>m_FastWindowIonCh;
input>>junk>>m_FastWindowSABRE;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_rmin;
input>>junk>>m_rmax;
input.close();
std::cout<<"Completed."<<std::endl;
return true;
}
void EVBApp::WriteConfigFile(const std::string& fullpath)
{
std::cout<<"Writing out configuration to file: "<<fullpath<<std::endl;
std::ofstream output(fullpath);
if(!output.is_open())
{
std::cout<<"Write failed! Unable to open output file!"<<std::endl;
return;
} }
output<<"-------Data Location----------"<<std::endl; EVBApp::~EVBApp()
output<<"WorkspaceDirectory: "<<m_workspace<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"------Experimental Inputs------"<<std::endl;
output<<"ChannelMapFile: "<<m_mapfile<<std::endl;
output<<"ScalerFile: "<<m_scalerfile<<std::endl;
output<<"CutListFile: "<<m_cutList<<std::endl;
output<<"ZT: "<<m_ZT<<std::endl;
output<<"AT: "<<m_AT<<std::endl;
output<<"ZP: "<<m_ZP<<std::endl;
output<<"AP: "<<m_AP<<std::endl;
output<<"ZE: "<<m_ZE<<std::endl;
output<<"AE: "<<m_AE<<std::endl;
output<<"BField(G): "<<m_B<<std::endl;
output<<"BeamKE(MeV): "<<m_BKE<<std::endl;
output<<"Theta(deg): "<<m_Theta<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"-------Timing Information------"<<std::endl;
output<<"BoardOffsetFile: "<<m_shiftfile<<std::endl;
output<<"SlowCoincidenceWindow(ps): "<<m_SlowWindow<<std::endl;
output<<"FastCoincidenceWindow_IonCh(ps): "<<m_FastWindowIonCh<<std::endl;
output<<"FastCoincidenceWindow_SABRE(ps): "<<m_FastWindowSABRE<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"--------Run Information--------"<<std::endl;
output<<"MinRun: "<<m_rmin<<std::endl;
output<<"MaxRun: "<<m_rmax<<std::endl;
output<<"-------------------------------"<<std::endl;
output.close();
std::cout<<"Completed."<<std::endl;
}
void EVBApp::PlotHistograms()
{
std::string analyze_dir = m_workspace+"/analyzed/";
std::string plot_file = m_workspace+"/histograms/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root";
SFPPlotter grammer;
grammer.ApplyCutlist(m_cutList);
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Generating a histogram file from analyzed files"<<std::endl;
std::cout<<"Analyzed directory: "<<analyze_dir<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
std::cout<<"Cut List File: "<<m_cutList<<std::endl;
std::cout<<"Histogram File: "<<plot_file<<std::endl;
if(m_pb)
grammer.AttachProgressBar(m_pb);
grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax);
if(grabber.GrabFilesInRange())
{ {
std::cout<<"Working..."; }
grammer.Run(grabber.GetFileList(), plot_file);
bool EVBApp::ReadConfigFile(const std::string& fullpath)
{
std::cout<<"Reading in configuration from file: "<<fullpath<<std::endl;
std::ifstream input(fullpath);
if(!input.is_open())
{
std::cout<<"Read failed! Unable to open input file!"<<std::endl;
return false;
}
std::string junk;
std::getline(input, junk);
input>>junk>>m_workspace;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_mapfile;
input>>junk>>m_scalerfile;
input>>junk>>m_cutList;
input>>junk>>m_ZT>>junk>>m_AT;
input>>junk>>m_ZP>>junk>>m_AP;
input>>junk>>m_ZE>>junk>>m_AE;
input>>junk>>m_B;
input>>junk>>m_BKE;
input>>junk>>m_Theta;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_shiftfile;
input>>junk>>m_SlowWindow;
input>>junk>>m_FastWindowIonCh;
input>>junk>>m_FastWindowSABRE;
input>>junk;
std::getline(input, junk);
std::getline(input, junk);
input>>junk>>m_rmin;
input>>junk>>m_rmax;
input.close();
std::cout<<"Completed."<<std::endl;
return true;
}
void EVBApp::WriteConfigFile(const std::string& fullpath)
{
std::cout<<"Writing out configuration to file: "<<fullpath<<std::endl;
std::ofstream output(fullpath);
if(!output.is_open())
{
std::cout<<"Write failed! Unable to open output file!"<<std::endl;
return;
}
output<<"-------Data Location----------"<<std::endl;
output<<"WorkspaceDirectory: "<<m_workspace<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"------Experimental Inputs------"<<std::endl;
output<<"ChannelMapFile: "<<m_mapfile<<std::endl;
output<<"ScalerFile: "<<m_scalerfile<<std::endl;
output<<"CutListFile: "<<m_cutList<<std::endl;
output<<"ZT: "<<m_ZT<<std::endl;
output<<"AT: "<<m_AT<<std::endl;
output<<"ZP: "<<m_ZP<<std::endl;
output<<"AP: "<<m_AP<<std::endl;
output<<"ZE: "<<m_ZE<<std::endl;
output<<"AE: "<<m_AE<<std::endl;
output<<"BField(G): "<<m_B<<std::endl;
output<<"BeamKE(MeV): "<<m_BKE<<std::endl;
output<<"Theta(deg): "<<m_Theta<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"-------Timing Information------"<<std::endl;
output<<"BoardOffsetFile: "<<m_shiftfile<<std::endl;
output<<"SlowCoincidenceWindow(ps): "<<m_SlowWindow<<std::endl;
output<<"FastCoincidenceWindow_IonCh(ps): "<<m_FastWindowIonCh<<std::endl;
output<<"FastCoincidenceWindow_SABRE(ps): "<<m_FastWindowSABRE<<std::endl;
output<<"-------------------------------"<<std::endl;
output<<"--------Run Information--------"<<std::endl;
output<<"MinRun: "<<m_rmin<<std::endl;
output<<"MaxRun: "<<m_rmax<<std::endl;
output<<"-------------------------------"<<std::endl;
output.close();
std::cout<<"Completed."<<std::endl;
}
void EVBApp::PlotHistograms()
{
std::string analyze_dir = m_workspace+"/analyzed/";
std::string plot_file = m_workspace+"/histograms/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root";
SFPPlotter grammer;
grammer.ApplyCutlist(m_cutList);
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Generating a histogram file from analyzed files"<<std::endl;
std::cout<<"Analyzed directory: "<<analyze_dir<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
std::cout<<"Cut List File: "<<m_cutList<<std::endl;
std::cout<<"Histogram File: "<<plot_file<<std::endl;
if(m_pb)
grammer.AttachProgressBar(m_pb);
grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax);
if(grabber.GrabFilesInRange())
{
std::cout<<"Working...";
grammer.Run(grabber.GetFileList(), plot_file);
std::cout<<" Complete."<<std::endl;
}
else
{
std::cout<<"Unable to find files at PlotHistograms"<<std::endl;
}
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2RawRoot()
{
std::string rawroot_dir = m_workspace+"/raw_root/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir, "", ".tar.gz",0,1000);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string rawfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2RawRoot(rawfile);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::MergeROOTFiles()
{
std::string merge_file = m_workspace+"/merged/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root";
std::string file_dir = m_workspace+"/analyzed/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Merging ROOT files into single ROOT file"<<std::endl;
std::cout<<"Workspace directory: "<<m_workspace<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
std::cout<<"Output file: "<<merge_file<<std::endl;
std::string prefix = "";
std::string suffix = ".root";
grabber.SetSearchParams(file_dir, prefix, suffix,m_rmin,m_rmax);
std::cout<<"Beginning the merge...";
if(!grabber.Merge_TChain(merge_file))
{
std::cout<<"Unable to find files at MergeROOTFiles"<<std::endl;
return;
}
std::cout<<" Complete."<<std::endl; std::cout<<" Complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
} }
else
void EVBApp::Convert2SortedRoot()
{ {
std::cout<<"Unable to find files at PlotHistograms"<<std::endl; std::string sortroot_dir = m_workspace+"/sorted/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<= m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2FastSortedRoot() {
std::string sortroot_dir = m_workspace+"/fast/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2FastSortedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2SlowAnalyzedRoot() {
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin, m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2SlowAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2FastAnalyzedRoot()
{
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Fast Ion Chamber Coincidence Window(ps): "<<m_FastWindowIonCh<<std::endl;
std::cout<<"Fast SABRE Coincidence Window(ps): "<<m_FastWindowSABRE<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2FastAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
bool EVBApp::SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke)
{
if((at + ap - ae) < 0 || (zt + zp - ze) < 0)
{
std::cout<<"Invalid Parameters at SetKinematicParameters"<<std::endl;
return false;
}
m_ZT = zt; m_AT = at; m_ZP = zp; m_AP = ap; m_ZE = ze; m_AE = ae;
m_B = b; m_Theta = theta; m_BKE = bke;
m_ZR = (zt + zp - ze);
m_AR = (at + ap - ae);
return true;
} }
std::cout<<"-------------------------------------------"<<std::endl;
} }
void EVBApp::Convert2RawRoot()
{
std::string rawroot_dir = m_workspace+"/raw_root/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir, "", ".tar.gz",0,1000);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string rawfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2RawRoot(rawfile);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::MergeROOTFiles()
{
std::string merge_file = m_workspace+"/merged/run_"+std::to_string(m_rmin)+"_"+std::to_string(m_rmax)+".root";
std::string file_dir = m_workspace+"/analyzed/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Merging ROOT files into single ROOT file"<<std::endl;
std::cout<<"Workspace directory: "<<m_workspace<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
std::cout<<"Output file: "<<merge_file<<std::endl;
std::string prefix = "";
std::string suffix = ".root";
grabber.SetSearchParams(file_dir, prefix, suffix,m_rmin,m_rmax);
std::cout<<"Beginning the merge...";
if(!grabber.Merge_TChain(merge_file))
{
std::cout<<"Unable to find files at MergeROOTFiles"<<std::endl;
return;
}
std::cout<<" Complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2SortedRoot()
{
std::string sortroot_dir = m_workspace+"/sorted/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<= m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2FastSortedRoot() {
std::string sortroot_dir = m_workspace+"/fast/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2FastSortedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2SlowAnalyzedRoot() {
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin, m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2SlowAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
void EVBApp::Convert2FastAnalyzedRoot()
{
std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
std::cout<<"Converting Binary file Archive to ROOT file"<<std::endl;
std::cout<<"Binary Archive Directory: "<<binary_dir<<std::endl;
std::cout<<"Temporary Unpack Directory: "<<unpack_dir<<std::endl;
std::cout<<"Timestamp Shift File: "<<m_shiftfile<<std::endl;
std::cout<<"Channel Map File: "<<m_mapfile<<std::endl;
std::cout<<"Slow Coincidence Window(ps): "<<m_SlowWindow<<std::endl;
std::cout<<"Fast Ion Chamber Coincidence Window(ps): "<<m_FastWindowIonCh<<std::endl;
std::cout<<"Fast SABRE Coincidence Window(ps): "<<m_FastWindowSABRE<<std::endl;
std::cout<<"Min Run: "<<m_rmin<<" Max Run: "<<m_rmax<<std::endl;
grabber.SetSearchParams(binary_dir,"",".tar.gz",m_rmin,m_rmax);
std::cout<<"Workspace Directory: "<<m_workspace<<std::endl;
std::string sortfile, binfile;
std::string unpack_command, wipe_command;
CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile);
if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i);
if(binfile == "")
continue;
converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl;
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin";
system(unpack_command.c_str());
converter.Convert2FastAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
system(wipe_command.c_str());
}
std::cout<<std::endl<<"Conversion complete."<<std::endl;
std::cout<<"-------------------------------------------"<<std::endl;
}
bool EVBApp::SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke)
{
if((at + ap - ae) < 0 || (zt + zp - ze) < 0)
{
std::cout<<"Invalid Parameters at SetKinematicParameters"<<std::endl;
return false;
}
m_ZT = zt; m_AT = at; m_ZP = zp; m_AP = ap; m_ZE = ze; m_AE = ae;
m_B = b; m_Theta = theta; m_BKE = bke;
m_ZR = (zt + zp - ze);
m_AR = (at + ap - ae);
return true;
}

View File

@ -12,87 +12,90 @@
#include "RunCollector.h" #include "RunCollector.h"
#include <TGProgressBar.h> #include <TGProgressBar.h>
class EVBApp { namespace EventBuilder {
public:
EVBApp();
~EVBApp();
bool ReadConfigFile(const std::string& filename); class EVBApp {
void WriteConfigFile(const std::string& filename); public:
EVBApp();
~EVBApp();
void PlotHistograms(); bool ReadConfigFile(const std::string& filename);
void MergeROOTFiles(); void WriteConfigFile(const std::string& filename);
void Convert2SortedRoot();
void Convert2FastSortedRoot();
void Convert2RawRoot();
void Convert2SlowAnalyzedRoot();
void Convert2FastAnalyzedRoot();
inline void SetRunRange(int rmin, int rmax) { m_rmin = rmin; m_rmax = rmax; }; void PlotHistograms();
inline void SetWorkDirectory(const std::string& fullpath) { m_workspace = fullpath; }; void MergeROOTFiles();
inline void SetChannelMap(const std::string& name) { m_mapfile = name; }; void Convert2SortedRoot();
inline void SetBoardShiftFile(const std::string& name) { m_shiftfile = name; }; void Convert2FastSortedRoot();
inline void SetSlowCoincidenceWindow(double window) { m_SlowWindow = window; }; void Convert2RawRoot();
inline void SetFastWindowIonChamber(double window) { m_FastWindowIonCh = window; }; void Convert2SlowAnalyzedRoot();
inline void SetFastWindowSABRE(double window) { m_FastWindowSABRE = window; }; void Convert2FastAnalyzedRoot();
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 void SetRunRange(int rmin, int rmax) { m_rmin = rmin; m_rmax = rmax; };
inline int GetRunMax() const {return m_rmax;} inline void SetWorkDirectory(const std::string& fullpath) { m_workspace = fullpath; };
inline std::string GetWorkDirectory() const {return m_workspace;} inline void SetChannelMap(const std::string& name) { m_mapfile = name; };
inline int GetTargetZ() const {return m_ZT;} inline void SetBoardShiftFile(const std::string& name) { m_shiftfile = name; };
inline int GetTargetA() const {return m_AT;} inline void SetSlowCoincidenceWindow(double window) { m_SlowWindow = window; };
inline int GetProjectileZ() const {return m_ZP;} inline void SetFastWindowIonChamber(double window) { m_FastWindowIonCh = window; };
inline int GetProjectileA() const {return m_AP;} inline void SetFastWindowSABRE(double window) { m_FastWindowSABRE = window; };
inline int GetEjectileZ() const {return m_ZE;} inline void SetCutList(const std::string& name) { m_cutList = name; };
inline int GetEjectileA() const {return m_AE;} inline void SetScalerFile(const std::string& fullpath) { m_scalerfile = fullpath; };
inline int GetResidualZ() const {return m_ZR;} bool SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke);
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; } 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;
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;
};
#endif #endif

View File

@ -36,70 +36,73 @@
#include "MassLookup.h" #include "MassLookup.h"
#include "FP_kinematics.h" #include "FP_kinematics.h"
//requires (Z,A) for T, P, and E, as well as energy of P, namespace EventBuilder {
// 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)
{
/* CONSTANTS */ //requires (Z,A) for T, P, and E, as well as energy of P,
const double UTOMEV = 931.4940954; //MeV per u; // spectrograph angle of interest, and field value
const double MEVTOJ = 1.60218E-13; //J per MeV double Delta_Z(int ZT, int AT, int ZP, int AP, int ZE, int AE,
const double RESTMASS_ELECTRON = 0.000548579909; //amu double EP, double angle, double B)
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)
{ {
std::cerr << "***WARNING: error loading one or more masses; returning 0\n";
return 0; /* 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)
{
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<<std::endl;
return -1*rho*DISP*MAG*K; //delta-Z in cm
} }
double Q = MT + MP - ME - MR; //Q-value double Wire_Dist() {return 4.28625;} //cm
//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<<std::endl;
return -1*rho*DISP*MAG*K; //delta-Z in cm
} }
double Wire_Dist() {return 4.28625;} //cm

View File

@ -32,11 +32,15 @@
#ifndef FP_KINEMATICS #ifndef FP_KINEMATICS
#define FP_KINEMATICS #define FP_KINEMATICS
//requires (Z,A) for T, P, and E, as well as energy of P, namespace EventBuilder {
// 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);
double Wire_Dist(); //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);
double Wire_Dist();
}
#endif #endif

View File

@ -1,125 +1,128 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "FastSort.h" #include "FastSort.h"
//windows given in picoseconds, converted to nanoseconds namespace EventBuilder {
FastSort::FastSort(float si_windowSize, float ion_windowSize) : //windows given in picoseconds, converted to nanoseconds
si_coincWindow(si_windowSize/1.0e3), ion_coincWindow(ion_windowSize/1.0e3), event_address(nullptr) FastSort::FastSort(float si_windowSize, float ion_windowSize) :
{ si_coincWindow(si_windowSize/1.0e3), ion_coincWindow(ion_windowSize/1.0e3), event_address(nullptr)
}
FastSort::~FastSort()
{
delete event_address;
}
void FastSort::ResetSABRE()
{
for(int i=0; i<5; i++)
fastEvent.sabreArray[i] = sblank;
}
void FastSort::ResetFocalPlane()
{
fastEvent.focalPlane = fpblank;
}
/*Assign a set of ion chamber data to the scintillator*/
void FastSort::ProcessFocalPlane(unsigned int scint_index, unsigned int ionch_index) {
/*In order to have a coincidence window, one must choose a portion of the ion chamber to form a requirement.
*In this case, I chose one of the anodes. But in principle you could also choose any other part of the ion
*chamber
*/
if(slowEvent.focalPlane.anodeB.size() > 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<DetectorHit> rings;
std::vector<DetectorHit> 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<slowEvent.sabreArray[i].rings.size(); j++)
{
float sabreRelTime = fabs(slowEvent.sabreArray[i].rings[j].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(sabreRelTime < si_coincWindow)
rings.push_back(slowEvent.sabreArray[i].rings[j]);
}
for(unsigned int j=0; j<slowEvent.sabreArray[i].wedges.size(); j++)
{
float sabreRelTime = fabs(slowEvent.sabreArray[i].wedges[j].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(sabreRelTime < si_coincWindow)
wedges.push_back(slowEvent.sabreArray[i].wedges[j]);
}
fastEvent.sabreArray[i].rings = rings;
fastEvent.sabreArray[i].wedges = wedges;
}
}
std::vector<CoincEvent> FastSort::GetFastEvents(CoincEvent& event)
{
slowEvent = event;
std::vector<CoincEvent> 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<slowEvent.focalPlane.scintL.size(); i++)
{ {
ResetSABRE(); }
ProcessSABRE(i);
//loop over ion chamber FastSort::~FastSort()
//NOTE: as written, this dumps data that does not have an ion chamber hit! {
//If you want scint/SABRE singles, move the fill outside of this loop delete event_address;
for(unsigned int j=0; j<maxSize; j++) }
{
ResetFocalPlane(); void FastSort::ResetSABRE()
ProcessFocalPlane(i, j); {
fast_events.push_back(fastEvent); for(int i=0; i<5; i++)
fastEvent.sabreArray[i] = sblank;
}
void FastSort::ResetFocalPlane()
{
fastEvent.focalPlane = fpblank;
}
/*Assign a set of ion chamber data to the scintillator*/
void FastSort::ProcessFocalPlane(unsigned int scint_index, unsigned int ionch_index) {
/*In order to have a coincidence window, one must choose a portion of the ion chamber to form a requirement.
*In this case, I chose one of the anodes. But in principle you could also choose any other part of the ion
*chamber
*/
if(slowEvent.focalPlane.anodeB.size() > 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<DetectorHit> rings;
std::vector<DetectorHit> 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<slowEvent.sabreArray[i].rings.size(); j++)
{
float sabreRelTime = fabs(slowEvent.sabreArray[i].rings[j].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(sabreRelTime < si_coincWindow)
rings.push_back(slowEvent.sabreArray[i].rings[j]);
}
for(unsigned int j=0; j<slowEvent.sabreArray[i].wedges.size(); j++)
{
float sabreRelTime = fabs(slowEvent.sabreArray[i].wedges[j].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(sabreRelTime < si_coincWindow)
wedges.push_back(slowEvent.sabreArray[i].wedges[j]);
}
fastEvent.sabreArray[i].rings = rings;
fastEvent.sabreArray[i].wedges = wedges;
}
}
std::vector<CoincEvent> FastSort::GetFastEvents(CoincEvent& event)
{
slowEvent = event;
std::vector<CoincEvent> 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<slowEvent.focalPlane.scintL.size(); i++)
{
ResetSABRE();
ProcessSABRE(i);
//loop over ion chamber
//NOTE: as written, this dumps data that does not have an ion chamber hit!
//If you want scint/SABRE singles, move the fill outside of this loop
for(unsigned int j=0; j<maxSize; j++)
{
ResetFocalPlane();
ProcessFocalPlane(i, j);
fast_events.push_back(fastEvent);
}
}
return fast_events;
}
} }

View File

@ -9,26 +9,29 @@
#include "DataStructs.h" #include "DataStructs.h"
#include <TH2.h> #include <TH2.h>
class FastSort namespace EventBuilder {
{
public: class FastSort
FastSort(float si_windowSize, float ion_windowSize); {
~FastSort();
std::vector<CoincEvent> GetFastEvents(CoincEvent& event);
private: public:
void ResetSABRE(); FastSort(float si_windowSize, float ion_windowSize);
void ResetFocalPlane(); ~FastSort();
void ProcessSABRE(unsigned int scint_index); std::vector<CoincEvent> GetFastEvents(CoincEvent& event);
void ProcessFocalPlane(unsigned int scint_index, unsigned int ionch_index);
float si_coincWindow, ion_coincWindow; private:
CoincEvent *event_address, slowEvent; void ResetSABRE();
CoincEvent fastEvent, blank; void ResetFocalPlane();
SabreDetector sblank; void ProcessSABRE(unsigned int scint_index);
FPDetector fpblank; 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 #endif

View File

@ -1,106 +1,108 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "FlagHandler.h" #include "FlagHandler.h"
FlagHandler::FlagHandler() : namespace EventBuilder {
log("./event_log.txt")
{
}
FlagHandler::FlagHandler(const std::string& filename) : FlagHandler::FlagHandler() :
log(filename) log("./event_log.txt")
{
}
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"<<std::endl;
log<<"-----------------------------"<<std::endl;
for(auto& counter : event_count_map)
{ {
}
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"<<std::endl;
log<<"-----------------------------"<<std::endl; log<<"-----------------------------"<<std::endl;
log<<"GLOBAL CHANNEL No.: "<<counter.first<<std::endl; for(auto& counter : event_count_map)
log<<"Total number of events: "<<counter.second.total_counts<<std::endl; {
log<<"Dead time incurred (only for V1724): "<<counter.second.dead_time<<std::endl; log<<"-----------------------------"<<std::endl;
log<<"Timestamp rollovers: "<<counter.second.time_roll<<std::endl; log<<"GLOBAL CHANNEL No.: "<<counter.first<<std::endl;
log<<"Timestamp resets from external: "<<counter.second.time_reset<<std::endl; log<<"Total number of events: "<<counter.second.total_counts<<std::endl;
log<<"Fake events: "<<counter.second.fake_event<<std::endl; log<<"Dead time incurred (only for V1724): "<<counter.second.dead_time<<std::endl;
log<<"Memory full: "<<counter.second.mem_full<<std::endl; log<<"Timestamp rollovers: "<<counter.second.time_roll<<std::endl;
log<<"Triggers lost: "<<counter.second.trig_lost<<std::endl; log<<"Timestamp resets from external: "<<counter.second.time_reset<<std::endl;
log<<"N Triggers lost: "<<counter.second.n_trig_lost<<std::endl; log<<"Fake events: "<<counter.second.fake_event<<std::endl;
log<<"Saturation within the gate: "<<counter.second.sat_in_gate<<std::endl; log<<"Memory full: "<<counter.second.mem_full<<std::endl;
log<<"1024 Triggers found: "<<counter.second.trig_1024<<std::endl; log<<"Triggers lost: "<<counter.second.trig_lost<<std::endl;
log<<"Saturation on input: "<<counter.second.sat_input<<std::endl; log<<"N Triggers lost: "<<counter.second.n_trig_lost<<std::endl;
log<<"N Triggers counted: "<<counter.second.n_trig_count<<std::endl; log<<"Saturation within the gate: "<<counter.second.sat_in_gate<<std::endl;
log<<"Events not matched: "<<counter.second.event_not_matched<<std::endl; log<<"1024 Triggers found: "<<counter.second.trig_1024<<std::endl;
log<<"Pile ups: "<<counter.second.pile_up<<std::endl; log<<"Saturation on input: "<<counter.second.sat_input<<std::endl;
log<<"PLL lock lost: "<<counter.second.pll_lock_loss<<std::endl; log<<"N Triggers counted: "<<counter.second.n_trig_count<<std::endl;
log<<"Over Temperature: "<<counter.second.over_temp<<std::endl; log<<"Events not matched: "<<counter.second.event_not_matched<<std::endl;
log<<"ADC Shutdown: "<<counter.second.adc_shutdown<<std::endl; log<<"Pile ups: "<<counter.second.pile_up<<std::endl;
log<<"-----------------------------"<<std::endl; log<<"PLL lock lost: "<<counter.second.pll_lock_loss<<std::endl;
log<<"Over Temperature: "<<counter.second.over_temp<<std::endl;
log<<"ADC Shutdown: "<<counter.second.adc_shutdown<<std::endl;
log<<"-----------------------------"<<std::endl;
}
} }
} }

View File

@ -3,59 +3,62 @@
#include <map> #include <map>
struct FlagCount namespace EventBuilder {
{
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 struct FlagCount
{ {
public: long total_counts=0;
FlagHandler(); long dead_time=0;
FlagHandler(const std::string& filename); long time_roll=0;
~FlagHandler(); long time_reset=0;
void CheckFlag(int board, int channel, int flag); 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;
};
const int DeadTime = 0x00000001; class FlagHandler
const int TimeRollover = 0x00000002; {
const int TimeReset = 0x00000004; public:
const int FakeEvent = 0x00000008; FlagHandler();
const int MemFull = 0x00000010; FlagHandler(const std::string& filename);
const int TrigLost = 0x00000020; ~FlagHandler();
const int NTrigLost = 0x00000040; void CheckFlag(int board, int channel, int flag);
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: const int DeadTime = 0x00000001;
std::ofstream log; const int TimeRollover = 0x00000002;
std::map<int, FlagCount> event_count_map; 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;
void WriteLog(); private:
}; std::ofstream log;
std::map<int, FlagCount> event_count_map;
void WriteLog();
};
}
#endif #endif

View File

@ -11,65 +11,67 @@ Written by G.W. McCann Aug. 2020
#include "EventBuilder.h" #include "EventBuilder.h"
#include "MassLookup.h" #include "MassLookup.h"
namespace EventBuilder {
/* /*
Read in AMDC mass file, preformated to remove excess info. Here assumes that by default Read in AMDC mass file, preformated to remove excess info. Here assumes that by default
the file is in a local directory etc/ the file is in a local directory etc/
*/ */
MassLookup::MassLookup() 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())
{ {
int Z,A; std::string filepath;
std::string junk, element, key; #ifdef ETC_DIR_PATH
double atomicMassBig, atomicMassSmall, isotopicMass; filepath = ETC_DIR_PATH;
std::getline(massfile,junk); filepath += "mass.txt";
std::getline(massfile,junk); #else
while(massfile>>junk) filepath = "./etc/mass.txt";
#endif
std::ifstream massfile(filepath);
if(massfile.is_open())
{ {
massfile>>Z>>A>>element>>atomicMassBig>>atomicMassSmall; int Z,A;
isotopicMass = (atomicMassBig + atomicMassSmall*1e-6 - Z*electron_mass)*u_to_mev; std::string junk, element, key;
key = "("+std::to_string(Z)+","+A+")"; double atomicMassBig, atomicMassSmall, isotopicMass;
massTable[key] = isotopicMass; std::getline(massfile,junk);
elementTable[Z] = element; 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."<<std::endl;
} }
else
std::cerr<<"Unable to open mass.txt at MassLookup! Prepare for errors."<<std::endl;
}
MassLookup::~MassLookup() {} MassLookup::~MassLookup() {}
//Returns nuclear mass in MeV //Returns nuclear mass in MeV
double MassLookup::FindMass(int Z, int A) double MassLookup::FindMass(int Z, int A)
{
std::string key = "("+std::to_string(Z)+","+std::to_string(A)+")";
auto data = massTable.find(key);
if(data == massTable.end())
{ {
std::cerr<<"Invaild nucleus at MassLookup! Returning mass of 0"<<std::endl; std::string key = "("+std::to_string(Z)+","+std::to_string(A)+")";
return 0; auto data = massTable.find(key);
if(data == massTable.end())
{
std::cerr<<"Invaild nucleus at MassLookup! Returning mass of 0"<<std::endl;
return 0;
}
return data->second;
} }
return data->second;
}
//returns element symbol //returns element symbol
std::string MassLookup::FindSymbol(int Z, int A) std::string MassLookup::FindSymbol(int Z, int A)
{
auto data = elementTable.find(Z);
if(data == elementTable.end())
{ {
std::cerr<<"Invaild nucleus at MassLookup! Returning empty symbol"<<std::endl; auto data = elementTable.find(Z);
return ""; if(data == elementTable.end())
{
std::cerr<<"Invaild nucleus at MassLookup! Returning empty symbol"<<std::endl;
return "";
}
std::string fullsymbol = std::to_string(A) + data->second;
return fullsymbol;
} }
std::string fullsymbol = std::to_string(A) + data->second;
return fullsymbol;
} }

View File

@ -11,25 +11,29 @@ Written by G.W. McCann Aug. 2020
#ifndef MASS_LOOKUP_H #ifndef MASS_LOOKUP_H
#define MASS_LOOKUP_H #define MASS_LOOKUP_H
class MassLookup namespace EventBuilder {
{
public: class MassLookup
MassLookup(); {
~MassLookup();
double FindMass(int Z, int A);
std::string FindSymbol(int Z, int A);
private: public:
std::unordered_map<std::string, double> massTable; MassLookup();
std::unordered_map<int, std::string> elementTable; ~MassLookup();
double FindMass(int Z, int A);
std::string FindSymbol(int Z, int A);
//constants private:
static constexpr double u_to_mev = 931.4940954; std::unordered_map<std::string, double> massTable;
static constexpr double electron_mass = 0.000548579909; std::unordered_map<int, std::string> 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;
//static instance for use throught program
static MassLookup MASS;
}
#endif #endif

View File

@ -8,33 +8,37 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "OrderChecker.h" #include "OrderChecker.h"
OrderChecker::OrderChecker() namespace EventBuilder {
{
}
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; i<tree->GetEntries(); i++)
{ {
tree->GetEntry();
if(prevStamp >= ts)
{
std::cerr<<"Bad order at entry "<<i<<" out of "<<tree->GetEntries()<<std::endl;
return false;
}
} }
file->Close(); OrderChecker::~OrderChecker()
return true; {
}
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; i<tree->GetEntries(); i++)
{
tree->GetEntry();
if(prevStamp >= ts)
{
std::cerr<<"Bad order at entry "<<i<<" out of "<<tree->GetEntries()<<std::endl;
return false;
}
}
file->Close();
return true;
}
} }

View File

@ -8,12 +8,16 @@
#ifndef ORDERCHECKER_H #ifndef ORDERCHECKER_H
#define ORDERCHECKER_H #define ORDERCHECKER_H
class OrderChecker namespace EventBuilder {
{
public: class OrderChecker
OrderChecker(); {
~OrderChecker(); public:
bool IsOrdered(const std::string& filename); OrderChecker();
}; ~OrderChecker();
bool IsOrdered(const std::string& filename);
};
}
#endif #endif

View File

@ -7,127 +7,89 @@
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
RunCollector::RunCollector(): namespace EventBuilder {
m_initFlag(false), m_directory(""), m_prefix(""), m_suffix(""), m_minRun(0), m_maxRun(0)
{
}
RunCollector::RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix) : RunCollector::RunCollector():
m_initFlag(true), m_directory(dirname), m_prefix(prefix), m_suffix(suffix), m_minRun(0), m_maxRun(0) m_initFlag(false), m_directory(""), m_prefix(""), m_suffix(""), m_minRun(0), m_maxRun(0)
{
}
RunCollector::RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, 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
{ {
std::cerr<<"Unable to find any files in directory; check name given to the input.txt"<<std::endl;
return false;
} }
TSystemFile *file; RunCollector::RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix) :
std::string fname, temp; m_initFlag(true), m_directory(dirname), m_prefix(prefix), m_suffix(suffix), m_minRun(0), m_maxRun(0)
TIter next_element(flist); //List iterator
while((file = (TSystemFile*)next_element()))
{ {
temp = file->GetName(); }
if(temp.size() < m_prefix.size() || temp.size() < m_suffix.size())
continue; RunCollector::RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max) :
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) && m_initFlag(true), m_directory(dirname), m_prefix(prefix), m_suffix(suffix), m_minRun(min), m_maxRun(max)
!temp.compare(temp.size()-m_suffix.size(), m_suffix.size(), m_suffix)) {
}
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; std::cerr<<"Unable to find any files in directory; check name given to the input.txt"<<std::endl;
m_filelist.push_back(fname); return false;
}
TSystemFile *file;
std::string fname, temp;
TIter next_element(flist); //List iterator
while((file = (TSystemFile*)next_element()))
{
temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < m_suffix.size())
continue;
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) &&
!temp.compare(temp.size()-m_suffix.size(), m_suffix.size(), m_suffix))
{
fname = m_directory+temp;
m_filelist.push_back(fname);
}
}
delete flist;
if(m_filelist.size()>0)
return true;
else
{
std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<<std::endl;
return false;
} }
} }
delete flist; std::string RunCollector::GrabFile(int runNum) {
if(m_filelist.size()>0) if(!m_initFlag)
return true; return "";
else TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
{ TList* flist = sysdir.GetListOfFiles();
std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<<std::endl;
return false;
}
}
std::string RunCollector::GrabFile(int runNum) { if(!flist)
if(!m_initFlag) return "";
return "";
TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
TList* flist = sysdir.GetListOfFiles();
if(!flist) TSystemFile *file;
return ""; std::string fname = "", temp;
std::string runno = "_"+std::to_string(runNum)+m_suffix;
TSystemFile *file; TIter next_element(flist);
std::string fname = "", temp; while((file = (TSystemFile*)next_element()))
std::string runno = "_"+std::to_string(runNum)+m_suffix;
TIter next_element(flist);
while((file = (TSystemFile*)next_element()))
{
temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < runno.size())
continue;
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) &&
!temp.compare(temp.size()-runno.size(),runno.size(), runno))
{
fname = m_directory+temp;
break;
}
}
delete flist;
return fname;
}
/*Grabs all files within a specified run range*/
bool RunCollector::GrabFilesInRange()
{
if(!m_initFlag)
return false;
TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
TList *flist = sysdir.GetListOfFiles();
m_filelist.clear();
if(!flist)
{
std::cerr<<"Unable to find any files in directory; check name given to input.txt"<<std::endl;
return false;
}
TSystemFile *file;
std::string fname, temp;
std::string runno;
for(int i=m_minRun; i<=m_maxRun; i++) //loop over range
{
TIter next_element(flist);//list iterator
runno = "_"+std::to_string(i) + m_suffix; //suffix is now _#.suffix
while((file = (TSystemFile*)next_element())) //look through directory until file found
{ {
temp = file->GetName(); temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < runno.size()) 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)) !temp.compare(temp.size()-runno.size(),runno.size(), runno))
{ {
fname = m_directory+temp; fname = m_directory+temp;
m_filelist.push_back(fname); break;
break; //if we find the file, break out of iterator loop
} }
} }
delete flist;
return fname;
} }
delete flist; /*Grabs all files within a specified run range*/
if(m_filelist.size()>0) bool RunCollector::GrabFilesInRange()
return true;
else
{ {
std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<<std::endl; if(!m_initFlag)
return false;
TSystemDirectory sysdir(m_directory.c_str(), m_directory.c_str());
TList *flist = sysdir.GetListOfFiles();
m_filelist.clear();
if(!flist)
{
std::cerr<<"Unable to find any files in directory; check name given to input.txt"<<std::endl;
return false;
}
TSystemFile *file;
std::string fname, temp;
std::string runno;
for(int i=m_minRun; i<=m_maxRun; i++) //loop over range
{
TIter next_element(flist);//list iterator
runno = "_"+std::to_string(i) + m_suffix; //suffix is now _#.suffix
while((file = (TSystemFile*)next_element())) //look through directory until file found
{
temp = file->GetName();
if(temp.size() < m_prefix.size() || temp.size() < runno.size())
continue;
else if(!file->IsDirectory() && !temp.compare(0,m_prefix.size(),m_prefix) &&
!temp.compare(temp.size()-runno.size(),runno.size(), runno))
{
fname = m_directory+temp;
m_filelist.push_back(fname);
break; //if we find the file, break out of iterator loop
}
}
}
delete flist;
if(m_filelist.size()>0)
return true;
else
{
std::cerr<<"Unable to find files with matching run name in directory; check input.txt"<<std::endl;
return false;
}
}
bool RunCollector::Merge_hadd(const std::string& outname)
{
if(!m_initFlag)
return false;
if(m_maxRun == 0)
{
if(GrabAllFiles())
{
std::string clump = "hadd "+outname;
for(unsigned int i=0; i<m_filelist.size(); i++)
clump += " "+m_filelist[i];
std::cout<<"Merging runs into single file..."<<std::endl;
std::system(clump.c_str());
std::cout<<"Finished merging"<<std::endl;
return true;
}
else
return false;
}
else
{
if(GrabFilesInRange())
{
std::string clump = "hadd "+outname;
for(unsigned int i=0; i<m_filelist.size(); i++)
clump += " "+m_filelist[i];
std::cout<<"Merging runs "<<m_minRun<<" to "<<m_maxRun<<" into a single file..."<<std::endl;
std::system(clump.c_str());
std::cout<<"Finished merging"<<std::endl;
return true;
}
else
return false;
}
}
bool RunCollector::Merge_TChain(const std::string& outname)
{
if(!m_initFlag)
return false;
TFile *output = new TFile(outname.c_str(), "RECREATE");
TChain *chain = new TChain("SPSTree", "SPSTree");
if(m_maxRun == 0)
{
if(GrabAllFiles())
{
for(unsigned int i=0; i<m_filelist.size(); i++)
chain->Add(m_filelist[i].c_str());
std::cout<<"Merging runs into single file..."<<std::endl;
chain->Merge(output,0,"fast");
std::cout<<"Finished merging"<<std::endl;
return true;
}
else
return false;
}
else
{
if(GrabFilesInRange())
{
for(unsigned int i=0; i<m_filelist.size(); i++)
chain->Add(m_filelist[i].c_str());
std::cout<<"Merging runs "<<m_minRun<<" to "<<m_maxRun<<" into a single file..."<<std::endl;
chain->Merge(output,0,"fast");
std::cout<<"Finished merging"<<std::endl;
return true;
} else
return false;
}
if(output->IsOpen())
output->Close();
return false; return false;
} }
} }
bool RunCollector::Merge_hadd(const std::string& outname)
{
if(!m_initFlag)
return false;
if(m_maxRun == 0)
{
if(GrabAllFiles())
{
std::string clump = "hadd "+outname;
for(unsigned int i=0; i<m_filelist.size(); i++)
clump += " "+m_filelist[i];
std::cout<<"Merging runs into single file..."<<std::endl;
std::system(clump.c_str());
std::cout<<"Finished merging"<<std::endl;
return true;
}
else
return false;
}
else
{
if(GrabFilesInRange())
{
std::string clump = "hadd "+outname;
for(unsigned int i=0; i<m_filelist.size(); i++)
clump += " "+m_filelist[i];
std::cout<<"Merging runs "<<m_minRun<<" to "<<m_maxRun<<" into a single file..."<<std::endl;
std::system(clump.c_str());
std::cout<<"Finished merging"<<std::endl;
return true;
}
else
return false;
}
}
bool RunCollector::Merge_TChain(const std::string& outname)
{
if(!m_initFlag)
return false;
TFile *output = new TFile(outname.c_str(), "RECREATE");
TChain *chain = new TChain("SPSTree", "SPSTree");
if(m_maxRun == 0)
{
if(GrabAllFiles())
{
for(unsigned int i=0; i<m_filelist.size(); i++)
chain->Add(m_filelist[i].c_str());
std::cout<<"Merging runs into single file..."<<std::endl;
chain->Merge(output,0,"fast");
std::cout<<"Finished merging"<<std::endl;
return true;
}
else
return false;
}
else
{
if(GrabFilesInRange())
{
for(unsigned int i=0; i<m_filelist.size(); i++)
chain->Add(m_filelist[i].c_str());
std::cout<<"Merging runs "<<m_minRun<<" to "<<m_maxRun<<" into a single file..."<<std::endl;
chain->Merge(output,0,"fast");
std::cout<<"Finished merging"<<std::endl;
return true;
} else
return false;
}
if(output->IsOpen())
output->Close();
return false;
}

View File

@ -10,35 +10,38 @@
#ifndef RUNCOLLECTOR_H #ifndef RUNCOLLECTOR_H
#define RUNCOLLECTOR_H #define RUNCOLLECTOR_H
class RunCollector namespace EventBuilder {
{
public:
RunCollector();
RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix);
RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
~RunCollector();
void SetSearchParams(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
bool Merge_hadd(const std::string& outname);
bool Merge_TChain(const std::string& outname);
bool GrabAllFiles();
bool GrabFilesInRange();
std::string GrabFile(int runNum);
inline std::string GetSearchDir() { return m_directory; }
inline std::string GetSearchPrefix() { return m_prefix; }
inline std::string GetSearchSuffix() { return m_suffix; }
inline int GetRunMin() { return m_minRun; }
inline int GetRunMax() { return m_maxRun; }
inline const std::vector<std::string>& GetFileList() { return m_filelist; }
private: class RunCollector
bool m_initFlag; {
std::string m_directory; public:
std::string m_prefix; RunCollector();
std::string m_suffix; RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix);
int m_minRun, m_maxRun; //user run limits RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
const int m_maxAllowedRuns = 1000; //class run limit ~RunCollector();
std::vector<std::string> m_filelist; void SetSearchParams(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
bool Merge_hadd(const std::string& outname);
bool Merge_TChain(const std::string& outname);
bool GrabAllFiles();
bool GrabFilesInRange();
std::string GrabFile(int runNum);
inline std::string GetSearchDir() { return m_directory; }
inline std::string GetSearchPrefix() { return m_prefix; }
inline std::string GetSearchSuffix() { return m_suffix; }
inline int GetRunMin() { return m_minRun; }
inline int GetRunMax() { return m_maxRun; }
inline const std::vector<std::string>& GetFileList() { return m_filelist; }
}; private:
bool m_initFlag;
std::string m_directory;
std::string m_prefix;
std::string m_suffix;
int m_minRun, m_maxRun; //user run limits
const int m_maxAllowedRuns = 1000; //class run limit
std::vector<std::string> m_filelist;
};
}
#endif #endif

View File

@ -12,194 +12,197 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
namespace EventBuilder {
/*Constructor takes in kinematic parameters for generating focal plane weights*/ /*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, SFPAnalyzer::SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep,
double angle, double b) double angle, double b)
{
zfp = Delta_Z(zt, at, zp, ap, ze, ae, ep, angle, b);
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: "<<w1<<" w2: "<<w2<<std::endl;
}
/*2D histogram fill wrapper for use with THashTable (faster)*/
void SFPAnalyzer::MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex,
int binsy, double miny, double maxy, double valuey)
{
TH2F *histo = (TH2F*) rootObj->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); zfp = Delta_Z(zt, at, zp, ap, ze, ae, ep, angle, b);
h->Fill(valuex, valuey); event_address = new CoincEvent();
rootObj->Add(h); 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
{
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*/ SFPAnalyzer::~SFPAnalyzer()
if(!event.focalPlane.delayFR.empty())
{ {
pevent.delayFrontRightE = event.focalPlane.delayFR[0].Long; rootObj->Clear();
pevent.delayFrontRightTime = event.focalPlane.delayFR[0].Time; delete rootObj;
pevent.delayFrontRightShort = event.focalPlane.delayFR[0].Short; delete event_address;
}
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*/ void SFPAnalyzer::Reset()
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; pevent = blank; //set output back to blank
MyFill("xavg",1200,-300,300,pevent.xavg); }
if((pevent.x2-pevent.x1) > 0)
pevent.theta = std::atan((pevent.x2-pevent.x1)/36.0); /*Use functions from FP_kinematics to calculate weights for xavg
else if((pevent.x2-pevent.x1) < 0) *While this seems kind of funny, it is mathematically equivalent to making a line
pevent.theta = TMath::Pi() + std::atan((pevent.x2-pevent.x1)/36.0); *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: "<<w1<<" w2: "<<w2<<std::endl;
}
/*2D histogram fill wrapper for use with THashTable (faster)*/
void SFPAnalyzer::MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex,
int binsy, double miny, double maxy, double valuey)
{
TH2F *histo = (TH2F*) rootObj->FindObject(name.c_str());
if(histo != nullptr)
histo->Fill(valuex, valuey);
else else
pevent.theta = TMath::Pi()/2.0; {
MyFill("xavg vs theta",600,-300,300,pevent.xavg,314,0,3.14,pevent.theta); TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy);
MyFill("x1 vs x2",600,-300,300,pevent.x1,600,-300,300,pevent.x2); 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;
} }

View File

@ -13,33 +13,36 @@
#include "DataStructs.h" #include "DataStructs.h"
#include "FP_kinematics.h" #include "FP_kinematics.h"
namespace EventBuilder {
class SFPAnalyzer class SFPAnalyzer
{ {
public: public:
SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, double angle, SFPAnalyzer(int zt, int at, int zp, int ap, int ze, int ae, double ep, double angle,
double b); double b);
~SFPAnalyzer(); ~SFPAnalyzer();
ProcessedEvent GetProcessedEvent(CoincEvent& event); ProcessedEvent GetProcessedEvent(CoincEvent& event);
inline void ClearHashTable() { rootObj->Clear(); } inline void ClearHashTable() { rootObj->Clear(); }
inline THashTable* GetHashTable() { return rootObj; } inline THashTable* GetHashTable() { return rootObj; }
private: private:
void Reset(); //Sets ouput structure back to "zero" void Reset(); //Sets ouput structure back to "zero"
void GetWeights(); //weights for xavg void GetWeights(); //weights for xavg
void AnalyzeEvent(CoincEvent& event); void AnalyzeEvent(CoincEvent& event);
/*Fill wrappers for use with THashTable*/ /*Fill wrappers for use with THashTable*/
void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex, void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex,
int binsy, double miny, double maxy, double valuey); int binsy, double miny, double maxy, double valuey);
void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex); void MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex);
CoincEvent *event_address; //Input branch address CoincEvent *event_address; //Input branch address
ProcessedEvent pevent, blank; //output branch and reset ProcessedEvent pevent, blank; //output branch and reset
double w1, w2, zfp; double w1, w2, zfp;
THashTable *rootObj; //root storage THashTable *rootObj; //root storage
}; };
}
#endif #endif

View File

@ -10,287 +10,291 @@
#include "SFPPlotter.h" #include "SFPPlotter.h"
#include <TSystem.h> #include <TSystem.h>
/*Generates storage and initializes pointers*/ namespace EventBuilder {
SFPPlotter::SFPPlotter()
{
event_address = new ProcessedEvent();
m_pb = nullptr;
}
SFPPlotter::~SFPPlotter() /*Generates storage and initializes pointers*/
{ 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
{ {
TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); event_address = new ProcessedEvent();
h->Fill(valuex, valuey); m_pb = nullptr;
table->Add(h);
} }
}
/*1D histogram fill wrapper*/ SFPPlotter::~SFPPlotter()
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); delete event_address;
h->Fill(valuex);
table->Add(h);
} }
}
/*Makes histograms where only rejection is unset data*/ /*2D histogram fill wrapper*/
void SFPPlotter::MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table) 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)
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; TH2F *histo = (TH2F*) table->FindObject(name.c_str());
Double_t delayRelFT = ev.delayFrontMaxTime - ev.anodeBackTime; if(histo != nullptr)
Double_t delayRelBT = ev.delayBackMaxTime - ev.anodeBackTime; histo->Fill(valuex, valuey);
Double_t anodeRelBT = ev.anodeBackTime - ev.scintLeftTime; else
Double_t delayRelFT_toScint = ev.delayFrontMaxTime - ev.scintLeftTime; {
Double_t delayRelBT_toScint = ev.delayBackMaxTime - ev.scintLeftTime; TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy);
MyFill(table,"anodeRelFrontTime_NoCuts",1000,-3000,3500, anodeRelFT); h->Fill(valuex, valuey);
MyFill(table,"delayRelFrontTime_NoCuts",1000,-3000,-3500,delayRelFT); table->Add(h);
MyFill(table,"delayRelBackTime_NoCuts",1000,-3000,-3500,delayRelBT); }
}
/*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++) for(int i=0; i<5; i++)
{ {
if(ev.sabreRingE[i] != -1) if(ev.sabreRingE[i] != -1)
{ {
Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime; MyFill(table,"sabreRingE_Cut",2000,0,20,ev.sabreRingE[i]);
Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; MyFill(table,"xavg_Cut_sabrefcoinc",600,-300,300,ev.xavg);
Double_t sabreRelRT_toScint = ev.sabreRingTime[i] - ev.scintLeftTime; MyFill(table,"xavg_sabreRingE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreRingE[i]);
Double_t sabreRelWT_toScint = ev.sabreWedgeTime[i] - ev.scintLeftTime; MyFill(table,"sabreWedgeE_Cut",2000,0,20,ev.sabreWedgeE[i]);
MyFill(table,"xavg_sabrefcoinc_NoCuts",600,-300,300, ev.xavg); MyFill(table,"xavg_sabreWedgeE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreWedgeE[i]);
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) /*Runs a list of files given from a RunCollector class*/
MyFill(table,"x1NoCuts_only1plane",600,-300,300,ev.x1); void SFPPlotter::Run(const std::vector<std::string>& files, const std::string& output)
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; TFile *outfile = TFile::Open(output.c_str(), "RECREATE");
Double_t anodeRelBT = ev.anodeBackTime - ev.anodeBackTime; TChain* chain = new TChain("SPSTree");
Double_t anodeRelFT_toScint = ev.anodeFrontTime-ev.scintLeftTime; for(unsigned int i=0; i<files.size(); i++)
MyFill(table,"anodeRelBackTime_Cut",1000,-3000,3500, anodeRelBT); chain->Add(files[i].c_str());
MyFill(table,"anodeRelFrontTime_Cut",1000,-3000,3500, anodeRelFT); chain->SetBranchAddress("event", &event_address);
MyFill(table,"anodeRelTime_toScint_Cut",1000,-3000,3500,anodeRelFT_toScint); THashTable* table = new THashTable();
for(int i=0; i<5; i++)
long blentries = chain->GetEntries();
if(m_pb)
SetProgressBar(blentries);
std::cout<<"Total number of events: "<<blentries<<std::endl;
long count=0, flush_val=blentries*0.01, flush_count=0;
for(long i=0; i<chain->GetEntries(); i++)
{ {
if(ev.sabreRingE[i] != -1) count++;
if(count == flush_val)
{ {
Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime; if(m_pb) {
Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; m_pb->Increment(count);
MyFill(table,"sabreRelRingTime_Cut",1000,-3000,3500, sabreRelRT); gSystem->ProcessEvents();
MyFill(table,"sabreRelWedgeTime_Cut",1000,-3000,3500, sabreRelWT); count = 0;
} else {
flush_count++;
count=0;
std::cout<<"\rPercent of data processed: "<<flush_count*10<<"%"<<std::flush;
}
} }
chain->GetEntry(i);
MakeUncutHistograms(*event_address, table);
if(cutter.IsValid()) MakeCutHistograms(*event_address, table);
} }
} std::cout<<std::endl;
else outfile->cd();
{ table->Write();
MyFill(table,"noscinttime_counter_Cut",2,0,1,1); if(cutter.IsValid())
}
for(int i=0; i<5; i++)
{
if(ev.sabreRingE[i] != -1)
{ {
MyFill(table,"sabreRingE_Cut",2000,0,20,ev.sabreRingE[i]); auto clist = cutter.GetCuts();
MyFill(table,"xavg_Cut_sabrefcoinc",600,-300,300,ev.xavg); for(unsigned int i=0; i<clist.size(); i++)
MyFill(table,"xavg_sabreRingE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreRingE[i]); clist[i]->Write();
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]);
} }
delete table;
outfile->Close();
delete outfile;
} }
}
/*Runs a list of files given from a RunCollector class*/
void SFPPlotter::Run(const std::vector<std::string>& files, const std::string& output)
{
TFile *outfile = TFile::Open(output.c_str(), "RECREATE");
TChain* chain = new TChain("SPSTree");
for(unsigned int i=0; i<files.size(); i++)
chain->Add(files[i].c_str());
chain->SetBranchAddress("event", &event_address);
THashTable* table = new THashTable();
long blentries = chain->GetEntries(); void SFPPlotter::SetProgressBar(long total)
if(m_pb)
SetProgressBar(blentries);
std::cout<<"Total number of events: "<<blentries<<std::endl;
long count=0, flush_val=blentries*0.01, flush_count=0;
for(long i=0; i<chain->GetEntries(); i++)
{ {
count++; m_pb->SetMax(total);
if(count == flush_val) m_pb->SetMin(0);
{ m_pb->SetPosition(0);
if(m_pb) { gSystem->ProcessEvents();
m_pb->Increment(count);
gSystem->ProcessEvents();
count = 0;
} else {
flush_count++;
count=0;
std::cout<<"\rPercent of data processed: "<<flush_count*10<<"%"<<std::flush;
}
}
chain->GetEntry(i);
MakeUncutHistograms(*event_address, table);
if(cutter.IsValid()) MakeCutHistograms(*event_address, table);
} }
std::cout<<std::endl;
outfile->cd();
table->Write();
if(cutter.IsValid())
{
auto clist = cutter.GetCuts();
for(unsigned int i=0; i<clist.size(); i++)
clist[i]->Write();
}
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();
} }

View File

@ -13,33 +13,37 @@
#include "CutHandler.h" #include "CutHandler.h"
#include <TGProgressBar.h> #include <TGProgressBar.h>
class SFPPlotter namespace EventBuilder {
{
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<std::string>& files, const std::string& output);
private: class SFPPlotter
void SetProgressBar(long total); {
void Chain(const std::vector<std::string>& files); //Form TChain public:
void MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table); SFPPlotter();
void MakeCutHistograms(const ProcessedEvent& ev, THashTable* table); ~SFPPlotter();
inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; }
inline void ApplyCutlist(const std::string& listname) { cutter.SetCuts(listname); }
void Run(const std::vector<std::string>& files, const std::string& output);
/*Histogram fill wrapper functions*/ private:
void MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex, void SetProgressBar(long total);
int binsy, double miny, double maxy, double valuey); void Chain(const std::vector<std::string>& files); //Form TChain
void MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex); void MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table);
void MakeCutHistograms(const ProcessedEvent& ev, THashTable* table);
ProcessedEvent *event_address; /*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);
/*Cuts*/ ProcessedEvent *event_address;
CutHandler cutter;
TGProgressBar* m_pb; //GUI progress /*Cuts*/
CutHandler cutter;
}; TGProgressBar* m_pb; //GUI progress
};
}
#endif #endif

View File

@ -12,70 +12,74 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "ShiftMap.h" #include "ShiftMap.h"
ShiftMap::ShiftMap() : namespace EventBuilder {
m_filename(""), m_validFlag(false)
{
}
ShiftMap::ShiftMap(const std::string& filename) : ShiftMap::ShiftMap() :
m_filename(filename), m_validFlag(false) m_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 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)
{ {
for(int i=0; i<16; i++) input>>temp;
input>>shift;
if(temp == "all") //keyword to set all channels in this board to same shift
{ {
gchan = board*16 + i; for(int i=0; i<16; i++)
{
gchan = board*16 + i;
m_map[gchan] = shift;
}
}
else
{
channel = stoi(temp);
gchan = channel + board*16;
m_map[gchan] = shift; m_map[gchan] = shift;
} }
} }
else
{ m_validFlag = true;
channel = stoi(temp);
gchan = channel + board*16;
m_map[gchan] = shift;
}
} }
m_validFlag = true;
} }

View File

@ -12,25 +12,29 @@
#ifndef SHIFTMAP_H #ifndef SHIFTMAP_H
#define SHIFTMAP_H #define SHIFTMAP_H
class ShiftMap namespace EventBuilder {
{
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: class ShiftMap
void ParseFile(); {
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);
std::string m_filename; private:
bool m_validFlag; void ParseFile();
std::unordered_map<int, uint64_t> m_map; std::string m_filename;
bool m_validFlag;
}; std::unordered_map<int, uint64_t> m_map;
};
}
#endif #endif

View File

@ -10,171 +10,175 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "SlowSort.h" #include "SlowSort.h"
/*Sort the Sabre Data in order of descending energy*/ namespace EventBuilder {
bool SabreSort(const DetectorHit& i, const DetectorHit& j) {
return (i.Long>j.Long);
}
/*Constructor takes input of coincidence window size, and fills sabre channel map*/ /*Sort the Sabre Data in order of descending energy*/
SlowSort::SlowSort() : bool SabreSort(const DetectorHit& i, const DetectorHit& j) {
m_coincWindow(-1.0), m_eventFlag(false) return (i.Long>j.Long);
{
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; /*Constructor takes input of coincidence window size, and fills sabre channel map*/
else if ((curHit.Timestamp - startTime) < m_coincWindow) SlowSort::SlowSort() :
m_hitList.push_back(curHit); m_coincWindow(-1.0), m_eventFlag(false)
else
{ {
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;
}
return true;
}
void SlowSort::FlushHitsToEvent()
{
if(m_hitList.empty())
{
m_eventFlag = false;
return;
}
ProcessEvent(); ProcessEvent();
m_hitList.clear(); m_hitList.clear();
startTime = curHit.Timestamp;
m_hitList.push_back(curHit);
m_eventFlag = true; m_eventFlag = true;
} }
return true; const CoincEvent& SlowSort::GetEvent()
}
void SlowSort::FlushHitsToEvent()
{
if(m_hitList.empty())
{ {
m_eventFlag = false; m_eventFlag = false;
return; return m_event;
} }
ProcessEvent(); /*Function called when an event outside the coincidence window is detected
m_hitList.clear(); *Process all of the hits in the list, and write them to the sorted tree
m_eventFlag = true; */
} void SlowSort::ProcessEvent()
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)
{ {
gchan = curHit.Channel + curHit.Board*16; //global channel Reset();
event_stats->Fill(gchan, size); DetectorHit dhit;
dhit.Time = curHit.Timestamp/1.0e3; int gchan;
dhit.Ch = gchan; int size = m_hitList.size();
dhit.Long = curHit.Energy; for(DPPChannel& curHit: m_hitList)
dhit.Short = curHit.EnergyShort; {
auto channel_info = cmap.FindChannel(gchan); 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()) if(channel_info == cmap.End())
{ {
std::cout<<std::endl; std::cout<<std::endl;
std::cout<<"------Data Assignment Error!-------"<<std::endl; std::cout<<"------Data Assignment Error!-------"<<std::endl;
std::cout<<"Global channel number "<<gchan<<" found in data stream, but not assigned in ChannelMap!"<<std::endl; std::cout<<"Global channel number "<<gchan<<" found in data stream, but not assigned in ChannelMap!"<<std::endl;
std::cout<<"Skipping this hit..."<<std::endl; std::cout<<"Skipping this hit..."<<std::endl;
std::cout<<"-----------------------------------"<<std::endl; std::cout<<"-----------------------------------"<<std::endl;
continue; continue;
} }
if(channel_info->second.type == DetType::FocalPlane) if(channel_info->second.type == DetType::FocalPlane)
{ {
auto variable = varMap.find(channel_info->second.attribute); auto variable = varMap.find(channel_info->second.attribute);
if(variable != varMap.end()) if(variable != varMap.end())
variable->second->push_back(dhit); 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<<std::endl;
std::cout<<"------Data Assignment Error!-------"<<std::endl;
std::cout<<"Channel is present in channel map, but does not have a variable assigned in variable map!"<<std::endl;
std::cout<<"global channel number: "<<gchan<<" channel detector type: "<<channel_info->second.type<<" attribute: "<<channel_info->second.attribute<<std::endl;
std::cout<<"Skipping this hit..."<<std::endl;
std::cout<<"-----------------------------------"<<std::endl;
}
} }
else if(channel_info->second.type == DetType::Sabre) //Organize the SABRE data in descending energy order
for(int s=0; s<5; s++)
{ {
auto variable = varMap.find(channel_info->second.attribute); sort(m_event.sabreArray[s].rings.begin(), m_event.sabreArray[s].rings.end(), SabreSort);
if(variable != varMap.end()) sort(m_event.sabreArray[s].wedges.begin(), m_event.sabreArray[s].wedges.end(), SabreSort);
variable->second->push_back(dhit);
}
else
{
std::cout<<std::endl;
std::cout<<"------Data Assignment Error!-------"<<std::endl;
std::cout<<"Channel is present in channel map, but does not have a variable assigned in variable map!"<<std::endl;
std::cout<<"global channel number: "<<gchan<<" channel detector type: "<<channel_info->second.type<<" attribute: "<<channel_info->second.attribute<<std::endl;
std::cout<<"Skipping this hit..."<<std::endl;
std::cout<<"-----------------------------------"<<std::endl;
} }
} }
//Organize the SABRE data in descending energy order
for(int s=0; s<5; s++)
{
sort(m_event.sabreArray[s].rings.begin(), m_event.sabreArray[s].rings.end(), SabreSort);
sort(m_event.sabreArray[s].wedges.begin(), m_event.sabreArray[s].wedges.end(), SabreSort);
}
} }

View File

@ -16,39 +16,43 @@
#include <TH2.h> #include <TH2.h>
#include <unordered_map> #include <unordered_map>
class SlowSort namespace EventBuilder {
{
public: class SlowSort
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: public:
void InitVariableMaps(); SlowSort();
void Reset(); SlowSort(double windowSize, const std::string& mapfile);
void ProcessEvent(); ~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; }
double m_coincWindow; private:
std::vector<DPPChannel> m_hitList; void InitVariableMaps();
bool m_eventFlag; void Reset();
CoincEvent m_event; void ProcessEvent();
CoincEvent m_blank;
double startTime, previousHitTime; double m_coincWindow;
std::unordered_map<DetAttribute, std::vector<DetectorHit>*> varMap; std::vector<DPPChannel> m_hitList;
bool m_eventFlag;
CoincEvent m_event;
CoincEvent m_blank;
TH2F* event_stats; double startTime, previousHitTime;
std::unordered_map<DetAttribute, std::vector<DetectorHit>*> varMap;
ChannelMap cmap; TH2F* event_stats;
}; ChannelMap cmap;
};
}
#endif #endif

View File

@ -8,30 +8,34 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "Stopwatch.h" #include "Stopwatch.h"
Stopwatch::Stopwatch() namespace EventBuilder {
{
start_time = Clock::now();
stop_time = start_time;
}
Stopwatch::~Stopwatch() {} Stopwatch::Stopwatch()
{
start_time = Clock::now();
stop_time = start_time;
}
void Stopwatch::Start() Stopwatch::~Stopwatch() {}
{
start_time = Clock::now();
}
void Stopwatch::Stop() void Stopwatch::Start()
{ {
stop_time = Clock::now(); start_time = Clock::now();
} }
double Stopwatch::GetElapsedSeconds() void Stopwatch::Stop()
{ {
return std::chrono::duration_cast<std::chrono::duration<double>>(stop_time-start_time).count(); stop_time = Clock::now();
} }
double Stopwatch::GetElapsedSeconds()
{
return std::chrono::duration_cast<std::chrono::duration<double>>(stop_time-start_time).count();
}
double Stopwatch::GetElapsedMilliseconds()
{
return std::chrono::duration_cast<std::chrono::duration<double>>(stop_time-start_time).count()*1000.0;
}
double Stopwatch::GetElapsedMilliseconds()
{
return std::chrono::duration_cast<std::chrono::duration<double>>(stop_time-start_time).count()*1000.0;
} }

View File

@ -10,21 +10,25 @@
#include <chrono> #include <chrono>
class Stopwatch namespace EventBuilder {
{
public:
Stopwatch();
~Stopwatch();
void Start();
void Stop();
double GetElapsedSeconds();
double GetElapsedMilliseconds();
private: class Stopwatch
using Time = std::chrono::high_resolution_clock::time_point; {
using Clock = std::chrono::high_resolution_clock; public:
Stopwatch();
~Stopwatch();
void Start();
void Stop();
double GetElapsedSeconds();
double GetElapsedMilliseconds();
Time start_time, stop_time; private:
}; using Time = std::chrono::high_resolution_clock::time_point;
using Clock = std::chrono::high_resolution_clock;
Time start_time, stop_time;
};
}
#endif #endif

View File

@ -1,7 +1,7 @@
#include "EventBuilder.h" #include "evb/EventBuilder.h"
#include "spsdict/DataStructs.h" #include "spsdict/DataStructs.h"
#include <TApplication.h> #include <TApplication.h>
#include "EVBMainFrame.h" #include "guidict/EVBMainFrame.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View File

@ -142,13 +142,13 @@ EVBMainFrame::EVBMainFrame(const TGWindow* p, UInt_t w, UInt_t h) :
TGLabel *typelabel = new TGLabel(RunFrame, "Operation Type:"); TGLabel *typelabel = new TGLabel(RunFrame, "Operation Type:");
fTypeBox = new TGComboBox(RunFrame, TypeBox); fTypeBox = new TGComboBox(RunFrame, TypeBox);
//Needs modification for new conversion based sorting GWM -- Dec 2020 //Needs modification for new conversion based sorting GWM -- Dec 2020
fTypeBox->AddEntry("Convert Slow", EVBApp::Operation::ConvertSlow); fTypeBox->AddEntry("Convert Slow", EventBuilder::EVBApp::Operation::ConvertSlow);
fTypeBox->AddEntry("Convert Fast", EVBApp::Operation::ConvertFast); fTypeBox->AddEntry("Convert Fast", EventBuilder::EVBApp::Operation::ConvertFast);
fTypeBox->AddEntry("Convert SlowA", EVBApp::Operation::ConvertSlowA); fTypeBox->AddEntry("Convert SlowA", EventBuilder::EVBApp::Operation::ConvertSlowA);
fTypeBox->AddEntry("Convert FastA", EVBApp::Operation::ConvertFastA); fTypeBox->AddEntry("Convert FastA", EventBuilder::EVBApp::Operation::ConvertFastA);
fTypeBox->AddEntry("Convert", EVBApp::Operation::Convert); fTypeBox->AddEntry("Convert", EventBuilder::EVBApp::Operation::Convert);
fTypeBox->AddEntry("Merge ROOT", EVBApp::Operation::Merge); fTypeBox->AddEntry("Merge ROOT", EventBuilder::EVBApp::Operation::Merge);
fTypeBox->AddEntry("Plot", EVBApp::Operation::Plot); fTypeBox->AddEntry("Plot", EventBuilder::EVBApp::Operation::Plot);
fTypeBox->Resize(200,20); fTypeBox->Resize(200,20);
fTypeBox->Connect("Selected(Int_t, Int_t)","EVBMainFrame",this,"HandleTypeSelection(Int_t,Int_t)"); fTypeBox->Connect("Selected(Int_t, Int_t)","EVBMainFrame",this,"HandleTypeSelection(Int_t,Int_t)");
TGLabel *rminlabel = new TGLabel(RunFrame, "Min Run:"); TGLabel *rminlabel = new TGLabel(RunFrame, "Min Run:");
@ -256,37 +256,37 @@ void EVBMainFrame::DoRun()
switch(type) switch(type)
{ {
case EVBApp::Operation::Plot : case EventBuilder::EVBApp::Operation::Plot :
{ {
RunPlot(); RunPlot();
break; break;
} }
case EVBApp::Operation::Convert : case EventBuilder::EVBApp::Operation::Convert :
{ {
fBuilder.Convert2RawRoot(); fBuilder.Convert2RawRoot();
break; break;
} }
case EVBApp::Operation::Merge : case EventBuilder::EVBApp::Operation::Merge :
{ {
fBuilder.MergeROOTFiles(); fBuilder.MergeROOTFiles();
break; break;
} }
case EVBApp::Operation::ConvertSlow : case EventBuilder::EVBApp::Operation::ConvertSlow :
{ {
fBuilder.Convert2SortedRoot(); fBuilder.Convert2SortedRoot();
break; break;
} }
case EVBApp::Operation::ConvertFast : case EventBuilder::EVBApp::Operation::ConvertFast :
{ {
fBuilder.Convert2FastSortedRoot(); fBuilder.Convert2FastSortedRoot();
break; break;
} }
case EVBApp::Operation::ConvertSlowA : case EventBuilder::EVBApp::Operation::ConvertSlowA :
{ {
fBuilder.Convert2SlowAnalyzedRoot(); fBuilder.Convert2SlowAnalyzedRoot();
break; break;
} }
case EVBApp::Operation::ConvertFastA : case EventBuilder::EVBApp::Operation::ConvertFastA :
{ {
fBuilder.Convert2FastAnalyzedRoot(); fBuilder.Convert2FastAnalyzedRoot();
break; break;

View File

@ -94,7 +94,7 @@ private:
TGPopupMenu *fFileMenu; TGPopupMenu *fFileMenu;
EVBApp fBuilder; EventBuilder::EVBApp fBuilder;
int counter; int counter;
UInt_t MAIN_W, MAIN_H; UInt_t MAIN_W, MAIN_H;

View File

@ -1,7 +1,7 @@
#include "EventBuilder.h" #include "evb/EventBuilder.h"
#include "spsdict/DataStructs.h" #include "spsdict/DataStructs.h"
#include "EVBApp.h" #include "evb/EVBApp.h"
#include "Stopwatch.h" #include "evb/Stopwatch.h"
int main(int argc, char** argv) 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) Plot (generate a default histogram file from analyzed data)
*/ */
EVBApp theBuilder; EventBuilder::EVBApp theBuilder;
theBuilder.ReadConfigFile(filename); theBuilder.ReadConfigFile(filename);
Stopwatch timer; EventBuilder::Stopwatch timer;
timer.Start(); timer.Start();
if(operation == "Convert") if(operation == "Convert")
theBuilder.Convert2RawRoot(); theBuilder.Convert2RawRoot();