Belle II Software  light-2212-foldex
EventVariables.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 // Own include
10 #include <analysis/variables/EventVariables.h>
11 
12 // include VariableManager
13 #include <analysis/VariableManager/Manager.h>
14 
15 // framework - DataStore
16 #include <framework/datastore/StoreArray.h>
17 #include <framework/datastore/StoreObjPtr.h>
18 #include <framework/dataobjects/EventMetaData.h>
19 
20 // dataobjects
21 #include <analysis/dataobjects/Particle.h>
22 #include <analysis/dataobjects/EventKinematics.h>
23 
24 #include <mdst/dataobjects/MCParticle.h>
25 #include <mdst/dataobjects/Track.h>
26 #include <mdst/dataobjects/ECLCluster.h>
27 #include <mdst/dataobjects/KLMCluster.h>
28 
29 #include <framework/dataobjects/EventT0.h>
30 #include <mdst/dataobjects/EventLevelTriggerTimeInfo.h>
31 
32 // database
33 #include <framework/database/DBObjPtr.h>
34 #include <mdst/dbobjects/BeamSpot.h>
35 
36 #include <analysis/utility/PCmsLabTransform.h>
37 
38 #include <framework/core/Environment.h>
39 #include <framework/logging/Logger.h>
40 
41 namespace Belle2 {
46  namespace Variable {
47 
48  // Event ------------------------------------------------
49  bool isMC(const Particle*)
50  {
51  return Environment::Instance().isMC();
52  }
53 
54  bool eventType(const Particle*)
55  {
56  StoreArray<MCParticle> mcparticles;
57  return (mcparticles.getEntries()) > 0 ? 0 : 1;
58  }
59 
60  bool isContinuumEvent(const Particle*)
61  {
62  return (isNotContinuumEvent(nullptr) == 1 ? 0 : 1);
63  }
64 
65  bool isChargedBEvent(const Particle*)
66  {
67  StoreArray<MCParticle> mcParticles;
68  for (const auto& mcp : mcParticles) {
69  int pdg_no = mcp.getPDG();
70  if (abs(pdg_no) == 521) return 1.0;
71  }
72  return 0.0;
73  }
74 
75  double isUnmixedBEvent(const Particle*)
76  {
77  StoreArray<MCParticle> mcParticles;
78  std::vector<int> bPDGs;
79  for (const auto& mcp : mcParticles) {
80  int pdg_no = mcp.getPDG();
81  if (abs(pdg_no) == 511) bPDGs.push_back(pdg_no);
82  }
83  if (bPDGs.size() == 2) {
84  return bPDGs[0] * bPDGs[1] < 0;
85  }
86  return std::numeric_limits<float>::quiet_NaN();
87  }
88 
89  bool isNotContinuumEvent(const Particle*)
90  {
91  StoreArray<MCParticle> mcParticles;
92  for (const MCParticle& mcp : mcParticles) {
93  int pdg_no = mcp.getPDG();
94  if (mcp.getMother() == nullptr &&
95  ((pdg_no == 553) ||
96  (pdg_no == 100553) ||
97  (pdg_no == 200553) ||
98  (pdg_no == 300553) ||
99  (pdg_no == 9000553) ||
100  (pdg_no == 9010553)))
101  return 1;
102  }
103  return 0;
104  }
105 
106  int nMCParticles(const Particle*)
107  {
108  StoreArray<MCParticle> mcps;
109  return mcps.getEntries();
110  }
111 
112  int nPrimaryMCParticles(const Particle*)
113  {
114  int n = 0;
115  StoreArray<MCParticle> mcps;
116  for (const auto& mcp : mcps)
117  if (mcp.isPrimaryParticle())
118  n++;
119  return n;
120  }
121 
122  int nInitialPrimaryMCParticles(const Particle*)
123  {
124  int n = 0;
125  StoreArray<MCParticle> mcps;
126  for (const auto& mcp : mcps)
127  if (mcp.isInitial() and mcp.isPrimaryParticle())
128  n++;
129  return n;
130  }
131 
132  int nVirtualPrimaryMCParticles(const Particle*)
133  {
134  int n = 0;
135  StoreArray<MCParticle> mcps;
136  for (const auto& mcp : mcps)
137  if (mcp.isVirtual() and mcp.isPrimaryParticle())
138  n++;
139  return n;
140  }
141 
142  int nTracks(const Particle*)
143  {
144  StoreArray<Track> tracks;
145  return tracks.getEntries();
146  }
147 
148  int nChargeZeroTrackFits(const Particle*)
149  {
150  StoreArray<TrackFitResult> tfrs;
151  int out = 0;
152  for (const auto& t : tfrs)
153  if (t.getChargeSign() == 0) out++;
154  return out;
155  }
156 
157  double belleECLEnergy(const Particle*)
158  {
159  StoreArray<ECLCluster> eclClusters;
160  double result = 0;
161  for (int i = 0; i < eclClusters.getEntries(); ++i) {
162  // sum only ECLClusters which have the N1 (n photons) hypothesis
163  if (!eclClusters[i]->hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons))
164  continue;
165 
166  result += eclClusters[i]->getEnergy(ECLCluster::EHypothesisBit::c_nPhotons);
167  }
168  return result;
169  }
170 
171  int nKLMClusters(const Particle*)
172  {
173  StoreArray<KLMCluster> klmClusters;
174  return klmClusters.getEntries();
175  }
176 
177  int expNum(const Particle*)
178  {
179  StoreObjPtr<EventMetaData> evtMetaData;
180  int exp_no = evtMetaData->getExperiment();
181  return exp_no;
182  }
183 
184  int productionIdentifier(const Particle*)
185  {
186  StoreObjPtr<EventMetaData> evtMetaData;
187  int eventProduction = evtMetaData->getProduction();
188  return eventProduction;
189  }
190 
191  int evtNum(const Particle*)
192  {
193  StoreObjPtr<EventMetaData> evtMetaData;
194  int evt_no = evtMetaData->getEvent();
195  return evt_no;
196  }
197 
198  int runNum(const Particle*)
199  {
200  StoreObjPtr<EventMetaData> evtMetaData;
201  int run_no = evtMetaData->getRun();
202  return run_no;
203  }
204 
205  // Beam Energies
206  double getCMSEnergy(const Particle*)
207  {
208  PCmsLabTransform T;
209  return T.getCMSEnergy();
210  }
211 
212  double getBeamPx(const Particle*)
213  {
214  PCmsLabTransform T;
215  return (T.getBeamFourMomentum()).Px();
216  }
217 
218  double getBeamPy(const Particle*)
219  {
220  PCmsLabTransform T;
221  return (T.getBeamFourMomentum()).Py();
222  }
223 
224  double getBeamPz(const Particle*)
225  {
226  PCmsLabTransform T;
227  return (T.getBeamFourMomentum()).Pz();
228  }
229 
230  double getBeamE(const Particle*)
231  {
232  PCmsLabTransform T;
233  return (T.getBeamFourMomentum()).E();
234  }
235 
236  double getGenIPX(const Particle*)
237  {
238  // generated IP corresponds to the generated vertex of the
239  // first not-initial and not-virtual MCParticle
240  StoreArray<MCParticle> mcps;
241  for (const auto& mcp : mcps)
242  if (not mcp.isInitial() and not mcp.isVirtual() and mcp.isPrimaryParticle())
243  return mcp.getVertex().X();
244  return std::numeric_limits<double>::quiet_NaN();
245  }
246 
247  double getGenIPY(const Particle*)
248  {
249  StoreArray<MCParticle> mcps;
250  for (const auto& mcp : mcps)
251  if (not mcp.isInitial() and not mcp.isVirtual() and mcp.isPrimaryParticle())
252  return mcp.getVertex().Y();
253  return std::numeric_limits<double>::quiet_NaN();
254  }
255 
256  double getGenIPZ(const Particle*)
257  {
258  StoreArray<MCParticle> mcps;
259  for (const auto& mcp : mcps)
260  if (not mcp.isInitial() and not mcp.isVirtual() and mcp.isPrimaryParticle())
261  return mcp.getVertex().Z();
262  return std::numeric_limits<double>::quiet_NaN();
263  }
264 
265  double getIPX(const Particle*)
266  {
267  static DBObjPtr<BeamSpot> beamSpotDB;
268  return (beamSpotDB->getIPPosition()).X();
269  }
270 
271  double getIPY(const Particle*)
272  {
273  static DBObjPtr<BeamSpot> beamSpotDB;
274  return (beamSpotDB->getIPPosition()).Y();
275  }
276 
277  double getIPZ(const Particle*)
278  {
279  static DBObjPtr<BeamSpot> beamSpotDB;
280  return (beamSpotDB->getIPPosition()).Z();
281  }
282 
283  double ipCovMatrixElement(const Particle*, const std::vector<double>& element)
284  {
285  int elementI = int(std::lround(element[0]));
286  int elementJ = int(std::lround(element[1]));
287 
288  if (elementI < 0 || elementI > 3) {
289  B2WARNING("Requested IP covariance matrix element is out of boundaries [0 - 3]:" << LogVar("i", elementI));
290  return std::numeric_limits<float>::quiet_NaN();
291  }
292  if (elementJ < 0 || elementJ > 3) {
293  B2WARNING("Requested particle's momentumVertex covariance matrix element is out of boundaries [0 - 3]:" << LogVar("j", elementJ));
294  return std::numeric_limits<float>::quiet_NaN();
295  }
296 
297  static DBObjPtr<BeamSpot> beamSpotDB;
298  return beamSpotDB->getCovVertex()(elementI, elementJ);
299  }
300 
301  // Event kinematics -> missing momentum in lab and CMS, missing energy and mass2, visible energy
302  double missingMomentumOfEvent(const Particle*)
303  {
304  StoreObjPtr<EventKinematics> evtShape;
305  if (!evtShape) {
306  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
307  return std::numeric_limits<float>::quiet_NaN();
308  }
309  double missing = evtShape->getMissingMomentum().R();
310  return missing;
311  }
312 
313  double missingMomentumOfEvent_Px(const Particle*)
314  {
315  StoreObjPtr<EventKinematics> evtShape;
316  if (!evtShape) {
317  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
318  return std::numeric_limits<float>::quiet_NaN();
319  }
320  double missing = evtShape->getMissingMomentum().X();
321  return missing;
322  }
323 
324  double missingMomentumOfEvent_Py(const Particle*)
325  {
326  StoreObjPtr<EventKinematics> evtShape;
327  if (!evtShape) {
328  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
329  return std::numeric_limits<float>::quiet_NaN();
330  }
331  double missing = evtShape->getMissingMomentum().Y();
332  return missing;
333  }
334 
335  double missingMomentumOfEvent_Pz(const Particle*)
336  {
337  StoreObjPtr<EventKinematics> evtShape;
338  if (!evtShape) {
339  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
340  return std::numeric_limits<float>::quiet_NaN();
341  }
342  double missing = evtShape->getMissingMomentum().Z();
343  return missing;
344  }
345 
346  double missingMomentumOfEvent_theta(const Particle*)
347  {
348  StoreObjPtr<EventKinematics> evtShape;
349  if (!evtShape) {
350  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
351  return std::numeric_limits<float>::quiet_NaN();
352  }
353  double missing = evtShape->getMissingMomentum().Theta();
354  return missing;
355  }
356 
357  double missingMomentumOfEventCMS(const Particle*)
358  {
359  StoreObjPtr<EventKinematics> evtShape;
360  if (!evtShape) {
361  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
362  return std::numeric_limits<float>::quiet_NaN();
363  }
364  double missing = evtShape->getMissingMomentumCMS().R();
365  return missing;
366  }
367 
368  double genMissingMomentumOfEventCMS(const Particle*)
369  {
370  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
371  if (!evtShape) {
372  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
373  return std::numeric_limits<float>::quiet_NaN();
374  }
375  double missing = evtShape->getMissingMomentumCMS().R();
376  return missing;
377  }
378 
379  double missingMomentumOfEventCMS_Px(const Particle*)
380  {
381  StoreObjPtr<EventKinematics> evtShape;
382  if (!evtShape) {
383  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
384  return std::numeric_limits<float>::quiet_NaN();
385  }
386  double missing = evtShape->getMissingMomentumCMS().X();
387  return missing;
388  }
389 
390  double missingMomentumOfEventCMS_Py(const Particle*)
391  {
392  StoreObjPtr<EventKinematics> evtShape;
393  if (!evtShape) {
394  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
395  return std::numeric_limits<float>::quiet_NaN();
396  }
397  double missing = evtShape->getMissingMomentumCMS().Y();
398  return missing;
399  }
400 
401  double missingMomentumOfEventCMS_Pz(const Particle*)
402  {
403  StoreObjPtr<EventKinematics> evtShape;
404  if (!evtShape) {
405  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
406  return std::numeric_limits<float>::quiet_NaN();
407  }
408  double missing = evtShape->getMissingMomentumCMS().Z();
409  return missing;
410  }
411 
412  double missingMomentumOfEventCMS_theta(const Particle*)
413  {
414  StoreObjPtr<EventKinematics> evtShape;
415  if (!evtShape) {
416  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
417  return std::numeric_limits<float>::quiet_NaN();
418  }
419  double theta = evtShape->getMissingMomentumCMS().Theta();
420  return theta;
421  }
422 
423  double missingEnergyOfEventCMS(const Particle*)
424  {
425  StoreObjPtr<EventKinematics> evtShape;
426  if (!evtShape) {
427  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
428  return std::numeric_limits<float>::quiet_NaN();
429  }
430  double missing = evtShape->getMissingEnergyCMS();
431  return missing;
432  }
433 
434  double genMissingEnergyOfEventCMS(const Particle*)
435  {
436  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
437  if (!evtShape) {
438  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
439  return std::numeric_limits<float>::quiet_NaN();
440  }
441  double missing = evtShape->getMissingEnergyCMS();
442  return missing;
443  }
444 
445 
446  double missingMass2OfEvent(const Particle*)
447  {
448  StoreObjPtr<EventKinematics> evtShape;
449  if (!evtShape) {
450  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
451  return std::numeric_limits<float>::quiet_NaN();
452  }
453  double missing = evtShape->getMissingMass2();
454  return missing;
455  }
456 
457  double genMissingMass2OfEvent(const Particle*)
458  {
459  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
460  if (!evtShape) {
461  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
462  return std::numeric_limits<float>::quiet_NaN();
463  }
464  double missing = evtShape->getMissingMass2();
465  return missing;
466  }
467 
468  double visibleEnergyOfEventCMS(const Particle*)
469  {
470  StoreObjPtr<EventKinematics> evtShape;
471  if (!evtShape) {
472  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
473  return std::numeric_limits<float>::quiet_NaN();
474  }
475  double visible = evtShape->getVisibleEnergyCMS();
476  return visible;
477  }
478 
479  double genVisibleEnergyOfEventCMS(const Particle*)
480  {
481  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
482  if (!evtShape) {
483  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
484  return std::numeric_limits<float>::quiet_NaN();
485  }
486  double visible = evtShape->getVisibleEnergyCMS();
487  return visible;
488  }
489 
490 
491  double totalPhotonsEnergyOfEvent(const Particle*)
492  {
493  StoreObjPtr<EventKinematics> evtShape;
494  if (!evtShape) {
495  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
496  return std::numeric_limits<float>::quiet_NaN();
497  }
498  double energyOfPhotons = evtShape->getTotalPhotonsEnergy();
499  return energyOfPhotons;
500  }
501 
502  double genTotalPhotonsEnergyOfEvent(const Particle*)
503  {
504  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
505  if (!evtShape) {
506  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
507  return std::numeric_limits<float>::quiet_NaN();
508  }
509  double energyOfPhotons = evtShape->getTotalPhotonsEnergy();
510  return energyOfPhotons;
511  }
512 
513  double eventYearMonthDay(const Particle*)
514  {
515  StoreObjPtr<EventMetaData> evtMetaData;
516  if (!evtMetaData) {
517  return std::numeric_limits<float>::quiet_NaN();
518  }
519  std::time_t rawtime = trunc(evtMetaData->getTime() / 1e9);
520  auto tt = std::gmtime(&rawtime); // GMT
521  int y = tt->tm_year + 1900; // years since 1900
522  int m = tt->tm_mon + 1; // months since January
523  int d = tt->tm_mday; // day of the month
524  return (y * 1e4) + (m * 1e2) + d;
525  }
526 
527  double eventYear(const Particle*)
528  {
529  StoreObjPtr<EventMetaData> evtMetaData;
530  if (!evtMetaData) {
531  return std::numeric_limits<float>::quiet_NaN();
532  }
533  std::time_t rawtime = trunc(evtMetaData->getTime() / 1e9);
534  auto tt = std::gmtime(&rawtime);
535  return tt->tm_year + 1900;
536  }
537 
538  double eventTimeSeconds(const Particle*)
539  {
540  StoreObjPtr<EventMetaData> evtMetaData;
541 
542  if (!evtMetaData) {
543  return std::numeric_limits<float>::quiet_NaN();
544  }
545  double evtTime = trunc(evtMetaData->getTime() / 1e9);
546 
547  return evtTime;
548  }
549 
550  double eventTimeSecondsFractionRemainder(const Particle*)
551  {
552  StoreObjPtr<EventMetaData> evtMetaData;
553 
554  if (!evtMetaData) {
555  return std::numeric_limits<float>::quiet_NaN();
556  }
557  double evtTime = trunc(evtMetaData->getTime() / 1e9);
558 
559  double evtTimeFrac = (evtMetaData->getTime() - evtTime * 1e9) / 1e9;
560 
561  return evtTimeFrac;
562  }
563 
564  double eventT0(const Particle*)
565  {
566  StoreObjPtr<EventT0> evtT0;
567 
568  if (!evtT0) {
569  B2WARNING("StoreObjPtr<EventT0> does not exist, are you running over cDST data?");
570  return std::numeric_limits<float>::quiet_NaN();
571  }
572 
573  if (evtT0->hasEventT0()) {
574  return evtT0->getEventT0();
575  } else {
576  return std::numeric_limits<float>::quiet_NaN();
577  }
578  }
579 
580  double timeSincePrevTriggerClockTicks(const Particle*)
581  {
582  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
583 
584  // Check if the pointer is valid
585  if (!TTDInfo.isValid()) {
586  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
587  return std::numeric_limits<float>::quiet_NaN();
588  }
589 
590  // And check if the stored data is valid
591  if (TTDInfo->isValid()) {
592  return TTDInfo->getTimeSincePrevTrigger();
593  } else {
594  return std::numeric_limits<float>::quiet_NaN();
595  }
596  }
597 
598  double timeSincePrevTriggerMicroSeconds(const Particle*)
599  {
600  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
601 
602  // Check if the pointer is valid
603  if (!TTDInfo.isValid()) {
604  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
605  return std::numeric_limits<float>::quiet_NaN();
606  }
607 
608  // And check if the stored data is valid
609  if (TTDInfo->isValid()) {
610  return TTDInfo->getTimeSincePrevTriggerInMicroSeconds();
611  } else {
612  return std::numeric_limits<float>::quiet_NaN();
613  }
614  }
615 
616  double triggeredBunchNumberTTD(const Particle*)
617  {
618  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
619 
620  // Check if the pointer is valid
621  if (!TTDInfo.isValid()) {
622  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
623  return std::numeric_limits<float>::quiet_NaN();
624  }
625 
626  // And check if the stored data is valid
627  if (TTDInfo->isValid()) {
628  return TTDInfo->getBunchNumber();
629  } else {
630  return std::numeric_limits<float>::quiet_NaN();
631  }
632  }
633 
634  double triggeredBunchNumber(const Particle*)
635  {
636  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
637 
638  // Check if the pointer is valid
639  if (!TTDInfo.isValid()) {
640  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
641  return std::numeric_limits<float>::quiet_NaN();
642  }
643 
644  // And check if the stored data is valid
645  if (TTDInfo->isValid()) {
646  return TTDInfo->getTriggeredBunchNumberGlobal();
647  } else {
648  return std::numeric_limits<float>::quiet_NaN();
649  }
650  }
651 
652  double hasRecentInjection(const Particle*)
653  {
654  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
655 
656  // Check if the pointer is valid
657  if (!TTDInfo.isValid()) {
658  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
659  return std::numeric_limits<float>::quiet_NaN();
660  }
661 
662  // And check if the stored data is valid
663  if (TTDInfo->isValid()) {
664  return TTDInfo->hasInjection();
665  } else {
666  return std::numeric_limits<float>::quiet_NaN();
667  }
668  }
669 
670  double timeSinceLastInjectionSignalClockTicks(const Particle*)
671  {
672  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
673 
674  // Check if the pointer is valid
675  if (!TTDInfo.isValid()) {
676  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
677  return std::numeric_limits<float>::quiet_NaN();
678  }
679 
680  // And check if the stored data is valid and if an injection happened recently
681  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
682  return TTDInfo->getTimeSinceLastInjection();
683  } else {
684  return std::numeric_limits<float>::quiet_NaN();
685  }
686  }
687 
688  double timeSinceLastInjectionSignalMicroSeconds(const Particle*)
689  {
690  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
691 
692  // Check if the pointer is valid
693  if (!TTDInfo.isValid()) {
694  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
695  return std::numeric_limits<float>::quiet_NaN();
696  }
697 
698  // And check if the stored data is valid and if an injection happened recently
699  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
700  return TTDInfo->getTimeSinceLastInjectionInMicroSeconds();
701  } else {
702  return std::numeric_limits<float>::quiet_NaN();
703  }
704  }
705 
706  double timeSinceLastInjectionClockTicks(const Particle*)
707  {
708  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
709 
710  // Check if the pointer is valid
711  if (!TTDInfo.isValid()) {
712  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
713  return std::numeric_limits<float>::quiet_NaN();
714  }
715 
716  // And check if the stored data is valid and if an injection happened recently
717  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
718  return TTDInfo->getTimeSinceInjectedBunch();
719  } else {
720  return std::numeric_limits<float>::quiet_NaN();
721  }
722  }
723 
724  double timeSinceLastInjectionMicroSeconds(const Particle*)
725  {
726  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
727 
728  // Check if the pointer is valid
729  if (!TTDInfo.isValid()) {
730  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
731  return std::numeric_limits<float>::quiet_NaN();
732  }
733 
734  // And check if the stored data is valid and if an injection happened recently
735  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
736  return TTDInfo->getTimeSinceInjectedBunchInMicroSeconds();
737  } else {
738  return std::numeric_limits<float>::quiet_NaN();
739  }
740  }
741 
742  double injectionInHER(const Particle*)
743  {
744  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
745 
746  // Check if the pointer is valid
747  if (!TTDInfo.isValid()) {
748  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
749  return std::numeric_limits<float>::quiet_NaN();
750  }
751 
752  // And check if the stored data is valid and if an injection happened recently
753  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
754  return TTDInfo->isHER();
755  } else {
756  return std::numeric_limits<float>::quiet_NaN();
757  }
758  }
759 
760  double revolutionCounter2(const Particle*)
761  {
762  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
763 
764  // Check if the pointer is valid
765  if (!TTDInfo.isValid()) {
766  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
767  return std::numeric_limits<float>::quiet_NaN();
768  }
769 
770  // And check if the stored data is valid
771  if (TTDInfo->isValid()) {
772  return TTDInfo->isRevo2();
773  } else {
774  return std::numeric_limits<float>::quiet_NaN();
775  }
776  }
777 
778 
779  VARIABLE_GROUP("Event");
780 
781  REGISTER_VARIABLE("isMC", isMC,
782  "[Eventbased] Returns 1 if current basf2 process is running over simulated (Monte-Carlo) dataset and 0 in case of real experimental data.");
783  REGISTER_VARIABLE("isContinuumEvent", isContinuumEvent,
784  "[Eventbased] Returns 1.0 if event doesn't contain a :math:`\\Upsilon(4S)` particle on generator level, 0.0 otherwise.");
785  REGISTER_VARIABLE("isNotContinuumEvent", isNotContinuumEvent,
786  "[Eventbased] Returns 1.0 if event does contain an :math:`\\Upsilon(4S)` particle on generator level and therefore is not a continuum event, 0.0 otherwise.");
787 
788  REGISTER_VARIABLE("isChargedBEvent", isChargedBEvent,
789  "[Eventbased] Returns 1.0 if event contains a charged B-meson on generator level.");
790  REGISTER_VARIABLE("isUnmixedBEvent", isUnmixedBEvent,
791  R"DOC([Eventbased] Returns 1.0 if the event contains opposite flavor neutral B-mesons on generator level,
792 0.0 in case of same flavor B-mesons and NaN if the event has no generated neutral B.)DOC");
793 
794  REGISTER_VARIABLE("nTracks", nTracks, R"DOC(
795 [Eventbased] Returns the total number of tracks (unfiltered) in the event.
796 
797 .. warning:: This variable is exceedingly background-dependent and should not really be used in any selections (other than perhaps for monitoring purposes).
798 .. seealso:: :b2:var:`nCleanedTracks` for a more useful variable for use in selections.
799 )DOC");
800  REGISTER_VARIABLE("nChargeZeroTrackFits", nChargeZeroTrackFits, R"DOC(
801 [Eventbased] Returns number of track fits with zero charge.
802 
803 .. note::
804  Sometimes, track fits can have zero charge, if background or non IP originating tracks, for example, are fit from the IP.
805  These tracks are excluded from particle lists, but a large amount of charge zero
806  fits may indicate problems with whole event constraints
807  or abnominally high beam backgrounds and/or noisy events.
808 )DOC");
809 
810  REGISTER_VARIABLE("belleECLEnergy", belleECLEnergy, R"DOC(
811 [Eventbased][Legacy] Returns total energy in ECL in the event as used in Belle 1 analyses.
812 
813 .. warning::
814 
815  For Belle II use cases use either ``totalEnergyOfParticlesInList(gamma:all)``,
816  or (probably better) fill a photon list with some minimal cleanup cuts and use that instea
817 
818  .. code-block:: python
819 
820  from variables import variables as vm
821  fillParticleList("gamma:cleaned", "E > 0.05 and isFromECL==1", path=path)
822  fillParticleList("e+:cleaned", "clusterE > 0.05", path=path)
823  vm.addAlias("myNeutralECLEnergy", "totalEnergyOfParticlesInList(gamma:cleaned)")
824  vm.addAlias("myChargedECLEnergy", "totalEnergyOfParticlesInList(e+:cleaned)")
825  vm.addAlias("myECLEnergy", "formula(myNeutralECLEnergy+myChargedECLEnergy)")
826 )DOC","GeV");
827  REGISTER_VARIABLE("nKLMClusters", nKLMClusters,
828  "[Eventbased] Returns number of KLM clusters in the event.");
829  REGISTER_VARIABLE("nMCParticles", nMCParticles,
830  "[Eventbased] Returns number of MCParticles in the event.");
831  REGISTER_VARIABLE("nPrimaryMCParticles", nPrimaryMCParticles,
832  "[Eventbased] Returns number of primary MCParticles in the event.");
833  REGISTER_VARIABLE("nInitialPrimaryMCParticles", nInitialPrimaryMCParticles,
834  "[Eventbased] Returns number of initial primary MCParticles in the event.");
835  REGISTER_VARIABLE("nVirtualPrimaryMCParticles", nVirtualPrimaryMCParticles,
836  "[Eventbased] Returns number of virtual primary MCParticles in the event.");
837 
838  REGISTER_VARIABLE("expNum", expNum, "[Eventbased] Returns the experiment number.");
839  REGISTER_VARIABLE("evtNum", evtNum, "[Eventbased] Returns the event number.");
840  REGISTER_VARIABLE("runNum", runNum, "[Eventbased] Returns the run number.");
841  REGISTER_VARIABLE("productionIdentifier", productionIdentifier, R"DOC(
842 [Eventbased] Production identifier.
843 Uniquely identifies an MC sample by the (grid-jargon) production ID.
844 This is useful when analysing large MC samples split between more than one production or combining different MC samples (e.g. combining all continuum samples).
845 In such cases the event numbers are sequential *only within a production*, so experiment/run/event will restart with every new sample analysed.
846 
847 .. tip:: Experiment/run/event/production is unique for all MC samples. Experiment/run/event is unique for data.
848 
849 .. seealso:: `Where can I rely on uniqueness of the ['__experiment__', '__run__', '__event__', '__candidate__'] combination? <https://questions.belle2.org/question/9704>`__
850 )DOC");
851 
852  REGISTER_VARIABLE("Ecms", getCMSEnergy, "[Eventbased] Returns center-of-mass energy.","GeV");
853  REGISTER_VARIABLE("beamE", getBeamE, "[Eventbased] Returns total beam energy in the laboratory frame.","GeV");
854  REGISTER_VARIABLE("beamPx", getBeamPx, "[Eventbased] Returns x component of total beam momentum in the laboratory frame.","GeV/c");
855  REGISTER_VARIABLE("beamPy", getBeamPy, "[Eventbased] Returns y component of total beam momentum in the laboratory frame.","GeV/c");
856  REGISTER_VARIABLE("beamPz", getBeamPz, "[Eventbased] Returns z component of total beam momentum in the laboratory frame.","GeV/c");
857  REGISTER_VARIABLE("IPX", getIPX, R"DOC(
858 [Eventbased] Returns x coordinate of the measured interaction point.
859 
860 .. note:: For old data and uncalibrated MC files this will return 0.0.
861 
862 .. note:: You might hear tracking and calibration people refer to this as the ``BeamSpot``.
863 )DOC","cm");
864  REGISTER_VARIABLE("IPY", getIPY, "[Eventbased] Returns y coordinate of the measured interaction point.","cm");
865  REGISTER_VARIABLE("IPZ", getIPZ, "[Eventbased] Returns z coordinate of the measured interaction point.","cm");
866  REGISTER_VARIABLE("IPCov(i,j)", ipCovMatrixElement, "[Eventbased] Returns (i,j)-th element of the covariance matrix of the measured interaction point.",":math:`\\text{cm}^2`");
867 
868  REGISTER_VARIABLE("genIPX", getGenIPX, R"DOC(
869 [Eventbased] Returns x coordinate of the interaction point used for the underlying **MC generation**.
870 Returns NaN for data.
871 
872 .. note:: This is normally smeared from 0.0
873 )DOC","cm");
874  REGISTER_VARIABLE("genIPY", getGenIPY, "[Eventbased] Returns y coordinate of the interaction point used for the underlying **MC generation**. Returns NaN for data.","cm");
875  REGISTER_VARIABLE("genIPZ", getGenIPZ, "[Eventbased] Returns z coordinate of the interaction point used for the underlying **MC generation**. Returns NaN for data.","cm");
876 
877  REGISTER_VARIABLE("date", eventYearMonthDay, R"DOC(
878 [Eventbased] Returns the date when the event was recorded, a number of the form YYYYMMDD (in UTC).
879 
880 .. seealso:: :b2:var:`year`, :b2:var:`eventTimeSeconds`, :b2:var:`eventTimeSecondsFractionRemainder`, provided for convenience.
881 )DOC");
882  REGISTER_VARIABLE("year", eventYear, R"DOC(
883 [Eventbased] Returns the year when the event was recorded (in UTC).
884 
885 .. tip::
886  For more precise event time, see :b2:var:`eventTimeSeconds` and :b2:var:`eventTimeSecondsFractionRemainder`.
887 )DOC");
888  REGISTER_VARIABLE("eventTimeSeconds", eventTimeSeconds,
889  "[Eventbased] Time of the event (truncated down) since 1970/1/1 (Unix epoch).","s");
890  REGISTER_VARIABLE("eventTimeSecondsFractionRemainder", eventTimeSecondsFractionRemainder, R"DOC(
891 [Eventbased] Remainder of the event time.
892 
893 .. tip::
894  Use eventTimeSeconds + eventTimeSecondsFractionRemainder to get the total event time in seconds.
895 )DOC","s");
896 
897  REGISTER_VARIABLE("timeSincePrevTriggerClockTicks", timeSincePrevTriggerClockTicks,
898  "[Eventbased] Time since the previous trigger (127MHz=RF/4 clock).","clock ticks");
899 
900  REGISTER_VARIABLE("timeSincePrevTriggerMicroSeconds", timeSincePrevTriggerMicroSeconds,
901  "[Eventbased] Time since the previous trigger.",":math:`\\mathrm{\\mu s}`");
902 
903  REGISTER_VARIABLE("triggeredBunchNumberTTD", triggeredBunchNumberTTD, R"DOC(
904 [Eventbased] Number of triggered bunch ranging from 0-1279.
905 
906 .. warning:: This is the bunch number as provided by the TTD, which does not necessarily correspond to the 'global' SKB bunch number.
907 .. note:: There are a maximum of 5120 buckets, which could each carry one bunch of e+/e-, but we only have 1280 clock ticks (=5120/4) to identify the bunches.
908 )DOC");
909 
910  REGISTER_VARIABLE("triggeredBunchNumber", triggeredBunchNumber, R"DOC(
911 [Eventbased] Number of triggered bunch ranging from 0-1279.
912 
913 .. note:: There are a maximum of 5120 buckets, which could each carry one bunch of e+/e-, but we only have 1280 clock ticks (=5120/4) to identify the bunches
914 )DOC");
915 
916  REGISTER_VARIABLE("hasRecentInjection", hasRecentInjection,
917  "[Eventbased] Returns 1 if an injection happened recently, 0 otherwise.");
918 
919  REGISTER_VARIABLE("timeSinceLastInjectionSignalClockTicks", timeSinceLastInjectionSignalClockTicks, R"DOC(
920 [Eventbased] Time since the last injection pre-kick signal (127MHz=RF/4 clock)
921 
922 .. warning:: this returns the time without the delay until the injected bunch reaches the detector (which differs for HER/LER)
923 )DOC","clock ticks");
924 
925  REGISTER_VARIABLE("timeSinceLastInjectionSignalMicroSeconds", timeSinceLastInjectionSignalMicroSeconds, R"DOC(
926 [Eventbased] Time since the last injection pre-kick signal
927 
928 .. warning:: this returns the time without the delay until the injected bunch reaches the detector (which differs for HER/LER)
929 )DOC",":math:`\\mathrm{\\mu s}`");
930 
931  REGISTER_VARIABLE("timeSinceLastInjectionClockTicks", timeSinceLastInjectionClockTicks,
932  "[Eventbased] Time since the last injected bunch passed by the detector.","clock ticks")
933 
934  REGISTER_VARIABLE("timeSinceLastInjectionMicroSeconds", timeSinceLastInjectionMicroSeconds,
935  "[Eventbased] Time since the last injected bunch passed by the detector.",":math:`\\mathrm{\\mu s}`")
936 
937  REGISTER_VARIABLE("injectionInHER", injectionInHER,
938  "[Eventbased] Returns 1 if injection was in HER, 0 otherwise.");
939 
940  REGISTER_VARIABLE("revolutionCounter2", revolutionCounter2, R"DOC(
941 [Eventbased] The lowest bit of revolution counter, i.e. return 0 or 1
942 
943 .. note:: related to PXD data acquisition; PXD needs ~2 revolutions to read out one frame
944 )DOC");
945 
946  VARIABLE_GROUP("EventKinematics");
947 
948  REGISTER_VARIABLE("missingMomentumOfEvent", missingMomentumOfEvent, R"DOC(
949 [Eventbased] The magnitude of the missing momentum in laboratory frame.
950 
951 .. warning:: You have to run the Event Kinematics builder module for this variable to be meaningful.
952 .. seealso:: `modularAnalysis.buildEventKinematics`.
953 )DOC","GeV/c");
954  REGISTER_VARIABLE("missingMomentumOfEvent_Px", missingMomentumOfEvent_Px, R"DOC(
955 [Eventbased] The x component of the missing momentum in laboratory frame.
956 )DOC","GeV/c");
957  REGISTER_VARIABLE("missingMomentumOfEvent_Py", missingMomentumOfEvent_Py, R"DOC(
958 [Eventbased] The y component of the missing momentum in laboratory frame.
959 )DOC","GeV/c");
960  REGISTER_VARIABLE("missingMomentumOfEvent_Pz", missingMomentumOfEvent_Pz, R"DOC(
961 [Eventbased] The z component of the missing momentum in laboratory frame.
962 )DOC","GeV/c");
963  REGISTER_VARIABLE("missingMomentumOfEvent_theta", missingMomentumOfEvent_theta, R"DOC(
964 [Eventbased] The theta angle of the missing momentum of the event in laboratory frame.
965 )DOC","rad");
966  REGISTER_VARIABLE("missingMomentumOfEventCMS", missingMomentumOfEventCMS, R"DOC(
967 [Eventbased] The magnitude of the missing momentum in center-of-mass frame.
968 )DOC","GeV/c");
969  REGISTER_VARIABLE("genMissingMomentumOfEventCMS", genMissingMomentumOfEventCMS, R"DOC(
970 [Eventbased] The magnitude of the missing momentum in center-of-mass frame from generator
971 )DOC","GeV/c");
972  REGISTER_VARIABLE("missingMomentumOfEventCMS_Px", missingMomentumOfEventCMS_Px, R"DOC(
973 [Eventbased] The x component of the missing momentum in center-of-mass frame.
974 )DOC","GeV/c");
975  REGISTER_VARIABLE("missingMomentumOfEventCMS_Py", missingMomentumOfEventCMS_Py, R"DOC(
976 [Eventbased] The y component of the missing momentum in center-of-mass frame.
977 )DOC","GeV/c");
978  REGISTER_VARIABLE("missingMomentumOfEventCMS_Pz", missingMomentumOfEventCMS_Pz, R"DOC(
979 [Eventbased] The z component of the missing momentum in center-of-mass frame.
980 )DOC","GeV/c");
981  REGISTER_VARIABLE("missingMomentumOfEventCMS_theta", missingMomentumOfEventCMS_theta, R"DOC(
982 [Eventbased] The theta angle of the missing momentum in center-of-mass frame.
983 )DOC","rad");
984  REGISTER_VARIABLE("missingEnergyOfEventCMS", missingEnergyOfEventCMS, R"DOC(
985 [Eventbased] The missing energy in center-of-mass frame.
986 )DOC","GeV");
987  REGISTER_VARIABLE("genMissingEnergyOfEventCMS", genMissingEnergyOfEventCMS, R"DOC(
988 [Eventbased] The missing energy in center-of-mass frame from generator.
989 )DOC","GeV");
990  REGISTER_VARIABLE("missingMass2OfEvent", missingMass2OfEvent, R"DOC(
991 [Eventbased] The missing mass squared.
992 )DOC",":math:`[\\text{GeV}/\\text{c}^2]^2`");
993  REGISTER_VARIABLE("genMissingMass2OfEvent", genMissingMass2OfEvent, R"DOC(
994 [Eventbased] The missing mass squared from generator
995 )DOC",":math:`[\\text{GeV}/\\text{c}^2]^2`");
996  REGISTER_VARIABLE("visibleEnergyOfEventCMS", visibleEnergyOfEventCMS, R"DOC(
997 [Eventbased] The visible energy in center-of-mass frame.
998 )DOC","GeV");
999  REGISTER_VARIABLE("genVisibleEnergyOfEventCMS", genVisibleEnergyOfEventCMS, R"DOC(
1000 [Eventbased] The visible energy in center-of-mass frame from generator.
1001 )DOC","GeV");
1002  REGISTER_VARIABLE("totalPhotonsEnergyOfEvent", totalPhotonsEnergyOfEvent, R"DOC(
1003 [Eventbased] The energy in laboratory frame of all the photons.
1004 )DOC","GeV");
1005  REGISTER_VARIABLE("genTotalPhotonsEnergyOfEvent", genTotalPhotonsEnergyOfEvent, R"DOC(
1006 [Eventbased] The energy in laboratory frame of all the photons. from generator.
1007 )DOC","GeV");
1008 
1009  VARIABLE_GROUP("Event (cDST only)");
1010  REGISTER_VARIABLE("eventT0", eventT0, R"DOC(
1011 [Eventbased][Calibration] The Event t0, is the time of the event relative to the trigger time.
1012 
1013 .. note::
1014  The event time can be measured by several sub-detectors including the SVD, CDC, ECL, and TOP.
1015  This eventT0 variable is the final combined value of all the event time measurements.
1016  Currently, only the SVD and ECL are used in this combination.
1017 )DOC","ns");
1018  }
1020 }
@ c_nPhotons
CR is split into n photons (N1)
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:55
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:23