 |
Belle II Software
release-05-02-19
|
10 #include <tracking/modules/spacePointCreator/SpacePoint2TrueHitConnectorModule.h>
11 #include <framework/datastore/StoreObjPtr.h>
12 #include <framework/dataobjects/EventMetaData.h>
13 #include <framework/core/Environment.h>
15 #include <pxd/dataobjects/PXDCluster.h>
16 #include <svd/dataobjects/SVDCluster.h>
17 #include <mdst/dataobjects/MCParticle.h>
24 #include <unordered_map>
25 #include <tracking/spacePointCreation/MapHelperFunctions.h>
40 setDescription(
"Module that tries to find the appropriate TrueHit to each SpacePoint and to register a relation between them for making MC information for SpacePoints more easily accesible for Modules that need it. Module can also be used to filter out 'fishy' SpacePoints.");
43 addParam(
"storeSeperate", m_PARAMstoreSeparate,
44 "Set to false if you do not want to create seperate StoreArrays for processed SpacePoints. (i.e. a relation from SpacePoint to TrueHit will be set in the passed StoreArray. NOTE: this StoreArray will contain SpacePoints with a relation to TrueHits and such without after this module). The Names of the output StoreArrays will be the names of the input StoreArrays with 'outputSuffix' (module parameter) appended to them",
47 addParam(
"registerAll", m_PARAMregisterAll,
48 "If set to true, the module simply registers a relation for all TrueHits that are related to a SpacePoint (resp. its Clusters). In this way the module can be used to find all related TrueHits and then the user can decide what to do with these TrueHits (otherwise this module does some decision making). Setting this to true means that all checks (e.g. 'minWeight', 'maxPosSigma', ...) are ommitted! NOTE that some of the information is lost in this way (e.g. how many of the Clusters of a SpacePoint have been related to a TrueHit)!",
51 addParam(
"positionAnalysis", m_PARAMpositionAnalysis,
52 "Analyze the positions of SpacePoints and corresponding TrueHits. NOTE: if enabled a root file gets created!",
false);
54 addParam(
"requirePrimary", m_PARAMrequirePrimary,
55 "Set to true if only relations to TrueHits that are related to a primary particle should get registered.",
false);
57 addParam(
"requireProximity", m_PARAMrequireProximity,
58 "Require that the TrueHit is close to the SpacePoint (in local coordinates). The meaning of 'close' can be defined with the parameters 'maxPosSigma' and 'maxGlobalPosDiff'.",
61 std::vector<std::string> defaultInList;
62 defaultInList.push_back(std::string(
""));
63 addParam(
"TrueHitNames", m_PARAMtrueHitNames,
64 "Container names of TrueHits. NOTE: need one name per 'DetectorType' (i.e. unique entries in 'DetectorType)!", defaultInList);
65 addParam(
"SpacePointNames", m_PARAMspacePointNames,
"Container names of SpacePoints.", {
"SVDSpacePoints",
"PXDSpacePoints"});
66 addParam(
"DetectorTypes", m_PARAMdetectorTypes,
67 "detector types to determine which entries in 'TrueHitNames' and 'SpacePointNames' belong to which detector type. Entries have to be 'SVD' or 'PXD'. NOTE: if more 'SpacePointNames' than 'DetectorTypes' get passed, the last entry in 'DetectorTypes' is assumed to be valid for all remaining 'SpacePointNames'!");
68 addParam(
"ClusterNames", m_PARAMclusterNames,
69 "Container names of Clusters. NOTE: need one name per 'DetectorType' (i.e. unique entries in 'DetectorType')!", defaultInList);
71 std::vector<std::string> defaultRootFName = {
"PositionAnalysis",
"RECREATE" };
72 addParam(
"rootFileName", m_PARAMrootFileName,
73 "Filename and write-mode ('RECREATE' or 'UPDATE'). If given more than 2 strings this module will cause termination",
76 addParam(
"outputSuffix", m_PARAMoutputSuffix,
77 "Suffix that will be appended to the container names if 'storeSeperate' is set to true", std::string(
"_relTH"));
79 addParam(
"maxGlobalPosDiff", m_PARAMmaxGlobalDiff,
80 "max difference of global position coordinates between TrueHit and SpacePoint (in each direction) in cm.", 0.05);
83 addParam(
"maxPosSigma", m_PARAMmaxPosSigma,
"Define the maximum local position difference in units of PitchSize / sqrt(12).", 4.);
84 addParam(
"minWeight", m_PARAMminWeight,
85 "Define a minimal weight a relation between a Cluster and a TrueHit has to have for the TrueHit to be considered as possible candidate.",
90 m_rootFilePtr =
nullptr;
95 "SpacePoint2TrueHitConnector::initialize: parameter positionAnalysis (and therefore root-output) is enabled and basf2 is running in multi-threaded mode - this can cause nondeterministic behavior! "
97 <<
" you can suppress multi-threading for this module by writing:"
99 <<
"main.add_module('SpacePoint2TrueHitConnector').set_property_flags(0) "
101 <<
"into the steering file!");
108 B2INFO(
"SpacePoint2TrueHitConnector -------------------------- initialize --------------------------------");
115 B2FATAL(
"Passed " << nTHNames <<
" TrueHitNames and " << nDetTypes <<
" DetectorTypes but number of passed SpacePointArrays is " <<
118 if ((nTHNames != nDetTypes) || (nClNames != nTHNames)) {
119 B2FATAL(
"Passed " << nTHNames <<
" TrueHitNames and " << nClNames <<
"ClusterNames but " << nDetTypes <<
" DetectorTypes!");
125 if (detType.compare(std::string(
"SVD")) != 0 && detType.compare(std::string(
"PXD")) != 0) {
126 B2FATAL(
"Found entry " << detType <<
" in DetectorTypes, but only 'PXD' and 'SVD' are allowed!");
128 if (detType.compare(std::string(
"SVD")) == 0) {
158 B2WARNING(
"'outputSuffix' is empty and 'storeSeperate' is set to true. This would lead to StoreArrays with the same name. Resetting to 'outputSuffix' to '_relTH'!");
190 B2WARNING(
"'maxPosSigma' is set to a value below 0: " <<
m_PARAMmaxPosSigma <<
"! Resetting to default (4)!");
201 const int eventCtr = eventMetaDataPtr->getEvent();
202 B2DEBUG(10,
"SpacePoint2TrueHitConnector::event(). Processing event " << eventCtr <<
" -----------------------");
209 const int nSpacePoints = spacePoints.
getEntries();
211 std::string detTypeStr = detType ==
c_SVD ?
"SVD" :
"PXD";
213 " for this event. detType: " << detTypeStr);
217 for (
int iSP = 0; iSP < nSpacePoints; ++iSP) {
219 B2DEBUG(49,
"Processing SpacePoint " << iSP <<
" from " << nSpacePoints);
221 baseMapT trueHitMap = processSpacePoint<baseMapT>(spacePoint, detType);
222 if (trueHitMap.empty())
continue;
225 B2DEBUG(50,
"Found " << nUniqueTHs <<
" TrueHits (unique) related to SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array "
227 unsigned int iRels = nUniqueTHs > 4 ? 4 : nUniqueTHs - 1;
232 std::string mapCont =
printMap(trueHitMap);
233 B2DEBUG(250,
"The TrueHits and their weights for spacePoint " << spacePoint->
getArrayIndex() <<
": " + mapCont);
241 pair<VXDTrueHit*, double> trueHitwWeight;
243 if (detType ==
c_PXD) trueHitwWeight = getTHwithWeight<baseMapT, PXDTrueHit>(trueHitMap,
m_PXDTrueHits, spacePoint,
c_PXD);
244 else trueHitwWeight = getTHwithWeight<baseMapT, SVDTrueHit>(trueHitMap,
m_SVDTrueHits, spacePoint,
c_SVD);
246 if (trueHitwWeight.first !=
nullptr) {
248 thIndex = trueHitwWeight.first->getArrayIndex();
250 B2DEBUG(10,
"Could not relate one TrueHit to SpacePoint " << spacePoint->
getArrayIndex() <<
".");
267 B2RESULT(
"SpacePoint2TrueHitConnector: Got " << sumSpacePoints <<
" SpacePoints in " <<
m_nContainers <<
268 " containers and registered " << sumRelations <<
" relations to TrueHits");
270 stringstream contSumm;
271 contSumm <<
"Container-wise summary: \n";
273 for (
unsigned int iCont = 0; iCont <
m_nContainers; ++iCont) {
274 contSumm <<
"In Container " << iCont <<
" (container name: " <<
m_inputSpacePoints[iCont].first.getName() <<
") " <<
276 " relations were registered.\nNumber of related TrueHits to a SpacePoint are:\n";
277 for (
unsigned int i = 0; i <
m_nRelTrueHitsCtr[iCont].size() - 1; ++i) { contSumm << i + 1 <<
" related TrueHits to a SpacePoint : " <<
m_nRelTrueHitsCtr[iCont].at(i) <<
"\n"; }
278 contSumm <<
" more than 4 related TrueHits to a SpacePoint: " <<
m_nRelTrueHitsCtr[iCont].at(4) <<
"\n";
280 iCont) <<
" were probably ghost hits in this container!\n";
281 contSumm <<
m_noTrueHitCtr[iCont] <<
" SpacePoints had no relation to a TrueHit at all.\n";
283 B2DEBUG(1, contSumm.str());
287 stringstream furtherSummary;
296 B2DEBUG(2, furtherSummary.str());
307 template<
typename MapType>
313 if (detType ==
c_PXD) {
314 trueHitMap = getRelatedTrueHits<MapType, PXDCluster, PXDTrueHit>(spacePoint,
m_PXDClusters.getName(),
m_PXDTrueHits.getName());
316 trueHitMap = getRelatedTrueHits<MapType, SVDCluster, SVDTrueHit>(spacePoint,
m_SVDClusters.getName(),
m_SVDTrueHits.getName());
318 }
catch (NoClusterToSpacePoint& anE) {
319 B2WARNING(
"Caught an exception while trying to relate SpacePoints and TrueHits: " << anE.what());
322 B2ERROR(
"Caught undefined exception while trying to relate SpacePoints and TrueHits");
326 B2DEBUG(499,
"trueHitMap.size() before return in processSpacePoint: " << trueHitMap.size());
331 template<
typename MapType,
typename ClusterType,
typename TrueHitType>
333 std::string trueHitName)
338 if (spacePointClusters.
size() == 0) {
339 B2DEBUG(1,
"Found no related Cluster for SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array " <<
341 throw NoClusterToSpacePoint();
343 B2DEBUG(75,
"Found " << spacePointClusters.
size() <<
" related Clusters to SpacePoint " << spacePoint->
getArrayIndex() <<
347 short noTrueHits = 0;
348 for (
size_t iCl = 0; iCl < spacePointClusters.
size(); ++iCl) {
350 const ClusterType* cluster = spacePointClusters[iCl];
352 if (clusterTrueHits.
size() == 0) {
353 B2DEBUG(3,
"Found no related TrueHit for Cluster " << cluster->getArrayIndex() <<
" contained by SpacePoint " <<
357 B2DEBUG(80,
"Found " << clusterTrueHits.
size() <<
" related TrueHits to Cluster " << cluster->getArrayIndex() <<
" from Array " <<
358 cluster->getArrayName());
360 for (
unsigned int i = 0; i < clusterTrueHits.
size(); ++i) {
365 int index = clusterTrueHits[i]->getArrayIndex();
366 if (trueHitsMap.find(index) == trueHitsMap.end()) {
368 B2DEBUG(499,
"Added new TrueHitInfo to map. Index " << index);
370 if (spacePointClusters.
weight(iCl) > 0) {
371 trueHitsMap[index].setUWeight(clusterTrueHits.
weight(i));
372 B2DEBUG(499,
"Added UCluster to TrueHitInfo with index " << index);
374 trueHitsMap[index].setVWeight(clusterTrueHits.
weight(i));
375 B2DEBUG(499,
"Added VCluster to TrueHitInfo with index " << index);
427 template<
typename MapType>
430 B2DEBUG(50,
"Registering all possible relations for SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array " <<
437 if (detType ==
c_PXD) reRegisterClusterRelations<PXDCluster>(spacePoint, newSP,
m_PXDClusters.getName());
438 else reRegisterClusterRelations<SVDCluster>(spacePoint, newSP,
m_SVDClusters.getName());
441 std::vector<TrueHitInfo> trueHitInfos =
getAllValues(trueHitMap);
443 std::sort(trueHitInfos.begin(), trueHitInfos.end());
446 if (detType ==
c_PXD) registerTrueHitRelation<PXDTrueHit>(newSP, info.m_Id, 1,
m_PXDTrueHits);
449 registerTrueHitRelation<SVDTrueHit>(newSP, info.m_Id, weight,
m_SVDTrueHits);
455 template<
typename TrueHitType>
457 std::pair<TrueHitType*, double> trueHitwWeight,
e_detTypes detType)
459 TrueHitType* trueHit = trueHitwWeight.first;
460 B2DEBUG(50,
"Registering relation to TrueHit " << trueHit->getArrayIndex() <<
" from Array " << trueHit->getArrayName());
466 if (detType ==
c_PXD) reRegisterClusterRelations<PXDCluster>(spacePoint, newSP,
m_PXDClusters.getName());
467 else reRegisterClusterRelations<SVDCluster>(spacePoint, newSP,
m_SVDClusters.getName());
472 B2DEBUG(50,
"Added Relation to TrueHit " << trueHit->getArrayIndex() <<
" from Array " << trueHit->getArrayName() <<
473 " for SpacePoint " << spacePoint->
getArrayIndex() <<
" (weight = " << trueHitwWeight.second <<
")");
477 template<
typename ClusterType>
481 B2DEBUG(100,
"Registering the Relations to Clusters of SpacePoint " << origSpacePoint->
getArrayIndex() <<
" in Array " <<
485 vector<pair<ClusterType*, double> > clustersAndWeights = getRelatedClusters<ClusterType>(origSpacePoint, clusterName);
486 for (
auto aCluster : clustersAndWeights) {
487 newSpacePoint->
addRelationTo(aCluster.first, aCluster.second);
488 B2DEBUG(100,
"Registered Relation to Cluster " << aCluster.first->getArrayIndex() <<
" with weight " << aCluster.second);
493 template<
typename ClusterType>
495 std::string clusterName)
497 vector<pair<ClusterType*, double> > indsAndWeights;
500 for (
unsigned int iCl = 0; iCl < relClusters.
size(); ++iCl) {
501 indsAndWeights.push_back(make_pair(relClusters[iCl], relClusters.
weight(iCl)));
505 if (indsAndWeights.empty()) { B2ERROR(
"No Clusters related to SpacePoint " << spacePoint->
getArrayIndex() <<
"!"); }
507 return indsAndWeights;
511 template<
typename TrueHitType>
515 TrueHitType* trueHit = trueHits[index];
518 B2DEBUG(50,
"Added Relation to TrueHit " << index <<
" from Array " << trueHits.getName() <<
" for SpacePoint " <<
519 spacePoint->
getArrayIndex() <<
" (weight = " << weight <<
")");
524 template<
typename MapType>
528 B2DEBUG(250,
"Doing position analysis for SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array " <<
533 pair<unsigned short int, unsigned short int> clusterSizes =
getClusterSizes(spacePoint, detType);
534 pair<double, double> positionError =
getLocalError(spacePoint);
539 if (setUV.first) relationStatus.
addStatus(c_SpacePointU);
540 if (setUV.second) relationStatus.
addStatus(c_SpacePointV);
542 const vector<TrueHitInfo> trueHitInfos =
getAllValues(trueHitMap);
543 unsigned int nRelations = trueHitInfos.size();
544 if (nRelations != 1) relationStatus.
addStatus(c_nonUniqueRelation);
545 else relationStatus.
addStatus(c_clearHit);
547 B2DEBUG(999,
"SpacePoint has assigned U: " << setUV.first <<
", V: " << setUV.second <<
". Possible TrueHits: " << nRelations);
549 pair<double, double> spLocalPos =
getLocalPos(spacePoint);
550 unsigned short int vxdId = spacePoint->
getVxdID();
554 bool onceU =
false, onceV =
false;
555 bool twoClusters =
false;
557 onceU = onceU || info.m_U;
558 onceV = onceV || info.m_V;
559 twoClusters = twoClusters || (info.getNClusters() == 2);
561 bool allSet = onceU && onceV;
564 if (!allSet) relationStatus.
addStatus(c_noiseCluster);
565 if (allSet && !twoClusters) relationStatus.
addStatus(c_ghostHit);
569 unsigned short int overAllStatus = relationStatus.
getStatus();
578 double weightU = info.m_wU;
579 double weightV = info.m_wV;
582 if (mcParticle !=
nullptr) {
586 if (info.m_Id == index) relationStatus.
addStatus(c_registeredRelation);
616 B2DEBUG(999,
"Branch contents of this entry:\nSPLocalU: " << spLocalPos.first <<
". SPLocalV: " << spLocalPos.second <<
"\n" << \
617 "SPGlobalX: " << spacePoint->
X() <<
", SPGlobalY: " << spacePoint->
Y() <<
", SPGlobalZ " << spacePoint->
Z() <<
"\n" << \
618 "THLocalU: " << trueHitPos.first.X() <<
", THLocalV: " << trueHitPos.first.Y() <<
"\n" << \
619 "THGlobalX: " << trueHitPos.second.X() <<
", THGlobalY: " << trueHitPos.second.Y() <<
", THGlobalZ: " << trueHitPos.second.Z() <<
621 "weight1: " << weightU <<
", weight2: " << weightV <<
", VxdID: " << vxdId <<
", nRelations: " << nRelations <<
", relStatus: " <<
627 template<
typename MapType,
typename TrueHitType>
628 std::pair<TrueHitType*, double>
633 std::pair<TrueHitType*, double> THwithWeight(
nullptr, 0.0);
635 if (trueHitInfos.empty())
return THwithWeight;
636 std::sort(trueHitInfos.begin(), trueHitInfos.end());
639 size_t nRelations = trueHitInfos.size();
641 B2DEBUG(50,
"Trying to select one TrueHit for SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array " <<
642 spacePoint->
getArrayName() <<
". SpacePoint has " << nClusters <<
" Clusters.");
643 B2DEBUG(150,
"There are " << nRelations <<
" possible candidates.");
648 output <<
"The candidates are: ";
649 for (
auto& info : trueHitInfos) { output << info; }
650 B2DEBUG(999, output.str());
652 std::pair<double, double> spacePointLocal =
getLocalPos(spacePoint);
655 B2DEBUG(999,
"SpacePoint " << spacePoint->
getArrayIndex() <<
" U: " << spacePointLocal.first <<
" V: " << spacePointLocal.second <<
656 " assigned: " << assignedLocal.first <<
", " << assignedLocal.second);
659 for (
int key : uniqueKeys) {
660 TrueHitType* trueHit = trueHits[key];
662 MCParticle* mcParticle = trueHit->template getRelatedFrom<MCParticle>(
"ALL");
664 int mcPartId = -1, pdgCode = 0;
665 bool primary =
false;
667 if (mcParticle !=
nullptr) {
670 pdgCode = mcParticle->
getPDG();
673 B2DEBUG(999,
"TrueHit " << key <<
" U: " << trueHit->getU() <<
", V: " << trueHit->getV() <<
" mc Particle Id: " << mcPartId <<
674 ", primary " << primary <<
", pdg: " << pdgCode);
680 bool ghostHit =
false;
682 B2DEBUG(499,
"Now checking trueHit: " << info);
683 if (nClusters == info.getNClusters()) {
684 TrueHitType* trueHit = trueHits[info.m_Id];
687 return make_pair(trueHit, weight);
690 B2DEBUG(499,
"The number of related Clusters ( = " << nClusters <<
") and the number of associated weights ( = " <<
691 info.getNClusters() <<
") do not match! This indicates a ghost hit");
702 template <
typename TrueHitType>
705 B2DEBUG(150,
"Checking TrueHit " << trueHit->getArrayIndex() <<
" from Array " << trueHit->getArrayName() <<
" and SpacePoint " <<
709 MCParticle* mcPart = trueHit->template getRelatedFrom<MCParticle>(
"ALL");
710 bool primaryPart =
false;
713 B2DEBUG(150,
"TrueHit is not related to a primary particle but 'requirePrimary' is set to true!");
720 B2DEBUG(999,
"Not checking positions because 'requireProximity' is set to false");
724 const VxdID trueHitVxdId = trueHit->getSensorID();
726 B2DEBUG(999,
"Comparing the VxdIDs, SpacePoint: " << spacePointVxdId <<
", TrueHit: " << trueHitVxdId);
727 if (spacePointVxdId != trueHitVxdId) {
728 B2DEBUG(150,
"SpacePoint and TrueHit do not have the same VxdID. spacePoint: " << spacePointVxdId <<
", trueHit: " << trueHitVxdId);
737 B2DEBUG(999,
"maximum residual in U: " << maxUres <<
", in V: " << maxVres);
739 const TVector3 trueHitLocalPos = TVector3(trueHit->getU(), trueHit->getV(), 0);
740 const TVector3 trueHitGlobalPos = SensorInfoBase.
pointToGlobal(trueHitLocalPos,
true);
742 std::pair<double, double> spacePointLocal =
getLocalPos(spacePoint);
746 if (setCoordinates.first) {
747 B2DEBUG(999,
"Comparing the U-coordinates, SpacePoint: " << spacePointLocal.first <<
", TrueHit: " << trueHitLocalPos.X() <<
748 " -> diff: " << spacePointLocal.first - trueHitLocalPos.X());
749 if (pow(spacePointLocal.first - trueHitLocalPos.X(), 2) > maxUres * maxUres) {
750 B2DEBUG(150,
"The local position difference in U direction is " << spacePointLocal.first - trueHitLocalPos.X() <<
751 " but maximum local position difference is set to: " << maxUres);
755 if (setCoordinates.second) {
756 B2DEBUG(999,
"Comparing the V-coordinates, SpacePoint: " << spacePointLocal.second <<
", TrueHit: " << trueHitLocalPos.Y() <<
757 " -> diff: " << spacePointLocal.second - trueHitLocalPos.Y());
758 if (pow(spacePointLocal.second - trueHitLocalPos.Y(), 2) > maxVres * maxVres) {
759 B2DEBUG(150,
"The local position difference in V direction is " << spacePointLocal.second - trueHitLocalPos.Y() <<
760 " but maximum local position difference is set to: " << maxVres);
766 if (setCoordinates.first && setCoordinates.second) {
767 B2DEBUG(999,
"Comparing the global positions, SpacePoint: (" << spacePoint->
X() <<
"," << spacePoint->
Y() <<
"," << spacePoint->
Z()
768 <<
"), TrueHit: (" << trueHitGlobalPos.X() <<
"," << trueHitGlobalPos.Y() <<
"," << trueHitGlobalPos.Z() <<
")");
772 B2DEBUG(150,
"The position differences are for X: " << spacePoint->
X() - trueHitGlobalPos.X() <<
", Y: " << spacePoint->
Y() -
773 trueHitGlobalPos.Y() <<
" Z: " << spacePoint->
Z() - trueHitGlobalPos.Z() <<
" but the maximum position difference is set to: " <<
778 B2DEBUG(5,
"For SpacePoint " << spacePoint->
getArrayIndex() <<
779 " one of the local coordinates was not assigned. The global positions and the un-assigned local coordinate were not compared!");
796 template<
typename TrueHitType>
800 const TVector3 localPos = TVector3(trueHit->getU(), trueHit->getV(), 0);
802 const VxdID trueHitVxdId = trueHit->getSensorID();
804 const TVector3 globalPos = SensorInfoBase.
pointToGlobal(localPos,
true);
806 return make_pair(localPos, globalPos);
816 B2FATAL(
"CurlingTrackCandSplitter::initialize() : rootFileName is set wrong: entries are: " << output);
821 m_treePtr =
new TTree(
"PosAnaTree",
"Position Analysis");
867 std::pair<unsigned short int, unsigned short int> clusterSizes = { 0, 0 };
868 if (detType ==
c_PXD) {
869 vector<pair<PXDCluster*, double> > relClusters = getRelatedClusters<PXDCluster>(spacePoint,
m_PXDClusters.getName());
870 return make_pair(relClusters[0].first->getUSize(), relClusters[0].first->getVSize());
872 vector<pair<SVDCluster*, double> > relClusters = getRelatedClusters<SVDCluster>(spacePoint,
m_SVDClusters.getName());
873 for (
auto cluster : relClusters) {
874 if (cluster.first->isUCluster()) clusterSizes.first = cluster.first->getSize();
875 else clusterSizes.second = cluster.first->getSize();
883 auto detType = spacePoint->
getType();
884 pair<double, double> errors = { -1., -1. };
886 vector<pair<PXDCluster*, double> > relClusters = getRelatedClusters<PXDCluster>(spacePoint,
m_PXDClusters.getName());
887 errors.first = relClusters[0].first->getUSigma();
888 errors.second = relClusters[0].first->getVSigma();
890 vector<pair<SVDCluster*, double> > relClusters = getRelatedClusters<SVDCluster>(spacePoint,
m_SVDClusters.getName());
891 for (
auto cluster : relClusters) {
892 if (cluster.first->isUCluster()) { errors.first = cluster.first->getPositionSigma(); }
893 else { errors.second = cluster.first->getPositionSigma(); }
896 B2ERROR(
"Detector type not known in SpacePoint2TrueHitConnector::getLocalError() !");
908 bool bothClusters = trueHitInfo.
m_U && trueHitInfo.
m_V;
911 short addWeight = 20 - (bothClusters ? 20 : isUAssigned ? 10 : 0);
913 return addWeight + (bothClusters ? 2 : 1);
size_t size() const
Get number of relations.
std::vector< double > TrueHitZGlobal
TrueHit global Z-position.
SpacePoint2TrueHitConnectorModule()
Constructor.
unsigned int m_rejectedNoPrimaryCtr
Count how many times a relation was rejected because TrueHit was not related to primary.
std::vector< unsigned int > ClusterSizeU
size of the u-cluster (resp.
helper struct to access root variables inside the module
std::pair< TrueHitType *, double > getTHwithWeight(const MapType &aMap, Belle2::StoreArray< TrueHitType > trueHits, Belle2::SpacePoint *spacePoint, e_detTypes detType)
get the TrueHit from information that is stored in the map (conditions are checked in the following o...
Class to uniquely identify a any structure of the PXD and SVD.
std::vector< e_detTypes > m_detectorTypes
storing the detector types for each container in vector, needed in initialize
std::vector< unsigned short int > RelationStatus
different flags of the relation stored in here (see c_relationStatus)
std::vector< double > SpacePointErrorU
position error of SpacePoint in U direction
void registerOneRelation(Belle2::SpacePoint *spacePoint, std::pair< TrueHitType *, double > trueHitwWeight, e_detTypes)
register Relation between SpacePoint and TrueHit (and if neccessary also between SpacePoint and Clust...
unsigned int getUniqueSize(const MapType &aMap)
get the number of unique keys inside the map NOTE: for non-multimap this is the same as ....
Belle2::StoreArray< Belle2::SVDCluster > m_SVDClusters
PXDClusters StoreArray used throughout the module.
void setDescription(const std::string &description)
Sets the description of the module.
double m_PARAMmaxPosSigma
defining th maximum difference of local coordinates in units of PitchSize / sqrt(12)
unsigned int m_nContainers
number of passed containers -> storing the size of an input vector for not having to obtain it every ...
Belle2::StoreArray< Belle2::PXDCluster > m_PXDClusters
PXDTClusters StoreArray used throughout the module.
void initializeRootFile()
initialize the root file that is used for output
double X() const
return the x-value of the global position of the SpacePoint
std::vector< unsigned int > ClusterSizeV
size of the v-cluster (resp.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_PARAMregisterAll
switch for registereing all relations for all TrueHits for all SpacePoints (there can be more than 1 ...
double Z() const
return the z-value of the global position of the SpacePoint
double m_PARAMmaxGlobalDiff
maximum difference of global position coordinates for each direction between TrueHit and SpacePoint
bool m_PARAMrequirePrimary
require the TrueHit to be related to a primary particle in order for the relation to get registered!
std::pair< double, double > getLocalPos(Belle2::SpacePoint *spacePoint)
get the local position of a SpacePoint
std::pair< bool, bool > getIfClustersAssigned() const
Returns, if u(v)-coordinate is based on cluster information.
void event() override
event: try to find the appropriate TrueHit to all SpacePoints
std::vector< double > TrueHitXGlobal
TrueHit global X-position.
void reRegisterClusterRelations(Belle2::SpacePoint *origSpacePoint, Belle2::SpacePoint *newSpacePoint, std::string clusterName="ALL")
register all the relations to Clusters that origSpacePoint had for newSpacePoint
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Class VXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
Base class to provide Sensor Information for PXD and SVD.
std::vector< std::string > m_PARAMspacePointNames
names of containers of SpacePoints
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
helper struct that holds information that is needed for the registration of the relation between Spac...
DataType Z() const
access variable Z (= .at(2) without boundary check)
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
std::pair< TVector3, TVector3 > getTrueHitPositions(TrueHitType *trueHit)
get the local (.first) and global (.second) position of a TrueHit (passed by index)
std::vector< unsigned int > m_noTrueHitCtr
Number of SpacePoints that contained a Cluster to which no TrueHit could be found (i....
unsigned int m_iCont
'helper variable' needed to not have to pass one integer down to processSpacePoint only to have a han...
TTree * m_treePtr
pointer to tree in root file
std::vector< std::string > m_PARAMrootFileName
name and update status of root file
helper class for setting up a bitfield that can be used to store several flags in one variable TODO: ...
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
std::unordered_map< int, TrueHitInfo > baseMapT
typedef for shorter notation throughout the module
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
unsigned int m_weightTooSmallCtr
Count the omitted relations because of a too small weight.
Belle2::StoreArray< Belle2::PXDTrueHit > m_PXDTrueHits
PXDTrueHits StoreArray used throughout the module.
double getVPitch(double v=0) const
Return the pitch of the sensor.
std::vector< std::array< unsigned int, 5 > > m_nRelTrueHitsCtr
counting different numbers of related TrueHits (to a SpacePoint) with one variable
void initializeCounters()
initialize all counters to 0 WARNING: only call in constructor of module!
double Y() const
return the y-value of the global position of the SpacePoint
bool compatibleCombination(Belle2::SpacePoint *spacePoint, TrueHitType *trueHit)
compares the TrueHit and the SpacePoint positions (global) to decide whether they are compatible NOTE...
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
TFile * m_rootFilePtr
pointer to root file
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
std::vector< typename MapType::key_type > getUniqueKeys(const MapType &aMap)
get the unique keys of a map (i.e.
void addStatus(T __statusBits)
add a status to the bitfield (if it has not already been added)
Class for type safe access to objects that are referred to in relations.
e_detTypes
enum to distinguish the detectortypes
std::pair< unsigned short int, unsigned short int > getClusterSizes(Belle2::SpacePoint *spacePoint, e_detTypes detType)
get the sizes of the related Clusters of a SpacePoint
std::vector< double > SpacePointULocal
SpacePoint local U-position.
static GeoCache & getInstance()
Return a reference to the singleton instance.
Abstract base class for different kinds of events.
std::vector< unsigned short int > HitVxdID
VxdID of the SpacePoint/TrueHit.
Type-safe access to single objects in the data store.
void initialize() override
initialize: initialize counters, check StoreArrays, register StoreArrays, ...
bool m_PARAMrequireProximity
require the TrueHit to be close to the SpacePoint.
std::vector< unsigned int > m_regRelationsCtr
Number of registered relations.
std::vector< unsigned int > NRelations
Number of related TrueHits to a SpacePoint.
std::vector< Belle2::StoreArray< Belle2::SpacePoint > > m_outputSpacePoints
StoreArray of all output SpacePoints.
Belle2::StoreArray< Belle2::SVDTrueHit > m_SVDTrueHits
SVDTrueHits StoreArray used throughout the module.
int getPDG() const
Return PDG code of particle.
MapType getRelatedTrueHits(Belle2::SpacePoint *spacePoint, std::string clusterName="ALL", std::string trueHitName="ALL")
get all the related TrueHits to the SpacePoint, including their weights in a map (multimap!...
std::vector< double > WeightU
weight of the relation between the U-Cluster of the SpacePoint and the TrueHit
double calculateRelationWeight(const TrueHitInfo &trueHitInfo, Belle2::SpacePoint *spacePoint)
calculate the Relation weight to be used (for SVD only, although method works with PXD as well!...
std::vector< unsigned int > m_noClusterCtr
Number of SpacePoints without relation to a Cluster (i.e.
std::vector< std::string > m_PARAMdetectorTypes
detector type names as strings to determine which name belongs to which detector type
bool m_PARAMstoreSeparate
switch for storing the SpacePoints that can be related to a TrueHit into separate StoreArrays,...
double getNormalizedLocalV() const
Return normalized local coordinates of the cluster in v (0 <= posV <= 1).
std::vector< unsigned int > m_ghostHitCtr
Number of SpacePoints that are considered ghost hits.
void positionAnalysis(Belle2::SpacePoint *spacePoint, const MapType &trueHitMap, const int &index, e_detTypes detType)
Analyze the position of SpacePoints and corresponding TrueHits.
std::vector< double > SpacePointXGlobal
SpacePoint global X-position.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
TVector3 pointToGlobal(const TVector3 &local, bool reco=false) const
Convert a point from local to global coordinates.
std::vector< unsigned int > m_rejectedRelsCtr
Number of SpacePoints that were not related to a TrueHit (i.e.
std::vector< double > SpacePointErrorY
positiion error of SpacePoint in Y direction (global)
bool m_PARAMpositionAnalysis
switch for doing the analysis of positions of SpacePoints and TrueHits
std::vector< std::string > m_PARAMclusterNames
names of containers of Clusters
double getUPitch(double v=0) const
Return the pitch of the sensor.
bool m_U
if true, U-Cluster is used by SpacePoint
std::vector< typename MapType::mapped_type > getAllValues(const MapType &aMap)
get all values in the map (i.e.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
std::vector< double > SpacePointVLocal
SpacePoint local V-position.
std::vector< std::string > m_PARAMtrueHitNames
names of containers of TrueHits
std::vector< double > TrueHitVLocal
TrueHit local V-position.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
MapType processSpacePoint(Belle2::SpacePoint *spacePoint, e_detTypes detType)
process a SpacePoint.
std::vector< double > SpacePointYGlobal
SpacePoint global Y-position.
RootVariables m_rootVariables
Root variables used for collecting data eventwise.
std::vector< double > WeightV
weight of the relation between the V-Cluster of the SpacePoint and the TrueHit
float weight(int index) const
Get weight with index.
void registerAllRelations(Belle2::SpacePoint *spacePoint, MapType trueHitMap, e_detTypes detType)
register a Relation to all the TrueHits in the trueHitMap for the passed SpacePoint
@ c_Debug
Debug: for code development.
std::vector< std::pair< ClusterType *, double > > getRelatedClusters(Belle2::SpacePoint *spacePoint, std::string clusterName="ALL")
get the pointers to the related Clusters and the weight of the original Relations between the spacePo...
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
A Class to store the Monte Carlo particle information.
Accessor to arrays stored in the data store.
std::vector< double > SpacePointZGlobal
SpacePoint global Z-position.
double m_PARAMminWeight
define a minimal weight a relation between Cluster and TrueHit.
static Environment & Instance()
Static method to get a reference to the Environment instance.
std::vector< std::pair< Belle2::StoreArray< Belle2::SpacePoint >, e_detTypes > > m_inputSpacePoints
StoreArray of all input SpacePoints.
std::string m_PARAMoutputSuffix
suffix that will be appended to the StoreArray names of the output StoreArrays
DataType X() const
access variable X (= .at(0) without boundary check)
void registerTrueHitRelation(Belle2::SpacePoint *spacePoint, int index, double weight, Belle2::StoreArray< TrueHitType > trueHits)
register the relation between a SpacePoint and the TrueHit (passed by index in the correspoinding Tru...
std::vector< unsigned int > m_SpacePointsCtr
Number of SpacePoints presented to the module.
void closeRootFile()
close root file
std::vector< double > TrueHitYGlobal
TrueHit global Y-position.
double m_maxGlobalDiff
storing the squared value of m_PARAMmaxGlobalDiff here to not alter the parameter input
std::vector< double > TrueHitULocal
TrueHit local U-position.
std::vector< double > SpacePointErrorV
position error of SpacePoint in V direction
const T getStatus() const
get the status of the bitfield
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
const std::string & getName() const
Returns the name of the module.
bool m_V
if true, V-Cluster is used by SpacePoint
unsigned short getNClustersAssigned() const
Returns the number of Clusters assigned to this SpacePoint.
std::pair< double, double > getLocalError(Belle2::SpacePoint *spacePoint)
get the position error of SpacePoints in local coordinates @retuns .first is U position error,...
std::vector< double > SpacePointErrorZ
positiion error of SpacePoint in Z direction (global)
void setStatus(T __statusBits)
set the status of the bitfield (CAUTION: overwrites any previously defined status!...
void terminate() override
terminate: print some summary information
int getEntries() const
Get the number of objects in the array.
std::string printMap(const MapType &aMap)
get the contents of the map as string.
DataType Y() const
access variable Y (= .at(1) without boundary check)
@ c_PrimaryParticle
bit 0: Particle is primary particle.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
const B2Vector3< double > & getPositionError() const
return the hitErrors in sigma of the global position
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
static std::pair< double, double > convertNormalizedToLocalCoordinates(const std::pair< double, double > &hitNormalized, Belle2::VxdID vxdID, const Belle2::VXD::SensorInfoBase *aSensorInfo=nullptr)
converts a hit in sensor-independent relative coordinates into local coordinate of given sensor.
double getNormalizedLocalU() const
Return normalized local coordinates of the cluster in u (0 <= posU <= 1).
void initializeCounters()
reset counters to 0 to avoid indeterministic behaviour
std::vector< double > SpacePointErrorX
positiion error of SpacePoint in X direction (global)