]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/DecodeRecoCocktail.C
New default values for baselines (F.Prino)
[u/mrichter/AliRoot.git] / MUON / DecodeRecoCocktail.C
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
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>
38
39 #if !defined(__CINT__) || defined(__MAKECINT__)
40 #include <Riostream.h>
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>
48 #include <TGeoManager.h>
49 #include "AliMUONRecoCheck.h"
50 #include "AliMUONTrack.h"
51 #include "AliMUONTrackParam.h"
52 #include "AliMUONTrackLight.h"
53 #include "AliMUONPairLight.h"
54 #include "AliMUONVTrackStore.h"
55 #include "AliMUONTrackExtrap.h"
56 #include "AliESDEvent.h"
57 #include "AliESDVertex.h"
58 #include "AliMCEventHandler.h"
59 #include "AliMCEvent.h"
60 /*TODO: need to update this with changes made to ITS
61 #include "AliITSVertexerPPZ.h"
62 #include "AliITSLoader.h"
63 */
64 #include "AliTracker.h"
65 #include "AliMagFMaps.h"
66 #endif
67
68
69 void 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.
73     char* geoFilename = "geometry.root"  // The filename containing the geometry.
74   )
75 {
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
81   char startingDir[200]; 
82   sprintf (startingDir,"%s",gSystem->pwd()); 
83   gSystem->cd(recodir); 
84
85   TClonesArray *muonArray   = new TClonesArray("AliMUONTrackLight",10); 
86   TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10); 
87   TTree *treeOut = new TTree("tree","tree"); 
88
89   TFile *fout = new TFile(outFileName,"recreate"); 
90   fout->cd(); 
91
92   treeOut->Branch("muons",&muonArray); 
93   treeOut->Branch("dimuons",&dimuonArray); 
94   
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 
106   printf("Loading field map...\n");
107   AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
108   AliTracker::SetFieldMap(field, kFALSE);
109   // set the magnetic field for track extrapolations
110   AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
111
112   AliMUONRecoCheck *rc = new AliMUONRecoCheck("AliESDs.root", simdir);
113   Int_t nev = rc->NumberOfEvents();
114   
115   /*TODO: need to update this with changes made to ITS
116   AliITSLoader* ITSloader =  (AliITSLoader*) runLoaderSim->GetLoader("ITSLoader");
117   AliITSVertexerPPZ *dovert = 0; 
118   if (ITSloader) { 
119     dovert = new AliITSVertexerPPZ("default",0,0);
120     // dovert->SetDebug(0);
121     dovert->SetDiffPhiMax(0.05);
122     dovert->SetWindow(3.);
123   }
124   AliESDVertex *vert = 0;
125   */
126   
127   TLorentzVector v; 
128  
129   for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events 
130     
131     /*TODO: need to update this with changes made to ITS
132     runLoaderSim->GetHeader();
133     if (ITSloader) { 
134       vert = dovert->FindVertexForCurrentEvent(ievent);
135     }
136     */
137     
138     //printf ("Event %d of %d\n",ievent,nev);
139     muonArray->Clear();     // clean muon and dimuon arrays 
140     dimuonArray->Clear(); 
141     
142     AliMUONVTrackStore* recoTracks = rc->ReconstructedTracks(ievent);  // Use tracks from actual reconstruction, but this does not work anymore.
143     //AliMUONVTrackStore* trackRefs = rc->ReconstructibleTracks(ievent);  // Only use reconstructible reference tracks.
144     AliMUONVTrackStore* trackRefs = rc->TrackRefs(ievent);
145     AliStack* pstack = (const_cast<AliMCEventHandler*>(rc->GetMCEventHandler()))->MCEvent()->Stack();
146     
147     TIter next(recoTracks->CreateIterator());
148     AliMUONTrack* trackReco = NULL;
149     
150     Int_t nTrackReco = recoTracks->GetSize();
151     Int_t nTracksESD = rc->GetESDEvent()->GetNumberOfMuonTracks();
152     if (nTrackReco != nTracksESD) printf ("Tracks in recoTracks (%d) and in ESD (%d) do not match!\n", nTrackReco, nTracksESD);
153     Int_t nreftracks = 0;
154     Int_t itrRec = 0;
155     while ( (trackReco = static_cast<AliMUONTrack*>(next())) != NULL )
156     {
157       // assign parameters concerning the reconstructed tracks
158       AliMUONTrackLight muLight;
159       
160       muLight.FillFromESD(rc->GetESDEvent()->GetMuonTrack(itrRec));
161       // muLight.FillFromAliMUONTrack(trackReco);
162       
163       // find the reference track and store further information 
164       TParticle *part = muLight.FindRefTrack(trackReco, trackRefs, pstack);
165       if (part) { 
166         v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
167         muLight.SetPGen(v); 
168         muLight.FillMuonHistory(pstack, part);
169         //        muLight.PrintInfo("A");
170         //store the referenced track in the muonArray:
171         TClonesArray &muons = *muonArray;
172         new (muons[nreftracks++]) AliMUONTrackLight(muLight);
173       } 
174       
175       itrRec++;
176     }  // end reco track
177     
178     // now loop over muon pairs to build dimuons
179     Int_t nmuons = muonArray->GetEntriesFast(); 
180     Int_t ndimuons = 0; 
181     for(Int_t itrRec1 = 0; itrRec1 < nmuons-1; itrRec1++) { 
182       AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1); 
183       for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){
184         AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2); 
185         AliMUONPairLight dimuLight;
186         dimuLight.SetMuons(*mu1, *mu2);
187         TClonesArray &dimuons = *dimuonArray;
188         new (dimuons[ndimuons++]) AliMUONPairLight(dimuLight);
189       }
190     }
191     
192     treeOut->Fill(); 
193   } 
194   
195   fout->cd(); 
196   treeOut->Write(); 
197   gSystem->cd(startingDir); 
198   fout->Close();
199   delete muonArray;
200   delete dimuonArray;
201   delete treeOut; 
202   delete fout;
203   delete rc;
204 }
205