]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/DecodeRecoCocktail.C
The present commit corresponds to an important change in the way the
[u/mrichter/AliRoot.git] / MUON / DecodeRecoCocktail.C
CommitLineData
fa6e7866 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
e54bf126 18/// \ingroup macros
19/// \file DecodeRecoCocktail.C
20/// \brief add brief description
21///
22/// \author A. De Falco, H. Woehri, INFN Cagliari, July 2006
23///
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
32///
33/// 13 Nov 2007:
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>
9bdda5f6 38
4d309390 39#if !defined(__CINT__) || defined(__MAKECINT__)
40#include <Riostream.h>
fa6e7866 41#include <TClonesArray.h>
42#include <TFile.h>
43#include <TTree.h>
44#include <TMath.h>
45#include <TLorentzVector.h>
46#include <TParticle.h>
47#include <TSystem.h>
59830a87 48#include <TGeoManager.h>
4d309390 49#include "AliMUONRecoCheck.h"
50#include "AliMUONTrack.h"
51#include "AliMUONTrackParam.h"
fa6e7866 52#include "AliMUONTrackLight.h"
53#include "AliMUONPairLight.h"
9bdda5f6 54#include "AliMUONVTrackStore.h"
22ccc301 55#include "AliMUONTrackExtrap.h"
9bdda5f6 56#include "AliESDEvent.h"
57#include "AliESDVertex.h"
58#include "AliMCEventHandler.h"
59#include "AliMCEvent.h"
f7a1cc68 60#include "AliMagF.h"
9bdda5f6 61/*TODO: need to update this with changes made to ITS
4d309390 62#include "AliITSVertexerPPZ.h"
63#include "AliITSLoader.h"
9bdda5f6 64*/
59830a87 65#include "AliTracker.h"
4d309390 66#endif
fa6e7866 67
4d309390 68
9bdda5f6 69void DecodeRecoCocktail(
70 char* recodir=".", // The directory containing galice.root for reconstructed data.
71 char* simdir="generated/", // The directory containing galice.root for simulated data.
72 char* outFileName = "MuonLight.root", // The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
61fed964 73 char* geoFilename = "geometry.root" // The filename containing the geometry.
9bdda5f6 74 )
75{
e54bf126 76/// \param recodir The directory containing galice.root for reconstructed data.
77/// \param simdir The directory containing galice.root for simulated data.
78/// \param outFileName The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
79/// \param geoFilename The filename containing the geometry.
80
4d309390 81 char startingDir[200];
82 sprintf (startingDir,"%s",gSystem->pwd());
9bdda5f6 83 gSystem->cd(recodir);
4d309390 84
85 TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",10);
86 TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10);
87 TTree *treeOut = new TTree("tree","tree");
88
fa6e7866 89 TFile *fout = new TFile(outFileName,"recreate");
4d309390 90 fout->cd();
fa6e7866 91
4d309390 92 treeOut->Branch("muons",&muonArray);
93 treeOut->Branch("dimuons",&dimuonArray);
94
59830a87 95 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
96 if (!gGeoManager) {
97 TGeoManager::Import(geoFilename);
98 if (!gGeoManager) {
99 Error("MUONmass_ESD", "getting geometry from file %s failed", geoFilename);
100 return;
101 }
102 }
103
104 // set mag field
105 // waiting for mag field in CDB
f7a1cc68 106 if (!TGeoGlobalMagField::Instance()->GetField()) {
107 printf("Loading field map...\n");
108 AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
109 TGeoGlobalMagField::Instance()->SetField(field);
110 }
59830a87 111 // set the magnetic field for track extrapolations
f7a1cc68 112 AliMUONTrackExtrap::SetField();
59830a87 113
61fed964 114 AliMUONRecoCheck *rc = new AliMUONRecoCheck("AliESDs.root", simdir);
9bdda5f6 115 Int_t nev = rc->NumberOfEvents();
fa6e7866 116
9bdda5f6 117 /*TODO: need to update this with changes made to ITS
a4ee7ab9 118 AliITSLoader* ITSloader = (AliITSLoader*) runLoaderSim->GetLoader("ITSLoader");
4d309390 119 AliITSVertexerPPZ *dovert = 0;
120 if (ITSloader) {
121 dovert = new AliITSVertexerPPZ("default",0,0);
21939432 122 // dovert->SetDebug(0);
4d309390 123 dovert->SetDiffPhiMax(0.05);
124 dovert->SetWindow(3.);
125 }
126 AliESDVertex *vert = 0;
9bdda5f6 127 */
fa6e7866 128
129 TLorentzVector v;
9bdda5f6 130
fa6e7866 131 for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events
9bdda5f6 132
133 /*TODO: need to update this with changes made to ITS
a4ee7ab9 134 runLoaderSim->GetHeader();
4d309390 135 if (ITSloader) {
136 vert = dovert->FindVertexForCurrentEvent(ievent);
137 }
9bdda5f6 138 */
139
a4ee7ab9 140 //printf ("Event %d of %d\n",ievent,nev);
fa6e7866 141 muonArray->Clear(); // clean muon and dimuon arrays
142 dimuonArray->Clear();
fa6e7866 143
61fed964 144 AliMUONVTrackStore* recoTracks = rc->ReconstructedTracks(ievent); // Use tracks from actual reconstruction, but this does not work anymore.
9bdda5f6 145 //AliMUONVTrackStore* trackRefs = rc->ReconstructibleTracks(ievent); // Only use reconstructible reference tracks.
146 AliMUONVTrackStore* trackRefs = rc->TrackRefs(ievent);
61fed964 147 AliStack* pstack = (const_cast<AliMCEventHandler*>(rc->GetMCEventHandler()))->MCEvent()->Stack();
9bdda5f6 148
149 TIter next(recoTracks->CreateIterator());
150 AliMUONTrack* trackReco = NULL;
151
152 Int_t nTrackReco = recoTracks->GetSize();
61fed964 153 Int_t nTracksESD = rc->GetESDEvent()->GetNumberOfMuonTracks();
9bdda5f6 154 if (nTrackReco != nTracksESD) printf ("Tracks in recoTracks (%d) and in ESD (%d) do not match!\n", nTrackReco, nTracksESD);
155 Int_t nreftracks = 0;
156 Int_t itrRec = 0;
157 while ( (trackReco = static_cast<AliMUONTrack*>(next())) != NULL )
158 {
fa6e7866 159 // assign parameters concerning the reconstructed tracks
4d309390 160 AliMUONTrackLight muLight;
a4ee7ab9 161
61fed964 162 muLight.FillFromESD(rc->GetESDEvent()->GetMuonTrack(itrRec));
9bdda5f6 163 // muLight.FillFromAliMUONTrack(trackReco);
4d309390 164
165 // find the reference track and store further information
61fed964 166 TParticle *part = muLight.FindRefTrack(trackReco, trackRefs, pstack);
fa6e7866 167 if (part) {
168 v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
82724a77 169 muLight.SetPGen(v);
9bdda5f6 170 muLight.FillMuonHistory(pstack, part);
4d309390 171 // muLight.PrintInfo("A");
fa6e7866 172 //store the referenced track in the muonArray:
173 TClonesArray &muons = *muonArray;
82724a77 174 new (muons[nreftracks++]) AliMUONTrackLight(muLight);
4d309390 175 }
9bdda5f6 176
177 itrRec++;
4d309390 178 } // end reco track
fa6e7866 179
180 // now loop over muon pairs to build dimuons
181 Int_t nmuons = muonArray->GetEntriesFast();
182 Int_t ndimuons = 0;
183 for(Int_t itrRec1 = 0; itrRec1 < nmuons-1; itrRec1++) {
184 AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1);
185 for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){
186 AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2);
4d309390 187 AliMUONPairLight dimuLight;
82724a77 188 dimuLight.SetMuons(*mu1, *mu2);
fa6e7866 189 TClonesArray &dimuons = *dimuonArray;
82724a77 190 new (dimuons[ndimuons++]) AliMUONPairLight(dimuLight);
fa6e7866 191 }
192 }
9bdda5f6 193
fa6e7866 194 treeOut->Fill();
4d309390 195 }
196
fa6e7866 197 fout->cd();
198 treeOut->Write();
199 gSystem->cd(startingDir);
82724a77 200 fout->Close();
82724a77 201 delete muonArray;
202 delete dimuonArray;
4d309390 203 delete treeOut;
204 delete fout;
205 delete rc;
fa6e7866 206}
4d309390 207