6 #include <phfield/PHFieldConfig_v3.h>
7 #include <phfield/PHFieldUtility.h>
8 #include <phgeom/PHGeomUtility.h>
26 #include <phgeom/PHGeomTGeo.h>
40 #include <boost/lexical_cast.hpp>
43 # define LogDebug(exp) std::cout << "DEBUG: " << __FUNCTION__ <<": "<< __LINE__ << ": " << exp << std::endl
45 # define LogDebug(exp)
50 _input_type(
SQReco::E1039),
51 _fitter_type(
SQReco::KFREF),
53 _eval_file_name(
"eval.root"),
56 _enable_eval_dst(false),
57 _tracklet_vector(nullptr),
60 _eventReducer(nullptr),
69 _event_header(nullptr),
71 _triggerhit_vector(nullptr),
72 _legacy_rec_container(true),
75 _recTrackVec(nullptr),
77 _t_geo_manager(nullptr)
80 _eval_listIDs.clear();
99 int ret = MakeNodes(topNode);
102 ret = GetNodes(topNode);
105 ret = InitField(topNode);
108 ret = InitGeom(topNode);
115 if(_evt_reducer_opt ==
"none")
117 _eventReducer =
nullptr;
119 else if(_evt_reducer_opt ==
"")
143 _gfitter->
init(_gfield,
"KalmanFitter");
147 _gfitter->
init(_gfield,
"KalmanFitterRefTrack");
151 _gfitter->
init(_gfield,
"DafSimple");
155 _gfitter->
init(_gfield,
"DafRef");
169 std::cout <<
"SQReco::InitField" << std::endl;
172 std::cout <<
" KF is disabled thus phfield is not needed. Skip InitField for SQReco." << std::endl;
182 std::cout <<
"PHField check: " <<
"-------" << std::endl;
183 std::ofstream field_scan(
"field_scan.csv");
196 std::cout <<
"SQReco::InitGeom" << std::endl;
199 std::cout <<
" KF is disabled thus TGeo is not needed. Skip InitGeom for SQReco." << std::endl;
209 if(
Verbosity() > 1) std::cout <<
"SQReco::InitGeom - create geom from " << _geom_file_name << std::endl;
215 if(
Verbosity() > 1) std::cout <<
"SQReco::InitGeom - use geom from NodeTree." << std::endl;
222 int SQReco::updateHitInfo(
SRawEvent* sraw_event)
226 size_t idx = _m_hitID_idx[hit.index];
227 SQHit* sq_hit = _hit_vector->
at(idx);
245 _m_hitID_idx.clear();
246 _m_trghitID_idx.clear();
250 int event_id = _event;
264 triggers[i] = _event_header->
get_trigger(static_cast<SQEvent::TriggerMask>(i));
285 if(_triggerhit_vector)
287 for(
size_t idx = 0; idx < _triggerhit_vector->
size(); ++idx)
289 SQHit* sq_hit = _triggerhit_vector->
at(idx);
305 for(
size_t idx = 0; idx < _hit_vector->
size(); ++idx)
307 SQHit* sq_hit = _hit_vector->
at(idx);
345 LogDebug(
"Entering SQReco::process_event: " << _event);
369 std::unique_ptr<SRawEvent> up_raw_event;
372 up_raw_event = std::unique_ptr<SRawEvent>(BuildSRawEvent());
373 _rawEvent = up_raw_event.get();
378 LogInfo(
"SRawEvent before the Reducer");
382 if(_eventReducer !=
nullptr)
390 LogInfo(
"SRawEvent after the Reducer");
394 int finderstatus = _fastfinder->
setRawEvent(_rawEvent);
395 if(_legacy_rec_container)
403 int nFittedTracks = 0;
405 for(
auto iter = rec_tracklets.begin(); iter != rec_tracklets.end(); ++iter)
414 fitOK = fitTrackCand(*iter, _kfitter);
416 fitOK = fitTrackCand(*iter, _gfitter);
424 fillRecTrack(recTrack);
435 LogDebug(
"Leaving SQReco::process_event: " << _event <<
", finder status " << finderstatus <<
", " << nTracklets <<
" track candidates, " << nFittedTracks <<
" fitted tracks");
440 for(
unsigned int i = 0; i < _eval_listIDs.size(); ++i)
442 std::list<Tracklet>& eval_tracklets = _fastfinder->
getTrackletList(_eval_listIDs[i]);
443 for(
auto iter = eval_tracklets.begin(); iter != eval_tracklets.end(); ++iter)
447 new((*_tracklets)[nTracklets])
Tracklet(*iter);
472 if(_gfitter !=
nullptr)
delete _gfitter;
490 LogDebug(
"kFitter failed to converge");
496 LogDebug(
"kmtrk quality cut failed");
510 fillRecTrack(strack);
522 LogDebug(
"gFitter failed to converge.");
544 fillRecTrack(strack);
548 int SQReco::InitEvalTree()
552 _tracklets =
new TClonesArray(
"Tracklet");
554 _eval_tree =
new TTree(
"eval",
"eval");
555 _eval_tree->Branch(
"eventID", &_event,
"eventID/I");
556 _eval_tree->Branch(
"tracklets", &_tracklets, 256000, 99);
557 _tracklets->BypassStreamer();
562 int SQReco::ResetEvalVars()
568 void SQReco::fillRecTrack(
SRecTrack& recTrack)
570 if(_legacy_rec_container)
582 LogInfo(
"No DST node, create one");
587 if(_legacy_rec_container)
591 eventNode->
addNode(recEventNode);
598 eventNode->
addNode(recEventNode);
607 eventNode->
addNode(trackletVecNode);
618 _run_header = findNode::getClass<SQRun>(topNode,
"SQRun");
625 _spill_map = findNode::getClass<SQSpillMap>(topNode,
"SQSpillMap");
632 _event_header = findNode::getClass<SQEvent>(topNode,
"SQEvent");
639 _hit_vector = findNode::getClass<SQHitVector>(topNode,
"SQHitVector");
646 _triggerhit_vector = findNode::getClass<SQHitVector>(topNode,
"SQTriggerHitVector");
647 if(!_triggerhit_vector)
655 _rawEvent = findNode::getClass<SRawEvent>(topNode,
"SRawEvent");
658 if(
Verbosity() > 0)
LogInfo(
"Using SRawEvent as input for E906-like data input");
667 if(std::find(_eval_listIDs.begin(), _eval_listIDs.end(), listID) == _eval_listIDs.end())
669 _eval_listIDs.push_back(listID);
int setRawEvent(SRawEvent *event_input)
virtual void set_pos(const float a)
void SplitLevel(const int i)
virtual int get_run_id() const =0
Return the run ID.
std::list< Tracklet > & getTrackletList(int i)
int Init(PHCompositeNode *topNode)
virtual void set_hodo_mask(const bool a)
void setTriggerBits(Int_t triggers[])
std::vector< Hit > & getAllHits()
void setRecStatus(int status)
virtual float get_pos() const
Return the absolute position of this hit. Probably the value is not properly set at present...
virtual bool get_trigger(const SQEvent::TriggerMask i) const =0
Return the trigger bit (fired or not) of the selected trigger channel.
SRecTrack getSRecTrack()
Output to SRecTrack.
PHGeomTGeo provide run-time access to TGeoManger. It is transient object and it shall NOT be saved to...
void setTracklet(Tracklet &tracklet, double z_reference=590., bool wildseedcov=false)
virtual void set_tdc_time(const float a)
bool is_eval_enabled() const
virtual double get_DoubleFlag(const std::string &name) const
PHBoolean addNode(PHNode *)
static PHGeomTGeo * GetGeomTGeoNode(PHCompositeNode *topNode, bool build_new=true)
Get non-persistent PHGeomTGeo from DST nodes. If not found, make a new one.
int process_event(PHCompositeNode *topNode)
void insertTriggerHit(Hit h)
An SQ interface class to hold one detector hit.
PHFieldConfig_v3 implements field configuration information for input a field map file...
int InitRun(PHCompositeNode *topNode)
virtual int get_event_id() const =0
Return the event ID, which is unique per run.
virtual int get_spill_id() const =0
Return the spill ID.
void setKalmanStatus(Int_t status)
void postFitUpdate(bool updateMeasurements=true)
static int ImportGeomFile(PHCompositeNode *topNode, const std::string &geometry_file)
TGeo ROOT/GDML/Macro file -> DST node with automatic file type discrimination based on file names...
static recoConsts * instance()
virtual short get_target_pos() const
Return the target position in this spill.
void print(unsigned int debugLvl=0)
static PHTFileServer & get(void)
return reference to class singleton
void init(GFField *field, const TString &fitter_choice="KalmanFitterRefTrack")
virtual bool is_in_time() const
Return 'true' if this hit is in the time window.
void setControlParameter(int nMaxIteration, double tolerance)
Set the convergence control parameters.
virtual void push_back(const SQTrack *trk)=0
Definition of hit structure.
virtual void set_drift_distance(const float a)
void setPTSlope(Double_t slopeX, Double_t slopeY)
void setEventInfo(Int_t runID, Int_t spillID, Int_t eventID)
Sets.
static PHField * GetFieldMapNode(const PHFieldConfig *default_config=nullptr, PHCompositeNode *topNode=nullptr, const int verbosity=0)
Get transient PHField from DST nodes. If not found, make a new one based on default_config.
virtual void set_trigger_mask(const bool a)
An SQ interface class to hold the data of one spill.
virtual const SQHit * at(const size_t idkey) const
virtual short get_detector_id() const
Return the detector ID of this hit.
virtual float get_drift_distance() const
Return the drift distance of this hit. Probably the value is not properly set at present. Meaningful only if this hit is of drift chamber or prop tube.
virtual int Verbosity() const
Gets the verbosity of this module.
void setTargetPos(Short_t targetPos)
Output a lot of messages.
std::list< Node > & getNodeList()
virtual const std::string get_CharFlag(const std::string &flag) const
void setInTime(bool f=true)
void setTracklet(Tracklet &tracklet, bool wildseedcov=true)
virtual float get_tdc_time() const
Return the TDC time (nsec) of this hit.
bool cd(const std::string &filename)
change to directory of TFile matching filename
void insertHit(Hit h)
Insert a new hit.
void setNHitsInPT(Int_t nHitsX, Int_t nHitsY)
void identify(std::ostream &os=std::cout) const
PHObject virtual overloads.
static TGeoManager * GetTGeoManager(PHCompositeNode *topNode)
Main user interface: DST node -> TGeoManager for downstream use.
Output some useful messages during manual command line running.
virtual void set_in_time(const bool a)
int reduceEvent(SRawEvent *rawEvent)
void insertTrack(SRecTrack trk)
Insert tracks.
virtual void identify(std::ostream &os=std::cout) const
bool is_eval_dst_enabled() const
virtual size_t size() const
void reIndex(bool doSort=false)
Reset the number hits on each plane.
virtual int get_hit_id() const
Return the ID of this hit.
void setRawEvent(SRawEvent *rawEvent)
directly setup everything by raw event
SQReco(const std::string &name="SQReco")
void setTriggerRoad(Int_t roadID)
virtual short get_element_id() const
Return the element ID of this hit.
void open(const std::string &filename, const std::string &type="RECREATE")
open a SafeTFile. If filename is not found in the map, create a new TFile and append to the map; incr...
bool isValid()
Self check to see if it is null.
int End(PHCompositeNode *topNode)
Called at the end of all processing.
int processTrack(GFTrack &track, bool display=false)
void Verbosity(const int a)
std::list< Tracklet > & getFinalTracklets()
Final output.
virtual int isValid() const
isValid returns non zero if object contains vailid data
void push_back(const Tracklet *tracklet)
virtual const SQSpill * get(unsigned int idkey) const
Return the SQSpill entry having spill ID = 'idkey'. Return '0' if no entry exists.
void add_eval_list(int listID)
int processOneTrack(KalmanTrack &_track)