19 #include <trackbase_historic/SvtxHit.h>
20 #include <trackbase_historic/SvtxHitMap.h>
36 #include <TDatabasePDG.h>
44 #include <HepMC/GenEvent.h>
46 #include <CLHEP/Units/SystemOfUnits.h>
48 #include <boost/format.hpp>
59 using namespace CLHEP;
62 unsigned int minLayer,
63 unsigned int m_maxLayer,
66 , m_saveDataStreamFile(
true)
67 , m_outputFileNameBase(outputfilename)
68 , m_minLayer(minLayer)
69 , m_maxLayer(m_maxLayer)
71 , m_vertexZAcceptanceCut(10)
72 , m_etaAcceptanceCut(1.1)
73 , m_hDataSize(nullptr)
76 , m_hLayerWaveletSize(nullptr)
77 , m_hLayerHit(nullptr)
78 , m_hLayerZBinHit(nullptr)
79 , m_hLayerZBinADC(nullptr)
80 , m_hLayerDataSize(nullptr)
81 , m_hLayerSumHit(nullptr)
82 , m_hLayerSumDataSize(nullptr)
103 for (
unsigned int i = 0;
i < hm->
nHistos();
i++)
107 TTree* T_Index =
new TTree(
"T_Index",
"T_Index");
119 cout <<
"could not locate geo node "
120 <<
"CYLINDERCELLGEOM_SVTX" << endl;
138 if ((
int) nZBins != layerGeom->
get_zbins())
140 cout <<
"TPCDataStreamEmulator::InitRun - Fatal Error - nZBin at layer " <<
layer <<
" is " << layerGeom->
get_zbins()
141 <<
", which is different from previous layers of nZBin = " << nZBins << endl;
148 cout <<
"TPCDataStreamEmulator::get_HistoManager - Making PHTFileServer " <<
m_outputFileNameBase +
".root"
155 TH1D*
h =
new TH1D(
"hNormalization",
156 "Normalization;Items;Summed quantity", 10, .5, 10.5);
158 h->GetXaxis()->SetBinLabel(i++,
"Event count");
159 h->GetXaxis()->SetBinLabel(i++,
"Collision count");
160 h->GetXaxis()->SetBinLabel(i++,
"TPC G4Hit");
161 h->GetXaxis()->SetBinLabel(i++,
"TPC G4Hit Edep");
162 h->GetXaxis()->SetBinLabel(i++,
"TPC Hit");
163 h->GetXaxis()->SetBinLabel(i++,
"TPC Wavelet");
164 h->GetXaxis()->SetBinLabel(i++,
"TPC DataSize");
166 h->GetXaxis()->LabelsOption(
"v");
179 new TH1D(
"hDataSize",
180 "TPC Data Size per Event;Data size [Byte];Count",
185 "TPC Recorded Wavelet per Event;Wavelet count;Count",
190 "Charged particle #eta distribution;#eta;Count",
194 new TH2D(
"hLayerWaveletSize",
195 "Number of Recorded ADC sample per Wavelet;Layer ID;ADC Sample Count per Wavelet",
197 nZBins, -.5, nZBins - .5));
200 new TH2D(
"hLayerHit",
201 "Number of Recorded ADC sample per channel;Layer ID;ADC Sample Count",
203 nZBins, -.5, nZBins - .5));
206 new TH2D(
"hLayerDataSize",
207 "Data size per channel;Layer ID;Data size [Byte]",
209 2 * nZBins, 0, 2 * nZBins));
212 new TH2D(
"hLayerSumHit",
213 "Number of Recorded ADC sample per layer;Layer ID;ADC Sample Count",
215 10000, -.5, 99999.5));
218 new TH2D(
"hLayerSumDataSize",
219 "Data size per trigger per layer;Layer ID;Data size [Byte]",
224 new TH2D(
"hLayerZBinHit",
225 "Number of Recorded ADC sample per Time Bin;z bin ID;Layer ID",
226 nZBins, -.5, nZBins - .5,
230 new TH2D(
"hLayerZBinADC",
231 "Sum ADC per Time Bin;z bin ID;Layer ID",
232 nZBins, -.5, nZBins - .5,
243 TH1D* h_norm =
dynamic_cast<TH1D*
>(hm->
getHisto(
"hNormalization"));
245 h_norm->Fill(
"Event count", 1);
247 PHG4HitContainer* g4hit = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_SVTX");
250 cout <<
"TPCDataStreamEmulator::process_event - Could not locate g4 hit node G4HIT_SVTX" << endl;
254 SvtxHitMap* hits = findNode::getClass<SvtxHitMap>(topNode,
"SvtxHitMap");
257 cout <<
"PCDataStreamEmulator::process_event - ERROR: Can't find node SvtxHitMap" << endl;
261 PHG4CellContainer* cells = findNode::getClass<PHG4CellContainer>(topNode,
"G4CELL_SVTX");
264 cout <<
"TPCDataStreamEmulator::process_event - could not locate cell node "
265 <<
"G4CELL_SVTX" << endl;
272 cout <<
"TPCDataStreamEmulator::process_event - could not locate geo node "
273 <<
"CYLINDERCELLGEOM_SVTX" << endl;
277 PHHepMCGenEventMap* geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
280 static bool once =
true;
285 cout <<
"TPCDataStreamEmulator::process_event - - missing node PHHepMCGenEventMap. Skipping HepMC stat." << std::endl;
290 h_norm->Fill(
"Collision count", geneventmap->
size());
297 cout <<
"TPCDataStreamEmulator::process_event - Fatal Error - "
298 <<
"unable to find DST node "
299 <<
"G4TruthInfo" << endl;
308 particle_iter != primary_range.second;
314 TParticlePDG* pdg_p = TDatabasePDG::Instance()->GetParticle(
318 if (fabs(pdg_p->Charge()) > 0)
337 const double edep = hiter->second->get_edep();
338 h_norm->Fill(
"TPC G4Hit Edep", edep);
339 h_norm->Fill(
"TPC G4Hit", 1);
346 vector<array<vector<int>, 2> > layerChanHit(
m_maxLayer + 1);
347 vector<array<vector<int>, 2> > layerChanDataSize(
m_maxLayer + 1);
362 cout <<
"TPCDataStreamEmulator::process_event - init layer " <<
layer <<
" with "
363 <<
"nphibins = " << nphibins
364 <<
", layerGeom->get_zbins() = " << layerGeom->
get_zbins() << endl;
374 if ((
int) nZBins != layerGeom->
get_zbins())
376 cout <<
"TPCDataStreamEmulator::process_event - Fatal Error - nZBin at layer " <<
layer <<
" is " << layerGeom->
get_zbins()
377 <<
", which is different from previous layers of nZBin = " << nZBins << endl;
382 for (
unsigned int side = 0; side < 2; ++side)
384 layerChanHit[
layer][side].resize(nphibins, 0);
386 layerChanDataSize[
layer][side].resize(nphibins, 0);
396 int last_phibin = -1;
398 vector<unsigned int> last_wavelet;
399 int last_wavelet_hittime = -1;
403 SvtxHit* hit = iter->second;
405 const int layer = hit->get_layer();
407 if (layer < m_minLayer or layer >
m_maxLayer)
continue;
412 const int side = (zbin < nZBins / 2) ? 0 : 1;
415 if (last_layer != layer or last_phibin != phibin or last_side != side or abs(last_zbin - zbin) != 1)
418 if (last_wavelet.size() > 0)
420 const int datasize =
writeWavelet(last_layer, last_side, last_phibin, last_wavelet_hittime, last_wavelet);
424 sumDataSize += datasize;
425 layerChanDataSize[last_layer][last_side][last_phibin] += datasize;
427 last_wavelet.clear();
435 const double z_abs = fabs(layerGeom->
get_zcenter(zbin));
438 const double eta = acceptanceVec.PseudoRapidity();
445 last_phibin = phibin;
448 last_wavelet_hittime = (side == 0) ? (zbin) : (nZBins - 1 - zbin);
449 assert(last_wavelet_hittime >= 0);
450 assert(last_wavelet_hittime <= nZBins / 2);
455 cout <<
"TPCDataStreamEmulator::process_event - layer " << layer <<
" hit with "
457 <<
"phibin = " << phibin
458 <<
",zbin = " << zbin
459 <<
",side = " << side
460 <<
",last_wavelet.size() = " << last_wavelet.size()
461 <<
",last_zbin = " << last_zbin
466 if (last_wavelet.size() > 0)
470 assert(zbin - last_zbin == 1);
474 assert(last_zbin - zbin == 1);
479 unsigned int adc = hit->get_adc();
480 last_wavelet.push_back(adc);
484 layerChanHit[
layer][side][phibin] += 1;
493 if (last_wavelet.size() > 0)
495 const int datasize =
writeWavelet(last_layer, last_side, last_phibin, last_wavelet_hittime, last_wavelet);
499 sumDataSize += datasize;
500 layerChanDataSize[last_layer][last_side][last_phibin] += datasize;
506 for (
unsigned int side = 0; side < 2; ++side)
509 for (
const int& hit : layerChanHit[
layer][side])
515 h_norm->Fill(
"TPC Hit", hit);
519 cout <<
"TPCDataStreamEmulator::process_event - hit: "
521 <<
"at layer = " <<
layer
522 <<
", side = " << side
529 cout <<
"TPCDataStreamEmulator::process_event - hLayerSumCellHit->Fill(" <<
layer <<
", " << sumHit <<
")" << endl;
535 for (
const int&
data : layerChanDataSize[
layer][side])
550 h_norm->Fill(
"TPC Wavelet", nWavelet);
553 h_norm->Fill(
"TPC DataSize", sumDataSize);
560 static const int headersize = 2;
563 const int datasizebit = wavelet.size() * 10;
564 int datasizebyte = datasizebit / 8;
565 if (datasizebyte * 8 < datasizebit) datasizebyte += 1;
570 return headersize + datasizebyte;
576 static string histname(
"TPCDataStreamEmulator_HISTOS");
584 <<
"TPCDataStreamEmulator::get_HistoManager - Making Fun4AllHistoManager " << histname