CMS 3D CMS Logo

EventCapture.cc
Go to the documentation of this file.
1 /*
2  * EventCapture.cpp
3  *
4  * Created on: Oct 23, 2019
5  * Author: kbunkow
6  */
7 
11 
16 
18 
19 #include <memory>
20 #include <sstream>
21 
23  const OMTFConfiguration* omtfConfig,
24  CandidateSimMuonMatcher* candidateSimMuonMatcher,
25  const MuonGeometryTokens& muonGeometryTokens,
27  : omtfConfig(omtfConfig),
28  goldenPatterns(gps),
29  candidateSimMuonMatcher(candidateSimMuonMatcher),
30  inputInProcs(omtfConfig->processorCnt()),
31  algoMuonsInProcs(omtfConfig->processorCnt()),
32  gbCandidatesInProcs(omtfConfig->processorCnt()) {
33  //LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" omtfConfig->nProcessors() "<<omtfConfig->nProcessors()<<std::endl;
34  if (edmCfg.exists("simTracksTag"))
35  simTracksTag = edmCfg.getParameter<edm::InputTag>("simTracksTag");
36  else
37  edm::LogImportant("OMTFReconstruction")
38  << "EventCapture::EventCapture: no InputTag simTracksTag found" << std::endl;
39 
40  if (this->candidateSimMuonMatcher)
41  stubsSimHitsMatcher = std::make_unique<StubsSimHitsMatcher>(edmCfg, omtfConfig, muonGeometryTokens);
42 }
43 
45  // TODO Auto-generated destructor stub
46 }
47 
51 }
52 
54  simMuons.clear();
55 
56  if (!simTracksTag.label().empty()) {
58  event.getByLabel(simTracksTag, simTraksHandle);
59 
60  for (unsigned int iSimTrack = 0; iSimTrack != simTraksHandle->size(); iSimTrack++) {
61  if (abs((*simTraksHandle.product())[iSimTrack].type()) == 13)
62  simMuons.emplace_back(simTraksHandle, iSimTrack);
63  }
64  }
65 
66  for (auto& input : inputInProcs)
67  input.reset();
68 
69  for (auto& algoMuonsInProc : algoMuonsInProcs)
70  algoMuonsInProc.clear();
71 
72  for (auto& gbCandidatesInProc : gbCandidatesInProcs)
73  gbCandidatesInProc.clear();
74 }
75 
76 void EventCapture::observeProcesorEmulation(unsigned int iProcessor,
77  l1t::tftype mtfType,
78  const std::shared_ptr<OMTFinput>& input,
79  const AlgoMuons& algoCandidates,
80  const AlgoMuons& gbCandidates,
81  const std::vector<l1t::RegionalMuonCand>& candMuons) {
82  unsigned int procIndx = omtfConfig->getProcIndx(iProcessor, mtfType);
83 
84  inputInProcs[procIndx] = input;
85 
86  algoMuonsInProcs[procIndx] = algoCandidates;
87  gbCandidatesInProcs[procIndx] = gbCandidates;
88 }
89 
91  std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
92  std::ostringstream ostr;
93  //filtering
94 
95  bool dump = false;
96 
98  std::vector<MatchingResult> matchingResults = candidateSimMuonMatcher->getMatchingResults();
99  edm::LogVerbatim("l1tOmtfEventPrint") << "matchingResults.size() " << matchingResults.size() << std::endl;
100 
101  //candidateSimMuonMatcher should use the trackingParticles, because the simTracks are not stored for the pile-up events
102  for (auto& matchingResult : matchingResults) {
103  //TODO choose a condition, to print the desired candidates
104  if (matchingResult.muonCand && matchingResult.muonCand->hwQual() >= 12 &&
105  matchingResult.muonCand->hwPt() > 38) { //&& matchingResult.genPt < 20
106  dump = true;
107 
108  bool runStubsSimHitsMatcher = false;
109  if (matchingResult.trackingParticle) {
110  auto trackingParticle = matchingResult.trackingParticle;
111  ostr << "trackingParticle: eventId " << trackingParticle->eventId().event() << " pdgId " << std::setw(3)
112  << trackingParticle->pdgId() << " trackId " << trackingParticle->g4Tracks().at(0).trackId() << " pt "
113  << std::setw(9) << trackingParticle->pt() //<<" Beta "<<simMuon->momentum().Beta()
114  << " eta " << std::setw(9) << trackingParticle->momentum().eta() << " phi " << std::setw(9)
115  << trackingParticle->momentum().phi() << std::endl;
116  } else {
117  ostr << "no simMuon ";
118  runStubsSimHitsMatcher = true;
119  }
120  ostr << "matched to: " << std::endl;
121  auto finalCandidate = matchingResult.muonCand;
122  ostr << " hwPt " << finalCandidate->hwPt() << " hwSign " << finalCandidate->hwSign() << " hwQual "
123  << finalCandidate->hwQual() << " hwEta " << std::setw(4) << finalCandidate->hwEta() << std::setw(4)
124  << " hwPhi " << finalCandidate->hwPhi() << " eta " << std::setw(9)
125  << (finalCandidate->hwEta() * 0.010875) << " phi " << std::endl;
126 
127  if (runStubsSimHitsMatcher)
128  stubsSimHitsMatcher->match(iEvent, matchingResult.muonCand, matchingResult.procMuon, ostr);
129  }
130  }
131  } else if (!simTracksTag.label().empty()) {
132  dump = false;
133  bool wasSimMuInOmtfPos = false;
134  bool wasSimMuInOmtfNeg = false;
135  for (auto& simMuon : simMuons) {
136  //TODO choose a condition, to print the desired events
137  if (simMuon->eventId().event() == 0 && abs(simMuon->momentum().eta()) > 0.82 &&
138  abs(simMuon->momentum().eta()) < 1.24 && simMuon->momentum().pt() >= 3.) {
139  ostr << "SimMuon: eventId " << simMuon->eventId().event() << " pdgId " << std::setw(3) << simMuon->type()
140  << " pt " << std::setw(9) << simMuon->momentum().pt() //<<" Beta "<<simMuon->momentum().Beta()
141  << " eta " << std::setw(9) << simMuon->momentum().eta() << " phi " << std::setw(9)
142  << simMuon->momentum().phi() << std::endl;
143 
144  if (simMuon->momentum().eta() > 0)
145  wasSimMuInOmtfPos = true;
146  else
147  wasSimMuInOmtfNeg = true;
148  }
149  }
150 
151  bool wasCandInNeg = false;
152  bool wasCandInPos = false;
153 
154  for (auto& finalCandidate : *finalCandidates) {
155  //TODO choose a condition, to print the desired candidates
156  if (finalCandidate.trackFinderType() == l1t::tftype::omtf_neg && finalCandidate.hwQual() >= 12 &&
157  finalCandidate.hwPt() > 20)
158  wasCandInNeg = true;
159 
160  if (finalCandidate.trackFinderType() == l1t::tftype::omtf_pos && finalCandidate.hwQual() >= 12 &&
161  finalCandidate.hwPt() > 20)
162  wasCandInPos = true;
163  }
164 
165  if ((wasSimMuInOmtfNeg && wasCandInNeg)) //TODO
166  dump = true;
167 
168  if ((wasSimMuInOmtfPos && wasCandInPos)) //TODO
169  dump = true;
170  } else {
171  //TODO choose a condition, to print the desired candidates
172  // an example of a simple cut, only on the canidate pt
173  /*
174  for (auto& finalCandidate : *finalCandidates) {
175  if (finalCandidate.hwPt() < 41) { // finalCandidate.hwQual() >= 1 41
176  dump = true;
177  }
178  } */
180  dump = true; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
181  }
182 
183  if (!dump)
184  return;
185 
187 
188  edm::LogVerbatim("l1tOmtfEventPrint") << "##################### EventCapture::observeEventEnd - dump of event "
189  << iEvent.id() << " #####################################################"
190  << std::endl;
191 
192  edm::LogVerbatim("l1tOmtfEventPrint") << ostr.str() << endl; //printing sim muons
193 
194  edm::LogVerbatim("l1tOmtfEventPrint") << "finalCandidates " << std::endl;
195  for (int bx = finalCandidates->getFirstBX(); bx <= finalCandidates->getLastBX(); bx++) {
196  for (auto finalCandidateIt = finalCandidates->begin(bx); finalCandidateIt != finalCandidates->end(bx);
197  finalCandidateIt++) {
198  auto& finalCandidate = *finalCandidateIt;
199  int globHwPhi = (finalCandidate.processor()) * 96 + finalCandidate.hwPhi();
200  // first processor starts at CMS phi = 15 degrees (24 in int)... Handle wrap-around with %. Add 576 to make sure the number is positive
201  globHwPhi = (globHwPhi + 600) % 576;
202 
203  double globalPhi = globHwPhi * 2. * M_PI / 576;
204  if (globalPhi > M_PI)
205  globalPhi = globalPhi - (2. * M_PI);
206 
207  int layerHits = (int)finalCandidate.trackAddress().at(0);
208  std::bitset<18> layerHitBits(layerHits);
209 
210  edm::LogVerbatim("l1tOmtfEventPrint")
211  << " bx " << bx << " hwPt " << finalCandidate.hwPt() << " hwSign " << finalCandidate.hwSign() << " hwQual "
212  << finalCandidate.hwQual() << " hwEta " << std::setw(4) << finalCandidate.hwEta() << std::setw(4) << " hwPhi "
213  << finalCandidate.hwPhi() << " eta " << std::setw(9) << (finalCandidate.hwEta() * 0.010875) << " phi "
214  << std::setw(9) << globalPhi << " " << layerHitBits << " processor "
215  << OmtfName(finalCandidate.processor(), finalCandidate.trackFinderType()) << std::endl;
216 
217  for (auto& trackAddr : finalCandidate.trackAddress()) {
218  if (trackAddr.first >= 10)
219  edm::LogVerbatim("l1tOmtfEventPrint")
220  << "trackAddr first " << trackAddr.first << " second " << trackAddr.second << " ptGeV "
221  << omtfConfig->hwPtToGev(trackAddr.second);
222  }
223  }
224  }
225  edm::LogVerbatim("l1tOmtfEventPrint") << std::endl;
226 
227  for (unsigned int iProc = 0; iProc < inputInProcs.size(); iProc++) {
228  OmtfName board(iProc);
229 
230  std::ostringstream ostrInput;
231  if (inputInProcs[iProc]) {
232  auto& omtfInput = *inputInProcs[iProc];
233  int layersWithStubs = 0;
234  for (auto& layer : omtfInput.getMuonStubs()) {
235  for (auto& stub : layer) {
236  bool layerFired = false;
237  if (stub && (stub->type != MuonStub::Type::EMPTY)) {
238  layerFired = true;
239 
240  auto globalPhiRad = omtfConfig->procHwPhiToGlobalPhi(
241  stub->phiHw, OMTFinputMaker::getProcessorPhiZero(omtfConfig, iProc % 6));
242  ostrInput << (*stub) << " globalPhiRad " << globalPhiRad << std::endl;
243  }
244  if (layerFired)
245  layersWithStubs++;
246  }
247  }
248 
249  if (layersWithStubs != 0) {
250  edm::LogVerbatim("l1tOmtfEventPrint") << "\niProcessor " << iProc << " " << board.name()
251  << " **************************************************" << std::endl;
252  edm::LogVerbatim("l1tOmtfEventPrint") << ostrInput.str() << std::endl;
253  }
254 
255  if (layersWithStubs < 2)
256  continue;
257 
258  edm::LogVerbatim("l1tOmtfEventPrint") << *inputInProcs[iProc] << std::endl;
259 
260  edm::LogVerbatim("l1tOmtfEventPrint") << "algoMuons " << std::endl;
261  //unsigned int procIndx = omtfConfig->getProcIndx(iProcessor, mtfType);
262  for (auto& algoMuon : algoMuonsInProcs[iProc]) {
263  if (algoMuon->isValid()) {
264  edm::LogVerbatim("l1tOmtfEventPrint")
265  << board.name() << " " << *algoMuon << " RefHitNum " << algoMuon->getRefHitNumber() << std::endl;
266  edm::LogVerbatim("l1tOmtfEventPrint") << algoMuon->getGpResult() << std::endl;
267 
268  if (goldenPatterns) //watch out with the golden patterns
269  for (auto& gp : *goldenPatterns) {
270  if (gp->key().thePt == 0)
271  continue;
272 
273  //printing GoldenPatternResult, uncomment if needed
274  /*auto& gpResult = gp->getResults()[iProc][algoMuon->getRefHitNumber()];
275  edm::LogVerbatim("l1tOmtfEventPrint") << " "<<gp->key() << " "
276  //<< " refLayer: " << gpResult.getRefLayer() << "\t"
277  << " Sum over layers: " << gpResult.getPdfSum() << "\t"
278  << " Number of hits: " << gpResult.getFiredLayerCnt() << "\t"
279  << std::endl;*/
280  }
281  edm::LogVerbatim("l1tOmtfEventPrint") << std::endl << std::endl;
282  }
283  }
284 
285  edm::LogVerbatim("l1tOmtfEventPrint") << "gbCandidates " << std::endl;
286  for (auto& gbCandidate : gbCandidatesInProcs[iProc])
287  if (gbCandidate->isValid())
288  edm::LogVerbatim("l1tOmtfEventPrint") << board.name() << " " << *gbCandidate << std::endl;
289 
290  edm::LogVerbatim("l1tOmtfEventPrint") << std::endl;
291  }
292  }
293 
294  edm::LogVerbatim("l1tOmtfEventPrint") << std::endl;
295 }
296 
299  stubsSimHitsMatcher->endJob();
300 }
Log< level::Info, true > LogVerbatim
CandidateSimMuonMatcher * candidateSimMuonMatcher
Definition: EventCapture.h:52
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< AlgoMuons > gbCandidatesInProcs
Definition: EventCapture.h:58
void observeEventBegin(const edm::Event &event) override
Definition: EventCapture.cc:53
void observeProcesorEmulation(unsigned int iProcessor, l1t::tftype mtfType, const std::shared_ptr< OMTFinput > &, const AlgoMuons &algoCandidates, const AlgoMuons &gbCandidates, const std::vector< l1t::RegionalMuonCand > &candMuons) override
Definition: EventCapture.cc:76
bool exists(std::string const &parameterName) const
checks if a parameter exists
T const * product() const
Definition: Handle.h:70
const OMTFConfiguration * omtfConfig
Definition: EventCapture.h:48
double procHwPhiToGlobalPhi(int procHwPhi, int procHwPhi0) const
std::string const & label() const
Definition: InputTag.h:36
static std::string const input
Definition: EdmProvDump.cc:50
std::unique_ptr< StubsSimHitsMatcher > stubsSimHitsMatcher
Definition: EventCapture.h:60
edm::InputTag simTracksTag
Definition: EventCapture.h:47
int iEvent
Definition: GenABIO.cc:224
std::vector< edm::Ptr< SimTrack > > simMuons
Definition: EventCapture.h:54
static int getProcessorPhiZero(const OMTFConfiguration *config, unsigned int iProcessor)
void beginRun(edm::EventSetup const &eventSetup) override
Definition: EventCapture.cc:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Error, true > LogImportant
double hwPtToGev(int hwPt) const override
uGMT pt scale conversion
const GoldenPatternVec< GoldenPattern > * goldenPatterns
Definition: EventCapture.h:50
#define M_PI
std::vector< MatchingResult > getMatchingResults()
~EventCapture() override
Definition: EventCapture.cc:44
void observeEventEnd(const edm::Event &event, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
Definition: EventCapture.cc:90
EventCapture(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, CandidateSimMuonMatcher *candidateSimMuonMatcher, const MuonGeometryTokens &muonGeometryTokens, const GoldenPatternVec< GoldenPattern > *gps=nullptr)
Definition: EventCapture.cc:22
std::vector< std::shared_ptr< OMTFinput > > inputInProcs
Definition: EventCapture.h:56
std::vector< std::unique_ptr< GoldenPatternType > > GoldenPatternVec
std::string name() const
Definition: OmtfName.cc:51
std::vector< AlgoMuonPtr > AlgoMuons
Definition: AlgoMuon.h:102
unsigned int getProcIndx(unsigned int iProcessor, l1t::tftype mtfType) const
input phi should be in the hardware scale (nPhiBins units for 2pi), can be in range -nPhiBins ...
void endJob() override
std::vector< AlgoMuons > algoMuonsInProcs
Definition: EventCapture.h:57
Definition: event.py:1