1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/SynchroCountsGrabber.h"
|
2 |
|
3 |
#include "DataFormats/Common/interface/Handle.h"
|
4 |
#include "FWCore/Framework/interface/Event.h"
|
5 |
#include "FWCore/Framework/interface/ESTransientHandle.h"
|
6 |
#include "FWCore/Framework/interface/ESHandle.h"
|
7 |
#include "FWCore/Framework/interface/EventSetup.h"
|
8 |
#include "FWCore/Framework/interface/ESWatcher.h"
|
9 |
|
10 |
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
11 |
#include "CondFormats/RPCObjects/interface/RPCEMap.h"
|
12 |
#include "CondFormats/DataRecord/interface/RPCEMapRcd.h"
|
13 |
#include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
|
14 |
#include "CondFormats/RPCObjects/interface/LinkBoardSpec.h"
|
15 |
#include "DataFormats/MuonDetId/interface/RPCDetId.h"
|
16 |
|
17 |
#include "DataFormats/MuonReco/interface/Muon.h"
|
18 |
|
19 |
#include "UserCode/L1RpcTriggerAnalysis/interface/TrackAtSurface.h"
|
20 |
#include "Geometry/RPCGeometry/interface/RPCGeometry.h"
|
21 |
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
|
22 |
#include "DataFormats/Math/interface/deltaR.h"
|
23 |
#include "DataFormats/Math/interface/deltaPhi.h"
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
SynchroCountsGrabber::SynchroCountsGrabber(const edm::ParameterSet& cfg)
|
31 |
: theCabling(0),
|
32 |
theSelector(cfg.getParameter<edm::ParameterSet>("synchroSelector")),
|
33 |
deltaR_MuonToDetUnit_cutoff(cfg.getParameter<double>("deltaR_MuonToDetUnit_cutoff")),
|
34 |
checkInside(cfg.getParameter<bool>("checkInside")),
|
35 |
theNoSynchroWarning(false)
|
36 |
{}
|
37 |
|
38 |
SynchroCountsGrabber::~SynchroCountsGrabber()
|
39 |
{
|
40 |
if (theNoSynchroWarning) std::cout <<" **** SynchroCountsGrabber **** WARNING - NoSynchroWarning was set!" << std::endl;
|
41 |
|
42 |
}
|
43 |
|
44 |
RPCRawSynchro::ProdItem SynchroCountsGrabber::counts(const edm::Event &ev, const edm::EventSetup &es)
|
45 |
{
|
46 |
RPCRawSynchro::ProdItem result;
|
47 |
|
48 |
if (theMapWatcher.check(es)) {
|
49 |
delete theCabling;
|
50 |
edm::ESTransientHandle<RPCEMap> readoutMapping;
|
51 |
es.get<RPCEMapRcd>().get(readoutMapping);
|
52 |
theCabling = readoutMapping->convert();
|
53 |
LogTrace("") << "SynchroCountsGrabber - record has CHANGED!!, read map, VERSION: " << theCabling->version();
|
54 |
}
|
55 |
|
56 |
edm::Handle<RPCRawSynchro::ProdItem> synchroCounts;
|
57 |
std::vector<edm::Handle<RPCRawSynchro::ProdItem> > handle_vec;
|
58 |
ev.getManyByType(handle_vec);
|
59 |
if(handle_vec.size()) synchroCounts = handle_vec[0];
|
60 |
if (!synchroCounts.isValid()) {
|
61 |
theNoSynchroWarning = true;
|
62 |
return result;
|
63 |
}
|
64 |
|
65 |
TrackAtSurface trackAtSurface(theMuon, ev,es);
|
66 |
edm::ESHandle<RPCGeometry> rpcGeometry;
|
67 |
es.get<MuonGeometryRecord>().get(rpcGeometry);
|
68 |
|
69 |
|
70 |
for(RPCRawSynchro::ProdItem::const_iterator it = synchroCounts->begin(); it != synchroCounts->end(); ++it) {
|
71 |
const LinkBoardElectronicIndex & path = it->first;
|
72 |
const std::vector<FebConnectorSpec> & febs = theCabling->location(path)->febs();
|
73 |
std::map<uint32_t,bool> dets;
|
74 |
for (std::vector<FebConnectorSpec>::const_iterator iif = febs.begin(); iif != febs.end(); ++iif) dets[iif->rawId()] = true;
|
75 |
for ( std::map<uint32_t,bool>::const_iterator im = dets.begin(); im != dets.end(); ++im) {
|
76 |
RPCDetId rpcDet(im->first);
|
77 |
const GeomDet *geomDet = rpcGeometry->idToDet(rpcDet);
|
78 |
GlobalPoint detPosition = geomDet->position();
|
79 |
if (deltaR(theMuon->eta(), theMuon->phi(), detPosition.eta(), detPosition.phi()) > deltaR_MuonToDetUnit_cutoff) continue;
|
80 |
TrajectoryStateOnSurface stateAtDet = trackAtSurface.atDetFromClose(rpcDet,detPosition);
|
81 |
|
82 |
if (!stateAtDet.isValid()) continue;
|
83 |
if (checkInside && !(geomDet->surface().bounds().inside(stateAtDet.localPosition()))) continue;
|
84 |
if (!theSelector.checkTraj(stateAtDet, rpcDet, ev, es)) continue;
|
85 |
result.push_back(*it);
|
86 |
}
|
87 |
}
|
88 |
return result;
|
89 |
}
|