-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBTagSFUtil_tprime.h
82 lines (51 loc) · 1.59 KB
/
BTagSFUtil_tprime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*************************************************************
Class Usage:
This class should only be used for upgrading and downgrading
if a single operating point is used in an analysis.
bool isBTagged = b-tag flag for jet
float Btag_SF = data/MC scale factor for b-tagging efficiency
float Btag_eff = b-tagging efficiency in MC
Author: Michael Segala
Contact: [email protected]
Updated: Ulrich Heintz 12/23/2011
Modified: Dinko Ferencek 10/01/2012
*************************************************************/
#ifndef BTagSFUtil_tprime_h
#define BTagSFUtil_tprime_h
#include <Riostream.h>
#include "TRandom3.h"
#include "TMath.h"
class BTagSFUtil{
public:
BTagSFUtil( int seed=0 );
~BTagSFUtil();
bool applySF(bool isBTagged, float Btag_SF = 0.98, float Btag_eff = 1.0);
private:
TRandom3* rand_;
};
BTagSFUtil::BTagSFUtil( int seed ) {
rand_ = new TRandom3(seed);
// rand_ = new TRandom3(10);
}
BTagSFUtil::~BTagSFUtil() {
delete rand_;
}
bool BTagSFUtil::applySF(bool isBTagged, float Btag_SF, float Btag_eff){
bool newBTag = isBTagged;
if (Btag_SF == 1) return newBTag; //no correction needed
//throw die
float coin = rand_->Uniform(1.);
if(Btag_SF > 1){ // use this if SF>1
if( !isBTagged ) {
//fraction of jets that need to be upgraded
float mistagPercent = (1.0 - Btag_SF) / (1.0 - (1.0/Btag_eff) );
//upgrade to tagged
if( coin < mistagPercent ) {newBTag = true;}
}
}else{ // use this if SF<1
//downgrade tagged to untagged
if( isBTagged && coin > Btag_SF ) {newBTag = false;}
}
return newBTag;
}
#endif