Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027
00028 #include "FWCore/Framework/interface/Event.h"
00029
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031
00032 #include <SimDataFormats/Track/interface/SimTrackContainer.h>
00033
00034 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00035 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00036
00037 #include <L1Trigger/RPCTrigger/interface/RPCLogCone.h>
00038 #include <L1Trigger/RPCTrigger/interface/RPCConst.h>
00039
00040 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
00041
00042 #include "DataFormats/Math/interface/LorentzVector.h"
00043 #include "Validation/MuonRPCGeometry/plugins/RPCPhiEff.h"
00044
00045 #include <iostream>
00046 #include <set>
00047 #include <fstream>
00048 #include <sstream>
00049
00050 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
00051
00052 #include "DataFormats/Math/interface/deltaR.h"
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 RPCPhiEff::RPCPhiEff(const edm::ParameterSet & ps) :
00066 m_rpcb( ps.getParameter< edm::InputTag >("rpcb") ),
00067 m_rpcf( ps.getParameter< edm::InputTag >("rpcf") ),
00068 m_g4( ps.getParameter< edm::InputTag >("g4") ),
00069 m_rpcdigi( ps.getParameter< edm::InputTag >("rpcdigi") )
00070 {
00071
00072
00073
00074 m_outfileR.open("muons.txt");
00075
00076 }
00077
00078
00079 RPCPhiEff::~RPCPhiEff()
00080 {
00081
00082
00083 m_outfileR.close();
00084
00085 }
00086
00087
00088
00089
00090
00091
00092
00093 void
00094 RPCPhiEff::analyze(const edm::Event & iEvent,
00095 const edm::EventSetup & iSetup)
00096 {
00097
00098
00099 edm::Handle<std::vector<L1MuRegionalCand> > rpcBarrel;
00100 edm::Handle<std::vector<L1MuRegionalCand> > rpcForward;
00101
00102
00103
00104 iEvent.getByLabel(m_rpcb,rpcBarrel);
00105 iEvent.getByLabel(m_rpcf,rpcForward);
00106
00107
00108 std::vector< edm::Handle<std::vector<L1MuRegionalCand> > > handleVec;
00109 handleVec.push_back( rpcBarrel );
00110 handleVec.push_back( rpcForward );
00111
00112
00113 edm::Handle<edm::SimTrackContainer> simTracks;
00114 iEvent.getByLabel(m_g4,simTracks);
00115
00116 float etaGen = 0, phiGen = 0, ptGen = 0;
00117
00118 int noOfMuons = 0;
00119 int noOfRecMuons = 0;
00120 int noOfMatchedRecMuons = 0;
00121
00122 bool firstRunForMuonMatchingCnt = true;
00123
00124
00125 double deltarMin = -1;
00126 edm::SimTrackContainer::const_iterator simTrk = simTracks->begin();
00127 for (; simTrk != simTracks->end(); ++simTrk) {
00128
00129 if (simTrk->type() != -13 && simTrk->type()!=13) continue;
00130
00131 edm::SimTrackContainer::const_iterator simTrk2 = simTrk;
00132 ++simTrk2;
00133 for (; simTrk2 != simTracks->end(); ++simTrk2) {
00134 if (simTrk2->type() != -13 && simTrk2->type()!=13) continue;
00135 double drCand = reco::deltaR(simTrk2->momentum(), simTrk->momentum());
00136 if (drCand < deltarMin || deltarMin < 0) deltarMin = drCand;
00137 }
00138
00139
00140 }
00141
00142
00143 if (deltarMin < 0.7 && deltarMin > 0) return;
00144
00145 simTrk = simTracks->begin();
00146 for (; simTrk != simTracks->end(); simTrk++) {
00147 int type = simTrk->type();
00148 if (type == 13 || type == -13) {
00149
00150 const math::XYZTLorentzVectorD momentum = simTrk->momentum();
00151 etaGen = momentum.eta();
00152 ptGen = momentum.Pt();
00153 phiGen = momentum.phi();
00154 noOfMuons++;
00155
00156 bool matched = false;
00157 int ptCodeRec = 0;
00158 int towerRec = 0;
00159 int phiRec = 0;
00160
00161 int qual = 0;
00162 int ghost = 0;
00163
00164
00165
00166 for ( std::vector< edm::Handle<std::vector<L1MuRegionalCand> > >::iterator it = handleVec.begin();
00167 it != handleVec.end();
00168 ++it )
00169 {
00170 std::vector<L1MuRegionalCand>::const_iterator itRPC;
00171 for (itRPC=(*it)->begin(); itRPC!=(*it)->end(); itRPC++){
00172 int ptCode = itRPC->pt_packed();
00173 if (ptCode != 0) {
00174
00175 if (firstRunForMuonMatchingCnt) ++noOfRecMuons;
00176 ptCodeRec=ptCode;
00177 phiRec=itRPC->phi_packed();
00178 qual = itRPC->quality();
00179 towerRec = itRPC->eta_packed();
00180 if (towerRec > 16) {
00181 towerRec = - ( (~towerRec & 63) + 1);
00182 }
00183
00184 float pi = 3.14159265;
00185
00186 float phiScaled = phiGen;
00187 if (phiScaled<0) phiScaled += 2*pi;
00188 int phiHwGen = (phiScaled)/2/pi*144;
00189
00190
00191
00192 if ( ( std::abs(phiHwGen-phiRec) < 10) && (std::abs(m_const.towerNumFromEta(etaGen)-towerRec)<1) )
00193 {
00194 if (matched) {
00195 ++ghost;
00196 }
00197 matched = true;
00198 ++noOfMatchedRecMuons;
00199 m_outfileR << etaGen << " " << phiGen << " " << ptGen
00200 << " " << towerRec << " " << phiRec << " " << ptCodeRec << " " << qual
00201 << " " << ghost
00202 << std::endl;
00203 }
00204 }
00205 }
00206 }
00207 firstRunForMuonMatchingCnt=false;
00208 if (!matched) {
00209 m_outfileR << etaGen << " " << phiGen << " " << ptGen
00210 << " " << 0 << " " << 0 << " " << 0 << " " << 0
00211 << " " << 0
00212 << std::endl;
00213
00214 }
00215
00216
00217 }
00218 }
00219
00220 edm::EventID id = iEvent.id();
00221 edm::EventNumber_t evNum = id.event();
00222 edm::RunNumber_t rnNum = id.run();
00223
00224 if (noOfMatchedRecMuons!=noOfRecMuons) {
00225 edm::LogInfo("RPCEffWarn") << " MuonCands " << noOfRecMuons
00226 << " matched " << noOfMatchedRecMuons
00227 << " in run " << rnNum
00228 << " event " << evNum;
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 }
00251
00252 std::string RPCPhiEff::fromCones(const edm::Event & iEvent){
00253
00254 return "";
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 std::string RPCPhiEff::fromRaw(const edm::Event & iEvent){
00306
00307 std::stringstream ss;
00308
00309
00310 edm::Handle<RPCDigiCollection> rpcDigis;
00311 iEvent.getByLabel(m_rpcdigi,rpcDigis);
00312
00313 std::set<int> hwPlanes;
00314
00315 RPCDigiCollection::DigiRangeIterator detUnitIt;
00316 for (detUnitIt=rpcDigis->begin();
00317 detUnitIt!=rpcDigis->end();
00318 ++detUnitIt)
00319 {
00320
00321 const RPCDigiCollection::Range& range = (*detUnitIt).second;
00322 bool hasBX0 = false;
00323 for (RPCDigiCollection::const_iterator digiIt = range.first;
00324 digiIt!=range.second;
00325 ++digiIt)
00326 {
00327 if (digiIt->bx() == 0) {
00328 hasBX0 = true;
00329 break;
00330 }
00331 }
00332
00333 if (!hasBX0) continue;
00334
00335 const RPCDetId& id = (*detUnitIt).first;
00336 int station = id.station();
00337 int layer = id.layer();
00338
00339
00340 if (station == 3)
00341 hwPlanes.insert(5);
00342
00343 else if (station == 4)
00344 hwPlanes.insert(6);
00345
00346 else if (station == 1 && layer == 1)
00347 hwPlanes.insert(1);
00348
00349 else if (station == 1 && layer == 2)
00350 hwPlanes.insert(2);
00351
00352 else if (station == 2 && layer == 1)
00353 hwPlanes.insert(3);
00354
00355 else if (station == 2 && layer == 2)
00356 hwPlanes.insert(4);
00357
00358 else
00359 std::cout << "??????????????" << std::endl;
00360
00361 }
00362
00363
00364 for (std::set<int>::iterator it= hwPlanes.begin();
00365 it!= hwPlanes.end();
00366 ++it)
00367 {
00368 ss << " " << *it;
00369 }
00370
00371
00372
00373
00374 return ss.str();
00375
00376
00377
00378 }
00379
00380
00381 void RPCPhiEff::beginJob(const edm::EventSetup &)
00382 {
00383 }
00384
00385
00386 void RPCPhiEff::endJob()
00387 {
00388 }
00389