Skip to content
Merged
58 changes: 52 additions & 6 deletions UserTools/LAPPDClusterTree/LAPPDClusterTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bool LAPPDClusterTree::Initialise(std::string configfile, DataModel &data)
WraparoundBin=0; QualityVar=0; TrigDeltaT1=0.; TrigDeltaT2=0.; PulseHeight=0.; MaxAmp0=0.; MaxAmp1=0.; BeamTime=0.; EventTime=0.; TotalCharge=0.; Npulses_cfd=0; Npulses_simp=0; T0Bin=0;
NHits=0; NHits_simp=0; Npulses_cfd=0; Npulses_simp=0;
Nchannels=60;
timestamps_meta=0;

for(int i=0; i<60; i++){
hQ[i]=0; hxpar[i]=0; hxperp[i]=0; htime[i]=0; hdeltime[i]=0; hvpeak[i]=0;
Expand All @@ -42,7 +43,7 @@ bool LAPPDClusterTree::Initialise(std::string configfile, DataModel &data)

SelectedAmp0[i]=0; SelectedAmp1[i]=0; SelectedTime0[i]=0; SelectedTime1[i]=0;

StripPeak[i]=0; StripPeak_Sm[i]=0; StripPeakT[i]=0; StripPeakT_Sm[i] =0;
StripPeak[i]=0; StripPeak_Sm[i]=0; StripPeakT[i]=0; StripPeakT_Sm[i] =0; StripMaxAmp[i]=0.; StripMinAmp[i]=0.; StripRMSAmp[i]=0.; StripStandDevAmp[i]=0.; StripVarianceAmp[i]=0.; StripInt[i]=0.;
StripQ[i]=0; StripQ_Sm[i]=0;

}
Expand All @@ -66,6 +67,7 @@ bool LAPPDClusterTree::Initialise(std::string configfile, DataModel &data)
fMyTree->Branch("EventTime", &EventTime, "EventTime/D" );
fMyTree->Branch("TotalCharge", &TotalCharge, "TotalCharge/D" );

fMyTree->Branch("timestamps_meta", &timestamps_meta, "timestamps_meta/I" );

//Hit parameters (from CFD)
fMyTree->Branch("NHits", &NHits, "NHits/I" );
Expand All @@ -86,6 +88,14 @@ bool LAPPDClusterTree::Initialise(std::string configfile, DataModel &data)
fMyTree->Branch("StripQ", StripQ, "StripQ[Nchannels]/D" );
fMyTree->Branch("StripQ_Sm", StripQ_Sm, "StripQ_Sm[Nchannels]/D" );

// Information of the waveforms
fMyTree->Branch("StripMaxAmp", StripMaxAmp, "StripMaxAmp[Nchannels]/D" );
fMyTree->Branch("StripMinAmp", StripMinAmp, "StripMinAmp[Nchannels]/D" );
fMyTree->Branch("StripRMSAmp", StripRMSAmp, "StripRMSAmp[Nchannels]/D" );
fMyTree->Branch("StripStandDevAmp", StripStandDevAmp, "StripStandDevAmp[Nchannels]/D" );
fMyTree->Branch("StripVarianceAmp", StripVarianceAmp, "StripVarianceAmp[Nchannels]/D" );
fMyTree->Branch("StripInt", StripInt, "StripInt[Nchannels]/D" );


//Hit parameters (from simple FindPeak)
fMyTree->Branch("NHits_simp", &NHits_simp, "NHits_simp/I" );
Expand Down Expand Up @@ -185,7 +195,31 @@ bool LAPPDClusterTree::Execute()
m_data->Stores["ANNIEEvent"]->Get("TML",TML);
m_data->Stores["ANNIEEvent"]->Get("TMR",TMR);

vector<string> acdcmetadata;
bool okACDCmetadata = m_data->Stores["ANNIEEvent"]->Get("ACDCmetadata", acdcmetadata);
if (!okACDCmetadata) {
std::cerr << "ERROR: Could not retrieve ACDCmetadata from ANNIEEvent store." << std::endl;
return false;
}

// Adding the TIMESTAMP In tree
// Timestamp indices inside ACDC metadata
// These four entries store the timestamp bytes (or string fragments)
static const std::array<size_t,4> TS_INDICES = {204, 206, 208, 210};
int meta_timestamp_int;
std::string meta_timestamp;

for (size_t idx : TS_INDICES) {
meta_timestamp += acdcmetadata.at(idx);
}

std::istringstream iss(meta_timestamp);
iss >> std::hex >> meta_timestamp_int;
timestamps_meta = meta_timestamp_int;
//std::cout << meta_timestamp_int << std::endl;
//std::cout << acdcmetadata[204] << acdcmetadata[206] << acdcmetadata[208] << acdcmetadata[210] << std::endl;
//std::cout << acdcmetadata[205] << acdcmetadata[207] << acdcmetadata[209] << acdcmetadata[211] << std::endl;
//std::cout<<"----------------------------------------------"<<std::endl;

map <int, vector<vector<double>>> :: iterator TMitr;
for (TMitr = TML.begin(); TMitr != TML.end(); ++TMitr){
Expand All @@ -198,6 +232,12 @@ bool LAPPDClusterTree::Execute()
StripPeakT_Sm[stripno] = aTML.at(3);
StripQ[stripno] = aTML.at(4);
StripQ_Sm[stripno] = aTML.at(5);
StripMaxAmp[stripno] = aTML.at(6);
StripMinAmp[stripno] = aTML.at(7);
StripRMSAmp[stripno] = aTML.at(8);
StripStandDevAmp[stripno] = aTML.at(9);
StripVarianceAmp[stripno] = aTML.at(10);
StripInt[stripno] = aTML.at(11);

//cout<<"Trace on Strip in ClusterTree "<<(int) stripno<<" amplitude:"<<aTML.at(0)<<" peaktime: "<<aTML.at(1)<<" charge:"<<aTML.at(4)<<" charge(smoothe peak):"<<aTML.at(5)<<endl;
}
Expand All @@ -213,6 +253,12 @@ bool LAPPDClusterTree::Execute()
StripPeakT_Sm[stripno+30] = aTML.at(3);
StripQ[stripno+30] = aTML.at(4);
StripQ_Sm[stripno+30] = aTML.at(5);
StripMaxAmp[stripno+30] = aTML.at(6);
StripMinAmp[stripno+30] = aTML.at(7);
StripRMSAmp[stripno+30] = aTML.at(8);
StripStandDevAmp[stripno+30] = aTML.at(9);
StripVarianceAmp[stripno+30] = aTML.at(10);
StripInt[stripno+30] = aTML.at(11);
//cout<<"Trace on Strip in ClusterTree "<<(int) channelno<<" amplitude:"<<aTML.at(0)<<" peaktime: "<<aTML.at(1)<<" charge:"<<aTML.at(4)<<" charge(smoothe peak):"<<aTML.at(5)<<endl;
}

Expand Down Expand Up @@ -395,8 +441,8 @@ bool LAPPDClusterTree::Execute()
int mystripnum = mychannel->GetStripNum();
int mystripside = mychannel->GetStripSide();

if(LAPPDClusterTreeVerbosity>2) cout<<"vPsize: "<<vPulse.size()<<" "<<mystripnum<<" "<<mystripside<<endl;;

if(LAPPDClusterTreeVerbosity>2) cout<<"vPsize: "<<vPulse.size()<<" "<<mystripnum<<" "<<mystripside<<endl;
for(int jj=0; jj<vPulse.size(); jj++){
if(Npulses_simp>=59) { cout<<"MORE THAN 60 SIMPLE PULSES!!!!!!"<<endl; break; }
LAPPDPulse apulse = vPulse.at(jj);
Expand All @@ -414,10 +460,10 @@ bool LAPPDClusterTree::Execute()
pulseQ_simp[Npulses_simp]=apulse.GetCharge();
Npulses_simp++;
//cout<<Npulses_simp<<" sdfsdf"<<endl;
}
}
}
}
if(LAPPDClusterTreeVerbosity>1) cout<<"DONE WITH SIMP Npulses: "<<Npulses_simp<<endl;
}
}



Expand Down
10 changes: 9 additions & 1 deletion UserTools/LAPPDClusterTree/LAPPDClusterTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class LAPPDClusterTree: public Tool {
Double_t StripQ[60];
Double_t StripQ_Sm[60];

//Noise Study
Double_t StripMaxAmp[60];
Double_t StripMinAmp[60];
Double_t StripRMSAmp[60];
Double_t StripVarianceAmp[60];
Double_t StripStandDevAmp[60];
Double_t StripInt[60];

//NEW!!!
Int_t NHits_simp;
Double_t hQ_simp[60];
Expand Down Expand Up @@ -112,7 +120,7 @@ class LAPPDClusterTree: public Tool {
Double_t pulsepeakbin_simp[60];
Int_t pulsestrip_simp[60];
Int_t pulseside_simp[60];

Int_t timestamps_meta;

private:

Expand Down
67 changes: 62 additions & 5 deletions UserTools/LAPPDTraceMax/LAPPDTraceMax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ bool LAPPDTraceMax::Execute(){
vector<double> ampvect = CalcAmp(bwav,lowR,hiR);
vector<double> ampvect_sm = CalcAmpSmoothed(bwav,lowR,hiR);

// find min max amplitude
vector<double> ampminmaxvect = CalcMinMaxAmp(bwav);

// integrate the pulse from the low range to high range in units of mV*psec
double Qmvpsec = CalcIntegral(bwav,lowR,hiR);
// convert to coulomb
Expand Down Expand Up @@ -112,6 +115,13 @@ bool LAPPDTraceMax::Execute(){
astripsumL.push_back(ampvect_sm.at(1));
astripsumL.push_back(Qelectrons);
astripsumL.push_back(sQelectrons);

astripsumL.push_back(ampminmaxvect.at(0));
astripsumL.push_back(ampminmaxvect.at(1));
astripsumL.push_back(ampminmaxvect.at(2));
astripsumL.push_back(ampminmaxvect.at(3));
astripsumL.push_back(ampminmaxvect.at(4));
astripsumL.push_back(ampminmaxvect.at(5));
}

if(stripside==1){
Expand All @@ -121,6 +131,13 @@ bool LAPPDTraceMax::Execute(){
astripsumR.push_back(ampvect_sm.at(1));
astripsumR.push_back(Qelectrons);
astripsumR.push_back(sQelectrons);

astripsumR.push_back(ampminmaxvect.at(0));
astripsumR.push_back(ampminmaxvect.at(1));
astripsumR.push_back(ampminmaxvect.at(2));
astripsumR.push_back(ampminmaxvect.at(3));
astripsumR.push_back(ampminmaxvect.at(4));
astripsumR.push_back(ampminmaxvect.at(5));
}

vastripsumL.push_back(astripsumL);
Expand Down Expand Up @@ -175,12 +192,52 @@ double LAPPDTraceMax::CalcIntegral(Waveform<double> hwav, double lowR, double hi
for(int i=lowb; i<hib; i++){
tQ+=((hwav.GetSample(i))*Deltat);
}
} else std::cout<<"OUT OF RANGE!!!!"<<std::flush;
} else std::cout<<"OUT OF RANGE!!!!"<<std::endl;

return tQ;
}


std::vector<double> LAPPDTraceMax::CalcMinMaxAmp(Waveform<double> hwav){

// Get the Samples from Waveform
std::vector<double> *theWav = hwav.GetSamples();
int nbins = theWav->size();

// Find the minimum and maximum values
auto minmax = std::minmax_element(theWav->begin(), theWav->end());

// Get the minimum and maximum values
double minAmp = *minmax.first;
double maxAmp = *minmax.second;

// Get RMS
double sumOfSquares = 0.0;
for (int i=0; i<nbins; i++) sumOfSquares += pow(theWav->at(i),2);
double rms = sqrt(sumOfSquares / nbins);

// Get Mean
double sum = 0.0;
for (int i=0; i<nbins; i++) sum += theWav->at(i);
double mean = sum / nbins;

// Get Variance
double variance = 0.0;
for (int i=0; i<nbins; i++) variance += pow(theWav->at(i) - mean,2);
variance = variance / nbins;

// Get Standard deviation
double StandDev = sqrt(variance);

vector<double> minmaxVect;
minmaxVect.push_back(minAmp);
minmaxVect.push_back(maxAmp);
minmaxVect.push_back(rms);
minmaxVect.push_back(StandDev);
minmaxVect.push_back(variance);
minmaxVect.push_back(mean);

return minmaxVect;
}

std::vector<double> LAPPDTraceMax::CalcAmp(Waveform<double> hwav, double lowR, double hiR){

Expand All @@ -202,7 +259,7 @@ std::vector<double> LAPPDTraceMax::CalcAmp(Waveform<double> hwav, double lowR, d
tTime=(double)i;
}
}
} else std::cout<<"OUT OF RANGE!!!!"<<std::flush;
} else std::cout<<"OUT OF RANGE!!!!"<<std::endl;

vector<double> tAmpVect;
tAmpVect.push_back(tAmp);
Expand Down Expand Up @@ -240,7 +297,7 @@ std::vector<double> LAPPDTraceMax::CalcAmpSmoothed(Waveform<double> hwav, double
tTime=(double)i - (Nsmooth/2.) ;
}
}
} else std::cout<<"OUT OF RANGE!!!!"<<std::flush;
} else std::cout<<"OUT OF RANGE!!!!"<<std::endl;

vector<double> tAmpVect;
tAmpVect.push_back(tAmp);
Expand All @@ -265,7 +322,7 @@ double LAPPDTraceMax::CalcIntegralSmoothed(Waveform<double> hwav, double lowR, d
for(int i=lowb; i<hib; i++){
tQ+=((hwav.GetSample(i))*Deltat);
}
} else std::cout<<"OUT OF RANGE!!!!";
} else std::cout<<"OUT OF RANGE!!!!"<<std::endl;

return tQ;
}
2 changes: 2 additions & 0 deletions UserTools/LAPPDTraceMax/LAPPDTraceMax.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>

#include "Tool.h"
#include <cmath>

class LAPPDTraceMax: public Tool {

Expand All @@ -22,6 +23,7 @@ class LAPPDTraceMax: public Tool {
double CalcIntegral(Waveform<double> hwav, double lowR, double hiR);
double CalcIntegralSmoothed(Waveform<double> hwav, double lowR, double hiR);
std::vector<double> CalcAmp(Waveform<double> hwav, double lowR, double hiR);
std::vector<double> CalcMinMaxAmp(Waveform<double> hwav);
std::vector<double> CalcAmpSmoothed(Waveform<double> hwav, double lowR, double hiR);
int DimSize;
double Deltat;
Expand Down