00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
00002
00003 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCand.h"
00004
00005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetFinderBase.h"
00006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctTdrJetFinder.h"
00007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHardwareJetFinder.h"
00008
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010
00011
00012 const int L1GctJetLeafCard::MAX_JET_FINDERS = 3;
00013
00014 L1GctJetLeafCard::L1GctJetLeafCard(int id, int iphi, jetFinderType jfType):
00015 L1GctProcessor(),
00016 m_id(id),
00017 m_whichJetFinder(jfType),
00018 phiPosition(iphi),
00019 m_exSum(0), m_eySum(0),
00020 m_hxSum(0), m_hySum(0),
00021 m_etSum(0), m_htSum(0),
00022 m_hfSums(),
00023 m_exSumPipe(), m_eySumPipe(),
00024 m_hxSumPipe(), m_hySumPipe(),
00025 m_etSumPipe(), m_htSumPipe(),
00026 m_hfSumsPipe(),
00027 m_ctorInputOk(true)
00028 {
00029
00030 if(m_id < 0 || m_id > 5)
00031 {
00032 m_ctorInputOk = false;
00033 if (m_verbose) {
00034 edm::LogWarning("L1GctSetupError")
00035 << "L1GctJetLeafCard::L1GctJetLeafCard() : Jet Leaf Card ID " << m_id << " has been incorrectly constructed!\n"
00036 << "ID number should be between the range of 0 to 5\n";
00037 }
00038 }
00039
00040
00041 if(phiPosition != m_id%3)
00042 {
00043 m_ctorInputOk = false;
00044 if (m_verbose) {
00045 edm::LogWarning("L1GctSetupError")
00046 << "L1GctJetLeafCard::L1GctJetLeafCard() : Jet Leaf Card ID " << m_id << " has been incorrectly constructed!\n"
00047 << "Argument iphi is " << phiPosition << ", should be " << (m_id%3) << " for this ID value \n";
00048 }
00049 }
00050
00051 switch (m_whichJetFinder) {
00052 case tdrJetFinder :
00053 m_jetFinderA = new L1GctTdrJetFinder( 3*id );
00054 m_jetFinderB = new L1GctTdrJetFinder(3*id+1);
00055 m_jetFinderC = new L1GctTdrJetFinder(3*id+2);
00056 break;
00057
00058 case hardwareJetFinder :
00059 m_jetFinderA = new L1GctHardwareJetFinder( 3*id );
00060 m_jetFinderB = new L1GctHardwareJetFinder(3*id+1);
00061 m_jetFinderC = new L1GctHardwareJetFinder(3*id+2);
00062 break;
00063
00064 default :
00065
00066 m_ctorInputOk = false;
00067 if (m_verbose) {
00068 edm::LogWarning("L1GctSetupError")
00069 << "L1GctJetLeafCard::L1GctJetLeafCard() : Jet Leaf Card ID " << m_id << " has been incorrectly constructed!\n"
00070 << "Unrecognised jetFinder type " << m_whichJetFinder << ", cannot setup jetFinders\n";
00071 }
00072
00073 }
00074
00075 if (!m_ctorInputOk && m_verbose) {
00076 edm::LogError("L1GctSetupError") << "Jet Leaf Card ID " << m_id << " has been incorrectly constructed";
00077 }
00078 }
00079
00080 L1GctJetLeafCard::~L1GctJetLeafCard()
00081 {
00082 delete m_jetFinderA;
00083 delete m_jetFinderB;
00084 delete m_jetFinderC;
00085 }
00086
00088 void L1GctJetLeafCard::setNeighbourLeafCards(std::vector<L1GctJetLeafCard*> neighbours)
00089 {
00090 std::vector<L1GctJetFinderBase*> jfNeighbours(2);
00091
00092 if (neighbours.size()==2) {
00093
00094 jfNeighbours.at(0) = neighbours.at(0)->getJetFinderC();
00095 jfNeighbours.at(1) = m_jetFinderB;
00096 m_jetFinderA->setNeighbourJetFinders(jfNeighbours);
00097
00098 jfNeighbours.at(0) = m_jetFinderA;
00099 jfNeighbours.at(1) = m_jetFinderC;
00100 m_jetFinderB->setNeighbourJetFinders(jfNeighbours);
00101
00102 jfNeighbours.at(0) = m_jetFinderB;
00103 jfNeighbours.at(1) = neighbours.at(1)->getJetFinderA();
00104 m_jetFinderC->setNeighbourJetFinders(jfNeighbours);
00105
00106 } else {
00107 m_ctorInputOk = false;
00108 if (m_verbose) {
00109 edm::LogWarning("L1GctSetupError")
00110 << "L1GctJetLeafCard::setNeighbourLeafCards() : In Jet Leaf Card ID " << m_id
00111 << " size of input vector should be 2, but is in fact " << neighbours.size() << "\n";
00112 }
00113 }
00114 }
00115
00116 std::ostream& operator << (std::ostream& s, const L1GctJetLeafCard& card)
00117 {
00118 using std::endl;
00119
00120 s << "===L1GctJetLeafCard===" << endl;
00121 s << "ID = " << card.m_id << endl;
00122 s << "i_phi = " << card.phiPosition << endl;;
00123 s << "Ex " << card.m_exSum << endl;
00124 s << "Ey " << card.m_eySum << endl;
00125 s << "Hx " << card.m_hxSum << endl;
00126 s << "Hy " << card.m_hySum << endl;
00127 s << "Et " << card.m_etSum << endl;
00128 s << "Ht " << card.m_htSum << endl;
00129 s << "JetFinder A : " << endl << (*card.m_jetFinderA);
00130 s << "JetFinder B : " << endl << (*card.m_jetFinderB);
00131 s << "JetFinder C : " << endl << (*card.m_jetFinderC);
00132 s << endl;
00133
00134 return s;
00135 }
00136
00138 void L1GctJetLeafCard::reset() {
00139 L1GctProcessor::reset();
00140 m_jetFinderA->reset();
00141 m_jetFinderB->reset();
00142 m_jetFinderC->reset();
00143 }
00144
00146 void L1GctJetLeafCard::setBxRange(const int firstBx, const int numberOfBx) {
00147 L1GctProcessor::setBxRange(firstBx, numberOfBx);
00148 m_jetFinderA->setBxRange(firstBx, numberOfBx);
00149 m_jetFinderB->setBxRange(firstBx, numberOfBx);
00150 m_jetFinderC->setBxRange(firstBx, numberOfBx);
00151 }
00152
00153 void L1GctJetLeafCard::setNextBx(const int bx) {
00154 L1GctProcessor::setNextBx(bx);
00155 m_jetFinderA->setNextBx(bx);
00156 m_jetFinderB->setNextBx(bx);
00157 m_jetFinderC->setNextBx(bx);
00158 }
00159
00160 void L1GctJetLeafCard::resetProcessor()
00161 {
00162 m_exSum.reset();
00163 m_eySum.reset();
00164 m_hxSum.reset();
00165 m_hySum.reset();
00166 m_etSum.reset();
00167 m_htSum.reset();
00168 m_hfSums.reset();
00169 }
00170
00171 void L1GctJetLeafCard::resetPipelines()
00172 {
00173 m_exSumPipe.reset(numOfBx());
00174 m_eySumPipe.reset(numOfBx());
00175 m_hxSumPipe.reset(numOfBx());
00176 m_hySumPipe.reset(numOfBx());
00177 m_etSumPipe.reset(numOfBx());
00178 m_htSumPipe.reset(numOfBx());
00179 m_hfSumsPipe.reset(numOfBx());
00180 }
00181
00182 void L1GctJetLeafCard::fetchInput() {
00183 m_jetFinderA->fetchInput();
00184 m_jetFinderB->fetchInput();
00185 m_jetFinderC->fetchInput();
00186 }
00187
00188 void L1GctJetLeafCard::process() {
00189
00190
00191 if (setupOk()) {
00192
00193
00194 m_jetFinderA->process();
00195 m_jetFinderB->process();
00196 m_jetFinderC->process();
00197
00198
00199
00200 std::vector< etTotalType > etStripSum(6);
00201 etStripSum.at(0) = m_jetFinderA->getEtStrip0();
00202 etStripSum.at(1) = m_jetFinderA->getEtStrip1();
00203 etStripSum.at(2) = m_jetFinderB->getEtStrip0();
00204 etStripSum.at(3) = m_jetFinderB->getEtStrip1();
00205 etStripSum.at(4) = m_jetFinderC->getEtStrip0();
00206 etStripSum.at(5) = m_jetFinderC->getEtStrip1();
00207
00208 m_etSum.reset();
00209 m_exSum.reset();
00210 m_eySum.reset();
00211
00212 for (unsigned i=0; i<6; ++i) {
00213 m_etSum = m_etSum + etStripSum.at(i);
00214 }
00215
00216 for (unsigned i=0; i<3; ++i) {
00217 unsigned jphi = 2*(phiPosition*3+i);
00218 m_exSum = m_exSum + exComponent(etStripSum.at(2*i), etStripSum.at(2*i+1), jphi);
00219 m_eySum = m_eySum + eyComponent(etStripSum.at(2*i), etStripSum.at(2*i+1), jphi);
00220 }
00221
00222
00223
00224 std::vector< etTotalType > htStripSum(6);
00225 htStripSum.at(0) = m_jetFinderA->getHtStrip0();
00226 htStripSum.at(1) = m_jetFinderA->getHtStrip1();
00227 htStripSum.at(2) = m_jetFinderB->getHtStrip0();
00228 htStripSum.at(3) = m_jetFinderB->getHtStrip1();
00229 htStripSum.at(4) = m_jetFinderC->getHtStrip0();
00230 htStripSum.at(5) = m_jetFinderC->getHtStrip1();
00231
00232 m_htSum.reset();
00233 m_hxSum.reset();
00234 m_hySum.reset();
00235
00236 for (unsigned i=0; i<6; ++i) {
00237 m_htSum = m_htSum + htStripSum.at(i);
00238 }
00239
00240 for (unsigned i=0; i<3; ++i) {
00241 unsigned jphi = 2*(phiPosition*3+i);
00242 m_hxSum = m_hxSum + exComponent(htStripSum.at(2*i), htStripSum.at(2*i+1), jphi);
00243 m_hySum = m_hySum + eyComponent(htStripSum.at(2*i), htStripSum.at(2*i+1), jphi);
00244 }
00245
00246 m_hfSums =
00247 m_jetFinderA->getHfSums() +
00248 m_jetFinderB->getHfSums() +
00249 m_jetFinderC->getHfSums();
00250
00251
00252 m_exSumPipe.store (m_exSum, bxRel());
00253 m_eySumPipe.store (m_eySum, bxRel());
00254 m_hxSumPipe.store (m_hxSum, bxRel());
00255 m_hySumPipe.store (m_hySum, bxRel());
00256 m_etSumPipe.store (m_etSum, bxRel());
00257 m_htSumPipe.store (m_htSum, bxRel());
00258 m_hfSumsPipe.store (m_hfSums, bxRel());
00259 }
00260 }
00261
00262 bool L1GctJetLeafCard::setupOk() const {
00263 return (m_ctorInputOk &&
00264 m_jetFinderA->setupOk() &&
00265 m_jetFinderB->setupOk() &&
00266 m_jetFinderC->setupOk()); }
00267
00268
00269 L1GctJetFinderBase::JetVector
00270 L1GctJetLeafCard::getOutputJetsA() const { return m_jetFinderA->getJets(); }
00271 L1GctJetFinderBase::JetVector
00272 L1GctJetLeafCard::getOutputJetsB() const { return m_jetFinderB->getJets(); }
00273 L1GctJetFinderBase::JetVector
00274 L1GctJetLeafCard::getOutputJetsC() const { return m_jetFinderC->getJets(); }
00275
00276
00277
00278
00279
00280 L1GctJetLeafCard::etComponentType
00281 L1GctJetLeafCard::exComponent(const L1GctJetLeafCard::etTotalType etStrip0,
00282 const L1GctJetLeafCard::etTotalType etStrip1,
00283 const unsigned jphi) const {
00284 unsigned fact0 = (2*jphi+6) % 36;
00285 unsigned fact1 = (2*jphi+8) % 36;
00286 return etValueForJetFinder(etStrip0, fact0, etStrip1, fact1);
00287 }
00288
00289 L1GctJetLeafCard::etComponentType
00290 L1GctJetLeafCard::eyComponent(const L1GctJetLeafCard::etTotalType etStrip0,
00291 const L1GctJetLeafCard::etTotalType etStrip1,
00292 const unsigned jphi) const {
00293 unsigned fact0 = (2*jphi+15) % 36;
00294 unsigned fact1 = (2*jphi+17) % 36;
00295 return etValueForJetFinder(etStrip0, fact0, etStrip1, fact1);
00296 }
00297
00298
00299
00300
00301 L1GctJetLeafCard::etComponentType
00302 L1GctJetLeafCard::etValueForJetFinder(const etTotalType etStrip0, const unsigned fact0,
00303 const etTotalType etStrip1, const unsigned fact1) const{
00304
00305
00306 const int factors[19] = {0xfffc001, 0xfffc0fa, 0xfffc3dd, 0xfffc894, 0xfffcefa,
00307 0xfffd6dd, 0xfffe000, 0xfffea1d, 0xffff4e3, 0x0000000,
00308 0x0000b1d, 0x00015e3, 0x0002000, 0x0002923, 0x0003106,
00309 0x000376c, 0x0003c23, 0x0003f06, 0x0003fff};
00310
00311 static const int internalComponentSize=15;
00312 static const int maxEt=1<<internalComponentSize;
00313
00314 int rotatedValue0, rotatedValue1, myFact;
00315 int etComponentSum = 0;
00316
00317 if (fact0 >= 36 || fact1 >= 36) {
00318 if (m_verbose) {
00319 edm::LogError("L1GctProcessingError")
00320 << "L1GctJetLeafCard::rotateEtValue() has been called with factor numbers "
00321 << fact0 << " and " << fact1 << "; should be less than 36 \n";
00322 }
00323 } else {
00324
00325
00326 if (fact0>18) { myFact = factors[(36-fact0)]; }
00327 else { myFact = factors[fact0]; }
00328
00329
00330 rotatedValue0 = static_cast<int>(etStrip0.value()) * myFact;
00331
00332
00333 if (fact1>18) { myFact = factors[(36-fact1)]; }
00334 else { myFact = factors[fact1]; }
00335
00336
00337 rotatedValue1 = static_cast<int>(etStrip1.value()) * myFact;
00338
00339
00340
00341
00342
00343
00344
00345 etComponentSum = ((rotatedValue0 + rotatedValue1) + 0x1000)>>13;
00346
00347 etComponentSum = etComponentSum & (maxEt-1);
00348 if (etComponentSum >= (maxEt/2)) {
00349 etComponentSum = etComponentSum - maxEt;
00350 }
00351 }
00352
00353
00354 etComponentType temp(etComponentSum);
00355 temp.setOverFlow(temp.overFlow() || etStrip0.overFlow() || etStrip1.overFlow());
00356 return temp;
00357 }