15#include "FairLogger.h"
16#include "FairRootManager.h"
17#include "FairRunAna.h"
18#include "FairRuntimeDb.h"
24#include "R3BTCalEngine.h"
25#include "R3BTCalPar.h"
26#include "TClonesArray.h"
31 : FairTask(
"NeulandMapped2Cal", 1)
36 , fMappedTrigger(NULL)
38 , fCal(new TClonesArray(
"R3BNeulandCalData"))
42 , fClockFreq(1. / VFTX_CLOCK_MHZ * 1000.)
47 : FairTask(name, iVerbose)
52 , fMappedTrigger(NULL)
54 , fCal(new TClonesArray(
"R3BNeulandCalData"))
58 , fClockFreq(1. / VFTX_CLOCK_MHZ * 1000.)
74 fNofTcalPars = fTcalPar->GetNumModulePar();
76 if (fNofTcalPars == 0)
78 LOG(error) <<
"There are no TCal parameters in container LandTCalPar";
82 LOG(info) <<
"R3BNeulandMapped2Cal::Init : read " << fNofTcalPars <<
" calibrated modules";
84 FairRootManager* mgr = FairRootManager::Instance();
87 LOG(fatal) <<
"FairRootManager not found";
90 header =
dynamic_cast<R3BEventHeader*
>(mgr->GetObject(
"EventHeader."));
93 LOG(fatal) <<
"Branch R3BEventHeader not found";
96 fMapped =
dynamic_cast<TClonesArray*
>(mgr->GetObject(
"NeulandMappedData"));
99 LOG(fatal) <<
"Branch NeulandMapped not found";
101 fMappedTrigger =
dynamic_cast<TClonesArray*
>(mgr->GetObject(
"NeulandTrigMappedData"));
102 if (NULL == fMappedTrigger)
104 LOG(info) <<
"Branch NeulandTrigMapped not found";
107 mgr->Register(
"NeulandCalData",
"Neuland", fCal, kTRUE);
110 htcal1 =
new TH2F(
"htcal1",
"htcal1", 800, 0.5, 800.5, 500, -1., 6.);
111 htcal2 =
new TH2F(
"htcal2",
"htcal2", 800, 0.5, 800.5, 500, -1., 6.);
112 htcal3 =
new TH2F(
"htcal3",
"htcal3", 800, 0.5, 800.5, 500, -1., 6.);
113 htcal4 =
new TH2F(
"htcal4",
"htcal4", 800, 0.5, 800.5, 500, -1., 6.);
116 R3BLOG(info,
"Read " << fNofTcalPars <<
" modules");
123 FairRuntimeDb* rtdb = FairRuntimeDb::instance();
124 R3BLOG_IF(error, !rtdb,
"FairRuntimeDb not found");
127 R3BLOG_IF(warn, !fMapPar,
"Could not get access to neulandMappingPar container");
129 fTcalPar =
dynamic_cast<R3BTCalPar*
>(rtdb->getContainer(
"LandTCalPar"));
133 LOG(error) <<
"Could not get access to LandTCalPar-Container.";
139void R3BNeulandMapped2Cal::SetParameter()
149 fNofTcalPars = fTcalPar->GetNumModulePar();
150 R3BLOG_IF(fatal, fNofTcalPars == 0,
"There are no TCal parameters in container TofdTCalPar");
165 if (header->GetTrigger() != fTrigger)
171 Int_t nHits = fMapped->GetEntriesFast();
174 if (nHits < fNofPMTs)
181 if (nHits > (fNofPMTs / 2))
187 if (nHits >= fNhitmin)
193void R3BNeulandMapped2Cal::MakeCal()
197 std::vector<double> trig_map(13 * fNofPlanes);
200 nHits = fMappedTrigger->GetEntriesFast();
201 for (
int i = 0; i < nHits; ++i)
205 auto par = fTcalPar->GetModuleParAt(100, iBar, 10);
210 auto time = par->GetTimeVFTX(mapped->fFineTime1LE);
211 trig_map.at(iBar - 1) = fClockFreq - time + mapped->fCoarseTime1LE * fClockFreq;
214 nHits = fMapped->GetEntriesFast();
216 R3BTCalModulePar* par;
222 for (Int_t ihit = 0; ihit < nHits; ihit++)
224 R3BPaddleTamexMappedData* hit =
dynamic_cast<R3BPaddleTamexMappedData*
>(fMapped->At(ihit));
236 auto trig_i = fMapPar->GetTrigMap(iPlane, iBar, iSide);
237 double trig_ns = NAN;
239 trig_ns = trig_map.at(trig_i);
247 if ((iPlane < 1) || (iPlane > fNofPlanes))
249 LOG(info) <<
"R3BNeulandMapped2TCal::Exec : Plane number out of range: " << iPlane;
252 if ((iBar < 1) || (iBar > fNofBarsPerPlane))
254 LOG(info) <<
"R3BNeulandMapped2TCal::Exec : Bar number out of range: " << iBar;
258 int edge = 2 * iSide - 1;
261 if (!(par = fTcalPar->GetModuleParAt(iPlane, iBar, edge)))
263 LOG(debug) <<
"R3BNeulandTcal::Exec : Tcal par not found, barId: " << iBar <<
", side: " << iSide;
268 timeLE = par->GetTimeVFTX(tdc);
271 if (!(par = fTcalPar->GetModuleParAt(iPlane, iBar, edge + 1)))
273 LOG(debug) <<
"R3BNeulandTcal::Exec : Tcal par not found, barId: " << iBar <<
", side: " << iSide;
278 timeTE = par->GetTimeVFTX(tdc);
280 if (timeLE < 0. || timeLE > fClockFreq || timeTE < 0. || timeTE > fClockFreq)
282 LOG(error) <<
"R3BNeulandMapped2Tcal::Exec : error in time calibration: ch= " << iPlane << iBar << iSide
283 <<
", tdc= " << tdc <<
", time leading edge = " << timeLE <<
", time trailing edge = " << timeTE;
289 htcal1->Fill((iPlane - 1) * 50 + iBar, timeLE);
290 htcal2->Fill((iPlane - 1) * 50 + iBar, timeTE);
294 htcal3->Fill((iPlane - 1) * 50 + iBar, timeLE);
295 htcal4->Fill((iPlane - 1) * 50 + iBar, timeTE);
299 timeLE = fClockFreq - timeLE + coarse * fClockFreq;
301 timeTE = fClockFreq - timeTE + coarse * fClockFreq;
303 if (timeTE - timeLE < 0)
305 qdc = 2048 * fClockFreq + timeTE - timeLE;
309 qdc = timeTE - timeLE;
313 timeLE = timeLE + WalkCorrection(qdc);
315 new ((*fCal)[fNPmt]) R3BNeulandCalData((iPlane - 1) * 50 + iBar, iSide, timeLE, trig_ns, qdc);
317 LOG(debug2) <<
"tot: " << qdc <<
"lt: " << timeLE <<
"trigT: " << trig_ns <<
"\n";
335 if (fVerbose && 0 == (fNEvents % 100000))
337 LOG(info) <<
"R3BNeulandMapped2Cal::Exec : event=" << fNEvents <<
" nPMTs=" << fNPmt;
358Double_t R3BNeulandMapped2Cal::WalkCorrection(Double_t x)
364 x = x * 17.2278 / 162.464;
366 y0 = -4.29359 + 17.3841 / sqrt(x) + 0.073181;
368 y1 = 1.59667 + 78.5274 * pow(x, -1.97051) - 4.00192 / x - 0.125473 * x + 0.00130958 * x * x;
#define R3BLOG(severity, x)
#define R3BLOG_IF(severity, condition, x)
ClassImp(R3B::Neuland::Cal2HitPar)
An analysis task to apply TCAL calibration for NeuLAND.
virtual InitStatus ReInit()
Method for re-initialization of parameter containers in case the Run ID has changed.
virtual void FinishTask()
Method for finish of the task execution.
virtual void SetParContainers()
Method for initialization of the parameter containers.
virtual void FinishEvent()
A method for finish of processing of an event.
R3BNeulandMapped2Cal()
Default constructor.
virtual InitStatus Init()
Method for task initialization.
virtual ~R3BNeulandMapped2Cal()
Destructor.
virtual void Exec(Option_t *option)
Method for event loop implementation.
const Int_t GetNbPaddles()
const Int_t GetNbPlanes()
Accessor functions.
const Int_t & GetPlaneId() const
const Int_t & GetBarId() const