CMS 3D CMS Logo

RPCPhiEff.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RPCPhiEff
4 // Class: RPCPhiEff
5 //
13 //
14 // Original Author: Tomasz Fruboes
15 // Created: Wed Mar 7 08:31:57 CET 2007
16 //
17 //
18 
20 // system include files
21 #include <memory>
22 
23 // user include files
25 
27 
29 
32 
34 
35 #include <iostream>
36 #include <set>
37 #include <fstream>
38 #include <sstream>
39 
41 
43 
44 //
45 // constants, enums and typedefs
46 //
47 
48 //
49 // static data member definitions
50 //
51 
52 //
53 // constructors and destructor
54 //
56  : m_rpcbToken(consumes<std::vector<L1MuRegionalCand> >(ps.getParameter<edm::InputTag>("rpcb"))),
57  m_rpcfToken(consumes<std::vector<L1MuRegionalCand> >(ps.getParameter<edm::InputTag>("rpcf"))),
58  m_g4Token(consumes<edm::SimTrackContainer>(ps.getParameter<edm::InputTag>("g4"))),
59  m_rpcdigiToken(consumes<RPCDigiCollection>(ps.getParameter<edm::InputTag>("rpcdigi"))) {
60  //m_outfileC.open("phieffC.txt");
61  m_outfileR.open("muons.txt");
62 }
63 
65  //m_outfileC.close();
66  m_outfileR.close();
67 }
68 
69 //
70 // member functions
71 //
72 
73 // ------------ method called to for each event ------------
74 void RPCPhiEff::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
77 
78  iEvent.getByToken(m_rpcbToken, rpcBarrel);
79  iEvent.getByToken(m_rpcfToken, rpcForward);
80 
81  std::vector<edm::Handle<std::vector<L1MuRegionalCand> > > handleVec;
82  handleVec.push_back(rpcBarrel);
83  handleVec.push_back(rpcForward);
84 
85  // Fetch MCdata
87  iEvent.getByToken(m_g4Token, simTracks);
88 
89  float etaGen = 0, phiGen = 0, ptGen = 0;
90 
91  int noOfRecMuons = 0;
92  int noOfMatchedRecMuons = 0;
93 
94  bool firstRunForMuonMatchingCnt = true;
95 
96  // ask MC muons to be separated
97  double deltarMin = -1;
98  edm::SimTrackContainer::const_iterator simTrk = simTracks->begin();
99  for (; simTrk != simTracks->end(); ++simTrk) {
100  if (simTrk->type() != -13 && simTrk->type() != 13)
101  continue;
102 
103  edm::SimTrackContainer::const_iterator simTrk2 = simTrk;
104  ++simTrk2;
105  for (; simTrk2 != simTracks->end(); ++simTrk2) {
106  if (simTrk2->type() != -13 && simTrk2->type() != 13)
107  continue;
108  double drCand = reco::deltaR(simTrk2->momentum(), simTrk->momentum());
109  if (drCand < deltarMin || deltarMin < 0)
110  deltarMin = drCand;
111  }
112  }
113 
114  //std::cout << deltarMin << std::endl;
115  if (deltarMin < 0.7 && deltarMin > 0)
116  return;
117 
118  simTrk = simTracks->begin();
119  for (; simTrk != simTracks->end(); simTrk++) {
120  int type = simTrk->type();
121  if (type == 13 || type == -13) {
122  // Get the data
123  const math::XYZTLorentzVectorD momentum = simTrk->momentum();
124  etaGen = momentum.eta();
125  ptGen = momentum.Pt();
126  phiGen = momentum.phi();
127 
128  bool matched = false;
129  int ptCodeRec = 0;
130  int towerRec = 0;
131  int phiRec = 0;
132  //int muonsFound=0;
133  int qual = 0;
134  int ghost = 0; // number of ghost for montecarlo muon
135 
136  // Iter rpc muon cands, perform delta R matching
137  // todo perform matching also using eta...
138  for (std::vector<edm::Handle<std::vector<L1MuRegionalCand> > >::iterator it = handleVec.begin();
139  it != handleVec.end();
140  ++it) {
141  std::vector<L1MuRegionalCand>::const_iterator itRPC;
142  for (itRPC = (*it)->begin(); itRPC != (*it)->end(); itRPC++) {
143  int ptCode = itRPC->pt_packed();
144  if (ptCode != 0) {
145  if (firstRunForMuonMatchingCnt)
146  ++noOfRecMuons;
147  ptCodeRec = ptCode;
148  phiRec = itRPC->phi_packed();
149  qual = itRPC->quality();
150  towerRec = itRPC->eta_packed();
151  if (towerRec > 16) {
152  towerRec = -((~towerRec & 63) + 1);
153  }
154  // match
155  float pi = 3.14159265;
156  //float phiPhys = 2*pi*float(phiRec)/144-pi;
157  float phiScaled = phiGen;
158  if (phiScaled < 0)
159  phiScaled += 2 * pi;
160  int phiHwGen = (phiScaled) / 2 / pi * 144;
161 
162  //std::cout << "phi " << phiGen << " " << phiHwGen << " " << phiRec
163  // << " eta " << etaGen << " " << m_const.towerNumFromEta(etaGen) << " "<< towerRec << std::endl;
164  if ((std::abs(phiHwGen - phiRec) < 10) && (std::abs(m_const.towerNumFromEta(etaGen) - towerRec) < 1)) {
165  if (matched) { // we have matched m.c. earlier, this is ghost
166  ++ghost;
167  }
168  matched = true;
169  ++noOfMatchedRecMuons;
170  m_outfileR << etaGen << " " << phiGen << " " << ptGen << " " << towerRec << " " << phiRec << " "
171  << ptCodeRec << " " << qual << " " << ghost << std::endl;
172  }
173  } // (ptCode != 0)
174  } // muon cands iter ends
175  } // barrell/fwd iter ends
176  firstRunForMuonMatchingCnt = false;
177  if (!matched) {
178  m_outfileR << etaGen << " " << phiGen << " " << ptGen << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " "
179  << 0 << std::endl;
180  }
181  }
182  }
183 
184  edm::EventID id = iEvent.id();
185  edm::EventNumber_t evNum = id.event();
186  edm::RunNumber_t rnNum = id.run();
187 
188  if (noOfMatchedRecMuons != noOfRecMuons) {
189  edm::LogInfo("RPCEffWarn") << " MuonCands " << noOfRecMuons << " matched " << noOfMatchedRecMuons << " in run "
190  << rnNum << " event " << evNum;
191  }
192 
193  /*
194  m_outfileC << etaGen << " " << phiGen << " " << ptGen << " "
195  << phiRec << " " << towerRec << " " << muonsFound << " "
196  << fromCones(iEvent) <<std::endl;*/
197  /*m_outfileR << etaGen << " " << phiGen << " " << ptGen << " "
198  << phiRec << " " << towerRec << " " << muonsFound << " "
199  << fromRaw(iEvent) <<std::endl;*/
200 
201  /*
202  m_outfileR << etaGen << " " << phiGen << " " << ptGen << " "
203  << phiRec << " " << towerRec << " " << muonsFound << " "
204  << std::endl;
205 
206  */
207 }
208 
210 
211 // ------------ Check hw planes fired using rpc digis
213  std::stringstream ss;
214 
215  // Digi data.
217  iEvent.getByToken(m_rpcdigiToken, rpcDigis);
218 
219  std::set<int> hwPlanes;
220 
222  for (detUnitIt = rpcDigis->begin(); detUnitIt != rpcDigis->end(); ++detUnitIt) {
223  const RPCDigiCollection::Range& range = (*detUnitIt).second;
224  bool hasBX0 = false;
225  for (RPCDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
226  if (digiIt->bx() == 0) {
227  hasBX0 = true;
228  break;
229  }
230  }
231 
232  if (!hasBX0)
233  continue;
234 
235  const RPCDetId& id = (*detUnitIt).first;
236  int station = id.station();
237  int layer = id.layer();
238  //int region = id.region();
239 
240  if (station == 3)
241  hwPlanes.insert(5);
242 
243  else if (station == 4)
244  hwPlanes.insert(6);
245 
246  else if (station == 1 && layer == 1)
247  hwPlanes.insert(1);
248 
249  else if (station == 1 && layer == 2)
250  hwPlanes.insert(2);
251 
252  else if (station == 2 && layer == 1)
253  hwPlanes.insert(3);
254 
255  else if (station == 2 && layer == 2)
256  hwPlanes.insert(4);
257 
258  else
259  std::cout << "??????????????" << std::endl;
260  }
261 
262  for (std::set<int>::iterator it = hwPlanes.begin(); it != hwPlanes.end(); ++it) {
263  ss << " " << *it;
264  }
265 
266  return ss.str();
267 }
268 
269 // ------------ method called once each job just before starting event loop ------------
271 
272 // ------------ method called once each job just after ending the event loop ------------
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
unsigned long long EventNumber_t
RPCPhiEff(const edm::ParameterSet &)
Definition: RPCPhiEff.cc:55
edm::EDGetTokenT< edm::SimTrackContainer > m_g4Token
Definition: RPCPhiEff.h:60
~RPCPhiEff() override
Definition: RPCPhiEff.cc:64
std::string fromRaw(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:212
const Double_t pi
edm::EDGetTokenT< std::vector< L1MuRegionalCand > > m_rpcfToken
Definition: RPCPhiEff.h:59
int iEvent
Definition: GenABIO.cc:224
void beginJob() override
Definition: RPCPhiEff.cc:270
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: RPCPhiEff.cc:74
edm::EDGetTokenT< RPCDigiCollection > m_rpcdigiToken
Definition: RPCPhiEff.h:61
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
Log< level::Info, false > LogInfo
std::pair< const_iterator, const_iterator > Range
std::vector< RPCDigi >::const_iterator const_iterator
HLT enums.
edm::EDGetTokenT< std::vector< L1MuRegionalCand > > m_rpcbToken
Definition: RPCPhiEff.h:58
static int towerNumFromEta(const double eta)
Definition: RPCConst.cc:60
unsigned int RunNumber_t
std::string fromCones(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:209
void endJob() override
Definition: RPCPhiEff.cc:273
std::vector< SimTrack > SimTrackContainer
std::ofstream m_outfileR
Definition: RPCPhiEff.h:52
RPCConst m_const
Definition: RPCPhiEff.h:63