BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
ToF400_Digit2Hit_Run7_SRC.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 * File: ToF400_Digit2Hit_Run7_SRC.C
9 * Author: mikhailr
10 *
11 * Created on May 24, 2018, 3:17 PM
12 */
13
14R__ADD_INCLUDE_PATH($VMCWORKDIR)
15#include "macro/run/bmnloadlibs.C"
16
17using namespace std;
18
20
23const Int_t NDet = 20;
24
25void ToF400_Digit2Hit_Run7_SRC(TString file = "/home/storage/digits/SRC/bmn_run3482_digi.root", Int_t nEvForRead = 0)
26{
27
28 bmnloadlibs(); // load BmnRoot libraries
29
30 // Init output tree and file
31 TTree* treeHitIn = new TTree("TOF400", "TOF400");
32 vector<double>* XTof = new vector<double>;
33 vector<double>* YTof = new vector<double>;
34 vector<double>* ZTof = new vector<double>;
35 vector<double>* TimeTof = new vector<double>;
36 UInt_t EventHeader_EventID;
37
38 treeHitIn->Branch("EventID", &EventHeader_EventID);
39 treeHitIn->Branch("XTof", &XTof);
40 treeHitIn->Branch("YTof", &YTof);
41 treeHitIn->Branch("ZTof", &ZTof);
42 treeHitIn->Branch("TimeTof", &TimeTof);
43
44 TString outName = file;
45 Int_t Point = outName.First('.');
46 outName.Replace(Point, 20, "_Tof400Hit.root");
47 TFile* FileHitOut = new TFile(outName.Data(), "RECREATE");
48
49 // Init BmnTOF1Detector
50 BmnTOF1Detector* Plane[NDet];
51 TString name;
52 for (Int_t i = 0; i < NDet; i++) {
53 name = Form("Plane%d", i);
54 Plane[i] = new BmnTOF1Detector(i, 2, NULL);
55 Plane[i]->SetCorrLR("TOF400_LRcorr_RUN7.dat");
56 Plane[i]->SetGeoFile("geofile_full_src.root");
57 } //*/
58
59 // Init tree with Digi
60 TChain* eveTree = new TChain("cbmsim");
61 TString inName = Form("%s", file.Data());
62 cout << endl << endl << "Open file " << inName << endl << endl;
63 Int_t AddReturn;
64 AddReturn = eveTree->Add(inName);
65 // cout << "AddReturn = " << AddReturn << endl;
66
67 TClonesArray* ToF400Digits = new TClonesArray("BmnTof1Digit");
68 eveTree->SetBranchAddress("TOF400", &ToF400Digits);
69
70 TClonesArray* T0Digits = new TClonesArray("BmnTrigDigit");
71 eveTree->SetBranchAddress("BC2", &T0Digits);
72
73 TClonesArray* EventHeaderDig = new TClonesArray("BmnEventHeader");
74 eveTree->SetBranchAddress("EventHeader", &EventHeaderDig);
75
76 Long64_t nEvents = eveTree->GetEntries();
77 if (nEvForRead == 0 || nEvForRead > nEvents)
78 nEvForRead = nEvents;
79 cout << "Will be read " << nEvForRead << " events from " << nEvents << endl;
80
81 // eveTree->Print();
82
83 // Read digi tree
84 for (Long64_t iEv = 0; iEv < nEvForRead; iEv++) {
85
86 ToF400Digits->Delete();
87 T0Digits->Delete();
88 EventHeaderDig->Delete();
89
90 if (iEv % 10000 == 0)
91 cout << "#EVENT: " << iEv << endl;
92 // cout << "Read event " << iEv << endl;
93 eveTree->GetEntry(iEv);
94
95 BmnEventHeader* digHeader = (BmnEventHeader*)EventHeaderDig->At(0);
96 EventHeader_EventID = digHeader->GetEventId();
97 if (iEv % 10000 == 0)
98 cout << "#EVENTHeader: " << EventHeader_EventID << endl;
99
100 // cout << "Check T0 digits " << endl;
101 Int_t CountMod0 = 0, CountMod1 = 0;
102 for (Int_t i = 0; i < T0Digits->GetEntriesFast(); i++) {
103 BmnTrigDigit* digT0 = (BmnTrigDigit*)T0Digits->At(i);
104 if (digT0->GetMod() == 0)
105 CountMod0++;
106 if (digT0->GetMod() == 1)
107 CountMod1++;
108 }
109
110 if (CountMod0 == 1 && CountMod1 >= 0) // check T0
111 {
112 // cout << "Looking for right T0 digit" << "; nDigits = " << T0Digits->GetEntriesFast() << endl;
113 BmnTrigDigit* digT0 = NULL;
114 for (Int_t i = 0; i < T0Digits->GetEntriesFast(); i++) {
115 digT0 = (BmnTrigDigit*)T0Digits->At(i);
116 if (digT0->GetMod() == 0)
117 break; // take first T0 digit. needed for ToF calculation.
118 }
119 if (digT0->GetAmp() >= 19.26 && digT0->GetAmp() <= 22.06) {
120
121 XTof->clear();
122 YTof->clear();
123 ZTof->clear();
124 TimeTof->clear();
125
126 //--------------------------- RPC --------------------------------------------------
127 for (Int_t i = 0; i < NDet; i++)
128 Plane[i]->Clear();
129
130 // cout << "Read TOF400 Digits" << "; NDigits = " << ToF400Digits->GetEntriesFast() <<
131 // endl;
132 for (Int_t iDig = 0; iDig < ToF400Digits->GetEntriesFast(); ++iDig) {
133 FlagHit = kFALSE;
134 BmnTof1Digit* digTof = (BmnTof1Digit*)ToF400Digits->At(iDig);
135 FlagHit = Plane[digTof->GetPlane()]->SetDigit(digTof);
136 }
137
138 // cout << "Fiil vectors" << endl;
139 TVector3 XYZ;
140 XYZ.SetXYZ(0., 0., 0.);
141 Double_t ToF = 0;
142 FlagHit = kFALSE;
143 for (Int_t i = 0; i < NDet; i++) { // loop over TOF400 Planes
144 Int_t nHits = Plane[i]->FindHits(digT0);
145 // cout << "nHits in Plane " << i << " = " << nHits << endl;
146 if (nHits > 0) {
147 for (Int_t s = 0; s < 47; s++) { // loop over Plane's strips
148 XYZ.SetXYZ(0., 0., 0.);
149 ToF = 0;
150 FlagHit = kFALSE;
151 FlagHit = Plane[i]->GetXYZTime(s, &XYZ, &ToF);
152 if (FlagHit == kTRUE) {
153 // cout << "Plane = " << i << "; Strip = " << s << "; X="
154 // << XYZ.X() << "; Y=" << XYZ.Y() << "; Z=" << XYZ.Z()
155 // << "; Time=" << ToF << endl;
156 XTof->push_back(XYZ.X());
157 YTof->push_back(XYZ.Y());
158 ZTof->push_back(XYZ.Z());
159 TimeTof->push_back(ToF);
160 }
161 } // end for (Int_t s = 0; s < 47; s++)
162 }
163 } // end for (Int_t i = 0; i < NDet; i++)
164
165 // cout << "Fill output tree" << endl;
166 treeHitIn->Fill();
167
168 } // end if (digT0->GetAmp() >= 17.3 && digT0->GetAmp() <= 19.2)
169 } // end if (CountMod0 == 1 && CountMod1 <= 0)
170 } // end for (Int_t iEv = 0; iEv < nEvForRead; iEv++)
171
172 cout << "End Data Analysis" << endl;
173 cout << "Save data in " << outName << endl;
174 FileHitOut->cd();
175 treeHitIn->Write();
176 FileHitOut->Close();
177}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
unsigned int UInt_t
constexpr Bool_t kFALSE
double Double_t
long long Long64_t
constexpr Bool_t kTRUE
#define R__ADD_INCLUDE_PATH(PATH)
char * Form(const char *fmt,...)
UInt_t GetEventId()
Get the event ID for this event.
Bool_t GetXYZTime(Int_t Str, TVector3 *XYZ, Double_t *ToF)
Bool_t SetGeoFile(TString NameFile)
Bool_t SetCorrLR(TString NameFile)
Short_t GetPlane() const
Double_t GetAmp() const
Short_t GetMod() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
void Delete(Option_t *option="") override
Bool_t cd() override
void Close(Option_t *option="") override
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Ssiz_t First(char c) const
const char * Data() const
virtual Int_t Fill()
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
Double_t Z() const
void SetXYZ(Double_t x, Double_t y, Double_t z)
Double_t Y() const
Double_t X() const
Double_t NHitBD
Double_t TimeBD
Bool_t FlagHit
Double_t AmpBD
const Int_t NDet
void ToF400_Digit2Hit_Run7_SRC(TString file="/home/storage/digits/SRC/bmn_run3482_digi.root", Int_t nEvForRead=0)
Definition json.hpp:4446