]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/macros/trackMatching/SaveTrueMatchesSimple.C
Update tracking class and macros, and pid class to read correctly the ESDs
[u/mrichter/AliRoot.git] / EMCAL / macros / trackMatching / SaveTrueMatchesSimple.C
1 //
2 // This macro generates a simple TTree containing
3 // all true matches collected from one event.
4 //
5 // For each match it is stored:
6 //  - label ID of the track
7 //  - label ID of the EMCAL cluster
8 //  - momentum (3D) of the track
9 //  - vertex (3D) of the track
10 //
11 // All tracks which come from kinks are excluded 
12 // from this computation, and fake tracks are collected.
13 // If desired, it is possible to change these settings 
14 // operating on the Bool_t variables listed below.
15 //  
16
17 Bool_t rejectKinks = kTRUE;     // switch to TRUE to include kinks in computation
18 Bool_t rejectFakes = kFALSE;    // switch to TRUE to include fake tracks in computation
19
20 class match_t
21 {
22         public:
23         
24         Int_t    label;       // GEANT label of particle
25         Int_t    indexT;      // index of track in ESD collection
26         Int_t    indexC;      // index of cluster in ESD collection
27         Double_t p[3];        // track momentum
28         Double_t v[3];        // track vertex
29 };
30
31 //
32 // Read AliESDs.root file and saves all true pairs of trak-cluster.
33 //
34 void SaveTrueMatchesSimple(const char *outFileName="true-matches.root")
35 {
36         //
37         // open ESD file, retrieve tree and link to branch cursor
38         //
39         TFile *srcFile = TFile::Open("AliESDs.root");
40         if (!srcFile) return;
41         TTree *srcTree = (TTree*)srcFile->Get("esdTree");
42         if (!srcTree) return;
43         
44         AliESDEvent* esd = new AliESDEvent();
45         esd->ReadFromTree(srcTree);     
46         Long64_t nEvents = srcTree->GetEntries();
47         
48         //
49         // Open output file and create output tree
50         //
51         TFile *outFile = new TFile(outFileName, "RECREATE");
52         match_t match;
53
54         //
55         // Loop on events and store true matches
56         //
57         Bool_t isKink;
58         Int_t label, count, nTracks, firstCluster, lastCluster;
59         for (Long64_t iev = 0; iev < nEvents; iev++) {
60
61                 srcTree->GetEntry(iev);
62                 cout << "Event " << iev + 1 << " of " << nEvents << ": " << endl;
63                 
64                 nTracks = esd->GetNumberOfTracks();
65                 firstCluster = 0;
66                 lastCluster  = esd->GetNumberOfCaloClusters();
67                 cout << "Tracks found      : " << nTracks << endl;
68                 cout << "EMC clusters found: " << lastCluster - firstCluster << endl;
69                 
70                 // create new matches tree
71                 TTree *outTree = new TTree(Form("tm_%d", iev), Form("True matches from event %d", iev));
72                 outTree->Branch("matches", &match, "label/I:indexT/I:indexC/I:p[3]/D:v[3]/D");
73                 
74                 // external loop on tracks
75                 for (Int_t it = 0; it < nTracks; it++) {
76                         AliESDtrack *esdTrack = esd->GetTrack(it);
77                         // start check to reject kinks
78                         if (rejectKinks) {
79                                 isKink = kFALSE;
80                                 for (Int_t i = 0; i < 3; i++) {
81                                         if (esdTrack->GetKinkIndex(i) > 0) isKink = kTRUE;
82                                 }
83                                 if (isKink) continue;
84                         }
85                         // get track GEANT label (to be checked for match)
86                         label = esdTrack->GetLabel();
87                         if (rejectFakes) {
88                                 if (label < 0) continue;
89                         }
90                         else {
91                                 label = TMath::Abs(label);
92                         }
93                         // store track data into candidate match variable
94                         // anyway, it will be stored in the tree only
95                         // if it matches a cluster
96                         match.indexT = it;
97                         esdTrack->GetPxPyPz(match.p);
98                         esdTrack->GetXYZ(match.v);
99                         // internal loop on clusters
100                         // a counter counts how many true matches are
101                         // generated for the same track
102                         count = 0;
103                         for (Int_t ic = firstCluster; ic < lastCluster; ic++) {
104                                 AliESDCaloCluster *cl = esd->GetCaloCluster(ic);
105                                 if (!cl->IsEMCAL()) continue;
106                                 if (cl->GetLabel() != label) continue;
107                                 // if the method reaches this point, we
108                                 // have found a match to be stored
109                                 match.label = label;
110                                 match.indexC = ic;
111                                 outTree->Fill();
112                                 count++;
113                         }
114                         // alert for multiple matches
115                         if (count > 0) {
116                                 cout << "Found " << count << " clusters which match track " << it << " in ESD";
117                                 if (count > 1) cout << " --> MULTIPLE MATCH";
118                                 cout << endl;
119                         }
120                 } // end loop on tracks
121                 
122                 outFile->cd();
123                 outTree->Write();
124                 delete outTree;
125         }
126         
127         outFile->Close();
128 }