]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/DecodeRecoCocktail.C
Adding a line to be able to generate core dumps online
[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>
4d309390 48#include "AliMUONRecoCheck.h"
49#include "AliMUONTrack.h"
fa6e7866 50#include "AliMUONTrackLight.h"
51#include "AliMUONPairLight.h"
9bdda5f6 52#include "AliMUONVTrackStore.h"
9bdda5f6 53#include "AliESDEvent.h"
54#include "AliESDVertex.h"
f202486b 55#include "AliESDMuonTrack.h"
9bdda5f6 56#include "AliMCEventHandler.h"
57#include "AliMCEvent.h"
a99c3449 58#include "AliStack.h"
9bdda5f6 59/*TODO: need to update this with changes made to ITS
4d309390 60#include "AliITSVertexerPPZ.h"
61#include "AliITSLoader.h"
9bdda5f6 62*/
4d309390 63#endif
fa6e7866 64
4d309390 65
9bdda5f6 66void DecodeRecoCocktail(
67 char* recodir=".", // The directory containing galice.root for reconstructed data.
68 char* simdir="generated/", // The directory containing galice.root for simulated data.
f202486b 69 char* outFileName = "MuonLight.root" // The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
9bdda5f6 70 )
71{
e54bf126 72/// \param recodir The directory containing galice.root for reconstructed data.
73/// \param simdir The directory containing galice.root for simulated data.
74/// \param outFileName The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
75/// \param geoFilename The filename containing the geometry.
76
4d309390 77 char startingDir[200];
78 sprintf (startingDir,"%s",gSystem->pwd());
9bdda5f6 79 gSystem->cd(recodir);
4d309390 80
81 TClonesArray *muonArray = new TClonesArray("AliMUONTrackLight",10);
82 TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10);
83 TTree *treeOut = new TTree("tree","tree");
84
fa6e7866 85 TFile *fout = new TFile(outFileName,"recreate");
4d309390 86 fout->cd();
fa6e7866 87
4d309390 88 treeOut->Branch("muons",&muonArray);
89 treeOut->Branch("dimuons",&dimuonArray);
90
61fed964 91 AliMUONRecoCheck *rc = new AliMUONRecoCheck("AliESDs.root", simdir);
fa6e7866 92
9bdda5f6 93 /*TODO: need to update this with changes made to ITS
a4ee7ab9 94 AliITSLoader* ITSloader = (AliITSLoader*) runLoaderSim->GetLoader("ITSLoader");
4d309390 95 AliITSVertexerPPZ *dovert = 0;
96 if (ITSloader) {
97 dovert = new AliITSVertexerPPZ("default",0,0);
21939432 98 // dovert->SetDebug(0);
4d309390 99 dovert->SetDiffPhiMax(0.05);
100 dovert->SetWindow(3.);
101 }
102 AliESDVertex *vert = 0;
9bdda5f6 103 */
fa6e7866 104
105 TLorentzVector v;
9bdda5f6 106
f202486b 107 Int_t nev = rc->NumberOfEvents();
fa6e7866 108 for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events
9bdda5f6 109
110 /*TODO: need to update this with changes made to ITS
a4ee7ab9 111 runLoaderSim->GetHeader();
4d309390 112 if (ITSloader) {
113 vert = dovert->FindVertexForCurrentEvent(ievent);
114 }
9bdda5f6 115 */
116
a4ee7ab9 117 //printf ("Event %d of %d\n",ievent,nev);
fa6e7866 118 muonArray->Clear(); // clean muon and dimuon arrays
119 dimuonArray->Clear();
fa6e7866 120
a99c3449 121 AliMUONVTrackStore* recoTracks = rc->ReconstructedTracks(ievent, kFALSE); // Use tracks from actual reconstruction.
9bdda5f6 122 //AliMUONVTrackStore* trackRefs = rc->ReconstructibleTracks(ievent); // Only use reconstructible reference tracks.
123 AliMUONVTrackStore* trackRefs = rc->TrackRefs(ievent);
61fed964 124 AliStack* pstack = (const_cast<AliMCEventHandler*>(rc->GetMCEventHandler()))->MCEvent()->Stack();
9bdda5f6 125
f202486b 126 // loop over ESD tracks
9bdda5f6 127 Int_t nreftracks = 0;
f202486b 128 const AliESDEvent* esd = rc->GetESDEvent();
129 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
130 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
131
132 AliESDMuonTrack* esdTrack = esd->GetMuonTrack(iTrack);
133
134 // skip ghosts
135 if (!esdTrack->ContainTrackerData()) continue;
a4ee7ab9 136
f202486b 137 // find the corresponding MUON track
138 AliMUONTrack* trackReco = (AliMUONTrack*) recoTracks->FindObject(esdTrack->GetUniqueID());
4d309390 139
f202486b 140 // try to match the reconstructed track with a simulated one
141 Int_t nMatchClusters = 0;
142 AliMUONTrack* matchedTrackRef = rc->FindCompatibleTrack(*trackReco, *trackRefs, nMatchClusters, kFALSE, 10.);
143
144 if (matchedTrackRef) {
145
146 //store new referenced track in the muonArray
147 AliMUONTrackLight* muLight = new ((*muonArray)[nreftracks++]) AliMUONTrackLight();
148
149 // assign parameters concerning the reconstructed tracks
150 muLight->FillFromESD(esdTrack);
151 // muLight->FillFromAliMUONTrack(trackReco);
152
153 // store further information related to the simulated track
154 muLight->SetTrackPythiaLine(matchedTrackRef->GetUniqueID());
155 TParticle *part = pstack->Particle(matchedTrackRef->GetUniqueID());
156 muLight->SetTrackPDGCode(part->GetPdgCode());
fa6e7866 157 v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
f202486b 158 muLight->SetPGen(v);
159 muLight->FillMuonHistory(pstack, part);
4d309390 160 // muLight.PrintInfo("A");
f202486b 161
162 }
9bdda5f6 163
f202486b 164 } // end esd track
fa6e7866 165
166 // now loop over muon pairs to build dimuons
167 Int_t nmuons = muonArray->GetEntriesFast();
168 Int_t ndimuons = 0;
169 for(Int_t itrRec1 = 0; itrRec1 < nmuons-1; itrRec1++) {
170 AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1);
171 for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){
172 AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2);
4d309390 173 AliMUONPairLight dimuLight;
82724a77 174 dimuLight.SetMuons(*mu1, *mu2);
fa6e7866 175 TClonesArray &dimuons = *dimuonArray;
82724a77 176 new (dimuons[ndimuons++]) AliMUONPairLight(dimuLight);
fa6e7866 177 }
178 }
9bdda5f6 179
fa6e7866 180 treeOut->Fill();
4d309390 181 }
182
fa6e7866 183 fout->cd();
184 treeOut->Write();
185 gSystem->cd(startingDir);
82724a77 186 fout->Close();
82724a77 187 delete muonArray;
188 delete dimuonArray;
4d309390 189 delete treeOut;
190 delete fout;
191 delete rc;
fa6e7866 192}
4d309390 193