9#include <tracking/modules/spacePointCreator/PhaseSpaceAnalysisModule.h>
11#include <framework/dataobjects/EventMetaData.h>
12#include <framework/datastore/StoreObjPtr.h>
23 setDescription(
"Module for analysing the phase space covered by TrackCands (resp. their related MCParticles)");
25 std::vector<std::string> defaultNames = { std::string(
"") };
28 "If there are more 'containerNames' than 'trackCandTypes' the last type is assumed for all the names that cannot be matched"\
29 "one-to-one with a trackCandType. If there are as much names as types the i-th name is assumed to be of the i-th type");
32 "Use the first container as reference and only collect data for those MCParticle that"\
33 " cannot be found in the other containers.",
false);
35 std::vector<std::string> defaultRootFName = {
"PhaseSpaceAnalysis",
"RECREATE" };
37 " ('UPDATE' or 'RECREATE')", defaultRootFName);
47 B2INFO(
"PhaseSpaceAnalysis ------------------------ initialize --------------------------");
54 if (nTypes > nNames) { B2FATAL(
"Passed " << nTypes <<
" trackCandTypese but only " << nNames <<
" containerNames!"); }
56 for (
size_t iName = 0; iName < nNames; ++iName) {
57 size_t iType = iName < nTypes ? iName : nTypes - 1;
59 if (tcType.compare(std::string(
"GFTC")) != 0 && tcType.compare(std::string(
"SPTC")) != 0) {
60 B2FATAL(
"Found id " << tcType <<
" in 'trackCandTypes' but only 'GFTC' and 'SPTC' are allowed!");
64 if (tcType.compare(std::string(
"GFTC")) == 0) {
74 output +=
"'" +
id +
"' ";
76 B2FATAL(
"PhaseSpaceAnalysis::initialize() : rootFileName is set wrong: entries are: " << output);
93 const int eventCounter = eventMetaDataPtr->getEvent();
94 std::string arrayNames;
96 arrayNames +=
" " + name;
98 B2DEBUG(25,
"PhaseSpaceAnalysis::event(). Processing event " << eventCounter <<
" for StoreArray names :" << arrayNames);
101 B2DEBUG(25,
"Found " << nMCParticles <<
" MCParticles for this event");
103 std::vector<std::vector<int> > mcPartIds;
105 for (std::pair<boost::any, e_trackCandType> storeArray :
m_tcStoreArrays) {
107 if (storeArray.second ==
c_gftc) {
109 }
else if (storeArray.second ==
c_sptc) {
112 B2DEBUG(25, mcPartIds.back().size() <<
" MCParticles of this event were set for this container");
119 for (
size_t iTree = 0; iTree < mcPartIds.size(); ++iTree) {
120 B2DEBUG(25,
"Now collecting values for vector of MCParticle Ids " << iTree);
124 for (
int id : mcPartIds[iTree]) {
126 B2WARNING(
"Found a negative id in mcParticleId: " <<
id << \
127 ". It seems that it has not been set properly, I will skip this MC Particle");
132 if (mcParticle ==
nullptr) {
146 std::stringstream furtherInfo;
149 " nullptr pointers to MCParticles";
152 B2INFO(
"PhaseSpaceAnalysis::terminate(): Collected mcParticle info in " <<
m_PARAMcontainerNames.size() <<
" containers."\
153 " Collected information from " << nMCParts <<
" MCParticles and wrote them into " <<
m_treeNames.size() <<
" different trees."\
154 << furtherInfo.str());
157 std::stringstream output;
158 output <<
"tree-wise summary (no of mcParticles):";
159 for (
unsigned int ctr :
m_mcPartCtr) output <<
" " << ctr;
160 B2DEBUG(25, output.str());
166 for (TTree* tree :
m_treePtrs) { tree->Write(); }
174 B2DEBUG(25,
"initializing root file. fileName: " << fileName <<
", writeOption: " << writeOption);
175 m_rootFilePtr =
new TFile(fileName.c_str(), writeOption.c_str());
177 for (
size_t i = 0; i < treeNames.size(); ++i) {
178 TTree* tree =
new TTree(treeNames[i].c_str(),
"data of mc particles");
203 B2DEBUG(25,
"Collecting values for MCParticle " << mcParticle->
getArrayIndex());
205 const ROOT::Math::XYZVector momentum = mcParticle->
getMomentum();
206 rootVariables.
MomX.push_back(momentum.X());
207 rootVariables.
MomY.push_back(momentum.Y());
208 rootVariables.
MomZ.push_back(momentum.Z());
210 rootVariables.
pT.push_back(momentum.Rho());
211 rootVariables.
Eta.push_back(momentum.Eta());
213 B2DEBUG(25,
"XYZVector momentum: (" << momentum.X() <<
"," << momentum.Y() <<
"," << momentum.Z() << \
214 "). This leads to p_T = " << momentum.Rho() <<
" and eta = " << momentum.Eta());
216 const ROOT::Math::XYZVector vertex = mcParticle->
getVertex();
217 rootVariables.
VertX.push_back(vertex.Y());
218 rootVariables.
VertY.push_back(vertex.Y());
219 rootVariables.
VertZ.push_back(vertex.Z());
221 B2DEBUG(25,
"vertex: (" << vertex.X() <<
"," << vertex.Y() <<
"," << vertex.Z() <<
")");
225 rootVariables.
PDG.push_back(mcParticle->
getPDG());
226 rootVariables.
Mass.push_back(mcParticle->
getMass());
228 B2DEBUG(25,
"Charge " << mcParticle->
getCharge() <<
", PDG code" << mcParticle->
getPDG() <<
", Energy " << \
233template<
typename TrackCandType>
236 const int nTrackCands = trackCands.
getEntries();
237 B2DEBUG(25,
"In StoreArray " << trackCands.
getName() <<
": " << nTrackCands <<
" track candidates for this event");
238 std::vector<int> mcPartIds;
239 for (
int i = 0; i < nTrackCands; ++i) mcPartIds.push_back(trackCands[i]->getMcTrackId());
248 if (allIDs.size() < 2) {
249 B2DEBUG(25,
"There are no more than 1 vectors passed to getDiffIds. No comparison possible. Returning passed vector");
265 std::vector<std::vector<int> > diffIds;
266 std::vector<int> referenceIds = allIDs.at(0);
267 diffIds.push_back(referenceIds);
270 for (
size_t iVec = 1; iVec < allIDs.size(); ++iVec) {
271 std::vector<int> compareIds = allIDs[iVec];
272 diffIds.push_back(compareIds);
273 std::vector<int> notFoundIds;
274 for (
int id : referenceIds) {
275 if (find(compareIds.begin(), compareIds.end(),
id) == compareIds.end()) {
276 notFoundIds.push_back(
id);
279 diffIds.push_back(notFoundIds);
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
@ c_Debug
Debug: for code development.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
A Class to store the Monte Carlo particle information.
float getEnergy() const
Return particle energy in GeV.
float getMass() const
Return the particle mass in GeV.
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
float getCharge() const
Return the particle charge defined in TDatabasePDG.
int getPDG() const
Return PDG code of particle.
ROOT::Math::XYZVector getMomentum() const
Return momentum.
void setDescription(const std::string &description)
Sets the description of the module.
void initializeRootFile(std::string fileName, std::string writeOption, std::vector< std::string > treeNames)
create a root file with file name
std::vector< std::string > m_PARAMtrackCandTypes
types of the track candidates in containerNames
std::vector< unsigned int > m_mcPartCtr
container wise counter of TrackCands / MCParticles
void initialize() override
initialize
StoreArray< SpacePointTrackCand > m_SpacePointTrackCands
SpacePointTrackCands StoreArray.
RootVariables m_rootVariables
root variables used for collecting data event-wise
bool m_PARAMdiffAnalysis
take containers pair-wise and only analyze those particles that are found in one container but not in...
unsigned int m_noMcPartCtr
Counter for nullptr pointers to MC Particles (should always be zero.
void event() override
event
void terminate() override
terminate
std::vector< std::string > m_treeNames
names of the trees that are stored in the root file
StoreArray< genfit::TrackCand > m_GenfitTrackCands
Genfit::TrackCands StoreArray.
std::vector< std::string > m_PARAMrootFileName
name of the output root file name
unsigned int m_skippedTCsCtr
Counter for negative MC particle ids (should always be zero.
@ c_gftc
genfit::TrackCand
@ c_sptc
SpacePointTrackCand.
std::vector< TTree * > m_treePtrs
each container name gets its own tree in the root file
std::vector< std::string > m_PARAMcontainerNames
collection name of trackCands to be investigated
void initializeCounters(size_t nContainers)
initialize all counters to 0 to avoid undefined behavior
static std::vector< std::vector< int > > getDiffIds(const std::vector< std::vector< int > > &allIDs)
get all referee statuses from all SpacePointTrackCand
static void getValuesForRoot(Belle2::MCParticle *mcParticle, RootVariables &rootVariables)
collect the values for root output
static std::vector< int > getMCParticleIDs(Belle2::StoreArray< TrackCandType > trackCands)
get all MCPartileIDs of tracks
TFile * m_rootFilePtr
Pointer to root file.
StoreArray< MCParticle > m_MCParticles
MCParticles StoreArray.
PhaseSpaceAnalysisModule()
Constructor.
std::vector< std::pair< boost::any, e_trackCandType > > m_tcStoreArrays
StoreArrays of the containers.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
helper class to have all RootVariables assembled in one container
std::vector< double > Mass
mc particle mass
std::vector< double > Eta
pseudo rapidity.
std::vector< double > MomY
y momentum
std::vector< double > VertZ
z position of vertex
std::vector< double > MomX
x momentum
std::vector< int > PDG
mc particle pdg code
std::vector< double > MomZ
z momentum
std::vector< double > VertY
y position of vertex
std::vector< double > VertX
x position of vertex
std::vector< double > Charge
mc particle charge
std::vector< double > pT
transverse momentum.
std::vector< double > Energy
mc particle energy