mirror of
https://github.com/gwm17/SabreCal.git
synced 2024-11-22 18:18:52 -05:00
Fleshed out project. Needs testing
This commit is contained in:
parent
87c674d487
commit
19ccc3610d
36
src/CalDict/cal_dict.cxx_tmp_3535
Normal file
36
src/CalDict/cal_dict.cxx_tmp_3535
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Do NOT change. Changes will be lost next time file is generated
|
||||
|
||||
#define R__DICTIONARY_FILENAME srcdICalDictdIcal_dict
|
||||
#define R__NO_DEPRECATION
|
||||
|
||||
/*******************************************************************/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#define G__DICTIONARY
|
||||
#include "RConfig.h"
|
||||
#include "TClass.h"
|
||||
#include "TDictAttributeMap.h"
|
||||
#include "TInterpreter.h"
|
||||
#include "TROOT.h"
|
||||
#include "TBuffer.h"
|
||||
#include "TMemberInspector.h"
|
||||
#include "TInterpreter.h"
|
||||
#include "TVirtualMutex.h"
|
||||
#include "TError.h"
|
||||
|
||||
#ifndef G__ROOT
|
||||
#define G__ROOT
|
||||
#endif
|
||||
|
||||
#include "RtypesImp.h"
|
||||
#include "TIsAProxy.h"
|
||||
#include "TFileMergeInfo.h"
|
||||
#include <algorithm>
|
||||
#include "TCollectionProxyInfo.h"
|
||||
/*******************************************************************/
|
||||
|
||||
#include "TDataMember.h"
|
||||
|
36
src/CalDict/cal_dict.cxx_tmp_3544
Normal file
36
src/CalDict/cal_dict.cxx_tmp_3544
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Do NOT change. Changes will be lost next time file is generated
|
||||
|
||||
#define R__DICTIONARY_FILENAME srcdICalDictdIcal_dict
|
||||
#define R__NO_DEPRECATION
|
||||
|
||||
/*******************************************************************/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#define G__DICTIONARY
|
||||
#include "RConfig.h"
|
||||
#include "TClass.h"
|
||||
#include "TDictAttributeMap.h"
|
||||
#include "TInterpreter.h"
|
||||
#include "TROOT.h"
|
||||
#include "TBuffer.h"
|
||||
#include "TMemberInspector.h"
|
||||
#include "TInterpreter.h"
|
||||
#include "TVirtualMutex.h"
|
||||
#include "TError.h"
|
||||
|
||||
#ifndef G__ROOT
|
||||
#define G__ROOT
|
||||
#endif
|
||||
|
||||
#include "RtypesImp.h"
|
||||
#include "TIsAProxy.h"
|
||||
#include "TFileMergeInfo.h"
|
||||
#include <algorithm>
|
||||
#include "TCollectionProxyInfo.h"
|
||||
/*******************************************************************/
|
||||
|
||||
#include "TDataMember.h"
|
||||
|
36
src/CalDict/cal_dict.cxx_tmp_3665
Normal file
36
src/CalDict/cal_dict.cxx_tmp_3665
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Do NOT change. Changes will be lost next time file is generated
|
||||
|
||||
#define R__DICTIONARY_FILENAME srcdICalDictdIcal_dict
|
||||
#define R__NO_DEPRECATION
|
||||
|
||||
/*******************************************************************/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#define G__DICTIONARY
|
||||
#include "RConfig.h"
|
||||
#include "TClass.h"
|
||||
#include "TDictAttributeMap.h"
|
||||
#include "TInterpreter.h"
|
||||
#include "TROOT.h"
|
||||
#include "TBuffer.h"
|
||||
#include "TMemberInspector.h"
|
||||
#include "TInterpreter.h"
|
||||
#include "TVirtualMutex.h"
|
||||
#include "TError.h"
|
||||
|
||||
#ifndef G__ROOT
|
||||
#define G__ROOT
|
||||
#endif
|
||||
|
||||
#include "RtypesImp.h"
|
||||
#include "TIsAProxy.h"
|
||||
#include "TFileMergeInfo.h"
|
||||
#include <algorithm>
|
||||
#include "TCollectionProxyInfo.h"
|
||||
/*******************************************************************/
|
||||
|
||||
#include "TDataMember.h"
|
||||
|
52
src/CalibrationMap.cpp
Normal file
52
src/CalibrationMap.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "CalibrationMap.h"
|
||||
#include <fstream>
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
CalibrationMap::CalibrationMap() :
|
||||
m_isValid(false)
|
||||
{
|
||||
}
|
||||
|
||||
CalibrationMap::CalibrationMap(const std::string& filename) :
|
||||
m_isValid(false)
|
||||
{
|
||||
Init(filename);
|
||||
}
|
||||
|
||||
CalibrationMap::~CalibrationMap() {}
|
||||
|
||||
void CalibrationMap::Init(const std::string &filename)
|
||||
{
|
||||
std::ifstream input(filename);
|
||||
if(!input.is_open())
|
||||
{
|
||||
m_isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string junk;
|
||||
int gchan;
|
||||
Parameters params;
|
||||
|
||||
std::getline(input, junk);
|
||||
std::getline(input, junk);
|
||||
|
||||
while(input>>gchan)
|
||||
{
|
||||
input>>params.slope>>params.offset;
|
||||
m_map[gchan] = params;
|
||||
}
|
||||
|
||||
m_isValid = true;
|
||||
}
|
||||
|
||||
const Parameters& CalibrationMap::GetParameters(int gchan) const
|
||||
{
|
||||
auto iter = m_map.find(gchan);
|
||||
if(iter != m_map.end())
|
||||
return iter->second;
|
||||
else
|
||||
return m_dummyParams;
|
||||
}
|
||||
}
|
29
src/CalibrationMap.h
Normal file
29
src/CalibrationMap.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef CALIBRATION_MAP_H
|
||||
#define CALIBRATION_MAP_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "CalibrationStructs.h"
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
class CalibrationMap
|
||||
{
|
||||
public:
|
||||
CalibrationMap();
|
||||
CalibrationMap(const std::string& filename);
|
||||
~CalibrationMap();
|
||||
|
||||
void Init(const std::string& filename);
|
||||
|
||||
const Parameters& GetParameters(int gchan) const;
|
||||
inline const bool IsValid() const { return m_isValid; }
|
||||
|
||||
private:
|
||||
bool m_isValid;
|
||||
std::unordered_map<int, Parameters> m_map;
|
||||
Parameters m_dummyParams; //for null result
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
160
src/Calibrator.cpp
Normal file
160
src/Calibrator.cpp
Normal file
|
@ -0,0 +1,160 @@
|
|||
#include "Calibrator.h"
|
||||
#include "TFile.h"
|
||||
#include "TTree.h"
|
||||
#include "DataStructs.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "TSpectrum.h"
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
Calibrator::Calibrator(const std::string& gainfile) :
|
||||
m_gainMap(gainfile)
|
||||
{
|
||||
TH1::AddDirectory(kFALSE);
|
||||
}
|
||||
|
||||
Calibrator::~Calibrator() {}
|
||||
|
||||
void Calibrator::Run(const std::string& datafile, const std::string& outputfile, const std::string& plotfile)
|
||||
{
|
||||
if(!m_gainMap.IsValid())
|
||||
{
|
||||
std::cerr<<"ERR -- Bad gain map at Calibrator::Run!"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
TFile* input = TFile::Open(datafile.c_str(), "READ");
|
||||
if(!input->IsOpen())
|
||||
{
|
||||
std::cerr<<"ERR -- Bad data file "<<datafile<<" at Calibrator::Run!"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
TTree* tree = (TTree*) input->Get("Data");
|
||||
uint16_t energy, board, channel;
|
||||
tree->SetBranchAddress("Energy", &energy);
|
||||
tree->SetBranchAddress("Board", &board);
|
||||
tree->SetBranchAddress("Channel", &channel);
|
||||
|
||||
int gchan;
|
||||
|
||||
uint64_t nentries = tree->GetEntries();
|
||||
float flush_percent = 0.1f;
|
||||
uint64_t count=0, flush_count=0, flush_val=nentries*flush_percent;
|
||||
|
||||
std::vector<TH1F> histograms;
|
||||
for(int i=0; i<s_totalChannels; i++)
|
||||
{
|
||||
std::string name = "channel"+std::to_string(i);
|
||||
histograms.emplace_back(name.c_str(), name.c_str(), 16384, 0.0, 16384.0);
|
||||
}
|
||||
|
||||
for(uint64_t i=0; i<nentries; i++)
|
||||
{
|
||||
tree->GetEntry(i);
|
||||
count++;
|
||||
if(count == flush_val)
|
||||
{
|
||||
flush_count++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent of data processed: "<<flush_count*flush_percent*100.0<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
gchan = board*16 + channel; //Global channel (16 channels per board)
|
||||
auto& params = m_gainMap.GetParameters(gchan);
|
||||
|
||||
if(energy > 100.0) //Reject electronic noise
|
||||
histograms[i].Fill(params.slope*(energy*s_gainFactor) + params.offset);
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
input->Close();
|
||||
|
||||
std::cout<<"Finding calibration parameters..."<<std::endl;
|
||||
FindParameters(histograms);
|
||||
std::cout<<"Writing to disk..."<<std::endl;
|
||||
WriteHistograms(histograms, plotfile);
|
||||
WriteParameters(outputfile);
|
||||
}
|
||||
|
||||
void Calibrator::FindParameters(const std::vector<TH1F>& grams)
|
||||
{
|
||||
TSpectrum finder;
|
||||
double threshold = 0.5;
|
||||
double sigma = 5.0;
|
||||
|
||||
Parameters these_params;
|
||||
double peakMean;
|
||||
|
||||
for(auto& histo : grams)
|
||||
{
|
||||
finder.Search(&histo, sigma, "nobackground", threshold);
|
||||
if(finder.GetNPeaks() == 0)
|
||||
{
|
||||
std::cerr<<"No peaks found in histogram "<<histo.GetName()<<std::endl;
|
||||
m_params.push_back(Parameters());
|
||||
}
|
||||
else if(finder.GetNPeaks() > 1)
|
||||
{
|
||||
peakMean = 0.0;
|
||||
double peakAmp = 0.0;
|
||||
std::cerr<<"Multiple peaks found in histogram "<<histo.GetName();
|
||||
std::cerr<<"Keeping the largest peak."<<std::endl;
|
||||
double mean, amp;
|
||||
for(int i=0; i<finder.GetNPeaks(); i++)
|
||||
{
|
||||
mean = finder.GetPositionX()[i];
|
||||
amp = finder.GetPositionY()[i];
|
||||
if(amp > peakAmp)
|
||||
{
|
||||
peakMean = mean;
|
||||
peakAmp = amp;
|
||||
}
|
||||
}
|
||||
these_params.slope = s_241Am_alphaKE/peakMean;
|
||||
these_params.offset = 0.0;
|
||||
m_params.push_back(these_params);
|
||||
}
|
||||
else
|
||||
{
|
||||
peakMean = finder.GetPositionX()[0];
|
||||
these_params.slope = s_241Am_alphaKE/peakMean;
|
||||
these_params.offset = 0.0;
|
||||
m_params.push_back(these_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Calibrator::WriteHistograms(const std::vector<TH1F> &grams, const std::string &plotfile)
|
||||
{
|
||||
TFile* output = TFile::Open(plotfile.c_str(), "RECREATE");
|
||||
if(!output->IsOpen())
|
||||
{
|
||||
std::cerr<<"Unable to open file "<<plotfile<<" for saving histograms"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for(auto& histo : grams)
|
||||
{
|
||||
histo.Write();
|
||||
}
|
||||
|
||||
output->Close();
|
||||
}
|
||||
|
||||
void Calibrator::WriteParameters(const std::string &outputfile)
|
||||
{
|
||||
std::ofstream output(outputfile);
|
||||
if(!output.is_open())
|
||||
{
|
||||
std::cerr<<"Unable to open file "<<outputfile<<" for saving parameters"<<std::endl;
|
||||
return;
|
||||
}
|
||||
output<<"Channel Slope Offset"<<std::endl;
|
||||
for(size_t i=0; i<m_params.size(); i++)
|
||||
{
|
||||
output<<i<<" "<<m_params[i].slope<<" "<<m_params[i].offset<<std::endl;
|
||||
}
|
||||
output.close();
|
||||
}
|
||||
}
|
36
src/Calibrator.h
Normal file
36
src/Calibrator.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef CALIBRATOR_H
|
||||
#define CALIBRATOR_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ChannelMap.h"
|
||||
#include "GainMap.h"
|
||||
#include "CalibrationStructs.h"
|
||||
|
||||
#include "TH1.h"
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
class Calibrator
|
||||
{
|
||||
public:
|
||||
Calibrator(const std::string& gainfile);
|
||||
~Calibrator();
|
||||
|
||||
void Run(const std::string& datafile, const std::string& outputfile, const std::string& plotfile="");
|
||||
|
||||
private:
|
||||
void FindParameters(const std::vector<TH1F>& grams);
|
||||
void WriteHistograms(const std::vector<TH1F>& grams, const std::string& plotfile);
|
||||
void WriteParameters(const std::string& outputfile);
|
||||
|
||||
GainMap m_gainMap;
|
||||
std::vector<Parameters> m_params;
|
||||
|
||||
static constexpr int s_totalChannels = 127; //Total channels in SABRE
|
||||
static constexpr double s_241Am_alphaKE = 5.468; //MeV
|
||||
static constexpr double s_gainFactor = 1.5; //For if you're dumb and the electronics gain needs adjusted
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* Calibrator_hpp */
|
163
src/DataOrganizer.cpp
Normal file
163
src/DataOrganizer.cpp
Normal file
|
@ -0,0 +1,163 @@
|
|||
#include "DataOrganizer.h"
|
||||
#include "TFile.h"
|
||||
#include "TTree.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
DataOrganizer::DataOrganizer(const std::string& channelfile, const std::string& gainfile,
|
||||
const std::string& calfile) :
|
||||
m_channelMap(channelfile), m_gainMap(gainfile), m_calMap(calfile)
|
||||
{
|
||||
}
|
||||
|
||||
DataOrganizer::~DataOrganizer() {}
|
||||
|
||||
void DataOrganizer::Run(const std::string& inputdata, const std::string& outputdata)
|
||||
{
|
||||
if(!(m_channelMap.IsValid() && m_gainMap.IsValid() && m_calMap.IsValid()))
|
||||
{
|
||||
std::cerr<<"ERR -- Invalid map files at DataOrganizer::Run()"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
TFile* input = TFile::Open(inputdata.c_str(), "READ");
|
||||
if(!input->IsOpen())
|
||||
{
|
||||
std::cerr<<"ERR -- Unable to open input data file "<<inputdata<<" at DataOrganizer::Run()"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
TTree* intree = (TTree*) input->Get("SPSTree");
|
||||
|
||||
TFile* output = TFile::Open(outputdata.c_str(), "RECREATE");
|
||||
if(!output->IsOpen())
|
||||
{
|
||||
std::cerr<<"ERR -- Unable to open output data file "<<inputdata<<" at DataOrganizer::Run()"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
TTree* outtree = new TTree("CalTree", "CalTree");
|
||||
|
||||
ProcessedEvent* inevent = new ProcessedEvent();
|
||||
intree->SetBranchAddress("event", &inevent);
|
||||
|
||||
CalEvent outevent;
|
||||
outtree->Branch("event", &outevent);
|
||||
|
||||
std::vector<SabreTemp> rings, wedges;
|
||||
double eTemp;
|
||||
double ratio;
|
||||
SabrePair this_pair;
|
||||
|
||||
uint64_t nevents = intree->GetEntries();
|
||||
m_stats.totalEvents = nevents;
|
||||
double flush_percent = 0.05;
|
||||
uint64_t count=0, flush_count=0, flush_val=nevents*flush_percent;
|
||||
|
||||
for(uint64_t i=0; i<nevents; i++)
|
||||
{
|
||||
intree->GetEvent(i);
|
||||
count++;
|
||||
if(count == flush_val)
|
||||
{
|
||||
flush_count++;
|
||||
count = 0;
|
||||
std::cout<<"\rPercent of data processed: "<<flush_count*flush_percent*100.0<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
//copy FP crap
|
||||
outevent.xavg = inevent->xavg;
|
||||
outevent.scintE = inevent->scintLeft;
|
||||
outevent.cathodeE = inevent->cathode;
|
||||
outevent.anodeFrontE = inevent->anodeFront;
|
||||
outevent.anodeBackE = inevent->anodeBack;
|
||||
outevent.scintT = inevent->scintLeftTime;
|
||||
|
||||
for(int j=0; j<5; j++)
|
||||
{
|
||||
rings.clear();
|
||||
wedges.clear();
|
||||
auto& this_sabre = inevent->sabreArray[j];
|
||||
|
||||
int64_t diff = this_sabre.rings.size() - this_sabre.wedges.size();
|
||||
m_stats.sabreRingFrags += diff > 0 ? diff : 0;
|
||||
m_stats.sabreWedgeFrags += diff < 0 ? -1*diff : 0;
|
||||
for(auto& ring : this_sabre.rings)
|
||||
{
|
||||
m_stats.totalSabreHits++;
|
||||
auto& ringGains = m_gainMap.GetParameters(ring.Ch);
|
||||
auto& ringCals = m_calMap.GetParameters(ring.Ch);
|
||||
eTemp = ringCals.slope*(ringGains.slope*ring.Long + ringGains.offset) + ringCals.offset;
|
||||
if(eTemp > s_sabreThreshold)
|
||||
{
|
||||
m_stats.goodSabreHits++;
|
||||
rings.emplace_back(eTemp, ring.Time, ring.Ch, false);
|
||||
}
|
||||
else
|
||||
m_stats.sabreBelowThreshold++;
|
||||
}
|
||||
for(auto& wedge : this_sabre.wedges)
|
||||
{
|
||||
m_stats.totalSabreHits++;
|
||||
auto& wedgeGains = m_gainMap.GetParameters(wedge.Ch);
|
||||
auto& wedgeCals = m_calMap.GetParameters(wedge.Ch);
|
||||
eTemp = wedgeCals.slope*(wedgeGains.slope*wedge.Long + wedgeGains.offset) + wedgeCals.offset;
|
||||
if(eTemp > s_sabreThreshold)
|
||||
{
|
||||
m_stats.goodSabreHits++;
|
||||
wedges.emplace_back(eTemp, wedge.Time, wedge.Ch, false);
|
||||
}
|
||||
else
|
||||
m_stats.sabreBelowThreshold++;
|
||||
}
|
||||
|
||||
//Now match rings and wedges
|
||||
for(auto& ring : rings)
|
||||
{
|
||||
for(auto& wedge : wedges)
|
||||
{
|
||||
if(wedge.used || ring.used)
|
||||
continue;
|
||||
ratio = std::abs(1.0 - ring.energy/wedge.energy);
|
||||
if(ratio < s_sabreMatchCond)
|
||||
{
|
||||
auto& ringdata = m_channelMap.GetChannel(ring.gchan);
|
||||
auto& wedgedata = m_channelMap.GetChannel(wedge.gchan);
|
||||
this_pair.ringch = ring.gchan;
|
||||
this_pair.wedgech = wedge.gchan;
|
||||
this_pair.local_ring = ringdata.localChannel;
|
||||
this_pair.local_wedge = wedgedata.localChannel;
|
||||
this_pair.detID = wedgedata.detID;
|
||||
this_pair.ringE = ring.energy;
|
||||
this_pair.wedgeE = wedge.energy;
|
||||
outevent.sabre.push_back(this_pair);
|
||||
m_stats.pairsMade++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
outtree->Fill();
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
|
||||
input->Close();
|
||||
output->cd();
|
||||
outtree->Write(outtree->GetName(), TObject::kOverwrite);
|
||||
output->Close();
|
||||
}
|
||||
|
||||
void DataOrganizer::ShowStats()
|
||||
{
|
||||
std::cout<<"Total number of events: "<<m_stats.totalEvents<<std::endl;
|
||||
std::cout<<"Total number of SABRE hits: "<<m_stats.totalSabreHits<<std::endl;
|
||||
std::cout<<"Total number of good SABRE hits: "<<m_stats.goodSabreHits<<std::endl;
|
||||
std::cout<<"Number of ring/wedge pairs made: "<<m_stats.pairsMade<<std::endl;
|
||||
std::cout<<"Matching efficiency percentage: "<<((double)m_stats.pairsMade)/m_stats.goodSabreHits<<std::endl;
|
||||
std::cout<<"Number of hits below threshold: "<<m_stats.sabreBelowThreshold<<std::endl;
|
||||
std::cout<<"Number of wedge fragments: "<<m_stats.sabreWedgeFrags<<std::endl;
|
||||
std::cout<<"Number of ring fragments: "<<m_stats.sabreRingFrags<<std::endl;
|
||||
}
|
||||
}
|
58
src/DataOrganizer.h
Normal file
58
src/DataOrganizer.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
#ifndef DATA_ORGANIZER_H
|
||||
#define DATA_ORGANIZER_H
|
||||
|
||||
#include "ChannelMap.h"
|
||||
#include "GainMap.h"
|
||||
#include "CalibrationMap.h"
|
||||
|
||||
#include "CalDict/DataStructs.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
struct AnalysisStats
|
||||
{
|
||||
uint64_t totalEvents = 0;
|
||||
uint64_t totalSabreHits = 0;
|
||||
uint64_t goodSabreHits = 0; //Above threshold, good number for matching
|
||||
uint64_t pairsMade = 0;
|
||||
uint64_t sabreRingFrags = 0;
|
||||
uint64_t sabreWedgeFrags = 0;
|
||||
uint64_t sabreBelowThreshold = 0;
|
||||
};
|
||||
|
||||
struct SabreTemp
|
||||
{
|
||||
SabreTemp(double e, double t, int g, bool u) :
|
||||
energy(e), time(t), gchan(g), used(u)
|
||||
{}
|
||||
double energy;
|
||||
double time;
|
||||
int gchan;
|
||||
bool used = false;
|
||||
};
|
||||
|
||||
class DataOrganizer
|
||||
{
|
||||
public:
|
||||
DataOrganizer(const std::string& channelfile, const std::string& gainfile, const std::string& calfile);
|
||||
~DataOrganizer();
|
||||
|
||||
void Run(const std::string& inputdata, const std::string& outputdata);
|
||||
void ShowStats();
|
||||
|
||||
private:
|
||||
ChannelMap m_channelMap;
|
||||
GainMap m_gainMap;
|
||||
CalibrationMap m_calMap;
|
||||
|
||||
AnalysisStats m_stats;
|
||||
|
||||
static constexpr double s_sabreMatchCond = 0.2; //Ring/wedge %diff
|
||||
static constexpr double s_sabreThreshold = 0.2; //MeV
|
||||
static constexpr double s_sabreTimeCond = 100.0; //ns
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
51
src/GainMap.cpp
Normal file
51
src/GainMap.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "GainMap.h"
|
||||
#include <fstream>
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
GainMap::GainMap() :
|
||||
m_isValid(false)
|
||||
{
|
||||
}
|
||||
|
||||
GainMap::GainMap(const std::string& filename) :
|
||||
m_isValid(false)
|
||||
{
|
||||
Init(filename);
|
||||
}
|
||||
|
||||
GainMap::~GainMap() {}
|
||||
|
||||
void GainMap::Init(const std::string& filename)
|
||||
{
|
||||
std::ifstream input(filename);
|
||||
if(!input.is_open())
|
||||
{
|
||||
m_isValid = false;
|
||||
return;
|
||||
}
|
||||
std::string junk;
|
||||
int gchan;
|
||||
Parameters pars;
|
||||
|
||||
std::getline(input, junk);
|
||||
std::getline(input, junk);
|
||||
|
||||
while(input>>gchan)
|
||||
{
|
||||
input>>pars.slope>>pars.offset;
|
||||
m_map[gchan] = pars;
|
||||
}
|
||||
|
||||
m_isValid = true;
|
||||
}
|
||||
|
||||
const Parameters& GainMap::GetParameters(int gchan) const
|
||||
{
|
||||
auto iter = m_map.find(gchan);
|
||||
if(iter != m_map.end())
|
||||
return iter->second;
|
||||
else
|
||||
return m_dummyParams;
|
||||
}
|
||||
}
|
30
src/GainMap.h
Normal file
30
src/GainMap.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef GAIN_MAP_H
|
||||
#define GAIN_MAP_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "CalibrationStructs.h"
|
||||
|
||||
namespace SabreCal {
|
||||
|
||||
class GainMap
|
||||
{
|
||||
public:
|
||||
GainMap();
|
||||
GainMap(const std::string& filename);
|
||||
~GainMap();
|
||||
|
||||
void Init(const std::string& filename);
|
||||
|
||||
const Parameters& GetParameters(int gchan) const;
|
||||
inline const bool IsValid() const { return m_isValid; }
|
||||
|
||||
private:
|
||||
std::unordered_map<int, Parameters> m_map;
|
||||
Parameters m_dummyParams; //for null results
|
||||
|
||||
bool m_isValid;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -50,7 +50,7 @@ namespace SabreCal {
|
|||
{
|
||||
count = 0;
|
||||
flushes++;
|
||||
std::cout<<"\rPercent of data processed: "<<flush_percent*flushes*100.0f<<"%"<<std::endl;
|
||||
std::cout<<"\rPercent of data processed: "<<flush_percent*flushes*100.0f<<"%"<<std::flush;
|
||||
}
|
||||
|
||||
for(int j=0; j<5; j++)
|
||||
|
@ -104,7 +104,7 @@ namespace SabreCal {
|
|||
graph_array.resize(m_totalChannels);
|
||||
|
||||
//Make all of the wedge graphs, and get the gain match parameters
|
||||
for(size_t i=0; i<m_firstRing; i++)
|
||||
for(int i=0; i<m_firstRing; i++)
|
||||
{
|
||||
if(m_data[i].x.size() != 0)
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ namespace SabreCal {
|
|||
}
|
||||
|
||||
//Now do rings, after applying parameters from wedges
|
||||
for(size_t i=m_firstRing; i<m_totalChannels; i++)
|
||||
for(int i=m_firstRing; i<m_totalChannels; i++)
|
||||
{
|
||||
if(m_data[i].x.size() != 0)
|
||||
{
|
||||
|
@ -179,4 +179,4 @@ namespace SabreCal {
|
|||
output.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
136
src/main.cpp
Normal file
136
src/main.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
#include "GainMatcher.h"
|
||||
#include "Calibrator.h"
|
||||
#include "DataOrganizer.h"
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
std::string inputfile;
|
||||
std::string option;
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr<<"ERR -- SabreCal requires an input configuration file."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if(std::string(argv[1]) == "--help")
|
||||
{
|
||||
std::cout<<"SABRE Calibration Help"<<std::endl;
|
||||
std::cout<<"To run: ./bin/SabreCal <option> <input config>"<<std::endl;
|
||||
std::cout<<"Available Options"<<std::endl;
|
||||
std::cout<<"--gainmatch: Only run gain-matching"<<std::endl;
|
||||
std::cout<<"--calibrate: Only run calibration (requires gain-matching parameters)"<<std::endl;
|
||||
std::cout<<"--apply: Apply calibration and gain-matching parameters to a dataset (requires gain-matching and calibration parameters)"<<std::endl;
|
||||
std::cout<<"--all: Run gain-matching, calibration, and apply to data set"<<std::endl;
|
||||
std::cout<<"Default behavior (no option) is the same as --all"<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
inputfile = argv[1];
|
||||
option = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
inputfile = argv[2];
|
||||
option = argv[1];
|
||||
}
|
||||
|
||||
std::ifstream input(argv[1]);
|
||||
std::string junk;
|
||||
|
||||
std::string gaindata, caldata, inputdata, outputdata;
|
||||
std::string gainplots, calplots;
|
||||
std::string gainfile, calfile, channelfile;
|
||||
int ring_to_match, wedge_to_match;
|
||||
|
||||
input>>junk>>gaindata;
|
||||
input>>junk>>gainplots;
|
||||
input>>junk>>caldata;
|
||||
input>>junk>>calplots;
|
||||
input>>junk>>inputdata;
|
||||
input>>junk>>outputdata;
|
||||
input>>junk>>gainfile;
|
||||
input>>junk>>calfile;
|
||||
input>>junk>>channelfile;
|
||||
input>>junk>>ring_to_match>>junk>>wedge_to_match;
|
||||
|
||||
std::cout<<"----------SABRE Calibration----------"<<std::endl;
|
||||
std::cout<<"Gain-Matching Data: "<<gaindata<<std::endl;
|
||||
std::cout<<"Gain-Matching Plots: "<<gainplots<<std::endl;
|
||||
std::cout<<"Gain-Match Parameter file: "<<gainfile<<std::endl;
|
||||
std::cout<<"Ring-to-Match: "<<ring_to_match<<" Wedge-to-Match: "<<wedge_to_match<<std::endl;
|
||||
std::cout<<"Calibration Data: "<<caldata<<std::endl;
|
||||
std::cout<<"Calibration Plots: "<<calplots<<std::endl;
|
||||
std::cout<<"Calibration Parameter file: "<<calfile<<std::endl;
|
||||
std::cout<<"Data to Calibrate: "<<inputdata<<std::endl;
|
||||
std::cout<<"Calibration Output: "<<outputdata<<std::endl;
|
||||
std::cout<<"Channel Map: "<<channelfile<<std::endl;
|
||||
|
||||
if(option == "--gainmatch")
|
||||
{
|
||||
std::cout<<"Calculating SABRE gain-matching parameters..."<<std::endl;
|
||||
SabreCal::GainMatcher matcher(channelfile, ring_to_match, wedge_to_match);
|
||||
if(gainplots == "None")
|
||||
matcher.Run(gaindata, gainfile);
|
||||
else
|
||||
matcher.Run(gaindata, gainfile, gainplots);
|
||||
}
|
||||
else if (option == "--calibrate")
|
||||
{
|
||||
std::cout<<"Calculating SABRE calibration parameters..."<<std::endl;
|
||||
SabreCal::Calibrator calib(gainfile);
|
||||
if(calplots == "None")
|
||||
calib.Run(caldata, calfile);
|
||||
else
|
||||
calib.Run(caldata, calfile, calplots);
|
||||
}
|
||||
else if (option == "--apply")
|
||||
{
|
||||
std::cout<<"Applying SABRE gain-matching and calibration parameters to dataset..."<<std::endl;
|
||||
SabreCal::DataOrganizer organ(channelfile, gainfile, calfile);
|
||||
organ.Run(inputdata, outputdata);
|
||||
organ.ShowStats();
|
||||
}
|
||||
else if (option == "" || option == "--all")
|
||||
{
|
||||
std::cout<<"Calculating SABRE gain-matching parameters..."<<std::endl;
|
||||
SabreCal::GainMatcher matcher(channelfile, ring_to_match, wedge_to_match);
|
||||
if(gainplots == "None")
|
||||
matcher.Run(gaindata, gainfile);
|
||||
else
|
||||
matcher.Run(gaindata, gainfile, gainplots);
|
||||
std::cout<<"Calculating SABRE calibration parameters..."<<std::endl;
|
||||
SabreCal::Calibrator calib(gainfile);
|
||||
if(calplots == "None")
|
||||
calib.Run(caldata, calfile);
|
||||
else
|
||||
calib.Run(caldata, calfile, calplots);
|
||||
std::cout<<"Applying SABRE gain-matching and calibration parameters to dataset..."<<std::endl;
|
||||
SabreCal::DataOrganizer organ(channelfile, gainfile, calfile);
|
||||
organ.Run(inputdata, outputdata);
|
||||
organ.ShowStats();
|
||||
}
|
||||
else if (option == "--help")
|
||||
{
|
||||
std::cout<<"SABRE Calibration Help"<<std::endl;
|
||||
std::cout<<"To run: ./bin/SabreCal <option> <input config>"<<std::endl;
|
||||
std::cout<<"Available Options"<<std::endl;
|
||||
std::cout<<"--gainmatch: Only run gain-matching"<<std::endl;
|
||||
std::cout<<"--calibrate: Only run calibration (requires gain-matching parameters)"<<std::endl;
|
||||
std::cout<<"--apply: Apply calibration and gain-matching parameters to a dataset (requires gain-matching and calibration parameters)"<<std::endl;
|
||||
std::cout<<"--all: Run gain-matching, calibration, and apply to data set"<<std::endl;
|
||||
std::cout<<"Default behavior (no option) is the same as --all"<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"Unrecognized option passed to SabreCal. Use --help to see available options"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout<<"Finished."<<std::endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user