#include "ReconPrintout.hxx" #include "ReconObjectUtils.hxx" #include "TrackingUtils.hxx" namespace ReconPrintout { //***************************************************************************** /// Print the contents of the specified container in the specified fit. Details of the /// highest-level objects in the container are also printed. void DumpContainer(COMET::ICOMETEvent& event, const std::string& fit, const std::string& container_name) { //***************************************************************************** std::cout << "Dumping container " << fit << "/" << container_name << ":" << std::endl; COMET::IHandle tc = ReconObjectUtils::GetContainer(event, fit, container_name); if (tc) { DumpContainer(*tc); } } //***************************************************************************** /// Print the contents of the specified container in the specified fit. Details of all objects /// in the container are printed, along with their constituents. void DumpContainerWithHistory(COMET::ICOMETEvent& event, const std::string& fit, const std::string& container_name) { //***************************************************************************** std::cout << "Dumping container (with history) " << fit << "/" << container_name << ":" << std::endl; COMET::IHandle tc = ReconObjectUtils::GetContainer(event, fit, container_name); if (tc) { DumpContainerWithHistory(*tc); } } //***************************************************************************** /// Print the details of top-level objects in the container. void DumpContainer(const COMET::IReconObjectContainer& tc) { //***************************************************************************** if (!(&tc)) { return; } std::cout << std::endl; std::cout << "Dumping container " << tc.GetName() << ":" << std::endl; COMET::IReconObjectContainer::const_iterator pp1; for (pp1 = tc.begin(); pp1 != tc.end(); pp1++) { std::cout << " - " << *pp1 << std::endl; } std::cout << std::endl; } //***************************************************************************** /// Print the details of all objects in the container, including (recursively) all their /// constituents. void DumpContainerWithHistory(const COMET::IReconObjectContainer& tc) { //***************************************************************************** if (!(&tc)) { return; } std::cout << std::endl; std::cout << "Dumping container (with history) " << tc.GetName() << ":" << std::endl; COMET::IReconObjectContainer::const_iterator pp1; for (pp1 = tc.begin(); pp1 != tc.end(); pp1++) { DumpReconHistory(*pp1); } std::cout << std::endl; } //***************************************************************************** /// Recursively print details of the object and its constituents. void DumpReconHistory(COMET::IHandle t1, int nspaces) { //***************************************************************************** std::string spa = ""; for (int i = 0; i < nspaces; i++) { spa = spa + " "; } std::cout << spa << " - " << t1 << std::endl; COMET::IHandle t1const = t1->GetConstituents(); if (!t1const) { return; } COMET::IReconObjectContainer::const_iterator it1; for (it1 = t1const->begin(); it1 != t1const->end(); it1++) { int nspaces_new = nspaces + 2; if (*it1) { DumpReconHistory(*it1, nspaces_new); } } } //***************************************************************************** /// Print the contents of the algorithm result. Prints basic information for all /// THitSelections and TReconObjectContainers. void DumpResult(const COMET::IAlgorithmResult& from) { //***************************************************************************** std::cout << std::endl; std::cout << "dumping IAlgorithmResult '" << from.GetName() << "'" << std::endl; for (COMET::IAlgorithmResult::const_iterator item = from.begin(); item != from.end(); ++item) { TString className((*item)->ClassName()); TString itemName = (*item)->GetName(); // Ignore all symbolic links. // I think that copying these would result in multiple copies of // the hit selections and track containers. if (className.Contains("COMET::IDataSymLink")) { continue; } // Check if it is HitSelection or TrackContainer. if (className.Contains("COMET::IHitSelection")) { COMET::IHandle fromHits = from.Get (itemName); if (!fromHits) { continue; } std::cout << " - IHitSelection '" << itemName << "': " << fromHits->size() << " hits" << std::endl; } if (className.Contains("COMET::IReconObjectContainer")) { COMET::IHandle fromRecon = from.Get (itemName); if (!fromRecon) { continue; } std::cout << " - IReconObjectContainer '" << itemName << "': " << fromRecon->size() << " objects" << std::endl; } } std::cout << std::endl; } } /// Print information related to a IReconCluster. std::ostream& operator<<(std::ostream& os, const COMET::IReconCluster& object) { os << object.ConvertDetector() << " Cluster " << " (" << &object << "): "; if (object.GetHits()) os << "#hits = " << object.GetHits()->size() << ", "; if (object.GetConstituents()) os << "#cons = " << object.GetConstituents()->size() << ", "; os << "#nodes = " << object.GetNodes().size() << ", status = " << object.ConvertStatus(); if (object.CheckStatus(COMET::IReconBase::kSuccess)) { os << ", ndof = " << object.GetNDOF() << ", chi2 = " << object.GetQuality(); } os << ", t = " << object.GetPosition().T(); os << ", E = " << object.GetEDeposit(); return os; } /// Print information related to a IReconPID. std::ostream& operator<<(std::ostream& os, const COMET::IReconPID& object) { os << object.ConvertDetector() << " PID " << " (" << &object << "): "; if (object.GetHits()) os << "#hits = " << object.GetHits()->size() << ", "; if (object.GetConstituents()) { os << "#cons = " << object.GetConstituents()->size() << ", "; if (object.GetConstituents()->size() > 1 && TrackingUtils::GetMatchingChi2(object) != 0) os << "match chi2 = " << TrackingUtils::GetMatchingChi2(object) << ", "; } if (TrackingUtils::GetSenseOK(object)) os << "senseOK = " << TrackingUtils::GetSenseOK(object) << ", "; os << "#nodes = " << object.GetNodes().size() << ", status = " << object.ConvertStatus(); if (object.CheckStatus(COMET::IReconBase::kSuccess)) { os << ", ndof = " << object.GetNDOF() << ", chi2 = " << object.GetQuality(); os << ", p = " << std::setprecision(6) << object.GetMomentum() << ", q = " << object.GetCharge(); } os << ", t = " << object.GetPosition().T(); os << ", PID = " << object.ConvertParticleId() << ", weight = " << object.GetPIDWeight() << ", #alter = " << object.GetAlternates().size(); return os; } //******************************************* /// Print information related to a IReconTrack. std::ostream& operator<<(std::ostream& os, const COMET::IReconTrack& object) { //******************************************* os << object.ConvertDetector() << " Track " <<" (" << &object << "): "; if (object.GetHits()) os << " #hits = " << object.GetHits()->size() << ", "; if (object.GetConstituents()){ os << "#cons = " << object.GetConstituents()->size() << ", "; if (object.GetConstituents()->size() > 1 && TrackingUtils::GetMatchingChi2(object) != 0) os << "match chi2 = " << TrackingUtils::GetMatchingChi2(object) << ", "; } if (TrackingUtils::GetSenseOK(object)) os << "senseOK = " << TrackingUtils::GetSenseOK(object) << ", "; os << "#nodes = " << object.GetNodes().size() << ", status = " << object.ConvertStatus(); if (object.CheckStatus(COMET::IReconBase::kSuccess)){ os << ", ndof = " << object.GetNDOF() << ", chi2 = " << object.GetQuality(); if (object.GetState()){ os << ", p = " << std::setprecision(6) << TrackingUtils::GetMomentum(object.GetState()) << ", q = " << TrackingUtils::GetCharge(object.GetState()); } } os << ", t = " << object.GetPosition().T(); os << ", r = (" << object.GetPosition().X() << ", " << object.GetPosition().Y() << ", " << object.GetPosition().Z() << ")"; return os; } //******************************************* /// Print information related to a IReconShower. std::ostream& operator<<(std::ostream& os, const COMET::IReconShower& object) { //******************************************* os << object.ConvertDetector() << " Shower " <<" (" << &object << "): "; if (object.GetHits()) os << "#hits = " << object.GetHits()->size() << ", "; if (object.GetConstituents()) os << "#cons = " << object.GetConstituents()->size() << ", "; os << "#nodes = " << object.GetNodes().size() << ", status = " << object.ConvertStatus(); if (object.CheckStatus(COMET::IReconBase::kSuccess)){ os << ", ndof = " << object.GetNDOF() << ", chi2 = " << object.GetQuality(); } os << ", t = " << object.GetPosition().T(); os << ", r = (" << object.GetPosition().X() << ", " << object.GetPosition().Y() << ", " << object.GetPosition().Z() << ")"; os << ", E = " << object.GetEDeposit(); return os; } //******************************************* /// Print information related to a IReconVertex. std::ostream& operator<<(std::ostream& os, const COMET::IReconVertex& object) { //******************************************* os << object.ConvertDetector() << " Vertex " << " (" << &object << "): pos = " << object.GetPosition().X() << object.GetPosition().Y() << object.GetPosition().Z() << " t = " << object.GetPosition().T(); if (object.GetConstituents()){ os << ", #cons = " << object.GetConstituents()->size(); } os << ", #nodes = " << object.GetNodes().size() << ", status = " << object.ConvertStatus(); if (object.CheckStatus(COMET::IReconBase::kSuccess)){ os << ", ndof = " << object.GetNDOF() << ", chi2 = " << object.GetQuality(); } return os; } //******************************************* /// Print information related to a generic IReconBase object. std::ostream& operator<<(std::ostream& os, const COMET::IReconBase& object) { //******************************************* os << object.ConvertDetector() << " IReconBase " <<" (" << &object << "): "; if (object.GetHits()) os << " #hits = " << object.GetHits()->size() << ", "; if (object.GetConstituents()) os << "#cons = " << object.GetConstituents()->size() << ", "; if (TrackingUtils::GetSenseOK(object)) os << "senseOK = " << TrackingUtils::GetSenseOK(object) << ", "; os << "#nodes = " << object.GetNodes().size() << ", status = " << object.ConvertStatus(); if (object.CheckStatus(COMET::IReconBase::kSuccess)) os << ", ndof = " << object.GetNDOF() << ", chi2 = " << object.GetQuality(); return os; } //******************************************* /// Print information related a TRecon* object. The appropriate operator is called /// for the object type. std::ostream& operator<<(std::ostream& os, const COMET::IHandle& object) { //******************************************* COMET::IHandle cluster = object; if (cluster) os << *cluster; COMET::IHandle pid = object; if (pid) os << *pid; COMET::IHandle track = object; if (track) os << *track; COMET::IHandle vertex = object; if (vertex) os << *vertex; COMET::IHandle shower = object; if (shower) os << *shower; return os; }