4 #include "TMVA/Reader.h"
5 #include "Criteria/ICriterion.h"
16 BDTCrit2 (
float scoreMin ,
float scoreMax ){
29 float EvalDeltaPhi( KiTrack::IHit*a, KiTrack::IHit*b ){
36 float phia = atan2( ay, ax );
37 float phib = atan2( by, bx );
38 float deltaPhi = phia - phib;
40 if (deltaPhi > M_PI) deltaPhi -= 2*M_PI;
41 if (deltaPhi < -M_PI) deltaPhi += 2*M_PI;
43 if (( by*by + bx*bx < 0.0001 )||( ay*ay + ax*ax < 0.0001 )) deltaPhi = 0.;
45 deltaPhi = 180.*fabs( deltaPhi ) / M_PI;
48 float EvalDeltaRho( KiTrack::IHit*a, KiTrack::IHit*b ){
54 float rhoA = sqrt( ax*ax + ay*ay );
55 float rhoB = sqrt( bx*bx + by*by );
57 float deltaRho = rhoA - rhoB;
61 float EvalRZRatio( KiTrack::IHit*a, KiTrack::IHit*b ){
71 double ratioSquared = 0.;
73 ratioSquared = ( (ax-bx)*(ax-bx) + (ay-by)*(ay-by) + (az-bz)*(az-bz) ) / ( (az-bz) * ( az-bz ) );
75 return sqrt(ratioSquared);
78 float EvalStraightTrackRatio( KiTrack::IHit*a, KiTrack::IHit*b ){
88 double rhoASquared = ax*ax + ay*ay;
89 double rhoBSquared = bx*bx + by*by;
91 double ratioSquared = 0;
92 if( (rhoBSquared >0.) && ( az != 0. ) ){
94 ratioSquared = ( ( rhoASquared * ( bz*bz ) ) / ( rhoBSquared * ( az*az ) ) );
97 return sqrt( ratioSquared );
100 virtual bool areCompatible( KiTrack::Segment* parent , KiTrack::Segment* child ){
103 if ( reader ==
nullptr ){
104 BDTCrit2::reader =
new TMVA::Reader(
"!Color:!Silent");
107 BDTCrit2::reader->AddVariable(
"Crit2_RZRatio", &BDTCrit2::Crit2_RZRatio);
108 BDTCrit2::reader->AddVariable(
"Crit2_DeltaRho", &BDTCrit2::Crit2_DeltaRho);
109 BDTCrit2::reader->AddVariable(
"Crit2_DeltaPhi", &BDTCrit2::Crit2_DeltaPhi);
110 BDTCrit2::reader->AddVariable(
"Crit2_StraightTrackRatio", &BDTCrit2::Crit2_StraightTrackRatio);
112 BDTCrit2::reader->BookMVA(
"BDT method",
"bdt2-Copy1.xml");
115 if (( parent->getHits().size() == 1 )&&( child->getHits().size() == 1 )){
119 s <<
"Crit2_BDT::This criterion needs 2 segments with 1 hit each, passed was a "
120 << parent->getHits().size() <<
" hit segment (parent) and a "
121 << child->getHits().size() <<
" hit segment (child).";
123 throw KiTrack::BadSegmentLength( s.str() );
126 KiTrack::IHit* a = parent->getHits()[0];
127 KiTrack::IHit* b = child-> getHits()[0];
134 BDTCrit2::Crit2_DeltaPhi = EvalDeltaPhi( a, b );
135 BDTCrit2::Crit2_DeltaRho = EvalDeltaRho( a, b );
136 BDTCrit2::Crit2_RZRatio = EvalRZRatio( a, b );
137 BDTCrit2::Crit2_StraightTrackRatio = EvalStraightTrackRatio( a, b );
139 float score = BDTCrit2::reader->EvaluateMVA(
"BDT method");
142 _map_name_value[
"Crit2_BDT"] = score;
143 _map_name_value[
"Crit2_BDT_DeltaPhi"] = BDTCrit2::Crit2_DeltaPhi;
144 _map_name_value[
"Crit2_BDT_DeltaRho"] = BDTCrit2::Crit2_DeltaRho;
145 _map_name_value[
"Crit2_BDT_RZRatio"] = BDTCrit2::Crit2_RZRatio;
146 _map_name_value[
"Crit2_BDT_StraightTrackRatio"] = BDTCrit2::Crit2_StraightTrackRatio;
149 if ( score < _scoreMin || score > _scoreMax )
return false;
160 static TMVA::Reader *reader;
162 static float Crit2_RZRatio, Crit2_DeltaRho, Crit2_DeltaPhi, Crit2_StraightTrackRatio;
175 BDTCrit3 (
float scoreMin ,
float scoreMax ){
176 _scoreMax = scoreMax;
177 _scoreMin = scoreMin;
188 float Eval3DAngle(KiTrack::IHit*a, KiTrack::IHit*b, KiTrack::IHit*c ){
192 float Eval2DAngle(KiTrack::IHit*a, KiTrack::IHit*b, KiTrack::IHit*c ){
196 float EvalChangeRZRatio(KiTrack::IHit*a, KiTrack::IHit*b, KiTrack::IHit*c ){
201 virtual bool areCompatible( KiTrack::Segment* parent , KiTrack::Segment* child ){
203 if ( reader ==
nullptr ){
204 BDTCrit3::reader =
new TMVA::Reader(
"!Color:!Silent");
207 BDTCrit3::reader->AddVariable(
"Crit3_ChangeRZRatio", &BDTCrit3::Crit3_ChangeRZRatio);
208 BDTCrit3::reader->AddVariable(
"Crit3_3DAngle", &BDTCrit3::Crit3_3DAngle);
209 BDTCrit3::reader->AddVariable(
"Crit3_2DAngle", &BDTCrit3::Crit3_2DAngle);
211 BDTCrit3::reader->BookMVA(
"BDT method",
"bdt2-Copy1.xml");
214 if (( parent->getHits().size() == 2 )&&( child->getHits().size() == 2 )){
218 s <<
"Crit3_BDT::This criterion needs 2 segments with 1 hit each, passed was a "
219 << parent->getHits().size() <<
" hit segment (parent) and a "
220 << child->getHits().size() <<
" hit segment (child).";
222 throw KiTrack::BadSegmentLength( s.str() );
225 KiTrack::IHit* a = child->getHits()[0];
226 KiTrack::IHit* b = child->getHits()[1];
227 KiTrack::IHit* c = parent-> getHits()[1];
230 BDTCrit3::Crit3_2DAngle = Eval2DAngle( a, b, c );
231 BDTCrit3::Crit3_3DAngle = Eval3DAngle( a, b, c );
232 BDTCrit3::Crit3_ChangeRZRatio = EvalChangeRZRatio( a, b, c );
234 float score = BDTCrit3::reader->EvaluateMVA(
"BDT3 method");
237 _map_name_value[
"Crit3_BDT"] = score;
238 _map_name_value[
"Crit3_BDT_2DAngle"] = BDTCrit3::Crit3_2DAngle;
239 _map_name_value[
"Crit3_BDT_3DAngle"] = BDTCrit3::Crit3_3DAngle;
240 _map_name_value[
"Crit3_BDT_ChangeRZRatio"] = BDTCrit3::Crit3_ChangeRZRatio;
244 if ( score < _scoreMin || score > _scoreMax )
return false;
254 static TMVA::Reader *reader;
256 static float Crit3_ChangeRZRatio, Crit3_3DAngle, Crit3_2DAngle;