CMS 3D CMS Logo

DataROOTDumper2.cc
Go to the documentation of this file.
1 /*
2  * DataROOTDumper2.cc
3  *
4  * Created on: Dec 11, 2019
5  * Author: kbunkow
6  */
7 
9 
15 
16 #include "TFile.h"
17 #include "TTree.h"
18 #include "TParameter.h"
19 #include "TObjString.h"
20 
21 #include <boost/range/adaptor/reversed.hpp>
22 #include <boost/timer/timer.hpp>
23 #include <boost/archive/xml_iarchive.hpp>
24 #include <boost/archive/xml_oarchive.hpp>
25 #include <boost/archive/text_oarchive.hpp>
26 #include <boost/archive/text_iarchive.hpp>
27 
29  const OMTFConfiguration* omtfConfig,
31  : EmulationObserverBase(edmCfg, omtfConfig) {
32  edm::LogVerbatim("l1tOmtfEventPrint") << " omtfConfig->nTestRefHits() " << omtfConfig->nTestRefHits()
33  << " event.omtfGpResultsPdfSum.num_elements() " << endl;
35 
36  edm::LogVerbatim("l1tOmtfEventPrint") << " DataROOTDumper2 created" << std::endl;
37 }
38 
40 
42  rootFile = new TFile(rootFileName.c_str(), "RECREATE");
43  rootTree = new TTree("OMTFHitsTree", "");
44 
45  rootTree->Branch("muonPt", &omtfEvent.muonPt);
46  rootTree->Branch("muonEta", &omtfEvent.muonEta);
47  rootTree->Branch("muonPhi", &omtfEvent.muonPhi);
48  rootTree->Branch("muonCharge", &omtfEvent.muonCharge);
49 
50  rootTree->Branch("omtfPt", &omtfEvent.omtfPt);
51  rootTree->Branch("omtfEta", &omtfEvent.omtfEta);
52  rootTree->Branch("omtfPhi", &omtfEvent.omtfPhi);
53  rootTree->Branch("omtfCharge", &omtfEvent.omtfCharge);
54 
55  rootTree->Branch("omtfScore", &omtfEvent.omtfScore);
56  rootTree->Branch("omtfQuality", &omtfEvent.omtfQuality);
57  rootTree->Branch("omtfRefLayer", &omtfEvent.omtfRefLayer);
58  rootTree->Branch("omtfProcessor", &omtfEvent.omtfProcessor);
59 
60  rootTree->Branch("omtfFiredLayers", &omtfEvent.omtfFiredLayers); //<<<<<<<<<<<<<<<<<<<<<<!!!!TODOO
61 
62  ptGenPos = new TH1I("ptGenPos", "ptGenPos", 400, 0, 200);
63  ptGenNeg = new TH1I("ptGenNeg", "ptGenNeg", 400, 0, 200);
64 }
65 
67  rootFile->Write();
68  ptGenPos->Write();
69  ptGenNeg->Write();
70 
71  delete rootFile;
72  delete rootTree;
73 }
74 
76  std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
77  int muonCharge = 0;
78  if (simMuon) {
79  if (abs(simMuon->momentum().eta()) < 0.8 || abs(simMuon->momentum().eta()) > 1.24)
80  return;
81 
82  muonCharge = (abs(simMuon->type()) == 13) ? simMuon->type() / -13 : 0;
83  if (muonCharge > 0)
84  ptGenPos->Fill(simMuon->momentum().pt());
85  else
86  ptGenNeg->Fill(simMuon->momentum().pt());
87  }
88 
89  if (simMuon == nullptr || !omtfCand->isValid()) //no sim muon or empty candidate
90  return;
91 
92  omtfEvent.muonPt = simMuon->momentum().pt();
93  omtfEvent.muonEta = simMuon->momentum().eta();
94 
95  //TODO add cut on ete if needed
96  /* if(abs(event.muonEta) < 0.8 || abs(event.muonEta) > 1.24)
97  return;*/
98 
99  omtfEvent.muonPhi = simMuon->momentum().phi();
100  omtfEvent.muonCharge = muonCharge; //TODO
101 
102  if (omtfCand->getPt() > 0) { //&& omtfCand->getFiredLayerCnt() > 3 TODO add to the if needed
105  omtfEvent.omtfPhi = omtfCand->getPhi();
107  omtfEvent.omtfScore = omtfCand->getPdfSum();
108  omtfEvent.omtfQuality = regionalMuonCand.hwQual(); //omtfCand->getQ();
109  omtfEvent.omtfFiredLayers = omtfCand->getFiredLayerBits();
110  omtfEvent.omtfRefLayer = omtfCand->getRefLayer();
112 
113  omtfEvent.hits.clear();
114 
115  auto& gpResult = omtfCand->getGpResult();
116 
117  /*
118  edm::LogVerbatim("l1tOmtfEventPrint")<<"DataROOTDumper2:;observeEventEnd muonPt "<<event.muonPt<<" muonCharge "<<event.muonCharge
119  <<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer<<" omtfPtCont "<<event.omtfPtCont
120  <<std::endl;
121 */
122 
123  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
124  auto& stubResult = gpResult.getStubResults()[iLogicLayer];
125  if (stubResult.getMuonStub()) { //&& stubResult.getValid() //TODO!!!!!!!!!!!!!!!!1
127  hit.layer = iLogicLayer;
128  hit.quality = stubResult.getMuonStub()->qualityHw;
129  hit.eta = stubResult.getMuonStub()->etaHw; //in which scale?
130  hit.valid = stubResult.getValid();
131 
132  int hitPhi = stubResult.getMuonStub()->phiHw;
133  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[omtfCand->getRefLayer()];
134  int phiRefHit = gpResult.getStubResults()[refLayerLogicNum].getMuonStub()->phiHw;
135 
136  if (omtfConfig->isBendingLayer(iLogicLayer)) {
137  hitPhi = stubResult.getMuonStub()->phiBHw;
138  phiRefHit = 0; //phi ref hit for the bending layer set to 0, since it should not be included in the phiDist
139  }
140 
141  //phiDist = hitPhi - phiRefHit;
142  hit.phiDist = hitPhi - phiRefHit;
143 
144  /* LogTrace("l1tOmtfEventPrint")<<" muonPt "<<event.muonPt<<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer
145  <<" layer "<<int(hit.layer)<<" PdfBin "<<stubResult.getPdfBin()<<" hit.phiDist "<<hit.phiDist<<" valid "<<stubResult.getValid()<<" " //<<" phiDist "<<phiDist
146  <<" getDistPhiBitShift "<<omtfCand->getGoldenPatern()->getDistPhiBitShift(iLogicLayer, omtfCand->getRefLayer())
147  <<" meanDistPhiValue "<<omtfCand->getGoldenPatern()->meanDistPhiValue(iLogicLayer, omtfCand->getRefLayer())//<<(phiDist != hit.phiDist? "!!!!!!!<<<<<" : "")
148  <<endl;*/
149 
150  if (hit.phiDist > 504 || hit.phiDist < -512) {
151  edm::LogVerbatim("l1tOmtfEventPrint")
152  << " muonPt " << omtfEvent.muonPt << " omtfPt " << omtfEvent.omtfPt << " RefLayer "
153  << omtfEvent.omtfRefLayer << " layer " << int(hit.layer) << " hit.phiDist " << hit.phiDist << " valid "
154  << stubResult.getValid() << " !!!!!!!!!!!!!!!!!!!!!!!!" << endl;
155  }
156 
157  DetId detId(stubResult.getMuonStub()->detId);
158  if (detId.subdetId() == MuonSubdetId::CSC) {
159  CSCDetId cscId(detId);
160  hit.z = cscId.chamber() % 2;
161  }
162 
163  omtfEvent.hits.push_back(hit.rawData);
164  }
165  }
166 
167  //debug
168  /*if( (int)event.hits.size() != omtfCand->getQ()) {
169  LogTrace("l1tOmtfEventPrint")<<" muonPt "<<event.muonPt<<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer
170  <<" hits.size "<<event.hits.size()<<" omtfCand->getQ "<<omtfCand->getQ()<<" !!!!!!!!!!!!!!!!!!aaa!!!!!!"<<endl;
171  }*/
172 
173  rootTree->Fill();
174  evntCnt++;
175  }
176 }
177 
178 void DataROOTDumper2::endJob() { edm::LogVerbatim("l1tOmtfEventPrint") << " evntCnt " << evntCnt << endl; }
Log< level::Info, true > LogVerbatim
void endJob() override
AlgoMuons::value_type omtfCand
double omtfPt
virtual double hwEtaToEta(int hwEta) const
center of eta bin
unsigned int omtfFiredLayers
double muonPt
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
const int hwQual() const
Get quality code.
OmtfEvent omtfEvent
double muonPhi
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
double omtfPhi
unsigned int evntCnt
int iEvent
Definition: GenABIO.cc:224
l1t::RegionalMuonCand regionalMuonCand
double omtfEta
unsigned int omtfQuality
void initializeTTree(std::string rootFileName)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int chamber() const
Definition: CSCDetId.h:62
const std::vector< int > & getRefToLogicNumber() const
double hwPtToGev(int hwPt) const override
uGMT pt scale conversion
const int hwSign() const
Get charge sign bit (charge = (-1)^(sign))
unsigned int nTestRefHits() const
Definition: DetId.h:17
DataROOTDumper2(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, std::string rootFileName)
std::vector< unsigned long > hits
double muonEta
static constexpr int CSC
Definition: MuonSubdetId.h:12
unsigned int omtfRefLayer
const OMTFConfiguration * omtfConfig
void observeEventEnd(const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
~DataROOTDumper2() override
bool isBendingLayer(unsigned int iLayer) const override