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