]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/macros/trackMatching/FindMatches.C
track matching macros from Alberto
[u/mrichter/AliRoot.git] / EMCAL / macros / trackMatching / FindMatches.C
CommitLineData
e10611f0 1//
2// This macro performs the matching operation between ESD tracks
3// and EMCAL clusters (stored as AliESDCaloCluster objects).
4// Due to the necessity to know the magnetic field, it is supposed that
5// this macro runs in the directory where event files are stored
6// (galice.root --> recovery magnetic field), and saves its output in
7// a directory specified in the argument (default = work directory)
8//
9
10void FindMatches(const char *fileOut = "matchESD.root")
11{
12 //
13 // Initialize AliRun manager.
14 //
15 if (gAlice) {
16 delete gAlice;
17 gAlice = 0;
18 }
19
20 //
21 // Initialize AliRunLoader, in order
22 // to read magnetic field from simulation.
23 //
24 AliRunLoader *rl = AliRunLoader::Open("galice.root");
25 if (!rl) return;
26 rl->LoadgAlice();
27 gAlice = rl->GetAliRun();
28 AliMagF *magf = gAlice->Field();
29 Bool_t constField = (magf->Type() == 1);
30 AliTracker::SetFieldMap(magf, constField);
31
32 //
33 // Open ESD file and recoveries TTree of ESD objects.
34 //
35 TFile *esdFile = new TFile("AliESDs.root");
36 TTree *esdTree = (TTree*)esdFile->Get("esdTree");
37 AliESD *esd = 0;
38 esdTree->SetBranchAddress("ESD", &esd);
39 Long64_t nEvents = esdTree->GetEntries();
40
41 //
42 // Set this important flag to the tracker.
43 // This example works with and AliESD file already saved
44 // after the tracking procedure done during AliReconstruction::Run().
45 // All tracks saved in such a file, are already propagated to the vertex,
46 // while EMCAL matching needs to be done using track status in the outermost
47 // available position.
48 // Then, we must use the "outer" parameters in the ESD track, and we must
49 // tell to the track to copy the outer parameters from its AliESDtrack seed.
50 //
51 AliEMCALTrack::SetUseOuterParams(kTRUE);
52
53 //
54 // Instantiate match finder, and set some cuts.
55 // Distances are in centimeters, angles in degrees.
56 //
57 AliEMCALTracker *mf = new AliEMCALTracker;
58 mf->SetCutX(5.0);
59 mf->SetCutY(5.0);
60 mf->SetCutZ(5.0);
61 mf->SetCutAlpha(-50., 50.); // --> i.e. exclude this cut
62 mf->SetCutAngle(10.);
63 mf->SetMaxDistance(5.0);
64
65 //
66 // Define how to manage energy loss correction.
67 // Actually, these corrections are exlcluded.
68 //
69 // mf->SetCorrection(0.0604557, 34.5437); // at the moment, we exclude energy loss correction
70 mf->SetTrackCorrectionMode("NONE");
71 mf->SetNumberOfSteps(0);
72 //TGeoManager::Import("misaligned_geometry.root");
73
74 //
75 // Before starting looping on files, the output file is created.
76 // It will be structurally identical to the ESD source tree, with the
77 // only difference that here the "fEMCALindex" datamember of the ESD tracks
78 // will have been set to a meaningful value.
79 //
80 TFile *outFile = TFile::Open(fileOut, "RECREATE");
81 TTree *outTree = new TTree("esdTree", "ESD with matched clusters");
82 outTree->Branch("ESD", "AliESD", &esd);
83
84 //
85 // Loop on events.
86 // The whole track matching procedure is compiled in the
87 // method "PropagateBack" which accepts and input ESD collection.
88 // This method modifies the passed object then, the same object is linked
89 // to source tree and target tree branch.
90 //
91 Int_t nTracks, nStep1, nStep2, nSaved;
92 for (Long64_t iev = 0; iev < nEvents; iev++) {
93 cout << "Finding matches in event " << iev + 1 << "/" << nEvents << endl;
94 esdTree->GetEntry(iev);
95 mf->PropagateBack(esd);
96 outTree->Fill();
97 }
98
99 //
100 // Save processed tree and close output file.
101 //
102 outFile->cd();
103 outTree->Write("esdTree", TObject::kOverwrite);
104 outFile->Close();
105}