12 #include "boost/property_tree/info_parser.hpp"
13 #include "boost/property_tree/xml_parser.hpp"
42 m_angularBased_HFOR =
false;
43 m_jetBased_HFOR =
false;
46 m_jetBasedHFOR_pT_min = 5000.;
47 m_jetBasedHFOR_eta_max = 4.5;
57 m_sampleName = m_sampleNameMap[m_sampleType] ;
64 m_runConfigFile =
"" ;
69 m_Nquarks[
"FS"][4] = 0 ;
70 m_Nquarks[
"FS"][5] = 0 ;
72 m_Nquarks[
"ME"][4] = 0 ;
73 m_Nquarks[
"ME"][5] = 0 ;
75 m_Nquarks[
"GS"][4] = 0 ;
76 m_Nquarks[
"GS"][5] = 0 ;
78 m_Nquarks[
"MPI"][4] = 0 ;
79 m_Nquarks[
"MPI"][5] = 0 ;
90 m_dR[
"ME"][4].clear() ;
91 m_dR[
"ME"][5].clear() ;
93 m_dR[
"GS"][4].clear() ;
94 m_dR[
"GS"][5].clear() ;
109 unsigned int nPart = 0 ;
125 std::map <int, std::vector<const xAOD::TruthParticle* > > fsQuarksMap ;
128 for (
const auto *truth : truthEvent ) {
130 if (truth !=
nullptr) {
132 nPart = truth->nTruthParticles();
133 for (
unsigned int i = 0;
i < nPart;
i++) {
135 if (truthParticle !=
nullptr) {
138 if (is_FinalState(truthParticle) ) {
139 fsQuarksMap[4].push_back(truthParticle) ;
144 if ( is_FinalState(truthParticle) ) {
145 fsQuarksMap[5].push_back(truthParticle) ;
154 m_Nquarks[
"FS"][4] += fsQuarksMap[4].size() ;
155 m_Nquarks[
"FS"][5] += fsQuarksMap[5].size() ;
161 findHFQuarks(fsQuarksMap) ;
163 if(m_angularBased_HFOR){
164 action = angularBasedRemoval() ;
165 }
else if (m_jetBased_HFOR) {
168 else Warning(
"HFOR_Truth::findOverlap()",
"No JetContainer passed to jet-based HFOR!");
171 Error(
"HFOR_Truth::findOverlap()",
"No HFOR type has been specified!");
175 for (
auto&
cc: m_qq ) {
176 std::string cc_name =
cc.first ;
177 for (
auto& qmap:
cc.second) {
178 int id = qmap.first ;
179 std::cout <<
" ***** ----> " << cc_name <<
" " <<
id <<
" " << qmap.second.size() << std::endl ;
197 Warning(__PRETTY_FUNCTION__,
"This is not a valid AlpgenPythia sample, do nothing") ;
201 if(m_debug) std::cout<<std::endl<<
"jetBased HFOR"<<std::endl;
202 bool killEvent =
false;
203 if(!
jets)
Error(
"HFOR_Truth::jetBasedRemoval()",
"Couldn't jet container! It is needed for JetBased HFOR!");
206 std::vector <const xAOD::TruthParticle*> B_ME_v = m_qq[
"ME"][5];
207 std::vector <const xAOD::TruthParticle*> C_ME_v = m_qq[
"ME"][4];
208 std::vector <const xAOD::TruthParticle*> B_GS_v = m_qq[
"GS"][5];
209 std::vector <const xAOD::TruthParticle*> C_GS_v = m_qq[
"GS"][4];
212 const std::string labelGhostB =
"GhostBQuarksFinal", labelGhostC =
"GhostCQuarksFinal";
213 std::vector<const xAOD::TruthParticle *> ghostB, ghostC;
216 Error(
"HFOR_Truth::jetBasedRemoval()",
"Couldn't access truth particleas associated to HF quarks!");
220 size_t nGhostMatchedBQuarks = ghostB.size();
221 size_t nGhostMatchedCQuarks = ghostC.size();
222 size_t nB_ME = 0, nC_ME = 0, nB_GS = 0, nC_GS = 0;
224 if(nGhostMatchedCQuarks == 0 && nGhostMatchedBQuarks == 0)
continue;
225 if(
jet->pt() < m_jetBasedHFOR_pT_min || std::fabs(
jet->eta()) > m_jetBasedHFOR_eta_max )
continue;
230 if(!
part)
Error(
"HFOR_Truth::jetBasedRemoval()",
"No BQuark particles but ghost-matching exists!! It should not happen!");
238 if(!
part)
Error(
"HFOR_Truth::jetBasedRemoval()",
"No CQuark particles but ghost-matching exists!! It should not happen!");
248 if( nB_GS == 1 || nC_GS == 1) killEvent |=
true;
249 else killEvent |=
false;
253 if( nB_ME == 2 ) killEvent |=
true;
254 else killEvent |=
false;
258 if( nC_ME == 2 ) killEvent |=
true;
259 else killEvent |=
false;
263 std::cout<<
"Looking j: pt= "<<
jet->pt()/1000.<<
" eta= "<<
jet->eta()<<
" phi= "<<
jet->phi()
264 <<
" FinalCount B "<<
jet->auxdata<
int>(
"GhostBQuarksFinalCount")
265 <<
" FinalCount C "<<
jet->auxdata<
int>(
"GhostCQuarksFinalCount")<<std::endl;
267 std::cout<<
"nB_ME = "<<nB_ME<<
" nC_ME = "<<nC_ME<<
" nB_GS = "<<nB_GS<<
" nC_GS = "<<nC_GS<<std::endl;
269 std::cout<<
"ghost b: "<<
part<<
" Vtx: "<<
part->prodVtx()<<
" n parent: "<<
part->nParents()<<
" n children: "<<
part->nChildren()<<std::endl;
271 std::cout<<
" mother: "<<
part->parent()<<
" mother mothers: "<<
part->parent()->nParents()<<std::endl;
276 std::cout<<
"ghost c: "<<
part<<
" n parent: "<<
part->nParents()<<
" n children: "<<
part->nChildren()<<std::endl;
277 if(
part->nParents()) std::cout<<
"mother: "<<
part->parent()<<
" Vtx: "<<
part->prodVtx()<<
" mother mothers: "<<
part->parent()->nParents()<<std::endl;
279 std::cout<<
"WARNING: MISSING LINK!!!"<<std::endl;
284 if(m_debug) std::cout<<
"KILL event? "<<killEvent<<std::endl;
302 unsigned int nChildren = bcQuark->
nChildren() ;
303 unsigned int nParents = bcQuark->
nParents() ;
305 bool isFromHadron = false ;
306 bool iscFromb = false ;
310 for (
unsigned int i=0;
i<nParents;
i++) {
312 if(m_debug) std::cout <<
" Father PDGID " << father->
pdgId() <<
" (quark is " << bcQuark->
pdgId() <<
")" << std::endl ;
313 isFromHadron = (isFromHadron | father->
isHadron() ) ;
318 if (isFromHadron || iscFromb) {
322 for (
unsigned int i=0;
i<nChildren;
i++) {
324 if (son !=
nullptr) {
344 std::vector<const xAOD::TruthParticle* > >& fsQuarksMap) {
349 int fsq_pdgId = -999 ;
357 unsigned int nParents = 0 ;
359 bool hasAncestor = false ;
360 bool hasProton = false ;
368 std::vector <const xAOD::TruthParticle*> ME ;
369 std::vector <const xAOD::TruthParticle*>
PDF ;
371 std::map< int, std::vector <const xAOD::TruthParticle*> > xME ;
372 std::map< int, std::vector <const xAOD::TruthParticle*> > xPDF ;
374 std::map< int, std::vector <const xAOD::TruthParticle*> > MPI ;
375 std::map< int, std::vector <const xAOD::TruthParticle*> > GS ;
376 std::map< int, std::vector <const xAOD::TruthParticle*> > ME_PDF ;
377 std::map< int, std::vector <const xAOD::TruthParticle*> > UFO ;
386 std::map<std::string, bool> tipo ;
391 for (
const auto& fsQuarks: fsQuarksMap ) {
392 fsq_pdgId = fsQuarks.first ;
393 for (
const auto& bcQuark: fsQuarks.second) {
394 fsq_status = bcQuark->
status() ;
395 if (fsq_status == 3) {
396 if ( bcQuark->nChildren() == 0 ) {
398 ME.push_back(bcQuark) ;
400 for (
unsigned int i=0;
i<bcQuark->nParents();
i++) {
404 if ( (father->
absPdgId() == fsq_pdgId) && (father->
status() == 3) ) {
405 PDF.push_back(father) ;
411 PDF.push_back(bcQuark) ;
419 for (
const auto& fsQuarks: fsQuarksMap ) {
420 fsq_pdgId = fsQuarks.first ;
421 for (
const auto& bcQuark: fsQuarks.second) {
422 fsq_status = bcQuark->status() ;
423 if (fsq_status != 3) {
432 while (hasAncestor) {
445 if ( nParents != 0 ) {
447 ancestor = ancestor->
parent(0) ;
450 else hasAncestor = false ;
453 tipo = checkAncestor(ancestor,bcQuark) ;
454 if ( tipo[
"orphan"] or tipo[
"cFromb"] or tipo[
"bFromb"] ) {
455 hasAncestor = false ;
458 hasProton |= tipo[
"proton"] ;
463 if ( (
level == 1) & hasProton ) {
465 MPI[fsq_pdgId].push_back(bcQuark) ;
467 if ( (
level == 2) & hasProton ) {
468 if ( (ME.size() +
PDF.size()) == 0 ) {
470 GS[fsq_pdgId].push_back(bcQuark) ;
474 ME_PDF[fsq_pdgId].push_back(bcQuark) ;
477 prodVtx = bcQuark->prodVtx() ;
478 pdgId = bcQuark->pdgId() ;
480 bc34 = ( (vtxBarcode == -3) | (vtxBarcode == -4) ) ;
486 while (hasAncestor) {
489 for (
unsigned int npp=0; npp<nParents; npp++) {
490 ancestor = ancestor->
parent(npp) ;
491 prodVtx = ancestor->
prodVtx() ;
493 bc34 = ( (vtxBarcode == -3) | (vtxBarcode == -4) ) & (ancestor->
pdgId() ==
pdgId) ;
494 if (bc34) pvtx34 = prodVtx ;
497 else hasAncestor = false ;
505 if ( (
part->prodVtx() == pvtx34 ) && (
part->pdgId() == -
pdgId) ) {
506 xPDF[fsq_pdgId].push_back(bcQuark) ;
513 for (
auto&
part: ME) {
515 nParents =
part->nParents() ;
516 for (
unsigned int i=0;
i<nParents;
i++) {
517 father =
part->parent(
i) ;
519 xME[fsq_pdgId].push_back(bcQuark) ;
527 GS[fsq_pdgId].push_back(bcQuark) ;
532 UFO[fsq_pdgId].push_back(bcQuark) ;
538 if (
PDF.size() != xPDF[fsq_pdgId].size()) {
548 m_Nquarks[
"ME"][4] += xME[4].size() ;
549 m_Nquarks[
"ME"][5] += xME[5].size() ;
551 m_Nquarks[
"GS"][4] += GS[4].size() ;
552 m_Nquarks[
"GS"][5] += GS[5].size() ;
554 m_Nquarks[
"MPI"][4] += MPI[4].size() ;
555 m_Nquarks[
"MPI"][5] += MPI[5].size() ;
558 std::cout<<
"m_qq.size = "<<m_qq.size()<<endl;
559 std::cout<<
"PDF n = "<<
PDF.size()<<std::endl;
560 for(
auto &
i :
PDF) std::cout<<
i<<std::endl;
561 std::cout<<
"ME n = "<<ME.size()<<std::endl;
562 for(
auto &
i : ME) std::cout<<
i<<std::endl;
563 std::cout<<
"GS n = "<<GS.size()<<std::endl;
564 for (
const auto& gs_item : GS){
565 std::cout<<
"GS item i = "<<gs_item.first<<std::endl;
566 for(
const auto &
i : gs_item.second) std::cout<<
i<<std::endl;
569 std::cout<<
"xPDF n = "<<xPDF.size()<<std::endl;
570 for (
const auto& xPDF_item : xPDF){
571 std::cout<<
"xPDF item i = "<<xPDF_item.first<<std::endl;
572 for(
const auto &
i : xPDF_item.second) std::cout<<
i<<std::endl;
575 std::cout<<
"xME n = "<<xME.size()<<std::endl;
576 for (
const auto& xME_item : xME){
577 std::cout<<
"xME item i = "<<xME_item.first<<std::endl;
578 for(
const auto &
i : xME_item.second) std::cout<<
i<<std::endl;
581 std::cout<<
"MPI n = "<<MPI.size()<<std::endl;
582 for (
const auto& mpi_item : MPI){
583 std::cout<<
"MPI item i = "<<mpi_item.first<<std::endl;
584 for(
const auto &
i : mpi_item.second) std::cout<<
i<<std::endl;
586 std::cout<<
"ME_PDF n = "<<ME_PDF.size()<<std::endl;
587 for (
const auto& ME_PDF_item : ME_PDF){
588 std::cout<<
"ME_PDF item i = "<<ME_PDF_item.first<<std::endl;
589 for(
const auto &
i : ME_PDF_item.second) std::cout<<
i<<std::endl;
592 std::cout<<
"UFO n = "<<UFO.size()<<std::endl;
593 for (
const auto& UFO_item : UFO){
594 std::cout<<
"UFO item i = "<<UFO_item.first<<std::endl;
595 for(
const auto &
i : UFO_item.second) std::cout<<
i<<std::endl;
609 std::map<std::string, bool> tipo ;
611 tipo [
"proton"] = false ;
612 tipo [
"top"] = false ;
614 tipo [
"cFromb"] = false ;
615 tipo [
"bFromb"] = false ;
616 tipo [
"orphan"] = false ;
617 if (!is_sameFlavor(ancestor, bcQuark) ) {
618 tipo [
"proton"] = is_proton(ancestor);
619 tipo [
"top"] = ancestor->
isTop() ;
620 tipo [
"W"] = ancestor->
isW() ;
625 tipo[
"orphan"] = true ;
638 return (
x->absPdgId() == 2212) ;
649 return (
x->absPdgId() ==
y->absPdgId() ) ;
660 m_runConfigFile = std::move(runConfigFile) ;
663 boost::property_tree::read_info (m_runConfigFile, runConfig) ;
665 for(boost::property_tree::ptree::value_type &
v : runConfig.get_child(
"flavor.isLight")) {
668 for(boost::property_tree::ptree::value_type &
v : runConfig.get_child(
"flavor.isBB")) {
671 for(boost::property_tree::ptree::value_type &
v : runConfig.get_child(
"flavor.isCC")) {
674 for(boost::property_tree::ptree::value_type &
v : runConfig.get_child(
"flavor.isC")) {
693 for (
auto&
kk: m_runConfigMap ) {
696 it =
find (
kk.second.begin(),
kk.second.end(), sampleRunNumber);
704 m_sampleName = m_sampleNameMap[m_sampleType] ;
713 return m_sampleType ;
721 return m_sampleName ;
758 std::map< std::string, std::map<int, int> > hasMatch ;
761 for (
auto& bcProcMap : m_qq ) {
762 proc = bcProcMap.first ;
763 for (
auto& bcMap : bcProcMap.second) {
764 flavor = bcMap.first ;
765 hasMatch[
proc][flavor] = 0 ;
766 m_dR[
proc][flavor].clear() ;
767 if ( bcMap.second.size() > 1) {
769 for (
unsigned int i=0;
i<bcMap.second.size();
i++) {
770 for (
unsigned int j=
i+1;j<bcMap.second.size();j++) {
775 if (
x->pdgId() == -
y->pdgId() ) {
777 dR = sqrt(
pow(
x->phi() -
y->phi(),2) +
pow(
x->eta() -
y->eta(),2) ) ;
778 m_dR[
proc][flavor].push_back(dR) ;
779 if ( dR < m_matchCone ) {
780 hasMatch[
proc][flavor]++ ;
782 if (
x->prodVtx() ==
y->prodVtx()) {
783 std::cout <<
"Match from same Vertex flavor->" << flavor << std::endl ;
786 std::cout <<
"Match NOT from same Vertex flavor->" << flavor << std::endl ;
788 std::cout <<
"///////////////// " <<
proc <<
" " << flavor <<
" dr " << dR << std::endl ;
792 if(m_debug) std::cout <<
"No Match (dr>0.4)" << std::endl ;
801 tipo = m_sampleType ;
807 if ( (!m_qq[
"ME"][4].
empty()) || (!m_qq[
"ME"][5].
empty()) ) {
809 if(m_debug) std::cout <<
"Killed by ME size 4,5: " << m_qq[
"ME"][4].size() <<
" , " << m_qq[
"ME"][4].size() << std::endl ;
812 else if (!m_qq[
"GS"][5].
empty()) {
813 if (hasMatch[
"GS"][5] > 0) {
821 else if (!m_qq[
"GS"][4].
empty()) {
822 if (hasMatch[
"GS"][4] > 0) {
834 if ( hasMatch[
"ME"][4] > 0 ) {
837 else if (hasMatch[
"GS"][5] > 0) {
840 else if (!m_qq[
"GS"][5].
empty()) {
848 if ( hasMatch[
"GS"][5] > 0 ) {
851 else if (!m_qq[
"GS"][5].
empty() ) {
859 if (hasMatch[
"ME"][5] > 0 )
875 return m_Nquarks[
process][flavor] ;
884 return m_Nclass[htipo] ;