#ifndef _PHYSICS_TOWER_DATA_HH_ #define _PHYSICS_TOWER_DATA_HH_ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Component: PhysicsTowerData.hh // Purpose: This is the container class for physics towers i.e. calorimeter towers whose Et // are calculated using a specific vertex. // // Note: Using primitive "find" functions for now. They will use "default" parameters // // Created: 16/06/99 Pierre Savard // // History: 13/09/99 Pierre Savard // Changed class name and EDMize // 08/04/02 Bob Wagner (Argonne) // Have ConstIterator inherit from std::iterator to // make gcc compiler happy. It demands that STL algorithms // using ConstIterator obey STL iterator structure and // have things like pointer, reference, value_type, etc. // defined in a typedef. The std::iterator base class // supplies the necessary typedefs. // 01/05/03 Dan MacQueen - made all three components of the vertex available. // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include "Experiment/Experiment.hh" #include "Edm/StorableObject.hh" #include "Edm/ConstHandle.hh" #include "Edm/Handle.hh" #include "Edm/Id.hh" #include "AbsEnv/AbsEnv.hh" #include "CalorGeometry/CalConstants.hh" #include "CalorGeometry/Locations.hh" #include "CalorGeometry/TowerKey.hh" #include "CalorObjects/PhysicsTowerParams.hh" //ROOT headers #include "TBuffer.h" // Needed a few kludges to make cint happy #ifndef __CINT__ #include "CLHEP/Vector/LorentzVector.h" #include "CalorObjects/PhysicsTower.hh" #else class HepLorentzVector; class PhysicsTower; #endif // namespace calor { class PhysicsTowerData; typedef Handle PhysicsTowerData_h; typedef ConstHandle PhysicsTowerData_ch; class PhysicsTowerData : public StorableObject{ public: enum Error{ERROR,OK}; typedef PhysicsTower* TowerData[TOWER_NETA][TOWER_MAX_NPHI]; // // Memory management // PhysicsTowerData(); PhysicsTowerData(PhysicsTowerParams& params); // Copy constructor PhysicsTowerData(const PhysicsTowerData& rhs): StorableObject(), _towerParams(rhs._towerParams){ size_t iEta; size_t iPhi; for (iEta = 0; iEta < TOWER_NETA; ++iEta){ for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi){ if(rhs._data[iEta][iPhi] == 0){ _data[iEta][iPhi] = 0; } else{ _data[iEta][iPhi] = rhs._data[iEta][iPhi]->clone(); } } } } // The swap method is used to make sure we (eventually) have safe exception handling void swap(PhysicsTowerData& copy) { _towerParams = copy._towerParams; UChar_t iEta; UChar_t iPhi; for (iEta = 0; iEta < TOWER_NETA; ++iEta) for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi) std::swap(_data[iEta][iPhi], copy._data[iEta][iPhi]); } // Assignment operator (uses swap above); PhysicsTowerData& operator=(const PhysicsTowerData& rhs) { PhysicsTowerData temp(rhs); swap(temp); return (*this); } // Destructor protected: ~PhysicsTowerData(); public: virtual void destroy(void) ; virtual void deallocate(void) ; virtual std::string class_name(void) const ; virtual Version_t class_version(void) const ; virtual void print(std::ostream& os) const ; virtual bool postread(EventRecord* p_record); virtual bool prewrite(EventRecord* p_record); virtual bool deactivate(EventRecord* p_record); virtual bool activate(EventRecord* p_record); // These methods will fetch a PhysicsTowerData object from the event // the version below will grab the first PhysicsTowerData object in the // event. It will use AbsEnv::theEvent() to get the event pointer. static Error find(PhysicsTowerData_ch&); static Error find(PhysicsTowerData_ch& ,const std::string& description); static Error find(PhysicsTowerData_ch& ,const std::string& description, AbsEvent* anEvent); static Error find(PhysicsTowerData_ch& ,PhysicsTowerParams* , const std::string& description); static Error find(PhysicsTowerData_ch& ,PhysicsTowerParams* , const std::string& description,AbsEvent* anEvent ); // // Manipulation and access // int size() const; // returns number of towers with energy const PhysicsTowerParams& parameters() const; std::string sourceName() const; std::string calcName() const; float threshold() const; // the reason we have this here and not // in a view is to speed up the creation // of the collection. float vertex() const; float threeVertex(int i) const; Id sourceID() const; // Add a tower bool add(PhysicsTower* pTower); // delete a tower bool destroyTower(PhysicsTower* pTower); // Give read access to a specific tower const PhysicsTower* tower(size_t iEta, size_t iPhi) const; const PhysicsTower* tower(int iEta, int iPhi) const; const PhysicsTower* tower(TowerKey tKey) const; // Give read/write access to a specific tower PhysicsTower* tower(size_t iEta, size_t iPhi); PhysicsTower* tower(int iEta, int iPhi); PhysicsTower* tower(TowerKey tKey); // Give read and write access to a specific tower // This method will create the tower if it does not // exist. It is used in PhysicsTowerDataMaker. PhysicsTower* towerMake(TowerKey& tKey); //friend std::ostream& operator<<(std::ostream& os, const PhysicsTowerData& c); private: TowerData _data; PhysicsTowerParams _towerParams; #ifndef __CINT__ public: // // Iterators // // These iterators will return the next non-null pointer to a PhysicsTower // The begin() and end() methods of PhysicsTowerData will find the first and // last non-null pointer // The constant iterator class ConstIterator : public std::iterator { public: ConstIterator(); ConstIterator(const TowerData& td,size_t iEta, size_t iPhi); ConstIterator(const ConstIterator& rhs); size_t iEta(); size_t iPhi(); PhysicsTower* tower() const; ConstIterator& operator++(); ConstIterator& operator--(); PhysicsTower* operator->() const; PhysicsTower& operator*() const; bool operator==(const ConstIterator& it) const; bool operator!=(const ConstIterator& it) const; ConstIterator& operator=(const ConstIterator& iter); private: size_t _iEta; size_t _iPhi; const TowerData* _dataptr; }; ConstIterator begin() const; ConstIterator end() const; typedef ConstIterator const_iterator; // The non-const Iterator class Iterator { public: Iterator(); Iterator(TowerData& td,size_t iEta, size_t iPhi); Iterator(const Iterator& rhs); size_t iEta(); size_t iPhi(); PhysicsTower* tower(); Iterator& operator++(); Iterator& operator--(); PhysicsTower* operator->(); PhysicsTower& operator*(); bool operator==(const Iterator& it) const; bool operator!=(const Iterator& it) const; Iterator& operator=(const Iterator& iter); private: size_t _iEta; size_t _iPhi; TowerData* _dataptr; }; Iterator begin(); Iterator end(); typedef Iterator iterator; #endif // CINT // EDM stuff ClassDef(PhysicsTowerData, 2) }; // inline implementation inline std::string PhysicsTowerData::sourceName() const {return _towerParams.inputName();} inline std::string PhysicsTowerData::calcName() const {return _towerParams.calculatorName();} inline float PhysicsTowerData::threshold() const {return _towerParams.calcThreshold();} inline float PhysicsTowerData::vertex() const {return _towerParams.vertex(2);} // This returns the Z-vertex. Below, all three vertex components can be found. inline float PhysicsTowerData::threeVertex(int i) const {return _towerParams.vertex(i);} inline Id PhysicsTowerData::sourceID() const {return _towerParams.inputID();} inline const PhysicsTowerParams& PhysicsTowerData::parameters() const {return _towerParams;} #ifndef __CINT__ inline PhysicsTowerData::ConstIterator::ConstIterator( const ConstIterator& rhs ){ _iEta = rhs._iEta; _iPhi = rhs._iPhi; _dataptr = rhs._dataptr; } inline PhysicsTowerData::ConstIterator PhysicsTowerData::begin() const{ ConstIterator iter(_data,0,0); while(iter.tower() == 0 && !(iter.iEta()==51 && iter.iPhi() ==47)) ++iter; return iter;} inline PhysicsTowerData::ConstIterator PhysicsTowerData::end() const{ ConstIterator iter(_data,TOWER_NETA-1,TOWER_MAX_NPHI-1); // while(iter.tower() == 0 && !(iter.iEta()==0 && iter.iPhi() ==0)) --iter; return iter;} inline size_t PhysicsTowerData::ConstIterator::iEta() { return _iEta; } inline size_t PhysicsTowerData::ConstIterator::iPhi() { return _iPhi; } inline PhysicsTower* PhysicsTowerData::ConstIterator::tower() const { return (*_dataptr)[_iEta][_iPhi];} inline PhysicsTowerData::Iterator::Iterator( const Iterator& rhs ){ _iEta = rhs._iEta; _iPhi = rhs._iPhi; _dataptr = rhs._dataptr; } inline PhysicsTowerData::Iterator PhysicsTowerData::begin(){ Iterator iter(_data,0,0); while(iter.tower() == 0 && !(iter.iEta()==51 && iter.iPhi() ==47)) ++iter; return iter;} inline PhysicsTowerData::Iterator PhysicsTowerData::end(){ Iterator iter(_data,TOWER_NETA-1,TOWER_MAX_NPHI-1); // while(iter.tower() == 0 && !(iter.iEta()==0 && iter.iPhi() ==0)) --iter; return iter;} inline size_t PhysicsTowerData::Iterator::iEta() { return _iEta; } inline size_t PhysicsTowerData::Iterator::iPhi() { return _iPhi; } inline PhysicsTower* PhysicsTowerData::Iterator::tower() { return (*_dataptr)[_iEta][_iPhi]; } inline const PhysicsTower * PhysicsTowerData::tower(size_t iEta, size_t iPhi) const{ return _data[iEta][iPhi];} inline const PhysicsTower * PhysicsTowerData::tower(int iEta, int iPhi) const{ return _data[iEta][iPhi];} inline const PhysicsTower * PhysicsTowerData::tower(TowerKey tKey) const{ int iEta = tKey.iEta(); int iPhi = tKey.iPhi(); return _data[iEta][iPhi]; } #endif // CINT // } // namespace calor #endif // _PHYSICS_TOWER_DATA_HH_