CMS 3D CMS Logo

L1GctGlobalEnergyAlgos.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalEnergyAlgos.h"
00002 
00003 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelEnergyFpga.h"
00004 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 using std::ostream;
00010 using std::endl;
00011 using std::vector;
00012 using std::max;
00013 
00014 const unsigned int L1GctGlobalEnergyAlgos::N_JET_COUNTERS_USED=L1GctWheelJetFpga::N_JET_COUNTERS;
00015 const unsigned int L1GctGlobalEnergyAlgos::N_JET_COUNTERS_MAX =12;
00016 
00017 L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos(vector<L1GctWheelEnergyFpga*> wheelFpga,
00018                                                vector<L1GctWheelJetFpga*> wheelJetFpga) :
00019   L1GctProcessor(),
00020   m_plusWheelFpga(wheelFpga.at(1)),
00021   m_minusWheelFpga(wheelFpga.at(0)),
00022   m_plusWheelJetFpga(wheelJetFpga.at(1)),
00023   m_minusWheelJetFpga(wheelJetFpga.at(0)),
00024   m_metComponents(0,0, L1GctMet::cordicTranslate),
00025   m_mhtComponents(0,0, L1GctMet::floatingPoint),
00026   m_exValPlusWheel(), m_eyValPlusWheel(),
00027   m_etValPlusWheel(), m_htValPlusWheel(),
00028   m_exVlMinusWheel(), m_eyVlMinusWheel(),
00029   m_etVlMinusWheel(), m_htVlMinusWheel(),
00030   m_jcValPlusWheel(N_JET_COUNTERS_USED),
00031   m_jcVlMinusWheel(N_JET_COUNTERS_USED),
00032   m_exValPlusPipe(), m_eyValPlusPipe(),
00033   m_etValPlusPipe(), m_htValPlusPipe(),
00034   m_exVlMinusPipe(), m_eyVlMinusPipe(),
00035   m_etVlMinusPipe(), m_htVlMinusPipe(),
00036   m_jcValPlusPipe(N_JET_COUNTERS_USED),
00037   m_jcVlMinusPipe(N_JET_COUNTERS_USED),
00038   m_outputEtMiss(), m_outputEtMissPhi(),
00039   m_outputEtSum(), m_outputEtHad(),
00040   m_outputJetCounts(N_JET_COUNTERS_MAX),
00041   m_setupOk(true)
00042 {
00043   if(wheelFpga.size() != 2)
00044     {
00045       m_setupOk = false;
00046       if (m_verbose) {
00047         edm::LogWarning("L1GctSetupError")
00048           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() : Global Energy Algos has been incorrectly constructed!\n"
00049           << "This class needs two wheel card pointers. "
00050           << "Number of wheel card pointers present is " << wheelFpga.size() << ".\n";
00051       }
00052     }
00053   
00054   if(wheelJetFpga.size() != 2)
00055     {
00056       m_setupOk = false;
00057       if (m_verbose) {
00058         edm::LogWarning("L1GctSetupError")
00059           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() : Global Energy Algos has been incorrectly constructed!\n"
00060           << "This class needs two wheel jet fpga pointers. "
00061           << "Number of wheel jet fpga pointers present is " << wheelJetFpga.size() << ".\n";
00062       }
00063     }
00064   
00065   if(m_plusWheelFpga == 0)
00066     {
00067       m_setupOk = false;
00068       if (m_verbose) {
00069         edm::LogWarning("L1GctSetupError")
00070           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00071           << "Plus Wheel Fpga pointer has not been set!\n";
00072       }
00073     }
00074   if(m_minusWheelFpga == 0)
00075     {
00076       m_setupOk = false;
00077       if (m_verbose) {
00078         edm::LogWarning("L1GctSetupError")
00079           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00080           << "Minus Wheel Fpga pointer has not been set!\n";
00081       }
00082     }
00083   if(m_plusWheelJetFpga == 0)
00084     {
00085       m_setupOk = false;
00086       if (m_verbose) {
00087         edm::LogWarning("L1GctSetupError")
00088           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00089           << "Plus Wheel Jet Fpga pointer has not been set!\n";
00090       }
00091     }
00092   if(m_minusWheelJetFpga == 0)
00093     {
00094       m_setupOk = false;
00095       if (m_verbose) {
00096         edm::LogWarning("L1GctSetupError")
00097           << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
00098           << "Minus Wheel Jet Fpga pointer has not been set!\n";
00099       }
00100     }
00101 
00102     // Set the scale for missing Ht
00103     //+++!!! THIS SHOULD EVENTUALLY COME FROM CondFormats !!!+++
00104     // A shift of 3 bits corresponds to a scale factor of 8
00105     // (with respect to the Ht scale defined elsewhere)
00106     //+++!!! THIS SHOULD EVENTUALLY COME FROM CondFormats !!!+++
00107     m_mhtComponents.setBitShift(3);
00108 
00109     // Setup to perform the Hf sums
00110     m_hfSumProcessor = new L1GctGlobalHfSumAlgos(wheelJetFpga);
00111 
00112     m_setupOk &= m_hfSumProcessor->setupOk();
00113 
00114     if (!m_setupOk && m_verbose) {
00115       edm::LogError("L1GctSetupError") << "L1GctGlobalEnergyAlgos has been incorrectly constructed";
00116     }
00117 }
00118 
00119 L1GctGlobalEnergyAlgos::~L1GctGlobalEnergyAlgos()
00120 {
00121   if (m_hfSumProcessor != 0) {
00122     delete m_hfSumProcessor;
00123   }
00124 }
00125 
00126 ostream& operator << (ostream& os, const L1GctGlobalEnergyAlgos& fpga)
00127 {
00128   os << "===L1GctGlobalEnergyAlgos===" << endl;
00129   os << "WheelEnergyFpga* minus = " << fpga.m_minusWheelFpga << endl;
00130   os << "WheelEnergyFpga* plus  = " << fpga.m_plusWheelFpga << endl;
00131   os << "WheelJetFpga* minus = " << fpga.m_minusWheelJetFpga << endl;
00132   os << "WheelJetFpga* plus  = " << fpga.m_plusWheelJetFpga << endl;
00133   os << "Inputs from Plus wheel:" << endl;
00134   os << "  Ex " << fpga.m_exValPlusWheel << "\n  Ey " << fpga.m_eyValPlusWheel << endl;
00135   os << "  Et " << fpga.m_etValPlusWheel << "\n  Ht " << fpga.m_htValPlusWheel << endl; 
00136   os << "Inputs from Minus wheel:" << endl;
00137   os << "  Ex " << fpga.m_exVlMinusWheel << "\n  Ey " << fpga.m_eyVlMinusWheel << endl;
00138   os << "  Et " << fpga.m_etVlMinusWheel << "\n  Ht " << fpga.m_htVlMinusWheel << endl; 
00139   os << "Input Jet counts " << endl;
00140   for(unsigned i=0; i < fpga.m_jcValPlusWheel.size(); i++)
00141     {
00142       os << "  Plus wheel  " << i << ": " << fpga.m_jcValPlusWheel.at(i);
00143       os << "  Minus wheel " << i << ": " << fpga.m_jcVlMinusWheel.at(i) << endl;
00144     } 
00145   os << endl;
00146   int bxZero = -fpga.bxMin();
00147   if (bxZero>=0 && bxZero<fpga.numOfBx()) {
00148     os << "Output Etmiss " << fpga.m_outputEtMiss.contents.at(bxZero) << endl;
00149     os << "Output Etmiss Phi " << fpga.m_outputEtMissPhi.contents.at(bxZero) << endl;
00150     os << "Output EtSum " << fpga.m_outputEtSum.contents.at(bxZero) << endl;
00151     os << "Output EtHad " << fpga.m_outputEtHad.contents.at(bxZero) << endl;
00152     int pos = bxZero*L1GctGlobalEnergyAlgos::N_JET_COUNTERS_MAX;
00153     os << "Output Jet counts " << endl;
00154     for(unsigned i=0; i < L1GctGlobalEnergyAlgos::N_JET_COUNTERS_MAX; i++)
00155       {
00156         os << i << ": " << fpga.m_outputJetCounts.contents.at(pos++) << endl;
00157       } 
00158     os << endl;
00159   }
00160   os << *fpga.m_hfSumProcessor;
00161 
00162   return os;
00163 }
00164 
00166 void L1GctGlobalEnergyAlgos::reset() {
00167   L1GctProcessor::reset();
00168   m_hfSumProcessor->reset();
00169 }
00170 
00172 void L1GctGlobalEnergyAlgos::setBxRange(const int firstBx, const int numberOfBx) {
00173   L1GctProcessor::setBxRange(firstBx, numberOfBx);
00174   m_hfSumProcessor->setBxRange(firstBx, numberOfBx);
00175 }
00176 
00177 void L1GctGlobalEnergyAlgos::setNextBx(const int bx) {
00178   L1GctProcessor::setNextBx(bx);
00179   m_hfSumProcessor->setNextBx(bx);
00180 }
00181 
00182 void L1GctGlobalEnergyAlgos::resetProcessor() {
00183   m_exValPlusWheel.reset();
00184   m_exVlMinusWheel.reset();
00185   m_eyValPlusWheel.reset();
00186   m_eyVlMinusWheel.reset();
00187   m_etValPlusWheel.reset();
00188   m_etVlMinusWheel.reset();
00189   m_htValPlusWheel.reset();
00190   m_htVlMinusWheel.reset();
00191   m_hxValPlusWheel.reset();
00192   m_hxVlMinusWheel.reset();
00193   m_hyValPlusWheel.reset();
00194   m_hyVlMinusWheel.reset();
00195   for (unsigned i=0; i<N_JET_COUNTERS_USED; i++) {
00196     m_jcValPlusWheel.at(i).reset();
00197     m_jcVlMinusWheel.at(i).reset();
00198   }
00199 }
00200 
00201 void L1GctGlobalEnergyAlgos::resetPipelines() {
00202   m_outputEtMiss.reset    (numOfBx());
00203   m_outputEtMissPhi.reset (numOfBx());
00204   m_outputEtSum.reset     (numOfBx());
00205   m_outputEtHad.reset     (numOfBx());
00206   m_outputHtMiss.reset    (numOfBx());
00207   m_outputHtMissPhi.reset (numOfBx());
00208   m_outputJetCounts.reset (numOfBx());
00209 
00210   m_exValPlusPipe.reset (numOfBx());
00211   m_eyValPlusPipe.reset (numOfBx());
00212   m_etValPlusPipe.reset (numOfBx());
00213   m_htValPlusPipe.reset (numOfBx());
00214   m_hxValPlusPipe.reset (numOfBx());
00215   m_hyValPlusPipe.reset (numOfBx());
00216 
00217   m_exVlMinusPipe.reset (numOfBx());
00218   m_eyVlMinusPipe.reset (numOfBx());
00219   m_etVlMinusPipe.reset (numOfBx());
00220   m_htVlMinusPipe.reset (numOfBx());
00221   m_hxVlMinusPipe.reset (numOfBx());
00222   m_hyVlMinusPipe.reset (numOfBx());
00223 
00224   m_jcValPlusPipe.reset (numOfBx());
00225   m_jcVlMinusPipe.reset (numOfBx());
00226 
00227 }
00228 
00229 void L1GctGlobalEnergyAlgos::fetchInput() {
00230   if (m_setupOk) {
00231     // input from WheelEnergyFpgas
00232     m_exValPlusWheel = m_plusWheelFpga->getOutputEx();
00233     m_eyValPlusWheel = m_plusWheelFpga->getOutputEy();
00234     m_etValPlusWheel = m_plusWheelFpga->getOutputEt();
00235     m_htValPlusWheel = m_plusWheelJetFpga->getOutputHt();
00236     m_hxValPlusWheel = m_plusWheelJetFpga->getOutputHx();
00237     m_hyValPlusWheel = m_plusWheelJetFpga->getOutputHy();
00238   
00239     m_exVlMinusWheel = m_minusWheelFpga->getOutputEx();
00240     m_eyVlMinusWheel = m_minusWheelFpga->getOutputEy();
00241     m_etVlMinusWheel = m_minusWheelFpga->getOutputEt();
00242     m_htVlMinusWheel = m_minusWheelJetFpga->getOutputHt();
00243     m_hxVlMinusWheel = m_minusWheelJetFpga->getOutputHx();
00244     m_hyVlMinusWheel = m_minusWheelJetFpga->getOutputHy();
00245 
00246     //
00247     for (unsigned i=0; i<N_JET_COUNTERS_USED; i++) {
00248       m_jcValPlusWheel.at(i) = m_plusWheelJetFpga->getOutputJc(i);
00249       m_jcVlMinusWheel.at(i) = m_minusWheelJetFpga->getOutputJc(i);
00250     }
00251 
00252     m_hfSumProcessor->fetchInput();
00253   }
00254 }
00255 
00256 
00257 // process the event
00258 void L1GctGlobalEnergyAlgos::process()
00259 {
00260   if (m_setupOk) {
00261     // Store the inputs in pipelines
00262     m_exValPlusPipe.store(m_exValPlusWheel, bxRel());
00263     m_eyValPlusPipe.store(m_eyValPlusWheel, bxRel());
00264     m_etValPlusPipe.store(m_etValPlusWheel, bxRel());
00265     m_htValPlusPipe.store(m_htValPlusWheel, bxRel());
00266     m_hxValPlusPipe.store(m_hxValPlusWheel, bxRel());
00267     m_hyValPlusPipe.store(m_hyValPlusWheel, bxRel());
00268 
00269     m_exVlMinusPipe.store(m_exVlMinusWheel, bxRel());
00270     m_eyVlMinusPipe.store(m_eyVlMinusWheel, bxRel());
00271     m_etVlMinusPipe.store(m_etVlMinusWheel, bxRel());
00272     m_htVlMinusPipe.store(m_htVlMinusWheel, bxRel());
00273     m_hxVlMinusPipe.store(m_hxVlMinusWheel, bxRel());
00274     m_hyVlMinusPipe.store(m_hyVlMinusWheel, bxRel());
00275 
00276     m_jcValPlusPipe.store(m_jcValPlusWheel, bxRel());
00277     m_jcVlMinusPipe.store(m_jcVlMinusWheel, bxRel());
00278 
00279     // Process to produce the outputs
00280     etComponentType ExSum, EySum;
00281     etmiss_vec EtMissing, HtMissing;
00282 
00283     //
00284     //-----------------------------------------------------------------------------
00285     // Form the Ex and Ey sums
00286     ExSum = m_exValPlusWheel + m_exVlMinusWheel;
00287     EySum = m_eyValPlusWheel + m_eyVlMinusWheel;
00288     // Execute the missing Et algorithm
00289     m_metComponents.setComponents(-ExSum, -EySum);
00290     EtMissing = m_metComponents.metVector();
00291 
00292     m_outputEtMiss.store    (EtMissing.mag, bxRel());
00293     m_outputEtMissPhi.store (EtMissing.phi, bxRel());
00294 
00295     //
00296     //-----------------------------------------------------------------------------
00297     // Form the Hx and Hy sums
00298     ExSum = m_hxValPlusWheel + m_hxVlMinusWheel;
00299     EySum = m_hyValPlusWheel + m_hyVlMinusWheel;
00300     // Execute the missing Et algorithm
00301     m_mhtComponents.setComponents(-ExSum, -EySum);
00302     HtMissing = m_mhtComponents.metVector();
00303 
00304     // Store 6 bits each of magnitude and phi angle.
00305     // Note EtMissPhi is 7 bits so we keep the range (0-70)
00306     // and lose the LSB.
00307     static const unsigned MAX_HT_VALUE = 0x3f;
00308     static const unsigned PHI_HT_MASK  = 0x7e;
00309     if ( (HtMissing.mag.value() > MAX_HT_VALUE) || (HtMissing.mag.overFlow()) ) {
00310       HtMissing.mag.setValue(MAX_HT_VALUE);
00311     }
00312     HtMissing.phi.setValue(HtMissing.phi.value() & PHI_HT_MASK);
00313 
00314     m_outputHtMiss.store    (HtMissing.mag, bxRel());
00315     m_outputHtMissPhi.store (HtMissing.phi, bxRel());
00316 
00317     //
00318     //-----------------------------------------------------------------------------
00319     // Form the Et and Ht sums
00320     m_outputEtSum.store (m_etValPlusWheel + m_etVlMinusWheel, bxRel());
00321     m_outputEtHad.store (m_htValPlusWheel + m_htVlMinusWheel, bxRel());
00322 
00323     //
00324     //-----------------------------------------------------------------------------
00325     // Add the jet counts.
00326     std::vector<L1GctJetCount<5> > temp(N_JET_COUNTERS_MAX);
00327     for (unsigned i=0; i<N_JET_COUNTERS_USED; i++) {
00328       temp.at(i) =
00329         L1GctJetCount<5>(m_jcValPlusWheel.at(i)) +
00330         L1GctJetCount<5>(m_jcVlMinusWheel.at(i));
00331     }
00332     m_outputJetCounts.store(temp, bxRel());
00333 
00334     m_hfSumProcessor->process();
00335   }
00336 }
00337 
00338 std::vector< std::vector<unsigned> > L1GctGlobalEnergyAlgos::getJetCountValuesColl() const {
00339   std::vector< std::vector<unsigned> > result(numOfBx());
00340   for (int i=0; i<numOfBx(); i++) {
00341     result.at(i) = jetCountValues(i);
00342   }
00343   return result;
00344 }
00345 
00346 std::vector<unsigned> L1GctGlobalEnergyAlgos::jetCountValues(const int bx) const {
00347   std::vector<unsigned> jetCountValues(N_JET_COUNTERS_MAX);
00348   int pos = bx*N_JET_COUNTERS_MAX;  
00349   for (unsigned jc=0; jc<N_JET_COUNTERS_MAX; jc++) {
00350     jetCountValues.at(jc) = m_outputJetCounts.contents.at(pos++).value();
00351   }
00352   return jetCountValues;
00353 }
00354 
00355 //----------------------------------------------------------------------------------------------
00356 // check setup
00357 //
00358 bool L1GctGlobalEnergyAlgos::setupOk() const { 
00359   return (m_setupOk && 
00360           m_hfSumProcessor != 0 &&
00361           m_hfSumProcessor->setupOk()); 
00362 }
00363 
00364   
00365 //----------------------------------------------------------------------------------------------
00366 // set input data per wheel: x component of missing Et
00367 //
00368 void L1GctGlobalEnergyAlgos::setInputWheelEx(unsigned wheel, int energy, bool overflow)
00369 {
00370   if (wheel==0) {
00371     m_exValPlusWheel.setValue(energy);
00372     m_exValPlusWheel.setOverFlow(overflow);
00373   } else if (wheel==1) {
00374     m_exVlMinusWheel.setValue(energy);
00375     m_exVlMinusWheel.setOverFlow(overflow);
00376   }
00377 }
00378 
00379 //----------------------------------------------------------------------------------------------
00380 // set input data per wheel: y component of missing Et
00381 //
00382 void L1GctGlobalEnergyAlgos::setInputWheelEy(unsigned wheel, int energy, bool overflow)
00383 {
00384   if (wheel==0) {
00385     m_eyValPlusWheel.setValue(energy);
00386     m_eyValPlusWheel.setOverFlow(overflow);
00387   } else if (wheel==1) {
00388     m_eyVlMinusWheel.setValue(energy);
00389     m_eyVlMinusWheel.setOverFlow(overflow);
00390   }
00391 }
00392 
00393 //----------------------------------------------------------------------------------------------
00394 // set input data per wheel: scalar sum of Et
00395 //
00396 void L1GctGlobalEnergyAlgos::setInputWheelEt(unsigned wheel, unsigned energy, bool overflow)
00397 {
00398   if (wheel==0) {
00399     m_etValPlusWheel.setValue(energy);
00400     m_etValPlusWheel.setOverFlow(overflow);
00401   } else if (wheel==1) {
00402     m_etVlMinusWheel.setValue(energy);
00403     m_etVlMinusWheel.setOverFlow(overflow);
00404   }
00405 }
00406 
00407 //----------------------------------------------------------------------------------------------
00408 // set input data per wheel: sum of transverse energy in jets (Ht)
00409 //
00410 void L1GctGlobalEnergyAlgos::setInputWheelHt(unsigned wheel, unsigned energy, bool overflow)
00411 {
00412   if (wheel==0) {
00413     m_htValPlusWheel.setValue(energy);
00414     m_htValPlusWheel.setOverFlow(overflow);
00415   } else if (wheel==1) {
00416     m_htVlMinusWheel.setValue(energy);
00417     m_htVlMinusWheel.setOverFlow(overflow);
00418   }
00419 }
00420 
00421 
00422 //----------------------------------------------------------------------------------------------
00423 // set input data per wheel: x component of Ht
00424 //
00425 void L1GctGlobalEnergyAlgos::setInputWheelHx(unsigned wheel, unsigned energy, bool overflow)
00426 {
00427   if (wheel==0) {
00428     m_hxValPlusWheel.setValue(energy);
00429     m_hxValPlusWheel.setOverFlow(overflow);
00430   } else if (wheel==1) {
00431     m_hxVlMinusWheel.setValue(energy);
00432     m_hxVlMinusWheel.setOverFlow(overflow);
00433   }
00434 }
00435 
00436 
00437 //----------------------------------------------------------------------------------------------
00438 // set input data per wheel: y component of Ht
00439 //
00440 void L1GctGlobalEnergyAlgos::setInputWheelHy(unsigned wheel, unsigned energy, bool overflow)
00441 {
00442   if (wheel==0) {
00443     m_hyValPlusWheel.setValue(energy);
00444     m_hyValPlusWheel.setOverFlow(overflow);
00445   } else if (wheel==1) {
00446     m_hyVlMinusWheel.setValue(energy);
00447     m_hyVlMinusWheel.setOverFlow(overflow);
00448   }
00449 }
00450 
00451 
00452 //----------------------------------------------------------------------------------------------
00453 // Set the jet count input values
00454 //
00455 void L1GctGlobalEnergyAlgos::setInputWheelJc(unsigned wheel, unsigned jcnum, unsigned count)
00456 {
00457   if (jcnum<N_JET_COUNTERS_USED) {
00458     if (wheel==0) {
00459       m_jcValPlusWheel.at(jcnum).setValue(count);
00460     } else if (wheel==1) {
00461       m_jcVlMinusWheel.at(jcnum).setValue(count);
00462     }
00463   }
00464 }
00465 
00466 

Generated on Tue Jun 9 17:40:10 2009 for CMSSW by  doxygen 1.5.4