/[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.2 by pam-fi, Wed Aug 5 17:04:18 2009 UTC revision 1.5 by pam-fi, Tue Oct 27 10:18:20 2009 UTC
# Line 17  void LiveTimeAction::_InitHistos(vector< Line 17  void LiveTimeAction::_InitHistos(vector<
17    _textHisto.assign(_bins.size() - 1, 0);    _textHisto.assign(_bins.size() - 1, 0);
18    _rootHisto.SetName("ltHisto");    _rootHisto.SetName("ltHisto");
19    _rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff));    _rootHisto.SetTitle(Form("Live time (thr.: %.2f)", _thresholdCoeff));
20    _rootHisto.GetXaxis()->SetTitle("R");    _rootHisto.GetXaxis()->SetTitle("R [GV]");
21    _rootHisto.GetYaxis()->SetTitle("Events");    _rootHisto.GetYaxis()->SetTitle("Events");
22    
23    Double_t *auxArray = new Double_t[_bins.size()];    Double_t *auxArray = new Double_t[_bins.size()];
# Line 33  void LiveTimeAction::_InitHistos(vector< Line 33  void LiveTimeAction::_InitHistos(vector<
33    
34  LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) :  LiveTimeAction::LiveTimeAction(const char *actionName, TString outFileBase, vector<float> &bins, float thresholdCoeff) :
35    CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff(    CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0), _thresholdCoeff(
36        thresholdCoeff), _total(0.), _zeroBin(0.)        thresholdCoeff), _totalNorm(0.), _infBin(0.), _nGoodHisto(0), _nGoodInfBin(0)
37  #ifdef DEBUGPAMCUT  #ifdef DEBUGPAMCUT
38  , _outUp(0), _outDown(0)  , _outUp(0), _outDown(0)
39  #endif  #endif
# Line 43  LiveTimeAction::LiveTimeAction(const cha Line 43  LiveTimeAction::LiveTimeAction(const cha
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), _totalNorm(0.), _infBin(0.), _nGoodHisto(0), _nGoodInfBin(0)
47  #ifdef DEBUGPAMCUT  #ifdef DEBUGPAMCUT
48  , _outUp(0), _outDown(0)  , _outUp(0), _outDown(0)
49  #endif  #endif
# Line 58  LiveTimeAction::LiveTimeAction(const cha Line 58  LiveTimeAction::LiveTimeAction(const cha
58    while (!rigBinListFile.eof()) {    while (!rigBinListFile.eof()) {
59      rigBinListFile >> auxString;      rigBinListFile >> auxString;
60      if (auxString != "") {      if (auxString != "") {
61        _bins.push_back(auxString.Atof());        bins.push_back(auxString.Atof());
62      }      }
63    }    }
64    rigBinListFile.close();    rigBinListFile.close();
# Line 69  LiveTimeAction::LiveTimeAction(const cha Line 69  LiveTimeAction::LiveTimeAction(const cha
69    
70  void LiveTimeAction::OnGood(PamLevel2 *event) {  void LiveTimeAction::OnGood(PamLevel2 *event) {
71    
72    float lt = 0.16 * (float) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds    double lt = 0.16 * (double) event->GetTrigLevel2()->dltime[0] / 1000.; // In seconds
73    _total += lt;    
74    //  cout << 0.16 * event->GetTrigLevel2()->dltime[0] / 1000. << endl;
75    //  cout << lt << endl;
76    
77    float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();    float cRig = _thresholdCoeff * event->GetOrbitalInfo()->GetCutoffSVL();
78    if (cRig >= _bins[0]) {    if (cRig >= _bins[0]) {
79      int i = 1;      int i = 1;
80      int binningSize = _bins.size();      int binningSize = _bins.size();
81      bool found = false;      bool found = false;
82      while (!found && i < binningSize) {      while (!found && i < binningSize) {
83        if (cRig < _bins[i])        if (cRig < _bins[i]) // less than bin[i-1] maximum edge
84          found = true;          found = true;
85        else        else
86          i++;          i++;
87      }      }
88      if (found) {      if (found) {
89        _textHisto[i - 1] += lt;        _totalNorm += lt; // use double for sums of many real numbers
90          _textHisto[i - 1] += lt; // use double for sums of many real numbers
91        _rootHisto.Fill(cRig, lt);        _rootHisto.Fill(cRig, lt);
92          _nGoodHisto++;
93      }      }
94    
95  #ifdef DEBUGPAMCUT  #ifdef DEBUGPAMCUT
# Line 93  void LiveTimeAction::OnGood(PamLevel2 *e Line 98  void LiveTimeAction::OnGood(PamLevel2 *e
98  #endif  #endif
99    }    }
100    
101    else {    else if (cRig > 0.) {
102      _zeroBin += lt;      _infBin += lt;
103        _nGoodInfBin++;
104  #ifdef DEBUGPAMCUT  #ifdef DEBUGPAMCUT
105      _outDown++;      _outDown++;
106  #endif  #endif
# Line 106  void LiveTimeAction::Finalize() { Line 112  void LiveTimeAction::Finalize() {
112    if (_outFileBase != "") {    if (_outFileBase != "") {
113    
114      // Write the text file      // Write the text file
115      ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);      ofstream outTextFile((_outFileBase + "-" + GetName() + ".txt").Data(), ios_base::out);
116      streamsize oldPrec = cout.precision();      streamsize oldPrec = cout.precision();
117      streamsize newPrec = 4;      streamsize newPrec = 4;
118      outTextFile.precision(newPrec);      outTextFile.precision(newPrec);
# Line 114  void LiveTimeAction::Finalize() { Line 120  void LiveTimeAction::Finalize() {
120      for (unsigned int i = 0; i < _textHisto.size(); i++)      for (unsigned int i = 0; i < _textHisto.size(); i++)
121        outTextFile << _textHisto[i] << "\n";        outTextFile << _textHisto[i] << "\n";
122      outTextFile.close();      outTextFile.close();
123      outTextFile.open((_outFileBase + "-report.txt").Data(), ios_base::out);      outTextFile.open((_outFileBase + "-" + GetName() + "-InfBin.txt").Data(), ios_base::out);
124      outTextFile << "Zero bin: " << GetZeroBin() << "\n";      outTextFile << GetLTInfBin() << endl;
     outTextFile << "Total live time: " << GetTotalLT() << "\n";  
125      outTextFile.close();      outTextFile.close();
126      outTextFile.precision(oldPrec);      outTextFile.precision(oldPrec);
127      outTextFile << resetiosflags(ios::floatfield);      outTextFile << resetiosflags(ios::floatfield);
128    
129      // Write the ROOT file      // Write the ROOT file
130      TFile outRootFile((_outFileBase + ".root"), "RECREATE");      TFile outRootFile((_outFileBase + "-" + GetName() + ".root"), "RECREATE");
131      outRootFile.cd();      outRootFile.cd();
132      _rootHisto.Write();      _rootHisto.Write();
133      outRootFile.Close();      outRootFile.Close();

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

  ViewVC Help
Powered by ViewVC 1.1.23