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

Diff of /PamCut/CollectionActions/RigFillAction/RigFillAction.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by pam-fi, Fri Jul 17 08:22:48 2009 UTC revision 1.3 by pam-fi, Wed Aug 5 17:43:36 2009 UTC
# Line 9  Line 9 
9    
10  #include "RigFillAction.h"  #include "RigFillAction.h"
11    
12  RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) :  void RigFillAction::_InitHistos(vector<float> &bins) {
   CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0),  
       _thresholdCoeff(thresholdCoeff) {  
13    
14    // Reading the bins from file    _bins = bins;
   ifstream rigBinListFile;  
   rigBinListFile.open(rigBinsFile);  
   
   TString auxString;  
   while (!rigBinListFile.eof()) {  
     rigBinListFile >> auxString;  
     if (auxString != "") {  
       _bins.push_back(auxString.Atof());  
     }  
   }  
   rigBinListFile.close();  
15    
16    // Initializing histograms    // Initializing histograms
17    _rootHisto.SetName("rfHisto");    _rootHisto.SetName("rfHisto");
# Line 41  RigFillAction::RigFillAction(const char Line 28  RigFillAction::RigFillAction(const char
28    _rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray);    _rootHisto.SetBins(_bins.size() - 1, auxArray, _bins.size() - 1, auxArray);
29    delete[] auxArray;    delete[] auxArray;
30    
31      _zeroCutoffBins.resize(_bins.size() - 1, 0);
32    _textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0);    _textHisto.Resize(_bins.size() - 1, _bins.size() - 1, 0);
33  }  }
34    
35    RigFillAction::RigFillAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) :
36      CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0),
37          _zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) {
38    
39      _InitHistos(bins);
40    
41    }
42    
43    RigFillAction::RigFillAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) :
44      CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0, 0, 0),
45          _zeroCutoffBins(0), _thresholdCoeff(thresholdCoeff) {
46    
47      // Reading the bins from file
48      ifstream rigBinListFile;
49      rigBinListFile.open(rigBinsFile);
50    
51      TString auxString;
52      vector<float> bins(0);
53      while (!rigBinListFile.eof()) {
54        rigBinListFile >> auxString;
55        if (auxString != "") {
56          bins.push_back(auxString.Atof());
57        }
58      }
59      rigBinListFile.close();
60    
61      _InitHistos(bins);
62    
63    }
64    
65  void RigFillAction::OnGood(PamLevel2 *event) {  void RigFillAction::OnGood(PamLevel2 *event) {
66    
67    float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();    float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();
# Line 54  void RigFillAction::OnGood(PamLevel2 *ev Line 72  void RigFillAction::OnGood(PamLevel2 *ev
72    //Bin identification: value must be less than (<) bin maximum    //Bin identification: value must be less than (<) bin maximum
73    
74    int i = 1;    int i = 1;
75    while (rig >= _bins[i] && i < (int)_textHisto.GetNRows()) {    while (rig >= _bins[i] && i < (int) _textHisto.GetNRows()) {
76      i++;      i++;
77    }    }
78    i--;    i--;
79    
80    int j = 1;    //Check the zero bins
81    while (rigThreshold >= _bins[j] && j < (int)_textHisto.GetNCols()) {    if (rigThreshold < _bins[0])
82      j++;      _zeroCutoffBins[i]++;
83    }    else {
84    j--;      int j = 1;
85        while (rigThreshold >= _bins[j] && j < (int) _textHisto.GetNCols()) {
86          j++;
87        }
88        j--;
89    
90    if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols())      if (i < (int) _textHisto.GetNRows() && j < (int) _textHisto.GetNCols())
91      _textHisto[i][j]++;        _textHisto[i][j]++;
92      }
93  }  }
94    
95  void RigFillAction::Finalize() {  void RigFillAction::Finalize() {
96    
97    // Write the text file    // Write the text file
98    ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);    if (_outFileBase != "") {
99    for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) {  
100      for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) {      ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);
101        outTextFile << setw(7) << _textHisto[i][j] << "  ";      for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) {
102          for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) {
103            outTextFile << setw(7) << _textHisto[i][j] << "  ";
104          }
105          outTextFile << "\n";
106      }      }
107      outTextFile << "\n";      outTextFile.close();
   }  
   outTextFile.close();  
108    
109    // Write the ROOT file      // Write the report file, where zero bins are recorded
110    TFile outRootFile((_outFileBase + ".root"), "RECREATE");      outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out);
111    outRootFile.cd();      outTextFile << "Zero bins for cutoff rigidity: \n";
112    _rootHisto.Write();      for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++)
113    outRootFile.Close();        outTextFile << GetCutoffZeroBins()[i] << "\n";
114        outTextFile.close();
115    
116        // Write the ROOT file
117        TFile outRootFile((_outFileBase + ".root"), "RECREATE");
118        outRootFile.cd();
119        _rootHisto.Write();
120        outRootFile.Close();
121    
122      }
123  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.23