Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-25 02:14:15

0001 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixTcp.h>
0002 
0003 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBGroup.h"
0004 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBIdMap.h"
0005 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainTowerEE.h"
0006 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
0007 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
0008 #include <CondFormats/EcalObjects/interface/EcalTPGTPMode.h>
0009 
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include <vector>
0015 //----------------------------------------------------------------------------------------
0016 EcalFenixTcp::EcalFenixTcp(
0017     bool tcpFormat, bool debug, bool famos, int binOfMax, int maxNrSamples, int nbMaxStrips, bool tpInfoPrintout)
0018     : debug_(debug), nbMaxStrips_(nbMaxStrips), tpInfoPrintout_(tpInfoPrintout) {
0019   bypasslin_.resize(nbMaxStrips_);
0020   for (int i = 0; i < nbMaxStrips_; i++)
0021     bypasslin_[i] = new EcalFenixBypassLin();
0022   adder_ = new EcalFenixEtTot();
0023   maxOf2_ = new EcalFenixMaxof2(maxNrSamples, nbMaxStrips_);
0024   formatter_EB_ = new EcalFenixTcpFormatEB(tcpFormat, debug_, famos, binOfMax);
0025   formatter_EE_ = new EcalFenixTcpFormatEE(tcpFormat, debug_, famos, binOfMax);
0026   fgvbEB_ = new EcalFenixFgvbEB(maxNrSamples);
0027   fgvbEE_ = new EcalFenixTcpFgvbEE();
0028   sfgvbEB_ = new EcalFenixTcpsFgvbEB();
0029 
0030   // permanent data structures
0031   bypasslin_out_.resize(nbMaxStrips_);
0032   std::vector<int> vec(maxNrSamples, 0);
0033   for (int i = 0; i < nbMaxStrips_; i++)
0034     bypasslin_out_[i] = vec;
0035 
0036   adder_even_out_.resize(maxNrSamples);
0037   adder_odd_out_.resize(maxNrSamples);
0038   maxOf2_out_.resize(maxNrSamples);
0039   fgvb_out_.resize(maxNrSamples);
0040   strip_fgvb_out_.resize(maxNrSamples);
0041 }
0042 //-----------------------------------------------------------------------------------------
0043 EcalFenixTcp::~EcalFenixTcp() {
0044   for (int i = 0; i < nbMaxStrips_; i++)
0045     delete bypasslin_[i];
0046   delete adder_;
0047   delete maxOf2_;
0048   delete formatter_EB_;
0049   delete formatter_EE_;
0050   delete fgvbEB_;
0051   delete fgvbEE_;
0052 }
0053 //-----------------------------------------------------------------------------------------
0054 
0055 void EcalFenixTcp::process(std::vector<EBDataFrame> &bid,  // dummy argument for template call
0056                            std::vector<std::vector<int>> &tpframetow,
0057                            int nStr,
0058                            std::vector<EcalTriggerPrimitiveSample> &tptow,
0059                            std::vector<EcalTriggerPrimitiveSample> &tptow2,
0060                            bool isInInnerRing,
0061                            EcalTrigTowerDetId towid) {
0062   int bitMask = 12;
0063   // The 14th bit is always used for the odd>even flag. If the flagging is off in the Strip fenix the feature will be not used.
0064   int bitOddEven = 13;
0065   process_part1(tpframetow, nStr, bitMask, bitOddEven);
0066 
0067   process_part2_barrel(tpframetow,
0068                        nStr,
0069                        bitMask,
0070                        bitOddEven,
0071                        ecaltpgFgEBGroup_,
0072                        ecaltpgLutGroup_,
0073                        ecaltpgLut_,
0074                        ecaltpgFineGrainEB_,
0075                        ecaltpgBadTT_,
0076                        ecaltpgSpike_,
0077                        tptow,
0078                        tptow2,
0079                        towid);
0080 }
0081 
0082 //-----------------------------------------------------------------------------------------
0083 void EcalFenixTcp::process(std::vector<EEDataFrame> &bid,  // dummy argument for template call
0084                            std::vector<std::vector<int>> &tpframetow,
0085                            int nStr,
0086                            std::vector<EcalTriggerPrimitiveSample> &tptow,
0087                            std::vector<EcalTriggerPrimitiveSample> &tptow2,
0088                            bool isInInnerRing,
0089                            EcalTrigTowerDetId towid) {
0090   int bitMask = 12;  // Pascal: endcap has 12 bits as in EB (bug in FENIX!!!!)
0091   // The 14th bit is always used for the odd>even flag. If the flagging is off in the Strip fenix the feature will be not used.
0092   int bitOddEven = 13;
0093 
0094   process_part1(tpframetow, nStr, bitMask, bitOddEven);
0095 
0096   process_part2_endcap(tpframetow,
0097                        nStr,
0098                        bitMask,
0099                        bitOddEven,
0100                        ecaltpgLutGroup_,
0101                        ecaltpgLut_,
0102                        ecaltpgFineGrainTowerEE_,
0103                        ecaltpgBadTT_,
0104                        tptow,
0105                        tptow2,
0106                        isInInnerRing,
0107                        towid);
0108 }
0109 //-----------------------------------------------------------------------------------------
0110 void EcalFenixTcp::process_part1(std::vector<std::vector<int>> &tpframetow, int nStr, int bitMask, int bitOddEven) {
0111   // call adder
0112   this->getAdder()->process(tpframetow, nStr, bitMask, bitOddEven, adder_even_out_, adder_odd_out_);
0113   if (debug_) {
0114     edm::LogVerbatim("EcalTPG") << "output of TCP adder is a vector of size: " << adder_even_out_.size();
0115     edm::LogVerbatim("EcalTPG") << "EVEN sum : ";
0116     std::string even_adder_outputs;
0117     for (unsigned int i = 0; i < adder_even_out_.size(); i++) {
0118       even_adder_outputs.append(" ");
0119       even_adder_outputs.append(std::to_string(adder_even_out_[i]));
0120     }
0121     edm::LogVerbatim("EcalTPG") << even_adder_outputs << "\n";
0122 
0123     edm::LogVerbatim("EcalTPG") << "ODD sum : ";
0124     std::string odd_adder_outputs;
0125     for (unsigned int i = 0; i < adder_odd_out_.size(); i++) {
0126       odd_adder_outputs.append(" ");
0127       odd_adder_outputs.append(std::to_string(adder_odd_out_[i]));
0128     }
0129     edm::LogVerbatim("EcalTPG") << odd_adder_outputs << "\n";
0130   }
0131   return;
0132 }
0133 //-----------------------------------------------------------------------------------------
0134 void EcalFenixTcp::process_part2_barrel(std::vector<std::vector<int>> &bypasslinout,
0135                                         int nStr,
0136                                         int bitMask,
0137                                         int bitOddEven,
0138                                         const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup,
0139                                         const EcalTPGLutGroup *ecaltpgLutGroup,
0140                                         const EcalTPGLutIdMap *ecaltpgLut,
0141                                         const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB,
0142                                         const EcalTPGTowerStatus *ecaltpgBadTT,
0143                                         const EcalTPGSpike *ecaltpgSpike,
0144                                         std::vector<EcalTriggerPrimitiveSample> &tcp_out,
0145                                         std::vector<EcalTriggerPrimitiveSample> &tcp_outTcc,
0146                                         EcalTrigTowerDetId towid) {
0147   // call maxof2
0148   // the oddEven flag is used to exclude "odd" strip from the computation of the maxof2 as in the fenix firmware
0149   this->getMaxOf2()->process(bypasslinout, nStr, bitMask, bitOddEven, maxOf2_out_);
0150 
0151   if (debug_) {
0152     edm::LogVerbatim("EcalTPG") << "output of maxof2 is a vector of size: " << maxOf2_out_.size();
0153     edm::LogVerbatim("EcalTPG") << "value : ";
0154     std::string maxOf2_outputs;
0155     for (unsigned int i = 0; i < maxOf2_out_.size(); i++) {
0156       maxOf2_outputs.append(" ");
0157       maxOf2_outputs.append(std::to_string(maxOf2_out_[i]));
0158     }
0159     edm::LogVerbatim("EcalTPG") << maxOf2_outputs << "\n";
0160   }
0161 
0162   // call fgvb
0163   this->getFGVBEB()->setParameters(towid.rawId(), ecaltpgFgEBGroup, ecaltpgFineGrainEB);
0164   // The FGVB is computed only on the even sum, as in the firmware
0165   this->getFGVBEB()->process(adder_even_out_, maxOf2_out_, fgvb_out_);
0166 
0167   // Call sFGVB
0168   this->getsFGVBEB()->process(bypasslinout, nStr, bitMask, strip_fgvb_out_);
0169 
0170   if (debug_) {
0171     edm::LogVerbatim("EcalTPG") << "output of fgvb is a vector of size: " << fgvb_out_.size();
0172     edm::LogVerbatim("EcalTPG") << "value : ";
0173     std::string fgvb_output;
0174     for (unsigned int i = 0; i < fgvb_out_.size(); i++) {
0175       fgvb_output.append(" ");
0176       fgvb_output.append(std::to_string(fgvb_out_[i]));
0177     }
0178     edm::LogVerbatim("EcalTPG") << fgvb_output;
0179   }
0180 
0181   // call formatter
0182   int eTTotShift = 2;
0183 
0184   this->getFormatterEB()->setParameters(
0185       towid.rawId(), ecaltpgLutGroup, ecaltpgLut, ecaltpgBadTT, ecaltpgSpike, ecaltpgTPMode_);
0186   this->getFormatterEB()->process(
0187       adder_even_out_, adder_odd_out_, fgvb_out_, strip_fgvb_out_, eTTotShift, tcp_out, tcp_outTcc);
0188 
0189   if (tpInfoPrintout_) {
0190     for (unsigned int i = 3; i < tcp_out.size(); i++) {
0191       edm::LogVerbatim("EcalTPG") << " " << i << " " << tcp_out[i];
0192     }
0193   }
0194 
0195   if (debug_) {
0196     edm::LogVerbatim("EcalTPG") << "\noutput of TCP formatter Barrel is a vector of size: " << tcp_out.size();
0197     edm::LogVerbatim("EcalTPG") << "value : ";
0198     for (unsigned int i = 0; i < tcp_out.size(); i++) {
0199       edm::LogVerbatim("EcalTPG") << " " << i << " " << tcp_out[i];
0200     }
0201     edm::LogVerbatim("EcalTPG");
0202   }
0203 
0204   return;
0205 }
0206 //-----------------------------------------------------------------------------------------
0207 void EcalFenixTcp::process_part2_endcap(std::vector<std::vector<int>> &bypasslinout,
0208                                         int nStr,
0209                                         int bitMask,
0210                                         int bitOddEven,
0211                                         const EcalTPGLutGroup *ecaltpgLutGroup,
0212                                         const EcalTPGLutIdMap *ecaltpgLut,
0213                                         const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE,
0214                                         const EcalTPGTowerStatus *ecaltpgbadTT,
0215                                         std::vector<EcalTriggerPrimitiveSample> &tcp_out,
0216                                         std::vector<EcalTriggerPrimitiveSample> &tcp_outTcc,
0217                                         bool isInInnerRings,
0218                                         EcalTrigTowerDetId towid)
0219 
0220 {
0221   // Zero EB strip records
0222   for (unsigned int i = 0; i < strip_fgvb_out_.size(); ++i) {
0223     strip_fgvb_out_[i] = 0;
0224   }
0225 
0226   // call fgvb
0227   this->getFGVBEE()->setParameters(towid.rawId(), ecaltpgFineGrainTowerEE);
0228   //  fgvbEE_->process(bypasslin_out_,nStr,bitMask,fgvb_out_);
0229   fgvbEE_->process(bypasslinout, nStr, bitMask, fgvb_out_);
0230 
0231   // call formatter
0232   int eTTotShift = 2;  // Pascal: endcap has 12 bits as in EB (bug in FENIX!!!!)
0233                        // so shift must be applied to just keep [11:2]
0234 
0235   this->getFormatterEE()->setParameters(
0236       towid.rawId(), ecaltpgLutGroup, ecaltpgLut, ecaltpgbadTT, nullptr, ecaltpgTPMode_);
0237 
0238   // Pass both the even and the odd Et sums to the EE formatter also if there is not TCP in the electronics.
0239   // The feature can be implemented in the TCC in the future: the emulator is kept generic.
0240   this->getFormatterEE()->process(
0241       adder_even_out_, adder_odd_out_, fgvb_out_, strip_fgvb_out_, eTTotShift, tcp_out, tcp_outTcc, isInInnerRings);
0242   if (debug_) {
0243     edm::LogVerbatim("EcalTPG") << "\noutput of TCP formatter(endcap) is a vector of size: " << tcp_out.size();
0244     edm::LogVerbatim("EcalTPG") << "value : ";
0245     for (unsigned int i = 0; i < tcp_out.size(); i++) {
0246       edm::LogVerbatim("EcalTPG") << " " << i << " " << tcp_out[i];
0247     }
0248     edm::LogVerbatim("EcalTPG");
0249   }
0250   return;
0251 }