4 #include <pdbcalbase/PdbParameterMap.h>
24 #include <mvtx/MvtxDefs.h>
36 #include <HepMC/GenEvent.h>
37 #include <HepMC/GenVertex.h>
41 #include <TDatabasePDG.h>
45 #include <TLorentzVector.h>
49 #include <rapidjson/document.h>
50 #include <rapidjson/ostreamwrapper.h>
51 #include <rapidjson/prettywriter.h>
53 #include <boost/format.hpp>
54 #include <boost/property_tree/json_parser.hpp>
55 #include <boost/property_tree/ptree.hpp>
56 #include <boost/property_tree/xml_parser.hpp>
75 , m_GenEventMap(nullptr)
76 , m_truthInfo(nullptr)
77 , m_g4hits_mvtx(nullptr)
82 , m_hitStaveLayer(nullptr)
83 , m_hitModuleHalfStave(nullptr)
84 , m_hitChipModule(nullptr)
85 , m_hitLayerMap(nullptr)
86 , m_hitPixelPhiMap(nullptr)
87 , m_hitPixelPhiMapHL(nullptr)
88 , m_hitPixelZMap(nullptr)
97 _f =
new TFile((
_foutname +
string(
".root")).c_str(),
"RECREATE");
109 m_hitLayerMap =
new TH3F(
"hitLayerMap",
"hitLayerMap", 600, -10, 10, 600, -10, 10, 10, -.5, 9.5);
110 m_hitLayerMap->SetTitle(
"hitLayerMap;x [mm];y [mm];Half Layers");
112 m_hitPixelPhiMap =
new TH3F(
"hitPixelPhiMap",
"hitPixelPhiMap", 16000, -.5, 16000 - .5, 600, -M_PI, M_PI, 10, -.5, 9.5);
113 m_hitPixelPhiMap->SetTitle(
"hitPixelPhiMap;PixelPhiIndex in layer;phi [rad];Half Layers Index");
114 m_hitPixelPhiMapHL =
new TH3F(
"hitPixelPhiMapHL",
"hitPixelPhiMapHL", 16000, -.5, 16000 - .5, 600, -M_PI, M_PI, 10, -.5, 9.5);
115 m_hitPixelPhiMapHL->SetTitle(
"hitPixelPhiMap;PixelPhiIndex in half layer;phi [rad];Half Layers Index");
116 m_hitPixelZMap =
new TH3F(
"hitPixelZMap",
"hitPixelZMap", 16000, -.5, 16000 - .5, 600, 15, 15, 10, -.5, 9.5);
117 m_hitPixelZMap->SetTitle(
"hitPixelZMap;hitPixelZMap;z [cm];Half Layers");
119 m_hitStaveLayer =
new TH2F(
"hitStaveLayer",
"hitStaveLayer", 100, -.5, 100 - .5, 10, -.5, 9.5);
121 m_hitModuleHalfStave =
new TH2F(
"hitModuleHalfStave",
"hitModuleHalfStave", 100, -.5, 100 - .5, 10, -.5, 9.5);
123 m_hitChipModule =
new TH2F(
"hitChipModule",
"hitChipModule", 100, -.5, 100 - .5, 10, -.5, 9.5);
132 findNode::getClass<PHG4CylinderGeomContainer>(topNode,
"CYLINDERGEOM_MVTX");
135 std::cout <<
PHWHERE <<
"ERROR: Can't find node CYLINDERCELLGEOM_MVTX" << std::endl;
139 m_truthInfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,
"G4TruthInfo");
142 std::cout <<
PHWHERE <<
"ERROR: Can't find node G4TruthInfo" << std::endl;
146 m_Flags = findNode::getClass<PdbParameterMap>(topNode,
"HFMLTrigger_HepMCTriggerFlags");
149 cout <<
"HFMLTriggerInterface::InitRun - WARNING - missing HFMLTrigger_HepMCTriggerFlags" << endl;
185 std::cout <<
PHWHERE <<
" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID " <<
_embedding_id;
186 std::cout <<
". Print PHHepMCGenEventMap:";
191 HepMC::GenEvent* theEvent = genevt->
getEvent();
195 cout <<
"HFMLTriggerInterface::process_event - process HepMC::GenEvent with signal_process_id = "
196 << theEvent->signal_process_id();
197 if (theEvent->signal_process_vertex())
199 cout <<
" and signal_process_vertex : ";
200 theEvent->signal_process_vertex()->print();
202 cout <<
" - Event record:" << endl;
210 rapidjson::Document d;
212 rapidjson::Document::AllocatorType& alloc = d.GetAllocator();
214 auto loadCoordinate = [&](
double x,
double y,
double z) {
230 vertexTree.PushBack(x, alloc).PushBack(y, alloc).PushBack(
z, alloc);
242 metaTree.AddMember(
"Description",
"These are meta data for this event. Not intended to use in ML algorithm", alloc);
243 metaTree.AddMember(
"EventID",
_ievent, alloc);
244 metaTree.AddMember(
"Unit",
"cm", alloc);
245 metaTree.AddMember(
"CollisionVertex",
252 metaTree.AddMember(
"PixelHalfLayerIndex_Count",
_nlayers_maps * 2, alloc);
262 static const unsigned int nChip(9);
264 layerDescTree.AddMember(
"PixelPhiIndexInLayer_Count", geom->
get_N_staves() * geom->
get_NX(), alloc);
265 layerDescTree.AddMember(
"PixelPhiIndexInHalfLayer_Count", geom->
get_N_staves() * geom->
get_NX() / 2, alloc);
266 layerDescTree.AddMember(
"PixelZIndex_Count", nChip * geom->
get_NZ(), alloc);
267 layerDescTree.AddMember(
"HalfLayer_Count", 2, alloc);
268 layerDescTree.AddMember(
"Stave_Count", geom->
get_N_staves(), alloc);
269 layerDescTree.AddMember(
"Chip_Count", nChip, alloc);
270 layerDescTree.AddMember(
"Pixel_Count", geom->
get_NX() * geom->
get_NZ(), alloc);
276 metaTree.AddMember(keyName,
277 layerDescTree, alloc);
283 truthTriggerFlagTree.AddMember(
"Description",
284 "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.",
293 for (
auto flagIter = range.first; flagIter != range.second; ++flagIter)
297 const string&
name = flagIter->first;
299 const bool flag = flagIter->second > 0 ?
true :
false;
301 flagsTree.AddMember(keyName, flag, alloc);
305 truthTriggerFlagTree.AddMember(
"Flags", flagsTree, alloc);
310 rawHitTree.AddMember(
"Description",
311 "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.",
320 unsigned int hitID(0);
322 for (
auto hitset_iter = hitset_range.first; hitset_iter != hitset_range.second; ++hitset_iter)
325 auto hit_range = hitset_iter->second->getHits();
326 for (
auto hit_iter = hit_range.first;
327 hit_iter != hit_range.second;
330 auto hitkey = hit_iter->first;
331 auto hit = hit_iter->second;
334 if (layer < _nlayers_maps)
341 assert((
int)pixel_x < geom->get_NX());
342 assert((
int)pixel_z < geom->get_NZ());
366 hitIDTree.AddMember(
"HitSequenceInEvent",
hitID, alloc);
373 hitIDTree.AddMember(
"Layer", layer, alloc);
375 hitIDTree.AddMember(
"Stave", stave, alloc);
378 hitIDTree.AddMember(
"Chip", chip, alloc);
379 hitIDTree.AddMember(
"Pixel_x", pixel_x, alloc);
380 hitIDTree.AddMember(
"Pixel_z", pixel_z, alloc);
381 hitTree.AddMember(
"ID", hitIDTree, alloc);
383 hitTree.AddMember(
"Coordinate",
384 loadCoordinate(world_coords.x(),
390 rawHitsTree.PushBack(hitTree, alloc);
404 rawHitTree.AddMember(
"MVTXHits", rawHitsTree, alloc);
409 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.",
413 std::multimap<const int, const unsigned long long> m_track_g4hits_map;
418 PHG4Hit *g4hit = g4hit_iter->second;
419 m_track_g4hits_map.insert(make_pair(g4hit->
get_trkid(), g4hit_iter->first));
428 for (
auto pp_iter = pp_range.first;
429 pp_iter != pp_range.second;
435 if (! m_track_g4hits_map.count(g4particle->
get_track_id()))
438 std::cout <<
"WARNING: G4 particle " << g4particle->
get_track_id() \
439 <<
" does not hit any MVTX layer." << std::endl;
446 auto g4hits_iter = m_track_g4hits_map.equal_range(g4particle->
get_track_id());
447 for (
auto& g4hit_iter = g4hits_iter.first;
448 g4hit_iter != g4hits_iter.second; ++g4hit_iter)
452 trackHitTree.PushBack(static_cast<uint64_t>(g4hit_iter->second), alloc);
457 trackTree.AddMember(
"TrackSequenceInEvent", g4particle->
get_track_id(), alloc);
458 trackTree.AddMember(
"HitSequenceInEvent", trackHitTree, alloc);
460 trackTree.AddMember(
"ParticleTypeID", g4particle->
get_pid(), alloc);
461 trackTree.AddMember(
"TrackMomentum",
462 loadCoordinate(g4particle->
get_px(),
472 truthTracksTree.PushBack(trackTree, alloc);
475 truthHitTree.AddMember(
"TruthTracks", truthTracksTree, alloc);
478 d.AddMember(
"MetaData", metaTree, alloc);
479 d.AddMember(
"TruthTriggerFlag", truthTriggerFlagTree, alloc);
480 d.AddMember(
"RawHit", rawHitTree, alloc);
481 d.AddMember(
"TruthHit", truthHitTree, alloc);
495 rapidjson::OStreamWrapper osw(
m_jsonOut);
496 rapidjson::PrettyWriter<rapidjson::OStreamWrapper>
writer(osw);
521 cout <<
"HFMLTriggerInterface::End - output to " <<
_foutname <<
".*" << endl;
529 m_hitsets = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
532 std::cout <<
PHWHERE <<
"ERROR: Can't find node TRKR_HITSET" << std::endl;
550 m_g4hits_mvtx = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_MVTX");
553 std::cout <<
PHWHERE <<
" unable to find DST node G4HIT_MVTX" << std::endl;
557 m_GenEventMap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
560 std::cout <<
PHWHERE <<
" - Fatal error - missing node PHHepMCGenEventMap" << std::endl;