/[PAMELA software]/PamCut/CollectionActions/FluxHistoAction/FluxHistoAction.cpp
ViewVC logotype

Contents of /PamCut/CollectionActions/FluxHistoAction/FluxHistoAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Wed Jun 10 12:43:12 2009 UTC (15 years, 5 months ago) by pam-fi
Branch: MAIN
Changes since 1.2: +1 -1 lines
Fix in Finalize().

1 /*
2 * FluxHistoAction.cpp
3 *
4 * Created on: 20-mag-2009
5 * Author: Nicola Mori
6 */
7
8 /*! @file FluxHistoAction.cpp The FluxHistoAction class implementation file */
9
10 #include "FluxHistoAction.h"
11
12 FluxHistoAction::FluxHistoAction(const char *actionName, TString outFileBase, TString rigBinsFile, TString mode) :
13 CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _mode(mode)
14 #ifdef DEBUGPAMCUT
15 , _outUp(0), _outDown(0)
16 #endif
17 {
18
19 // Reading the bins from file
20 ifstream rigBinListFile;
21 rigBinListFile.open(rigBinsFile);
22
23 TString auxString;
24 while (!rigBinListFile.eof()) {
25 rigBinListFile >> auxString;
26 if (auxString != "") {
27 _bins.push_back(auxString.Atof());
28 }
29 }
30 rigBinListFile.close();
31
32 // Initializing histograms
33 _textHisto.assign(_bins.size() - 1, 0);
34 _rootHisto.SetName("rigHisto");
35 _rootHisto.SetTitle("Rigidity histogram");
36 _rootHisto.GetXaxis()->SetTitle("R");
37 _rootHisto.GetYaxis()->SetTitle("Events");
38
39 Double_t *auxArray = new Double_t[_bins.size()];
40
41 for (unsigned int i = 1; i < _bins.size(); i++) {
42 auxArray[i] = _bins[i];
43 }
44
45 _rootHisto.SetBins(_bins.size() - 1, auxArray);
46
47 delete[] auxArray;
48 }
49
50 void FluxHistoAction::OnGood(PamLevel2 *event) {
51
52 float rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection();
53 if (rig >= _bins[0]) {
54 int i = 1;
55 int binningSize = _bins.size();
56 bool found = false;
57 while (!found && i < binningSize) {
58 if (rig < _bins[i])
59 found = true;
60 else
61 i++;
62 }
63 if (found) {
64 _textHisto[i - 1]++;
65 _rootHisto.Fill(rig);
66 }
67 #ifdef DEBUGPAMCUT
68 else
69 _outUp++;
70 #endif
71 }
72 #ifdef DEBUGPAMCUT
73 else
74 _outDown++;
75 #endif
76
77 }
78
79 void FluxHistoAction::Finalize() {
80
81 // Write the text file
82 // Currently, text output doesn't support append.
83 ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);
84 streamsize oldPrec = cout.precision();
85 streamsize newPrec = 4;
86 outTextFile.precision(newPrec);
87 outTextFile.setf(ios::fixed, ios::floatfield);
88 for (unsigned int i = 0; i < _textHisto.size(); i++)
89 outTextFile << _bins[i] << " " << _bins[i + 1] << " " << _textHisto[i] << "\n";
90 outTextFile.close();
91 outTextFile.precision(oldPrec);
92 outTextFile << resetiosflags(ios::floatfield);
93
94 // Write the ROOT file
95 TFile outRootFile((_outFileBase + ".root"), _mode);
96 outRootFile.cd();
97 _rootHisto.Write();
98 outRootFile.Close();
99
100 #ifdef DEBUGPAMCUT
101 cout << "Debug informations from " << GetName() << ":\n";
102 cout << " Events below the lowest rigidity: " << _outDown << "\n";
103 cout << " Events above the highest rigidity: " << _outUp << endl;
104 #endif
105 }

  ViewVC Help
Powered by ViewVC 1.1.23