Belle II Software  release-08-01-10
CurlingTrackCandSplitterModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <tracking/modules/spacePointCreator/CurlingTrackCandSplitterModule.h>
10 
11 // DataStore Stuff
12 #include <framework/dataobjects/EventMetaData.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 
15 // Clusters and TrueHits
16 #include <pxd/dataobjects/PXDCluster.h>
17 #include <pxd/dataobjects/PXDTrueHit.h>
18 #include <svd/dataobjects/SVDCluster.h>
19 #include <svd/dataobjects/SVDTrueHit.h>
20 
21 // SpacePoint related stuff
22 #include <tracking/spacePointCreation/SpacePoint.h>
23 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
24 
25 #include <boost/format.hpp>
26 
27 #include <algorithm> // sort & unique
28 
29 using namespace Belle2;
30 
31 REG_MODULE(CurlingTrackCandSplitter);
32 
33 // COULDDO: somehow retrieve the names under which Clusters and TrueHits are stored in the StoreArray (possible?) Or make them a parameter of the module. Otherwise it can happen, that, if more than one StoreArray of XYZCluster is present, all of them get searched, which might be unintended (or even undefined behaviour)
34 
36 {
37  setDescription("Module for checking SpacePointTrackCands for curling behaviour and (if wanted) splitting them into SpacePointTrackCands that no longer show curling behaviour. WARNING: MODULE IS DEPRECATED use SPTCReferee instead!");
38 
39  addParam("splitCurlers", m_PARAMsplitCurlers,
40  "Split curling SpacePointTrackCands into non-curling SpacePointTrackCands and store them", true);
41  addParam("nTrackStubs", m_PARAMnTrackStubs,
42  "Maximum number of SpacePointTrackCand Stubs to be created from a curling SpacePointTrackCand. Set to 0 if you want all possible TrackCand Stubs",
43  0);
44 
45  addParam("SpacePointTCName", m_PARAMsptcName, "Collection name of the SpacePointTrackCands to be analyzed for curling behaviour",
46  std::string(""));
47  addParam("curlingFirstOutName", m_PARAMcurlingOutFirstName,
48  "Collection name under which the first outgoing part of a curling TrackCand will be stored in the StoreArray. The first part of a curling Track has its origin at the interaction point.",
49  std::string(""));
50  addParam("curlingAllInName", m_PARAMcurlingAllInName,
51  "Collection name under which all ingoing parts of a curling TrackCand will be stored in the StoreArray", std::string(""));
52  addParam("curlingRestOutName", m_PARAMcurlingOutRestName,
53  "Collection name under which all but the first outgoing parts of a curling TrackCand will be stored in the StoreArray",
54  std::string(""));
55  addParam("completeCurlerName", m_PARAMcompleteCurlerName,
56  "Collection name under which all parts of a curling TrackCand will be stored in the StoreArray together. NOTE: only if this parameter is set to a non-empty string a complete (but splitted) curling TrackCand will be stored!",
57  std::string(""));
58 
59  // WARNING TODO: find out the units that are used internally!!!
60  std::vector<double> defaultOrigin = { 0., 0., 0. };
61  addParam("setOrigin", m_PARAMsetOrigin,
62  "WARNING: still need to find out the units that are used internally! Reset origin to given point. Used for determining the direction of flight of a particle for a given hit. Needs to be reset for e.g. testbeam, where origin is not at (0,0,0)",
63  defaultOrigin);
64 
65  addParam("positionAnalysis", m_PARAMpositionAnalysis,
66  "Set to true to investigate the positions of SpacePoints and TrueHits and write them to a ROOT file", false);
67 
68  std::vector<std::string> defaultRootFName;
69  defaultRootFName.push_back("PositionResiduals");
70  defaultRootFName.push_back("RECREATE");
71 
72  addParam("rootFileName", m_PARAMrootFileName,
73  "Filename and write-mode ('RECREATE' or 'UPDATE'). If given more than 2 strings this module will cause termination",
74  defaultRootFName);
75 
76 
77  addParam("useNonSingleTHinPA", m_PARAMuseNonSingleTHinPA,
78  "Switch for using SpacePoints in position Analysis that are related to more than one TrueHit", false);
79 
80  initializeCounters(); // NOTE: they get initialized in initialize again!!
81 
82  // initialize other variables to some default values to avoid unintended behaviour
83  m_saveCompleteCurler = false;
84  m_treePtr = nullptr;
85  m_rootFilePtr = nullptr;
86 }
87 
88 // ================================================= INITIALIZE =========================================================
90 {
92  B2INFO("CurlingTrackCandSplitter ----------------------------- initialize() -------------------------------------");
93  B2WARNING("CurlingTrackCandSplitter is deprecated and will be removed from framework in the near future! use SPTCReferee instead!");
94  // check if all necessary StoreArrays are present
96 
97  // count all empty input parameter strings, and issue a warning if more than one is empty (COULDDO: B2FATAL instead of warning)
98  int emptyCtr = 0;
99  if (m_PARAMcurlingOutFirstName.empty()) { emptyCtr++; }
100  if (m_PARAMcurlingAllInName.empty()) { emptyCtr++; }
101  if (m_PARAMcurlingOutRestName.empty()) { emptyCtr++; }
102 
103  if (emptyCtr > 1) {
104  B2WARNING("CurlingTrackCandSplitter::initialize: More than one of your input strings for the collection names is empty. This can lead to undeterministic behaviour since two or more collections will be stored under the same name!");
105  }
106 
107  // register new StoreArrays, and relation to original TrackCand
110 
113 
116 
117  // have to do this here, because in event() I do not want to check every time if this string is empty or not and act accordingly. If I register this with an empty string here, I can use it with an empty string in event() and only store stuff into it, when it is actually named with a non-empty string
120 
121  if (!m_PARAMcompleteCurlerName.empty()) {
122  m_saveCompleteCurler = true;
123  B2DEBUG(21, "You put in " << m_PARAMcompleteCurlerName <<
124  " as collection name for complete curling TrackCands. Complete curling TrackCands will hence be stored.");
125  } else {
126  B2DEBUG(21,
127  "You did not put in any under which complete curling TrackCands should be stored, hence curling TrackCands will only be stored in parts.");
128  m_saveCompleteCurler = false;
129  }
130 
131  // check value for nTrackStubs and reset if necessary
132  if (m_PARAMnTrackStubs < 0) {
133  B2WARNING("CurlingTrackCandSplitter::initialize> Value of nTrackStubs is below 0: nTrackStubs = " << m_PARAMnTrackStubs <<
134  ". Resetting this value to 0 now! This means that all parts of curling TrackCands will be stored.");
135  m_PARAMnTrackStubs = 0;
136  } else { B2DEBUG(21, "Entered value for nTrackStubs = " << m_PARAMnTrackStubs); }
137 
138  B2DEBUG(21, "Entered Value for splitCurlers: " << m_PARAMsplitCurlers);
139 
140  if (m_PARAMsetOrigin.size() != 3) {
141  B2WARNING("CurlingTrackCandSplitter::initialize: Provided origin is not a 3D point! Please provide 3 values (x,y,z). Rejecting user input and setting origin to (0,0,0) for now!");
142  m_PARAMsetOrigin.clear();
143  m_PARAMsetOrigin.assign(3, 0);
144  }
146  B2DEBUG(21, "Set origin to (x,y,z): (" << m_origin.X() << "," << m_origin.Y() << "," << m_origin.Z() << ")");
147 
149  // check if there are two entries and if the second value is either UPDATE or RECREATE
150  if (m_PARAMrootFileName.size() != 2 || (m_PARAMrootFileName[1] != "UPDATE" && m_PARAMrootFileName[1] != "RECREATE")) {
151  std::string output;
152  for (std::string entry : m_PARAMrootFileName) { output += "'" + entry + "' "; }
153  B2FATAL("CurlingTrackCandSplitter::initialize() : rootFileName is set wrong: entries are: " << output);
154  }
155  // create ROOT file
156  m_PARAMrootFileName[0] += ".root";
157  m_rootFilePtr = new TFile(m_PARAMrootFileName[0].c_str(), m_PARAMrootFileName[1].c_str());
158  m_treePtr = new TTree("m_treePtr", "aTree");
159 
160  // link everything to the according variables
161  for (int layer = 0; layer < c_nPlanes; ++layer) {
162  std::string layerString = (boost::format("%1%") % (layer +
163  1)).str(); // layer numbering starts at 1 this way (plus cppcheck complains about division by zero otherwise)
164 
165  std::string name = "SpacePointXGlobal_" + layerString;
166  m_treePtr->Branch(name.c_str(), &m_rootSpacePointXGlobals.at(layer));
167  name = "SpacePointYGlobal_" + layerString;
168  m_treePtr->Branch(name.c_str(), &m_rootSpacePointYGlobals.at(layer));
169  name = "SpacePointZGlobal_" + layerString;
170  m_treePtr->Branch(name.c_str(), &m_rootSpacePointZGlobals.at(layer));
171 
172  name = "SpacePointULocal_" + layerString;
173  m_treePtr->Branch(name.c_str(), &m_rootSpacePointULocals.at(layer));
174  name = "SpacePointVlocal_" + layerString;
175  m_treePtr->Branch(name.c_str(), &m_rootSpacePointVLocals.at(layer));
176 
177  name = "TrueHitXGlobal_" + layerString;
178  m_treePtr->Branch(name.c_str(), &m_rootTrueHitXGlobals.at(layer));
179  name = "TrueHitYGlobal_" + layerString;
180  m_treePtr->Branch(name.c_str(), &m_rootTrueHitYGlobals.at(layer));
181  name = "TrueHitZGlobal_" + layerString;
182  m_treePtr->Branch(name.c_str(), &m_rootTrueHitZGlobals.at(layer));
183 
184  name = "TrueHitULocal_" + layerString;
185  m_treePtr->Branch(name.c_str(), &m_rootTrueHitULocals.at(layer));
186  name = "TrueHitVLocal_" + layerString;
187  m_treePtr->Branch(name.c_str(), &m_rootTrueHitVLocals.at(layer));
188 
189  name = "PosResidualsXGlobal_" + layerString;
190  m_treePtr->Branch(name.c_str(), &m_rootPosResidueXGlobal.at(layer));
191  name = "PosResidualsYGlobal_" + layerString;
192  m_treePtr->Branch(name.c_str(), &m_rootPosResidueYGlobal.at(layer));
193  name = "PosResidualsZGlobal_" + layerString;
194  m_treePtr->Branch(name.c_str(), &m_rootPosResidueZGlobal.at(layer));
195 
196  name = "PosResidualsULocal_" + layerString;
197  m_treePtr->Branch(name.c_str(), &m_rootPosResidueULocal.at(layer));
198  name = "PosResidualsVLocal_" + layerString;
199  m_treePtr->Branch(name.c_str(), &m_rootPosResidueVLocal.at(layer));
200 
201 
202  name = "LocalPositionResiduals_" + layerString;
203  m_treePtr->Branch(name.c_str(), &m_rootLocalPosResiduals.at(layer));
204  name = "GlobalPositionResiduals_" + layerString;
205  m_treePtr->Branch(name.c_str(), &m_rootGlobalPosResiduals.at(layer));
206 
207  name = "MisMatchPosDistance_" + layerString;
208  m_treePtr->Branch(name.c_str(), &m_rootMisMatchPosDistance.at(layer));
209  name = "MisMatchPosX_" + layerString;
210  m_treePtr->Branch(name.c_str(), &m_rootMisMatchPosX.at(layer));
211  name = "MisMatchPosY_" + layerString;
212  m_treePtr->Branch(name.c_str(), &m_rootMisMatchPosY.at(layer));
213  name = "MisMatchPosZ_" + layerString;
214  m_treePtr->Branch(name.c_str(), &m_rootMisMatchPosZ.at(layer));
215 
216  name = "MisMatchPosU_" + layerString;
217  m_treePtr->Branch(name.c_str(), &m_rootMisMatchPosU.at(layer));
218  name = "MisMatchPosV_" + layerString;
219  m_treePtr->Branch(name.c_str(), &m_rootMisMatchPosV.at(layer));
220 
221  name = "MisMatchMomX_" + layerString;
222  m_treePtr->Branch(name.c_str(), &m_rootMisMatchMomX.at(layer));
223  name = "MisMatchMomY_" + layerString;
224  m_treePtr->Branch(name.c_str(), &m_rootMisMatchMomY.at(layer));
225  name = "MisMatchMomZ_" + layerString;
226  m_treePtr->Branch(name.c_str(), &m_rootMisMatchMomZ.at(layer));
227  }
228  } else {
229  m_rootFilePtr = nullptr;
230  m_treePtr = nullptr;
231  }
232 }
233 
234 // =================================================== EVENT ============================================================
236 {
237  StoreObjPtr<EventMetaData> eventMetaDataPtr("EventMetaData", DataStore::c_Event);
238  const int eventCounter = eventMetaDataPtr->getEvent();
239  B2DEBUG(21, "CurlingTrackCandSplitter::event(). -------------- Processing event " << eventCounter << " ----------------");
240 
241  // StoreArrays that will be used for storing
242  int nTCs = m_spacePointTCs.getEntries();
243 
244  B2DEBUG(21, "Found " << nTCs << " SpacePointTrackCands in StoreArray " << m_spacePointTCs.getName() << " for this event");
245 
246  RootVariables rootVariables;
247 
248  for (int iTC = 0; iTC < nTCs; ++iTC) {
249  SpacePointTrackCand* spacePointTC = m_spacePointTCs[iTC];
251 
252  B2DEBUG(21, "=========================== Processing SpacePointTrackCand " << iTC << " ===============================");
253  try {
254  const std::vector<int> splittingIndices = checkTrackCandForCurling(*spacePointTC, rootVariables);
255 
256  if (splittingIndices.empty()) {
257  B2DEBUG(21, "This SpacePointTrackCand shows no curling behaviour and will be added to collection: " << m_PARAMcurlingOutFirstName);
258  spacePointTC->setTrackStubIndex(0); // set TrackStubIndex to 0 (indicates, that this TrackCandidate shows no curling behaviour)
259  // add this spacePoint to the StoreArray with the first outgoing parts since the whole TC is outgoing
260  SpacePointTrackCand* newSPTC = m_curlingFirstOuts.appendNew(*spacePointTC);
261  newSPTC->addRelationTo(spacePointTC);
263  } else {
264  B2DEBUG(21, "This SpacePointTrackCand shows curling behaviour");
265  if (!m_PARAMsplitCurlers) {
266  B2DEBUG(21, "This SpacePointTrackCand could be split into " << splittingIndices.size() + 1 <<
267  " but will not, because splitCurlers is set to false");
268  continue; // should jump to enclosing for-loop!!! (process the next SpacePointTrackCand)
269  }
270  m_curlingTCCtr++;
271  // get the TrackCand Stubs
272  std::vector<SpacePointTrackCand> trackStubs = splitCurlingTrackCand(*spacePointTC, m_PARAMnTrackStubs, splittingIndices);
273 
274  // add the stubs to the appropriate StoreArray
275  for (SpacePointTrackCand trackStub : trackStubs) {
277  if (m_saveCompleteCurler) {
278  SpacePointTrackCand* newSPTC = m_curlingCompletes.appendNew(trackStub);
279  newSPTC->addRelationTo(spacePointTC);
280  B2DEBUG(21, "Added SpacePointTrackCand " << newSPTC->getArrayIndex() << " to StoreArray " << newSPTC->getArrayName());
281  }
282  if (!trackStub.isOutgoing()) {
283  SpacePointTrackCand* newSPTC = m_curlingAllIns.appendNew(trackStub);
284  newSPTC->addRelationTo(spacePointTC);
285  B2DEBUG(21, "Added SpacePointTrackCand " << newSPTC->getArrayIndex() << " to StoreArray " << newSPTC->getArrayName());
286  } else { // if not ingoing differentiate between first part and all of the rest
287  if (trackStub.getTrackStubIndex() > 1) {
288  SpacePointTrackCand* newSPTC = m_curlingRestOuts.appendNew(trackStub);
289  newSPTC->addRelationTo(spacePointTC);
290  B2DEBUG(21, "Added SpacePointTrackCand " << newSPTC->getArrayIndex() << " to StoreArray " << newSPTC->getArrayName());
291  } else {
292  SpacePointTrackCand* newSPTC = m_curlingFirstOuts.appendNew(trackStub);
293  newSPTC->addRelationTo(spacePointTC);
294  B2DEBUG(21, "Added SpacePointTrackCand " << newSPTC->getArrayIndex() << " to StoreArray " << newSPTC->getArrayName());
295  }
296  }
297  }
298  }
299  } catch (FoundNoTrueHit& anE) {
300  B2WARNING("Caught an exception during checking for curling behaviour: " << anE.what() <<
301  " This TrackCandidate cannot be checked for curling behaviour");
303  } catch (FoundNoCluster& anE) {
304  B2WARNING("Caught an exception during checking for curling behaviour: " << anE.what() <<
305  " This TrackCandidate cannot be checked for curling behaviour");
307  } catch (TrueHitsNotMatching& anE) {
308  B2WARNING("Caught an exception during checking for curling behaviour: " << anE.what() <<
309  " This TrackCandidate cannot be checked for curling behaviour");
311  } catch (SpacePointTrackCand::UnsupportedDetType& anE) {
312  B2WARNING("Caught an exception during checking for curling behaviour: " << anE.what() <<
313  " This TrackCandidate cannot be checked for curling behaviour");
315  }
316  }
317  // only write to root once per event
318  if (m_PARAMpositionAnalysis) { writeToRoot(rootVariables); }
319 }
320 
321 // =================================================== TERMINATE ========================================================
323 {
324  B2INFO("CurlingTrackCandSplitter::terminate(): checked " << m_spacePointTCCtr << " SpacePointTrackCands for curling behaviour. " <<
325  m_curlingTCCtr << " of them were curling and " << m_createdTrackStubsCtr << " TrackStubs were created. " << m_NoCurlingTCsCtr <<
326  " SPTCs were not curling and were merely copied into StoreArray " << m_PARAMcurlingOutFirstName << ". In " <<
327  m_noDecisionPossibleCtr << " cases no decision could be made. There were " << m_NoSingleTrueHitCtr <<
328  " SpacePoints that were related to more than one TrueHit");
329  // do ROOT file stuff
330  if (m_treePtr != nullptr) {
331  m_rootFilePtr->cd(); //important! without this the famework root I/O (SimpleOutput etc) could mix with the root I/O of this module
332  m_treePtr->Write();
333  m_rootFilePtr->Close();
334  }
335 }
336 
337 // ============================================== CHECK FOR CURLING ======================================================
339  RootVariables& rootVariables)
340 {
341  const std::vector<const Belle2::SpacePoint*>& tcSpacePoints = SPTrackCand.getHits();
342  unsigned int nHits = SPTrackCand.getNHits();
343 
344  B2DEBUG(21, "SpacePointTrackCand contains " << nHits << " SpacePoints");
345 
346  std::vector<int> returnVector; // fill this vector with indices, if no indices can be found, leave it empty
347 
348  std::pair<bool, bool>
349  directions; // only store the last two directions to decide if it has changed or not. .first is always last hit, .second is present hit.
350  directions.first =
351  true; // assume that the track points outwards from the interaction point at first. NOTE: this assumption is not dangerous here (it is in other places because it does not have to be the case). The information on the direction of flight for the first hit is stored in the returnVector itself. If the first entry is 0 (this means that the trackCand first 'pointed' towards the interaction point)
352 
353  for (unsigned int iHit = 0; iHit < nHits; ++iHit) {
354  const SpacePoint* spacePoint = tcSpacePoints[iHit];
355  auto detType = spacePoint->getType();
356 
357  B2DEBUG(21, "Now checking SpacePoint " << iHit << " in SPTC. This SpacePoint has Index " << spacePoint->getArrayIndex() <<
358  " in StoreArray " << spacePoint->getArrayName());
359 
360  // get global position and momentum for every spacePoint in the SpacePointTrackCand
361  std::pair<B2Vector3<double>, B2Vector3<double> > hitGlobalPosMom;
362 
363  if (detType == VXD::SensorInfoBase::PXD) {
364  // first get PXDCluster, from that get TrueHit
365  PXDCluster* pxdCluster =
366  spacePoint->getRelatedTo<PXDCluster>("ALL"); // COULDDO: search only certain Cluster Arrays -> get name somehow
367  // CAUTION: only looking for one TrueHit here, but there could actually be more of them 'molded' into one Cluster
368  PXDTrueHit* pxdTrueHit =
369  pxdCluster->getRelatedTo<PXDTrueHit>("ALL"); // COULDDO: search only certain PXDTrueHit arrays -> new parameter for module
370 
371  if (pxdTrueHit == nullptr) {
372  B2DEBUG(21, "Found no PXDTrueHit for PXDCluster " << pxdCluster->getArrayIndex() << " from Array " << pxdCluster->getArrayName() <<
373  ". This PXDCluster is related with SpacePoint " << spacePoint->getArrayIndex() << " from Array " << spacePoint->getArrayName());
374  throw FoundNoTrueHit();
375  }
376 
377  B2DEBUG(21, "Found PXDCluster " << pxdCluster->getArrayIndex() << " and " << " PXDTrueHit " << pxdTrueHit->getArrayIndex() <<
378  " from StoreArray " << pxdTrueHit->getArrayName() << " related to this SpacePoint");
379 
380  B2DEBUG(21, "Now getting global position and momentum for PXDCluster " << pxdCluster->getArrayIndex() << " from Array " <<
381  pxdCluster->getArrayName());
382  hitGlobalPosMom = getGlobalPositionAndMomentum(pxdTrueHit);
383 
384  // if position analysis is set to true, print to root file
385  if (m_PARAMpositionAnalysis) { getValuesForRoot(spacePoint, pxdTrueHit, rootVariables); }
386 
387  } else if (detType == VXD::SensorInfoBase::SVD) {
388  // get all related SVDClusters and do some sanity checks, before getting the SVDTrueHits and then using them to get global position and momentum
389  RelationVector<SVDCluster> svdClusters =
390  spacePoint->getRelationsTo<SVDCluster>("ALL"); // COULDDO: search only certain Cluster Arrays -> get name somehow (addidional parameter?)
391  if (svdClusters.size() == 0) {
392  B2WARNING("Found no related clusters for SpacePoint " << spacePoint->getArrayIndex() << " from Array " << spacePoint->getArrayName()
393  << ". With no Cluster no information if a track is curling or not can be obtained");
394  throw FoundNoCluster(); // this should also never happen, as the vice versa way is used to get to the SpacePoints in the first place (in the GFTC2SPTCConverterModule e.g.)
395  } else {
396  // collect the TrueHits, if there is more than one compare them, to see if both Clusters point to the same TrueHit
397  // WARNING there can be more! more than one TrueHit can be 'hidden' in one Cluster!!!
398  // TODO: look at this again, this seems not to work properly at the moment!!!
399  std::vector<const SVDTrueHit*> svdTrueHits;
400  for (const SVDCluster& aCluster : svdClusters) {
401  // CAUTION: there can be more than one TrueHit for a given Cluster!!!
402  RelationVector<SVDTrueHit> relTrueHits =
403  aCluster.getRelationsTo<SVDTrueHit>("ALL"); // COULDDO: search only certain SVDTrueHit arrays -> new parameter for module
404  if (relTrueHits.size() == 0) {
405  B2DEBUG(21, "Found no SVDTrueHit for SVDCluster " << aCluster.getArrayIndex() << " from Array " << aCluster.getArrayName() <<
406  ". This SVDCluster is related with SpacePoint " << spacePoint->getArrayIndex() << " from Array " << spacePoint->getArrayName());
407  throw FoundNoTrueHit();
408  }
409 
410  B2DEBUG(21, "Found " << relTrueHits.size() << " TrueHits for SVDCluster " << aCluster.getArrayIndex() << " from Array " <<
411  aCluster.getArrayName());
412  for (unsigned int i = 0; i < relTrueHits.size(); ++i) { svdTrueHits.push_back(relTrueHits[i]); }
413  }
414 
415  // if there is only one cluster related to the SpacePoint simply check if one (or more TrueHits are present). Additionally checking the size for svdTrueHits again is not necessary here, because if there was only one Cluster and no TrueHits were found this part is never reached!
416  // WARNING: It is not guaranteed that this actually leads to a valid relation between SpacePoint and TrueHit!!
417  // TODO: continuing with next SpacePoint skips check for curling behavior!!! FIX this!!!
418 // if (svdClusters.size() == 1) {
419 // std::stringstream inds;
420 // for (const SVDTrueHit * trueHit : svdTrueHits) { inds << trueHit->getArrayIndex() << ", "; }
421 // B2DEBUG(21, "Found only one Cluster related to SpacePoint " << spacePoint->getArrayIndex() << " from Array " << spacePoint->getArrayName() << ". To this Cluster " << svdTrueHits.size() << " related TrueHits were found. Indices: " << inds.str());
422 // m_NoSingleTrueHitCtr++;
423 // continue; // start over with next SpacePoint
424 // }
425 
426  // if there is at least one TrueHit in the vector check how many unique TrueHits there are
427  if (svdTrueHits.size() >= 1) {
428  B2DEBUG(21, "Found " << svdTrueHits.size() << " SVDTrueHits related to Clusters related to SpacePoint " <<
429  spacePoint->getArrayIndex() << " from Array " << spacePoint->getArrayName() << ". Now checking if they are compatible");
430 
431  // sort & unique to find the unique entries of the relation vector
432  std::sort(svdTrueHits.begin(), svdTrueHits.end());
433  unsigned int oldSize = svdTrueHits.size();
434  auto newEnd = std::unique(svdTrueHits.begin(), svdTrueHits.end());
435  svdTrueHits.resize(std::distance(svdTrueHits.begin(), newEnd));
436 
437  // If there is no overlapping TrueHit get all indices of the TrueHits and print a warning. If position Analysis is enabled calculate the position differences of the TrueHits. In the end throw an Exception (only if the TrueHits belong to a non-single Cluster SVD SpacePoint)
438  if (svdTrueHits.size() == oldSize) {
439  std::stringstream trueHitInds;
440  for (const SVDTrueHit* trueHit : svdTrueHits) { trueHitInds << trueHit->getArrayIndex() << ", "; }
441  B2DEBUG(21, "There is no overlapping TrueHit for SpacePoint " << spacePoint->getArrayIndex() << " from Array " <<
442  spacePoint->getArrayName() << ". The Indices of the TrueHits are: " << trueHitInds.str());
443 
444  // Only do these calculations if output to root is is enabled
446  std::vector<B2Vector3<double> > globalPositions;
447  std::vector<B2Vector3<double> > globalMomenta;
448  // collect all values
449  for (unsigned int i = 0; i < svdTrueHits.size(); ++i) {
450  auto posMom = getGlobalPositionAndMomentum(svdTrueHits[i]);
451  globalPositions.push_back(posMom.first);
452  globalMomenta.push_back(posMom.second);
453  }
454  // WARNING: getting only layer number of first TrueHit in vector here. Although this should not change, this is never actually checked!!
455  int layer = svdTrueHits[0]->getSensorID().getLayerNumber() - 1; // layer numbering starts at 1, indexing of array at 0
456  // do the calculations (starting from one because of comparison of two elements in each run through loop)
457  for (unsigned int i = 1; i < globalPositions.size(); ++i) {
458  rootVariables.MisMatchPosResiduals.at(layer).push_back((globalPositions[i] - globalPositions[i - 1]).Mag());
459 
460  rootVariables.MisMatchPosX.at(layer).push_back((globalPositions[i] - globalPositions[i - 1]).X());
461  rootVariables.MisMatchPosY.at(layer).push_back((globalPositions[i] - globalPositions[i - 1]).Y());
462  rootVariables.MisMatchPosZ.at(layer).push_back((globalPositions[i] - globalPositions[i - 1]).Z());
463 
464  rootVariables.MisMatchPosU.at(layer).push_back((svdTrueHits[i]->getU() - svdTrueHits[i - 1]->getU()));
465  rootVariables.MisMatchPosV.at(layer).push_back((svdTrueHits[i]->getV() - svdTrueHits[i - 1]->getV()));
466 
467  B2Vector3<double> momDiff = globalMomenta[i] - globalMomenta[i - 1];
468  rootVariables.MisMatchMomX.at(layer).push_back(momDiff.X());
469  rootVariables.MisMatchMomY.at(layer).push_back(momDiff.Y());
470  rootVariables.MisMatchMomZ.at(layer).push_back(momDiff.Z());
471  }
472  }
473  // if the TrueHits are related from a singleCluster SVD SpacePoint (i.e. more than one TrueHits are molded into one Cluster) do not throw this exception but continue with the curling checking
474  if (svdClusters.size() > 1) { TrueHitsNotMatching(); }
475  }
476  }
477 
478  // if there is more than one TrueHit remaining for one SpacePoint increase the counter
479  if (svdTrueHits.size() > 1) {
481  }
482 
483  // WARNING if there are more than one matching TrueHits only the first TrueHit is used for comparison and for position analysis
484  B2DEBUG(21, "Now getting global position and momentum for SVDCluster " << svdClusters[0]->getArrayIndex() << " from Array " <<
485  svdClusters[0]->getArrayName() << " via SVDTrueHit " << svdTrueHits[0]->getArrayIndex() << " from StoreArray " <<
486  svdTrueHits[0]->getArrayName());
487  hitGlobalPosMom = getGlobalPositionAndMomentum(svdTrueHits[0]);
488 
489  // if position analysis is set to true, print to root file
490  // only do so if there is only one TrueHit (this is only for the moment!!!) OR if the switch is set to do so even if there is more than one TrueHit
491  // TODO: Decide how to handle such cases where more than one TrueHit is left and implement accordingly
492  if (m_PARAMpositionAnalysis && (svdTrueHits.size() == 1 || m_PARAMuseNonSingleTHinPA)) { getValuesForRoot(spacePoint, svdTrueHits[0], rootVariables); }
493  }
494  } else { // this should never be reached, because it should be caught in the creation of the SpacePointTrackCand which is passed to this function!
495  throw SpacePointTrackCand::UnsupportedDetType();
496  }
497 
498  // get the direction of flight for the present SpacePoint
499  directions.second = getDirectionOfFlight(hitGlobalPosMom, m_origin);
500 
501  // check if the directions have changed since the last hit, if so, add the number of the SpacePoint (inside the SpacePointTrackCand) to the returnVector
502  if (directions.first != directions.second) {
503  B2DEBUG(21, "The direction of flight has changed for SpacePoint " << iHit <<
504  " in SpacePointTrackCand. The StoreArray index of this SpacePoint is " << spacePoint->getArrayIndex() << " in " <<
505  spacePoint->getArrayName());
506  returnVector.push_back(iHit);
507  }
508  // assign old value to .first, for next comparison
509  directions.first = directions.second;
510  }
511  return returnVector;
512 }
513 
514 // ======================================= GET GLOBAL POSITION AND MOMENTUM ============================================================
515 
517 template<class TrueHit>
518 std::pair<const Belle2::B2Vector3<double>, const Belle2::B2Vector3<double> >
520 {
521  // get sensor stuff (needed for pointToGlobal)
522  VxdID aVxdId = aTrueHit->getSensorID();
523 
524  B2DEBUG(21, "Getting global position and momentum vectors for TrueHit " << aTrueHit->getArrayIndex() << " from Array " <<
525  aTrueHit->getArrayName() << ". This hit has VxdID " << aVxdId);
526 
527  const VXD::GeoCache& geometry = VXD::GeoCache::getInstance();
528  const VXD::SensorInfoBase& sensorInfoBase = geometry.getSensorInfo(aVxdId);
529 
530  // get position
531  B2Vector3<double> hitLocal = B2Vector3<double>(aTrueHit->getU(), aTrueHit->getV(), 0);
532  B2Vector3<double> hitGlobal = sensorInfoBase.pointToGlobal(
533  hitLocal, true); // should work like this, since local coordinates are only 2D
534  B2DEBUG(21, "Local position of hit is (" << hitLocal.X() << "," << hitLocal.Y() << "," << hitLocal.Z() <<
535  "), Global position of hit is (" << hitGlobal.X() << "," << hitGlobal.Y() << "," << hitGlobal.Z() << ")");
536 
537  // get momentum
538  B2Vector3<double> pGlobal = sensorInfoBase.vectorToGlobal(aTrueHit->getMomentum(), true);
539  B2DEBUG(21, "Global momentum of hit is (" << pGlobal.X() << "," << pGlobal.Y() << "," << pGlobal.Z() << ")");
540 
541  return std::make_pair(hitGlobal, pGlobal);
542 }
543 
544 // ======================================= GET DIRECTION OF FLIGHT ======================================================================
546  std::pair<const B2Vector3<double>, const B2Vector3<double>>& hitPosAndMom,
547  const B2Vector3<double>& origin)
548 {
549  B2Vector3<double> originToHit = hitPosAndMom.first - origin;
550  B2Vector3<double> momentumAtHit = hitPosAndMom.second + originToHit;
551 
552 
553  B2DEBUG(21, "Position of hit relative to origin is (" << originToHit.X() << "," << originToHit.Y() << "," << originToHit.Z() <<
554  "). Momentum relative to hit (relative to origin) (" << momentumAtHit.X() << "," << momentumAtHit.Y() << "," << momentumAtHit.Z() <<
555  ")");
556 
557  // cylindrical coordinates (?) -> use B2Vector3.Perp() to get the radial component of a given vector
558  // for spherical coordinates -> use B2Vector3.Mag() for the same purposes
559  double hitRadComp = originToHit.Perp(); // radial component of hit coordinates
560  double hitMomRadComp =
561  momentumAtHit.Perp(); // radial component of the tip of the momentum vector, when its origin would be the hit position (as it is only the direction of the momentum that matters here, units are completely ignored -> COULDDO: use the unit() method from B2Vector3
562 
563  B2DEBUG(21, " radial component of hit coordinates: " << hitRadComp <<
564  ", radial component of tip of momentum vector with its origin set to hit position: " << hitMomRadComp);
565 
566  if (hitMomRadComp < hitRadComp) {
567  B2DEBUG(21, "Direction of flight is inwards for this hit");
568  return false;
569  } else {
570  B2DEBUG(21, "Direction of flight is outwards for this hit");
571  return true;
572  }
573 }
574 
575 // ================================================ SPLIT CURLING TRACK CAND =========================================================
576 const std::vector<Belle2::SpacePointTrackCand>
578  const std::vector<int>& splitIndices)
579 {
580  std::vector<SpacePointTrackCand> spacePointTCs;
581 
582  std::vector<std::pair<int, int> >
583  rangeIndices; // store pairs of Indices indicating the first and the last index of a TrackStub inside a SpacePointTrackCand
584 
585  int firstIndex = 0; // first 'first index' is 0
586  for (int index : splitIndices) {
587  rangeIndices.push_back({firstIndex, index});
588  firstIndex = index + 1; // next first index is last index + 1
589  }
590  rangeIndices.push_back({firstIndex, SPTrackCand.getNHits() - 1}); // the last TrackStub contains all hits from the last splitIndex to the end of the SpacePointTrackCand
591 
592  // NOTE: if the first index of splitIndices is zero, this means that the direction of flight for the first SpacePoint (i.e. TrueHit) of the TrackCand was not outgoing.
593  // WARNING: This is only true as long as this behaviour is not changed in checkTrackCandForCurling(...), as there the assumption is made that the direction of flight of the first hit is outgoing, and only if it is not 0 is the first entry of the returnVector of the latter.
594  bool outgoing = splitIndices[0] != 0;
595 
596  // return NTracklets (user defined) at most, or if NTracklets is 0, return all
597  // if NTracklets is 0 set it to the appropriate size for the following for-loop
598  if (NTracklets < 1) { NTracklets = rangeIndices.size(); }
599  for (unsigned iTr = 0; iTr < rangeIndices.size() && iTr < uint(NTracklets); ++iTr) {
600 
601  int lastInd = rangeIndices[iTr].second;
602  int firstInd = rangeIndices[iTr].first;
603 
604  B2DEBUG(21, "Creating Track Stub " << iTr << " of " << splitIndices.size() <<
605  " possible Track Stub for this SpacePointTrackCand. The indices for this Tracklet are (first,last): (" << firstInd << "," << lastInd
606  << "). This SpacePointTrackCand contains " << SPTrackCand.getNHits() << " SpacePoints in total.");
607 
608  // encapsulate these functions into a try-clause since both throw
609  try {
610  const std::vector<const SpacePoint*> trackletSpacePoints = SPTrackCand.getHitsInRange(firstInd, lastInd);
611  const std::vector<double> trackletSortingParams = SPTrackCand.getSortingParametersInRange(firstInd, lastInd);
612 
613  SpacePointTrackCand newSPTrackCand = SpacePointTrackCand(trackletSpacePoints, SPTrackCand.getPdgCode(), SPTrackCand.getChargeSeed(),
614  SPTrackCand.getMcTrackID());
615  newSPTrackCand.setSortingParameters(trackletSortingParams);
616 
617  // TODO: set state seed and cov seed for all but the first tracklets (first is just the seed of the original TrackCand)
618  if (iTr < 1) {
619  newSPTrackCand.set6DSeed(SPTrackCand.getStateSeed());
620  newSPTrackCand.setCovSeed(SPTrackCand.getCovSeed());
621  }
622 
623  // set direction of flight and flip it for the next track stub (track is split where the direction of flight changes so this SHOULD not introduce any errors)
624  newSPTrackCand.setFlightDirection(outgoing);
625  outgoing = !outgoing;
626 
627  // if the TrackCandidate curls this index starts at 1, if it is a curling TrackCand
628  newSPTrackCand.setTrackStubIndex(iTr + 1);
629 
630  spacePointTCs.push_back(newSPTrackCand);
631  } catch (SpacePointTrackCand::SPTCIndexOutOfBounds& anE) {
632  B2WARNING("Caught an exception while trying to split SpacePointTrackCands: " << anE.what() <<
633  " This SPTC will be skipped from splitting!");
634  }
635  }
636 
637  return spacePointTCs;
638 }
639 
640 // ======================================================= GET ROOT VALUES =========================================================
641 template <class TrueHit>
642 void CurlingTrackCandSplitterModule::getValuesForRoot(const Belle2::SpacePoint* spacePoint, const TrueHit* trueHit,
643  RootVariables& rootVariables)
644 {
645  B2DEBUG(21, "Getting positions (for ROOT output) of SpacePoint " << spacePoint->getArrayIndex() << " from Array " <<
646  spacePoint->getArrayName() << " and TrueHit " << trueHit->getArrayIndex() << " from Array " << trueHit->getArrayName());
647 
648  // get VxdIDs of spacePoint and trueHit (and their according layer numbers for storing the information in the appropriate arrays)
649  VxdID spacePointVxdId = spacePoint->getVxdID();
650  VxdID trueHitVxdId = trueHit->getSensorID();
651 
652  // get positions from SpacePoint
653  const B2Vector3<double>& spacePointGlobal =
654  spacePoint->getPosition(); // COULDDO: uneccesary, spacePoint->X(), etc. returns the same information!
655 // std::pair<double, double> spacePointUV = getUV(spacePoint);
656  TaggedUVPos spacePointUV = getUV(spacePoint);
657  const B2Vector3<double> spacePointLocal = B2Vector3<double>(spacePointUV.m_U, spacePointUV.m_V, 0);
658 
659  // get local position from TrueHit
660  const B2Vector3<double> trueHitLocal = B2Vector3<double>(trueHit->getU(), trueHit->getV(), 0);
661 
662  // get sensor Info for global position of TrueHit
663  const VXD::GeoCache& geometry = VXD::GeoCache::getInstance();
664  const VXD::SensorInfoBase& sensorInfoBase = geometry.getSensorInfo(trueHitVxdId);
665 
666  // get global position from TrueHit
667  const B2Vector3<double> trueHitGlobal = sensorInfoBase.pointToGlobal(trueHitLocal, true);
668 
669  // Layer numbering starts at 1 not at 0 so deduce layer by one to access array
670  int spLayer = spacePointVxdId.getLayerNumber() - 1;
671  int thLayer = trueHitVxdId.getLayerNumber() - 1;
672 
673  if (spLayer != thLayer) {
674  B2FATAL("Layer numbers of TrueHit and SpacePoint do not match!"); // this should never happen -> FATAL if it does, because something has gone amiss then
675  }
676 
677  // all positions collected, but only write the values to ROOT that have been set appropriately!
678  bool singleCluster = true; // for debug output
679  if (spacePointUV.m_setU) {
680  rootVariables.SpacePointULocal.at(spLayer).push_back(spacePointUV.m_U);
681  rootVariables.TrueHitULocal.at(thLayer).push_back(trueHit->getU());
682  rootVariables.PosResidueULocal.at(spLayer).push_back((spacePointUV.m_U - trueHit->getU()));
683  }
684  if (spacePointUV.m_setV) {
685  rootVariables.SpacePointVLocal.at(spLayer).push_back(spacePointUV.m_V);
686  rootVariables.TrueHitVLocal.at(thLayer).push_back(trueHit->getV());
687  rootVariables.PosResidueVLocal.at(spLayer).push_back((spacePointUV.m_V - trueHit->getV()));
688  }
689  if (spacePointUV.m_setU && spacePointUV.m_setV) {
690  rootVariables.SpacePointXGlobal.at(spLayer).push_back(spacePoint->X());
691  rootVariables.SpacePointYGlobal.at(spLayer).push_back(spacePoint->Y());
692  rootVariables.SpacePointZGlobal.at(spLayer).push_back(spacePoint->Z());
693 
694  rootVariables.TrueHitXGlobal.at(thLayer).push_back(trueHitGlobal.X());
695  rootVariables.TrueHitYGlobal.at(thLayer).push_back(trueHitGlobal.Y());
696  rootVariables.TrueHitZGlobal.at(thLayer).push_back(trueHitGlobal.Z());
697 
698  rootVariables.PosResidueXGlobal.at(spLayer).push_back((spacePointGlobal - trueHitGlobal).X());
699  rootVariables.PosResidueYGlobal.at(spLayer).push_back((spacePointGlobal - trueHitGlobal).Y());
700  rootVariables.PosResidueZGlobal.at(spLayer).push_back((spacePointGlobal - trueHitGlobal).Z());
701 
702  rootVariables.PosResiduesGlobal.at(spLayer).push_back((spacePointGlobal - trueHitGlobal).Mag());
703  rootVariables.PosResiduesLocal.at(spLayer).push_back((spacePointLocal - trueHitLocal).Mag());
704 
705  singleCluster = false;
706  }
707 
708  B2DEBUG(21, "Global (x,y,z)/Local (U,V) positions of SpacePoint: (" << spacePointGlobal.X() << "," << spacePointGlobal.Y() << ","
709  << spacePointGlobal.Z() << ")/(" << spacePointLocal.X() << "," << spacePointLocal.Y() << "). This was a singleCluster SpacePoint: "
710  << singleCluster);
711 
712  B2DEBUG(21, "Global (x,y,z)/Local (U,V) positions of TrueHit: (" << trueHitGlobal.X() << "," << trueHitGlobal.Y() << "," <<
713  trueHitGlobal.Z() << ")/(" << trueHitLocal.X() << "," << trueHitLocal.Y() << ")");
714 
715  B2DEBUG(21, "This leads to position differences global/local: " << (spacePointGlobal - trueHitGlobal).Mag() << "/" <<
716  (spacePointLocal - trueHitLocal).Mag());
717 
718 }
719 
720 // =================================== WRITE TO ROOT ===============================================================================
722 {
725 
728 
732 
733  m_rootTrueHitULocals = rootVariables.TrueHitULocal;
734  m_rootTrueHitVLocals = rootVariables.TrueHitVLocal;
735 
736  m_rootTrueHitXGlobals = rootVariables.TrueHitXGlobal;
737  m_rootTrueHitYGlobals = rootVariables.TrueHitYGlobal;
738  m_rootTrueHitZGlobals = rootVariables.TrueHitZGlobal;
739 
745 
747  m_rootMisMatchPosX = rootVariables.MisMatchPosX;
748  m_rootMisMatchPosY = rootVariables.MisMatchPosY;
749  m_rootMisMatchPosZ = rootVariables.MisMatchPosZ;
750 
751  m_rootMisMatchPosU = rootVariables.MisMatchPosU;
752  m_rootMisMatchPosV = rootVariables.MisMatchPosV;
753 
754  m_rootMisMatchMomX = rootVariables.MisMatchMomX;
755  m_rootMisMatchMomY = rootVariables.MisMatchMomY;
756  m_rootMisMatchMomZ = rootVariables.MisMatchMomZ;
757 
758  m_treePtr->Fill();
759 }
760 
762 {
763  TaggedUVPos returnVals; // initialized to: both bools false, both doubles to 0.
764 
765  // get the normalized local coordinates from SpacePoint and convert them to local coordinates (have to do so because at the slanted parts the local U-position is dependant on the local V-position)
766  double normU = spacePoint->getNormalizedLocalU();
767  double normV = spacePoint->getNormalizedLocalV();
768 
769  // convert normalized coordinates to local coordinates (those are already 'unwedged')
770  std::pair<double, double> localUV = SpacePoint::convertNormalizedToLocalCoordinates(std::make_pair(normU, normV),
771  spacePoint->getVxdID());
772  //double unwedgedU = SpacePoint::getUUnwedged(localUV, spacePoint->getVxdID());
773 
774  // set values for return: set both m_U and m_V regardless if they have actually been set in the SpacePoint and simply assign the m_setX tags, as they decide if a value is actually used
775  std::pair<bool, bool> setCoords = spacePoint->getIfClustersAssigned();
776 
777  returnVals.m_setU = setCoords.first;
778  returnVals.m_setV = setCoords.second;
779  returnVals.m_U = localUV.first;
780  returnVals.m_V = localUV.second;
781 
782  return returnVals;
783 }
784 
785 // ====================================================== INITIALIZE COUNTERS =======================================================
787 {
789  m_curlingTCCtr = 0;
791  m_spacePointTCCtr = 0;
793  m_NoCurlingTCsCtr = 0;
794 }
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:433
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
Definition: B2Vector3.h:200
void SetXYZ(DataType x, DataType y, DataType z)
set all coordinates using data type
Definition: B2Vector3.h:464
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchPosX
Difference of X-positions (global) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchPosV
Difference of V-positions (local) for mismatched TrueHits (layerwise)
int m_NoCurlingTCsCtr
Counter for SPTCs that were not curling and hence were added to the StoreArray of first out parts.
StoreArray< SpacePointTrackCand > m_spacePointTCs
SpacePointTrackCand StoreArray.
std::string m_PARAMcurlingOutRestName
collection name of all but the first outgoing parts of a curling TrackCand
std::array< std::vector< double >, c_nPlanes > m_rootPosResidueYGlobal
Y-position (global) difference between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootSpacePointZGlobals
Global Z-Positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchPosU
Difference of U-positions (local) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchMomX
Difference of Momentum in X-Direction for TrueHits that do not match but are related from one SpacePo...
StoreArray< SpacePointTrackCand > m_curlingAllIns
Curling SpacePointTrackCand StoreArray.
StoreArray< SpacePointTrackCand > m_curlingFirstOuts
Curling SpacePointTrackCand StoreArray.
bool m_saveCompleteCurler
set to true if all parts of a curling TrackCand should be stored in a separate StoreArray (no paramet...
void initialize() override
initialize: initialize counters, register stuff in DataStore, check if all necessary StoreArrays are ...
std::array< std::vector< double >, c_nPlanes > m_rootSpacePointYGlobals
Global Y-Positions of SpacePoints (layerwise)
std::vector< double > m_PARAMsetOrigin
set the origin to a specific point.
void event() override
event: check SpacePointTrackCand for curling behaviour, split if needed (and wanted by user)
std::array< std::vector< double >, c_nPlanes > m_rootGlobalPosResiduals
Global Position Residuals between TrueHits and SpacePoints (layerwise)
int m_PARAMnTrackStubs
maximum number of TrackCand Stubs to be stored for a curling TrackCand
bool getDirectionOfFlight(std::pair< const B2Vector3< double >, const B2Vector3< double > > const &hitPosAndMom, const B2Vector3< double > &origin)
determine the direction of flight of a particle for a given hit and the origin (assumed interaction p...
std::string m_PARAMcurlingAllInName
collection name of all ingoing parts of a curling TrackCand
std::array< std::vector< double >, c_nPlanes > m_rootTrueHitXGlobals
Global U-Positions of TrueHits (layerwise)
void terminate() override
terminate: print some summary on the modules work
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchPosDistance
Distance of TrueHits that do not match but are related from one SpacePoint (layerwise)
std::string m_PARAMcompleteCurlerName
collection name of all parts of a curling TrackCand
std::string m_PARAMsptcName
collection name of the SpacePointTrackCands to be analyzed
int m_NoSingleTrueHitCtr
Counter for SpacePoints that relate to more than one TrueHit.
int m_createdTrackStubsCtr
Counter for created TrackCand Stubs by splitting a SpacePointTrackCand.
std::array< std::vector< double >, c_nPlanes > m_rootPosResidueXGlobal
X-position (global) difference between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchMomZ
Difference of Momentum in Z-Direction for TrueHits that do not match but are related from one SpacePo...
std::array< std::vector< double >, c_nPlanes > m_rootSpacePointXGlobals
Global X-Positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootSpacePointULocals
Local U-Positions of SpacePoints (layerwise)
std::vector< std::string > m_PARAMrootFileName
two entries accepted.
const std::vector< int > checkTrackCandForCurling(const Belle2::SpacePointTrackCand &, RootVariables &rootVariables)
Check if the track candidate is curling.
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchMomY
Difference of Momentum in Y-Direction for TrueHits that do not match but are related from one SpacePo...
void getValuesForRoot(const SpacePoint *spacePoint, const TrueHit *trueHit, RootVariables &rootVariables)
Get The Values that are later written to a ROOT file.
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchPosZ
Difference of Z-positions (global) for mismatched TrueHits (layerwise)
TaggedUVPos getUV(const SpacePoint *spacePoint)
get U&V for a SpacePoint (via its relation to Clusters) (SpacePoint can only return normalized U&V co...
StoreArray< SpacePointTrackCand > m_curlingCompletes
Curling SpacePointTrackCand StoreArray.
void writeToRoot(const RootVariables &rootVariables)
Write previously collected values to ROOT file.
std::pair< const B2Vector3< double >, const B2Vector3< double > > getGlobalPositionAndMomentum(TrueHit *aTrueHit)
Get the global position and momentum for a given TrueHit (PXD or SVD at the moment).
std::array< std::vector< double >, c_nPlanes > m_rootSpacePointVLocals
Local V-Positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootPosResidueZGlobal
Z-position (global) difference between TrueHit and SpacePoint (layerwise)
B2Vector3< double > m_origin
origin used internally (set from user set value)
int m_noDecisionPossibleCtr
Counter for TrackCands where a decision if curling or not is not possible.
std::array< std::vector< double >, c_nPlanes > m_rootLocalPosResiduals
Local Position Residuals between TrueHits and SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootTrueHitYGlobals
Global V-Positions of TrueHits (layerwise)
bool m_PARAMuseNonSingleTHinPA
Switch for using SpacePoints in position Analysis that are related to more than one TrueHit.
std::string m_PARAMcurlingOutFirstName
collection name of the first outgoing (i.e.
const std::vector< Belle2::SpacePointTrackCand > splitCurlingTrackCand(const Belle2::SpacePointTrackCand &SPTrackCand, int NTracklets, const std::vector< int > &splitIndices)
Split a culring track candidate into (up to NTracklets) tracklets.
std::array< std::vector< double >, c_nPlanes > m_rootTrueHitVLocals
Local Y-Positions of TrueHits (layerwise)
int m_curlingTCCtr
Counter for TrackCands that show curling behaviour.
int m_spacePointTCCtr
Counter for presented SpacePointTrackCands.
void initializeCounters()
initialize all counters to 0 for avoiding undeterministic behaviour.
std::array< std::vector< double >, c_nPlanes > m_rootMisMatchPosY
Difference of Y-positions (global) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootTrueHitULocals
Local X-Positions of TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootTrueHitZGlobals
Global Z-Positions of TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > m_rootPosResidueVLocal
V-position (local) difference between TrueHit and SpacePoint (layerwise)
bool m_PARAMpositionAnalysis
Set to true if output to ROOT file is desired with the positions and position differences of SpacePoi...
StoreArray< SpacePointTrackCand > m_curlingRestOuts
Curling SpacePointTrackCand StoreArray.
bool m_PARAMsplitCurlers
indicating if the SpacePointTrackCands should only be analyzed for curling behaviour,...
std::array< std::vector< double >, c_nPlanes > m_rootPosResidueULocal
U-position (local) differnece between TrueHit and SpacePoint (layerwise)
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
Class PXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: PXDTrueHit.h:31
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
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).
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: SVDTrueHit.h:33
Storage for (VXD) SpacePoint-based track candidates.
void setSortingParameters(const std::vector< double > &sortParams)
set the sorting parameters
void set6DSeed(const TVectorD &state6D)
set the 6D state seed
unsigned int getNHits() const
get the number of hits (space points) in the track candidate
int getPdgCode() const
get pdg code
void setCovSeed(const TMatrixDSym &cov)
set the covariance matrix seed
int getMcTrackID() const
get the MC Track ID
const std::vector< const Belle2::SpacePoint * > & getHits() const
get hits (space points) of track candidate
void setTrackStubIndex(int trackStubInd)
set TrackStub index
const TMatrixDSym & getCovSeed() const
get the covariance matrix seed (6D).
const std::vector< const Belle2::SpacePoint * > getHitsInRange(int firstInd, int lastInd) const
get hits (SpacePoints) in range (indices of SpacePoint inside SpacePointTrackCand) including first in...
const std::vector< double > getSortingParametersInRange(int firstIndex, int lastIndex) const
get the sorting parameters in range (indices of SpacePoints inside SpacePointTrackCand) including fir...
const TVectorD & getStateSeed() const
get state seed as 6D vector
double getChargeSeed() const
get charge
void setFlightDirection(bool direction)
set the direction of flight (true is outgoing, false is ingoing).
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
const B2Vector3< double > & getPosition() const
return the position vector in global coordinates
Definition: SpacePoint.h:138
double getNormalizedLocalV() const
Return normalized local coordinates of the cluster in v (0 <= posV <= 1).
Definition: SpacePoint.h:154
VxdID getVxdID() const
Return the VxdID of the sensor on which the the cluster of the SpacePoint lives.
Definition: SpacePoint.h:148
std::pair< bool, bool > getIfClustersAssigned() const
Returns, if u(v)-coordinate is based on cluster information.
Definition: SpacePoint.h:162
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
Definition: SpacePoint.h:145
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.
Definition: SpacePoint.cc:178
double Z() const
return the z-value of the global position of the SpacePoint
Definition: SpacePoint.h:129
double X() const
return the x-value of the global position of the SpacePoint
Definition: SpacePoint.h:123
double getNormalizedLocalU() const
Return normalized local coordinates of the cluster in u (0 <= posU <= 1).
Definition: SpacePoint.h:151
double Y() const
return the y-value of the global position of the SpacePoint
Definition: SpacePoint.h:126
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
Base class to provide Sensor Information for PXD and SVD.
ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a point from local to global coordinates.
ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a vector from local to global coordinates.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
Abstract base class for different kinds of events.
std::array< std::vector< double >, c_nPlanes > PosResidueVLocal
V-position (local) difference between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchMomZ
Difference of Momentum in Z-Direction for TrueHits that do not match but are related from one SpacePo...
std::array< std::vector< double >, c_nPlanes > MisMatchPosZ
Difference of Z-positions (global) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchPosU
Difference of U-positions (local) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > PosResidueZGlobal
Z-position (global) difference between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchMomX
Difference of Momentum in X-Direction for TrueHits that do not match but are related from one SpacePo...
std::array< std::vector< double >, c_nPlanes > MisMatchPosV
Difference of V-positions (local) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchPosResiduals
Distance between TrueHits that do not match but are related from one SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchPosY
Difference of Y-positions (global) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > SpacePointYGlobal
global y-positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchPosX
Difference of X-positions (global) for mismatched TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > SpacePointVLocal
local v-positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > TrueHitULocal
local u-positions of TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > SpacePointZGlobal
global z-positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > PosResidueULocal
U-position (local) differnece between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > TrueHitXGlobal
global x-positions of TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > PosResiduesGlobal
position differences in global coordinates (layerwise)
std::array< std::vector< double >, c_nPlanes > SpacePointULocal
local u-positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > TrueHitVLocal
local v-positions of TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > MisMatchMomY
Difference of Momentum in Y-Direction for TrueHits that do not match but are related from one SpacePo...
std::array< std::vector< double >, c_nPlanes > PosResidueYGlobal
Y-position (global) difference between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > SpacePointXGlobal
global x-positions of SpacePoints (layerwise)
std::array< std::vector< double >, c_nPlanes > PosResiduesLocal
position differences in local coordinates (layerwise)
std::array< std::vector< double >, c_nPlanes > PosResidueXGlobal
X-position (global) difference between TrueHit and SpacePoint (layerwise)
std::array< std::vector< double >, c_nPlanes > TrueHitZGlobal
global z-positions of TrueHits (layerwise)
std::array< std::vector< double >, c_nPlanes > TrueHitYGlobal
global y-positions of TrueHits (layerwise)
struct for easier handling of getting U- & V-position of SpacePoints and some difficulties that arise...