-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMCinfo.cpp
122 lines (110 loc) · 3.29 KB
/
getMCinfo.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/****************************************************************************************
* DANSS data analysis - extract positron info from IBD simulation *
****************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "Riostream.h"
#include "TROOT.h"
#include "TMath.h"
#include "TFile.h"
#include "TChain.h"
#include "TNetFile.h"
#include "TRandom.h"
#include "TTree.h"
#include "TBranch.h"
#include "TCanvas.h"
#include "TPostScript.h"
#include "TStyle.h"
#include "TClonesArray.h"
#include "TStopwatch.h"
#include "TTreeCacheUnzip.h"
#include "TRandom.h"
#include "TDirectory.h"
#include "TProcessID.h"
#include "TObject.h"
#include "TClonesArray.h"
#include "TRefArray.h"
#include "TRef.h"
#include "TKey.h"
#include "TGraph.h"
#include "TF1.h"
#include "TH1.h"
#include "TH2.h"
#include "evtbuilder.h"
int main(int argc, char **argv)
{
struct MCEventStruct MCEvent;
struct MCParticleStruct MCParticle;
struct DanssFromMC FromMC;
TFile *PairFile;
TFile *MCFile;
TFile *OutFile;
TTree *PairTree;
TTree *MCTree;
TTree *OutTree;
long long i, j, N, K;
long long j0;
if (argc < 4) {
printf("Usage: %s pair_file.root MC_file.root output_file.root\n", argv[0]);
return 10;
}
PairFile = new TFile(argv[1]);
MCFile = new TFile(argv[2]);
OutFile = new TFile(argv[3], "RECREATE");
if (!PairFile->IsOpen() || !MCFile->IsOpen() || !OutFile->IsOpen()) return 20;
PairTree = (TTree *) PairFile->Get("DanssPair");
MCTree = (TTree *) MCFile->Get("DANSSParticle");
if (!PairTree || !MCTree) return 30;
PairTree->SetBranchAddress("MCEvent", &MCEvent);
MCTree->SetBranchAddress("ParticleData", &MCParticle);
N = PairTree->GetEntries();
K = MCTree->GetEntries();
if (!N || !K) return 40;
OutFile->cd();
OutTree = new TTree("FromMC", "FromMC");
OutTree->Branch("FromMC", &FromMC, "MCPositronEnergy/F:MCPositronX[3]:MCNeutronEnergy");
for (i=0, j=0; i<N; i++) {
PairTree->GetEntry(i);
j0 = j;
for (;j<K-1; j++) {
MCTree->GetEntry(j);
if (MCEvent.EventID == MCParticle.EventID && ((int)MCParticle.ID) == 1) break; // search for positron
}
if (j == K-1) {
printf("Very strange EventID = %f positron not found in MC @ %Ld\n", MCEvent.EventID, j0);
// we need to do something nevertheless !
FromMC.MCPositronEnergy = 0;
FromMC.MCPositronX[0] = 0;
FromMC.MCPositronX[1] = 0;
FromMC.MCPositronX[2] = 0;
FromMC.MCNeutronEnergy = 0;
OutTree->Fill();
j = j0;
continue;
}
FromMC.MCPositronEnergy = MCParticle.ParticleEnergy;
FromMC.MCPositronX[0] = 48.0 - MCParticle.X / 10000.0; // um to cm
FromMC.MCPositronX[1] = 48.0 - MCParticle.Y / 10000.0; // um to cm
FromMC.MCPositronX[2] = 49.5 + MCParticle.Z / 10000.0; // um to cm
j++;
MCTree->GetEntry(j);
if (MCEvent.EventID != MCParticle.EventID || MCParticle.ID != 2) { // neutron should be here !
printf("Very strange EventID = %f neutron not found in MC @ %Ld\n", MCEvent.EventID, j0);
FromMC.MCPositronEnergy = 0;
FromMC.MCPositronX[0] = 0;
FromMC.MCPositronX[1] = 0;
FromMC.MCPositronX[2] = 0;
FromMC.MCNeutronEnergy = 0;
OutTree->Fill();
j = j0;
continue;
}
FromMC.MCNeutronEnergy = MCParticle.ParticleEnergy;
OutTree->Fill();
}
OutTree->Write();
PairFile->Close();
MCFile->Close();
OutFile->Close();
return 0;
}