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

Diff of /PamCut/CollectionActions/LiveTimeAction/LiveTimeAction.cpp

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

revision 1.1 by pam-fi, Fri Jul 17 08:22:47 2009 UTC revision 1.2 by pam-fi, Wed Aug 5 17:04:18 2009 UTC
# Line 9  Line 9 
9    
10  #include "LiveTimeAction.h"  #include "LiveTimeAction.h"
11    
12    void LiveTimeAction::_InitHistos(vector<float> &bins) {
13    
14      _bins = bins;
15    
16      // Initializing histograms
17      _textHisto.assign(_bins.size() - 1, 0);
18      _rootHisto.SetName("ltHisto");
19      _rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff));
20      _rootHisto.GetXaxis()->SetTitle("R");
21      _rootHisto.GetYaxis()->SetTitle("Events");
22    
23      Double_t *auxArray = new Double_t[_bins.size()];
24    
25      for (unsigned int i = 1; i < _bins.size(); i++) {
26        auxArray[i] = _bins[i];
27      }
28    
29      _rootHisto.SetBins(_bins.size() - 1, auxArray);
30    
31      delete[] auxArray;
32    }
33    
34    LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) :
35      CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff(
36          thresholdCoeff), _total(0.), _zeroBin(0.)
37    #ifdef DEBUGPAMCUT
38    , _outUp(0), _outDown(0)
39    #endif
40    {
41      _InitHistos(bins);
42    }
43    
44  LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) :  LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, TString rigBinsFile, float thresholdCoeff) :
45    CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff(    CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff(
46        thresholdCoeff), _total(0.), _zeroBin(0.)        thresholdCoeff), _total(0.), _zeroBin(0.)
# Line 22  LiveTimeAction::LiveTimeAction(const cha Line 54  LiveTimeAction::LiveTimeAction(const cha
54    rigBinListFile.open(rigBinsFile);    rigBinListFile.open(rigBinsFile);
55    
56    TString auxString;    TString auxString;
57      vector<float> bins(0);
58    while (!rigBinListFile.eof()) {    while (!rigBinListFile.eof()) {
59      rigBinListFile >> auxString;      rigBinListFile >> auxString;
60      if (auxString != "") {      if (auxString != "") {
# Line 30  LiveTimeAction::LiveTimeAction(const cha Line 63  LiveTimeAction::LiveTimeAction(const cha
63    }    }
64    rigBinListFile.close();    rigBinListFile.close();
65    
66    // Initializing histograms    _InitHistos(bins);
   _textHisto.assign(_bins.size() - 1, 0);  
   _rootHisto.SetName("ltHisto");  
   _rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff));  
   _rootHisto.GetXaxis()->SetTitle("R");  
   _rootHisto.GetYaxis()->SetTitle("Events");  
67    
   Double_t *auxArray = new Double_t[_bins.size()];  
   
   for (unsigned int i = 1; i < _bins.size(); i++) {  
     auxArray[i] = _bins[i];  
   }  
   
   _rootHisto.SetBins(_bins.size() - 1, auxArray);  
   
   delete[] auxArray;  
68  }  }
69    
70  void LiveTimeAction::OnGood(PamLevel2 *event) {  void LiveTimeAction::OnGood(PamLevel2 *event) {
# Line 84  void LiveTimeAction::OnGood(PamLevel2 *e Line 103  void LiveTimeAction::OnGood(PamLevel2 *e
103    
104  void LiveTimeAction::Finalize() {  void LiveTimeAction::Finalize() {
105    
106    // Write the text file    if (_outFileBase != "") {
107    ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);  
108    streamsize oldPrec = cout.precision();      // Write the text file
109    streamsize newPrec = 4;      ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);
110    outTextFile.precision(newPrec);      streamsize oldPrec = cout.precision();
111    outTextFile.setf(ios::fixed, ios::floatfield);      streamsize newPrec = 4;
112    for (unsigned int i = 0; i < _textHisto.size(); i++)      outTextFile.precision(newPrec);
113      outTextFile << _textHisto[i] << "\n";      outTextFile.setf(ios::fixed, ios::floatfield);
114    outTextFile.close();      for (unsigned int i = 0; i < _textHisto.size(); i++)
115    outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out);        outTextFile << _textHisto[i] << "\n";
116    outTextFile << "Zero bin: " << GetZeroBin() << "\n";      outTextFile.close();
117    outTextFile << "Total live time: " << GetTotalLT() << "\n";      outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out);
118    outTextFile.close();      outTextFile << "Zero bin: " << GetZeroBin() << "\n";
119    outTextFile.precision(oldPrec);      outTextFile << "Total live time: " << GetTotalLT() << "\n";
120    outTextFile << resetiosflags(ios::floatfield);      outTextFile.close();
121        outTextFile.precision(oldPrec);
122    // Write the ROOT file      outTextFile << resetiosflags(ios::floatfield);
123    TFile outRootFile((_outFileBase + ".root"), "RECREATE");  
124    outRootFile.cd();      // Write the ROOT file
125    _rootHisto.Write();      TFile outRootFile((_outFileBase + ".root"), "RECREATE");
126    outRootFile.Close();      outRootFile.cd();
127        _rootHisto.Write();
128        outRootFile.Close();
129    
130      }
131    
132  #ifdef DEBUGPAMCUT  #ifdef DEBUGPAMCUT
133    cout << "Debug informations from " << GetName() << ":\n";    cout << "Debug informations from " << GetName() << ":\n";

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

  ViewVC Help
Powered by ViewVC 1.1.23