1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <meta http-equiv="X-UA-Compatible" content="IE=9"/>
- <meta name="generator" content="Doxygen 1.8.13"/>
- <meta name="viewport" content="width=device-width, initial-scale=1"/>
- <title>TTTT Analysis: /home/caleb/Sources/TTTT/analysis/MVA_Creation.cpp Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="dynsections.js"></script>
- <link href="search/search.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="search/searchdata.js"></script>
- <script type="text/javascript" src="search/search.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectalign" style="padding-left: 0.5em;">
- <div id="projectname">TTTT Analysis
-  <span id="projectnumber">0.1</span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.13 -->
- <script type="text/javascript">
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- </script>
- <script type="text/javascript" src="menudata.js"></script>
- <script type="text/javascript" src="menu.js"></script>
- <script type="text/javascript">
- $(function() {
- initMenu('',true,false,'search.php','Search');
- $(document).ready(function() { init_search(); });
- });
- </script>
- <div id="main-nav"></div>
- <!-- window showing the filter options -->
- <div id="MSearchSelectWindow"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- onkeydown="return searchBox.OnSearchSelectKey(event)">
- </div>
- <!-- iframe showing the search results (closed by default) -->
- <div id="MSearchResultsWindow">
- <iframe src="javascript:void(0)" frameborder="0"
- name="MSearchResults" id="MSearchResults">
- </iframe>
- </div>
- <div id="nav-path" class="navpath">
- <ul>
- <li class="navelem"><a class="el" href="dir_b8678fa8510b7ff9a55ffd4d18fd5e47.html">analysis</a></li> </ul>
- </div>
- </div><!-- top -->
- <div class="header">
- <div class="headertitle">
- <div class="title">MVA_Creation.cpp</div> </div>
- </div><!--header-->
- <div class="contents">
- <a href="MVA__Creation_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> </div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="preprocessor">#include <iostream></span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="preprocessor">#include <vector></span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="preprocessor">#include <utility></span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="preprocessor">#include <numeric></span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="preprocessor">#include <limits></span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> </div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="preprocessor">#include "filval/filval.hpp"</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <span class="preprocessor">#include "filval_root/filval_root.hpp"</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> </div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> <span class="preprocessor">#include "<a class="code" href="MiniTreeDataSet_8hpp.html">MiniTreeDataSet.hpp</a>"</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="preprocessor">#include <TSystem.h></span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> </div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="preprocessor">#define PI 3.14159</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="preprocessor">#define W_MASS 80.385 // GeV/c^2</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="preprocessor">#define Z_MASS 91.188 // GeV/c^2</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="preprocessor">#define T_MASS 172.44 // GeV/c^2</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> </div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="keyword">using namespace </span><a class="code" href="namespacestd.html">std</a>;</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> <span class="keyword">using namespace </span><a class="code" href="namespacefv.html">fv</a>;</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> <span class="keyword">using namespace </span><a class="code" href="namespacefv_1_1root.html">fv::root</a>;</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> </div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="keywordtype">void</span> enable_branches(MiniTreeDataSet& mt){</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  mt.track_branch<<span class="keywordtype">int</span>>(<span class="stringliteral">"nLepGood"</span>);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  mt.track_branch<<span class="keywordtype">int</span>>(<span class="stringliteral">"nJet"</span>);</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  mt.track_branch<<span class="keywordtype">int</span>>(<span class="stringliteral">"nGenPart"</span>);</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> </div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  mt.track_branch<<span class="keywordtype">int</span>>(<span class="stringliteral">"nBJetLoose40"</span>);</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  mt.track_branch<<span class="keywordtype">int</span>>(<span class="stringliteral">"nBJetMedium40"</span>);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  mt.track_branch<<span class="keywordtype">int</span>>(<span class="stringliteral">"nBJetTight40"</span>);</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> }</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="preprocessor">#define MVA_DTYPES int, int, int, int, int</span></div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="keywordtype">void</span> declare_values(MiniTreeDataSet& mt){</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> </div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <span class="keyword">auto</span> event_number = mt.get_current_event_number();</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keyword">auto</span> is_training = fv::apply(fv::GenFunction::register_function<<span class="keywordtype">bool</span>(<span class="keywordtype">int</span>)>(<span class="stringliteral">"is_odd"</span>,</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  FUNC(([](<span class="keywordtype">int</span> n){</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <span class="keywordflow">return</span> (n%2) == 1;</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  }))), fv::tuple(event_number));</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> </div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keyword">auto</span> is_signal = fv::bound(fv::GenFunction::register_function<<span class="keywordtype">bool</span>()>(<span class="stringliteral">"is_signal"</span>,</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  FUNC(([mt=&mt](){</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <span class="keyword">const</span> std::string& label = mt->get_current_event_label();</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">return</span> label == <span class="stringliteral">"signal"</span>;</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  }))), <span class="stringliteral">"is_signal"</span>);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span> </div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <span class="keyword">auto</span> weight = fv::constant<double>(<span class="stringliteral">"1"</span>, 1);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span> </div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keyword">auto</span> mva_data = fv::root::mva_data<MVA_DTYPES>(is_training, is_signal, weight,</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  {<span class="stringliteral">"nJet"</span>, lookup<int>(<span class="stringliteral">"nJet"</span>)},</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  {<span class="stringliteral">"nBJetLoose40"</span>, lookup<int>(<span class="stringliteral">"nBJetLoose40"</span>)},</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  {<span class="stringliteral">"nBJetMedium40"</span>, lookup<int>(<span class="stringliteral">"nBJetMedium40"</span>)},</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  {<span class="stringliteral">"nBJetTight40"</span>, lookup<int>(<span class="stringliteral">"nBJetTight40"</span>)},</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  {<span class="stringliteral">"nLepGood"</span>, lookup<int>(<span class="stringliteral">"nLepGood"</span>)}</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  );</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  GenValue::alias(<span class="stringliteral">"mva_data"</span>, mva_data);</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span> </div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span> }</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span> </div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span> <span class="keywordtype">void</span> declare_containers(MiniTreeDataSet& mt){</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="keyword">auto</span> mva_data = (MVAData<MVA_DTYPES>*)lookup<MVAData<MVA_DTYPES>::type>(<span class="stringliteral">"mva_data"</span>);</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="keyword">auto</span> mva = mt.register_container<MVA<MVA_DTYPES>>(<span class="stringliteral">"my_mva"</span>, mva_data);</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  mva->add_method(<span class="stringliteral">"KNN"</span>, <span class="stringliteral">"H:nkNN=20:ScaleFrac=0.8:SigmaFact=1.0:Kernel=Gaus:UseKernel=F:UseWeight=T:!Trim"</span>);</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> }</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> </div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span> </div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> <span class="keywordtype">void</span> create_mva(<span class="keyword">const</span> std::string& output_filename, <span class="keyword">const</span> std::vector<std::string>& sig_files, <span class="keyword">const</span> std::vector<std::string>& bg_files, <span class="keywordtype">bool</span> silent){</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  gSystem->Load(<span class="stringliteral">"libfilval.so"</span>);</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="keyword">auto</span> replace_suffix = [](<span class="keyword">const</span> std::string& input, <span class="keyword">const</span> std::string& new_suffix){</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">return</span> input.substr(0, input.find_last_of(<span class="stringliteral">"."</span>)) + new_suffix;</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  };</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <span class="keywordtype">string</span> log_filename = replace_suffix(output_filename, <span class="stringliteral">".log"</span>);</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> </div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  std::map<std::string, std::string> filenames_with_labels;</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keywordflow">for</span> (<span class="keyword">const</span> std::string& fname : sig_files){</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  filenames_with_labels[fname] = <span class="stringliteral">"signal"</span>;</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  }</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <span class="keywordflow">for</span> (<span class="keyword">const</span> std::string& fname : bg_files){</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  filenames_with_labels[fname] = <span class="stringliteral">"background"</span>;</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  }</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span> </div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  MiniTreeDataSet mt(output_filename, filenames_with_labels);</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span> </div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  enable_branches(mt);</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  declare_values(mt);</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  declare_containers(mt);</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span> </div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  mt.process(silent);</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  mt.save_all();</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> }</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> </div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> * argv[])</div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> {</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  fv::util::ArgParser args(argc, argv);</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  <span class="keywordflow">if</span>(args.cmdOptionExists(<span class="stringliteral">"-h"</span>)) {</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  cout << <span class="stringliteral">"Usage: ./mva (-s) -out outfile.root -sig [signal_minitree.root]+ -bg [background_minitree.root]+"</span> << endl;</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  }</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordtype">bool</span> silent = args.cmdOptionExists(<span class="stringliteral">"-s"</span>);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  <span class="keywordtype">string</span> output_filename = args.getCmdOption(<span class="stringliteral">"-out"</span>);</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  std::vector<std::string> sig_files;</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  std::vector<std::string> bg_files;</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  std::vector<std::string>* cur_flist = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span> </div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=1; i<argc; i++){</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  <span class="keywordflow">if</span> (!strncmp(argv[i], <span class="stringliteral">"-sig"</span>, 4)){</div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  cur_flist = &sig_files;</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  }</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strncmp(argv[i], <span class="stringliteral">"-bg"</span>, 3)){</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  cur_flist = &bg_files;</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  <span class="keywordflow">continue</span>;</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  }</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strncmp(argv[i], <span class="stringliteral">"-out"</span>, 4)){</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  cur_flist = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  }</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cur_flist != <span class="keyword">nullptr</span>){</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  cur_flist->push_back(argv[i]);</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  }</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  }</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  create_mva(output_filename, sig_files, bg_files, silent);</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> }</div><div class="ttc" id="MiniTreeDataSet_8hpp_html"><div class="ttname"><a href="MiniTreeDataSet_8hpp.html">MiniTreeDataSet.hpp</a></div></div>
- <div class="ttc" id="namespacestd_html"><div class="ttname"><a href="namespacestd.html">std</a></div><div class="ttdoc">STL namespace. </div></div>
- <div class="ttc" id="namespacefv_html"><div class="ttname"><a href="namespacefv.html">fv</a></div><div class="ttdoc">The namespace containing all filval classes and functions. </div><div class="ttdef"><b>Definition:</b> <a href="api_8hpp_source.html#l00046">api.hpp:46</a></div></div>
- <div class="ttc" id="namespacefv_1_1root_html"><div class="ttname"><a href="namespacefv_1_1root.html">fv::root</a></div><div class="ttdef"><b>Definition:</b> <a href="root_2api_8hpp_source.html#l00008">api.hpp:8</a></div></div>
- </div><!-- fragment --></div><!-- contents -->
- <!-- start footer part -->
- <hr class="footer"/><address class="footer"><small>
- Generated by  <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/>
- </a> 1.8.13
- </small></address>
- </body>
- </html>
|