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 **************************************************************************/
19 /// \file DecodeRecoCocktail.C
20 /// \brief add brief description
22 /// \author A. De Falco, H. Woehri, INFN Cagliari, July 2006
24 /// This macro reads the generation/reconstruction files in the
25 /// input directories (recodir and simdir),
26 /// builds a tree that contains, for each event, an array of muons and dimuons
27 /// (TClonesArrays of AliMUONTrackLight and AliMUONPairLight objects)
28 /// and writes the tree in an output file (outFileName)
29 /// Note that if the path for the output file is not explicitly specified,
30 /// it will be written in the directory containing the generation/reconstruction
31 /// 27-Nov-2006: modified by in order to loop on files
34 /// Updated this macro to work with new version of AliMUONRecoCheck. Also, we are
35 /// now fetching reconstructed track data from ESD and not the track tree, because
36 /// the AliMUONTrack objects for reconstructed tracks are no longer stored on disk.
37 /// - Artur Szostak <artursz@iafrica.com>
39 #if !defined(__CINT__) || defined(__MAKECINT__)
40 #include <Riostream.h>
41 #include <TClonesArray.h>
45 #include <TLorentzVector.h>
46 #include <TParticle.h>
48 #include <TGeoManager.h>
49 #include <TGeoGlobalMagField.h>
50 #include "AliMUONRecoCheck.h"
51 #include "AliMUONTrack.h"
52 #include "AliMUONTrackParam.h"
53 #include "AliMUONTrackLight.h"
54 #include "AliMUONPairLight.h"
55 #include "AliMUONVTrackStore.h"
56 #include "AliMUONTrackExtrap.h"
57 #include "AliESDEvent.h"
58 #include "AliESDVertex.h"
59 #include "AliMCEventHandler.h"
60 #include "AliMCEvent.h"
62 #include "AliGRPManager.h"
63 /*TODO: need to update this with changes made to ITS
64 #include "AliITSVertexerPPZ.h"
65 #include "AliITSLoader.h"
67 #include "AliTracker.h"
71 void DecodeRecoCocktail(
72 char* recodir=".", // The directory containing galice.root for reconstructed data.
73 char* simdir="generated/", // The directory containing galice.root for simulated data.
74 char* outFileName = "MuonLight.root", // The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
75 char* geoFilename = "geometry.root" // The filename containing the geometry.
78 /// \param recodir The directory containing galice.root for reconstructed data.
79 /// \param simdir The directory containing galice.root for simulated data.
80 /// \param outFileName The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
81 /// \param geoFilename The filename containing the geometry.
83 char startingDir[200];
84 sprintf (startingDir,"%s",gSystem->pwd());
87 TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",10);
88 TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10);
89 TTree *treeOut = new TTree("tree","tree");
91 TFile *fout = new TFile(outFileName,"recreate");
94 treeOut->Branch("muons",&muonArray);
95 treeOut->Branch("dimuons",&dimuonArray);
97 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
99 TGeoManager::Import(geoFilename);
101 Error("MUONmass_ESD", "getting geometry from file %s failed", geoFilename);
107 // waiting for mag field in CDB
108 if (!TGeoGlobalMagField::Instance()->GetField()) {
109 printf("Loading field map...\n");
110 AliGRPManager *grpMan = new AliGRPManager();
111 grpMan->ReadGRPEntry();
112 grpMan->SetMagField();
115 // set the magnetic field for track extrapolations
116 AliMUONTrackExtrap::SetField();
118 AliMUONRecoCheck *rc = new AliMUONRecoCheck("AliESDs.root", simdir);
119 Int_t nev = rc->NumberOfEvents();
121 /*TODO: need to update this with changes made to ITS
122 AliITSLoader* ITSloader = (AliITSLoader*) runLoaderSim->GetLoader("ITSLoader");
123 AliITSVertexerPPZ *dovert = 0;
125 dovert = new AliITSVertexerPPZ("default",0,0);
126 // dovert->SetDebug(0);
127 dovert->SetDiffPhiMax(0.05);
128 dovert->SetWindow(3.);
130 AliESDVertex *vert = 0;
135 for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events
137 /*TODO: need to update this with changes made to ITS
138 runLoaderSim->GetHeader();
140 vert = dovert->FindVertexForCurrentEvent(ievent);
144 //printf ("Event %d of %d\n",ievent,nev);
145 muonArray->Clear(); // clean muon and dimuon arrays
146 dimuonArray->Clear();
148 AliMUONVTrackStore* recoTracks = rc->ReconstructedTracks(ievent); // Use tracks from actual reconstruction, but this does not work anymore.
149 //AliMUONVTrackStore* trackRefs = rc->ReconstructibleTracks(ievent); // Only use reconstructible reference tracks.
150 AliMUONVTrackStore* trackRefs = rc->TrackRefs(ievent);
151 AliStack* pstack = (const_cast<AliMCEventHandler*>(rc->GetMCEventHandler()))->MCEvent()->Stack();
153 TIter next(recoTracks->CreateIterator());
154 AliMUONTrack* trackReco = NULL;
156 Int_t nTrackReco = recoTracks->GetSize();
157 Int_t nTracksESD = rc->GetESDEvent()->GetNumberOfMuonTracks();
158 if (nTrackReco != nTracksESD) printf ("Tracks in recoTracks (%d) and in ESD (%d) do not match!\n", nTrackReco, nTracksESD);
159 Int_t nreftracks = 0;
161 while ( (trackReco = static_cast<AliMUONTrack*>(next())) != NULL )
163 // assign parameters concerning the reconstructed tracks
164 AliMUONTrackLight muLight;
166 muLight.FillFromESD(rc->GetESDEvent()->GetMuonTrack(itrRec));
167 // muLight.FillFromAliMUONTrack(trackReco);
169 // find the reference track and store further information
170 TParticle *part = muLight.FindRefTrack(trackReco, trackRefs, pstack);
172 v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
174 muLight.FillMuonHistory(pstack, part);
175 // muLight.PrintInfo("A");
176 //store the referenced track in the muonArray:
177 TClonesArray &muons = *muonArray;
178 new (muons[nreftracks++]) AliMUONTrackLight(muLight);
184 // now loop over muon pairs to build dimuons
185 Int_t nmuons = muonArray->GetEntriesFast();
187 for(Int_t itrRec1 = 0; itrRec1 < nmuons-1; itrRec1++) {
188 AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1);
189 for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){
190 AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2);
191 AliMUONPairLight dimuLight;
192 dimuLight.SetMuons(*mu1, *mu2);
193 TClonesArray &dimuons = *dimuonArray;
194 new (dimuons[ndimuons++]) AliMUONPairLight(dimuLight);
203 gSystem->cd(startingDir);