File indexing completed on 2025-08-05 08:11:14
0001 #include "MbdEmulatorTreeMaker.h"
0002
0003 #include <globalvertex/GlobalVertex.h>
0004 #include <globalvertex/GlobalVertexv1.h>
0005 #include <globalvertex/GlobalVertexMap.h>
0006 #include <globalvertex/GlobalVertexMapv1.h>
0007 #include <vector>
0008
0009 #include <fun4all/Fun4AllReturnCodes.h>
0010 #include <phool/PHCompositeNode.h>
0011 #include <phool/PHIODataNode.h>
0012 #include <phool/PHNode.h>
0013 #include <phool/PHNodeIterator.h>
0014 #include <phool/PHObject.h>
0015 #include <phool/getClass.h>
0016
0017
0018 #include <iostream>
0019
0020 #include <map>
0021
0022
0023 MbdEmulatorTreeMaker::MbdEmulatorTreeMaker(const std::string &name, const std::string &outfilename):
0024 SubsysReco(name)
0025
0026 {
0027 _foutname = outfilename;
0028 }
0029
0030
0031 MbdEmulatorTreeMaker::~MbdEmulatorTreeMaker()
0032 {
0033
0034 }
0035
0036
0037 int MbdEmulatorTreeMaker::Init(PHCompositeNode *topNode)
0038 {
0039
0040 if (Verbosity()) std::cout << __FUNCTION__ << __LINE__<<std::endl;
0041 _f = new TFile( _foutname.c_str(), "RECREATE");
0042
0043 std::cout << " making a file = " << _foutname.c_str() << " , _f = " << _f << std::endl;
0044
0045 _tree = new TTree("ttree","a persevering date tree");
0046
0047
0048 _tree->Branch("trigger_charge_sum",b_trigger_charge_sum,"trigger_charge_sum[32]/i");
0049 _tree->Branch("trigger_nhit",b_trigger_nhit,"trigger_nhit[4]/i");
0050 _tree->Branch("trigger_time_sum",b_trigger_time_sum,"trigger_time_sum[16]/i");
0051 _tree->Branch("trigger_south_tavg",&b_trigger_south_tavg,"trigger_south_tavg/i");
0052 _tree->Branch("trigger_south_nhit",&b_trigger_south_nhit,"trigger_south_nhit/i");
0053 _tree->Branch("trigger_north_tavg",&b_trigger_north_tavg,"trigger_north_tavg/i");
0054 _tree->Branch("trigger_north_nhit",&b_trigger_north_nhit,"trigger_north_nhit/i");
0055 _tree->Branch("trigger_vertex_add",&b_trigger_vertex_add,"trigger_vertex_add/i");
0056 _tree->Branch("trigger_vertex_sub",&b_trigger_vertex_sub,"trigger_vertex_sub/i");
0057
0058 _i_event = 0;
0059 _tree->Branch("gl1_clock",&b_gl1_clock, "gl1_clock/l");
0060 _tree->Branch("gl1_scaled",b_gl1_scaled, "gl1_scaled[64]/l");
0061 _tree->Branch("gl1_live",b_gl1_live, "gl1_live[64]/l");
0062 _tree->Branch("gl1_raw",b_gl1_raw, "gl1_raw[64]/l");
0063 _tree->Branch("gl1_rawvec",&b_gl1_rawvec, "gl1_rawvec/l");
0064 _tree->Branch("gl1_livevec",&b_gl1_livevec, "gl1_livevec/l");
0065 _tree->Branch("gl1_scaledvec",&b_gl1_scaledvec, "gl1_scaledvec/l");
0066
0067 _tree->Branch("mbd_vertex_z", &b_vertex_z, "mbd_vertex_z/F");
0068
0069 std::cout << "Done initing the treemaker"<<std::endl;
0070 return Fun4AllReturnCodes::EVENT_OK;
0071 }
0072
0073
0074 int MbdEmulatorTreeMaker::InitRun(PHCompositeNode *topNode)
0075 {
0076 if (Verbosity()) std::cout << __FUNCTION__ << __LINE__<<std::endl;
0077 return Fun4AllReturnCodes::EVENT_OK;
0078 }
0079
0080
0081
0082 void MbdEmulatorTreeMaker::SetVerbosity(int verbo){
0083 _verbosity = verbo;
0084 return;
0085 }
0086
0087
0088 int MbdEmulatorTreeMaker::process_event(PHCompositeNode *topNode)
0089 {
0090
0091
0092 int i;
0093
0094 _i_event++;
0095
0096 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0097 _gl1_packet = findNode::getClass<Gl1Packet>(topNode, "GL1Packet");
0098
0099 _ll1out_mbd = findNode::getClass<LL1Out>(topNode, "LL1OUT_MBD");
0100
0101 _trigger_primitives_mbd = findNode::getClass<TriggerPrimitiveContainer>(topNode, "TRIGGERPRIMITIVES_MBD");
0102
0103
0104 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0105 GlobalVertexMap* vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
0106 float vertex_z = 0;
0107 b_vertex_z = -999;
0108 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0109
0110 if (vertexmap)
0111 {
0112 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0113 if (!vertexmap->empty())
0114 {
0115 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0116 GlobalVertex* vtx = vertexmap->begin()->second;
0117 if (vtx)
0118 {
0119 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0120 vertex_z = vtx->get_z();
0121 b_vertex_z = vertex_z;
0122 }
0123 }
0124 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0125 }
0126 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0127 if (_gl1_packet)
0128 {
0129 b_gl1_clock = _gl1_packet->lValue(0, "BCO");
0130 b_gl1_rawvec = _gl1_packet->lValue(0, "TriggerInput");
0131 b_gl1_livevec = _gl1_packet->lValue(0, "TriggerVector");
0132 b_gl1_scaledvec = _gl1_packet->lValue(0, "ScaledVector");
0133
0134 for (int i = 0; i < 64; i++)
0135 {
0136 b_gl1_scaled[i] = _gl1_packet->lValue(i, 2);
0137 b_gl1_raw[i] = _gl1_packet->lValue(i, 0);
0138 b_gl1_live[i] = _gl1_packet->lValue(i, 1);
0139 }
0140 }
0141 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0142 std::vector<unsigned int>::iterator it;
0143 std::vector<unsigned int> *sum;
0144 TriggerPrimitiveContainerv1::Range range;
0145 TriggerPrimitivev1::Range srange;
0146 if (_trigger_primitives_mbd)
0147 {
0148 i = 0;
0149 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0150 range = _trigger_primitives_mbd->getTriggerPrimitives();
0151 for (TriggerPrimitiveContainerv1::Iter iter = range.first ; iter != range.second ; ++iter)
0152 {
0153 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0154 _trigger_primitive = (*iter).second;
0155 if (!_trigger_primitive)
0156 {
0157 continue;
0158 }
0159 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0160 srange = _trigger_primitive->getSums();
0161 for (TriggerPrimitive::Iter siter = srange.first; siter != srange.second; ++siter)
0162 {
0163
0164 sum = (*siter).second;
0165 if (!sum->size())
0166 {
0167 return Fun4AllReturnCodes::ABORTEVENT;
0168 }
0169 unsigned int val = sum->at(0);
0170 int ii = i%13;
0171 int ij = i/13;
0172 if ( ii < 9)
0173 {
0174 b_trigger_charge_sum[ij*8 + ii] = val;
0175 }
0176 else if (ii == 9)
0177 {
0178 b_trigger_nhit[ij] = val;
0179 }
0180 else
0181 {
0182 b_trigger_time_sum[ij*4 + ii - 10] = val;
0183 }
0184 i++;
0185 }
0186 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0187 }
0188 }
0189
0190 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0191 if (_ll1out_mbd)
0192 {
0193 i = 0;
0194
0195
0196 LL1Outv1::Range wrange = _ll1out_mbd->getTriggerWords();
0197 for (LL1Outv1::Iter iter = wrange.first ; iter != wrange.second ; ++iter)
0198 {
0199
0200 std::vector<unsigned int> *trigger_word = (*iter).second;
0201 if (!trigger_word->size())
0202 {
0203 return Fun4AllReturnCodes::ABORTEVENT;
0204 }
0205 if (i == 0)
0206 {
0207 b_trigger_south_tavg = trigger_word->at(0);
0208 }
0209 else if (i==1)
0210 {
0211 b_trigger_north_tavg = trigger_word->at(0);
0212 }
0213 else if (i==2)
0214 {
0215 b_trigger_south_nhit = trigger_word->at(0);
0216 }
0217 else if (i==3)
0218 {
0219 b_trigger_north_nhit = trigger_word->at(0);
0220 }
0221 else if (i==6)
0222 {
0223 b_trigger_vertex_sub = trigger_word->at(0);
0224 }
0225 else if (i==7)
0226 {
0227 b_trigger_vertex_add = trigger_word->at(0);
0228 }
0229 i++;
0230 }
0231 }
0232
0233 if (Verbosity()) std::cout << __FILE__ << " "<< __LINE__<<" "<<std::endl;
0234
0235 _tree->Fill();
0236
0237 return Fun4AllReturnCodes::EVENT_OK;
0238 }
0239
0240
0241
0242 void MbdEmulatorTreeMaker::GetNodes(PHCompositeNode* topNode)
0243 {
0244
0245
0246 }
0247
0248 int MbdEmulatorTreeMaker::ResetEvent(PHCompositeNode *topNode)
0249 {
0250 if (Verbosity() > 0)
0251 {
0252 std::cout << "MbdEmulatorTreeMaker::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
0253 }
0254
0255
0256 return Fun4AllReturnCodes::EVENT_OK;
0257 }
0258
0259
0260 int MbdEmulatorTreeMaker::EndRun(const int runnumber)
0261 {
0262 if (Verbosity() > 0)
0263 {
0264 std::cout << "MbdEmulatorTreeMaker::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
0265 }
0266 return Fun4AllReturnCodes::EVENT_OK;
0267 }
0268
0269
0270 int MbdEmulatorTreeMaker::End(PHCompositeNode *topNode)
0271 {
0272 if (Verbosity() > 0)
0273 {
0274 std::cout << "MbdEmulatorTreeMaker::End(PHCompositeNode *topNode) This is the End..." << std::endl;
0275 }
0276 std::cout<<"Total events: "<<_i_event<<std::endl;
0277 _f->Write();
0278 _f->Close();
0279
0280 return Fun4AllReturnCodes::EVENT_OK;
0281 }
0282
0283
0284 int MbdEmulatorTreeMaker::Reset(PHCompositeNode *topNode)
0285 {
0286 if (Verbosity() > 0)
0287 {
0288 std::cout << "MbdEmulatorTreeMaker::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
0289 }
0290 return Fun4AllReturnCodes::EVENT_OK;
0291 }
0292