00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetFinderBase.h"
00006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
00007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetSorter.h"
00008
00009
00010 const int L1GctWheelJetFpga::MAX_JETS_OUT = 4;
00011 const unsigned int L1GctWheelJetFpga::MAX_LEAF_CARDS = 3;
00012 const unsigned int L1GctWheelJetFpga::MAX_JETS_PER_LEAF = L1GctJetLeafCard::MAX_JET_FINDERS * L1GctJetFinderBase::MAX_JETS_OUT;
00013 const int L1GctWheelJetFpga::MAX_JETS_IN = L1GctWheelJetFpga::MAX_LEAF_CARDS * L1GctWheelJetFpga::MAX_JETS_PER_LEAF;
00014
00015 L1GctWheelJetFpga::L1GctWheelJetFpga(int id,
00016 std::vector<L1GctJetLeafCard*> inputLeafCards) :
00017 L1GctProcessor(),
00018 m_id(id),
00019 m_inputLeafCards(inputLeafCards),
00020 m_centralJetSorter(new L1GctJetSorter()),
00021 m_forwardJetSorter(new L1GctJetSorter()),
00022 m_tauJetSorter(new L1GctJetSorter()),
00023 m_inputJets(MAX_JETS_IN),
00024 m_rawCentralJets(MAX_JETS_IN),
00025 m_rawForwardJets(MAX_JETS_IN),
00026 m_rawTauJets(MAX_JETS_IN),
00027 m_inputHx(MAX_LEAF_CARDS),
00028 m_inputHy(MAX_LEAF_CARDS),
00029 m_inputHfSums(MAX_LEAF_CARDS),
00030 m_centralJets(MAX_JETS_OUT),
00031 m_forwardJets(MAX_JETS_OUT),
00032 m_tauJets(MAX_JETS_OUT),
00033 m_outputHx(0), m_outputHy(0), m_outputHfSums(),
00034 m_outputHxPipe(), m_outputHyPipe()
00035 {
00036 if (checkSetup()) {
00037
00038 setupJetsVectors(0);
00039
00040 } else {
00041 if (m_verbose) {
00042 edm::LogError("L1GctSetupError") << "L1GctWheelJetFpga has been incorrectly constructed";
00043 }
00044 }
00045 }
00046
00047 bool L1GctWheelJetFpga::checkSetup() const
00048 {
00049 bool result=true;
00050
00051
00052 if(m_id < 0 || m_id > 1)
00053 {
00054 result = false;
00055 if (m_verbose) {
00056 edm::LogWarning("L1GctSetupError")
00057 << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00058 << "ID number should be between the range of 0 to 1\n";
00059 }
00060 }
00061
00062 if(m_inputLeafCards.size() != MAX_LEAF_CARDS)
00063 {
00064 result = false;
00065 if (m_verbose) {
00066 edm::LogWarning("L1GctSetupError")
00067 << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00068 << "This class needs " << MAX_LEAF_CARDS << " jet leaf card pointers, yet only " << m_inputLeafCards.size()
00069 << " leaf card pointers are present.\n";
00070 }
00071 }
00072
00073 for(unsigned int i = 0; i < MAX_LEAF_CARDS; ++i)
00074 {
00075 if(m_inputLeafCards.at(i) == 0)
00076 {
00077 result = false;
00078 if (m_verbose) {
00079 edm::LogWarning("L1GctSetupError")
00080 << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00081 << "Leaf card pointer " << i << " has not been set!\n";
00082 }
00083 }
00084 }
00085 return result;
00086 }
00087
00088 L1GctWheelJetFpga::~L1GctWheelJetFpga()
00089 {
00090 if (m_centralJetSorter != 0) delete m_centralJetSorter;
00091 if (m_forwardJetSorter != 0) delete m_forwardJetSorter;
00092 if (m_tauJetSorter != 0) delete m_tauJetSorter;
00093 }
00094
00095 std::ostream& operator << (std::ostream& os, const L1GctWheelJetFpga& fpga)
00096 {
00097 using std::endl;
00098 os << "===L1GctWheelJetFPGA===" << endl;
00099 os << "ID = " << fpga.m_id << endl;
00100 os << "No of Input Leaf Cards " << fpga.m_inputLeafCards.size() << endl;
00101 for(unsigned i=0; i < fpga.m_inputLeafCards.size(); i++)
00102 {
00103 os << "InputLeafCard* " << i << " = " << fpga.m_inputLeafCards.at(i) << endl;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 os << endl;
00141 return os;
00142 }
00143
00144 void L1GctWheelJetFpga::resetProcessor()
00145 {
00146 for (unsigned int i=0; i<MAX_LEAF_CARDS; ++i)
00147 {
00148 m_inputHx.at(i).reset();
00149 m_inputHy.at(i).reset();
00150 m_inputHfSums.at(i).reset();
00151 }
00152 m_outputHx.reset();
00153 m_outputHy.reset();
00154 m_outputHfSums.reset();
00155 }
00156
00157 void L1GctWheelJetFpga::setupObjects()
00158 {
00159 setupJetsVectors(static_cast<int16_t>(bxAbs()));
00160 }
00161
00162 void L1GctWheelJetFpga::resetPipelines()
00163 {
00164 m_outputHxPipe.reset(numOfBx());
00165 m_outputHyPipe.reset(numOfBx());
00166 }
00167
00168 void L1GctWheelJetFpga::fetchInput()
00169 {
00170 if (checkSetup()) {
00171
00172 for(unsigned short iLeaf = 0; iLeaf < MAX_LEAF_CARDS; ++iLeaf)
00173 {
00174 if (m_inputLeafCards.at(iLeaf) != 0) {
00175
00176 storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsA(), iLeaf, 0);
00177 storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsB(), iLeaf, L1GctJetFinderBase::MAX_JETS_OUT);
00178 storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsC(), iLeaf, 2*L1GctJetFinderBase::MAX_JETS_OUT);
00179
00180
00181 m_inputHx.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHx();
00182 m_inputHy.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHy();
00183
00184
00185 m_inputHfSums.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHfSums();
00186 }
00187 }
00188 }
00189 }
00190
00191 void L1GctWheelJetFpga::process()
00192 {
00193 if (checkSetup()) {
00194 classifyJets();
00195
00196 m_centralJetSorter->setJets(m_rawCentralJets);
00197 m_forwardJetSorter->setJets(m_rawForwardJets);
00198 m_tauJetSorter->setJets(m_rawTauJets);
00199
00200 m_rawCentralJets = m_centralJetSorter->getSortedJets();
00201 m_rawForwardJets = m_forwardJetSorter->getSortedJets();
00202 m_rawTauJets = m_tauJetSorter->getSortedJets();
00203
00204 for(unsigned short iJet = 0; iJet < MAX_JETS_OUT; ++iJet)
00205 {
00206 m_centralJets.at(iJet) = m_rawCentralJets.at(iJet);
00207 m_forwardJets.at(iJet) = m_rawForwardJets.at(iJet);
00208 m_tauJets.at(iJet) = m_rawTauJets.at(iJet);
00209 }
00210
00211
00212 m_outputHx = m_inputHx.at(0) + m_inputHx.at(1) + m_inputHx.at(2);
00213 m_outputHy = m_inputHy.at(0) + m_inputHy.at(1) + m_inputHy.at(2);
00214
00215
00216 m_outputHfSums = m_inputHfSums.at(0) + m_inputHfSums.at(1) + m_inputHfSums.at(2);
00217
00218 m_outputHxPipe.store( m_outputHx, bxRel());
00219 m_outputHyPipe.store( m_outputHy, bxRel());
00220 }
00221
00222 }
00223
00224 void L1GctWheelJetFpga::setInputJet(int i, L1GctJetCand jet)
00225 {
00226 if(i >=0 && i < MAX_JETS_IN)
00227 {
00228 m_inputJets.at(i) = jet;
00229 }
00230 else
00231 {
00232 if (m_verbose) {
00233 edm::LogError("L1GctInputError")
00234 << "L1GctWheelJetFpga::setInputJet() : In WheelJetFpga ID " << m_id << ", inputted jet candidate "
00235 << i << " is outside input index range of 0 to " << (MAX_JETS_IN-1) << "\n";
00236 }
00237 }
00238 }
00239
00241 std::vector< L1GctInternHtMiss > L1GctWheelJetFpga::getInternalHtMiss() const
00242 {
00243
00244 std::vector< L1GctInternHtMiss > result;
00245 for (int bx=0; bx<numOfBx(); bx++) {
00246 result.push_back( L1GctInternHtMiss::emulatorMissHtx( m_outputHxPipe.contents.at(bx).value(),
00247 m_outputHxPipe.contents.at(bx).overFlow(),
00248 static_cast<int16_t> (bx-bxMin()) ) );
00249 result.push_back( L1GctInternHtMiss::emulatorMissHty( m_outputHyPipe.contents.at(bx).value(),
00250 m_outputHyPipe.contents.at(bx).overFlow(),
00251 static_cast<int16_t> (bx-bxMin()) ) );
00252 }
00253 return result;
00254 }
00255
00256 void L1GctWheelJetFpga::storeJets(JetVector jets, unsigned short iLeaf, unsigned short offset)
00257 {
00258 for(unsigned short iJet = 0; iJet < L1GctJetFinderBase::MAX_JETS_OUT; ++iJet)
00259 {
00260 m_inputJets.at(iLeaf*MAX_JETS_PER_LEAF + offset + iJet) = jets.at(iJet);
00261 }
00262 }
00263
00264 void L1GctWheelJetFpga::classifyJets()
00265 {
00266 JetVector::iterator currentJet;
00267
00268 unsigned short pos=0;
00269
00270
00271
00272 for(currentJet = m_inputJets.begin(); currentJet != m_inputJets.end(); ++currentJet, ++pos)
00273 {
00274 if (!currentJet->empty()) {
00275 if(currentJet->isForward())
00276 {
00277 m_rawForwardJets.at(pos) = *currentJet;
00278 }
00279 else
00280 {
00281 if(currentJet->isCentral())
00282 {
00283 m_rawCentralJets.at(pos) = *currentJet;
00284 }
00285 else
00286 {
00287 if(currentJet->isTau())
00288 {
00289 m_rawTauJets.at(pos) = *currentJet;
00290 }
00291 else
00292 {
00293 if (m_verbose) {
00294 edm::LogWarning("L1GctProcessingError")
00295 << "Unclassified jet found by WheelJetFpga id " << m_id
00296 << ". Jet details follow." << std::endl << *currentJet << std::endl;
00297 }
00298 }
00299 }
00300 }
00301 }
00302 }
00303 }
00304
00305 void L1GctWheelJetFpga::setupJetsVectors(const int16_t bx)
00306 {
00307
00308
00309 L1GctJetCand tempCen(0, 0, 0, false, false, (uint16_t) 0, (uint16_t) 0, bx);
00310 L1GctJetCand tempTau(0, 0, 0, true, false, (uint16_t) 0, (uint16_t) 0, bx);
00311 L1GctJetCand tempFwd(0, 0, 0, false, true, (uint16_t) 0, (uint16_t) 0, bx);
00312
00313
00314 m_rawCentralJets.assign(MAX_JETS_IN, tempCen);
00315 m_rawTauJets.assign (MAX_JETS_IN, tempTau);
00316 m_rawForwardJets.assign(MAX_JETS_IN, tempFwd);
00317
00318 m_centralJets.assign(MAX_JETS_OUT, tempCen);
00319 m_tauJets.assign (MAX_JETS_OUT, tempTau);
00320 m_forwardJets.assign(MAX_JETS_OUT, tempFwd);
00321 }