Belle II Software  release-08-01-10
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 header.
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 Const::doubleNaN;
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  ROOT::Math::PxPyPzEVector getCMSEnergyMCVector()
237  {
238  StoreArray<MCParticle> mcps;
239  ROOT::Math::PxPyPzEVector sum;
240  for (const auto& mcp : mcps) {
241  // only consider primary final-state particle generated by generator
242  if (mcp.isPrimaryParticle() and not(mcp.isInitial() or mcp.isVirtual())) {
243  const MCParticle* mother = mcp.getMother();
244  // only consider particles with no mother or particles whose mother is not initial or virtual
245  if (not mother or not(mother->isPrimaryParticle() and not(mother->isInitial() or mother->isVirtual())))
246  sum += mcp.get4Vector();
247  }
248  }
249  return sum;
250  }
251 
252  double getCMSEnergyMC(const Particle*)
253  {
254  StoreArray<MCParticle> mcps;
255  if (!mcps) {
256  return Const::doubleNaN;
257  } else return getCMSEnergyMCVector().M();
258  }
259 
260  double getTotalEnergyMC(const Particle*)
261  {
262  StoreArray<MCParticle> mcps;
263  if (!mcps) {
264  return Const::doubleNaN;
265  } else return getCMSEnergyMCVector().E();
266  }
267 
268  double getGenIPX(const Particle*)
269  {
270  // generated IP corresponds to the generated vertex of the
271  // first not-initial and not-virtual MCParticle
272  StoreArray<MCParticle> mcps;
273  for (const auto& mcp : mcps)
274  if (not mcp.isInitial() and not mcp.isVirtual() and mcp.isPrimaryParticle())
275  return mcp.getVertex().X();
276  return Const::doubleNaN;
277  }
278 
279  double getGenIPY(const Particle*)
280  {
281  StoreArray<MCParticle> mcps;
282  for (const auto& mcp : mcps)
283  if (not mcp.isInitial() and not mcp.isVirtual() and mcp.isPrimaryParticle())
284  return mcp.getVertex().Y();
285  return Const::doubleNaN;
286  }
287 
288  double getGenIPZ(const Particle*)
289  {
290  StoreArray<MCParticle> mcps;
291  for (const auto& mcp : mcps)
292  if (not mcp.isInitial() and not mcp.isVirtual() and mcp.isPrimaryParticle())
293  return mcp.getVertex().Z();
294  return Const::doubleNaN;
295  }
296 
297  double getIPX(const Particle*)
298  {
299  static DBObjPtr<BeamSpot> beamSpotDB;
300  return (beamSpotDB->getIPPosition()).X();
301  }
302 
303  double getIPY(const Particle*)
304  {
305  static DBObjPtr<BeamSpot> beamSpotDB;
306  return (beamSpotDB->getIPPosition()).Y();
307  }
308 
309  double getIPZ(const Particle*)
310  {
311  static DBObjPtr<BeamSpot> beamSpotDB;
312  return (beamSpotDB->getIPPosition()).Z();
313  }
314 
315  double ipCovMatrixElement(const Particle*, const std::vector<double>& element)
316  {
317  int elementI = int(std::lround(element[0]));
318  int elementJ = int(std::lround(element[1]));
319 
320  if (elementI < 0 || elementI > 3) {
321  B2WARNING("Requested IP covariance matrix element is out of boundaries [0 - 3]:" << LogVar("i", elementI));
322  return Const::doubleNaN;
323  }
324  if (elementJ < 0 || elementJ > 3) {
325  B2WARNING("Requested particle's momentumVertex covariance matrix element is out of boundaries [0 - 3]:" << LogVar("j", elementJ));
326  return Const::doubleNaN;
327  }
328 
329  static DBObjPtr<BeamSpot> beamSpotDB;
330  return beamSpotDB->getCovVertex()(elementI, elementJ);
331  }
332 
333  // Event kinematics -> missing momentum in lab and CMS, missing energy and mass2, visible energy
334  double missingMomentumOfEvent(const Particle*)
335  {
336  StoreObjPtr<EventKinematics> evtShape;
337  if (!evtShape) {
338  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
339  return Const::doubleNaN;
340  }
341  double missing = evtShape->getMissingMomentum().R();
342  return missing;
343  }
344 
345  double missingMomentumOfEvent_Px(const Particle*)
346  {
347  StoreObjPtr<EventKinematics> evtShape;
348  if (!evtShape) {
349  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
350  return Const::doubleNaN;
351  }
352  double missing = evtShape->getMissingMomentum().X();
353  return missing;
354  }
355 
356  double missingMomentumOfEvent_Py(const Particle*)
357  {
358  StoreObjPtr<EventKinematics> evtShape;
359  if (!evtShape) {
360  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
361  return Const::doubleNaN;
362  }
363  double missing = evtShape->getMissingMomentum().Y();
364  return missing;
365  }
366 
367  double missingMomentumOfEvent_Pz(const Particle*)
368  {
369  StoreObjPtr<EventKinematics> evtShape;
370  if (!evtShape) {
371  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
372  return Const::doubleNaN;
373  }
374  double missing = evtShape->getMissingMomentum().Z();
375  return missing;
376  }
377 
378  double missingMomentumOfEvent_theta(const Particle*)
379  {
380  StoreObjPtr<EventKinematics> evtShape;
381  if (!evtShape) {
382  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
383  return Const::doubleNaN;
384  }
385  double missing = evtShape->getMissingMomentum().Theta();
386  return missing;
387  }
388 
389  double missingMomentumOfEventCMS(const Particle*)
390  {
391  StoreObjPtr<EventKinematics> evtShape;
392  if (!evtShape) {
393  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
394  return Const::doubleNaN;
395  }
396  double missing = evtShape->getMissingMomentumCMS().R();
397  return missing;
398  }
399 
400  double genMissingMomentumOfEventCMS(const Particle*)
401  {
402  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
403  if (!evtShape) {
404  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
405  return Const::doubleNaN;
406  }
407  double missing = evtShape->getMissingMomentumCMS().R();
408  return missing;
409  }
410 
411  double missingMomentumOfEventCMS_Px(const Particle*)
412  {
413  StoreObjPtr<EventKinematics> evtShape;
414  if (!evtShape) {
415  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
416  return Const::doubleNaN;
417  }
418  double missing = evtShape->getMissingMomentumCMS().X();
419  return missing;
420  }
421 
422  double missingMomentumOfEventCMS_Py(const Particle*)
423  {
424  StoreObjPtr<EventKinematics> evtShape;
425  if (!evtShape) {
426  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
427  return Const::doubleNaN;
428  }
429  double missing = evtShape->getMissingMomentumCMS().Y();
430  return missing;
431  }
432 
433  double missingMomentumOfEventCMS_Pz(const Particle*)
434  {
435  StoreObjPtr<EventKinematics> evtShape;
436  if (!evtShape) {
437  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
438  return Const::doubleNaN;
439  }
440  double missing = evtShape->getMissingMomentumCMS().Z();
441  return missing;
442  }
443 
444  double missingMomentumOfEventCMS_theta(const Particle*)
445  {
446  StoreObjPtr<EventKinematics> evtShape;
447  if (!evtShape) {
448  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
449  return Const::doubleNaN;
450  }
451  double theta = evtShape->getMissingMomentumCMS().Theta();
452  return theta;
453  }
454 
455  double missingEnergyOfEventCMS(const Particle*)
456  {
457  StoreObjPtr<EventKinematics> evtShape;
458  if (!evtShape) {
459  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
460  return Const::doubleNaN;
461  }
462  double missing = evtShape->getMissingEnergyCMS();
463  return missing;
464  }
465 
466  double genMissingEnergyOfEventCMS(const Particle*)
467  {
468  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
469  if (!evtShape) {
470  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
471  return Const::doubleNaN;
472  }
473  double missing = evtShape->getMissingEnergyCMS();
474  return missing;
475  }
476 
477 
478  double missingMass2OfEvent(const Particle*)
479  {
480  StoreObjPtr<EventKinematics> evtShape;
481  if (!evtShape) {
482  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
483  return Const::doubleNaN;
484  }
485  double missing = evtShape->getMissingMass2();
486  return missing;
487  }
488 
489  double genMissingMass2OfEvent(const Particle*)
490  {
491  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
492  if (!evtShape) {
493  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
494  return Const::doubleNaN;
495  }
496  double missing = evtShape->getMissingMass2();
497  return missing;
498  }
499 
500  double visibleEnergyOfEventCMS(const Particle*)
501  {
502  StoreObjPtr<EventKinematics> evtShape;
503  if (!evtShape) {
504  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
505  return Const::doubleNaN;
506  }
507  double visible = evtShape->getVisibleEnergyCMS();
508  return visible;
509  }
510 
511  double genVisibleEnergyOfEventCMS(const Particle*)
512  {
513  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
514  if (!evtShape) {
515  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
516  return Const::doubleNaN;
517  }
518  double visible = evtShape->getVisibleEnergyCMS();
519  return visible;
520  }
521 
522 
523  double totalPhotonsEnergyOfEvent(const Particle*)
524  {
525  StoreObjPtr<EventKinematics> evtShape;
526  if (!evtShape) {
527  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule?");
528  return Const::doubleNaN;
529  }
530  double energyOfPhotons = evtShape->getTotalPhotonsEnergy();
531  return energyOfPhotons;
532  }
533 
534  double genTotalPhotonsEnergyOfEvent(const Particle*)
535  {
536  StoreObjPtr<EventKinematics> evtShape("EventKinematicsFromMC");
537  if (!evtShape) {
538  B2WARNING("Cannot find missing momentum information, did you forget to run EventKinematicsModule with usingMC parameter set to true?");
539  return Const::doubleNaN;
540  }
541  double energyOfPhotons = evtShape->getTotalPhotonsEnergy();
542  return energyOfPhotons;
543  }
544 
545  double eventYearMonthDay(const Particle*)
546  {
547  StoreObjPtr<EventMetaData> evtMetaData;
548  if (!evtMetaData) {
549  return Const::doubleNaN;
550  }
551  std::time_t rawtime = trunc(evtMetaData->getTime() / 1e9);
552  auto tt = std::gmtime(&rawtime); // GMT
553  int y = tt->tm_year + 1900; // years since 1900
554  int m = tt->tm_mon + 1; // months since January
555  int d = tt->tm_mday; // day of the month
556  return (y * 1e4) + (m * 1e2) + d;
557  }
558 
559  double eventYear(const Particle*)
560  {
561  StoreObjPtr<EventMetaData> evtMetaData;
562  if (!evtMetaData) {
563  return Const::doubleNaN;
564  }
565  std::time_t rawtime = trunc(evtMetaData->getTime() / 1e9);
566  auto tt = std::gmtime(&rawtime);
567  return tt->tm_year + 1900;
568  }
569 
570  double eventTimeSeconds(const Particle*)
571  {
572  StoreObjPtr<EventMetaData> evtMetaData;
573 
574  if (!evtMetaData) {
575  return Const::doubleNaN;
576  }
577  double evtTime = trunc(evtMetaData->getTime() / 1e9);
578 
579  return evtTime;
580  }
581 
582  double eventTimeSecondsFractionRemainder(const Particle*)
583  {
584  StoreObjPtr<EventMetaData> evtMetaData;
585 
586  if (!evtMetaData) {
587  return Const::doubleNaN;
588  }
589  double evtTime = trunc(evtMetaData->getTime() / 1e9);
590 
591  double evtTimeFrac = (evtMetaData->getTime() - evtTime * 1e9) / 1e9;
592 
593  return evtTimeFrac;
594  }
595 
596  double eventT0(const Particle*)
597  {
598  StoreObjPtr<EventT0> evtT0;
599 
600  if (!evtT0) {
601  B2WARNING("StoreObjPtr<EventT0> does not exist, are you running over cDST data?");
602  return Const::doubleNaN;
603  }
604 
605  if (evtT0->hasEventT0()) {
606  return evtT0->getEventT0();
607  } else {
608  return Const::doubleNaN;
609  }
610  }
611 
612  double timeSincePrevTriggerClockTicks(const Particle*)
613  {
614  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
615 
616  // Check if the pointer is valid
617  if (!TTDInfo.isValid()) {
618  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
619  return Const::doubleNaN;
620  }
621 
622  // And check if the stored data is valid
623  if (TTDInfo->isValid()) {
624  return TTDInfo->getTimeSincePrevTrigger();
625  } else {
626  return Const::doubleNaN;
627  }
628  }
629 
630  double timeSincePrevTriggerMicroSeconds(const Particle*)
631  {
632  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
633 
634  // Check if the pointer is valid
635  if (!TTDInfo.isValid()) {
636  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
637  return Const::doubleNaN;
638  }
639 
640  // And check if the stored data is valid
641  if (TTDInfo->isValid()) {
642  return TTDInfo->getTimeSincePrevTriggerInMicroSeconds();
643  } else {
644  return Const::doubleNaN;
645  }
646  }
647 
648  double triggeredBunchNumberTTD(const Particle*)
649  {
650  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
651 
652  // Check if the pointer is valid
653  if (!TTDInfo.isValid()) {
654  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
655  return Const::doubleNaN;
656  }
657 
658  // And check if the stored data is valid
659  if (TTDInfo->isValid()) {
660  return TTDInfo->getBunchNumber();
661  } else {
662  return Const::doubleNaN;
663  }
664  }
665 
666  double triggeredBunchNumber(const Particle*)
667  {
668  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
669 
670  // Check if the pointer is valid
671  if (!TTDInfo.isValid()) {
672  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
673  return Const::doubleNaN;
674  }
675 
676  // And check if the stored data is valid
677  if (TTDInfo->isValid()) {
678  return TTDInfo->getTriggeredBunchNumberGlobal();
679  } else {
680  return Const::doubleNaN;
681  }
682  }
683 
684  double hasRecentInjection(const Particle*)
685  {
686  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
687 
688  // Check if the pointer is valid
689  if (!TTDInfo.isValid()) {
690  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
691  return Const::doubleNaN;
692  }
693 
694  // And check if the stored data is valid
695  if (TTDInfo->isValid()) {
696  return TTDInfo->hasInjection();
697  } else {
698  return Const::doubleNaN;
699  }
700  }
701 
702  double timeSinceLastInjectionSignalClockTicks(const Particle*)
703  {
704  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
705 
706  // Check if the pointer is valid
707  if (!TTDInfo.isValid()) {
708  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
709  return Const::doubleNaN;
710  }
711 
712  // And check if the stored data is valid and if an injection happened recently
713  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
714  return TTDInfo->getTimeSinceLastInjection();
715  } else {
716  return Const::doubleNaN;
717  }
718  }
719 
720  double timeSinceLastInjectionSignalMicroSeconds(const Particle*)
721  {
722  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
723 
724  // Check if the pointer is valid
725  if (!TTDInfo.isValid()) {
726  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
727  return Const::doubleNaN;
728  }
729 
730  // And check if the stored data is valid and if an injection happened recently
731  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
732  return TTDInfo->getTimeSinceLastInjectionInMicroSeconds();
733  } else {
734  return Const::doubleNaN;
735  }
736  }
737 
738  double timeSinceLastInjectionClockTicks(const Particle*)
739  {
740  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
741 
742  // Check if the pointer is valid
743  if (!TTDInfo.isValid()) {
744  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
745  return Const::doubleNaN;
746  }
747 
748  // And check if the stored data is valid and if an injection happened recently
749  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
750  return TTDInfo->getTimeSinceInjectedBunch();
751  } else {
752  return Const::doubleNaN;
753  }
754  }
755 
756  double timeSinceLastInjectionMicroSeconds(const Particle*)
757  {
758  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
759 
760  // Check if the pointer is valid
761  if (!TTDInfo.isValid()) {
762  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
763  return Const::doubleNaN;
764  }
765 
766  // And check if the stored data is valid and if an injection happened recently
767  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
768  return TTDInfo->getTimeSinceInjectedBunchInMicroSeconds();
769  } else {
770  return Const::doubleNaN;
771  }
772  }
773 
774  double injectionInHER(const Particle*)
775  {
776  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
777 
778  // Check if the pointer is valid
779  if (!TTDInfo.isValid()) {
780  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
781  return Const::doubleNaN;
782  }
783 
784  // And check if the stored data is valid and if an injection happened recently
785  if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
786  return TTDInfo->isHER();
787  } else {
788  return Const::doubleNaN;
789  }
790  }
791 
792  double revolutionCounter2(const Particle*)
793  {
794  StoreObjPtr<EventLevelTriggerTimeInfo> TTDInfo;
795 
796  // Check if the pointer is valid
797  if (!TTDInfo.isValid()) {
798  B2WARNING("StoreObjPtr<EventLevelTriggerTimeInfo> does not exist, are you running over data reconstructed with release-05 or earlier?");
799  return Const::doubleNaN;
800  }
801 
802  // And check if the stored data is valid
803  if (TTDInfo->isValid()) {
804  return TTDInfo->isRevo2();
805  } else {
806  return Const::doubleNaN;
807  }
808  }
809 
810 
811  VARIABLE_GROUP("Event");
812 
813  REGISTER_VARIABLE("isMC", isMC,
814  "[Eventbased] Returns 1 if current basf2 process is running over simulated (Monte-Carlo) dataset and 0 in case of real experimental data.");
815  REGISTER_VARIABLE("isContinuumEvent", isContinuumEvent,
816  "[Eventbased] Returns 1.0 if event doesn't contain a :math:`\\Upsilon(4S)` particle on generator level, 0.0 otherwise.");
817  REGISTER_VARIABLE("isNotContinuumEvent", isNotContinuumEvent,
818  "[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.");
819 
820  REGISTER_VARIABLE("isChargedBEvent", isChargedBEvent,
821  "[Eventbased] Returns 1.0 if event contains a charged B-meson on generator level.");
822  REGISTER_VARIABLE("isUnmixedBEvent", isUnmixedBEvent,
823  R"DOC([Eventbased] Returns 1.0 if the event contains opposite flavor neutral B-mesons on generator level,
824 0.0 in case of same flavor B-mesons and NaN if the event has no generated neutral B.)DOC");
825 
826  REGISTER_VARIABLE("nTracks", nTracks, R"DOC(
827 [Eventbased] Returns the total number of tracks (unfiltered) in the event.
828 
829 .. warning:: This variable is exceedingly background-dependent and should not really be used in any selections (other than perhaps for monitoring purposes).
830 .. seealso:: :b2:var:`nCleanedTracks` for a more useful variable for use in selections.
831 )DOC");
832  REGISTER_VARIABLE("nChargeZeroTrackFits", nChargeZeroTrackFits, R"DOC(
833 [Eventbased] Returns number of track fits with zero charge.
834 
835 .. note::
836  Sometimes, track fits can have zero charge, if background or non IP originating tracks, for example, are fit from the IP.
837  These tracks are excluded from particle lists, but a large amount of charge zero
838  fits may indicate problems with whole event constraints
839  or abnominally high beam backgrounds and/or noisy events.
840 )DOC");
841 
842  REGISTER_VARIABLE("belleECLEnergy", belleECLEnergy, R"DOC(
843 [Eventbased][Legacy] Returns total energy in ECL in the event as used in Belle 1 analyses.
844 
845 .. warning::
846  For Belle II use cases use either ``totalEnergyOfParticlesInList(gamma:all)``,
847  or (probably better) fill a photon list with some minimal cleanup cuts and use that instead:
848 
849  .. code-block:: python
850 
851  from variables import variables as vm
852  fillParticleList("gamma:cleaned", "E > 0.05 and isFromECL==1", path=path)
853  fillParticleList("e+:cleaned", "clusterE > 0.05", path=path)
854  vm.addAlias("myNeutralECLEnergy", "totalEnergyOfParticlesInList(gamma:cleaned)")
855  vm.addAlias("myChargedECLEnergy", "totalEnergyOfParticlesInList(e+:cleaned)")
856  vm.addAlias("myECLEnergy", "formula(myNeutralECLEnergy+myChargedECLEnergy)")
857 
858 )DOC","GeV");
859  REGISTER_VARIABLE("nKLMClusters", nKLMClusters,
860  "[Eventbased] Returns number of KLM clusters in the event.");
861  REGISTER_VARIABLE("nMCParticles", nMCParticles,
862  "[Eventbased] Returns number of MCParticles in the event.");
863  REGISTER_VARIABLE("nPrimaryMCParticles", nPrimaryMCParticles,
864  "[Eventbased] Returns number of primary MCParticles in the event.");
865  REGISTER_VARIABLE("nInitialPrimaryMCParticles", nInitialPrimaryMCParticles,
866  "[Eventbased] Returns number of initial primary MCParticles in the event.");
867  REGISTER_VARIABLE("nVirtualPrimaryMCParticles", nVirtualPrimaryMCParticles,
868  "[Eventbased] Returns number of virtual primary MCParticles in the event.");
869 
870  REGISTER_VARIABLE("expNum", expNum, "[Eventbased] Returns the experiment number.");
871  REGISTER_VARIABLE("evtNum", evtNum, "[Eventbased] Returns the event number.");
872  REGISTER_VARIABLE("runNum", runNum, "[Eventbased] Returns the run number.");
873  REGISTER_VARIABLE("productionIdentifier", productionIdentifier, R"DOC(
874 [Eventbased] Production identifier.
875 Uniquely identifies an MC sample by the (grid-jargon) production ID.
876 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).
877 In such cases the event numbers are sequential *only within a production*, so experiment/run/event will restart with every new sample analysed.
878 
879 .. tip:: Experiment/run/event/production is unique for all MC samples. Experiment/run/event is unique for data.
880 
881 .. seealso:: `Where can I rely on uniqueness of the ['__experiment__', '__run__', '__event__', '__candidate__'] combination? <https://questions.belle2.org/question/9704>`__
882 )DOC");
883 
884  REGISTER_VARIABLE("Ecms", getCMSEnergy, "[Eventbased] Returns center-of-mass energy.\n\n", "GeV");
885  REGISTER_VARIABLE("beamE", getBeamE, "[Eventbased] Returns total beam energy in the laboratory frame.\n\n","GeV");
886  REGISTER_VARIABLE("beamPx", getBeamPx, "[Eventbased] Returns x component of total beam momentum in the laboratory frame.\n\n","GeV/c");
887  REGISTER_VARIABLE("beamPy", getBeamPy, "[Eventbased] Returns y component of total beam momentum in the laboratory frame.\n\n","GeV/c");
888  REGISTER_VARIABLE("beamPz", getBeamPz, "[Eventbased] Returns z component of total beam momentum in the laboratory frame.\n\n","GeV/c");
889  REGISTER_VARIABLE("EcmsMC", getCMSEnergyMC, "[Eventbased] Truth value of sqrt(s)\n\n", "GeV");
890  REGISTER_VARIABLE("totalEnergyMC", getTotalEnergyMC, "[Eventbased] Truth value of sum of energies of all the generated particles\n\n", "GeV");
891 
892  REGISTER_VARIABLE("IPX", getIPX, R"DOC(
893 [Eventbased] Returns x coordinate of the measured interaction point.
894 
895 .. note:: For old data and uncalibrated MC files this will return 0.0.
896 
897 .. note:: You might hear tracking and calibration people refer to this as the ``BeamSpot``.
898 
899 )DOC","cm");
900  REGISTER_VARIABLE("IPY", getIPY, "[Eventbased] Returns y coordinate of the measured interaction point.\n\n","cm");
901  REGISTER_VARIABLE("IPZ", getIPZ, "[Eventbased] Returns z coordinate of the measured interaction point.\n\n","cm");
902  REGISTER_VARIABLE("IPCov(i,j)", ipCovMatrixElement, "[Eventbased] Returns (i,j)-th element of the covariance matrix of the measured interaction point.\n\n",":math:`\\text{cm}^2`");
903 
904  REGISTER_VARIABLE("genIPX", getGenIPX, R"DOC(
905 [Eventbased] Returns x coordinate of the interaction point used for the underlying **MC generation**.
906 Returns NaN for data.
907 
908 .. note:: This is normally smeared from 0.0
909 
910 )DOC","cm");
911  REGISTER_VARIABLE("genIPY", getGenIPY, "[Eventbased] Returns y coordinate of the interaction point used for the underlying **MC generation**. Returns NaN for data.\n\n","cm");
912  REGISTER_VARIABLE("genIPZ", getGenIPZ, "[Eventbased] Returns z coordinate of the interaction point used for the underlying **MC generation**. Returns NaN for data.\n\n","cm");
913 
914  REGISTER_VARIABLE("date", eventYearMonthDay, R"DOC(
915 [Eventbased] Returns the date when the event was recorded, a number of the form YYYYMMDD (in UTC).
916 
917 .. seealso:: :b2:var:`year`, :b2:var:`eventTimeSeconds`, :b2:var:`eventTimeSecondsFractionRemainder`, provided for convenience.
918 )DOC");
919  REGISTER_VARIABLE("year", eventYear, R"DOC(
920 [Eventbased] Returns the year when the event was recorded (in UTC).
921 
922 .. tip::
923  For more precise event time, see :b2:var:`eventTimeSeconds` and :b2:var:`eventTimeSecondsFractionRemainder`.
924 )DOC");
925  REGISTER_VARIABLE("eventTimeSeconds", eventTimeSeconds,
926  "[Eventbased] Time of the event (truncated down) since 1970/1/1 (Unix epoch).\n\n","s");
927  REGISTER_VARIABLE("eventTimeSecondsFractionRemainder", eventTimeSecondsFractionRemainder, R"DOC(
928 [Eventbased] Remainder of the event time.
929 
930 .. tip:: Use eventTimeSeconds + eventTimeSecondsFractionRemainder to get the total event time in seconds.
931 
932 )DOC","s");
933 
934  REGISTER_VARIABLE("timeSincePrevTriggerClockTicks", timeSincePrevTriggerClockTicks,
935  "[Eventbased] Time since the previous trigger (127MHz=RF/4 clock).\n\n","clock ticks");
936 
937  REGISTER_VARIABLE("timeSincePrevTriggerMicroSeconds", timeSincePrevTriggerMicroSeconds,
938  "[Eventbased] Time since the previous trigger.\n\n",":math:`\\mathrm{\\mu s}`");
939 
940  REGISTER_VARIABLE("triggeredBunchNumberTTD", triggeredBunchNumberTTD, R"DOC(
941 [Eventbased] Number of triggered bunch ranging from 0-1279.
942 
943 .. warning:: This is the bunch number as provided by the TTD, which does not necessarily correspond to the 'global' SKB bunch number.
944 .. 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.
945 )DOC");
946 
947  REGISTER_VARIABLE("triggeredBunchNumber", triggeredBunchNumber, R"DOC(
948 [Eventbased] Number of triggered bunch ranging from 0-1279.
949 
950 .. 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
951 )DOC");
952 
953  REGISTER_VARIABLE("hasRecentInjection", hasRecentInjection,
954  "[Eventbased] Returns 1 if an injection happened recently, 0 otherwise.");
955 
956  REGISTER_VARIABLE("timeSinceLastInjectionSignalClockTicks", timeSinceLastInjectionSignalClockTicks, R"DOC(
957 [Eventbased] Time since the last injection pre-kick signal (127MHz=RF/4 clock)
958 
959 .. warning:: this returns the time without the delay until the injected bunch reaches the detector (which differs for HER/LER)
960 
961 )DOC","clock ticks");
962 
963  REGISTER_VARIABLE("timeSinceLastInjectionSignalMicroSeconds", timeSinceLastInjectionSignalMicroSeconds, R"DOC(
964 [Eventbased] Time since the last injection pre-kick signal
965 
966 .. warning:: this returns the time without the delay until the injected bunch reaches the detector (which differs for HER/LER)
967 
968 )DOC",":math:`\\mathrm{\\mu s}`");
969 
970  REGISTER_VARIABLE("timeSinceLastInjectionClockTicks", timeSinceLastInjectionClockTicks,
971  "[Eventbased] Time since the last injected bunch passed by the detector.\n\n","clock ticks")
972 
973  REGISTER_VARIABLE("timeSinceLastInjectionMicroSeconds", timeSinceLastInjectionMicroSeconds,
974  "[Eventbased] Time since the last injected bunch passed by the detector.\n\n",":math:`\\mathrm{\\mu s}`")
975 
976  REGISTER_VARIABLE("injectionInHER", injectionInHER,
977  "[Eventbased] Returns 1 if injection was in HER, 0 otherwise.");
978 
979  REGISTER_VARIABLE("revolutionCounter2", revolutionCounter2, R"DOC(
980 [Eventbased] The lowest bit of revolution counter, i.e. return 0 or 1
981 
982 .. note:: related to PXD data acquisition; PXD needs ~2 revolutions to read out one frame
983 )DOC");
984 
985  VARIABLE_GROUP("EventKinematics");
986 
987  REGISTER_VARIABLE("missingMomentumOfEvent", missingMomentumOfEvent, R"DOC(
988 [Eventbased] The magnitude of the missing momentum in laboratory frame.
989 
990 .. warning:: You have to run the Event Kinematics builder module for this variable to be meaningful.
991 .. seealso:: `modularAnalysis.buildEventKinematics`.
992 
993 )DOC","GeV/c");
994  REGISTER_VARIABLE("missingMomentumOfEvent_Px", missingMomentumOfEvent_Px, R"DOC(
995 [Eventbased] The x component of the missing momentum in laboratory frame.
996 
997 )DOC","GeV/c");
998  REGISTER_VARIABLE("missingMomentumOfEvent_Py", missingMomentumOfEvent_Py, R"DOC(
999 [Eventbased] The y component of the missing momentum in laboratory frame.
1000 
1001 )DOC","GeV/c");
1002  REGISTER_VARIABLE("missingMomentumOfEvent_Pz", missingMomentumOfEvent_Pz, R"DOC(
1003 [Eventbased] The z component of the missing momentum in laboratory frame.
1004 
1005 )DOC","GeV/c");
1006  REGISTER_VARIABLE("missingMomentumOfEvent_theta", missingMomentumOfEvent_theta, R"DOC(
1007 [Eventbased] The theta angle of the missing momentum of the event in laboratory frame.
1008 
1009 )DOC","rad");
1010  REGISTER_VARIABLE("missingMomentumOfEventCMS", missingMomentumOfEventCMS, R"DOC(
1011 [Eventbased] The magnitude of the missing momentum in center-of-mass frame.
1012 
1013 )DOC","GeV/c");
1014  REGISTER_VARIABLE("genMissingMomentumOfEventCMS", genMissingMomentumOfEventCMS, R"DOC(
1015 [Eventbased] The magnitude of the missing momentum in center-of-mass frame from generator
1016 
1017 )DOC","GeV/c");
1018  REGISTER_VARIABLE("missingMomentumOfEventCMS_Px", missingMomentumOfEventCMS_Px, R"DOC(
1019 [Eventbased] The x component of the missing momentum in center-of-mass frame.
1020 
1021 )DOC","GeV/c");
1022  REGISTER_VARIABLE("missingMomentumOfEventCMS_Py", missingMomentumOfEventCMS_Py, R"DOC(
1023 [Eventbased] The y component of the missing momentum in center-of-mass frame.
1024 
1025 )DOC","GeV/c");
1026  REGISTER_VARIABLE("missingMomentumOfEventCMS_Pz", missingMomentumOfEventCMS_Pz, R"DOC(
1027 [Eventbased] The z component of the missing momentum in center-of-mass frame.
1028 
1029 )DOC","GeV/c");
1030  REGISTER_VARIABLE("missingMomentumOfEventCMS_theta", missingMomentumOfEventCMS_theta, R"DOC(
1031 [Eventbased] The theta angle of the missing momentum in center-of-mass frame.
1032 
1033 )DOC","rad");
1034  REGISTER_VARIABLE("missingEnergyOfEventCMS", missingEnergyOfEventCMS, R"DOC(
1035 [Eventbased] The missing energy in center-of-mass frame.
1036 
1037 )DOC","GeV");
1038  REGISTER_VARIABLE("genMissingEnergyOfEventCMS", genMissingEnergyOfEventCMS, R"DOC(
1039 [Eventbased] The missing energy in center-of-mass frame from generator.
1040 
1041 )DOC","GeV");
1042  REGISTER_VARIABLE("missingMass2OfEvent", missingMass2OfEvent, R"DOC(
1043 [Eventbased] The missing mass squared.
1044 
1045 )DOC",":math:`[\\text{GeV}/\\text{c}^2]^2`");
1046  REGISTER_VARIABLE("genMissingMass2OfEvent", genMissingMass2OfEvent, R"DOC(
1047 [Eventbased] The missing mass squared from generator
1048 
1049 )DOC",":math:`[\\text{GeV}/\\text{c}^2]^2`");
1050  REGISTER_VARIABLE("visibleEnergyOfEventCMS", visibleEnergyOfEventCMS, R"DOC(
1051 [Eventbased] The visible energy in center-of-mass frame.
1052 
1053 )DOC","GeV");
1054  REGISTER_VARIABLE("genVisibleEnergyOfEventCMS", genVisibleEnergyOfEventCMS, R"DOC(
1055 [Eventbased] The visible energy in center-of-mass frame from generator.
1056 
1057 )DOC","GeV");
1058  REGISTER_VARIABLE("totalPhotonsEnergyOfEvent", totalPhotonsEnergyOfEvent, R"DOC(
1059 [Eventbased] The energy in laboratory frame of all the photons.
1060 
1061 )DOC","GeV");
1062  REGISTER_VARIABLE("genTotalPhotonsEnergyOfEvent", genTotalPhotonsEnergyOfEvent, R"DOC(
1063 [Eventbased] The energy in laboratory frame of all the photons. from generator.
1064 
1065 )DOC","GeV");
1066 
1067  VARIABLE_GROUP("Event (cDST only)");
1068  REGISTER_VARIABLE("eventT0", eventT0, R"DOC(
1069 [Eventbased][Calibration] The Event t0, is the time of the event relative to the trigger time.
1070 
1071 .. note::
1072  The event time can be measured by several sub-detectors including the SVD, CDC, ECL, and TOP.
1073  This eventT0 variable is the final combined value of all the event time measurements.
1074  Currently, only the SVD and ECL are used in this combination.
1075 
1076 )DOC","ns");
1077  }
1079 }
static const double doubleNaN
quiet_NaN
Definition: Const.h:694
@ c_nPhotons
CR is split into n photons (N1)
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:54
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.