File indexing completed on 2025-08-06 08:13:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define SCORRELATORUTILITIES_PARTOOLS_CC
0012
0013
0014 #include "ParTools.h"
0015
0016
0017 using namespace std;
0018
0019
0020
0021
0022
0023 namespace SColdQcdCorrelatorAnalysis {
0024
0025
0026
0027
0028 int Tools::GetSignal(const bool isEmbed) {
0029
0030 return isEmbed ? Const::SubEvt::EmbedSignal : Const::SubEvt::NotEmbedSignal;
0031
0032 }
0033
0034
0035
0036
0037
0038
0039 int Tools::GetEmbedID(PHCompositeNode* topNode, const int iEvtToGrab) {
0040
0041
0042 PHHepMCGenEvent* mcEvt = Interfaces::GetMcEvent(topNode, iEvtToGrab);
0043 return mcEvt -> get_embedding_id();
0044
0045 }
0046
0047
0048
0049
0050
0051
0052 int Tools::GetEmbedIDFromBarcode(const int barcode, PHCompositeNode* topNode) {
0053
0054
0055 int idEmbed = Const::SubEvt::NotEmbedSignal;
0056 bool foundBarcode = false;
0057
0058
0059 PHHepMCGenEventMap* mcEvtMap = Interfaces::GetMcEventMap(topNode);
0060 for (
0061 PHHepMCGenEventMap::ConstIter genEvt = mcEvtMap -> begin();
0062 genEvt != mcEvtMap -> end();
0063 ++genEvt
0064 ) {
0065
0066
0067 for (
0068 HepMC::GenEvent::particle_const_iterator hepPar = genEvt -> second -> getEvent() -> particles_begin();
0069 hepPar != genEvt -> second -> getEvent() -> particles_end();
0070 ++hepPar
0071 ) {
0072
0073
0074 if ((*hepPar) -> barcode() == barcode) {
0075 idEmbed = genEvt -> first;
0076 foundBarcode = true;
0077 break;
0078 }
0079 }
0080
0081
0082 if (foundBarcode) break;
0083
0084 }
0085 return idEmbed;
0086
0087 }
0088
0089
0090
0091
0092
0093
0094 int Tools::GetEmbedIDFromTrackID(const int idTrack, PHCompositeNode* topNode) {
0095
0096
0097 PHG4TruthInfoContainer* info = Interfaces::GetTruthContainer(topNode);
0098
0099
0100 return info -> isEmbeded(idTrack);
0101
0102 }
0103
0104
0105
0106
0107
0108
0109 bool Tools::IsFinalState(const int status) {
0110
0111 return (status == 1);
0112
0113 }
0114
0115
0116
0117
0118
0119
0120 bool Tools::IsSubEvtGood(
0121 const int embedID,
0122 const int option,
0123 const bool isEmbed
0124 ) {
0125
0126
0127 int signalID = Const::SubEvt::NotEmbedSignal;
0128 if (isEmbed) {
0129 signalID = Const::SubEvt::EmbedSignal;
0130 }
0131
0132 bool isSubEvtGood = true;
0133 switch (option) {
0134
0135
0136 case Const::SubEvtOpt::Everything:
0137 isSubEvtGood = true;
0138 break;
0139
0140
0141 case Const::SubEvtOpt::OnlySignal:
0142 isSubEvtGood = (embedID == signalID);
0143 break;
0144
0145
0146 case Const::SubEvtOpt::AllBkgd:
0147 isSubEvtGood = (embedID <= Const::SubEvt::Background);
0148 break;
0149
0150
0151 case Const::SubEvtOpt::PrimaryBkgd:
0152 isSubEvtGood = (embedID == Const::SubEvt::Background);
0153 break;
0154
0155
0156 case Const::SubEvtOpt::Pileup:
0157 isSubEvtGood = (embedID < Const::SubEvt::Background);
0158 break;
0159
0160
0161 default:
0162 isSubEvtGood = true;
0163 break;
0164 }
0165 return isSubEvtGood;
0166
0167 }
0168
0169
0170
0171
0172
0173
0174 bool Tools::IsSubEvtGood(const int embedID, vector<int> subEvtsToUse) {
0175
0176 bool isSubEvtGood = false;
0177 for (const int evtToUse : subEvtsToUse) {
0178 if (embedID == evtToUse) {
0179 isSubEvtGood = true;
0180 break;
0181 }
0182 }
0183 return isSubEvtGood;
0184
0185 }
0186
0187
0188
0189
0190
0191
0192 float Tools::GetParticleCharge(const int pid) {
0193
0194
0195 float charge = Const::MapPidOntoCharge()[abs(pid)];
0196
0197
0198 if (pid < 0) {
0199 charge *= -1.;
0200 }
0201 return charge;
0202
0203 }
0204
0205
0206
0207
0208
0209
0210 vector<int> Tools::GrabSubevents(
0211 PHCompositeNode* topNode,
0212 vector<int> subEvtsToUse
0213 ) {
0214
0215
0216 vector<int> subevents;
0217
0218 PHHepMCGenEventMap* mcEvtMap = Interfaces::GetMcEventMap(topNode);
0219 for (
0220 PHHepMCGenEventMap::ConstIter itEvt = mcEvtMap -> begin();
0221 itEvt != mcEvtMap -> end();
0222 ++itEvt
0223 ) {
0224
0225
0226 const int embedID = itEvt -> second -> get_embedding_id();
0227
0228
0229 bool addToList = false;
0230 for (const int idToCheck : subEvtsToUse) {
0231 if (embedID == idToCheck) {
0232 addToList = true;
0233 break;
0234 }
0235 }
0236
0237
0238 if (addToList) subevents.push_back(embedID);
0239
0240 }
0241 return subevents;
0242
0243 }
0244
0245
0246
0247
0248
0249
0250 vector<int> Tools::GrabSubevents(
0251 PHCompositeNode* topNode,
0252 const int option,
0253 const bool isEmbed
0254 ) {
0255
0256
0257 vector<int> subevents;
0258
0259 PHHepMCGenEventMap* mcEvtMap = Interfaces::GetMcEventMap(topNode);
0260 for (
0261 PHHepMCGenEventMap::ConstIter itEvt = mcEvtMap -> begin();
0262 itEvt != mcEvtMap -> end();
0263 ++itEvt
0264 ) {
0265
0266
0267 const int embedID = itEvt -> second -> get_embedding_id();
0268
0269
0270 const bool isSubEvtGood = IsSubEvtGood(embedID, option, isEmbed);
0271 if (isSubEvtGood) subevents.push_back(embedID);
0272 }
0273 return subevents;
0274
0275 }
0276
0277
0278
0279
0280
0281
0282 PHG4Particle* Tools::GetPHG4ParticleFromBarcode(
0283 const int barcode,
0284 PHCompositeNode* topNode
0285 ) {
0286
0287
0288 PHG4Particle* parToGrab = NULL;
0289
0290
0291 PHG4TruthInfoContainer* container = Interfaces::GetTruthContainer(topNode);
0292
0293
0294 PHG4TruthInfoContainer::ConstRange particles = container -> GetParticleRange();
0295 for (
0296 PHG4TruthInfoContainer::ConstIterator itPar = particles.first;
0297 itPar != particles.second;
0298 ++itPar
0299 ) {
0300 if (itPar -> second -> get_barcode() == barcode) {
0301 parToGrab = itPar -> second;
0302 break;
0303 }
0304 }
0305 return parToGrab;
0306
0307 }
0308
0309
0310
0311
0312
0313
0314 PHG4Particle* Tools::GetPHG4ParticleFromTrackID(const int id, PHCompositeNode* topNode) {
0315
0316
0317 PHG4Particle* parToGrab = NULL;
0318
0319
0320 PHG4TruthInfoContainer* container = Interfaces::GetTruthContainer(topNode);
0321
0322
0323 PHG4TruthInfoContainer::ConstRange particles = container -> GetParticleRange();
0324 for (
0325 PHG4TruthInfoContainer::ConstIterator itPar = particles.first;
0326 itPar != particles.second;
0327 ++itPar
0328 ) {
0329 if (itPar -> second -> get_track_id() == id) {
0330 parToGrab = itPar -> second;
0331 break;
0332 }
0333 }
0334 return parToGrab;
0335
0336 }
0337
0338
0339
0340
0341
0342
0343 HepMC::GenParticle* Tools::GetHepMCGenParticleFromBarcode(
0344 const int barcode,
0345 PHCompositeNode* topNode
0346 ) {
0347
0348
0349 HepMC::GenParticle* parToGrab = NULL;
0350 bool foundBarcode = false;
0351
0352
0353 PHHepMCGenEventMap* mcEvtMap = Interfaces::GetMcEventMap(topNode);
0354 for (
0355 PHHepMCGenEventMap::ConstIter genEvt = mcEvtMap -> begin();
0356 genEvt != mcEvtMap -> end();
0357 ++genEvt
0358 ) {
0359
0360
0361 for (
0362 HepMC::GenEvent::particle_const_iterator hepPar = genEvt -> second -> getEvent() -> particles_begin();
0363 hepPar != genEvt -> second -> getEvent() -> particles_end();
0364 ++hepPar
0365 ) {
0366
0367
0368 if ((*hepPar) -> barcode() == barcode) {
0369 parToGrab = *hepPar;
0370 foundBarcode = true;
0371 break;
0372 }
0373 }
0374
0375
0376 if (foundBarcode) break;
0377
0378 }
0379 return parToGrab;
0380
0381 }
0382
0383 }
0384
0385