]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONrecoNtuple.C
Containers definition
[u/mrichter/AliRoot.git] / MUON / MUONrecoNtuple.C
CommitLineData
c2a319d4 1// Macro MUONrecoNtuple.C (TO BE COMPILED)
2// for testing the C++ reconstruction code
3// and producing an Ntuple with reconstructed tracks
4// in output file "MUONtrackReco.root".
5// An example for using the Ntuple is in the macro MUONmassPlot.C
6
7// Arguments:
8// FirstEvent (default 0)
9// LastEvent (default 0)
10// RecGeantHits (1 to reconstruct GEANT hits) (default 0)
11// FileName (for signal) (default "galice.root")
12// BkgGeantFileName (for background),
13// needed only if RecGeantHits = 1 and background to be added
14
15// IMPORTANT NOTICE FOR USERS:
16// under "root" or "root.exe", execute the following commands:
17// 1. "gSystem->SetIncludePath("-I$ALICE_ROOT/MUON -I$ALICE_ROOT/STEER -I$ROOTSYS/include")" to get the right path at compilation time
18// 2. ".x loadlibs.C" to load the shared libraries
19// 3. ".x MUONrecoNtuple.C+()" with the right arguments, without forgetting the "+" which implies the compilation of the macro before its execution
20
21#include <iostream.h>
22
23#include <TClassTable.h>
24#include <TClonesArray.h>
25#include <TFile.h>
26#include <TParticle.h>
27#include <TROOT.h>
28#include <TTree.h>
29
30#include "AliRun.h"
31
32#include "AliMUONEventReconstructor.h"
33#include "AliMUONTrack.h"
34#include "AliMUONTrackHit.h"
35#include "AliMUONTrackParam.h"
36
37// Classes for Ntuple ////////////////////////////////////////////////////
38
39class AliMUONTrackRecNtuple : public TObject {
40 public:
41 // for direct access to members
42 Int_t fCharge; // charge of reconstructed track (+/- 1)
43 Float_t fPxRec; // Px of reconstructed track at vertex (GeV/c)
44 Float_t fPyRec; // Py of reconstructed track at vertex (GeV/c)
45 Float_t fPzRec; // Pz of reconstructed track at vertex (GeV/c)
46 Float_t fZRec; // Z of reconstructed track at vertex (cm)
47 Float_t fZRec1; // Z of reconstructed track at first hit (cm)
48 Int_t fNHits; // number of hits
49 Float_t fChi2; // chi2 of fit
50 Float_t fPxGen; // Px of best compatible generated track at vertex (GeV/c)
51 Float_t fPyGen; // Py of best compatible generated track at vertex (GeV/c)
52 Float_t fPzGen; // Pz of best compatible generated track at vertex (GeV/c)
53 AliMUONTrackRecNtuple(){;} // Constructor
54 virtual ~AliMUONTrackRecNtuple(){;} // Destructor
55 protected:
56 private:
57 ClassDef(AliMUONTrackRecNtuple, 1) // AliMUONTrackRecNtuple
58 };
59
60class AliMUONHeaderRecNtuple : public TObject {
61 public:
62 // for direct access to members
63 Int_t fEvent; // event number
64 AliMUONHeaderRecNtuple(){;} // Constructor
65 virtual ~AliMUONHeaderRecNtuple(){;} // Destructor
66 protected:
67 private:
68 ClassDef(AliMUONHeaderRecNtuple, 1) // AliMUONHeaderRecNtuple
69 };
70
71ClassImp(AliMUONTrackRecNtuple) // Class implementation in ROOT context
72ClassImp(AliMUONHeaderRecNtuple) // Class implementation in ROOT context
73
74 //__________________________________________________________________________
75void AliMUONEventRecNtupleFill(AliMUONEventReconstructor *Reco, Int_t FillWrite = 0)
76{
77 // Fill Ntuple for reconstructed event pointed to by "Reco"
78 // if "FillWrite" different from -1.
79 // Ntuple is created automatically before filling first event.
80 // If "FillWrite" = -1, write and close the file
81
82 static Bool_t firstTime = kTRUE;
83 static TTree *ntuple;
84 static AliMUONHeaderRecNtuple *header = new AliMUONHeaderRecNtuple();
85 static TClonesArray *recTracks = new TClonesArray("AliMUONTrackRecNtuple",5);
86
87 Int_t trackIndex;
88 AliMUONTrack *track;
89 AliMUONTrackParam *trackParam;
90 AliMUONTrackRecNtuple *recTrackNt;
91 Double_t bendingSlope, nonBendingSlope, pYZ;
92
93 if (FillWrite == -1) {
94 // better to create the file before the Ntuple ????
95 TFile *file = new TFile("MUONtrackReco.root","recreate");
96 ntuple->Write();
97 file->Write();
98 file->Close();
99 }
100
101 if (firstTime) {
102 firstTime = kFALSE;
103 // first call: create tree for Ntuple...
104 ntuple = new TTree("MUONtrackReco", "MUONtrackReco");
105 ntuple->Branch("Header","AliMUONHeaderRecNtuple", &header);
106 ntuple->Branch("Tracks", &recTracks);
107 }
108
109 // header
110 header->fEvent = gAlice->GetHeader()->GetEvent();
111
112 TClonesArray *recoTracksPtr = Reco->GetRecTracksPtr();
113 recoTracksPtr->Compress(); // for simple loop without "Next" since no hole
114 recTracks->Clear(); // to reset the TClonesArray of tracks to be put in the ntuple
115 // Loop over reconstructed tracks
116 for (trackIndex = 0; trackIndex < Reco->GetNRecTracks(); trackIndex++) {
117 track = (AliMUONTrack*) ((*recoTracksPtr)[trackIndex]);
118 recTrackNt = (AliMUONTrackRecNtuple*)
119 new ((*recTracks)[trackIndex]) AliMUONTrackRecNtuple();
120 // track parameters at Vertex
121 trackParam = track->GetTrackParamAtVertex();
122 recTrackNt->fCharge =
123 Int_t(TMath::Sign(1., trackParam->GetInverseBendingMomentum()));
124 bendingSlope = trackParam->GetBendingSlope();
125 nonBendingSlope = trackParam->GetNonBendingSlope();
126 pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
127 recTrackNt->fPzRec = pYZ / TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
128 recTrackNt->fPxRec = recTrackNt->fPzRec * nonBendingSlope;
129 recTrackNt->fPyRec = recTrackNt->fPzRec * bendingSlope;
130 recTrackNt->fZRec = trackParam->GetZ();
131 // track parameters at first hit
132 trackParam = ((AliMUONTrackHit*)
133 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
134 recTrackNt->fZRec1 = trackParam->GetZ();
135 // chi2
136 recTrackNt->fChi2 = track->GetFitFMin();
137 // number of hits
138 recTrackNt->fNHits = track->GetNTrackHits();
139 // track parameters at vertex of best compatible generated track:
140 // in fact muon with the right charge
141 for (int iPart = 0; iPart < gAlice->Particles()->GetEntriesFast(); iPart++) {
142 TParticle *particle = (TParticle*) gAlice->Particles()->UncheckedAt(iPart);
143 if ((particle->GetPdgCode() * recTrackNt->fCharge) == -13) {
144 recTrackNt->fPxGen = particle->Px();
145 recTrackNt->fPyGen = particle->Py();
146 recTrackNt->fPzGen = particle->Pz();
147 }
148 }
149 } // for (trackIndex = 0;...
150
151 ntuple->Fill();
152
153 return;
154}
155
156void MUONrecoNtuple (Int_t FirstEvent = 0, Int_t LastEvent = 0, Int_t RecGeantHits = 0, Text_t *FileName = "galice.root", Text_t *BkgGeantFileName = "")
157{
158 //
159 cout << "MUON_recoNtuple" << endl;
160 cout << "FirstEvent " << FirstEvent << endl;
161 cout << "LastEvent " << LastEvent << endl;
162 cout << "RecGeantHits " << RecGeantHits << endl;
163 cout << "FileName ``" << FileName << "''" << endl;
164 cout << "BkgGeantFileName ``" << BkgGeantFileName << "''" << endl;
165// // Dynamically link some shared libs
166// if (gClassTable->GetID("AliRun") < 0) {
167// gROOT->LoadMacro("loadlibs.C");
168// loadlibs();
169// }
170
171 // Connect the Root Galice file containing Geometry, Kine, Hits
172 // and eventually RawClusters
173 TFile *file = (TFile*) gROOT->GetListOfFiles()->FindObject(FileName);
174 if (!file) {
175 printf("\n Creating file %s\n", FileName);
176 file = new TFile(FileName);
177 }
178 else printf("\n File %s found in file list\n", FileName);
179
180 // Get AliRun object from file or create it if not on file
181 if (!gAlice) {
182 gAlice = (AliRun*) file->Get("gAlice");
183 if (gAlice) printf("AliRun object found on file\n");
184 if (!gAlice) {
185 printf("\n Create new gAlice object");
186 gAlice = new AliRun("gAlice","Alice test program");
187 }
188 }
189
190 // Initializations
191 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
192 AliMUONEventReconstructor *Reco = new AliMUONEventReconstructor();
193
194 Reco->SetRecGeantHits(RecGeantHits);
195
196 // The right place for changing AliMUONEventReconstructor parameters
197 // with respect to the default ones
198// Reco->SetMaxSigma2Distance(100.0);
199 Reco->SetPrintLevel(10);
200// Reco->SetPrintLevel(1);
201// Reco->SetBendingResolution(0.0);
202// Reco->SetNonBendingResolution(0.0);
203 cout << "AliMUONEventReconstructor: actual parameters" << endl;
204 Reco->Dump();
205// gObjectTable->Print();
206
207 // Loop over events
208 for (Int_t event = FirstEvent; event <= LastEvent; event++) {
209 cout << "Event: " << event << endl;
210// AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
211 Int_t nparticles = gAlice->GetEvent(event);
212 cout << "nparticles: " << nparticles << endl;
213 // prepare background file and/or event if necessary
214 if (RecGeantHits == 1) {
215 if (event == FirstEvent) Reco->SetBkgGeantFile(BkgGeantFileName);
216 if (Reco->GetBkgGeantFile())Reco->NextBkgGeantEvent();
217 }
218 Reco->EventReconstruct();
219 // Dump current event
220 Reco->EventDump();
221 // Fill Ntuple
222 AliMUONEventRecNtupleFill(Reco, 0);
223// gObjectTable->Print();
224
225 } // Event loop
226 // Write Ntuple
227 AliMUONEventRecNtupleFill(Reco, -1);
228}