ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/MultiThresholdEfficiency.h
Revision: 1.1
Committed: Wed Sep 14 08:09:05 2011 UTC (13 years, 7 months ago) by arizzi
Content type: text/plain
Branch: MAIN
CVS Tags: Sept14th2011_2, Sept14th2011
Log Message:
add code to compute combinatorics of multi threshold triggers

File Contents

# User Rev Content
1 arizzi 1.1 #ifndef MULTITHRESHOLDEFFICIENCY_H
2     #define MULTITHRESHOLDEFFICIENCY_H
3     #include <math.h>
4     #include <iostream>
5     #include <vector>
6     using namespace std;
7     class MultiThresholdEfficiency
8     {
9     public:
10     MultiThresholdEfficiency(int nOfThresholds) : thresholds(nOfThresholds) {}
11    
12     //thresholds are from tigther to looser
13     virtual bool filter(vector<int> numberOfPassPerThreshold);
14    
15     //A vector with, for each object the efficiency of passing threshold N while notpassing N-1
16     float weight(vector<vector<float> > input);
17    
18     private:
19     int thresholds;
20    
21     };
22    
23    
24     bool MultiThresholdEfficiency::filter(std::vector<int> t)
25     {
26     // One high threshold and two low threshold
27     return t[0] >= 1 && t[1] >= 2;
28     }
29    
30    
31    
32     float MultiThresholdEfficiency::weight(vector<vector<float> > objects)
33     {
34     int nobjects=objects.size();
35     std::vector<int> comb(objects.size());
36     for(int i=0;i < objects.size(); i++) comb[i]=0;
37     int idx=0;
38     int max=thresholds+1; //
39     float p=0,tot=0;
40     if(objects.size()==0) return 0.;
41     while(comb[objects.size()-1] < max)
42     {
43     //std::cout << std::endl << "New comb" << std::endl;
44     // for(int i=0;i < objects.size(); i++) {std::cout << comb[i] << " ";}
45     // std::cout << std::endl;
46     std::vector<int> pass;
47     for(int j=0;j<thresholds;j++) pass.push_back(0);
48    
49     float thisCombinationProbability=1.;
50     // std::cout << "OBJ Probs: ";
51     for(size_t j=0;j<nobjects;j++) // loop on objects
52     {
53     float cumulative=1.;
54     for(int n=0;n<comb[j];n++) cumulative*= (1.-objects[j][n]); // 10 20 70 10/100,20/90 90/100*70/90
55     thisCombinationProbability*=cumulative;
56     if(comb[j]< thresholds) {
57     thisCombinationProbability*=(objects[j])[comb[j]];
58     // std::cout << cumulative*(objects[j])[comb[j]] << " ";
59     }
60     /* else
61     {
62     std::cout << cumulative << " " ;
63     }*/
64    
65    
66     for(size_t k=0;k< thresholds; k++ ) // loop on threshold
67     {
68     bool passed = ( k >= comb[j] ) ; //k=0, is the tightest, passed only if comb[j] = 0, k=1 pass if comb 0 or 1
69     if(passed) pass[k]++;
70     }
71     }
72     // std::cout << endl;
73     if(filter(pass)) p+=thisCombinationProbability;
74     tot+=thisCombinationProbability;
75     // std::cout << thisCombinationProbability << " " << p << " " << tot<< std::endl;
76     while (comb[idx] == max -1 && idx+1 < objects.size()) idx++; // find first object for which we did not already test all configs
77     // next combination
78     comb[idx]++; // test a new config for that jet
79     for(int i=0;i<idx;i++) { comb[i]=0; } // reset the tested configs for all previous objects
80     idx=0;
81     }
82     if( fabs(tot-1.) > 0.01 )
83     {
84     std::cout << "ERROR, total must be one " << tot << std::endl;
85     }
86     return p;
87     }
88    
89     #endif
90