#include "IReconPID.hxx" ClassImp(COMET::IReconPID); COMET::IReconPID::IReconPID() { fParticleId= kNotSet; fParticleWeight = 0; fState = new IPIDState; fNodes = new IReconNodeContainerImpl; } void COMET::IReconPID::CopyTReconPID(const COMET::IReconPID& pid){ fNodes = new IReconNodeContainerImpl; fParticleId = pid.GetParticleId(); fParticleWeight = pid.GetPIDWeight(); // Copy the nodes // Create new nodes with IPIDState's COMET::IReconNodeContainer::const_iterator in; for (in=pid.GetNodes().begin(); in!=pid.GetNodes().end();in++){ COMET::IHandle node(new COMET::IReconNode); COMET::IHandle object = (*in)->GetObject(); node->SetObject(object); COMET::IHandle tstate = (*in)->GetState(); if (tstate){ COMET::IHandle pstate(new COMET::IPIDState(*tstate)); node->SetState(pstate); } node->SetQuality((*in)->GetQuality()); fNodes->push_back(node); } if (pid.GetState()){ COMET::IHandle state = pid.GetState(); fState = new IPIDState(*state); } else { fState = new IPIDState; } } COMET::IReconPID::IReconPID(const COMET::IReconPID& pid, int i) : COMET::IReconBase(pid) { // integer input parameter is dummy. Just to use a diferent constructor // which does not copy the alternates CopyTReconPID(pid); } COMET::IReconPID::IReconPID(const COMET::IReconPID& pid) : COMET::IReconBase(pid) { CopyTReconPID(pid); // copy the alternates COMET::IReconObjectContainer::const_iterator it; for (it = pid.GetAlternates().begin(); it != pid.GetAlternates().end(); ++it) { COMET::IHandle alter = *it; AddAlternate(alter->GetParticleId(),alter->GetPIDWeight()); } } COMET::IReconPID::IReconPID(COMET::IHandle track) : COMET::IReconBase(*track){ fParticleId= kNotSet; fParticleWeight = 0; fNodes = new IReconNodeContainerImpl; // copy the state by converting it from ITrackState to IPIDState COMET::IHandle state = track->GetState(); if (state) { fState = new IPIDState(*state); } else { fState = new IPIDState; } // Copy the nodes // Create new nodes with IPIDState's IReconNodeContainer& nodes = GetNodes(); GetNodes().clear(); for (COMET::IReconNodeContainer::const_iterator in=track->GetNodes().begin(); in!=track->GetNodes().end(); ++in){ COMET::IHandle tstate = (*in)->GetState(); COMET::IHandle object = (*in)->GetObject(); if (!tstate) { COMETError("Track node without track state"); continue; } COMET::IHandle node(new COMET::IReconNode); COMET::IHandle pstate(new COMET::IPIDState(*tstate)); node->SetObject(object); node->SetState(pstate); node->SetQuality((*in)->GetQuality()); nodes.push_back(node); } // remove constituents, since the input object has been promoted // to a IReconPID. This will have a unique constituent: the input object IDatum* c = FindDatum("constituents"); if (c){ erase(c); delete c; } // add the track as constituent (notice that this is not really a // constituent but the promoted object) AddConstituent(track); } COMET::IReconPID::IReconPID(COMET::IHandle shower) : COMET::IReconBase(*shower) { fParticleId= kNotSet; fParticleWeight = 0; fNodes = new IReconNodeContainerImpl; // copy the state by converting it from IShowerState to IPIDState COMET::IHandle state = shower->GetState(); if (state) { fState = new IPIDState(*state); } else { fState = new IPIDState; } // Copy the nodes // Create new nodes with IPIDState's IReconNodeContainer& nodes = GetNodes(); GetNodes().clear(); if (shower->GetNodes().size()>0) { for (COMET::IReconNodeContainer::const_iterator in = shower->GetNodes().begin(); in!=shower->GetNodes().end(); in++) { COMET::IHandle tstate = (*in)->GetState(); COMET::IHandle object = (*in)->GetObject(); if (!tstate) { COMETError("Shower node without shower state"); continue; } COMET::IHandle node(new COMET::IReconNode); COMET::IHandle pstate(new COMET::IPIDState(*tstate)); node->SetObject(object); node->SetState(pstate); node->SetQuality((*in)->GetQuality()); nodes.push_back(node); } } else { COMET::IHandle tstate = shower->GetState(); COMET::IHandle object = shower; if (!tstate) { COMETError("Shower node without shower state"); } else { COMET::IHandle node(new COMET::IReconNode); COMET::IHandle pstate(new COMET::IPIDState(*tstate)); node->SetObject(object); node->SetState(pstate); node->SetQuality(shower->GetQuality()); nodes.push_back(node); } } // remove constituents, since the input object has been promoted // to a IReconPID. This will have a unique constituent: the input object IDatum* c = FindDatum("constituents"); if (c){ erase(c); delete c; } // add the shower as constituent (notice that this is not really a // constituent but the promoted object) AddConstituent(shower); } COMET::IReconPID::~IReconPID() {} TLorentzVector COMET::IReconPID::GetPosition() const { // This is the preferred way to access a state field. IHandle state = GetState(); if (!state) throw EMissingField(); return state->GetPosition(); } TLorentzVector COMET::IReconPID::GetPositionVariance() const { // This is the preferred way to access a state field. IHandle state = GetState(); if (!state) throw EMissingField(); return state->GetPositionVariance(); } bool COMET::IReconPID::IsXPID() const { TLorentzVector var = GetPositionVariance(); if (COMET::ICorrValues::IsFree(var.X())) return false; return true; } bool COMET::IReconPID::IsYPID() const { TLorentzVector var = GetPositionVariance(); if (COMET::ICorrValues::IsFree(var.Y())) return false; return true; } bool COMET::IReconPID::IsZPID() const { TLorentzVector var = GetPositionVariance(); if (COMET::ICorrValues::IsFree(var.Z())) return false; return true; } int COMET::IReconPID::GetDimensions() const{ TLorentzVector var = GetPositionVariance(); int dim = 0; if (IsXPID()) ++dim; if (IsYPID()) ++dim; if (IsZPID()) ++dim; return dim; } TVector3 COMET::IReconPID::GetDirection() const { // This is the preferred way to access a state field. IHandle state = GetState(); if (!state) throw EMissingField(); return state->GetDirection(); } double COMET::IReconPID::GetMomentum() const { // This is the preferred way to access a state field. IHandle state = GetState(); if (!state) throw EMissingField(); return state->GetMomentum(); } double COMET::IReconPID::GetCharge() const { // This is the preferred way to access a state field. IHandle state = GetState(); if (!state) throw EMissingField(); return state->GetCharge(); } void COMET::IReconPID::AddAlternate(ParticleId id, double weight) { // erase a previous alternate if it has the same id COMET::IReconObjectContainer::iterator it; for (it = fAlternatives.begin(); it != fAlternatives.end(); it++){ COMET::IHandle pid = *it; if ( pid->GetParticleId() == id){ fAlternatives.erase(it); break; } } // create a new IReconPID copying the main IReconPID. Don't copy the // alternates. is there any other solution ? COMET::IHandle alter(new COMET::IReconPID(*this,1)); // set the new information alter->SetParticleId(id); alter->SetPIDWeight(weight); AddAlternate(alter); } std::string COMET::IReconPID::ConvertParticleId() const { return ConvertParticleId(fParticleId); } std::string COMET::IReconPID::ConvertParticleId(COMET::IReconPID::ParticleId id){ std::string s(""); if (id == kNotSet) s= "Not Set"; if (id == kOther) s= "Other"; if (id == kShower) s= "Shower"; if (id == kEM) s= "EM"; if (id == kElectron) s= "Electron"; if (id == kGamma) s= "Gamma"; if (id == kHadronic) s= "Hadronic"; if (id == kPiZero) s= "Pi0"; if (id == kLightTrack) s= "Light track"; if (id == kMuon) s= "Muon"; if (id == kPion) s= "Pion"; if (id == kHeavyTrack) s= "Heavy track"; if (id == kProton) s= "Proton"; if (id == kKaon) s= "Kaon"; return s; } void COMET::IReconPID::ls(Option_t *opt) const { COMET::IReconBase::ls_base(opt); TROOT::IncreaseDirLevel(); TROOT::IndentLevel(); std::cout << "Particle Id: " << ConvertParticleId() << " Weight: " << GetPIDWeight() << std::endl; if (fState) { TROOT::IncreaseDirLevel(); fState->ls(opt); TROOT::DecreaseDirLevel(); } TROOT::IncreaseDirLevel(); fAlternatives.ls(opt); TROOT::DecreaseDirLevel(); if (fNodes) { TROOT::IncreaseDirLevel(); fNodes->ls(opt); TROOT::DecreaseDirLevel(); } TROOT::IncreaseDirLevel(); for (const_iterator v = begin(); v != end(); ++v) { (*v)->ls(opt); }; TROOT::DecreaseDirLevel(); TROOT::DecreaseDirLevel(); }