//____________________________________________________________________
//
// Atlas B-tagger class
//
// Basically the tag weight and a validity flag is stored for each
// tagger. For some taggers some additinoal information is stored. In
// detail:
//
//   * Impact paramter 2d/3d
//       - number of tracks
//       - b/u likelihoods
//
//   * SV1 and SV2
//       - b/u likelihoods
//
//   * SVInfoPlus and SV0InfoPlus
//       - invariant mass at sec. vertex
//       - number of 2-track vertices
//       - flag for good vertex
//       - total number of tracks
//       - number of good tracks at vertex
//       - number of good tracks in jet
//       - energy fraction sec. vtx/jet of charged tracks
//
//   * JetFitterTag
//       - b/u likelihoods
//       - number of vertices with more than one track
//       - number of single-track vertices
//       - number of tracks at vertices (with more than one track - sum)
//       - invariant mass of the tracks fitted to the vertices with at least 2 tracks
//       - energy fraction sec. vtx/jet of charged tracks
//       - 3-dim significance of all vertices with more than one track or -if not there-
//       - delta(phi) between sum of all momenta at vertices and the fitted B-meson flight direction 
//       - delta(eta) between sum of all momenta at vertices and the fitted B-meson flight direction
//
//
// Author: Oliver Maria Kind <mailto: kind@physik.hu-berlin.de>
// Update: $Id: AtlBTag.cxx,v 1.28 2016/09/30 14:41:45 mergelm Exp $
// Copyright: 2009 (C) Oliver Maria Kind
//
#include "AtlBTag.h"
#include <TString.h>
#include <iostream>

using namespace std;

static const char* fgTaggerNames[AtlBTag::kNumTaggers] = {
    "IP2D",
    "IP3D",
    "SVInfoPlus",
    "SV1",
    "SV2",
    "SV0",
    "SV0InfoPlus",
    "SoftMuonTag",
    "JetProb",
    "JetFitterTagNN",
    "JetFitterCOMBNN",
    "Baseline",
    "MV1",
    "MV1c",
    "MV2c20",
    "MV2c10_70",
    "MV2c10_77",
    "MV2c10_85",
};

//____________________________________________________________________

AtlBTag::AtlBTag() {
    //
    // Default constructor
    //
    fTagger = kInvalidTagger;
}

//____________________________________________________________________

AtlBTag::AtlBTag(enum ETagger tagger, Double_t weight, Bool_t Valid)
    : fTagger(tagger), fWeight(weight), fValid(Valid) {
    //
    // Normal constructor
    //
    fNTrk = 0;
    fPb = 0.;
    fPu = 0.;
    fSecVtxMass = 0.;
    fN1TrkSecVtx = 0;
    fN2TrkSecVtx = 0;
    fNManyTrkSecVtx = 0;
    fGoodSecVtx = kFALSE;
    fNGoodVtxTrk = 0;
    fNGoodJetTrk = 0;
    fEFrac = 0.;
    fSignificance3d = 0.;
    fDeltaPhi = 0.;
    fDeltaEta = 0.;
}

//____________________________________________________________________

AtlBTag::~AtlBTag() {
    //
    // Default destructor
    //
}

//____________________________________________________________________

void AtlBTag::Clear(Option_t *option) {
    //
    // Clear this object
    //
    fTagger = kInvalidTagger;
    fWeight = 0.;
    fValid = kFALSE;

    fNTrk = 0;
    fPb = 0.;
    fPu = 0.;
    fSecVtxMass = 0.;
    fN1TrkSecVtx = 0;
    fN2TrkSecVtx = 0;
    fNManyTrkSecVtx = 0;
    fGoodSecVtx = kFALSE;
    fNGoodVtxTrk = 0;
    fNGoodJetTrk = 0;
    fEFrac = 0.;
    fSignificance3d = 0.;
    fDeltaPhi = 0.;
    fDeltaEta = 0.;
}

//____________________________________________________________________

const char* AtlBTag::GetTaggerName(ETagger tagger) {
    //
    // Get human-readable name of tagger
    //
    return fgTaggerNames[tagger];
}

//____________________________________________________________________

AtlBTag::ETagger AtlBTag::GetTaggerByName(const char *name) {
    //
    // Get enum value for full name of tagger
    //
    // In case no tagger was found for the given name the value
    // kInvalidTagger is returned
    //
    for ( Int_t i = 0; i < kNumTaggers; i++) {
	if ( strcasecmp(fgTaggerNames[i], name ) == 0 )
	    return (ETagger)i;
    }
    return kInvalidTagger;
}

//____________________________________________________________________

void AtlBTag::Print(Option_t *option) const {
    //
    // Print object information
    //
    if ( fTagger == kInvalidTagger ) return;
    TString opt = option;
    opt.ToLower();

    // Print header
    if ( !opt.Contains("nohead") ) PrintHeader();

    // Print
    cout.setf(ios::showpoint | ios::fixed, ios::floatfield);
    cout.precision(3);
    cout.width(20); cout << GetName();
    cout.width(12); cout << fWeight;
    cout.width(6);  cout << IsValid();
    if ( fTagger == kIP2d || fTagger == kIP3d
	 || fTagger == kSV1 || fTagger == kSV2 ) {
	cout.width(7); cout << fPb;
	cout.width(7); cout << fPu;
    } else {
	cout.width(7); cout << "---";
	cout.width(7); cout << "---";
    }
    cout.width(13); cout << "---";

    if ( fTagger == kIP2d || fTagger == kIP3d ) {
	cout.width(6); cout << fNTrk;
    } else {
	cout.width(6); cout << "--";
    }
    cout << endl;

    // Print footer
    if ( !opt.Contains("nohead") ) PrintFooter();
}

//____________________________________________________________________

void AtlBTag::PrintHeader() {
    //
    // Print information header
    //
    cout << "-----------------------------------------------------------------------" << endl
	 << "B-Tagger                  Weight Valid     Pb     Pu   Mass (GeV)  NTrk" << endl
	 << "-----------------------------------------------------------------------" << endl;
}

//____________________________________________________________________

void AtlBTag::PrintFooter() {
    //
    // Print footer
    //
    cout << "-----------------------------------------------------------------------" << endl;
}
 AtlBTag.cxx:1
 AtlBTag.cxx:2
 AtlBTag.cxx:3
 AtlBTag.cxx:4
 AtlBTag.cxx:5
 AtlBTag.cxx:6
 AtlBTag.cxx:7
 AtlBTag.cxx:8
 AtlBTag.cxx:9
 AtlBTag.cxx:10
 AtlBTag.cxx:11
 AtlBTag.cxx:12
 AtlBTag.cxx:13
 AtlBTag.cxx:14
 AtlBTag.cxx:15
 AtlBTag.cxx:16
 AtlBTag.cxx:17
 AtlBTag.cxx:18
 AtlBTag.cxx:19
 AtlBTag.cxx:20
 AtlBTag.cxx:21
 AtlBTag.cxx:22
 AtlBTag.cxx:23
 AtlBTag.cxx:24
 AtlBTag.cxx:25
 AtlBTag.cxx:26
 AtlBTag.cxx:27
 AtlBTag.cxx:28
 AtlBTag.cxx:29
 AtlBTag.cxx:30
 AtlBTag.cxx:31
 AtlBTag.cxx:32
 AtlBTag.cxx:33
 AtlBTag.cxx:34
 AtlBTag.cxx:35
 AtlBTag.cxx:36
 AtlBTag.cxx:37
 AtlBTag.cxx:38
 AtlBTag.cxx:39
 AtlBTag.cxx:40
 AtlBTag.cxx:41
 AtlBTag.cxx:42
 AtlBTag.cxx:43
 AtlBTag.cxx:44
 AtlBTag.cxx:45
 AtlBTag.cxx:46
 AtlBTag.cxx:47
 AtlBTag.cxx:48
 AtlBTag.cxx:49
 AtlBTag.cxx:50
 AtlBTag.cxx:51
 AtlBTag.cxx:52
 AtlBTag.cxx:53
 AtlBTag.cxx:54
 AtlBTag.cxx:55
 AtlBTag.cxx:56
 AtlBTag.cxx:57
 AtlBTag.cxx:58
 AtlBTag.cxx:59
 AtlBTag.cxx:60
 AtlBTag.cxx:61
 AtlBTag.cxx:62
 AtlBTag.cxx:63
 AtlBTag.cxx:64
 AtlBTag.cxx:65
 AtlBTag.cxx:66
 AtlBTag.cxx:67
 AtlBTag.cxx:68
 AtlBTag.cxx:69
 AtlBTag.cxx:70
 AtlBTag.cxx:71
 AtlBTag.cxx:72
 AtlBTag.cxx:73
 AtlBTag.cxx:74
 AtlBTag.cxx:75
 AtlBTag.cxx:76
 AtlBTag.cxx:77
 AtlBTag.cxx:78
 AtlBTag.cxx:79
 AtlBTag.cxx:80
 AtlBTag.cxx:81
 AtlBTag.cxx:82
 AtlBTag.cxx:83
 AtlBTag.cxx:84
 AtlBTag.cxx:85
 AtlBTag.cxx:86
 AtlBTag.cxx:87
 AtlBTag.cxx:88
 AtlBTag.cxx:89
 AtlBTag.cxx:90
 AtlBTag.cxx:91
 AtlBTag.cxx:92
 AtlBTag.cxx:93
 AtlBTag.cxx:94
 AtlBTag.cxx:95
 AtlBTag.cxx:96
 AtlBTag.cxx:97
 AtlBTag.cxx:98
 AtlBTag.cxx:99
 AtlBTag.cxx:100
 AtlBTag.cxx:101
 AtlBTag.cxx:102
 AtlBTag.cxx:103
 AtlBTag.cxx:104
 AtlBTag.cxx:105
 AtlBTag.cxx:106
 AtlBTag.cxx:107
 AtlBTag.cxx:108
 AtlBTag.cxx:109
 AtlBTag.cxx:110
 AtlBTag.cxx:111
 AtlBTag.cxx:112
 AtlBTag.cxx:113
 AtlBTag.cxx:114
 AtlBTag.cxx:115
 AtlBTag.cxx:116
 AtlBTag.cxx:117
 AtlBTag.cxx:118
 AtlBTag.cxx:119
 AtlBTag.cxx:120
 AtlBTag.cxx:121
 AtlBTag.cxx:122
 AtlBTag.cxx:123
 AtlBTag.cxx:124
 AtlBTag.cxx:125
 AtlBTag.cxx:126
 AtlBTag.cxx:127
 AtlBTag.cxx:128
 AtlBTag.cxx:129
 AtlBTag.cxx:130
 AtlBTag.cxx:131
 AtlBTag.cxx:132
 AtlBTag.cxx:133
 AtlBTag.cxx:134
 AtlBTag.cxx:135
 AtlBTag.cxx:136
 AtlBTag.cxx:137
 AtlBTag.cxx:138
 AtlBTag.cxx:139
 AtlBTag.cxx:140
 AtlBTag.cxx:141
 AtlBTag.cxx:142
 AtlBTag.cxx:143
 AtlBTag.cxx:144
 AtlBTag.cxx:145
 AtlBTag.cxx:146
 AtlBTag.cxx:147
 AtlBTag.cxx:148
 AtlBTag.cxx:149
 AtlBTag.cxx:150
 AtlBTag.cxx:151
 AtlBTag.cxx:152
 AtlBTag.cxx:153
 AtlBTag.cxx:154
 AtlBTag.cxx:155
 AtlBTag.cxx:156
 AtlBTag.cxx:157
 AtlBTag.cxx:158
 AtlBTag.cxx:159
 AtlBTag.cxx:160
 AtlBTag.cxx:161
 AtlBTag.cxx:162
 AtlBTag.cxx:163
 AtlBTag.cxx:164
 AtlBTag.cxx:165
 AtlBTag.cxx:166
 AtlBTag.cxx:167
 AtlBTag.cxx:168
 AtlBTag.cxx:169
 AtlBTag.cxx:170
 AtlBTag.cxx:171
 AtlBTag.cxx:172
 AtlBTag.cxx:173
 AtlBTag.cxx:174
 AtlBTag.cxx:175
 AtlBTag.cxx:176
 AtlBTag.cxx:177
 AtlBTag.cxx:178
 AtlBTag.cxx:179
 AtlBTag.cxx:180
 AtlBTag.cxx:181
 AtlBTag.cxx:182
 AtlBTag.cxx:183
 AtlBTag.cxx:184
 AtlBTag.cxx:185
 AtlBTag.cxx:186
 AtlBTag.cxx:187
 AtlBTag.cxx:188
 AtlBTag.cxx:189
 AtlBTag.cxx:190
 AtlBTag.cxx:191
 AtlBTag.cxx:192
 AtlBTag.cxx:193
 AtlBTag.cxx:194
 AtlBTag.cxx:195
 AtlBTag.cxx:196
 AtlBTag.cxx:197
 AtlBTag.cxx:198
 AtlBTag.cxx:199
 AtlBTag.cxx:200
 AtlBTag.cxx:201
 AtlBTag.cxx:202
 AtlBTag.cxx:203
 AtlBTag.cxx:204
 AtlBTag.cxx:205
 AtlBTag.cxx:206
 AtlBTag.cxx:207
 AtlBTag.cxx:208
 AtlBTag.cxx:209
 AtlBTag.cxx:210
 AtlBTag.cxx:211
 AtlBTag.cxx:212
 AtlBTag.cxx:213
 AtlBTag.cxx:214
 AtlBTag.cxx:215
 AtlBTag.cxx:216
 AtlBTag.cxx:217