int PHG4TrackGhostRejection::process_event(PHCompositeNode *topNode) { if(verbosity > 0) cout << "PHG4TrackGhostRejection::process_event -- entered" << endl; //--------------------------------- // Get Objects off of the Node Tree //--------------------------------- // Pull the reconstructed track information off the node tree... _g4tracks = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap"); if(!_g4tracks) { cerr << PHWHERE << " ERROR: Can't find SvtxTrackMap." << endl; return Fun4AllReturnCodes::ABORTEVENT; } if (verbosity > 1) { _g4tracks->identify(); for (SvtxTrackMap::Iter iter = _g4tracks->begin(); iter != _g4tracks->end(); ++iter) { SvtxTrack *track = iter->second; track->identify(); } } //---------------------------- // Sort the hits on each track //---------------------------- _candidates.clear(); for (SvtxTrackMap::Iter iter = _g4tracks->begin(); iter != _g4tracks->end(); ++iter) { SvtxTrack* track = iter->second; PHG4TrackCandidate combo; combo.trackid = track->get_id(); combo.nhits = track->size_clusters(); for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; combo.hitids.push_back(cluster_id); } if (track->get_ndf() != 0) { combo.chisq = track->get_chisq()/track->get_ndf(); } combo.keep = true; // sort the hits by index stable_sort(combo.hitids.begin(),combo.hitids.end(),hit_sort); _candidates.push_back(combo); } //--------------------- // Fill the overlap map //--------------------- _overlapping.clear(); for(unsigned int i = 0; i < _candidates.size(); i++) { for(unsigned int j = i+1; j < _candidates.size(); j++) { // determine the maximum length of the anticipated storage unsigned maxhits = _candidates[i].hitids.size(); if(_candidates[j].hitids.size() > maxhits) { maxhits = _candidates[j].hitids.size(); } // create the difference storage std::vector<unsigned int> diff; diff.assign(maxhits,0); // run the difference algorithm std::vector<unsigned int>::iterator it = diff.begin(); it = std::set_difference(_candidates[i].hitids.begin(),_candidates[i].hitids.end(), _candidates[j].hitids.begin(),_candidates[j].hitids.end(), diff.begin()); // calculate the overlap unsigned int overlap = maxhits - int(it - diff.begin()); // insert an overlapping pair into the map if(overlap > _max_shared_hits) _overlapping.insert(std::make_pair(i,j)); } } //---------------------- // Flag the ghost tracks //---------------------- std::multimap<unsigned,unsigned int>::iterator iter; for (iter = _overlapping.begin(); iter != _overlapping.end(); iter++) { unsigned int key = iter->first; unsigned int value = iter->second; if (_candidates[key].nhits > _candidates[value].nhits) { // prefer longer track _candidates[value].keep = false; } else if (_candidates[key].nhits < _candidates[value].nhits) { // prefer longer track _candidates[key].nhits = false; } else { // choose between equal length tracks by chisq/dof if (_candidates[key].chisq < _candidates[value].chisq) { _candidates[value].keep = false; } else { _candidates[key].keep = false; } } } //------------------------ // Remove the ghost tracks //------------------------ SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode, "SvtxVertexMap"); int initial_size = _g4tracks->size(); // loop over container and delete! for (unsigned int i = 0; i < _candidates.size(); i++) { if (!_candidates[i].keep) { // look for the track to delete if (_g4tracks->find(_candidates[i].trackid) != _g4tracks->end()) { _g4tracks->erase(_candidates[i].trackid); // also remove the track id from any vertex that contains this track if (!vertexmap) continue; for (SvtxVertexMap::Iter iter = vertexmap->begin(); iter != vertexmap->end(); ++iter) { SvtxVertex* vertex = iter->second; vertex->erase_track(_candidates[i].trackid); } } } } if (verbosity > 1) { _g4tracks->identify(); for (SvtxTrackMap::Iter iter = _g4tracks->begin(); iter != _g4tracks->end(); ++iter) { SvtxTrack *track = iter->second; track->identify(); } } if(verbosity > 0) cout << "PHG4TrackGhostRejection - rejected and removed " << initial_size - _g4tracks->size() << " tracks" << endl;; if(verbosity > 0) cout << "PHG4TrackGhostRejection::process_event -- exited" << endl; return Fun4AllReturnCodes::EVENT_OK; }
void SvtxEvaluator::fillOutputNtuples(PHCompositeNode *topNode) { if (verbosity > 1) cout << "SvtxEvaluator::fillOutputNtuples() entered" << endl; SvtxVertexEval* vertexeval = _svtxevalstack->get_vertex_eval(); SvtxTrackEval* trackeval = _svtxevalstack->get_track_eval(); SvtxClusterEval* clustereval = _svtxevalstack->get_cluster_eval(); SvtxHitEval* hiteval = _svtxevalstack->get_hit_eval(); SvtxTruthEval* trutheval = _svtxevalstack->get_truth_eval(); //----------------------- // fill the Vertex NTuple //----------------------- if (_ntp_vertex) { //cout << "Filling ntp_vertex " << endl; SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (vertexmap && truthinfo) { for (SvtxVertexMap::Iter iter = vertexmap->begin(); iter != vertexmap->end(); ++iter) { SvtxVertex* vertex = iter->second; PHG4VtxPoint* point = vertexeval->max_truth_point_by_ntracks(vertex); float vx = vertex->get_x(); float vy = vertex->get_y(); float vz = vertex->get_z(); float ntracks = vertex->size_tracks(); float gvx = NAN; float gvy = NAN; float gvz = NAN; float gvt = NAN; float gntracks = truthinfo->GetNumPrimaryVertexParticles(); float nfromtruth = NAN; if (point) { gvx = point->get_x(); gvy = point->get_y(); gvz = point->get_z(); gvt = point->get_t(); gntracks = truthinfo->GetNumPrimaryVertexParticles(); nfromtruth = vertexeval->get_ntracks_contribution(vertex,point); } float vertex_data[11] = {(float) _ievent, vx, vy, vz, ntracks, gvx, gvy, gvz, gvt, gntracks, nfromtruth }; /* cout << "vertex: " << " ievent " << vertex_data[0] << " vx " << vertex_data[1] << " vy " << vertex_data[2] << " vz " << vertex_data[3] << endl; */ _ntp_vertex->Fill(vertex_data); } } } //----------------------- // fill the gpoint NTuple //----------------------- if (_ntp_gpoint) { //cout << "Filling ntp_gpoint " << endl; SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (vertexmap && truthinfo) { PHG4VtxPoint* point = truthinfo->GetPrimaryVtx(truthinfo->GetPrimaryVertexIndex()); if (point) { SvtxVertex* vertex = vertexeval->best_vertex_from(point); float gvx = point->get_x(); float gvy = point->get_y(); float gvz = point->get_z(); float gvt = point->get_t(); float gntracks = truthinfo->GetNumPrimaryVertexParticles(); float vx = NAN; float vy = NAN; float vz = NAN; float ntracks = NAN; float nfromtruth = NAN; if (vertex) { vx = vertex->get_x(); vy = vertex->get_y(); vz = vertex->get_z(); ntracks = vertex->size_tracks(); nfromtruth = vertexeval->get_ntracks_contribution(vertex,point); } float gpoint_data[11] = {(float) _ievent, gvx, gvy, gvz, gvt, gntracks, vx, vy, vz, ntracks, nfromtruth }; _ntp_gpoint->Fill(gpoint_data); } } } //--------------------- // fill the G4hit NTuple //--------------------- if (_ntp_g4hit) { //cout << "Filling ntp_g4hit " << endl; std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(); for (std::set<PHG4Hit*>::iterator iter = g4hits.begin(); iter != g4hits.end(); ++iter) { PHG4Hit *g4hit = *iter; PHG4Particle *g4particle = trutheval->get_particle(g4hit); float g4hitID = g4hit->get_hit_id(); float gx = g4hit->get_avg_x(); float gy = g4hit->get_avg_y(); float gz = g4hit->get_avg_z(); float gt = g4hit->get_avg_t(); float gedep = g4hit->get_edep(); float glayer = g4hit->get_layer(); float gtrackID = g4hit->get_trkid(); float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gembed = NAN; float gprimary = NAN; float gfpx = 0.; float gfpy = 0.; float gfpz = 0.; float gfx = 0.; float gfy = 0.; float gfz = 0.; if (g4particle) { if (_scan_for_embedded) { if (trutheval->get_embed(g4particle) == 0) continue; } gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle) std::set<SvtxCluster*> clusters = clustereval->all_clusters_from(g4hit); float nclusters = clusters.size(); // best cluster reco'd SvtxCluster* cluster = clustereval->best_cluster_from(g4hit); float clusID = NAN; float x = NAN; float y = NAN; float z = NAN; float e = NAN; float adc = NAN; float layer = NAN; float size = NAN; float phisize = NAN; float zsize = NAN; float efromtruth = NAN; if (cluster) { clusID = cluster->get_id(); x = cluster->get_x(); y = cluster->get_y(); z = cluster->get_z(); e = cluster->get_e(); adc = cluster->get_adc(); layer = cluster->get_layer(); size = cluster->size_hits(); phisize = cluster->get_phi_size(); zsize = cluster->get_z_size(); if (g4particle) { efromtruth = clustereval->get_energy_contribution(cluster,g4particle); } } float g4hit_data[36] = {(float) _ievent, g4hitID, gx, gy, gz, gt, gedep, glayer, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, nclusters, clusID, x, y, z, e, adc, layer, size, phisize, zsize, efromtruth }; _ntp_g4hit->Fill(g4hit_data); } } //-------------------- // fill the Hit NTuple //-------------------- if (_ntp_hit) { //cout << "Filling ntp_hit " << endl; // need things off of the DST... SvtxHitMap* hitmap = findNode::getClass<SvtxHitMap>(topNode,"SvtxHitMap"); if (hitmap) { for (SvtxHitMap::Iter iter = hitmap->begin(); iter != hitmap->end(); ++iter) { SvtxHit* hit = iter->second; PHG4Hit* g4hit = hiteval->max_truth_hit_by_energy(hit); PHG4CylinderCell* g4cell = hiteval->get_cell(hit); PHG4Particle* g4particle = trutheval->get_particle(g4hit); float event = _ievent; float hitID = hit->get_id(); float e = hit->get_e(); float adc = hit->get_adc(); float layer = hit->get_layer(); float cellID = hit->get_cellid(); float ecell = g4cell->get_edep(); float g4hitID = NAN; float gedep = NAN; float gx = NAN; float gy = NAN; float gz = NAN; float gt = NAN; float gtrackID = NAN; float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float gembed = NAN; float gprimary = NAN; float efromtruth = NAN; if (g4hit) { g4hitID = g4hit->get_hit_id(); gedep = g4hit->get_edep(); gx = g4hit->get_avg_x(); gy = g4hit->get_avg_y(); gz = g4hit->get_avg_z(); gt = g4hit->get_avg_t(); if (g4particle) { if (_scan_for_embedded) { if (trutheval->get_embed(g4particle) == 0) continue; } gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle){ } if (g4particle) { efromtruth = hiteval->get_energy_contribution(hit,g4particle); } float hit_data[33] = { event, hitID, e, adc, layer, cellID, ecell, g4hitID, gedep, gx, gy, gz, gt, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, efromtruth }; _ntp_hit->Fill(hit_data); } } } //------------------------ // fill the Cluster NTuple //------------------------ //cout << "check for ntp_cluster" << endl; if (_ntp_cluster && !_scan_for_embedded) { //cout << "Filling ntp_cluster 1 " << endl; // need things off of the DST... SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (clustermap) { for (SvtxClusterMap::Iter iter = clustermap->begin(); iter != clustermap->end(); ++iter) { SvtxCluster* cluster = iter->second; SvtxTrack* track = trackeval->best_track_from(cluster); PHG4Hit *g4hit = clustereval->max_truth_hit_by_energy(cluster); PHG4Particle *g4particle = trutheval->get_particle(g4hit); float hitID = cluster->get_id(); float x = cluster->get_x(); float y = cluster->get_y(); float z = cluster->get_z(); float ex = sqrt(cluster->get_error(0,0)); float ey = sqrt(cluster->get_error(1,1)); float ez = cluster->get_z_error(); float ephi = cluster->get_phi_error(); float e = cluster->get_e(); float adc = cluster->get_adc(); float layer = cluster->get_layer(); float size = cluster->size_hits(); float phisize = cluster->get_phi_size(); float zsize = cluster->get_z_size(); float trackID = NAN; if (track) trackID = track->get_id(); float g4hitID = NAN; float gx = NAN; float gy = NAN; float gz = NAN; float gt = NAN; float gtrackID = NAN; float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float gembed = NAN; float gprimary = NAN; float efromtruth = NAN; if (g4hit) { g4hitID = g4hit->get_hit_id(); gx = g4hit->get_avg_x(); gy = g4hit->get_avg_y(); gz = g4hit->get_avg_z(); gt = g4hit->get_avg_t(); if (g4particle) { gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle){ } // if (g4hit) { if (g4particle){ efromtruth = clustereval->get_energy_contribution(cluster,g4particle); } float cluster_data[38] = {(float) _ievent, hitID, x, y, z, ex, ey, ez, ephi, e, adc, layer, size, phisize, zsize, trackID, g4hitID, gx, gy, gz, gt, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, efromtruth}; _ntp_cluster->Fill(cluster_data); } } } else if (_ntp_cluster && _scan_for_embedded) { //cout << "Filling ntp_cluster 2 " << endl; // if only scanning embedded signals, loop over all the tracks from // embedded particles and report all of their clusters, including those // from other sources (noise hits on the embedded track) // need things off of the DST... SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap"); SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (trackmap) { for (SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter) { SvtxTrack* track = iter->second; PHG4Particle* truth = trackeval->max_truth_particle_by_nclusters(track); if (truth) { if (trutheval->get_embed(truth) == 0) continue; } for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; SvtxCluster* cluster = clustermap->get(cluster_id); PHG4Hit *g4hit = clustereval->max_truth_hit_by_energy(cluster); PHG4Particle *g4particle = trutheval->get_particle(g4hit); float hitID = cluster->get_id(); float x = cluster->get_x(); float y = cluster->get_y(); float z = cluster->get_z(); float ex = sqrt(cluster->get_error(0,0)); float ey = sqrt(cluster->get_error(1,1)); float ez = cluster->get_z_error(); float ephi = cluster->get_phi_error(); float e = cluster->get_e(); float adc = cluster->get_adc(); float layer = cluster->get_layer(); float size = cluster->size_hits(); float phisize = cluster->get_phi_size(); float zsize = cluster->get_z_size(); float trackID = NAN; if (track) trackID = track->get_id(); float g4hitID = NAN; float gx = NAN; float gy = NAN; float gz = NAN; float gt = NAN; float gtrackID = NAN; float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float gembed = NAN; float gprimary = NAN; float efromtruth = NAN; if (g4hit) { g4hitID = g4hit->get_hit_id(); gx = g4hit->get_avg_x(); gy = g4hit->get_avg_y(); gz = g4hit->get_avg_z(); gt = g4hit->get_avg_t(); if (g4particle) { gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle){ } // if (g4hit) { if (g4particle){ efromtruth = clustereval->get_energy_contribution(cluster,g4particle); } float cluster_data[38] = {(float) _ievent, hitID, x, y, z, ex, ey, ez, ephi, e, adc, layer, size, phisize, zsize, trackID, g4hitID, gx, gy, gz, gt, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, efromtruth}; _ntp_cluster->Fill(cluster_data); } } } } //------------------------ // fill the Gtrack NTuple //------------------------ // need things off of the DST... //cout << "check for ntp_gtrack" << endl; if (_ntp_gtrack) { //cout << "Filling ntp_gtrack " << endl; PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (truthinfo) { PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange(); for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter) { PHG4Particle* g4particle = iter->second; if (_scan_for_embedded) { if (trutheval->get_embed(g4particle) == 0) continue; } float gtrackID = g4particle->get_track_id(); float gflavor = g4particle->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle); float ng4hits = g4hits.size(); float gpx = g4particle->get_px(); float gpy = g4particle->get_py(); float gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); float gvx = vtx->get_x(); float gvy = vtx->get_y(); float gvz = vtx->get_z(); float gvt = vtx->get_t(); float gfpx = 0.; float gfpy = 0.; float gfpz = 0.; float gfx = 0.; float gfy = 0.; float gfz = 0.; PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } float gembed = trutheval->get_embed(g4particle); float gprimary = trutheval->is_primary(g4particle); SvtxTrack* track = trackeval->best_track_from(g4particle); float trackID = NAN; float charge = NAN; float quality = NAN; float chisq = NAN; float ndf = NAN; float nhits = NAN; unsigned int layers = 0x0; float dca2d = NAN; float dca2dsigma = NAN; float px = NAN; float py = NAN; float pz = NAN; float pcax = NAN; float pcay = NAN; float pcaz = NAN; float nfromtruth = NAN; float layersfromtruth = NAN; if (track) { trackID = track->get_id(); charge = track->get_charge(); quality = track->get_quality(); chisq = track->get_chisq(); ndf = track->get_ndf(); nhits = track->size_clusters(); for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; SvtxCluster* cluster = clustermap->get(cluster_id); unsigned int layer = cluster->get_layer(); if (layer < 32) layers |= (0x1 << layer); } dca2d = track->get_dca2d(); dca2dsigma = track->get_dca2d_error(); px = track->get_px(); py = track->get_py(); pz = track->get_pz(); pcax = track->get_x(); pcay = track->get_y(); pcaz = track->get_z(); nfromtruth = trackeval->get_nclusters_contribution(track,g4particle); layersfromtruth = trackeval->get_nclusters_contribution_by_layer(track,g4particle); } float gtrack_data[36] = {(float) _ievent, gtrackID, gflavor, ng4hits, gpx, gpy, gpz, gvx, gvy, gvz, gvt, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, trackID, px, py, pz, charge, quality, chisq, ndf, nhits, (float) layers, dca2d, dca2dsigma, pcax, pcay, pcaz, nfromtruth, layersfromtruth }; /* cout << " ievent " << _ievent << " gtrackID " << gtrackID << " gflavor " << gflavor << " ng4hits " << ng4hits << endl; */ _ntp_gtrack->Fill(gtrack_data); } } } //------------------------ // fill the Track NTuple //------------------------ if (_ntp_track) { //cout << "Filling ntp_track " << endl; // need things off of the DST... SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap"); SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (trackmap) { for (SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter) { SvtxTrack* track = iter->second; float trackID = track->get_id(); float charge = track->get_charge(); float quality = track->get_quality(); float chisq = track->get_chisq(); float ndf = track->get_ndf(); float nhits = track->size_clusters(); unsigned int layers = 0x0; for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; SvtxCluster* cluster = clustermap->get(cluster_id); unsigned int layer = cluster->get_layer(); if (layer < 31) layers |= (0x1 << layer); } float dca2d = track->get_dca2d(); float dca2dsigma = track->get_dca2d_error(); float px = track->get_px(); float py = track->get_py(); float pz = track->get_pz(); float pcax = track->get_x(); float pcay = track->get_y(); float pcaz = track->get_z(); float presdphi = track->get_cal_dphi(SvtxTrack::PRES); float presdeta = track->get_cal_deta(SvtxTrack::PRES); float prese3x3 = track->get_cal_energy_3x3(SvtxTrack::PRES); float prese = track->get_cal_cluster_e(SvtxTrack::PRES); float cemcdphi = track->get_cal_dphi(SvtxTrack::CEMC); float cemcdeta = track->get_cal_deta(SvtxTrack::CEMC); float cemce3x3 = track->get_cal_energy_3x3(SvtxTrack::CEMC); float cemce = track->get_cal_cluster_e(SvtxTrack::CEMC); float hcalindphi = track->get_cal_dphi(SvtxTrack::HCALIN); float hcalindeta = track->get_cal_deta(SvtxTrack::HCALIN); float hcaline3x3 = track->get_cal_energy_3x3(SvtxTrack::HCALIN); float hcaline = track->get_cal_cluster_e(SvtxTrack::HCALIN); float hcaloutdphi = track->get_cal_dphi(SvtxTrack::HCALOUT); float hcaloutdeta = track->get_cal_deta(SvtxTrack::HCALOUT); float hcaloute3x3 = track->get_cal_energy_3x3(SvtxTrack::HCALOUT); float hcaloute = track->get_cal_cluster_e(SvtxTrack::HCALOUT); float gtrackID = NAN; float gflavor = NAN; float ng4hits = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gvt = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float gembed = NAN; float gprimary = NAN; float nfromtruth = NAN; float layersfromtruth = NAN; PHG4Particle* g4particle = trackeval->max_truth_particle_by_nclusters(track); if (g4particle) { if (_scan_for_embedded) { if (trutheval->get_embed(g4particle) == 0) continue; } gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle); ng4hits = g4hits.size(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); gvt = vtx->get_t(); PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); nfromtruth = trackeval->get_nclusters_contribution(track,g4particle); layersfromtruth = trackeval->get_nclusters_contribution_by_layer(track,g4particle); } float track_data[52] = {(float) _ievent, trackID, px, py, pz, charge, quality, chisq, ndf, nhits, (float) layers, dca2d, dca2dsigma, pcax, pcay, pcaz, presdphi, presdeta, prese3x3, prese, cemcdphi, cemcdeta, cemce3x3, cemce, hcalindphi, hcalindeta, hcaline3x3, hcaline, hcaloutdphi, hcaloutdeta, hcaloute3x3, hcaloute, gtrackID, gflavor, ng4hits, gpx, gpy, gpz, gvx, gvy, gvz, gvt, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, nfromtruth, layersfromtruth }; /* cout << "ievent " << _ievent << " trackID " << trackID << " nhits " << nhits << " px " << px << " py " << py << " pz " << pz << " gembed " << gembed << " gprimary " << gprimary << endl; */ _ntp_track->Fill(track_data); } } } return; }
int PHG4HoughTransformTPC::process_event(PHCompositeNode *topNode) { _timer.get()->restart(); if(_write_reco_tree==true){ _recoevent->tracks.clear();} if(verbosity > 0) cout << "PHG4HoughTransformTPC::process_event -- entered" << endl; // moving clearing to the beginning of event or we will have // return bugs from early exits! _clusters_init.clear(); _clusters.clear(); _tracks.clear(); //--------------------------------- // Get Objects off of the Node Tree //--------------------------------- GetNodes(topNode); // Translate into Helix_Hough objects //----------------------------------- //wrap_clusters_timer.get()->restart(); for (SvtxClusterMap::Iter iter = _g4clusters->begin(); iter != _g4clusters->end(); ++iter) { SvtxCluster* cluster = iter->second; //cluster->identify(); float phi = atan2(cluster->get_position(1),cluster->get_position(0)); unsigned int ilayer = _layer_ilayer_map[cluster->get_layer()]; float xy_error=0.;float z_error=0.; if (_use_cell_size) { xy_error = _smear_xy_layer[ilayer] * _vote_error_scale[ilayer]; z_error = _smear_z_layer[ilayer] * _vote_error_scale[ilayer]; } else { if( cluster->get_phi_size() <= _max_cluster_error*_smear_xy_layer[ilayer] ){xy_error = cluster->get_phi_size() * _vote_error_scale[ilayer];} else{xy_error = _max_cluster_error*_smear_xy_layer[ilayer] * _vote_error_scale[ilayer];} if(cluster->get_z_size() <= _max_cluster_error*_smear_z_layer[ilayer]){z_error = cluster->get_z_size() * _vote_error_scale[ilayer];} else{z_error = _max_cluster_error*_smear_z_layer[ilayer] * _vote_error_scale[ilayer];} } vector<SimpleHit3D>* which_vec = &_clusters; if (ilayer<_seed_layers) {which_vec=&_clusters_init;} //SimpleHit3D(float xx, float dxx, float yy, float dyy, float zz, float dzz, unsigned int ind, int lyr=-1) SimpleHit3D hit3d(cluster->get_x(),fabs(xy_error*sin(phi)), cluster->get_y(),fabs(xy_error*cos(phi)), cluster->get_z(),z_error, cluster->get_id(),ilayer); // copy covariance over for (int i=0; i<3; ++i) { for (int j=i; j<3; ++j) { hit3d.set_error(i,j,cluster->get_error(i,j)); } } which_vec->push_back(hit3d); } if (verbosity > 20) { cout << "-------------------------------------------------------------------" << endl; cout << "PHG4HoughTransformTPC::process_event has the following input clusters:" << endl; if (!_clusters_init.empty()) { for (unsigned int i = 0; i < _clusters_init.size(); ++i) { cout << "n init clusters = "<<_clusters_init.size() << endl; _clusters_init[i].print(); } } else { for (unsigned int i = 0; i < _clusters.size(); ++i) { cout << "n clusters = "<<_clusters.size() << endl; _clusters[i].print(); } } cout << "-------------------------------------------------------------------" << endl; } cout<<"_clusters_init.size() = "<<_clusters_init.size()<<endl; //------------------------------------ // Perform the initial zvertex finding //------------------------------------ if(verbosity > 0) cout << "PHG4HoughTransformTPC::process_event -- initial vertex finding..." << endl; // Grab some initial tracks for initial z-vertex finding _tracks.clear(); _vertex.clear(); _vertex.push_back(0.0); // x guess _vertex.push_back(0.0); // y guess _vertex.push_back(0.0); // z guess if(_use_vertex) { // find maxtracks tracks unsigned int maxtracks = 100; // _tracker->setRemoveHits(false); _tracker->findHelices(_clusters_init, _req_seed, _max_hits_init, _tracks, maxtracks); // _tracker->setRemoveHits(_remove_hits); cout<<"found "<<_tracks.size()<<" tracks"<<endl; if(_tracks.size() == 0){return Fun4AllReturnCodes::EVENT_OK;} else if(_tracks.size() == 1) { _vertex[0] = cos(_tracks[0].phi) * _tracks[0].d; _vertex[1] = sin(_tracks[0].phi) * _tracks[0].d; _vertex[2] = _tracks[0].z0; } else { vector<vector<double> > pTmap; for(unsigned int i=0;i<_tracks.size();++i) { if(_tracks[i].kappa == 0.0){continue;} double pT = kappaToPt(_tracks[i].kappa); pTmap.push_back(vector<double>()); pTmap.back().push_back(pT); pTmap.back().push_back((double)i); } sort(pTmap.begin(), pTmap.end()); vector<SimpleTrack3D> vtxtracks; unsigned int maxvtxtracks=100; if(_tracks.size() < maxvtxtracks) { vtxtracks = _tracks; } else { for(unsigned int i=0;i<maxvtxtracks;++i) { vtxtracks.push_back(_tracks[ (int)(pTmap[pTmap.size()-1-i][1]) ]); } } vector<double> zvertices(3,0.); vector<float> temp_vertex(3,0.); vector<unsigned int> vtracks(3,0); for(unsigned int iter = 0;iter < 3; ++iter) { temp_vertex[2] = 0.; TH1D z0_hist("z0_hist","z0_hist", 20, -10., 10.); for(unsigned int i=0;i<vtxtracks.size();++i) { z0_hist.Fill(vtxtracks[i].z0); } temp_vertex[2] = z0_hist.GetBinCenter( z0_hist.GetMaximumBin() ); _vertexFinder.findVertex(vtxtracks, temp_vertex, 3., true); _vertexFinder.findVertex(vtxtracks, temp_vertex, 0.1, true); _vertexFinder.findVertex(vtxtracks, temp_vertex, 0.02, false); vector<SimpleTrack3D> ttracks; for(unsigned int t=0;t<vtxtracks.size();++t) { if( fabs(vtxtracks[t].z0 - temp_vertex[2]) < 0.1 ){vtracks[iter] += 1;} else{ttracks.push_back(vtxtracks[t]);} } vtxtracks = ttracks; zvertices[iter] = temp_vertex[2]; } _vertex[2] = zvertices[0]; unsigned int zbest = 0; for(unsigned int iter = 1;iter < 3; ++iter) { if(vtracks[iter] > vtracks[zbest]) { _vertex[2] = zvertices[iter]; zbest = iter; } } } if(verbosity > 0) cout << "PHG4HoughTransformTPC::process_event -- found initial vertex : " << _vertex[0] << " " << _vertex[1] << " " << _vertex[2] << endl; _tracks.clear(); // shift the vertex to the origin for(unsigned int ht=0;ht<_clusters_init.size();++ht) { _clusters_init[ht].x -= _vertex[0]; _clusters_init[ht].y -= _vertex[1]; _clusters_init[ht].z -= _vertex[2]; } for(unsigned int ht=0;ht<_clusters.size();++ht) { _clusters[ht].x -= _vertex[0]; _clusters[ht].y -= _vertex[1]; _clusters[ht].z -= _vertex[2]; } } // if(_use_vertex) //---------------------------------- // Preform the track finding //---------------------------------- _tracker->clear(); _tracks.clear(); _timer_initial_hough.get()->restart(); _tracker->findHelices(_clusters_init, _min_hits_init, _max_hits_init, _tracks); _timer_initial_hough.get()->stop(); if(verbosity > 0) { cout << "PHG4HoughTransformTPC::process_event -- full track finding pass found: " << _tracks.size() << " tracks" << endl; } //---------------------------- // Re-center event on detector //---------------------------- if(verbosity > 0) cout << "PHG4HoughTransformTPC::process_event -- recentering event on detector..." << endl; vector<double> chi_squareds; for(unsigned int tt=0;tt<_tracks.size();tt++) { // move the hits in the track back to their original position for(unsigned int hh=0;hh<_tracks[tt].hits.size();hh++) { _tracks[tt].hits[hh].x = _tracks[tt].hits[hh].x + _vertex[0]; _tracks[tt].hits[hh].y = _tracks[tt].hits[hh].y + _vertex[1]; _tracks[tt].hits[hh].z = _tracks[tt].hits[hh].z + _vertex[2]; // _tracks[tt].z0 += _vertex[2]; } chi_squareds.push_back(_tracker->getKalmanStates()[tt].chi2);} if(verbosity > 0) { cout << "PHG4HoughTransformTPC::process_event -- final track count: " << _tracks.size() << endl; } //--------------------------- // Final vertex determination //--------------------------- // final best guess of the primary vertex position here... if(verbosity > 0) { cout<< "PHG4HoughTransformTPC::process_event -- calculating final vertex" << endl; } // sort the tracks by pT vector<vector<double> > pTmap; for(unsigned int i=0;i<_tracks.size();++i) { double pT = kappaToPt(_tracks[i].kappa); pTmap.push_back(vector<double>()); pTmap.back().push_back(pT); pTmap.back().push_back((double)i); } sort(pTmap.begin(), pTmap.end()); vector<SimpleTrack3D> vtxtracks; vector<Matrix<float,5,5> > vtxcovariances; unsigned int maxvtxtracks=100; if(_tracks.size() < maxvtxtracks){vtxtracks = _tracks;} else { for(unsigned int i=0;i<maxvtxtracks;++i) { vtxtracks.push_back(_tracks[ (int)(pTmap[pTmap.size()-1-i][1]) ]); vtxcovariances.push_back( (_tracker->getKalmanStates())[ (int)(pTmap[pTmap.size()-1-i][1]) ].C ); } } double vx = _vertex[0]; double vy = _vertex[1]; double vz = _vertex[2]; _vertex[0] = 0.; _vertex[1] = 0.; _vertex[2] = 0.; _vertexFinder.findVertex(vtxtracks, vtxcovariances, _vertex, 0.3, false); _vertexFinder.findVertex(vtxtracks, vtxcovariances, _vertex, 0.1, false); _vertexFinder.findVertex(vtxtracks, vtxcovariances, _vertex, 0.02, false); _vertexFinder.findVertex(vtxtracks, vtxcovariances, _vertex, 0.005, false); _vertex[0] += vx; _vertex[1] += vy; _vertex[2] += vz; if(verbosity > 0) { cout << "PHG4HoughTransformTPC::process_event -- final vertex: " << _vertex[0] << " " << _vertex[1] << " " << _vertex[2] << endl; } //-------------------------------- // Translate back into PHG4 objects //-------------------------------- if(verbosity > 0) { cout << "PHG4HoughTransformTPC::process_event -- producing PHG4Track objects..." << endl; } SvtxVertex_v1 vertex; vertex.set_t0(0.0); for (int i=0;i<3;++i) vertex.set_position(i,_vertex[i]); vertex.set_chisq(0.0); vertex.set_ndof(0); vertex.set_error(0,0,0.0); vertex.set_error(0,1,0.0); vertex.set_error(0,2,0.0); vertex.set_error(1,0,0.0); vertex.set_error(1,1,0.0); vertex.set_error(1,2,0.0); vertex.set_error(2,0,0.0); vertex.set_error(2,1,0.0); vertex.set_error(2,2,0.0); // copy out the reconstructed vertex position //_g4tracks->setVertex(_vertex[0],_vertex[1],_vertex[2]); //_g4tracks->setVertexError(0.0,0.0,0.0); // at this point we should already have an initial pt and pz guess... // need to translate this into the PHG4Track object... vector<SimpleHit3D> track_hits; int clusterID; int clusterLayer; float cluster_x; float cluster_y; float cluster_z; // float dEdx1; // float dEdx2; for(unsigned int itrack=0; itrack<_tracks.size();itrack++) { SvtxTrack_v1 track; track.set_id(itrack); track_hits.clear(); track_hits = _tracks.at(itrack).hits; for(unsigned int ihit = 0; ihit<track_hits.size();ihit++) { // dEdx1=0; // dEdx2=0; if( (track_hits.at(ihit).index) >= _g4clusters->size()){continue;} SvtxCluster *cluster = _g4clusters->get(track_hits.at(ihit).index); clusterID = cluster->get_id(); clusterLayer = cluster->get_layer(); cluster_x = cluster->get_x(); cluster_y = cluster->get_y(); cluster_z = cluster->get_z(); if( (clusterLayer < (int)_seed_layers) && (clusterLayer >= 0) ) { track.insert_cluster(clusterID); } } float kappa = _tracks.at(itrack).kappa; float d = _tracks.at(itrack).d; float phi = _tracks.at(itrack).phi; float dzdl = _tracks.at(itrack).dzdl; float z0 = _tracks.at(itrack).z0; // track.set_helix_phi(phi); // track.set_helix_kappa(kappa); // track.set_helix_d(d); // track.set_helix_z0(z0); // track.set_helix_dzdl(dzdl); float pT = kappaToPt(kappa); float x_center = cos(phi)*(d+1/kappa); // x coordinate of circle center float y_center = sin(phi)*(d+1/kappa); // y " " " " // find helicity from cross product sign short int helicity; if((track_hits[0].x-x_center)*(track_hits[track_hits.size()-1].y-y_center) - (track_hits[0].y-y_center)*(track_hits[track_hits.size()-1].x-x_center) > 0) { helicity = 1; } else { helicity = -1; } float pZ = 0; if(dzdl != 1) { pZ = pT * dzdl / sqrt(1.0 - dzdl*dzdl); } int ndf = 2*_tracks.at(itrack).hits.size() - 5; track.set_chisq(chi_squareds[itrack]); track.set_ndf(ndf); track.set_px( pT*cos(phi-helicity*M_PI/2) ); track.set_py( pT*sin(phi-helicity*M_PI/2) ); track.set_pz( pZ ); track.set_dca2d( d ); track.set_dca2d_error(sqrt(_tracker->getKalmanStates()[itrack].C(1,1))); if(_write_reco_tree==true) { _recoevent->tracks.push_back( SimpleRecoTrack() ); _recoevent->tracks.back().px = pT*cos(phi-helicity*M_PI/2); _recoevent->tracks.back().py = pT*sin(phi-helicity*M_PI/2); _recoevent->tracks.back().pz = pZ; _recoevent->tracks.back().d = d; _recoevent->tracks.back().z0 = z0; _recoevent->tracks.back().quality = chi_squareds[itrack]/((float)ndf); _recoevent->tracks.back().charge = (-1*helicity); } if(_magField > 0) { track.set_charge( helicity ); } else { track.set_charge( -1.0*helicity ); } Matrix<float,6,6> euclidean_cov = Matrix<float,6,6>::Zero(6,6); convertHelixCovarianceToEuclideanCovariance( _magField, phi, d, kappa, z0, dzdl, _tracker->getKalmanStates()[itrack].C, euclidean_cov ); for(unsigned int row=0;row<6;++row) { for(unsigned int col=0;col<6;++col) { track.set_error(row,col,euclidean_cov(row,col)); } } track.set_x( vertex.get_x() + d*cos(phi) ); track.set_y( vertex.get_y() + d*sin(phi) ); track.set_z( vertex.get_z() + z0 ); _g4tracks->insert(&track); vertex.insert_track(track.get_id()); if (verbosity > 5) { cout << "track " << itrack << " quality = " << track.get_quality() << endl; cout << "px = " << track.get_px() << " py = " << track.get_py() << " pz = " << track.get_pz() << endl; } } // track loop SvtxVertex *vtxptr = _g4vertexes->insert(&vertex); if (verbosity > 5) vtxptr->identify(); if(verbosity > 0) { cout << "PHG4HoughTransformTPC::process_event -- leaving process_event" << endl; } if(_write_reco_tree==true){ _reco_tree->Fill(); } _timer.get()->stop(); return Fun4AllReturnCodes::EVENT_OK; }
void SvtxEvaluator::printInputInfo(PHCompositeNode *topNode) { if (verbosity > 1) cout << "SvtxEvaluator::printInputInfo() entered" << endl; if (verbosity > 3) { // event information cout << endl; cout << PHWHERE << " INPUT FOR EVENT " << _ievent << endl; cout << endl; cout << "---PHG4HITS-------------" << endl; _svtxevalstack->get_truth_eval()->set_strict(_strict); std::set<PHG4Hit*> g4hits = _svtxevalstack->get_truth_eval()->all_truth_hits(); unsigned int ig4hit = 0; for(std::set<PHG4Hit*>::iterator iter = g4hits.begin(); iter != g4hits.end(); ++iter) { PHG4Hit *g4hit = *iter; cout << ig4hit << " of " << g4hits.size(); cout << ": PHG4Hit: " << endl; g4hit->identify(); ++ig4hit; } cout << "---SVTXCLUSTERS-------------" << endl; SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (clustermap) { unsigned int icluster = 0; for (SvtxClusterMap::Iter iter = clustermap->begin(); iter != clustermap->end(); ++iter) { SvtxCluster* cluster = iter->second; cout << icluster << " of " << clustermap->size(); cout << ": SvtxCluster: " << endl; cluster->identify(); ++icluster; } } cout << "---SVXTRACKS-------------" << endl; SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap"); if (trackmap) { unsigned int itrack = 0; for (SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter) { cout << itrack << " of " << trackmap->size(); SvtxTrack *track = iter->second; cout << " : SvtxTrack:" << endl; track->identify(); cout << endl; } } cout << "---SVXVERTEXES-------------" << endl; SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); if (vertexmap) { unsigned int ivertex = 0; for (SvtxVertexMap::Iter iter = vertexmap->begin(); iter != vertexmap->end(); ++iter) { cout << ivertex << " of " << vertexmap->size(); SvtxVertex *vertex = iter->second; cout << " : SvtxVertex:" << endl; vertex->identify(); cout << endl; } } } return; }
void SvtxEvaluator::printOutputInfo(PHCompositeNode *topNode) { if (verbosity > 1) cout << "SvtxEvaluator::printOutputInfo() entered" << endl; //========================================== // print out some useful stuff for debugging //========================================== if (verbosity > 0) { SvtxTrackEval* trackeval = _svtxevalstack->get_track_eval(); SvtxClusterEval* clustereval = _svtxevalstack->get_cluster_eval(); SvtxTruthEval* trutheval = _svtxevalstack->get_truth_eval(); // event information cout << endl; cout << PHWHERE << " NEW OUTPUT FOR EVENT " << _ievent << endl; cout << endl; PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); PHG4VtxPoint *gvertex = truthinfo->GetPrimaryVtx( truthinfo->GetPrimaryVertexIndex() ); float gvx = gvertex->get_x(); float gvy = gvertex->get_y(); float gvz = gvertex->get_z(); float vx = NAN; float vy = NAN; float vz = NAN; SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); if (vertexmap) { if (!vertexmap->empty()) { SvtxVertex* vertex = (vertexmap->begin()->second); vx = vertex->get_x(); vy = vertex->get_y(); vz = vertex->get_z(); } } cout << "===Vertex Reconstruction=======================" << endl; cout << "vtrue = (" << gvx << "," << gvy << "," << gvz << ") => vreco = (" << vx << "," << vy << "," << vz << ")" << endl; cout << endl; cout << "===Tracking Summary============================" << endl; unsigned int ng4hits[100] = {0}; std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(); for (std::set<PHG4Hit*>::iterator iter = g4hits.begin(); iter != g4hits.end(); ++iter) { PHG4Hit *g4hit = *iter; ++ng4hits[g4hit->get_layer()]; } SvtxHitMap* hitmap = findNode::getClass<SvtxHitMap>(topNode,"SvtxHitMap"); unsigned int nhits[100] = {0}; if (hitmap) { for (SvtxHitMap::Iter iter = hitmap->begin(); iter != hitmap->end(); ++iter) { SvtxHit* hit = iter->second; ++nhits[hit->get_layer()]; } } SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); unsigned int nclusters[100] = {0}; if (clustermap) { for (SvtxClusterMap::Iter iter = clustermap->begin(); iter != clustermap->end(); ++iter) { SvtxCluster* cluster = iter->second; ++nclusters[cluster->get_layer()]; } } for (unsigned int ilayer = 0; ilayer < 100; ++ilayer) { cout << "layer " << ilayer << ": nG4hits = " << ng4hits[ilayer] << " => nHits = " << nhits[ilayer] << " => nClusters = " << nclusters[ilayer] << endl; } SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap"); cout << "nGtracks = " << std::distance(truthinfo->GetPrimaryParticleRange().first, truthinfo->GetPrimaryParticleRange().second); cout << " => nTracks = "; if (trackmap) cout << trackmap->size() << endl; else cout << 0 << endl; // cluster wise information if (verbosity > 1) { for(std::set<PHG4Hit*>::iterator iter = g4hits.begin(); iter != g4hits.end(); ++iter) { PHG4Hit *g4hit = *iter; cout << endl; cout << "===PHG4Hit===================================" << endl; cout << " PHG4Hit: "; g4hit->identify(); std::set<SvtxCluster*> clusters = clustereval->all_clusters_from(g4hit); for (std::set<SvtxCluster*>::iterator jter = clusters.begin(); jter != clusters.end(); ++jter) { SvtxCluster *cluster = *jter; cout << "===Created-SvtxCluster================" << endl; cout << "SvtxCluster: "; cluster->identify(); } } PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange(); for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter) { PHG4Particle *particle = iter->second; // track-wise information cout << endl; cout << "=== Gtrack ===================================================" << endl; cout << " PHG4Particle id = " << particle->get_track_id() << endl; particle->identify(); cout << " ptrue = ("; cout.width(5); cout << particle->get_px(); cout << ","; cout.width(5); cout << particle->get_py(); cout << ","; cout.width(5); cout << particle->get_pz(); cout << ")" << endl; cout << " vtrue = ("; cout.width(5); cout << truthinfo->GetVtx(particle->get_vtx_id())->get_x(); cout << ","; cout.width(5); cout << truthinfo->GetVtx(particle->get_vtx_id())->get_y(); cout << ","; cout.width(5); cout << truthinfo->GetVtx(particle->get_vtx_id())->get_z(); cout << ")" << endl; cout << " pt = " << sqrt(pow(particle->get_px(),2)+pow(particle->get_py(),2)) << endl; cout << " phi = " << atan2(particle->get_py(),particle->get_px()) << endl; cout << " eta = " << asinh(particle->get_pz()/sqrt(pow(particle->get_px(),2)+pow(particle->get_py(),2))) << endl; cout << " embed flag = " << truthinfo->isEmbeded(particle->get_track_id()) << endl; cout << " ---Associated-PHG4Hits-----------------------------------------" << endl; std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(particle); for(std::set<PHG4Hit*>::iterator jter = g4hits.begin(); jter != g4hits.end(); ++jter) { PHG4Hit *g4hit = *jter; float x = 0.5*(g4hit->get_x(0)+g4hit->get_x(1)); float y = 0.5*(g4hit->get_y(0)+g4hit->get_y(1)); float z = 0.5*(g4hit->get_z(0)+g4hit->get_z(1)); cout << " #" << g4hit->get_hit_id() << " xtrue = ("; cout.width(5); cout << x; cout << ","; cout.width(5); cout << y; cout << ","; cout.width(5); cout << z; cout << ")"; std::set<SvtxCluster*> clusters = clustereval->all_clusters_from(g4hit); for (std::set<SvtxCluster*>::iterator kter = clusters.begin(); kter != clusters.end(); ++kter) { SvtxCluster *cluster = *kter; float x = cluster->get_x(); float y = cluster->get_y(); float z = cluster->get_z(); cout << " => #" << cluster->get_id(); cout << " xreco = ("; cout.width(5); cout << x; cout << ","; cout.width(5); cout << y; cout << ","; cout.width(5); cout << z; cout << ")"; } cout << endl; } if (trackmap&&clustermap) { std::set<SvtxTrack*> tracks = trackeval->all_tracks_from(particle); for (std::set<SvtxTrack*>::iterator jter = tracks.begin(); jter != tracks.end(); ++jter) { SvtxTrack *track = *jter; float px = track->get_px(); float py = track->get_py(); float pz = track->get_pz(); cout << "===Created-SvtxTrack==========================================" << endl; cout << " SvtxTrack id = " << track->get_id() << endl; cout << " preco = ("; cout.width(5); cout << px; cout << ","; cout.width(5); cout << py; cout << ","; cout.width(5); cout << pz; cout << ")" << endl; cout << " quality = " << track->get_quality() << endl; cout << " nfromtruth = " << trackeval->get_nclusters_contribution(track,particle) << endl; cout << " ---Associated-SvtxClusters-to-PHG4Hits-------------------------" << endl; for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; SvtxCluster* cluster = clustermap->get(cluster_id); float x = cluster->get_x(); float y = cluster->get_y(); float z = cluster->get_z(); cout << " #" << cluster->get_id() << " xreco = ("; cout.width(5); cout << x; cout << ","; cout.width(5); cout << y; cout << ","; cout.width(5); cout << z; cout << ") =>"; PHG4Hit* g4hit = clustereval->max_truth_hit_by_energy(cluster); if ((g4hit) && (g4hit->get_trkid() == particle->get_track_id())) { x = 0.5*(g4hit->get_x(0)+g4hit->get_x(1)); y = 0.5*(g4hit->get_y(0)+g4hit->get_y(1)); z = 0.5*(g4hit->get_z(0)+g4hit->get_z(1)); cout << " #" << g4hit->get_hit_id() << " xtrue = ("; cout.width(5); cout << x; cout << ","; cout.width(5); cout << y; cout << ","; cout.width(5); cout << z; cout << ") => Gtrack id = " << g4hit->get_trkid(); } else { cout << " noise hit"; } } cout << endl; } } } } cout << endl; } // if verbosity return; }
void SvtxEvaluator::fillOutputNtuples(PHCompositeNode *topNode) { if (verbosity > 1) cout << "SvtxEvaluator::fillOutputNtuples() entered" << endl; SvtxVertexEval* vertexeval = _svtxevalstack->get_vertex_eval(); SvtxTrackEval* trackeval = _svtxevalstack->get_track_eval(); SvtxClusterEval* clustereval = _svtxevalstack->get_cluster_eval(); SvtxHitEval* hiteval = _svtxevalstack->get_hit_eval(); SvtxTruthEval* trutheval = _svtxevalstack->get_truth_eval(); //----------------------- // fill the Vertex NTuple //----------------------- if (_ntp_vertex) { SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (vertexmap && truthinfo) { for (SvtxVertexMap::Iter iter = vertexmap->begin(); iter != vertexmap->end(); ++iter) { SvtxVertex* vertex = iter->second; PHG4VtxPoint* point = vertexeval->max_truth_point_by_ntracks(vertex); float vx = vertex->get_x(); float vy = vertex->get_y(); float vz = vertex->get_z(); float ntracks = vertex->size_tracks(); float gvx = NAN; float gvy = NAN; float gvz = NAN; float gntracks = truthinfo->GetNumPrimaryVertexParticles(); float nfromtruth = NAN; if (point) { gvx = point->get_x(); gvy = point->get_y(); gvz = point->get_z(); gntracks = truthinfo->GetNumPrimaryVertexParticles(); nfromtruth = vertexeval->get_ntracks_contribution(vertex,point); } float vertex_data[10] = {_ievent, vx, vy, vz, ntracks, gvx, gvy, gvz, gntracks, nfromtruth }; _ntp_vertex->Fill(vertex_data); } } } //----------------------- // fill the gpoint NTuple //----------------------- if (_ntp_gpoint) { SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (vertexmap && truthinfo) { PHG4VtxPoint* point = truthinfo->GetPrimaryVtx(truthinfo->GetPrimaryVertexIndex()); SvtxVertex* vertex = vertexeval->best_vertex_from(point); float gvx = point->get_x(); float gvy = point->get_y(); float gvz = point->get_z(); float gntracks = truthinfo->GetNumPrimaryVertexParticles(); float vx = NAN; float vy = NAN; float vz = NAN; float ntracks = NAN; float nfromtruth = NAN; if (vertex) { vx = vertex->get_x(); vy = vertex->get_y(); vz = vertex->get_z(); ntracks = vertex->size_tracks(); nfromtruth = vertexeval->get_ntracks_contribution(vertex,point); } float gpoint_data[10] = {_ievent, gvx, gvy, gvz, gntracks, vx, vy, vz, ntracks, nfromtruth }; _ntp_gpoint->Fill(gpoint_data); } } //--------------------- // fill the G4hit NTuple //--------------------- if (_ntp_g4hit) { std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(); for (std::set<PHG4Hit*>::iterator iter = g4hits.begin(); iter != g4hits.end(); ++iter) { PHG4Hit *g4hit = *iter; PHG4Particle *g4particle = trutheval->get_particle(g4hit); float g4hitID = g4hit->get_hit_id(); float gx = 0.5*(g4hit->get_x(0)+g4hit->get_x(1)); float gy = 0.5*(g4hit->get_y(0)+g4hit->get_y(1)); float gz = 0.5*(g4hit->get_z(0)+g4hit->get_z(1)); float gedep = g4hit->get_edep(); float glayer = g4hit->get_layer(); float gtrackID = g4hit->get_trkid(); float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gembed = NAN; float gprimary = NAN; float gfpx = NULL; float gfpy = NULL; float gfpz = NULL; float gfx = NULL; float gfy = NULL; float gfz = NULL; if (g4particle) { gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle) std::set<SvtxCluster*> clusters = clustereval->all_clusters_from(g4hit); float nclusters = clusters.size(); // best cluster reco'd SvtxCluster* cluster = clustereval->best_cluster_from(g4hit); float clusID = NAN; float x = NAN; float y = NAN; float z = NAN; float e = NAN; float adc = NAN; float layer = NAN; float size = NAN; float phisize = NAN; float zsize = NAN; float efromtruth = NAN; if (cluster) { clusID = cluster->get_id(); x = cluster->get_x(); y = cluster->get_y(); z = cluster->get_z(); e = cluster->get_e(); adc = cluster->get_adc(); layer = cluster->get_layer(); size = cluster->size_hits(); phisize = cluster->get_phi_size(); zsize = cluster->get_z_size(); if (g4particle) { efromtruth = clustereval->get_energy_contribution(cluster,g4particle); } } float g4hit_data[35] = {_ievent, g4hitID, gx, gy, gz, gedep, glayer, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, nclusters, clusID, x, y, z, e, adc, layer, size, phisize, zsize, efromtruth }; _ntp_g4hit->Fill(g4hit_data); } } //-------------------- // fill the Hit NTuple //-------------------- if (_ntp_hit) { // need things off of the DST... SvtxHitMap* hitmap = findNode::getClass<SvtxHitMap>(topNode,"SvtxHitMap"); if (hitmap) { for (SvtxHitMap::Iter iter = hitmap->begin(); iter != hitmap->end(); ++iter) { SvtxHit* hit = iter->second; PHG4Hit* g4hit = hiteval->max_truth_hit_by_energy(hit); PHG4CylinderCell* g4cell = hiteval->get_cell(hit); PHG4Particle* g4particle = trutheval->get_particle(g4hit); float event = _ievent; float hitID = hit->get_id(); float e = hit->get_e(); float adc = hit->get_adc(); float layer = hit->get_layer(); float cellID = hit->get_cellid(); float ecell = g4cell->get_edep(); float g4hitID = NAN; float gedep = NAN; float gx = NAN; float gy = NAN; float gz = NAN; float gtrackID = NAN; float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float glast = NAN; float gembed = NAN; float gprimary = NAN; float efromtruth = NAN; if (g4hit) { g4hitID = g4hit->get_hit_id(); gedep = g4hit->get_edep(); gx = 0.5*(g4hit->get_x(0)+g4hit->get_x(1)); gy = 0.5*(g4hit->get_y(0)+g4hit->get_y(1)); gz = 0.5*(g4hit->get_z(0)+g4hit->get_z(1)); gx = g4hit->get_x(0); gy = g4hit->get_y(0); gz = g4hit->get_z(0); if (g4particle) { gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } glast = NAN; gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle){ } if (g4particle) { efromtruth = hiteval->get_energy_contribution(hit,g4particle); } float hit_data[32] = { event, hitID, e, adc, layer, cellID, ecell, g4hitID, gedep, gx, gy, gz, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, efromtruth }; _ntp_hit->Fill(hit_data); } } } //------------------------ // fill the Cluster NTuple //------------------------ if (_ntp_cluster) { // need things off of the DST... SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (clustermap) { for (SvtxClusterMap::Iter iter = clustermap->begin(); iter != clustermap->end(); ++iter) { SvtxCluster* cluster = iter->second; PHG4Hit *g4hit = clustereval->max_truth_hit_by_energy(cluster); PHG4Particle *g4particle = trutheval->get_particle(g4hit); float hitID = cluster->get_id(); float x = cluster->get_x(); float y = cluster->get_y(); float z = cluster->get_z(); float e = cluster->get_e(); float adc = cluster->get_adc(); float layer = cluster->get_layer(); float size = cluster->size_hits(); float phisize = cluster->get_phi_size(); float zsize = cluster->get_z_size(); float g4hitID = NAN; float gx = NAN; float gy = NAN; float gz = NAN; float gtrackID = NAN; float gflavor = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float glast = NAN; float gembed = NAN; float gprimary = NAN; float nhits = NAN; float efromtruth = NAN; if (g4hit) { g4hitID = g4hit->get_hit_id(); gx = 0.5*(g4hit->get_x(0)+g4hit->get_x(1)); gy = 0.5*(g4hit->get_y(0)+g4hit->get_y(1)); gz = 0.5*(g4hit->get_z(0)+g4hit->get_z(1)); gx = g4hit->get_x(0); gy = g4hit->get_y(0); gz = g4hit->get_z(0); if (g4particle) { gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } glast = NAN; gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); } // if (g4particle){ } // if (g4hit) { if (g4particle){ efromtruth = clustereval->get_energy_contribution(cluster,g4particle); } float cluster_data[33] = {_ievent, hitID, x, y, z, e, adc, layer, size, phisize, zsize, g4hitID, gx, gy, gz, gtrackID, gflavor, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, nhits, efromtruth}; _ntp_cluster->Fill(cluster_data); } } } //------------------------ // fill the Gtrack NTuple //------------------------ // need things off of the DST... if (_ntp_gtrack) { PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (truthinfo) { PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange(); for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter) { PHG4Particle* g4particle = iter->second; float gtrackID = g4particle->get_track_id(); float gflavor = g4particle->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle); float ng4hits = g4hits.size(); float gpx = g4particle->get_px(); float gpy = g4particle->get_py(); float gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); float gvx = vtx->get_x(); float gvy = vtx->get_y(); float gvz = vtx->get_z(); float gfpx = NULL; float gfpy = NULL; float gfpz = NULL; float gfx = NULL; float gfy = NULL; float gfz = NULL; PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } float gembed = trutheval->get_embed(g4particle); float gprimary = trutheval->is_primary(g4particle); SvtxTrack* track = trackeval->best_track_from(g4particle); float trackID = NAN; float charge = NAN; float quality = NAN; float chisq = NAN; float ndf = NAN; float nhits = NAN; unsigned int layers = 0x0; float dca = NAN; float dca2d = NAN; float dca2dsigma = NAN; float px = NAN; float py = NAN; float pz = NAN; float pcax = NAN; float pcay = NAN; float pcaz = NAN; float nfromtruth = NAN; if (track) { trackID = track->get_id(); charge = track->get_charge(); quality = track->get_quality(); chisq = track->get_chisq(); ndf = track->get_ndf(); nhits = track->size_clusters(); for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; SvtxCluster* cluster = clustermap->get(cluster_id); unsigned int layer = cluster->get_layer(); if (layer < 32) layers |= (0x1 << layer); } dca = track->get_dca(); dca2d = track->get_dca2d(); dca2dsigma = track->get_dca2d_error(); px = track->get_px(); py = track->get_py(); pz = track->get_pz(); pcax = track->get_x(); pcay = track->get_y(); pcaz = track->get_z(); nfromtruth = trackeval->get_nclusters_contribution(track,g4particle); } float gtrack_data[34] = {_ievent, gtrackID, gflavor, ng4hits, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, trackID, px, py, pz, charge, quality, chisq, ndf, nhits, layers, dca2d, dca2dsigma, pcax, pcay, pcaz, nfromtruth }; _ntp_gtrack->Fill(gtrack_data); } } } //------------------------ // fill the Track NTuple //------------------------ if (_ntp_track) { // need things off of the DST... SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap"); SvtxClusterMap* clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap"); if (trackmap) { for (SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter) { SvtxTrack* track = iter->second; float trackID = track->get_id(); float charge = track->get_charge(); float quality = track->get_quality(); float chisq = track->get_chisq(); float ndf = track->get_ndf(); float nhits = track->size_clusters(); unsigned int layers = 0x0; for (SvtxTrack::ConstClusterIter iter = track->begin_clusters(); iter != track->end_clusters(); ++iter) { unsigned int cluster_id = *iter; SvtxCluster* cluster = clustermap->get(cluster_id); unsigned int layer = cluster->get_layer(); if (layer < 32) layers |= (0x1 << layer); } float dca2d = track->get_dca2d(); float dca2dsigma = track->get_dca2d_error(); float px = track->get_px(); float py = track->get_py(); float pz = track->get_pz(); float pcax = track->get_x(); float pcay = track->get_y(); float pcaz = track->get_z(); float presdphi = track->get_cal_dphi(SvtxTrack::PRES); float presdeta = track->get_cal_deta(SvtxTrack::PRES); float prese3x3 = track->get_cal_energy_3x3(SvtxTrack::PRES); float prese = track->get_cal_cluster_e(SvtxTrack::PRES); float cemcdphi = track->get_cal_dphi(SvtxTrack::CEMC); float cemcdeta = track->get_cal_deta(SvtxTrack::CEMC); float cemce3x3 = track->get_cal_energy_3x3(SvtxTrack::CEMC); float cemce = track->get_cal_cluster_e(SvtxTrack::CEMC); float hcalindphi = track->get_cal_dphi(SvtxTrack::HCALIN); float hcalindeta = track->get_cal_deta(SvtxTrack::HCALIN); float hcaline3x3 = track->get_cal_energy_3x3(SvtxTrack::HCALIN); float hcaline = track->get_cal_cluster_e(SvtxTrack::HCALIN); float hcaloutdphi = track->get_cal_dphi(SvtxTrack::HCALOUT); float hcaloutdeta = track->get_cal_deta(SvtxTrack::HCALOUT); float hcaloute3x3 = track->get_cal_energy_3x3(SvtxTrack::HCALOUT); float hcaloute = track->get_cal_cluster_e(SvtxTrack::HCALOUT); float gtrackID = NAN; float gflavor = NAN; float ng4hits = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gfpx = NAN; float gfpy = NAN; float gfpz = NAN; float gfx = NAN; float gfy = NAN; float gfz = NAN; float gembed = NAN; float gprimary = NAN; float nfromtruth = NAN; PHG4Particle* g4particle = trackeval->max_truth_particle_by_nclusters(track); if (g4particle) { gtrackID = g4particle->get_track_id(); gflavor = g4particle->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle); ng4hits = g4hits.size(); gpx = g4particle->get_px(); gpy = g4particle->get_py(); gpz = g4particle->get_pz(); PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle); gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); PHG4Hit* outerhit = trutheval->get_outermost_truth_hit(g4particle); if (outerhit) { gfpx = outerhit->get_px(1); gfpy = outerhit->get_py(1); gfpz = outerhit->get_pz(1); gfx = outerhit->get_x(1); gfy = outerhit->get_y(1); gfz = outerhit->get_z(1); } gembed = trutheval->get_embed(g4particle); gprimary = trutheval->is_primary(g4particle); nfromtruth = trackeval->get_nclusters_contribution(track,g4particle); } float track_data[50] = {_ievent, trackID, px, py, pz, charge, quality, chisq, ndf, nhits, layers, dca2d, dca2dsigma, pcax, pcay, pcaz, presdphi, presdeta, prese3x3, prese, cemcdphi, cemcdeta, cemce3x3, cemce, hcalindphi, hcalindeta, hcaline3x3, hcaline, hcaloutdphi, hcaloutdeta, hcaloute3x3, hcaloute, gtrackID, gflavor, ng4hits, gpx, gpy, gpz, gvx, gvy, gvz, gfpx, gfpy, gfpz, gfx, gfy, gfz, gembed, gprimary, nfromtruth }; _ntp_track->Fill(track_data); } } } return; }
void CaloEvaluator::fillOutputNtuples(PHCompositeNode *topNode) { if (verbosity > 2) cout << "CaloEvaluator::fillOutputNtuples() entered" << endl; CaloRawClusterEval* clustereval = _caloevalstack->get_rawcluster_eval(); CaloRawTowerEval* towereval = _caloevalstack->get_rawtower_eval(); CaloTruthEval* trutheval = _caloevalstack->get_truth_eval(); //---------------------- // fill the Event NTuple //---------------------- if (_do_gpoint_eval) { // need things off of the DST... PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (!truthinfo) { cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl; exit(-1); } // need things off of the DST... SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); PHG4VtxPoint *gvertex = truthinfo->GetPrimaryVtx( truthinfo->GetPrimaryVertexIndex() ); float gvx = gvertex->get_x(); float gvy = gvertex->get_y(); float gvz = gvertex->get_z(); float vx = NAN; float vy = NAN; float vz = NAN; if (vertexmap) { if (!vertexmap->empty()) { SvtxVertex* vertex = (vertexmap->begin()->second); vx = vertex->get_x(); vy = vertex->get_y(); vz = vertex->get_z(); } } float gpoint_data[7] = {_ievent, gvx, gvy, gvz, vx, vy, vz }; _ntp_gpoint->Fill(gpoint_data); } //------------------------ // fill the Gshower NTuple //------------------------ if (_ntp_gshower) { if (verbosity > 1) cout << "CaloEvaluator::filling gshower ntuple..." << endl; PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (!truthinfo) { cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl; exit(-1); } PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange(); for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter) { PHG4Particle* primary = iter->second; if (primary->get_e() < _truth_e_threshold) continue; if (!_truth_trace_embed_flags.empty()) { if (_truth_trace_embed_flags.find(trutheval->get_embed(primary)) == _truth_trace_embed_flags.end()) continue; } float gparticleID = primary->get_track_id(); float gflavor = primary->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->get_shower_from_primary(primary); float gnhits = g4hits.size(); float gpx = primary->get_px(); float gpy = primary->get_py(); float gpz = primary->get_pz(); float ge = primary->get_e(); float gpt = sqrt(gpx*gpx+gpy*gpy); float geta = NAN; if (gpt != 0.0) geta = asinh(gpz/gpt); float gphi = atan2(gpy,gpx); PHG4VtxPoint* vtx = trutheval->get_vertex(primary); float gvx = vtx->get_x(); float gvy = vtx->get_y(); float gvz = vtx->get_z(); float gembed = trutheval->get_embed(primary); float gedep = trutheval->get_shower_energy_deposit(primary); float gmrad = trutheval->get_shower_moliere_radius(primary); RawCluster* cluster = clustereval->best_cluster_from(primary); float clusterID = NAN; float ntowers = NAN; float eta = NAN; float phi = NAN; float e = NAN; float efromtruth = NAN; if (cluster) { clusterID = cluster->get_id(); ntowers = cluster->getNTowers(); eta = cluster->get_eta(); phi = cluster->get_phi(); e = cluster->get_energy(); efromtruth = clustereval->get_energy_contribution(cluster, primary); } float shower_data[20] = {_ievent, gparticleID, gflavor, gnhits, geta, gphi, ge, gpt, gvx, gvy, gvz, gembed, gedep, gmrad, clusterID, ntowers, eta, phi, e, efromtruth }; _ntp_gshower->Fill(shower_data); } } //---------------------- // fill the Tower NTuple //---------------------- if (_do_tower_eval) { if (verbosity > 1) cout << "CaloEvaluator::filling tower ntuple..." << endl; string towernode = "TOWER_CALIB_" + _caloname; RawTowerContainer* towers = findNode::getClass<RawTowerContainer>(topNode,towernode.c_str()); if (!towers) { cerr << PHWHERE << " ERROR: Can't find " << towernode << endl; exit(-1); } string towergeomnode = "TOWERGEOM_" + _caloname; RawTowerGeomContainer* towergeom = findNode::getClass<RawTowerGeomContainer>(topNode,towergeomnode.c_str()); if (!towergeom) { cerr << PHWHERE << " ERROR: Can't find " << towergeomnode << endl; exit(-1); } RawTowerContainer::ConstRange begin_end = towers->getTowers(); RawTowerContainer::ConstIterator rtiter; for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter) { RawTower *tower = rtiter->second; if (tower->get_energy() < _reco_e_threshold) continue; float towerid = tower->get_id(); float ieta = tower->get_bineta(); float iphi = tower->get_binphi(); float eta = towergeom->get_etacenter(tower->get_bineta()); float phi = towergeom->get_phicenter(tower->get_binphi()); float e = tower->get_energy(); PHG4Particle* primary = towereval->max_truth_primary_by_energy(tower); float gparticleID = NAN; float gflavor = NAN; float gnhits = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float ge = NAN; float gpt = NAN; float geta = NAN; float gphi = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gembed = NAN; float gedep = NAN; float gmrad = NAN; float efromtruth = NAN; if (primary) { gparticleID = primary->get_track_id(); gflavor = primary->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->get_shower_from_primary(primary); gnhits = g4hits.size(); gpx = primary->get_px(); gpy = primary->get_py(); gpz = primary->get_pz(); ge = primary->get_e(); gpt = sqrt(gpx * gpx + gpy * gpy); if (gpt != 0.0) geta = asinh(gpz / gpt); gphi = atan2(gpy, gpx); PHG4VtxPoint* vtx = trutheval->get_vertex(primary); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } gembed = trutheval->get_embed(primary); gedep = trutheval->get_shower_energy_deposit(primary); gmrad = trutheval->get_shower_moliere_radius(primary); efromtruth = towereval->get_energy_contribution(tower, primary); } float tower_data[21] = {_ievent, towerid, ieta, iphi, eta, phi, e, gparticleID, gflavor, gnhits, geta, gphi, ge, gpt, gvx, gvy, gvz, gembed, gedep, gmrad, efromtruth }; _ntp_tower->Fill(tower_data); } } //------------------------ // fill the Cluster NTuple //------------------------ if (_do_cluster_eval) { if (verbosity > 1) cout << "CaloEvaluator::filling gcluster ntuple..." << endl; string clusternode = "CLUSTER_" + _caloname; RawClusterContainer* clusters = findNode::getClass<RawClusterContainer>(topNode,clusternode.c_str()); if (!clusters) { cerr << PHWHERE << " ERROR: Can't find " << clusternode << endl; exit(-1); } // for every cluster for (unsigned int icluster = 0; icluster < clusters->size(); icluster++) { RawCluster *cluster = clusters->getCluster(icluster); if (cluster->get_energy() < _reco_e_threshold) continue; float clusterID = cluster->get_id(); float ntowers = cluster->getNTowers(); float eta = cluster->get_eta(); float phi = cluster->get_phi(); float e = cluster->get_energy(); PHG4Particle* primary = clustereval->max_truth_primary_by_energy(cluster); float gparticleID = NAN; float gflavor = NAN; float gnhits = NAN; float gpx = NAN; float gpy = NAN; float gpz = NAN; float ge = NAN; float gpt = NAN; float geta = NAN; float gphi = NAN; float gvx = NAN; float gvy = NAN; float gvz = NAN; float gembed = NAN; float gedep = NAN; float gmrad = NAN; float efromtruth = NAN; if (primary) { gparticleID = primary->get_track_id(); gflavor = primary->get_pid(); std::set<PHG4Hit*> g4hits = trutheval->get_shower_from_primary(primary); gnhits = g4hits.size(); gpx = primary->get_px(); gpy = primary->get_py(); gpz = primary->get_pz(); ge = primary->get_e(); gpt = sqrt(gpx * gpx + gpy * gpy); if (gpt != 0.0) geta = asinh(gpz / gpt); gphi = atan2(gpy, gpx); PHG4VtxPoint* vtx = trutheval->get_vertex(primary); if (vtx) { gvx = vtx->get_x(); gvy = vtx->get_y(); gvz = vtx->get_z(); } gembed = trutheval->get_embed(primary); gedep = trutheval->get_shower_energy_deposit(primary); gmrad = trutheval->get_shower_moliere_radius(primary); efromtruth = clustereval->get_energy_contribution(cluster, primary); } float cluster_data[20] = {_ievent, clusterID, ntowers, eta, phi, e, gparticleID, gflavor, gnhits, geta, gphi, ge, gpt, gvx, gvy, gvz, gembed, gedep, gmrad, efromtruth }; _ntp_cluster->Fill(cluster_data); } } return; }
void CaloEvaluator::printOutputInfo(PHCompositeNode *topNode) { if (verbosity > 2) cout << "CaloEvaluator::printOutputInfo() entered" << endl; CaloRawClusterEval* clustereval = _caloevalstack->get_rawcluster_eval(); CaloTruthEval* trutheval = _caloevalstack->get_truth_eval(); //========================================== // print out some useful stuff for debugging //========================================== if (verbosity > 1) { // event information cout << endl; cout << PHWHERE << " NEW OUTPUT FOR EVENT " << _ievent << endl; cout << endl; // need things off of the DST... PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if (!truthinfo) { cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl; exit(-1); } // need things off of the DST... SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); PHG4VtxPoint *gvertex = truthinfo->GetPrimaryVtx( truthinfo->GetPrimaryVertexIndex() ); float gvx = gvertex->get_x(); float gvy = gvertex->get_y(); float gvz = gvertex->get_z(); float vx = NAN; float vy = NAN; float vz = NAN; if (vertexmap) { if (!vertexmap->empty()) { SvtxVertex* vertex = (vertexmap->begin()->second); vx = vertex->get_x(); vy = vertex->get_y(); vz = vertex->get_z(); } } cout << "vtrue = (" << gvx << "," << gvy << "," << gvz << ") => vreco = (" << vx << "," << vy << "," << vz << ")" << endl; PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange(); for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter) { PHG4Particle* primary = iter->second; cout << endl; cout << "===Primary PHG4Particle=========================================" << endl; cout << " particle id = " << primary->get_track_id() << endl; cout << " flavor = " << primary->get_pid() << endl; cout << " (px,py,pz,e) = ("; float gpx = primary->get_px(); float gpy = primary->get_py(); float gpz = primary->get_pz(); float ge = primary->get_e(); cout.width(5); cout << gpx; cout << ","; cout.width(5); cout << gpy; cout << ","; cout.width(5); cout << gpz; cout << ","; cout.width(5); cout << ge; cout << ")" << endl; float gpt = sqrt(gpx*gpx+gpy*gpy); float geta = NAN; if (gpt != 0.0) geta = asinh(gpz/gpt); float gphi = atan2(gpy,gpx); cout << "(eta,phi,e,pt) = ("; cout.width(5); cout << geta; cout << ","; cout.width(5); cout << gphi; cout << ","; cout.width(5); cout << ge; cout << ","; cout.width(5); cout << gpt; cout << ")" << endl; PHG4VtxPoint* vtx = trutheval->get_vertex(primary); float gvx = vtx->get_x(); float gvy = vtx->get_y(); float gvz = vtx->get_z(); cout << " vtrue = ("; cout.width(5); cout << gvx; cout << ","; cout.width(5); cout << gvy; cout << ","; cout.width(5); cout << gvz; cout << ")" << endl; cout << " embed = " << trutheval->get_embed(primary) << endl; cout << " edep = " << trutheval->get_shower_energy_deposit(primary) << endl; cout << " mrad = " << trutheval->get_shower_moliere_radius(primary) << endl; std::set<RawCluster*> clusters = clustereval->all_clusters_from(primary); for (std::set<RawCluster*>::iterator clusiter = clusters.begin(); clusiter != clusters.end(); ++clusiter) { RawCluster* cluster = (*clusiter); float ntowers = cluster->getNTowers(); float eta = cluster->get_eta(); float phi = cluster->get_phi(); float e = cluster->get_energy(); float efromtruth = clustereval->get_energy_contribution(cluster, primary); cout << " => #" << cluster->get_id() << " (eta,phi,e) = ("; cout.width(5); cout << eta; cout << ","; cout.width(5); cout << phi; cout << ","; cout.width(5); cout << e; cout << "), ntowers = "<< ntowers <<", efromtruth = " << efromtruth << endl; } } cout << endl; } return; }
int PHG4HoughTransform::export_output() { if (_tracks.empty()) return Fun4AllReturnCodes::EVENT_OK; SvtxVertex_v1 vertex; vertex.set_t0(0.0); for (int i=0;i<3;++i) vertex.set_position(i,_vertex[i]); vertex.set_chisq(0.0); vertex.set_ndof(0); vertex.set_error(0,0,0.0); vertex.set_error(0,1,0.0); vertex.set_error(0,2,0.0); vertex.set_error(1,0,0.0); vertex.set_error(1,1,0.0); vertex.set_error(1,2,0.0); vertex.set_error(2,0,0.0); vertex.set_error(2,1,0.0); vertex.set_error(2,2,0.0); // at this point we should already have an initial pt and pz guess... // need to translate this into the PHG4Track object... vector<SimpleHit3D> track_hits; int clusterID; int clusterLayer; for (unsigned int itrack = 0; itrack < _tracks.size(); itrack++) { SvtxTrack_v1 track; track.set_id(itrack); track_hits.clear(); track_hits = _tracks.at(itrack).hits; for (unsigned int ihit = 0; ihit < track_hits.size(); ihit++) { if ((track_hits.at(ihit).get_id()) >= _g4clusters->size()) { continue; } SvtxCluster* cluster = _g4clusters->get(track_hits.at(ihit).get_id()); clusterID = cluster->get_id(); clusterLayer = cluster->get_layer(); if ((clusterLayer < (int)_nlayers) && (clusterLayer >= 0)) { track.insert_cluster(clusterID); } } float kappa = _tracks.at(itrack).kappa; float d = _tracks.at(itrack).d; float phi = _tracks.at(itrack).phi; float dzdl = _tracks.at(itrack).dzdl; float z0 = _tracks.at(itrack).z0; // track.set_helix_phi(phi); // track.set_helix_kappa(kappa); // track.set_helix_d(d); // track.set_helix_z0(z0); // track.set_helix_dzdl(dzdl); float pT = kappaToPt(kappa); float x_center = cos(phi) * (d + 1 / kappa); // x coordinate of circle center float y_center = sin(phi) * (d + 1 / kappa); // y " " " " // find helicity from cross product sign short int helicity; if ((track_hits[0].get_x() - x_center) * (track_hits[track_hits.size() - 1].get_y() - y_center) - (track_hits[0].get_y() - y_center) * (track_hits[track_hits.size() - 1].get_x() - x_center) > 0) { helicity = 1; } else { helicity = -1; } float pZ = 0; if (dzdl != 1) { pZ = pT * dzdl / sqrt(1.0 - dzdl * dzdl); } int ndf = 2 * _tracks.at(itrack).hits.size() - 5; track.set_chisq(_track_errors[itrack]); track.set_ndf(ndf); track.set_px(pT * cos(phi - helicity * M_PI / 2)); track.set_py(pT * sin(phi - helicity * M_PI / 2)); track.set_pz(pZ); track.set_dca2d(d); track.set_dca2d_error(sqrt(_track_covars[itrack](1, 1))); if (_magField > 0) { track.set_charge(helicity); } else { track.set_charge(-1.0 * helicity); } Eigen::Matrix<float, 6, 6> euclidean_cov = Eigen::Matrix<float, 6, 6>::Zero(6, 6); convertHelixCovarianceToEuclideanCovariance( _magField, phi, d, kappa, z0, dzdl, _track_covars[itrack], euclidean_cov); for (unsigned int row = 0; row < 6; ++row) { for (unsigned int col = 0; col < 6; ++col) { track.set_error(row, col, euclidean_cov(row, col)); } } track.set_x(vertex.get_x() + d * cos(phi)); track.set_y(vertex.get_y() + d * sin(phi)); track.set_z(vertex.get_z() + z0); _g4tracks->insert(&track); vertex.insert_track(track.get_id()); if (verbosity > 5) { cout << "track " << itrack << " quality = " << track.get_quality() << endl; cout << "px = " << track.get_px() << " py = " << track.get_py() << " pz = " << track.get_pz() << endl; } } // track loop SvtxVertex *vtxptr = _g4vertexes->insert(&vertex); if (verbosity > 5) vtxptr->identify(); if (verbosity > 0) { cout << "PHG4HoughTransform::process_event -- leaving process_event" << endl; } // we are done with these now... _clusters.clear(); _tracks.clear(); _track_errors.clear(); _track_covars.clear(); _vertex.clear(); _vertex.assign(3,0.0); return Fun4AllReturnCodes::EVENT_OK; }
int SimpleTrackingAnalysis::process_event(PHCompositeNode *topNode) { // --- This is the class process_event method // --- This is where the bulk of the analysis is done // --- Here we get the various data nodes we need to do the analysis // --- Then we use variables (accessed through class methods) to perform calculations if ( verbosity > -1 ) { cout << endl; cout << "------------------------------------------------------------------------------------" << endl; cout << "Now processing event number " << nevents << endl; // would be good to add verbosity switch } ++nevents; // You may as youtself, why ++nevents (pre-increment) rather // than nevents++ (post-increment)? The short answer is performance. // For simple types it probably doesn't matter, but it can really help // for complex types (like the iterators below). // --- Truth level information PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo"); if ( !truthinfo ) { cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl; exit(-1); } // --- SvtxTrackMap SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap"); if ( !trackmap ) { cerr << PHWHERE << " ERROR: Can't find SvtxTrackMap" << endl; exit(-1); } // --- SvtxVertexMap SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap"); if ( !vertexmap ) { cerr << PHWHERE << " ERROR: Can't find SvtxVertexMap" << endl; exit(-1); } // --- Create SVTX eval stack SvtxEvalStack svtxevalstack(topNode); // --- Get evaluator objects from the eval stack SvtxVertexEval* vertexeval = svtxevalstack.get_vertex_eval(); SvtxTrackEval* trackeval = svtxevalstack.get_track_eval(); SvtxTruthEval* trutheval = svtxevalstack.get_truth_eval(); if ( verbosity > 0 ) cout << "Now going to loop over truth partcles..." << endl; // need verbosity switch // --- Loop over all truth particles PHG4TruthInfoContainer::Range range = truthinfo->GetPrimaryParticleRange(); for ( PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter ) { PHG4Particle* g4particle = iter->second; // You may ask yourself, why second? // In C++ the iterator is a map, which has two members // first is the key (analogous the index of an arry), // second is the value (analogous to the value stored for the array index) int particleID = g4particle->get_pid(); if ( trutheval->get_embed(g4particle) <= 0 && fabs(particleID) == 11 && verbosity > 0 ) { cout << "NON EMBEDDED ELECTRON!!! WHEE!!! " << particleID << " " << iter->first << endl; } if ( trutheval->get_embed(g4particle) <= 0 ) continue; // only look at embedded particles // no good for hits files bool iselectron = fabs(particleID) == 11; bool ispion = fabs(particleID) == 211; if ( verbosity > 0 ) cout << "embedded particle ID is " << particleID << " ispion " << ispion << " iselectron " << iselectron << " " << iter->first << endl; set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle); float ng4hits = g4hits.size(); float truept = sqrt(pow(g4particle->get_px(),2)+pow(g4particle->get_py(),2)); float true_energy = g4particle->get_e(); // --- Get the reconsructed SvtxTrack based on the best candidate from the truth info SvtxTrack* track = trackeval->best_track_from(g4particle); if (!track) continue; float recopt = track->get_pt(); float recop = track->get_p(); if ( verbosity > 0 ) { cout << "truept is " << truept << endl; cout << "recopt is " << recopt << endl; cout << "true energy is " << true_energy << endl; } // --- energy variables directly from the track object float emc_energy_track = track->get_cal_energy_3x3(SvtxTrack::CEMC); float hci_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALIN); float hco_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALOUT); if ( verbosity > 0 ) { cout << "emc_energy_track is " << emc_energy_track << endl; cout << "hci_energy_track is " << hci_energy_track << endl; cout << "hco_energy_track is " << hco_energy_track << endl; } // ------------------------------------------------------------------------------------- // --- IMPORTANT NOTE: according to Jin, dphi and deta will not work correctly in HIJING float emc_dphi_track = track->get_cal_dphi(SvtxTrack::CEMC); float hci_dphi_track = track->get_cal_dphi(SvtxTrack::HCALIN); float hco_dphi_track = track->get_cal_dphi(SvtxTrack::HCALOUT); float emc_deta_track = track->get_cal_deta(SvtxTrack::CEMC); float hci_deta_track = track->get_cal_deta(SvtxTrack::HCALIN); float hco_deta_track = track->get_cal_deta(SvtxTrack::HCALOUT); float assoc_dphi = 0.1; // adjust as needed, consider class set method float assoc_deta = 0.1; // adjust as needed, consider class set method bool good_emc_assoc = fabs(emc_dphi_track) < assoc_dphi && fabs(emc_deta_track) < assoc_deta; bool good_hci_assoc = fabs(hci_dphi_track) < assoc_dphi && fabs(hci_deta_track) < assoc_deta; bool good_hco_assoc = fabs(hco_dphi_track) < assoc_dphi && fabs(hco_deta_track) < assoc_deta; // ------------------------------------------------------------------------------------------ float hct_energy_track = 0; if ( hci_energy_track >= 0 ) hct_energy_track += hci_energy_track; if ( hco_energy_track >= 0 ) hct_energy_track += hco_energy_track; float total_energy_dumb = 0; if ( emc_energy_track >= 0 ) total_energy_dumb += emc_energy_track; if ( hci_energy_track >= 0 ) total_energy_dumb += hci_energy_track; if ( hco_energy_track >= 0 ) total_energy_dumb += hco_energy_track; float total_energy_smart = 0; if ( good_emc_assoc ) total_energy_smart += emc_energy_track; if ( good_hci_assoc ) total_energy_smart += hci_energy_track; if ( good_hco_assoc ) total_energy_smart += hco_energy_track; // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- //cout << "starting the main part of the truth analysis" << endl; // examine truth particles that leave all (7 or 8 depending on design) detector hits if ( ng4hits == nlayers ) { _truept_particles_leavingAllHits->Fill(truept); unsigned int nfromtruth = trackeval->get_nclusters_contribution(track,g4particle); unsigned int ndiff = abs((int)nfromtruth-(int)nlayers); if ( ndiff <= 2 ) _truept_particles_recoWithin2Hits->Fill(truept); if ( ndiff <= 1 ) _truept_particles_recoWithin1Hit->Fill(truept); if ( ndiff == 0 ) _truept_particles_recoWithExactHits->Fill(truept); float diff = fabs(recopt-truept)/truept; if ( diff < 0.05 ) _truept_particles_recoWithin5Percent->Fill(truept); if ( diff < 0.04 ) { _truept_particles_recoWithin4Percent->Fill(truept); _truept_quality_particles_recoWithin4Percent->Fill(truept,track->get_quality()); } if ( diff < 0.03 ) _truept_particles_recoWithin3Percent->Fill(truept); double good_energy = total_energy_dumb - 3.14; double eoverp = good_energy/recop; double sigmapt = 0.011 + 0.0008*recopt; th2d_truept_particles_withcalocuts_leavingAllHits->Fill(truept,eoverp); if ( ndiff <= 2 ) th2d_truept_particles_withcalocuts_recoWithin2Hits->Fill(truept,eoverp); if ( ndiff <= 1 ) th2d_truept_particles_withcalocuts_recoWithin1Hit->Fill(truept,eoverp); if ( ndiff == 0 ) th2d_truept_particles_withcalocuts_recoWithExactHits->Fill(truept,eoverp); if ( diff < 0.05 ) th2d_truept_particles_withcalocuts_recoWithin5Percent->Fill(truept,eoverp); if ( diff < 0.04 ) th2d_truept_particles_withcalocuts_recoWithin4Percent->Fill(truept,eoverp); if ( diff < 0.03 ) th2d_truept_particles_withcalocuts_recoWithin3Percent->Fill(truept,eoverp); if ( diff < 1.0*sigmapt ) th2d_truept_particles_withcalocuts_recoWithin1Sigma->Fill(recopt,eoverp); if ( diff < 2.0*sigmapt ) th2d_truept_particles_withcalocuts_recoWithin2Sigma->Fill(recopt,eoverp); if ( diff < 3.0*sigmapt ) th2d_truept_particles_withcalocuts_recoWithin3Sigma->Fill(recopt,eoverp); } // end of requirement of ng4hits == nlayers } // end of loop over truth particles // loop over all reco particles int ntracks = 0; for ( SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter ) { // --- Get the StxTrack object (from the iterator) SvtxTrack* track = iter->second; float recopt = track->get_pt(); float recop = track->get_p(); // --- Get the truth particle from the evaluator PHG4Particle* g4particle = trackeval->max_truth_particle_by_nclusters(track); float truept = sqrt(pow(g4particle->get_px(),2)+pow(g4particle->get_py(),2)); int particleID = g4particle->get_pid(); if ( verbosity > 5 ) cout << "particle ID is " << particleID << endl; bool iselectron = fabs(particleID) == 11; bool ispion = fabs(particleID) == 211; // --------------------- // --- calorimeter stuff // --------------------- // --- get the energy values directly from the track float emc_energy_track = track->get_cal_energy_3x3(SvtxTrack::CEMC); float hci_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALIN); float hco_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALOUT); float total_energy = 0; if ( emc_energy_track > 0 ) total_energy += emc_energy_track; if ( hci_energy_track > 0 ) total_energy += hci_energy_track; if ( hco_energy_track > 0 ) total_energy += hco_energy_track; if ( verbosity > 2 ) cout << "total calo energy is " << total_energy << endl; if (trutheval->get_embed(g4particle) > 0) { // embedded results (quality or performance measures) _truept_dptoverpt->Fill(truept,(recopt-truept)/truept); _truept_dca->Fill(truept,track->get_dca2d()); _recopt_quality->Fill(recopt,track->get_quality()); if ( verbosity > 0 ) cout << "embedded particle ID is " << particleID << " ispion " << ispion << " iselectron " << iselectron << endl; // --- } // end if (embedded results) else { // electron and pion (hadron) id // non-embedded results (purity measures) _recopt_tracks_all->Fill(recopt); _recopt_quality_tracks_all->Fill(recopt,track->get_quality()); unsigned int nfromtruth = trackeval->get_nclusters_contribution(track,g4particle); unsigned int ndiff = abs((int)nfromtruth-(int)nlayers); if ( ndiff <= 2 ) _recopt_tracks_recoWithin2Hits->Fill(recopt); if ( ndiff <= 1 ) _recopt_tracks_recoWithin1Hit->Fill(recopt); if ( ndiff == 0 ) _recopt_tracks_recoWithExactHits->Fill(recopt); float diff = fabs(recopt-truept)/truept; if ( diff < 0.05 ) _recopt_tracks_recoWithin5Percent->Fill(recopt); if ( diff < 0.04 ) { _recopt_tracks_recoWithin4Percent->Fill(recopt); _recopt_quality_tracks_recoWithin4Percent->Fill(recopt,track->get_quality()); } if ( diff < 0.03 ) _recopt_tracks_recoWithin3Percent->Fill(recopt); // -------------------------------------- // --- same but now with calorimeter cuts // -------------------------------------- double good_energy = total_energy - 3.14; double eoverp = good_energy/recop; double sigmapt = 0.011 + 0.0008*recopt; th2d_recopt_tracks_withcalocuts_all->Fill(recopt,eoverp); if ( ndiff <= 2 ) th2d_recopt_tracks_withcalocuts_recoWithin2Hits->Fill(recopt,eoverp); if ( ndiff <= 1 ) th2d_recopt_tracks_withcalocuts_recoWithin1Hit->Fill(recopt,eoverp); if ( ndiff == 0 ) th2d_recopt_tracks_withcalocuts_recoWithExactHits->Fill(recopt,eoverp); if ( diff < 0.05 ) th2d_recopt_tracks_withcalocuts_recoWithin5Percent->Fill(recopt,eoverp); if ( diff < 0.04 ) th2d_recopt_tracks_withcalocuts_recoWithin4Percent->Fill(recopt,eoverp); if ( diff < 0.03 ) th2d_recopt_tracks_withcalocuts_recoWithin3Percent->Fill(recopt,eoverp); if ( diff < 1.0*sigmapt ) th2d_recopt_tracks_withcalocuts_recoWithin1Sigma->Fill(recopt,eoverp); if ( diff < 2.0*sigmapt ) th2d_recopt_tracks_withcalocuts_recoWithin2Sigma->Fill(recopt,eoverp); if ( diff < 3.0*sigmapt ) th2d_recopt_tracks_withcalocuts_recoWithin3Sigma->Fill(recopt,eoverp); // --- done with reco tracks } // else (non-embedded results) ++ntracks; } // loop over reco tracks hmult->Fill(ntracks); // --- Get the leading vertex SvtxVertex* maxvertex = NULL; unsigned int maxtracks = 0; for ( SvtxVertexMap::Iter iter = vertexmap->begin(); iter != vertexmap->end(); ++iter ) { SvtxVertex* vertex = iter->second; if ( vertex->size_tracks() > maxtracks ) { maxvertex = vertex; maxtracks = vertex->size_tracks(); } } if ( !maxvertex ) { cerr << PHWHERE << " ERROR: cannot get reconstructed vertex (event number " << nevents << ")" << endl; ++nerrors; return Fun4AllReturnCodes::DISCARDEVENT; } // --- Get the coordinates for the vertex from the evaluator PHG4VtxPoint* point = vertexeval->max_truth_point_by_ntracks(maxvertex); if ( !point ) { cerr << PHWHERE << " ERROR: cannot get truth vertex (event number " << nevents << ")" << endl; ++nerrors; return Fun4AllReturnCodes::DISCARDEVENT; } _dx_vertex->Fill(maxvertex->get_x() - point->get_x()); _dy_vertex->Fill(maxvertex->get_y() - point->get_y()); _dz_vertex->Fill(maxvertex->get_z() - point->get_z()); hmult_vertex->Fill(ntracks); return Fun4AllReturnCodes::EVENT_OK; }