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