CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/SimCalorimetry/HcalSimAlgos/src/HcalSiPMHitResponse.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSiPMHitResponse.h"
00002 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSiPM.h"
00003 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h"
00004 #include "SimCalorimetry/HcalSimAlgos/interface/HcalShapes.h"
00005 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVHitFilter.h"
00008 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVSimParameterMap.h"
00009 #include "SimCalorimetry/CaloSimAlgos/interface/CaloSimParameters.h"
00010 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVHitCorrection.h"
00011 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVShape.h"
00012 #include "FWCore/Utilities/interface/isFinite.h"
00013 
00014 HcalSiPMHitResponse::HcalSiPMHitResponse(const CaloVSimParameterMap * parameterMap,
00015                                          const CaloShapes * shapes) :
00016   CaloHitResponse(parameterMap, shapes), theSiPM(0), theRecoveryTime(250.) {
00017   theSiPM = new HcalSiPM(14000);
00018 }
00019 
00020 HcalSiPMHitResponse::~HcalSiPMHitResponse() {
00021   if (theSiPM)
00022     delete theSiPM;
00023 }
00024 
00025 void HcalSiPMHitResponse::initializeHits() {
00026 }
00027 
00028 void HcalSiPMHitResponse::finalizeHits() {
00029 }
00030 
00031 
00032 void HcalSiPMHitResponse::add(const PCaloHit& hit) {
00033     if (!edm::isNotFinite(hit.time()) &&
00034         ((theHitFilter == 0) || (theHitFilter->accepts(hit)))) {
00035       DetId id(hit.id());
00036       if (pixelHistory.find(id)==pixelHistory.end()) {
00037         pixelHistory.insert(std::pair<DetId, HcalSiPMRecovery>(id, HcalSiPMRecovery(theRecoveryTime)));
00038       }
00039       int pixelIntegral = pixelHistory[id].getIntegral(hit.time());
00040       int oldIntegral = pixelIntegral;
00041       CaloSamples signal(makeSiPMSignal(id, hit, pixelIntegral));
00042       pixelHistory[id].addToHistory(hit.time(), pixelIntegral-oldIntegral);
00043       add(signal);
00044     }
00045 }
00046 
00047 void HcalSiPMHitResponse::run(MixCollection<PCaloHit> & hits) {
00048   typedef std::multiset <const PCaloHit *, PCaloHitCompareTimes> SortedHitSet;
00049 
00050   std::map< DetId, SortedHitSet > sortedhits;
00051   for (MixCollection<PCaloHit>::MixItr hitItr = hits.begin();
00052        hitItr != hits.end(); ++hitItr) {
00053     if (!((hitItr.bunch() < theMinBunch) || (hitItr.bunch() > theMaxBunch)) &&
00054         !(edm::isNotFinite(hitItr->time())) &&
00055         ((theHitFilter == 0) || (theHitFilter->accepts(*hitItr)))) {
00056       DetId id(hitItr->id());
00057       if (sortedhits.find(id)==sortedhits.end())
00058         sortedhits.insert(std::pair<DetId, SortedHitSet>(id, SortedHitSet()));
00059       sortedhits[id].insert(&(*hitItr));
00060     }
00061   }
00062   int pixelIntegral, oldIntegral;
00063   HcalSiPMRecovery pixelHistory(theRecoveryTime);
00064   for (std::map<DetId, SortedHitSet>::iterator i = sortedhits.begin(); 
00065        i!=sortedhits.end(); ++i) {
00066     pixelHistory.clearHistory();
00067     for (SortedHitSet::iterator itr = i->second.begin(); 
00068          itr != i->second.end(); ++itr) {
00069       const PCaloHit& hit = **itr;
00070       pixelIntegral = pixelHistory.getIntegral(hit.time());
00071       oldIntegral = pixelIntegral;
00072       CaloSamples signal(makeSiPMSignal(i->first, hit, pixelIntegral));
00073       pixelHistory.addToHistory(hit.time(), pixelIntegral-oldIntegral);
00074       add(signal);
00075     }
00076   }
00077 }
00078 
00079 
00080 void HcalSiPMHitResponse::setRandomEngine(CLHEP::HepRandomEngine & engine)
00081 {
00082   theSiPM->initRandomEngine(engine);
00083   CaloHitResponse::setRandomEngine(engine);
00084 }
00085 
00086 
00087 CaloSamples HcalSiPMHitResponse::makeSiPMSignal(const DetId & id,
00088                                                 const PCaloHit & inHit, 
00089                                                 int & integral ) const {
00090   
00091   PCaloHit hit = inHit;
00092   if (theHitCorrection != 0) {
00093     hit.setTime(hit.time() + theHitCorrection->delay(hit));
00094   }
00095 
00096   const HcalSimParameters& pars = dynamic_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
00097   theSiPM->setNCells(pars.pixels());
00098 
00099   double signal = analogSignalAmplitude(id, hit.energy(), pars);
00100   int photons = static_cast<int>(signal + 0.5);
00101   int pixels = theSiPM->hitCells(photons, integral);
00102   integral += pixels;
00103   signal = double(pixels);
00104 
00105   CaloSamples result(makeBlankSignal(id));
00106 
00107   if(pixels > 0)
00108   {
00109     const CaloVShape * shape = theShapes->shape(id);
00110     double jitter = hit.time() - timeOfFlight(id);
00111 
00112     const double tzero = pars.timePhase() - jitter -
00113       BUNCHSPACE*(pars.binOfMaximum() - thePhaseShift_);
00114     double binTime = tzero;
00115 
00116     for (int bin = 0; bin < result.size(); bin++) {
00117       result[bin] += (*shape)(binTime)*signal;
00118       binTime += BUNCHSPACE;
00119     }
00120   }
00121 
00122   return result;
00123 }
00124