Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:26

0001 #include "DataFormats/DetId/interface/DetId.h"
0002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitAnalyzer.h"
0003 #include "SimCalorimetry/CaloSimAlgos/interface/CaloSimParameters.h"
0004 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVHitFilter.h"
0005 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVSimParameterMap.h"
0006 #include "SimCalorimetry/CaloSimAlgos/interface/CaloValidationStatistics.h"
0007 
0008 #include <iostream>
0009 
0010 CaloHitAnalyzer::CaloHitAnalyzer(const std::string &name,
0011                                  double hitEnergyThreshold,
0012                                  const CaloVSimParameterMap *parameterMap,
0013                                  const CaloVHitFilter *filter)
0014     : hitEnergySumMap_(),
0015       hitEnergyThreshold_(hitEnergyThreshold),
0016       simParameterMap_(parameterMap),
0017       hitFilter_(filter),
0018       summary_(name, 1., 0.),
0019       noiseHits_(0) {}
0020 
0021 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0022 void CaloHitAnalyzer::fillHits(MixCollection<PCaloHit> &hits) {
0023   hitEnergySumMap_.clear();
0024   noiseHits_ = 0;
0025   // store the energy of each hit in a map
0026   MixCollection<PCaloHit>::MixItr hitItr = hits.begin();
0027   MixCollection<PCaloHit>::MixItr last = hits.end();
0028   for (; hitItr != last; ++hitItr) {
0029     if (hitFilter_ == nullptr || hitFilter_->accepts(*hitItr)) {
0030       int id = hitItr->id();
0031       // double samplingFactor =
0032       // simParameterMap_->simParameters(DetId(id)).samplingFactor();
0033       double samplingFactor = 1.;
0034       double energy = hitItr->energy() * samplingFactor;
0035 
0036       // add it to the map
0037       std::map<int, double>::iterator mapItr = hitEnergySumMap_.find(id);
0038       if (mapItr == hitEnergySumMap_.end()) {
0039         hitEnergySumMap_[id] = energy;
0040       } else {
0041         mapItr->second += energy;
0042       }
0043     }
0044   }
0045 }
0046 
0047 void CaloHitAnalyzer::analyze(int id, double recEnergy) {
0048   if (recEnergy > hitEnergyThreshold_) {
0049     std::map<int, double>::iterator mapItr = hitEnergySumMap_.find(id);
0050     if (mapItr == hitEnergySumMap_.end()) {
0051       ++noiseHits_;
0052     } else {
0053       // keep statistics of the rec energy / sim energy
0054       summary_.addEntry(recEnergy / mapItr->second);
0055     }
0056   }
0057 }