showData.C

reading full.root - Ivan Muzalevsky, 02/12/2018 04:04 PM

Download (3.66 KB)

 
1
void showData(){
2

    
3
        TFile* f = new TFile("/home/muzalevsky/expertroot/macro/muzalevsky/full.root");
4
        TTree* t = (TTree*) f->Get("er");
5
        TClonesArray* tracks = new TClonesArray("ERMCTrack",13);
6
        t->SetBranchAddress("MCTrack", &tracks);
7

    
8
        TFile *f1 = new TFile("/home/muzalevsky/expertroot/macro/muzalevsky/kin.root","RECREATE");
9
        TTree *tree = new TTree("tree","kin");
10
        TLorentzVector *n1 = new TLorentzVector();
11
        TLorentzVector *n2 = new TLorentzVector();
12
        TLorentzVector *h5 = new TLorentzVector();
13

    
14
        tree->Branch("n1.", &n1); 
15
        tree->Branch("n2.", &n2); 
16
        tree->Branch("h5.", &h5); 
17

    
18
        Int_t pdg,mID,tID,h3ID;
19
        Int_t nN,flag,nh3,nEvents;
20
        nEvents = 0;
21
        for(Int_t i=0; i<t->GetEntries();i++){
22
        // for(Int_t i=0; i<10;i++){
23
                // cout << " next event " << endl; 
24
                nN = 0; // number of neutrons
25
                nh3 = 0;
26
                flag = 0; // flag ( if 1 fill the tree, 0  - not)
27
                t->GetEntry(i);
28

    
29

    
30

    
31
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
32
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
33
                    pdg = track->GetPdgCode();
34
                    mID = track->GetMotherId();
35
                    // cout << pdg << endl;
36
            } 
37

    
38

    
39
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
40
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
41
                    pdg = track->GetPdgCode();
42
                    mID = track->GetMotherId();
43
                    if( pdg == 1000010050 ) {
44
                            flag = 1; // if there is an H5 in steck this event is interesting
45
                            nEvents ++ ;
46
                            // cout << "found ";
47
                    }        
48
                    // if( pdg == 1000010030 ) {h3ID = mID; nh3++;} // if i want to choose the right neutrons i need to know their motherID
49
            } 
50

    
51
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
52
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
53
                    pdg = track->GetPdgCode();
54
                    mID = track->GetMotherId();
55
                    if( (pdg == 1000010030) && (flag == 1) ) {h3ID = mID; nh3++;} // if i want to choose the right neutrons i need to know their motherID
56
            } 
57

    
58

    
59
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
60
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
61
                    pdg = track->GetPdgCode();
62
                    mID = track->GetMotherId();
63

    
64
                    if( (pdg == 2112) && (mID == h3ID) && (flag == 1) ) {
65
                            // track->Get4Momentum(n1);
66
                            nN++;
67
                    } 
68
                    // cout << track->GetPdgCode() << endl;
69
                }
70
                // if((flag == 1) && (nN!=2)) {cout << nh3 << " wtf "<< i << endl;}
71
        }
72

    
73

    
74
        /*        t->GetEntry(1619);
75
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
76
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
77
                    pdg = track->GetPdgCode();
78
                    cout << pdg << endl;
79
            } 
80
                  cout << endl << "next event " << endl;
81
                t->GetEntry(2519);
82
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
83
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
84
                    pdg = track->GetPdgCode();
85
                    cout << pdg << endl;
86
            } 
87
            cout << endl << "next event " << endl;
88
                t->GetEntry(3950);
89
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
90
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
91
                    pdg = track->GetPdgCode();
92
                    cout << pdg << endl;
93
            } 
94
                  cout << endl << "next event " << endl;
95
                t->GetEntry(5847);
96
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
97
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
98
                    pdg = track->GetPdgCode();
99
                    cout << pdg << endl;
100
            } 
101
                  cout << endl << "next event " << endl;
102
                t->GetEntry(6900);
103
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
104
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
105
                    pdg = track->GetPdgCode();
106
                    cout << pdg << endl;
107
            } 
108
                  cout << endl << "next event " << endl;*/
109

    
110

    
111

    
112
        cout << nEvents;
113
        tree->Write();
114
        f1->Close();
115
        return;
116
}