]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/macros/trackMatching/SaveTrueMatchesSimple.C
The present commit corresponds to an important change in the way the
[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_compiled(const char *outFileName)
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         AliESD *esd = 0;
44         srcTree->SetBranchAddress("ESD", &esd);
45         Long64_t nEvents = srcTree->GetEntries();
46         
47         //
48         // Open output file and create output tree
49         //
50         TFile *outFile = new TFile(outFileName, "RECREATE");
51         match_t match;
52
53         //
54         // Loop on events and store true matches
55         //
56         Bool_t isKink;
57         Int_t label, count, nTracks, firstCluster, lastCluster;
58         for (Long64_t iev = 0; iev < nEvents; iev++) {
59
60                 srcTree->GetEntry(iev);
61                 cout << "Event " << iev + 1 << " of " << nEvents << ": " << endl;
62                 
63                 nTracks = esd->GetNumberOfTracks();
64                 firstCluster = esd->GetFirstEMCALCluster();
65                 lastCluster = esd->GetFirstEMCALCluster() + esd->GetNumberOfEMCALClusters();
66                 cout << "Tracks found      : " << nTracks << endl;
67                 cout << "EMC clusters found: " << lastCluster - firstCluster << endl;
68                 
69                 // create new matches tree
70                 TTree *outTree = new TTree(Form("tm_%d", iev), Form("True matches from event %d", iev));
71                 outTree->Branch("matches", &match, "label/I:indexT/I:indexC/I:p[3]/D:v[3]/D");
72                 
73                 // external loop on tracks
74                 for (Int_t it = 0; it < nTracks; it++) {
75                         AliESDtrack *esdTrack = esd->GetTrack(it);
76                         // start check to reject kinks
77                         if (rejectKinks) {
78                                 isKink = kFALSE;
79                                 for (Int_t i = 0; i < 3; i++) {
80                                         if (esdTrack->GetKinkIndex(i) > 0) isKink = kTRUE;
81                                 }
82                                 if (isKink) continue;
83                         }
84                         // get track GEANT label (to be checked for match)
85                         label = esdTrack->GetLabel();
86                         if (rejectFakes) {
87                                 if (label < 0) continue;
88                         }
89                         else {
90                                 label = TMath::Abs(label);
91                         }
92                         // store track data into candidate match variable
93                         // anyway, it will be stored in the tree only
94                         // if it matches a cluster
95                         match.indexT = it;
96                         esdTrack->GetPxPyPz(match.p);
97                         esdTrack->GetXYZ(match.v);
98                         // internal loop on clusters
99                         // a counter counts how many true matches are
100                         // generated for the same track
101                         count = 0;
102                         for (Int_t ic = firstCluster; ic < lastCluster; ic++) {
103                                 AliESDCaloCluster *cl = esd->GetCaloCluster(ic);
104                                 // reject pseudo-clusters & unmatched clusters
105                                 if (cl->GetClusterType() != AliESDCaloCluster::kClusterv1) continue;
106                                 if (cl->GetPrimaryIndex() != 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 }