56 cout <<
"In DTACHit_factory::init" << endl;
66 bool printMessages =
false;
67 if (addRun(runnumber)) {
72 jout <<
"In DTACHit_factory, loading constants..." << endl;
74 readCCDB( eventLoop );
84 makeFADCHits(eventLoop, eventNumber);
85 makeTDCHits(eventLoop, eventNumber);
92 map<string, double> scaleFactors;
94 if (eventLoop->GetCalib(
"/TAC/digi_scales", scaleFactors))
95 jout <<
"Error loading /TAC/digi_scales !" << endl;
96 if (scaleFactors.find(
"TAC_ADC_ASCALE") != scaleFactors.end())
97 energyScale = scaleFactors[
"TAC_ADC_ASCALE"];
99 jerr <<
"Unable to get TAC_ADC_ASCALE from /TAC/digi_scales !" << endl;
101 if (scaleFactors.find(
"TAC_ADC_TSCALE") != scaleFactors.end())
102 timeScaleADC = scaleFactors[
"TAC_ADC_TSCALE"];
104 jerr <<
"Unable to get TAC_ADC_TSCALE from /TAC/digi_scales !" << endl;
107 map<string, double> baseTimeOffsets;
109 if (eventLoop->GetCalib(
"/TAC/base_time_offset", baseTimeOffsets))
110 jout <<
"Error loading /TAC/base_time_offset !" << endl;
111 if (baseTimeOffsets.find(
"TAC_BASE_TIME_OFFSET") != baseTimeOffsets.end())
112 timeBaseADC = baseTimeOffsets[
"TAC_BASE_TIME_OFFSET"];
115 <<
"Unable to get TAC_BASE_TIME_OFFSET from /TAC/base_time_offset !"
118 if (baseTimeOffsets.find(
"TAC_TDC_BASE_TIME_OFFSET")
119 != baseTimeOffsets.end())
120 timeBaseTDC = baseTimeOffsets[
"TAC_TDC_BASE_TIME_OFFSET"];
123 <<
"Unable to get TAC_TDC_BASE_TIME_OFFSET from /TAC/base_time_offset !"
128 if (eventLoop->GetCalib(
"/TAC/gains", energyGain))
129 jout <<
"Error loading /TAC/gains !" << endl;
131 if (eventLoop->GetCalib(
"/TAC/pedestals", adcPedestal))
132 jout <<
"Error loading /TAC/pedestals !" << endl;
134 if (eventLoop->GetCalib(
"/TAC/adc_timing_offsets", adcTimeOffset))
135 jout <<
"Error loading /TAC/adc_timing_offsets !" << endl;
137 if (eventLoop->GetCalib(
"/TAC/timing_offsets", tdcTimeOffsets))
138 jout <<
"Error loading /TAC/timing_offsets !" << endl;
140 if (eventLoop->GetCalib(
"TAC/timewalk_parms", timeWalkParameters))
141 jout <<
"Error loading /TAC/timewalk_parms !" << endl;
147 uint64_t eventNumber) {
149 eventLoop->GetSingle(locTTabUtilities);
152 vector<const DTACDigiHit*> tacDigiHits;
153 eventLoop->Get(tacDigiHits);
155 for (
auto& tacDigiHit : tacDigiHits) {
157 if (errorCheckIsNeededForFADC()
159 tacDigiHit->getQF()))
166 double nsamples_integral = tacDigiHit->getNsamplesIntegral();
167 double nsamples_pedestal = tacDigiHit->getNsamplesPedestal();
170 if (nsamples_pedestal == 0) {
171 jerr <<
"DSCDigiHit with nsamples_pedestal == 0 ! Event = "
172 << eventNumber << endl;
178 if ((tacDigiHit->getPedestal() > 0)
180 && nsamples_pedestal > 0) {
181 pedestal = (double) tacDigiHit->getPedestal() / nsamples_pedestal;
185 if (tacDigiHit->getPulseTime() == 0 || tacDigiHit->getPedestal() == 0
186 || tacDigiHit->getPulsePeak() == 0)
188 double pulse_peak = tacDigiHit->getPulsePeak() -
pedestal;
191 double pulseIntegral = (double) tacDigiHit->getPulseIntegral()
192 - pedestal * nsamples_integral;
194 double pulseTime = (double) tacDigiHit->getPulseTime();
198 tacHit->
setE(energyScale * energyGain * pulseIntegral);
201 timeScaleADC * pulseTime - adcTimeOffset + timeBaseADC);
203 tacHit->
setTimeTDC(numeric_limits<double>::quiet_NaN());
218 tacHit->AddAssociatedObject(tacDigiHit);
220 _data.push_back(tacHit);
232 eventLoop->GetSingle(locTTabUtilities);
234 vector<const DTACTDCDigiHit*> tacTDCDigiHits;
235 eventLoop->Get(tacTDCDigiHits);
237 for (
auto& tacTDCDigiHit : tacTDCDigiHits) {
241 tacTDCDigiHit) - timeBaseTDC;
248 if (fabs(tdcTime) < timeWindowTDC) {
249 DTACHit *tacHitCombined = findMatch(tdcTime);
250 if (tacHitCombined ==
nullptr) {
253 tacHitCombined =
new DTACHit();
254 tacHitCombined->
setE(0.0);
256 numeric_limits<double>::quiet_NaN());
258 _data.push_back(tacHitCombined);
262 tacHitCombined->
setT(tdcTime);
265 if (useTimeWalkCorrections && (tacHitCombined->
getE() > 0.0)) {
277 double C1 = timeWalkParameters[1];
278 double C2 = timeWalkParameters[2];
279 double A_THRESH = timeWalkParameters[3];
280 double A0 = timeWalkParameters[4];
283 * (pow(A / A_THRESH, C2) - pow(A0 / A_THRESH, C2));
285 tacHitCombined->
setT(tdcTime);
287 tacHitCombined->AddAssociatedObject(tacTDCDigiHit);
301 DTACHit *bestMatchedHit =
nullptr;
305 for (
auto& adcHit : _data) {
307 if (!isfinite(adcHit->getTimeFADC()))
310 double deltaT = fabs(adcHit->getTimeFADC() - tdcTime);
311 if (deltaT > timeDifferencInADCandTDC)
314 if (bestMatchedHit !=
nullptr) {
315 if (deltaT < fabs(bestMatchedHit->
getTimeFADC() - tdcTime))
316 bestMatchedHit = adcHit;
318 bestMatchedHit = adcHit;
320 return bestMatchedHit;
bool CheckFADC250_NoErrors(uint32_t QF) const
static set< int > announcedRuns
virtual jerror_t readCCDB(jana::JEventLoop *loop)
void setTimeTDC(double timeTdc=0)
double Convert_DigiTimeToNs_CAEN1290TDC(const JObject *locTDCDigiHit) const
static bool useTimeWalkCorrections
static bool checkErrorsOnFADC
double getPulsePeak() const
virtual void makeTDCHits(jana::JEventLoop *loop, uint64_t eventnumber)
void setTimeFADC(double timeFadc=0)
virtual jerror_t fini(void) override
Called after last event of last event source has been processed.
virtual void makeFADCHits(jana::JEventLoop *loop, uint64_t eventnumber)
virtual void Reset_Data(void)
virtual jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber) override
Called every event.
void setFADCPresent(bool fadcPresent=false)
void setPulsePeak(double pulsePeak=0)
virtual jerror_t erun(void) override
Called everytime run number changes, if brun has been called.
virtual DTACHit * findMatch(double tdcTime)
void setTDCPresent(bool tdcPresent=false)
static double timeWindowTDC
bool CheckFADC250_PedestalOK(uint32_t QF) const
virtual jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber) override
Called everytime a new run number is detected.
static double timeDifferencInADCandTDC
static TH1I * pedestal[nChan]
virtual jerror_t init(void) override
Called once at program start.
double getTimeFADC() const