File indexing completed on 2025-08-05 08:15:08
0001 #include <cstdlib>
0002 #include <iostream>
0003 #include <string>
0004
0005 #include "TFile.h"
0006 #include "TTree.h"
0007 #include "TString.h"
0008 #include "TObjString.h"
0009 #include "TSystem.h"
0010 #include "TROOT.h"
0011
0012 #include <boost/format.hpp>
0013 #include <boost/math/special_functions/sign.hpp>
0014
0015
0016
0017
0018
0019
0020 void TPCEventDisplay_Hits(const string &outfile = "./TPCEventDisplay_cosmics25926",
0021 const string &infile = "/sphenix/u/rosstom/macros/TrackingProduction/cosmics25926_ntup.root",
0022 const string &runNumber = "25926",
0023 int nEventsToRun = 5){
0024
0025 TFile *ntpFile = TFile::Open(infile.c_str());
0026 TTree *hitTree = (TTree*)ntpFile->Get("ntp_hit");
0027
0028 Float_t event;
0029 Float_t x, y, z, adc;
0030 hitTree->SetBranchAddress("event",&event);
0031 hitTree->SetBranchAddress("x",&x);
0032 hitTree->SetBranchAddress("y",&y);
0033 hitTree->SetBranchAddress("z",&z);
0034 hitTree->SetBranchAddress("adc",&adc);
0035
0036 Int_t currentEvent = 0;
0037 bool firstHit = true;
0038
0039 std::ofstream outdata;
0040 outdata.open((outfile+"_event0.json").c_str(),std::ofstream::out | std::ofstream::trunc);
0041 if( !outdata ) {
0042 cerr << "ERROR: file could not be opened" << endl;
0043 exit(1);
0044 }
0045 outdata << "{\n \"EVENT\": {\n \"runid\":" << runNumber << ", \n \"evtid\": 1, \n \"time\": 0, \n \"timeStr\": \"2023-08-23, 15:23:30 EST\", \n \"type\": \"Cosmics\", \n \"s_nn\": 0, \n \"B\": 0.0,\n \"pv\": [0,0,0],\n \"runstats\": [ \n \"sPHENIX Time Projection Chamber\", \"2023-08-23, Run 25926 - Event 1\", \"Cosmics Data\"] \n },\n" << endl;
0046
0047 outdata << " \"META\": {\n \"HITS\": {\n \"INNERTRACKER\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 2,\n \"color\": 16777215\n } \n },\n" << endl;
0048 outdata << " \"TRACKHITS\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 2,\n \"transparent\": 0.5,\n \"color\": 16777215\n } \n },\n" << endl;
0049 outdata << " \"JETS\": {\n \"type\": \"JET\",\n \"options\": {\n \"rmin\": 0,\n \"rmax\": 78,\n \"emin\": 0,\n \"emax\": 30,\n \"color\": 16777215,\n \"transparent\": 0.5 \n }\n }\n }\n }\n," << endl;
0050 outdata << " \"HITS\": {\n \"CEMC\":[{\"eta\": 0, \"phi\": 0, \"e\": 0}\n ],\n \"HCALIN\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n ],\n \"HCALOUT\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n \n ],\n\n" << endl;
0051 outdata << " \"TRACKHITS\": [\n\n ";
0052
0053 for(int i = 0; i < hitTree->GetEntries(); i++)
0054 {
0055 hitTree->GetEntry(i);
0056
0057 if (event != currentEvent)
0058 {
0059 if (event == currentEvent + 1)
0060 {
0061 outdata << "],\n \"JETS\": [\n ]\n }," << endl;
0062 outdata << "\"TRACKS\": {" << endl;
0063 outdata <<"\""<<"INNERTRACKER"<<"\": [";
0064 outdata << "]" << endl;
0065 outdata << "}" << endl;
0066 outdata << "}" << endl;
0067 outdata.close();
0068
0069 currentEvent = event;
0070 firstHit = true;
0071 if (currentEvent >= nEventsToRun) break;
0072
0073 outdata.open((outfile+"_event"+std::to_string(currentEvent)+".json").c_str(),std::ofstream::out | std::ofstream::trunc);
0074 if( !outdata )
0075 {
0076 cerr << "ERROR: file could not be opened" << endl;
0077 exit(1);
0078 }
0079 outdata << "{\n \"EVENT\": {\n \"runid\":" << runNumber << ", \n \"evtid\": 1, \n \"time\": 0, \n \"timeStr\": \"2023-08-23, 15:23:30 EST\", \n \"type\": \"Cosmics\", \n \"s_nn\": 0, \n \"B\": 0.0,\n \"pv\": [0,0,0],\n \"runstats\": [ \n \"sPHENIX Time Projection Chamber\", \"2023-08-23, Run 25926 - Event " << currentEvent+1 << "\", \"Cosmics Data\"] \n },\n" << endl;
0080
0081 outdata << " \"META\": {\n \"HITS\": {\n \"INNERTRACKER\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 2,\n \"color\": 16777215\n } \n },\n" << endl;
0082 outdata << " \"TRACKHITS\": {\n \"type\": \"3D\",\n \"options\": {\n \"size\": 2,\n \"transparent\": 0.5,\n \"color\": 16777215\n } \n },\n" << endl;
0083 outdata << " \"JETS\": {\n \"type\": \"JET\",\n \"options\": {\n \"rmin\": 0,\n \"rmax\": 78,\n \"emin\": 0,\n \"emax\": 30,\n \"color\": 16777215,\n \"transparent\": 0.5 \n }\n }\n }\n }\n," << endl;
0084 outdata << " \"HITS\": {\n \"CEMC\":[{\"eta\": 0, \"phi\": 0, \"e\": 0}\n ],\n \"HCALIN\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n ],\n \"HCALOUT\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n \n ],\n\n" << endl;
0085 outdata << " \"TRACKHITS\": [\n\n ";
0086 }
0087 else
0088 {
0089 std::cout << "Error: hit for a previous event placed later in the ntuple" << std::endl;
0090 }
0091 }
0092
0093 stringstream spts;
0094
0095 if (firstHit) firstHit = false;
0096 else spts << ",";
0097
0098 spts << "{ \"x\": ";
0099 spts << x;
0100 spts << ", \"y\": ";
0101 spts << y;
0102 spts << ", \"z\": ";
0103 spts << z;
0104 spts << ", \"e\": ";
0105 spts << adc;
0106 spts << "}";
0107
0108 outdata << (boost::format("%1%") % spts.str());
0109 spts.clear();
0110 spts.str("");
0111 }
0112 std::cout << "Done" << std::endl;
0113 }