CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FML1PtSmearer.cc
Go to the documentation of this file.
1 
4 
7 
8 #include <cmath>
9 #include <iostream>
10 #include <fstream>
11 
13 
14 using namespace std;
15 
17  : random(engine) {
18 
19  string fname = "FastSimulation/Muons/data/resolutionL1.data";
20  // std::string path(std::getenv("CMSSW_SEARCH__PATH"));
21  std::string path(getenv("CMSSW_SEARCH_PATH"));
22  FileInPath f1(path,fname);
23  if ( f1() == 0) {
24  std::cout << "File " << fname << " not found in " << path << std::endl;
25  throw Genexception(" resolution list not found for FastMuonLvl1Trigger.");
26  } else {
27  // The following should be on LogInfo
28  //cout << "Reading " << f1.name() << std::endl;
29  }
30  std::ifstream & listfile = *f1();
31 
32  int ind;
33  float num=0.;
34  for (int ieta=0; ieta<3; ieta++) {
35  for (int i=0; i<NPT; i++) {
36  float sum = 0.;
37  ind = i*NPTL1 + ieta*(NPT*NPTL1);
38  for (int j=0; j<NPTL1; j++) {
39  listfile >> num;
40  sum += num;
41  resolution[ind]=sum;
42  ind++;
43  }
44  ind = i*NPTL1 + ieta*(NPT*NPTL1);
45  for (int j=0; j<NPTL1 ; j++){
46  resolution[ind] /= sum;
47  ind++;
48  }
49  }
50  }
51 
52 }
53 
55 
56 
57 
59  // get and smear the pt
60  double Pt=aMuon->smearedPt();
61  double AbsEta=fabs(aMuon->getMomentum().eta());
62 
63  bool StatusCode=true;
64 
65  if (AbsEta>2.40 || Pt<3) { StatusCode=false;}
66 
67  if (StatusCode){
68 
69  int ieta = 0;
70  if (AbsEta<1.04) ieta = 0 ;
71  else if (AbsEta<2.07) ieta = 1 ;
72  else if (AbsEta<2.40) ieta = 2 ;
73 
74  int counter = 0;
75  int ipt = IndexOfPtgen(Pt);
76  int ind = counter + ipt*NPTL1 + ieta*(NPT*NPTL1);
77  double prob = random->flatShoot();
78  while ( (prob > resolution[ind]) && counter<NPTL1 ){
79  counter++;
80  ind++;
81  }
82  counter++;
83  aMuon->setPtPacked(counter & 31);
84  aMuon->setPtValue(SimpleL1MuGMTCand::ptScale[counter]);
85 
86  prob = random->flatShoot();
87  if (prob <= ChargeMisIdent(ieta,Pt)) {
88  int OldCharge = aMuon->charge();
89  int NewCharge = -OldCharge;
90  aMuon->setCharge(NewCharge);
91  }
92 
93  }
94 
95  return StatusCode;
96 
97 }
98 
99 
101 
102  static float vecpt[NPT] = {
103  1., 2., 3., 4., 5., 6., 7., 8., 9.,
104  10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
105  20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
106  30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
107  40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
108  50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
109  60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
110  70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
111  80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
112  90., 91., 92., 93., 94., 95., 96., 97., 98., 99.,
113  100., 110., 120., 130., 140., 150., 160., 170., 180., 190.,
114  200., 210., 220., 230., 240., 250., 260., 270., 280., 290.,
115  300., 310., 320., 330., 340., 350., 360., 370., 380., 390.,
116  400., 500., 600., 700., 800., 900., 1000. };
117 
118  for (int i=0; i<NPT; i++) {
119  if (pt<vecpt[i]) return i;
120  }
121  return NPT;
122 }
~FML1PtSmearer()
Destructor.
void setPtPacked(unsigned pt)
set packed pt-code of muon candidate
Definition: L1MuGMTCand.h:156
int i
Definition: DBlmapReader.cc:9
static const int NPTL1
Definition: FML1PtSmearer.h:35
FML1PtSmearer(const RandomEngine *engine)
Constructor (read in the parametrizations from a data file)
const RandomEngine * random
Definition: FML1PtSmearer.h:31
static const int NPT
Definition: FML1PtSmearer.h:36
float resolution[DIMRES]
Definition: FML1PtSmearer.h:38
bool smear(SimpleL1MuGMTCand *)
smear the transverse momentum of a SimplL1MuGMTCand
int charge() const
get charge
TRandom random
Definition: MVATrainer.cc:138
int path() const
Definition: HLTadd.h:3
static const float ptScale[32]
int j
Definition: DBlmapReader.cc:9
void setCharge(int charge)
set charge and packed code of muon candidate
int IndexOfPtgen(float pt)
float ChargeMisIdent(int ieta, double pt)
Definition: FML1PtSmearer.h:40
float smearedPt() const
return the smeared L1 Pt value before discretization in 32-bit
const LorentzVector getMomentum() const
long long int num
Definition: procUtils.cc:71
double flatShoot(double xmin=0.0, double xmax=1.0) const
Definition: RandomEngine.h:30
string fname
main script
tuple cout
Definition: gather_cfg.py:41
void setPtValue(float ptVal)
Set Pt Value.
Definition: L1MuGMTCand.h:182