Commit 38e00744 authored by dino's avatar dino
Browse files

Beautifications


git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1039 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 2683071a
#ifndef DATAPAIRFILE_H_INCLUDED
#define DATAPAIRFILE_H_INCLUDED
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory.h>
// manages files containing pairs of values
// binary (buffered) or (unbuffered) space-separated ascii
// read or write mode
template <typename T1, typename T2>
class dataPairFile
{
typedef struct {
T1 value1;
T2 value2;
} spec_t;
public:
FILE *fp;
std::string fname;
bool status;
bool asciiMode;
bool writeMode;
unsigned int count;
unsigned int length;
unsigned int totcount;
spec_t *spec;
dataPairFile(std::string fn, bool amode = false, bool wmode = false, int len = 1024) :
fp(NULL), status(false), asciiMode(amode), writeMode(wmode), count(0), length(0), totcount(0), spec(NULL)
{
fname = fn;
length = (len > 0) ? len : 1024;
spec = new spec_t[length];
clear();
totcount = 0;
if(asciiMode) {
fp = false; // to be done
//if(wmode)
// fp = fopen(fname.c_str(), "w");
//else
// fp = fopen(fname.c_str(), "r");
}
else {
if(wmode) {
fp = fopen(fname.c_str(), "wb");
count = 0;
}
else {
fp = fopen(fname.c_str(), "rb");
count = length;
}
}
status = (fp != NULL);
}
~dataPairFile()
{
putbuf();
if(fp) {
fclose(fp);
std::cout << fname << " --> " << totcount << " counts "
<< " ( " << (totcount + length-1)/length << "*" << length << " )" << std::endl;
}
}
void clear()
{
memset(spec, 0, sizeof(spec_t)*length);
count = 0;
}
void putbuf()
{
if(fp && writeMode && count) {
totcount += count;
size_t nn = fwrite(spec, sizeof(spec_t), count, fp);
status = (nn == count);
clear();
}
}
void getbuf()
{
if(writeMode || !fp) {
count = 1000;
status = false;
}
else {
if(count>=length) {
totcount += count;
size_t nn = fread(spec, sizeof(spec_t), length, fp);
status = (nn == length);
if(!status && nn > 0) {
length = (unsigned int)nn;
status = true;
}
count = status? 0 : 1000;
}
}
}
bool put(T1 val1, T2 val2)
{
if(!writeMode)
return false;
if(count == length)
putbuf();
spec[count].value1 = val1;
spec[count].value2 = val2;
count++;
return true;
}
bool get(T1 &val1, T2 &val2)
{
if(writeMode)
return false;
if(count >= length)
getbuf();
val1 = spec[count].value1;
val2 = spec[count].value2;
count++;
return true;
}
};
#endif // DATAPAIRFILE_H_INCLUDED
......@@ -43,7 +43,6 @@ fTrigger("data:crystal")
SpectraDB ->SetfDefaultHostName((char*)gSystem->HostName());
NetworkRoot->SetVerbose(0);
NetworkRoot->StartGNetServer(false);
cout << "GRU port opened " << port << endl;
#endif // AF_FromGRU_
......
......@@ -53,9 +53,7 @@ AncillaryFilterVME::AncillaryFilterVME()
SpectraDB ->SetfDefaultHostName((char*)gSystem->HostName());
NetworkRoot->SetVerbose(0);
NetworkRoot->StartGNetServer(false);
cout << "GRU port opened " << port << endl;
memset(XFP, 0, sizeof(XFP));
#endif // AF_FromGRU_
......@@ -89,7 +87,6 @@ AncillaryFilterVME::~AncillaryFilterVME()
delete EDE;
delete MCP, PRISMA_MCPcal, TOF_D, Ic_Range;
delete AllChan, PRISMA_Vel, PRISMA_X_FP, tmp_ERR;
for(int nn = 0; nn < 10; nn++) {
delete [] LR_Cath[nn];
delete [] TOF[nn];
......@@ -311,28 +308,22 @@ void AncillaryFilterVME::Analysis()
// TxTy_Dante0->Fill( Converter[3].GetValue(0),Converter[3].GetValue(1));
// TxTy_Dante1->Fill( Converter[3].GetValue(2),Converter[3].GetValue(3));
//}
int tofGood=0;
for (int ii=22; ii<32; ii++){
if (Converter[0].GetValue(ii) > 200.f) {
tofGood++;
break;
}
}
if (tofGood) {
MCP->Fill(Converter[0].GetValue(16),Converter[0].GetValue(17));
EDE->Fill(
Converter[1].GetValue(0)+Converter[1].GetValue(1)+Converter[1].GetValue(2)+Converter[1].GetValue(3),
Converter[1].GetValue(0) );
}
//TimingLaBrLaBr->Fill( Converter[1].GetValue(13), Converter[1].GetValue(14));
//TimingLaBrGe ->Fill( Converter[1].GetValue(13), Converter[1].GetValue(6));
//TimingLaBrGe1 ->Fill( Converter[1].GetValue(13), Converter[1].GetValue(4));
#endif // AF_FromGRU_ && AF_PRISMA
#if defined(AF_FromGRU_) && defined(AF_DANTE)
......@@ -344,11 +335,9 @@ void AncillaryFilterVME::Analysis()
TxTy_Dante1->Fill( Converter[0].GetValue(2),Converter[0].GetValue(3));
}
MCP->Fill( Converter[0].GetValue(5),(Float_t)Converter[0].GetValue(4));
EDE->Fill(
Converter[1].GetValue(1)+(Float_t)Converter[1].GetValue(2)+Converter[1].GetValue(3)+Converter[1].GetValue(4),
Converter[1].GetValue(2) );
//TimingLaBrLaBr->Fill( Converter[1].GetValue(13),Converter[1].GetValue(14));
//TimingLaBrGe ->Fill( Converter[1].GetValue(13),Converter[1].GetValue(6));
//TimingLaBrGe1 ->Fill( Converter[1].GetValue(13),Converter[1].GetValue(4));
......@@ -451,7 +440,6 @@ bool AncillaryFilterVME::initPresort()
SpectraDB->AddSpectrum( LR_Cath[i],"MWPPAC");
SpectraDB->AddSpectrum( TOF[i],"TOF");
}
#endif // AF_FromGRU_
return true;
......
......@@ -107,7 +107,7 @@ PSAFilterGridSearch::PSAFilterGridSearch()
PSAxz_Proje = new TH2F("PSAxz_Proje","PSAxz_Proje",128,-50,50,128,0,100);
PSAyz_Proje = new TH2F("PSAyz_Proje","PSAyz_Proje",128,-50,50,128,0,100);
// PSAxyz = new TH3F("PSAxyz","PSAxyz",128,-50,50,128,-50,50,128,0,100);
//PSAxyz = new TH3F("PSAxyz","PSAxyz",128,-50,50,128,-50,50,128,0,100);
PSASpectraDB = new GSpectra();
PSANetworkRoot = new GNetServerRoot (PSASpectraDB);
......@@ -131,7 +131,6 @@ PSAFilterGridSearch::PSAFilterGridSearch()
PSASpectraDB->AddSpectrum (PSAyz_Proje);
//PSASpectraDB->AddSpectrum (PSAxyz);
PSANetworkRoot->StartGNetServer(false); //UNCOMMENT HERE TO START THE GRU SERVER
#endif // PSA_FromGRU_
}
......@@ -143,7 +142,6 @@ PSAFilterGridSearch::~PSAFilterGridSearch()
delete PSAxz_Proje;
delete PSAyz_Proje;
#endif
}
Int_t PSAFilterGridSearch::AlgoSpecificInitialise()
......
......@@ -8,8 +8,8 @@
//
//#include "commonDefs.h"
// Define this symbol to write to file a correction to the timestamp of the events
//#define TSHIFT_CORRECTION
#ifdef TSHIFT_CORRECTION
#include "dataPairFile.h"
#endif
......
......@@ -93,9 +93,17 @@ PreprocessingFilterPSA::PreprocessingFilterPSA() :
fValueOld = 0;
#endif
// inclusion of prePSA
nNsamp = defTraceLengthRaw;
nNbase = int(0.15*nNsamp + 0.5); // 15%
if(nNbase < 1) nNbase = 1;
nEvDump = -1;
#ifdef PPF_FromGRU_
#ifdef TIMING_CFD
mwd = NULL;
#endif
#ifdef PPF_FromGRU_
CCE_raw = new TH1F("CCE_raw","CCE_raw",32768,0,32767);
CCE1_raw = new TH1F("CCE1_raw","CCE1_raw",32768,0,32767);
CCE = new TH1F("CCE","CCE",32768,0,32767);
......@@ -142,20 +150,8 @@ PreprocessingFilterPSA::PreprocessingFilterPSA() :
//
// //////HERE TO RESTART THE SERVER//////
PPNetworkRoot->StartGNetServer(false);
#endif // PPF_FromGRU_
// inclusion of prePSA
nNsamp = defTraceLengthRaw;
nNbase = int(0.15*nNsamp + 0.5); // 15%
if(nNbase < 1) nNbase = 1;
nEvDump = -1;
#ifdef TIMING_CFD
mwd = NULL;
#endif
}
PreprocessingFilterPSA::~PreprocessingFilterPSA()
......@@ -168,7 +164,6 @@ PreprocessingFilterPSA::~PreprocessingFilterPSA()
delete seg_raw;
delete CCE;
delete CCE1;
for(int nn = 0; nn < CrystalInterface::kNbSegments; nn++) {
delete [] SGTraces[nn];
}
......@@ -219,9 +214,10 @@ Int_t PreprocessingFilterPSA::AlgoSpecificInitialise()
tstmpFileI = new dataPairFile<ULong64_t, float>(GetConfPath()+"Tadjust.fdat", false, false, 1000);
#endif
#ifdef TIME_AVERAGE
// the preset value should come from the configuration file
tAverage.Initialize(30.f);
#endif
// these are initialized to the maximum length
if(fCC ) delete [] fCC; fCC = new float [defTraceLengthRaw]; memset(fCC, 0, sizeof(float)*defTraceLengthRaw);
......@@ -246,13 +242,11 @@ Int_t PreprocessingFilterPSA::Process()
//float tCC = 0; // the time correction of the triggering core (??)
#ifdef PPF_FromGRU_
CCE_raw -> Fill((int)CoreE[0]);
CCE1_raw -> Fill((int)CoreE[1]);
for (int i=0; i<CrystalInterface::kNbSegments; i++){
seg_raw->Fill(SegE[i]+i*specLenE);
}
for (int i=0; i<CrystalInterface::kNbSegments; i++){
SGTraces[i]->Reset();
for (int k=0; k<CrystalInterface::kDefaultLength; k++){
......@@ -260,7 +254,6 @@ Int_t PreprocessingFilterPSA::Process()
// std::cout << "trace_raw" <<"\t"<< k <<"\t"<< k <<"\t"<< SegmentTraces[i][k]<< "\n";
}
}
for (int i=0; i<CrystalInterface::kNbCores; i++){
CCTraces[i]->Reset();
for (int k=0; k<CrystalInterface::kDefaultLength; k++){
......@@ -268,7 +261,6 @@ Int_t PreprocessingFilterPSA::Process()
// std::cout << "trace_raw" <<"\t"<< k <<"\t"<< k <<"\t"<< CoreTraces[i][k]<< "\n";
}
}
#endif // PPF_FromGRU_
bool evok = ProcessEvent(segmult, sumE1, sumE2);
......@@ -517,25 +509,25 @@ bool PreprocessingFilterPSA::initPresort()
matrEcTc->setComment("Energy(keV)-Time(ns) for the triggering core");
hGroup.add(matrEcTc);
matrEeTr = new nDhist<unsigned short>(CC.nSG+CC.nCC+2, matETdim, 100);
matrEeTr->setFileName(fOdirPrefix+"Prep?EeTr.matr");
matrEeTr->setComment("Energy(keV)-T10-90(samp)");
hGroup.add(matrEeTr);
//matrEeTr = new nDhist<unsigned short>(CC.nSG+CC.nCC+2, matETdim, 100);
//matrEeTr->setFileName(fOdirPrefix+"Prep?EeTr.matr");
//matrEeTr->setComment("Energy(keV)-T10-90(samp)");
//hGroup.add(matrEeTr);
//matrEsTs = new nDhist<unsigned short>(CC.nSG, 100, matTTdim); // energy in steps of 20 keV, time in ns
//matrEsTs->setFileName(fOdirPrefix+"Prep?EsTs.matr");
//matrEsTs->setComment("Segments: Energy(keV)-Time(ns, relative to core)");
//hGroup.add(matrEsTs);
matrTT1 = new nDhist<unsigned short>(matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
matrTT1->setFileName(fOdirPrefix+"Prep?TT1.matr");
matrTT1->setComment("relative and absolute Core_to_Segment time, before shifting traces");
hGroup.add(matrTT1);
//matrTT1 = new nDhist<unsigned short>(matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
//matrTT1->setFileName(fOdirPrefix+"Prep?TT1.matr");
//matrTT1->setComment("relative and absolute Core_to_Segment time, before shifting traces");
//hGroup.add(matrTT1);
matrTT2 = new nDhist<unsigned short>(matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
matrTT2->setFileName(fOdirPrefix+"Prep?TT2.matr");
matrTT2->setComment("relative and absolute Core_to_Segment time, after shifting the traces");
hGroup.add(matrTT2);
//matrTT2 = new nDhist<unsigned short>(matTTdim*CC.nSG/6, matTTdim*CC.nSG/6);
//matrTT2->setFileName(fOdirPrefix+"Prep?TT2.matr");
//matrTT2->setComment("relative and absolute Core_to_Segment time, after shifting the traces");
//hGroup.add(matrTT2);
//matrTT3 = new nDhist<unsigned short>(5, 1000, 1000);
//matrTT3->setFileName(fOdirPrefix+"Prep?TT3.matr");
......@@ -983,8 +975,9 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
nNsamp = fTraceLengthRaw;
nNbase = int(0.15*nNsamp + 0.5);
if(nNbase < 1) nNbase = 1;
#ifdef TIME_AVERAGE
tAverage.Initialize(0.3f*nNsamp); // make sure that this agrees with the actual setting of the electronics
#endif
#ifdef TIMING_CFD
// reset also mwd (if used)
if(mwd) delete mwd;
......@@ -1043,15 +1036,16 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
int ieeCC = (int)(matEEgain*eCore);
int iesCC = (int)(matEEgain*sCore);
if(matrEeEtrCC)
matrEeEtrCC->Incr(0, ieeCC, iesCC);
matrEeEtrCC->Incr(0, ieeCC, iesCC); // all events
#endif
// To be excluded if BuiltinPulser
//if(sCore+purDelta < eCore*purSlope)
// return false;
if(sCore+purDelta < eCore*purSlope) {
#ifdef PPF_LOCALSPECTRA
if(matrEeEtrCC)
matrEeEtrCC->Incr(1, ieeCC, iesCC);
if(matrEeEtrCC)
matrEeEtrCC->Incr(1, ieeCC, iesCC); // rejected events
#endif
return false;
}
#endif
// calibrate segments and adjust their traces
......@@ -1077,11 +1071,11 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
if(ener > CC.pSG[nn].emink)
specEner->Incr(1, nn, (int)(ener*fEnergyGain+specOffE));
}
// until we introduce the Xtalk for the core, these spectra are the same as in [0], so don't increment them
//for(unsigned int nn = 0; nn < CC.nCC; nn++) {
// specEner->Incr(1, CC.nSG + nn, (int)(CoreE[nn]*fEnergyGain+specOffE)); // with gain
// specEner->Incr(1, CC.nSG + nn+CC.nCC, (int)(CoreE[nn] +specOffE)); // at 1 keV/ch
//}
// until we introduce the Xtalk for the core, these spectra are the same as in [0]
for(unsigned int nn = 0; nn < CC.nCC; nn++) {
specEner->Incr(1, CC.nSG + nn, (int)(CoreE[nn]*fEnergyGain+specOffE)); // with gain
specEner->Incr(1, CC.nSG + nn+CC.nCC, (int)(CoreE[nn] +specOffE)); // at 1 keV/ch
}
#endif
if(fDeadSegment >= 0) {
......@@ -1131,7 +1125,7 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
if(ener > CC.pSG[ns].emink) { // but it is better to use the individual thresholds
sumSegs += ener;
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.
......@@ -1208,7 +1202,9 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
ShiftMoveTrace(fTracesCC[iTR], nNsamp, 0, fTC);
WRITEWORKINGWAVE1(fTC, true);
// calculate the sum of net-charge waves for the trigger
// calculate the sum of 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);
for(int is = 0; is < nSegFold; is++) {
int ns = netChargeSegs[is];
......@@ -1223,8 +1219,8 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
}
WRITEWORKINGWAVE1(fTT, true);
float *fTU = fTrigUseOnlyCC ? fTC : fTT; // pointer to change in a consistent way which of the 3 calculated waves to use for triggering
float tRefCC = FindTriggerTime(fTU, trigFraction, trigChansCC); // use the sum of core + net-charge segments //PULSER_ON_CC_A1_A2((1))
float *fTU = fTrigUseOnlyCC ? fTC : fTT; // pointer to select in a consistent way which of the 3 calculated waves to use for triggering
float tRefCC = FindTriggerTime(fTU, trigFraction, trigChansCC); // use the sum of core + net-charge segments //PULSER_ON_CC_A1_A2((1))
WRITEWORKINGWAVE1(fTU, true);
WRITEWORKINGWAVE2(mwd->MWDptrTFA(), true); // timing filter wave from the trigger
WRITEWORKINGWAVE2(mwd->MWDptrCFD(), true); // cfd wave in the trigger
......@@ -1247,14 +1243,14 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
#endif
bBadCFD = (tRefCC < 1.f);
#if 0
#ifdef TIME_AVERAGE
if( bBadCFD )
tRefCC = tAverage.Get(eCore); // value taken from the stored averages
else
tAverage.Set(eCore, tRefCC); // value used to improve averages
#else
if( bBadCFD )
return false;
return false; // discard the event
#endif
// put both trigger times to the same value
......@@ -1291,8 +1287,10 @@ bool PreprocessingFilterPSA::ProcessEvent(int &smult, float &eSumSG1, float &e
// fHandShift is an ad-hoc common shift to have the traces well positioned in the PSA.
float fHandShift = CC.pCC[iTR].tmove; // CC.pCC[iTR].tmove is interpreted as global shift and should be given in units of samples !!
float fshiftCC = (defTriggerSample+defTriggerSamplePlus) - tRefCC + fHandShift;
//float extraShift = getTstampFileValue(timestamp);
//fshiftCC += extraShift;
#ifdef TSHIFT_CORRETCTION
float extraShift = getTstampFileValue(timestamp);
fshiftCC += extraShift;
#endif
for(int nc = 0; nc < nCC; nc++) {
ShiftMoveTrace(fTracesCC[nc], nNsamp, fshiftCC, tmp); // no extra shift for the cores
memcpy(fTracesCC[nc], tmp, sizeof(tmp));
......@@ -1844,8 +1842,8 @@ void PreprocessingFilterPSA::calcTT(float tRefCC, nDhist<unsigned int>*specTT, n
}
}
// Version for the analysis of the tests done by Francesco with an external pulser injected into some channels of the digitizer in order to
// determine the limits to the time resolution due to clock jitter and power noise
// Version for the analysis of the tests done by Francesco with an external pulser injected into some channels
// of the digitizer in order to determine the limits to the time resolution due to clock jitter and power noise
// It is called instead of the normal calcTT by enabling the symbol PULSER_ON_CC_A1_A2 at the beginning of this file,
// and replacing the instructions at the comments //PULSER_ON_CC_A1_A2((#)) with the following blocks of code
......
......@@ -14,15 +14,19 @@
// equal the stright line has a discretely-different zero-intercept due to the fact that the initial part of the signals is not stright.
// Until this is fixed, it is better to re-time the signals using the CFD, which is less sensitive to the problem.
// By enabling the following the re-timing of the signals inside the captured traces is done by a CFD (see MWD for details of this "interpolated" version)
// By enabling the following the re-timing of the signals inside the captured traces
// is done by a CFD (see MWD for details of this "interpolated" version)
#define TIMING_CFD
#ifdef TIMING_CFD
# include "mwdlib.h"
#endif
//#define TSHIFT_CORRECTION
// Enable this symbol to calculate an average event T0 as a function of the core
// amplitude from which to get the timing of events that have not triggered correctly
//#define TIME_AVERAGE
// Define this symbol to apply a correction to the timestamp of the events getting the value from a file
//#define TSHIFT_CORRECTION
#ifdef TSHIFT_CORRECTION
#include "dataPairFile.h"
#endif
......@@ -47,6 +51,7 @@
// Preprocessing imported from the "Padova" programs
#ifdef TIME_AVERAGE
// TimeAverage: a service class to calculate the trigger position of the CC as a function of its energy;
// used to assign a trigger position in case of failure of the timing algorithm
const float tAverFactor = 1/100.f;
......@@ -94,6 +99,7 @@ public:
return (naver) ? taver/naver : tRefDefault;
}
};
#endif // #ifdef TIME_AVERAGE
class PreprocessingFilterPSA : public PreprocessingFilter
{
......@@ -157,7 +163,9 @@ public:
int netChargeSegs[36];
float sumSegs;
TimeAverage tAverage;
#ifdef TIME_AVERAGE
TimeAverage tAverage;
#endif
#ifdef PPF_LOCALSPECTRA
nDhist<unsigned int> *specEner;
......
......@@ -2031,10 +2031,10 @@ void TrackingFilter::InitGenStructures()
//OftSpec_TTA->setComment("T_gamma-anc from CFD (ns)");
//hGroup.add(OftSpec_TTA);
OftMatr_ETA = new nDhist<unsigned short>(4096, 1024);
OftMatr_ETA->setFileName(fOdirPrefix+"Oft?EgTa-g.matr");
OftMatr_ETA->setComment("E(gamma)--T(gamma_tstamp-ancillary_tstamp)");
hGroup.add(OftMatr_ETA);
//OftMatr_ETA = new nDhist<unsigned short>(4096, 1024);
//OftMatr_ETA->setFileName(fOdirPrefix+"Oft?EgTa-g.matr");
//OftMatr_ETA->setComment("E(gamma)--T(gamma_tstamp-ancillary_tstamp)");
//hGroup.add(OftMatr_ETA);
}
#endif //#ifdef TF_LOCALSPECTRA
......
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