BmnRoot
Loading...
Searching...
No Matches
Tof400Identification.c
Go to the documentation of this file.
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7
8
9#include <stdio.h>
10#include <fstream>
11#include <istream>
12#include <iostream>
13#include <ctime>
14#include <vector>
15
16#include <TMath.h>
17#include "TChain.h"
18#include "TF1.h"
19#include "TH1.h"
20#include "TH2.h"
21#include "TCanvas.h"
22#include "TFile.h"
23#include "TList.h"
24#include "TDirectory.h"
25#include "TPad.h"
26#include "TClonesArray.h"
27#include "TVector3.h"
28
29void Tof400Identification(TString NameFileIn = "bmndst.root", Int_t nEvForRead = 0) {
30
31 TStopwatch timer;
32 timer.Start();
33 Int_t nBytes = 0;
34
35 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
36 bmnloadlibs(); // load BmnRoot libraries
37 //gStyle->SetOptStat(kFALSE);
38
39 TH1I *hBetta = new TH1I("hBetta", "hBetta", 400, -2., 2.);
40 hBetta->GetXaxis()->SetTitle("beta ");
41 hBetta->SetMarkerStyle(8);
42 hBetta->SetMarkerColor(2);
43
44 TH2I *hMomentumBetta = new TH2I("hMomentumBeta", "hMomentumBeta", 1000, -10., 10., 400, -2., 2.);
45 hMomentumBetta->GetXaxis()->SetTitle("momentum, GeV/c ");
46 hMomentumBetta->GetYaxis()->SetTitle("beta ");
47
48 //--------Data Analysis-----------------------------------------------------------------
49
50 TChain *eveTree = new TChain("cbmsim");
51 TString inName = Form("$VMCWORKDIR/macro/run/%s", NameFileIn.Data());
52 //inName = file;
53 cout << "Open file " << inName << endl << endl;
54 eveTree->Add(inName);
55
56 TClonesArray *Tof400Hits;
57 eveTree->SetBranchAddress("BmnTof400Hit", &Tof400Hits);
58
59 TClonesArray *BmnGlobTr;
60 eveTree->SetBranchAddress("BmnGlobalTrack", &BmnGlobTr);
61
62 Long64_t nEvents = eveTree->GetEntries();
63 if (nEvForRead == 0 || nEvForRead > nEvents) nEvForRead = nEvents;
64 cout << "Will be read " << nEvForRead << " events from " << nEvents << endl;
65
66 for (Int_t iEv = 0; iEv < nEvForRead; iEv++) {
67
68 if (iEv % 50000 == 0)
69 cout << "EVENT: " << iEv << endl;
70 nBytes = eveTree->GetEntry(iEv);
71
72 for (Int_t iGlobTrack = 0; iGlobTrack < BmnGlobTr->GetEntriesFast(); iGlobTrack++) {
73 BmnGlobalTrack* Track = (BmnGlobalTrack*) BmnGlobTr->At(iGlobTrack);
74 FairTrackParam parLast(*(Track->GetParamLast()));
75 FairTrackParam parFirst(*(Track->GetParamFirst()));
76 Int_t IndexTof1Hit = Track->GetTof1HitIndex();
77 if (IndexTof1Hit == -1) continue;
78 //cout << "Event#" << iEv << endl;
79 BmnTofHit* hitTof400 = (BmnTofHit*) Tof400Hits->At(IndexTof1Hit);
80 Double_t Velocity = hitTof400->GetLength() / hitTof400->GetTimeStamp() / 10.; // * 10^8 m/s
81 Double_t Betta = Velocity / 2.99792458; //
82 hBetta->Fill(Betta);
83 Double_t Momentum = 1. / Track->GetParamLast()->GetQp();
84 hMomentumBetta ->Fill(Momentum, Betta);
85
86 } // end for (Int_t iGlobTrack = 0; iGlobTrack < BmnGlobalTrack->GetEntriesFast(); iGlobTrack++)
87 }// end for (Int_t iEv = 0; iEv < nEvForRead; iEv++)
88
89 timer.Stop();
90 cout << "Readed " << nEvForRead << " events" << endl;
91 cout << "Time = " << timer.RealTime() << " s" << endl;
92 cout << "Time/Event = " << timer.RealTime() / (Double_t) nEvForRead * 1000. << " ms/Event" << endl;
93 cout << "TimeCPU = " << timer.CpuTime() << " s" << endl;
94 cout << "TimeCPU/Event = " << timer.CpuTime() / (Double_t) nEvForRead * 1000. << " ms/Event" << endl;
95
96 timer.Reset();
97 timer.Start();
98 TString outName = NameFileIn;
99 Int_t Point = outName.First('.');
100 outName.Replace(Point, 15, "_Identification.root");
101 outName = Form("/home/storage/analysis/%s", outName.Data());
102 cout << "Save data to " << outName.Data() << endl;
103 TFile *fileout = new TFile(outName.Data(), "RECREATE");
104
105 hBetta->Write();
106 hMomentumBetta->Write();
107
108 fileout->Close();
109
110 timer.Stop();
111
112 cout << "Time for write root = " << timer.RealTime() << " s" << endl;
113
114}
Int_t GetTof1HitIndex() const
Double_t GetLength()
Definition BmnHit.h:89
FairTrackParam * GetParamFirst()
Definition BmnTrack.h:72
FairTrackParam * GetParamLast()
Definition BmnTrack.h:76
void Tof400Identification(TString NameFileIn="bmndst.root", Int_t nEvForRead=0)