This file is indexed.

/usr/include/root/TMVA/RuleEnsemble.h is in libroot-tmva-dev 5.34.19+dfsg-1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
// @(#)root/tmva $Id$
// Author: Andreas Hoecker, Joerg Stelzer, Fredrik Tegenfeldt, Helge Voss

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : RuleEnsemble                                                          *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      A class generating an ensemble of rules                                   *
 *      Input:  a forest of decision trees                                        *
 *      Output: an ensemble of rules                                              *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Fredrik Tegenfeldt <Fredrik.Tegenfeldt@cern.ch> - Iowa State U., USA      *
 *      Helge Voss         <Helge.Voss@cern.ch>         - MPI-KP Heidelberg, Ger. *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         * 
 *      Iowa State U.                                                             *
 *      MPI-K Heidelberg, Germany                                                 * 
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_RuleEnsemble
#define ROOT_TMVA_RuleEnsemble

#if ROOT_VERSION_CODE >= 364802
#ifndef ROOT_TMathBase
#include "TMathBase.h"
#endif
#else
#ifndef ROOT_TMath
#include "TMath.h"
#endif
#endif

#ifndef ROOT_TMVA_DecisionTree
#include "TMVA/DecisionTree.h"
#endif
#ifndef ROOT_TMVA_Event
#include "TMVA/Event.h"
#endif
#ifndef ROOT_TMVA_Rule
#include "TMVA/Rule.h"
#endif
#ifndef ROOT_TMVA_Types
#include "TMVA/Types.h"
#endif

class TH1F;

namespace TMVA {

   class TBits;
   class MethodBase;
   class RuleFit;
   class MethodRuleFit;
   class RuleEnsemble;
   class MsgLogger;

   std::ostream& operator<<( std::ostream& os, const RuleEnsemble& event );

   class RuleEnsemble {

      // output operator for a RuleEnsemble
      friend std::ostream& operator<< ( std::ostream& os, const RuleEnsemble& rules );
      
   public:

      enum ELearningModel { kFull=0, kRules=1, kLinear=2 };

      // main constructor
      RuleEnsemble( RuleFit* rf );

      // copy constructor
      RuleEnsemble( const RuleEnsemble& other );

      // empty constructor
      RuleEnsemble();

      // destructor
      virtual ~RuleEnsemble();

      // initialize
      void Initialize( const RuleFit* rf );

      // set message type
      void SetMsgType( EMsgType t );

      // makes the model - calls MakeRules() and MakeLinearTerms()
      void MakeModel();

      // generates the rules from a given forest of decision trees
      void MakeRules( const std::vector< const TMVA::DecisionTree *>& forest );

      // make the linear terms
      void MakeLinearTerms();

      // select linear model
      void SetModelLinear() { fLearningModel = kLinear; }

      // select rule model
      void SetModelRules()  { fLearningModel = kRules; }

      // select full (linear+rules) model
      void SetModelFull()   { fLearningModel = kFull; }

      // set rule collection (if not created by MakeRules())
      void SetRules( const std::vector< TMVA::Rule *> & rules );

      // set RuleFit ptr
      void SetRuleFit( const RuleFit *rf ) { fRuleFit = rf; }

      // set coefficients
      void  SetCoefficients( const std::vector< Double_t >& v );
      void  SetCoefficient( UInt_t i, Double_t v )                  { if (i<fRules.size()) fRules[i]->SetCoefficient(v); }
      //
      void  SetOffset(Double_t v=0.0)                               { fOffset=v; }
      void  AddOffset(Double_t v)                                   { fOffset+=v; }
      void  SetLinCoefficients( const std::vector< Double_t >& v )  { fLinCoefficients = v; }
      void  SetLinCoefficient( UInt_t i, Double_t v )               { fLinCoefficients[i] = v; }
      void  SetLinDM( const std::vector<Double_t>   & xmin ) { fLinDM   = xmin; }
      void  SetLinDP( const std::vector<Double_t>   & xmax ) { fLinDP   = xmax; }
      void  SetLinNorm( const std::vector<Double_t> & norm ) { fLinNorm = norm; }

      Double_t CalcLinNorm( Double_t stdev ) { return ( stdev>0 ? fAverageRuleSigma/stdev : 1.0 ); }

      // clear coefficients
      void  ClearCoefficients( Double_t val=0 )    { for (UInt_t i=0; i<fRules.size(); i++)           fRules[i]->SetCoefficient(val); }
      void  ClearLinCoefficients( Double_t val=0 ) { for (UInt_t i=0; i<fLinCoefficients.size(); i++) fLinCoefficients[i]=val; }
      void  ClearLinNorm( Double_t val=1.0 )       { for (UInt_t i=0; i<fLinNorm.size(); i++)         fLinNorm[i]=val; }

      // set maximum allowed distance between equal rules
      void SetRuleMinDist(Double_t d)          { fRuleMinDist = d; }

      // set minimum rule importance - used by CleanupRules()
      void SetImportanceCut(Double_t minimp=0) { fImportanceCut=minimp; }

      // set the quantile for linear terms
      void SetLinQuantile(Double_t q)          { fLinQuantile=q; }

      // set average sigma for rules
      void SetAverageRuleSigma(Double_t v) { if (v>0.5) v=0.5; fAverageRuleSigma = v; fAverageSupport = 0.5*(1.0+TMath::Sqrt(1.0-4.0*v*v)); }

      // Calculate the number of possible rules from a given tree
      Int_t CalcNRules( const TMVA::DecisionTree* dtree );
      // Recursivly search for end-nodes; used by CalcNRules()
      void  FindNEndNodes( const TMVA::Node* node, Int_t& nendnodes );

      // set current event to be used
      void SetEvent( const Event & e ) { fEvent = &e; fEventCacheOK = kFALSE; }

      // fill cached values of rule/linear respons
      void UpdateEventVal();

      // fill binary rule respons for all events (or selected subset)
      void MakeRuleMap(const std::vector<const TMVA::Event *> *events=0, UInt_t ifirst=0, UInt_t ilast=0);

      // clear rule map
      void ClearRuleMap() { fRuleMap.clear(); fRuleMapEvents=0; }

      // evaluates the event using the ensemble of rules
      // the following uses fEventCache, that is per event saved in cache
      Double_t EvalEvent() const;
      Double_t EvalEvent( const Event & e );

      // same as previous but using other model coefficients
      Double_t EvalEvent( Double_t ofs,
                          const std::vector<Double_t> & coefs,
                          const std::vector<Double_t> & lincoefs) const;
      Double_t EvalEvent( const Event & e,
                          Double_t ofs,
                          const std::vector<Double_t> & coefs,
                          const std::vector<Double_t> & lincoefs);

      // same as above but using the event index
      // these will use fRuleMap - MUST call MakeRuleMap() before - no check...
      Double_t EvalEvent( UInt_t evtidx ) const;
      Double_t EvalEvent( UInt_t evtidx,
                          Double_t ofs,
                          const std::vector<Double_t> & coefs,
                          const std::vector<Double_t> & lincoefs) const;

      // evaluate the linear term using event by reference
      //      Double_t EvalLinEvent( UInt_t vind ) const;
      Double_t EvalLinEvent() const;
      Double_t EvalLinEvent( const std::vector<Double_t> & coefs ) const;
      Double_t EvalLinEvent( const Event &e );
      Double_t EvalLinEvent( const Event &e, UInt_t vind );
      Double_t EvalLinEvent( const Event &e, const std::vector<Double_t> & coefs );

      // idem but using evtidx - must call MakeRuleMap() first
      Double_t EvalLinEvent( UInt_t evtidx ) const;
      Double_t EvalLinEvent( UInt_t evtidx, const std::vector<Double_t> & coefs ) const;
      Double_t EvalLinEvent( UInt_t evtidx, UInt_t vind ) const;
      Double_t EvalLinEvent( UInt_t evtidx, UInt_t vind, Double_t coefs ) const;

      // evaluate linear terms used to fill fEventLinearVal
      Double_t EvalLinEventRaw( UInt_t vind, const Event &e, Bool_t norm ) const;
      Double_t EvalLinEventRaw( UInt_t vind, UInt_t evtidx,  Bool_t norm ) const;

      // calculate p(y=1|x) for a given event using the linear terms
      Double_t PdfLinear( Double_t & nsig, Double_t & ntot ) const;

      // calculate p(y=1|x) for a given event using the rules
      Double_t PdfRule( Double_t & nsig, Double_t & ntot ) const;

      // calculate F* = 2*p(y=1|x) - 1
      Double_t FStar() const;
      Double_t FStar(const TMVA::Event & e );

      // set reference importance for all model objects
      void SetImportanceRef(Double_t impref);

      // calculates the support for all rules given the set of events
      void CalcRuleSupport();

      // calculates rule importance
      void CalcImportance();

      // calculates rule importance
      Double_t CalcRuleImportance();

      // calculates linear importance
      Double_t CalcLinImportance();

      // calculates variable importance
      void CalcVarImportance();

      // remove rules of low importance
      void CleanupRules();

      // remove linear terms of low importance
      void CleanupLinear();

      // remove similar rules
      void RemoveSimilarRules();

      // get rule statistics
      void RuleStatistics();

      // get rule response stats
      void RuleResponseStats();

      // copy operator
      void operator=( const RuleEnsemble& other ) { Copy( other ); }

      // calculate sum of the squared coefficents
      Double_t CoefficientRadius();

      // fill the vector with the coefficients
      void GetCoefficients( std::vector< Double_t >& v );

      // accessors
      const MethodRuleFit*                   GetMethodRuleFit()   const;
      const MethodBase*                      GetMethodBase()      const;
      const RuleFit*                         GetRuleFit()         const { return fRuleFit; }
      //
      const std::vector<const TMVA::Event *>*     GetTrainingEvents()  const;
      const Event*                    GetTrainingEvent(UInt_t i) const;
      const Event*                    GetEvent() const { return fEvent; }
      //
      Bool_t                          DoLinear()             const { return (fLearningModel==kFull) || (fLearningModel==kLinear); }
      Bool_t                          DoRules()              const { return (fLearningModel==kFull) || (fLearningModel==kRules); }
      Bool_t                          DoOnlyRules()          const { return (fLearningModel==kRules); }
      Bool_t                          DoOnlyLinear()         const { return (fLearningModel==kLinear); }
      Bool_t                          DoFull()               const { return (fLearningModel==kFull); }
      ELearningModel                  GetLearningModel()     const { return fLearningModel; }
      Double_t                        GetImportanceCut()     const { return fImportanceCut; }
      Double_t                        GetImportanceRef()     const { return fImportanceRef; }
      Double_t                        GetOffset()            const { return fOffset; }
      UInt_t                          GetNRules()            const { return (DoRules() ? fRules.size():0); }
      const std::vector<TMVA::Rule*>& GetRulesConst()        const { return fRules; }
      std::vector<TMVA::Rule*>&       GetRules()                   { return fRules; }
      const std::vector< Double_t >&  GetLinCoefficients()   const { return fLinCoefficients; }
      const std::vector< Double_t >&  GetLinNorm()           const { return fLinNorm; }
      const std::vector< Double_t >&  GetLinImportance()     const { return fLinImportance; }
      const std::vector< Double_t >&  GetVarImportance()     const { return fVarImportance; }
      UInt_t                          GetNLinear()           const { return (DoLinear() ? fLinNorm.size():0); }
      Double_t                        GetLinQuantile()       const { return fLinQuantile; }

      const Rule    *GetRulesConst(int i)        const { return fRules[i]; }
      Rule          *GetRules(int i)                   { return fRules[i]; }

      UInt_t         GetRulesNCuts(int i)        const { return fRules[i]->GetRuleCut()->GetNcuts(); }
      Double_t       GetRuleMinDist()            const { return fRuleMinDist; }
      Double_t       GetLinCoefficients(int i)   const { return fLinCoefficients[i]; }
      Double_t       GetLinNorm(int i)           const { return fLinNorm[i]; }
      Double_t       GetLinDM(int i)             const { return fLinDM[i]; }
      Double_t       GetLinDP(int i)             const { return fLinDP[i]; }
      Double_t       GetLinImportance(int i)     const { return fLinImportance[i]; }
      Double_t       GetVarImportance(int i)     const { return fVarImportance[i]; }
      Double_t       GetRulePTag(int i)          const { return fRulePTag[i]; }
      Double_t       GetRulePSS(int i)           const { return fRulePSS[i]; }
      Double_t       GetRulePSB(int i)           const { return fRulePSB[i]; }
      Double_t       GetRulePBS(int i)           const { return fRulePBS[i]; }
      Double_t       GetRulePBB(int i)           const { return fRulePBB[i]; }

      Bool_t         IsLinTermOK(int i)          const { return fLinTermOK[i]; }
      //
      Double_t       GetAverageSupport()             const { return fAverageSupport; }
      Double_t       GetAverageRuleSigma()           const { return fAverageRuleSigma; }
      Double_t       GetEventRuleVal(UInt_t i)       const { return (fEventRuleVal[i] ? 1.0:0.0); }
      Double_t       GetEventLinearVal(UInt_t i)     const { return fEventLinearVal[i]; }
      Double_t       GetEventLinearValNorm(UInt_t i) const { return fEventLinearVal[i]*fLinNorm[i]; }
      //
      const std::vector<UInt_t>  & GetEventRuleMap(UInt_t evtidx) const { return fRuleMap[evtidx]; }
      const TMVA::Event *GetRuleMapEvent(UInt_t evtidx) const { return (*fRuleMapEvents)[evtidx]; }
      Bool_t         IsRuleMapOK()               const { return fRuleMapOK; }

      // print rule generation info
      void  PrintRuleGen() const;

      // print the ensemble
      void  Print() const;

      // print the model in a cryptic way
      void  PrintRaw   ( std::ostream& os  ) const; // obsolete
      void* AddXMLTo   ( void* parent ) const;
   
      // read the model from input stream
      void  ReadRaw    ( std::istream& istr ); // obsolete
      void  ReadFromXML( void* wghtnode ); 


   private:

      // delete all rules
      void DeleteRules() { for (UInt_t i=0; i<fRules.size(); i++) delete fRules[i]; fRules.clear(); }

      // copy method
      void  Copy( RuleEnsemble const& other );

      // set all coeffs to default values
      void  ResetCoefficients();

      // make rules form one decision tree
      void  MakeRulesFromTree( const DecisionTree *dtree );

      // add a rule with tghe given end-node
      void  AddRule( const Node *node );

      // make a rule
      Rule *MakeTheRule( const Node *node );


      ELearningModel                fLearningModel;     // can be full (rules+linear), rules, linear
      Double_t                      fImportanceCut;     // minimum importance accepted
      Double_t                      fLinQuantile;       // quantile cut to remove outliers
      Double_t                      fOffset;            // offset in discriminator function
      std::vector< TMVA::Rule* >    fRules;             // vector of rules
      std::vector< Char_t >         fLinTermOK;         // flags linear terms with sufficient strong importance <-- stores boolean
      std::vector< Double_t >       fLinDP;             // delta+ in eq 24, ref 2
      std::vector< Double_t >       fLinDM;             // delta-
      std::vector< Double_t >       fLinCoefficients;   // linear coefficients, one per variable
      std::vector< Double_t >       fLinNorm;           // norm of ditto, see after eq 26 in ref 2
      std::vector< TH1F* >          fLinPDFB;           // pdfs for each variable, background
      std::vector< TH1F* >          fLinPDFS;           // pdfs for each variable, signal
      std::vector< Double_t >       fLinImportance;     // linear term importance
      std::vector< Double_t >       fVarImportance;     // one importance per input variable
      Double_t                      fImportanceRef;     // reference importance (max)
      Double_t                      fAverageSupport;    // average support (over all rules)
      Double_t                      fAverageRuleSigma;  // average rule sigma
      //
      std::vector< Double_t >       fRuleVarFrac;       // fraction of rules using a given variable - size of vector = n(variables)
      std::vector< Double_t >       fRulePSS;           // p(tag as S|S) - tagged as S if rule is SIG and the event is accepted
      std::vector< Double_t >       fRulePSB;           // p(tag as S|B)
      std::vector< Double_t >       fRulePBS;           // p(tag as B|S)
      std::vector< Double_t >       fRulePBB;           // p(tag as B|B)
      std::vector< Double_t >       fRulePTag;          // p(tag)
      Double_t                      fRuleFSig;          // N(sig)/N(sig)+N(bkg)
      Double_t                      fRuleNCave;         // N(cuts) average
      Double_t                      fRuleNCsig;         // idem sigma
      //
      Double_t                      fRuleMinDist;       // minimum rule distance
      UInt_t                        fNRulesGenerated;   // number of rules generated, before cleanup
      //
      const Event*                  fEvent;             // current event.
      Bool_t                        fEventCacheOK;      // true if rule/linear respons are updated
      std::vector<Char_t>           fEventRuleVal;      // the rule respons of current event <----- stores boolean
      std::vector<Double_t>         fEventLinearVal;    // linear respons
      //
      Bool_t                        fRuleMapOK;         // true if MakeRuleMap() has been called
      std::vector< std::vector<UInt_t> > fRuleMap;           // map of rule responses
      UInt_t                        fRuleMapInd0;       // start index
      UInt_t                        fRuleMapInd1;       // last index
      const std::vector<const TMVA::Event *> *fRuleMapEvents; // pointer to vector of events used
      //
      const RuleFit*                fRuleFit;           // pointer to rule fit object 

      mutable MsgLogger*            fLogger;            //! message logger
      MsgLogger& Log() const { return *fLogger; }                       
   };
}

//_______________________________________________________________________
inline void TMVA::RuleEnsemble::UpdateEventVal()
{
   //
   // Update rule and linear respons using the current event
   //
   if (fEventCacheOK) return;
   //
   if (DoRules()) {
      UInt_t nrules = fRules.size();
      fEventRuleVal.resize(nrules,kFALSE);
      for (UInt_t r=0; r<nrules; r++) {
         fEventRuleVal[r] = fRules[r]->EvalEvent(*fEvent);
      }
   }
   if (DoLinear()) {
      UInt_t nlin = fLinTermOK.size();
      fEventLinearVal.resize(nlin,0);
      for (UInt_t r=0; r<nlin; r++) {
         fEventLinearVal[r] = EvalLinEventRaw(r,*fEvent,kFALSE); // not normalised!
      }
   }
   fEventCacheOK = kTRUE;
}

//_____________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalEvent() const
{
   // evaluate current event

   Int_t nrules = fRules.size();
   Double_t rval=fOffset;
   Double_t linear=0;
   //
   // evaluate all rules
   // normally it should NOT use the normalized rules - the flag should be kFALSE
   //
   if (DoRules()) {
      for ( Int_t i=0; i<nrules; i++ ) {
         if (fEventRuleVal[i])
            rval += fRules[i]->GetCoefficient();
      }
   }
   //
   // Include linear part - the call below incorporates both coefficient and normalisation (fLinNorm)
   //
   if (DoLinear()) linear = EvalLinEvent();
   rval +=linear;

   return rval;
}

//_____________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalEvent( Double_t ofs,
                                               const std::vector<Double_t> & coefs,
                                               const std::vector<Double_t> & lincoefs ) const
{
   // evaluate current event with given offset and coefs

   Int_t nrules    = fRules.size();
   Double_t rval   = ofs;
   Double_t linear = 0;
   //
   // evaluate all rules
   //
   if (DoRules()) {
      for ( Int_t i=0; i<nrules; i++ ) {
         if (fEventRuleVal[i])
            rval += coefs[i];
      }
   }
   //
   // Include linear part - the call below incorporates both coefficient and normalisation (fLinNorm)
   //
   if (DoLinear()) linear = EvalLinEvent(lincoefs);
   rval +=linear;

   return rval;
}

//_____________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalEvent(const TMVA::Event & e)
{
   // evaluate event e
   SetEvent(e);
   UpdateEventVal();
   return EvalEvent();
}

//_____________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalEvent(const TMVA::Event & e,
                                              Double_t ofs,
                                              const std::vector<Double_t> & coefs,
                                              const std::vector<Double_t> & lincoefs )
{
   // evaluate event e
   SetEvent(e);
   UpdateEventVal();
   return EvalEvent(ofs,coefs,lincoefs);
}

//_____________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalEvent(UInt_t evtidx) const
{
   // evaluate event with index evtidx
   if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1)) return 0;
   //
   Double_t rval=fOffset;
   if (DoRules()) {
      UInt_t nrules = fRuleMap[evtidx].size();
      UInt_t rind;
      for (UInt_t ir = 0; ir<nrules; ir++) {
         rind = fRuleMap[evtidx][ir];
         rval += fRules[rind]->GetCoefficient();
      }
   }
   if (DoLinear()) {
      UInt_t nlin = fLinTermOK.size();
      for (UInt_t r=0; r<nlin; r++) {
         if (fLinTermOK[r]) {
            rval += fLinCoefficients[r] * EvalLinEventRaw(r,*(*fRuleMapEvents)[evtidx],kTRUE);
         }
      }
   }
   return rval;
}

//_____________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalEvent(UInt_t evtidx,
                                              Double_t ofs,
                                              const std::vector<Double_t> & coefs,
                                              const std::vector<Double_t> & lincoefs ) const
{
   // evaluate event with index evtidx and user given model coefficients
   //
   if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1)) return 0;
   Double_t rval=ofs;
   if (DoRules()) {
      UInt_t nrules = fRuleMap[evtidx].size();
      UInt_t rind;
      for (UInt_t ir = 0; ir<nrules; ir++) {
         rind = fRuleMap[evtidx][ir];
         rval += coefs[rind];
      }
   }
   if (DoLinear()) {
      rval += EvalLinEvent( evtidx, lincoefs );
   }
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEventRaw( UInt_t vind, const TMVA::Event & e, Bool_t norm) const
{
   // evaluate the event linearly (not normalized)

   Double_t val  = e.GetValue(vind);
   Double_t rval = TMath::Min( fLinDP[vind], TMath::Max( fLinDM[vind], val ) );
   if (norm) rval *= fLinNorm[vind];
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEventRaw( UInt_t vind, UInt_t evtidx, Bool_t norm) const
{
   // evaluate the event linearly (not normalized)

   Double_t val  = (*fRuleMapEvents)[evtidx]->GetValue(vind);
   Double_t rval = TMath::Min( fLinDP[vind], TMath::Max( fLinDM[vind], val ) );
   if (norm) rval *= fLinNorm[vind];
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent() const
{
   // evaluate event linearly

   Double_t rval=0;
   for (UInt_t v=0; v<fLinTermOK.size(); v++) {
      if (fLinTermOK[v])
         rval += fLinCoefficients[v]*fEventLinearVal[v]*fLinNorm[v];
   }
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent(const std::vector<Double_t> & coefs) const
{
   // evaluate event linearly using the given coefficients

   Double_t rval=0;
   for (UInt_t v=0; v<fLinTermOK.size(); v++) {
      if (fLinTermOK[v])
         rval += coefs[v]*fEventLinearVal[v]*fLinNorm[v];
   }
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( const TMVA::Event& e )
{
   // evaluate event linearly

   SetEvent(e);
   UpdateEventVal();
   return EvalLinEvent();
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( const TMVA::Event& e, UInt_t vind )
{
   // evaluate linear term vind

   SetEvent(e);
   UpdateEventVal();
   return GetEventLinearValNorm(vind);
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( const TMVA::Event& e, const std::vector<Double_t> & coefs )
{
   // evaluate event linearly using the given coefficients

   SetEvent(e);
   UpdateEventVal();
   return EvalLinEvent(coefs);
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( UInt_t evtidx, const std::vector<Double_t> & coefs ) const
{
   // evaluate event linearly using the given coefficients
   if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1)) return 0;
   Double_t rval=0;
   UInt_t nlin = fLinTermOK.size();
   for (UInt_t r=0; r<nlin; r++) {
      if (fLinTermOK[r]) {
         rval += coefs[r] * EvalLinEventRaw(r,*(*fRuleMapEvents)[evtidx],kTRUE);
      }
   }
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( UInt_t evtidx ) const
{
   // evaluate event linearly using the given coefficients
   if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1)) return 0;
   Double_t rval=0;
   UInt_t nlin = fLinTermOK.size();
   for (UInt_t r=0; r<nlin; r++) {
      if (fLinTermOK[r]) {
         rval += fLinCoefficients[r] * EvalLinEventRaw(r,*(*fRuleMapEvents)[evtidx],kTRUE);
      }
   }
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( UInt_t evtidx, UInt_t vind ) const
{
   // evaluate event linearly using the given coefficients
   if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1)) return 0;
   Double_t rval;
   rval = fLinCoefficients[vind] * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],kTRUE);
   return rval;
}

//_______________________________________________________________________
inline Double_t TMVA::RuleEnsemble::EvalLinEvent( UInt_t evtidx, UInt_t vind, Double_t coefs ) const
{
   // evaluate event linearly using the given coefficients
   if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1)) return 0;
   Double_t rval;
   rval = coefs * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],kTRUE);
   return rval;
}

#endif