Commit 5a3831b8 authored by Iain's avatar Iain
Browse files

Clean up and pulling the lastest develop. It should be ready for saveing waveforms to file now

parent ef031b21
Pipeline #43537 failed with stages
in 1 minute and 7 seconds
......@@ -13,9 +13,13 @@ all: lib bin/vanwftk
PF : bin/PulseFinding.exe
lib : lib/libSipmAnalysis.so
lib : lib/libSipmAnalysis.so lib/libLegacySipmAnalysis.so
lib/libSipmAnalysis.so : obj/Waveform.o obj/old/LecroyFile.o obj/old/V1730File.o obj/old/DataFile.o obj/RootDict.o #obj/LecroyHdfFile.o obj/WaveformProcessor.o
lib/libLegacySipmAnalysis.so : obj/Waveform.o obj/old/LecroyFile.o obj/old/V1730File.o obj/old/DataFile.o obj/RootDict.o #obj/LecroyHdfFile.o obj/WaveformProcessor.o
mkdir -p $(@D)
g++ -shared -fPIC -o lib/libLegacySipmAnalysis.so $^ $(LFLAGS)
lib/libSipmAnalysis.so : obj/RunManager.o obj/reader/V1730Factory.o obj/reader/Reader.o obj/writer/PulseWriteProcessor.o obj/reader/V1730File.o obj/Waveform.o obj/Event.o obj/Channel.o obj/WaveformStatistic.o obj/pulse_finding/PFS.o obj/pulse_finding/PulseFindingProcessor.o obj/pulse_analysis/Exp2GausPulseFittingStrategy.o obj/pulse_analysis/PulseFittingStrategy1.o obj/pulse_analysis/PulseFittingStrategy2.o obj/pulse_analysis/PulseFittingStrategy3.o obj/pulse_analysis/PulseAnalysisProcessor.o obj/writer/NTupleWriter.o obj/StepRunManager.o obj/baseline/BaselineProcessor.o obj/baseline/MostProbBaselineStrategy.o obj/RootDict.o
mkdir -p $(@D)
g++ -shared -fPIC -o lib/libSipmAnalysis.so $^ $(LFLAGS)
......@@ -23,11 +27,11 @@ bin/PulseFinding.exe : obj/PulseFinding.o obj/WaveformStatistic.o obj/old/Lecroy
mkdir -p $(@D)
g++ -o bin/PulseFinding.exe $^ $(LFLAGS)
bin/vanwftk : obj/RunManager.o obj/reader/V1730Factory.o obj/reader/Reader.o obj/reader/V1730File.o obj/writer/PulseWriteProcessor.o obj/writer/NTupleWriter.o obj/Waveform.o obj/Event.o obj/Channel.o obj/WaveformStatistic.o obj/pulse_finding/PFS.o obj/pulse_finding/PulseFindingProcessor.o obj/pulse_analysis/Exp2GausPulseFittingStrategy.o obj/pulse_analysis/PulseFittingStrategy1.o obj/pulse_analysis/PulseFittingStrategy2.o obj/pulse_analysis/PulseFittingStrategy3.o obj/pulse_analysis/PulseAnalysisProcessor.o obj/baseline/BaselineProcessor.o obj/baseline/MostProbBaselineStrategy.o
bin/vanwftk : obj/RunManager.o obj/reader/V1730Factory.o obj/reader/Reader.o obj/writer/PulseWriteProcessor.o obj/reader/V1730File.o obj/Waveform.o obj/Event.o obj/Channel.o obj/WaveformStatistic.o obj/pulse_finding/PFS.o obj/pulse_finding/PulseFindingProcessor.o obj/pulse_analysis/Exp2GausPulseFittingStrategy.o obj/pulse_analysis/PulseFittingStrategy1.o obj/pulse_analysis/PulseFittingStrategy2.o obj/pulse_analysis/PulseFittingStrategy3.o obj/pulse_analysis/PulseAnalysisProcessor.o obj/writer/NTupleWriter.o obj/StepRunManager.o obj/baseline/BaselineProcessor.o obj/baseline/MostProbBaselineStrategy.o obj/RootDict.o
mkdir -p $(@D)
g++ -o bin/vanwftk $^ $(LFLAGS) -ljsoncpp
obj/RootDict.o : code/Waveform.h code/reader/V1730File.h code/reader/DataFile.h code/reader/Reader.h code/pulse_finding/PFS.h code/pulse_finding/PulseFindingProcessor.h code/pulse_analysis/PulseAnalysisProcessor.h code/pulse_analysis/PulseFittingStrategy1.h code/EventProcessor.h code/Linkdef.h
obj/RootDict.o : code/Pulse.h code/Baseline.h code/Channel.h code/Event.h code/Waveform.h code/RunManager.h code/StepRunManager.h
# rootcint -f code/RootDict.cxx -c -I/home/deap/nEXO/packages/hdf5-1.8.13/hdf5/include -I$ROOTANADIR $^
rootcint -f code/RootDict.cxx -c -I$(ROOTANADIR) $^
mkdir -p $(@D)
......
......@@ -4,7 +4,7 @@
/**
* Event constructor.
*/
Event::Event() {}
Event::Event() { eventID = 0; };
/**
* Store all the channels of the current event.
......@@ -23,4 +23,19 @@ void Event::addChannels(Channel::Channels newChannels) {
* This allows pass by reference and changes to the channels outside of the
* Event class will persist.
*/
Channel::Channels *Event::getChannels() { return &channels; }
\ No newline at end of file
Channel::Channels *Event::getChannels() { return &channels; }
/**
* Inceases the event id counter 'eventID' by one, to be called when getting the
* next event
*
* Used for keeping track of event id when developing new pulse algorthims
*/
void Event::incrementID() { eventID++; }
/**
* Returns the events id 'eventID'
*
* Used for keeping track of event id when developing new pulse algorthims
*/
int Event::getID() { return eventID; }
\ No newline at end of file
......@@ -16,9 +16,12 @@ public:
void addChannels(std::vector<Channel> newChannels);
std::vector<Channel> *getChannels();
void incrementID();
int getID();
private:
std::vector<Channel> channels; /*!< Channels of the current Event. */
int eventID;
};
#endif // EVENT_H
\ No newline at end of file
......@@ -72,6 +72,7 @@ void RunManager::processEvents() {
pulsesSaved += wrProcessor.processEvent(event);
pulsesAnalyzed += pulses - pulsesSkipped;
}
event->incrementID();
}
wrProcessor.write();
......@@ -95,7 +96,7 @@ int main(int argc, char **argv) {
std::unique_ptr<RunManager> rm;
try {
rm = RunManager::fromConfigFile(argv[1]);
RunManager::fromConfigFile(rm, argv[1]);
} catch (Json::RuntimeError err) {
std::cerr << "Config file must be valid JSON:\n" << err.what() << std::endl;
return EXIT_FAILURE;
......
......@@ -31,12 +31,17 @@ public:
* flexibility if developers want to introduce new config formats, or source
* JSON objects from sources other than locally-available files.
*/
static std::unique_ptr<RunManager> fromConfigFile(std::string path) {
static void fromConfigFile(std::unique_ptr<RunManager> &rm,
std::string path) {
Json::Value rootCfgJson;
std::ifstream configFile{path, std::ifstream::binary};
configFile >> rootCfgJson;
return RunManager::fromJson(rootCfgJson);
if (rm == nullptr) {
rm = std::unique_ptr<RunManager>(new RunManager());
}
fromJson(rm, rootCfgJson);
}
/**
......@@ -48,7 +53,8 @@ public:
* program. That said, major (i.e. top-level) schema changes should be
* validated here.
*/
static std::unique_ptr<RunManager> fromJson(Json::Value rootCfgJson) {
static void fromJson(std::unique_ptr<RunManager> &rm,
Json::Value rootCfgJson) {
const auto eventLimit = rootCfgJson.get("EventLimit", 0).asInt();
const auto dataSourceCfgJson{rootCfgJson["DataSource"]};
const auto channelCfgJson{rootCfgJson["ChannelConfigs"]};
......@@ -96,20 +102,22 @@ public:
channelConfigs.push_back({bes, pfs, pas, vars});
}
return std::unique_ptr<RunManager>{new RunManager{
eventLimit, {device, filePath, channels, vars}, channelConfigs}};
rm->eventLimit = eventLimit;
rm->dataSource = {device, filePath, channels, vars};
rm->channelConfigs = channelConfigs;
}
RunManager(){};
void processEvents();
const int eventLimit; /*!< Limits the number of events that get processed. */
const DataSource
int eventLimit; /*!< Limits the number of events that get processed. */
DataSource
dataSource; /*!< Defines the datasource providing Events for analysis */
std::vector<ChannelConfig>
channelConfigs; /*!< Holds strategy configs and variables for each channel
that gets analyzed */
private:
protected:
Reader *createReader();
RunManager(int eventLimit, DataSource dataSource,
......
#ifndef Waveform_h
#define Waveform_h
#include "Baseline.h"
#include "TF1.h"
#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"
struct Baseline { // TODO: maybe not where this should go
double mu;
double RMS;
// double STD;//not used yet
};
/**
* A waveform class that contains the data and logic to process statistics about
* a waveform.
......@@ -24,6 +19,7 @@ public:
Waveform(int aNBin, double aMin, double aMax, const char *aName = 0,
int aRebin = 1); // always created in time domain
Waveform(const TH1D &aWF, int aRebin = 1, const char *aName = 0);
inline Waveform(){};
virtual ~Waveform();
void setNegPolarity() { mPolarity = -1; }
const int getPolarity() { return mPolarity; }
......@@ -133,9 +129,11 @@ public:
double getMinPos() const;
double getMaxPos() const;
private:
// Waveform(const char* aName, TH1D* aHReal, TH2D* aHComp);
Baseline waveformBaseline;
ClassDef(Waveform, 1)
private :
// Waveform(const char* aName, TH1D* aHReal, TH2D* aHComp);
Baseline waveformBaseline;
void initFourier();
void fourierTransform();
......
......@@ -152,6 +152,13 @@ bool IExp2GausPulseFittingStrategy::analyze(Channel &channel, Json::Value cfg) {
return checkPulses(channel, cfg);
}
/*
* Returns the name of the fitting function used in ROOT as a string
*/
std::string IExp2GausPulseFittingStrategy::getFitFunctionName() {
return "FExp2Gaus";
};
bool IExp2GausPulseFittingStrategy::checkParams(Json::Value params) {
return params.isMember("RiseTimeSigma") &&
params.isMember("PulseBaselineCalcEndOffset") &&
......
......@@ -43,16 +43,17 @@ public:
}
bool analyze(Channel &channel, Json::Value cfg) override;
bool checkParams(Json::Value params) override;
virtual std::string getFitFunctionName() override;
protected:
virtual void setFitParemeters(TF1 *fit, Pulse &p, Json::Value cfg) = 0;
virtual TF1 *createFitFunction(Json::Value cfg);
private:
void sortPulses(Channel *channel);
bool refit(Channel *channel, TF1 *fitFunction,
std::vector<PulseGroup> &pulseGroups, Json::Value cfg);
void calcSinglePulseTemplateChi2(Channel *channel, Json::Value cfg);
TF1 *createFitFunction(Json::Value cfg);
bool checkPulses(Channel &channel, Json::Value cfg);
std::string fitOption;
};
......
......@@ -64,3 +64,13 @@ int PulseAnalysisProcessor::processEvent(Event *event) {
return skipped;
}
/*
* Returns the name of the fitting function used for a give channel 'ch'
* Takes a ch id 'ch'
*
* Returns the ROOT fit name as a string
*/
std::string PulseAnalysisProcessor::getFitFunctionName(int ch) {
return strategies[ch]->getFitFunctionName();
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ class PulseAnalysisProcessor : public IEventProcessor {
public:
PulseAnalysisProcessor(std::vector<ChannelConfig> channelConfigs);
int processEvent(Event *event) override;
std::string getFitFunctionName(int ch);
private:
std::vector<IPulseAnalysisStrategy *> strategies; /*!< Used internally to map
......
......@@ -22,6 +22,7 @@ public:
virtual bool analyze(Channel &channel, Json::Value cfg) = 0;
virtual bool checkParams(Json::Value params) = 0;
virtual ~IPulseAnalysisStrategy() {}
virtual std::string getFitFunctionName() = 0;
};
#endif // __PULSEANALYSISSTRATEGY_H
......@@ -46,7 +46,7 @@ int PulseWriteProcessor::processEvent(Event *event) {
for (int i = 0; i < channels->size(); i++) {
Channel channel = channels->at(i);
Waveform *waveform = channel.getWaveform();
strategies[i]->push(0, channel, i, *waveform, vars.at(i));
strategies[i]->push(event->getID(), channel, i, *waveform, vars.at(i));
pulseCounter += channels->at(i).getPulses()->size();
}
......
//R__LOAD_LIBRARY(lib/libSipmAnalysis.so)
//gSystem->Load("/home/exo/packages/hdf5-1.8.13/lib/libhdf5_cpp.so")
//Before executing do: .L libexample.so
#include <fstream>
/*
Usage example:
.x macros/EbyECheck.C(8492,155,101,0,"ntp/VUV4PDEFeb2018")
- The third one is the fit type
- To select the fit to use you have to modify the WaveformProcessor.cxx. Here you can only select how to fit (i.e. refitting or not)
- The Run number is in RunInfo.txt
- Run Number in RunInfo.txt must be in progressive order otherwise macro crasches. Need to adjust this thing in the class!
giacomo@triumf.ca
*/
gSystem->Load("lib/libSipmAnalysis.so");
void EbyECheck(int aRun, int aEvent, int aFitType=0, int aChannel=1, const char* aDir="ntp/DN",int aSameColor=0){
//TCanvas *c1 = new TCanvas("FitGraph", "FitGraph", 900, 700);
//WaveformProcessor* wfProc = WaveformProcessor::instanceForRootMacro("ntpDN/DNRunInfo.txt",aRun);
//WaveformProcessor* wfProc = WaveformProcessor::instanceForRootMacro("RunInfo.txt",aRun, 5, aChannel);
//WaveformProcessor* wfProc = WaveformProcessor::instanceForRootMacro("ntpLight/LightRunInfo.txt",aRun, 5, aChannel);
char FRunInfo[200];
sprintf(FRunInfo,"%s/RunInfo.txt",aDir);
cout << FRunInfo << endl;
//Here it should be necessary to add a check that control if in the RunInfo you have all the paramenterswe need otherwise it crashes .....
//Third parameter Number of allowed pulses, usally 5
WaveformProcessor* wfProc = WaveformProcessor::instanceForRootMacro(FRunInfo,aRun, 15, aChannel);
//WaveformProcessor* wfProc = WaveformProcessor::instanceForRootMacro("PmtStabilityRunInfo.txt",aRun, 5, aChannel);
wfProc->setFitOption("V");
wfProc->readWaveform(aEvent);
cout << "Trigger time = " << wfProc->getTriggerTime() << endl;
if(aSameColor==0){
wfProc->getCurrentWaveform()->DrawCopy();
aSameColor=2;
}
else{
wfProc->getCurrentWaveform()->SetLineColor(aSameColor);
wfProc->getCurrentWaveform()->DrawCopy("same");
}
wfProc->processBaseline();
wfProc->findPulse();
if(wfProc->getNPulse()>0){
std::cout<<"Pulses found...!"<<std::endl;
TGraph* GPulse = wfProc->getPulseGraph();
GPulse->SetMarkerStyle(23);
GPulse->SetMarkerColor(aSameColor);
GPulse->Draw("p");
gStyle->SetOptStat(0);
for(int iPulse=0; iPulse<wfProc->getNPulse(); iPulse++){
std::cout<< "Pulse Information (No FIT): "<<iPulse<<std::endl;
std::cout<<" TIME: "<<wfProc->getPulseTime(iPulse)<<" CHARGE: "<<wfProc->getPulseCharge(iPulse)<<" ABS. AMPLITUDE: "<<wfProc->getPulseAbsAmplitude(iPulse)<<std::endl;
std::cout<<" AMPLITUDE: "<<wfProc->getPulseAmplitude(iPulse)<<std::endl;
}
if(aFitType>0){
wfProc->setFitOption("R0");
wfProc->fit(aFitType);
//Stai chiamando due volte Fit Function quindi due volte in output informazione sui fit
//questo non e una funzione ma un TF1
wfProc->getFitFunction()->SetLineColor(aSameColor);
wfProc->getFitFunction()->DrawCopy("same");
int number_pulse=wfProc->getNPulse();
cout<<"Total Number of pulses ...."<<number_pulse<<endl;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment