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

Annotation of /PamCut/CollectionActions/RigFillAction/RigFillAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Thu Mar 11 19:11:01 2010 UTC (14 years, 9 months ago) by pam-fi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +0 -0 lines
FILE REMOVED
Replaced by a Histo2D-inherited version.

1 pam-fi 1.1 /*
2     * RigFillAction.cpp
3     *
4     * Created on: 14/lug/2009
5     * Author: Nicola Mori
6     */
7    
8     /*! @file RigFillAction.cpp The RigFillAction class implementation file. */
9    
10     #include "RigFillAction.h"
11    
12 pam-fi 1.2 void RigFillAction::_InitHistos(vector<float> &bins) {
13 pam-fi 1.1
14 pam-fi 1.2 _bins = bins;
15 pam-fi 1.1
16     // Initializing histograms
17     _rootHisto.SetName("rfHisto");
18 pam-fi 1.5 _rootHisto.SetTitle(Form("R Vs Rc (thr.: %.2f)", _thresholdCoeff));
19     _rootHisto.GetXaxis()->SetTitle("Rc (GV)");
20     _rootHisto.GetYaxis()->SetTitle("R (GV)");
21 pam-fi 1.1
22     Double_t *auxArray = new Double_t[_bins.size()];
23    
24     for (unsigned int i = 1; i < _bins.size(); i++) {
25     auxArray[i] = _bins[i];
26     }
27    
28     _rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray);
29     delete[] auxArray;
30    
31 pam-fi 1.2 _zeroCutoffBins.resize(_bins.size() - 1, 0);
32 pam-fi 1.1 _textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0);
33 pam-fi 1.4 _totalTextHisto.resize(_bins.size() - 1, 0);
34 pam-fi 1.1 }
35    
36 pam-fi 1.2 RigFillAction::RigFillAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) :
37     CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0),
38 pam-fi 1.4 _zeroCutoffBins(0), _totalTextHisto(0), _thresholdCoeff(thresholdCoeff) {
39 pam-fi 1.2
40     _InitHistos(bins);
41    
42     }
43    
44     RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) :
45     CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0),
46 pam-fi 1.4 _zeroCutoffBins(0), _totalTextHisto(0), _thresholdCoeff(thresholdCoeff) {
47 pam-fi 1.2
48     // Reading the bins from file
49     ifstream rigBinListFile;
50     rigBinListFile.open(rigBinsFile);
51    
52     TString auxString;
53     vector<float> bins(0);
54     while (!rigBinListFile.eof()) {
55     rigBinListFile >> auxString;
56     if (auxString != "") {
57     bins.push_back(auxString.Atof());
58     }
59     }
60     rigBinListFile.close();
61    
62     _InitHistos(bins);
63    
64     }
65    
66 pam-fi 1.1 void RigFillAction::OnGood(PamLevel2 *event) {
67    
68     float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();
69     float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();
70    
71 pam-fi 1.6 //_rootHisto.Fill(rigThreshold, rig); // X,Y in the ROOT histogram
72 pam-fi 1.1
73 pam-fi 1.4 // Event rigidity bin identification.
74 pam-fi 1.5
75 pam-fi 1.4 if (rig < _bins[0] || rig >= _bins[(int) _textHisto.GetNRows()]) {
76     return;
77     }
78 pam-fi 1.1
79     int i = 1;
80 pam-fi 1.4 while (rig >= _bins[i]) {
81 pam-fi 1.1 i++;
82     }
83     i--;
84    
85 pam-fi 1.4 // Threshold rigidity bin identification.
86 pam-fi 1.5
87 pam-fi 1.6 if (rigThreshold <= 0 || rigThreshold >= _bins[(int) _textHisto.GetNRows()]) {
88 pam-fi 1.5 return;
89     }
90    
91 pam-fi 1.6 if (0 < rigThreshold && rigThreshold < _bins[0])
92 pam-fi 1.2 _zeroCutoffBins[i]++;
93     else {
94     int j = 1;
95 pam-fi 1.4 while (rigThreshold >= _bins[j]) {
96 pam-fi 1.2 j++;
97     }
98     j--;
99    
100 pam-fi 1.4 _textHisto[i][j]++;
101     _totalTextHisto[i]++;
102 pam-fi 1.5
103 pam-fi 1.1 }
104     }
105    
106     void RigFillAction::Finalize() {
107    
108     // Write the text file
109 pam-fi 1.2 if (_outFileBase != "") {
110    
111 pam-fi 1.5 ofstream outTextFile((_outFileBase + "-" + GetName() + ".txt").Data(), ios_base::out);
112 pam-fi 1.2 for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) {
113     for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) {
114     outTextFile << setw(7) << _textHisto[i][j] << " ";
115     }
116     outTextFile << "\n";
117 pam-fi 1.1 }
118 pam-fi 1.2 outTextFile.close();
119 pam-fi 1.1
120 pam-fi 1.2 // Write the report file, where zero bins are recorded
121 pam-fi 1.5 outTextFile.open((_outFileBase + "-" + GetName() + "-InfBins.txt").Data(), ios_base::out);
122 pam-fi 1.2 for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++)
123 pam-fi 1.4 outTextFile << GetHistoThreshInfBin()[i] << "\n";
124 pam-fi 1.3 outTextFile.close();
125 pam-fi 1.2
126     // Write the ROOT file
127 pam-fi 1.6 /*TFile outRootFile((_outFileBase + "-" + GetName() + ".root"), "RECREATE");
128     outRootFile.cd();
129     _rootHisto.Write();
130     outRootFile.Close();
131     */
132 pam-fi 1.2 }
133 pam-fi 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.23