CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
19 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
29 
31 
34 
36 
37 #include <iostream>
38 #include <set>
39 #include <fstream>
40 #include <sstream>
41 
43 
45 
46 //
47 // constants, enums and typedefs
48 //
49 
50 //
51 // static data member definitions
52 //
53 
54 //
55 // constructors and destructor
56 //
58  m_rpcbToken( consumes<std::vector<L1MuRegionalCand> > (
59  ps.getParameter< edm::InputTag >("rpcb"))),
60  m_rpcfToken( consumes<std::vector<L1MuRegionalCand> > (
61  ps.getParameter< edm::InputTag >("rpcf"))),
62  m_g4Token( consumes<edm::SimTrackContainer>(
63  ps.getParameter< edm::InputTag >("g4"))),
64  m_rpcdigiToken( consumes<RPCDigiCollection> (
65  ps.getParameter< edm::InputTag >("rpcdigi")))
66 {
67 
68 
69  //m_outfileC.open("phieffC.txt");
70  m_outfileR.open("muons.txt");
71 
72 }
73 
74 
76 {
77 
78  //m_outfileC.close();
79  m_outfileR.close();
80 
81 }
82 
83 
84 //
85 // member functions
86 //
87 
88 // ------------ method called to for each event ------------
89 void
91  const edm::EventSetup & iSetup)
92 {
93 
94 
97 
98  iEvent.getByToken(m_rpcbToken, rpcBarrel);
99  iEvent.getByToken(m_rpcfToken, rpcForward);
100 
101 
102  std::vector< edm::Handle<std::vector<L1MuRegionalCand> > > handleVec;
103  handleVec.push_back( rpcBarrel );
104  handleVec.push_back( rpcForward );
105 
106  // Fetch MCdata
108  iEvent.getByToken(m_g4Token, simTracks);
109 
110  float etaGen = 0, phiGen = 0, ptGen = 0;
111 
112  int noOfMuons = 0;
113  int noOfRecMuons = 0;
114  int noOfMatchedRecMuons = 0;
115 
116  bool firstRunForMuonMatchingCnt = true;
117 
118  // ask MC muons to be separated
119  double deltarMin = -1;
120  edm::SimTrackContainer::const_iterator simTrk = simTracks->begin();
121  for (; simTrk != simTracks->end(); ++simTrk) {
122 
123  if (simTrk->type() != -13 && simTrk->type()!=13) continue;
124 
125  edm::SimTrackContainer::const_iterator simTrk2 = simTrk;
126  ++simTrk2;
127  for (; simTrk2 != simTracks->end(); ++simTrk2) {
128  if (simTrk2->type() != -13 && simTrk2->type()!=13) continue;
129  double drCand = reco::deltaR(simTrk2->momentum(), simTrk->momentum());
130  if (drCand < deltarMin || deltarMin < 0) deltarMin = drCand;
131  }
132 
133 
134  }
135 
136  //std::cout << deltarMin << std::endl;
137  if (deltarMin < 0.7 && deltarMin > 0) return;
138 
139  simTrk = simTracks->begin();
140  for (; simTrk != simTracks->end(); simTrk++) {
141  int type = simTrk->type();
142  if (type == 13 || type == -13) {
143  // Get the data
144  const math::XYZTLorentzVectorD momentum = simTrk->momentum();
145  etaGen = momentum.eta();
146  ptGen = momentum.Pt();
147  phiGen = momentum.phi();
148  noOfMuons++;
149 
150  bool matched = false;
151  int ptCodeRec = 0;
152  int towerRec = 0;
153  int phiRec = 0;
154  //int muonsFound=0;
155  int qual = 0;
156  int ghost = 0; // number of ghost for montecarlo muon
157 
158  // Iter rpc muon cands, perform delta R matching
159  // todo perform matching also using eta...
160  for ( std::vector< edm::Handle<std::vector<L1MuRegionalCand> > >::iterator it = handleVec.begin();
161  it != handleVec.end();
162  ++it )
163  {
164  std::vector<L1MuRegionalCand>::const_iterator itRPC;
165  for (itRPC=(*it)->begin(); itRPC!=(*it)->end(); itRPC++){
166  int ptCode = itRPC->pt_packed();
167  if (ptCode != 0) {
168 
169  if (firstRunForMuonMatchingCnt) ++noOfRecMuons;
170  ptCodeRec=ptCode;
171  phiRec=itRPC->phi_packed();
172  qual = itRPC->quality();
173  towerRec = itRPC->eta_packed();
174  if (towerRec > 16) {
175  towerRec = - ( (~towerRec & 63) + 1);
176  }
177  // match
178  float pi = 3.14159265;
179  //float phiPhys = 2*pi*float(phiRec)/144-pi;
180  float phiScaled = phiGen;
181  if (phiScaled<0) phiScaled += 2*pi;
182  int phiHwGen = (phiScaled)/2/pi*144;
183 
184  //std::cout << "phi " << phiGen << " " << phiHwGen << " " << phiRec
185  // << " eta " << etaGen << " " << m_const.towerNumFromEta(etaGen) << " "<< towerRec << std::endl;
186  if ( ( std::abs(phiHwGen-phiRec) < 10) && (std::abs(m_const.towerNumFromEta(etaGen)-towerRec)<1) )
187  {
188  if (matched) { // we have matched m.c. earlier, this is ghost
189  ++ghost;
190  }
191  matched = true;
192  ++noOfMatchedRecMuons;
193  m_outfileR << etaGen << " " << phiGen << " " << ptGen
194  << " " << towerRec << " " << phiRec << " " << ptCodeRec << " " << qual
195  << " " << ghost
196  << std::endl;
197  }
198  } // (ptCode != 0)
199  } // muon cands iter ends
200  } // barrell/fwd iter ends
201  firstRunForMuonMatchingCnt=false;
202  if (!matched) {
203  m_outfileR << etaGen << " " << phiGen << " " << ptGen
204  << " " << 0 << " " << 0 << " " << 0 << " " << 0
205  << " " << 0
206  << std::endl;
207 
208  }
209 
210 
211  }
212  }
213 
214  edm::EventID id = iEvent.id();
215  edm::EventNumber_t evNum = id.event();
216  edm::RunNumber_t rnNum = id.run();
217 
218  if (noOfMatchedRecMuons!=noOfRecMuons) {
219  edm::LogInfo("RPCEffWarn") << " MuonCands " << noOfRecMuons
220  << " matched " << noOfMatchedRecMuons
221  << " in run " << rnNum
222  << " event " << evNum;
223  }
224 
225 
226 
227  /*
228  m_outfileC << etaGen << " " << phiGen << " " << ptGen << " "
229  << phiRec << " " << towerRec << " " << muonsFound << " "
230  << fromCones(iEvent) <<std::endl;*/
231  /*m_outfileR << etaGen << " " << phiGen << " " << ptGen << " "
232  << phiRec << " " << towerRec << " " << muonsFound << " "
233  << fromRaw(iEvent) <<std::endl;*/
234 
235 
236  /*
237  m_outfileR << etaGen << " " << phiGen << " " << ptGen << " "
238  << phiRec << " " << towerRec << " " << muonsFound << " "
239  << std::endl;
240 
241  */
242 
243 
244 }
245 
247 
248  return "";
249 }
250 /*
251  std::stringstream ss;
252 
253  edm::Handle < RPCDigiCollection > rpcDigis;
254  iEvent.getByLabel("muonRPCDigis", rpcDigis);
255 
256  L1RpcLogConesVec conesVec = m_theLinksystem.getCones(rpcDigis);
257 
258  L1RpcLogConesVec bestCones;
259 
260  // bool wasRef = false;
261  int maxfpCount = 0;
262 
263 
264  for (L1RpcLogConesVec::const_iterator it = conesVec.begin();
265  it != conesVec.end(); ++it) {
266  int currentFpCount = it->getFiredPlanesCnt();
267 
268  if (currentFpCount > maxfpCount) { // the cone pointed by it is better
269  bestCones.clear();
270  bestCones.push_back(*it);
271  maxfpCount = currentFpCount;
272  }
273 
274  } // end of conesVec loop
275 
276 
277  //int planePat = 0;
278  //int one = 1;
279  //int planeCnt = 0;
280 
281  if (bestCones.begin() != bestCones.end()) {
282 
283  L1RpcLogConesVec::const_iterator bc = bestCones.begin();
284  for (int i = 0; i < 6; ++i) {
285 
286  if (bc->getHitsCnt(i)!=0) {
287  //planePat = planePat | (one << i);
288  //planeCnt++;
289  ss << " " << i+1;
290  }
291  }
292  }
293 
294  return ss.str();
295  }
296 */
297 
298 // ------------ Check hw planes fired using rpc digis
300 
301  std::stringstream ss;
302 
303  // Digi data.
305  iEvent.getByToken(m_rpcdigiToken, rpcDigis);
306 
307  std::set<int> hwPlanes;
308 
310  for (detUnitIt=rpcDigis->begin();
311  detUnitIt!=rpcDigis->end();
312  ++detUnitIt)
313  {
314 
315  const RPCDigiCollection::Range& range = (*detUnitIt).second;
316  bool hasBX0 = false;
317  for (RPCDigiCollection::const_iterator digiIt = range.first;
318  digiIt!=range.second;
319  ++digiIt)
320  {
321  if (digiIt->bx() == 0) {
322  hasBX0 = true;
323  break;
324  }
325  }
326 
327  if (!hasBX0) continue;
328 
329  const RPCDetId& id = (*detUnitIt).first;
330  int station = id.station();
331  int layer = id.layer();
332  //int region = id.region();
333 
334  if (station == 3)
335  hwPlanes.insert(5);
336 
337  else if (station == 4)
338  hwPlanes.insert(6);
339 
340  else if (station == 1 && layer == 1)
341  hwPlanes.insert(1);
342 
343  else if (station == 1 && layer == 2)
344  hwPlanes.insert(2);
345 
346  else if (station == 2 && layer == 1)
347  hwPlanes.insert(3);
348 
349  else if (station == 2 && layer == 2)
350  hwPlanes.insert(4);
351 
352  else
353  std::cout << "??????????????" << std::endl;
354 
355  }
356 
357 
358  for (std::set<int>::iterator it= hwPlanes.begin();
359  it!= hwPlanes.end();
360  ++it)
361  {
362  ss << " " << *it;
363  }
364 
365 
366 
367 
368  return ss.str();
369 
370 
371 
372 }
373 
374 // ------------ method called once each job just before starting event loop ------------
376 {
377 }
378 
379 // ------------ method called once each job just after ending the event loop ------------
381 {
382 }
383 
type
Definition: HCALResponse.h:21
virtual void beginJob()
Definition: EDAnalyzer.h:63
EventNumber_t event() const
Definition: EventID.h:44
~RPCPhiEff()
Definition: RPCPhiEff.cc:75
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
unsigned int EventNumber_t
Definition: EventID.h:30
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
RPCPhiEff(const edm::ParameterSet &)
Definition: RPCPhiEff.cc:57
edm::EDGetTokenT< edm::SimTrackContainer > m_g4Token
Definition: RPCPhiEff.h:62
std::string fromRaw(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:299
edm::EDGetTokenT< std::vector< L1MuRegionalCand > > m_rpcfToken
Definition: RPCPhiEff.h:61
int iEvent
Definition: GenABIO.cc:243
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::EDGetTokenT< RPCDigiCollection > m_rpcdigiToken
Definition: RPCPhiEff.h:63
std::vector< RPCDigi >::const_iterator const_iterator
edm::EventID id() const
Definition: EventBase.h:56
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: RPCPhiEff.cc:90
edm::EDGetTokenT< std::vector< L1MuRegionalCand > > m_rpcbToken
Definition: RPCPhiEff.h:60
tuple cout
Definition: gather_cfg.py:121
std::pair< const_iterator, const_iterator > Range
static int towerNumFromEta(const double eta)
Definition: RPCConst.cc:62
unsigned int RunNumber_t
Definition: EventRange.h:32
double pi
std::string fromCones(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:246
virtual void endJob()
Definition: RPCPhiEff.cc:380
std::vector< SimTrack > SimTrackContainer
std::ofstream m_outfileR
Definition: RPCPhiEff.h:53
RPCConst m_const
Definition: RPCPhiEff.h:65