10#include <analysis/variables/MetaVariables.h>
11#include <analysis/variables/MCTruthVariables.h>
13#include <analysis/VariableManager/Utility.h>
14#include <analysis/dataobjects/Particle.h>
15#include <analysis/dataobjects/ParticleList.h>
16#include <analysis/utility/PCmsLabTransform.h>
17#include <analysis/utility/ReferenceFrame.h>
18#include <analysis/utility/EvtPDLUtil.h>
19#include <analysis/utility/ParticleCopy.h>
20#include <analysis/utility/ValueIndexPairSorting.h>
21#include <analysis/ClusterUtility/ClusterUtils.h>
22#include <analysis/variables/VariableFormulaConstructor.h>
24#include <framework/logging/Logger.h>
25#include <framework/datastore/StoreArray.h>
26#include <framework/datastore/StoreObjPtr.h>
27#include <framework/dataobjects/EventExtraInfo.h>
28#include <framework/utilities/Conversion.h>
29#include <framework/utilities/MakeROOTCompatible.h>
30#include <framework/gearbox/Const.h>
32#include <mdst/dataobjects/Track.h>
33#include <mdst/dataobjects/MCParticle.h>
34#include <mdst/dataobjects/ECLCluster.h>
35#include <mdst/dataobjects/TrackFitResult.h>
37#include <boost/algorithm/string.hpp>
45#include <TDatabasePDG.h>
46#include <Math/Vector4D.h>
57 if (arguments.size() == 1) {
59 auto func = [var](
const Particle * particle) ->
double {
60 UseReferenceFrame<RestFrame> frame(particle);
61 double result = std::get<double>(var->function(particle));
66 B2FATAL(
"Wrong number of arguments for meta function useRestFrame");
72 if (arguments.size() == 1) {
74 auto func = [var](
const Particle * particle) ->
double {
75 UseReferenceFrame<CMSFrame> frame;
76 double result = std::get<double>(var->function(particle));
81 B2FATAL(
"Wrong number of arguments for meta function useCMSFrame");
87 if (arguments.size() == 1) {
89 auto func = [var](
const Particle * particle) ->
double {
90 UseReferenceFrame<LabFrame> frame;
91 double result = std::get<double>(var->function(particle));
96 B2FATAL(
"Wrong number of arguments for meta function useLabFrame");
102 if (arguments.size() == 2) {
105 int daughterIndexTagB = 0;
107 daughterIndexTagB = Belle2::convertString<int>(arguments[1]);
108 }
catch (std::invalid_argument&) {
109 B2FATAL(
"Second argument of useTagSideRecoilRestFrame meta function must be integer!");
112 auto func = [var, daughterIndexTagB](
const Particle * particle) ->
double {
113 if (particle->getPDGCode() != 300553)
115 B2ERROR(
"Variable should only be used on a Upsilon(4S) Particle List!");
120 ROOT::Math::PxPyPzEVector pSigB = T.getBeamFourMomentum() - particle->getDaughter(daughterIndexTagB)->get4Vector();
121 Particle tmp(pSigB, -particle->getDaughter(daughterIndexTagB)->getPDGCode());
123 UseReferenceFrame<RestFrame> frame(&tmp);
124 double result = std::get<double>(var->function(particle));
130 B2FATAL(
"Wrong number of arguments for meta function useTagSideRecoilRestFrame");
136 if (arguments.size() == 2) {
138 std::string listName = arguments[1];
139 auto func = [var, listName](
const Particle * particle) ->
double {
140 StoreObjPtr<ParticleList> list(listName);
141 unsigned listSize = list->getListSize();
145 B2WARNING(
"The selected ParticleList contains more than 1 Particles in this event. The variable useParticleRestFrame will use only the first candidate, and the result may not be the expected one."
146 <<
LogVar(
"ParticleList", listName)
147 <<
LogVar(
"Number of candidates in the list", listSize));
148 const Particle* p = list->getParticle(0);
149 UseReferenceFrame<RestFrame> frame(p);
150 double result = std::get<double>(var->function(particle));
155 B2FATAL(
"Wrong number of arguments for meta function useParticleRestFrame.");
161 if (arguments.size() == 2) {
163 std::string listName = arguments[1];
164 auto func = [var, listName](
const Particle * particle) ->
double {
165 StoreObjPtr<ParticleList> list(listName);
166 unsigned listSize = list->getListSize();
170 B2WARNING(
"The selected ParticleList contains more than 1 Particles in this event. The variable useParticleRestFrame will use only the first candidate, and the result may not be the expected one."
171 <<
LogVar(
"ParticleList", listName)
172 <<
LogVar(
"Number of candidates in the list", listSize));
173 const Particle* p = list->getParticle(0);
175 ROOT::Math::PxPyPzEVector recoil = T.getBeamFourMomentum() - p->get4Vector();
177 Particle pRecoil(recoil, 0);
178 pRecoil.setVertex(particle->getVertex());
179 UseReferenceFrame<RestFrame> frame(&pRecoil);
180 double result = std::get<double>(var->function(particle));
185 B2FATAL(
"Wrong number of arguments for meta function useParticleRestFrame.");
191 if (arguments.size() >= 2) {
193 auto func = [var, arguments](
const Particle * particle) ->
double {
196 ROOT::Math::PxPyPzEVector pSum(0, 0, 0, 0);
198 for (
unsigned int i = 1; i < arguments.size(); i++)
200 auto generalizedIndex = arguments[i];
201 const Particle* dauPart = particle->getParticleFromGeneralizedIndexString(generalizedIndex);
203 pSum += dauPart->get4Vector();
207 Particle tmp(pSum, 0);
208 UseReferenceFrame<RestFrame> frame(&tmp);
209 double result = std::get<double>(var->function(particle));
214 B2FATAL(
"Wrong number of arguments for meta function useDaughterRestFrame.");
220 if (arguments.size() == 1) {
222 auto func = [var](
const Particle * particle) ->
double {
223 int index = ancestorBIndex(particle);
225 StoreArray<MCParticle> mcparticles;
226 Particle temp(mcparticles[index]);
227 UseReferenceFrame<RestFrame> frame(&temp);
228 double result = std::get<double>(var->function(particle));
233 B2FATAL(
"Wrong number of arguments for meta function useMCancestorBRestFrame.");
239 if (arguments.size() == 1) {
240 auto extraInfoName = arguments[0];
241 auto func = [extraInfoName](
const Particle * particle) ->
double {
242 if (particle ==
nullptr)
244 B2WARNING(
"Returns NaN because the particle is nullptr! If you want EventExtraInfo variables, please use eventExtraInfo() instead");
247 if (particle->hasExtraInfo(extraInfoName))
249 return particle->getExtraInfo(extraInfoName);
257 B2FATAL(
"Wrong number of arguments for meta function extraInfo");
263 if (arguments.size() == 1) {
264 auto extraInfoName = arguments[0];
265 auto func = [extraInfoName](
const Particle*) ->
double {
266 StoreObjPtr<EventExtraInfo> eventExtraInfo;
267 if (not eventExtraInfo.isValid())
269 if (eventExtraInfo->hasExtraInfo(extraInfoName))
271 return eventExtraInfo->getExtraInfo(extraInfoName);
279 B2FATAL(
"Wrong number of arguments for meta function extraInfo");
285 if (arguments.size() == 1) {
288 auto func = [var, key](
const Particle*) ->
double {
290 StoreObjPtr<EventExtraInfo> eventExtraInfo;
291 if (not eventExtraInfo.isValid())
292 eventExtraInfo.create();
293 if (eventExtraInfo->hasExtraInfo(key))
295 return eventExtraInfo->getExtraInfo(key);
299 auto var_result = var->function(
nullptr);
300 if (std::holds_alternative<double>(var_result)) {
301 value = std::get<double>(var_result);
302 }
else if (std::holds_alternative<int>(var_result)) {
303 return std::get<int>(var_result);
304 }
else if (std::holds_alternative<bool>(var_result)) {
305 return std::get<bool>(var_result);
307 eventExtraInfo->addExtraInfo(key, value);
313 B2FATAL(
"Wrong number of arguments for meta function eventCached");
319 if (arguments.size() == 1) {
322 auto func = [var, key](
const Particle * particle) ->
double {
324 if (particle->hasExtraInfo(key))
326 return particle->getExtraInfo(key);
329 double value = std::get<double>(var->function(particle));
337 const_cast<Particle*
>(particle)->addExtraInfo(key, value);
343 B2FATAL(
"Wrong number of arguments for meta function particleCached");
352 if (arguments.size() != 1) B2FATAL(
"Wrong number of arguments for meta function formula");
353 FormulaParser<VariableFormulaConstructor> parser;
355 return parser.parse(arguments[0]);
356 }
catch (std::runtime_error& e) {
363 if (arguments.size() <= 1) {
365 std::string cutString;
366 if (arguments.size() == 1)
367 cutString = arguments[0];
369 auto func = [cut](
const Particle*) ->
int {
371 int number_of_tracks = 0;
372 StoreArray<Track> tracks;
373 for (
const auto& track : tracks)
375 const TrackFitResult* trackFit = track.getTrackFitResultWithClosestMass(
Const::pion);
376 if (!trackFit)
continue;
377 if (trackFit->getChargeSign() == 0) {
381 if (cut->check(&particle))
386 return number_of_tracks;
391 B2FATAL(
"Wrong number of arguments for meta function nCleanedTracks");
397 if (arguments.size() <= 1) {
399 std::string cutString;
400 if (arguments.size() == 1)
401 cutString = arguments[0];
403 auto func = [cut](
const Particle*) ->
int {
405 int number_of_clusters = 0;
406 StoreArray<ECLCluster> clusters;
407 for (
const auto& cluster : clusters)
413 Particle particle(&cluster);
414 if (cut->check(&particle))
415 number_of_clusters++;
418 return number_of_clusters;
423 B2FATAL(
"Wrong number of arguments for meta function nCleanedECLClusters");
429 if (arguments.size() == 1) {
430 std::string cutString = arguments[0];
432 auto func = [cut](
const Particle * particle) ->
bool {
433 if (cut->check(particle))
440 B2FATAL(
"Wrong number of arguments for meta function passesCut");
446 if (arguments.size() == 1) {
447 std::string cutString = arguments[0];
449 auto func = [cut](
const Particle*) ->
bool {
450 if (cut->check(
nullptr))
457 B2FATAL(
"Wrong number of arguments for meta function passesEventCut");
463 if (arguments.size() == 2) {
466 pdgCode = Belle2::convertString<int>(arguments[0]);
467 }
catch (std::invalid_argument&) {
468 B2FATAL(
"The first argument of varFor meta function must be a positive integer!");
471 auto func = [pdgCode, var](
const Particle * particle) ->
double {
472 if (std::abs(particle->getPDGCode()) == std::abs(pdgCode))
474 auto var_result = var->function(particle);
475 if (std::holds_alternative<double>(var_result)) {
476 return std::get<double>(var_result);
477 }
else if (std::holds_alternative<int>(var_result)) {
478 return std::get<int>(var_result);
479 }
else if (std::holds_alternative<bool>(var_result)) {
480 return std::get<bool>(var_result);
486 B2FATAL(
"Wrong number of arguments for meta function varFor");
492 if (arguments.size() == 1) {
494 auto func = [var](
const Particle * particle) ->
double {
495 if (particle->getMCParticle())
500 auto var_result = var->function(particle);
501 if (std::holds_alternative<double>(var_result)) {
502 return std::get<double>(var_result);
503 }
else if (std::holds_alternative<int>(var_result)) {
504 return std::get<int>(var_result);
505 }
else if (std::holds_alternative<bool>(var_result)) {
506 return std::get<bool>(var_result);
513 B2FATAL(
"Wrong number of arguments for meta function varForMCGen");
519 if (arguments.size() == 1) {
520 std::string listName = arguments[0];
521 auto func = [listName](
const Particle * particle) ->
int {
524 StoreObjPtr<ParticleList> listOfParticles(listName);
526 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to nParticlesInList");
528 return listOfParticles->getListSize();
533 B2FATAL(
"Wrong number of arguments for meta function nParticlesInList");
540 if (arguments.size() != 1) {
541 B2FATAL(
"Wrong number of arguments for isInList");
543 auto listName = arguments[0];
545 auto func = [listName](
const Particle * particle) ->
bool {
548 StoreObjPtr<ParticleList> list(listName);
549 if (!(list.isValid()))
551 B2FATAL(
"Invalid Listname " << listName <<
" given to isInList");
555 return list->contains(particle);
564 if (arguments.size() != 1) {
565 B2FATAL(
"Wrong number of arguments for sourceObjectIsInList");
567 auto listName = arguments[0];
569 auto func = [listName](
const Particle * particle) ->
int {
572 StoreObjPtr<ParticleList> list(listName);
573 if (!(list.isValid()))
575 B2FATAL(
"Invalid Listname " << listName <<
" given to sourceObjectIsInList");
581 if (particlesource == Particle::EParticleSourceObject::c_Composite
582 or particlesource == Particle::EParticleSourceObject::c_Undefined)
588 for (
unsigned i = 0; i < list->getListSize(); ++i)
590 Particle* iparticle = list->getParticle(i);
591 if (particle->getMdstSource() == iparticle->getMdstSource())
603 if (arguments.size() != 1) {
604 B2FATAL(
"Wrong number of arguments for mcParticleIsInMCList");
606 auto listName = arguments[0];
608 auto func = [listName](
const Particle * particle) ->
bool {
611 StoreObjPtr<ParticleList> list(listName);
612 if (!(list.isValid()))
613 B2FATAL(
"Invalid Listname " << listName <<
" given to mcParticleIsInMCList");
616 const MCParticle* mcp = particle->getMCParticle();
617 if (mcp ==
nullptr)
return false;
620 for (
unsigned i = 0; i < list->getListSize(); ++i)
622 const MCParticle* imcp = list->getParticle(i)->
getMCParticle();
623 if ((imcp !=
nullptr) and (mcp->getArrayIndex() == imcp->getArrayIndex()))
633 B2WARNING(
"isDaughterOfList is outdated and replaced by isDescendantOfList.");
634 std::vector<std::string> new_arguments = arguments;
635 new_arguments.push_back(std::string(
"1"));
636 return isDescendantOfList(new_arguments);
641 B2WARNING(
"isGrandDaughterOfList is outdated and replaced by isDescendantOfList.");
642 std::vector<std::string> new_arguments = arguments;
643 new_arguments.push_back(std::string(
"2"));
644 return isDescendantOfList(new_arguments);
649 if (arguments.size() > 0) {
650 auto listNames = arguments;
651 auto func = [listNames](
const Particle * particle) ->
bool {
653 int generation_flag = -1;
656 generation_flag = Belle2::convertString<int>(listNames.back());
657 }
catch (std::exception& e) {}
659 for (
auto& iListName : listNames)
662 Belle2::convertString<int>(iListName);
664 }
catch (std::exception& e) {}
667 auto list_comparison = [](
auto&& self,
const Particle * m,
const Particle * p,
int flag)->
bool {
669 for (
unsigned i = 0; i < m->getNDaughters(); ++i)
671 const Particle* daughter = m->getDaughter(i);
672 if ((flag == 1.) or (flag < 0)) {
673 if (p->isCopyOf(daughter)) {
679 if (daughter->getNDaughters() > 0) {
680 result = self(self, daughter, p, flag - 1);
690 StoreObjPtr<ParticleList> listOfParticles(iListName);
692 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << iListName <<
" given to isDescendantOfList");
694 for (
unsigned i = 0; i < listOfParticles->getListSize(); ++i) {
695 Particle* iParticle = listOfParticles->getParticle(i);
696 output = list_comparison(list_comparison, iParticle, particle, generation_flag);
706 B2FATAL(
"Wrong number of arguments for meta function isDescendantOfList");
712 if (arguments.size() > 0) {
713 auto listNames = arguments;
714 auto func = [listNames](
const Particle * particle) ->
bool {
716 int generation_flag = -1;
719 generation_flag = Belle2::convertString<int>(listNames.back());
720 }
catch (std::exception& e) {}
722 if (particle->getMCParticle() ==
nullptr)
727 for (
auto& iListName : listNames)
730 std::stod(iListName);
732 }
catch (std::exception& e) {}
734 auto list_comparison = [](
auto&& self,
const Particle * m,
const Particle * p,
int flag)->
bool {
736 for (
unsigned i = 0; i < m->getNDaughters(); ++i)
738 const Particle* daughter = m->getDaughter(i);
739 if ((flag == 1.) or (flag < 0)) {
740 if (daughter->getMCParticle() !=
nullptr) {
741 if (p->getMCParticle()->getArrayIndex() == daughter->getMCParticle()->getArrayIndex()) {
747 if (daughter->getNDaughters() > 0) {
748 result = self(self, daughter, p, flag - 1);
758 StoreObjPtr<ParticleList> listOfParticles(iListName);
760 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << iListName <<
" given to isMCDescendantOfList");
762 for (
unsigned i = 0; i < listOfParticles->getListSize(); ++i) {
763 Particle* iParticle = listOfParticles->getParticle(i);
764 output = list_comparison(list_comparison, iParticle, particle, generation_flag);
774 B2FATAL(
"Wrong number of arguments for meta function isMCDescendantOfList");
780 if (arguments.size() == 1) {
782 auto func = [var](
const Particle * particle) ->
double {
783 double product = 1.0;
784 if (particle->getNDaughters() == 0)
788 if (std::holds_alternative<double>(var->function(particle->getDaughter(0))))
790 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
791 product *= std::get<double>(var->function(particle->getDaughter(j)));
793 }
else if (std::holds_alternative<int>(var->function(particle->getDaughter(0))))
795 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
796 product *= std::get<int>(var->function(particle->getDaughter(j)));
803 B2FATAL(
"Wrong number of arguments for meta function daughterProductOf");
809 if (arguments.size() == 1) {
811 auto func = [var](
const Particle * particle) ->
double {
813 if (particle->getNDaughters() == 0)
817 if (std::holds_alternative<double>(var->function(particle->getDaughter(0))))
819 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
820 sum += std::get<double>(var->function(particle->getDaughter(j)));
822 }
else if (std::holds_alternative<int>(var->function(particle->getDaughter(0))))
824 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
825 sum += std::get<int>(var->function(particle->getDaughter(j)));
832 B2FATAL(
"Wrong number of arguments for meta function daughterSumOf");
838 if (arguments.size() == 1) {
840 auto func = [var](
const Particle * particle) ->
double {
842 if (particle->getNDaughters() == 0)
846 if (std::holds_alternative<double>(var->function(particle->getDaughter(0))))
848 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
849 double iValue = std::get<double>(var->function(particle->getDaughter(j)));
850 if (std::isnan(iValue))
continue;
851 if (std::isnan(min)) min = iValue;
852 if (iValue < min) min = iValue;
854 }
else if (std::holds_alternative<int>(var->function(particle->getDaughter(0))))
856 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
857 int iValue = std::get<int>(var->function(particle->getDaughter(j)));
858 if (std::isnan(min)) min = iValue;
859 if (iValue < min) min = iValue;
866 B2FATAL(
"Wrong number of arguments for meta function daughterLowest");
872 if (arguments.size() == 1) {
874 auto func = [var](
const Particle * particle) ->
double {
876 if (particle->getNDaughters() == 0)
880 if (std::holds_alternative<double>(var->function(particle->getDaughter(0))))
882 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
883 double iValue = std::get<double>(var->function(particle->getDaughter(j)));
884 if (std::isnan(iValue))
continue;
885 if (std::isnan(max)) max = iValue;
886 if (iValue > max) max = iValue;
888 }
else if (std::holds_alternative<int>(var->function(particle->getDaughter(0))))
890 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
891 int iValue = std::get<int>(var->function(particle->getDaughter(j)));
892 if (std::isnan(max)) max = iValue;
893 if (iValue > max) max = iValue;
900 B2FATAL(
"Wrong number of arguments for meta function daughterHighest");
906 if (arguments.size() == 3) {
907 auto func = [arguments](
const Particle * particle) ->
double {
908 if (particle ==
nullptr)
910 const Particle* dau_i = particle->getParticleFromGeneralizedIndexString(arguments[0]);
911 const Particle* dau_j = particle->getParticleFromGeneralizedIndexString(arguments[1]);
912 auto variablename = arguments[2];
913 if (dau_i ==
nullptr || dau_j ==
nullptr)
915 B2ERROR(
"One of the first two arguments doesn't specify a valid (grand-)daughter!");
919 auto result_j = var->function(dau_j);
920 auto result_i = var->function(dau_i);
922 if (std::holds_alternative<double>(result_j) && std::holds_alternative<double>(result_i))
924 diff = std::get<double>(result_j) - std::get<double>(result_i);
925 }
else if (std::holds_alternative<int>(result_j) && std::holds_alternative<int>(result_i))
927 diff = std::get<int>(result_j) - std::get<int>(result_i);
930 throw std::runtime_error(
"Bad variant access");
932 if (variablename ==
"phi" or variablename ==
"clusterPhi" or std::regex_match(variablename, std::regex(
"use.*Frame\\(phi\\)"))
933 or std::regex_match(variablename, std::regex(
"use.*Frame\\(clusterPhi\\)")))
935 if (fabs(diff) > M_PI) {
937 diff = diff - 2 * M_PI;
939 diff = 2 * M_PI + diff;
947 B2FATAL(
"Wrong number of arguments for meta function daughterDiffOf");
953 if (arguments.size() == 3) {
954 auto func = [arguments](
const Particle * particle) ->
double {
955 if (particle ==
nullptr)
957 const Particle* dau_i = particle->getParticleFromGeneralizedIndexString(arguments[0]);
958 const Particle* dau_j = particle->getParticleFromGeneralizedIndexString(arguments[1]);
959 auto variablename = arguments[2];
960 if (dau_i ==
nullptr || dau_j ==
nullptr)
962 B2ERROR(
"One of the first two arguments doesn't specify a valid (grand-)daughter!");
967 if (iMcDaughter ==
nullptr || jMcDaughter ==
nullptr)
969 Particle iTmpPart(iMcDaughter);
970 Particle jTmpPart(jMcDaughter);
972 auto result_j = var->function(&jTmpPart);
973 auto result_i = var->function(&iTmpPart);
975 if (std::holds_alternative<double>(result_j) && std::holds_alternative<double>(result_i))
977 diff = std::get<double>(result_j) - std::get<double>(result_i);
978 }
else if (std::holds_alternative<int>(result_j) && std::holds_alternative<int>(result_i))
980 diff = std::get<int>(result_j) - std::get<int>(result_i);
983 throw std::runtime_error(
"Bad variant access");
985 if (variablename ==
"phi" or std::regex_match(variablename, std::regex(
"use.*Frame\\(phi\\)")))
987 if (fabs(diff) > M_PI) {
989 diff = diff - 2 * M_PI;
991 diff = 2 * M_PI + diff;
999 B2FATAL(
"Wrong number of arguments for meta function mcDaughterDiffOf");
1005 if (arguments.size() == 5) {
1007 Belle2::convertString<int>(arguments[0]);
1008 Belle2::convertString<int>(arguments[1]);
1009 Belle2::convertString<int>(arguments[2]);
1010 Belle2::convertString<int>(arguments[3]);
1011 }
catch (std::invalid_argument&) {
1012 B2FATAL(
"First four arguments of grandDaughterDiffOf meta function must be integers!");
1014 std::vector<std::string> new_arguments;
1015 new_arguments.push_back(std::string(arguments[0] +
":" + arguments[2]));
1016 new_arguments.push_back(std::string(arguments[1] +
":" + arguments[3]));
1017 new_arguments.push_back(arguments[4]);
1018 return daughterDiffOf(new_arguments);
1020 B2FATAL(
"Wrong number of arguments for meta function grandDaughterDiffOf");
1026 std::vector<std::string> new_arguments = arguments;
1027 new_arguments.push_back(std::string(
"phi"));
1028 return daughterDiffOf(new_arguments);
1033 std::vector<std::string> new_arguments = arguments;
1034 new_arguments.push_back(std::string(
"phi"));
1035 return mcDaughterDiffOf(new_arguments);
1040 std::vector<std::string> new_arguments = arguments;
1041 new_arguments.push_back(std::string(
"phi"));
1042 return grandDaughterDiffOf(new_arguments);
1047 std::vector<std::string> new_arguments = arguments;
1048 new_arguments.push_back(std::string(
"clusterPhi"));
1049 return daughterDiffOf(new_arguments);
1054 std::vector<std::string> new_arguments = arguments;
1055 new_arguments.push_back(std::string(
"clusterPhi"));
1056 return grandDaughterDiffOf(new_arguments);
1061 std::vector<std::string> new_arguments = arguments;
1062 new_arguments.push_back(std::string(
"useCMSFrame(phi)"));
1063 return daughterDiffOf(new_arguments);
1068 std::vector<std::string> new_arguments = arguments;
1069 new_arguments.push_back(std::string(
"useCMSFrame(phi)"));
1070 return mcDaughterDiffOf(new_arguments);
1075 std::vector<std::string> new_arguments = arguments;
1076 new_arguments.push_back(std::string(
"useCMSFrame(clusterPhi)"));
1077 return daughterDiffOf(new_arguments);
1082 if (arguments.size() == 3) {
1083 auto func = [arguments](
const Particle * particle) ->
double {
1084 if (particle ==
nullptr)
1086 const Particle* dau_i = particle->getParticleFromGeneralizedIndexString(arguments[0]);
1087 const Particle* dau_j = particle->getParticleFromGeneralizedIndexString(arguments[1]);
1088 if (!(dau_i && dau_j))
1090 B2ERROR(
"One of the first two arguments doesn't specify a valid (grand-)daughter!");
1094 double iValue, jValue;
1095 if (std::holds_alternative<double>(var->function(dau_j)))
1097 iValue = std::get<double>(var->function(dau_i));
1098 jValue = std::get<double>(var->function(dau_j));
1099 }
else if (std::holds_alternative<int>(var->function(dau_j)))
1101 iValue = std::get<int>(var->function(dau_i));
1102 jValue = std::get<int>(var->function(dau_j));
1104 return (jValue - iValue) / (jValue + iValue);
1108 B2FATAL(
"Wrong number of arguments for meta function daughterNormDiffOf");
1114 if (arguments.size() == 2) {
1115 int daughterNumber = 0;
1117 daughterNumber = Belle2::convertString<int>(arguments[0]);
1118 }
catch (std::invalid_argument&) {
1119 B2FATAL(
"First argument of daughterMotherDiffOf meta function must be integer!");
1121 auto variablename = arguments[1];
1122 auto func = [variablename, daughterNumber](
const Particle * particle) ->
double {
1123 if (particle ==
nullptr)
1125 if (daughterNumber >=
int(particle->getNDaughters()))
1130 auto result_mother = var->function(particle);
1131 auto result_daughter = var->function(particle->getDaughter(daughterNumber));
1133 if (std::holds_alternative<double>(result_mother) && std::holds_alternative<double>(result_daughter)) {
1134 diff = std::get<double>(result_mother) - std::get<double>(result_daughter);
1135 }
else if (std::holds_alternative<int>(result_mother) && std::holds_alternative<int>(result_daughter)) {
1136 diff = std::get<int>(result_mother) - std::get<int>(result_daughter);
1138 throw std::runtime_error(
"Bad variant access");
1141 if (variablename ==
"phi" or variablename ==
"useCMSFrame(phi)") {
1142 if (fabs(diff) > M_PI) {
1144 diff = diff - 2 * M_PI;
1146 diff = 2 * M_PI + diff;
1155 B2FATAL(
"Wrong number of arguments for meta function daughterMotherDiffOf");
1161 if (arguments.size() == 2) {
1162 int daughterNumber = 0;
1164 daughterNumber = Belle2::convertString<int>(arguments[0]);
1165 }
catch (std::invalid_argument&) {
1166 B2FATAL(
"First argument of daughterMotherDiffOf meta function must be integer!");
1169 auto func = [var, daughterNumber](
const Particle * particle) ->
double {
1170 if (particle ==
nullptr)
1172 if (daughterNumber >=
int(particle->getNDaughters()))
1176 double daughterValue = 0.0, motherValue = 0.0;
1177 if (std::holds_alternative<double>(var->function(particle))) {
1178 daughterValue = std::get<double>(var->function(particle->getDaughter(daughterNumber)));
1179 motherValue = std::get<double>(var->function(particle));
1180 }
else if (std::holds_alternative<int>(var->function(particle))) {
1181 daughterValue = std::get<int>(var->function(particle->getDaughter(daughterNumber)));
1182 motherValue = std::get<int>(var->function(particle));
1184 return (motherValue - daughterValue) / (motherValue + daughterValue);
1189 B2FATAL(
"Wrong number of arguments for meta function daughterMotherNormDiffOf");
1195 if (arguments.size() == 2 || arguments.size() == 3) {
1197 auto func = [arguments](
const Particle * particle) ->
double {
1198 if (particle ==
nullptr)
1201 std::vector<ROOT::Math::PxPyPzEVector> pDaus;
1205 for (
auto& generalizedIndex : arguments)
1207 const Particle* dauPart = particle->getParticleFromGeneralizedIndexString(generalizedIndex);
1209 pDaus.push_back(frame.getMomentum(dauPart));
1211 B2WARNING(
"Trying to access a daughter that does not exist. Index = " << generalizedIndex);
1217 if (pDaus.size() == 2)
1224 B2FATAL(
"Wrong number of arguments for meta function daughterAngle");
1228 double grandDaughterDecayAngle(
const Particle* particle,
const std::vector<double>& arguments)
1230 if (arguments.size() == 2) {
1235 int daughterIndex = std::lround(arguments[0]);
1236 if (daughterIndex >=
int(particle->getNDaughters()))
1238 const Particle* dau = particle->getDaughter(daughterIndex);
1240 int grandDaughterIndex = std::lround(arguments[1]);
1241 if (grandDaughterIndex >=
int(dau->getNDaughters()))
1244 B2Vector3D boost = dau->get4Vector().BoostToCM();
1246 ROOT::Math::PxPyPzEVector motherMomentum = - particle->get4Vector();
1247 motherMomentum = ROOT::Math::Boost(boost) * motherMomentum;
1249 ROOT::Math::PxPyPzEVector grandDaughterMomentum = dau->getDaughter(grandDaughterIndex)->get4Vector();
1250 grandDaughterMomentum = ROOT::Math::Boost(boost) * grandDaughterMomentum;
1255 B2FATAL(
"The variable grandDaughterDecayAngle needs exactly two integers as arguments!");
1261 if (arguments.size() == 2 || arguments.size() == 3) {
1263 auto func = [arguments](
const Particle * particle) ->
double {
1264 if (particle ==
nullptr)
1267 std::vector<ROOT::Math::PxPyPzEVector> pDaus;
1271 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_MCParticle)
1273 for (
auto& generalizedIndex : arguments) {
1274 const MCParticle* mcPart = particle->getMCParticle();
1275 if (mcPart ==
nullptr)
1278 if (dauMcPart ==
nullptr)
1281 pDaus.push_back(frame.getMomentum(dauMcPart->get4Vector()));
1285 for (
auto& generalizedIndex : arguments) {
1286 const Particle* dauPart = particle->getParticleFromGeneralizedIndexString(generalizedIndex);
1287 if (dauPart ==
nullptr)
1291 if (dauMcPart ==
nullptr)
1294 pDaus.push_back(frame.getMomentum(dauMcPart->get4Vector()));
1299 if (pDaus.size() == 2)
1306 B2FATAL(
"Wrong number of arguments for meta function mcDaughterAngle");
1310 double daughterClusterAngleInBetween(
const Particle* particle,
const std::vector<double>& daughterIndices)
1312 if (daughterIndices.size() == 2) {
1313 int daughterIndexi = std::lround(daughterIndices[0]);
1314 int daughterIndexj = std::lround(daughterIndices[1]);
1315 if (std::max(daughterIndexi, daughterIndexj) >=
int(particle->getNDaughters())) {
1318 const ECLCluster* clusteri = particle->getDaughter(daughterIndexi)->getECLCluster();
1319 const ECLCluster* clusterj = particle->getDaughter(daughterIndexj)->getECLCluster();
1320 if (clusteri and clusterj) {
1324 ClusterUtils clusutils;
1325 B2Vector3D pi = frame.getMomentum(clusutils.Get4MomentumFromCluster(clusteri, clusteriBit)).Vect();
1326 B2Vector3D pj = frame.getMomentum(clusutils.Get4MomentumFromCluster(clusterj, clusterjBit)).Vect();
1327 return pi.Angle(pj);
1331 }
else if (daughterIndices.size() == 3) {
1332 int daughterIndexi = std::lround(daughterIndices[0]);
1333 int daughterIndexj = std::lround(daughterIndices[1]);
1334 int daughterIndexk = std::lround(daughterIndices[2]);
1335 if (std::max(std::max(daughterIndexi, daughterIndexj), daughterIndexk) >=
int(particle->getNDaughters())) {
1338 const ECLCluster* clusteri = (particle->getDaughter(daughterIndices[0]))->getECLCluster();
1339 const ECLCluster* clusterj = (particle->getDaughter(daughterIndices[1]))->getECLCluster();
1340 const ECLCluster* clusterk = (particle->getDaughter(daughterIndices[2]))->getECLCluster();
1341 if (clusteri and clusterj and clusterk) {
1346 ClusterUtils clusutils;
1347 B2Vector3D pi = frame.getMomentum(clusutils.Get4MomentumFromCluster(clusteri, clusteriBit)).Vect();
1348 B2Vector3D pj = frame.getMomentum(clusutils.Get4MomentumFromCluster(clusterj, clusterjBit)).Vect();
1349 B2Vector3D pk = frame.getMomentum(clusutils.Get4MomentumFromCluster(clusterk, clusterkBit)).Vect();
1350 return pk.
Angle(pi + pj);
1355 B2FATAL(
"Wrong number of arguments for daughterClusterAngleInBetween!");
1361 if (arguments.size() > 1) {
1362 auto func = [arguments](
const Particle * particle) ->
double {
1364 ROOT::Math::PxPyPzEVector pSum;
1366 for (
auto& generalizedIndex : arguments)
1368 const Particle* dauPart = particle->getParticleFromGeneralizedIndexString(generalizedIndex);
1370 pSum += frame.getMomentum(dauPart);
1379 B2FATAL(
"Wrong number of arguments for meta function daughterInvM. At least two integers are needed.");
1385 if (arguments.size() == 2) {
1389 divideBy = Belle2::convertString<int>(arguments[1]);
1390 }
catch (std::invalid_argument&) {
1391 B2FATAL(
"Second argument of modulo meta function must be integer!");
1393 auto func = [var, divideBy](
const Particle * particle) ->
int {
1394 auto var_result = var->function(particle);
1395 if (std::holds_alternative<double>(var_result))
1397 return int(std::get<double>(var_result)) % divideBy;
1398 }
else if (std::holds_alternative<int>(var_result))
1400 return std::get<int>(var_result) % divideBy;
1401 }
else if (std::holds_alternative<bool>(var_result))
1403 return int(std::get<bool>(var_result)) % divideBy;
1408 B2FATAL(
"Wrong number of arguments for meta function modulo");
1414 if (arguments.size() == 1) {
1417 auto func = [var](
const Particle * particle) ->
bool {
return std::isnan(std::get<double>(var->function(particle))); };
1420 B2FATAL(
"Wrong number of arguments for meta function isNAN");
1426 if (arguments.size() == 2) {
1428 double defaultOutput;
1430 defaultOutput = Belle2::convertString<double>(arguments[1]);
1431 }
catch (std::invalid_argument&) {
1432 B2FATAL(
"The second argument of ifNANgiveX meta function must be a number!");
1434 auto func = [var, defaultOutput](
const Particle * particle) ->
double {
1435 double output = std::get<double>(var->function(particle));
1436 if (std::isnan(output))
return defaultOutput;
1441 B2FATAL(
"Wrong number of arguments for meta function ifNANgiveX");
1447 if (arguments.size() == 1) {
1450 auto func = [var](
const Particle * particle) ->
bool {
return std::isinf(std::get<double>(var->function(particle))); };
1453 B2FATAL(
"Wrong number of arguments for meta function isInfinity");
1459 if (arguments.size() >= 2) {
1465 for (
size_t i = 1; i < arguments.size(); ++i) {
1467 finalMask |= Belle2::convertString<int>(arguments[i]);
1468 }
catch (std::invalid_argument&) {
1469 B2FATAL(
"The input flags to meta function unmask() should be integer!");
1475 auto func = [var, finalMask](
const Particle * particle) ->
double {
1477 auto var_result = var->function(particle);
1478 if (std::holds_alternative<double>(var_result))
1481 if (std::isnan(std::get<double>(var_result))) {
1484 value = int(std::get<double>(var_result));
1485 }
else if (std::holds_alternative<int>(var_result))
1487 value = std::get<int>(var_result);
1491 value &= (~finalMask);
1498 B2FATAL(
"Meta function unmask needs at least two arguments!");
1504 if (arguments.size() == 3) {
1506 std::string cutString = arguments[0];
1512 auto func = [cut, variableIfTrue, variableIfFalse](
const Particle * particle) ->
double {
1513 if (particle ==
nullptr)
1515 if (cut->check(particle))
1517 auto var_result = variableIfTrue->function(particle);
1518 if (std::holds_alternative<double>(var_result)) {
1519 return std::get<double>(var_result);
1520 }
else if (std::holds_alternative<int>(var_result)) {
1521 return std::get<int>(var_result);
1522 }
else if (std::holds_alternative<bool>(var_result)) {
1523 return std::get<bool>(var_result);
1527 auto var_result = variableIfFalse->function(particle);
1528 if (std::holds_alternative<double>(var_result)) {
1529 return std::get<double>(var_result);
1530 }
else if (std::holds_alternative<int>(var_result)) {
1531 return std::get<int>(var_result);
1532 }
else if (std::holds_alternative<bool>(var_result)) {
1533 return std::get<bool>(var_result);
1540 B2FATAL(
"Wrong number of arguments for meta function conditionalVariableSelector");
1546 if (arguments.size() > 0) {
1547 std::vector<const Variable::Manager::Var*> variables;
1548 for (
auto& argument : arguments)
1551 auto func = [variables, arguments](
const Particle * particle) ->
double {
1552 double pValueProduct = 1.;
1553 for (
auto variable : variables)
1555 double pValue = std::get<double>(variable->function(particle));
1559 pValueProduct *= pValue;
1561 double pValueSum = 1.;
1562 double factorial = 1.;
1563 for (
unsigned int i = 1; i < arguments.size(); ++i)
1566 pValueSum += pow(-std::log(pValueProduct), i) / factorial;
1568 return pValueProduct * pValueSum;
1572 B2FATAL(
"Wrong number of arguments for meta function pValueCombination");
1578 if (arguments.size() == 1) {
1580 auto func = [var](
const Particle * particle) ->
double {
1581 auto var_result = var->function(particle);
1582 if (std::holds_alternative<double>(var_result))
1584 return std::abs(std::get<double>(var_result));
1585 }
else if (std::holds_alternative<int>(var_result))
1587 return std::abs(std::get<int>(var_result));
1592 B2FATAL(
"Wrong number of arguments for meta function abs");
1598 if (arguments.size() == 2) {
1603 B2FATAL(
"One or both of the used variables doesn't exist!");
1605 auto func = [var1, var2](
const Particle * particle) ->
double {
1607 auto var_result1 = var1->function(particle);
1608 auto var_result2 = var2->function(particle);
1609 if (std::holds_alternative<double>(var_result1))
1611 val1 = std::get<double>(var_result1);
1612 }
else if (std::holds_alternative<int>(var_result1))
1614 val1 = std::get<int>(var_result1);
1616 if (std::holds_alternative<double>(var_result2))
1618 val2 = std::get<double>(var_result2);
1619 }
else if (std::holds_alternative<int>(var_result2))
1621 val2 = std::get<int>(var_result2);
1623 return std::max(val1, val2);
1627 B2FATAL(
"Wrong number of arguments for meta function max");
1633 if (arguments.size() == 2) {
1638 B2FATAL(
"One or both of the used variables doesn't exist!");
1640 auto func = [var1, var2](
const Particle * particle) ->
double {
1642 auto var_result1 = var1->function(particle);
1643 auto var_result2 = var2->function(particle);
1644 if (std::holds_alternative<double>(var_result1))
1646 val1 = std::get<double>(var_result1);
1647 }
else if (std::holds_alternative<int>(var_result1))
1649 val1 = std::get<int>(var_result1);
1651 if (std::holds_alternative<double>(var_result2))
1653 val2 = std::get<double>(var_result2);
1654 }
else if (std::holds_alternative<int>(var_result2))
1656 val2 = std::get<int>(var_result2);
1658 return std::min(val1, val2);
1662 B2FATAL(
"Wrong number of arguments for meta function min");
1668 if (arguments.size() == 1) {
1670 auto func = [var](
const Particle * particle) ->
double {
1671 auto var_result = var->function(particle);
1672 if (std::holds_alternative<double>(var_result))
1673 return std::sin(std::get<double>(var_result));
1674 else if (std::holds_alternative<int>(var_result))
1675 return std::sin(std::get<int>(var_result));
1680 B2FATAL(
"Wrong number of arguments for meta function sin");
1686 if (arguments.size() == 1) {
1688 auto func = [var](
const Particle * particle) ->
double {
1689 auto var_result = var->function(particle);
1690 if (std::holds_alternative<double>(var_result))
1691 return std::asin(std::get<double>(var_result));
1692 else if (std::holds_alternative<int>(var_result))
1693 return std::asin(std::get<int>(var_result));
1698 B2FATAL(
"Wrong number of arguments for meta function asin");
1704 if (arguments.size() == 1) {
1706 auto func = [var](
const Particle * particle) ->
double {
1707 auto var_result = var->function(particle);
1708 if (std::holds_alternative<double>(var_result))
1709 return std::cos(std::get<double>(var_result));
1710 else if (std::holds_alternative<int>(var_result))
1711 return std::cos(std::get<int>(var_result));
1716 B2FATAL(
"Wrong number of arguments for meta function cos");
1722 if (arguments.size() == 1) {
1724 auto func = [var](
const Particle * particle) ->
double {
1725 auto var_result = var->function(particle);
1726 if (std::holds_alternative<double>(var_result))
1727 return std::acos(std::get<double>(var_result));
1728 else if (std::holds_alternative<int>(var_result))
1729 return std::acos(std::get<int>(var_result));
1734 B2FATAL(
"Wrong number of arguments for meta function acos");
1740 if (arguments.size() == 1) {
1742 auto func = [var](
const Particle * particle) ->
double {
return std::tan(std::get<double>(var->function(particle))); };
1745 B2FATAL(
"Wrong number of arguments for meta function tan");
1751 if (arguments.size() == 1) {
1753 auto func = [var](
const Particle * particle) ->
double {
return std::atan(std::get<double>(var->function(particle))); };
1756 B2FATAL(
"Wrong number of arguments for meta function atan");
1762 if (arguments.size() == 1) {
1764 auto func = [var](
const Particle * particle) ->
double {
1765 auto var_result = var->function(particle);
1766 if (std::holds_alternative<double>(var_result))
1767 return std::exp(std::get<double>(var_result));
1768 else if (std::holds_alternative<int>(var_result))
1769 return std::exp(std::get<int>(var_result));
1774 B2FATAL(
"Wrong number of arguments for meta function exp");
1780 if (arguments.size() == 1) {
1782 auto func = [var](
const Particle * particle) ->
double {
1783 auto var_result = var->function(particle);
1784 if (std::holds_alternative<double>(var_result))
1785 return std::log(std::get<double>(var_result));
1786 else if (std::holds_alternative<int>(var_result))
1787 return std::log(std::get<int>(var_result));
1792 B2FATAL(
"Wrong number of arguments for meta function log");
1798 if (arguments.size() == 1) {
1800 auto func = [var](
const Particle * particle) ->
double {
1801 auto var_result = var->function(particle);
1802 if (std::holds_alternative<double>(var_result))
1803 return std::log10(std::get<double>(var_result));
1804 else if (std::holds_alternative<int>(var_result))
1805 return std::log10(std::get<int>(var_result));
1810 B2FATAL(
"Wrong number of arguments for meta function log10");
1816 if (arguments.size() == 1) {
1818 auto func = [var](
const Particle * particle) ->
double {
1819 if (particle ==
nullptr)
1822 StoreArray<Particle> particles;
1823 if (!particle->hasExtraInfo(
"original_index"))
1826 auto originalParticle = particles[particle->getExtraInfo(
"original_index")];
1827 if (!originalParticle)
1829 auto var_result = var->function(originalParticle);
1830 if (std::holds_alternative<double>(var_result))
1832 return std::get<double>(var_result);
1833 }
else if (std::holds_alternative<int>(var_result))
1835 return std::get<int>(var_result);
1836 }
else if (std::holds_alternative<bool>(var_result))
1838 return std::get<bool>(var_result);
1843 B2FATAL(
"Wrong number of arguments for meta function originalParticle");
1849 if (arguments.size() == 2) {
1850 int daughterNumber = 0;
1852 daughterNumber = Belle2::convertString<int>(arguments[0]);
1853 }
catch (std::invalid_argument&) {
1854 B2FATAL(
"First argument of daughter meta function must be integer!");
1857 auto func = [var, daughterNumber](
const Particle * particle) ->
double {
1858 if (particle ==
nullptr)
1860 if (daughterNumber >=
int(particle->getNDaughters()))
1864 auto var_result = var->function(particle->getDaughter(daughterNumber));
1865 if (std::holds_alternative<double>(var_result)) {
1866 return std::get<double>(var_result);
1867 }
else if (std::holds_alternative<int>(var_result)) {
1868 return std::get<int>(var_result);
1869 }
else if (std::holds_alternative<bool>(var_result)) {
1870 return std::get<bool>(var_result);
1876 B2FATAL(
"Wrong number of arguments for meta function daughter");
1882 if (arguments.size() == 2) {
1883 int daughterNumber = 0;
1885 daughterNumber = Belle2::convertString<int>(arguments[0]);
1886 }
catch (std::invalid_argument&) {
1887 B2FATAL(
"First argument of daughter meta function must be integer!");
1890 auto func = [var, daughterNumber](
const Particle * particle) ->
double {
1891 if (particle ==
nullptr)
1893 if (daughterNumber >=
int(particle->getNDaughters()))
1897 StoreArray<Particle> particles;
1898 if (!particle->getDaughter(daughterNumber)->hasExtraInfo(
"original_index"))
1900 auto originalDaughter = particles[particle->getDaughter(daughterNumber)->getExtraInfo(
"original_index")];
1901 if (!originalDaughter)
1904 auto var_result = var->function(originalDaughter);
1905 if (std::holds_alternative<double>(var_result)) {
1906 return std::get<double>(var_result);
1907 }
else if (std::holds_alternative<int>(var_result)) {
1908 return std::get<int>(var_result);
1909 }
else if (std::holds_alternative<bool>(var_result)) {
1910 return std::get<bool>(var_result);
1916 B2FATAL(
"Wrong number of arguments for meta function daughter");
1922 if (arguments.size() == 2) {
1923 int daughterNumber = 0;
1925 daughterNumber = Belle2::convertString<int>(arguments[0]);
1926 }
catch (std::invalid_argument&) {
1927 B2FATAL(
"First argument of mcDaughter meta function must be integer!");
1930 auto func = [var, daughterNumber](
const Particle * particle) ->
double {
1931 if (particle ==
nullptr)
1933 if (particle->getMCParticle())
1935 if (daughterNumber >=
int(particle->getMCParticle()->getNDaughters())) {
1938 Particle tempParticle = Particle(particle->getMCParticle()->getDaughters().at(daughterNumber));
1939 auto var_result = var->function(&tempParticle);
1940 if (std::holds_alternative<double>(var_result)) {
1941 return std::get<double>(var_result);
1942 }
else if (std::holds_alternative<int>(var_result)) {
1943 return std::get<int>(var_result);
1944 }
else if (std::holds_alternative<bool>(var_result)) {
1945 return std::get<bool>(var_result);
1954 B2FATAL(
"Wrong number of arguments for meta function mcDaughter");
1960 if (arguments.size() == 1) {
1962 auto func = [var](
const Particle * particle) ->
double {
1963 if (particle ==
nullptr)
1965 if (particle->getMCParticle())
1967 if (particle->getMCParticle()->getMother() ==
nullptr) {
1970 Particle tempParticle = Particle(particle->getMCParticle()->getMother());
1971 auto var_result = var->function(&tempParticle);
1972 if (std::holds_alternative<double>(var_result)) {
1973 return std::get<double>(var_result);
1974 }
else if (std::holds_alternative<int>(var_result)) {
1975 return std::get<int>(var_result);
1976 }
else if (std::holds_alternative<bool>(var_result)) {
1977 return std::get<bool>(var_result);
1986 B2FATAL(
"Wrong number of arguments for meta function mcMother");
1992 if (arguments.size() == 2) {
1993 int particleNumber = 0;
1995 particleNumber = Belle2::convertString<int>(arguments[0]);
1996 }
catch (std::invalid_argument&) {
1997 B2FATAL(
"First argument of genParticle meta function must be integer!");
2001 auto func = [var, particleNumber](
const Particle*) ->
double {
2002 StoreArray<MCParticle> mcParticles(
"MCParticles");
2003 if (particleNumber >= mcParticles.getEntries())
2008 MCParticle* mcParticle = mcParticles[particleNumber];
2009 Particle part = Particle(mcParticle);
2010 auto var_result = var->function(&part);
2011 if (std::holds_alternative<double>(var_result))
2013 return std::get<double>(var_result);
2014 }
else if (std::holds_alternative<int>(var_result))
2016 return std::get<int>(var_result);
2017 }
else if (std::holds_alternative<bool>(var_result))
2019 return std::get<bool>(var_result);
2024 B2FATAL(
"Wrong number of arguments for meta function genParticle");
2030 if (arguments.size() == 1) {
2033 auto func = [var](
const Particle*) ->
double {
2034 StoreArray<MCParticle> mcParticles(
"MCParticles");
2035 if (mcParticles.getEntries() == 0)
2040 MCParticle* mcUpsilon4S = mcParticles[0];
2041 if (mcUpsilon4S->isInitial()) mcUpsilon4S = mcParticles[2];
2042 if (mcUpsilon4S->getPDG() != 300553)
2047 Particle upsilon4S = Particle(mcUpsilon4S);
2048 auto var_result = var->function(&upsilon4S);
2049 if (std::holds_alternative<double>(var_result))
2051 return std::get<double>(var_result);
2052 }
else if (std::holds_alternative<int>(var_result))
2054 return std::get<int>(var_result);
2055 }
else if (std::holds_alternative<bool>(var_result))
2057 return std::get<bool>(var_result);
2062 B2FATAL(
"Wrong number of arguments for meta function genUpsilon4S");
2068 if (arguments.size() == 4) {
2069 std::string listName = arguments[0];
2070 std::string rankedVariableName = arguments[1];
2071 std::string returnVariableName = arguments[2];
2072 std::string extraInfoName = rankedVariableName +
"_rank";
2075 rank = Belle2::convertString<int>(arguments[3]);
2076 }
catch (std::invalid_argument&) {
2077 B2ERROR(
"3rd argument of getVariableByRank meta function (Rank) must be an integer!");
2082 auto func = [var, rank, extraInfoName, listName](
const Particle*)->
double {
2083 StoreObjPtr<ParticleList> list(listName);
2085 const unsigned int numParticles = list->getListSize();
2086 for (
unsigned int i = 0; i < numParticles; i++)
2088 const Particle* p = list->getParticle(i);
2089 if (p->getExtraInfo(extraInfoName) == rank) {
2090 auto var_result = var->function(p);
2091 if (std::holds_alternative<double>(var_result)) {
2092 return std::get<double>(var_result);
2093 }
else if (std::holds_alternative<int>(var_result)) {
2094 return std::get<int>(var_result);
2095 }
else if (std::holds_alternative<bool>(var_result)) {
2096 return std::get<bool>(var_result);
2101 return std::numeric_limits<double>::signaling_NaN();
2105 B2FATAL(
"Wrong number of arguments for meta function getVariableByRank");
2111 if (arguments.size() == 1 or arguments.size() == 2) {
2113 std::string listName = arguments[0];
2114 std::string cutString =
"";
2116 if (arguments.size() == 2) {
2117 cutString = arguments[1];
2122 auto func = [listName, cut](
const Particle*) ->
int {
2124 StoreObjPtr<ParticleList> list(listName);
2126 for (
unsigned int i = 0; i < list->getListSize(); i++)
2128 const Particle* particle = list->getParticle(i);
2129 if (cut->check(particle)) {
2137 B2FATAL(
"Wrong number of arguments for meta function countInList");
2143 if (arguments.size() == 2 or arguments.size() == 3) {
2145 std::string roeListName = arguments[0];
2146 std::string cutString = arguments[1];
2148 if (arguments.size() == 2) {
2149 B2INFO(
"Use pdgCode of electron as default in meta variable veto, other arguments: " << roeListName <<
", " << cutString);
2152 pdgCode = Belle2::convertString<int>(arguments[2]);;
2153 }
catch (std::invalid_argument&) {
2154 B2FATAL(
"Third argument of veto meta function must be integer!");
2161 auto func = [roeListName, cut, pdgCode, flavourType](
const Particle * particle) ->
bool {
2162 StoreObjPtr<ParticleList> roeList(roeListName);
2163 ROOT::Math::PxPyPzEVector vec = particle->get4Vector();
2164 for (
unsigned int i = 0; i < roeList->getListSize(); i++)
2166 const Particle* roeParticle = roeList->getParticle(i);
2167 if (not particle->overlapsWith(roeParticle)) {
2168 ROOT::Math::PxPyPzEVector tempCombination = roeParticle->get4Vector() + vec;
2169 std::vector<int> indices = { particle->getArrayIndex(), roeParticle->getArrayIndex() };
2170 Particle tempParticle = Particle(tempCombination, pdgCode, flavourType, indices, particle->getArrayPointer());
2171 if (cut->check(&tempParticle)) {
2180 B2FATAL(
"Wrong number of arguments for meta function veto");
2186 if (arguments.size() == 1) {
2187 std::string cutString = arguments[0];
2189 auto func = [cut](
const Particle * particle) ->
int {
2191 for (
auto& daughter : particle->getDaughters())
2193 if (cut->check(daughter))
2200 B2FATAL(
"Wrong number of arguments for meta function countDaughters");
2206 if (arguments.size() == 1) {
2207 std::string cutString = arguments[0];
2209 auto func = [cut](
const Particle * particle) ->
int {
2211 std::vector<const Particle*> fspDaughters;
2212 particle->fillFSPDaughters(fspDaughters);
2215 for (
auto& daughter : fspDaughters)
2217 if (cut->check(daughter))
2224 B2FATAL(
"Wrong number of arguments for meta function countFSPDaughters");
2230 if (arguments.size() == 1) {
2231 std::string cutString = arguments[0];
2233 auto func = [cut](
const Particle * particle) ->
int {
2235 std::vector<const Particle*> allDaughters;
2236 particle->fillAllDaughters(allDaughters);
2239 for (
auto& daughter : allDaughters)
2241 if (cut->check(daughter))
2248 B2FATAL(
"Wrong number of arguments for meta function countDescendants");
2252 Manager::FunctionPtr numberOfNonOverlappingParticles(
const std::vector<std::string>& arguments)
2255 auto func = [arguments](
const Particle * particle) ->
int {
2257 int _numberOfNonOverlappingParticles = 0;
2258 for (
const auto& listName : arguments)
2260 StoreObjPtr<ParticleList> list(listName);
2261 if (not list.isValid()) {
2262 B2FATAL(
"Invalid list named " << listName <<
" encountered in numberOfNonOverlappingParticles.");
2264 for (
unsigned int i = 0; i < list->getListSize(); i++) {
2265 const Particle* p = list->getParticle(i);
2266 if (not particle->overlapsWith(p)) {
2267 _numberOfNonOverlappingParticles++;
2271 return _numberOfNonOverlappingParticles;
2278 void appendDaughtersRecursive(Particle* mother)
2281 auto* mcmother = mother->getRelated<MCParticle>();
2286 std::vector<MCParticle*> mcdaughters = mcmother->
getDaughters();
2287 StoreArray<Particle> particles;
2289 for (
auto& mcdaughter : mcdaughters) {
2291 Particle tmp_daughter(mcdaughter);
2292 Particle* new_daughter = particles.appendNew(tmp_daughter);
2293 new_daughter->addRelationTo(mcdaughter);
2294 mother->appendDaughter(new_daughter,
false);
2296 if (mcdaughter->getNDaughters() > 0)
2297 appendDaughtersRecursive(new_daughter);
2304 if (arguments.size() == 1) {
2306 auto func = [var](
const Particle * particle) ->
double {
2307 const MCParticle* mcp = particle->getMCParticle();
2312 Particle tmpPart(mcp);
2313 StoreArray<Particle> particles;
2314 Particle* newPart = particles.appendNew(tmpPart);
2315 newPart->addRelationTo(mcp);
2317 appendDaughtersRecursive(newPart);
2319 auto var_result = var->function(newPart);
2320 if (std::holds_alternative<double>(var_result))
2322 return std::get<double>(var_result);
2323 }
else if (std::holds_alternative<int>(var_result))
2325 return std::get<int>(var_result);
2326 }
else if (std::holds_alternative<bool>(var_result))
2328 return std::get<bool>(var_result);
2333 B2FATAL(
"Wrong number of arguments for meta function matchedMC");
2339 if (arguments.size() == 1) {
2342 auto func = [var](
const Particle * particle) ->
double {
2344 const ECLCluster* cluster = particle->getECLCluster();
2347 auto mcps = cluster->getRelationsTo<MCParticle>();
2350 std::vector<std::pair<double, int>> weightsAndIndices;
2351 for (
unsigned int i = 0; i < mcps.size(); ++i)
2352 weightsAndIndices.emplace_back(mcps.weight(i), i);
2355 std::sort(weightsAndIndices.begin(), weightsAndIndices.end(),
2356 ValueIndexPairSorting::higherPair<
decltype(weightsAndIndices)::value_type>);
2359 const MCParticle* mcp = mcps.object(weightsAndIndices[0].second);
2361 Particle tmpPart(mcp);
2362 StoreArray<Particle> particles;
2363 Particle* newPart = particles.appendNew(tmpPart);
2364 newPart->addRelationTo(mcp);
2366 appendDaughtersRecursive(newPart);
2368 auto var_result = var->function(newPart);
2369 if (std::holds_alternative<double>(var_result))
2371 return std::get<double>(var_result);
2372 }
else if (std::holds_alternative<int>(var_result))
2374 return std::get<int>(var_result);
2375 }
else if (std::holds_alternative<bool>(var_result))
2377 return std::get<bool>(var_result);
2386 B2FATAL(
"Wrong number of arguments for meta function clusterBestMatchedMCParticle");
2392 if (arguments.size() == 1) {
2395 auto func = [var](
const Particle * particle) ->
double {
2397 const ECLCluster* cluster = particle->getECLCluster();
2400 auto mcps = cluster->getRelationsTo<MCParticle>();
2403 std::map<int, double> mapMCParticleIndxAndWeight;
2404 getKlongWeightMap(particle, mapMCParticleIndxAndWeight);
2407 if (mapMCParticleIndxAndWeight.size() == 0)
2411 auto maxMap = std::max_element(mapMCParticleIndxAndWeight.begin(), mapMCParticleIndxAndWeight.end(),
2412 [](
const auto & x,
const auto & y) { return x.second < y.second; }
2415 StoreArray<MCParticle> mcparticles;
2416 const MCParticle* mcKlong = mcparticles[maxMap->first];
2418 Particle tmpPart(mcKlong);
2419 auto var_result = var->function(&tmpPart);
2420 if (std::holds_alternative<double>(var_result))
2422 return std::get<double>(var_result);
2423 }
else if (std::holds_alternative<int>(var_result))
2425 return std::get<int>(var_result);
2426 }
else if (std::holds_alternative<bool>(var_result))
2428 return std::get<bool>(var_result);
2437 B2FATAL(
"Wrong number of arguments for meta function clusterBestMatchedMCKlong");
2441 double matchedMCHasPDG(
const Particle* particle,
const std::vector<double>& pdgCode)
2443 if (pdgCode.size() != 1) {
2444 B2FATAL(
"Too many arguments provided to matchedMCHasPDG!");
2446 int inputPDG = std::lround(pdgCode[0]);
2448 const MCParticle* mcp = particle->getMCParticle();
2452 return std::abs(mcp->getPDG()) == inputPDG;
2457 if (arguments.size() == 1) {
2458 std::string listName = arguments[0];
2459 auto func = [listName](
const Particle * particle) ->
double {
2462 StoreObjPtr<ParticleList> listOfParticles(listName);
2464 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to totalEnergyOfParticlesInList");
2465 double totalEnergy = 0;
2466 int nParticles = listOfParticles->getListSize();
2467 for (
int i = 0; i < nParticles; i++)
2469 const Particle* part = listOfParticles->getParticle(i);
2471 totalEnergy += frame.getMomentum(part).E();
2478 B2FATAL(
"Wrong number of arguments for meta function totalEnergyOfParticlesInList");
2484 if (arguments.size() == 1) {
2485 std::string listName = arguments[0];
2486 auto func = [listName](
const Particle*) ->
double {
2487 StoreObjPtr<ParticleList> listOfParticles(listName);
2489 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to totalPxOfParticlesInList");
2491 int nParticles = listOfParticles->getListSize();
2493 for (
int i = 0; i < nParticles; i++)
2495 const Particle* part = listOfParticles->getParticle(i);
2496 totalPx += frame.getMomentum(part).Px();
2502 B2FATAL(
"Wrong number of arguments for meta function totalPxOfParticlesInList");
2508 if (arguments.size() == 1) {
2509 std::string listName = arguments[0];
2510 auto func = [listName](
const Particle*) ->
double {
2511 StoreObjPtr<ParticleList> listOfParticles(listName);
2513 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to totalPyOfParticlesInList");
2515 int nParticles = listOfParticles->getListSize();
2517 for (
int i = 0; i < nParticles; i++)
2519 const Particle* part = listOfParticles->getParticle(i);
2520 totalPy += frame.getMomentum(part).Py();
2526 B2FATAL(
"Wrong number of arguments for meta function totalPyOfParticlesInList");
2532 if (arguments.size() == 1) {
2533 std::string listName = arguments[0];
2534 auto func = [listName](
const Particle*) ->
double {
2535 StoreObjPtr<ParticleList> listOfParticles(listName);
2537 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to totalPzOfParticlesInList");
2539 int nParticles = listOfParticles->getListSize();
2541 for (
int i = 0; i < nParticles; i++)
2543 const Particle* part = listOfParticles->getParticle(i);
2544 totalPz += frame.getMomentum(part).Pz();
2550 B2FATAL(
"Wrong number of arguments for meta function totalPzOfParticlesInList");
2556 if (arguments.size() > 0) {
2558 auto func = [arguments](
const Particle * particle) ->
double {
2560 ROOT::Math::PxPyPzEVector total4Vector;
2562 std::vector<Particle*> particlePool;
2565 for (
const auto& argument : arguments)
2567 StoreObjPtr <ParticleList> listOfParticles(argument);
2569 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << argument <<
" given to invMassInLists");
2570 int nParticles = listOfParticles->getListSize();
2571 for (
int i = 0; i < nParticles; i++) {
2572 bool overlaps =
false;
2573 Particle* part = listOfParticles->getParticle(i);
2574 for (
auto poolPart : particlePool) {
2575 if (part->overlapsWith(poolPart)) {
2581 total4Vector += part->get4Vector();
2582 particlePool.push_back(part);
2586 double invariantMass = total4Vector.M();
2587 return invariantMass;
2592 B2FATAL(
"Wrong number of arguments for meta function invMassInLists");
2596 Manager::FunctionPtr totalECLEnergyOfParticlesInList(
const std::vector<std::string>& arguments)
2598 if (arguments.size() == 1) {
2599 std::string listName = arguments[0];
2600 auto func = [listName](
const Particle * particle) ->
double {
2603 StoreObjPtr<ParticleList> listOfParticles(listName);
2605 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to totalEnergyOfParticlesInList");
2606 double totalEnergy = 0;
2607 int nParticles = listOfParticles->getListSize();
2608 for (
int i = 0; i < nParticles; i++)
2610 const Particle* part = listOfParticles->getParticle(i);
2611 const ECLCluster* cluster = part->getECLCluster();
2613 if (cluster !=
nullptr) {
2614 totalEnergy += cluster->getEnergy(clusterHypothesis);
2622 B2FATAL(
"Wrong number of arguments for meta function totalECLEnergyOfParticlesInList");
2628 if (arguments.size() == 1) {
2629 std::string listName = arguments[0];
2630 auto func = [listName](
const Particle*) ->
double {
2631 StoreObjPtr<ParticleList> listOfParticles(listName);
2633 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to maxPtInList");
2634 int nParticles = listOfParticles->getListSize();
2637 for (
int i = 0; i < nParticles; i++)
2639 const Particle* part = listOfParticles->getParticle(i);
2640 const double Pt = frame.getMomentum(part).Pt();
2641 if (Pt > maxPt) maxPt = Pt;
2647 B2FATAL(
"Wrong number of arguments for meta function maxPtInList");
2651 Manager::FunctionPtr eclClusterTrackMatchedWithCondition(
const std::vector<std::string>& arguments)
2653 if (arguments.size() <= 1) {
2655 std::string cutString;
2656 if (arguments.size() == 1)
2657 cutString = arguments[0];
2659 auto func = [cut](
const Particle * particle) ->
double {
2661 if (particle ==
nullptr)
2664 const ECLCluster* cluster = particle->getECLCluster();
2668 auto tracks = cluster->getRelationsFrom<Track>();
2670 for (
const auto& track : tracks) {
2673 if (cut->check(&trackParticle))
2682 B2FATAL(
"Wrong number of arguments for meta function eclClusterSpecialTrackMatched");
2688 if (arguments.size() == 2) {
2689 std::string listName = arguments[0];
2692 auto func = [listName, var](
const Particle*) ->
double {
2693 StoreObjPtr<ParticleList> listOfParticles(listName);
2695 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid list name " << listName <<
" given to averageValueInList");
2696 int nParticles = listOfParticles->getListSize();
2697 if (nParticles == 0)
2702 if (std::holds_alternative<double>(var->function(listOfParticles->getParticle(0))))
2704 for (
int i = 0; i < nParticles; i++) {
2705 average += std::get<double>(var->function(listOfParticles->getParticle(i))) / nParticles;
2707 }
else if (std::holds_alternative<int>(var->function(listOfParticles->getParticle(0))))
2709 for (
int i = 0; i < nParticles; i++) {
2710 average += std::get<int>(var->function(listOfParticles->getParticle(i))) / nParticles;
2717 B2FATAL(
"Wrong number of arguments for meta function averageValueInList");
2723 if (arguments.size() == 2) {
2724 std::string listName = arguments[0];
2727 auto func = [listName, var](
const Particle*) ->
double {
2728 StoreObjPtr<ParticleList> listOfParticles(listName);
2730 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid list name " << listName <<
" given to medianValueInList");
2731 int nParticles = listOfParticles->getListSize();
2732 if (nParticles == 0)
2736 std::vector<double> valuesInList;
2737 if (std::holds_alternative<double>(var->function(listOfParticles->getParticle(0))))
2739 for (
int i = 0; i < nParticles; i++) {
2740 valuesInList.push_back(std::get<double>(var->function(listOfParticles->getParticle(i))));
2742 }
else if (std::holds_alternative<int>(var->function(listOfParticles->getParticle(0))))
2744 for (
int i = 0; i < nParticles; i++) {
2745 valuesInList.push_back(std::get<int>(var->function(listOfParticles->getParticle(i))));
2748 std::sort(valuesInList.begin(), valuesInList.end());
2749 if (nParticles % 2 != 0)
2751 return valuesInList[nParticles / 2];
2754 return 0.5 * (valuesInList[nParticles / 2] + valuesInList[nParticles / 2 - 1]);
2759 B2FATAL(
"Wrong number of arguments for meta function medianValueInList");
2765 if (arguments.size() == 2) {
2766 std::string listName = arguments[0];
2769 auto func = [listName, var](
const Particle*) ->
double {
2770 StoreObjPtr<ParticleList> listOfParticles(listName);
2772 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid list name " << listName <<
" given to sumValueInList");
2773 int nParticles = listOfParticles->getListSize();
2774 if (nParticles == 0)
2779 if (std::holds_alternative<double>(var->function(listOfParticles->getParticle(0))))
2781 for (
int i = 0; i < nParticles; i++) {
2782 sum += std::get<double>(var->function(listOfParticles->getParticle(i)));
2784 }
else if (std::holds_alternative<int>(var->function(listOfParticles->getParticle(0))))
2786 for (
int i = 0; i < nParticles; i++) {
2787 sum += std::get<int>(var->function(listOfParticles->getParticle(i)));
2794 B2FATAL(
"Wrong number of arguments for meta function sumValueInList");
2800 if (arguments.size() == 2) {
2801 std::string listName = arguments[0];
2804 auto func = [listName, var](
const Particle*) ->
double {
2805 StoreObjPtr<ParticleList> listOfParticles(listName);
2807 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid list name " << listName <<
" given to productValueInList");
2808 int nParticles = listOfParticles->getListSize();
2809 if (nParticles == 0)
2814 if (std::holds_alternative<double>(var->function(listOfParticles->getParticle(0))))
2816 for (
int i = 0; i < nParticles; i++) {
2817 product *= std::get<double>(var->function(listOfParticles->getParticle(i)));
2819 }
else if (std::holds_alternative<int>(var->function(listOfParticles->getParticle(0))))
2821 for (
int i = 0; i < nParticles; i++) {
2822 product *= std::get<int>(var->function(listOfParticles->getParticle(i)));
2829 B2FATAL(
"Wrong number of arguments for meta function productValueInList");
2836 if (arguments.size() != 1)
2837 B2FATAL(
"Wrong number of arguments for meta function angleToClosestInList");
2839 std::string listname = arguments[0];
2841 auto func = [listname](
const Particle * particle) ->
double {
2843 StoreObjPtr<ParticleList> list(listname);
2844 if (not list.isValid())
2845 B2FATAL(
"Invalid particle list name " << listname <<
" given to angleToClosestInList");
2848 if (list->getListSize() == 0)
2853 const auto p_this =
B2Vector3D(frame.getMomentum(particle).Vect());
2856 double minAngle = 2 * M_PI;
2857 for (
unsigned int i = 0; i < list->getListSize(); ++i)
2859 const Particle* compareme = list->getParticle(i);
2860 const auto p_compare =
B2Vector3D(frame.getMomentum(compareme).Vect());
2861 double angle = p_compare.Angle(p_this);
2862 if (minAngle > angle) minAngle = angle;
2872 if (arguments.size() != 2)
2873 B2FATAL(
"Wrong number of arguments for meta function closestInList");
2875 std::string listname = arguments[0];
2880 auto func = [listname, var](
const Particle * particle) ->
double {
2882 StoreObjPtr<ParticleList> list(listname);
2883 if (not list.isValid())
2884 B2FATAL(
"Invalid particle list name " << listname <<
" given to closestInList");
2888 const auto p_this =
B2Vector3D(frame.getMomentum(particle).Vect());
2891 double minAngle = 2 * M_PI;
2893 for (
unsigned int i = 0; i < list->getListSize(); ++i)
2895 const Particle* compareme = list->getParticle(i);
2896 const auto p_compare =
B2Vector3D(frame.getMomentum(compareme).Vect());
2897 double angle = p_compare.Angle(p_this);
2898 if (minAngle > angle) {
2906 auto var_result = var->function(list->getParticle(iClosest));
2907 if (std::holds_alternative<double>(var_result))
2909 return std::get<double>(var_result);
2910 }
else if (std::holds_alternative<int>(var_result))
2912 return std::get<int>(var_result);
2913 }
else if (std::holds_alternative<bool>(var_result))
2915 return std::get<bool>(var_result);
2924 if (arguments.size() != 1)
2925 B2FATAL(
"Wrong number of arguments for meta function angleToMostB2BInList");
2927 std::string listname = arguments[0];
2929 auto func = [listname](
const Particle * particle) ->
double {
2931 StoreObjPtr<ParticleList> list(listname);
2932 if (not list.isValid())
2933 B2FATAL(
"Invalid particle list name " << listname <<
" given to angleToMostB2BInList");
2936 if (list->getListSize() == 0)
2941 const auto p_this =
B2Vector3D(frame.getMomentum(particle).Vect());
2945 double maxAngle = 0;
2946 for (
unsigned int i = 0; i < list->getListSize(); ++i)
2948 const Particle* compareme = list->getParticle(i);
2949 const auto p_compare =
B2Vector3D(frame.getMomentum(compareme).Vect());
2950 double angle = p_compare.Angle(p_this);
2951 if (maxAngle < angle) maxAngle = angle;
2961 if (arguments.size() != 1)
2962 B2FATAL(
"Wrong number of arguments for meta function deltaPhiToMostB2BPhiInList");
2964 std::string listname = arguments[0];
2966 auto func = [listname](
const Particle * particle) ->
double {
2968 StoreObjPtr<ParticleList> list(listname);
2969 if (not list.isValid())
2970 B2FATAL(
"Invalid particle list name " << listname <<
" given to deltaPhiToMostB2BPhiInList");
2973 if (list->getListSize() == 0)
2978 const auto phi_this = frame.getMomentum(particle).Phi();
2981 double maxAngle = 0;
2982 for (
unsigned int i = 0; i < list->getListSize(); ++i)
2984 const Particle* compareme = list->getParticle(i);
2985 const auto phi_compare = frame.getMomentum(compareme).Phi();
2986 double angle = std::abs(phi_compare - phi_this);
2987 if (angle > M_PI) {angle = 2 * M_PI - angle;}
2988 if (maxAngle < angle) maxAngle = angle;
2998 if (arguments.size() != 2)
2999 B2FATAL(
"Wrong number of arguments for meta function mostB2BInList");
3001 std::string listname = arguments[0];
3006 auto func = [listname, var](
const Particle * particle) ->
double {
3008 StoreObjPtr<ParticleList> list(listname);
3009 if (not list.isValid())
3010 B2FATAL(
"Invalid particle list name " << listname <<
" given to mostB2BInList");
3014 const auto p_this =
B2Vector3D(frame.getMomentum(particle).Vect());
3018 double maxAngle = -1.0;
3020 for (
unsigned int i = 0; i < list->getListSize(); ++i)
3022 const Particle* compareme = list->getParticle(i);
3023 const auto p_compare =
B2Vector3D(frame.getMomentum(compareme).Vect());
3024 double angle = p_compare.Angle(p_this);
3025 if (maxAngle < angle) {
3033 auto var_result = var->function(list->getParticle(iMostB2B));
3034 if (std::holds_alternative<double>(var_result))
3036 return std::get<double>(var_result);
3037 }
else if (std::holds_alternative<int>(var_result))
3039 return std::get<int>(var_result);
3040 }
else if (std::holds_alternative<bool>(var_result))
3042 return std::get<bool>(var_result);
3050 if (arguments.size() == 1) {
3051 std::string listName = arguments[0];
3052 auto func = [listName](
const Particle*) ->
double {
3053 StoreObjPtr<ParticleList> listOfParticles(listName);
3055 if (!(listOfParticles.isValid())) B2FATAL(
"Invalid Listname " << listName <<
" given to maxOpeningAngleInList");
3056 int nParticles = listOfParticles->getListSize();
3061 double maxOpeningAngle = -1;
3062 for (
int i = 0; i < nParticles; i++)
3064 B2Vector3D v1 = frame.getMomentum(listOfParticles->getParticle(i)).Vect();
3065 for (
int j = i + 1; j < nParticles; j++) {
3066 B2Vector3D v2 = frame.getMomentum(listOfParticles->getParticle(j)).Vect();
3067 const double angle =
v1.Angle(v2);
3068 if (angle > maxOpeningAngle) maxOpeningAngle = angle;
3071 return maxOpeningAngle;
3075 B2FATAL(
"Wrong number of arguments for meta function maxOpeningAngleInList");
3082 if (arguments.size() >= 2) {
3087 auto func = [var, arguments](
const Particle * particle) ->
double {
3088 if (particle ==
nullptr)
3090 B2WARNING(
"Trying to access a daughter that does not exist. Skipping");
3096 ROOT::Math::PxPyPzEVector pSum(0, 0, 0, 0);
3100 for (
unsigned int iCoord = 1; iCoord < arguments.size(); iCoord++)
3102 auto generalizedIndex = arguments[iCoord];
3103 const Particle* dauPart = particle->getParticleFromGeneralizedIndexString(generalizedIndex);
3105 pSum += frame.getMomentum(dauPart);
3107 B2WARNING(
"Trying to access a daughter that does not exist. Index = " << generalizedIndex);
3113 Particle sumOfDaughters(pSum, 100);
3115 auto var_result = var->function(&sumOfDaughters);
3117 if (std::holds_alternative<double>(var_result))
3119 return std::get<double>(var_result);
3120 }
else if (std::holds_alternative<int>(var_result))
3122 return std::get<int>(var_result);
3123 }
else if (std::holds_alternative<bool>(var_result))
3125 return std::get<bool>(var_result);
3130 B2FATAL(
"Wrong number of arguments for meta function daughterCombination");
3133 Manager::FunctionPtr useAlternativeDaughterHypothesis(
const std::vector<std::string>& arguments)
3146 if (arguments.size() >= 2) {
3157 std::unordered_map<unsigned int, int> mapOfReplacedDaughters;
3160 for (
unsigned int iCoord = 1; iCoord < arguments.size(); iCoord++) {
3161 auto replacedDauString = arguments[iCoord];
3163 std::vector<std::string> indexAndMass;
3164 boost::split(indexAndMass, replacedDauString, boost::is_any_of(
":"));
3167 if (indexAndMass.size() > 2) {
3168 B2WARNING(
"The string indicating which daughter's mass should be replaced contains more than two elements separated by a colon. Perhaps you tried to pass a generalized index, which is not supported yet for this variable. The offending string is "
3169 << replacedDauString <<
", while a correct syntax looks like 0:K+.");
3173 if (indexAndMass.size() < 2) {
3174 B2WARNING(
"The string indicating which daughter's mass should be replaced contains only one colon-separated element instead of two. The offending string is "
3175 << replacedDauString <<
", while a correct syntax looks like 0:K+.");
3182 dauIndex = Belle2::convertString<int>(indexAndMass[0]);
3183 }
catch (std::invalid_argument&) {
3184 B2FATAL(
"Found the string " << indexAndMass[0] <<
"instead of a daughter index.");
3188 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(indexAndMass[1].c_str());
3190 B2WARNING(
"Particle not in evt.pdl file! " << indexAndMass[1]);
3195 int pdgCode = particlePDG->PdgCode();
3196 mapOfReplacedDaughters[dauIndex] = pdgCode;
3200 if (mapOfReplacedDaughters.size() != arguments.size() - 1)
3201 B2FATAL(
"Overlapped daughter's index is detected in the meta-variable useAlternativeDaughterHypothesis");
3209 auto func = [var, mapOfReplacedDaughters](
const Particle * particle) ->
double {
3210 if (particle ==
nullptr)
3212 B2WARNING(
"Trying to access a particle that does not exist. Skipping");
3222 ROOT::Math::PxPyPzMVector pSum(0, 0, 0, 0);
3224 for (
unsigned int iDau = 0; iDau < particle->getNDaughters(); iDau++)
3226 const Particle* dauPart = particle->getDaughter(iDau);
3228 B2WARNING(
"Trying to access a daughter that does not exist. Index = " << iDau);
3232 ROOT::Math::PxPyPzMVector dauMom = ROOT::Math::PxPyPzMVector(frame.getMomentum(dauPart));
3236 pdgCode = mapOfReplacedDaughters.at(iDau);
3237 }
catch (std::out_of_range&) {
3244 double p_x = dauMom.Px();
3245 double p_y = dauMom.Py();
3246 double p_z = dauMom.Pz();
3247 dauMom.SetCoordinates(p_x, p_y, p_z, TDatabasePDG::Instance()->GetParticle(pdgCode)->Mass());
3248 const_cast<Particle*
>(dummy->getDaughter(iDau))->set4VectorDividingByMomentumScaling(ROOT::Math::PxPyPzEVector(dauMom));
3251 const int charge = dummy->getDaughter(iDau)->getCharge();
3252 if (TDatabasePDG::Instance()->GetParticle(pdgCode)->Charge() / 3.0 ==
charge)
3253 const_cast<Particle*
>(dummy->getDaughter(iDau))->setPDGCode(pdgCode);
3255 const_cast<Particle*
>(dummy->getDaughter(iDau))->setPDGCode(-1 * pdgCode);
3261 dummy->set4Vector(ROOT::Math::PxPyPzEVector(pSum));
3263 auto var_result = var->function(dummy);
3266 if (std::holds_alternative<double>(var_result))
3268 return std::get<double>(var_result);
3269 }
else if (std::holds_alternative<int>(var_result))
3271 return std::get<int>(var_result);
3272 }
else if (std::holds_alternative<bool>(var_result))
3274 return std::get<bool>(var_result);
3280 B2FATAL(
"Wrong number of arguments for meta function useAlternativeDaughterHypothesis");
3285 if (arguments.size() == 2) {
3287 std::string arg = arguments[0];
3289 TParticlePDG* part = TDatabasePDG::Instance()->GetParticle(arg.c_str());
3291 if (part !=
nullptr) {
3292 pdg_code = std::abs(part->PdgCode());
3295 pdg_code = Belle2::convertString<int>(arg);
3296 }
catch (std::exception& e) {}
3299 if (pdg_code == -1) {
3300 B2FATAL(
"Ancestor " + arg +
" is not recognised. Please provide valid PDG code or particle name.");
3303 auto func = [pdg_code, var](
const Particle * particle) ->
double {
3304 const Particle* p = particle;
3306 int ancestor_level = std::get<double>(
Manager::Instance().getVariable(
"hasAncestor(" + std::to_string(pdg_code) +
", 0)")->function(p));
3307 if ((ancestor_level <= 0) or (std::isnan(ancestor_level)))
3312 const MCParticle* i_p = p->getMCParticle();
3314 for (
int a = 0; a < ancestor_level ; a = a + 1)
3316 i_p = i_p->getMother();
3320 StoreArray<Particle> particles;
3321 Particle* newPart = particles.appendNew(m_p);
3322 newPart->addRelationTo(i_p);
3324 appendDaughtersRecursive(newPart);
3326 auto var_result = var->function(newPart);
3327 if (std::holds_alternative<double>(var_result))
3329 return std::get<double>(var_result);
3330 }
else if (std::holds_alternative<int>(var_result))
3332 return std::get<int>(var_result);
3333 }
else if (std::holds_alternative<bool>(var_result))
3335 return std::get<bool>(var_result);
3340 B2FATAL(
"Wrong number of arguments for meta function varForFirstMCAncestorOfType (expected 2: type and variable of interest)");
3346 if (arguments.size() != 1) {
3347 B2FATAL(
"Number of arguments for nTrackFitResults must be 1, particleType or PDGcode");
3350 std::string arg = arguments[0];
3351 TParticlePDG* part = TDatabasePDG::Instance()->GetParticle(arg.c_str());
3353 if (part !=
nullptr) {
3354 absPdg = std::abs(part->PdgCode());
3357 absPdg = Belle2::convertString<int>(arg);
3358 }
catch (std::exception& e) {}
3361 auto func = [absPdg](
const Particle*) ->
int {
3363 Const::ChargedStable type(absPdg);
3364 StoreArray<Track> tracks;
3366 int nTrackFitResults = 0;
3368 for (
const auto& track : tracks)
3370 const TrackFitResult* trackFit = track.getTrackFitResultWithClosestMass(type);
3372 if (!trackFit)
continue;
3373 if (trackFit->getChargeSign() == 0)
continue;
3378 return nTrackFitResults;
3387 if (arguments.size() == 2) {
3389 int default_val = Belle2::convertString<int>(arguments[1]);
3390 auto func = [var, default_val](
const Particle * particle) ->
int {
3391 auto var_result = var->function(particle);
3392 if (std::holds_alternative<double>(var_result))
3394 double value = std::get<double>(var_result);
3395 if (value > std::numeric_limits<int>::max())
3396 value = std::numeric_limits<int>::max();
3397 if (value < std::numeric_limits<int>::min())
3398 value = std::numeric_limits<int>::min();
3399 if (std::isnan(value))
3400 value = default_val;
3401 return static_cast<int>(value);
3402 }
else if (std::holds_alternative<int>(var_result))
3403 return std::get<int>(var_result);
3404 else if (std::holds_alternative<bool>(var_result))
3405 return static_cast<int>(std::get<bool>(var_result));
3406 else return default_val;
3410 B2FATAL(
"Wrong number of arguments for meta function int, please provide variable name and replacement value for NaN!");
3414 VARIABLE_GROUP(
"MetaFunctions");
3415 REGISTER_METAVARIABLE(
"nCleanedECLClusters(cut)", nCleanedECLClusters,
3416 "[Eventbased] Returns the number of clean Clusters in the event\n"
3417 "Clean clusters are defined by the clusters which pass the given cut assuming a photon hypothesis.",
3418 Manager::VariableDataType::c_int);
3419 REGISTER_METAVARIABLE(
"nCleanedTracks(cut)", nCleanedTracks,
3420 "[Eventbased] Returns the number of clean Tracks in the event\n"
3421 "Clean tracks are defined by the tracks which pass the given cut assuming a pion hypothesis.", Manager::VariableDataType::c_int);
3422 REGISTER_METAVARIABLE(
"formula(v1 + v2 * [v3 - v4] / v5^v6)", formula, R
"DOCSTRING(
3423Returns the result of the given formula, where v1 to vN are variables or floating
3424point numbers. Currently the only supported operations are addition (``+``),
3425subtraction (``-``), multiplication (``*``), division (``/``) and power (``^``
3426or ``**``). Parenthesis can be in the form of square brackets ``[v1 * v2]``
3427or normal brackets ``(v1 * v2)``. It will work also with variables taking
3428arguments. Operator precedence is taken into account. For example ::
3430 (daughter(0, E) + daughter(1, E))**2 - p**2 + 0.138
3432.. versionchanged:: release-03-00-00
3433 now both, ``[]`` and ``()`` can be used for grouping operations, ``**`` can
3434 be used for exponent and float literals are possible directly in the
3436)DOCSTRING", Manager::VariableDataType::c_double);
3437 REGISTER_METAVARIABLE("useRestFrame(variable)", useRestFrame,
3438 "Returns the value of the variable using the rest frame of the given particle as current reference frame.\n"
3439 "E.g. ``useRestFrame(daughter(0, p))`` returns the total momentum of the first daughter in its mother's rest-frame", Manager::VariableDataType::c_double);
3440 REGISTER_METAVARIABLE(
"useCMSFrame(variable)", useCMSFrame,
3441 "Returns the value of the variable using the CMS frame as current reference frame.\n"
3442 "E.g. ``useCMSFrame(E)`` returns the energy of a particle in the CMS frame.", Manager::VariableDataType::c_double);
3443 REGISTER_METAVARIABLE(
"useLabFrame(variable)", useLabFrame, R
"DOC(
3444Returns the value of ``variable`` in the *lab* frame.
3447 The lab frame is the default reference frame, usually you don't need to use this meta-variable.
3448 E.g. ``useLabFrame(E)`` returns the energy of a particle in the Lab frame, same as just ``E``.
3450Specifying the lab frame is useful in some corner-cases. For example:
3451``useRestFrame(daughter(0, formula(E - useLabFrame(E))))`` which is the difference of the first daughter's energy in the rest frame of the mother (current particle) with the same daughter's lab-frame energy.
3452)DOC", Manager::VariableDataType::c_double);
3453 REGISTER_METAVARIABLE("useTagSideRecoilRestFrame(variable, daughterIndexTagB)", useTagSideRecoilRestFrame,
3454 "Returns the value of the variable in the rest frame of the recoiling particle to the tag side B meson.\n"
3455 "The variable should only be applied to an Upsilon(4S) list.\n"
3456 "E.g. ``useTagSideRecoilRestFrame(daughter(1, daughter(1, p)), 0)`` applied on a Upsilon(4S) list (``Upsilon(4S)->B+:tag B-:sig``) returns the momentum of the second daughter of the signal B meson in the signal B meson rest frame.", Manager::VariableDataType::c_double);
3457 REGISTER_METAVARIABLE(
"useParticleRestFrame(variable, particleList)", useParticleRestFrame,
3458 "Returns the value of the variable in the rest frame of the first Particle contained in the given ParticleList.\n"
3459 "It is strongly recommended to pass a ParticleList that contains at most only one Particle in each event. "
3460 "When more than one Particle is present in the ParticleList, only the first Particle in the list is used for "
3461 "computing the rest frame and a warning is thrown. If the given ParticleList is empty in an event, it returns NaN.", Manager::VariableDataType::c_double);
3462 REGISTER_METAVARIABLE(
"useRecoilParticleRestFrame(variable, particleList)", useRecoilParticleRestFrame,
3463 "Returns the value of the variable in the rest frame of recoil system against the first Particle contained in the given ParticleList.\n"
3464 "It is strongly recommended to pass a ParticleList that contains at most only one Particle in each event. "
3465 "When more than one Particle is present in the ParticleList, only the first Particle in the list is used for "
3466 "computing the rest frame and a warning is thrown. If the given ParticleList is empty in an event, it returns NaN.", Manager::VariableDataType::c_double);
3467 REGISTER_METAVARIABLE(
"useDaughterRestFrame(variable, daughterIndex_1, [daughterIndex_2, ... daughterIndex_3])", useDaughterRestFrame,
3468 "Returns the value of the variable in the rest frame of the selected daughter particle.\n"
3469 "The daughter is identified via generalized daughter index, e.g. ``0:1`` identifies the second daughter (1) "
3470 "of the first daughter (0). If the daughter index is invalid, it returns NaN.\n"
3471 "If two or more indices are given, the rest frame of the sum of the daughters is used.",
3472 Manager::VariableDataType::c_double);
3473 REGISTER_METAVARIABLE(
"useMCancestorBRestFrame(variable)", useMCancestorBRestFrame,
3474 "Returns the value of the variable in the rest frame of the ancestor B MC particle.\n"
3475 "If no B or no MC-matching is found, it returns NaN.", Manager::VariableDataType::c_double);
3476 REGISTER_METAVARIABLE(
"passesCut(cut)", passesCut,
3477 "Returns 1 if particle passes the cut otherwise 0.\n"
3478 "Useful if you want to write out if a particle would have passed a cut or not.", Manager::VariableDataType::c_bool);
3479 REGISTER_METAVARIABLE(
"passesEventCut(cut)", passesEventCut,
3480 "[Eventbased] Returns 1 if event passes the cut otherwise 0.\n"
3481 "Useful if you want to select events passing a cut without looping into particles, such as for skimming.\n", Manager::VariableDataType::c_bool);
3482 REGISTER_METAVARIABLE(
"countDaughters(cut)", countDaughters,
3483 "Returns number of direct daughters which satisfy the cut.\n"
3484 "Used by the skimming package (for what exactly?)", Manager::VariableDataType::c_int);
3485 REGISTER_METAVARIABLE(
"countFSPDaughters(cut)", countDescendants,
3486 "Returns number of final-state daughters which satisfy the cut.",
3487 Manager::VariableDataType::c_int);
3488 REGISTER_METAVARIABLE(
"countDescendants(cut)", countDescendants,
3489 "Returns number of descendants for all generations which satisfy the cut.",
3490 Manager::VariableDataType::c_int);
3491 REGISTER_METAVARIABLE(
"varFor(pdgCode, variable)", varFor,
3492 "Returns the value of the variable for the given particle if its abs(pdgCode) agrees with the given one.\n"
3493 "E.g. ``varFor(11, p)`` returns the momentum if the particle is an electron or a positron.", Manager::VariableDataType::c_double);
3494 REGISTER_METAVARIABLE(
"varForMCGen(variable)", varForMCGen,
3495 "Returns the value of the variable for the given particle if the MC particle related to it is primary, not virtual, and not initial.\n"
3496 "If no MC particle is related to the given particle, or the MC particle is not primary, virtual, or initial, NaN will be returned.\n"
3497 "E.g. ``varForMCGen(PDG)`` returns the PDG code of the MC particle related to the given particle if it is primary, not virtual, and not initial.", Manager::VariableDataType::c_double);
3498 REGISTER_METAVARIABLE(
"nParticlesInList(particleListName)", nParticlesInList,
3499 "[Eventbased] Returns number of particles in the given particle List.", Manager::VariableDataType::c_int);
3500 REGISTER_METAVARIABLE(
"isInList(particleListName)", isInList,
3501 "Returns 1 if the particle is in the list provided, 0 if not. Note that this only checks the particle given. For daughters of composite particles, please see :b2:var:`isDaughterOfList`.", Manager::VariableDataType::c_bool);
3502 REGISTER_METAVARIABLE(
"isDaughterOfList(particleListNames)", isDaughterOfList,
3503 "Returns 1 if the given particle is a daughter of at least one of the particles in the given particle Lists.", Manager::VariableDataType::c_bool);
3504 REGISTER_METAVARIABLE(
"isDescendantOfList(particleListName[, anotherParticleListName][, generationFlag = -1])", isDescendantOfList, R
"DOC(
3505 Returns 1 if the given particle appears in the decay chain of the particles in the given ParticleLists.
3507 Passing an integer as the last argument, allows to check if the particle belongs to the specific generation:
3509 * ``isDescendantOfList(<particle_list>,1)`` returns 1 if particle is a daughter of the list,
3510 * ``isDescendantOfList(<particle_list>,2)`` returns 1 if particle is a granddaughter of the list,
3511 * ``isDescendantOfList(<particle_list>,3)`` returns 1 if particle is a great-granddaughter of the list, etc.
3512 * Default value is ``-1`` that is inclusive for all generations.
3513 )DOC", Manager::VariableDataType::c_bool);
3514 REGISTER_METAVARIABLE("isMCDescendantOfList(particleListName[, anotherParticleListName][, generationFlag = -1])", isMCDescendantOfList, R
"DOC(
3515 Returns 1 if the given particle is linked to the same MC particle as any reconstructed daughter of the decay lists.
3517 Passing an integer as the last argument, allows to check if the particle belongs to the specific generation:
3519 * ``isMCDescendantOfList(<particle_list>,1)`` returns 1 if particle is matched to the same particle as any daughter of the list,
3520 * ``isMCDescendantOfList(<particle_list>,2)`` returns 1 if particle is matched to the same particle as any granddaughter of the list,
3521 * ``isMCDescendantOfList(<particle_list>,3)`` returns 1 if particle is matched to the same particle as any great-granddaughter of the list, etc.
3522 * Default value is ``-1`` that is inclusive for all generations.
3524 It makes only sense for lists created with `fillParticleListFromMC` function with ``addDaughters=True`` argument.
3525 )DOC", Manager::VariableDataType::c_bool);
3527 REGISTER_METAVARIABLE("sourceObjectIsInList(particleListName)", sourceObjectIsInList, R
"DOC(
3528Returns 1 if the underlying mdst object (e.g. track, or cluster) was used to create a particle in ``particleListName``, 0 if not.
3531 This only makes sense for particles that are not composite. Returns -1 for composite particles.
3532)DOC", Manager::VariableDataType::c_int);
3534 REGISTER_METAVARIABLE("mcParticleIsInMCList(particleListName)", mcParticleIsInMCList, R
"DOC(
3535Returns 1 if the particle's matched MC particle is also matched to a particle in ``particleListName``
3536(or if either of the lists were filled from generator level `modularAnalysis.fillParticleListFromMC`.)
3538.. seealso:: :b2:var:`isMCDescendantOfList` to check daughters.
3539)DOC", Manager::VariableDataType::c_bool);
3541 REGISTER_METAVARIABLE("isGrandDaughterOfList(particleListNames)", isGrandDaughterOfList,
3542 "Returns 1 if the given particle is a grand daughter of at least one of the particles in the given particle Lists.", Manager::VariableDataType::c_bool);
3543 REGISTER_METAVARIABLE(
"originalParticle(variable)", originalParticle, R
"DOC(
3544 Returns value of variable for the original particle from which the given particle is copied.
3546 The copy of particle is created, for example, when the vertex fit updates the daughters and `modularAnalysis.copyParticles` is called.
3547 Returns NaN if the given particle is not copied and so there is no original particle.
3548 )DOC", Manager::VariableDataType::c_double);
3549 REGISTER_METAVARIABLE("daughter(i, variable)", daughter, R
"DOC(
3550 Returns value of variable for the i-th daughter. E.g.
3552 * ``daughter(0, p)`` returns the total momentum of the first daughter.
3553 * ``daughter(0, daughter(1, p)`` returns the total momentum of the second daughter of the first daughter.
3555 Returns NaN if particle is nullptr or if the given daughter-index is out of bound (>= amount of daughters).
3556 )DOC", Manager::VariableDataType::c_double);
3557 REGISTER_METAVARIABLE("originalDaughter(i, variable)", originalDaughter, R
"DOC(
3558 Returns value of variable for the original particle from which the i-th daughter is copied.
3560 The copy of particle is created, for example, when the vertex fit updates the daughters and `modularAnalysis.copyParticles` is called.
3561 Returns NaN if the daughter is not copied and so there is no original daughter.
3563 Returns NaN if particle is nullptr or if the given daughter-index is out of bound (>= amount of daughters).
3564 )DOC", Manager::VariableDataType::c_double);
3565 REGISTER_METAVARIABLE("mcDaughter(i, variable)", mcDaughter, R
"DOC(
3566 Returns the value of the requested variable for the i-th Monte Carlo daughter of the particle.
3568 Returns NaN if the particle is nullptr, if the particle is not matched to an MC particle,
3569 or if the i-th MC daughter does not exist.
3571 E.g. ``mcDaughter(0, PDG)`` will return the PDG code of the first MC daughter of the matched MC
3572 particle of the reconstructed particle the function is applied to.
3574 The meta variable can also be nested: ``mcDaughter(0, mcDaughter(1, PDG))``.
3575 )DOC", Manager::VariableDataType::c_double);
3576 REGISTER_METAVARIABLE("mcMother(variable)", mcMother, R
"DOC(
3577 Returns the value of the requested variable for the Monte Carlo mother of the particle.
3579 Returns NaN if the particle is nullptr, if the particle is not matched to an MC particle,
3580 or if the MC mother does not exist.
3582 E.g. ``mcMother(PDG)`` will return the PDG code of the MC mother of the matched MC
3583 particle of the reconstructed particle the function is applied to.
3585 The meta variable can also be nested: ``mcMother(mcMother(PDG))``.
3586 )DOC", Manager::VariableDataType::c_double);
3587 REGISTER_METAVARIABLE("genParticle(index, variable)", genParticle, R
"DOC(
3588[Eventbased] Returns the ``variable`` for the ith generator particle.
3589The arguments of the function must be the ``index`` of the particle in the MCParticle Array,
3590and ``variable``, the name of the function or variable for that generator particle.
3591If ``index`` goes beyond the length of the MCParticles array, NaN will be returned.
3593E.g. ``genParticle(0, p)`` returns the total momentum of the first MCParticle, which in a generic decay up to MC15 is
3594the Upsilon(4S) and for MC16 and beyond the initial electron.
3595)DOC", Manager::VariableDataType::c_double);
3596 REGISTER_METAVARIABLE("genUpsilon4S(variable)", genUpsilon4S, R
"DOC(
3597[Eventbased] Returns the ``variable`` evaluated for the generator-level :math:`\Upsilon(4S)`.
3598If no generator level :math:`\Upsilon(4S)` exists for the event, NaN will be returned.
3600E.g. ``genUpsilon4S(p)`` returns the total momentum of the :math:`\Upsilon(4S)` in a generic decay.
3601``genUpsilon4S(mcDaughter(1, p))`` returns the total momentum of the second daughter of the
3602generator-level :math:`\Upsilon(4S)` (i.e. the momentum of the second B meson in a generic decay).
3603)DOC", Manager::VariableDataType::c_double);
3604 REGISTER_METAVARIABLE("daughterProductOf(variable)", daughterProductOf,
3605 "Returns product of a variable over all daughters.\n"
3606 "E.g. ``daughterProductOf(extraInfo(SignalProbability))`` returns the product of the SignalProbabilitys of all daughters.", Manager::VariableDataType::c_double);
3607 REGISTER_METAVARIABLE(
"daughterSumOf(variable)", daughterSumOf,
3608 "Returns sum of a variable over all daughters.\n"
3609 "E.g. ``daughterSumOf(nDaughters)`` returns the number of grand-daughters.", Manager::VariableDataType::c_double);
3610 REGISTER_METAVARIABLE(
"daughterLowest(variable)", daughterLowest,
3611 "Returns the lowest value of the given variable among all daughters.\n"
3612 "E.g. ``useCMSFrame(daughterLowest(p))`` returns the lowest momentum in CMS frame.", Manager::VariableDataType::c_double);
3613 REGISTER_METAVARIABLE(
"daughterHighest(variable)", daughterHighest,
3614 "Returns the highest value of the given variable among all daughters.\n"
3615 "E.g. ``useCMSFrame(daughterHighest(p))`` returns the highest momentum in CMS frame.", Manager::VariableDataType::c_double);
3616 REGISTER_METAVARIABLE(
"daughterDiffOf(daughterIndex_i, daughterIndex_j, variable)", daughterDiffOf, R
"DOC(
3617 Returns the difference of a variable between the two given daughters.
3618 E.g. ``useRestFrame(daughterDiffOf(0, 1, p))`` returns the momentum difference between first and second daughter in the rest frame of the given particle.
3619 (That means that it returns :math:`p_j - p_i`)
3621 The daughters can be provided as generalized daughter indexes, which are simply colon-separated
3622 lists of daughter indexes, ordered starting from the root particle. For example, ``0:1``
3623 identifies the second daughter (1) of the first daughter (0) of the mother particle.
3625 )DOC", Manager::VariableDataType::c_double);
3626 REGISTER_METAVARIABLE("mcDaughterDiffOf(i, j, variable)", mcDaughterDiffOf,
3627 "MC matched version of the `daughterDiffOf` function.", Manager::VariableDataType::c_double);
3628 REGISTER_METAVARIABLE(
"grandDaughterDiffOf(i, j, variable)", grandDaughterDiffOf,
3629 "Returns the difference of a variable between the first daughters of the two given daughters.\n"
3630 "E.g. ``useRestFrame(grandDaughterDiffOf(0, 1, p))`` returns the momentum difference between the first daughters of the first and second daughter in the rest frame of the given particle.\n"
3631 "(That means that it returns :math:`p_j - p_i`)", Manager::VariableDataType::c_double);
3632 MAKE_DEPRECATED(
"grandDaughterDiffOf",
false,
"light-2402-ocicat", R
"DOC(
3633 The difference between any combination of (grand-)daughters can be calculated with the more general variable :b2:var:`daughterDiffOf`
3634 by using generalized daughter indexes.)DOC");
3635 REGISTER_METAVARIABLE("daughterDiffOfPhi(i, j)", daughterDiffOfPhi,
3636 "Returns the difference in :math:`\\phi` between the two given daughters. The unit of the angle is ``rad``.\n"
3637 "The difference is signed and takes account of the ordering of the given daughters.\n"
3638 "The function returns :math:`\\phi_j - \\phi_i`.", Manager::VariableDataType::c_double);
3640 The difference of the azimuthal angle :math:`\\phi` of two daughters can be calculated with the generic variable :b2:var:`daughterDiffOf`.)DOC");
3641 REGISTER_METAVARIABLE("mcDaughterDiffOfPhi(i, j)", mcDaughterDiffOfPhi,
3642 "MC matched version of the `daughterDiffOfPhi` function. The unit of the angle is ``rad``", Manager::VariableDataType::c_double);
3643 MAKE_DEPRECATED(
"mcDaughterDiffOfPhi",
true,
"release-06-00-00", R
"DOC(
3644 The difference of the azimuthal angle :math:`\\phi` of the MC partners of two daughters can be calculated with the generic variable :b2:var:`mcDaughterDiffOf`.)DOC");
3645 REGISTER_METAVARIABLE("grandDaughterDiffOfPhi(i, j)", grandDaughterDiffOfPhi,
3646 "Returns the difference in :math:`\\phi` between the first daughters of the two given daughters. The unit of the angle is ``rad``.\n"
3647 "The difference is signed and takes account of the ordering of the given daughters.\n"
3648 "The function returns :math:`\\phi_j - \\phi_i`.\n", Manager::VariableDataType::c_double);
3649 MAKE_DEPRECATED(
"grandDaughterDiffOfPhi",
true,
"release-06-00-00", R
"DOC(
3650 The difference of the azimuthal angle :math:`\\phi` of two granddaughters can be calculated with the generic variable :b2:var:`grandDaughterDiffOf`.)DOC");
3651 REGISTER_METAVARIABLE("daughterDiffOfClusterPhi(i, j)", daughterDiffOfClusterPhi,
3652 "Returns the difference in :math:`\\phi` between the ECLClusters of two given daughters. The unit of the angle is ``rad``.\n"
3653 "The difference is signed and takes account of the ordering of the given daughters.\n"
3654 "The function returns :math:`\\phi_j - \\phi_i`.\n"
3655 "The function returns NaN if at least one of the daughters is not matched to or not based on an ECLCluster.", Manager::VariableDataType::c_double);
3656 MAKE_DEPRECATED(
"daughterDiffOfClusterPhi",
true,
"release-06-00-00", R
"DOC(
3657 The difference of the azimuthal angle :math:`\\phi` of the related ECL clusters of two daughters can be calculated with the generic variable :b2:var:`daughterDiffOf`.)DOC");
3658 REGISTER_METAVARIABLE("grandDaughterDiffOfClusterPhi(i, j)", grandDaughterDiffOfClusterPhi,
3659 "Returns the difference in :math:`\\phi` between the ECLClusters of the daughters of the two given daughters. The unit of the angle is ``rad``.\n"
3660 "The difference is signed and takes account of the ordering of the given daughters.\n"
3661 "The function returns :math:`\\phi_j - \\phi_i`.\n"
3662 "The function returns NaN if at least one of the daughters is not matched to or not based on an ECLCluster.\n", Manager::VariableDataType::c_double);
3663 MAKE_DEPRECATED(
"grandDaughterDiffOfClusterPhi",
true,
"release-06-00-00", R
"DOC(
3664 The difference of the azimuthal angle :math:`\\phi` of the related ECL clusters of two granddaughters can be calculated with the generic variable :b2:var:`grandDaughterDiffOf`.)DOC");
3665 REGISTER_METAVARIABLE("daughterDiffOfPhiCMS(i, j)", daughterDiffOfPhiCMS,
3666 "Returns the difference in :math:`\\phi` between the two given daughters in the CMS frame. The unit of the angle is ``rad``.\n"
3667 "The difference is signed and takes account of the ordering of the given daughters.\n"
3668 "The function returns :math:`\\phi_j - \\phi_i`.", Manager::VariableDataType::c_double);
3669 MAKE_DEPRECATED(
"daughterDiffOfPhiCMS",
true,
"release-06-00-00", R
"DOC(
3670 The difference of the azimuthal angle :math:`\\phi` of two daughters in the CMS frame can be calculated with the generic variable :b2:var:`daughterDiffOf`.)DOC");
3671 REGISTER_METAVARIABLE("mcDaughterDiffOfPhiCMS(i, j)", daughterDiffOfPhiCMS,
3672 "MC matched version of the `daughterDiffOfPhiCMS` function. The unit of the angle is ``rad``", Manager::VariableDataType::c_double);
3673 MAKE_DEPRECATED(
"mcDaughterDiffOfPhiCMS",
true,
"release-06-00-00", R
"DOC(
3674 The difference of the azimuthal angle :math:`\\phi` of the MC partners of two daughters in the CMS frame can be calculated with the generic variable :b2:var:`mcDaughterDiffOf`.)DOC");
3675 REGISTER_METAVARIABLE("daughterDiffOfClusterPhiCMS(i, j)", daughterDiffOfClusterPhiCMS,
3676 "Returns the difference in :math:`\\phi` between the ECLClusters of two given daughters in the CMS frame. The unit of the angle is ``rad``.\n"
3677 "The difference is signed and takes account of the ordering of the given daughters.\n"
3678 "The function returns :math:`\\phi_j - \\phi_i``.\n"
3679 "The function returns NaN if at least one of the daughters is not matched to or not based on an ECLCluster.", Manager::VariableDataType::c_double);
3680 MAKE_DEPRECATED(
"daughterDiffOfClusterPhiCMS",
true,
"release-06-00-00", R
"DOC(
3681 The difference of the azimuthal angle :math:`\\phi` of the related ECL clusters of two daughters in the CMS frame can be calculated with the generic variable :b2:var:`daughterDiffOf`.)DOC");
3682 REGISTER_METAVARIABLE("daughterNormDiffOf(i, j, variable)", daughterNormDiffOf,
3683 "Returns the normalized difference of a variable between the two given daughters.\n"
3684 "E.g. ``daughterNormDiffOf(0, 1, p)`` returns the normalized momentum difference between first and second daughter in the lab frame.", Manager::VariableDataType::c_double);
3685 REGISTER_METAVARIABLE(
"daughterMotherDiffOf(i, variable)", daughterMotherDiffOf,
3686 "Returns the difference of a variable between the given daughter and the mother particle itself.\n"
3687 "E.g. ``useRestFrame(daughterMotherDiffOf(0, p))`` returns the momentum difference between the given particle and its first daughter in the rest frame of the mother.", Manager::VariableDataType::c_double);
3688 REGISTER_METAVARIABLE(
"daughterMotherNormDiffOf(i, variable)", daughterMotherNormDiffOf,
3689 "Returns the normalized difference of a variable between the given daughter and the mother particle itself.\n"
3690 "E.g. ``daughterMotherNormDiffOf(1, p)`` returns the normalized momentum difference between the given particle and its second daughter in the lab frame.", Manager::VariableDataType::c_double);
3691 REGISTER_METAVARIABLE(
"daughterAngle(daughterIndex_1, daughterIndex_2[, daughterIndex_3])", daughterAngle, R
"DOC(
3692 Returns the angle in between any pair of particles belonging to the same decay tree.
3693 The unit of the angle is ``rad``.
3695 The particles are identified via generalized daughter indexes, which are simply colon-separated lists of
3696 daughter indexes, ordered starting from the root particle. For example, ``0:1:3`` identifies the fourth
3697 daughter (3) of the second daughter (1) of the first daughter (0) of the mother particle. ``1`` simply
3698 identifies the second daughter of the root particle.
3700 Both two and three generalized indexes can be given to ``daughterAngle``. If two indices are given, the
3701 variable returns the angle between the momenta of the two given particles. If three indices are given, the
3702 variable returns the angle between the momentum of the third particle and a vector which is the sum of the
3703 first two daughter momenta.
3706 ``daughterAngle(0, 3)`` will return the angle between the first and fourth daughter.
3707 ``daughterAngle(0, 1, 3)`` will return the angle between the fourth daughter and the sum of the first and
3709 ``daughterAngle(0:0, 3:0)`` will return the angle between the first daughter of the first daughter, and
3710 the first daughter of the fourth daughter.
3712 )DOC", Manager::VariableDataType::c_double);
3713 REGISTER_METAVARIABLE("mcDaughterAngle(daughterIndex_1, daughterIndex_2, [daughterIndex_3])", mcDaughterAngle,
3714 "MC matched version of the `daughterAngle` function. Also works if applied directly to MC particles. The unit of the angle is ``rad``", Manager::VariableDataType::c_double);
3715 REGISTER_VARIABLE(
"grandDaughterDecayAngle(i, j)", grandDaughterDecayAngle,
3716 "Returns the decay angle of the granddaughter in the daughter particle's rest frame.\n"
3717 "It is calculated with respect to the reverted momentum vector of the particle.\n"
3718 "Two arguments representing the daughter and granddaughter indices have to be provided as arguments.\n\n",
"rad");
3719 REGISTER_VARIABLE(
"daughterClusterAngleInBetween(i, j)", daughterClusterAngleInBetween,
3720 "Returns the angle between clusters associated to the two daughters."
3721 "If two indices given: returns the angle between the momenta of the clusters associated to the two given daughters."
3722 "If three indices given: returns the angle between the momentum of the third particle's cluster and a vector "
3723 "which is the sum of the first two daughter's cluster momenta."
3724 "Returns nan if any of the daughters specified don't have an associated cluster."
3725 "The arguments in the argument vector must be integers corresponding to the ith and jth (and kth) daughters.\n\n",
"rad");
3726 REGISTER_METAVARIABLE(
"daughterInvM(i[, j, ...])", daughterInvM, R
"DOC(
3727 Returns the invariant mass adding the Lorentz vectors of the given daughters. The unit of the invariant mass is GeV/:math:`\text{c}^2`
3728 E.g. ``daughterInvM(0, 1, 2)`` returns the invariant Mass :math:`m = \sqrt{(p_0 + p_1 + p_2)^2}` of the first, second and third daughter.
3730 Daughters from different generations of the decay tree can be combined using generalized daughter indexes,
3731 which are simply colon-separated daughter indexes for each generation, starting from the root particle. For
3732 example, ``0:1:3`` identifies the fourth daughter (3) of the second daughter (1) of the first daughter(0) of
3733 the mother particle.
3735 Returns NaN if the given daughter-index is out of bound (>= number of daughters))DOC", Manager::VariableDataType::c_double);
3736 REGISTER_METAVARIABLE("extraInfo(name)", extraInfo,
3737 "Returns extra info stored under the given name.\n"
3738 "The extraInfo has to be set by a module first.\n"
3739 "E.g. ``extraInfo(SignalProbability)`` returns the SignalProbability calculated by the ``MVAExpert`` module.\n"
3740 "If nothing is set under the given name or if the particle is a nullptr, NaN is returned.\n"
3741 "In the latter case please use `eventExtraInfo` if you want to access an EventExtraInfo variable.", Manager::VariableDataType::c_double);
3742 REGISTER_METAVARIABLE(
"eventExtraInfo(name)", eventExtraInfo,
3743 "[Eventbased] Returns extra info stored under the given name in the event extra info.\n"
3744 "The extraInfo has to be set first by another module like MVAExpert in event mode.\n"
3745 "If nothing is set under this name, NaN is returned.", Manager::VariableDataType::c_double);
3746 REGISTER_METAVARIABLE(
"eventCached(variable)", eventCached,
3747 "[Eventbased] Returns value of event-based variable and caches this value in the EventExtraInfo.\n"
3748 "The result of second call to this variable in the same event will be provided from the cache.\n"
3749 "It is recommended to use this variable in order to declare custom aliases as event-based. This is "
3750 "necessary if using the eventwise mode of variablesToNtuple).", Manager::VariableDataType::c_double);
3751 REGISTER_METAVARIABLE(
"particleCached(variable)", particleCached,
3752 "Returns value of given variable and caches this value in the ParticleExtraInfo of the provided particle.\n"
3753 "The result of second call to this variable on the same particle will be provided from the cache.", Manager::VariableDataType::c_double);
3754 REGISTER_METAVARIABLE(
"modulo(variable, n)", modulo,
3755 "Returns rest of division of variable by n.", Manager::VariableDataType::c_int);
3756 REGISTER_METAVARIABLE(
"abs(variable)", abs,
3757 "Returns absolute value of the given variable.\n"
3758 "E.g. abs(mcPDG) returns the absolute value of the mcPDG, which is often useful for cuts.", Manager::VariableDataType::c_double);
3759 REGISTER_METAVARIABLE(
"max(var1,var2)", max,
"Returns max value of two variables.\n", Manager::VariableDataType::c_double);
3760 REGISTER_METAVARIABLE(
"min(var1,var2)", min,
"Returns min value of two variables.\n", Manager::VariableDataType::c_double);
3761 REGISTER_METAVARIABLE(
"sin(variable)", sin,
"Returns sine value of the given variable.", Manager::VariableDataType::c_double);
3762 REGISTER_METAVARIABLE(
"asin(variable)", asin,
"Returns arcsine of the given variable. The unit of the asin() is ``rad``", Manager::VariableDataType::c_double);
3763 REGISTER_METAVARIABLE(
"cos(variable)", cos,
"Returns cosine value of the given variable.", Manager::VariableDataType::c_double);
3764 REGISTER_METAVARIABLE(
"acos(variable)", acos,
"Returns arccosine value of the given variable. The unit of the acos() is ``rad``", Manager::VariableDataType::c_double);
3765 REGISTER_METAVARIABLE(
"tan(variable)", tan,
"Returns tangent value of the given variable.", Manager::VariableDataType::c_double);
3766 REGISTER_METAVARIABLE(
"atan(variable)", atan,
"Returns arctangent value of the given variable. The unit of the atan() is ``rad``", Manager::VariableDataType::c_double);
3767 REGISTER_METAVARIABLE(
"exp(variable)", exp,
"Returns exponential evaluated for the given variable.", Manager::VariableDataType::c_double);
3768 REGISTER_METAVARIABLE(
"log(variable)", log,
"Returns natural logarithm evaluated for the given variable.", Manager::VariableDataType::c_double);
3769 REGISTER_METAVARIABLE(
"log10(variable)", log10,
"Returns base-10 logarithm evaluated for the given variable.", Manager::VariableDataType::c_double);
3770 REGISTER_METAVARIABLE(
"int(variable, nan_replacement)", convertToInt, R
"DOC(
3771 Casts the output of the variable to an integer value.
3774 Overflow and underflow are clipped at maximum and minimum values, respectively. NaN values are replaced with the value of the 2nd argument.
3776 )DOC", Manager::VariableDataType::c_int);
3777 REGISTER_METAVARIABLE("isNAN(variable)", isNAN,
3778 "Returns true if variable value evaluates to nan (determined via std::isnan(double)).\n"
3779 "Useful for debugging.", Manager::VariableDataType::c_bool);
3780 REGISTER_METAVARIABLE(
"ifNANgiveX(variable, x)", ifNANgiveX,
3781 "Returns x (has to be a number) if variable value is nan (determined via std::isnan(double)).\n"
3782 "Useful for technical purposes while training MVAs.", Manager::VariableDataType::c_double);
3783 REGISTER_METAVARIABLE(
"isInfinity(variable)", isInfinity,
3784 "Returns true if variable value evaluates to infinity (determined via std::isinf(double)).\n"
3785 "Useful for debugging.", Manager::VariableDataType::c_bool);
3786 REGISTER_METAVARIABLE(
"unmask(variable, flag1, flag2, ...)", unmask,
3787 "unmask(variable, flag1, flag2, ...) or unmask(variable, mask) sets certain bits in the variable to zero.\n"
3788 "For example, if you want to set the second, fourth and fifth bits to zero, you could call \n"
3789 "``unmask(variable, 2, 8, 16)`` or ``unmask(variable, 26)``.\n"
3790 "", Manager::VariableDataType::c_double);
3791 REGISTER_METAVARIABLE(
"conditionalVariableSelector(cut, variableIfTrue, variableIfFalse)", conditionalVariableSelector,
3792 "Returns one of the two supplied variables, depending on whether the particle passes the supplied cut.\n"
3793 "The first variable is returned if the particle passes the cut, and the second variable is returned otherwise.", Manager::VariableDataType::c_double);
3794 REGISTER_METAVARIABLE(
"pValueCombination(p1, p2, ...)", pValueCombination,
3795 "Returns the combined p-value of the provided p-values according to the formula given in `Nucl. Instr. and Meth. A 411 (1998) 449 <https://doi.org/10.1016/S0168-9002(98)00293-9>`_ .\n"
3796 "If any of the p-values is invalid, i.e. smaller than zero, -1 is returned.", Manager::VariableDataType::c_double);
3797 REGISTER_METAVARIABLE(
"veto(particleList, cut, pdgCode = 11)", veto,
3798 "Combines current particle with particles from the given particle list and returns 1 if the combination passes the provided cut. \n"
3799 "For instance one can apply this function on a signal Photon and provide a list of all photons in the rest of event and a cut \n"
3800 "around the neutral Pion mass (e.g. ``0.130 < M < 0.140``). \n"
3801 "If a combination of the signal Photon with a ROE photon fits this criteria, hence looks like a neutral pion, the veto-Metavariable will return 1", Manager::VariableDataType::c_bool);
3802 REGISTER_METAVARIABLE(
"matchedMC(variable)", matchedMC,
3803 "Returns variable output for the matched MCParticle by constructing a temporary Particle from it.\n"
3804 "This may not work too well if your variable requires accessing daughters of the particle.\n"
3805 "E.g. ``matchedMC(p)`` returns the total momentum of the related MCParticle.\n"
3806 "Returns NaN if no matched MCParticle exists.", Manager::VariableDataType::c_double);
3807 REGISTER_METAVARIABLE(
"clusterBestMatchedMCParticle(variable)", clusterBestMatchedMCParticle,
3808 "Returns variable output for the MCParticle that is best-matched with the ECLCluster of the given Particle.\n"
3809 "E.g. To get the energy of the MCParticle that matches best with an ECLCluster, one could use ``clusterBestMatchedMCParticle(E)``\n"
3810 "When the variable is called for ``gamma`` and if the ``gamma`` is matched with MCParticle, it works same as `matchedMC`.\n"
3811 "If the variable is called for ``gamma`` that fails to match with an MCParticle, it provides the mdst-level MCMatching information abouth the ECLCluster.\n"
3812 "Returns NaN if the particle is not matched to an ECLCluster, or if the ECLCluster has no matching MCParticles", Manager::VariableDataType::c_double);
3813 REGISTER_METAVARIABLE(
"varForBestMatchedMCKlong(variable)", clusterBestMatchedMCKlong,
3814 "Returns variable output for the Klong MCParticle which has the best match with the ECLCluster of the given Particle.\n"
3815 "Returns NaN if the particle is not matched to an ECLCluster, or if the ECLCluster has no matching Klong MCParticle", Manager::VariableDataType::c_double);
3817 REGISTER_METAVARIABLE(
"countInList(particleList, cut='')", countInList,
"[Eventbased] "
3818 "Returns number of particle which pass given in cut in the specified particle list.\n"
3819 "Useful for creating statistics about the number of particles in a list.\n"
3820 "E.g. ``countInList(e+, isSignal == 1)`` returns the number of correctly reconstructed electrons in the event.\n"
3821 "The variable is event-based and does not need a valid particle pointer as input.", Manager::VariableDataType::c_int);
3822 REGISTER_METAVARIABLE(
"getVariableByRank(particleList, rankedVariableName, variableName, rank)", getVariableByRank, R
"DOC(
3823 [Eventbased] Returns the value of ``variableName`` for the candidate in the ``particleList`` with the requested ``rank``.
3826 The `BestCandidateSelection` module available via `rankByHighest` / `rankByLowest` has to be used before.
3829 The first candidate matching the given rank is used.
3830 Thus, it is not recommended to use this variable in conjunction with ``allowMultiRank`` in the `BestCandidateSelection` module.
3832 The suffix ``_rank`` is automatically added to the argument ``rankedVariableName``,
3833 which either has to be the name of the variable used to order the candidates or the selected outputVariable name without the ending ``_rank``.
3834 This means that your selected name for the rank variable has to end with ``_rank``.
3836 An example of this variable's usage is given in the tutorial `B2A602-BestCandidateSelection <https://gitlab.desy.de/belle2/software/basf2/-/tree/main/analysis/examples/tutorials/B2A602-BestCandidateSelection.py>`_
3837 )DOC", Manager::VariableDataType::c_double);
3838 REGISTER_VARIABLE("matchedMCHasPDG(PDGCode)", matchedMCHasPDG,
3839 "Returns if the absolute value of the PDGCode of the MCParticle related to the Particle matches a given PDGCode."
3840 "Returns 0/NAN/1 if PDGCode does not match/is not available/ matches");
3841 REGISTER_METAVARIABLE(
"numberOfNonOverlappingParticles(pList1, pList2, ...)", numberOfNonOverlappingParticles,
3842 "Returns the number of non-overlapping particles in the given particle lists"
3843 "Useful to check if there is additional physics going on in the detector if one reconstructed the Y4S", Manager::VariableDataType::c_int);
3844 REGISTER_METAVARIABLE(
"totalEnergyOfParticlesInList(particleListName)", totalEnergyOfParticlesInList,
3845 "[Eventbased] Returns the total energy of particles in the given particle List. The unit of the energy is ``GeV``", Manager::VariableDataType::c_double);
3846 REGISTER_METAVARIABLE(
"totalPxOfParticlesInList(particleListName)", totalPxOfParticlesInList,
3847 "[Eventbased] Returns the total momentum Px of particles in the given particle List. The unit of the momentum is ``GeV/c``", Manager::VariableDataType::c_double);
3848 REGISTER_METAVARIABLE(
"totalPyOfParticlesInList(particleListName)", totalPyOfParticlesInList,
3849 "[Eventbased] Returns the total momentum Py of particles in the given particle List. The unit of the momentum is ``GeV/c``", Manager::VariableDataType::c_double);
3850 REGISTER_METAVARIABLE(
"totalPzOfParticlesInList(particleListName)", totalPzOfParticlesInList,
3851 "[Eventbased] Returns the total momentum Pz of particles in the given particle List. The unit of the momentum is ``GeV/c``", Manager::VariableDataType::c_double);
3852 REGISTER_METAVARIABLE(
"invMassInLists(pList1, pList2, ...)", invMassInLists,
3853 "[Eventbased] Returns the invariant mass of the combination of particles in the given particle lists. The unit of the invariant mass is GeV/:math:`\\text{c}^2` ", Manager::VariableDataType::c_double);
3854 REGISTER_METAVARIABLE(
"totalECLEnergyOfParticlesInList(particleListName)", totalECLEnergyOfParticlesInList,
3855 "[Eventbased] Returns the total ECL energy of particles in the given particle List. The unit of the energy is ``GeV``", Manager::VariableDataType::c_double);
3856 REGISTER_METAVARIABLE(
"maxPtInList(particleListName)", maxPtInList,
3857 "[Eventbased] Returns maximum transverse momentum Pt in the given particle List. The unit of the transverse momentum is ``GeV/c``", Manager::VariableDataType::c_double);
3858 REGISTER_METAVARIABLE(
"eclClusterSpecialTrackMatched(cut)", eclClusterTrackMatchedWithCondition,
3859 "Returns if at least one Track that satisfies the given condition is related to the ECLCluster of the Particle.", Manager::VariableDataType::c_double);
3860 REGISTER_METAVARIABLE(
"averageValueInList(particleListName, variable)", averageValueInList,
3861 "[Eventbased] Returns the arithmetic mean of the given variable of the particles in the given particle list.", Manager::VariableDataType::c_double);
3862 REGISTER_METAVARIABLE(
"medianValueInList(particleListName, variable)", medianValueInList,
3863 "[Eventbased] Returns the median value of the given variable of the particles in the given particle list.", Manager::VariableDataType::c_double);
3864 REGISTER_METAVARIABLE(
"sumValueInList(particleListName, variable)", sumValueInList,
3865 "[Eventbased] Returns the sum of the given variable of the particles in the given particle list.", Manager::VariableDataType::c_double);
3866 REGISTER_METAVARIABLE(
"productValueInList(particleListName, variable)", productValueInList,
3867 "[Eventbased] Returns the product of the given variable of the particles in the given particle list.", Manager::VariableDataType::c_double);
3868 REGISTER_METAVARIABLE(
"angleToClosestInList(particleListName)", angleToClosestInList,
3869 "Returns the angle between this particle and the closest particle (smallest opening angle) in the list provided. The unit of the angle is ``rad`` ", Manager::VariableDataType::c_double);
3870 REGISTER_METAVARIABLE(
"closestInList(particleListName, variable)", closestInList,
3871 "Returns `variable` for the closest particle (smallest opening angle) in the list provided.", Manager::VariableDataType::c_double);
3872 REGISTER_METAVARIABLE(
"angleToMostB2BInList(particleListName)", angleToMostB2BInList,
3873 "Returns the angle between this particle and the most back-to-back particle (closest opening angle to 180) in the list provided. The unit of the angle is ``rad`` ", Manager::VariableDataType::c_double);
3874 REGISTER_METAVARIABLE(
"deltaPhiToMostB2BPhiInList(particleListName)", deltaPhiToMostB2BPhiInList,
3875 "Returns the abs(delta phi) between this particle and the most back-to-back particle in phi (closest opening angle to 180) in the list provided. The unit of the angle is ``rad`` ", Manager::VariableDataType::c_double);
3876 REGISTER_METAVARIABLE(
"mostB2BInList(particleListName, variable)", mostB2BInList,
3877 "Returns `variable` for the most back-to-back particle (closest opening angle to 180) in the list provided.", Manager::VariableDataType::c_double);
3878 REGISTER_METAVARIABLE(
"maxOpeningAngleInList(particleListName)", maxOpeningAngleInList,
3879 "[Eventbased] Returns maximum opening angle in the given particle List. The unit of the angle is ``rad`` ", Manager::VariableDataType::c_double);
3880 REGISTER_METAVARIABLE(
"daughterCombination(variable, daughterIndex_1, daughterIndex_2 ... daughterIndex_n)", daughterCombination,R
"DOC(
3881Returns a ``variable`` function only of the 4-momentum calculated on an arbitrary set of (grand)daughters.
3884 ``variable`` can only be a function of the daughters' 4-momenta.
3886Daughters from different generations of the decay tree can be combined using generalized daughter indexes, which are simply colon-separated
3887the list of daughter indexes, starting from the root particle: for example, ``0:1:3`` identifies the fourth
3888daughter (3) of the second daughter (1) of the first daughter (0) of the mother particle.
3891 ``daughterCombination(M, 0, 3, 4)`` will return the invariant mass of the system made of the first, fourth and fifth daughter of particle.
3892 ``daughterCombination(M, 0:0, 3:0)`` will return the invariant mass of the system made of the first daughter of the first daughter and the first daughter of the fourth daughter.
3894)DOC", Manager::VariableDataType::c_double);
3895 REGISTER_METAVARIABLE("useAlternativeDaughterHypothesis(variable, daughterIndex_1:newMassHyp_1, ..., daughterIndex_n:newMassHyp_n)", useAlternativeDaughterHypothesis,R
"DOC(
3896Returns a ``variable`` calculated using new mass hypotheses for (some of) the particle's daughters.
3899 ``variable`` can only be a function of the particle 4-momentum, which is re-calculated as the sum of the daughters' 4-momenta, and the daughters' 4-momentum.
3900 This means that if you made a kinematic fit without updating the daughters' momenta, the result of this variable will not reflect the effect of the kinematic fit.
3901 Also, the track fit is not performed again: the variable only re-calculates the 4-vectors using different mass assumptions.
3902 In the variable, a copy of the given particle is created with daughters' alternative mass assumption (i.e. the original particle and daughters are not changed).
3905 Generalized daughter indexes are not supported (yet!): this variable can be used only on first-generation daughters.
3908 ``useAlternativeDaughterHypothesis(M, 0:K+, 2:pi-)`` will return the invariant mass of the particle assuming that the first daughter is a kaon and the third is a pion, instead of whatever was used in reconstructing the decay.
3909 ``useAlternativeDaughterHypothesis(mRecoil, 1:p+)`` will return the recoil mass of the particle assuming that the second daughter is a proton instead of whatever was used in reconstructing the decay.
3911)DOC", Manager::VariableDataType::c_double);
3912 REGISTER_METAVARIABLE("varForFirstMCAncestorOfType(type, variable)",varForFirstMCAncestorOfType,R
"DOC(Returns requested variable of the first ancestor of the given type.
3913Ancestor type can be set up by PDG code or by particle name (check evt.pdl for valid particle names))DOC", Manager::VariableDataType::c_double);
3915 REGISTER_METAVARIABLE("nTrackFitResults(particleType)", nTrackFitResults,
3916 "[Eventbased] Returns the total number of TrackFitResults for a given particleType. The argument can be the name of particle (e.g. pi+) or PDG code (e.g. 211).",
3917 Manager::VariableDataType::c_int);
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
int getPDGCode() const
PDG code.
static const ChargedStable pion
charged pion particle
static const double doubleNaN
quiet_NaN
static const ChargedStable electron
electron particle
EHypothesisBit
The hypothesis bits for this ECLCluster (Connected region (CR) is split using this hypothesis.
@ c_nPhotons
CR is split into n photons (N1)
static std::unique_ptr< GeneralCut > compile(const std::string &cut)
Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead y...
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
@ c_PrimaryParticle
bit 0: Particle is primary particle.
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
static std::string makeROOTCompatible(std::string str)
Remove special characters that ROOT dislikes in branch names, e.g.
const MCParticle * getMCParticle() const
Returns the pointer to the MCParticle object that was used to create this Particle (ParticleType == c...
EParticleSourceObject
particle source enumerators
const Particle * getParticleFromGeneralizedIndexString(const std::string &generalizedIndex) const
Explores the decay tree of the particle and returns the (grand^n)daughter identified by a generalized...
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
@ c_Unflavored
Is its own antiparticle or we don't know whether it is a particle/antiparticle.
@ c_Flavored
Is either particle or antiparticle.
static const ReferenceFrame & GetCurrent()
Get current rest frame.
std::function< VarVariant(const Particle *)> FunctionPtr
functions stored take a const Particle* and return VarVariant.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
Class to store variables with their name which were sent to the logging service.
#define MAKE_DEPRECATED(name, make_fatal, version, description)
Registers a variable as deprecated.
B2Vector3< double > B2Vector3D
typedef for common usage with double
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
bool hasAntiParticle(int pdgCode)
Checks if the particle with given pdg code has an anti-particle or not.
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Abstract base class for different kinds of events.
const std::vector< double > v2
MATLAB generated random vector.
const std::vector< double > v1
MATLAB generated random vector.