Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-14 02:22:58

0001 #ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBTrigPrimTestAlgo_h
0002 #define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBTrigPrimTestAlgo_h
0003 /** \class EcalEBTrigPrimTestAlgo
0004 \author N. Marinelli - Univ. of Notre Dame
0005  * forPhase II 
0006  * While the new digitization is not yet implemented, we use the old Digis to make TP per crystal
0007  *
0008  ************************************************************/
0009 #include <sys/time.h>
0010 #include <iostream>
0011 #include <vector>
0012 
0013 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0014 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0015 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
0016 #include "DataFormats/Common/interface/SortedCollection.h"
0017 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0018 
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0021 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0022 
0023 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixLinearizer.h>
0024 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixAmplitudeFilter.h>
0025 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixPeakFinder.h>
0026 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixStripFormatEB.h>
0027 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixTcpFormat.h>
0028 
0029 #include <map>
0030 #include <utility>
0031 
0032 class EcalTrigTowerDetId;
0033 class ETPCoherenceTest;
0034 class EcalEBTriggerPrimitiveSample;
0035 class EBDataFrame;
0036 
0037 class EcalEBTrigPrimTestAlgo {
0038 public:
0039   // not BarrelOnly
0040   explicit EcalEBTrigPrimTestAlgo(const EcalTrigTowerConstituentsMap *eTTmap,
0041                                   const CaloGeometry *theGeometry,
0042                                   int nSamples,
0043                                   int binofmax,
0044                                   bool tcpFormat,
0045                                   bool debug,
0046                                   bool famos);
0047   //barrel only
0048   explicit EcalEBTrigPrimTestAlgo(int nSamples, int binofmax, bool tcpFormat, bool debug, bool famos);
0049 
0050   virtual ~EcalEBTrigPrimTestAlgo();
0051 
0052   void run(const EBDigiCollection *col, EcalEBTrigPrimDigiCollection &result, EcalEBTrigPrimDigiCollection &resultTcp);
0053 
0054   void setPointers(const EcalTPGLinearizationConst *ecaltpLin,
0055                    const EcalTPGPedestals *ecaltpPed,
0056                    const EcalTPGCrystalStatus *ecaltpgBadX,
0057                    const EcalTPGWeightIdMap *ecaltpgWeightMap,
0058                    const EcalTPGWeightGroup *ecaltpgWeightGroup,
0059                    const EcalTPGSlidingWindow *ecaltpgSlidW,
0060                    const EcalTPGLutGroup *ecaltpgLutGroup,
0061                    const EcalTPGLutIdMap *ecaltpgLut,
0062                    const EcalTPGTowerStatus *ecaltpgBadTT,
0063                    const EcalTPGSpike *ecaltpgSpike) {
0064     ecaltpPed_ = ecaltpPed;
0065     ecaltpLin_ = ecaltpLin;
0066     ecaltpgBadX_ = ecaltpgBadX;
0067     ecaltpgWeightMap_ = ecaltpgWeightMap;
0068     ecaltpgWeightGroup_ = ecaltpgWeightGroup;
0069     ecaltpgSlidW_ = ecaltpgSlidW;
0070     ecaltpgLutGroup_ = ecaltpgLutGroup;
0071     ecaltpgLut_ = ecaltpgLut;
0072     ecaltpgBadTT_ = ecaltpgBadTT;
0073     ecaltpgSpike_ = ecaltpgSpike;
0074   }
0075 
0076 private:
0077   void init();
0078   template <class T>
0079   void initStructures(std::vector<std::vector<std::pair<int, std::vector<T> > > > &towMap);
0080   template <class T>
0081   void clean(std::vector<std::vector<std::pair<int, std::vector<T> > > > &towerMap);
0082   template <class Coll>
0083   void fillMap(Coll const *col,
0084                std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi> > > > &towerMap);
0085   int findStripNr(const EBDetId &id);
0086   int findStripNr(const EEDetId &id);
0087 
0088   // FIXME: temporary until hashedIndex works alsom for endcap
0089   int getIndex(const EBDigiCollection *, EcalTrigTowerDetId &id) { return id.hashedIndex(); }
0090   // mind that eta is continuous between barrel+endcap
0091   int getIndex(const EEDigiCollection *, EcalTrigTowerDetId &id) {
0092     int ind = (id.ietaAbs() - 18) * 72 + id.iphi();
0093     if (id.zside() < 0)
0094       ind += 792;
0095     return ind;
0096   }
0097 
0098   const EcalTrigTowerConstituentsMap *eTTmap_ = nullptr;
0099   const CaloGeometry *theGeometry_ = nullptr;
0100 
0101   float threshold;
0102   int nSamples_;
0103   int binOfMaximum_;
0104   int maxNrSamples_;
0105 
0106   bool tcpFormat_;
0107   bool barrelOnly_;
0108   bool debug_;
0109   bool famos_;
0110 
0111   int nrTowers_;  // nr of towers found by fillmap method
0112   static const unsigned int maxNrTowers_;
0113   static const unsigned int maxNrSamplesOut_;
0114   static const unsigned int nrSamples_;
0115 
0116   // data structures kept during the whole run
0117   std::vector<std::vector<int> > striptp_;
0118   std::vector<std::vector<std::pair<int, std::vector<EBDataFrame> > > > towerMapEB_;
0119   std::vector<std::vector<std::pair<int, std::vector<EEDataFrame> > > > towerMapEE_;
0120   std::vector<std::pair<int, EcalTrigTowerDetId> > hitTowers_;
0121   std::vector<EcalEBTriggerPrimitiveSample> towtp_;
0122   std::vector<EcalEBTriggerPrimitiveSample> towtp2_;
0123 
0124   enum { nbMaxStrips_ = 5 };
0125   enum { nbMaxXtals_ = 5 };
0126 
0127   const EcalElectronicsMapping *theMapping_;
0128 
0129   std::vector<EcalEBFenixLinearizer *> linearizer_;
0130   EcalEBFenixAmplitudeFilter *amplitude_filter_;
0131   EcalEBFenixPeakFinder *peak_finder_;
0132   EcalEBFenixStripFormatEB *fenixFormatterEB_;
0133   EcalEBFenixTcpFormat *fenixTcpFormat_;
0134 
0135   //
0136   const EcalTPGPedestals *ecaltpPed_;
0137   const EcalTPGLinearizationConst *ecaltpLin_;
0138   const EcalTPGCrystalStatus *ecaltpgBadX_;
0139   const EcalTPGWeightIdMap *ecaltpgWeightMap_;
0140   const EcalTPGWeightGroup *ecaltpgWeightGroup_;
0141   const EcalTPGSlidingWindow *ecaltpgSlidW_;
0142   const EcalTPGLutGroup *ecaltpgLutGroup_;
0143   const EcalTPGLutIdMap *ecaltpgLut_;
0144   const EcalTPGTowerStatus *ecaltpgBadTT_;
0145   const EcalTPGSpike *ecaltpgSpike_;
0146 
0147   EcalEBFenixLinearizer *getLinearizer(int i) const { return linearizer_[i]; }
0148   std::vector<std::vector<int> > lin_out_;
0149   //
0150   EcalEBFenixAmplitudeFilter *getFilter() const { return amplitude_filter_; }
0151   std::vector<int> filt_out_;
0152   std::vector<int> peak_out_;
0153   std::vector<int> format_out_;
0154   // these two are dummy
0155   std::vector<int> fgvb_out_;
0156   std::vector<int> fgvb_out_temp_;
0157 
0158   //
0159   EcalEBFenixPeakFinder *getPeakFinder() const { return peak_finder_; }
0160   EcalEBFenixStripFormatEB *getFormatterEB() const { return fenixFormatterEB_; }
0161   //
0162   EcalEBFenixTcpFormat *getFormatter() const { return fenixTcpFormat_; }
0163   std::vector<int> tcpformat_out_;
0164 };
0165 
0166 template <class T>
0167 void EcalEBTrigPrimTestAlgo::clean(std::vector<std::vector<std::pair<int, std::vector<T> > > > &towMap) {
0168   // clean internal data structures
0169   for (unsigned int i = 0; i < maxNrTowers_; ++i)
0170     for (int j = 0; j < nbMaxStrips_; ++j)
0171       (towMap[i])[j].first = 0;
0172   return;
0173 }
0174 
0175 template <class Coll>
0176 void EcalEBTrigPrimTestAlgo::fillMap(
0177     Coll const *col, std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi> > > > &towerMap) {
0178   typedef typename Coll::Digi Digi;
0179 
0180   // implementation for Barrel
0181   if (col) {
0182     nrTowers_ = 0;
0183     if (debug_)
0184       std::cout << "Fill mapping, Collection size = " << col->size() << std::endl;
0185     ;
0186     for (unsigned int i = 0; i < col->size(); ++i) {
0187       Digi samples((*col)[i]);
0188       EcalTrigTowerDetId coarser = (*eTTmap_).towerOf(samples.id());
0189       int index = getIndex(col, coarser);
0190       int stripnr = findStripNr(samples.id());
0191 
0192       int filled = 0;
0193       for (unsigned int ij = 0; ij < towerMap[index].size(); ++ij)
0194         filled += towerMap[index][ij].first;
0195       if (!filled) {
0196         hitTowers_[nrTowers_++] = std::pair<int, EcalTrigTowerDetId>(index, coarser);
0197       }
0198 
0199       //FIXME: temporary protection
0200       int ncryst = towerMap[index][stripnr - 1].first;
0201       if (ncryst >= nbMaxXtals_) {
0202         edm::LogError("EcalTrigPrimFunctionAlgo")
0203             << "! Too many xtals for TT " << coarser << " stripnr " << stripnr << " xtalid " << samples.id();
0204         continue;
0205       }
0206       ((towerMap[index])[stripnr - 1].second)[ncryst] = samples;
0207       (towerMap[index])[stripnr - 1].first++;
0208     }
0209 
0210     if (debug_)
0211       std::cout << "fillMap"
0212                 << "[EcalTrigPrimFunctionalAlgo] (found " << col->size() << " frames in " << towerMap.size()
0213                 << " towers) " << std::endl;
0214   } else {
0215     if (debug_)
0216       std::cout << "FillMap - FillMap Collection size=0 !!!!" << std::endl;
0217     ;
0218   }
0219 }
0220 
0221 template <class T>
0222 void EcalEBTrigPrimTestAlgo::initStructures(std::vector<std::vector<std::pair<int, std::vector<T> > > > &towMap) {
0223   //initialise internal data structures
0224 
0225   std::vector<T> vec0(nbMaxXtals_);
0226   std::vector<std::pair<int, std::vector<T> > > vec1(nbMaxStrips_);
0227   for (int i = 0; i < nbMaxStrips_; ++i)
0228     vec1[i] = std::pair<int, std::vector<T> >(0, vec0);
0229   towMap.resize(maxNrTowers_);
0230   for (unsigned int i = 0; i < maxNrTowers_; ++i)
0231     towMap[i] = vec1;
0232 
0233   std::vector<int> vecint(maxNrSamples_);
0234   striptp_.resize(nbMaxStrips_);
0235   for (int i = 0; i < nbMaxStrips_; ++i)
0236     striptp_[i] = vecint;
0237 }
0238 
0239 #endif