CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/CalibCalorimetry/HcalAlgos/src/HcalPulseShapes.cc

Go to the documentation of this file.
00001 #include "CalibCalorimetry/HcalAlgos/interface/HcalPulseShapes.h"
00002 #include "CondFormats/HcalObjects/interface/HcalMCParam.h"
00003 #include "CondFormats/HcalObjects/interface/HcalMCParams.h"
00004 #include "CondFormats/DataRecord/interface/HcalMCParamsRcd.h"
00005 #include "CondFormats/HcalObjects/interface/HcalRecoParam.h"
00006 #include "CondFormats/HcalObjects/interface/HcalRecoParams.h"
00007 #include "CondFormats/DataRecord/interface/HcalRecoParamsRcd.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 // #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00013 #include <cmath>
00014 
00015 #include <iostream>
00016 #include <fstream>
00017 
00018 HcalPulseShapes::HcalPulseShapes() 
00019 : theMCParams(0),
00020   theRecoParams(0),
00021   theShapes()
00022 {
00023 /*
00024 
00025 Reco  MC
00026 --------------------------------------------------------------------------------------
00027 000                                                   not used (reserved)
00028 101   101      hpdShape_                              HPD (original version)
00029 102   102      =101                                   HPD BV 30 volts in HBP iphi54
00030 103   123      hpdShape_v2, hpdShapeMC_v2             HPD (2011. oct version)
00031 104   124      hpdBV30Shape_v2, hpdBV30ShapeMC_v2     HPD bv30 in HBP iph54
00032 105   125      hpdShape_v2, hpdShapeMC_v2             HPD (2011.11.12 version)
00033 201   201      siPMShape_                             SiPMs Zecotec shape   (HO)
00034 202   202      =201,                                  SiPMs Hamamatsu shape (HO)
00035 301   301      hfShape_                               regular HF PMT shape
00036 401   401                                             regular ZDC shape
00037 --------------------------------------------------------------------------------------
00038 
00039 */
00040 
00041  
00042   float ts1, ts2, ts3, thpd, tpre, wd1, wd2, wd3;
00043 
00044   //  HPD Shape  Version 1 (used before CMSSW5, until Oct 2011)
00045   ts1=8. ; ts2=10. ; ts3=29.3; thpd=4.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;  
00046   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShape_);
00047   theShapes[101] = &hpdShape_;
00048   theShapes[102] = theShapes[101];
00049 
00050   //  HPD Shape  Version 2 for CMSSW 5. Nov 2011  (RECO and MC separately)
00051   ts1=8. ; ts2=10. ; ts3=25.0; thpd=4.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
00052   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShape_v2);
00053   theShapes[103] = &hpdShape_v2;
00054 
00055   ts1=8. ; ts2=10. ; ts3=29.3; thpd=4.0; tpre=7.0; wd1=2.0; wd2=0.7; wd3=1.0;
00056   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShapeMC_v2);
00057   theShapes[123] = &hpdShapeMC_v2;
00058 
00059   //  HPD Shape  Version 3 for CMSSW 5. Nov 2011  (RECO and MC separately)
00060   ts1=8. ; ts2=19. ; ts3=29.3; thpd=4.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=0.32;
00061   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShape_v3);
00062   theShapes[105] = &hpdShape_v3;
00063 
00064   ts1=8. ; ts2=10. ; ts3=22.3; thpd=4.0; tpre=7.0; wd1=2.0; wd2=0.7; wd3=1.0;
00065   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShapeMC_v3);
00066   theShapes[125] = &hpdShapeMC_v3;
00067 
00068   // HPD with Bias Voltage 30 volts, wider pulse.  (HBPlus iphi54)
00069 
00070   ts1=8. ; ts2=12. ; ts3=31.7; thpd=9.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
00071   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdBV30Shape_v2);
00072   theShapes[104] = &hpdBV30Shape_v2;
00073 
00074   ts1=8. ; ts2=12. ; ts3=31.7; thpd=9.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
00075   computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdBV30ShapeMC_v2);
00076   theShapes[124] = &hpdBV30ShapeMC_v2;
00077 
00078   // HF and SiPM
00079 
00080   computeHFShape();
00081   computeSiPMShape();
00082 
00083   theShapes[201] = &siPMShape_;
00084   theShapes[202] = theShapes[201];
00085   theShapes[301] = &hfShape_;
00086   //theShapes[401] = new CaloCachedShapeIntegrator(&theZDCShape);
00087 
00088   /*
00089   // backward-compatibility with old scheme
00090   theShapes[0] = theShapes[101];
00091   //FIXME "special" HB
00092   theShapes[1] = theShapes[101];
00093   theShapes[2] = theShapes[201];
00094   theShapes[3] = theShapes[301];
00095   //theShapes[4] = theShapes[401];
00096   */
00097 }
00098 
00099 
00100 HcalPulseShapes::~HcalPulseShapes() {
00101   delete theMCParams;
00102   delete theRecoParams;
00103 }
00104 
00105 
00106 void HcalPulseShapes::beginRun(edm::EventSetup const & es)
00107 {
00108   edm::ESHandle<HcalMCParams> p;
00109   es.get<HcalMCParamsRcd>().get(p);
00110   theMCParams = new HcalMCParams(*p.product());
00111 
00112   edm::ESHandle<HcalRecoParams> q;
00113   es.get<HcalRecoParamsRcd>().get(q);
00114   theRecoParams = new HcalRecoParams(*q.product());
00115 
00116 //      std::cout<<" skdump in HcalPulseShapes::beginRun   dupm MCParams "<<std::endl;
00117 //      std::ofstream skfile("skdumpMCParamsNewFormat.txt");
00118 //      HcalDbASCIIIO::dumpObject(skfile, (*theMCParams) );
00119 }
00120 
00121 
00122 void HcalPulseShapes::endRun()
00123 {
00124   delete theMCParams;
00125   theMCParams = 0;
00126 
00127   delete theRecoParams;
00128   theRecoParams = 0;
00129 }
00130 
00131 
00132 //void HcalPulseShapes::computeHPDShape()
00133 void HcalPulseShapes::computeHPDShape(float ts1, float ts2, float ts3, float thpd, float tpre,
00134                                 float wd1, float wd2, float wd3, Shape &tmphpdShape_)
00135 {
00136 
00137   /*
00138   std::cout << "o HcalPulseShapes::computeHPDShape  " 
00139             << " ts1, ts2, ts3, thpd, tpre, w1, w2, w3 =" 
00140             <<  ts1 << ", " << ts2 << ", " << ts3 << ", " 
00141             << thpd << ", " << tpre << ", " << wd1 << ", " <<  wd2 
00142             << ", "  << wd3 << std::endl;
00143   */
00144 
00145 // pulse shape time constants in ns
00146 /*
00147   const float ts1  = 8.;          // scintillation time constants : 1,2,3
00148   const float ts2  = 10.;           
00149   const float ts3  = 29.3;         
00150   const float thpd = 4.;          // HPD current collection drift time
00151   const float tpre = 9.;          // preamp time constant (refit on TB04 data)
00152   
00153   const float wd1 = 2.;           // relative weights of decay exponents 
00154   const float wd2 = 0.7;
00155   const float wd3 = 1.;
00156 */  
00157   // pulse shape componnts over a range of time 0 ns to 255 ns in 1 ns steps
00158   unsigned int nbin = 256;
00159   tmphpdShape_.setNBin(nbin);
00160   std::vector<float> ntmp(nbin,0.0);  // zeroing output pulse shape
00161   std::vector<float> nth(nbin,0.0);   // zeroing HPD drift shape
00162   std::vector<float> ntp(nbin,0.0);   // zeroing Binkley preamp shape
00163   std::vector<float> ntd(nbin,0.0);   // zeroing Scintillator decay shape
00164 
00165   unsigned int i,j,k;
00166   float norm;
00167 
00168   // HPD starts at I and rises to 2I in thpd of time
00169   norm=0.0;
00170   for(j=0;j<thpd && j<nbin;j++){
00171     nth[j] = 1.0 + ((float)j)/thpd;
00172     norm += nth[j];
00173   }
00174   // normalize integrated current to 1.0
00175   for(j=0;j<thpd && j<nbin;j++){
00176     nth[j] /= norm;
00177   }
00178   
00179   // Binkley shape over 6 time constants
00180   norm=0.0;
00181   for(j=0;j<6*tpre && j<nbin;j++){
00182     ntp[j] = ((float)j)*exp(-((float)(j*j))/(tpre*tpre));
00183     norm += ntp[j];
00184   }
00185   // normalize pulse area to 1.0
00186   for(j=0;j<6*tpre && j<nbin;j++){
00187     ntp[j] /= norm;
00188   }
00189 
00190 // ignore stochastic variation of photoelectron emission
00191 // <...>
00192 
00193 // effective tile plus wave-length shifter decay time over 4 time constants
00194   unsigned int tmax = 6 * (int)ts3;
00195  
00196   norm=0.0;
00197   for(j=0;j<tmax && j<nbin;j++){
00198     ntd[j] = wd1 * exp(-((float)j)/ts1) + 
00199       wd2 * exp(-((float)j)/ts2) + 
00200       wd3 * exp(-((float)j)/ts3) ; 
00201     norm += ntd[j];
00202   }
00203   // normalize pulse area to 1.0
00204   for(j=0;j<tmax && j<nbin;j++){
00205     ntd[j] /= norm;
00206   }
00207   
00208   unsigned int t1,t2,t3,t4;
00209   for(i=0;i<tmax && i<nbin;i++){
00210     t1 = i;
00211     //    t2 = t1 + top*rand;
00212     // ignoring jitter from optical path length
00213     t2 = t1;
00214     for(j=0;j<thpd && j<nbin;j++){
00215       t3 = t2 + j;
00216       for(k=0;k<4*tpre && k<nbin;k++){       // here "4" is set deliberately,
00217         t4 = t3 + k;                         // as in test fortran toy MC ...
00218         if(t4<nbin){                         
00219           unsigned int ntb=t4;                        
00220           ntmp[ntb] += ntd[i]*nth[j]*ntp[k];
00221         }
00222       }
00223     }
00224   }
00225   
00226   // normalize for 1 GeV pulse height
00227   norm = 0.;
00228   for(i=0;i<nbin;i++){
00229     norm += ntmp[i];
00230   }
00231 
00232   //cout << " Convoluted SHAPE ==============  " << endl;
00233   for(i=0; i<nbin; i++){
00234     ntmp[i] /= norm;
00235     //  cout << " shape " << i << " = " << ntmp[i] << endl;   
00236   }
00237 
00238   for(i=0; i<nbin; i++){
00239     tmphpdShape_.setShapeBin(i,ntmp[i]);
00240   }
00241 }
00242 
00243 void HcalPulseShapes::computeHFShape() {
00244   // first create pulse shape over a range of time 0 ns to 255 ns in 1 ns steps
00245   unsigned int nbin = 256;
00246   hfShape_.setNBin(nbin);
00247   std::vector<float> ntmp(nbin,0.0);  // 
00248 
00249   const float k0=0.7956; // shape parameters
00250   const float p2=1.355;
00251   const float p4=2.327;
00252   const float p1=4.3;    // position parameter
00253 
00254   float norm = 0.0;
00255 
00256   for(unsigned int j = 0; j < 25 && j < nbin; ++j){
00257 
00258     float r0 = j-p1;
00259     float sigma0 = (r0<0) ? p2 : p2*p4;
00260     r0 /= sigma0;
00261     if(r0 < k0) ntmp[j] = exp(-0.5*r0*r0);
00262     else ntmp[j] = exp(0.5*k0*k0-k0*r0);
00263     norm += ntmp[j];
00264   }
00265   // normalize pulse area to 1.0
00266   for(unsigned int j = 0; j < 25 && j < nbin; ++j){
00267     ntmp[j] /= norm;
00268     hfShape_.setShapeBin(j,ntmp[j]);
00269   }
00270 }
00271 
00272 
00273 void HcalPulseShapes::computeSiPMShape()
00274 {
00275   unsigned int nbin = 512;
00276   siPMShape_.setNBin(nbin);
00277   std::vector<float> nt(nbin,0.0);  //
00278 
00279   double norm = 0.;
00280   for (unsigned int j = 0; j < nbin; ++j) {
00281     if (j <= 31.)
00282       nt[j] = 2.15*j;
00283     else if ((j > 31) && (j <= 96))
00284       nt[j] = 102.1 - 1.12*j;
00285     else
00286       nt[j] = 0.0076*j - 6.4;
00287     norm += (nt[j]>0) ? nt[j] : 0.;
00288   }
00289 
00290   for (unsigned int j = 0; j < nbin; ++j) {
00291     nt[j] /= norm;
00292     siPMShape_.setShapeBin(j,nt[j]);
00293   }
00294 }
00295 
00296 
00297 const HcalPulseShapes::Shape &
00298 HcalPulseShapes::getShape(int shapeType) const
00299 {
00300 
00301   //  std::cout << "- HcalPulseShapes::Shape for type "<< shapeType 
00302   //            << std::endl;
00303 
00304   ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
00305   if(shapeMapItr == theShapes.end()) {
00306    throw cms::Exception("HcalPulseShapes") << "unknown shapeType";
00307    return  hpdShape_;   // should not return this, but...
00308   } else {
00309     return *(shapeMapItr->second);
00310   }
00311 }
00312 
00313 
00314 const HcalPulseShapes::Shape &
00315 HcalPulseShapes::shape(const HcalDetId & detId) const
00316 {
00317   if(!theMCParams) {
00318     return defaultShape(detId);
00319   }
00320   int shapeType = theMCParams->getValues(detId)->signalShape();
00321   /*
00322           int sub     = detId.subdet();
00323           int depth   = detId.depth();
00324           int inteta  = detId.ieta();
00325           int intphi  = detId.iphi();
00326           
00327           std::cout << " HcalPulseShapes::shape cell:" 
00328                     << " sub, ieta, iphi, depth = " 
00329                     << sub << "  " << inteta << "  " << intphi 
00330                     << "  " << depth  << " => ShapeId "<<  shapeType 
00331                     << std::endl;
00332   */
00333   ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
00334   if(shapeMapItr == theShapes.end()) {
00335     return defaultShape(detId);
00336   } else {
00337     return *(shapeMapItr->second);
00338   }
00339 }
00340 
00341 const HcalPulseShapes::Shape &
00342 HcalPulseShapes::shapeForReco(const HcalDetId & detId) const
00343 {
00344   if(!theRecoParams) {
00345     return defaultShape(detId);
00346   }
00347   int shapeType = theRecoParams->getValues(detId.rawId())->pulseShapeID();
00348   /*
00349           int sub     = detId.subdet();
00350           int depth   = detId.depth();
00351           int inteta  = detId.ieta();
00352           int intphi  = detId.iphi();
00353           
00354           std::cout << ">> HcalPulseShapes::shapeForReco cell:" 
00355                     << " sub, ieta, iphi, depth = " 
00356                     << sub << "  " << inteta << "  " << intphi 
00357                     << "  " << depth  << " => ShapeId "<<  shapeType 
00358                     << std::endl;
00359   */
00360 
00361   ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
00362   if(shapeMapItr == theShapes.end()) {
00363     return defaultShape(detId);
00364   } else {
00365     return *(shapeMapItr->second);
00366   }
00367 }
00368 
00369 
00370 const HcalPulseShapes::Shape &
00371 HcalPulseShapes::defaultShape(const HcalDetId & detId) const
00372 {
00373   edm::LogWarning("HcalPulseShapes") << "Cannot find HCAL MC Params ";
00374   HcalSubdetector subdet = detId.subdet();
00375   switch(subdet) {
00376   case HcalBarrel:
00377     return hbShape();
00378   case HcalEndcap:
00379     return heShape();
00380   case HcalForward:
00381     return hfShape();
00382   case HcalOuter:
00383     //FIXME doesn't look for SiPMs
00384     return hoShape(false);
00385   default:
00386     throw cms::Exception("HcalPulseShapes") << "unknown detId";
00387     break;
00388   }
00389 }
00390