Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:29

0001 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixStrip.h>
0002 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixStripFgvbEE.h>
0003 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixStripFormatEB.h>
0004 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixStripFormatEE.h>
0005 #include <CondFormats/EcalObjects/interface/EcalTPGTPMode.h>
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0009 
0010 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h>
0011 #include <string>
0012 #include <bitset>
0013 
0014 //-------------------------------------------------------------------------------------
0015 EcalFenixStrip::EcalFenixStrip(const EcalElectronicsMapping *theMapping,
0016                                bool debug,
0017                                bool famos,
0018                                int maxNrSamples,
0019                                int nbMaxXtals,
0020                                bool tpInfoPrintout)
0021     : theMapping_(theMapping), debug_(debug), famos_(famos), nbMaxXtals_(nbMaxXtals), tpInfoPrintout_(tpInfoPrintout) {
0022   linearizer_.resize(nbMaxXtals_);
0023   for (int i = 0; i < nbMaxXtals_; i++)
0024     linearizer_[i] = new EcalFenixLinearizer(famos_);
0025   adder_ = new EcalFenixEtStrip();
0026   amplitude_filter_ = new EcalFenixAmplitudeFilter(tpInfoPrintout);
0027   oddAmplitude_filter_ = new EcalFenixOddAmplitudeFilter(tpInfoPrintout);
0028   peak_finder_ = new EcalFenixPeakFinder();
0029   fenixFormatterEB_ = new EcalFenixStripFormatEB();
0030   fenixFormatterEE_ = new EcalFenixStripFormatEE();
0031   fgvbEE_ = new EcalFenixStripFgvbEE();
0032 
0033   // prepare data storage for all events
0034   std::vector<int> v;
0035   v.resize(maxNrSamples);
0036   lin_out_.resize(nbMaxXtals_);
0037   for (int i = 0; i < 5; i++)
0038     lin_out_[i] = v;
0039   add_out_.resize(maxNrSamples);
0040 
0041   even_filt_out_.resize(maxNrSamples);
0042   even_peak_out_.resize(maxNrSamples);
0043   odd_filt_out_.resize(maxNrSamples);
0044   odd_peak_out_.resize(maxNrSamples);
0045 
0046   format_out_.resize(maxNrSamples);
0047   fgvb_out_.resize(maxNrSamples);
0048   fgvb_out_temp_.resize(maxNrSamples);
0049 }
0050 
0051 //-------------------------------------------------------------------------------------
0052 EcalFenixStrip::~EcalFenixStrip() {
0053   for (int i = 0; i < nbMaxXtals_; i++)
0054     delete linearizer_[i];
0055   delete adder_;
0056   delete amplitude_filter_;
0057   delete oddAmplitude_filter_;
0058   delete peak_finder_;
0059   delete fenixFormatterEB_;
0060   delete fenixFormatterEE_;
0061   delete fgvbEE_;
0062 }
0063 
0064 void EcalFenixStrip::process(std::vector<EBDataFrame> &samples, int nrXtals, std::vector<int> &out) {
0065   // now call processing
0066   if (samples.empty()) {
0067     edm::LogWarning("EcalTPG") << "Warning: 0 size vector found in EcalFenixStripProcess!!!!!";
0068     return;
0069   }
0070   const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(samples[0].id());
0071   uint32_t stripid = elId.rawId() & 0xfffffff8;  // from Pascal
0072 
0073   identif_ = getFGVB()->getMissedStripFlag();
0074 
0075   process_part1(identif_,
0076                 samples,
0077                 nrXtals,
0078                 stripid,
0079                 ecaltpPed_,
0080                 ecaltpLin_,
0081                 ecaltpgWeightMap_,
0082                 ecaltpgWeightGroup_,
0083                 ecaltpgOddWeightMap_,
0084                 ecaltpgOddWeightGroup_,
0085                 ecaltpgBadX_);  // templated part
0086   process_part2_barrel(stripid, ecaltpgSlidW_,
0087                        ecaltpgFgStripEE_);  // part different for barrel/endcap
0088   out = format_out_;
0089 }
0090 
0091 void EcalFenixStrip::process(std::vector<EEDataFrame> &samples, int nrXtals, std::vector<int> &out) {
0092   // now call processing
0093   if (samples.empty()) {
0094     std::cout << " Warning: 0 size vector found in EcalFenixStripProcess!!!!!" << std::endl;
0095     return;
0096   }
0097   const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(samples[0].id());
0098   uint32_t stripid = elId.rawId() & 0xfffffff8;  // from Pascal
0099 
0100   identif_ = getFGVB()->getMissedStripFlag();
0101 
0102   process_part1(identif_,
0103                 samples,
0104                 nrXtals,
0105                 stripid,
0106                 ecaltpPed_,
0107                 ecaltpLin_,
0108                 ecaltpgWeightMap_,
0109                 ecaltpgWeightGroup_,
0110                 ecaltpgOddWeightMap_,
0111                 ecaltpgOddWeightGroup_,
0112                 ecaltpgBadX_);  // templated part
0113   process_part2_endcap(stripid, ecaltpgSlidW_, ecaltpgFgStripEE_, ecaltpgStripStatus_);
0114   out = format_out_;  // FIXME: timing
0115   return;
0116 }
0117 
0118 /*
0119 * strip level processing - part1.
0120 * The linearizer and adder are run only once.
0121 * Then the even and odd filters and peak finder are run looking at the TPmode flag
0122 */
0123 template <class T>
0124 void EcalFenixStrip::process_part1(int identif,
0125                                    std::vector<T> &df,
0126                                    int nrXtals,
0127                                    uint32_t stripid,
0128                                    const EcalTPGPedestals *ecaltpPed,
0129                                    const EcalTPGLinearizationConst *ecaltpLin,
0130                                    const EcalTPGWeightIdMap *ecaltpgWeightMap,
0131                                    const EcalTPGWeightGroup *ecaltpgWeightGroup,
0132                                    const EcalTPGOddWeightIdMap *ecaltpgOddWeightMap,
0133                                    const EcalTPGOddWeightGroup *ecaltpgOddWeightGroup,
0134                                    const EcalTPGCrystalStatus *ecaltpBadX) {
0135   if (debug_) {
0136     edm::LogVerbatim("EcalTPG");
0137     edm::LogVerbatim("EcalTPG") << "EcalFenixStrip input is a vector of size: " << nrXtals << "\n";
0138     edm::LogVerbatim("EcalTPG") << "ECAL TPG TPMode printout:";
0139 
0140     std::stringstream ss;
0141     ecaltpgTPMode_->print(ss);
0142     edm::LogVerbatim("EcalTPG") << ss.str() << "\n";
0143   }
0144 
0145   // loop over crystals
0146   for (int cryst = 0; cryst < nrXtals; cryst++) {
0147     if (debug_) {
0148       edm::LogVerbatim("EcalTPG") << "crystal " << cryst << " ADC counts per clock (non-linearized): ";
0149       int Nsamples = df[cryst].size();
0150       std::string XTAL_ADCs;
0151 
0152       for (int i = 0; i < Nsamples; i++) {
0153         XTAL_ADCs.append(" ");
0154         XTAL_ADCs.append(std::to_string(df[cryst][i].adc()));
0155       }
0156 
0157       edm::LogVerbatim("EcalTPG") << XTAL_ADCs << "\n";
0158     }
0159     // call linearizer
0160     this->getLinearizer(cryst)->setParameters(df[cryst].id().rawId(), ecaltpPed, ecaltpLin, ecaltpBadX);
0161     this->getLinearizer(cryst)->process(df[cryst], lin_out_[cryst]);
0162   }
0163 
0164   if (debug_) {
0165     edm::LogVerbatim("EcalTPG") << "output of linearizer is a vector of size: " << lin_out_.size() << " of which "
0166                                 << nrXtals << " are used";
0167 
0168     for (int ix = 0; ix < nrXtals; ix++) {
0169       edm::LogVerbatim("EcalTPG") << "crystal " << std::to_string(ix) << " values per clock (linearized): ";
0170       std::string Lin_Vals;
0171       std::string Lin_Vals_in_time = "[";
0172 
0173       for (unsigned int i = 0; i < lin_out_[ix].size(); i++) {
0174         Lin_Vals.append(" ");
0175         if (i >= 2 && i < 7) {
0176           Lin_Vals_in_time.append(
0177               std::to_string((lin_out_[ix])[i]));  // Save in time vals separately for nicely formatted digis
0178           if (i < 6)
0179             Lin_Vals_in_time.append(", ");
0180           else
0181             Lin_Vals_in_time.append("]");
0182         }
0183         Lin_Vals.append(std::to_string((lin_out_[ix])[i]));
0184       }
0185       Lin_Vals.append("]");
0186 
0187       edm::LogVerbatim("EcalTPG") << Lin_Vals << " --> In time digis: " << Lin_Vals_in_time << "\n";
0188     }
0189   }
0190 
0191   // Now call the sFGVB - this is common between EB and EE!
0192   getFGVB()->setParameters(identif, stripid, ecaltpgFgStripEE_);
0193   getFGVB()->process(lin_out_, fgvb_out_temp_);
0194 
0195   if (debug_) {
0196     edm::LogVerbatim("EcalTPG") << "output of strip fgvb is a vector of size: " << fgvb_out_temp_.size();
0197     std::string fgvb_vals;
0198     for (unsigned int i = 0; i < fgvb_out_temp_.size(); i++) {
0199       fgvb_vals.append(" ");
0200       fgvb_vals.append(std::to_string(fgvb_out_temp_[i]));
0201     }
0202     edm::LogVerbatim("EcalTPG") << fgvb_vals << "\n";
0203   }
0204   // call adder
0205   this->getAdder()->process(lin_out_, nrXtals, add_out_);  // add_out is of size SIZEMAX=maxNrSamples
0206 
0207   if (debug_) {
0208     edm::LogVerbatim("EcalTPG") << "output of adder is a vector of size: " << add_out_.size();
0209     for (unsigned int ix = 0; ix < add_out_.size(); ix++) {
0210       edm::LogVerbatim("EcalTPG") << "Clock: " << ix << " value: " << add_out_[ix];
0211     }
0212     edm::LogVerbatim("EcalTPG");
0213   }
0214 
0215   if (famos_) {
0216     even_filt_out_[0] = add_out_[0];
0217     even_peak_out_[0] = add_out_[0];
0218     return;
0219   } else {
0220     // This is where the amplitude filters are called
0221     // the TPmode flag will determine which are called and if the peak finder is called.
0222     // Call even amplitude filter
0223     this->getEvenFilter()->setParameters(stripid, ecaltpgWeightMap, ecaltpgWeightGroup);
0224     this->getEvenFilter()->process(add_out_, even_filt_out_, fgvb_out_temp_, fgvb_out_);
0225 
0226     // Print out even filter ET and sfgvb values
0227     if (debug_) {
0228       edm::LogVerbatim("EcalTPG");
0229       edm::LogVerbatim("EcalTPG") << "output of EVEN filter is a vector of size: " << even_filt_out_.size();
0230       for (unsigned int ix = 0; ix < even_filt_out_.size(); ix++) {
0231         edm::LogVerbatim("EcalTPG") << "Clock: " << ix << " value : " << even_filt_out_[ix];
0232       }
0233       edm::LogVerbatim("EcalTPG");
0234       edm::LogVerbatim("EcalTPG") << "output of EVEN sfgvb after filter is a vector of size: " << fgvb_out_.size();
0235       for (unsigned int ix = 0; ix < fgvb_out_.size(); ix++) {
0236         edm::LogVerbatim("EcalTPG") << "Clock: " << ix << " value : " << fgvb_out_[ix];
0237       }
0238     }
0239 
0240     // Call peak finder on even filter output
0241     this->getPeakFinder()->process(even_filt_out_, even_peak_out_);
0242 
0243     // Print out even filter peak finder values
0244     if (debug_) {
0245       edm::LogVerbatim("EcalTPG");
0246       edm::LogVerbatim("EcalTPG") << "output of EVEN peakfinder is a vector of size: " << even_peak_out_.size();
0247       for (unsigned int ix = 0; ix < even_peak_out_.size(); ix++) {
0248         edm::LogVerbatim("EcalTPG") << "Clock: " << ix << "  value : " << even_peak_out_[ix];
0249       }
0250       edm::LogVerbatim("EcalTPG");
0251     }
0252 
0253     //  Run the odd filter
0254     this->getOddFilter()->setParameters(stripid, ecaltpgOddWeightMap, ecaltpgOddWeightGroup);
0255     this->getOddFilter()->process(add_out_, odd_filt_out_);
0256 
0257     // Print out odd filter ET
0258     if (debug_) {
0259       edm::LogVerbatim("EcalTPG");
0260       edm::LogVerbatim("EcalTPG") << "output of ODD filter is a vector of size: " << odd_filt_out_.size();
0261       for (unsigned int ix = 0; ix < odd_filt_out_.size(); ix++) {
0262         edm::LogVerbatim("EcalTPG") << "Clock: " << ix << "  value : " << odd_filt_out_[ix];
0263       }
0264       edm::LogVerbatim("EcalTPG");
0265     }
0266 
0267     // And run the odd peak finder always (then the formatter will use the configuration to decide to use it or not)
0268     // Call peak finder on even filter output
0269     this->getPeakFinder()->process(odd_filt_out_, odd_peak_out_);
0270 
0271     if (debug_) {
0272       edm::LogVerbatim("EcalTPG") << "output of ODD peakfinder is a vector of size: " << odd_peak_out_.size();
0273       for (unsigned int ix = 0; ix < odd_peak_out_.size(); ix++) {
0274         edm::LogVerbatim("EcalTPG") << "Clock: " << ix << "  value : " << odd_peak_out_[ix];
0275       }
0276       edm::LogVerbatim("EcalTPG");
0277     }
0278 
0279     return;
0280   }
0281 }
0282 
0283 //----------------------------------------------------------------------------------
0284 void EcalFenixStrip::process_part2_barrel(uint32_t stripid,
0285                                           const EcalTPGSlidingWindow *ecaltpgSlidW,
0286                                           const EcalTPGFineGrainStripEE *ecaltpgFgStripEE) {
0287   // call formatter
0288   this->getFormatterEB()->setParameters(stripid, ecaltpgSlidW, ecaltpgTPMode_);
0289   this->getFormatterEB()->process(fgvb_out_, even_peak_out_, even_filt_out_, odd_peak_out_, odd_filt_out_, format_out_);
0290 
0291   if (debug_) {
0292     edm::LogVerbatim("EcalTPG") << "output of strip EB formatter is a vector of size: " << format_out_.size();
0293     edm::LogVerbatim("EcalTPG") << "value : ";
0294     for (unsigned int ix = 0; ix < format_out_.size(); ix++) {
0295       edm::LogVerbatim("EcalTPG") << "Clock: " << ix << " value : " << format_out_[ix] << "  0b"
0296                                   << std::bitset<14>(format_out_[ix]).to_string();
0297     }
0298     edm::LogVerbatim("EcalTPG");
0299   }
0300   return;
0301 }
0302 //-------------------------------------------------------------------------------------
0303 void EcalFenixStrip::process_part2_endcap(uint32_t stripid,
0304                                           const EcalTPGSlidingWindow *ecaltpgSlidW,
0305                                           const EcalTPGFineGrainStripEE *ecaltpgFgStripEE,
0306                                           const EcalTPGStripStatus *ecaltpgStripStatus) {
0307   // call formatter
0308   this->getFormatterEE()->setParameters(stripid, ecaltpgSlidW, ecaltpgStripStatus, ecaltpgTPMode_);
0309   this->getFormatterEE()->process(fgvb_out_, even_peak_out_, even_filt_out_, odd_peak_out_, odd_filt_out_, format_out_);
0310 
0311   if (debug_) {
0312     edm::LogVerbatim("EcalTPG") << "\noutput of strip EE formatter is a vector of size: " << format_out_.size();
0313     edm::LogVerbatim("EcalTPG") << "value : ";
0314     for (unsigned int ix = 0; ix < format_out_.size(); ix++) {
0315       edm::LogVerbatim("EcalTPG") << "Clock: " << ix << "  value : " << format_out_[ix] << "  0b"
0316                                   << std::bitset<14>(format_out_[ix]).to_string();
0317     }
0318     edm::LogVerbatim("EcalTPG");
0319   }
0320 
0321   return;
0322 }