#ifndef TReconBase_hxx_seen #define TReconBase_hxx_seen #include #include "EoaCore.hxx" #include "ICOMETLog.hxx" #include "IHandle.hxx" #include "IDatum.hxx" #include "IDataVector.hxx" #include "IHitSelection.hxx" #include "IReconState.hxx" namespace COMET { class IReconBase; class IReconObjectContainer; class IReconNodeContainer; /// An exception associated with a reconstruction object. OA_EXCEPTION(EReconObject, EoaCore); /// An exception thrown when a requested field is not supported by the /// current object state. OA_EXCEPTION(EMissingField, EReconObject); } /// Define a base class for all of the reconstruction objects. This contains /// the shared methods required to implement the basic reconstruction object /// functionality. Each IReconBase object has it's TObject::fUniqueID value /// set. These values can be used to associate global reconstruction objects /// to sub-detector reconstruction objects. class COMET::IReconBase : public IDataVector { public: /// The bits defining the state of the reconstruction that created this /// object. The state bits come in two flavors: Status bits are used to /// summarize the completion status of the algorithm. Detector bits are /// used to record which detectors provided information to the algorithm. /// The status bits are accessed using SetStatus() and GetStatus(). The /// detector bits are accessed using AddDetector() and UsesDetector(). /// The full status field can be accessed using the GetStatus() method. typedef enum { /// The algorithm ran to completion. This bit is set using /// SetStatus() and checked using CheckStatus() kRan = BIT(0), /// The algorithm succeeded and the result is reliable. This bit is /// set using SetStatus and checked using CheckStatus(). kSuccess = BIT(1), /// A chi2 fitting method was used and the quality corresponds to a /// chi2. This bit is set using SetStatus and checked using /// CheckStatus(). kChi2Fit = BIT(2), /// A maximum likelihood fitting methods was used. This bit is set /// using SetStatus and checked using CheckStatus(). kLikelihoodFit = BIT(3), /// A kalman fitting algorithm was used. This bit is set using /// SetStatus and checked using CheckStatus(). kKalmanFit = BIT(4), // this bit is reserved for future possibility to use the RecPack track fitting /// A genfit fitting algorithm was used. This bit is set using /// SetStatus and checked using CheckStatus(). kGenFit = BIT(5), /// A neuralnet track finding algorithm was used. This bit is set using /// SetStatus and checked using CheckStatus(). kNeuralNet = BIT(6), /// A Hough track finding algorithm was used. This bit is set using /// SetStatus and checked using CheckStatus(). kHough = BIT(7), /// A mask of all of the status bits. kStatusMask = kRan|kSuccess|kChi2Fit|kLikelihoodFit|kKalmanFit|kGenFit|kNeuralNet|kHough, ///////////////////////////////////////////////////////////////// // The remaining bits define which detectors contribute information // to the reconstruction object. ///////////////////////////////////////////////////////////////// /// The result uses data from the CDC. This bit is set /// using AddDetector() and checked using UsesDetector(). kCDC = BIT(16), /// The result uses data from the CTH. This bit is set /// using AddDetector() and checked using UsesDetector(). kCTH = BIT(17), /// The result uses data from the StrawTrk. This bit is set /// using AddDetector() and checked using UsesDetector(). kStrawTrk = BIT(18), /// The result uses data from the ECAL. This bit is set /// using AddDetector() and checked using UsesDetector(). kECAL = BIT(19), /// The result uses data from the CRV. This bit is set /// using AddDetector() and checked using UsesDetector(). kCosmicVeto = BIT(20), /// A mask for all of the detector bits. kDetectorMask = kCDC|kCTH|kStrawTrk|kECAL|kCosmicVeto } StateBits; /// A status value with one or more bits sets typedef unsigned long Status; public: virtual ~IReconBase(); /// Get the name of the algorithm that created this reconstruction object. std::string GetAlgorithmName() const {return fAlgorithm;} /// Set the name of the algorithm. void SetAlgorithmName(const char* name) {fAlgorithm = name;} /// Check the status of the reconstruction that created this /// reconstruction result. This method checks if any of the bit bool CheckStatus(COMET::IReconBase::Status status) const; /// Set the status of the algorithm that generated this object. void SetStatus(COMET::IReconBase::Status status); /// Clear the status of the algorithm that generated this object. void ClearStatus(COMET::IReconBase::Status status); /// Get the status field for this object. COMET::IReconBase::Status GetStatus() const; /// Get the detector bits that are set for this object. COMET::IReconBase::Status GetDetectors() const; /// Return true if the object uses a particular detector bool UsesDetector(COMET::IReconBase::Status detector) const; /// Add one or more detector to the object. void AddDetector(COMET::IReconBase::Status detector); /// Remove a detector from the object. void RemoveDetector(COMET::IReconBase::Status detector); /// Return the goodness of fit for the reconstruction. double GetQuality() const {return fQuality;} /// Set the goodness of the fit from the reconstruction. void SetQuality(double quality) {fQuality = quality;} /// Get the number of degrees of freedom in the reconstruction. int GetNDOF() const {return fNDOF;} /// Set the number of degrees of freedom. void SetNDOF(int n) {fNDOF = n;} /// Get the state associated with this reconstruction object. The state /// is created by the derived class. This should generally be used in /// user code with a specific COMET::IHandle type. For instance, if you want /// to access a COMET::IReconCluster state, you should write code like: /// /// \code /// COMET::IHandle state = recObj->GetState(); /// if (state) { /// // the state /// } /// \endcode /// /// Which hides the dynamic cast and makes sure that the local variable /// has the right type. /// /// The state holds (most of) the reconstruction object parameter values. /// And is used to get and set the values and covariances. As an example, /// to set the direction of the IReconTrack object: /// \code /// COMET::IHandle trackState = reconTrack->GetState(); /// TVector3 theDir(0,0,1); /// trackState->SetDirection(theDir); // This works /// trackState->SetDirection(0,0,1); // This also works. /// // Assume dirCov is a TMatrixD holding the covariance. /// for (int i=0; i< IMDirectionState::GetSize(); ++i) { /// for (int j=0; j< IMDirectionState::GetSize(); ++j) { /// trackState->SetCovariance(i+trackState->GetDirectionIndex(), /// j+trackState->GetDirectionIndex(), /// dirCov(i,j)); /// } /// } /// \endcode COMET::IHandle GetState() const { if (!fState) { COMETError("IReconBase with NULL State: " << "State must be created in the derived class."); throw EReconObject(); } return COMET::IHandle(fState,false); } /// Get the parameter values at each stage of the reconstruction. /// - For the track and particle objects (see the \ref reconTrack and \ref /// reconParticle sections), the parameter values will be the associated /// with each intermediate position. /// - For an incremental fit, the parameter values are associated with each /// stage of the fit. /// - For other objects, the parameter values will be associated with the /// reconstruction objects that have been added to the fit. const COMET::IReconNodeContainer& GetNodes() const { if (!fNodes) { COMETError("IReconBase without a IReconNodeContainer:" << "Must be created in derived class constructor"); throw EReconObject(); } return *fNodes; } /// Provide a non-constant version of the node container so that nodes can /// be added. COMET::IReconNodeContainer& GetNodes() { if (!fNodes) { COMETError("IReconBase without a IReconNodeContainer:" << "Must be created in derived class constructor"); throw EReconObject(); } return *fNodes; } /// Provide the hits associated with this recon object. The hits are /// saved as an entry in the data vector (with name "hits"), and may not /// be present for all objects. COMET::IHandle GetHits() const; /// Add a hit selection to the recon object. The recon object takes /// ownership of the hit (as per the COMET pointer ownership policy), so /// you must not add a hit selection currently owned by another object. /// The name of the hit selection will be changed to "hits". void AddHits(COMET::IHitSelection* hits); /// Provide the reconstruction objects used in the algorithm that created /// this object. The consituients are used to help understand how the /// object was fit, and are different from the nodes which represent /// actual intermediate steps of the fitting process. COMET::IHandle GetConstituents() const; /// Add a new constituent to the TReconObject. This stores the /// constituents in the order in which they are added. The constituents /// are saved in a IReconObjectContainer, and are available using the /// GetConstituents method, or using the normal IDatum::Get<> method. /// This will create a constituents sub-object if one doesn't exist. void AddConstituent(COMET::IHandle obj); /// Add several constituents in one go by adding all objects in a /// IReconObjectContainer void AddConstituents(COMET::IHandle objs); /// @{Override methods in the base TObject class. virtual void ls(Option_t* opt = "") const; virtual void Browse(TBrowser* b); /// @} /// Turn the object status into a string. std::string ConvertStatus() const; /// Turn the contributing detectors into a string. std::string ConvertDetector() const; /// Return true if this is a composite object. The definition of a /// composite object means that different parts of the object might be /// considered as the "root". This allows the implementation of /// "junctions" and other more complex concepts. bool IsComposite() const; /// Mark this as a composite object. void SetComposite(bool comp = true); protected: /// Default constructor. IReconBase(); /// Construct a named reconstruction object. This constructs a new empty /// IReconBase object and is defined as explicit so that it will not /// function as a type conversion between a const char* and the IReconBase /// class. This can only be used in one of the derived classes. explicit IReconBase(const char* name, const char* title = "Reconstruction Object"); /// Copy the object (this is not a deep copy). IReconBase(const COMET::IReconBase& object); /// Implement the listing of the base class fields. This is used by ls() void ls_base(Option_t* opt) const; /// The quality of reconstruction; float fQuality; /// The state for this object. COMET::IReconState* fState; /// The nodes for the object. COMET::IReconNodeContainer* fNodes; /// The status of the reconstruction COMET::IReconBase::Status fStatus; /// The number of degrees of freedom. int fNDOF; /// The name of the reconstruction algorithm. std::string fAlgorithm; /// Define the flag bits used by the IReconBase object. These can't /// collide with any state bits defined in IObject, IDatum, or IDataVector /// (the parent classes), and none of the children can define a state bit /// that collides with these definitions. Bits 14 to 23 are available for /// use. enum EReconBaseBits { kCompositeObject = BIT(18) // The object is composite. }; ClassDef(IReconBase,3); }; /// A container class for reconstruction objects inheriting from a std::vector /// of IHandle. class COMET::IReconObjectContainer : public IDatum, public std::vector< COMET::IHandle > { public: IReconObjectContainer(); IReconObjectContainer(const char* name, const char* title = "Recon Object Container"); virtual ~IReconObjectContainer(); virtual void push_back(COMET::IHandle data); /// @{Override methods in the base TObject class. virtual void ls(Option_t* opt = "") const; virtual Bool_t IsFolder(void) const {return kTRUE;}; virtual void Browse(TBrowser* b); /// @} private: ClassDef(IReconObjectContainer,1); }; #endif