CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ------------
EventNumber_t event() const
Definition: EventID.h:40
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
unsigned long long EventNumber_t
RPCPhiEff(const edm::ParameterSet &)
Definition: RPCPhiEff.cc:56
edm::EDGetTokenT< edm::SimTrackContainer > m_g4Token
Definition: RPCPhiEff.h:60
~RPCPhiEff() override
Definition: RPCPhiEff.cc:65
constexpr std::array< uint8_t, layerIndexSize > layer
const uint16_t range(const Frame &aFrame)
std::string fromRaw(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:215
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:273
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: RPCPhiEff.cc:75
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
edm::EventID id() const
Definition: EventBase.h:59
edm::EDGetTokenT< std::vector< L1MuRegionalCand > > m_rpcbToken
Definition: RPCPhiEff.h:58
tuple cout
Definition: gather_cfg.py:144
static int towerNumFromEta(const double eta)
Definition: RPCConst.cc:60
unsigned int RunNumber_t
std::string fromCones(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:212
void endJob() override
Definition: RPCPhiEff.cc:276
std::vector< SimTrack > SimTrackContainer
std::ofstream m_outfileR
Definition: RPCPhiEff.h:52
RPCConst m_const
Definition: RPCPhiEff.h:63