Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:39

0001 // ***************************************************************************
0002 // *                                                                         *
0003 // *        IMPORTANT NOTE: You would never want to do this by hand!         *
0004 // *                                                                         *
0005 // * This is for testing purposes only. Use PhysicsTools/MVATrainer instead. *
0006 // *                                                                         *
0007 // ***************************************************************************
0008 
0009 // In order for this example to work (which you should not do in FWLite
0010 // anyway) you have to uncomment the commented-out parts in
0011 // src/classes_def.xml to add definitions of BitSet dictionaries back
0012 
0013 void testFWLiteWrite()
0014 {
0015     using namespace PhysicsTools::Calibration;
0016 
0017 // set up some dummy calibration by hand for testing
0018 
0019     MVAComputer calibration;
0020 
0021 // vars
0022 
0023     Variable var;
0024     var.name = "test";
0025     calibration.inputSet.push_back(var);
0026 
0027     var.name = "normal";
0028     calibration.inputSet.push_back(var);
0029 
0030     var.name = "toast";
0031     calibration.inputSet.push_back(var);
0032 
0033 // normalize
0034 
0035     ProcNormalize norm;
0036 
0037     PhysicsTools::BitSet testSet1(3);
0038     testSet1[0] = testSet1[1] = true;
0039     norm.inputVars = convert(testSet1);
0040 
0041     HistogramF pdf(3, 4.0, 5.5);
0042     pdf.setBinContent(1, 1.0);
0043     pdf.setBinContent(2, 1.5);
0044     pdf.setBinContent(3, 1.0);
0045     norm.categoryIdx = -1;
0046     norm.distr.push_back(pdf);
0047     norm.distr.push_back(pdf);
0048 
0049     calibration.addProcessor(&norm);
0050 
0051 // likelihood
0052 
0053     ProcLikelihood lkh;
0054 
0055     PhysicsTools::BitSet testSet2(5);
0056     testSet2[2] = true;
0057     lkh.inputVars = convert(testSet2);
0058 
0059     pdf = HistogramF(6, 0.0, 1.0);
0060     pdf.setBinContent(1, 1.0);
0061     pdf.setBinContent(2, 1.5);
0062     pdf.setBinContent(3, 1.0);
0063     pdf.setBinContent(4, 1.0);
0064     pdf.setBinContent(5, 1.5);
0065     pdf.setBinContent(6, 1.0);
0066     ProcLikelihood::SigBkg sigBkg;
0067     sigBkg.signal = pdf;
0068     pdf = HistogramF(9, 0.0, 1.0);
0069     pdf.setBinContent(1, 1.0);
0070     pdf.setBinContent(2, 1.5);
0071     pdf.setBinContent(3, 1.0);
0072     pdf.setBinContent(4, 1.0);
0073     pdf.setBinContent(5, 1.5);
0074     pdf.setBinContent(6, 1.0);
0075     pdf.setBinContent(7, 1.5);
0076     pdf.setBinContent(8, 1.0);
0077     pdf.setBinContent(9, 1.7);
0078     sigBkg.background = pdf;
0079     sigBkg.useSplines = true;
0080     lkh.categoryIdx = -1;
0081     lkh.neverUndefined = true;
0082     lkh.individual = false;
0083     lkh.logOutput = false;
0084     lkh.keepEmpty = true;
0085     lkh.pdfs.push_back(sigBkg);
0086 
0087     calibration.addProcessor(&lkh);
0088 
0089 // likelihood 2
0090 
0091     PhysicsTools::BitSet testSet3(6);
0092     testSet3[2] = testSet3[3] = true;
0093     lkh.inputVars = convert(testSet3);
0094     sigBkg.useSplines = true;
0095     lkh.pdfs.push_back(sigBkg);
0096 
0097     calibration.addProcessor(&lkh);
0098 
0099 // optional
0100 
0101     ProcOptional opt;
0102 
0103     PhysicsTools::BitSet testSet4(7);
0104     testSet4[5] = testSet4[6] = true;
0105     opt.inputVars = convert(testSet4);
0106 
0107     opt.neutralPos.push_back(0.6);
0108     opt.neutralPos.push_back(0.7);
0109 
0110     calibration.addProcessor(&opt);
0111 
0112 // PCA
0113 
0114     ProcMatrix pca;
0115 
0116     PhysicsTools::BitSet testSet5(9);
0117     testSet5[4] = testSet5[7] = testSet5[8] = true;
0118     pca.inputVars = convert(testSet5);
0119 
0120     pca.matrix.rows = 2;
0121     pca.matrix.columns = 3;
0122     pca.matrix.elements.push_back(0.2);
0123     pca.matrix.elements.push_back(0.3);
0124     pca.matrix.elements.push_back(0.4);
0125     pca.matrix.elements.push_back(0.8);
0126     pca.matrix.elements.push_back(0.7);
0127     pca.matrix.elements.push_back(0.6);
0128 
0129     calibration.addProcessor(&pca);
0130 
0131 // linear
0132 
0133     ProcLinear lin;
0134 
0135     PhysicsTools::BitSet testSet6(11);
0136     testSet6[9] = testSet6[10] = true;
0137     lin.inputVars = convert(testSet6);
0138 
0139     lin.coeffs.push_back(0.3);
0140     lin.coeffs.push_back(0.7);
0141     lin.offset = 0.0;
0142 
0143     calibration.addProcessor(&lin);
0144 
0145 // output
0146 
0147     calibration.output = 11;
0148 
0149 // write the calibration to a file called "test.mva"
0150 
0151     PhysicsTools::MVAComputer::writeCalibration("test.mva", &calibration);
0152 }