showData.C

макрос, переводящий данные в формат, готовый к отрисовке - Ivan Muzalevsky, 03/21/2018 02:47 PM

Download (4.27 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",20);
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

    
11
        ERMCTrack *n1 = new ERMCTrack();
12
        ERMCTrack *n2 = new ERMCTrack();
13
        ERMCTrack *h3 = new ERMCTrack();
14
        ERMCTrack *h5 = new ERMCTrack();
15
        ERMCTrack *he3 = new ERMCTrack();
16
        ERMCTrack *he6 = new ERMCTrack();
17
        ERMCTrack *h2 = new ERMCTrack();
18

    
19
        tree->Bronch("n1.", "ERMCTrack", &n1);
20
        tree->Bronch("n2.", "ERMCTrack", &n2);
21
        tree->Bronch("h3.", "ERMCTrack", &h3);
22
        tree->Bronch("h5.", "ERMCTrack", &h5);
23
        tree->Bronch("he3.", "ERMCTrack", &he3);
24
        tree->Bronch("he6.", "ERMCTrack", &he6);
25
        tree->Bronch("h2.", "ERMCTrack", &h2);
26

    
27

    
28
        Int_t pdg,mID,tID,h3ID,h5ID;
29
        Int_t nN,flag,nh3,nEvents;
30
        nEvents = 0;
31
        for(Int_t i=0; i<t->GetEntries();i++){
32
        // for(Int_t i=0; i<10;i++){
33
                // cout << " next event " << endl; 
34
                nN = 0; // number of neutrons
35
                nh3 = 0;
36
                flag = 0; // flag ( if 1 fill the tree, 0  - not)
37
                t->GetEntry(i);
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
                            // track->Get4Momentum(*h5);
47
                            h5 = track;
48
                            h5ID = mID;
49
                            // cout << "found ";
50
                    }
51

    
52
                    // if( pdg == 1000010030 ) {h3ID = mID; nh3++;} // if i want to choose the right neutrons i need to know their motherID
53
            } 
54
            if(flag!=1) continue;
55

    
56
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
57
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
58
                    pdg = track->GetPdgCode();
59
                    mID = track->GetMotherId();
60
                    if(pdg == 1000010030) { // if i want to choose the right neutrons i need to know their motherID
61
                            h3ID = mID; 
62
                            nh3++;
63
                            // track->Get4Momentum(*h3);
64
                            h3 = track;
65
                    } 
66
            } 
67
            if(nh3!=1) continue;  // i want to read events with 1 h3 only
68

    
69
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
70
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
71
                    pdg = track->GetPdgCode();
72
                    mID = track->GetMotherId();
73

    
74
                    if((pdg == 2112) && (mID == h3ID)) {
75
                            nN++;
76
                            // if(nN == 1) track->Get4Momentum(*n1);
77
                            // if(nN == 2) track->Get4Momentum(*n2);
78
                            if(nN == 1) n1 = track;
79
                            if(nN == 2) n2 = track;
80
                    }
81
                    if((pdg == 1000020030) && (mID == h5ID)) he3 = track;
82

    
83
                    if(pdg == 1000020060) he6 = track;
84
                    if(pdg == 1000010020) h2 = track;
85
                    // if(pdg == 1000020060) track->Get4Momentum(*he6);
86
                    // cout << track->GetPdgCode() << endl;
87
                }
88
                if(nN!=2) {cout << nN << " wtf "<< i << endl;}
89
                tree->Fill();
90
        } // t->GetEntries()
91

    
92
        // cout << nEvents;
93
        tree->Write();
94
        f1->Close();
95
        return;
96
}
97
        /*        t->GetEntry(1619);
98
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
99
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
100
                    pdg = track->GetPdgCode();
101
                    cout << pdg << endl;
102
            } 
103
                  cout << endl << "next event " << endl;
104
                t->GetEntry(2519);
105
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
106
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
107
                    pdg = track->GetPdgCode();
108
                    cout << pdg << endl;
109
            } 
110
            cout << endl << "next event " << endl;
111
                t->GetEntry(3950);
112
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
113
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
114
                    pdg = track->GetPdgCode();
115
                    cout << pdg << endl;
116
            } 
117
                  cout << endl << "next event " << endl;
118
                t->GetEntry(5847);
119
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
120
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
121
                    pdg = track->GetPdgCode();
122
                    cout << pdg << endl;
123
            } 
124
                  cout << endl << "next event " << endl;
125
                t->GetEntry(6900);
126
                for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++){
127
                    ERMCTrack* track = (ERMCTrack*)tracks->At(iTrack);
128
                    pdg = track->GetPdgCode();
129
                    cout << pdg << endl;
130
            } 
131
                  cout << endl << "next event " << endl;*/