CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
XMLEventWriter Class Reference

#include <XMLEventWriter.h>

Inheritance diagram for XMLEventWriter:
IOMTFEmulationObserver

Public Member Functions

void addProcesorData (std::string key, boost::property_tree::ptree &procDataTree) override
 
void endJob () override
 
void observeEventBegin (const edm::Event &iEvent) override
 
void observeEventEnd (const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
 
void observeProcesorBegin (unsigned int iProcessor, l1t::tftype mtfType) override
 
void observeProcesorEmulation (unsigned int iProcessor, l1t::tftype mtfType, const std::shared_ptr< OMTFinput > &input, const AlgoMuons &algoCandidates, const AlgoMuons &gbCandidates, const std::vector< l1t::RegionalMuonCand > &candMuons) override
 
 XMLEventWriter (const OMTFConfiguration *aOMTFConfig, std::string fName)
 
 ~XMLEventWriter () override
 
- Public Member Functions inherited from IOMTFEmulationObserver
virtual void beginRun (edm::EventSetup const &eventSetup)
 
 IOMTFEmulationObserver ()
 
virtual ~IOMTFEmulationObserver ()
 

Private Attributes

unsigned int eventId = 0
 
unsigned int eventNum = 0
 
boost::property_tree::ptree * eventTree = nullptr
 
std::string fName
 
const OMTFConfigurationomtfConfig
 
boost::property_tree::ptree procTree
 
boost::property_tree::ptree tree
 

Detailed Description

Definition at line 22 of file XMLEventWriter.h.

Constructor & Destructor Documentation

◆ XMLEventWriter()

XMLEventWriter::XMLEventWriter ( const OMTFConfiguration aOMTFConfig,
std::string  fName 
)

Definition at line 21 of file XMLEventWriter.cc.

References eventNum, OMTFConfiguration::patternsVersion(), and BeamSplash_cfg::version.

22  : omtfConfig(aOMTFConfig), fName(fName) {
23  //std::string fName = "OMTF";
24  eventNum = 0;
25 
26  unsigned int version = aOMTFConfig->patternsVersion();
27  const unsigned int mask16bits = 0xFFFF;
28 
29  version &= mask16bits;
30 
31  std::ostringstream stringStr;
32  stringStr.str("");
33  stringStr << "0x" << std::hex << std::setfill('0') << std::setw(4) << version;
34 
35  tree.put("OMTF.<xmlattr>.version", stringStr.str());
36 };
unsigned int eventNum
unsigned int patternsVersion() const
std::string fName
Definition: tree.py:1
const OMTFConfiguration * omtfConfig

◆ ~XMLEventWriter()

XMLEventWriter::~XMLEventWriter ( )
override

Definition at line 38 of file XMLEventWriter.cc.

38 {}

Member Function Documentation

◆ addProcesorData()

void XMLEventWriter::addProcesorData ( std::string  key,
boost::property_tree::ptree &  procDataTree 
)
inlineoverridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 30 of file XMLEventWriter.h.

References submitPVResolutionJobs::key, and procTree.

30  {
31  procTree.add_child(key, procDataTree);
32  }
key
prepare the HTCondor submission files and eventually submit them
boost::property_tree::ptree procTree

◆ endJob()

void XMLEventWriter::endJob ( void  )
overridevirtual

Implements IOMTFEmulationObserver.

Definition at line 212 of file XMLEventWriter.cc.

References fName, and MCScenario_CRAFT1_22X::write_xml().

212  {
213  edm::LogInfo("l1tOmtfEventPrint") << "XMLEventWriter::endJob() - writing the data to the xml - starting";
215  fName, tree, std::locale(), boost::property_tree::xml_parser::xml_writer_make_settings<std::string>(' ', 2));
216  edm::LogInfo("l1tOmtfEventPrint") << "XMLEventWriter::endJob() - writing the data to the xml - done";
217 }
def write_xml(scenario, fileName)
Log< level::Info, false > LogInfo
std::string fName
Definition: tree.py:1

◆ observeEventBegin()

void XMLEventWriter::observeEventBegin ( const edm::Event iEvent)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 198 of file XMLEventWriter.cc.

References eventId, eventNum, eventTree, and iEvent.

198  {
199  eventNum++;
200  eventId = iEvent.id().event();
201 
202  eventTree = &(tree.add("OMTF.Event", ""));
203  eventTree->add("<xmlattr>.iEvent", eventId);
204 
205  eventTree = &(eventTree->add("bx", ""));
206  eventTree->add("<xmlattr>.iBx", 2 * eventId);
207 }
int iEvent
Definition: GenABIO.cc:224
unsigned int eventNum
unsigned int eventId
boost::property_tree::ptree * eventTree
Definition: tree.py:1

◆ observeEventEnd()

void XMLEventWriter::observeEventEnd ( const edm::Event iEvent,
std::unique_ptr< l1t::RegionalMuonCandBxCollection > &  finalCandidates 
)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 209 of file XMLEventWriter.cc.

210  {}

◆ observeProcesorBegin()

void XMLEventWriter::observeProcesorBegin ( unsigned int  iProcessor,
l1t::tftype  mtfType 
)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 40 of file XMLEventWriter.cc.

References makeMuonMisalignmentScenario::endcap, OmtfName::name(), l1t::omtf_neg, l1t::omtf_pos, omtfConfig, OmtfName::position(), and procTree.

40  {
41  procTree.clear();
42 
43  int endcap = (mtfType == l1t::omtf_neg) ? -1 : ((mtfType == l1t::omtf_pos) ? +1 : 0);
44  OmtfName board(iProcessor, endcap, omtfConfig);
45  procTree.add("<xmlattr>.board", board.name());
46  procTree.add("<xmlattr>.iProcessor", iProcessor);
47 
48  std::ostringstream stringStr;
49  stringStr << (board.position() == 1 ? "+" : "") << board.position();
50  procTree.add("<xmlattr>.position", stringStr.str());
51 }
boost::property_tree::ptree procTree
const OMTFConfiguration * omtfConfig

◆ observeProcesorEmulation()

void XMLEventWriter::observeProcesorEmulation ( unsigned int  iProcessor,
l1t::tftype  mtfType,
const std::shared_ptr< OMTFinput > &  input,
const AlgoMuons algoCandidates,
const AlgoMuons gbCandidates,
const std::vector< l1t::RegionalMuonCand > &  candMuons 
)
overridevirtual

Dump only regions, where a candidate was found

Implements IOMTFEmulationObserver.

Definition at line 53 of file XMLEventWriter.cc.

References makeMuonMisalignmentScenario::endcap, eventTree, input, OMTFConfiguration::nLayers(), OMTFConfiguration::nPhiBins(), l1t::omtf_neg, l1t::omtf_pos, omtfConfig, and procTree.

58  {
59  int endcap = (mtfType == l1t::omtf_neg) ? -1 : ((mtfType == l1t::omtf_pos) ? +1 : 0);
60  OmtfName board(iProcessor, endcap, omtfConfig);
61 
62  if (candMuons.empty())
63  return;
64 
65  for (unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) {
66  boost::property_tree::ptree layerTree;
67 
68  for (unsigned int iHit = 0; iHit < input->getMuonStubs()[iLayer].size(); ++iHit) {
69  int hitPhi = input->getPhiHw(iLayer, iHit);
70  if (hitPhi >= (int)omtfConfig->nPhiBins())
71  continue;
72 
73  auto& hitTree = layerTree.add("Hit", "");
74 
75  hitTree.add("<xmlattr>.iInput", iHit);
76  hitTree.add("<xmlattr>.iEta", input->getHitEta(iLayer, iHit));
77  hitTree.add("<xmlattr>.iPhi", hitPhi);
78 
79  //in the firmware the hit quality is taken from link data only for the DT stubs
80  //for the CSC and RPC 1 means the hit is valid, 0 - not.
81  //in the input it is still worth to have the actual quality of the CSC and RPC
82  //Because it might be used in the neural network
83  if (iLayer >= 6)
84  hitTree.add("<xmlattr>.iQual", 1);
85  else
86  hitTree.add("<xmlattr>.iQual", input->getHitQual(iLayer, iHit));
87  }
88 
89  if (!layerTree.empty()) {
90  layerTree.add("<xmlattr>.iLayer", iLayer);
91  procTree.add_child("Layer", layerTree);
92  }
93  }
94 
95  for (auto& algoCand : algoCandidates) {
97  if (algoCand->isValid()) {
98  auto& algoMuonTree = procTree.add("AlgoMuon", "");
99  algoMuonTree.add("<xmlattr>.charge", algoCand->getChargeConstr());
100  algoMuonTree.add("<xmlattr>.disc", algoCand->getDisc());
101  algoMuonTree.add("<xmlattr>.pdfSumConstr", algoCand->getGpResultConstr().getPdfSum());
102  algoMuonTree.add("<xmlattr>.pdfSumUnconstr", algoCand->getGpResultUnconstr().getPdfSumUnconstr());
103  algoMuonTree.add("<xmlattr>.etaCode", algoCand->getEtaHw());
104  algoMuonTree.add("<xmlattr>.iRefHit", algoCand->getRefHitNumber());
105  algoMuonTree.add("<xmlattr>.iRefLayer", algoCand->getRefLayer());
106 
107  //algoMuonTree.add("<xmlattr>.layers", std::bitset<18>(algoCand->getFiredLayerBits()));
108 
109  algoMuonTree.add("<xmlattr>.layersConstr", std::bitset<18>(algoCand->getGpResultConstr().getFiredLayerBits()));
110  algoMuonTree.add("<xmlattr>.layersUnconstr",
111  std::bitset<18>(algoCand->getGpResultUnconstr().getFiredLayerBits()));
112 
113  algoMuonTree.add("<xmlattr>.nHits", algoCand->getQ());
114 
115  algoMuonTree.add("<xmlattr>.firedCntConstr", algoCand->getGpResultConstr().getFiredLayerCnt());
116  algoMuonTree.add("<xmlattr>.firedCntUnconstr", algoCand->getGpResultUnconstr().getFiredLayerCnt());
117 
118  algoMuonTree.add("<xmlattr>.patNumConstr", algoCand->getHwPatternNumConstr());
119  algoMuonTree.add("<xmlattr>.patNumUnconstr", algoCand->getHwPatternNumUnconstr());
120 
121  algoMuonTree.add("<xmlattr>.phiCode", algoCand->getPhi());
122 
123  algoMuonTree.add("<xmlattr>.phiConstr", algoCand->getGpResultConstr().getPhi());
124  algoMuonTree.add("<xmlattr>.phiUnConstr", algoCand->getGpResultUnconstr().getPhi());
125 
126  algoMuonTree.add("<xmlattr>.phiRHit", algoCand->getPhiRHit());
127 
128  //in the firmware, the algoMuon has no pt nor upt yet,
129  //only the pattern number, which is converted to the hwpt in the ghostbuster
130  algoMuonTree.add("<xmlattr>.ptCodeConstr", algoCand->getPtConstr());
131  algoMuonTree.add("<xmlattr>.ptCodeUnconstr", algoCand->getPtUnconstr());
132 
133  auto& gpResultTree = algoMuonTree.add("gpResultConstr", "");
134  auto& gpResultConstr = algoCand->getGpResultConstr();
135 
136  gpResultTree.add("<xmlattr>.patNum", algoCand->getHwPatternNumConstr());
137  gpResultTree.add("<xmlattr>.pdfSum", gpResultConstr.getPdfSum());
138 
139  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResultConstr.getStubResults().size(); ++iLogicLayer) {
140  auto& layerTree = gpResultTree.add("layer", "");
141  layerTree.add("<xmlattr>.num", iLogicLayer);
142  auto pdfBin = gpResultConstr.getStubResults()[iLogicLayer].getPdfBin();
143  if (pdfBin == 5400)
144  pdfBin = 0;
145  layerTree.add("<xmlattr>.pdfBin", pdfBin);
146  layerTree.add("<xmlattr>.pdfVal", gpResultConstr.getStubResults()[iLogicLayer].getPdfVal());
147  layerTree.add("<xmlattr>.fired", gpResultConstr.isLayerFired(iLogicLayer));
148  }
149 
150  if (algoCand->getGpResultUnconstr().isValid()) {
151  auto& gpResultTree = algoMuonTree.add("gpResultUnconstr", "");
152  auto& gpResult = algoCand->getGpResultUnconstr();
153 
154  gpResultTree.add("<xmlattr>.patNum", algoCand->getHwPatternNumUnconstr());
155  gpResultTree.add("<xmlattr>.pdfSum", gpResult.getPdfSumUnconstr());
156 
157  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
158  auto& layerTree = gpResultTree.add("layer", "");
159  layerTree.add("<xmlattr>.num", iLogicLayer);
160  auto pdfBin = gpResult.getStubResults()[iLogicLayer].getPdfBin();
161  if (pdfBin == 5400)
162  pdfBin = 0;
163  layerTree.add("<xmlattr>.pdfBin", pdfBin);
164  layerTree.add("<xmlattr>.pdfVal", gpResult.getStubResults()[iLogicLayer].getPdfVal());
165  layerTree.add("<xmlattr>.fired", gpResult.isLayerFired(iLogicLayer));
166  }
167  }
168  }
169  }
170 
171  for (auto& candMuon : candMuons) {
172  auto& candMuonTree = procTree.add("CandMuon", "");
173  candMuonTree.add("<xmlattr>.hwEta", candMuon.hwEta());
174  candMuonTree.add("<xmlattr>.hwPhi", candMuon.hwPhi());
175  candMuonTree.add("<xmlattr>.hwPt", candMuon.hwPt());
176  candMuonTree.add("<xmlattr>.hwUPt", candMuon.hwPtUnconstrained());
177  candMuonTree.add("<xmlattr>.hwQual", candMuon.hwQual());
178  candMuonTree.add("<xmlattr>.hwSign", candMuon.hwSign());
179  candMuonTree.add("<xmlattr>.hwSignValid", candMuon.hwSignValid());
180  candMuonTree.add("<xmlattr>.hwTrackAddress", std::bitset<29>(candMuon.trackAddress().at(0)));
181  candMuonTree.add("<xmlattr>.link", candMuon.link());
182  candMuonTree.add("<xmlattr>.processor", candMuon.processor());
183 
184  std::ostringstream stringStr;
185  if (candMuon.trackFinderType() == l1t::omtf_neg)
186  stringStr << "OMTF_NEG";
187  else if (candMuon.trackFinderType() == l1t::omtf_pos)
188  stringStr << "OMTF_POS";
189  else
190  stringStr << candMuon.trackFinderType();
191  candMuonTree.add("<xmlattr>.trackFinderType", stringStr.str());
192  }
193 
194  if (!procTree.empty())
195  eventTree->add_child("Processor", procTree);
196 }
static std::string const input
Definition: EdmProvDump.cc:50
unsigned int nPhiBins() const
unsigned int nLayers() const
boost::property_tree::ptree * eventTree
boost::property_tree::ptree procTree
const OMTFConfiguration * omtfConfig

Member Data Documentation

◆ eventId

unsigned int XMLEventWriter::eventId = 0
private

Definition at line 61 of file XMLEventWriter.h.

Referenced by ntupleDataFormat.Event::eventIdStr(), and observeEventBegin().

◆ eventNum

unsigned int XMLEventWriter::eventNum = 0
private

Definition at line 59 of file XMLEventWriter.h.

Referenced by observeEventBegin(), and XMLEventWriter().

◆ eventTree

boost::property_tree::ptree* XMLEventWriter::eventTree = nullptr
private

Definition at line 53 of file XMLEventWriter.h.

Referenced by observeEventBegin(), and observeProcesorEmulation().

◆ fName

std::string XMLEventWriter::fName
private

Definition at line 57 of file XMLEventWriter.h.

Referenced by endJob().

◆ omtfConfig

const OMTFConfiguration* XMLEventWriter::omtfConfig
private

Definition at line 49 of file XMLEventWriter.h.

Referenced by observeProcesorBegin(), and observeProcesorEmulation().

◆ procTree

boost::property_tree::ptree XMLEventWriter::procTree
private

◆ tree

boost::property_tree::ptree XMLEventWriter::tree
private