// $Id: MacroCell.hh,v 1.27 2005/05/27 00:23:20 thea Exp $ // Author: M. Pallavicini - 7-10-03 created /***************************************************************************** * ESAF: Euso Simulation and Analysis Framework * * * * Id: MacroCell * * Package: Electronics * * Coordinator: Marco.Pallavicini * * * *****************************************************************************/ #ifndef __MACROCELL_H__ #define __MACROCELL_H__ #include #include #include "Photon.hh" #include "EsafConfigurable.hh" #include "ElementaryCell.hh" #include "TriggerEngine.hh" #include "EsafMsgSource.hh" class FrontEndChip; class Photomultiplier; class MacroCellData; class MacroCellGeometry; //////////////////////////////////////////////////////////////////////////////// // // // MacroCell // // // //////////////////////////////////////////////////////////////////////////////// class MacroCell : public EsafConfigurable, public EsafMsgSource { public: MacroCell(Int_t,Int_t); // ctor virtual ~MacroCell(); // dtor EsafConfigClass(Electronics,MacroCell) static void ResetClass() {gCellCounter=1;} // reset static counter Bool_t Add(ElementaryCell*, Int_t, Int_t); // add an elementary cell to the macrocell inline Int_t GetRows() const {return fRows;} inline Int_t GetColumns() const {return fCols;} inline size_t Chips() const {return fECs.size();} // number of front end chips inline size_t GetNumECs() const {return fECs.size();} // number of front end chips inline Int_t Id() const {return fCellId;} // MacroCell ID FrontEndChip* FrontEnd(Int_t,Int_t); // get front end inline const vector* Pmts() const {return &fPmts;} inline Photomultiplier* GetPmt(Int_t i) {return fPmts[i];} // pmts inline const vector* ECs() const { return &fECs;} inline ElementaryCell* GetEC(Int_t i) { return fECs[i];} inline ElementaryCell* GetEC(Int_t r,Int_t c) { return GetEC( RowColId(r,c) );} // elementary cells // Check if all PMTs are ready Bool_t CheckPmtState() const; // Set the first Gtu time offset. Each PMT hit time must be related inline void SetGtuBegin( Double_t s ) {fGtuOffset = s;} inline Double_t GetGtuBegin() const {return fGtuOffset;} // to this time which is the beginning of the first relevant GTU inline Double_t GetGtuLength() const { return fGtuLength;} // gtu length virtual MacroCellData* Simulate(Int_t night_glow_code=0) = 0; // simulate the full MacroCell // return the time of the first hit and last hit of this event // associated to this macrocell Double_t FirstHitTime(); // time of the first hit Double_t LastHitTime(); // time of last hit Bool_t IsEmpty() const; // returns true if there are no hits of if there is low signal void Reset(); // reset macrocell data and get ready for next event inline Int_t TriggerThreshold() const { return fTriggerThreshold;} // trigger parameters // number of consequtive GTU needed to trigger inline ETriggerTypeIdentifier TriggerType() const { return fTriggerType;} // trigger type ( 0 = None, 1=persistency only 2=persist. & contiguity) inline MacroCellGeometry *Geometry() { return pGeometry; } // return pointer to MacroCell geometry object inline void SetGeometry(MacroCellGeometry *g) { pGeometry=g; } inline Int_t GetUniqueIdRowCol(Int_t r, Int_t c) { pair p(r,c); if (fUidRowCol.count(p)==1) // returns the unique id of a given row and col return fUidRowCol[p]; else return 0;} inline pair& GetRowColUniqueId(Int_t uid) { if (fRowColUid.count(uid)==1) // returns the unique id of a given row and col return fRowColUid[uid]; else throw runtime_error("GetRowColUniqueId: Invalid uid"); } static map &GetEngines() {return *fEngines;} // trigger engines inline void SetLowSignalThreshold(Int_t th) { fLowSignalThreshold = th; } // set low signal threshold private: Int_t fCellId; // macrocell info static Int_t gCellCounter; Int_t fNumECs; // number of Elementary Cells vector fPmts; // pmts vector< ElementaryCell* > fECs; // list of elementary cells attached to this MacroCell map fECRowColMap; // map from rows and columns to elementary cell // the row-col pair is coded into an integer through the RowColId function map< pair, Int_t> fUidRowCol; // map from Macrocell internal row-col coordinates to unique id map< Int_t, pair > fRowColUid; // same map the other way around static map *fEngines; // trigger engines; static because right now all macrocell have the same trigger // easy to change to macrocell dependent trigger protected: void SetECRowCol(ElementaryCell* ec, Int_t r, Int_t c); // set elementary cell Bool_t IsValid(Int_t,Int_t) const; // true if row column is valid Bool_t IsLogicEnabled() const; private: Int_t fRows, fCols; // number of rows and columns inline Int_t RowColId(Int_t r,Int_t c) const {return ((r-1)*GetColumns() + c -1 );} // this identifier goes from 0 to Rows()*GetColumns()-1 Double_t fGtuOffset; // time in ns corresponding to first edge of first GTU Double_t fGtuLength; // gtu length in ns Bool_t fLogicEnabled; // if true the simulation of the macrocell logic is performed Int_t fTriggerThreshold; // trigger threshold, i.e. number of consequtive GTU with macrocell // activity needed to generate a valid trigger ETriggerTypeIdentifier fTriggerType; // trigger type MacroCellGeometry *pGeometry; // geometry Int_t fLowSignalThreshold; // minimum number of signal regured to ClassDef(MacroCell,0) }; inline Bool_t MacroCell::IsValid(Int_t r, Int_t c) const { // // Check if a pair of rows and columns are valid // return ( (r>0) && (r<=GetRows()) && (c>0) && (c<=GetColumns()) ); } inline Bool_t MacroCell::IsLogicEnabled() const {return fLogicEnabled;} inline void MacroCell::SetECRowCol(ElementaryCell* ec, Int_t r, Int_t c) { fECRowColMap[RowColId(r,c)] = ec; } #endif /* __MACROCELL_H__*/