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];
227 for(
int i = 0;
i < maxEne;
i++){
229 corrHFgEm[
i][
j] = _corrHFgEm[
i*maxEta +
j];
230 corrHFgHad[
i][
j] = _corrHFgHad[
i*maxEta +
j];
231 corrHFhEm[
i][
j] = _corrHFhEm[
i*maxEta +
j];
232 corrHFhHad[
i][
j] = _corrHFhHad[
i*maxEta +
j];
238 int ieta =
abs((
int)(eta / etaStep)) ;
241 int det = getDet(ieta);
242 int deta = ieta - HDeta[det];
243 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
244 else if(deta < 0 ) deta = 0;
246 for (
int i = 0;
i < maxHDe[det];
i++) {
247 if(energy < eGridHD[det][
i]) {
248 if(i == 0)
return mipfraction [det][0][deta];
253 if(ie == -1)
return mipfraction [det][maxHDe[det]-1][deta];
255 double x1 = eGridHD[det][ie];
256 double x2 = eGridHD[det][ie+1];
257 y1=mipfraction[det][ie][deta];
258 y2=mipfraction[det][ie+1][deta];
260 mean=(y1*(x2-energy) + y2*(energy-x1))/(x2-x1);
267 int ieta =
abs((
int)(eta / etaStep)) ;
271 if(usemip) mip = _mip;
281 if(ieta >= maxEMeta ) ieta = maxEMeta-1;
282 else if(ieta < 0) ieta = 0;
285 for (
int i = 0;
i < maxEMe;
i++) {
286 if(energy < eGridEM[
i]) {
292 if(ie == -1) ie = maxEMe - 2;
295 mean = interEM(energy, ie, ieta, random);
299 else if(partype == 1) {
301 int det = getDet(ieta);
302 int deta = ieta - HDeta[det];
303 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
304 else if(deta < 0 ) deta = 0;
307 for (
int i = 0;
i < maxHDe[det];
i++) {
308 if(energy < eGridHD[det][
i]) {
314 if(ie == -1) ie = maxHDe[det] - 2;
317 if(det==2 && energy <20 && deta>5){
318 for (
int i = 0;
i < maxHDe[3];
i++) {
319 if(energy < eGridHD[3][
i]) {
327 mean = interHD(mip, energy, ie, deta, det, random);
332 else if(partype == 2) {
335 for(
int i = 0;
i < maxMUeta;
i++) {
336 if(fabs(eta) < etaGridMU[
i]) {
341 if(ieta < 0) ieta = 0;
343 if(ieta < maxMUeta) {
345 for (
int i = 0;
i < maxMUe;
i++) {
346 if(energy < eGridMU[
i]) {
352 if(ie == -1) ie = maxMUe - 2;
355 mean = interMU(energy, ie, ieta, random);
356 if(mean > energy) mean = energy;
363 LogInfo(
"FastCalorimetry") << std::endl
364 <<
" HCALResponse::responseHCAL, partype = " << partype
365 <<
" E, eta = " << energy <<
" " << eta
366 <<
" mean = " << mean << std::endl;
376 for(
int i = 0;
i < maxMUbin;
i++) {
377 if(x > responseMU[ie][ieta][
i]) {
383 for(
int i = 0;
i < maxMUbin;
i++) {
384 if(x > responseMU[ie+1][ieta][
i]) {
390 double x1 = eGridMU[ie];
391 double x2 = eGridMU[ie+1];
392 double y1 = (bin1 + random->
flatShoot()) * muStep;
393 double y2 = (bin2 + random->
flatShoot()) * muStep;
397 LogInfo(
"FastCalorimetry") << std::endl
398 <<
" HCALResponse::interMU " << std::endl
399 <<
" x, x1-x2, y1-y2 = " 400 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
405 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
409 LogInfo(
"FastCalorimetry") << std::endl
410 <<
" HCALResponse::interMU " << std::endl
411 <<
" e, ie, ieta = " << e <<
" " << ie <<
" " << ieta << std::endl
412 <<
" response = " << mean << std::endl;
426 if (det==2 && ieta>5 && e<20){
428 for(
int p = 0;
p < 4;
p++){
429 y1=PoissonParameters[
p][ie][ieta];
430 y2=PoissonParameters[
p][ie+1][ieta];
432 x1 = eGridHD[det+1][ie];
433 x2 = eGridHD[det+1][ie+1];
434 pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
438 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);
443 x1 = eGridHD[det][ie];
444 x2 = eGridHD[det][ie+1];
447 for(
int p = 0;
p < nPar;
p++){
453 bool use_custom =
false;
457 if((
p==0 ||
p==1) && e < x1){
458 double tmp = (y1*x2-y2*x1)/(x2-x1);
465 else if((
p==2 ||
p==3 ||
p==4 ||
p==5)){
466 if(e < x1 && y1 < y2){
470 else if(e > x2 && y2 < y1){
477 if(use_custom) pars[
p] = custom;
478 else pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
482 if(nPar==6) mean = cballShootNoNegative(pars[0],pars[1],pars[2],pars[3],pars[4],pars[5], random);
483 else if(nPar==2) mean = gaussShootNoNegative(pars[0],pars[1], random);
490 double y1 = meanEM[ie][ieta];
491 double y2 = meanEM[ie+1][ieta];
492 double x1 = eGridEM[ie];
493 double x2 = eGridEM[ie+1];
497 LogInfo(
"FastCalorimetry") << std::endl
498 <<
" HCALResponse::interEM mean " << std::endl
499 <<
" x, x1-x2, y1-y2 = " 500 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
504 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
506 y1 = sigmaEM[ie][ieta];
507 y2 = sigmaEM[ie+1][ieta];
511 LogInfo(
"FastCalorimetry") << std::endl
512 <<
" HCALResponse::interEM sigma" << std::endl
513 <<
" x, x1-x2, y1-y2 = " 514 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
518 double sigma = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
521 double rndm = gaussShootNoNegative(mean, sigma, random);
529 double s = eResponseScale[hit];
530 double n = eResponseExponent;
531 double p = eResponsePlateau[hit];
532 double c = eResponseCoefficient;
534 double response = e * p / (1+c*
exp(n *
log(s/e)));
536 if(response<0.) response = 0.;
543 resolution = e *
sqrt( RespPar[
HCAL][hit][0]*RespPar[
HCAL][hit][0]/(e) + RespPar[
HCAL][hit][1]*RespPar[
HCAL][hit][1] );
546 double rndm = gaussShootNoNegative(response, resolution, random);
554 for(d = 0; d < 2; d++){
555 if(ieta < HDeta[d+1]){
566 while (out < 0.) out = random->
gaussShoot(e,sigma);
576 double out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
578 while (out < 0.) out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
597 for (
int i = 0;
i < maxEne;
i++) {
598 if(ee >= energyHF[
i]) jmin =
i;
605 if(ee < energyHF[0]) {
606 if(
abs(type)==11 ||
abs(type)==22) {
607 corrHFem[
i] = corrHFgEm[0][
i];
608 corrHFhad[
i] = corrHFgHad[0][
i];
610 corrHFem[
i] = corrHFhEm[0][
i];
611 corrHFhad[
i] = corrHFhHad[0][
i];
613 }
else if(jmin >= maxEne-1) {
614 if(
abs(type)==11 ||
abs(type)==22) {
616 corrHFhad[
i] = corrHFgHad[
maxEta][
i];
619 corrHFhad[
i] = corrHFhHad[
maxEta][
i];
623 x2 = energyHF[jmin+1];
624 if(
abs(type)==11 ||
abs(type)==22) {
625 y1em = corrHFgEm[jmin][
i];
626 y2em = corrHFgEm[jmin+1][
i];
627 y1had = corrHFgHad[jmin][
i];
628 y2had = corrHFgHad[jmin+1][
i];
630 y1em = corrHFhEm[jmin][
i];
631 y2em = corrHFhEm[jmin+1][
i];
632 y1had = corrHFhHad[jmin][
i];
633 y2had = corrHFhHad[jmin+1][
i];
635 corrHFem[
i] = y1em + (ee-x1)*((y2em-y1em)/(x2-x1));
636 corrHFhad[
i] = y1had + (ee-x1)*((y2had-y1had)/(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)
T x() const
Cartesian x coordinate.
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 *)