25 RespPar[
HCAL][0][0] = pset.
getParameter<
double>(
"HadronBarrelResolution_Stochastic");
26 RespPar[
HCAL][0][1] = pset.
getParameter<
double>(
"HadronBarrelResolution_Constant");
27 RespPar[
HCAL][0][2] = pset.
getParameter<
double>(
"HadronBarrelResolution_Noise");
29 RespPar[
HCAL][1][0] = pset.
getParameter<
double>(
"HadronEndcapResolution_Stochastic");
30 RespPar[
HCAL][1][1] = pset.
getParameter<
double>(
"HadronEndcapResolution_Constant");
31 RespPar[
HCAL][1][2] = pset.
getParameter<
double>(
"HadronEndcapResolution_Noise");
33 RespPar[
VFCAL][0][0] = pset.
getParameter<
double>(
"HadronForwardResolution_Stochastic");
34 RespPar[
VFCAL][0][1] = pset.
getParameter<
double>(
"HadronForwardResolution_Constant");
35 RespPar[
VFCAL][0][2] = pset.
getParameter<
double>(
"HadronForwardResolution_Noise");
37 RespPar[
VFCAL][1][0] = pset.
getParameter<
double>(
"ElectronForwardResolution_Stochastic");
38 RespPar[
VFCAL][1][1] = pset.
getParameter<
double>(
"ElectronForwardResolution_Constant");
39 RespPar[
VFCAL][1][2] = pset.
getParameter<
double>(
"ElectronForwardResolution_Noise");
41 eResponseScale[0] = pset.
getParameter<
double>(
"eResponseScaleHB");
42 eResponseScale[1] = pset.
getParameter<
double>(
"eResponseScaleHE");
43 eResponseScale[2] = pset.
getParameter<
double>(
"eResponseScaleHF");
45 eResponsePlateau[0] = pset.
getParameter<
double>(
"eResponsePlateauHB");
46 eResponsePlateau[1] = pset.
getParameter<
double>(
"eResponsePlateauHE");
47 eResponsePlateau[2] = pset.
getParameter<
double>(
"eResponsePlateauHF");
49 eResponseExponent = pset.
getParameter<
double>(
"eResponseExponent");
50 eResponseCoefficient = pset.
getParameter<
double>(
"eResponseCoefficient");
73 maxHDetas[0] = HDeta[1] - HDeta[0];
74 maxHDetas[1] = HDeta[2] - HDeta[1];
75 maxHDetas[2] = HDeta[3] - HDeta[2];
79 parNames = pset.
getParameter<std::vector<std::string> >(
"parNames");
85 for(
int p = 0;
p < nPar;
p++){
86 for(
int m = 0;
m < 3;
m++){
87 for(
int d = 0;
d < 3;
d++){
95 for(
int i = 0;
i < maxHDe[
d];
i++){
99 for(
int j = 0;
j < maxHDetas[
d];
j++){
109 PoissonParameters=
vec3(4);
110 std::string PoissonParName[] = {
"mean_overall",
"shift_overall",
"mean_between",
"shift_between"};
111 for(
int d = 0;
d < 4;
d++){
113 for(
int i = 0;
i < maxHDe[3];
i++){
114 PoissonParameters[
d].resize(maxHDe[3]);
115 for(
int j = 0;
j < maxHDetas[2];
j++){
116 PoissonParameters[
d][
i].resize(maxHDetas[2]);
117 PoissonParameters[
d][
i][
j]= tmp1[
i*maxHDetas[2] +
j];
125 mipfraction =
vec3(3);
126 for(
int d = 0;
d < 3;
d++){
128 std::string mipname = fraction + mipNames[0] + detNames[
d] ;
130 mipfraction[
d].resize(maxHDe[
d]);
131 for(
int i = 0;
i < maxHDe[
d];
i++){
133 mipfraction[
d][
i].resize(maxHDetas[d]);
134 for(
int j = 0;
j < maxHDetas[
d];
j++){
136 mipfraction[
d][
i][
j]= tmp1[
i*maxHDetas[
d] +
j];
152 double _barrelMUeta = pset.
getParameter<
double>(
"barrelMUeta");
153 double _endcapMUeta = pset.
getParameter<
double>(
"endcapMUeta");
154 barrelMUeta = endcapMUeta = maxMUeta;
155 for(
int i = 0;
i < maxMUeta;
i++) {
156 if(fabs(_barrelMUeta) <= etaGridMU[
i]) { barrelMUeta =
i;
break; }
158 for(
int i = 0;
i < maxMUeta;
i++) {
159 if(fabs(_endcapMUeta) <= etaGridMU[
i]) { endcapMUeta =
i;
break; }
161 int maxMUetas[] = {endcapMUeta - barrelMUeta, maxMUeta - endcapMUeta};
164 responseMU =
vec3(maxMUe,
vec2(maxMUeta,
vec1(maxMUbin,0)));
170 for(
int i = 0;
i < maxMUe;
i++){
171 for(
int j = 0;
j < maxMUeta;
j++){
173 if(
j==barrelMUeta) {loc = 0; eta_loc = barrelMUeta;}
174 else if(
j==endcapMUeta) {loc = 1; eta_loc = endcapMUeta;}
176 for(
int k = 0;
k < maxMUbin;
k++){
177 responseMU[
i][
j][
k] = _responseMU[loc][
i*maxMUetas[loc]*maxMUbin + (
j-eta_loc)*maxMUbin +
k];
181 LogInfo(
"FastCalorimetry") <<
" responseMU " <<
i <<
" " <<
j <<
" " <<
k <<
" = "
182 << responseMU[
i][
j][
k] << std::endl;
191 maxEMeta = maxHDetas[2];
192 respFactorEM = pset.
getParameter<
double>(
"respFactorEM");
200 meanEM =
vec2(maxEMe,
vec1(maxEMeta,0));
201 sigmaEM =
vec2(maxEMe,
vec1(maxEMeta,0));
202 for(
int i = 0;
i < maxEMe;
i++){
203 for(
int j = 0;
j < maxEMeta;
j++){
204 meanEM[
i][
j] = respFactorEM * _meanEM[
i*maxEMeta +
j];
205 sigmaEM[
i][
j] = respFactorEM * _sigmaEM[
i*maxEMeta +
j];
220 int ieta =
abs((
int)(eta / etaStep)) ;
223 int det = getDet(ieta);
224 int deta = ieta - HDeta[det];
225 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
226 else if(deta < 0 ) deta = 0;
228 for (
int i = 0;
i < maxHDe[det];
i++) {
229 if(energy < eGridHD[det][
i]) {
230 if(i == 0)
return mipfraction [det][0][deta];
235 if(ie == -1)
return mipfraction [det][maxHDe[det]-1][deta];
237 double x1 = eGridHD[det][ie];
238 double x2 = eGridHD[det][ie+1];
239 y1=mipfraction[det][ie][deta];
240 y2=mipfraction[det][ie+1][deta];
242 mean=(y1*(x2-
energy) + y2*(energy-x1))/(x2-x1);
249 int ieta =
abs((
int)(eta / etaStep)) ;
253 if(usemip) mip = _mip;
263 if(ieta >= maxEMeta ) ieta = maxEMeta-1;
264 else if(ieta < 0) ieta = 0;
267 for (
int i = 0;
i < maxEMe;
i++) {
268 if(energy < eGridEM[
i]) {
274 if(ie == -1) ie = maxEMe - 2;
277 mean = interEM(energy, ie, ieta, random);
281 else if(partype == 1) {
283 int det = getDet(ieta);
284 int deta = ieta - HDeta[det];
285 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
286 else if(deta < 0 ) deta = 0;
289 for (
int i = 0;
i < maxHDe[det];
i++) {
290 if(energy < eGridHD[det][
i]) {
296 if(ie == -1) ie = maxHDe[det] - 2;
299 if(det==2 && energy <20 && deta>5){
300 for (
int i = 0;
i < maxHDe[3];
i++) {
301 if(energy < eGridHD[3][
i]) {
309 mean = interHD(mip, energy, ie, deta, det, random);
314 else if(partype == 2) {
317 for(
int i = 0;
i < maxMUeta;
i++) {
318 if(fabs(eta) < etaGridMU[
i]) {
323 if(ieta < 0) ieta = 0;
325 if(ieta < maxMUeta) {
327 for (
int i = 0;
i < maxMUe;
i++) {
328 if(energy < eGridMU[
i]) {
334 if(ie == -1) ie = maxMUe - 2;
337 mean = interMU(energy, ie, ieta, random);
338 if(mean > energy) mean =
energy;
345 LogInfo(
"FastCalorimetry") << std::endl
346 <<
" HCALResponse::responseHCAL, partype = " << partype
347 <<
" E, eta = " << energy <<
" " << eta
348 <<
" mean = " << mean << std::endl;
358 for(
int i = 0;
i < maxMUbin;
i++) {
359 if(x > responseMU[ie][ieta][
i]) {
365 for(
int i = 0;
i < maxMUbin;
i++) {
366 if(x > responseMU[ie+1][ieta][
i]) {
372 double x1 = eGridMU[ie];
373 double x2 = eGridMU[ie+1];
374 double y1 = (bin1 + random->
flatShoot()) * muStep;
375 double y2 = (bin2 + random->
flatShoot()) * muStep;
379 LogInfo(
"FastCalorimetry") << std::endl
380 <<
" HCALResponse::interMU " << std::endl
381 <<
" x, x1-x2, y1-y2 = "
382 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
387 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
391 LogInfo(
"FastCalorimetry") << std::endl
392 <<
" HCALResponse::interMU " << std::endl
393 <<
" e, ie, ieta = " << e <<
" " << ie <<
" " << ieta << std::endl
394 <<
" response = " << mean << std::endl;
408 if (det==2 && ieta>5 && e<20){
410 for(
int p = 0;
p < 4;
p++){
411 y1=PoissonParameters[
p][ie][ieta];
412 y2=PoissonParameters[
p][ie+1][ieta];
414 x1 = eGridHD[det+1][ie];
415 x2 = eGridHD[det+1][ie+1];
416 pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
420 mean =random->
poissonShoot((
int (PoissonShootNoNegative(pars[0],pars[1],random))+(
int (PoissonShootNoNegative(pars[2],pars[3],random)))/4+random->
flatShoot()/4) *6)/(0.3755*6);
425 x1 = eGridHD[det][ie];
426 x2 = eGridHD[det][ie+1];
429 for(
int p = 0;
p < nPar;
p++){
435 bool use_custom =
false;
439 if((
p==0 ||
p==1) && e < x1){
440 double tmp = (y1*x2-y2*x1)/(x2-x1);
447 else if((
p==2 ||
p==3 ||
p==4 ||
p==5)){
448 if(e < x1 && y1 < y2){
452 else if(e > x2 && y2 < y1){
459 if(use_custom) pars[
p] = custom;
460 else pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
464 if(nPar==6) mean = cballShootNoNegative(pars[0],pars[1],pars[2],pars[3],pars[4],pars[5], random);
465 else if(nPar==2) mean = gaussShootNoNegative(pars[0],pars[1], random);
472 double y1 = meanEM[ie][ieta];
473 double y2 = meanEM[ie+1][ieta];
474 double x1 = eGridEM[ie];
475 double x2 = eGridEM[ie+1];
479 LogInfo(
"FastCalorimetry") << std::endl
480 <<
" HCALResponse::interEM mean " << std::endl
481 <<
" x, x1-x2, y1-y2 = "
482 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
486 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
488 y1 = sigmaEM[ie][ieta];
489 y2 = sigmaEM[ie+1][ieta];
493 LogInfo(
"FastCalorimetry") << std::endl
494 <<
" HCALResponse::interEM sigma" << std::endl
495 <<
" x, x1-x2, y1-y2 = "
496 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
500 double sigma = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
503 double rndm = gaussShootNoNegative(mean, sigma, random);
511 double s = eResponseScale[hit];
512 double n = eResponseExponent;
513 double p = eResponsePlateau[hit];
514 double c = eResponseCoefficient;
516 double response = e * p / (1+c*
exp(n *
log(s/e)));
518 if(response<0.) response = 0.;
525 resolution = e *
sqrt( RespPar[
HCAL][hit][0]*RespPar[
HCAL][hit][0]/(e) + RespPar[
HCAL][hit][1]*RespPar[
HCAL][hit][1] );
528 double rndm = gaussShootNoNegative(response, resolution, random);
536 for(d = 0; d < 2; d++){
537 if(ieta < HDeta[d+1]){
548 while (out < 0.) out = random->
gaussShoot(e,sigma);
558 double out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
560 while (out < 0.) out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
579 for (
int i = 0;
i < maxEne;
i++) {
580 if(ee >= energyHF[
i]) jmin =
i;
583 double x1, x2, y1, y2;
585 if(ee < energyHF[0]) {
586 if(
abs(type)==11 ||
abs(type)==22) corrHF[
i] = corrHFg[
i];
587 else corrHF[
i] = corrHFh[
i];
588 }
else if(jmin >= maxEne-1) {
589 if(
abs(type)==11 ||
abs(type)==22) corrHF[
i] = corrHFg[maxEta*jmin+
i];
590 else corrHF[
i] = corrHFh[maxEta*jmin+
i];
593 x2 = energyHF[jmin+1];
594 if(
abs(type)==11 ||
abs(type)==22) {
595 y1 = corrHFg[maxEta*jmin+
i];
596 y2 = corrHFg[maxEta*(jmin+1)+
i];
598 y1 = corrHFh[maxEta*jmin+
i];
599 y2 = corrHFh[maxEta*(jmin+1)+
i];
601 corrHF[
i] = y1 + (ee-x1)*((y2-y1)/(x2-x1));
T getParameter(std::string const &) const
double responseHCAL(int _mip, double energy, double eta, int partype, RandomEngineAndDistribution const *)
double flatShoot(double xmin=0.0, double xmax=1.0) const
double getHCALEnergyResponse(double e, int hit, RandomEngineAndDistribution const *)
double interEM(double e, int ie, int ieta, RandomEngineAndDistribution const *)
void correctHF(double e, int type)
double PoissonShootNoNegative(double e, double sigma, RandomEngineAndDistribution const *)
std::vector< double > vec1
Abs< T >::type abs(const T &t)
double getMIPfraction(double energy, double eta)
double interHD(int mip, double e, int ie, int ieta, int det, RandomEngineAndDistribution const *)
double interMU(double e, int ie, int ieta, RandomEngineAndDistribution const *)
std::vector< std::vector< double > > tmp
double gaussShoot(double mean=0.0, double sigma=1.0) const
unsigned int poissonShoot(double mean) const
HCALResponse(const edm::ParameterSet &pset)
double gaussShootNoNegative(double e, double sigma, RandomEngineAndDistribution const *)
double cballShootNoNegative(double mu, double sigma, double aL, double nL, double aR, double nR, RandomEngineAndDistribution const *)