00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesBuilder.h>
00019 #include <L1Trigger/CSCTriggerPrimitives/src/CSCMotherboard.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 =
00036 CSCTriggerNumbering::minTriggerSectorId();
00037 const int CSCTriggerPrimitivesBuilder::max_sector =
00038 CSCTriggerNumbering::maxTriggerSectorId();
00039 const int CSCTriggerPrimitivesBuilder::min_subsector =
00040 CSCTriggerNumbering::minTriggerSubSectorId();
00041 const int CSCTriggerPrimitivesBuilder::max_subsector =
00042 CSCTriggerNumbering::maxTriggerSubSectorId();
00043 const int CSCTriggerPrimitivesBuilder::min_chamber =
00044 CSCTriggerNumbering::minTriggerCscId();
00045 const int CSCTriggerPrimitivesBuilder::max_chamber =
00046 CSCTriggerNumbering::maxTriggerCscId();
00047
00048
00049
00050
00051 CSCTriggerPrimitivesBuilder::CSCTriggerPrimitivesBuilder(const edm::ParameterSet& conf) {
00052
00053
00054
00055 for (int endc = min_endcap; endc <= max_endcap; endc++) {
00056 for (int stat = min_station; stat <= max_station; stat++) {
00057 int numsubs = ((stat == 1) ? max_subsector : 1);
00058 for (int sect = min_sector; sect <= max_sector; sect++) {
00059 for (int subs = min_subsector; subs <= numsubs; subs++) {
00060 for (int cham = min_chamber; cham <= max_chamber; cham++) {
00061 if ((endc <= 0 || endc > MAX_ENDCAPS) ||
00062 (stat <= 0 || stat > MAX_STATIONS) ||
00063 (sect <= 0 || sect > MAX_SECTORS) ||
00064 (subs <= 0 || subs > MAX_SUBSECTORS) ||
00065 (cham <= 0 || stat > MAX_CHAMBERS)) {
00066 edm::LogError("L1CSCTPEmulatorSetupError")
00067 << "+++ trying to instantiate TMB of illegal CSC id ["
00068 << " endcap = " << endc << " station = " << stat
00069 << " sector = " << sect << " subsector = " << subs
00070 << " chamber = " << cham << "]; skipping it... +++\n";
00071 continue;
00072 }
00073
00074
00075 tmb_[endc-1][stat-1][sect-1][subs-1][cham-1] =
00076 new CSCMotherboard(endc, stat, sect, subs, cham, conf);
00077 }
00078 }
00079 }
00080 }
00081 }
00082
00083
00084 m_minBX = conf.getParameter<int>("MinBX");
00085 m_maxBX = conf.getParameter<int>("MaxBX");
00086
00087
00088 m_muonportcard = new CSCMuonPortCard();
00089 }
00090
00091
00092
00093
00094 CSCTriggerPrimitivesBuilder::~CSCTriggerPrimitivesBuilder() {
00095 for (int endc = min_endcap; endc <= max_endcap; endc++) {
00096 for (int stat = min_station; stat <= max_station; stat++) {
00097 int numsubs = ((stat == 1) ? max_subsector : 1);
00098 for (int sect = min_sector; sect <= max_sector; sect++) {
00099 for (int subs = min_subsector; subs <= numsubs; subs++) {
00100 for (int cham = min_chamber; cham <= max_chamber; cham++) {
00101 delete tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00102 }
00103 }
00104 }
00105 }
00106 }
00107 delete m_muonportcard;
00108 }
00109
00110
00111
00112
00113
00114 void CSCTriggerPrimitivesBuilder::setConfigParameters(const CSCDBL1TPParameters* conf) {
00115
00116
00117 for (int endc = min_endcap; endc <= max_endcap; endc++) {
00118 for (int stat = min_station; stat <= max_station; stat++) {
00119 int numsubs = ((stat == 1) ? max_subsector : 1);
00120 for (int sect = min_sector; sect <= max_sector; sect++) {
00121 for (int subs = min_subsector; subs <= numsubs; subs++) {
00122 for (int cham = min_chamber; cham <= max_chamber; cham++) {
00123 CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00124 tmb->setConfigParameters(conf);
00125 }
00126 }
00127 }
00128 }
00129 }
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 void CSCTriggerPrimitivesBuilder::build(const CSCBadChambers* badChambers,
00142 const CSCWireDigiCollection* wiredc,
00143 const CSCComparatorDigiCollection* compdc,
00144 CSCALCTDigiCollection& oc_alct,
00145 CSCCLCTDigiCollection& oc_clct,
00146 CSCCLCTPreTriggerCollection & oc_pretrig,
00147 CSCCorrelatedLCTDigiCollection& oc_lct,
00148 CSCCorrelatedLCTDigiCollection& oc_sorted_lct) {
00149
00150 CSCTriggerGeomManager* theGeom = CSCTriggerGeometry::get();
00151
00152 for (int endc = min_endcap; endc <= max_endcap; endc++) {
00153 for (int stat = min_station; stat <= max_station; stat++) {
00154 int numsubs = ((stat == 1) ? max_subsector : 1);
00155 for (int sect = min_sector; sect <= max_sector; sect++) {
00156 for (int subs = min_subsector; subs <= numsubs; subs++) {
00157 for (int cham = min_chamber; cham <= max_chamber; cham++) {
00158 CSCMotherboard* tmb = tmb_[endc-1][stat-1][sect-1][subs-1][cham-1];
00159
00160
00161 if (tmb != 0 &&
00162 theGeom->chamber(endc, stat, sect, subs, cham) != 0) {
00163
00164
00165 int ring =
00166 CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
00167 int chid =
00168 CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs,
00169 stat, cham);
00170
00171 CSCDetId detid(endc, stat, ring, chid, 0);
00172
00173
00174 if (badChambers->isInBadChamber(detid)) continue;
00175
00176 std::vector<CSCCorrelatedLCTDigi> lctV = tmb->run(wiredc,compdc);
00177
00178 std::vector<CSCALCTDigi> alctV = tmb->alct->readoutALCTs();
00179 std::vector<CSCCLCTDigi> clctV = tmb->clct->readoutCLCTs();
00180 std::vector<int> preTriggerBXs = tmb->clct->preTriggerBXs();
00181
00182
00183 if (alctV.empty() && clctV.empty() && lctV.empty()) continue;
00184
00185
00186 if (!lctV.empty()) {
00187 LogTrace("L1CSCTrigger")
00188 << "Put " << lctV.size() << " LCT digi"
00189 << ((lctV.size() > 1) ? "s " : " ") << "in collection\n";
00190 oc_lct.put(std::make_pair(lctV.begin(),lctV.end()), detid);
00191 }
00192
00193
00194 if (!alctV.empty()) {
00195 LogTrace("L1CSCTrigger")
00196 << "Put " << alctV.size() << " ALCT digi"
00197 << ((alctV.size() > 1) ? "s " : " ") << "in collection\n";
00198 oc_alct.put(std::make_pair(alctV.begin(),alctV.end()), detid);
00199 }
00200
00201
00202 if (!clctV.empty()) {
00203 LogTrace("L1CSCTrigger")
00204 << "Put " << clctV.size() << " CLCT digi"
00205 << ((clctV.size() > 1) ? "s " : " ") << "in collection\n";
00206 oc_clct.put(std::make_pair(clctV.begin(),clctV.end()), detid);
00207 }
00208
00209
00210 if (!preTriggerBXs.empty()) {
00211 LogTrace("L1CSCTrigger")
00212 << "Put " << preTriggerBXs.size() << " CLCT pretriggers"
00213 << ((preTriggerBXs.size() > 1) ? "s " : " ") << "in collection\n";
00214 oc_pretrig.put(std::make_pair(preTriggerBXs.begin(),preTriggerBXs.end()), detid);
00215 }
00216 }
00217 }
00218 }
00219 }
00220 }
00221 }
00222
00223
00224 m_muonportcard->loadDigis(oc_lct);
00225
00226 std::vector<csctf::TrackStub> result;
00227 for(int bx = m_minBX; bx <= m_maxBX; ++bx)
00228 for(int e = min_endcap; e <= max_endcap; ++e)
00229 for(int st = min_station; st <= max_station; ++st)
00230 for(int se = min_sector; se <= max_sector; ++se)
00231 {
00232 if(st == 1)
00233 {
00234 std::vector<csctf::TrackStub> subs1, subs2;
00235 subs1 = m_muonportcard->sort(e, st, se, 1, bx);
00236 subs2 = m_muonportcard->sort(e, st, se, 2, bx);
00237 result.insert(result.end(), subs1.begin(), subs1.end());
00238 result.insert(result.end(), subs2.begin(), subs2.end());
00239 }
00240 else
00241 {
00242 std::vector<csctf::TrackStub> sector;
00243 sector = m_muonportcard->sort(e, st, se, 0, bx);
00244 result.insert(result.end(), sector.begin(), sector.end());
00245 }
00246 }
00247
00248 std::vector<csctf::TrackStub>::const_iterator itr = result.begin();
00249 for (; itr != result.end(); itr++) {
00250 oc_sorted_lct.insertDigi(CSCDetId(itr->getDetId().rawId()), *(itr->getDigi()));
00251 LogDebug("L1CSCTrigger")
00252 << "MPC " << *(itr->getDigi()) << " found in ME"
00253 << ((itr->endcap() == 1) ? "+" : "-") << itr->station() << "/"
00254 << CSCDetId(itr->getDetId().rawId()).ring() << "/"
00255 << CSCDetId(itr->getDetId().rawId()).chamber()
00256 << " (sector " << itr->sector()
00257 << " trig id. " << itr->cscid() << ")" << "\n";
00258 }
00259 }