2021-07-13 16:36:41 -04:00
|
|
|
#include "EventBuilder.h"
|
|
|
|
#include "CutHandler.h"
|
|
|
|
|
|
|
|
CutHandler::CutHandler() :
|
|
|
|
validFlag(false)
|
|
|
|
{
|
|
|
|
InitVariableMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
CutHandler::CutHandler(const std::string& filename) :
|
|
|
|
validFlag(false)
|
|
|
|
{
|
|
|
|
SetCuts(filename);
|
|
|
|
InitVariableMap();
|
|
|
|
}
|
|
|
|
|
2021-12-13 12:28:56 -05:00
|
|
|
CutHandler::~CutHandler()
|
|
|
|
{
|
|
|
|
for(unsigned int i=0; i<file_array.size(); i++)
|
|
|
|
if(file_array[i]->IsOpen())
|
|
|
|
file_array[i]->Close();
|
2021-07-13 16:36:41 -04:00
|
|
|
}
|
|
|
|
|
2021-12-13 12:28:56 -05:00
|
|
|
void CutHandler::SetCuts(const std::string& filename)
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
std::ifstream cutlist(filename);
|
|
|
|
|
2021-12-13 12:28:56 -05:00
|
|
|
if(!cutlist.is_open())
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
validFlag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string junk, name, fname, varx, vary;
|
|
|
|
cutlist>>junk>>junk>>junk>>junk;
|
|
|
|
|
|
|
|
cut_array.clear();
|
|
|
|
file_array.clear();
|
|
|
|
|
2021-12-13 12:28:56 -05:00
|
|
|
while(cutlist>>name)
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
cutlist>>fname>>varx>>vary;
|
|
|
|
TFile* file = TFile::Open(fname.c_str(), "READ");
|
|
|
|
TCutG* cut = (TCutG*) file->Get("CUTG");
|
2021-12-13 12:28:56 -05:00
|
|
|
if(cut)
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
cut->SetVarX(varx.c_str());
|
|
|
|
cut->SetVarY(vary.c_str());
|
|
|
|
cut->SetName(name.c_str());
|
|
|
|
cut_array.push_back(cut);
|
|
|
|
file_array.push_back(file);
|
2021-12-13 12:28:56 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
validFlag = false;
|
|
|
|
std::cerr<<"CutHandler has encountered a bad cut at file: "<<file<<"."<<std::endl;
|
|
|
|
std::cerr<<"The file either does not exist or does not contain a TCutG named CUTG"<<std::endl;
|
|
|
|
std::cerr<<"Cuts will not be used."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 12:28:56 -05:00
|
|
|
if(cut_array.size() > 0)
|
2021-08-03 10:06:43 -04:00
|
|
|
validFlag = true;
|
2021-12-13 12:28:56 -05:00
|
|
|
else
|
2021-08-03 10:06:43 -04:00
|
|
|
validFlag = false;
|
2021-07-13 16:36:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ADD MORE VARIABLES HERE!
|
|
|
|
*/
|
2021-12-13 12:28:56 -05:00
|
|
|
void CutHandler::InitVariableMap()
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
varmap["x1"] = &m_event.x1;
|
|
|
|
varmap["x2"] = &m_event.x2;
|
|
|
|
varmap["xavg"] = &m_event.xavg;
|
|
|
|
varmap["scintLeft"] = &m_event.scintLeft;
|
|
|
|
varmap["anodeBack"] = &m_event.anodeBack;
|
|
|
|
varmap["cathode"] = &m_event.cathode;
|
|
|
|
}
|
|
|
|
|
2021-12-13 17:04:44 -05:00
|
|
|
bool CutHandler::IsInside(const ProcessedEvent* eaddress)
|
2021-12-13 12:28:56 -05:00
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
m_event = *eaddress;
|
|
|
|
std::string x, y;
|
2021-12-13 12:28:56 -05:00
|
|
|
for(unsigned int i=0; i<cut_array.size(); i++)
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
TCutG* cut = cut_array[i];
|
|
|
|
x = cut->GetVarX();
|
|
|
|
y = cut->GetVarY();
|
|
|
|
auto xentry = varmap.find(x);
|
|
|
|
auto yentry = varmap.find(y);
|
2021-12-13 12:28:56 -05:00
|
|
|
if(xentry == varmap.end() || yentry == varmap.end())
|
|
|
|
{
|
2021-07-13 16:36:41 -04:00
|
|
|
std::cerr<<"Unmapped variable called in CutHandler::IsInside()! Var names: "<<xentry->first<<" , "<<yentry->first<<std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-13 12:28:56 -05:00
|
|
|
if(!cut->IsInside(*(xentry->second), *(yentry->second)))
|
2021-07-13 16:36:41 -04:00
|
|
|
return false;
|
2021-12-13 12:28:56 -05:00
|
|
|
|
2021-07-13 16:36:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|