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 
20  const OMTFConfiguration* omtfConfig,
22  : EmulationObserverBase(edmCfg, omtfConfig) {
23  edm::LogVerbatim("l1tOmtfEventPrint") << " omtfConfig->nTestRefHits() " << omtfConfig->nTestRefHits()
24  << " event.omtfGpResultsPdfSum.num_elements() " << endl;
26 
27  edm::LogVerbatim("l1tOmtfEventPrint") << " DataROOTDumper2 created" << std::endl;
28 }
29 
31 
33  rootFile = new TFile(rootFileName.c_str(), "RECREATE");
34  rootTree = new TTree("OMTFHitsTree", "");
35 
36  rootTree->Branch("muonPt", &omtfEvent.muonPt);
37  rootTree->Branch("muonEta", &omtfEvent.muonEta);
38  rootTree->Branch("muonPhi", &omtfEvent.muonPhi);
39  rootTree->Branch("muonCharge", &omtfEvent.muonCharge);
40 
41  rootTree->Branch("omtfPt", &omtfEvent.omtfPt);
42  rootTree->Branch("omtfEta", &omtfEvent.omtfEta);
43  rootTree->Branch("omtfPhi", &omtfEvent.omtfPhi);
44  rootTree->Branch("omtfCharge", &omtfEvent.omtfCharge);
45 
46  rootTree->Branch("omtfScore", &omtfEvent.omtfScore);
47  rootTree->Branch("omtfQuality", &omtfEvent.omtfQuality);
48  rootTree->Branch("omtfRefLayer", &omtfEvent.omtfRefLayer);
49  rootTree->Branch("omtfProcessor", &omtfEvent.omtfProcessor);
50 
51  rootTree->Branch("omtfFiredLayers", &omtfEvent.omtfFiredLayers); //<<<<<<<<<<<<<<<<<<<<<<!!!!TODOO
52 
53  ptGenPos = new TH1I("ptGenPos", "ptGenPos", 400, 0, 200);
54  ptGenNeg = new TH1I("ptGenNeg", "ptGenNeg", 400, 0, 200);
55 }
56 
58  rootFile->Write();
59  ptGenPos->Write();
60  ptGenNeg->Write();
61 
62  delete rootFile;
63  delete rootTree;
64 }
65 
67  std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
68  int muonCharge = 0;
69  if (simMuon) {
70  if (abs(simMuon->momentum().eta()) < 0.8 || abs(simMuon->momentum().eta()) > 1.24)
71  return;
72 
73  muonCharge = (abs(simMuon->type()) == 13) ? simMuon->type() / -13 : 0;
74  if (muonCharge > 0)
75  ptGenPos->Fill(simMuon->momentum().pt());
76  else
77  ptGenNeg->Fill(simMuon->momentum().pt());
78  }
79 
80  if (simMuon == nullptr || !omtfCand->isValid()) //no sim muon or empty candidate
81  return;
82 
83  omtfEvent.muonPt = simMuon->momentum().pt();
84  omtfEvent.muonEta = simMuon->momentum().eta();
85 
86  //TODO add cut on ete if needed
87  /* if(abs(event.muonEta) < 0.8 || abs(event.muonEta) > 1.24)
88  return;*/
89 
90  omtfEvent.muonPhi = simMuon->momentum().phi();
91  omtfEvent.muonCharge = muonCharge; //TODO
92 
93  if (omtfCand->getPt() > 0) { //&& omtfCand->getFiredLayerCnt() > 3 TODO add to the if needed
96  omtfEvent.omtfPhi = omtfCand->getPhi();
98  omtfEvent.omtfScore = omtfCand->getPdfSum();
99  omtfEvent.omtfQuality = regionalMuonCand.hwQual(); //omtfCand->getQ();
100  omtfEvent.omtfFiredLayers = omtfCand->getFiredLayerBits();
101  omtfEvent.omtfRefLayer = omtfCand->getRefLayer();
103 
104  omtfEvent.hits.clear();
105 
106  auto& gpResult = omtfCand->getGpResult();
107 
108  /*
109  edm::LogVerbatim("l1tOmtfEventPrint")<<"DataROOTDumper2:;observeEventEnd muonPt "<<event.muonPt<<" muonCharge "<<event.muonCharge
110  <<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer<<" omtfPtCont "<<event.omtfPtCont
111  <<std::endl;
112 */
113 
114  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
115  auto& stubResult = gpResult.getStubResults()[iLogicLayer];
116  if (stubResult.getMuonStub()) { //&& stubResult.getValid() //TODO!!!!!!!!!!!!!!!!1
118  hit.layer = iLogicLayer;
119  hit.quality = stubResult.getMuonStub()->qualityHw;
120  hit.eta = stubResult.getMuonStub()->etaHw; //in which scale?
121  hit.valid = stubResult.getValid();
122 
123  int hitPhi = stubResult.getMuonStub()->phiHw;
124  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[omtfCand->getRefLayer()];
125  int phiRefHit = gpResult.getStubResults()[refLayerLogicNum].getMuonStub()->phiHw;
126 
127  if (omtfConfig->isBendingLayer(iLogicLayer)) {
128  hitPhi = stubResult.getMuonStub()->phiBHw;
129  phiRefHit = 0; //phi ref hit for the bending layer set to 0, since it should not be included in the phiDist
130  }
131 
132  //phiDist = hitPhi - phiRefHit;
133  hit.phiDist = hitPhi - phiRefHit;
134 
135  /* LogTrace("l1tOmtfEventPrint")<<" muonPt "<<event.muonPt<<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer
136  <<" layer "<<int(hit.layer)<<" PdfBin "<<stubResult.getPdfBin()<<" hit.phiDist "<<hit.phiDist<<" valid "<<stubResult.getValid()<<" " //<<" phiDist "<<phiDist
137  <<" getDistPhiBitShift "<<omtfCand->getGoldenPatern()->getDistPhiBitShift(iLogicLayer, omtfCand->getRefLayer())
138  <<" meanDistPhiValue "<<omtfCand->getGoldenPatern()->meanDistPhiValue(iLogicLayer, omtfCand->getRefLayer())//<<(phiDist != hit.phiDist? "!!!!!!!<<<<<" : "")
139  <<endl;*/
140 
141  if (hit.phiDist > 504 || hit.phiDist < -512) {
142  edm::LogVerbatim("l1tOmtfEventPrint")
143  << " muonPt " << omtfEvent.muonPt << " omtfPt " << omtfEvent.omtfPt << " RefLayer "
144  << omtfEvent.omtfRefLayer << " layer " << int(hit.layer) << " hit.phiDist " << hit.phiDist << " valid "
145  << stubResult.getValid() << " !!!!!!!!!!!!!!!!!!!!!!!!" << endl;
146  }
147 
148  DetId detId(stubResult.getMuonStub()->detId);
149  if (detId.subdetId() == MuonSubdetId::CSC) {
150  CSCDetId cscId(detId);
151  hit.z = cscId.chamber() % 2;
152  }
153 
154  omtfEvent.hits.push_back(hit.rawData);
155  }
156  }
157 
158  //debug
159  /*if( (int)event.hits.size() != omtfCand->getQ()) {
160  LogTrace("l1tOmtfEventPrint")<<" muonPt "<<event.muonPt<<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer
161  <<" hits.size "<<event.hits.size()<<" omtfCand->getQ "<<omtfCand->getQ()<<" !!!!!!!!!!!!!!!!!!aaa!!!!!!"<<endl;
162  }*/
163 
164  rootTree->Fill();
165  evntCnt++;
166  }
167 }
168 
169 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