CMS 3D CMS Logo

XMLEventWriter.cc
Go to the documentation of this file.
1 /*
2  * XMLEventWriter.cc
3  *
4  * Created on: Oct 12, 2017
5  * Author: kbunkow
6  */
7 
14 
16 
17 #include <boost/property_tree/xml_parser.hpp>
18 
19 #include <bitset>
20 
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 };
37 
39 
40 void XMLEventWriter::observeProcesorBegin(unsigned int iProcessor, l1t::tftype mtfType) {
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 }
52 
53 void XMLEventWriter::observeProcesorEmulation(unsigned int iProcessor,
54  l1t::tftype mtfType,
55  const std::shared_ptr<OMTFinput>& input,
56  const AlgoMuons& algoCandidates,
57  const AlgoMuons& gbCandidates,
58  const std::vector<l1t::RegionalMuonCand>& candMuons) {
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 }
197 
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 }
208 
210  std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {}
211 
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 }
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
static std::string const input
Definition: EdmProvDump.cc:50
int iEvent
Definition: GenABIO.cc:224
unsigned int nPhiBins() const
unsigned int eventNum
unsigned int patternsVersion() const
unsigned int nLayers() const
def write_xml(scenario, fileName)
Log< level::Info, false > LogInfo
std::string fName
int position() const
Definition: OmtfName.cc:82
std::string name() const
Definition: OmtfName.cc:51
std::vector< AlgoMuonPtr > AlgoMuons
Definition: AlgoMuon.h:176
void endJob() override
unsigned int eventId
boost::property_tree::ptree * eventTree
void observeEventEnd(const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
XMLEventWriter(const OMTFConfiguration *aOMTFConfig, std::string fName)
boost::property_tree::ptree procTree
Definition: tree.py:1
void observeEventBegin(const edm::Event &iEvent) override
~XMLEventWriter() override
const OMTFConfiguration * omtfConfig
void observeProcesorBegin(unsigned int iProcessor, l1t::tftype mtfType) override