PamCut: CollectionActions/FluxHistoAction/FluxHistoAction.cpp Source File

- Main Page
- Classes
- Files

- File List
- File Members

# CollectionActions/FluxHistoAction/FluxHistoAction.cpp

Go to the documentation of this file.

    00001 /*
    00002  * FluxHistoAction.cpp
    00003  *
    00004  *  Created on: 20-mag-2009
    00005  *      Author: Nicola Mori
    00006  */
    00007
    00010 #include "FluxHistoAction.h"
    00011
    00012 FluxHistoAction::FluxHistoAction(const char *actionName, TString outFileBase, TString rigBinsFile) :
    00013   CollectionAction(actionName), _outFileBase(outFileBase), _bins(0), _rootHisto(), _textHisto(0)
    00014 #ifdef DEBUGPAMCUT
    00015       , _outUp(0), _outDown(0)
    00016 #endif
    00017 {
    00018
    00019   // Reading the bins from file
    00020   ifstream rigBinListFile;
    00021   rigBinListFile.open(rigBinsFile);
    00022
    00023   TString auxString;
    00024   while (!rigBinListFile.eof()) {
    00025     rigBinListFile >> auxString;
    00026     if (auxString != "") {
    00027       _bins.push_back(auxString.Atof());
    00028     }
    00029   }
    00030   rigBinListFile.close();
    00031
    00032   // Initializing histograms
    00033   _textHisto.assign(_bins.size() - 1, 0);
    00034   _rootHisto.SetName("rigHisto");
    00035   _rootHisto.SetTitle("Rigidity histogram");
    00036   _rootHisto.GetXaxis()->SetTitle("R");
    00037   _rootHisto.GetYaxis()->SetTitle("Events");
    00038
    00039   Double_t *auxArray = new Double_t[_bins.size()];
    00040
    00041   for (unsigned int i = 1; i < _bins.size(); i++) {
    00042     auxArray[i] = _bins[i];
    00043   }
    00044
    00045   _rootHisto.SetBins(_bins.size() - 1, auxArray);
    00046
    00047   delete[] auxArray;
    00048 }
    00049
    00050 void FluxHistoAction::OnGood(PamLevel2 *event) {
    00051
    00052   float rig = 1. / event->GetTrack(0)->GetTrkTrack()->GetDeflection();
    00053   if (rig >= _bins[0]) {
    00054     int i = 1;
    00055     int binningSize = _bins.size();
    00056     bool found = false;
    00057     while (!found && i < binningSize) {
    00058       if (rig < _bins[i])
    00059         found = true;
    00060       else
    00061         i++;
    00062     }
    00063     if (found) {
    00064       _textHisto[i - 1]++;
    00065       _rootHisto.Fill(rig);
    00066     }
    00067 #ifdef DEBUGPAMCUT
    00068     else
    00069       _outUp++;
    00070 #endif
    00071   }
    00072 #ifdef DEBUGPAMCUT
    00073   else
    00074     _outDown++;
    00075 #endif
    00076
    00077 }
    00078
    00079 void FluxHistoAction::Finalize() {
    00080
    00081   // Write the text file
    00082   ofstream outTextFile((_outFileBase + ".txt").Data(), ios_base::out);
    00083   streamsize oldPrec = cout.precision();
    00084   streamsize newPrec = 4;
    00085   outTextFile.precision(newPrec);
    00086   outTextFile.setf(ios::fixed, ios::floatfield);
    00087   for (unsigned int i = 0; i < _textHisto.size(); i++)
    00088     outTextFile << _bins[i] << "  " << _bins[i + 1] << "  " << _textHisto[i] << "\n";
    00089   outTextFile.close();
    00090   outTextFile.precision(oldPrec);
    00091   outTextFile << resetiosflags(ios::floatfield);
    00092
    00093   // Write the ROOT file
    00094   TFile outRootFile((_outFileBase + ".root"), "RECREATE");
    00095   outRootFile.cd();
    00096   _rootHisto.Write();
    00097   //outRootFile.Close();
    00098
    00099 #ifdef DEBUGPAMCUT
    00100   cout << "Debug informations from " << GetName() << ":\n";
    00101   cout << "   Events below the lowest rigidity: " << _outDown << "\n";
    00102   cout << "   Events above the highest rigidity: " << _outUp << endl;
    00103 #endif
    00104 }