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