14 #include <ktracker/SRecEvent.h>
29 write_sq_event_info(true),
31 m_file_name(
"output.root"),
38 m_compression_level(5),
56 std::cout <<
"Fun4AllRUSOutputManager::OpenFile(): Attempting to open file: "
57 << m_file_name <<
" with tree: " << m_tree_name << std::endl;
59 m_file =
new TFile(m_file_name.c_str(),
"RECREATE");
60 m_file->SetCompressionAlgorithm(ROOT::kLZMA);
61 m_file->SetCompressionLevel(m_compression_level);
63 if (!m_file || m_file->IsZombie()) {
64 std::cerr <<
"Error: Could not create file " << m_file_name << std::endl;
67 std::cout <<
"File " << m_file->GetName() <<
" opened successfully." << std::endl;
69 m_tree =
new TTree(m_tree_name.c_str(),
"Tree for storing events");
71 std::cerr <<
"Error: Could not create tree " << m_tree_name << std::endl;
74 std::cout <<
"Tree " << m_tree->GetName() <<
" created successfully." << std::endl;
77 m_tree->Branch(
"runID", &runID,
"runID/I");
78 m_tree->Branch(
"eventID", &eventID,
"eventID/I");
80 if (write_sq_event_info) {
81 m_tree->Branch(
"spillID", &spillID,
"spillID/I");
82 m_tree->Branch(
"rfID", &rfID,
"rfID/I");
83 m_tree->Branch(
"turnID", &turnID,
"turnID/I");
84 m_tree->Branch(
"rfIntensity", rfIntensity,
"rfIntensity[33]/I");
85 m_tree->Branch(
"fpgaTrigger", fpgaTrigger,
"fpgaTrigger[5]/I");
86 m_tree->Branch(
"nimTrigger", nimTrigger,
"nimTrigger[5]/I");
90 m_tree->Branch(
"hitID", &hitID);
91 m_tree->Branch(
"hitTrackID", &hitTrackID);
92 m_tree->Branch(
"detectorID", &detectorID);
93 m_tree->Branch(
"elementID", &elementID);
94 m_tree->Branch(
"tdcTime", &tdcTime);
95 m_tree->Branch(
"driftDistance", &driftDistance);
98 m_evt = findNode::getClass<SQEvent>(startNode,
"SQEvent");
99 m_hit_vec = findNode::getClass<SQHitVector>(startNode,
"SQHitVector");
100 m_vec_trk = findNode::getClass<SQTrackVector>(startNode,
"SQTruthTrackVector");
103 if (m_vec_trk !=
nullptr) {
104 mc_truth_mode =
true;
105 std::cout <<
"Detected SQTruthTrackVector node -enabling MC truth output." << std::endl;
107 m_tree->Branch(
"gProcessID", &gProcessID);
108 m_tree->Branch(
"gCharge", &gCharge);
109 m_tree->Branch(
"gTrackID", &gTrackID);
110 m_tree->Branch(
"gvx", &gvx);
111 m_tree->Branch(
"gvy", &gvy);
112 m_tree->Branch(
"gvz", &gvz);
113 m_tree->Branch(
"gpx", &gpx);
114 m_tree->Branch(
"gpy", &gpy);
115 m_tree->Branch(
"gpz", &gpz);
117 m_tree->Branch(
"gx_st1", &gx_st1);
118 m_tree->Branch(
"gy_st1", &gy_st1);
119 m_tree->Branch(
"gz_st1", &gz_st1);
120 m_tree->Branch(
"gpx_st1", &gpx_st1);
121 m_tree->Branch(
"gpy_st1", &gpy_st1);
122 m_tree->Branch(
"gpz_st1", &gpz_st1);
124 m_tree->Branch(
"gx_st3", &gx_st3);
125 m_tree->Branch(
"gy_st3", &gy_st3);
126 m_tree->Branch(
"gz_st3", &gz_st3);
127 m_tree->Branch(
"gpx_st3", &gpx_st3);
128 m_tree->Branch(
"gpy_st3", &gpy_st3);
129 m_tree->Branch(
"gpz_st3", &gpz_st3);
131 mc_truth_mode =
false;
132 std::cout <<
"No SQTruthTrackVector node found -writing data-mode output only." << std::endl;
136 m_tree->SetAutoFlush(m_auto_flush);
137 m_tree->SetBasketSize(
"*", m_basket_size);
140 if (!m_evt || !m_hit_vec) {
141 std::cerr <<
"Error: Missing SQEvent or SQHitVector nodes in the node tree." << std::endl;
149 if (!m_file || !m_tree) {
153 if (write_sq_event_info){
171 for (
int i = -16; i <= 16; ++i) {
175 if (!mc_truth_mode) {
177 for (
int ihit = 0; ihit < m_hit_vec->
size(); ++ihit) {
178 SQHit* hit = m_hit_vec->
at(ihit);
190 for (
unsigned int ii = 0; ii < m_vec_trk->
size(); ii++) {
216 if (z <= -296. && z >= -304.) source_flag = 1;
217 else if (z >= 0. && z < 500) source_flag = 2;
218 else if (z > -296. && z < 0.) source_flag = 3;
219 else if (z < -304) source_flag = 0;
221 for (
int ihit = 0; ihit < m_hit_vec->
size(); ++ihit) {
222 SQHit* hit = m_hit_vec->
at(ihit);
225 int process_id_ = (trk->
get_charge() > 0) ? process_id : process_id + 10;
226 unsigned int encodedValue =
EncodeProcess(process_id_, source_flag);
227 gProcessID.push_back(encodedValue);
243 std::cout <<
"Fun4AllRUSOutputManager::CloseFile(): Closing file: " << m_file_name << std::endl;
256 driftDistance.clear();
262 gvx.clear(); gvy.clear(); gvz.clear();
263 gpx.clear(); gpy.clear(); gpz.clear();
264 gx_st1.clear(); gy_st1.clear(); gz_st1.clear();
265 gpx_st1.clear(); gpy_st1.clear(); gpz_st1.clear();
266 gx_st3.clear(); gy_st3.clear(); gz_st3.clear();
267 gpx_st3.clear(); gpy_st3.clear(); gpz_st3.clear();
273 return ((sourceFlag & 0x3) << 5) |
Fun4AllRUSOutputManager(const std::string &myname="UNIVERSALOUT")
virtual ~Fun4AllRUSOutputManager()
unsigned int EncodeProcess(int processID, int sourceFlag)
void ResetTrueTrackBranches()
int OpenFile(PHCompositeNode *startNode)
virtual int Write(PHCompositeNode *startNode)
write starting from given node
virtual int get_run_id() const =0
Return the run ID.
virtual int get_qie_rf_intensity(const short i) const =0
Return the i-th QIE RF intensity, where i=-16...+16.
virtual bool get_trigger(const SQEvent::TriggerMask i) const =0
Return the trigger bit (fired or not) of the selected trigger channel.
virtual int get_qie_turn_id() const =0
Return the QIE turn ID.
virtual int get_qie_rf_id() const =0
Return the QIE RF ID.
virtual int get_spill_id() const =0
Return the spill ID.
virtual int get_event_id() const =0
Return the event ID, which is unique per run.
virtual const SQHit * at(const size_t idkey) const =0
virtual size_t size() const =0
An SQ interface class to hold one detector hit.
virtual float get_drift_distance() const
Return the drift distance of this hit. Probably the value is not properly set at present....
virtual short get_element_id() const
Return the element ID of this hit.
virtual int get_hit_id() const
Return the ID of this hit.
virtual float get_tdc_time() const
Return the TDC time (nsec) of this hit.
virtual short get_detector_id() const
Return the detector ID of this hit.
virtual int get_track_id() const
Return the track ID associated with this hit. Probably the value is not properly set at present.
virtual const SQTrack * at(const size_t id) const =0
virtual size_t size() const =0
An SQ interface class to hold one true or reconstructed track.
virtual int get_track_id() const =0
Return the track ID, which is unique per event(?).
virtual TVector3 get_pos_vtx() const =0
Return the track position at vertex.
virtual int get_charge() const =0
Return the charge, i.e. +1 or -1.
virtual TLorentzVector get_mom_vtx() const =0
Return the track momentum at vertex.
virtual TLorentzVector get_mom_st1() const =0
Return the track momentum at Station 1.
virtual TVector3 get_pos_st3() const =0
Return the track position at Station 3.
virtual TVector3 get_pos_st1() const =0
Return the track position at Station 1.
virtual TLorentzVector get_mom_st3() const =0
Return the track momentum at Station 3.