CMS 3D CMS Logo

ConversionLikelihoodCalculator.cc
Go to the documentation of this file.
2 
3 
5 {
6  reader_ = new TMVA::Reader("!Color:Silent");
7 
8 // std::cout << "Init Reader()" << std::endl;
9 
10  reader_->AddVariable("log(e_over_p)", &log_e_over_p_);
11  reader_->AddVariable("log(abs(cot_theta))", &log_abs_cot_theta_);
12  reader_->AddVariable("log(abs(delta_phi))", &log_abs_delta_phi_);
13  reader_->AddVariable("log(chi2_max_pt)", &log_chi2_max_pt_);
14  reader_->AddVariable("log(chi2_min_pt)", &log_chi2_min_pt_);
15 
16 }
17 
18 void ConversionLikelihoodCalculator::setWeightsFile(const char * weightsFile)
19 {
20 // std::cout << "Before BookMVA " << weightsFile << std::endl;
21  reader_->BookMVA("Likelihood", weightsFile);
22 // std::cout << "After BookMVA" << std::endl;
23 }
24 
26 {
27  if (conversion->nTracks() != 2) return -1.;
28 
29  log_e_over_p_ = log(conversion->EoverP());
30 
31  log_abs_cot_theta_ = log(fabs(conversion->pairCotThetaSeparation()));
32 
33  double delta_phi = conversion->tracks()[0]->innerMomentum().phi()-conversion->tracks()[1]->innerMomentum().phi();
34  double pi = 3.14159265;
35  // phi normalization
36  while (delta_phi > pi) delta_phi -= 2*pi;
37  while (delta_phi < -pi) delta_phi += 2*pi;
38  log_abs_delta_phi_ = log(fabs(delta_phi));
39 
40  double chi2_1 = conversion->tracks()[0]->normalizedChi2();
41  double pt_1 = conversion->tracks()[0]->pt();
42 
43  double chi2_2 = conversion->tracks()[1]->normalizedChi2();
44  double pt_2 = conversion->tracks()[1]->pt();
45 
46  double chi2_max_pt=chi2_1;
47  double chi2_min_pt=chi2_2;
48 
49  if (pt_2 > pt_1) {
50  chi2_max_pt=chi2_2;
51  chi2_min_pt=chi2_1;
52  }
53 
54  log_chi2_max_pt_ = log(chi2_max_pt);
55  log_chi2_min_pt_ = log(chi2_min_pt);
56 
57 // std::cout << "log_e_over_p_ " << log_e_over_p_ << std::endl;
58 // std::cout << "log_abs_cot_theta_ " << log_abs_cot_theta_ << std::endl;
59 // std::cout << "log_abs_delta_phi_ " << log_abs_delta_phi_ << std::endl;
60 // std::cout << "log_chi2_max_pt_ " << log_chi2_max_pt_ << std::endl;
61 // std::cout << "log_chi2_min_pt_ " << log_chi2_min_pt_ << std::endl;
62  std::vector<Float_t> inputVec;
63  inputVec.push_back(log_e_over_p_ );
64  inputVec.push_back(log_abs_cot_theta_ );
65  inputVec.push_back(log_abs_delta_phi_ );
66  inputVec.push_back(log_chi2_max_pt_ );
67  inputVec.push_back(log_chi2_min_pt_ );
68  float like = reader_->EvaluateMVA(inputVec,"Likelihood");
69 // std::cout << "reader_->EvaluateMVA(\"Likelihood\") " << reader_->EvaluateMVA(inputVec,"Likelihood") << std::endl;
70 
71  return like;
72 }
73 
75 {
76 
77  if (conversion.nTracks() != 2) return -1.;
78 
79  log_e_over_p_ = log(conversion.EoverP());
80 
81  log_abs_cot_theta_ = log(fabs(conversion.pairCotThetaSeparation()));
82 
83 
84  double delta_phi = conversion.tracksPin()[0].phi()-conversion.tracksPin()[1].phi();
85  double pi = 3.14159265;
86  // phi normalization
87  while (delta_phi > pi) delta_phi -= 2*pi;
88  while (delta_phi < -pi) delta_phi += 2*pi;
89  log_abs_delta_phi_ = log(fabs(delta_phi));
90 
91  double chi2_1 = conversion.tracks()[0]->normalizedChi2();
92  double pt_1 = conversion.tracks()[0]->pt();
93 
94  double chi2_2 = conversion.tracks()[1]->normalizedChi2();
95  double pt_2 = conversion.tracks()[1]->pt();
96 
97  double chi2_max_pt=chi2_1;
98  double chi2_min_pt=chi2_2;
99 
100  if (pt_2 > pt_1) {
101  chi2_max_pt=chi2_2;
102  chi2_min_pt=chi2_1;
103  }
104 
105  log_chi2_max_pt_ = log(chi2_max_pt);
106  log_chi2_min_pt_ = log(chi2_min_pt);
107 
108 // std::cout << "log_e_over_p_ " << log_e_over_p_ << std::endl;
109 // std::cout << "log_abs_cot_theta_ " << log_abs_cot_theta_ << std::endl;
110 // std::cout << "log_abs_delta_phi_ " << log_abs_delta_phi_ << std::endl;
111 // std::cout << "log_chi2_max_pt_ " << log_chi2_max_pt_ << std::endl;
112 // std::cout << "log_chi2_min_pt_ " << log_chi2_min_pt_ << std::endl;
113  std::vector<Float_t> inputVec;
114  inputVec.push_back(log_e_over_p_ );
115  inputVec.push_back(log_abs_cot_theta_ );
116  inputVec.push_back(log_abs_delta_phi_ );
117  inputVec.push_back(log_chi2_max_pt_ );
118  inputVec.push_back(log_chi2_min_pt_ );
119  float like = reader_->EvaluateMVA(inputVec,"Likelihood");
120 // std::cout << "reader_->EvaluateMVA(\"Likelihood\") " << reader_->EvaluateMVA(inputVec,"Likelihood") << std::endl;
121 
122  return like;
123 }
124 
125 
double EoverP() const
Definition: Conversion.cc:259
double pairCotThetaSeparation() const
Delta cot(Theta) where Theta is the angle in the (y,z) plane between the two tracks. Original tracks are used.
Definition: Conversion.cc:209
const Double_t pi
void setWeightsFile(const char *weightsFile)
unsigned int nTracks() const
Number of tracks= 0,1,2.
Definition: Conversion.h:101
double calculateLikelihood(reco::ConversionRef conversion)
const std::vector< math::XYZVectorF > & tracksPin() const
Vector of track momentum measured at the innermost hit.
Definition: Conversion.h:159
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
std::vector< edm::RefToBase< reco::Track > > const & tracks() const
vector of track to base references
Definition: Conversion.cc:176