-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_DTR.C
51 lines (45 loc) · 1.37 KB
/
calculate_DTR.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
void calculate_DTR(const TString inputFileName)
{
//Input setup
TFile* inputFile = TFile::Open(inputFileName);
if(not inputFile)
{
std::cerr << "ERROR: input file not found! Aborting..." << std::endl;
gSystem->Exit(EXIT_FAILURE);
}
TTree* inputTree = dynamic_cast<TTree*>(inputFile->Get("Tree"));
if(not inputTree)
{
std::cerr << "ERROR: input tree not found! Aborting..." << std::endl;
gSystem->Exit(EXIT_FAILURE);
}
Double_t DT_True{0.}, DT_Meas{0.};
inputTree->SetBranchAddress("B_DT_True", &DT_True);
inputTree->SetBranchAddress("B_DT_Measured",&DT_Meas);
//Output setup
TString outputFileName{inputFileName};
outputFileName.ReplaceAll(".root","-withDTR.root");
TFile* outputFile = TFile::Open(outputFileName,"CREATE");
if(not outputFile)
{
std::cerr<< "ERROR: output file name already exists! Aborting..." << std::endl;
gSystem->Exit(EXIT_FAILURE);
}
TTree* outputTree = inputTree->CloneTree(0);
Double_t DTR{-999.};
outputTree->Branch("DTR",&DTR,"DTR/D");
//Event loop
const ULong64_t nEntries = inputTree->GetEntries();
for(ULong64_t iEvt{0}; iEvt < nEntries; ++iEvt)
{
if(iEvt % 1'000 == 0){std::cout << "Processed event: " << iEvt << "/" << nEntries << std::endl;}
inputTree->GetEntry(iEvt);
DTR = DT_True - DT_Meas;
outputTree->Fill();
}
outputTree->Write();
outputFile->Write();
outputFile->Close();
inputFile ->Close();
return;
}