Commit 29fb21a8 authored by dino's avatar dino
Browse files

PostPsaFilter can produce the distribution of timestamps; various changes in the "LOCALSPECTRA"

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1137 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 0e300999
......@@ -285,8 +285,11 @@
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="..\PRISMA\src\lib_prisma\include;"C:\Program Files (x86)\boost\boost_1_40";..\common;..\producers\Crystal;..\producers\Crystal\includeATCA;..\producers\AncillaryTCP;..\filters\Preprocessing;..\filters\Preprocessing\includePrePSA;..\filters\Ancillary;..\filters\Ancillary\includeVME;..\filters\PSA;..\filters\PSA\includePSA;..\filters\Tracking;..\filters\Tracking\includeOFT;..\filters\Tracking\includeMGT;..\builders;C:\root\include;..\filters\PostPSA;..\filters\Global;..\..\include"
PreprocessorDefinitions="WIN64;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NRV_TYPE=NRV_OFFLINE"
ExceptionHandling="1"
RuntimeLibrary="2"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="false"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
......
......@@ -649,13 +649,15 @@ Int_t AncillaryFilter::SetInput()
ADF::RawFrame *frame_in = dynamic_cast<ADF::RawFrame *> (fFrameRaw_In->GetFrame());
UInt_t lenChar = frame_in->Read(); // length of the data buffer in bytes
if(lenChar > rawBufSize*sizeof(UInt_t) ) {
//if(lenChar > rawBufSize*sizeof(UInt_t) ) {
if(lenChar != rawBufSize*sizeof(UInt_t) ) {
if(rawBuf)
delete [] rawBuf;
rawBufSize = (lenChar+3)/sizeof(UInt_t);
rawBuf = new UInt_t[rawBufSize];
memset(rawBuf, 0, rawBufSize*sizeof(UInt_t));
}
memset(rawBuf, 0, rawBufSize*sizeof(UInt_t));
frame_in->RawBuffer().Export((Char_t*)rawBuf, lenChar);
......
......@@ -1194,7 +1194,7 @@ void GlobalFilter::GetParameters(UInt_t *error_code)
ok = 2 == sscanf(data.c_str(), "%d %f", &fSizeMatr_gg2, &fGainMatr_gg2);
KEND;
KPAR("Details", "", "list input events in symbolic form (very slow and incompletee)");
KPAR("Details", "", "list input events in symbolic form (very slow and incomplete)");
fDebug = true;
ok = true;
KEND;
......
......@@ -2553,7 +2553,7 @@ Int_t PSAFilterGridSearch::AlgoSpecificPostProcess(int slot)
float rr = sqrt(fx*fx + fy*fy);
// positions inside the crystal
if(PsaMatrXYZR || PsaMatrSeg ||PsaMatrXYZ) {
incrPosMats(-1, 0, fx, fy, fz, rr); // PsaMatrXYZ
incrPosMats(-((netChSeg%6)+1), 0, fx, fy, fz, rr); // PsaMatrXYZ
if(pOut->enerSG >= lowSegEnergy) { // not too-low energy
incrPosMats(netChSeg, 0, fx, fy, fz, rr); // 0 --> all hits
if(nh < numXYZ-3)
......@@ -2634,12 +2634,15 @@ void PSAFilterGridSearch::incrPosMats(int netChSeg, int nhi, float fx, float fy,
if(netChSeg < 0) {
if(PsaMatrXYZ) {
int slice90 = 90 - netChSeg; // negative value passed is -((netChSeg%6)+1
PsaMatrXYZ->Incr(0, 0, xAddrU(fx), yAddrU(fy) ); // total projection
PsaMatrXYZ->Incr(0, zAddrU(fz), xAddrU(fx), yAddrU(fy) );
PsaMatrXYZ->Incr(1, 0, xAddrU(fx), zAddrU(fz) );
PsaMatrXYZ->Incr(0, slice90, xAddrU(fx), yAddrU(fy) );
PsaMatrXYZ->Incr(0, zAddrU(fz), xAddrU(fx), yAddrU(fy) ); // the slices in 91...96
PsaMatrXYZ->Incr(1, 0, xAddrU(fx), zAddrU(fz) ); // total projection
PsaMatrXYZ->Incr(1, yAddrU(fy), xAddrU(fx), zAddrU(fz) );
PsaMatrXYZ->Incr(2, 0, yAddrU(fy), zAddrU(fz) );
PsaMatrXYZ->Incr(2, 0, yAddrU(fy), zAddrU(fz) ); // total projection
PsaMatrXYZ->Incr(2, xAddrU(fx), yAddrU(fy), zAddrU(fz) );
}
return;
}
......
......@@ -72,6 +72,10 @@ PostPSAFilter::PostPSAFilter() :
fPostAccepted = true;
fNewCrystalID = -1; // no change
bWriteTstampDiff = false;
sTstampDiff = NULL;
tStampOld = 0;
fUseMultiHist = true;
#ifdef PSA_MULTIHIST
PostSpecEner = NULL; PostMatrXYZ = NULL; PostMatrRZE = NULL;
......@@ -80,6 +84,9 @@ PostPSAFilter::PostPSAFilter() :
PostPSAFilter::~PostPSAFilter()
{
if(bWriteTstampDiff && sTstampDiff)
delete sTstampDiff;
sTstampDiff = NULL;
}
void PostPSAFilter::process_config(const Char_t *directory_path, UInt_t *error_code)
......@@ -202,6 +209,10 @@ void PostPSAFilter::process_initialise (UInt_t *error_code)
cServer.SetCommandFile(GetConfPath() + gMotherClass + ".live");
if(bWriteTstampDiff) {
sTstampDiff = new sAppend<UInt_t>(fOdirPrefix+"PSA__0-2048-UI__tstdiff.bdat", 2048);
}
#ifdef PPS_MULTIHIST
if(fUseMultiHist) {
PostSpecEner = new MultiHist<unsigned int>(4, 40, specLenE);
......@@ -347,6 +358,11 @@ void PostPSAFilter::GetParameters(UInt_t *error_code)
ok = 1 == sscanf(data.c_str(), "%f", &fEnergyGain);
KEND;
KPAR("WriteTstampDiff", "", "Write list-mode of time stamp difference");
bWriteTstampDiff = true;
ok = true;
KEND;
KPAR("NoMultiHist", "", "exclude flat binary spectra");
fUseMultiHist = false;
ok = true;
......@@ -597,6 +613,26 @@ Int_t PostPSAFilter::Process()
}
}
if(bWriteTstampDiff) {
if(tStampOld == 0) {
#if 1
// seconds and fraction of seconds of first timestamp, assuming 100 Ms/s
sTstampDiff->add(UInt_t(timestamp/100000000));
sTstampDiff->add(UInt_t(timestamp-100000000*(timestamp/100000000)));
#else
// time stamp of first event, written in little endian
sTstampDiff->add(UInt_t(timestamp & 0xFFFFFFFF));
sTstampDiff->add(UInt_t(timestamp >> 32));
#endif
}
else {
ULong64_t tstdiff = timestamp - tStampOld;
sTstampDiff->add(UInt_t(tstdiff & 0xFFFFFFFF));
}
}
tStampOld = timestamp;
#ifdef PPS_MULTIHIST
if(PostSpecEner) {
const int NSEGS = ADF::CrystalInterface::kNbSegments; // 36
......@@ -649,11 +685,13 @@ Int_t PostPSAFilter::Process()
float fx = pLoc->fx;
float fy = pLoc->fy;
float fz = pLoc->fz;
int slice90 = 91 + (pLoc->Sg%6);
PostMatrXYZ->Incr(0, 0, xAddrU(fx), yAddrU(fy) ); // total projection
PostMatrXYZ->Incr(0, zAddrU(fz), xAddrU(fx), yAddrU(fy) );
PostMatrXYZ->Incr(1, 0, xAddrU(fx), zAddrU(fz) );
PostMatrXYZ->Incr(0, slice90, xAddrU(fx), yAddrU(fy) ); // the 6 slices in 91...96
PostMatrXYZ->Incr(1, 0, xAddrU(fx), zAddrU(fz) ); // total projection
PostMatrXYZ->Incr(1, yAddrU(fy), xAddrU(fx), zAddrU(fz) );
PostMatrXYZ->Incr(2, 0, yAddrU(fy), zAddrU(fz) );
PostMatrXYZ->Incr(2, 0, yAddrU(fy), zAddrU(fz) ); // total projection
PostMatrXYZ->Incr(2, xAddrU(fx), yAddrU(fy), zAddrU(fz) );
}
}
......@@ -707,16 +745,17 @@ Int_t PostPSAFilter::Process()
// Move the integer part of the trace position to the timestamp, removing most of the
// time-walk due to the use of a LE trigger in the preprocessing elctronics.
// CoreT[0] holds the fractional part; CoreT[1] is left unchanged for control purposes
const float T0 = 40.f; // final position of data
float tpos = CoreT[0] - T0 ; // in samples
const float T0 = 40.f; // final position of data (samples)
const int TS = 1; // scale time units
float tpos = (CoreT[0] - T0)*TS ; // in samples
if(tpos >= 0) {
int itst = int(tpos + 0.5f);
timestamp += itst;
timestamp = TS*timestamp + itst;
tpos -= itst;
}
else {
int itst = int(-tpos + 0.5f);
timestamp -= itst;
timestamp = TS*timestamp - itst;
tpos += itst;
}
CoreT[0] = tpos + T0; // no change to CoreT[1]
......
......@@ -18,7 +18,7 @@
# include "MultiHist.h"
#endif
#include "cycleServer.h"
#include "sAppend.h"
#include "adetParams.h"
#include <ctime>
......@@ -66,6 +66,9 @@ protected:
// to test how to add anonymous parameters
//ADF::Anonymous myAno;
Bool_t bWriteTstampDiff;
sAppend<UInt_t> *sTstampDiff;
unsigned long long tStampOld; // to build the time-stamp difference, managed by Process()
bool fUseMultiHist;
#ifdef PPS_MULTIHIST
......
......@@ -60,8 +60,7 @@ PreprocessingFilterPSA::PreprocessingFilterPSA() :
#ifdef PPF_MULTIHIST
PreSpecEner(NULL), PreSpecEsum(NULL), PreMatrEcEsum(NULL),
PreMatrEeEtrCC(NULL), PreMatrEeEtr(NULL), PreMatrEsEs(NULL), PreMatrEcTc(NULL), PreMatrEsTs(NULL), PreMatrEeTr(NULL),
PreMatrTT1(NULL), PreMatrTT2(NULL), PreMatrTT3(NULL), PreMatrXT(NULL),
PreSpecTT1(NULL), PreSpecTT2(NULL),
PreSpecTT(NULL), PreMatrTT(NULL), PreMatrXT(NULL),
PreSpecExtalk(NULL), PreMatrExtalk(NULL),
#endif //PPF_MULTIHIST
fpPrepTraces(NULL), doWriteTrace(true),
......@@ -549,35 +548,20 @@ bool PreprocessingFilterPSA::initPresort()
//PreMatrEsTs->setComment("Segments: Energy(keV)-Time(ns, relative to core)");
//hGroup.add(PreMatrEsTs);
//PreMatrTT1 = new MultiHist<unsigned short>(matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
//PreMatrTT1->setFileName(fOdirPrefix+"Prep?TT1.matr");
//PreMatrTT1->setComment("relative and absolute Core_to_Segment time, before shifting traces");
//hGroup.add(PreMatrTT1);
//PreMatrTT2 = new MultiHist<unsigned short>(matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
//PreMatrTT2->setFileName(fOdirPrefix+"Prep?TT2.matr");
//PreMatrTT2->setComment("relative and absolute Core_to_Segment time, after shifting the traces");
//hGroup.add(PreMatrTT2);
//PreMatrTT3 = new MultiHist<unsigned short>(5, 1000, 1000);
//PreMatrTT3->setFileName(fOdirPrefix+"Prep?TT3.matr");
//PreMatrTT3->setComment("timing checks");
//hGroup.add(PreMatrTT3);
//PreMatrTT = new MultiHist<unsigned short>(2, matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
//PreMatrTT->setFileName(fOdirPrefix+"Prep?TT.matr");
//PreMatrTT->setComment("relative and absolute Core_to_Segment time, before and after shifting traces");
//hGroup.add(PreMatrTT);
//PreMatrXT = new MultiHist<unsigned short>(100*CC.nSG*CC.nSG, 1536);
//PreMatrXT->setFileName(fOdirPrefix+"Prep?XT.matr");
//PreMatrXT->setComment("CrossTalk matrix at Fold 1");
//hGroup.add(PreMatrXT);
PreSpecTT1 = new MultiHist<unsigned int>(2, 40, speTTlen);
PreSpecTT1->setFileName(fOdirPrefix+"Prep?TT1.spec");
PreSpecTT1->setComment("time spectra, before shifting the traces)");
hGroup.add(PreSpecTT1);
PreSpecTT2 = new MultiHist<unsigned int>(2, 40, speTTlen);
PreSpecTT2->setFileName(fOdirPrefix+"Prep?TT2.spec");
PreSpecTT2->setComment("time spectra after shifting the traces)");
hGroup.add(PreSpecTT2);
PreSpecTT = new MultiHist<unsigned int>(4, 40, speTTlen);
PreSpecTT->setFileName(fOdirPrefix+"Prep?TT.spec");
PreSpecTT->setComment("time spectra, before and after shifting the traces)");
hGroup.add(PreSpecTT);
PreSpecEner = new MultiHist<unsigned int>(2, CC.nSG + 2*CC.nCC, specLenE);
PreSpecEner->setFileName(fOdirPrefix+"Prep?Ener.spec");
......@@ -619,9 +603,11 @@ bool PreprocessingFilterPSA::initPresort()
bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float &eSumSG2)
{
// given that these 3 variables always have the "standard" value (36,2,0)
// should probably make them const (and unroll most of the loops on nCC)
int nSG = CC.nSG; // 36
int nCC = CC.nCC; // 2
int iTR = CC.itrig; // 0
int iTR = CC.itrig; // 0
segMult = nSegFold = 0;
eSumSG1 = 0; // sum of net charge segments before xTalk correction
......@@ -652,8 +638,8 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
}
}
//// Test if the core energy derived from the trace is close enough to the "good" energy of core
//// This is a kind of pileup rejection, which helps rejecting pile-up events at high singles rate
//// test if the core energy derived from the trace is close enough to the "good" energy of core
//// it is a kind of pile-up control, which helps rejecting piled-up events at high singles rate
if(checkPileUp) {
float sCore = AverageValue(fTracesCC[iTR] + (nNsamp -2*nNbase), 2*nNbase);
#ifdef PPF_MULTIHIST
......@@ -686,7 +672,7 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
memcpy(xSegE, SegE, sizeof(xSegE));
#ifdef PPF_MULTIHIST
// [1] calibrated spectra BEFORE special treatment of dead and unstable segments and BEFORE cross-talk corrections
// [1] calibrated spectra BEFORE special treatment of dead and unstable segments and BEFORE cross-talk corrections
if(PreSpecEner) {
for(int nn = 0; nn < CC.nSG; nn++) {
float ener = SegE[nn];
......@@ -753,12 +739,11 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
netChargeSegs[nSegFold++] = ns;
}
//else {
// // Although zeroing the channels below threshold seems the right thing to do, this cannot be done
// // because the the "negative" values are neeed to properly treat the cross-talk correction.
// // In fact, if the negative amplitudes produced (in the other segments) by very high energy hits are zeroed,
// // the "corrected" values for the now-zero channels can be easily 20-30 keV, i.e. over threshold, producing
// // artificial events of very large multiplicity. What we can do to remove the peak at zero in the segment spectra
// // is to zero the under-threshold AFTER the cross-talk correction
// // Zeroing the channels below threshold seems the right thing to do, but is if wrong because the "negative"
// // values are neeed to properly treat the cross-talk correction. In fact, if the negative amplitudes produced
// // (in the other segments) by very high energy hits are zeroed, the "corrected" values for the now-zero channels
// // can be easily 20-30 keV, i.e. over threshold, producing artificial events of very large multiplicity
// // To remove the peak at zero in the segment spectra, zero the under-threshold values AFTER the cross-talk correction
// SegE[ns] = 0;
//}
}
......@@ -773,8 +758,8 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
segMult = nSegFold;
eSumSG2 = eSumSG1 = sumSegs; // set to this for the case of no crosstalk correction
// core energy derived from xTalk
#ifdef PPF_MULTIHIST
// core energy derived from xTalk
if(PreSpecExtalk || PreMatrExtalk)
CoreEnergyFromXtalk(segMult);
#endif
......@@ -831,8 +816,8 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
////////////////////////////////////
// Apply time shifts specified in PreprocessingFilterPSA.conf
// to the cores and the net-charge segments needed for timing
// Being the reference for all time shifts the triggering core is not moved
// to the cores* and the net-charge segments needed for timing
// *being the reference for all time shifts the triggering core is not moved
for(int ic = 0; ic < nCC; ic++) {
WRITEWORKINGWAVE1(fTracesCC[ic], true);
float xmove = (ic==iTR) ? 0 : CC.pCC[ic].tmove/tStep;
......@@ -849,7 +834,7 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
//// copy the triggering core into the "netcharge" wave
memcpy(fTC, sTracesCC[iTR], nNsamp*sizeof(float));
//// calculate the sum of shifted net-charge waves for the trigger
//// calculate the sum of time-shifted net-charge waves for the trigger
// WE SHOULD PROBABLY EXCLUDE FROM THE SUM THE VERY LOW ENERGY SEGMENTS,
// BY SETTING A THRESHOLD ON A FRACTION OF THE CORE ENERGY
memset(fTS, 0, sizeof(float)*nNsamp);
......@@ -893,7 +878,7 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
return false; // discard the event
//// put both trigger times to the same value
// Due to the fact that the GTS tree alignment is done only up to the Preprocessing electronics an
// Due to the fact that the GTS tree alignment is done only up to the Preprocessing electronics
// (and not down to the Digitizer) the correction CC.pCC[iTR].tmove/tStep does not adjust the
// Tgamma-gamma of all detector pairs to be in the same position. Therefore it does not make sense to apply it.
// In fact, in PostPSAFilter.conf we can give the (empyrically determined) proper value with the keyword ShiftCC
......@@ -917,9 +902,9 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
// Energy-Risetime matrix for all channels
calcRiseTime();
}
if(PreSpecTT1) {
if(PreSpecTT) {
// absolute and relative time spectra (done before shifting the waves)
calcTT(tRefCC, PreSpecTT1, PreMatrTT1, PreMatrEsTs);
calcTT(tRefCC, 0, 2, 0, true);
}
#endif // PPF_MULTIHIST
......@@ -954,7 +939,7 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
#ifdef PPF_MULTIHIST
// absolute and relative time spectra for the shifted waves
if(PreSpecTT2) {
if(PreSpecTT) {
#if 1
// To be sure that the traces have been shifted correctly, rebuild fTC, fTS and fTT (just fTT) with no shifts and retrigger
// To avoid loosing the "unshifted" view in the last traces of the Prep__1000-42-100-S__Traces.samp, we put it directly in fWW
......@@ -984,7 +969,7 @@ bool PreprocessingFilterPSA::ProcessEvent(int &segMult, float &eSumSG1, float
PreMatrEcTc->Incr(1, enecc, tzero);
}
calcTT(tRefCCs, PreSpecTT2, PreMatrTT2, NULL);
calcTT(tRefCCs, 1, 3, 1, false);
}
#endif //PPF_MULTIHIST
......@@ -1518,24 +1503,24 @@ int PreprocessingFilterPSA::xTalkCorrNet(float *pSG_Ener, float &segsum)
#ifdef PPF_MULTIHIST
// specTT[0][0...NSEG-1] triggering point of segments
// specTT[0][NSEG, NSEG+1] triggering point of the two cores cRefCC and cRefCC1
// specTT[0][NSEG+2] triggering point of the external trigger tRefCC
// specTT[1][0...NSEG-1] timing (in ns) segment re external trigger (tRefSG-tRefCC)*tScale+speTTlen/2 (for eCore > calcTT_eminCC)
// specTT[1][NSEG, NSEG+1] timing of the two cores re external trigger
// specTT[0][NSEG+2] timing between the two cores ()
// specTT[ss0][0...NSEG-1] triggering point of segments
// specTT[ss0][NSEG, NSEG+1] triggering point of the two cores cRefCC and cRefCC1
// specTT[ss0][NSEG+2] triggering point of the external trigger tRefCC
// specTT[ss1][0...NSEG-1] timing (in ns) segment re external trigger (tRefSG-tRefCC)*tScale+speTTlen/2 (for eCore > calcTT_eminCC)
// specTT[ss1][NSEG, NSEG+1] timing of the two cores re external trigger
// specTT[ss0][NSEG+2] timing between the two cores ()
// Remember that the recalculated local triggers are not (yet?) moved according to the calibrationo table, which so far affects only tRefCC
void PreprocessingFilterPSA::calcTT(float tRefCC, MultiHist<unsigned int>*specTT, MultiHist<unsigned short>*matrTT, MultiHist<unsigned short>*matrETsg)
void PreprocessingFilterPSA::calcTT(float tRefCC, int ss0, int ss1, int sm0, bool bEsTs)
{
//int aa1 = int((tRefCC-int(tRefCC))*tScale*tGain);
//int aa2 = int(tRefCC*tScale*tGain);
//int aa3 = aa2%100;
if(!specTT)
if(!PreSpecTT)
return;
specTT->Incr(0, CC.nSG+2, int(tRefCC*tScale*tGain)); // "external" trigger point (usually from the CC+Netcharges)
specTT->Incr(0, CC.nSG+2, int((tRefCC-int(tRefCC))*tScale*tGain)); // to verify flatness of subsample distribution
PreSpecTT->Incr(ss0, CC.nSG+2, int(tRefCC*tScale*tGain)); // "external" trigger point (usually from the CC+Netcharges)
PreSpecTT->Incr(ss0, CC.nSG+2, int((tRefCC-int(tRefCC))*tScale*tGain)); // to verify flatness of subsample distribution
// trigger on the triggering core
float cRefCC = FindTriggerTime(sTracesCC[CC.itrig], trigFraction, trigChansCC);
......@@ -1545,10 +1530,10 @@ void PreprocessingFilterPSA::calcTT(float tRefCC, MultiHist<unsigned int>*specTT
if(cRefCC < 1.f)
return;
specTT->Incr(0, CC.nSG, int(cRefCC*tScale*tGain)); // triggering-core trigger point
specTT->Incr(0, CC.nSG, int((cRefCC-int(cRefCC))*tScale*tGain)); // to verify flatness of subsample distribution
PreSpecTT->Incr(ss0, CC.nSG, int(cRefCC*tScale*tGain)); // triggering-core trigger point
PreSpecTT->Incr(ss0, CC.nSG, int((cRefCC-int(cRefCC))*tScale*tGain)); // to verify flatness of subsample distribution
float tCCE = (cRefCC-tRefCC)*tScale*tGain; // time relative to the external trigger
specTT->Incr(1, CC.nSG, int(tCCE + speTTlen/2)); // relative time placed at the center of spectrum
PreSpecTT->Incr(ss1, CC.nSG, int(tCCE + speTTlen/2)); // relative time placed at the center of spectrum
// trigger on the second core
int iCC1 = (CC.itrig+1)%ADF::CrystalInterface::kNbCores;
......@@ -1558,12 +1543,12 @@ void PreprocessingFilterPSA::calcTT(float tRefCC, MultiHist<unsigned int>*specTT
WRITEWORKINGWAVE2(mwd->MWDptrCFD(), true); // cfd wave in the trigger
if(cRefCC1 > 1.f) {
specTT->Incr(0, CC.nSG+1, int(cRefCC1*tScale*tGain)); // trigger point for the second core
specTT->Incr(0, CC.nSG+1, int((cRefCC1-int(cRefCC1))*tScale*tGain)); // to verify flatness of subsample distribution
PreSpecTT->Incr(ss0, CC.nSG+1, int(cRefCC1*tScale*tGain)); // trigger point for the second core
PreSpecTT->Incr(ss0, CC.nSG+1, int((cRefCC1-int(cRefCC1))*tScale*tGain)); // to verify flatness of subsample distribution
float tCC1 = (cRefCC1-tRefCC)*tScale*tGain; // time relative to the external trigger
specTT->Incr(1, CC.nSG+1, int(tCC1 + speTTlen/2)); // relative time placed at the center of spectrum
PreSpecTT->Incr(ss1, CC.nSG+1, int(tCC1 + speTTlen/2)); // relative time placed at the center of spectrum
float tCC2 = (cRefCC1-cRefCC)*tScale*tGain; // timing between the two cores
specTT->Incr(1, CC.nSG+2, int(tCC2 + speTTlen/2)); // relative time placed at the center of spectrum
PreSpecTT->Incr(ss1, CC.nSG+2, int(tCC2 + speTTlen/2)); // relative time placed at the center of spectrum
}
//#define TT_FOR_ALL_SEGMENT_MULTIPLICITIES
......@@ -1582,33 +1567,33 @@ void PreprocessingFilterPSA::calcTT(float tRefCC, MultiHist<unsigned int>*specTT
if(tRefSG < 1.f)
continue;
specTT->Incr(0, theSeg, int(tRefSG*tScale*tGain)); // trigger point for the segment
specTT->Incr(0, theSeg, int((tRefSG-int(tRefSG))*tScale*tGain)); // to verify flatness of subsample distribution
PreSpecTT->Incr(ss0, theSeg, int(tRefSG*tScale*tGain)); // trigger point for the segment
PreSpecTT->Incr(ss0, theSeg, int((tRefSG-int(tRefSG))*tScale*tGain)); // to verify flatness of subsample distribution
float tCCSG = (tRefSG-tRefCC)*tScale*tGain; // time relative to the external trigger
if(CoreE[CC.itrig] > calcTT_eminCC) {
specTT->Incr(1, theSeg, int(tCCSG + speTTlen/2)); // relative time placed at the center of spectrum
}
if(matrETsg) {
matrETsg->Incr(theSeg, (int)(fEnergyGainET*SegE[theSeg]), int(tCCSG+matTTdim/2)); // seg-gamma-time
PreSpecTT->Incr(ss1, theSeg, int(tCCSG + speTTlen/2)); // relative time placed at the center of spectrum
}
if(matrTT) {
if(PreMatrTT) {
int t1 = int(cRefCC*tScale - 100); // offset depends on electronics
int t2 = int(tRefSG*tScale - 100); // and should be adjusted manually
if(t1>0 && t1<matTTdim && t2>0 && t2<matTTdim) {
int n1 = (theSeg/6)*matTTdim; // sectors
int n2 = (theSeg%6)*matTTdim; // slices
matrTT->Incr(t1+n1, t2+n2);
PreMatrTT->Incr(sm0, t1+n1, t2+n2);
}
}
if(bEsTs && PreMatrEsTs) {
PreMatrEsTs->Incr(theSeg, (int)(fEnergyGainET*SegE[theSeg]), int(tCCSG+matTTdim/2)); // seg-gamma-time
}
}
}
void PreprocessingFilterPSA::calcTTPulser(float tRefCC, MultiHist<unsigned int>*specTT, MultiHist<unsigned short>*matrTT, MultiHist<unsigned short>*matrETsg)
void PreprocessingFilterPSA::calcTTPulser(float tRefCC, int ss0, int ss1, int sm0, bool bEsTs)
{
if(!specTT)
if(!PreSpecTT)
return;
specTT->Incr(0, CC.nSG+2, int(tRefCC*tScale*tGain)); // "external" trigger point (usually from the CC+Netcharges)
PreSpecTT->Incr(ss0, CC.nSG+2, int(tRefCC*tScale*tGain)); // "external" trigger point (usually from the CC+Netcharges)
// trigger on the core
float cRefCC = FindTriggerTime(fTracesCC[CC.itrig], trigFraction, trigChansCC);
......@@ -1626,18 +1611,18 @@ void PreprocessingFilterPSA::calcTTPulser(float tRefCC, MultiHist<unsigned int>*
// practically no improvement
#endif
specTT->Incr(0, CC.nSG, int(cRefCC*tScale*tGain)); // triggering-core trigger point
PreSpecTT->Incr(ss0, CC.nSG, int(cRefCC*tScale*tGain)); // triggering-core trigger point
float tCCE = (cRefCC-tRefCC)*tScale*tGain; // time relative to the external trigger
specTT->Incr(1, CC.nSG+2, int(tCCE + speTTlen/2)); // relative time placed at the center of spectrum
PreSpecTT->Incr(ss1, CC.nSG+2, int(tCCE + speTTlen/2)); // relative time placed at the center of spectrum
// the second core
int iCC1 = (CC.itrig+1)%ADF::CrystalInterface::kNbCores;
float cRefCC1 = FindTriggerTime(fTracesCC[iCC1], trigFraction, trigChansCC);
if(cRefCC1 > 1.f) {
specTT->Incr(0, CC.nSG+1, int(cRefCC1*tScale*tGain));
PreSpecTT->Incr(ss0, CC.nSG+1, int(cRefCC1*tScale*tGain));
float tCC1 = (cRefCC1-cRefCC)*tScale*tGain;
specTT->Incr(1, CC.nSG+1, int(tCC1 + speTTlen/2));
PreSpecTT->Incr(ss1, CC.nSG+1, int(tCC1 + speTTlen/2));
}
float tsg0 = 0, tsg1 = 0;
......@@ -1646,26 +1631,26 @@ void PreprocessingFilterPSA::calcTTPulser(float tRefCC, MultiHist<unsigned int>*
if(iSegLast == 0) tsg0 = tRefSG;
if(iSegLast == 1) tsg1 = tRefSG;
if(tRefSG > 1.f) {
specTT->Incr(0, iSegLast, int(tRefSG*tScale*tGain)); // trigger point for the segment
PreSpecTT->Incr(ss0, iSegLast, int(tRefSG*tScale*tGain)); // trigger point for the segment
float tCCSG = (tRefSG-cRefCC)*tScale*tGain; // time relative to the triggering core
if(CoreE[CC.itrig] > calcTT_eminCC)
specTT->Incr(1, iSegLast, int(tCCSG + speTTlen/2)); // relative time placed at the center of spectrum
if(matrETsg) {
matrETsg->Incr(iSegLast, (int)(fEnergyGainET*CoreE[0]), int(tCCSG+matTTdim/2)); // seg-gamma-time
}
if(matrTT) {
PreSpecTT->Incr(ss1, iSegLast, int(tCCSG + speTTlen/2)); // relative time placed at the center of spectrum
if(PreMatrTT) {
int t1 = (unsigned int)(cRefCC*tScale - 100); // offset depends on electronics
int t2 = (unsigned int)(tRefSG*tScale - 100); // and should be adjusted manually
if(t1>0 && t1<matTTdim && t2>0 && t2<matTTdim) {
unsigned int n1 = (iSegLast/6)*matTTdim; // sectors
unsigned int n2 = (iSegLast%6)*matTTdim; // slices
matrTT->Incr(t1+n1, t2+n2);
PreMatrTT->Incr(sm0, t1+n1, t2+n2);
}
}
if(bEsTs && PreMatrEsTs) {
PreMatrEsTs->Incr(iSegLast, (int)(fEnergyGainET*CoreE[0]), int(tCCSG+matTTdim/2)); // seg-gamma-time
}
}
}
if(nSegFold==2) {
specTT->Incr(1, CC.nSG, int((tsg1-tsg0)*tScale*tGain + speTTlen/2)); // relative time placed at the center of spectrum
PreSpecTT->Incr(ss1, CC.nSG, int((tsg1-tsg0)*tScale*tGain + speTTlen/2)); // relative time placed at the center of spectrum
}
}
......@@ -1727,53 +1712,6 @@ float PreprocessingFilterPSA::FindRiseTime(float *data)
return float(t90-t10);
}
void PreprocessingFilterPSA::CheckTiming(float *fWW)
{
if(!PreMatrTT3)
return;
#ifdef TIMING_CFD
float tFract = mwd->fFractCDF;
int tSmooth = mwd->nSmooth;
mwd->fFractCDF = 0.20f;
mwd->nSmooth = 0;
float cRefCC1 = FindTriggerTime(fWW, trigFraction, trigChansCC);
mwd->fFractCDF = 0.30f;
mwd->nSmooth = 5;
float cRefCC2 = FindTriggerTime(fWW, trigFraction, trigChansCC);
mwd->fFractCDF = tFract; // leave it as it was
mwd->nSmooth = tSmooth;
#else
float cRefCC1 = FindTriggerTime(fWW, .10f, 5);
float cRefCC2 = FindTriggerTime(fWW, .10f, 10);
#endif
if(cRefCC1 > 1.f && cRefCC2 > 1.f) {
// 1-2
int iRefCC1 = int(tStep*cRefCC1);
int iRefCC2 = int(tStep*cRefCC2);
PreMatrTT3->Incr(0, iRefCC1, iRefCC2);
// int(1)-2
iRefCC1 = 10*int(cRefCC1);
iRefCC2 = int(tStep*cRefCC2);
PreMatrTT3->Incr(1, iRefCC1, iRefCC2);
// int(2)-1
iRefCC1 = int(tStep)*int(cRefCC2);
iRefCC2 = int(tStep*cRefCC1);
PreMatrTT3->Incr(2, iRefCC1, iRefCC2);
// int(1)-1
iRefCC1 = int(tStep)*int(cRefCC1);
iRefCC2 = int(tStep*cRefCC1);
PreMatrTT3->Incr(3, iRefCC1, iRefCC2);
// int(2)-2
iRefCC1 = int(tStep)*int(cRefCC2);
iRefCC2 = int(tStep*cRefCC2);
PreMatrTT3->Incr(4, iRefCC1, iRefCC2);
}
}
</