Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 =
0189           eTTmap_ ? (*eTTmap_).towerOf(samples.id()) : EcalTrigTowerConstituentsMap::barrelTowerOf(samples.id());
0190       int index = getIndex(col, coarser);
0191       int stripnr = findStripNr(samples.id());
0192 
0193       int filled = 0;
0194       for (unsigned int ij = 0; ij < towerMap[index].size(); ++ij)
0195         filled += towerMap[index][ij].first;
0196       if (!filled) {
0197         hitTowers_[nrTowers_++] = std::pair<int, EcalTrigTowerDetId>(index, coarser);
0198       }
0199 
0200       //FIXME: temporary protection
0201       int ncryst = towerMap[index][stripnr - 1].first;
0202       if (ncryst >= nbMaxXtals_) {
0203         edm::LogError("EcalTrigPrimFunctionAlgo")
0204             << "! Too many xtals for TT " << coarser << " stripnr " << stripnr << " xtalid " << samples.id();
0205         continue;
0206       }
0207       ((towerMap[index])[stripnr - 1].second)[ncryst] = samples;
0208       (towerMap[index])[stripnr - 1].first++;
0209     }
0210 
0211     if (debug_)
0212       std::cout << "fillMap"
0213                 << "[EcalTrigPrimFunctionalAlgo] (found " << col->size() << " frames in " << towerMap.size()
0214                 << " towers) " << std::endl;
0215   } else {
0216     if (debug_)
0217       std::cout << "FillMap - FillMap Collection size=0 !!!!" << std::endl;
0218     ;
0219   }
0220 }
0221 
0222 template <class T>
0223 void EcalEBTrigPrimTestAlgo::initStructures(std::vector<std::vector<std::pair<int, std::vector<T> > > > &towMap) {
0224   //initialise internal data structures
0225 
0226   std::vector<T> vec0(nbMaxXtals_);
0227   std::vector<std::pair<int, std::vector<T> > > vec1(nbMaxStrips_);
0228   for (int i = 0; i < nbMaxStrips_; ++i)
0229     vec1[i] = std::pair<int, std::vector<T> >(0, vec0);
0230   towMap.resize(maxNrTowers_);
0231   for (unsigned int i = 0; i < maxNrTowers_; ++i)
0232     towMap[i] = vec1;
0233 
0234   std::vector<int> vecint(maxNrSamples_);
0235   striptp_.resize(nbMaxStrips_);
0236   for (int i = 0; i < nbMaxStrips_; ++i)
0237     striptp_[i] = vecint;
0238 }
0239 
0240 #endif