1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 // A. De Falco, H. Woehri, INFN Cagliari, July 2006
19 // This macro reads the generation/reconstruction files in the
20 // input directories (recodir and simdir),
21 // builds a tree that contains, for each event, an array of muons and dimuons
22 // (TClonesArrays of AliMUONTrackLight and AliMUONPairLight objects)
23 // and writes the tree in an output file (outFileName)
24 // Note that if the path for the output file is not explicitly specified,
25 // it will be written in the directory containing the generation/reconstruction
26 // 27-Nov-2006: modified by in order to loop on files
29 // Updated this macro to work with new version of AliMUONRecoCheck. Also, we are
30 // now fetching reconstructed track data from ESD and not the track tree, because
31 // the AliMUONTrack objects for reconstructed tracks are no longer stored on disk.
32 // - Artur Szostak <artursz@iafrica.com>
34 #if !defined(__CINT__) || defined(__MAKECINT__)
35 #include <Riostream.h>
36 #include <TClonesArray.h>
40 #include <TLorentzVector.h>
41 #include <TParticle.h>
43 #include <TGeoManager.h>
44 #include "AliMUONRecoCheck.h"
45 #include "AliMUONTrack.h"
46 #include "AliMUONTrackParam.h"
47 #include "AliMUONTrackLight.h"
48 #include "AliMUONPairLight.h"
49 #include "AliMUONVTrackStore.h"
50 #include "AliMUONTrackExtrap.h"
51 #include "AliESDEvent.h"
52 #include "AliESDVertex.h"
53 #include "AliMCEventHandler.h"
54 #include "AliMCEvent.h"
55 /*TODO: need to update this with changes made to ITS
56 #include "AliITSVertexerPPZ.h"
57 #include "AliITSLoader.h"
59 #include "AliTracker.h"
60 #include "AliMagFMaps.h"
64 void DecodeRecoCocktail(
65 char* recodir=".", // The directory containing galice.root for reconstructed data.
66 char* simdir="generated/", // The directory containing galice.root for simulated data.
67 char* outFileName = "MuonLight.root", // The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
68 char* geoFilename = "geometry.root" // The filename containing the geometry.
71 char startingDir[200];
72 sprintf (startingDir,"%s",gSystem->pwd());
75 TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",10);
76 TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10);
77 TTree *treeOut = new TTree("tree","tree");
79 TFile *fout = new TFile(outFileName,"recreate");
82 treeOut->Branch("muons",&muonArray);
83 treeOut->Branch("dimuons",&dimuonArray);
85 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
87 TGeoManager::Import(geoFilename);
89 Error("MUONmass_ESD", "getting geometry from file %s failed", geoFilename);
95 // waiting for mag field in CDB
96 printf("Loading field map...\n");
97 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
98 AliTracker::SetFieldMap(field, kFALSE);
99 // set the magnetic field for track extrapolations
100 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
102 AliMUONRecoCheck *rc = new AliMUONRecoCheck("AliESDs.root", simdir);
103 Int_t nev = rc->NumberOfEvents();
105 /*TODO: need to update this with changes made to ITS
106 AliITSLoader* ITSloader = (AliITSLoader*) runLoaderSim->GetLoader("ITSLoader");
107 AliITSVertexerPPZ *dovert = 0;
109 dovert = new AliITSVertexerPPZ("default",0,0);
110 // dovert->SetDebug(0);
111 dovert->SetDiffPhiMax(0.05);
112 dovert->SetWindow(3.);
114 AliESDVertex *vert = 0;
119 for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events
121 /*TODO: need to update this with changes made to ITS
122 runLoaderSim->GetHeader();
124 vert = dovert->FindVertexForCurrentEvent(ievent);
128 //printf ("Event %d of %d\n",ievent,nev);
129 muonArray->Clear(); // clean muon and dimuon arrays
130 dimuonArray->Clear();
132 AliMUONVTrackStore* recoTracks = rc->ReconstructedTracks(ievent); // Use tracks from actual reconstruction, but this does not work anymore.
133 //AliMUONVTrackStore* trackRefs = rc->ReconstructibleTracks(ievent); // Only use reconstructible reference tracks.
134 AliMUONVTrackStore* trackRefs = rc->TrackRefs(ievent);
135 AliStack* pstack = (const_cast<AliMCEventHandler*>(rc->GetMCEventHandler()))->MCEvent()->Stack();
137 TIter next(recoTracks->CreateIterator());
138 AliMUONTrack* trackReco = NULL;
140 Int_t nTrackReco = recoTracks->GetSize();
141 Int_t nTracksESD = rc->GetESDEvent()->GetNumberOfMuonTracks();
142 if (nTrackReco != nTracksESD) printf ("Tracks in recoTracks (%d) and in ESD (%d) do not match!\n", nTrackReco, nTracksESD);
143 Int_t nreftracks = 0;
145 while ( (trackReco = static_cast<AliMUONTrack*>(next())) != NULL )
147 // assign parameters concerning the reconstructed tracks
148 AliMUONTrackLight muLight;
150 muLight.FillFromESD(rc->GetESDEvent()->GetMuonTrack(itrRec));
151 // muLight.FillFromAliMUONTrack(trackReco);
153 // find the reference track and store further information
154 TParticle *part = muLight.FindRefTrack(trackReco, trackRefs, pstack);
156 v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
158 muLight.FillMuonHistory(pstack, part);
159 // muLight.PrintInfo("A");
160 //store the referenced track in the muonArray:
161 TClonesArray &muons = *muonArray;
162 new (muons[nreftracks++]) AliMUONTrackLight(muLight);
168 // now loop over muon pairs to build dimuons
169 Int_t nmuons = muonArray->GetEntriesFast();
171 for(Int_t itrRec1 = 0; itrRec1 < nmuons-1; itrRec1++) {
172 AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1);
173 for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){
174 AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2);
175 AliMUONPairLight dimuLight;
176 dimuLight.SetMuons(*mu1, *mu2);
177 TClonesArray &dimuons = *dimuonArray;
178 new (dimuons[ndimuons++]) AliMUONPairLight(dimuLight);
187 gSystem->cd(startingDir);