test
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 // ------------ Check hw planes fired using rpc digis
253 
254  std::stringstream ss;
255 
256  // Digi data.
258  iEvent.getByToken(m_rpcdigiToken, rpcDigis);
259 
260  std::set<int> hwPlanes;
261 
263  for (detUnitIt=rpcDigis->begin();
264  detUnitIt!=rpcDigis->end();
265  ++detUnitIt)
266  {
267 
268  const RPCDigiCollection::Range& range = (*detUnitIt).second;
269  bool hasBX0 = false;
270  for (RPCDigiCollection::const_iterator digiIt = range.first;
271  digiIt!=range.second;
272  ++digiIt)
273  {
274  if (digiIt->bx() == 0) {
275  hasBX0 = true;
276  break;
277  }
278  }
279 
280  if (!hasBX0) continue;
281 
282  const RPCDetId& id = (*detUnitIt).first;
283  int station = id.station();
284  int layer = id.layer();
285  //int region = id.region();
286 
287  if (station == 3)
288  hwPlanes.insert(5);
289 
290  else if (station == 4)
291  hwPlanes.insert(6);
292 
293  else if (station == 1 && layer == 1)
294  hwPlanes.insert(1);
295 
296  else if (station == 1 && layer == 2)
297  hwPlanes.insert(2);
298 
299  else if (station == 2 && layer == 1)
300  hwPlanes.insert(3);
301 
302  else if (station == 2 && layer == 2)
303  hwPlanes.insert(4);
304 
305  else
306  std::cout << "??????????????" << std::endl;
307 
308  }
309 
310 
311  for (std::set<int>::iterator it= hwPlanes.begin();
312  it!= hwPlanes.end();
313  ++it)
314  {
315  ss << " " << *it;
316  }
317 
318 
319 
320 
321  return ss.str();
322 
323 
324 
325 }
326 
327 // ------------ method called once each job just before starting event loop ------------
329 {
330 }
331 
332 // ------------ method called once each job just after ending the event loop ------------
334 {
335 }
336 
type
Definition: HCALResponse.h:21
virtual void beginJob()
Definition: EDAnalyzer.h:72
EventNumber_t event() const
Definition: EventID.h:41
~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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
unsigned long long EventNumber_t
RPCPhiEff(const edm::ParameterSet &)
Definition: RPCPhiEff.cc:57
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
edm::EDGetTokenT< edm::SimTrackContainer > m_g4Token
Definition: RPCPhiEff.h:62
std::string fromRaw(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:252
const Double_t pi
edm::EDGetTokenT< std::vector< L1MuRegionalCand > > m_rpcfToken
Definition: RPCPhiEff.h:61
int iEvent
Definition: GenABIO.cc:230
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< RPCDigiCollection > m_rpcdigiToken
Definition: RPCPhiEff.h:63
std::vector< RPCDigi >::const_iterator const_iterator
edm::EventID id() const
Definition: EventBase.h:60
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
std::string fromCones(const edm::Event &iEvent)
Definition: RPCPhiEff.cc:246
virtual void endJob()
Definition: RPCPhiEff.cc:333
std::vector< SimTrack > SimTrackContainer
std::ofstream m_outfileR
Definition: RPCPhiEff.h:53
RPCConst m_const
Definition: RPCPhiEff.h:65