1 |
/* |
2 |
* MassVsRigHistoAction.cpp |
3 |
* |
4 |
* Created on: 28-marth-2010 |
5 |
* Author: Vitaly Malakhov |
6 |
*/ |
7 |
|
8 |
/*! @file MassVsRigHistoAction.cpp The MassVsRigHistoAction class implementation file. */ |
9 |
|
10 |
#include "MassVsRigHistoAction.h" |
11 |
|
12 |
MassVsRigHistoAction::MassVsRigHistoAction(const char *actionName, TString outFileBase, TString mode, |
13 |
bool outRoot, bool outText, TString title, Int_t Z, TString rigBinFile) : |
14 |
Histo2DAction<Int_t> (actionName, title, outFileBase, mode, outRoot, outText), _Z(Z), _rigBinFile(rigBinFile){ |
15 |
|
16 |
} |
17 |
|
18 |
void MassVsRigHistoAction::OnGood(PamLevel2 *event) { |
19 |
Float_t betaev = event->GetTrack(0)->GetToFTrack()->beta[12]; |
20 |
if(betaev>1) betaev = 2-betaev; |
21 |
Float_t rigev = 1./event->GetTrack(0)->GetTrkTrack()->GetDeflection(); |
22 |
Float_t Mass = _Z*rigev*sqrt(pow(betaev,-2)-1); |
23 |
Fill(rigev, Mass); |
24 |
} |
25 |
|
26 |
void MassVsRigHistoAction::Finalize() { |
27 |
|
28 |
Histo2DAction<Int_t>::Finalize(); |
29 |
|
30 |
ifstream binListFile; |
31 |
binListFile.open(_rigBinFile); |
32 |
|
33 |
TString auxString; |
34 |
_xRBins.resize(0); |
35 |
while (!binListFile.eof()) { |
36 |
binListFile >> auxString; |
37 |
if (auxString != "") { |
38 |
_xRBins.push_back(auxString.Atof()); |
39 |
} |
40 |
} |
41 |
binListFile.close(); |
42 |
|
43 |
TH1F tmphisto; |
44 |
tmphisto.SetBins(GetRootHisto()->GetNbinsY(),GetRootHisto()->GetXaxis()->GetXmin(),GetRootHisto()->GetXaxis()->GetXmax()); |
45 |
|
46 |
for (UInt_t i=0; i < _xRBins.size()-1 ;i++){ |
47 |
_fixedRigHisto.push_back(tmphisto); |
48 |
ostringstream ss1(ostringstream::out); |
49 |
ss1 << _xRBins[i]; |
50 |
ostringstream ss2(ostringstream::out); |
51 |
ss2 << _xRBins[i+1]; |
52 |
TString s1 = ss1.str(); |
53 |
TString s2 = ss2.str(); |
54 |
for(Int_t j = 0; j<s1.Sizeof()-1; j++) if(s1[j] == '.') s1[j] = 'p'; |
55 |
for(Int_t j = 0; j<s2.Sizeof()-1; j++) if(s2[j] == '.') s2[j] = 'p'; |
56 |
_fixedRigHisto[i].SetName((TString)GetName()+"_Rig"+s1+"_"+s2+"GV"); |
57 |
_fixedRigHisto[i].SetTitle((TString)GetName()+"_Rig"+s1+"_"+s2+"GV"); |
58 |
for(Int_t k = 0; k < GetRootHisto()->GetNbinsY(); k++){ |
59 |
Float_t sumbins = 0; |
60 |
for(Int_t j = 0; j < GetRootHisto()->GetNbinsX(); j++){ |
61 |
if(GetRootHisto()->GetXaxis()->GetBinUpEdge(j) > _xRBins[i] && GetRootHisto()->GetXaxis()->GetBinLowEdge(j) < _xRBins[i+1]) sumbins += GetRootHisto()->GetBinContent(j,k); |
62 |
} |
63 |
_fixedRigHisto[i].SetBinContent(k,sumbins); |
64 |
} |
65 |
} |
66 |
TFile outRootFile((Histo2DAction<Int_t>::_outFileBase + ".root"), "UPDATE"); |
67 |
outRootFile.cd(); |
68 |
for (UInt_t i=0; i < _xRBins.size()-1 ;i++) |
69 |
_fixedRigHisto[i].Write(); |
70 |
outRootFile.Close(); |
71 |
|
72 |
} |