CMS 3D CMS Logo

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