1 |
pam-fi |
1.1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
2 |
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
3 |
|
|
<title>PamCut: CollectionActions/FluxHistoAction/FluxHistoAction.cpp Source File</title> |
4 |
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"> |
5 |
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"> |
6 |
|
|
</head><body> |
7 |
|
|
<!-- Generated by Doxygen 1.5.9 --> |
8 |
|
|
<div class="navigation" id="top"> |
9 |
|
|
<div class="tabs"> |
10 |
|
|
<ul> |
11 |
|
|
<li><a href="index.html"><span>Main Page</span></a></li> |
12 |
|
|
<li><a href="annotated.html"><span>Classes</span></a></li> |
13 |
|
|
<li class="current"><a href="files.html"><span>Files</span></a></li> |
14 |
|
|
</ul> |
15 |
|
|
</div> |
16 |
|
|
<div class="tabs"> |
17 |
|
|
<ul> |
18 |
|
|
<li><a href="files.html"><span>File List</span></a></li> |
19 |
|
|
<li><a href="globals.html"><span>File Members</span></a></li> |
20 |
|
|
</ul> |
21 |
|
|
</div> |
22 |
|
|
<h1>CollectionActions/FluxHistoAction/FluxHistoAction.cpp</h1><a href="FluxHistoAction_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> |
23 |
|
|
<a name="l00002"></a>00002 <span class="comment"> * FluxHistoAction.cpp</span> |
24 |
|
|
<a name="l00003"></a>00003 <span class="comment"> *</span> |
25 |
|
|
<a name="l00004"></a>00004 <span class="comment"> * Created on: 20-mag-2009</span> |
26 |
|
|
<a name="l00005"></a>00005 <span class="comment"> * Author: Nicola Mori</span> |
27 |
|
|
<a name="l00006"></a>00006 <span class="comment"> */</span> |
28 |
|
|
<a name="l00007"></a>00007 |
29 |
|
|
<a name="l00010"></a>00010 <span class="preprocessor">#include "<a class="code" href="FluxHistoAction_8h.html">FluxHistoAction.h</a>"</span> |
30 |
|
|
<a name="l00011"></a>00011 |
31 |
|
|
<a name="l00012"></a><a class="code" href="classFluxHistoAction.html#2f215089b4dc3b414b29a88e32df820d">00012</a> <a class="code" href="classFluxHistoAction.html#2f215089b4dc3b414b29a88e32df820d" title="Constructor.">FluxHistoAction::FluxHistoAction</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *actionName, TString outFileBase, TString rigBinsFile) : |
32 |
|
|
<a name="l00013"></a>00013 <a class="code" href="classCollectionAction.html" title="An abstract class that defines the interface of a generic collection action.">CollectionAction</a>(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0) |
33 |
|
|
<a name="l00014"></a>00014 #ifdef DEBUGPAMCUT |
34 |
|
|
<a name="l00015"></a>00015 , _outUp(0), _outDown(0) |
35 |
|
|
<a name="l00016"></a>00016 #endif |
36 |
|
|
<a name="l00017"></a>00017 { |
37 |
|
|
<a name="l00018"></a>00018 |
38 |
|
|
<a name="l00019"></a>00019 <span class="comment">// Reading the bins from file</span> |
39 |
|
|
<a name="l00020"></a>00020 ifstream rigBinListFile; |
40 |
|
|
<a name="l00021"></a>00021 rigBinListFile.open(rigBinsFile); |
41 |
|
|
<a name="l00022"></a>00022 |
42 |
|
|
<a name="l00023"></a>00023 TString auxString; |
43 |
|
|
<a name="l00024"></a>00024 <span class="keywordflow">while</span> (!rigBinListFile.eof()) { |
44 |
|
|
<a name="l00025"></a>00025 rigBinListFile >> auxString; |
45 |
|
|
<a name="l00026"></a>00026 <span class="keywordflow">if</span> (auxString != <span class="stringliteral">""</span>) { |
46 |
|
|
<a name="l00027"></a>00027 <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>.push_back(auxString.Atof()); |
47 |
|
|
<a name="l00028"></a>00028 } |
48 |
|
|
<a name="l00029"></a>00029 } |
49 |
|
|
<a name="l00030"></a>00030 rigBinListFile.close(); |
50 |
|
|
<a name="l00031"></a>00031 |
51 |
|
|
<a name="l00032"></a>00032 <span class="comment">// Initializing histograms</span> |
52 |
|
|
<a name="l00033"></a>00033 <a class="code" href="classFluxHistoAction.html#39cb52b179b2d169f39d692ca3f077ce">_textHisto</a>.assign(<a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>.size() - 1, 0); |
53 |
|
|
<a name="l00034"></a>00034 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.SetName(<span class="stringliteral">"rigHisto"</span>); |
54 |
|
|
<a name="l00035"></a>00035 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.SetTitle(<span class="stringliteral">"Rigidity histogram"</span>); |
55 |
|
|
<a name="l00036"></a>00036 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.GetXaxis()->SetTitle(<span class="stringliteral">"R"</span>); |
56 |
|
|
<a name="l00037"></a>00037 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.GetYaxis()->SetTitle(<span class="stringliteral">"Events"</span>); |
57 |
|
|
<a name="l00038"></a>00038 |
58 |
|
|
<a name="l00039"></a>00039 Double_t *auxArray = <span class="keyword">new</span> Double_t[<a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>.size()]; |
59 |
|
|
<a name="l00040"></a>00040 |
60 |
|
|
<a name="l00041"></a>00041 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 1; i < <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>.size(); i++) { |
61 |
|
|
<a name="l00042"></a>00042 auxArray[i] = <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>[i]; |
62 |
|
|
<a name="l00043"></a>00043 } |
63 |
|
|
<a name="l00044"></a>00044 |
64 |
|
|
<a name="l00045"></a>00045 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.SetBins(<a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>.size() - 1, auxArray); |
65 |
|
|
<a name="l00046"></a>00046 |
66 |
|
|
<a name="l00047"></a>00047 <span class="keyword">delete</span>[] auxArray; |
67 |
|
|
<a name="l00048"></a>00048 } |
68 |
|
|
<a name="l00049"></a>00049 |
69 |
|
|
<a name="l00050"></a><a class="code" href="classFluxHistoAction.html#363f9657ac69e1051449ec1907c04809">00050</a> <span class="keywordtype">void</span> <a class="code" href="classFluxHistoAction.html#363f9657ac69e1051449ec1907c04809" title="Fills histogram with the selected event.">FluxHistoAction::OnGood</a>(PamLevel2 *event) { |
70 |
|
|
<a name="l00051"></a>00051 |
71 |
|
|
<a name="l00052"></a>00052 <span class="keywordtype">float</span> rig = 1. / <span class="keyword">event</span>->GetTrack(0)->GetTrkTrack()->GetDeflection(); |
72 |
|
|
<a name="l00053"></a>00053 <span class="keywordflow">if</span> (rig >= <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>[0]) { |
73 |
|
|
<a name="l00054"></a>00054 <span class="keywordtype">int</span> i = 1; |
74 |
|
|
<a name="l00055"></a>00055 <span class="keywordtype">int</span> binningSize = <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>.size(); |
75 |
|
|
<a name="l00056"></a>00056 <span class="keywordtype">bool</span> found = <span class="keyword">false</span>; |
76 |
|
|
<a name="l00057"></a>00057 <span class="keywordflow">while</span> (!found && i < binningSize) { |
77 |
|
|
<a name="l00058"></a>00058 <span class="keywordflow">if</span> (rig < <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>[i]) |
78 |
|
|
<a name="l00059"></a>00059 found = <span class="keyword">true</span>; |
79 |
|
|
<a name="l00060"></a>00060 <span class="keywordflow">else</span> |
80 |
|
|
<a name="l00061"></a>00061 i++; |
81 |
|
|
<a name="l00062"></a>00062 } |
82 |
|
|
<a name="l00063"></a>00063 <span class="keywordflow">if</span> (found) { |
83 |
|
|
<a name="l00064"></a>00064 <a class="code" href="classFluxHistoAction.html#39cb52b179b2d169f39d692ca3f077ce">_textHisto</a>[i - 1]++; |
84 |
|
|
<a name="l00065"></a>00065 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.Fill(rig); |
85 |
|
|
<a name="l00066"></a>00066 } |
86 |
|
|
<a name="l00067"></a>00067 <span class="preprocessor">#ifdef DEBUGPAMCUT</span> |
87 |
|
|
<a name="l00068"></a>00068 <span class="preprocessor"></span> <span class="keywordflow">else</span> |
88 |
|
|
<a name="l00069"></a>00069 _outUp++; |
89 |
|
|
<a name="l00070"></a>00070 <span class="preprocessor">#endif</span> |
90 |
|
|
<a name="l00071"></a>00071 <span class="preprocessor"></span> } |
91 |
|
|
<a name="l00072"></a>00072 <span class="preprocessor">#ifdef DEBUGPAMCUT</span> |
92 |
|
|
<a name="l00073"></a>00073 <span class="preprocessor"></span> <span class="keywordflow">else</span> |
93 |
|
|
<a name="l00074"></a>00074 _outDown++; |
94 |
|
|
<a name="l00075"></a>00075 <span class="preprocessor">#endif</span> |
95 |
|
|
<a name="l00076"></a>00076 <span class="preprocessor"></span> |
96 |
|
|
<a name="l00077"></a>00077 } |
97 |
|
|
<a name="l00078"></a>00078 |
98 |
|
|
<a name="l00079"></a><a class="code" href="classFluxHistoAction.html#4565d0ea3ca0f895af489455dfd5ff04">00079</a> <span class="keywordtype">void</span> <a class="code" href="classFluxHistoAction.html#4565d0ea3ca0f895af489455dfd5ff04" title="Writes the histogram to the output files (ASCII and ROOT).">FluxHistoAction::Finalize</a>() { |
99 |
|
|
<a name="l00080"></a>00080 |
100 |
|
|
<a name="l00081"></a>00081 <span class="comment">// Write the text file</span> |
101 |
|
|
<a name="l00082"></a>00082 ofstream outTextFile((<a class="code" href="classFluxHistoAction.html#aa222dff82e9c14a330f95a9fc51d142">_outFileBase</a> + <span class="stringliteral">".txt"</span>).Data(), ios_base::out); |
102 |
|
|
<a name="l00083"></a>00083 streamsize oldPrec = cout.precision(); |
103 |
|
|
<a name="l00084"></a>00084 streamsize newPrec = 4; |
104 |
|
|
<a name="l00085"></a>00085 outTextFile.precision(newPrec); |
105 |
|
|
<a name="l00086"></a>00086 outTextFile.setf(ios::fixed, ios::floatfield); |
106 |
|
|
<a name="l00087"></a>00087 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classFluxHistoAction.html#39cb52b179b2d169f39d692ca3f077ce">_textHisto</a>.size(); i++) |
107 |
|
|
<a name="l00088"></a>00088 outTextFile << <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>[i] << <span class="stringliteral">" "</span> << <a class="code" href="classFluxHistoAction.html#c739385ec91f9a66caa36af6da127aa1">_bins</a>[i + 1] << <span class="stringliteral">" "</span> << <a class="code" href="classFluxHistoAction.html#39cb52b179b2d169f39d692ca3f077ce">_textHisto</a>[i] << <span class="stringliteral">"\n"</span>; |
108 |
|
|
<a name="l00089"></a>00089 outTextFile.close(); |
109 |
|
|
<a name="l00090"></a>00090 outTextFile.precision(oldPrec); |
110 |
|
|
<a name="l00091"></a>00091 outTextFile << resetiosflags(ios::floatfield); |
111 |
|
|
<a name="l00092"></a>00092 |
112 |
|
|
<a name="l00093"></a>00093 <span class="comment">// Write the ROOT file</span> |
113 |
|
|
<a name="l00094"></a>00094 TFile outRootFile((<a class="code" href="classFluxHistoAction.html#aa222dff82e9c14a330f95a9fc51d142">_outFileBase</a> + <span class="stringliteral">".root"</span>), <span class="stringliteral">"RECREATE"</span>); |
114 |
|
|
<a name="l00095"></a>00095 outRootFile.cd(); |
115 |
|
|
<a name="l00096"></a>00096 <a class="code" href="classFluxHistoAction.html#ece98abe4d37ec7b9e872143203bc613">_rootHisto</a>.Write(); |
116 |
|
|
<a name="l00097"></a>00097 <span class="comment">//outRootFile.Close();</span> |
117 |
|
|
<a name="l00098"></a>00098 |
118 |
|
|
<a name="l00099"></a>00099 <span class="preprocessor">#ifdef DEBUGPAMCUT</span> |
119 |
|
|
<a name="l00100"></a>00100 <span class="preprocessor"></span> cout << <span class="stringliteral">"Debug informations from "</span> << <a class="code" href="classCollectionAction.html#96783ca0685b2095bf519c17a057c926" title="Returns the action name.">GetName</a>() << <span class="stringliteral">":\n"</span>; |
120 |
|
|
<a name="l00101"></a>00101 cout << <span class="stringliteral">" Events below the lowest rigidity: "</span> << _outDown << <span class="stringliteral">"\n"</span>; |
121 |
|
|
<a name="l00102"></a>00102 cout << <span class="stringliteral">" Events above the highest rigidity: "</span> << _outUp << endl; |
122 |
|
|
<a name="l00103"></a>00103 <span class="preprocessor">#endif</span> |
123 |
|
|
<a name="l00104"></a>00104 <span class="preprocessor"></span>} |
124 |
|
|
</pre></div></div> |
125 |
|
|
<hr size="1"><address style="text-align: right;"><small>Generated on Wed May 27 15:21:27 2009 for PamCut by |
126 |
|
|
<a href="http://www.doxygen.org/index.html"> |
127 |
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> |
128 |
|
|
</body> |
129 |
|
|
</html> |