CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/SimCalorimetry/CaloSimAlgos/src/CaloHitAnalyzer.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitAnalyzer.h"
00002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloValidationStatistics.h"
00003 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVSimParameterMap.h"
00004 #include "SimCalorimetry/CaloSimAlgos/interface/CaloSimParameters.h"
00005 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVHitFilter.h"
00006 #include "DataFormats/DetId/interface/DetId.h"
00007 
00008 #include <iostream>
00009 
00010 CaloHitAnalyzer::CaloHitAnalyzer(const std::string & name,
00011                       double hitEnergyThreshold,
00012                       const CaloVSimParameterMap * parameterMap,
00013                       const CaloVHitFilter * filter)
00014 : hitEnergySumMap_(),
00015   hitEnergyThreshold_(hitEnergyThreshold),
00016   simParameterMap_(parameterMap),
00017   hitFilter_(filter),
00018   summary_(name, 1., 0.),
00019   noiseHits_(0)
00020 {
00021 }
00022 
00023 
00024 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00025 void CaloHitAnalyzer::fillHits(MixCollection<PCaloHit> & hits) {
00026   hitEnergySumMap_.clear();
00027   noiseHits_ = 0;
00028   // store the energy of each hit in a map
00029   MixCollection<PCaloHit>::MixItr hitItr = hits.begin();
00030   MixCollection<PCaloHit>::MixItr last = hits.end();
00031   for( ; hitItr != last; ++hitItr) 
00032   {
00033     if(hitFilter_ == 0 || hitFilter_->accepts(*hitItr)) {
00034       int id = hitItr->id();
00035       //double samplingFactor = simParameterMap_->simParameters(DetId(id)).samplingFactor();
00036       double samplingFactor = 1.;
00037       double energy = hitItr->energy() * samplingFactor;
00038 
00039       // add it to the map
00040       std::map<int, double>::iterator mapItr = hitEnergySumMap_.find(id);
00041       if(mapItr == hitEnergySumMap_.end()) {
00042         hitEnergySumMap_[id] = energy;
00043       } else {
00044         mapItr->second += energy;
00045       }
00046     }
00047   }
00048 }
00049 
00050 
00051 void CaloHitAnalyzer::analyze(int id, double recEnergy) {
00052   if(recEnergy > hitEnergyThreshold_) {
00053     std::map<int, double>::iterator mapItr = hitEnergySumMap_.find(id);
00054     if(mapItr == hitEnergySumMap_.end()) {
00055       ++noiseHits_;
00056     } else {
00057        // keep statistics of the rec energy / sim energy
00058       summary_.addEntry(recEnergy/mapItr->second);
00059     }
00060   }
00061 }
00062