00001 #include "L1Trigger/RPCTrigger/interface/RPCTrigger.h"
00002
00003
00004 #include "CondFormats/DataRecord/interface/L1RPCConfigRcd.h"
00005 #include "CondFormats/L1TObjects/interface/L1RPCConfig.h"
00006
00007 #include "CondFormats/DataRecord/interface/L1RPCConeBuilderRcd.h"
00008 #include "CondFormats/RPCObjects/interface/L1RPCConeBuilder.h"
00009
00010 #include "CondFormats/DataRecord/interface/L1RPCHwConfigRcd.h"
00011 #include "CondFormats/RPCObjects/interface/L1RPCHwConfig.h"
00012
00013
00014
00015
00016
00017
00018 RPCTrigger::RPCTrigger(const edm::ParameterSet& iConfig):
00019 m_pacTrigger(0),
00020 m_trigConfig(0)
00021 {
00022 produces<std::vector<L1MuRegionalCand> >("RPCb");
00023 produces<std::vector<L1MuRegionalCand> >("RPCf");
00024
00025
00026 m_firstRun = true;
00027 m_cacheID = 0;
00028
00029
00030 m_triggerDebug = iConfig.getUntrackedParameter<int>("RPCTriggerDebug",0);
00031
00032
00033
00034
00035 if ( m_triggerDebug != 1 && m_triggerDebug != 2)
00036 m_triggerDebug = 0;
00037
00038 m_label = iConfig.getParameter<std::string>("label");
00039 m_buildOwnLinkSystem = iConfig.getParameter<bool>("buildOwnLinkSystem");
00040 }
00041
00042
00043
00044
00045 RPCTrigger::~RPCTrigger(){
00046 if (m_pacTrigger != 0) delete m_pacTrigger;
00047 if (m_trigConfig != 0) delete m_trigConfig;
00048 }
00049
00050
00051
00052 void
00053 RPCTrigger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00054 {
00055
00056
00057
00058 if (m_firstRun){
00059
00060 m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
00061 m_firstRun = false;
00062 edm::ESHandle<L1RPCConfig> conf;
00063 iSetup.get<L1RPCConfigRcd>().get(conf);
00064 const L1RPCConfig *rpcconf = conf.product();
00065
00066
00067 m_pacManager.init(rpcconf);
00068 m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
00069 m_trigConfig->setDebugLevel(m_triggerDebug);
00070 m_pacTrigger = new RPCPacTrigger(m_trigConfig);
00071
00072
00073 }
00074
00075 if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {
00076
00077
00078 m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
00079
00080 edm::ESHandle<L1RPCConfig> conf;
00081 iSetup.get<L1RPCConfigRcd>().get(conf);
00082 const L1RPCConfig *rpcconf = conf.product();
00083
00084 m_pacManager.init(rpcconf);
00085 delete m_trigConfig;
00086 m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
00087 m_trigConfig->setDebugLevel(m_triggerDebug);
00088
00089 delete m_pacTrigger;
00090 m_pacTrigger = new RPCPacTrigger(m_trigConfig);
00091
00092
00093
00094 }
00095
00096
00097
00098 if (m_buildOwnLinkSystem && !m_theLinksystem.isGeometryBuilt()){
00099
00100 edm::LogInfo("RPC") << "Building RPC links map for a RPCTrigger";
00101 edm::ESHandle<RPCGeometry> rpcGeom;
00102 iSetup.get<MuonGeometryRecord>().get( rpcGeom );
00103 m_theLinksystem.buildGeometry(rpcGeom);
00104 edm::LogInfo("RPC") << "RPC links map for a RPCTrigger built";
00105
00106 }
00107
00108
00109 edm::Handle<RPCDigiCollection> rpcDigis;
00110
00111
00112 iEvent.getByLabel(m_label, rpcDigis);
00113 std::auto_ptr<std::vector<L1MuRegionalCand> > candBarell(new std::vector<L1MuRegionalCand>);
00114 std::auto_ptr<std::vector<L1MuRegionalCand> > candForward(new std::vector<L1MuRegionalCand>);
00115
00116 for (int iBx = -1; iBx < 2; ++ iBx) {
00117
00118 L1RpcLogConesVec ActiveCones;
00119 if (m_buildOwnLinkSystem){
00120 ActiveCones = m_theLinksystem.getCones(rpcDigis, iBx);
00121 } else {
00122 edm::ESHandle<L1RPCConeBuilder> coneBuilder;
00123 iSetup.get<L1RPCConeBuilderRcd>().get(coneBuilder);
00124
00125 edm::ESHandle<L1RPCHwConfig> hwConfig;
00126 iSetup.get<L1RPCHwConfigRcd>().get(hwConfig);
00127
00128 ActiveCones = m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, hwConfig, iBx);
00129
00130 }
00131
00132 L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones);
00133
00134 int maxFiredPlanes = 0;
00135
00136 for (unsigned int i=0;i<ActiveCones.size();i++){
00137 int fpCnt = ActiveCones[i].getFiredPlanesCnt();
00138 if (fpCnt > maxFiredPlanes)
00139 maxFiredPlanes = fpCnt;
00140 }
00141
00142
00143
00144 LogDebug("RPCTrigger") << "---Filling candindates in new event--- "
00145 << maxFiredPlanes << std::endl;
00146
00147 std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
00148 std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
00149
00150
00151 candBarell->insert(candBarell->end(), RPCb.begin(), RPCb.end());
00152
00153
00154 candForward->insert(candForward->end(), RPCf.begin(), RPCf.end());
00155
00156 }
00157 iEvent.put(candBarell, "RPCb");
00158 iEvent.put(candForward, "RPCf");
00159
00160 }
00162
00169
00170 std::vector<L1MuRegionalCand> RPCTrigger::giveFinallCandindates(L1RpcTBMuonsVec finalMuons, int type, int bx){
00171
00172 std::vector<L1MuRegionalCand> RPCCand;
00173
00174 for(unsigned int iMu = 0; iMu < finalMuons.size(); iMu++)
00175 {
00176
00177 if (finalMuons[iMu].getPtCode()==0){
00178 continue;
00179 }
00180
00181 L1MuRegionalCand l1Cand;
00182
00183 l1Cand.setBx(bx);
00184
00185
00186 l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
00187 l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
00188
00189 l1Cand.setType(type);
00190
00191 int charge=finalMuons[iMu].getSign();
00192
00193 if (charge == 0)
00194 l1Cand.setChargePacked(1);
00195 else
00196 l1Cand.setChargePacked(0);
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 int phiPacked = finalMuons[iMu].getPhiAddr();
00216 l1Cand.setPhiPacked(phiPacked);
00217
00218
00219
00220
00221
00222 signed short etaAddr = finalMuons[iMu].getEtaAddr();
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 l1Cand.setEtaPacked(etaAddr);
00233 l1Cand.setChargeValid(true);
00234
00235
00236
00237
00238
00239
00240
00241
00242 RPCCand.push_back(l1Cand);
00243
00244 LogDebug("RPCTrigger") << "Found muonf of pt "
00245 << finalMuons[iMu].getPtCode()
00246 << " bx " << l1Cand.bx()
00247 << " L1Charge " << l1Cand.charge_packed()
00248 << " ql " << l1Cand.quality()
00249 << " fp " << finalMuons[iMu].getFiredPlanes()
00250 << " b/f " << l1Cand.type_idx()
00251 << " phi " << l1Cand.phi_packed()
00252 << " eta " << l1Cand.eta_packed()
00253
00254 << " killed " << finalMuons[iMu].wasKilled();
00255
00256
00257 }
00258
00259 return RPCCand;
00260 }
00261