File indexing completed on 2024-04-06 12:19:32
0001 #include <L1Trigger/CSCTrackFinder/src/CSCTFTrackBuilder.h>
0002
0003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0004
0005 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0006 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
0007 #include <DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h>
0008
0009 #include <DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h>
0010 #include <L1Trigger/CSCTrackFinder/interface/CSCTFSectorProcessor.h>
0011
0012 #include "CondFormats/L1TObjects/interface/L1MuCSCTFConfiguration.h"
0013 #include "CondFormats/DataRecord/interface/L1MuCSCTFConfigurationRcd.h"
0014 #include <sstream>
0015 #include <cstdlib>
0016
0017 CSCTFTrackBuilder::CSCTFTrackBuilder(const edm::ParameterSet& pset,
0018 bool TMB07,
0019 const L1MuTriggerScales* scales,
0020 const L1MuTriggerPtScale* ptScale) {
0021 m_minBX = pset.getParameter<int>("MinBX");
0022 m_maxBX = pset.getParameter<int>("MaxBX");
0023
0024 for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e) {
0025 for (int s = CSCTriggerNumbering::minTriggerSectorId(); s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s) {
0026
0027 my_SPs[e - 1][s - 1] = new CSCTFSectorProcessor(e, s, pset, TMB07, scales, ptScale);
0028 }
0029 }
0030 }
0031
0032 void CSCTFTrackBuilder::initialize(const edm::EventSetup& c, const Tokens& tokens) {
0033
0034 for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e) {
0035 for (int s = CSCTriggerNumbering::minTriggerSectorId(); s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s) {
0036 my_SPs[e - 1][s - 1]->initialize(c, tokens);
0037 }
0038 }
0039 }
0040
0041 CSCTFTrackBuilder::~CSCTFTrackBuilder() {
0042 for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e) {
0043 for (int s = CSCTriggerNumbering::minTriggerSectorId(); s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s) {
0044 delete my_SPs[e - 1][s - 1];
0045 my_SPs[e - 1][s - 1] = nullptr;
0046 }
0047 }
0048 }
0049
0050 void CSCTFTrackBuilder::buildTracks(
0051 const CSCCorrelatedLCTDigiCollection* lcts,
0052 const CSCTriggerContainer<csctf::TrackStub>* dtstubss,
0053 L1CSCTrackCollection* trkcoll,
0054 CSCTriggerContainer<csctf::TrackStub>* stubs_to_dt) {
0055 std::vector<csc::L1Track> trks;
0056 CSCTriggerContainer<csctf::TrackStub> stub_list;
0057
0058 CSCCorrelatedLCTDigiCollection::DigiRangeIterator Citer;
0059
0060 for (Citer = lcts->begin(); Citer != lcts->end(); Citer++) {
0061 CSCCorrelatedLCTDigiCollection::const_iterator Diter = (*Citer).second.first;
0062 CSCCorrelatedLCTDigiCollection::const_iterator Dend = (*Citer).second.second;
0063
0064 for (; Diter != Dend; Diter++) {
0065 csctf::TrackStub theStub((*Diter), (*Citer).first);
0066 stub_list.push_back(theStub);
0067 }
0068 }
0069
0070
0071
0072
0073
0074
0075 stub_list.push_many(*dtstubss);
0076
0077
0078 for (int e = CSCDetId::minEndcapId(); e <= CSCDetId::maxEndcapId(); ++e) {
0079 for (int s = CSCTriggerNumbering::minTriggerSectorId(); s <= CSCTriggerNumbering::maxTriggerSectorId(); ++s) {
0080 CSCTriggerContainer<csctf::TrackStub> current_e_s = stub_list.get(e, s);
0081 int spReturnValue = my_SPs[e - 1][s - 1]->run(current_e_s);
0082 if (spReturnValue == -1)
0083 {
0084 trkcoll->clear();
0085 stubs_to_dt->clear();
0086 return;
0087 } else if (spReturnValue) {
0088 std::vector<csc::L1Track> theTracks = my_SPs[e - 1][s - 1]->tracks().get();
0089 trks.insert(trks.end(), theTracks.begin(), theTracks.end());
0090 }
0091 stubs_to_dt->push_many(my_SPs[e - 1][s - 1]->dtStubs());
0092 }
0093 }
0094
0095
0096 trkcoll->resize(trks.size());
0097 std::vector<csc::L1Track>::const_iterator titr = trks.begin();
0098 L1CSCTrackCollection::iterator tcitr = trkcoll->begin();
0099
0100 for (; titr != trks.end(); titr++) {
0101 tcitr->first = (*titr);
0102 std::vector<csctf::TrackStub> possible_stubs = my_SPs[titr->endcap() - 1][titr->sector() - 1]->filteredStubs();
0103 std::vector<csctf::TrackStub>::const_iterator tkstbs = possible_stubs.begin();
0104
0105 int me1ID = titr->me1ID();
0106 int me2ID = titr->me2ID();
0107 int me3ID = titr->me3ID();
0108 int me4ID = titr->me4ID();
0109 int mb1ID = titr->mb1ID();
0110 int me1delay = titr->me1Tbin();
0111 int me2delay = titr->me2Tbin();
0112 int me3delay = titr->me3Tbin();
0113 int me4delay = titr->me4Tbin();
0114 int mb1delay = titr->mb1Tbin();
0115
0116
0117
0118 std::map<int, std::list<int> > timeline;
0119 if (me1ID)
0120 timeline[me1delay].push_back(1);
0121 if (me2ID)
0122 timeline[me2delay].push_back(2);
0123 if (me3ID)
0124 timeline[me3delay].push_back(3);
0125 if (me4ID)
0126 timeline[me4delay].push_back(4);
0127 int earliest_tbin = 0, second_earliest_tbin = 0;
0128 for (int bx = 7; bx >= 0; bx--) {
0129 std::list<int>::const_iterator iter = timeline[bx].begin();
0130 while (iter != timeline[bx].end()) {
0131 if (earliest_tbin == 0)
0132 earliest_tbin = bx;
0133 else if (second_earliest_tbin == 0)
0134 second_earliest_tbin = bx;
0135 iter++;
0136 }
0137 }
0138
0139
0140 int shift = (m_maxBX + m_minBX) / 2 - m_minBX + m_minBX;
0141 int me1Tbin = titr->bx() - me1delay + second_earliest_tbin + shift;
0142 int me2Tbin = titr->bx() - me2delay + second_earliest_tbin + shift;
0143 int me3Tbin = titr->bx() - me3delay + second_earliest_tbin + shift;
0144 int me4Tbin = titr->bx() - me4delay + second_earliest_tbin + shift;
0145 int mb1Tbin = titr->bx() - mb1delay + second_earliest_tbin + shift;
0146
0147 for (; tkstbs != possible_stubs.end(); tkstbs++) {
0148 switch (tkstbs->station()) {
0149 case 1:
0150 if ((tkstbs->getMPCLink() +
0151 (3 * (CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId(tkstbs->getDetId().rawId())) - 1))) ==
0152 me1ID &&
0153 me1ID != 0 && me1Tbin == tkstbs->BX()) {
0154 tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
0155 }
0156 break;
0157 case 2:
0158 if (tkstbs->getMPCLink() == me2ID && me2ID != 0 && me2Tbin == tkstbs->BX()) {
0159 tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
0160 }
0161 break;
0162 case 3:
0163 if (tkstbs->getMPCLink() == me3ID && me3ID != 0 && me3Tbin == tkstbs->BX()) {
0164 tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
0165 }
0166 break;
0167 case 4:
0168 if (tkstbs->getMPCLink() == me4ID && me4ID != 0 && me4Tbin == tkstbs->BX()) {
0169 tcitr->second.insertDigi(CSCDetId(tkstbs->getDetId().rawId()), *(tkstbs->getDigi()));
0170 }
0171 break;
0172 case 5:
0173 if (tkstbs->getMPCLink() == mb1ID && mb1ID != 0 && mb1Tbin == tkstbs->BX()) {
0174
0175 }
0176 break;
0177 default:
0178 edm::LogWarning("CSCTFTrackBuilder::buildTracks()")
0179 << "SERIOUS ERROR: STATION " << tkstbs->station() << " NOT IN RANGE [1,5]\n";
0180 };
0181 }
0182 tcitr++;
0183 }
0184 }