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);
239 int ieta =
abs((
int)(eta / etaStep)) ;
243 if(usemip) mip = _mip;
253 if(ieta >= maxEMeta ) ieta = maxEMeta-1;
254 else if(ieta < 0) ieta = 0;
257 for (
int i = 0;
i < maxEMe;
i++) {
258 if(energy < eGridEM[
i]) {
264 if(ie == -1) ie = maxEMe - 2;
267 mean = interEM(energy, ie, ieta, random);
271 else if(partype == 1) {
273 int det = getDet(ieta);
274 int deta = ieta - HDeta[det];
275 if(deta >= maxHDetas[det]) deta = maxHDetas[det] - 1;
276 else if(deta < 0 ) deta = 0;
279 for (
int i = 0;
i < maxHDe[det];
i++) {
280 if(energy < eGridHD[det][
i]) {
286 if(ie == -1) ie = maxHDe[det] - 2;
289 if(det==2 && energy <20 && deta>5){
290 for (
int i = 0;
i < maxHDe[3];
i++) {
291 if(energy < eGridHD[3][
i]) {
299 mean = interHD(mip, energy, ie, deta, det, random);
304 else if(partype == 2) {
307 for(
int i = 0;
i < maxMUeta;
i++) {
308 if(fabs(eta) < etaGridMU[
i]) {
313 if(ieta < 0) ieta = 0;
315 if(ieta < maxMUeta) {
317 for (
int i = 0;
i < maxMUe;
i++) {
318 if(energy < eGridMU[
i]) {
324 if(ie == -1) ie = maxMUe - 2;
327 mean = interMU(energy, ie, ieta, random);
328 if(mean > energy) mean =
energy;
335 LogInfo(
"FastCalorimetry") << std::endl
336 <<
" HCALResponse::responseHCAL, partype = " << partype
337 <<
" E, eta = " << energy <<
" " << eta
338 <<
" mean = " << mean << std::endl;
348 for(
int i = 0;
i < maxMUbin;
i++) {
349 if(x > responseMU[ie][ieta][
i]) {
355 for(
int i = 0;
i < maxMUbin;
i++) {
356 if(x > responseMU[ie+1][ieta][
i]) {
362 double x1 = eGridMU[ie];
363 double x2 = eGridMU[ie+1];
364 double y1 = (bin1 + random->
flatShoot()) * muStep;
365 double y2 = (bin2 + random->
flatShoot()) * muStep;
369 LogInfo(
"FastCalorimetry") << std::endl
370 <<
" HCALResponse::interMU " << std::endl
371 <<
" x, x1-x2, y1-y2 = "
372 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
377 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
381 LogInfo(
"FastCalorimetry") << std::endl
382 <<
" HCALResponse::interMU " << std::endl
383 <<
" e, ie, ieta = " << e <<
" " << ie <<
" " << ieta << std::endl
384 <<
" response = " << mean << std::endl;
397 if (det==2 && ieta>5 && e<20){
399 x1 = eGridHD[det+1][ie];
400 x2 = eGridHD[det+1][ie+1];
401 for(
int p = 0;
p < 4;
p++){
402 y1=PoissonParameters[
p][ie][ieta];
403 y2=PoissonParameters[
p][ie+1][ieta];
404 if(e>5)pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
407 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);
412 x1 = eGridHD[det][ie];
413 x2 = eGridHD[det][ie+1];
416 for(
int p = 0;
p < nPar;
p++){
422 bool use_custom =
false;
426 if((
p==0 ||
p==1) && e < x1){
427 double tmp = (y1*x2-y2*x1)/(x2-x1);
434 else if((
p==2 ||
p==3 ||
p==4 ||
p==5)){
435 if(e < x1 && y1 < y2){
439 else if(e > x2 && y2 < y1){
446 if(use_custom) pars[
p] = custom;
447 else pars[
p] = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
451 if(nPar==6) mean = cballShootNoNegative(pars[0],pars[1],pars[2],pars[3],pars[4],pars[5], random);
452 else if(nPar==2) mean = gaussShootNoNegative(pars[0],pars[1], random);
459 double y1 = meanEM[ie][ieta];
460 double y2 = meanEM[ie+1][ieta];
461 double x1 = eGridEM[ie];
462 double x2 = eGridEM[ie+1];
466 LogInfo(
"FastCalorimetry") << std::endl
467 <<
" HCALResponse::interEM mean " << std::endl
468 <<
" x, x1-x2, y1-y2 = "
469 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
473 double mean = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
475 y1 = sigmaEM[ie][ieta];
476 y2 = sigmaEM[ie+1][ieta];
480 LogInfo(
"FastCalorimetry") << std::endl
481 <<
" HCALResponse::interEM sigma" << std::endl
482 <<
" x, x1-x2, y1-y2 = "
483 << e <<
", " << x1 <<
"-" << x2 <<
" " << y1 <<
"-" << y2 << std::endl;
487 double sigma = (y1*(x2-
e) + y2*(e-x1))/(x2-x1);
490 double rndm = gaussShootNoNegative(mean, sigma, random);
498 double s = eResponseScale[hit];
499 double n = eResponseExponent;
500 double p = eResponsePlateau[hit];
501 double c = eResponseCoefficient;
503 double response = e * p / (1+c*
exp(n *
log(s/e)));
505 if(response<0.) response = 0.;
512 resolution = e *
sqrt( RespPar[
HCAL][hit][0]*RespPar[
HCAL][hit][0]/(e) + RespPar[
HCAL][hit][1]*RespPar[
HCAL][hit][1] );
515 double rndm = gaussShootNoNegative(response, resolution, random);
523 for(d = 0; d < 2; d++){
524 if(ieta < HDeta[d+1]){
535 while (out < 0.) out = random->
gaussShoot(e,sigma);
545 double out = cball.shoot(mu,sigma,aL,nL,aR,nR, random);
547 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 *)