4 #include <pdbcalbase/PdbParameterMap.h>
17 #include <g4mvtx/PHG4CylinderGeom_MVTX.h>
26 #include <trackbase_historic/SvtxCluster.h>
27 #include <trackbase_historic/SvtxClusterMap.h>
28 #include <trackbase_historic/SvtxHit.h>
29 #include <trackbase_historic/SvtxHitMap.h>
32 #include <trackbase_historic/SvtxVertex.h>
33 #include <trackbase_historic/SvtxVertexMap.h>
37 #include <HepMC/GenEvent.h>
38 #include <HepMC/GenVertex.h>
42 #include <TDatabasePDG.h>
46 #include <TLorentzVector.h>
50 #include <rapidjson/document.h>
51 #include <rapidjson/ostreamwrapper.h>
52 #include <rapidjson/prettywriter.h>
54 #include <boost/format.hpp>
55 #include <boost/property_tree/json_parser.hpp>
56 #include <boost/property_tree/ptree.hpp>
57 #include <boost/property_tree/xml_parser.hpp>
76 , _svtxevalstack(nullptr)
79 , m_truthInfo(nullptr)
81 , m_hitStaveLayer(nullptr)
82 , m_hitModuleHalfStave(nullptr)
83 , m_hitChipModule(nullptr)
84 , m_hitLayerMap(nullptr)
85 , m_hitPixelPhiMap(nullptr)
86 , m_hitPixelPhiMapHL(nullptr)
87 , m_hitPixelZMap(nullptr)
96 _f =
new TFile((
_foutname +
string(
".root")).c_str(),
"RECREATE");
108 m_hitLayerMap =
new TH3F(
"hitLayerMap",
"hitLayerMap", 600, -10, 10, 600, -10, 10, 10, -.5, 9.5);
109 m_hitLayerMap->SetTitle(
"hitLayerMap;x [mm];y [mm];Half Layers");
111 m_hitPixelPhiMap =
new TH3F(
"hitPixelPhiMap",
"hitPixelPhiMap", 16000, -.5, 16000 - .5, 600, -M_PI, M_PI, 10, -.5, 9.5);
112 m_hitPixelPhiMap->SetTitle(
"hitPixelPhiMap;PixelPhiIndex in layer;phi [rad];Half Layers Index");
113 m_hitPixelPhiMapHL =
new TH3F(
"hitPixelPhiMapHL",
"hitPixelPhiMapHL", 16000, -.5, 16000 - .5, 600, -M_PI, M_PI, 10, -.5, 9.5);
114 m_hitPixelPhiMapHL->SetTitle(
"hitPixelPhiMap;PixelPhiIndex in half layer;phi [rad];Half Layers Index");
115 m_hitPixelZMap =
new TH3F(
"hitPixelZMap",
"hitPixelZMap", 16000, -.5, 16000 - .5, 600, 15, 15, 10, -.5, 9.5);
116 m_hitPixelZMap->SetTitle(
"hitPixelZMap;hitPixelZMap;z [cm];Half Layers");
118 m_hitStaveLayer =
new TH2F(
"hitStaveLayer",
"hitStaveLayer", 100, -.5, 100 - .5, 10, -.5, 9.5);
120 m_hitModuleHalfStave =
new TH2F(
"hitModuleHalfStave",
"hitModuleHalfStave", 100, -.5, 100 - .5, 10, -.5, 9.5);
122 m_hitChipModule =
new TH2F(
"hitChipModule",
"hitChipModule", 100, -.5, 100 - .5, 10, -.5, 9.5);
130 m_hitMap = findNode::getClass<SvtxHitMap>(topNode,
"SvtxHitMap");
133 std::cout <<
PHWHERE <<
"ERROR: Can't find node SvtxHitMap" << std::endl;
137 findNode::getClass<PHG4CylinderGeomContainer>(topNode,
"CYLINDERGEOM_MAPS");
140 std::cout <<
PHWHERE <<
"ERROR: Can't find node CYLINDERCELLGEOM_SVTX" << std::endl;
144 m_truthInfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
147 std::cout <<
PHWHERE <<
"ERROR: Can't find node G4TruthInfo" << std::endl;
151 m_Flags = findNode::getClass<PdbParameterMap>(topNode,
"HFMLTrigger_HepMCTriggerFlags");
154 cout <<
"HFMLTriggerInterface::InitRun - WARNING - missing HFMLTrigger_HepMCTriggerFlags" << endl;
179 PHHepMCGenEventMap* geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
182 std::cout <<
PHWHERE <<
" - Fatal error - missing node PHHepMCGenEventMap" << std::endl;
189 std::cout <<
PHWHERE <<
" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID " <<
_embedding_id;
190 std::cout <<
". Print PHHepMCGenEventMap:";
195 HepMC::GenEvent* theEvent = genevt->
getEvent();
199 cout <<
"HFMLTriggerInterface::process_event - process HepMC::GenEvent with signal_process_id = "
200 << theEvent->signal_process_id();
201 if (theEvent->signal_process_vertex())
203 cout <<
" and signal_process_vertex : ";
204 theEvent->signal_process_vertex()->print();
206 cout <<
" - Event record:" << endl;
214 rapidjson::Document d;
216 rapidjson::Document::AllocatorType& alloc = d.GetAllocator();
218 auto loadCoordinate = [&](
double x,
double y,
double z) {
234 vertexTree.PushBack(x, alloc).PushBack(y, alloc).PushBack(
z, alloc);
246 metaTree.AddMember(
"Description",
"These are meta data for this event. Not intended to use in ML algorithm", alloc);
247 metaTree.AddMember(
"EventID",
_ievent, alloc);
248 metaTree.AddMember(
"Unit",
"cm", alloc);
249 metaTree.AddMember(
"CollisionVertex",
256 metaTree.AddMember(
"PixelHalfLayerIndex_Count",
_nlayers_maps * 2, alloc);
266 static const unsigned int nChip(9);
268 layerDescTree.AddMember(
"PixelPhiIndexInLayer_Count", geom->get_N_staves() * geom->get_NX(), alloc);
269 layerDescTree.AddMember(
"PixelPhiIndexInHalfLayer_Count", geom->get_N_staves() * geom->get_NX() / 2, alloc);
270 layerDescTree.AddMember(
"PixelZIndex_Count", nChip * geom->get_NZ(), alloc);
271 layerDescTree.AddMember(
"HalfLayer_Count", 2, alloc);
272 layerDescTree.AddMember(
"Stave_Count", geom->get_N_staves(), alloc);
273 layerDescTree.AddMember(
"Chip_Count", nChip, alloc);
274 layerDescTree.AddMember(
"Pixel_Count", geom->get_NX() * geom->get_NZ(), alloc);
280 metaTree.AddMember(keyName,
281 layerDescTree, alloc);
287 truthTriggerFlagTree.AddMember(
"Description",
288 "These are categorical true/false MonteCalo truth tags for the event. These are only known in training sample. This would be trigger output in real data processing.",
297 for (
auto flagIter = range.first; flagIter != range.second; ++flagIter)
301 const string&
name = flagIter->first;
303 const bool flag = flagIter->second > 0 ?
true :
false;
305 flagsTree.AddMember(keyName, flag, alloc);
309 truthTriggerFlagTree.AddMember(
"Flags", flagsTree, alloc);
314 rawHitTree.AddMember(
"Description",
315 "Raw data in the event in an unordered set of hit ID. To help in visualization stage, the coordinate of the hit is also appended. These would be input in real data.",
323 set<unsigned int> mapsHits;
329 SvtxHit* hit = iter->second;
331 unsigned int layer = hit->get_layer();
332 if (layer < _nlayers_maps)
334 unsigned int hitID = hit->get_id();
335 mapsHits.insert(hitID);
337 PHG4Cell* cell = hiteval->get_cell(hit);
339 PHG4CylinderGeom_MVTX* geom =
dynamic_cast<PHG4CylinderGeom_MVTX*
>(
m_Geoms->
GetLayerGeom(layer));
342 TVector3 local_coords = geom->get_local_coords_from_pixel(cell->
get_pixel_index());
347 unsigned int halflayer = (int) pixel_x >= geom->get_NX() / 2 ? 0 : 1;
349 assert((
int) pixel_x < geom->get_NX());
350 assert((
int) pixel_z < geom->get_NZ());
352 unsigned int halfLayerIndex(layer * 2 + halflayer);
353 unsigned int pixelPhiIndex(
355 unsigned int pixelPhiIndexHL(
356 cell->
get_stave_index() * geom->get_NX() / 2 + pixel_x % (geom->get_NX() / 2));
357 unsigned int pixelZIndex(cell->
get_chip_index() * geom->get_NZ() + pixel_z);
364 hitIDTree.AddMember(
"HitSequenceInEvent", hitID, alloc);
366 hitIDTree.AddMember(
"PixelHalfLayerIndex", halfLayerIndex, alloc);
367 hitIDTree.AddMember(
"PixelPhiIndexInLayer", pixelPhiIndex, alloc);
368 hitIDTree.AddMember(
"PixelPhiIndexInHalfLayer", pixelPhiIndexHL, alloc);
369 hitIDTree.AddMember(
"PixelZIndex", pixelZIndex, alloc);
371 hitIDTree.AddMember(
"Layer", layer, alloc);
372 hitIDTree.AddMember(
"HalfLayer", halflayer, alloc);
378 hitTree.AddMember(
"ID", hitIDTree, alloc);
380 hitTree.AddMember(
"Coordinate",
381 loadCoordinate(world_coords.x(),
387 rawHitsTree.PushBack(hitTree, alloc);
393 m_hitLayerMap->Fill(world_coords.x(), world_coords.y(), halfLayerIndex);
394 m_hitPixelPhiMap->Fill(pixelPhiIndex, atan2(world_coords.y(), world_coords.x()), halfLayerIndex);
395 m_hitPixelPhiMapHL->Fill(pixelPhiIndexHL, atan2(world_coords.y(), world_coords.x()), halfLayerIndex);
396 m_hitPixelZMap->Fill(pixelZIndex, world_coords.z(), halfLayerIndex);
400 rawHitTree.AddMember(
"MVTXHits", rawHitsTree, alloc);
405 truthHitTree.AddMember(
"Description",
"From the MonteCalo truth information, pairs of track ID and subset of RawHit that belong to the track. These are not presented in real data. The track ID is arbitary.",
415 iter != range.second;
425 unsigned int nMAPS(0);
427 for (
const SvtxCluster* cluster : g4clusters)
430 unsigned int layer = cluster->get_layer();
431 if (layer < _nlayers_maps)
435 for (SvtxCluster::ConstHitIter hiter = cluster->begin_hits();
436 hiter != cluster->end_hits();
440 unsigned int hitID = *hiter;
441 assert(mapsHits.find(hitID) != mapsHits.end());
445 trackHitTree.PushBack(hitID, alloc);
455 trackTree.AddMember(
"TrackSequenceInEvent", g4particle->
get_track_id(), alloc);
456 trackTree.AddMember(
"HitSequenceInEvent", trackHitTree, alloc);
458 trackTree.AddMember(
"ParticleTypeID", g4particle->
get_pid(), alloc);
459 trackTree.AddMember(
"TrackMomentum",
460 loadCoordinate(g4particle->
get_px(),
470 truthTracksTree.PushBack(trackTree, alloc);
474 truthHitTree.AddMember(
"TruthTracks", truthTracksTree, alloc);
477 d.AddMember(
"MetaData", metaTree, alloc);
478 d.AddMember(
"TruthTriggerFlag", truthTriggerFlagTree, alloc);
479 d.AddMember(
"RawHit", rawHitTree, alloc);
480 d.AddMember(
"TruthHit", truthHitTree, alloc);
494 rapidjson::OStreamWrapper osw(
m_jsonOut);
495 rapidjson::PrettyWriter<rapidjson::OStreamWrapper>
writer(osw);
523 cout <<
"HFMLTriggerInterface::End - output to " <<
_foutname <<
".*" << endl;