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