int main(int argc, char *argv[]){ TFile* fout = new TFile("cascade.result.root","RECREATE"); HepMC::IO_GenEvent fin("../CASCADE_HEPMC/bin/example_test_out.dat",std::ios::in); HepMC::GenEvent* evt = new HepMC::GenEvent; TTree *tree = new TTree("tree","cascade result"); tree->Branch("event",&evt); Int_t nevt = 0; while (evt = fin.read_next_event() ) { nevt++; if(debug){ cout<<"nevt: "<<nevt<<endl; getchar(); evt->print(); } tree->Fill(); } tree->Print(); fout->cd(); tree->Write(); fout->Close(); delete fout; return(0); }
int HFMLTriggerHepMCTrigger::process_event(PHCompositeNode* topNode) { assert(m_Geneventmap); PHHepMCGenEvent* genevt = m_Geneventmap->get(_embedding_id); if (!genevt) { std::cout << PHWHERE << " - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID " << _embedding_id; std::cout << ". Print PHHepMCGenEventMap:"; m_Geneventmap->identify(); return Fun4AllReturnCodes::ABORTRUN; } HepMC::GenEvent* theEvent = genevt->getEvent(); assert(theEvent); if (Verbosity() >= VERBOSITY_MORE) { cout << "HFMLTriggerHepMCTrigger::process_event - process HepMC::GenEvent with signal_process_id = " << theEvent->signal_process_id(); if (theEvent->signal_process_vertex()) { cout << " and signal_process_vertex : "; theEvent->signal_process_vertex()->print(); } cout << " - Event record:" << endl; theEvent->print(); } TDatabasePDG* pdg = TDatabasePDG::Instance(); int targetPID = std::abs(pdg->GetParticle("D0")->PdgCode()); int daughter1PID = std::abs(pdg->GetParticle("pi+")->PdgCode()); int daughter2PID = std::abs(pdg->GetParticle("K+")->PdgCode()); bool acceptEvent = false; assert(m_hNorm); m_hNorm->Fill("Event", 1); unsigned int nD0(0); unsigned int nD0PiK(0); auto range = theEvent->particle_range(); for (HepMC::GenEvent::particle_const_iterator piter = range.begin(); piter != range.end(); ++piter) { const HepMC::GenParticle* p = *piter; assert(p); if (std::abs(p->pdg_id()) == targetPID) { if (Verbosity()) { cout << "HFMLTriggerHepMCTrigger::process_event - Accept signal particle : "; p->print(); cout << endl; } m_hNorm->Fill("D0", 1); ++nD0; assert(m_DRapidity); const double rapidity = 0.5 * log((p->momentum().e() + p->momentum().z()) / (p->momentum().e() - p->momentum().z())); m_DRapidity->Fill(rapidity, 0); const HepMC::GenVertex* decayVertex = p->end_vertex(); int hasDecay1(0); int hasDecay2(0); int hasDecayOther(0); if (decayVertex) { for (auto diter = decayVertex->particles_out_const_begin(); diter != decayVertex->particles_out_const_end(); ++diter) { const HepMC::GenParticle* pd = *diter; assert(pd); if (Verbosity()) { cout << "HFMLTriggerHepMCTrigger::process_event - Testing daughter particle: "; pd->print(); cout << endl; } if (std::abs(pd->pdg_id()) == daughter1PID) { const double eta = pd->momentum().eta(); if (eta > _eta_min and eta < _eta_max) ++hasDecay1; } else if (std::abs(pd->pdg_id()) == daughter2PID) { const double eta = pd->momentum().eta(); if (eta > _eta_min and eta < _eta_max) ++hasDecay2; } else ++hasDecayOther; } if (hasDecay1 == 1 and hasDecay2 == 1 and hasDecayOther == 0) { m_hNorm->Fill("D0->PiK", 1); ++nD0PiK; acceptEvent = true; m_DRapidity->Fill(rapidity, 1); } } // if (decayVertex) else { cout << "HFMLTriggerHepMCTrigger::process_event - Warning - target particle did not have decay vertex : "; p->print(); cout << endl; } } // if (std::abs(p-> pdg_id()) == targetPID) } // for (HepMC::GenEvent::particle_const_iterator piter = range.begin(); piter != range.end(); ++piter) if (nD0 >= 2) { cout <<"HFMLTriggerHepMCTrigger::process_event - D0-Pair with nD0 = "<<nD0<<endl; m_hNorm->Fill("D0-Pair", nD0 * (nD0 - 1) / 2); } if (nD0PiK >= 2) { m_hNorm->Fill("D0->PiK-Pair", nD0PiK * (nD0PiK - 1) / 2); } ++_ievent; if (Verbosity()) { cout << "HFMLTriggerHepMCTrigger::process_event - acceptEvent = " << acceptEvent; cout << endl; if (acceptEvent) { cout << "HFMLTriggerHepMCTrigger::process_event - processed HepMC::GenEvent with signal_process_id = " << theEvent->signal_process_id(); if (theEvent->signal_process_vertex()) { cout << " and signal_process_vertex : "; theEvent->signal_process_vertex()->print(); } cout << " - Event record:" << endl; theEvent->print(); } } assert(m_Flags); m_Flags->set_int_param(Name(), acceptEvent); if (acceptEvent) { m_hNorm->Fill("Accepted", 1); return Fun4AllReturnCodes::EVENT_OK; } else return m_RejectReturnCode; }