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
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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 float ts1, ts2, ts3, thpd, tpre, wd1, wd2, wd3;
00043
00044
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
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
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
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
00079
00080 computeHFShape();
00081 computeSiPMShape();
00082
00083 theShapes[201] = &siPMShape_;
00084 theShapes[202] = theShapes[201];
00085 theShapes[301] = &hfShape_;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
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
00117
00118
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
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
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 unsigned int nbin = 256;
00159 tmphpdShape_.setNBin(nbin);
00160 std::vector<float> ntmp(nbin,0.0);
00161 std::vector<float> nth(nbin,0.0);
00162 std::vector<float> ntp(nbin,0.0);
00163 std::vector<float> ntd(nbin,0.0);
00164
00165 unsigned int i,j,k;
00166 float norm;
00167
00168
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
00175 for(j=0;j<thpd && j<nbin;j++){
00176 nth[j] /= norm;
00177 }
00178
00179
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
00186 for(j=0;j<6*tpre && j<nbin;j++){
00187 ntp[j] /= norm;
00188 }
00189
00190
00191
00192
00193
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
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
00212
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++){
00217 t4 = t3 + k;
00218 if(t4<nbin){
00219 unsigned int ntb=t4;
00220 ntmp[ntb] += ntd[i]*nth[j]*ntp[k];
00221 }
00222 }
00223 }
00224 }
00225
00226
00227 norm = 0.;
00228 for(i=0;i<nbin;i++){
00229 norm += ntmp[i];
00230 }
00231
00232
00233 for(i=0; i<nbin; i++){
00234 ntmp[i] /= norm;
00235
00236 }
00237
00238 for(i=0; i<nbin; i++){
00239 tmphpdShape_.setShapeBin(i,ntmp[i]);
00240 }
00241 }
00242
00243 void HcalPulseShapes::computeHFShape() {
00244
00245 unsigned int nbin = 256;
00246 hfShape_.setNBin(nbin);
00247 std::vector<float> ntmp(nbin,0.0);
00248
00249 const float k0=0.7956;
00250 const float p2=1.355;
00251 const float p4=2.327;
00252 const float p1=4.3;
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
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
00302
00303
00304 ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
00305 if(shapeMapItr == theShapes.end()) {
00306 throw cms::Exception("HcalPulseShapes") << "unknown shapeType";
00307 return hpdShape_;
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
00323
00324
00325
00326
00327
00328
00329
00330
00331
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
00350
00351
00352
00353
00354
00355
00356
00357
00358
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
00384 return hoShape(false);
00385 default:
00386 throw cms::Exception("HcalPulseShapes") << "unknown detId";
00387 break;
00388 }
00389 }
00390