9#include <framework/datastore/StoreArray.h>
11#include <framework/logging/Logger.h>
12#include "trg/ecl/TrgEclFAMFit.h"
14#include "trg/ecl/dataobjects/TRGECLHit.h"
15#include "trg/ecl/dataobjects/TRGECLDigi0.h"
16#include "trg/ecl/dataobjects/TRGECLFAMAna.h"
95 double* TCFitSample =
new double [12];
96 double* preped =
new double [4];
98 int nbin_pedestal = 4;
99 int fam_sampling_interval = 125;
109 double IntervaldT = 125 * 0.001 / Nsmalldt;
111 int FitSleepCounter = 100;
112 int FitSleepThreshold = 2;
114 for (
int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
116 for (
int iShift = 20; iShift < (NSampling - 12); iShift++) {
119 if (FitSleepCounter <= FitSleepThreshold) {
continue;}
120 for (
int iFitSample = 0; iFitSample < 12; iFitSample++) {
121 int iReplace = iFitSample + iShift;
122 TCFitSample[iFitSample] = digiEnergy[iTCIdm][iReplace] * 1000.0;
124 if (pedFlag == 1 && iFitSample < 4) {
126 TCFitSample[iFitSample] = preped[iFitSample];
135 dTBin = (int)(ShiftdTBin + Nsmalldt);
136 if (dTBin < 1) {dTBin = 1;}
137 if (dTBin > 20) {dTBin = 20;}
141 for (
int iFitSample = 0; iFitSample < 12; iFitSample++) {
142 CoeffAAA +=
CoeffNoise31[dTBin - 1][iFitSample] * TCFitSample[iFitSample];
143 CoeffBBB +=
CoeffNoise32[dTBin - 1][iFitSample] * TCFitSample[iFitSample];
145 double deltaT = CoeffBBB / CoeffAAA;
147 ShiftdTBin = int(deltaT / IntervaldT + dTBin);
149 double fitE = CoeffAAA;
154 double condition_t = -(deltaT + dTBin * IntervaldT - fam_sampling_interval * 0.001);
156 if (fabs(condition_t) < 0.8 * (fam_sampling_interval * 0.001) && fitE >
Threshold[iTCIdm]) {
157 double fitT = condition_t + (SmallOffset + iShift + nbin_pedestal - 5) * (fam_sampling_interval * 0.001);
161 double rand_sampling_correction = digiTiming[iTCIdm][iShift] + (nbin_pedestal - iShift + 32) * fam_sampling_interval;
177 delete [] TCFitSample;
194 int ta_id[20] = {1000};
195 double ttt_a[20] = {0};
196 double ttt_b[20] = {0};
197 for (
int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
201 int maxId[500] = {0};
202 for (
int iii = 0 ; iii < 500 ; iii++) {
212 for (
int iSampling = 1; iSampling < NSampling; iSampling++) {
217 if (TCDigiE[iTCIdm][iSampling] >= max) {
219 max = TCDigiE[iTCIdm][iSampling];
220 maxId[noutput] = iSampling;
225 if (count_down >= flag_down) {
226 if (count_up >= flag_up) {
232 double NoiseLevel = 0;
233 double NoiseCount = 0;
234 for (
int iNoise = 0; iNoise < 5; iNoise++) {
235 int iNoiseReplace = (maxId[noutput] - 10) + iNoise;
236 if (iNoiseReplace >= 0) {
237 NoiseLevel += TCDigiE[iTCIdm][iNoiseReplace];
241 if (NoiseCount != 0) { NoiseLevel /= NoiseCount; }
243 TCFitEnergy[iTCIdm].push_back(TCDigiE[iTCIdm][maxId[noutput]] - NoiseLevel);
244 if (!(maxId[noutput] - 1)) {
245 for (
int jSampling = 1; jSampling < maxId[noutput] + 3; jSampling++) {
246 TCDigiE[iTCIdm][jSampling] -= NoiseLevel;
249 for (
int jSampling = maxId[noutput] - 1; jSampling < maxId[noutput] + 3; jSampling++) {
250 TCDigiE[iTCIdm][jSampling] -= NoiseLevel;
254 for (
int iSearch = 0; iSearch < 5; iSearch++) {
256 if (TCDigiE[iTCIdm][maxId[noutput] - iSearch] > 0.6 *
TCFitEnergy[iTCIdm][noutput] &&
257 TCDigiE[iTCIdm][maxId[noutput] - iSearch - 1] < 0.6 *
TCFitEnergy[iTCIdm][noutput]) {
258 ta_id[noutput] = maxId[noutput] - iSearch - 1;
263 if (ta_id[noutput] == 1000) {
264 printf(
"TrgEclFAMFit::digi02> Cannot find TC Timing (TCId=%5i, E=%8.5f)!!!\n", iTCIdm - 1,
TCFitEnergy[iTCIdm][0]);
265 B2ERROR(
"TrgEclFAMFit::digi02> Cannot find TC Timing");
267 ttt_a[noutput] = TCDigiT[iTCIdm][ta_id[noutput]];
268 ttt_b[noutput] = TCDigiT[iTCIdm][ta_id[noutput] + 1];
270 (0.6 *
TCFitEnergy[iTCIdm][noutput] - TCDigiE[iTCIdm][ta_id[noutput]]) * (ttt_b[noutput] -
272 / (TCDigiE[iTCIdm][ta_id[noutput] + 1] - TCDigiE[iTCIdm][ta_id[noutput]])) - (278.7 + 2) + (
_DataBase->
GetTCFLatency(iTCIdm + 1)));
312 float max_shape_time = 563.48;
314 for (
int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
316 int maxId[500] = {0};
322 for (
int iSampling = 1; iSampling < NSampling; iSampling++) {
324 if (TCDigiEnergy[iTCIdm][iSampling] >= max) {
326 max = TCDigiEnergy[iTCIdm][iSampling];
327 maxId[noutput] = iSampling;
332 if (count_down >= flag_down) {
333 if (count_up >= flag_up) {
339 float NoiseLevel = 0;
340 float NoiseCount = 0;
341 for (
int iNoise = 0; iNoise < 42; iNoise++) {
342 int iNoiseReplace = (maxId[noutput] - 88) + iNoise;
343 if (iNoiseReplace >= 0) {
344 NoiseLevel += TCDigiEnergy[iTCIdm][iNoiseReplace];
348 if (NoiseCount != 0) { NoiseLevel /= NoiseCount; }
349 TCFitEnergy[iTCIdm].push_back(TCDigiEnergy[iTCIdm][maxId[noutput]] - NoiseLevel);
372 std::vector<int> TCId;
373 std::vector<double> RawTCTiming;
374 std::vector<double> RawTCEnergy;
375 std::vector<double> RawBeamBkgTag;
376 RawBeamBkgTag.clear();
388 for (
int ii = 0; ii < trgeclDigiArray.
getEntries(); ii++) {
391 if (
EventId != eventid) {
continue;}
392 TCId.push_back(aTRGECLDigi->
getTCId());
393 RawTCTiming.push_back(aTRGECLDigi -> getRawTiming());
394 RawTCEnergy.push_back(aTRGECLDigi -> getRawEnergy());
395 RawBeamBkgTag.push_back(aTRGECLDigi -> getBeamBkgTag());
398 for (
int iTCId = 0; iTCId < 576 ; iTCId ++) {
400 for (
int iHit = 0; iHit < hitsize; iHit++) {
401 const int rawsize = TCId.size();
402 for (
int iDigi = 0; iDigi < rawsize; iDigi++) {
403 if (TCId[iDigi] != (iTCId + 1)) {
continue;}
404 if (abs(
TCFitEnergy[iTCId][iHit] - RawTCEnergy[iDigi]) < 12) {
405 if (abs(
TCFitTiming[iTCId][iHit] - RawTCTiming[iDigi]) < 30) {
406 BeamBkgTag[iTCId].push_back(RawBeamBkgTag[iDigi]);
428 double tc_timing_correction = -15;
430 for (
int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
432 for (
int iHit = 0; iHit < hitsize; iHit++) {
436 TrgEclHitArray[hitNum]->setEventId(m_nEvent);
437 TrgEclHitArray[hitNum]->setTCId(iTCIdm + 1);
438 TrgEclHitArray[hitNum]->setEnergyDep(
TCFitEnergy[iTCIdm][iHit]);
439 TrgEclHitArray[hitNum]->setTimeAve(
TCFitTiming[iTCIdm][iHit] + tc_timing_correction);
441 TrgEclHitArray[hitNum]->setBeamBkgTag(
BeamBkgTag[iTCIdm][iHit]);
447 for (
int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
450 for (
int iHit = 0; iHit < hitsize; iHit++) {
454 TrgEclAnaArray[hitNum]->setEventId(m_nEvent);
455 TrgEclAnaArray[hitNum]->setTCId(iTCIdm + 1);
458 TrgEclAnaArray[hitNum]->setRawEnergy(
TCRawEnergy[iTCIdm][iHit]);
459 TrgEclAnaArray[hitNum]->setRawTiming(
TCRawTiming[iTCIdm][iHit]);
463 int ene_i0 = (int)(
TCFitEnergy[iTCIdm][iHit] * 100000.0 / p_ene2adc);
464 double ene_d = (double) ene_i0 * p_ene2adc / 100000;
465 TrgEclAnaArray[hitNum]->setFitEnergy(ene_d);
467 TrgEclAnaArray[hitNum]->setFitTiming(
TCFitTiming[iTCIdm][iHit] + tc_timing_correction);
468 TrgEclAnaArray[hitNum]->setBeamBkgTag(
BeamBkgTag[iTCIdm][iHit]);
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
int getEntries() const
Get the number of objects in the array.
Raw TC result nefor digitizing.
int getEventId() const
Get event id.
int getTCId() const
Get TC id.
double GetTCFLatency(int)
TC flight time latency
int _BeamBkgTag
Add beambkg.
std::vector< std::vector< double > > CoeffSigPDF1
Coeffisients of signal PDF1.
void save(int)
save fitting result into tables
std::vector< std::vector< int > > BeamBkgTag
fit timing
int _AnaTag
Fill Analysis table.
void setup(int)
setup fam module
std::vector< std::vector< double > > CoeffNoise32
Coeffisient of noise 2.
TrgEclFAMFit()
Constructor.
std::vector< std::vector< double > > TCFitEnergy
fit energy
std::vector< std::vector< double > > CoeffSigPDF0
Coeffisients of signal PDF0
std::vector< std::vector< double > > TCFitTiming
fit timing
TrgEclDataBase * _DataBase
Object of DataBase.
std::vector< std::vector< double > > TCRawTiming
Raw timing.
std::vector< std::vector< double > > CoeffNoise31
Coeffisients of noise 1.
void SetBeamBkgTag()
Set Beam Background Tag.
virtual ~TrgEclFAMFit()
Destructor.
std::vector< std::vector< double > > CoeffNoise33
Coeffisient of noise 3
std::vector< double > TCLatency
TC Latency.
std::vector< std::vector< double > > TCRawEnergy
Raw energy.
void FAMFit02(std::vector< std::vector< double > >, std::vector< std::vector< double > >)
function for backup 1
void FAMFit01(std::vector< std::vector< double > >, std::vector< std::vector< double > >)
function for fitting
int EventId
Fill Analysis table.
void FAMFit03(std::vector< std::vector< double > >, std::vector< std::vector< double > >)
function for backup2
std::vector< int > Threshold
Threshold (MeV)
TrgEclMapping * _TCMap
Object of TC Mapping.
int getTCThetaIdFromTCId(int)
get [TC Theta ID] from [TC ID]
int getTCPhiIdFromTCId(int)
get [TC Phi ID] from [TC ID]
Abstract base class for different kinds of events.