CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/L1Trigger/GlobalCaloTrigger/src/L1GctGlobalEnergyAlgos.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalEnergyAlgos.h"
00002 
00003 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
00004 
00005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelEnergyFpga.h"
00006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 using std::ostream;
00012 using std::endl;
00013 using std::vector;
00014 using std::max;
00015 
00016 L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos(vector<L1GctWheelEnergyFpga*> wheelFpga,
00017                                                vector<L1GctWheelJetFpga*> wheelJetFpga) :
00018   L1GctProcessor(),
00019   m_plusWheelFpga(wheelFpga.at(1)),
00020   m_minusWheelFpga(wheelFpga.at(0)),
00021   m_plusWheelJetFpga(wheelJetFpga.at(1)),
00022   m_minusWheelJetFpga(wheelJetFpga.at(0)),
00023   m_metComponents(0,0, L1GctMet::cordicTranslate),
00024   m_mhtComponents(0,0, L1GctMet::useHtMissLut),
00025   m_exValPlusWheel(), m_eyValPlusWheel(),
00026   m_etValPlusWheel(), m_htValPlusWheel(),
00027   m_exVlMinusWheel(), m_eyVlMinusWheel(),
00028   m_etVlMinusWheel(), m_htVlMinusWheel(),
00029   m_exValPlusPipe(), m_eyValPlusPipe(),
00030   m_etValPlusPipe(), m_htValPlusPipe(),
00031   m_exVlMinusPipe(), m_eyVlMinusPipe(),
00032   m_etVlMinusPipe(), m_htVlMinusPipe(),
00033   m_outputEtMiss(), m_outputEtMissPhi(),
00034   m_outputEtSum(), m_outputEtHad(),
00035   m_setupOk(true)
00036 {
00037   if(wheelFpga.size() != 2)
00038     {
00039       m_setupOk = false;
00040       if (m_verbose) {
00041         edm::LogWarning("L1GctSetupError")
00042           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() : Global Energy Algos has been incorrectly constructed!\n"
00043           << "This class needs two wheel card pointers. "
00044           << "Number of wheel card pointers present is " << wheelFpga.size() << ".\n";
00045       }
00046     }
00047   
00048   if(wheelJetFpga.size() != 2)
00049     {
00050       m_setupOk = false;
00051       if (m_verbose) {
00052         edm::LogWarning("L1GctSetupError")
00053           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() : Global Energy Algos has been incorrectly constructed!\n"
00054           << "This class needs two wheel jet fpga pointers. "
00055           << "Number of wheel jet fpga pointers present is " << wheelJetFpga.size() << ".\n";
00056       }
00057     }
00058   
00059   if(m_plusWheelFpga == 0)
00060     {
00061       m_setupOk = false;
00062       if (m_verbose) {
00063         edm::LogWarning("L1GctSetupError")
00064           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00065           << "Plus Wheel Fpga pointer has not been set!\n";
00066       }
00067     }
00068   if(m_minusWheelFpga == 0)
00069     {
00070       m_setupOk = false;
00071       if (m_verbose) {
00072         edm::LogWarning("L1GctSetupError")
00073           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00074           << "Minus Wheel Fpga pointer has not been set!\n";
00075       }
00076     }
00077   if(m_plusWheelJetFpga == 0)
00078     {
00079       m_setupOk = false;
00080       if (m_verbose) {
00081         edm::LogWarning("L1GctSetupError")
00082           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00083           << "Plus Wheel Jet Fpga pointer has not been set!\n";
00084       }
00085     }
00086   if(m_minusWheelJetFpga == 0)
00087     {
00088       m_setupOk = false;
00089       if (m_verbose) {
00090         edm::LogWarning("L1GctSetupError")
00091           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00092           << "Minus Wheel Jet Fpga pointer has not been set!\n";
00093       }
00094     }
00095 
00096   // Set the scale for missing Et and missing Ht
00097   // Missing Et has one extra bit of precision added in the (Ex, Ey) 
00098   // conversion step, so we reverse this here.
00099   m_metComponents.setBitShift(1);
00100   // Missing Ht has its own bit shifting before the LUT, so we don't
00101   // need any extra
00102   m_mhtComponents.setBitShift(0);
00103 
00104   // Setup to perform the Hf sums
00105   m_hfSumProcessor = new L1GctGlobalHfSumAlgos(wheelJetFpga);
00106 
00107   m_setupOk &= m_hfSumProcessor->setupOk();
00108 
00109   if (!m_setupOk && m_verbose) {
00110     edm::LogError("L1GctSetupError") << "L1GctGlobalEnergyAlgos has been incorrectly constructed";
00111   }
00112 }
00113 
00114 L1GctGlobalEnergyAlgos::~L1GctGlobalEnergyAlgos()
00115 {
00116   if (m_hfSumProcessor != 0) {
00117     delete m_hfSumProcessor;
00118   }
00119 }
00120 
00121 ostream& operator << (ostream& os, const L1GctGlobalEnergyAlgos& fpga)
00122 {
00123   os << "===L1GctGlobalEnergyAlgos===" << endl;
00124   os << "WheelEnergyFpga* minus = " << fpga.m_minusWheelFpga << endl;
00125   os << "WheelEnergyFpga* plus  = " << fpga.m_plusWheelFpga << endl;
00126   os << "WheelJetFpga* minus = " << fpga.m_minusWheelJetFpga << endl;
00127   os << "WheelJetFpga* plus  = " << fpga.m_plusWheelJetFpga << endl;
00128   os << "Inputs from Plus wheel:" << endl;
00129   os << "  Ex " << fpga.m_exValPlusWheel << "\n  Ey " << fpga.m_eyValPlusWheel << endl;
00130   os << "  Et " << fpga.m_etValPlusWheel << "\n  Ht " << fpga.m_htValPlusWheel << endl; 
00131   os << "Inputs from Minus wheel:" << endl;
00132   os << "  Ex " << fpga.m_exVlMinusWheel << "\n  Ey " << fpga.m_eyVlMinusWheel << endl;
00133   os << "  Et " << fpga.m_etVlMinusWheel << "\n  Ht " << fpga.m_htVlMinusWheel << endl; 
00134   int bxZero = -fpga.bxMin();
00135   if (bxZero>=0 && bxZero<fpga.numOfBx()) {
00136     os << "Output Etmiss " << fpga.m_outputEtMiss.contents.at(bxZero) << endl;
00137     os << "Output Etmiss Phi " << fpga.m_outputEtMissPhi.contents.at(bxZero) << endl;
00138     os << "Output EtSum " << fpga.m_outputEtSum.contents.at(bxZero) << endl;
00139     os << "Output EtHad " << fpga.m_outputEtHad.contents.at(bxZero) << endl;
00140   }
00141   os << *fpga.m_hfSumProcessor;
00142 
00143   return os;
00144 }
00145 
00147 void L1GctGlobalEnergyAlgos::reset() {
00148   L1GctProcessor::reset();
00149   m_hfSumProcessor->reset();
00150 }
00151 
00153 void L1GctGlobalEnergyAlgos::setBxRange(const int firstBx, const int numberOfBx) {
00154   L1GctProcessor::setBxRange(firstBx, numberOfBx);
00155   m_hfSumProcessor->setBxRange(firstBx, numberOfBx);
00156 }
00157 
00158 void L1GctGlobalEnergyAlgos::setNextBx(const int bx) {
00159   L1GctProcessor::setNextBx(bx);
00160   m_hfSumProcessor->setNextBx(bx);
00161 }
00162 
00163 void L1GctGlobalEnergyAlgos::resetProcessor() {
00164   m_exValPlusWheel.reset();
00165   m_exVlMinusWheel.reset();
00166   m_eyValPlusWheel.reset();
00167   m_eyVlMinusWheel.reset();
00168   m_etValPlusWheel.reset();
00169   m_etVlMinusWheel.reset();
00170   m_htValPlusWheel.reset();
00171   m_htVlMinusWheel.reset();
00172   m_hxValPlusWheel.reset();
00173   m_hxVlMinusWheel.reset();
00174   m_hyValPlusWheel.reset();
00175   m_hyVlMinusWheel.reset();
00176 }
00177 
00178 void L1GctGlobalEnergyAlgos::resetPipelines() {
00179   m_outputEtMiss.reset    (numOfBx());
00180   m_outputEtMissPhi.reset (numOfBx());
00181   m_outputEtSum.reset     (numOfBx());
00182   m_outputEtHad.reset     (numOfBx());
00183   m_outputHtMiss.reset    (numOfBx());
00184   m_outputHtMissPhi.reset (numOfBx());
00185 
00186   m_exValPlusPipe.reset (numOfBx());
00187   m_eyValPlusPipe.reset (numOfBx());
00188   m_etValPlusPipe.reset (numOfBx());
00189   m_htValPlusPipe.reset (numOfBx());
00190   m_hxValPlusPipe.reset (numOfBx());
00191   m_hyValPlusPipe.reset (numOfBx());
00192 
00193   m_exVlMinusPipe.reset (numOfBx());
00194   m_eyVlMinusPipe.reset (numOfBx());
00195   m_etVlMinusPipe.reset (numOfBx());
00196   m_htVlMinusPipe.reset (numOfBx());
00197   m_hxVlMinusPipe.reset (numOfBx());
00198   m_hyVlMinusPipe.reset (numOfBx());
00199 
00200 }
00201 
00202 void L1GctGlobalEnergyAlgos::fetchInput() {
00203   if (m_setupOk) {
00204     // input from WheelEnergyFpgas
00205     m_exValPlusWheel = m_plusWheelFpga->getOutputEx();
00206     m_eyValPlusWheel = m_plusWheelFpga->getOutputEy();
00207     m_etValPlusWheel = m_plusWheelFpga->getOutputEt();
00208     m_htValPlusWheel = m_plusWheelFpga->getOutputHt();
00209     m_hxValPlusWheel = m_plusWheelJetFpga->getOutputHx();
00210     m_hyValPlusWheel = m_plusWheelJetFpga->getOutputHy();
00211   
00212     m_exVlMinusWheel = m_minusWheelFpga->getOutputEx();
00213     m_eyVlMinusWheel = m_minusWheelFpga->getOutputEy();
00214     m_etVlMinusWheel = m_minusWheelFpga->getOutputEt();
00215     m_htVlMinusWheel = m_minusWheelFpga->getOutputHt();
00216     m_hxVlMinusWheel = m_minusWheelJetFpga->getOutputHx();
00217     m_hyVlMinusWheel = m_minusWheelJetFpga->getOutputHy();
00218 
00219     m_hfSumProcessor->fetchInput();
00220   }
00221 }
00222 
00223 
00224 // process the event
00225 void L1GctGlobalEnergyAlgos::process()
00226 {
00227   if (m_setupOk) {
00228     // Store the inputs in pipelines
00229     m_exValPlusPipe.store(m_exValPlusWheel, bxRel());
00230     m_eyValPlusPipe.store(m_eyValPlusWheel, bxRel());
00231     m_etValPlusPipe.store(m_etValPlusWheel, bxRel());
00232     m_htValPlusPipe.store(m_htValPlusWheel, bxRel());
00233     m_hxValPlusPipe.store(m_hxValPlusWheel, bxRel());
00234     m_hyValPlusPipe.store(m_hyValPlusWheel, bxRel());
00235 
00236     m_exVlMinusPipe.store(m_exVlMinusWheel, bxRel());
00237     m_eyVlMinusPipe.store(m_eyVlMinusWheel, bxRel());
00238     m_etVlMinusPipe.store(m_etVlMinusWheel, bxRel());
00239     m_htVlMinusPipe.store(m_htVlMinusWheel, bxRel());
00240     m_hxVlMinusPipe.store(m_hxVlMinusWheel, bxRel());
00241     m_hyVlMinusPipe.store(m_hyVlMinusWheel, bxRel());
00242 
00243     // Process to produce the outputs
00244     etComponentType ExSum, EySum;
00245     etmiss_vec EtMissing, HtMissing;
00246 
00247     //
00248     //-----------------------------------------------------------------------------
00249     // Form the Ex and Ey sums
00250     ExSum = m_exValPlusWheel + m_exVlMinusWheel;
00251     EySum = m_eyValPlusWheel + m_eyVlMinusWheel;
00252     // Execute the missing Et algorithm
00253     // Rotate by pi to evaluate MISSING Et. 
00254     // Implement this in the same way as the firmware
00255     m_metComponents.setComponents(ExSum, EySum);
00256     EtMissing = m_metComponents.metVector();
00257     if (EtMissing.phi.value() > 35) {
00258       EtMissing.phi.setValue(EtMissing.phi.value() - 36);
00259     } else {
00260       EtMissing.phi.setValue(EtMissing.phi.value() + 36);
00261     }
00262     if (EtMissing.mag.value() == etMissMaxValue) EtMissing.mag.setOverFlow(true);
00263 
00264     m_outputEtMiss.store    (EtMissing.mag, bxRel());
00265     m_outputEtMissPhi.store (EtMissing.phi, bxRel());
00266 
00267     //
00268     //-----------------------------------------------------------------------------
00269     // Form the Hx and Hy sums
00270     ExSum = m_hxValPlusWheel + m_hxVlMinusWheel;
00271     EySum = m_hyValPlusWheel + m_hyVlMinusWheel;
00272     // Execute the missing Et algorithm
00273     // Implement this in the same way as the firmware
00274     m_mhtComponents.setComponents(ExSum, EySum);
00275     HtMissing = m_mhtComponents.metVector();
00276     if (HtMissing.phi.value() > 8) {
00277       HtMissing.phi.setValue(HtMissing.phi.value() - 9);
00278     } else {
00279       HtMissing.phi.setValue(HtMissing.phi.value() + 9);
00280     }
00281 
00282     // Store 7 bits of magnitude and 5 bits of phi angle.
00283     static const unsigned MAX_HT_VALUE = 0x7f;
00284     static const unsigned PHI_HT_MASK  = 0x1f;
00285     if ( (HtMissing.mag.value() > MAX_HT_VALUE) || (HtMissing.mag.overFlow()) ) {
00286       HtMissing.mag.setValue(MAX_HT_VALUE);
00287     }
00288     HtMissing.phi.setValue(HtMissing.phi.value() & PHI_HT_MASK);
00289     m_outputHtMiss.store    (HtMissing.mag, bxRel());
00290     m_outputHtMissPhi.store (HtMissing.phi, bxRel());
00291 
00292     //
00293     //-----------------------------------------------------------------------------
00294     // Form the Et and Ht sums
00295     etTotalType ettTemp = m_etValPlusWheel + m_etVlMinusWheel;
00296     if (ettTemp.overFlow()) ettTemp.setValue(etTotalMaxValue);
00297     etHadType   httTemp = m_htValPlusWheel + m_htVlMinusWheel;
00298     if (httTemp.overFlow()) httTemp.setValue(etHadMaxValue);
00299     m_outputEtSum.store (ettTemp, bxRel());
00300     m_outputEtHad.store (httTemp, bxRel());
00301 
00302     m_hfSumProcessor->process();
00303   }
00304 }
00305 
00306 //----------------------------------------------------------------------------------------------
00307 // load setup info (for HtMiss calculation)
00308 //
00309 void L1GctGlobalEnergyAlgos::setJetFinderParams(const L1GctJetFinderParams* const jfpars)
00310 {
00311   // The jetFinders add an LSB when converting to x and y components,
00312   // so the scale lsb for htx and hty is half the lsb for htt.
00313   m_mhtComponents.setEtComponentLsb(jfpars->getHtLsbGeV()/2);
00314 }
00315 
00316 void L1GctGlobalEnergyAlgos::setHtMissScale(const L1CaloEtScale* const scale)
00317 {
00318   m_mhtComponents.setEtScale(scale);
00319 }
00320 
00321 //----------------------------------------------------------------------------------------------
00322 // check setup
00323 //
00324 bool L1GctGlobalEnergyAlgos::setupOk() const { 
00325   return (m_setupOk && 
00326           m_hfSumProcessor != 0 &&
00327           m_hfSumProcessor->setupOk()); 
00328 }
00329 
00330   
00331 //----------------------------------------------------------------------------------------------
00332 // set input data per wheel: x component of missing Et
00333 //
00334 void L1GctGlobalEnergyAlgos::setInputWheelEx(unsigned wheel, int energy, bool overflow)
00335 {
00336   if (wheel==0) {
00337     m_exValPlusWheel.setValue(energy);
00338     m_exValPlusWheel.setOverFlow(overflow);
00339   } else if (wheel==1) {
00340     m_exVlMinusWheel.setValue(energy);
00341     m_exVlMinusWheel.setOverFlow(overflow);
00342   }
00343 }
00344 
00345 //----------------------------------------------------------------------------------------------
00346 // set input data per wheel: y component of missing Et
00347 //
00348 void L1GctGlobalEnergyAlgos::setInputWheelEy(unsigned wheel, int energy, bool overflow)
00349 {
00350   if (wheel==0) {
00351     m_eyValPlusWheel.setValue(energy);
00352     m_eyValPlusWheel.setOverFlow(overflow);
00353   } else if (wheel==1) {
00354     m_eyVlMinusWheel.setValue(energy);
00355     m_eyVlMinusWheel.setOverFlow(overflow);
00356   }
00357 }
00358 
00359 //----------------------------------------------------------------------------------------------
00360 // set input data per wheel: scalar sum of Et
00361 //
00362 void L1GctGlobalEnergyAlgos::setInputWheelEt(unsigned wheel, unsigned energy, bool overflow)
00363 {
00364   if (wheel==0) {
00365     m_etValPlusWheel.setValue(energy);
00366     m_etValPlusWheel.setOverFlow(overflow);
00367   } else if (wheel==1) {
00368     m_etVlMinusWheel.setValue(energy);
00369     m_etVlMinusWheel.setOverFlow(overflow);
00370   }
00371 }
00372 
00373 //----------------------------------------------------------------------------------------------
00374 // set input data per wheel: sum of transverse energy in jets (Ht)
00375 //
00376 void L1GctGlobalEnergyAlgos::setInputWheelHt(unsigned wheel, unsigned energy, bool overflow)
00377 {
00378   if (wheel==0) {
00379     m_htValPlusWheel.setValue(energy);
00380     m_htValPlusWheel.setOverFlow(overflow);
00381   } else if (wheel==1) {
00382     m_htVlMinusWheel.setValue(energy);
00383     m_htVlMinusWheel.setOverFlow(overflow);
00384   }
00385 }
00386 
00387 
00388 //----------------------------------------------------------------------------------------------
00389 // set input data per wheel: x component of Ht
00390 //
00391 void L1GctGlobalEnergyAlgos::setInputWheelHx(unsigned wheel, unsigned energy, bool overflow)
00392 {
00393   if (wheel==0) {
00394     m_hxValPlusWheel.setValue(energy);
00395     m_hxValPlusWheel.setOverFlow(overflow);
00396   } else if (wheel==1) {
00397     m_hxVlMinusWheel.setValue(energy);
00398     m_hxVlMinusWheel.setOverFlow(overflow);
00399   }
00400 }
00401 
00402 
00403 //----------------------------------------------------------------------------------------------
00404 // set input data per wheel: y component of Ht
00405 //
00406 void L1GctGlobalEnergyAlgos::setInputWheelHy(unsigned wheel, unsigned energy, bool overflow)
00407 {
00408   if (wheel==0) {
00409     m_hyValPlusWheel.setValue(energy);
00410     m_hyValPlusWheel.setOverFlow(overflow);
00411   } else if (wheel==1) {
00412     m_hyVlMinusWheel.setValue(energy);
00413     m_hyVlMinusWheel.setOverFlow(overflow);
00414   }
00415 }
00416 
00417