Skip to content

Commit a76af72

Browse files
authored
Merge pull request #128 from ejangelico/Application
first version NNLS reco algorithm and improvement to LAPPDParseACC
2 parents 8b644c5 + 58c408d commit a76af72

34 files changed

+2493
-100
lines changed

DataModel/NnlsSolution.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "NnlsSolution.h"
2+
3+
NnlsSolution::~NnlsSolution()
4+
{
5+
component_times.clear();
6+
component_scales.clear();
7+
templateWaveform.ClearSamples(); //template used in the nnls algo, at the time binning used in the algorithm
8+
templateTimes.clear(); //time series of length of templateWaveform
9+
fullNnlsWaveform.ClearSamples(); //the full solution, sum of all components
10+
}
11+
12+
//add an nnls component to the components vector.
13+
//each of these components is a copy of the template waveform
14+
//at time "t" and scaled with factor "s".
15+
void NnlsSolution::AddComponent(double t, double s)
16+
{
17+
component_times.push_back(t);
18+
component_scales.push_back(s);
19+
}
20+
21+
//sum of all components, full waveform fit
22+
void NnlsSolution::SetFullSoln(Waveform<double> fullsoln)
23+
{
24+
fullNnlsWaveform.SetSamples(fullsoln.Samples());
25+
}
26+
27+
void NnlsSolution::SetTemplate(Waveform<double> tmpwfm, vector<double> temptimes)
28+
{
29+
templateWaveform.SetSamples(tmpwfm.Samples());
30+
templateTimes = temptimes;
31+
}

DataModel/NnlsSolution.h

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
This class is a data structure to store the already solved
3+
nnls algorithm outputs. It is meant to reduce the memory overhead
4+
used by the nnls matrices/vectors and just store info on
5+
the full solution and components of the solution. Originally,
6+
components of the solution were stored as full waveforms, but
7+
this would crash due to memory overusage. This class stores
8+
components as a tuple of time index and scale factor applied to template.
9+
-Evan Angelico, 7/11/2019
10+
*/
11+
12+
13+
#ifndef NnlsSolution_H
14+
#define NnlsSolution_H
15+
16+
#include <SerialisableObject.h>
17+
#include "Waveform.h"
18+
19+
using namespace std;
20+
21+
class NnlsSolution : public SerialisableObject
22+
{
23+
friend class boost::serialization::access;
24+
25+
public:
26+
NnlsSolution() : component_times(vector<double>{}), component_scales(vector<double>{}), templateWaveform(Waveform<double>{}),templateTimes(vector<double>{}),fullNnlsWaveform(Waveform<double>{}) {serialise=true;}
27+
~NnlsSolution();
28+
void AddComponent(double t, double s);
29+
void SetFullSoln(Waveform<double> fullsoln); //sum of all components, full waveform fit
30+
void SetTemplate(Waveform<double> tmpwfm, vector<double> temptimes);
31+
inline int GetNumberOfComponents() {return component_times.size();} //how many components are populated in components vector
32+
inline double GetComponentTime(int index) {return component_times.at(index);}
33+
inline double GetComponentScale(int index) {return component_scales.at(index);}
34+
35+
bool Print() {
36+
int verbose=0;
37+
bool filled = false;
38+
if(component_times.size() != 0) filled = true;
39+
cout << "Solution filled?: " << filled << endl;
40+
if(filled) cout << "Number of components: " << component_times.size() << endl;
41+
if(verbose){
42+
cout<<"Times and scales:" << endl;
43+
for(int i = 0; i < component_times.size(); i++){
44+
cout << component_times.at(i) << ", " << component_scales.at(i) << endl;
45+
}
46+
}
47+
48+
return true;
49+
}
50+
51+
52+
53+
protected:
54+
//components of the solution are pairs of doubles
55+
//first element is the time, second element is the scale
56+
//at which a template waveform appears relative to the
57+
//raw waveform in the time units of the raw waveform
58+
vector<double> component_times;
59+
vector<double> component_scales;
60+
Waveform<double> templateWaveform; //template used in the nnls algo, at the time binning used in the algorithm
61+
vector<double> templateTimes; //time series of length of templateWaveform
62+
Waveform<double> fullNnlsWaveform; //the full solution, sum of all components
63+
64+
template<class Archive> void serialize(Archive & ar, const unsigned int version){
65+
if(serialise){
66+
ar & component_times;
67+
ar & component_scales;
68+
ar & templateWaveform;
69+
ar & templateTimes;
70+
ar & fullNnlsWaveform;
71+
}
72+
}
73+
};
74+
75+
76+
#endif

UserTools/Factory/Factory.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ if (tool=="VtxExtendedVertexFinder") ret=new VtxExtendedVertexFinder;
6161
if (tool=="VtxPointDirectionFinder") ret=new VtxPointDirectionFinder;
6262
if (tool=="VtxPointVertexFinder") ret=new VtxPointVertexFinder;
6363
if (tool=="LoadCCData") ret=new LoadCCData;
64+
if (tool=="WaveformNNLS") ret=new WaveformNNLS;
6465
if (tool=="HitCleaner") ret=new HitCleaner;
6566
if (tool=="HitResiduals") ret=new HitResiduals;
6667
if (tool=="MonitorReceive") ret=new MonitorReceive;
+36-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "GenerateHits.h"
2+
#include <cstdlib>
3+
#include <time.h>
24

35
GenerateHits::GenerateHits():Tool(){}
46

@@ -27,36 +29,36 @@ bool GenerateHits::Execute(){
2729
std::vector<double> relpos;
2830
double tc,Q;
2931

30-
// MC truth hit 1
31-
Q=1.;
32-
pos.push_back(10.);
33-
pos.push_back(5.);
34-
pos.push_back(0.);
35-
relpos.push_back(10.);
36-
relpos.push_back(5.);
37-
tc = 1.050;
38-
LAPPDHit ahit1(TubeID,tc,Q,pos,relpos);
39-
40-
// clear vectors
41-
pos.clear();
42-
relpos.clear();
43-
44-
/*
45-
// MC truth hit 2
46-
tc = 1.140;
47-
Q=1.;
48-
pos.push_back(20.);
49-
pos.push_back(10.);
50-
pos.push_back(0.);
51-
relpos.push_back(20.);
52-
relpos.push_back(10.);
53-
LAPPDHit ahit2(TubeID,tc,Q,pos,relpos);
54-
*/
32+
int nhits;
33+
m_variables.Get("nhits", nhits);
5534

35+
//initialize random seed
36+
srand(time(NULL));
37+
38+
//all the hits
5639
vector<LAPPDHit> hits;
57-
hits.push_back(ahit1);
58-
// hits.push_back(ahit2);
5940

41+
//generate uniformly distributed hits
42+
//accross the surface of the LAPPD with
43+
//random values of position charge and time
44+
for(int i = 0; i < nhits; i++)
45+
{
46+
Q=1;
47+
//abs pos is not used for my analysis at the moment
48+
pos.push_back(0.);
49+
pos.push_back(0.);
50+
pos.push_back(0.);
51+
relpos.push_back(fRand(-98, 98));
52+
relpos.push_back(fRand(-98, 98));
53+
tc = fRand(0, 24.9); //ns, converted to ps later in LAPPDSim processing
54+
LAPPDHit temphit(TubeID,tc,Q,pos,relpos);
55+
pos.clear();
56+
relpos.clear();
57+
hits.push_back(temphit);
58+
59+
}
60+
61+
cout << "inserting " << hits.size() << " synthetic hits " << endl;
6062
// stuff the two hits into MCLAPPHit
6163
MCLAPPDHit.insert(pair <int,vector<LAPPDHit>> (0,hits));
6264

@@ -67,7 +69,14 @@ bool GenerateHits::Execute(){
6769
}
6870

6971

72+
double GenerateHits::fRand(double fMin, double fMax)
73+
{
74+
double f = (double)rand() / RAND_MAX;
75+
return fMin + f * (fMax - fMin);
76+
}
77+
7078
bool GenerateHits::Finalise(){
79+
cout << "Finalized generate alright " << endl;
7180

7281
return true;
7382
}

UserTools/GenerateHits/GenerateHits.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class GenerateHits: public Tool {
1616
bool Initialise(std::string configfile,DataModel &data);
1717
bool Execute();
1818
bool Finalise();
19+
double fRand(double fMin, double fMax);
1920

2021

2122
private:

UserTools/LAPPDAnalysis/LAPPDAnalysis.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ bool LAPPDAnalysis::Execute(){
2323
//BaselineSubtract
2424
Waveform<double> bwav;
2525
// get raw lappd data
26-
std::map<int,vector<Waveform<double>>> rawlappddata;
26+
map<int,vector<Waveform<double>>> rawlappddata;
2727
m_data->Stores["ANNIEEvent"]->Get("RawLAPPDData",rawlappddata);
28+
2829

2930
// the filtered Waveform
3031
std::map<int,vector<Waveform<double>>> blsublappddata;

0 commit comments

Comments
 (0)