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

Annotation of /PamCut/CollectionActions/FluxHistoAction/FluxHistoAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Fri Aug 14 10:34:28 2009 UTC (15 years, 4 months ago) by pam-fi
Branch: MAIN
CVS Tags: Root_V8, MergedToHEAD_1, nuclei_reproc, MergedFromV8_1, BeforeMergingFromV8_1, V9, HEAD
Branch point for: V8
Changes since 1.4: +1 -1 lines
Bug fix.

1 pam-fi 1.1 /*
2     * FluxHistoAction.cpp
3     *
4     * Created on: 20-mag-2009
5     * Author: Nicola Mori
6     */
7    
8 pam-fi 1.4 /*! @file FluxHistoAction.cpp The FluxHistoAction class implementation file. */
9 pam-fi 1.1
10     #include "FluxHistoAction.h"
11    
12 pam-fi 1.2 FluxHistoAction::FluxHistoAction(const char *actionName, TString outFileBase, TString rigBinsFile, TString mode) :
13     CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _mode(mode)
14 pam-fi 1.1 #ifdef DEBUGPAMCUT
15 pam-fi 1.2 , _outUp(0), _outDown(0)
16 pam-fi 1.1 #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 pam-fi 1.4 _rootHisto.SetName(GetName());
35 pam-fi 1.1 _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 pam-fi 1.5 for (unsigned int i = 0; i < _bins.size(); i++) {
42 pam-fi 1.1 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 pam-fi 1.2 _outUp++;
70 pam-fi 1.1 #endif
71     }
72     #ifdef DEBUGPAMCUT
73     else
74 pam-fi 1.2 _outDown++;
75 pam-fi 1.1 #endif
76    
77     }
78    
79     void FluxHistoAction::Finalize() {
80    
81     // Write the text file
82 pam-fi 1.2 // Currently, text output doesn't support append.
83 pam-fi 1.1 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 pam-fi 1.4 outTextFile << _textHisto[i] << "\n";
90 pam-fi 1.1 outTextFile.close();
91     outTextFile.precision(oldPrec);
92     outTextFile << resetiosflags(ios::floatfield);
93    
94     // Write the ROOT file
95 pam-fi 1.2 TFile outRootFile((_outFileBase + ".root"), _mode);
96 pam-fi 1.1 outRootFile.cd();
97     _rootHisto.Write();
98 pam-fi 1.3 outRootFile.Close();
99 pam-fi 1.1
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