18template<ca::EDetectorID DetID>
26template<ca::EDetectorID DetID>
44template<ca::EDetectorID DetID>
47 auto CheckBranch = [](
auto pBranch,
const char* brName) {
49 throw std::logic_error(Form(
"Branch %s is not available", brName));
54 auto* pFairManager = FairRootManager::Instance();
55 auto* pMcManager =
dynamic_cast<CbmMCDataManager*
>(pFairManager->GetObject(
"MCDataManager"));
56 CheckBranch(pMcManager,
"MCDataManager");
59 fpRecoEvents =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"CbmEvent"));
69 if (!pRecoSetupManager->IsInitialized()) {
76 fpBrPoints = pMcManager->InitBranch(
"MvdPoint");
77 fpBrHits =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"MvdHit"));
78 fpBrHitMatches =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"MvdHitMatch"));
85 fpBrPoints = pMcManager->InitBranch(
"StsPoint");
86 fpBrHits =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"StsHit"));
87 fpBrHitMatches =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"StsHitMatch"));
95 fpBrHits =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"MuchPixelHit"));
96 fpBrHitMatches =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"MuchPixelHitMatch"));
99 CheckBranch(
fpBrHits,
"MuchPixelHit");
103 fpBrPoints = pMcManager->InitBranch(
"TrdPoint");
104 fpBrHits =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TrdHit"));
105 fpBrHitMatches =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TrdHitMatch"));
112 fpBrPoints = pMcManager->InitBranch(
"TofPoint");
113 fpBrHits =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TofHit"));
114 fpBrHitMatches =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TofHitMatch"));
121 LOG(fatal) <<
"CA ideal hit producer for " <<
kDetName[DetID]
122 <<
": Wrong template argument is used: ca::EDetectorID::END";
127 if (
auto pGeoNodeMap = pRecoSetupManager->GetGeoNodeMap()) {
129 pGeoNodeMap->GetVolumeProperties([](
const auto& vol) { return vol.GetCenterZ(); },
ECbmModuleId::kTof));
132 throw std::runtime_error(
"geo node map was not built in cbm::RecoSetupManager. Please request it with "
133 "cbm::RecoSetupManager::BuildGeoNodeMaps(), when adding the manager as a task "
139 if (fsConfigName.size() != 0) {
144 std::any_of(fvStationPars.begin(), fvStationPars.end(), [](
const auto& p) { return p.fMode > 0; });
147 fbRunTheRoutine =
false;
150 std::stringstream msg;
151 msg <<
"\033[1;31mATTENTION! IDEAL HIT PRODUCER IS USED FOR " <<
kDetName[DetID] <<
"\033[0m";
152 LOG_IF(info, fbRunTheRoutine) << msg.str();
156catch (
const std::logic_error& error) {
157 LOG(error) <<
"CA ideal hit producer for " <<
kDetName[DetID] <<
": initialization failed. Reason: " << error.what();
163template<ca::EDetectorID DetID>
173 config = YAML::LoadFile(
fsConfigName)[
"ideal_hit_producer"];
175 std::string detBranchName =
"";
177 detBranchName =
"mvd";
180 detBranchName =
"sts";
183 detBranchName =
"much";
186 detBranchName =
"trd";
189 detBranchName =
"tof";
192 const auto& parNode = config[
"parameters"][detBranchName];
193 const auto& flagNode = config[
"flags"][detBranchName];
195 for (
int iSt = 0; iSt < nStations; ++iSt) {
197 auto& node = parNode[iSt];
198 short mode = flagNode[iSt].as<
int>(0);
200 par.fPhiU = node[
"du"][
"angle"].as<
double>() * 180. / M_PI;
201 par.fDu = node[
"du"][
"value"].as<
double>();
202 switch (node[
"du"][
"pdf"].as<char>()) {
203 case 'g': par.fPdfU = 0;
break;
204 case 'u': par.fPdfU = 1;
break;
205 default: par.fPdfU = -1;
break;
207 par.fPhiV = node[
"dv"][
"angle"].as<
double>() * 180. / M_PI;
208 par.fDv = node[
"dv"][
"value"].as<
double>();
209 switch (node[
"dv"][
"pdf"].as<char>()) {
210 case 'g': par.fPdfV = 0;
break;
211 case 'u': par.fPdfV = 1;
break;
212 default: par.fPdfV = -1;
break;
214 par.fDt = node[
"dt"][
"value"].as<
double>();
215 switch (node[
"dt"][
"pdf"].as<char>()) {
216 case 'g': par.fPdfT = 0;
break;
217 case 'u': par.fPdfT = 1;
break;
218 default: par.fPdfT = -1;
break;
241 catch (
const YAML::BadFile& err) {
242 std::stringstream msg;
243 msg <<
"YAML configuration file " <<
fsConfigName <<
" does not exist";
244 throw std::runtime_error(msg.str());
246 catch (
const YAML::ParserException& err) {
247 std::stringstream msg;
248 msg <<
"YAML configuration file " <<
fsConfigName <<
" is formatted improperly";
249 throw std::runtime_error(msg.str());
255template<ca::EDetectorID DetID>
278 std::vector<double> vHitMcEventTime;
283 for (
int iH = 0; iH <
fpBrHitsTmp->GetEntriesFast(); ++iH) {
285 double tMC = pHit->GetTime();
288 int iSt =
fpDetInterface->GetTrackingStationId(pHit->GetAddress());
295 if (setting.fMode == 2) {
300 if (setting.fMode == 1) {
303 if (oLinkToPoint == std::nullopt) {
306 auto& link = oLinkToPoint.value();
310 auto pos = TVector3{};
311 pPoint->Position(
pos);
323 double t = pPoint->GetTime() +
fpMCEventList->GetEventTime(link);
326 if (setting.fbSmear) {
327 double dx2 = pHit->GetDx() * pHit->GetDx();
328 double dxy = pHit->GetDxy();
329 double dy2 = pHit->GetDy() * pHit->GetDy();
336 double dt = pHit->GetTimeError();
351 iCluster = std::max(pHit->GetFrontClusterId(), iCluster);
352 iCluster = std::max(pHit->GetBackClusterId(), iCluster);
356 vHitMcEventTime.push_back(tMC);
364 for (
int iE = 0; iE < nEvents; ++iE) {
367 int nPoints =
fpBrPoints->Size(fileId, eventId);
372 for (
int iP = 0; iP < nPoints; ++iP) {
377 int iSt =
fpDetInterface->GetTrackingStationId(pPoint->GetDetectorID());
383 if (setting.fMode != 2) {
386 double du = setting.fDu;
387 double dv = setting.fDv;
388 double dt = setting.fDt;
395 auto pos = TVector3{};
396 pPoint->Position(
pos);
408 double t = pPoint->GetTime() +
fpMCEventList->GetEventTime(eventId, fileId);
412 if (setting.fbSmear) {
422 auto dpos = TVector3{std::sqrt(dx2), std::sqrt(dy2), dz};
429 auto address = pPoint->GetDetectorID();
431 int32_t iClustF = iCluster;
432 int32_t iClustB = iCluster + 1;
439 int32_t planeId = -1;
444 auto eLoss = pPoint->GetEnergyLoss();
457 pHitMatchNew->
AddLink(1., iP, eventId, fileId);
458 vHitMcEventTime.push_back(tMC);
478 double tStart =
event->GetStartTime();
479 double tEnd =
event->GetEndTime();
480 for (UInt_t iH = 0; iH < vHitMcEventTime.size(); iH++) {
481 double t = vHitMcEventTime[iH];
482 if ((t >= tStart && t <= tEnd) || tStart < 0 || tEnd < 0) {
492template<ca::EDetectorID DetID>
497 int nPoints =
fpBrPoints->Size(iFile, iEvent);
502 constexpr int kNofBitsRpcAddress = 11;
503 std::map<std::pair<int, int>,
int> mMatchedPointId;
506 LOG_IF(fatal, !pHitMatch) <<
"CA MC Module: hit match was not found for TOF hit " << iH;
507 double bestWeight = 0;
508 for (
int iLink = 0; iLink < pHitMatch->GetNofLinks(); ++iLink) {
509 const auto& link = pHitMatch->GetLink(iLink);
510 if (link.GetFile() != iFile || link.GetEntry() != iEvent) {
513 int iPext = link.GetIndex();
518 int trkId = pExtPoint->GetTrackID();
519 int rpcAddr = pExtPoint->GetDetectorID() << kNofBitsRpcAddress;
520 auto key = std::make_pair(trkId, rpcAddr);
521 auto prev = mMatchedPointId.find(key);
522 if (prev == mMatchedPointId.end()) {
523 bestWeight = link.GetWeight();
524 mMatchedPointId[key] = iPext;
527 if (bestWeight < link.GetWeight()) {
528 mMatchedPointId[key] = iPext;
537 int iPointSelected = -1;
539 int rpcAddrCurr = -1;
540 bool bTrkHasHits =
false;
541 double zDist = std::numeric_limits<double>::max();
542 double zCell = std::numeric_limits<double>::signaling_NaN();
543 for (
int iP = 0; iP < nPoints; ++iP) {
545 LOG_IF(fatal, !pExtPoint) <<
"NO POINT: TOF: file, event, index = " << iFile <<
' ' << iEvent <<
' ' << iP;
547 int iTmc = pExtPoint->GetTrackID();
548 int rpcAddr = pExtPoint->GetDetectorID() << kNofBitsRpcAddress;
550 if (rpcAddrCurr != rpcAddr || iTmcCurr != iTmc) {
551 if (iPointSelected != -1) {
555 rpcAddrCurr = rpcAddr;
556 auto key = std::make_pair(iTmc, rpcAddr);
557 auto found = mMatchedPointId.find(key);
558 bTrkHasHits = found != mMatchedPointId.end();
560 iPointSelected = found->second;
565 zDist = std::fabs(zCell - pExtPoint->GetZ());
571 auto newDist = std::fabs(pExtPoint->GetZ() - zCell);
572 if (newDist < zDist) {
580 if (iPointSelected != -1) {
@ kTof
Time-of-flight Detector.
friend fvec sqrt(const fvec &a)
Class characterising one event by a collection of links (indices) to data objects,...
void ClearData(ECbmDataType type)
Task class creating and managing CbmMCDataArray objects.
Container class for MC events with number, file and start time.
void AddLinks(const CbmMatch &match)
void AddLink(const CbmLink &newLink)
data class for a reconstructed 3-d hit in the STS
Bookkeeping of time-slice content.
Geometric intersection of a MC track with a TOFb detector.
data class for a reconstructed Energy-4D measurement in the TRD
static uint32_t ApplyMask(uint32_t address, ECbmModuleId moduleId)
Applies mask.
void BuildGeoNodeMaps()
Requests geo-node map building.
static RecoSetupManager * Instance()
Instance access.
A class to convert XY coordinates to UV coordinates.
std::tuple< double, double, double > ConvertCovMatrixUVtoXY(double du2, double duv, double dv2) const
Conversion function (du2, duv, dv2) -> (dx2, dxy, dy2)
std::pair< double, double > ConvertUVtoXY(double u, double v) const
Conversion function (x,y) -> (u,v)
std::tuple< double, double, double > ConvertCovMatrixXYtoUV(double dx2, double dxy, double dy2) const
Conversion function (dx2, dxy, dy2) -> (du2, duv, dv2)
std::pair< double, double > ConvertXYtoUV(double x, double y) const
Conversion function (x,y) -> (u,v)
Ideal hit producer class.
TClonesArray * fpRecoEvents
Array of reconstructed events.
std::vector< unsigned char > fvbPointIsLegit
Map of used point index.
void Exec(Option_t *option)
Execution of the task.
TClonesArray * fpBrHitsTmp
Temporary array of hits.
IdealHitProducerDet()
Constructor.
ECbmDataType fHitDataType
PointTypes_t::at< DetID > Point_t
CbmMCEventList * fpMCEventList
MC event list.
TClonesArray * fpBrHitMatchesTmp
Temporary array of hit matches.
std::unordered_map< uint32_t, double > fTofRpcZpos
std::vector< HitParameters > fvStationPars
Parameters, stored for each station.
const cbm::algo::RecoSetupUnit_t< ToCbmModuleId(DetID)> * fpDetInterface
CbmMCDataObject * fpMCEventHeader
MC event header.
int fHitCounter
Hit counter in a new branch.
~IdealHitProducerDet()
Destructor.
CbmTimeSlice * fpTimeSlice
Current time slice.
void PushBackHit(const Hit_t *pHit)
Pushes back a hit into the hits branch.
std::optional< CbmLink > GetMatchedPointLink(int iH)
Gets pointer to matched MC point.
bool fbRunTheRoutine
Management flag, which does run the routine if there was a request.
void FillPointIsLegit(int iEvGlob)
Fills map of legit points (inside MC event!)
std::string fsConfigName
Name of configuration file.
HitTypes_t::at< DetID > Hit_t
InitStatus Init()
Initialization of the task.
CbmMCDataArray * fpBrMCTracks
Branch: array of MC tracks.
void ParseConfig()
Parses the YAML configuration file.
TClonesArray * fpBrHitMatches
void SmearValue(double &value, double sigma, int opt)
Smears the value by a given standard deviation with a selected function.
CbmMCDataArray * fpBrPoints
constexpr DetIdArr_t< const char * > kDetName
Names of detector subsystems.