ROOT logo
//
// This macro performs the matching operation between ESD tracks 
// and EMCAL clusters (stored as AliESDCaloCluster objects).
// Due to the necessity to know the magnetic field, it is supposed that
// this macro runs in the directory where event files are stored
// (galice.root --> recovery magnetic field), and saves its output in
// a directory specified in the argument (default = work directory)
// 

void FindMatches(const char *fileOut = "matchESD.root")
{
	//
	// Initialize AliRun manager.
	//
	if (gAlice) {
		delete gAlice;
		gAlice = 0;
	}
	
	//
	// Initialize AliRunLoader, in order
	// to read magnetic field from simulation.
	//
	AliRunLoader *rl = AliRunLoader::Open("galice.root");
	if (!rl) return;
	rl->LoadgAlice();
	gAlice = rl->GetAliRun();

	//
	//Get magnetic field from GRP
	//
 	 AliGRPManager * grpMan=new AliGRPManager();
	 grpMan->ReadGRPEntry(); 
	 grpMan->SetMagField(); 

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