Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:40

0001 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
0002 #include "SimCalorimetry/CaloSimAlgos/interface/CaloCachedShapeIntegrator.h"
0003 #include "SimCalorimetry/HcalSimAlgos/interface/HcalShape.h"
0004 #include <cmath>
0005 #include <iostream>
0006 
0007 bool compare(CaloSamples& s1, CaloSamples& s2) {
0008   bool result = true;
0009   for (int i = 0; i < 10; ++i) {
0010     double v1 = s1[i];
0011     double v2 = s2[i];
0012     if (fabs(v1) < 0.00001) {
0013       if (fabs(v2) > 0.0001) {
0014         std::cout << "BAD VALUE " << v1 << " " << v2 << std::endl;
0015         result = false;
0016       }
0017     } else {
0018       if (fabs(v1 - v2) / v1 > 0.001) {
0019         std::cout << "BAD VALUE " << v1 << " " << v2 << std::endl;
0020         result = false;
0021       }
0022     }
0023   }
0024   return result;
0025 }
0026 
0027 double integrate(CaloSamples& s) {
0028   double result = 0.;
0029   for (int i = 0; i < 10; ++i) {
0030     result += s[i];
0031   }
0032   return result;
0033 }
0034 
0035 double centroid(CaloSamples& s) {
0036   double weightedSum = 0.;
0037   double sum = 0.;
0038   for (int i = 0; i < 10; ++i) {
0039     weightedSum += s[i] * i;
0040     sum += s[i];
0041   }
0042   return weightedSum / sum;
0043 }
0044 
0045 int main() {
0046   DetId detId;
0047   CaloSamples samples(detId, 10.);
0048   CaloSamples samples2(detId, 10.);
0049   CaloSamples expected(detId, 10.);
0050   CaloSamples expected2(detId, 10.);
0051 
0052   double values[10] = {2., 4., 8., 20., 32., 28., 24., 12., 8., 4.};
0053   double offset = 5.;
0054   double offset2 = 30.;
0055   double expect[10] = {1.6, 3.6, 7.2, 17.6, 29.6, 28.8, 24.8, 14.4, 8.8, 4.8};
0056   double expect2[10] = {0., 1.6, 3.6, 7.2, 17.6, 29.6, 28.8, 24.8, 14.4, 8.8};
0057 
0058   for (int i = 0; i < 10; ++i) {
0059     samples[i] = values[i];
0060     samples2[i] = values[i];
0061     expected[i] = expect[i];
0062     expected2[i] = expect2[i];
0063   }
0064   samples.offsetTime(offset);
0065   samples2.offsetTime(offset2);
0066 
0067   compare(samples, expected);
0068   compare(samples2, expected2);
0069 
0070   // test inching forward and inching back
0071   HcalShape hcalShape;
0072   hcalShape.setShape(101);
0073   CaloCachedShapeIntegrator intShape(&hcalShape);
0074   CaloSamples signalStep(detId, 10), signalJump(detId, 10), signalOrig(detId, 10);
0075   for (int i = 0; i < 10; ++i) {
0076     double value = intShape(i * 25);
0077     signalStep[i] = value;
0078     signalOrig[i] = value;
0079     signalJump[i] = value;
0080   }
0081 
0082   for (int i = 0; i < 15; ++i) {
0083     signalStep.offsetTime(1);
0084   }
0085   // make sure that 15 steps of 1 ns = one step of 15 ns
0086   signalJump.offsetTime(15);
0087   //compare(signalStep, signalJump);
0088   for (int i = 0; i < 15; ++i) {
0089     signalStep.offsetTime(-1);
0090   }
0091   // compare to original
0092   //compare(signalStep, signalOrig);
0093   // see if it has the same integral
0094   std::cout << "Integrate " << integrate(signalStep) << " " << integrate(signalJump) << " " << integrate(signalOrig)
0095             << std::endl;
0096   std::cout << "Centroid " << centroid(signalOrig) * 25 << " " << centroid(signalJump) * 25. << std::endl;
0097 }