Bug in storage manager making possible to delete permanent event fixed
[u/mrichter/AliRoot.git] / MFT / FilterMuonGlobalTracks.C
CommitLineData
5287d4cb 1#include "AliLog.h"
2#include "TFile.h"
3#include "TTree.h"
4#include "TClonesArray.h"
5#include "AliMuonForwardTrack.h"
6
7TFile *inputFileWithoutBranson=0, *inputFileWithBranson=0, *outputFile=0;
8TTree *fInputTreeWithoutBranson=0, *fInputTreeWithBranson=0;
9TTree *fOutputTreeWithoutBranson=0, *fOutputTreeWithBranson=0;
10TClonesArray *fInputMuonForwardTracksWithoutBranson=0, *fInputMuonForwardTracksWithBranson=0;
11TClonesArray *fOutputMuonForwardTracksWithoutBranson=0, *fOutputMuonForwardTracksWithBranson=0;
12
13AliMuonForwardTrack* GetTrackWithoutBranson(Int_t event, Int_t trackMCId);
14
15//====================================================================================================================================================
16
17void FilterMuonGlobalTracks() {
18
19 // ---- reading file of tracks reconstructed without Branson correction
20
21 inputFileWithoutBranson = new TFile("MuonGlobalTracks.withoutBransonCorrection.root");
22 if (!inputFileWithoutBranson || !inputFileWithoutBranson->IsOpen()) {
23 printf("Error opening file MuonGlobalTracks.withoutBransonCorrection.root");
24 return;
25 }
26 fInputTreeWithoutBranson = (TTree*) inputFileWithoutBranson->Get("AliMuonForwardTracks");
27 if (!fInputTreeWithoutBranson) {
28 printf("Error reading input tree from MuonGlobalTracks.withoutBransonCorrection.root");
29 return;
30 }
31 fInputTreeWithoutBranson->SetName("AliInputMuonForwardTracksWithoutBranson");
32 fInputMuonForwardTracksWithoutBranson = new TClonesArray("AliMuonForwardTrack");
33 fInputTreeWithoutBranson->SetBranchAddress("tracks", &fInputMuonForwardTracksWithoutBranson);
34
35 // ---- reading file of tracks reconstructed with Branson correction
36
37 inputFileWithBranson = new TFile("MuonGlobalTracks.withBransonCorrection.root");
38 if (!inputFileWithBranson || !inputFileWithBranson->IsOpen()) {
39 printf("Error opening file MuonGlobalTracks.withBransonCorrection.root");
40 return;
41 }
42 fInputTreeWithBranson = (TTree*) inputFileWithBranson->Get("AliMuonForwardTracks");
43 if (!fInputTreeWithBranson) {
44 printf("Error reading input tree from MuonGlobalTracks.withBransonCorrection.root");
45 return;
46 }
47 fInputTreeWithBranson->SetName("AliInputMuonForwardTracksWithBranson");
48 fInputMuonForwardTracksWithBranson = new TClonesArray("AliMuonForwardTrack");
49 fInputTreeWithBranson->SetBranchAddress("tracks", &fInputMuonForwardTracksWithBranson);
50
51 // ---- preparing output file and trees
52
53 outputFile = new TFile("MuonGlobalTracks.root","recreate");
54 fOutputTreeWithoutBranson = new TTree("AliMuonForwardTracksWithoutBranson", "Tree of AliMuonForwardTracks");
55 fOutputTreeWithBranson = new TTree("AliMuonForwardTracksWithBranson", "Tree of AliMuonForwardTracks");
56 fOutputMuonForwardTracksWithoutBranson = new TClonesArray("AliMuonForwardTrack");
57 fOutputMuonForwardTracksWithBranson = new TClonesArray("AliMuonForwardTrack");
58 fOutputTreeWithoutBranson -> Branch("tracks", &fOutputMuonForwardTracksWithoutBranson);
59 fOutputTreeWithBranson -> Branch("tracks", &fOutputMuonForwardTracksWithBranson);
60
61 // ----
62
63 Int_t nEvents = fInputTreeWithBranson->GetEntries();
64
65 for (Int_t iEv=0; iEv<nEvents; iEv++) {
66
67 fInputTreeWithBranson -> GetEvent(iEv);
68
69 printf("reading event %d\n", iEv);
70
71 Int_t nTracksOfEvent = fInputMuonForwardTracksWithBranson->GetEntries();
72 for (Int_t iTr=0; iTr<nTracksOfEvent; iTr++) {
73 AliMuonForwardTrack *trackWithBranson = (AliMuonForwardTrack*) fInputMuonForwardTracksWithBranson->At(iTr);
74 AliMuonForwardTrack *trackWithoutBranson = GetTrackWithoutBranson(iEv, trackWithBranson->GetTrackMCId());
75 if (!trackWithoutBranson) {
76 printf("Event %d, track %d : track without Branson not available!\n", iEv, iTr);
77 continue;
78 }
79 new ((*fOutputMuonForwardTracksWithBranson)[fOutputMuonForwardTracksWithBranson->GetEntries()]) AliMuonForwardTrack(*trackWithBranson);
80 new ((*fOutputMuonForwardTracksWithoutBranson)[fOutputMuonForwardTracksWithoutBranson->GetEntries()]) AliMuonForwardTrack(*trackWithoutBranson);
81 }
82
83 fOutputTreeWithBranson -> Fill();
84 fOutputTreeWithoutBranson -> Fill();
85
86 fOutputMuonForwardTracksWithBranson -> Delete();
87 fOutputMuonForwardTracksWithoutBranson -> Delete();
88
89 fInputMuonForwardTracksWithBranson -> Delete();
90 fInputMuonForwardTracksWithoutBranson -> Delete();
91
92 }
93
94 outputFile -> cd();
95 fOutputTreeWithBranson -> Write();
96 fOutputTreeWithoutBranson -> Write();
97 outputFile -> Close();
98
99}
100
101//====================================================================================================================================================
102
103AliMuonForwardTrack* GetTrackWithoutBranson(Int_t event, Int_t trackMCId) {
104
105 fInputTreeWithoutBranson -> GetEvent(event);
106
107 Int_t nTracksOfEvent = fInputMuonForwardTracksWithoutBranson->GetEntries();
108 for (Int_t iTr=0; iTr<nTracksOfEvent; iTr++) {
109 AliMuonForwardTrack *trackWithoutBranson = (AliMuonForwardTrack*) fInputMuonForwardTracksWithoutBranson->At(iTr);
110 if (trackWithoutBranson->GetTrackMCId() == trackMCId) return trackWithoutBranson;
111 }
112
113 return NULL;
114
115}
116
117//====================================================================================================================================================