00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesBuilder.h>
00018 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboard.h>
00019 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboardME11.h>
00020 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMuonPortCard.h>
00021
00022 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00023
00024 #include <L1Trigger/CSCCommonTrigger/interface/CSCTriggerGeometry.h>
00025 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
00026 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00027
00028
00029
00030
00031 const int CSCTriggerPrimitivesBuilder::min_endcap = CSCDetId::minEndcapId();
00032 const int CSCTriggerPrimitivesBuilder::max_endcap = CSCDetId::maxEndcapId();
00033 const int CSCTriggerPrimitivesBuilder::min_station = CSCDetId::minStationId();
00034 const int CSCTriggerPrimitivesBuilder::max_station = CSCDetId::maxStationId();
00035 const int CSCTriggerPrimitivesBuilder::min_sector = CSCTriggerNumbering::minTriggerSectorId();
00036 const int CSCTriggerPrimitivesBuilder::max_sector = CSCTriggerNumbering::maxTriggerSectorId();
00037 const int CSCTriggerPrimitivesBuilder::min_subsector = CSCTriggerNumbering::minTriggerSubSectorId();
00038 const int CSCTriggerPrimitivesBuilder::max_subsector = CSCTriggerNumbering::maxTriggerSubSectorId();
00039 const int CSCTriggerPrimitivesBuilder::min_chamber = CSCTriggerNumbering::minTriggerCscId();
00040 const int CSCTriggerPrimitivesBuilder::max_chamber = CSCTriggerNumbering::maxTriggerCscId();
00041
00042
00043
00044
00045 CSCTriggerPrimitivesBuilder::CSCTriggerPrimitivesBuilder(const edm::ParameterSet& conf)
00046 {
00047
00048
00049
00050 edm::ParameterSet commonParams = conf.getParameter<edm::ParameterSet>("commonParam");
00051 smartME1aME1b = commonParams.getUntrackedParameter<bool>("smartME1aME1b", false);
00052 disableME1a = commonParams.getUntrackedParameter<bool>("disableME1a", false);
00053 disableME42 = commonParams.getUntrackedParameter<bool>("disableME42", false);
00054
00055 checkBadChambers_ = conf.getUntrackedParameter<bool>("checkBadChambers", true);
00056
00057
00058 for (int endc = min_endcap; endc <= max_endcap; endc++)
00059 {
00060 for (int stat = min_station; stat <= max_station; stat++)
00061 {
00062 int numsubs = ((stat == 1) ? max_subsector : 1);
00063 for (int sect = min_sector; sect <= max_sector; sect++)
00064 {
00065 for (int subs = min_subsector; subs <= numsubs; subs++)
00066 {
00067 for (int cham = min_chamber; cham <= max_chamber; cham++)
00068 {
00069 if ((endc <= 0 || endc > MAX_ENDCAPS) ||
00070 (stat <= 0 || stat > MAX_STATIONS) ||
00071 (sect <= 0 || sect > MAX_SECTORS) ||
00072 (subs <= 0 || subs > MAX_SUBSECTORS) ||
00073 (cham <= 0 || stat > MAX_CHAMBERS))
00074 {
00075 edm::LogError("L1CSCTPEmulatorSetupError")
00076 << "+++ trying to instantiate TMB of illegal CSC id ["
00077 << " endcap = " << endc << " station = " << stat
00078 << " sector = " << sect << " subsector = " << subs
00079 << " chamber = " << cham << "]; skipping it... +++\n";
00080 continue;
00081 }
00082 int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
00083
00084
00085 if (stat==1 && ring==1 && smartME1aME1b)
00086 tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] = new CSCMotherboardME11(endc, stat, sect, subs, cham, conf);
00087 else
00088 tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] = new CSCMotherboard(endc, stat, sect, subs, cham, conf);
00089 }
00090 }
00091 }
00092 }
00093 }
00094
00095
00096 m_minBX = conf.getParameter<int>("MinBX");
00097 m_maxBX = conf.getParameter<int>("MaxBX");
00098
00099
00100 m_muonportcard = new CSCMuonPortCard(conf);
00101 }
00102
00103
00104
00105
00106 CSCTriggerPrimitivesBuilder::~CSCTriggerPrimitivesBuilder()
00107 {
00108 for (int endc = min_endcap; endc <= max_endcap; endc++)
00109 {
00110 for (int stat = min_station; stat <= max_station; stat++)
00111 {
00112 int numsubs = ((stat == 1) ? max_subsector : 1);
00113 for (int sect = min_sector; sect <= max_sector; sect++)
00114 {
00115 for (int subs = min_subsector; subs <= numsubs; subs++)
00116 {
00117 for (int cham = min_chamber; cham <= max_chamber; cham++)
00118 {
00119 delete tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00120 }
00121 }
00122 }
00123 }
00124 }
00125 delete m_muonportcard;
00126 }
00127
00128
00129
00130
00131
00132 void CSCTriggerPrimitivesBuilder::setConfigParameters(const CSCDBL1TPParameters* conf)
00133 {
00134
00135
00136 for (int endc = min_endcap; endc <= max_endcap; endc++)
00137 {
00138 for (int stat = min_station; stat <= max_station; stat++)
00139 {
00140 int numsubs = ((stat == 1) ? max_subsector : 1);
00141 for (int sect = min_sector; sect <= max_sector; sect++)
00142 {
00143 for (int subs = min_subsector; subs <= numsubs; subs++)
00144 {
00145 for (int cham = min_chamber; cham <= max_chamber; cham++)
00146 {
00147 CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00148 tmb->setConfigParameters(conf);
00149 }
00150 }
00151 }
00152 }
00153 }
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 void CSCTriggerPrimitivesBuilder::build(const CSCBadChambers* badChambers,
00166 const CSCWireDigiCollection* wiredc,
00167 const CSCComparatorDigiCollection* compdc,
00168 CSCALCTDigiCollection& oc_alct,
00169 CSCCLCTDigiCollection& oc_clct,
00170 CSCCLCTPreTriggerCollection & oc_pretrig,
00171 CSCCorrelatedLCTDigiCollection& oc_lct,
00172 CSCCorrelatedLCTDigiCollection& oc_sorted_lct)
00173 {
00174
00175 CSCTriggerGeomManager* theGeom = CSCTriggerGeometry::get();
00176
00177 for (int endc = min_endcap; endc <= max_endcap; endc++)
00178 {
00179 for (int stat = min_station; stat <= max_station; stat++)
00180 {
00181 int numsubs = ((stat == 1) ? max_subsector : 1);
00182 for (int sect = min_sector; sect <= max_sector; sect++)
00183 {
00184 for (int subs = min_subsector; subs <= numsubs; subs++)
00185 {
00186 for (int cham = min_chamber; cham <= max_chamber; cham++)
00187 {
00188
00189 int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
00190
00191 if (disableME42 && stat==4 && ring==2) continue;
00192
00193 CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00194
00195
00196 if (tmb == 0 || theGeom->chamber(endc, stat, sect, subs, cham) == 0) continue;
00197
00198 int chid = CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs, stat, cham);
00199
00200
00201 CSCDetId detid(endc, stat, ring, chid, 0);
00202
00203
00204
00205 if (checkBadChambers_ && badChambers->isInBadChamber(detid)) continue;
00206
00207
00208
00209 if (stat==1 && ring==1 && smartME1aME1b)
00210 {
00211 CSCMotherboardME11* tmb11 = static_cast<CSCMotherboardME11*>(tmb);
00212
00213
00214
00215 tmb11->run(wiredc,compdc);
00216 std::vector<CSCCorrelatedLCTDigi> lctV = tmb11->readoutLCTs1b();
00217 std::vector<CSCCorrelatedLCTDigi> lctV1a = tmb11->readoutLCTs1a();
00218
00219 std::vector<CSCALCTDigi> alctV1a, alctV = tmb11->alct->readoutALCTs();
00220
00221 std::vector<CSCCLCTDigi> clctV = tmb11->clct->readoutCLCTs();
00222 std::vector<int> preTriggerBXs = tmb11->clct->preTriggerBXs();
00223 std::vector<CSCCLCTDigi> clctV1a = tmb11->clct1a->readoutCLCTs();
00224 std::vector<int> preTriggerBXs1a = tmb11->clct1a->preTriggerBXs();
00225
00226
00227
00228 std::vector<CSCALCTDigi> tmpV(alctV);
00229 alctV.clear();
00230 for (unsigned int al=0; al < tmpV.size(); al++)
00231 {
00232 if (tmpV[al].getKeyWG()<=15) alctV1a.push_back(tmpV[al]);
00233 if (tmpV[al].getKeyWG()>=10) alctV.push_back(tmpV[al]);
00234 }
00235
00236
00237
00238
00239
00240 if (!(lctV.empty()&&alctV.empty()&&clctV.empty())) {
00241 LogTrace("L1CSCTrigger")
00242 << "CSCTriggerPrimitivesBuilder results in " <<detid;
00243 }
00244
00245
00246 if (!lctV.empty()) {
00247 LogTrace("L1CSCTrigger")
00248 << "Put " << lctV.size() << " ME1b LCT digi"
00249 << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
00250 oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
00251 }
00252
00253
00254 if (!alctV.empty()) {
00255 LogTrace("L1CSCTrigger")
00256 << "Put " << alctV.size() << " ME1b ALCT digi"
00257 << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
00258 oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
00259 }
00260
00261
00262 if (!clctV.empty()) {
00263 LogTrace("L1CSCTrigger")
00264 << "Put " << clctV.size() << " ME1b CLCT digi"
00265 << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
00266 oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
00267 }
00268
00269
00270 if (!preTriggerBXs.empty()) {
00271 LogTrace("L1CSCTrigger")
00272 << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
00273 << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00274 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00275 }
00276
00277
00278
00279 if (disableME1a) continue;
00280
00281 CSCDetId detid1a(endc, stat, 4, chid, 0);
00282
00283 if (!(lctV1a.empty()&&alctV1a.empty()&&clctV1a.empty())){
00284 LogTrace("L1CSCTrigger") << "CSCTriggerPrimitivesBuilder results in " <<detid1a;
00285 }
00286
00287
00288 if (!lctV1a.empty()) {
00289 LogTrace("L1CSCTrigger")
00290 << "Put " << lctV1a.size() << " ME1a LCT digi"
00291 << ((lctV1a.size() > 1) ? "s " : " ") << "in collection\n";
00292 oc_lct.put(std::make_pair(lctV1a.begin(),lctV1a.end()), detid1a);
00293 }
00294
00295
00296 if (!alctV1a.empty()) {
00297 LogTrace("L1CSCTrigger")
00298 << "Put " << alctV1a.size() << " ME1a ALCT digi"
00299 << ((alctV1a.size() > 1) ? "s " : " ") << "in collection\n";
00300 oc_alct.put(std::make_pair(alctV1a.begin(),alctV1a.end()), detid1a);
00301 }
00302
00303
00304 if (!clctV1a.empty()) {
00305 LogTrace("L1CSCTrigger")
00306 << "Put " << clctV1a.size() << " ME1a CLCT digi"
00307 << ((clctV1a.size() > 1) ? "s " : " ") << "in collection\n";
00308 oc_clct.put(std::make_pair(clctV1a.begin(),clctV1a.end()), detid1a);
00309 }
00310
00311
00312 if (!preTriggerBXs1a.empty()) {
00313 LogTrace("L1CSCTrigger")
00314 << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
00315 << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00316 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00317 }
00318 }
00319
00320
00321 else
00322 {
00323 tmb->run(wiredc,compdc);
00324
00325 std::vector<CSCCorrelatedLCTDigi> lctV = tmb->readoutLCTs();
00326 std::vector<CSCALCTDigi> alctV = tmb->alct->readoutALCTs();
00327 std::vector<CSCCLCTDigi> clctV = tmb->clct->readoutCLCTs();
00328 std::vector<int> preTriggerBXs = tmb->clct->preTriggerBXs();
00329
00330 if (!(alctV.empty() && clctV.empty() && lctV.empty())) {
00331 LogTrace("L1CSCTrigger")
00332 << "CSCTriggerPrimitivesBuilder got results in " <<detid;
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 if (!lctV.empty()) {
00349 LogTrace("L1CSCTrigger")
00350 << "Put " << lctV.size() << " LCT digi"
00351 << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
00352 oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
00353 }
00354
00355
00356 if (!alctV.empty()) {
00357 LogTrace("L1CSCTrigger")
00358 << "Put " << alctV.size() << " ALCT digi"
00359 << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
00360 oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
00361 }
00362
00363
00364 if (!clctV.empty()) {
00365 LogTrace("L1CSCTrigger")
00366 << "Put " << clctV.size() << " CLCT digi"
00367 << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
00368 oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
00369 }
00370
00371
00372 if (!preTriggerBXs.empty()) {
00373 LogTrace("L1CSCTrigger")
00374 << "Put " << preTriggerBXs.size() << " CLCT pretrigger"
00375 << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00376 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00377 }
00378 }
00379 }
00380 }
00381 }
00382 }
00383 }
00384
00385
00386 m_muonportcard->loadDigis(oc_lct);
00387
00388 std::vector<csctf::TrackStub> result;
00389 for(int bx = m_minBX; bx <= m_maxBX; ++bx)
00390 for(int e = min_endcap; e <= max_endcap; ++e)
00391 for(int st = min_station; st <= max_station; ++st)
00392 for(int se = min_sector; se <= max_sector; ++se)
00393 {
00394 if(st == 1)
00395 {
00396 std::vector<csctf::TrackStub> subs1, subs2;
00397 subs1 = m_muonportcard->sort(e, st, se, 1, bx);
00398 subs2 = m_muonportcard->sort(e, st, se, 2, bx);
00399 result.insert(result.end(), subs1.begin(), subs1.end());
00400 result.insert(result.end(), subs2.begin(), subs2.end());
00401 }
00402 else
00403 {
00404 std::vector<csctf::TrackStub> sector;
00405 sector = m_muonportcard->sort(e, st, se, 0, bx);
00406 result.insert(result.end(), sector.begin(), sector.end());
00407 }
00408 }
00409
00410 std::vector<csctf::TrackStub>::const_iterator itr = result.begin();
00411 for (; itr != result.end(); itr++)
00412 {
00413 oc_sorted_lct.insertDigi(CSCDetId(itr->getDetId().rawId()), *(itr->getDigi()));
00414 LogDebug("L1CSCTrigger")
00415 << "MPC " << *(itr->getDigi()) << " found in ME"
00416 << ((itr->endcap() == 1) ? "+" : "-") << itr->station() << "/"
00417 << CSCDetId(itr->getDetId().rawId()).ring() << "/"
00418 << CSCDetId(itr->getDetId().rawId()).chamber()
00419 << " (sector " << itr->sector()
00420 << " trig id. " << itr->cscid() << ")" << "\n";
00421 }
00422 }