/[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.4 by pam-fi, Wed Aug 26 16:34:15 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) {  
   
   // Reading the bins from file  
   ifstream rigBinListFile;  
   rigBinListFile.open(rigBinsFile);  
13    
14    TString auxString;    _bins = bins;
   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      _totalTextHisto.resize(_bins.size() - 1, 0);
34    }
35    
36    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          _zeroCutoffBins(0), _totalTextHisto(0), _thresholdCoeff(thresholdCoeff) {
39    
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          _zeroCutoffBins(0), _totalTextHisto(0), _thresholdCoeff(thresholdCoeff) {
47    
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  void RigFillAction::OnGood(PamLevel2 *event) {  void RigFillAction::OnGood(PamLevel2 *event) {
# Line 49  void RigFillAction::OnGood(PamLevel2 *ev Line 68  void RigFillAction::OnGood(PamLevel2 *ev
68    float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();    float rigThreshold = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();
69    float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();    float rig = event->GetTrack(0)->GetTrkTrack()->GetRigidity();
70    
71    _rootHisto.Fill(rigThreshold, rig);    _rootHisto.Fill(rigThreshold, rig); // X,Y in the ROOT histogram
72    
73    //Bin identification: value must be less than (<) bin maximum    // Event rigidity bin identification.
74      
75    //  cout << rig << endl;
76      if (rig < _bins[0] || rig >= _bins[(int) _textHisto.GetNRows()]) {
77    //    cout << "found!" << endl;
78        return;
79      }
80    
81    int i = 1;    int i = 1;
82    while (rig >= _bins[i] && i < (int)_textHisto.GetNRows()) {    while (rig >= _bins[i]) {
83      i++;      i++;
84    }    }
85    i--;    i--;
86    
87    int j = 1;    // Threshold rigidity bin identification.
88    while (rigThreshold >= _bins[j] && j < (int)_textHisto.GetNCols()) {    
89      j++;    if (rigThreshold < 0 || rigThreshold >= _bins[(int) _textHisto.GetNRows()]) return;
90    }    
91    j--;    if (0 <= rigThreshold && rigThreshold < _bins[0])
92        _zeroCutoffBins[i]++;
93      else {
94        int j = 1;
95        while (rigThreshold >= _bins[j]) {
96          j++;
97        }
98        j--;
99    
   if (i < (int)_textHisto.GetNRows() && j < (int)_textHisto.GetNCols())  
100      _textHisto[i][j]++;      _textHisto[i][j]++;
101        _totalTextHisto[i]++;
102        
103      }
104  }  }
105    
106  void RigFillAction::Finalize() {  void RigFillAction::Finalize() {
107    
108    // Write the text file    // Write the text file
109    ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);    if (_outFileBase != "") {
110    for (unsigned int i = 0; i < _textHisto.GetNRows(); i++) {  
111      for (unsigned int j = 0; j < _textHisto.GetNCols(); j++) {      ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);
112        outTextFile << setw(7) << _textHisto[i][j] << "  ";      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      }      }
118      outTextFile << "\n";      outTextFile.close();
   }  
   outTextFile.close();  
119    
120    // Write the ROOT file      // Write the report file, where zero bins are recorded
121    TFile outRootFile((_outFileBase + ".root"), "RECREATE");      outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out);
122    outRootFile.cd();      outTextFile << "Zero bins for cutoff rigidity: \n";
123    _rootHisto.Write();      for (unsigned int i = 0; i < _zeroCutoffBins.size(); i++)
124    outRootFile.Close();        outTextFile << GetHistoThreshInfBin()[i] << "\n";
125        outTextFile.close();
126    
127        // Write the ROOT file
128        TFile outRootFile((_outFileBase + ".root"), "RECREATE");
129        outRootFile.cd();
130        _rootHisto.Write();
131        outRootFile.Close();
132    
133      }
134  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23