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)
10 void FindMatches(const char *fileOut = "matchESD.root")
13 // Initialize AliRun manager.
21 // Initialize AliRunLoader, in order
22 // to read magnetic field from simulation.
24 AliRunLoader *rl = AliRunLoader::Open("galice.root");
27 gAlice = rl->GetAliRun();
30 //Get magnetic field from GRP
32 AliGRPManager * grpMan=new AliGRPManager();
33 grpMan->ReadGRPEntry();
34 grpMan->SetMagField();
37 // Open ESD file and recoveries TTree of ESD objects.
39 TFile *esdFile = new TFile("AliESDs.root");
40 TTree *esdTree = (TTree*)esdFile->Get("esdTree");
41 AliESDEvent* esd = new AliESDEvent();
42 esd->ReadFromTree(esdTree);
43 if (!esd) {cerr<<"no AliESDEvent"; return 1;};
45 Long64_t nEvents = esdTree->GetEntries();
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.
57 AliEMCALTrack::SetUseOuterParams(kTRUE);
60 // Instantiate match finder, and set some cuts.
61 // Distances are in centimeters, angles in degrees.
63 AliEMCALTracker *mf = new AliEMCALTracker;
67 mf->SetCutAlpha(-50., 50.); // --> i.e. exclude this cut
68 mf->SetCutAngle(10000.);
69 mf->SetMaxDistance(50.0);
72 // Define how to manage energy loss correction.
73 // Actually, these corrections are exlcluded.
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");
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.
86 TFile *outFile = TFile::Open(fileOut, "RECREATE");
87 TTree *outTree = new TTree("esdTree", "ESD with matched clusters");
88 //outTree->Branch("ESD", "AliESD", &esd);
89 esd->WriteToTree(outTree);
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.
98 Int_t nTracks, nStep1, nStep2, nSaved;
99 for (Long64_t iev = 0; iev < nEvents; iev++) {
100 //cout << "Finding matches in event " << iev + 1 << "/" << nEvents << endl;
101 esdTree->GetEntry(iev);
103 mf->PropagateBack(esd);
108 // Save processed tree and close output file.
111 outTree->Write("esdTree", TObject::kOverwrite);