25#include "FairEventHeader.h"
26#include "FairMCEventHeader.h"
27#include "FairRootManager.h"
28#include "FairRunAna.h"
29#include "FairRunSim.h"
30#include "FairRuntimeDb.h"
35#include "TClonesArray.h"
45using std::setprecision;
47using std::stringstream;
60 : FairTask(TString(name), verbose)
83 LOG(info) <<
" CbmTaskTofHitFinder => Get the digi parameters for tof";
86 FairRunAna* ana = FairRunAna::Instance();
87 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
111 pair<int32_t, int32_t> result;
116 nDigis = result.first;
117 nHits = result.second;
122 nEvents =
fEvents->GetEntriesFast();
123 for (int32_t iEvent = 0; iEvent < nEvents; iEvent++) {
127 nDigis += result.first;
128 nHits += result.second;
137 logOut << setw(20) << left << GetName() <<
" [";
138 logOut << fixed << setw(8) << setprecision(1) << right <<
fTimer.RealTime() * 1000. <<
" ms] ";
140 if (
fEvents) logOut <<
", events " << nEvents;
141 logOut <<
", digis " << nDigis <<
" / " << nDigisAll;
142 logOut <<
", hits " << nHits;
143 LOG(info) << logOut.str();
157 std::cout << std::endl;
158 LOG(info) <<
"=====================================";
159 LOG(info) << GetName() <<
": Run summary";
160 LOG(info) <<
"Time slices : " <<
fiNofTs;
161 LOG(info) <<
"Digis / TS : " << fixed << setprecision(2) <<
fNofDigisAll / double(
fiNofTs);
163 LOG(info) <<
"Time / TS : " << fixed << setprecision(2) << 1000. *
fdTimeTot / double(
fiNofTs) <<
" ms";
168 LOG(info) <<
"Events / TS : " << fixed << setprecision(2) << double(
fiNofEvents) / double(
fiNofTs);
172 LOG(info) <<
"=====================================\n";
179 FairRootManager* fManager = FairRootManager::Instance();
183 LOG(error) << GetName() <<
": No TofDigi input array present; "
184 <<
"task will be inactive.";
189 fEvents =
dynamic_cast<TClonesArray*
>(fManager->GetObject(
"Event"));
191 LOG(info) << GetName() <<
": Found Event branch; run event-based";
193 fEvents =
dynamic_cast<TClonesArray*
>(fManager->GetObject(
"CbmEvent"));
195 LOG(info) << GetName() <<
": Found CbmEvent branch; run event-based";
197 LOG(info) << GetName() <<
": No event branch found; run time-based";
204 FairRootManager*
rootMgr = FairRootManager::Instance();
219 LOG(fatal) <<
" Compressed Digis not implemented ... ";
224 bool isSimulation =
false;
226 LOG(info) <<
"CbmTaskTofHitFinder::InitParameters with GeoVersion " << iGeoVersion;
228 if (
k14a > iGeoVersion) {
229 LOG(error) <<
"CbmTaskTofHitFinder::InitParameters => Only compatible "
230 "with geometries after v12b !!!";
237 switch (iGeoVersion) {
240 default: LOG(error) <<
"CbmTaskTofHitFinder::InitParameters => Invalid geometry!!!" << iGeoVersion;
return false;
244 LOG(info) <<
"=> Get the digi parameters for tof";
245 FairRunAna* ana = FairRunAna::Instance();
246 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
250 LOG(info) <<
"Create DigiPar ";
255 LOG(error) <<
"CbmTofSimpleClusterizer::InitParameters => Could not obtain "
256 "the CbmTofDigiPar ";
269 for (int32_t iT = 0; iT < iNbSmTypes; iT++) {
272 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++)
283 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
286 fvCPTOff[iSmType].resize(iNbSm * iNbRpc);
288 fvCPWalk[iSmType].resize(iNbSm * iNbRpc);
289 for (int32_t iSm = 0; iSm < iNbSm; iSm++) {
290 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
292 fvCPTOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
293 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
294 fvCPWalk[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
296 for (int32_t iCh = 0; iCh < iNbChan; iCh++) {
297 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
298 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
299 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
300 for (int32_t iSide = 0; iSide < nbSide; iSide++) {
301 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.;
302 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 1.;
305 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide][iWx] = 0.;
312 LOG(info) <<
"CbmTaskTofHitFinder::InitCalibParameter: defaults set";
313 LOG(info) <<
"CbmTaskTofHitFinder::InitCalibParameter: initialization done";
320 gGeoManager->CdTop();
327 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
335 for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
338 for (int32_t iSm = 0; iSm < iNbSm; iSm++) {
339 for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
342 par->SysTimeRes = 0.080;
344 par->outTimeFactor = 1.0;
353 par->fChanPar.resize(iNbChan);
354 for (int32_t iCh = 0; iCh < iNbChan; iCh++) {
362 Cell& cell = par->fChanPar[iCh].cell;
363 cell.
pos.SetX(channelInfo->
GetX());
364 cell.
pos.SetY(channelInfo->
GetY());
365 cell.
pos.SetZ(channelInfo->
GetZ());
370 gGeoManager->FindNode(channelInfo->
GetX(), channelInfo->
GetY(), channelInfo->
GetZ());
371 double* rot_ptr = gGeoManager->GetCurrentMatrix()->GetRotationMatrix();
372 cell.
rotation = ROOT::Math::Rotation3D(&rot_ptr[0], &rot_ptr[9]);
374 par->fChanPar[iCh].fvCPTOff = std::move(
fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh]);
375 par->fChanPar[iCh].fvCPTotGain = std::move(
fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh]);
376 par->fChanPar[iCh].fvCPWalk = std::move(
fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh]);
379 fAlgo[iSmType][iSm * iNbRpc + iRpc].SetParams(std::move(par));
389 int32_t iInputNr = 0;
390 int32_t iEventNr = 0;
391 double dEventTime = 0.;
399 LOG(debug) <<
"Number of TOF digis: " << nDigis;
402 for (int32_t iDigi = 0; iDigi < nDigis; iDigi++) {
412 fStorDigiExp[smType][smId * numRpc + rpcId].push_back(*pDigi);
413 fStorDigiInd[smType][smId * numRpc + rpcId].push_back(digiIndex);
418 for (uint32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
421 for (uint32_t iSm = 0; iSm < iNbSm; iSm++) {
422 for (uint32_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
424 const uint32_t rpcIdx = iSm * iNbRpc + iRpc;
425 std::vector<CbmTofDigi>& digiExp =
fStorDigiExp[iSmType][rpcIdx];
426 std::vector<int32_t>& digiInd =
fStorDigiInd[iSmType][rpcIdx];
429 std::vector<Cluster> clusters =
fAlgo[iSmType][rpcIdx](digiExp, digiInd);
432 for (
auto const& cluster : clusters) {
433 const int32_t hitIndex =
fTofHitsColl->GetEntriesFast();
434 TVector3 hitpos = TVector3(cluster.globalPos.X(), cluster.globalPos.Y(), cluster.globalPos.Z());
435 TVector3 hiterr = TVector3(cluster.globalErr.X(), cluster.globalErr.Y(), cluster.globalErr.Z());
436 new ((*fTofHitsColl)[hitIndex])
437 CbmTofHit(cluster.detId, hitpos, hiterr, nHits, cluster.weightedTime, cluster.weightedTimeErr, 0, 0);
442 for (uint32_t i = 0; i < cluster.vDigiIndRef.size(); i++) {
443 digiMatch->
AddLink(
CbmLink(0., cluster.vDigiIndRef.at(i), iEventNr, iInputNr));
452 return std::make_pair(nDigis, nHits);
458 if (FairRunAna::Instance()) {
459 FairEventHeader*
event = FairRunAna::Instance()->GetEventHeader();
460 inputNr =
event->GetInputFileId();
461 eventNr =
event->GetMCEntryNumber();
462 eventTime =
event->GetEventTime();
468 if (!FairRunSim::Instance()) LOG(fatal) << GetName() <<
": neither SIM nor ANA run.";
469 FairMCEventHeader*
event = FairRunSim::Instance()->GetMCEventHeader();
471 eventNr =
event->GetEventID();
ClassImp(CbmConverterManager)
@ kTof
Time-of-flight Detector.
static FairRootManager * rootMgr
const int32_t numClWalkBinX
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
Class characterising one event by a collection of links (indices) to data objects,...
void AddLink(const CbmLink &newLink)
Simple Cluster building and hit producing for CBM ToF using Digis as input.
bool InitCalibParameter()
Initialize other parameters not included in parameter classes.
CbmTofDigiBdfPar * fDigiBdfPar
bool InitAlgos()
Create one algo object for each RPC.
std::vector< std::vector< std::vector< std::vector< double > > > > fvCPTotGain
std::vector< std::vector< std::vector< CbmTofDigi > > > fStorDigiExp
CbmDigiManager * fDigiMan
TClonesArray * fTofHitsColl
double fNofDigisAll
Total number of TOF digis in input.
TStopwatch fTimer
ROOT timer.
bool RegisterInputs()
Recover pointer on input TClonesArray: TofPoints, TofDigis...
bool RegisterOutputs()
Create and register output TClonesArray of Tof Hits.
std::vector< std::vector< std::vector< int32_t > > > fStorDigiInd
double fdNofHitsTot
Total number of hits produced.
virtual void Finish()
Inherited from FairTask.
bool InitParameters()
Initialize other parameters not included in parameter classes.
std::vector< std::vector< std::vector< std::vector< std::vector< double > > > > > fvCPWalk
double fNofDigisUsed
Total number of Tof Digis processed.
void GetEventInfo(int32_t &inputNr, int32_t &eventNr, double &eventTime)
Retrieve event info from run manager to properly fill the CbmLink objects.
int32_t fiNofTs
Number of processed timeslices.
int32_t fiNofEvents
Total number of events processed.
CbmTaskTofHitFinder()
Constructor.
virtual InitStatus Init()
Inherited from FairTask.
std::map< uint32_t, std::map< uint32_t, cbm::algo::tof::HitFinder > > fAlgo
TClonesArray * fTofDigiMatchColl
std::vector< std::vector< double > > fvCPSigPropSpeed
std::vector< std::vector< std::vector< std::vector< double > > > > fvCPTOff
double fdTimeTot
Total execution time.
virtual void SetParContainers()
Inherited from FairTask.
std::pair< int32_t, int32_t > BuildClusters(CbmEvent *event)
Build clusters out of ToF Digis and store the resulting info in a TofHit.
virtual ~CbmTaskTofHitFinder()
Destructor.
virtual void Exec(Option_t *option)
Inherited from FairTask.
CbmTofDetectorId * fTofId
CbmTofGeoHandler * fGeoHandler
static uint32_t GetUniqueAddress(uint32_t Sm, uint32_t Rpc, uint32_t Channel, uint32_t Side=0, uint32_t SmType=0, uint32_t RpcType=0)
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
Double_t GetSizey() const
Double_t GetSizex() const
virtual InitStatus Init()
virtual int32_t SetDetectorInfo(const CbmTofDetectorInfo detectorInfo)=0
Parameters class for the CBM ToF digitizer using beam data distributions.
Double_t GetFeeTimeRes() const
Int_t GetNbSmTypes() const
Double_t GetGapSize(Int_t iSmType, Int_t iRpc) const
Int_t GetNbSm(Int_t iSmType) const
Double_t GetMaxDistAlongCh() const
Int_t GetNbChan(Int_t iSmType, Int_t iRpc) const
Int_t GetNbGaps(Int_t iSmType, Int_t iRpc) const
Int_t GetChanType(Int_t iSmType, Int_t iRpc) const
Int_t GetNbRpc(Int_t iSmType) const
Bool_t UseExpandedDigi() const
Double_t GetMaxTimeDist() const
Double_t GetSignalSpeed() const
Double_t GetSigVel(Int_t iSmType, Int_t iSm, Int_t iRpc) const
CbmTofCell * GetCell(Int_t i)
Data class for expanded digital TOF information.
int32_t GetAddress() const
Inherited from CbmDigi.
Int_t Init(Bool_t isSimulation=kFALSE)
ROOT::Math::Rotation3D rotation
ROOT::Math::XYZVector pos