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];
212 int ieta =
abs((
int)(eta / etaStep)) ;
215 int det = getDet(ieta);
216 int deta = ieta - HDeta[det];
217 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
218 else if(deta < 0 ) deta = 0;
220 for (
int i = 0;
i < maxHDe[det];
i++) {
221 if(energy < eGridHD[det][
i]) {
222 if(i == 0)
return mipfraction [det][0][deta];
227 if(ie == -1)
return mipfraction [det][maxHDe[det]-1][deta];
229 double x1 = eGridHD[det][ie];
230 double x2 = eGridHD[det][ie+1];
231 y1=mipfraction[det][ie][deta];
232 y2=mipfraction[det][ie+1][deta];
234 mean=(y1*(x2-
energy) + y2*(energy-x1))/(x2-x1);
241 int ieta =
abs((
int)(eta / etaStep)) ;
245 if(usemip) mip = _mip;
255 if(ieta >= maxEMeta ) ieta = maxEMeta-1;
256 else if(ieta < 0) ieta = 0;
259 for (
int i = 0;
i < maxEMe;
i++) {
260 if(energy < eGridEM[
i]) {
266 if(ie == -1) ie = maxEMe - 2;
269 mean = interEM(energy, ie, ieta, random);
273 else if(partype == 1) {
275 int det = getDet(ieta);
276 int deta = ieta - HDeta[det];
277 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
278 else if(deta < 0 ) deta = 0;
281 for (
int i = 0;
i < maxHDe[det];
i++) {
282 if(energy < eGridHD[det][
i]) {
288 if(ie == -1) ie = maxHDe[det] - 2;
291 if(det==2 && energy <20 && deta>5){
292 for (
int i = 0;
i < maxHDe[3];
i++) {
293 if(energy < eGridHD[3][
i]) {
301 mean = interHD(mip, energy, ie, deta, det, random);
306 else if(partype == 2) {
309 for(
int i = 0;
i < maxMUeta;
i++) {
310 if(fabs(eta) < etaGridMU[
i]) {
315 if(ieta < 0) ieta = 0;
317 if(ieta < maxMUeta) {
319 for (
int i = 0;
i < maxMUe;
i++) {
320 if(energy < eGridMU[
i]) {
326 if(ie == -1) ie = maxMUe - 2;
329 mean = interMU(energy, ie, ieta, random);
330 if(mean > energy) mean =
energy;
337 LogInfo(
"FastCalorimetry") << std::endl
338 <<
" HCALResponse::responseHCAL, partype = " << partype
339 <<
" E, eta = " << energy <<
" " << eta
340 <<
" mean = " << mean << std::endl;
350 for(
int i = 0;
i < maxMUbin;
i++) {
351 if(x > responseMU[ie][ieta][
i]) {
357 for(
int i = 0;
i < maxMUbin;
i++) {
358 if(x > responseMU[ie+1][ieta][
i]) {
364 double x1 = eGridMU[ie];
365 double x2 = eGridMU[ie+1];
366 double y1 = (bin1 + random->
flatShoot()) * muStep;
367 double y2 = (bin2 + random->
flatShoot()) * muStep;
371 LogInfo(
"FastCalorimetry") << std::endl
372 <<
" HCALResponse::interMU " << std::endl
373 <<
" x, x1-x2, y1-y2 = "
374 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
379 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
383 LogInfo(
"FastCalorimetry") << std::endl
384 <<
" HCALResponse::interMU " << std::endl
385 <<
" e, ie, ieta = " << e <<
" " << ie <<
" " << ieta << std::endl
386 <<
" response = " << mean << std::endl;
400 if (det==2 && ieta>5 && e<20){
402 for(
int p = 0;
p < 4;
p++){
403 y1=PoissonParameters[
p][ie][ieta];
404 y2=PoissonParameters[
p][ie+1][ieta];
406 x1 = eGridHD[det+1][ie];
407 x2 = eGridHD[det+1][ie+1];
408 pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
412 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);
417 x1 = eGridHD[det][ie];
418 x2 = eGridHD[det][ie+1];
421 for(
int p = 0;
p < nPar;
p++){
427 bool use_custom =
false;
431 if((
p==0 ||
p==1) && e < x1){
432 double tmp = (y1*x2-y2*x1)/(x2-x1);
439 else if((
p==2 ||
p==3 ||
p==4 ||
p==5)){
440 if(e < x1 && y1 < y2){
444 else if(e > x2 && y2 < y1){
451 if(use_custom) pars[
p] = custom;
452 else pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
456 if(nPar==6) mean = cballShootNoNegative(pars[0],pars[1],pars[2],pars[3],pars[4],pars[5], random);
457 else if(nPar==2) mean = gaussShootNoNegative(pars[0],pars[1], random);
464 double y1 = meanEM[ie][ieta];
465 double y2 = meanEM[ie+1][ieta];
466 double x1 = eGridEM[ie];
467 double x2 = eGridEM[ie+1];
471 LogInfo(
"FastCalorimetry") << std::endl
472 <<
" HCALResponse::interEM mean " << std::endl
473 <<
" x, x1-x2, y1-y2 = "
474 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
478 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
480 y1 = sigmaEM[ie][ieta];
481 y2 = sigmaEM[ie+1][ieta];
485 LogInfo(
"FastCalorimetry") << std::endl
486 <<
" HCALResponse::interEM sigma" << std::endl
487 <<
" x, x1-x2, y1-y2 = "
488 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
492 double sigma = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
495 double rndm = gaussShootNoNegative(mean, sigma, random);
503 double s = eResponseScale[hit];
504 double n = eResponseExponent;
505 double p = eResponsePlateau[hit];
506 double c = eResponseCoefficient;
508 double response = e * p / (1+c*
exp(n *
log(s/e)));
510 if(response<0.) response = 0.;
517 resolution = e *
sqrt( RespPar[
HCAL][hit][0]*RespPar[
HCAL][hit][0]/(e) + RespPar[
HCAL][hit][1]*RespPar[
HCAL][hit][1] );
520 double rndm = gaussShootNoNegative(response, resolution, random);
528 for(d = 0; d < 2; d++){
529 if(ieta < HDeta[d+1]){
540 while (out < 0.) out = random->
gaussShoot(e,sigma);
550 double out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
552 while (out < 0.) out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
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 *)
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 *)