]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/macros/trackMatching/FindMatches.C
Update master to aliroot
[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();
07b7b86d 28
29 //
30 //Get magnetic field from GRP
31 //
32 AliGRPManager * grpMan=new AliGRPManager();
33 grpMan->ReadGRPEntry();
34 grpMan->SetMagField();
35
e10611f0 36 //
37 // Open ESD file and recoveries TTree of ESD objects.
38 //
39 TFile *esdFile = new TFile("AliESDs.root");
40 TTree *esdTree = (TTree*)esdFile->Get("esdTree");
3a2a23e1 41 AliESDEvent* esd = new AliESDEvent();
42 esd->ReadFromTree(esdTree);
43 if (!esd) {cerr<<"no AliESDEvent"; return 1;};
44
e10611f0 45 Long64_t nEvents = esdTree->GetEntries();
46
47 //
48 // Set this important flag to the tracker.
49 // This example works with and AliESD file already saved
50 // after the tracking procedure done during AliReconstruction::Run().
51 // All tracks saved in such a file, are already propagated to the vertex,
52 // while EMCAL matching needs to be done using track status in the outermost
53 // available position.
54 // Then, we must use the "outer" parameters in the ESD track, and we must
55 // tell to the track to copy the outer parameters from its AliESDtrack seed.
56 //
57 AliEMCALTrack::SetUseOuterParams(kTRUE);
58
59 //
60 // Instantiate match finder, and set some cuts.
61 // Distances are in centimeters, angles in degrees.
62 //
63 AliEMCALTracker *mf = new AliEMCALTracker;
a0270705 64 mf->SetCutX(50.0);
65 mf->SetCutY(50.0);
66 mf->SetCutZ(50.0);
e10611f0 67 mf->SetCutAlpha(-50., 50.); // --> i.e. exclude this cut
a0270705 68 mf->SetCutAngle(10000.);
69 mf->SetMaxDistance(50.0);
e10611f0 70
71 //
72 // Define how to manage energy loss correction.
73 // Actually, these corrections are exlcluded.
74 //
75 // mf->SetCorrection(0.0604557, 34.5437); // at the moment, we exclude energy loss correction
76 mf->SetTrackCorrectionMode("NONE");
77 mf->SetNumberOfSteps(0);
78 //TGeoManager::Import("misaligned_geometry.root");
79
80 //
81 // Before starting looping on files, the output file is created.
82 // It will be structurally identical to the ESD source tree, with the
83 // only difference that here the "fEMCALindex" datamember of the ESD tracks
84 // will have been set to a meaningful value.
85 //
86 TFile *outFile = TFile::Open(fileOut, "RECREATE");
87 TTree *outTree = new TTree("esdTree", "ESD with matched clusters");
3a2a23e1 88 //outTree->Branch("ESD", "AliESD", &esd);
89 esd->WriteToTree(outTree);
e10611f0 90
91 //
92 // Loop on events.
93 // The whole track matching procedure is compiled in the
94 // method "PropagateBack" which accepts and input ESD collection.
95 // This method modifies the passed object then, the same object is linked
96 // to source tree and target tree branch.
97 //
98 Int_t nTracks, nStep1, nStep2, nSaved;
99 for (Long64_t iev = 0; iev < nEvents; iev++) {
a0270705 100 //cout << "Finding matches in event " << iev + 1 << "/" << nEvents << endl;
e10611f0 101 esdTree->GetEntry(iev);
a0270705 102 mf->Clear("ALL");
e10611f0 103 mf->PropagateBack(esd);
104 outTree->Fill();
105 }
106
107 //
108 // Save processed tree and close output file.
109 //
110 outFile->cd();
111 outTree->Write("esdTree", TObject::kOverwrite);
112 outFile->Close();
113}