File indexing completed on 2025-08-03 08:12:31
0001 #include "Quarkonia2LeptonsMC.h"
0002
0003 #include <phool/getClass.h>
0004 #include <fun4all/Fun4AllServer.h>
0005 #include <fun4all/Fun4AllReturnCodes.h>
0006
0007 #include <phool/PHCompositeNode.h>
0008
0009
0010
0011
0012 #include <TLorentzVector.h>
0013 #include <TNtuple.h>
0014 #include <TFile.h>
0015 #include <TString.h>
0016 #include <TH2D.h>
0017 #include <TDatabasePDG.h>
0018
0019
0020
0021
0022 #include <phhepmc/PHHepMCGenEvent.h>
0023 #include <phhepmc/PHHepMCGenEventMap.h>
0024 #include <HepMC/GenEvent.h>
0025 #include <HepMC/GenVertex.h>
0026
0027 using namespace std;
0028
0029 Quarkonia2LeptonsMC::Quarkonia2LeptonsMC(std::string filename) :
0030 SubsysReco("Quarkonia2LeptonsMC" ),
0031 _embedding_id(1)
0032 {
0033 _foutname = filename;
0034 _tree_quarkonia = NULL;
0035 }
0036
0037 int
0038 Quarkonia2LeptonsMC::Init(PHCompositeNode *topNode)
0039 {
0040 _verbose = false;
0041 _ievent = 0;
0042
0043 _fout_root = new TFile(_foutname.c_str(), "RECREATE");
0044 _tree_quarkonia = new TNtuple("tree_quarkonia","quarkonia info","ev:px:py:pz:e:pt:eta:phi:invmass:ndaughter:d1d2angle");
0045
0046 return 0;
0047 }
0048
0049
0050 int
0051 Quarkonia2LeptonsMC::process_event(PHCompositeNode *topNode)
0052 {
0053
0054 _ievent ++;
0055
0056
0057
0058 PHHepMCGenEventMap * geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
0059 if (!geneventmap)
0060 {
0061 std::cout <<PHWHERE<<" - Fatal error - missing node PHHepMCGenEventMap"<<std::endl;
0062 return Fun4AllReturnCodes::ABORTRUN;
0063 }
0064
0065 PHHepMCGenEvent *genevt = geneventmap->get(_embedding_id);
0066 if (!genevt)
0067 {
0068 std::cout <<PHWHERE<<" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID "<<_embedding_id;
0069 std::cout <<". Print PHHepMCGenEventMap:";
0070 geneventmap->identify();
0071 return Fun4AllReturnCodes::ABORTRUN;
0072 }
0073
0074 HepMC::GenEvent* theEvent = genevt->getEvent();
0075
0076 for (HepMC::GenEvent::particle_const_iterator p = theEvent->particles_begin();
0077 p != theEvent->particles_end(); ++p)
0078 {
0079
0080 TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle( (*p)->pdg_id() );
0081
0082
0083 if (TString(pdg_p->GetName()) == "J/psi" && (*p)->end_vertex() && (*p)->status() == 2 )
0084 {
0085
0086
0087 float px = (*p)->momentum().px();
0088 float py = (*p)->momentum().py();
0089 float pz = (*p)->momentum().pz();
0090 float pe = (*p)->momentum().e();
0091 float pt = sqrt(pow((*p)->momentum().px(),2) + pow((*p)->momentum().py(),2));
0092 float eta = (*p)->momentum().eta();
0093 float phi = (*p)->momentum().phi();
0094 float invmass = (*p)->momentum().m();
0095
0096
0097 float ndaughter = (*p)->end_vertex()->particles_out_size();
0098
0099
0100 float d1d2angle = 0;
0101 if ( ndaughter == 2 )
0102 {
0103 HepMC::GenVertex::particles_out_const_iterator p_d1 = (*p)->end_vertex()->particles_out_const_begin();
0104 HepMC::GenVertex::particles_out_const_iterator p_d2 = p_d1 + 1;
0105
0106 TLorentzVector v_d1((*p_d1)->momentum().px(),(*p_d1)->momentum().py(),(*p_d1)->momentum().pz(),(*p_d1)->momentum().e());
0107 TLorentzVector v_d2((*p_d2)->momentum().px(),(*p_d2)->momentum().py(),(*p_d2)->momentum().pz(),(*p_d2)->momentum().e());
0108
0109 d1d2angle = v_d1.Angle(v_d2.Vect());
0110 }
0111
0112 float quarkonia_data[70] = {(float)_ievent,px,py,pz,pe,pt,eta,phi,invmass,ndaughter,d1d2angle};
0113 _tree_quarkonia -> Fill(quarkonia_data);
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 }
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 }
0166
0167 return Fun4AllReturnCodes::ABORTEVENT;
0168 }
0169
0170 int
0171 Quarkonia2LeptonsMC::End(PHCompositeNode *topNode)
0172 {
0173 _fout_root->cd();
0174 _tree_quarkonia->Write();
0175 _fout_root->Close();
0176
0177 return 0;
0178 }
0179
0180