/* * PndOnlineManager.h * * Created on: Nov. 14, 2012 * Author: Sean Dobbs (s-dobbs@northwestern.edu) * * Central class for online reconstruction/simulation */ #ifndef PNDONLINEMANAGER_H_ #define PNDONLINEMANAGER_H_ #include #include #include "FairRuntimeDb.h" #include "FairTSBufferFunctional.h" #include "PndOnline.h" #include "PndOnlineTrackHit.h" #include "PndOnlineTrack.h" #include "PndOnlineEvent.h" //#include "PndOnlineHitProducer.h" #include "PndOnlineGeometryManager.h" #include "FairTask.h" //#include "PndDetectorList.h" #include //#include /** detector list: enum DetectorId { kDCH,kDRC,kDSK,kEMC,kGEM,kLUMI,kMDT,kMVD,kRPC,kSTT,kTPC,kTOF,kFTS,kHYPG,kHYP}; **/ using namespace std; class PndOnlineManager { public: PndOnlineManager(PndOnlineGeometryManager *new_geometry=NULL) : geometryManager(new_geometry),outputTask(NULL),current_time(0),is_end_of_revolution(false),kHESRRevolution(PndOnline::kHESRRevolution),simulate_hesr_beam_structure(false) { master = new FairTask("OnlineTaskList"); stop_time_functor = new StopTime(); revolution_start_time = current_time; } ~PndOnlineManager() { delete master; delete stop_time_functor; } // Event loop void Init() { if(master) master->InitTask(); if(outputTask) outputTask->InitTask(); } void Clear(); void Reset() { Clear(); } void Process(); void LoadHits(double delta_t); void RemoveOldHits(double timeout_time); void ClearHits() { hits.clear(); for( map< int, list< PndOnlineTrackHit * > >::iterator it=detector_hits.begin(); it!=detector_hits.end(); it++) it->second.clear(); for( map< int, vector< list< PndOnlineTrackHit * > > >::iterator it2=hit_channel_map.begin(); it2!=hit_channel_map.end(); it2++) for( vector< list< PndOnlineTrackHit * > >::iterator it3=it2->second.begin(); it3!=it2->second.end(); it3++) it3->clear(); } void ClearTracks() { tracks.clear(); } void ClearEvents() { events.clear(); } void AddTask(FairTask *newTask) { master->Add(newTask); } //void AddHitProducer(PndOnlineHitProducer *newHitProducer) { hitProducer = newHitProducer; } void AddGeometryManager(PndOnlineGeometryManager *newGeometry) { geometryManager=newGeometry; } void AddOutputTask(FairTask *newOutputTask) { outputTask=newOutputTask; } // accessors list &GetHitList() { return hits; } list &GetDetectorHitList(int detector_id) { return detector_hits[detector_id]; } vector< list > &GetHitChannelMap(int detector_id) { return hit_channel_map[detector_id]; } list &GetTrackList() { return tracks; } list &GetEventList() { return events; } void GetHitTimedList( double start_time, double delta_t, list &hit_list ) { for(list::const_iterator it=hits.begin(); it!=hits.end(); it++) { if( ((*it)->BaseHit()->GetTimeStamp() > start_time) && ((*it)->BaseHit()->GetTimeStamp() < start_time+delta_t) ) hit_list.push_back( *it ); } } void GetTrackTimedList( double start_time, double delta_t, list &track_list ) { for(list::const_iterator it=tracks.begin(); it!=tracks.end(); it++) { if( ((*it)->T0() > start_time) && ((*it)->T0() < start_time+delta_t) ) track_list.push_back( *it ); } } void GetEventTimedList( double start_time, double delta_t, list &event_list ) { for(list::const_iterator it=events.begin(); it!=events.end(); it++) { if( ((*it)->T0() > start_time) && ((*it)->T0() < start_time+delta_t) ) event_list.push_back( *it ); } } // accessors for ROOT scripts TObjArray *GetFairHitObjectList() { TObjArray *objarr = new TObjArray(); for(list::iterator it=hits.begin();it!=hits.end(); it++) { objarr->AddLast( (*it)->BaseHit() ); } return objarr; } TObjArray *GetFairHitObjectList(int detector_id) { TObjArray *objarr = new TObjArray(); for(list::iterator it=detector_hits[detector_id].begin(); it!=detector_hits[detector_id].end(); it++) { objarr->AddLast( (*it)->BaseHit() ); } return objarr; } TObjArray *GetFairHitObjectTimedList(int detector_id, double start_time, double delta_t) { TObjArray *objarr = new TObjArray(); for(list::iterator it=detector_hits[detector_id].begin(); it!=detector_hits[detector_id].end(); it++) { if( ((*it)->BaseHit()->GetTimeStamp() > start_time) && ((*it)->BaseHit()->GetTimeStamp() < start_time+delta_t) ) { objarr->AddLast( (*it)->BaseHit() ); } } return objarr; } TObjArray *GetTrackHitObjectList() { TObjArray *objarr = new TObjArray(); for(list::iterator it=hits.begin();it!=hits.end(); it++) { objarr->AddLast( *it ); } return objarr; } TObjArray *GetTrackHitObjectList(int detector_id) { TObjArray *objarr = new TObjArray(); for(list::iterator it=detector_hits[detector_id].begin(); it!=detector_hits[detector_id].end(); it++) { objarr->AddLast( *it ); } return objarr; } TObjArray *GetTrackObjectList() { TObjArray *objarr = new TObjArray(); for(list::iterator it=tracks.begin();it!=tracks.end(); it++) { objarr->AddLast( *it ); } return objarr; } TObjArray *GetTrackObjectTimedList(double start_time, double delta_t) { TObjArray *objarr = new TObjArray(); for(list::iterator it=tracks.begin();it!=tracks.end(); it++) { if( ((*it)->T0() > start_time) && ((*it)->T0() < start_time+delta_t) ) objarr->AddLast( *it ); } return objarr; } TObjArray *GetEventObjectList() { TObjArray *objarr = new TObjArray(); for(list::iterator it=events.begin();it!=events.end(); it++) { objarr->AddLast( *it ); } return objarr; } // access regions-of-interest? bool IsDetectorActive(int detector_id) { return ( find(active_detectors.begin(),active_detectors.end(),detector_id) != active_detectors.end() ); } // setters void AddHit( int the_detector, PndOnlineTrackHit *new_hit ) { hits.push_back(new_hit); detector_hits[the_detector].push_back(new_hit); } void AddTrack( PndOnlineTrack *new_track ) { tracks.push_back(new_track); } void AddEvent( PndOnlineEvent *new_event ) { events.push_back(new_event); } void SetActiveDetector( int detector_id, int timeout_length ) { active_detectors.push_back(detector_id); detector_timeouts[detector_id] = timeout_length; geometryManager->LoadGeometry(detector_id); // don't check for return values... yet // only enable other mappings for STT so far switch(detector_id) { case PndOnline::kSTT: hit_channel_map[detector_id].resize( geometryManager->GetDetectorGeometry(PndOnline::kSTT)->GetEntriesFast() ); break; } } TClonesArray *GetGeometry(int the_detector) { return geometryManager->GetDetectorGeometry(the_detector); } // input functions void LoadStream(int detector_id, char *branch_name, int timeout_length); double GetCurrentTime() { return current_time; } void AdvanceCurrentTime(double delta_t) { current_time += delta_t; } bool SetStartTime(double new_time); /// HACK! //void SetHESRRevolutionDuration(double time) { PndOnline::kHESRRevolution = time; } void SetHESRRevolutionDuration(double time) { kHESRRevolution = time; } void SetHESRBeamStructure(bool do_sim) { simulate_hesr_beam_structure = do_sim; } // ADD IN TIME STATISTICS KEEPING private: FairTask *master; // root task for execuation //PndOnlineHitProducer *hitProducer; PndOnlineGeometryManager *geometryManager; FairTask *outputTask; // list of current objects list hits; list tracks; list events; // other representations map< int, list< PndOnlineTrackHit * > > detector_hits; map< int, vector< list< PndOnlineTrackHit * > > > hit_channel_map; vector active_detectors; // list of detectors we are reading in data for map detector_timeouts; // time (in ns) that we should let hits hang around before removing them // data from HitProducer map< int, TString > input_branches; BinaryFunctor* stop_time_functor; //! //BinaryFunctor* time_gap_functor; //! // internal interface for modifying time // (we may change how time is kept) // does not properly set location in the hit buffer void SetCurrentTime(double new_time) { current_time = new_time; } double current_time; bool simulate_hesr_beam_structure; // whether we should bother about this stuff double revolution_start_time; // what is the starting time of the current HESR revolution? bool is_end_of_revolution; // did we hit the end of a revolution and need to restart algorithms? double kHESRRevolution; }; #endif