Code review, with a focus on enforcing style and purging extraneous code. Changed name of GWMEventBuilder to EVBApp to better reflect class intent.

This commit is contained in:
Gordon McCann 2021-12-13 12:28:56 -05:00
parent 7c28e252cb
commit afcdd3bb8c
32 changed files with 1536 additions and 1258 deletions

View File

@ -9,35 +9,38 @@
#ifndef CHANNELMAP_H #ifndef CHANNELMAP_H
#define CHANNELMAP_H #define CHANNELMAP_H
struct Channel { struct Channel
{
int detectorType; //What kind of detector we're looking at int detectorType; //What kind of detector we're looking at
int detectorID; //Which specific detector we're looking at int detectorID; //Which specific detector we're looking at
int detectorPart; //Which specific part we're looking at int detectorPart; //Which specific part we're looking at
}; };
//Detector part/type identifiers for use in the code //Detector part/type identifiers for use in the code
enum DetAttribute { enum class DetAttribute
FOCALPLANE, {
SCINTLEFT, FocalPlane,
SCINTRIGHT, ScintLeft,
ANODEFRONT, ScintRight,
ANODEBACK, AnodeFront,
DELAYFR, AnodeBack,
DELAYFL, DelayFR,
DELAYBR, DelayFL,
DELAYBL, DelayBR,
CATHODE, DelayBL,
MONITOR, Cathode,
SABRERING = 88, //These are offset to avoid interference at the variable mapping phase Monitor,
SABREWEDGE = 99 //Just don't add any new attributes with values greater than 88 SabreRing = 88, //These are offset to avoid interference at the variable mapping phase
SabreWedge = 99 //Just don't add any new attributes with values greater than 88
}; };
class ChannelMap { class ChannelMap
{
public: public:
typedef std::unordered_map<int, Channel> Containter; typedef std::unordered_map<DetAttribute, Channel> Containter;
typedef std::unordered_map<int, Channel>::iterator Iterator; typedef std::unordered_map<DetAttribute, Channel>::iterator Iterator;
ChannelMap(); ChannelMap();
ChannelMap(const std::string& filename); ChannelMap(const std::string& filename);

View File

@ -15,7 +15,9 @@
#include "ShiftMap.h" #include "ShiftMap.h"
#include <memory> #include <memory>
class CompassFile { class CompassFile
{
public: public:
CompassFile(); CompassFile();
CompassFile(const std::string& filename); CompassFile(const std::string& filename);
@ -23,17 +25,18 @@ public:
~CompassFile(); ~CompassFile();
void Open(const std::string& filename); void Open(const std::string& filename);
void Close(); void Close();
inline bool IsOpen() { return m_file->is_open(); };
bool GetNextHit(); bool GetNextHit();
inline CompassHit GetCurrentHit() const { return m_currentHit; };
inline std::string GetName() { return m_filename; }; inline bool IsOpen() const { return m_file->is_open(); };
inline bool CheckHitHasBeenUsed() { return hitUsedFlag; }; //query to find out if we've used the current hit inline CompassHit GetCurrentHit() const { return m_currentHit; }
inline void SetHitHasBeenUsed() { hitUsedFlag = true; }; //flip the flag to indicate the current hit has been used inline std::string GetName() const { return m_filename; }
inline bool IsEOF() { return eofFlag; }; //see if we've read all available data inline bool CheckHitHasBeenUsed() const { return hitUsedFlag; } //query to find out if we've used the current hit
inline bool* GetUsedFlagPtr() { return &hitUsedFlag; }; inline void SetHitHasBeenUsed() { hitUsedFlag = true; } //flip the flag to indicate the current hit has been used
inline void AttachShiftMap(ShiftMap* map) { m_smap = map; }; inline bool IsEOF() const { return eofFlag; } //see if we've read all available data
inline unsigned int GetSize() { return m_size; }; inline bool* GetUsedFlagPtr() { return &hitUsedFlag; }
inline unsigned int GetNumberOfHits() { return m_nHits; }; 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:
@ -50,10 +53,12 @@ private:
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;

View File

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

View File

@ -18,15 +18,17 @@
#include <TGProgressBar.h> #include <TGProgressBar.h>
#include <TSystem.h> #include <TSystem.h>
class CompassRun { class CompassRun
{
public: public:
CompassRun(); CompassRun();
CompassRun(const std::string& dir); CompassRun(const std::string& dir);
~CompassRun(); ~CompassRun();
inline void SetDirectory(const std::string& dir) { directory = dir; }; inline void SetDirectory(const std::string& dir) { directory = dir; }
inline void SetScalerInput(const std::string& filename) { m_scalerinput = filename; }; inline void SetScalerInput(const std::string& filename) { m_scalerinput = filename; }
inline void SetRunNumber(int n) { runNum = n; }; inline void SetRunNumber(int n) { runNum = n; }
inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); }; inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); }
void Convert2RawRoot(const std::string& name); void Convert2RawRoot(const std::string& name);
void Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window); void Convert2SortedRoot(const std::string& name, 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 Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window);
@ -35,7 +37,7 @@ public:
void Convert2FastAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window, 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); 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; }; inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; }
private: private:
bool GetBinaryFiles(); bool GetBinaryFiles();

View File

@ -9,9 +9,9 @@ public:
CutHandler(const std::string& filename); CutHandler(const std::string& filename);
~CutHandler(); ~CutHandler();
void SetCuts(const std::string& filename); void SetCuts(const std::string& filename);
bool IsValid() { return validFlag; }; bool IsValid() { return validFlag; }
bool IsInside(ProcessedEvent* eaddress); bool IsInside(ProcessedEvent* eaddress);
std::vector<TCutG*> GetCuts() { return cut_array; }; std::vector<TCutG*> GetCuts() { return cut_array; }
private: private:
void InitVariableMap(); void InitVariableMap();

View File

@ -6,61 +6,66 @@
#ifndef DATA_STRUCTS_H #ifndef DATA_STRUCTS_H
#define DATA_STRUCTS_H #define DATA_STRUCTS_H
using namespace std;
struct DPPChannel { struct DPPChannel
Double_t Timestamp; {
Int_t Channel, Board, Energy, EnergyShort; double Timestamp;
Int_t Flags; int Channel, Board, Energy, EnergyShort;
int Flags;
}; };
struct DetectorHit { struct DetectorHit
Double_t Long=-1, Short=-1, Time=-1; {
Int_t Ch=-1; double Long=-1, Short=-1, Time=-1;
int Ch=-1;
}; };
struct SabreDetector { struct SabreDetector
vector<DetectorHit> rings; {
vector<DetectorHit> wedges; std::vector<DetectorHit> rings;
std::vector<DetectorHit> wedges;
}; };
struct FPDetector { struct FPDetector
vector<DetectorHit> delayFL, delayFR, delayBL, delayBR; {
vector<DetectorHit> anodeF, anodeB, scintL, scintR, cathode; std::vector<DetectorHit> delayFL, delayFR, delayBL, delayBR;
vector<DetectorHit> monitor; std::vector<DetectorHit> anodeF, anodeB, scintL, scintR, cathode;
std::vector<DetectorHit> monitor;
}; };
struct CoincEvent { struct CoincEvent
{
FPDetector focalPlane; FPDetector focalPlane;
SabreDetector sabreArray[5]; //index = ChannelMap Id# -1 SabreDetector sabreArray[5]; //index = ChannelMap Id# -1
}; };
struct ProcessedEvent { struct ProcessedEvent
Double_t fp1_tdiff = -1e6, fp2_tdiff = -1e6, fp1_tsum = -1, fp2_tsum = -1, {
double fp1_tdiff = -1e6, fp2_tdiff = -1e6, fp1_tsum = -1, fp2_tsum = -1,
fp1_tcheck = -1, fp2_tcheck = -1; fp1_tcheck = -1, fp2_tcheck = -1;
Double_t fp1_y=-1, fp2_y=-1; double fp1_y=-1, fp2_y=-1;
Double_t anodeFront = -1, anodeBack = -1, scintRight = -1, scintLeft = -1; double anodeFront = -1, anodeBack = -1, scintRight = -1, scintLeft = -1;
Double_t scintRightShort = -1, scintLeftShort = -1; double scintRightShort = -1, scintLeftShort = -1;
Double_t cathode = -1; double cathode = -1;
Double_t xavg = -1e6, x1 = -1e6, x2 = -1e6; double xavg = -1e6, x1 = -1e6, x2 = -1e6;
Double_t theta = -1e6; double theta = -1e6;
Double_t sabreRingE[5] = {-1,-1,-1,-1,-1}, sabreWedgeE[5] = {-1,-1,-1,-1,-1}; double sabreRingE[5] = {-1,-1,-1,-1,-1}, sabreWedgeE[5] = {-1,-1,-1,-1,-1};
Double_t sabreRingChannel[5] = {-1,-1,-1,-1,-1}, sabreWedgeChannel[5] = {-1,-1,-1,-1,-1}; double sabreRingChannel[5] = {-1,-1,-1,-1,-1}, sabreWedgeChannel[5] = {-1,-1,-1,-1,-1};
Double_t sabreRingTime[5] = {-1,-1,-1,-1,-1}, sabreWedgeTime[5] = {-1,-1,-1,-1,-1}; double sabreRingTime[5] = {-1,-1,-1,-1,-1}, sabreWedgeTime[5] = {-1,-1,-1,-1,-1};
Double_t delayFrontRightE = -1, delayFrontLeftE = -1; double delayFrontRightE = -1, delayFrontLeftE = -1;
Double_t delayBackRightE = -1, delayBackLeftE = -1; double delayBackRightE = -1, delayBackLeftE = -1;
Double_t delayFrontRightShort = -1, delayFrontLeftShort = -1; double delayFrontRightShort = -1, delayFrontLeftShort = -1;
Double_t delayBackRightShort = -1, delayBackLeftShort = -1; double delayBackRightShort = -1, delayBackLeftShort = -1;
Double_t anodeFrontTime = -1, anodeBackTime = -1; double anodeFrontTime = -1, anodeBackTime = -1;
Double_t scintRightTime = -1, scintLeftTime = -1; double scintRightTime = -1, scintLeftTime = -1;
Double_t delayFrontMaxTime = -1, delayBackMaxTime = -1; double delayFrontMaxTime = -1, delayBackMaxTime = -1;
Double_t delayFrontLeftTime = -1, delayFrontRightTime = -1; double delayFrontLeftTime = -1, delayFrontRightTime = -1;
Double_t delayBackLeftTime = -1, delayBackRightTime = -1; double delayBackLeftTime = -1, delayBackRightTime = -1;
Double_t cathodeTime = -1; double cathodeTime = -1;
Double_t monitorE = -1, monitorShort = -1; double monitorE = -1, monitorShort = -1;
Double_t monitorTime = -1; double monitorTime = -1;
SabreDetector sabreArray[5]; //index = ChannelMap Id# -1 SabreDetector sabreArray[5]; //index = ChannelMap Id# -1

View File

@ -1,21 +1,21 @@
/* /*
GWMEventBuilder.h EVBApp.h
Class which represents the API of the event building environment. Wraps together the core concepts Class which represents the API of the event building environment. Wraps together the core concepts
of the event builder, from conversion to plotting. Even intended to be able to archive data. of the event builder, from conversion to plotting. Even intended to be able to archive data.
Currently under development. Currently under development.
Written by G.W. McCann Oct. 2020 Written by G.W. McCann Oct. 2020
*/ */
#ifndef GWMEVENTBUILDER_H #ifndef EVBAPP_H
#define GWMEVENTBUILDER_H #define EVBAPP_H
#include "RunCollector.h" #include "RunCollector.h"
#include <TGProgressBar.h> #include <TGProgressBar.h>
class GWMEventBuilder { class EVBApp {
public: public:
GWMEventBuilder(); EVBApp();
~GWMEventBuilder(); ~EVBApp();
bool ReadConfigFile(const std::string& filename); bool ReadConfigFile(const std::string& filename);
void WriteConfigFile(const std::string& filename); void WriteConfigFile(const std::string& filename);
@ -28,9 +28,6 @@ public:
void Convert2SlowAnalyzedRoot(); void Convert2SlowAnalyzedRoot();
void Convert2FastAnalyzedRoot(); void Convert2FastAnalyzedRoot();
inline void SetAnalysisType(int type) { m_analysisType = type;};
inline int GetAnalysisType() { return m_analysisType; };
inline void SetRunRange(int rmin, int rmax) { m_rmin = rmin; m_rmax = rmax; }; inline void SetRunRange(int rmin, int rmax) { m_rmin = rmin; m_rmax = rmax; };
inline void SetWorkDirectory(const std::string& fullpath) { m_workspace = fullpath; }; inline void SetWorkDirectory(const std::string& fullpath) { m_workspace = fullpath; };
inline void SetChannelMap(const std::string& name) { m_mapfile = name; }; inline void SetChannelMap(const std::string& name) { m_mapfile = name; };
@ -42,38 +39,39 @@ public:
inline void SetScalerFile(const std::string& fullpath) { m_scalerfile = fullpath; }; 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); bool SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke);
inline int GetRunMin() {return m_rmin;}; inline int GetRunMin() const {return m_rmin;}
inline int GetRunMax() {return m_rmax;}; inline int GetRunMax() const {return m_rmax;}
inline std::string GetWorkDirectory() {return m_workspace;}; inline std::string GetWorkDirectory() const {return m_workspace;}
inline int GetTargetZ() {return m_ZT;}; inline int GetTargetZ() const {return m_ZT;}
inline int GetTargetA() {return m_AT;}; inline int GetTargetA() const {return m_AT;}
inline int GetProjectileZ() {return m_ZP;}; inline int GetProjectileZ() const {return m_ZP;}
inline int GetProjectileA() {return m_AP;}; inline int GetProjectileA() const {return m_AP;}
inline int GetEjectileZ() {return m_ZE;}; inline int GetEjectileZ() const {return m_ZE;}
inline int GetEjectileA() {return m_AE;}; inline int GetEjectileA() const {return m_AE;}
inline int GetResidualZ() {return m_ZR;}; inline int GetResidualZ() const {return m_ZR;}
inline int GetResidualA() {return m_AR;}; inline int GetResidualA() const {return m_AR;}
inline double GetBField() {return m_B;}; inline double GetBField() const {return m_B;}
inline double GetBeamKE() {return m_BKE;}; inline double GetBeamKE() const {return m_BKE;}
inline double GetTheta() {return m_Theta;}; inline double GetTheta() const {return m_Theta;}
inline double GetSlowCoincidenceWindow() { return m_SlowWindow; }; inline double GetSlowCoincidenceWindow() const { return m_SlowWindow; }
inline double GetFastWindowIonChamber() { return m_FastWindowIonCh; }; inline double GetFastWindowIonChamber() const { return m_FastWindowIonCh; }
inline double GetFastWindowSABRE() { return m_FastWindowSABRE; }; inline double GetFastWindowSABRE() const { return m_FastWindowSABRE; }
inline std::string GetChannelMap() { return m_mapfile; }; inline std::string GetChannelMap() const { return m_mapfile; }
inline std::string GetBoardShiftFile() { return m_shiftfile; }; inline std::string GetBoardShiftFile() const { return m_shiftfile; }
inline std::string GetCutList() { return m_cutList; }; inline std::string GetCutList() const { return m_cutList; }
inline std::string GetScalerFile() { return m_scalerfile; }; inline std::string GetScalerFile() const { return m_scalerfile; }
inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; }; inline void AttachProgressBar(TGProgressBar* pb) { m_pb = pb; }
enum BuildType { enum Operation
CONVERT, {
CONVERT_S, Convert,
CONVERT_SA, ConvertSlow,
CONVERT_F, ConvertSlowA,
CONVERT_FA, ConvertFast,
MERGE, ConvertFastA,
PLOT Merge,
Plot
}; };
private: private:
@ -91,8 +89,6 @@ private:
double m_FastWindowIonCh; double m_FastWindowIonCh;
double m_FastWindowSABRE; double m_FastWindowSABRE;
int m_analysisType;
RunCollector grabber; RunCollector grabber;
TGProgressBar* m_pb; TGProgressBar* m_pb;

View File

@ -9,14 +9,15 @@
#include "DataStructs.h" #include "DataStructs.h"
#include <TH2.h> #include <TH2.h>
class FastSort { class FastSort
{
public: public:
FastSort(float si_windowSize, float ion_windowSize); FastSort(float si_windowSize, float ion_windowSize);
~FastSort(); ~FastSort();
std::vector<CoincEvent> GetFastEvents(CoincEvent& event); std::vector<CoincEvent> GetFastEvents(CoincEvent& event);
private: private:
void ResetSABRE(); void ResetSABRE();
void ResetFocalPlane(); void ResetFocalPlane();
void ProcessSABRE(unsigned int scint_index); void ProcessSABRE(unsigned int scint_index);

View File

@ -3,7 +3,8 @@
#include <map> #include <map>
struct FlagCount { struct FlagCount
{
long total_counts=0; long total_counts=0;
long dead_time=0; long dead_time=0;
long time_roll=0; long time_roll=0;
@ -24,30 +25,31 @@ struct FlagCount {
long adc_shutdown=0; long adc_shutdown=0;
}; };
class FlagHandler { class FlagHandler
{
public: public:
FlagHandler(); FlagHandler();
FlagHandler(const std::string& filename); FlagHandler(const std::string& filename);
~FlagHandler(); ~FlagHandler();
void CheckFlag(int board, int channel, int flag); void CheckFlag(int board, int channel, int flag);
const int DEAD_TIME = 0x00000001; const int DeadTime = 0x00000001;
const int TIME_ROLLOVER = 0x00000002; const int TimeRollover = 0x00000002;
const int TIME_RESET = 0x00000004; const int TimeReset = 0x00000004;
const int FAKE_EVENT = 0x00000008; const int FakeEvent = 0x00000008;
const int MEM_FULL = 0x00000010; const int MemFull = 0x00000010;
const int TRIG_LOST = 0x00000020; const int TrigLost = 0x00000020;
const int N_TRIG_LOST = 0x00000040; const int NTrigLost = 0x00000040;
const int SATURATING_IN_GATE = 0x00000080; const int SaturatingInGate = 0x00000080;
const int TRIG_1024_COUNTED = 0x00000100; const int Trig1024Counted = 0x00000100;
const int SATURATING_INPUT = 0x00000400; const int SaturatingInput = 0x00000400;
const int N_TRIG_COUNTED = 0x00000800; const int NTrigCounted = 0x00000800;
const int EVENT_NOT_MATCHED = 0x00001000; const int EventNotMatched = 0x00001000;
const int FINE_TIME = 0x00004000; const int FineTime = 0x00004000;
const int PILE_UP = 0x00008000; const int PileUp = 0x00008000;
const int PLL_LOCK_LOSS = 0x00080000; const int PLLLockLoss = 0x00080000;
const int OVER_TEMP = 0x00100000; const int OverTemp = 0x00100000;
const int ADC_SHUTDOWN = 0x00200000; const int ADCShutdown = 0x00200000;
private: private:
std::ofstream log; std::ofstream log;

View File

@ -11,15 +11,16 @@ 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 { class MassLookup
{
public: public:
MassLookup(); MassLookup();
~MassLookup(); ~MassLookup();
double FindMass(int Z, int A); double FindMass(int Z, int A);
std::string FindSymbol(int Z, int A); std::string FindSymbol(int Z, int A);
private: private:
std::unordered_map<std::string, double> massTable; std::unordered_map<std::string, double> massTable;
std::unordered_map<int, std::string> elementTable; std::unordered_map<int, std::string> elementTable;

View File

@ -8,7 +8,8 @@
#ifndef ORDERCHECKER_H #ifndef ORDERCHECKER_H
#define ORDERCHECKER_H #define ORDERCHECKER_H
class OrderChecker { class OrderChecker
{
public: public:
OrderChecker(); OrderChecker();
~OrderChecker(); ~OrderChecker();

View File

@ -10,41 +10,35 @@
#ifndef RUNCOLLECTOR_H #ifndef RUNCOLLECTOR_H
#define RUNCOLLECTOR_H #define RUNCOLLECTOR_H
#include <TSystemDirectory.h> class RunCollector
#include <TSystemFile.h> {
#include <TCollection.h> public:
#include <TList.h>
#include <cstdlib>
#include <cstdio>
using namespace std;
class RunCollector {
public:
RunCollector(); RunCollector();
RunCollector(const string& dirname, const string& prefix, const string& suffix); RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix);
RunCollector(const string& dirname, const string& prefix, const string& suffix, int min, int max); RunCollector(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
~RunCollector(); ~RunCollector();
void SetSearchParams(const string& dirname, const string& prefix, const string& suffix, int min, int max); void SetSearchParams(const std::string& dirname, const std::string& prefix, const std::string& suffix, int min, int max);
int Merge_hadd(const string& outname); bool Merge_hadd(const std::string& outname);
int Merge_TChain(const string& outname); bool Merge_TChain(const std::string& outname);
int GrabAllFiles(); bool GrabAllFiles();
int GrabFilesInRange(); bool GrabFilesInRange();
std::string GrabFile(int runNum); std::string GrabFile(int runNum);
inline std::string GetSearchDir() {return dir.Data();}; inline std::string GetSearchDir() { return directory; }
inline std::string GetSearchPrefix() {return run.Data();}; inline std::string GetSearchPrefix() { return m_prefix; }
inline std::string GetSearchSuffix() {return end.Data();}; inline std::string GetSearchSuffix() { return m_suffix; }
inline int GetRunMin() {return MinRun;}; inline int GetRunMin() { return m_minRun; }
inline int GetRunMax() {return MaxRun;}; inline int GetRunMax() { return m_maxRun; }
vector<TString> filelist; 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;
private:
bool initFlag;
TString dir;
TString run;
TString end;
Int_t MaxRun, MinRun; //user run limits
const Int_t LITERALMAX = 1000; //class run limit
}; };
#endif #endif

View File

@ -13,32 +13,31 @@
#include "DataStructs.h" #include "DataStructs.h"
#include "FP_kinematics.h" #include "FP_kinematics.h"
using namespace std;
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 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 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_t w1, w2, zfp; double w1, w2, zfp;
THashTable *rootObj; //root storage THashTable *rootObj; //root storage
}; };

View File

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

View File

@ -12,23 +12,24 @@
#ifndef SHIFTMAP_H #ifndef SHIFTMAP_H
#define SHIFTMAP_H #define SHIFTMAP_H
class ShiftMap { class ShiftMap
{
public: public:
ShiftMap(); ShiftMap();
ShiftMap(const std::string& filename); ShiftMap(const std::string& filename);
~ShiftMap(); ~ShiftMap();
void SetFile(const std::string& filename); void SetFile(const std::string& filename);
inline bool IsSet() { return is_set; }; inline bool IsValid() { return m_validFlag; }
inline std::string GetFilename() { return m_filename; }; inline std::string GetFilename() { return m_filename; }
Long64_t GetShift(int gchan); Long64_t GetShift(int gchan);
private: private:
void ParseFile(); void ParseFile();
std::string m_filename; std::string m_filename;
bool is_set; bool m_validFlag;
std::unordered_map<int, Long64_t> m_map; std::unordered_map<int, uint64_t> m_map;
}; };

View File

@ -10,8 +10,8 @@
#include <chrono> #include <chrono>
class Stopwatch { class Stopwatch
{
public: public:
Stopwatch(); Stopwatch();
~Stopwatch(); ~Stopwatch();

View File

@ -22,9 +22,11 @@ ChannelMap::ChannelMap(const std::string& name) :
ChannelMap::~ChannelMap() {} ChannelMap::~ChannelMap() {}
bool ChannelMap::FillMap(const std::string& name) { bool ChannelMap::FillMap(const std::string& name)
{
std::ifstream input(name); std::ifstream input(name);
if(!input.is_open()) { if(!input.is_open())
{
is_valid = false; is_valid = false;
return is_valid; return is_valid;
} }
@ -34,33 +36,39 @@ bool ChannelMap::FillMap(const std::string& name) {
std::getline(input, junk); std::getline(input, junk);
std::getline(input, junk); std::getline(input, junk);
Channel this_chan; Channel this_chan;
while(input>>gchan) { while(input>>gchan)
{
//Set default values //Set default values
this_chan.detectorType = -1; this_chan.detectorType = -1;
this_chan.detectorID = -1; this_chan.detectorID = -1;
this_chan.detectorPart = -1; this_chan.detectorPart = -1;
input>>id>>type>>partname; input>>id>>type>>partname;
if(type == "SABRERING") { if(type == "SABRERING")
this_chan.detectorType = SABRERING; {
this_chan.detectorType = DetAttribute::SabreRing;
this_chan.detectorID = id; this_chan.detectorID = id;
this_chan.detectorPart = std::stoi(partname); this_chan.detectorPart = std::stoi(partname);
} else if(type == "SABREWEDGE") { }
this_chan.detectorType = SABREWEDGE; else if(type == "SABREWEDGE")
{
this_chan.detectorType = DetAttribute::SabreWedge;
this_chan.detectorID = id; this_chan.detectorID = id;
this_chan.detectorPart = std::stoi(partname); this_chan.detectorPart = std::stoi(partname);
} else if (type == "FOCALPLANE") { }
else if (type == "FOCALPLANE")
{
this_chan.detectorType = FOCALPLANE; this_chan.detectorType = FOCALPLANE;
this_chan.detectorID = id; this_chan.detectorID = id;
if(partname == "SCINTRIGHT") this_chan.detectorPart = SCINTRIGHT; if(partname == "SCINTRIGHT") this_chan.detectorPart = DetAttribute::ScintRight;
else if(partname == "SCINTLEFT") this_chan.detectorPart = SCINTLEFT; else if(partname == "SCINTLEFT") this_chan.detectorPart = DetAttribute::ScintLeft;
else if(partname == "DELAYFR") this_chan.detectorPart = DELAYFR; else if(partname == "DELAYFR") this_chan.detectorPart = DetAttribute::DelayFR;
else if(partname == "DELAYFL") this_chan.detectorPart = DELAYFL; else if(partname == "DELAYFL") this_chan.detectorPart = DetAttribute::DelayFL;
else if(partname == "DELAYBR") this_chan.detectorPart = DELAYBR; else if(partname == "DELAYBR") this_chan.detectorPart = DetAttribute::DelayBR;
else if(partname == "DELAYBL") this_chan.detectorPart = DELAYBL; else if(partname == "DELAYBL") this_chan.detectorPart = DetAttribute::DelayBL;
else if(partname == "CATHODE") this_chan.detectorPart = CATHODE; else if(partname == "CATHODE") this_chan.detectorPart = DetAttribute::Cathode;
else if(partname == "ANODEFRONT") this_chan.detectorPart = ANODEFRONT; else if(partname == "ANODEFRONT") this_chan.detectorPart = DetAttribute::AnodeFront;
else if(partname == "ANODEBACK") this_chan.detectorPart = ANODEBACK; else if(partname == "ANODEBACK") this_chan.detectorPart = DetAttribute::AnodeBack;
else if(partname == "MONITOR") this_chan.detectorPart = MONITOR; else if(partname == "MONITOR") this_chan.detectorPart = DetAttribute::Monitor;
} }
cmap[gchan] = this_chan; cmap[gchan] = this_chan;

View File

@ -35,11 +35,13 @@ CompassFile::CompassFile(const std::string& filename, int bsize) :
Open(filename); Open(filename);
} }
CompassFile::~CompassFile() { CompassFile::~CompassFile()
{
Close(); Close();
} }
void CompassFile::Open(const std::string& filename) { void CompassFile::Open(const std::string& filename)
{
eofFlag = false; eofFlag = false;
hitUsedFlag = true; hitUsedFlag = true;
m_filename = filename; m_filename = filename;
@ -48,21 +50,28 @@ void CompassFile::Open(const std::string& filename) {
m_file->seekg(0, std::ios_base::end); m_file->seekg(0, std::ios_base::end);
m_size = m_file->tellg(); m_size = m_file->tellg();
m_nHits = m_size/24; m_nHits = m_size/24;
if(m_size == 0) { if(m_size == 0)
{
eofFlag = true; eofFlag = true;
} else { }
else
{
m_file->seekg(0, std::ios_base::beg); m_file->seekg(0, std::ios_base::beg);
} }
} }
void CompassFile::Close() { void CompassFile::Close()
if(IsOpen()) { {
if(IsOpen())
{
m_file->close(); m_file->close();
} }
} }
int CompassFile::GetHitSize() { int CompassFile::GetHitSize()
if(!IsOpen()) { {
if(!IsOpen())
{
std::cerr<<"Unable to get hit size due to file not being open!"<<std::endl; std::cerr<<"Unable to get hit size due to file not being open!"<<std::endl;
return 0; return 0;
} }
@ -90,14 +99,17 @@ int CompassFile::GetHitSize() {
If the file cannot be opened, signals as though file is EOF If the file cannot be opened, signals as though file is EOF
*/ */
bool CompassFile::GetNextHit() { bool CompassFile::GetNextHit()
{
if(!IsOpen()) return true; if(!IsOpen()) return true;
if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF()) { if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF())
{
GetNextBuffer(); GetNextBuffer();
} }
if(!IsEOF()) { if(!IsEOF())
{
ParseNextHit(); ParseNextHit();
hitUsedFlag = false; hitUsedFlag = false;
} }
@ -112,9 +124,11 @@ bool CompassFile::GetNextHit() {
bit upon pulling the last buffer, but this class waits until that entire 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). last buffer is read to singal EOF (the true end of file).
*/ */
void CompassFile::GetNextBuffer() { void CompassFile::GetNextBuffer()
{
if(m_file->eof()) { if(m_file->eof())
{
eofFlag = true; eofFlag = true;
return; return;
} }
@ -126,24 +140,26 @@ void CompassFile::GetNextBuffer() {
} }
void CompassFile::ParseNextHit() { void CompassFile::ParseNextHit()
{
m_currentHit.board = *((UShort_t*)bufferIter); m_currentHit.board = *((uint16_t*)bufferIter);
bufferIter += 2; bufferIter += 2;
m_currentHit.channel = *((UShort_t*)bufferIter); m_currentHit.channel = *((uint16_t*)bufferIter);
bufferIter += 2; bufferIter += 2;
m_currentHit.timestamp = *((ULong64_t*)bufferIter); m_currentHit.timestamp = *((uint64_t*)bufferIter);
bufferIter += 8; bufferIter += 8;
m_currentHit.lgate = *((UShort_t*)bufferIter); m_currentHit.lgate = *((uint16_t*)bufferIter);
bufferIter += 2; bufferIter += 2;
m_currentHit.sgate = *((UShort_t*)bufferIter); m_currentHit.sgate = *((uint16_t*)bufferIter);
bufferIter += 2; bufferIter += 2;
m_currentHit.flags = *((UInt_t*)bufferIter); m_currentHit.flags = *((uint32_t*)bufferIter);
bufferIter += 4; bufferIter += 4;
m_currentHit.Ns = *((UInt_t*)bufferIter); m_currentHit.Ns = *((uint32_t*)bufferIter);
bufferIter += 4; bufferIter += 4;
if(m_smap != nullptr) { //memory safety if(m_smap != nullptr)
{ //memory safety
int gchan = m_currentHit.channel + m_currentHit.board*16; int gchan = m_currentHit.channel + m_currentHit.board*16;
m_currentHit.timestamp += m_smap->GetShift(gchan); m_currentHit.timestamp += m_smap->GetShift(gchan);
} }

View File

@ -33,9 +33,11 @@ CompassRun::~CompassRun() {}
/*Load em into a map*/ /*Load em into a map*/
void CompassRun::SetScalers() { void CompassRun::SetScalers()
{
std::ifstream input(m_scalerinput); std::ifstream input(m_scalerinput);
if(!input.is_open()) return; if(!input.is_open())
return;
m_scaler_flag = true; m_scaler_flag = true;
std::string junk, filename, varname; std::string junk, filename, varname;
@ -43,7 +45,8 @@ void CompassRun::SetScalers() {
std::getline(input, junk); std::getline(input, junk);
std::getline(input, junk); std::getline(input, junk);
m_scaler_map.clear(); m_scaler_map.clear();
while(input>>filename) { while(input>>filename)
{
input>>varname; input>>varname;
filename = directory+filename+"_run_"+to_string(runNum)+".bin"; filename = directory+filename+"_run_"+to_string(runNum)+".bin";
m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init); m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init);
@ -51,7 +54,8 @@ void CompassRun::SetScalers() {
input.close(); input.close();
} }
bool CompassRun::GetBinaryFiles() { bool CompassRun::GetBinaryFiles()
{
std::string prefix = ""; std::string prefix = "";
std::string suffix = ".bin"; //binaries std::string suffix = ".bin"; //binaries
RunCollector grabber(directory, prefix, suffix); RunCollector grabber(directory, prefix, suffix);
@ -62,26 +66,31 @@ bool CompassRun::GetBinaryFiles() {
bool scalerd; bool scalerd;
m_totalHits = 0; //reset total run size m_totalHits = 0; //reset total run size
for(auto& entry : grabber.filelist) { for(auto& entry : grabber.filelist)
{
//Handle scaler files, if they exist //Handle scaler files, if they exist
if(m_scaler_flag) { if(m_scaler_flag)
{
scalerd = false; scalerd = false;
for(auto& scaler_pair : m_scaler_map) { for(auto& scaler_pair : m_scaler_map)
if(std::string(entry.Data()) == scaler_pair.first) { {
if(std::string(entry.Data()) == scaler_pair.first)
{
ReadScalerData(entry.Data()); ReadScalerData(entry.Data());
scalerd = true; scalerd = true;
break; break;
} }
} }
if(scalerd) continue; if(scalerd)
continue;
} }
m_datafiles.emplace_back(entry.Data()); m_datafiles.emplace_back(entry.Data());
m_datafiles[m_datafiles.size()-1].AttachShiftMap(&m_smap); m_datafiles[m_datafiles.size()-1].AttachShiftMap(&m_smap);
//Any time we have a file that fails to be found, we terminate the whole process //Any time we have a file that fails to be found, we terminate the whole process
if(!m_datafiles[m_datafiles.size() - 1].IsOpen()) { if(!m_datafiles[m_datafiles.size() - 1].IsOpen())
return false; return false;
}
m_totalHits += m_datafiles[m_datafiles.size()-1].GetNumberOfHits(); m_totalHits += m_datafiles[m_datafiles.size()-1].GetNumberOfHits();
} }
@ -92,16 +101,20 @@ bool CompassRun::GetBinaryFiles() {
Pure counting of scalers. Potential upgrade path to something like Pure counting of scalers. Potential upgrade path to something like
average count rate etc. average count rate etc.
*/ */
void CompassRun::ReadScalerData(const std::string& filename) { void CompassRun::ReadScalerData(const std::string& filename)
if(!m_scaler_flag) return; {
if(!m_scaler_flag)
return;
Long64_t count; Long64_t count;
count = 0; count = 0;
CompassFile file(filename); CompassFile file(filename);
auto& this_param = m_scaler_map[file.GetName()]; auto& this_param = m_scaler_map[file.GetName()];
while(true) { while(true)
{
file.GetNextHit(); file.GetNextHit();
if(file.IsEOF()) break; if(file.IsEOF())
break;
count++; count++;
} }
this_param.SetVal(count); this_param.SetVal(count);
@ -116,25 +129,34 @@ void CompassRun::ReadScalerData(const std::string& filename) {
of a rolling start index. Once a file has gone EOF, we no longer need it. If this is the first file in the list, we can just skip of a rolling start index. Once a file has gone EOF, we no longer need it. If this is the first file in the list, we can just skip
that index all together. In this way, the loop can go from N times to N-1 times. that index all together. In this way, the loop can go from N times to N-1 times.
*/ */
bool CompassRun::GetHitsFromFiles() { bool CompassRun::GetHitsFromFiles()
{
std::pair<CompassHit, bool*> earliestHit = make_pair(CompassHit(), nullptr); std::pair<CompassHit, bool*> earliestHit = make_pair(CompassHit(), nullptr);
for(unsigned int i=startIndex; i<m_datafiles.size(); i++) { for(unsigned int i=startIndex; i<m_datafiles.size(); i++)
if(m_datafiles[i].CheckHitHasBeenUsed()) { {
if(m_datafiles[i].CheckHitHasBeenUsed())
{
m_datafiles[i].GetNextHit(); m_datafiles[i].GetNextHit();
} }
if(m_datafiles[i].IsEOF()) { if(m_datafiles[i].IsEOF())
{
if(i == startIndex) startIndex++; if(i == startIndex) startIndex++;
continue; continue;
} else if(i == startIndex) { }
else if(i == startIndex)
{
earliestHit = make_pair(m_datafiles[i].GetCurrentHit(), m_datafiles[i].GetUsedFlagPtr()); earliestHit = make_pair(m_datafiles[i].GetCurrentHit(), m_datafiles[i].GetUsedFlagPtr());
} else if(m_datafiles[i].GetCurrentHit().timestamp < earliestHit.first.timestamp) { }
else if(m_datafiles[i].GetCurrentHit().timestamp < earliestHit.first.timestamp)
{
earliestHit = make_pair(m_datafiles[i].GetCurrentHit(), m_datafiles[i].GetUsedFlagPtr()); earliestHit = make_pair(m_datafiles[i].GetCurrentHit(), m_datafiles[i].GetUsedFlagPtr());
} }
} }
if(earliestHit.second == nullptr) return false; //Make sure that there actually was a hit if(earliestHit.second == nullptr)
return false; //Make sure that there actually was a hit
hit = earliestHit.first; hit = earliestHit.first;
*earliestHit.second = true; *earliestHit.second = true;
return true; return true;
@ -151,96 +173,118 @@ void CompassRun::Convert2RawRoot(const std::string& name) {
outtree->Branch("Timestamp", &hit.timestamp); outtree->Branch("Timestamp", &hit.timestamp);
outtree->Branch("Flags", &hit.flags); outtree->Branch("Flags", &hit.flags);
if(!m_smap.IsSet()) { if(!m_smap.IsSet())
{
std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl; std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl;
std::cerr<<"Shifts will be locked to 0"<<std::endl; std::cerr<<"Shifts will be locked to 0"<<std::endl;
} }
SetScalers(); SetScalers();
if(!GetBinaryFiles()) { if(!GetBinaryFiles())
{
std::cerr<<"Unable to open a file!"<<std::endl; std::cerr<<"Unable to open a file!"<<std::endl;
return; return;
} }
if(m_pb) SetProgressBar(); if(m_pb)
SetProgressBar();
startIndex = 0; //Reset the startIndex startIndex = 0; //Reset the startIndex
unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0;
if(flush == 0) flush = 1; if(flush == 0)
while(true) { flush = 1;
while(true)
{
count++; count++;
if(count == flush) { //Progress Log if(count == flush)
if(m_pb) { { //Progress Log
if(m_pb)
{
m_pb->Increment(count); m_pb->Increment(count);
gSystem->ProcessEvents(); gSystem->ProcessEvents();
count=0; count=0;
} else { }
else
{
count = 0; count = 0;
flush_count++; flush_count++;
std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush; std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush;
} }
} }
if(!GetHitsFromFiles()) break; if(!GetHitsFromFiles())
break;
outtree->Fill(); outtree->Fill();
} }
output->cd(); output->cd();
outtree->Write(outtree->GetName(), TObject::kOverwrite); outtree->Write(outtree->GetName(), TObject::kOverwrite);
for(auto& entry : m_scaler_map) { for(auto& entry : m_scaler_map)
entry.second.Write(); entry.second.Write();
}
output->Close(); output->Close();
} }
void CompassRun::Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window) { void CompassRun::Convert2SortedRoot(const std::string& name, const std::string& mapfile, double window)
{
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SortTree", "SortTree"); TTree* outtree = new TTree("SortTree", "SortTree");
outtree->Branch("event", &event); outtree->Branch("event", &event);
if(!m_smap.IsSet()) { if(!m_smap.IsSet())
{
std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl; std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl;
std::cerr<<"Shifts will be locked to 0"<<std::endl; std::cerr<<"Shifts will be locked to 0"<<std::endl;
} }
SetScalers(); SetScalers();
if(!GetBinaryFiles()) { if(!GetBinaryFiles())
{
std::cerr<<"Unable to open a file!"<<std::endl; std::cerr<<"Unable to open a file!"<<std::endl;
return; return;
} }
if(m_pb) SetProgressBar(); if(m_pb)
SetProgressBar();
startIndex = 0; startIndex = 0;
SlowSort coincidizer(window, mapfile); SlowSort coincidizer(window, mapfile);
bool killFlag = false; bool killFlag = false;
unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0;
if(flush == 0) flush = 1; if(flush == 0)
while(true) { flush = 1;
while(true)
{
count++; count++;
if(count == flush) { if(count == flush)
if(m_pb) { {
if(m_pb)
{
m_pb->Increment(count); m_pb->Increment(count);
gSystem->ProcessEvents(); gSystem->ProcessEvents();
count=0; count=0;
} else { }
else
{
count = 0; count = 0;
flush_count++; flush_count++;
std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush; std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush;
} }
} }
if(!GetHitsFromFiles()) { if(!GetHitsFromFiles())
{
coincidizer.FlushHitsToEvent(); coincidizer.FlushHitsToEvent();
killFlag = true; killFlag = true;
} else {
coincidizer.AddHitToEvent(hit);
} }
else
coincidizer.AddHitToEvent(hit);
if(coincidizer.IsEventReady()) { if(coincidizer.IsEventReady())
{
event = coincidizer.GetEvent(); event = coincidizer.GetEvent();
outtree->Fill(); outtree->Fill();
if(killFlag) break; if(killFlag) break;
@ -249,32 +293,36 @@ void CompassRun::Convert2SortedRoot(const std::string& name, const std::string&
output->cd(); output->cd();
outtree->Write(outtree->GetName(), TObject::kOverwrite); outtree->Write(outtree->GetName(), TObject::kOverwrite);
for(auto& entry : m_scaler_map) { for(auto& entry : m_scaler_map)
entry.second.Write(); entry.second.Write();
}
coincidizer.GetEventStats()->Write(); coincidizer.GetEventStats()->Write();
output->Close(); output->Close();
} }
void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window) { void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window)
{
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SortTree", "SortTree"); TTree* outtree = new TTree("SortTree", "SortTree");
outtree->Branch("event", &event); outtree->Branch("event", &event);
if(!m_smap.IsSet()) { if(!m_smap.IsSet())
{
std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl; std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl;
std::cerr<<"Shifts will be locked to 0"<<std::endl; std::cerr<<"Shifts will be locked to 0"<<std::endl;
} }
SetScalers(); SetScalers();
if(!GetBinaryFiles()) { if(!GetBinaryFiles())
{
std::cerr<<"Unable to open a file!"<<std::endl; std::cerr<<"Unable to open a file!"<<std::endl;
return; return;
} }
if(m_pb) SetProgressBar(); if(m_pb)
SetProgressBar();
startIndex = 0; startIndex = 0;
CoincEvent this_event; CoincEvent this_event;
@ -286,72 +334,88 @@ void CompassRun::Convert2FastSortedRoot(const std::string& name, const std::stri
bool killFlag = false; bool killFlag = false;
unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0;
if(flush == 0) flush = 1; if(flush == 0)
while(true) { flush = 1;
while(true)
{
count++; count++;
if(count == flush) { if(count == flush)
if(m_pb) { {
if(m_pb)
{
m_pb->Increment(count); m_pb->Increment(count);
gSystem->ProcessEvents(); gSystem->ProcessEvents();
count=0; count=0;
} else { }
else
{
count = 0; count = 0;
flush_count++; flush_count++;
std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush; std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush;
} }
} }
if(!GetHitsFromFiles()) { if(!GetHitsFromFiles())
{
coincidizer.FlushHitsToEvent(); coincidizer.FlushHitsToEvent();
killFlag = true; killFlag = true;
} else { }
else
{
flagger.CheckFlag(hit.board, hit.channel, hit.flags); flagger.CheckFlag(hit.board, hit.channel, hit.flags);
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(hit);
} }
if(coincidizer.IsEventReady()) { if(coincidizer.IsEventReady())
{
this_event = coincidizer.GetEvent(); this_event = coincidizer.GetEvent();
fast_events = speedyCoincidizer.GetFastEvents(this_event); fast_events = speedyCoincidizer.GetFastEvents(this_event);
for(auto& entry : fast_events) { for(auto& entry : fast_events)
{
event = entry; event = entry;
outtree->Fill(); outtree->Fill();
} }
if(killFlag) break; if(killFlag)
break;
} }
} }
output->cd(); output->cd();
outtree->Write(outtree->GetName(), TObject::kOverwrite); outtree->Write(outtree->GetName(), TObject::kOverwrite);
for(auto& entry : m_scaler_map) { for(auto& entry : m_scaler_map)
entry.second.Write(); entry.second.Write();
}
coincidizer.GetEventStats()->Write(); coincidizer.GetEventStats()->Write();
output->Close(); output->Close();
} }
void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::string& mapfile, double window,
int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta) { int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta)
{
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SPSTree", "SPSTree"); TTree* outtree = new TTree("SPSTree", "SPSTree");
outtree->Branch("event", &pevent); outtree->Branch("event", &pevent);
if(!m_smap.IsSet()) { if(!m_smap.IsSet())
{
std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl; std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl;
std::cerr<<"Shifts will be locked to 0"<<std::endl; std::cerr<<"Shifts will be locked to 0"<<std::endl;
} }
SetScalers(); SetScalers();
if(!GetBinaryFiles()) { if(!GetBinaryFiles())
{
std::cerr<<"Unable to open a file!"<<std::endl; std::cerr<<"Unable to open a file!"<<std::endl;
return; return;
} }
if(m_pb) SetProgressBar(); if(m_pb)
SetProgressBar();
startIndex = 0; startIndex = 0;
CoincEvent this_event; CoincEvent this_event;
@ -372,44 +436,55 @@ void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::st
bool killFlag = false; bool killFlag = false;
unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0;
if(flush == 0) flush = 1; if(flush == 0)
while(true) { flush = 1;
while(true)
{
count++; count++;
if(count == flush) { if(count == flush)
if(m_pb) { {
if(m_pb)
{
m_pb->Increment(count); m_pb->Increment(count);
gSystem->ProcessEvents(); gSystem->ProcessEvents();
count=0; count=0;
} else { }
else
{
count = 0; count = 0;
flush_count++; flush_count++;
std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush; std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush;
} }
} }
if(!GetHitsFromFiles()) { if(!GetHitsFromFiles())
{
coincidizer.FlushHitsToEvent(); coincidizer.FlushHitsToEvent();
killFlag = true; killFlag = true;
} else { }
else
{
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(hit);
} }
if(coincidizer.IsEventReady()) { if(coincidizer.IsEventReady())
{
this_event = coincidizer.GetEvent(); this_event = coincidizer.GetEvent();
pevent = analyzer.GetProcessedEvent(this_event); pevent = analyzer.GetProcessedEvent(this_event);
outtree->Fill(); outtree->Fill();
if(killFlag) break; if(killFlag)
break;
} }
} }
output->cd(); output->cd();
outtree->Write(outtree->GetName(), TObject::kOverwrite); outtree->Write(outtree->GetName(), TObject::kOverwrite);
for(auto& entry : m_scaler_map) { for(auto& entry : m_scaler_map)
entry.second.Write(); entry.second.Write();
}
for(auto& entry : parvec) { for(auto& entry : parvec)
entry.Write(); entry.Write();
}
coincidizer.GetEventStats()->Write(); coincidizer.GetEventStats()->Write();
analyzer.GetHashTable()->Write(); analyzer.GetHashTable()->Write();
analyzer.ClearHashTable(); analyzer.ClearHashTable();
@ -417,26 +492,30 @@ void CompassRun::Convert2SlowAnalyzedRoot(const std::string& name, const std::st
} }
void CompassRun::Convert2FastAnalyzedRoot(const std::string& name, const std::string& mapfile, double window, double fsi_window, double fic_window, void CompassRun::Convert2FastAnalyzedRoot(const std::string& name, 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) { int zt, int at, int zp, int ap, int ze, int ae, double bke, double b, double theta)
{
TFile* output = TFile::Open(name.c_str(), "RECREATE"); TFile* output = TFile::Open(name.c_str(), "RECREATE");
TTree* outtree = new TTree("SPSTree", "SPSTree"); TTree* outtree = new TTree("SPSTree", "SPSTree");
outtree->Branch("event", &pevent); outtree->Branch("event", &pevent);
if(!m_smap.IsSet()) { if(!m_smap.IsSet())
{
std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl; std::cerr<<"Bad shift map at CompassRun::Convert()."<<std::endl;
std::cerr<<"Shifts will be locked to 0"<<std::endl; std::cerr<<"Shifts will be locked to 0"<<std::endl;
} }
SetScalers(); SetScalers();
if(!GetBinaryFiles()) { if(!GetBinaryFiles())
{
std::cerr<<"Unable to open a file!"<<std::endl; std::cerr<<"Unable to open a file!"<<std::endl;
return; return;
} }
if(m_pb) SetProgressBar(); if(m_pb)
SetProgressBar();
startIndex = 0; startIndex = 0;
CoincEvent this_event; CoincEvent this_event;
@ -461,56 +540,69 @@ void CompassRun::Convert2FastAnalyzedRoot(const std::string& name, const std::st
bool killFlag = false; bool killFlag = false;
unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0; unsigned int count = 0, flush = m_totalHits*0.01, flush_count = 0;
if(flush == 0) flush = 1; if(flush == 0)
while(true) { flush = 1;
while(true)
{
count++; count++;
if(count == flush) { if(count == flush)
if(m_pb) { {
if(m_pb)
{
m_pb->Increment(count); m_pb->Increment(count);
gSystem->ProcessEvents(); gSystem->ProcessEvents();
count=0; count=0;
} else { }
else
{
count = 0; count = 0;
flush_count++; flush_count++;
std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush; std::cout<<"\rPercent of run built: "<<flush_count*10<<"%"<<std::flush;
} }
} }
if(!GetHitsFromFiles()) { if(!GetHitsFromFiles())
{
coincidizer.FlushHitsToEvent(); coincidizer.FlushHitsToEvent();
killFlag = true; killFlag = true;
} else { }
else
{
flagger.CheckFlag(hit.board, hit.channel, hit.flags); flagger.CheckFlag(hit.board, hit.channel, hit.flags);
coincidizer.AddHitToEvent(hit); coincidizer.AddHitToEvent(hit);
} }
if(coincidizer.IsEventReady()) { if(coincidizer.IsEventReady())
{
this_event = coincidizer.GetEvent(); this_event = coincidizer.GetEvent();
fast_events = speedyCoincidizer.GetFastEvents(this_event); fast_events = speedyCoincidizer.GetFastEvents(this_event);
for(auto& entry : fast_events) { for(auto& entry : fast_events)
{
pevent = analyzer.GetProcessedEvent(entry); pevent = analyzer.GetProcessedEvent(entry);
outtree->Fill(); outtree->Fill();
} }
if(killFlag) break; if(killFlag)
break;
} }
} }
output->cd(); output->cd();
outtree->Write(outtree->GetName(), TObject::kOverwrite); outtree->Write(outtree->GetName(), TObject::kOverwrite);
for(auto& entry : m_scaler_map) { for(auto& entry : m_scaler_map)
entry.second.Write(); entry.second.Write();
}
for(auto& entry : parvec) { for(auto& entry : parvec)
entry.Write(); entry.Write();
}
coincidizer.GetEventStats()->Write(); coincidizer.GetEventStats()->Write();
analyzer.GetHashTable()->Write(); analyzer.GetHashTable()->Write();
analyzer.ClearHashTable(); analyzer.ClearHashTable();
output->Close(); output->Close();
} }
void CompassRun::SetProgressBar() { void CompassRun::SetProgressBar()
{
m_pb->SetMax(m_totalHits); m_pb->SetMax(m_totalHits);
m_pb->SetMin(0); m_pb->SetMin(0);
m_pb->SetPosition(0); m_pb->SetPosition(0);

View File

@ -14,16 +14,19 @@ CutHandler::CutHandler(const std::string& filename) :
InitVariableMap(); InitVariableMap();
} }
CutHandler::~CutHandler() { CutHandler::~CutHandler()
for(unsigned int i=0; i<file_array.size(); i++) { {
if(file_array[i]->IsOpen()) file_array[i]->Close(); 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) { void CutHandler::SetCuts(const std::string& filename)
{
std::ifstream cutlist(filename); std::ifstream cutlist(filename);
if(!cutlist.is_open()) { if(!cutlist.is_open())
{
validFlag = false; validFlag = false;
} }
@ -33,17 +36,21 @@ void CutHandler::SetCuts(const std::string& filename) {
cut_array.clear(); cut_array.clear();
file_array.clear(); file_array.clear();
while(cutlist>>name) { while(cutlist>>name)
{
cutlist>>fname>>varx>>vary; cutlist>>fname>>varx>>vary;
TFile* file = TFile::Open(fname.c_str(), "READ"); TFile* file = TFile::Open(fname.c_str(), "READ");
TCutG* cut = (TCutG*) file->Get("CUTG"); TCutG* cut = (TCutG*) file->Get("CUTG");
if(cut) { if(cut)
{
cut->SetVarX(varx.c_str()); cut->SetVarX(varx.c_str());
cut->SetVarY(vary.c_str()); cut->SetVarY(vary.c_str());
cut->SetName(name.c_str()); cut->SetName(name.c_str());
cut_array.push_back(cut); cut_array.push_back(cut);
file_array.push_back(file); file_array.push_back(file);
} else { }
else
{
validFlag = false; validFlag = false;
std::cerr<<"CutHandler has encountered a bad cut at file: "<<file<<"."<<std::endl; 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<<"The file either does not exist or does not contain a TCutG named CUTG"<<std::endl;
@ -52,17 +59,17 @@ void CutHandler::SetCuts(const std::string& filename) {
} }
} }
if(cut_array.size() > 0) { if(cut_array.size() > 0)
validFlag = true; validFlag = true;
} else { else
validFlag = false; validFlag = false;
}
} }
/* /*
ADD MORE VARIABLES HERE! ADD MORE VARIABLES HERE!
*/ */
void CutHandler::InitVariableMap() { void CutHandler::InitVariableMap()
{
varmap["x1"] = &m_event.x1; varmap["x1"] = &m_event.x1;
varmap["x2"] = &m_event.x2; varmap["x2"] = &m_event.x2;
varmap["xavg"] = &m_event.xavg; varmap["xavg"] = &m_event.xavg;
@ -71,23 +78,26 @@ void CutHandler::InitVariableMap() {
varmap["cathode"] = &m_event.cathode; varmap["cathode"] = &m_event.cathode;
} }
bool CutHandler::IsInside(ProcessedEvent* eaddress) { bool CutHandler::IsInside(ProcessedEvent* eaddress)
{
m_event = *eaddress; m_event = *eaddress;
std::string x, y; std::string x, y;
for(unsigned int i=0; i<cut_array.size(); i++) { for(unsigned int i=0; i<cut_array.size(); i++)
{
TCutG* cut = cut_array[i]; TCutG* cut = cut_array[i];
x = cut->GetVarX(); x = cut->GetVarX();
y = cut->GetVarY(); y = cut->GetVarY();
auto xentry = varmap.find(x); auto xentry = varmap.find(x);
auto yentry = varmap.find(y); auto yentry = varmap.find(y);
if(xentry == varmap.end() || yentry == varmap.end()) { if(xentry == varmap.end() || yentry == varmap.end())
{
std::cerr<<"Unmapped variable called in CutHandler::IsInside()! Var names: "<<xentry->first<<" , "<<yentry->first<<std::endl; std::cerr<<"Unmapped variable called in CutHandler::IsInside()! Var names: "<<xentry->first<<" , "<<yentry->first<<std::endl;
return false; return false;
} }
if(!cut->IsInside(*(xentry->second), *(yentry->second))) { if(!cut->IsInside(*(xentry->second), *(yentry->second)))
return false; return false;
}
} }
return true; return true;

View File

@ -1,5 +1,5 @@
/* /*
GWMEventBuilder.cpp EVBApp.cpp
Class which represents the API of the event building environment. Wraps together the core concepts Class which represents the API of the event building environment. Wraps together the core concepts
of the event builder, from conversion to plotting. Even intended to be able to archive data. of the event builder, from conversion to plotting. Even intended to be able to archive data.
Currently under development. Currently under development.
@ -8,7 +8,7 @@
*/ */
#include "EventBuilder.h" #include "EventBuilder.h"
#include <cstdlib> #include <cstdlib>
#include "GWMEventBuilder.h" #include "EVBApp.h"
#include "RunCollector.h" #include "RunCollector.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "SlowSort.h" #include "SlowSort.h"
@ -16,21 +16,23 @@
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
#include "SFPPlotter.h" #include "SFPPlotter.h"
GWMEventBuilder::GWMEventBuilder() : 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_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_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) m_cutList("none"), m_SlowWindow(0), m_FastWindowIonCh(0), m_FastWindowSABRE(0), m_pb(nullptr)
{ {
} }
GWMEventBuilder::~GWMEventBuilder() EVBApp::~EVBApp()
{ {
} }
bool GWMEventBuilder::ReadConfigFile(const std::string& fullpath) { bool EVBApp::ReadConfigFile(const std::string& fullpath)
{
std::cout<<"Reading in configuration from file: "<<fullpath<<std::endl; std::cout<<"Reading in configuration from file: "<<fullpath<<std::endl;
std::ifstream input(fullpath); std::ifstream input(fullpath);
if(!input.is_open()) { if(!input.is_open())
{
std::cout<<"Read failed! Unable to open input file!"<<std::endl; std::cout<<"Read failed! Unable to open input file!"<<std::endl;
return false; return false;
} }
@ -70,11 +72,13 @@ bool GWMEventBuilder::ReadConfigFile(const std::string& fullpath) {
return true; return true;
} }
void GWMEventBuilder::WriteConfigFile(const std::string& fullpath) { void EVBApp::WriteConfigFile(const std::string& fullpath)
{
std::cout<<"Writing out configuration to file: "<<fullpath<<std::endl; std::cout<<"Writing out configuration to file: "<<fullpath<<std::endl;
std::ofstream output(fullpath); std::ofstream output(fullpath);
if(!output.is_open()) { if(!output.is_open())
{
std::cout<<"Write failed! Unable to open output file!"<<std::endl; std::cout<<"Write failed! Unable to open output file!"<<std::endl;
return; return;
} }
@ -113,7 +117,8 @@ void GWMEventBuilder::WriteConfigFile(const std::string& fullpath) {
} }
void GWMEventBuilder::PlotHistograms() { void EVBApp::PlotHistograms()
{
std::string analyze_dir = m_workspace+"/analyzed/"; std::string analyze_dir = m_workspace+"/analyzed/";
std::string plot_file = m_workspace+"/histograms/run_"+to_string(m_rmin)+"_"+to_string(m_rmax)+".root"; std::string plot_file = m_workspace+"/histograms/run_"+to_string(m_rmin)+"_"+to_string(m_rmax)+".root";
SFPPlotter grammer; SFPPlotter grammer;
@ -125,20 +130,25 @@ void GWMEventBuilder::PlotHistograms() {
std::cout<<"Cut List File: "<<m_cutList<<std::endl; std::cout<<"Cut List File: "<<m_cutList<<std::endl;
std::cout<<"Histogram File: "<<plot_file<<std::endl; std::cout<<"Histogram File: "<<plot_file<<std::endl;
if(m_pb) grammer.AttachProgressBar(m_pb); if(m_pb)
grammer.AttachProgressBar(m_pb);
grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax); grabber.SetSearchParams(analyze_dir, "", ".root", m_rmin, m_rmax);
if(grabber.GrabFilesInRange()) { if(grabber.GrabFilesInRange())
{
std::cout<<"Working..."; std::cout<<"Working...";
grammer.Run(grabber.filelist, plot_file); grammer.Run(grabber.filelist, plot_file);
std::cout<<" Complete."<<std::endl; std::cout<<" Complete."<<std::endl;
} else { }
else
{
std::cout<<"Unable to find files at PlotHistograms"<<std::endl; std::cout<<"Unable to find files at PlotHistograms"<<std::endl;
} }
std::cout<<"-------------------------------------------"<<std::endl; std::cout<<"-------------------------------------------"<<std::endl;
} }
void GWMEventBuilder::Convert2RawRoot() { void EVBApp::Convert2RawRoot()
{
std::string rawroot_dir = m_workspace+"/raw_root/"; std::string rawroot_dir = m_workspace+"/raw_root/";
std::string unpack_dir = m_workspace+"/temp_binary/"; std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/"; std::string binary_dir = m_workspace+"/raw_binary/";
@ -160,13 +170,16 @@ void GWMEventBuilder::Convert2RawRoot() {
CompassRun converter(unpack_dir); CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile); converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile); converter.SetScalerInput(m_scalerfile);
if(m_pb) converter.AttachProgressBar(m_pb); if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl; std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++) { for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i); binfile = grabber.GrabFile(i);
if(binfile == "") continue; if(binfile == "")
continue;
converter.SetRunNumber(i); converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl; std::cout<<"Converting file: "<<binfile<<std::endl;
@ -184,7 +197,8 @@ void GWMEventBuilder::Convert2RawRoot() {
} }
void GWMEventBuilder::MergeROOTFiles() { void EVBApp::MergeROOTFiles()
{
std::string merge_file = m_workspace+"/merged/run_"+to_string(m_rmin)+"_"+to_string(m_rmax)+".root"; std::string merge_file = m_workspace+"/merged/run_"+to_string(m_rmin)+"_"+to_string(m_rmax)+".root";
std::string file_dir = m_workspace+"/analyzed/"; std::string file_dir = m_workspace+"/analyzed/";
std::cout<<"-------------GWM Event Builder-------------"<<std::endl; std::cout<<"-------------GWM Event Builder-------------"<<std::endl;
@ -196,7 +210,8 @@ void GWMEventBuilder::MergeROOTFiles() {
std::string suffix = ".root"; std::string suffix = ".root";
grabber.SetSearchParams(file_dir, prefix, suffix,m_rmin,m_rmax); grabber.SetSearchParams(file_dir, prefix, suffix,m_rmin,m_rmax);
std::cout<<"Beginning the merge..."; std::cout<<"Beginning the merge...";
if(!grabber.Merge_TChain(merge_file)) { if(!grabber.Merge_TChain(merge_file))
{
std::cout<<"Unable to find files at MergeROOTFiles"<<std::endl; std::cout<<"Unable to find files at MergeROOTFiles"<<std::endl;
return; return;
} }
@ -204,7 +219,8 @@ void GWMEventBuilder::MergeROOTFiles() {
std::cout<<"-------------------------------------------"<<std::endl; std::cout<<"-------------------------------------------"<<std::endl;
} }
void GWMEventBuilder::Convert2SortedRoot() { void EVBApp::Convert2SortedRoot()
{
std::string sortroot_dir = m_workspace+"/sorted/"; std::string sortroot_dir = m_workspace+"/sorted/";
std::string unpack_dir = m_workspace+"/temp_binary/"; std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/"; std::string binary_dir = m_workspace+"/raw_binary/";
@ -227,13 +243,16 @@ void GWMEventBuilder::Convert2SortedRoot() {
CompassRun converter(unpack_dir); CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile); converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile); converter.SetScalerInput(m_scalerfile);
if(m_pb) converter.AttachProgressBar(m_pb); if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl; std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<= m_rmax; i++) { for(int i=m_rmin; i<= m_rmax; i++)
{
binfile = grabber.GrabFile(i); binfile = grabber.GrabFile(i);
if(binfile == "") continue; if(binfile == "")
continue;
converter.SetRunNumber(i); converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl; std::cout<<"Converting file: "<<binfile<<std::endl;
@ -250,7 +269,7 @@ void GWMEventBuilder::Convert2SortedRoot() {
std::cout<<"-------------------------------------------"<<std::endl; std::cout<<"-------------------------------------------"<<std::endl;
} }
void GWMEventBuilder::Convert2FastSortedRoot() { void EVBApp::Convert2FastSortedRoot() {
std::string sortroot_dir = m_workspace+"/fast/"; std::string sortroot_dir = m_workspace+"/fast/";
std::string unpack_dir = m_workspace+"/temp_binary/"; std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/"; std::string binary_dir = m_workspace+"/raw_binary/";
@ -273,13 +292,16 @@ void GWMEventBuilder::Convert2FastSortedRoot() {
CompassRun converter(unpack_dir); CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile); converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile); converter.SetScalerInput(m_scalerfile);
if(m_pb) converter.AttachProgressBar(m_pb); if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl; std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++) { for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i); binfile = grabber.GrabFile(i);
if(binfile == "") continue; if(binfile == "")
continue;
converter.SetRunNumber(i); converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl; std::cout<<"Converting file: "<<binfile<<std::endl;
@ -296,7 +318,7 @@ void GWMEventBuilder::Convert2FastSortedRoot() {
std::cout<<"-------------------------------------------"<<std::endl; std::cout<<"-------------------------------------------"<<std::endl;
} }
void GWMEventBuilder::Convert2SlowAnalyzedRoot() { void EVBApp::Convert2SlowAnalyzedRoot() {
std::string sortroot_dir = m_workspace+"/analyzed/"; std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/"; std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/"; std::string binary_dir = m_workspace+"/raw_binary/";
@ -318,13 +340,16 @@ void GWMEventBuilder::Convert2SlowAnalyzedRoot() {
CompassRun converter(unpack_dir); CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile); converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile); converter.SetScalerInput(m_scalerfile);
if(m_pb) converter.AttachProgressBar(m_pb); if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl; std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++) { for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i); binfile = grabber.GrabFile(i);
if(binfile == "") continue; if(binfile == "")
continue;
converter.SetRunNumber(i); converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl; std::cout<<"Converting file: "<<binfile<<std::endl;
@ -341,7 +366,8 @@ void GWMEventBuilder::Convert2SlowAnalyzedRoot() {
std::cout<<"-------------------------------------------"<<std::endl; std::cout<<"-------------------------------------------"<<std::endl;
} }
void GWMEventBuilder::Convert2FastAnalyzedRoot() { void EVBApp::Convert2FastAnalyzedRoot()
{
std::string sortroot_dir = m_workspace+"/analyzed/"; std::string sortroot_dir = m_workspace+"/analyzed/";
std::string unpack_dir = m_workspace+"/temp_binary/"; std::string unpack_dir = m_workspace+"/temp_binary/";
std::string binary_dir = m_workspace+"/raw_binary/"; std::string binary_dir = m_workspace+"/raw_binary/";
@ -366,13 +392,16 @@ void GWMEventBuilder::Convert2FastAnalyzedRoot() {
CompassRun converter(unpack_dir); CompassRun converter(unpack_dir);
converter.SetShiftMap(m_shiftfile); converter.SetShiftMap(m_shiftfile);
converter.SetScalerInput(m_scalerfile); converter.SetScalerInput(m_scalerfile);
if(m_pb) converter.AttachProgressBar(m_pb); if(m_pb)
converter.AttachProgressBar(m_pb);
std::cout<<"Beginning conversion..."<<std::endl; std::cout<<"Beginning conversion..."<<std::endl;
for(int i=m_rmin; i<=m_rmax; i++) { for(int i=m_rmin; i<=m_rmax; i++)
{
binfile = grabber.GrabFile(i); binfile = grabber.GrabFile(i);
if(binfile == "") continue; if(binfile == "")
continue;
converter.SetRunNumber(i); converter.SetRunNumber(i);
std::cout<<"Converting file: "<<binfile<<std::endl; std::cout<<"Converting file: "<<binfile<<std::endl;
@ -389,9 +418,11 @@ void GWMEventBuilder::Convert2FastAnalyzedRoot() {
std::cout<<"-------------------------------------------"<<std::endl; std::cout<<"-------------------------------------------"<<std::endl;
} }
bool GWMEventBuilder::SetKinematicParameters(int zt, int at, int zp, int ap, int ze, int ae, double b, double theta, double bke) { 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) { if((at + ap - ae) < 0 || (zt + zp - ze) < 0)
{
std::cout<<"Invalid Parameters at SetKinematicParameters"<<std::endl; std::cout<<"Invalid Parameters at SetKinematicParameters"<<std::endl;
return false; return false;
} }

View File

@ -39,7 +39,8 @@
//requires (Z,A) for T, P, and E, as well as energy of P, //requires (Z,A) for T, P, and E, as well as energy of P,
// spectrograph angle of interest, and field value // spectrograph angle of interest, and field value
double Delta_Z(int ZT, int AT, int ZP, int AP, int ZE, int AE, double Delta_Z(int ZT, int AT, int ZP, int AP, int ZE, int AE,
double EP, double angle, double B) { double EP, double angle, double B)
{
/* CONSTANTS */ /* CONSTANTS */
const double UTOMEV = 931.4940954; //MeV per u; const double UTOMEV = 931.4940954; //MeV per u;
@ -66,7 +67,8 @@ double Delta_Z(int ZT, int AT, int ZP, int AP, int ZE, int AE,
ME = MASS.FindMass(ZE, AE) - ZE*RESTMASS_ELECTRON*UTOMEV; ME = MASS.FindMass(ZE, AE) - ZE*RESTMASS_ELECTRON*UTOMEV;
MR = MASS.FindMass(ZR, AR) - ZR*RESTMASS_ELECTRON*UTOMEV; MR = MASS.FindMass(ZR, AR) - ZR*RESTMASS_ELECTRON*UTOMEV;
if (MT*MP*ME*MR == 0) { if (MT*MP*ME*MR == 0)
{
std::cerr << "***WARNING: error loading one or more masses; returning 0\n"; std::cerr << "***WARNING: error loading one or more masses; returning 0\n";
return 0; return 0;
} }

View File

@ -1,23 +1,25 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "FastSort.h" #include "FastSort.h"
FastSort::FastSort(float si_windowSize, float ion_windowSize) { //windows given in picoseconds, converted to nanoseconds
si_coincWindow = si_windowSize/1.0e3; //given in pico s, want in nano s FastSort::FastSort(float si_windowSize, float ion_windowSize)
ion_coincWindow = ion_windowSize/1.0e3; si_coincWindow(si_windowSize/1.0e3), ion_coincWindow(ion_windowSize/1.0e3), event_address(nullptr)
event_address = NULL; {
} }
FastSort::~FastSort() { FastSort::~FastSort()
{
delete event_address; delete event_address;
} }
void FastSort::ResetSABRE() { void FastSort::ResetSABRE()
for(int i=0; i<5; i++) { {
for(int i=0; i<5; i++)
fastEvent.sabreArray[i] = sblank; fastEvent.sabreArray[i] = sblank;
}
} }
void FastSort::ResetFocalPlane() { void FastSort::ResetFocalPlane()
{
fastEvent.focalPlane = fpblank; fastEvent.focalPlane = fpblank;
} }
@ -28,65 +30,70 @@ void FastSort::ProcessFocalPlane(unsigned int scint_index, unsigned int ionch_in
*In this case, I chose one of the anodes. But in principle you could also choose any other part of the ion *In this case, I chose one of the anodes. But in principle you could also choose any other part of the ion
*chamber *chamber
*/ */
if(slowEvent.focalPlane.anodeB.size() > ionch_index) { //Back anode required to move on` 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); float anodeRelTime = fabs(slowEvent.focalPlane.anodeB[ionch_index].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(anodeRelTime > ion_coincWindow) return; //Window check if(anodeRelTime > ion_coincWindow)
return; //Window check
fastEvent.focalPlane.anodeB.push_back(slowEvent.focalPlane.anodeB[ionch_index]); fastEvent.focalPlane.anodeB.push_back(slowEvent.focalPlane.anodeB[ionch_index]);
fastEvent.focalPlane.scintL.push_back(slowEvent.focalPlane.scintL[scint_index]); fastEvent.focalPlane.scintL.push_back(slowEvent.focalPlane.scintL[scint_index]);
if(slowEvent.focalPlane.delayFL.size() > ionch_index) { if(slowEvent.focalPlane.delayFL.size() > ionch_index)
fastEvent.focalPlane.delayFL.push_back(slowEvent.focalPlane.delayFL[ionch_index]); fastEvent.focalPlane.delayFL.push_back(slowEvent.focalPlane.delayFL[ionch_index]);
}
if(slowEvent.focalPlane.delayFR.size() > ionch_index) { if(slowEvent.focalPlane.delayFR.size() > ionch_index)
fastEvent.focalPlane.delayFR.push_back(slowEvent.focalPlane.delayFR[ionch_index]); fastEvent.focalPlane.delayFR.push_back(slowEvent.focalPlane.delayFR[ionch_index]);
}
if(slowEvent.focalPlane.delayBR.size() > ionch_index) { if(slowEvent.focalPlane.delayBR.size() > ionch_index)
fastEvent.focalPlane.delayBR.push_back(slowEvent.focalPlane.delayBR[ionch_index]); fastEvent.focalPlane.delayBR.push_back(slowEvent.focalPlane.delayBR[ionch_index]);
}
if(slowEvent.focalPlane.delayBL.size() > ionch_index) { if(slowEvent.focalPlane.delayBL.size() > ionch_index)
fastEvent.focalPlane.delayBL.push_back(slowEvent.focalPlane.delayBL[ionch_index]); fastEvent.focalPlane.delayBL.push_back(slowEvent.focalPlane.delayBL[ionch_index]);
}
if(slowEvent.focalPlane.scintR.size() > ionch_index) { if(slowEvent.focalPlane.scintR.size() > ionch_index)
fastEvent.focalPlane.scintR.push_back(slowEvent.focalPlane.scintR[ionch_index]); fastEvent.focalPlane.scintR.push_back(slowEvent.focalPlane.scintR[ionch_index]);
}
if(slowEvent.focalPlane.anodeF.size() > ionch_index) { if(slowEvent.focalPlane.anodeF.size() > ionch_index)
fastEvent.focalPlane.anodeF.push_back(slowEvent.focalPlane.anodeF[ionch_index]); fastEvent.focalPlane.anodeF.push_back(slowEvent.focalPlane.anodeF[ionch_index]);
}
if(slowEvent.focalPlane.cathode.size() > ionch_index) { if(slowEvent.focalPlane.cathode.size() > ionch_index)
fastEvent.focalPlane.cathode.push_back(slowEvent.focalPlane.cathode[ionch_index]); fastEvent.focalPlane.cathode.push_back(slowEvent.focalPlane.cathode[ionch_index]);
} }
}
} }
/*Assign a set of SABRE data that falls within the coincidence window*/ /*Assign a set of SABRE data that falls within the coincidence window*/
void FastSort::ProcessSABRE(unsigned int scint_index) { void FastSort::ProcessSABRE(unsigned int scint_index)
for(int i=0; i<5; i++) { //loop over SABRE silicons {
for(int i=0; i<5; i++)
{ //loop over SABRE silicons
std::vector<DetectorHit> rings; std::vector<DetectorHit> rings;
std::vector<DetectorHit> wedges; std::vector<DetectorHit> wedges;
if(slowEvent.sabreArray[i].rings.size() == 0 || slowEvent.sabreArray[i].wedges.size() == 0) continue; //save some time on empties 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*/ /*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++) { 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); float sabreRelTime = fabs(slowEvent.sabreArray[i].rings[j].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(sabreRelTime < si_coincWindow) { if(sabreRelTime < si_coincWindow)
rings.push_back(slowEvent.sabreArray[i].rings[j]); rings.push_back(slowEvent.sabreArray[i].rings[j]);
} }
} for(unsigned int j=0; j<slowEvent.sabreArray[i].wedges.size(); 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); float sabreRelTime = fabs(slowEvent.sabreArray[i].wedges[j].Time - slowEvent.focalPlane.scintL[scint_index].Time);
if(sabreRelTime < si_coincWindow) { if(sabreRelTime < si_coincWindow)
wedges.push_back(slowEvent.sabreArray[i].wedges[j]); wedges.push_back(slowEvent.sabreArray[i].wedges[j]);
} }
}
fastEvent.sabreArray[i].rings = rings; fastEvent.sabreArray[i].rings = rings;
fastEvent.sabreArray[i].wedges = wedges; fastEvent.sabreArray[i].wedges = wedges;
} }
} }
std::vector<CoincEvent> FastSort::GetFastEvents(CoincEvent& event) { std::vector<CoincEvent> FastSort::GetFastEvents(CoincEvent& event)
{
slowEvent = event; slowEvent = event;
std::vector<CoincEvent> fast_events; std::vector<CoincEvent> fast_events;
@ -100,13 +107,15 @@ std::vector<CoincEvent> FastSort::GetFastEvents(CoincEvent& event) {
sizeArray[6] = slowEvent.focalPlane.cathode.size(); sizeArray[6] = slowEvent.focalPlane.cathode.size();
unsigned int maxSize = *max_element(sizeArray, sizeArray+7); unsigned int maxSize = *max_element(sizeArray, sizeArray+7);
//loop over scints //loop over scints
for(unsigned int i=0; i<slowEvent.focalPlane.scintL.size(); i++) { for(unsigned int i=0; i<slowEvent.focalPlane.scintL.size(); i++)
{
ResetSABRE(); ResetSABRE();
ProcessSABRE(i); ProcessSABRE(i);
//loop over ion chamber //loop over ion chamber
//NOTE: as written, this dumps data that does not have an ion chamber hit! //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 //If you want scint/SABRE singles, move the fill outside of this loop
for(unsigned int j=0; j<maxSize; j++) { for(unsigned int j=0; j<maxSize; j++)
{
ResetFocalPlane(); ResetFocalPlane();
ProcessFocalPlane(i, j); ProcessFocalPlane(i, j);
fast_events.push_back(fastEvent); fast_events.push_back(fastEvent);

View File

@ -2,65 +2,85 @@
#include "FlagHandler.h" #include "FlagHandler.h"
FlagHandler::FlagHandler() : FlagHandler::FlagHandler() :
log("./event_log.txt") log("./event_log.txt")
{ {
} }
FlagHandler::FlagHandler(const std::string& filename) : FlagHandler::FlagHandler(const std::string& filename) :
log(filename) log(filename)
{ {
} }
FlagHandler::~FlagHandler() { FlagHandler::~FlagHandler()
{
WriteLog(); WriteLog();
log.close(); log.close();
} }
void FlagHandler::CheckFlag(int board, int channel, int flag) { void FlagHandler::CheckFlag(int board, int channel, int flag)
{
int gchan = channel + board*16; int gchan = channel + board*16;
FlagCount& counter = event_count_map[gchan]; //yikes FlagCount& counter = event_count_map[gchan]; //yikes
counter.total_counts++; counter.total_counts++;
if(flag & DEAD_TIME) counter.dead_time++; if(flag & DeadTime)
counter.dead_time++;
if(flag & TIME_ROLLOVER) counter.time_roll++; if(flag & TimeRollover)
counter.time_roll++;
if(flag & TIME_RESET) counter.time_reset++; if(flag & TimeReset)
counter.time_reset++;
if(flag & FAKE_EVENT) counter.fake_event++; if(flag & FakeEvent)
counter.fake_event++;
if(flag & MEM_FULL) counter.mem_full++; if(flag & MemFull)
counter.mem_full++;
if(flag & TRIG_LOST) counter.trig_lost++; if(flag & TrigLost)
counter.trig_lost++;
if(flag & N_TRIG_LOST) counter.n_trig_lost++; if(flag & NTrigLost)
counter.n_trig_lost++;
if(flag & SATURATING_IN_GATE) counter.sat_in_gate++; if(flag & SaturatingInGate)
counter.sat_in_gate++;
if(flag & TRIG_1024_COUNTED) counter.trig_1024++;; if(flag & Trig1024Counted)
counter.trig_1024++;;
if(flag & SATURATING_INPUT) counter.sat_input++; if(flag & SaturatingInput)
counter.sat_input++;
if(flag & N_TRIG_COUNTED) counter.n_trig_count++; if(flag & NTrigCounted)
counter.n_trig_count++;
if(flag & EVENT_NOT_MATCHED) counter.event_not_matched++; if(flag & EventNotMatched)
counter.event_not_matched++;
if(flag & PILE_UP) counter.pile_up++; if(flag & PileUp)
counter.pile_up++;
if(flag & PLL_LOCK_LOSS) counter.pll_lock_loss++; if(flag & PLLLockLoss)
counter.pll_lock_loss++;
if(flag & OVER_TEMP) counter.over_temp++; if(flag & OverTemp)
counter.over_temp++;
if(flag & ADC_SHUTDOWN) counter.adc_shutdown++; if(flag & ADCShutdown)
counter.adc_shutdown++;
} }
void FlagHandler::WriteLog() { void FlagHandler::WriteLog()
{
log<<"Event Flag Log"<<std::endl; log<<"Event Flag Log"<<std::endl;
log<<"-----------------------------"<<std::endl; log<<"-----------------------------"<<std::endl;
for(auto& counter : event_count_map) { for(auto& counter : event_count_map)
{
log<<"-----------------------------"<<std::endl; log<<"-----------------------------"<<std::endl;
log<<"GLOBAL CHANNEL No.: "<<counter.first<<std::endl; log<<"GLOBAL CHANNEL No.: "<<counter.first<<std::endl;
log<<"Total number of events: "<<counter.second.total_counts<<std::endl; log<<"Total number of events: "<<counter.second.total_counts<<std::endl;

View File

@ -16,33 +16,37 @@ Written by G.W. McCann Aug. 2020
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::ifstream massfile("./etc/mass.txt"); std::ifstream massfile("./etc/mass.txt");
if(massfile.is_open()) { if(massfile.is_open())
std::string junk, A, element; {
int Z; int Z;
double atomicMassBig, atomicMassSmall, isotopicMass; double atomicMassBig, atomicMassSmall, isotopicMass;
getline(massfile,junk); getline(massfile,junk);
getline(massfile,junk); getline(massfile,junk);
while(massfile>>junk) { while(massfile>>junk)
{
massfile>>Z>>A>>element>>atomicMassBig>>atomicMassSmall; massfile>>Z>>A>>element>>atomicMassBig>>atomicMassSmall;
isotopicMass = (atomicMassBig + atomicMassSmall*1e-6 - Z*electron_mass)*u_to_mev; isotopicMass = (atomicMassBig + atomicMassSmall*1e-6 - Z*electron_mass)*u_to_mev;
std::string key = "("+std::to_string(Z)+","+A+")"; std::string key = "("+std::to_string(Z)+","+A+")";
massTable[key] = isotopicMass; massTable[key] = isotopicMass;
elementTable[Z] = element; 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)+")"; std::string key = "("+std::to_string(Z)+","+std::to_string(A)+")";
auto data = massTable.find(key); auto data = massTable.find(key);
if(data == massTable.end()) { if(data == massTable.end())
{
std::cerr<<"Invaild nucleus at MassLookup! Returning mass of 0"<<std::endl; std::cerr<<"Invaild nucleus at MassLookup! Returning mass of 0"<<std::endl;
return 0; return 0;
} }
@ -50,9 +54,11 @@ double MassLookup::FindMass(int Z, int A) {
} }
//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); auto data = elementTable.find(Z);
if(data == elementTable.end()) { if(data == elementTable.end())
{
std::cerr<<"Invaild nucleus at MassLookup! Returning empty symbol"<<std::endl; std::cerr<<"Invaild nucleus at MassLookup! Returning empty symbol"<<std::endl;
return ""; return "";
} }

View File

@ -8,25 +8,28 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "OrderChecker.h" #include "OrderChecker.h"
OrderChecker::OrderChecker() { OrderChecker::OrderChecker()
{
} }
OrderChecker::~OrderChecker() { OrderChecker::~OrderChecker()
{
} }
bool OrderChecker::IsOrdered(const std::string& filename) { bool OrderChecker::IsOrdered(const std::string& filename)
{
TFile* file = TFile::Open(filename.c_str(), "READ"); TFile* file = TFile::Open(filename.c_str(), "READ");
TTree* tree = (TTree*) file->Get("Data"); TTree* tree = (TTree*) file->Get("Data");
ULong64_t ts; uint64_t ts;
tree->SetBranchAddress("Timestamp", &ts); tree->SetBranchAddress("Timestamp", &ts);
ULong64_t prevStamp = 0; uint64_t prevStamp = 0;
for(Long64_t i=0; i<tree->GetEntries(); i++) { for(Long64_t i=0; i<tree->GetEntries(); i++)
{
tree->GetEntry(); tree->GetEntry();
if(prevStamp >= ts) { if(prevStamp >= ts)
{
std::cerr<<"Bad order at entry "<<i<<" out of "<<tree->GetEntries()<<std::endl; std::cerr<<"Bad order at entry "<<i<<" out of "<<tree->GetEntries()<<std::endl;
return false; return false;
} }

View File

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

View File

@ -12,24 +12,26 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "SFPAnalyzer.h" #include "SFPAnalyzer.h"
using namespace std;
/*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); zfp = Delta_Z(zt, at, zp, ap, ze, ae, ep, angle, b);
event_address = new CoincEvent(); event_address = new CoincEvent();
rootObj = new THashTable(); rootObj = new THashTable();
GetWeights(); GetWeights();
} }
SFPAnalyzer::~SFPAnalyzer() { SFPAnalyzer::~SFPAnalyzer()
{
rootObj->Clear(); rootObj->Clear();
delete rootObj; delete rootObj;
delete event_address; delete event_address;
} }
void SFPAnalyzer::Reset() { void SFPAnalyzer::Reset()
{
pevent = blank; //set output back to blank pevent = blank; //set output back to blank
} }
@ -38,19 +40,22 @@ void SFPAnalyzer::Reset() {
*from the two focal plane points and finding the intersection with *from the two focal plane points and finding the intersection with
*the kinematic focal plane *the kinematic focal plane
*/ */
void SFPAnalyzer::GetWeights() { void SFPAnalyzer::GetWeights()
{
w1 = (Wire_Dist()/2.0-zfp)/Wire_Dist(); w1 = (Wire_Dist()/2.0-zfp)/Wire_Dist();
w2 = 1.0-w1; w2 = 1.0-w1;
cout<<"w1: "<<w1<<" w2: "<<w2<<endl; cout<<"w1: "<<w1<<" w2: "<<w2<<endl;
} }
/*2D histogram fill wrapper for use with THashTable (faster)*/ /*2D histogram fill wrapper for use with THashTable (faster)*/
void SFPAnalyzer::MyFill(const string& name, int binsx, double minx, double maxx, double valuex, void SFPAnalyzer::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)
{
TH2F *histo = (TH2F*) rootObj->FindObject(name.c_str()); TH2F *histo = (TH2F*) rootObj->FindObject(name.c_str());
if(histo != NULL) { if(histo != nullptr)
histo->Fill(valuex, valuey); histo->Fill(valuex, valuey);
} else { else
{
TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy);
h->Fill(valuex, valuey); h->Fill(valuex, valuey);
rootObj->Add(h); rootObj->Add(h);
@ -58,69 +63,83 @@ void SFPAnalyzer::MyFill(const string& name, int binsx, double minx, double maxx
} }
/*1D histogram fill wrapper for use with THashTable (faster)*/ /*1D histogram fill wrapper for use with THashTable (faster)*/
void SFPAnalyzer::MyFill(const string& name, int binsx, double minx, double maxx, double valuex) { void SFPAnalyzer::MyFill(const std::string& name, int binsx, double minx, double maxx, double valuex)
{
TH1F *histo = (TH1F*) rootObj->FindObject(name.c_str()); TH1F *histo = (TH1F*) rootObj->FindObject(name.c_str());
if(histo != NULL) { if(histo != nullptr)
histo->Fill(valuex); histo->Fill(valuex);
} else { else
{
TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx); TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx);
h->Fill(valuex); h->Fill(valuex);
rootObj->Add(h); rootObj->Add(h);
} }
} }
void SFPAnalyzer::AnalyzeEvent(CoincEvent& event) { void SFPAnalyzer::AnalyzeEvent(CoincEvent& event)
{
Reset(); Reset();
if(!event.focalPlane.anodeF.empty()) { if(!event.focalPlane.anodeF.empty())
{
pevent.anodeFront = event.focalPlane.anodeF[0].Long; pevent.anodeFront = event.focalPlane.anodeF[0].Long;
pevent.anodeFrontTime = event.focalPlane.anodeF[0].Time; pevent.anodeFrontTime = event.focalPlane.anodeF[0].Time;
} }
if(!event.focalPlane.anodeB.empty()) { if(!event.focalPlane.anodeB.empty())
{
pevent.anodeBack = event.focalPlane.anodeB[0].Long; pevent.anodeBack = event.focalPlane.anodeB[0].Long;
pevent.anodeBackTime = event.focalPlane.anodeB[0].Time; pevent.anodeBackTime = event.focalPlane.anodeB[0].Time;
} }
if(!event.focalPlane.scintL.empty()) { if(!event.focalPlane.scintL.empty())
{
pevent.scintLeft = event.focalPlane.scintL[0].Long; pevent.scintLeft = event.focalPlane.scintL[0].Long;
pevent.scintLeftShort = event.focalPlane.scintL[0].Short; pevent.scintLeftShort = event.focalPlane.scintL[0].Short;
pevent.scintLeftTime = event.focalPlane.scintL[0].Time; pevent.scintLeftTime = event.focalPlane.scintL[0].Time;
} }
if(!event.focalPlane.scintR.empty()) { if(!event.focalPlane.scintR.empty())
{
pevent.scintRight = event.focalPlane.scintR[0].Long; pevent.scintRight = event.focalPlane.scintR[0].Long;
pevent.scintRightShort = event.focalPlane.scintR[0].Short; pevent.scintRightShort = event.focalPlane.scintR[0].Short;
pevent.scintRightTime = event.focalPlane.scintR[0].Time; pevent.scintRightTime = event.focalPlane.scintR[0].Time;
} }
if(!event.focalPlane.cathode.empty()) { if(!event.focalPlane.cathode.empty())
{
pevent.cathode = event.focalPlane.cathode[0].Long; pevent.cathode = event.focalPlane.cathode[0].Long;
pevent.cathodeTime = event.focalPlane.cathode[0].Time; pevent.cathodeTime = event.focalPlane.cathode[0].Time;
} }
if(!event.focalPlane.monitor.empty()) { if(!event.focalPlane.monitor.empty())
{
pevent.monitorE = event.focalPlane.monitor[0].Long; pevent.monitorE = event.focalPlane.monitor[0].Long;
pevent.monitorShort = event.focalPlane.monitor[0].Short; pevent.monitorShort = event.focalPlane.monitor[0].Short;
pevent.monitorTime = event.focalPlane.monitor[0].Time; pevent.monitorTime = event.focalPlane.monitor[0].Time;
} }
/*Delay lines and all that*/ /*Delay lines and all that*/
if(!event.focalPlane.delayFR.empty()) { if(!event.focalPlane.delayFR.empty())
{
pevent.delayFrontRightE = event.focalPlane.delayFR[0].Long; pevent.delayFrontRightE = event.focalPlane.delayFR[0].Long;
pevent.delayFrontRightTime = event.focalPlane.delayFR[0].Time; pevent.delayFrontRightTime = event.focalPlane.delayFR[0].Time;
pevent.delayFrontRightShort = event.focalPlane.delayFR[0].Short; pevent.delayFrontRightShort = event.focalPlane.delayFR[0].Short;
} }
if(!event.focalPlane.delayFL.empty()) { if(!event.focalPlane.delayFL.empty())
{
pevent.delayFrontLeftE = event.focalPlane.delayFL[0].Long; pevent.delayFrontLeftE = event.focalPlane.delayFL[0].Long;
pevent.delayFrontLeftTime = event.focalPlane.delayFL[0].Time; pevent.delayFrontLeftTime = event.focalPlane.delayFL[0].Time;
pevent.delayFrontLeftShort = event.focalPlane.delayFL[0].Short; pevent.delayFrontLeftShort = event.focalPlane.delayFL[0].Short;
} }
if(!event.focalPlane.delayBR.empty()) { if(!event.focalPlane.delayBR.empty())
{
pevent.delayBackRightE = event.focalPlane.delayBR[0].Long; pevent.delayBackRightE = event.focalPlane.delayBR[0].Long;
pevent.delayBackRightTime = event.focalPlane.delayBR[0].Time; pevent.delayBackRightTime = event.focalPlane.delayBR[0].Time;
pevent.delayBackRightShort = event.focalPlane.delayBR[0].Short; pevent.delayBackRightShort = event.focalPlane.delayBR[0].Short;
} }
if(!event.focalPlane.delayBL.empty()) { if(!event.focalPlane.delayBL.empty())
{
pevent.delayBackLeftE = event.focalPlane.delayBL[0].Long; pevent.delayBackLeftE = event.focalPlane.delayBL[0].Long;
pevent.delayBackLeftTime = event.focalPlane.delayBL[0].Time; pevent.delayBackLeftTime = event.focalPlane.delayBL[0].Time;
pevent.delayBackLeftShort = event.focalPlane.delayBL[0].Short; pevent.delayBackLeftShort = event.focalPlane.delayBL[0].Short;
} }
if(!event.focalPlane.delayFL.empty() && !event.focalPlane.delayFR.empty()) { 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_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_tsum = (event.focalPlane.delayFL[0].Time+event.focalPlane.delayFR[0].Time);
pevent.fp1_tcheck = (pevent.fp1_tsum)/2.0-pevent.anodeFrontTime; pevent.fp1_tcheck = (pevent.fp1_tsum)/2.0-pevent.anodeFrontTime;
@ -129,7 +148,8 @@ void SFPAnalyzer::AnalyzeEvent(CoincEvent& event) {
MyFill("x1",1200,-300,300,pevent.x1); MyFill("x1",1200,-300,300,pevent.x1);
MyFill("x1 vs anodeBack",600,-300,300,pevent.x1,512,0,4096,pevent.anodeBack); MyFill("x1 vs anodeBack",600,-300,300,pevent.x1,512,0,4096,pevent.anodeBack);
} }
if(!event.focalPlane.delayBL.empty() && !event.focalPlane.delayBR.empty()) { 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_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_tsum = (event.focalPlane.delayBL[0].Time+event.focalPlane.delayBR[0].Time);
pevent.fp2_tcheck = (pevent.fp2_tsum)/2.0-pevent.anodeBackTime; pevent.fp2_tcheck = (pevent.fp2_tsum)/2.0-pevent.anodeBackTime;
@ -139,13 +159,16 @@ void SFPAnalyzer::AnalyzeEvent(CoincEvent& event) {
MyFill("x2 vs anodeBack",600,-300,300,pevent.x2,512,0,4096,pevent.anodeBack); MyFill("x2 vs anodeBack",600,-300,300,pevent.x2,512,0,4096,pevent.anodeBack);
} }
/*SABRE data*/ /*SABRE data*/
for(int j=0; j<5; j++) { for(int j=0; j<5; j++)
if(!event.sabreArray[j].rings.empty()) { {
if(!event.sabreArray[j].rings.empty())
{
pevent.sabreRingE[j] = event.sabreArray[j].rings[0].Long; pevent.sabreRingE[j] = event.sabreArray[j].rings[0].Long;
pevent.sabreRingChannel[j] = event.sabreArray[j].rings[0].Ch; pevent.sabreRingChannel[j] = event.sabreArray[j].rings[0].Ch;
pevent.sabreRingTime[j] = event.sabreArray[j].rings[0].Time; pevent.sabreRingTime[j] = event.sabreArray[j].rings[0].Time;
} }
if(!event.sabreArray[j].wedges.empty()) { if(!event.sabreArray[j].wedges.empty())
{
pevent.sabreWedgeE[j] = event.sabreArray[j].wedges[0].Long; pevent.sabreWedgeE[j] = event.sabreArray[j].wedges[0].Long;
pevent.sabreWedgeChannel[j] = event.sabreArray[j].wedges[0].Ch; pevent.sabreWedgeChannel[j] = event.sabreArray[j].wedges[0].Ch;
pevent.sabreWedgeTime[j] = event.sabreArray[j].wedges[0].Time; pevent.sabreWedgeTime[j] = event.sabreArray[j].wedges[0].Time;
@ -156,28 +179,27 @@ void SFPAnalyzer::AnalyzeEvent(CoincEvent& event) {
/*Make some histograms and xavg*/ /*Make some histograms and xavg*/
MyFill("anodeBack vs scintLeft",512,0,4096,pevent.scintLeft,512,0,4096,pevent.anodeBack); MyFill("anodeBack vs scintLeft",512,0,4096,pevent.scintLeft,512,0,4096,pevent.anodeBack);
if(pevent.x1 != -1e6 && pevent.x2 != -1e6) { if(pevent.x1 != -1e6 && pevent.x2 != -1e6)
{
pevent.xavg = pevent.x1*w1+pevent.x2*w2; pevent.xavg = pevent.x1*w1+pevent.x2*w2;
MyFill("xavg",1200,-300,300,pevent.xavg); MyFill("xavg",1200,-300,300,pevent.xavg);
if((pevent.x2-pevent.x1) > 0) { if((pevent.x2-pevent.x1) > 0)
pevent.theta = atan((pevent.x2-pevent.x1)/36.0); pevent.theta = std::atan((pevent.x2-pevent.x1)/36.0);
} else if((pevent.x2-pevent.x1) < 0) { else if((pevent.x2-pevent.x1) < 0)
pevent.theta = TMath::Pi() + atan((pevent.x2-pevent.x1)/36.0); pevent.theta = TMath::Pi() + std::atan((pevent.x2-pevent.x1)/36.0);
} else { else
pevent.theta = TMath::Pi()/2.0; pevent.theta = TMath::Pi()/2.0;
}
MyFill("xavg vs theta",600,-300,300,pevent.xavg,314,0,3.14,pevent.theta); 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); MyFill("x1 vs x2",600,-300,300,pevent.x1,600,-300,300,pevent.x2);
} }
if(pevent.anodeFrontTime != -1 && pevent.scintRightTime != -1) { if(pevent.anodeFrontTime != -1 && pevent.scintRightTime != -1)
pevent.fp1_y = pevent.anodeFrontTime-pevent.scintRightTime; pevent.fp1_y = pevent.anodeFrontTime-pevent.scintRightTime;
} if(pevent.anodeBackTime != -1 && pevent.scintRightTime != -1)
if(pevent.anodeBackTime != -1 && pevent.scintRightTime != -1) {
pevent.fp2_y = pevent.anodeBackTime-pevent.scintRightTime; pevent.fp2_y = pevent.anodeBackTime-pevent.scintRightTime;
}
} }
ProcessedEvent SFPAnalyzer::GetProcessedEvent(CoincEvent& event) { ProcessedEvent SFPAnalyzer::GetProcessedEvent(CoincEvent& event)
{
AnalyzeEvent(event); AnalyzeEvent(event);
return pevent; return pevent;
} }

View File

@ -11,25 +11,29 @@
#include <TSystem.h> #include <TSystem.h>
/*Generates storage and initializes pointers*/ /*Generates storage and initializes pointers*/
SFPPlotter::SFPPlotter() { SFPPlotter::SFPPlotter()
{
rootObj = new THashTable(); rootObj = new THashTable();
rootObj->SetOwner(false);//THashTable doesnt own members; avoid double delete rootObj->SetOwner(false);//THashTable doesnt own members; avoid double delete
event_address = new ProcessedEvent(); event_address = new ProcessedEvent();
chain = new TChain("SPSTree"); chain = new TChain("SPSTree");
m_pb = NULL; m_pb = nullptr;
} }
SFPPlotter::~SFPPlotter() { SFPPlotter::~SFPPlotter()
{
delete event_address; delete event_address;
} }
/*2D histogram fill wrapper*/ /*2D histogram fill wrapper*/
void SFPPlotter::MyFill(const string& name, int binsx, double minx, double maxx, double valuex, 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) { int binsy, double miny, double maxy, double valuey)
{
TH2F *histo = (TH2F*) rootObj->FindObject(name.c_str()); TH2F *histo = (TH2F*) rootObj->FindObject(name.c_str());
if(histo != NULL) { if(histo != nullptr)
histo->Fill(valuex, valuey); histo->Fill(valuex, valuey);
} else { else
{
TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy); TH2F *h = new TH2F(name.c_str(), name.c_str(), binsx, minx, maxx, binsy, miny, maxy);
h->Fill(valuex, valuey); h->Fill(valuex, valuey);
rootObj->Add(h); rootObj->Add(h);
@ -37,227 +41,234 @@ void SFPPlotter::MyFill(const string& name, int binsx, double minx, double maxx,
} }
/*1D histogram fill wrapper*/ /*1D histogram fill wrapper*/
void SFPPlotter::MyFill(const string& name, int binsx, double minx, double maxx, double valuex) { void SFPPlotter::MyFill(THashTable* table, const std::string& name, int binsx, double minx, double maxx, double valuex)
{
TH1F *histo = (TH1F*) rootObj->FindObject(name.c_str()); TH1F *histo = (TH1F*) rootObj->FindObject(name.c_str());
if(histo != NULL) { if(histo != nullptr)
histo->Fill(valuex); histo->Fill(valuex);
} else { else
{
TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx); TH1F *h = new TH1F(name.c_str(), name.c_str(), binsx, minx, maxx);
h->Fill(valuex); h->Fill(valuex);
rootObj->Add(h); rootObj->Add(h);
} }
} }
void SFPPlotter::ApplyCutlist(const string& listname) {
cutter.SetCuts(listname);
}
/*Makes histograms where only rejection is unset data*/ /*Makes histograms where only rejection is unset data*/
void SFPPlotter::MakeUncutHistograms(ProcessedEvent ev) { void SFPPlotter::MakeUncutHistograms(const ProcessedEvent& ev, THashTable* table)
MyFill("x1NoCuts_bothplanes",600,-300,300,ev.x2); {
MyFill("x2NoCuts_bothplanes",600,-300,300,ev.x2); MyFill(table,"x1NoCuts_bothplanes",600,-300,300,ev.x2);
MyFill("xavgNoCuts_bothplanes",600,-300,300,ev.xavg); MyFill(table,"x2NoCuts_bothplanes",600,-300,300,ev.x2);
MyFill("xavgNoCuts_theta_bothplanes",600,-300,300,ev.xavg,100,0,TMath::Pi()/2.,ev.theta); 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("x1_delayBackRightE_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE); MyFill(table,"x1_delayBackRightE_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE);
MyFill("x2_delayBackRightE_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE); MyFill(table,"x2_delayBackRightE_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE);
MyFill("xavg_delayBackRightE_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE); MyFill(table,"xavg_delayBackRightE_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE);
MyFill("x1_x2_NoCuts",600,-300,300,ev.x1,600,-300,300,ev.x2); MyFill(table,"x1_x2_NoCuts",600,-300,300,ev.x1,600,-300,300,ev.x2);
Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0; Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0;
MyFill("x1_delayBackAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayBackAvgE); MyFill(table,"x1_delayBackAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayBackAvgE);
MyFill("x2_delayBackAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayBackAvgE); MyFill(table,"x2_delayBackAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayBackAvgE);
MyFill("xavg_delayBackAvgE_NoCuts",600,-300,300,ev.xavg,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; Double_t delayFrontAvgE = (ev.delayFrontRightE+ev.delayFrontLeftE)/2.0;
MyFill("x1_delayFrontAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE); MyFill(table,"x1_delayFrontAvgE_NoCuts",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE);
MyFill("x2_delayFrontAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE); MyFill(table,"x2_delayFrontAvgE_NoCuts",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE);
MyFill("xavg_delayFrontAvgE_NoCuts",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE); MyFill(table,"xavg_delayFrontAvgE_NoCuts",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE);
MyFill("scintLeft_anodeBack_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack); MyFill(table,"scintLeft_anodeBack_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack);
MyFill("scintLeft_anodeFront_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront); MyFill(table,"scintLeft_anodeFront_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront);
MyFill("scintLeft_cathode_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode); MyFill(table,"scintLeft_cathode_NoCuts",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode);
MyFill("x1_scintLeft_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.scintLeft); MyFill(table,"x1_scintLeft_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.scintLeft);
MyFill("x2_scintLeft_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.scintLeft); MyFill(table,"x2_scintLeft_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.scintLeft);
MyFill("xavg_scintLeft_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft); MyFill(table,"xavg_scintLeft_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft);
MyFill("x1_anodeBack_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeBack); MyFill(table,"x1_anodeBack_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeBack);
MyFill("x2_anodeBack_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeBack); MyFill(table,"x2_anodeBack_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeBack);
MyFill("xavg_anodeBack_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack); MyFill(table,"xavg_anodeBack_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack);
MyFill("x1_anodeFront_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeFront); MyFill(table,"x1_anodeFront_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.anodeFront);
MyFill("x2_anodeFront_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeFront); MyFill(table,"x2_anodeFront_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.anodeFront);
MyFill("xavg_anodeFront_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront); MyFill(table,"xavg_anodeFront_NoCuts",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront);
MyFill("x1_cathode_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.cathode); MyFill(table,"x1_cathode_NoCuts",600,-300,300,ev.x1,512,0,4096,ev.cathode);
MyFill("x2_cathode_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.cathode); MyFill(table,"x2_cathode_NoCuts",600,-300,300,ev.x2,512,0,4096,ev.cathode);
MyFill("xavg_cathode_NoCuts",600,-300,300,ev.xavg,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****/ /****Timing relative to back anode****/
if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1) { if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1)
{
Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime; Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime;
Double_t delayRelFT = ev.delayFrontMaxTime - ev.anodeBackTime; Double_t delayRelFT = ev.delayFrontMaxTime - ev.anodeBackTime;
Double_t delayRelBT = ev.delayBackMaxTime - ev.anodeBackTime; Double_t delayRelBT = ev.delayBackMaxTime - ev.anodeBackTime;
Double_t anodeRelBT = ev.anodeBackTime - ev.scintLeftTime; Double_t anodeRelBT = ev.anodeBackTime - ev.scintLeftTime;
Double_t delayRelFT_toScint = ev.delayFrontMaxTime - ev.scintLeftTime; Double_t delayRelFT_toScint = ev.delayFrontMaxTime - ev.scintLeftTime;
Double_t delayRelBT_toScint = ev.delayBackMaxTime - ev.scintLeftTime; Double_t delayRelBT_toScint = ev.delayBackMaxTime - ev.scintLeftTime;
MyFill("anodeRelFrontTime_NoCuts",1000,-3000,3500, anodeRelFT); MyFill(table,"anodeRelFrontTime_NoCuts",1000,-3000,3500, anodeRelFT);
MyFill("delayRelFrontTime_NoCuts",1000,-3000,-3500,delayRelFT); MyFill(table,"delayRelFrontTime_NoCuts",1000,-3000,-3500,delayRelFT);
MyFill("delayRelBackTime_NoCuts",1000,-3000,-3500,delayRelBT); MyFill(table,"delayRelBackTime_NoCuts",1000,-3000,-3500,delayRelBT);
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; Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime;
Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime;
Double_t sabreRelRT_toScint = ev.sabreRingTime[i] - ev.scintLeftTime; Double_t sabreRelRT_toScint = ev.sabreRingTime[i] - ev.scintLeftTime;
Double_t sabreRelWT_toScint = ev.sabreWedgeTime[i] - ev.scintLeftTime; Double_t sabreRelWT_toScint = ev.sabreWedgeTime[i] - ev.scintLeftTime;
MyFill("xavg_sabrefcoinc_NoCuts",600,-300,300, ev.xavg); MyFill(table,"xavg_sabrefcoinc_NoCuts",600,-300,300, ev.xavg);
MyFill("sabreRelRingTime_NoCuts",1000,-3000,3500, sabreRelRT); MyFill(table,"sabreRelRingTime_NoCuts",1000,-3000,3500, sabreRelRT);
MyFill("sabreRelWedgeTime_NoCuts",1000,-3000,3500, sabreRelWT); MyFill(table,"sabreRelWedgeTime_NoCuts",1000,-3000,3500, sabreRelWT);
MyFill("sabreRelRingTime_toScint",1000,-3000,3500,sabreRelRT_toScint); MyFill(table,"sabreRelRingTime_toScint",1000,-3000,3500,sabreRelRT_toScint);
MyFill("sabreRelWedgeTime_toScint",1000,-3000,3500,sabreRelWT_toScint); MyFill(table,"sabreRelWedgeTime_toScint",1000,-3000,3500,sabreRelWT_toScint);
MyFill("sabreRelRTScint_sabreRelRTAnode",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelRT); MyFill(table,"sabreRelRTScint_sabreRelRTAnode",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelRT);
MyFill("sabreRelRTScint_sabreRingChannel",500,-3000,3500,sabreRelRT_toScint,144,0,144,ev.sabreRingChannel[i]); MyFill(table,"sabreRelRTScint_sabreRingChannel",500,-3000,3500,sabreRelRT_toScint,144,0,144,ev.sabreRingChannel[i]);
MyFill("sabreRelRTAnode_sabreRingChannel",500,-3000,3500,sabreRelRT,144,0,144,ev.sabreRingChannel[i]); MyFill(table,"sabreRelRTAnode_sabreRingChannel",500,-3000,3500,sabreRelRT,144,0,144,ev.sabreRingChannel[i]);
MyFill("sabreRelWTScint_sabreWedgeChannel",500,-3000,3500,sabreRelWT_toScint,144,0,144,ev.sabreWedgeChannel[i]); MyFill(table,"sabreRelWTScint_sabreWedgeChannel",500,-3000,3500,sabreRelWT_toScint,144,0,144,ev.sabreWedgeChannel[i]);
MyFill("sabreRelRT_sabreRelWT",500,-3000,3500,sabreRelRT,500,-3000,3500,sabreRelWT); MyFill(table,"sabreRelRT_sabreRelWT",500,-3000,3500,sabreRelRT,500,-3000,3500,sabreRelWT);
MyFill("sabreRelRT_sabreRelWT_scint",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelWT_toScint); MyFill(table,"sabreRelRT_sabreRelWT_scint",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,sabreRelWT_toScint);
MyFill("sabreRelRTScint_anodeRelT",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,anodeRelBT); MyFill(table,"sabreRelRTScint_anodeRelT",500,-3000,3500,sabreRelRT_toScint,500,-3000,3500,anodeRelBT);
} }
} }
MyFill("anodeBackRelTime_toScint",1000,-3000,3500,anodeRelBT); MyFill(table,"anodeBackRelTime_toScint",1000,-3000,3500,anodeRelBT);
MyFill("delayRelBackTime_toScint",1000,-3000,3500,delayRelBT_toScint); MyFill(table,"delayRelBackTime_toScint",1000,-3000,3500,delayRelBT_toScint);
MyFill("delayRelFrontTime_toScint",1000,-3000,3500,delayRelFT_toScint); MyFill(table,"delayRelFrontTime_toScint",1000,-3000,3500,delayRelFT_toScint);
} else { }
MyFill("noscinttime_counter_NoCuts",2,0,1,1); 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]);
}
} }
int count = 0; if(ev.x1 != -1e6 && ev.x2 == -1e6)
for(int i=0; i<5; i++) { MyFill(table,"x1NoCuts_only1plane",600,-300,300,ev.x1);
if(ev.sabreRingE[i] != -1) { //Again, at this point front&back are required else if(ev.x2 != -1e6 && ev.x1 == -1e6)
MyFill("sabreRingE_NoCuts",2000,0,20,ev.sabreRingE[i]); MyFill(table,"x2NoCuts_only1plane",600,-300,300,ev.x2);
MyFill("sabreRingChannel_sabreRingE_NoCuts",144,0,144,ev.sabreRingChannel[i],200,0,20,ev.sabreRingE[i]); else if(ev.x1 == -1e6 && ev.x2 == -1e6)
MyFill("sabreWedgeE_NoCuts",2000,0,20,ev.sabreWedgeE[i]); MyFill(table,"nopos_counter",2,0,1,1);
MyFill("sabreWedgeChannel_sabreWedgeE_NoCuts",144,0,144,ev.sabreWedgeChannel[i],200,0,20,ev.sabreWedgeE[i]);
} else {
count++;
}
}
if(count == 80) {
MyFill("xavg_bothplanes_sabreanticoinc_NoCuts",600,-300,300,ev.xavg);
}
if(ev.x1 != -1e6 && ev.x2 == -1e6) {
MyFill("x1NoCuts_only1plane",600,-300,300,ev.x1);
} else if(ev.x2 != -1e6 && ev.x1 == -1e6) {
MyFill("x2NoCuts_only1plane",600,-300,300,ev.x2);
} else if(ev.x1 == -1e6 && ev.x2 == -1e6) {
MyFill("nopos_counter",2,0,1,1);
}
} }
/*Makes histograms with cuts & gates implemented*/ /*Makes histograms with cuts & gates implemented*/
void SFPPlotter::MakeCutHistograms(ProcessedEvent ev) { void SFPPlotter::MakeCutHistograms(const ProcessedEvent& ev, THashTable* table)
if(cutter.IsInside(&ev)) { {
MyFill("x1_bothplanes_Cut",600,-300,300,ev.x1); if(!cutter.IsInside(&ev))
MyFill("x2_bothplanes_Cut",600,-300,300,ev.x2); return;
MyFill("xavg_bothplanes_Cut",600,-300,300,ev.xavg);
MyFill("x1_x2_Cut",600,-300,300,ev.x1, 600,-300,300,ev.x2);
MyFill("xavg_theta_Cut_bothplanes",600,-300,300,ev.xavg,100,0,TMath::Pi()/2.,ev.theta);
MyFill("x1_delayBackRightE_Cut",600,-300,300,ev.x1,512,0,4096,ev.delayBackRightE); MyFill(table,"x1_bothplanes_Cut",600,-300,300,ev.x1);
MyFill("x2_delayBackRightE_Cut",600,-300,300,ev.x2,512,0,4096,ev.delayBackRightE); MyFill(table,"x2_bothplanes_Cut",600,-300,300,ev.x2);
MyFill("xavg_delayBackRightE_Cut",600,-300,300,ev.xavg,512,0,4096,ev.delayBackRightE); 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; Double_t delayBackAvgE = (ev.delayBackRightE+ev.delayBackLeftE)/2.0;
MyFill("x1_delayBackAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayBackAvgE); MyFill(table,"x1_delayBackAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayBackAvgE);
MyFill("x2_delayBackAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayBackAvgE); MyFill(table,"x2_delayBackAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayBackAvgE);
MyFill("xavg_delayBackAvgE_Cut",600,-300,300,ev.xavg,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; Double_t delayFrontAvgE = (ev.delayFrontRightE+ev.delayFrontLeftE)/2.0;
MyFill("x1_delayFrontAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE); MyFill(table,"x1_delayFrontAvgE_Cut",600,-300,300,ev.x1,512,0,4096,delayFrontAvgE);
MyFill("x2_delayFrontAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE); MyFill(table,"x2_delayFrontAvgE_Cut",600,-300,300,ev.x2,512,0,4096,delayFrontAvgE);
MyFill("xavg_delayFrontAvgE_Cut",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE); MyFill(table,"xavg_delayFrontAvgE_Cut",600,-300,300,ev.xavg,512,0,4096,delayFrontAvgE);
MyFill("scintLeft_anodeBack_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack); MyFill(table,"scintLeft_anodeBack_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeBack);
MyFill("scintLeft_anodeFront_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront); MyFill(table,"scintLeft_anodeFront_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.anodeFront);
MyFill("scintLeft_cathode_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode); MyFill(table,"scintLeft_cathode_Cut",512,0,4096,ev.scintLeft,512,0,4096,ev.cathode);
MyFill("x1_scintLeft_Cut",600,-300,300,ev.x1,512,0,4096,ev.scintLeft); MyFill(table,"x1_scintLeft_Cut",600,-300,300,ev.x1,512,0,4096,ev.scintLeft);
MyFill("x2_scintLeft_Cut",600,-300,300,ev.x2,512,0,4096,ev.scintLeft); MyFill(table,"x2_scintLeft_Cut",600,-300,300,ev.x2,512,0,4096,ev.scintLeft);
MyFill("xavg_scintLeft_Cut",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft); MyFill(table,"xavg_scintLeft_Cut",600,-300,300,ev.xavg,512,0,4096,ev.scintLeft);
MyFill("x1_anodeBack_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeBack); MyFill(table,"x1_anodeBack_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeBack);
MyFill("x2_anodeBack_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeBack); MyFill(table,"x2_anodeBack_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeBack);
MyFill("xavg_anodeBack_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack); MyFill(table,"xavg_anodeBack_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeBack);
MyFill("x1_anodeFront_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeFront); MyFill(table,"x1_anodeFront_Cut",600,-300,300,ev.x1,512,0,4096,ev.anodeFront);
MyFill("x2_anodeFront_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeFront); MyFill(table,"x2_anodeFront_Cut",600,-300,300,ev.x2,512,0,4096,ev.anodeFront);
MyFill("xavg_anodeFront_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront); MyFill(table,"xavg_anodeFront_Cut",600,-300,300,ev.xavg,512,0,4096,ev.anodeFront);
MyFill("x1_cathode_Cut",600,-300,300,ev.x1,512,0,4096,ev.cathode); MyFill(table,"x1_cathode_Cut",600,-300,300,ev.x1,512,0,4096,ev.cathode);
MyFill("x2_cathode_Cut",600,-300,300,ev.x2,512,0,4096,ev.cathode); MyFill(table,"x2_cathode_Cut",600,-300,300,ev.x2,512,0,4096,ev.cathode);
MyFill("xavg_cathode_Cut",600,-300,300,ev.xavg,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****/ /****Timing relative to back anode****/
if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1) { if(ev.anodeBackTime != -1 && ev.scintLeftTime != -1)
{
Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime; Double_t anodeRelFT = ev.anodeFrontTime - ev.anodeBackTime;
Double_t anodeRelBT = ev.anodeBackTime - ev.anodeBackTime; Double_t anodeRelBT = ev.anodeBackTime - ev.anodeBackTime;
Double_t anodeRelFT_toScint = ev.anodeFrontTime-ev.scintLeftTime; Double_t anodeRelFT_toScint = ev.anodeFrontTime-ev.scintLeftTime;
MyFill("anodeRelBackTime_Cut",1000,-3000,3500, anodeRelBT); MyFill(table,"anodeRelBackTime_Cut",1000,-3000,3500, anodeRelBT);
MyFill("anodeRelFrontTime_Cut",1000,-3000,3500, anodeRelFT); MyFill(table,"anodeRelFrontTime_Cut",1000,-3000,3500, anodeRelFT);
MyFill("anodeRelTime_toScint_Cut",1000,-3000,3500,anodeRelFT_toScint); MyFill(table,"anodeRelTime_toScint_Cut",1000,-3000,3500,anodeRelFT_toScint);
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; Double_t sabreRelRT = ev.sabreRingTime[i] - ev.anodeBackTime;
Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime; Double_t sabreRelWT = ev.sabreWedgeTime[i] - ev.anodeBackTime;
MyFill("sabreRelRingTime_Cut",1000,-3000,3500, sabreRelRT); MyFill(table,"sabreRelRingTime_Cut",1000,-3000,3500, sabreRelRT);
MyFill("sabreRelWedgeTime_Cut",1000,-3000,3500, sabreRelWT); MyFill(table,"sabreRelWedgeTime_Cut",1000,-3000,3500, sabreRelWT);
} }
} }
} else { }
MyFill("noscinttime_counter_Cut",2,0,1,1); else
{
MyFill(table,"noscinttime_counter_Cut",2,0,1,1);
} }
int count = 0; for(int i=0; i<5; i++)
for(int i=0; i<5; i++) { {
if(ev.sabreRingE[i] != -1) { if(ev.sabreRingE[i] != -1)
MyFill("sabreRingE_Cut",2000,0,20,ev.sabreRingE[i]); {
MyFill("xavg_Cut_sabrefcoinc",600,-300,300,ev.xavg); MyFill(table,"sabreRingE_Cut",2000,0,20,ev.sabreRingE[i]);
MyFill("xavg_sabreRingE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreRingE[i]); MyFill(table,"xavg_Cut_sabrefcoinc",600,-300,300,ev.xavg);
MyFill("sabreWedgeE_Cut",2000,0,20,ev.sabreWedgeE[i]); MyFill(table,"xavg_sabreRingE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreRingE[i]);
MyFill("xavg_sabreWedgeE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreWedgeE[i]); MyFill(table,"sabreWedgeE_Cut",2000,0,20,ev.sabreWedgeE[i]);
} else { MyFill(table,"xavg_sabreWedgeE_Cut",600,-300,300,ev.xavg,200,0,20,ev.sabreWedgeE[i]);
count++;
}
}
if(count == 80) {
MyFill("xavg_bothplanes_sabreanticoinc_Cut",600,-300,300,ev.xavg);
} }
} }
} }
/*Runs a list of files given from a RunMusher/Collector class*/ /*Runs a list of files given from a RunCollector class*/
void SFPPlotter::Run(vector<TString> files, const string& output) { void SFPPlotter::Run(const std::vector<std::string>& files, const std::string& output)
Chain(files); {
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); chain->SetBranchAddress("event", &event_address);
TFile *outfile = new TFile(output.c_str(), "RECREATE"); THastTable* table = new THashTable();
long blentries = chain->GetEntries(); long blentries = chain->GetEntries();
if(m_pb) SetProgressBar(blentries); if(m_pb)
SetProgressBar(blentries);
cout<<"Total number of events: "<<blentries<<endl; cout<<"Total number of events: "<<blentries<<endl;
long count=0, flush=blentries*0.01, nflushes=0; long count=0, flush_val=blentries*0.01, flush_count=0;
if(flush == 0) flush = 1;
for(long double i=0; i<chain->GetEntries(); i++) { for(long i=0; i<chain->GetEntries(); i++)
{
count++; count++;
if(count == flush) { if(count == flush_val)
{
if(m_pb) { if(m_pb) {
m_pb->Increment(count); m_pb->Increment(count);
gSystem->ProcessEvents(); gSystem->ProcessEvents();
count = 0; count = 0;
} else { } else {
nflushes++; flush_count++;
count=0; count=0;
std::cout<<"\rPercent of data processed: "<<nflushes*10<<"%"<<std::flush; std::cout<<"\rPercent of data processed: "<<flush_count*10<<"%"<<std::flush;
} }
} }
chain->GetEntry(i); chain->GetEntry(i);
@ -267,26 +278,20 @@ void SFPPlotter::Run(vector<TString> files, const string& output) {
cout<<endl; cout<<endl;
outfile->cd(); outfile->cd();
rootObj->Write(); rootObj->Write();
if(cutter.IsValid()) { if(cutter.IsValid())
{
auto clist = cutter.GetCuts(); auto clist = cutter.GetCuts();
for(unsigned int i=0; i<clist.size(); i++) { for(unsigned int i=0; i<clist.size(); i++)
clist[i]->Write(); clist[i]->Write();
} }
}
delete rootObj; delete rootObj;
outfile->Close(); outfile->Close();
delete outfile; delete outfile;
} }
/*Link all files*/
void SFPPlotter::Chain(vector<TString> files) {
for(unsigned int i=0; i<files.size(); i++) {
chain->Add(files[i]);
}
}
void SFPPlotter::SetProgressBar(long total)
void SFPPlotter::SetProgressBar(long total) { {
m_pb->SetMax(total); m_pb->SetMax(total);
m_pb->SetMin(0); m_pb->SetMin(0);
m_pb->SetPosition(0); m_pb->SetPosition(0);

View File

@ -13,57 +13,69 @@
#include "ShiftMap.h" #include "ShiftMap.h"
ShiftMap::ShiftMap() : ShiftMap::ShiftMap() :
m_filename(""), is_set(false) m_filename(""), m_validFlag(false)
{ {
} }
ShiftMap::ShiftMap(const std::string& filename) : ShiftMap::ShiftMap(const std::string& filename) :
m_filename(filename), is_set(false) m_filename(filename), m_validFlag(false)
{ {
ParseFile(); ParseFile();
} }
ShiftMap::~ShiftMap() {} ShiftMap::~ShiftMap() {}
void ShiftMap::SetFile(const std::string& filename) { void ShiftMap::SetFile(const std::string& filename)
{
m_filename = filename; m_filename = filename;
ParseFile(); ParseFile();
} }
Long64_t ShiftMap::GetShift(int gchan) { uint64_t ShiftMap::GetShift(int gchan)
if(!is_set) return 0.0; {
if(!m_validFlag)
return 0;
auto iter = m_map.find(gchan); auto iter = m_map.find(gchan);
if(iter == m_map.end()) { if(iter == m_map.end())
return 0.0; return 0;
} else return iter->second; else
return iter->second;
} }
void ShiftMap::ParseFile() { void ShiftMap::ParseFile()
{
m_validFlag = false;
std::ifstream input(m_filename); std::ifstream input(m_filename);
if(!input.is_open()) return; if(!input.is_open())
return;
int board, channel, gchan; int board, channel, gchan;
Long64_t shift; uint64_t shift;
std::string junk, temp; std::string junk, temp;
std::getline(input, junk); std::getline(input, junk);
std::getline(input, junk); std::getline(input, junk);
while(input>>board) { while(input>>board)
{
input>>temp; input>>temp;
input>>shift; input>>shift;
if(temp == "all") { //keyword to set all channels in this board to same shift if(temp == "all") //keyword to set all channels in this board to same shift
for(int i=0; i<16; i++) { {
for(int i=0; i<16; i++)
{
gchan = board*16 + i; gchan = board*16 + i;
m_map[gchan] = shift; m_map[gchan] = shift;
} }
} else { }
else
{
channel = stoi(temp); channel = stoi(temp);
gchan = channel + board*16; gchan = channel + board*16;
m_map[gchan] = shift; m_map[gchan] = shift;
} }
} }
is_set = true; m_validFlag = true;
} }

View File

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

View File

@ -1,9 +1,11 @@
#include "EventBuilder.h" #include "EventBuilder.h"
#include "GWMEventBuilder.h" #include "EVBApp.h"
#include "Stopwatch.h" #include "Stopwatch.h"
int main(int argc, char** argv) { int main(int argc, char** argv)
if(argc != 3) { {
if(argc != 3)
{
std::cerr<<"Incorrect number of command line arguments!"<<std::endl; std::cerr<<"Incorrect number of command line arguments!"<<std::endl;
std::cerr<<"Need to specify type of operation (buildSlow, buildFast, etc.) and input file."<<std::endl; std::cerr<<"Need to specify type of operation (buildSlow, buildFast, etc.) and input file."<<std::endl;
return 1; return 1;
@ -14,46 +16,40 @@ int main(int argc, char** argv) {
/* DEFAULT Operation Types: /* DEFAULT Operation Types:
convert (convert binary archive to root data) Convert (convert binary archive to root data)
convertSlow (convert binary arhcive to event slow data) ConvertSlow (convert binary arhcive to event slow data)
convertFast (convert binary archive to event fast data) ConvertFast (convert binary archive to event fast data)
convertSlowA (convert binary archive to analyzed slow event data) ConvertSlowA (convert binary archive to analyzed slow event data)
convertFastA (convert binary archive to analyzed fast event data) ConvertFastA (convert binary archive to analyzed fast event data)
merge (combine root files) Merge (combine root files)
plot (generate a default histogram file from analyzed data) Plot (generate a default histogram file from analyzed data)
*/ */
GWMEventBuilder theBuilder; EVBApp theBuilder;
if(!theBuilder.ReadConfigFile(filename)) {
return 1; return 1;
}
Stopwatch timer; Stopwatch timer;
timer.Start(); timer.Start();
if(operation == "convert") { if(operation == "Convert")
theBuilder.SetAnalysisType(GWMEventBuilder::CONVERT);
theBuilder.Convert2RawRoot(); theBuilder.Convert2RawRoot();
} else if(operation == "merge") { else if(operation == "Merge")
theBuilder.SetAnalysisType(GWMEventBuilder::MERGE);
theBuilder.MergeROOTFiles(); theBuilder.MergeROOTFiles();
} else if(operation == "plot") { else if(operation == "Plot")
theBuilder.SetAnalysisType(GWMEventBuilder::PLOT);
theBuilder.PlotHistograms(); theBuilder.PlotHistograms();
} else if (operation == "convertSlow"){ else if (operation == "ConvertSlow")
theBuilder.SetAnalysisType(GWMEventBuilder::CONVERT_S);
theBuilder.Convert2SortedRoot(); theBuilder.Convert2SortedRoot();
} else if (operation == "convertFast"){ else if (operation == "ConvertFast")
theBuilder.SetAnalysisType(GWMEventBuilder::CONVERT_F);
theBuilder.Convert2FastSortedRoot(); theBuilder.Convert2FastSortedRoot();
} else if (operation == "convertSlowA"){ else if (operation == "ConvertSlowA")
theBuilder.SetAnalysisType(GWMEventBuilder::CONVERT_SA);
theBuilder.Convert2SlowAnalyzedRoot(); theBuilder.Convert2SlowAnalyzedRoot();
} else if (operation == "convertFastA"){ else if (operation == "ConvertFastA")
theBuilder.SetAnalysisType(GWMEventBuilder::CONVERT_FA);
theBuilder.Convert2FastAnalyzedRoot(); theBuilder.Convert2FastAnalyzedRoot();
} else { else
{
std::cerr<<"Unidentified type of operation! Check your first argument."<<std::endl; std::cerr<<"Unidentified type of operation! Check your first argument."<<std::endl;
return 1; return 1;
} }
timer.Stop(); timer.Stop();
std::cout<<"Elapsed time (ms): "<<timer.GetElapsedMilliseconds()<<std::endl; std::cout<<"Elapsed time (ms): "<<timer.GetElapsedMilliseconds()<<std::endl;