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
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
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
23 #include <TClassTable.h>
24 #include <TClonesArray.h>
26 #include <TParticle.h>
32 #include "AliMUONEventReconstructor.h"
33 #include "AliMUONTrack.h"
34 #include "AliMUONTrackHit.h"
35 #include "AliMUONTrackParam.h"
37 // Classes for Ntuple ////////////////////////////////////////////////////
39 class AliMUONTrackRecNtuple : public TObject {
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
57 ClassDef(AliMUONTrackRecNtuple, 1) // AliMUONTrackRecNtuple
60 class AliMUONHeaderRecNtuple : public TObject {
62 // for direct access to members
63 Int_t fEvent; // event number
64 AliMUONHeaderRecNtuple(){;} // Constructor
65 virtual ~AliMUONHeaderRecNtuple(){;} // Destructor
68 ClassDef(AliMUONHeaderRecNtuple, 1) // AliMUONHeaderRecNtuple
71 ClassImp(AliMUONTrackRecNtuple) // Class implementation in ROOT context
72 ClassImp(AliMUONHeaderRecNtuple) // Class implementation in ROOT context
74 //__________________________________________________________________________
75 void AliMUONEventRecNtupleFill(AliMUONEventReconstructor *Reco, Int_t FillWrite = 0)
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
82 static Bool_t firstTime = kTRUE;
84 static AliMUONHeaderRecNtuple *header = new AliMUONHeaderRecNtuple();
85 static TClonesArray *recTracks = new TClonesArray("AliMUONTrackRecNtuple",5);
89 AliMUONTrackParam *trackParam;
90 AliMUONTrackRecNtuple *recTrackNt;
91 Double_t bendingSlope, nonBendingSlope, pYZ;
93 if (FillWrite == -1) {
94 // better to create the file before the Ntuple ????
95 TFile *file = new TFile("MUONtrackReco.root","recreate");
103 // first call: create tree for Ntuple...
104 ntuple = new TTree("MUONtrackReco", "MUONtrackReco");
105 ntuple->Branch("Header","AliMUONHeaderRecNtuple", &header);
106 ntuple->Branch("Tracks", &recTracks);
110 header->fEvent = gAlice->GetHeader()->GetEvent();
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();
136 recTrackNt->fChi2 = track->GetFitFMin();
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();
149 } // for (trackIndex = 0;...
156 void MUONrecoNtuple (Int_t FirstEvent = 0, Int_t LastEvent = 0, Int_t RecGeantHits = 0, Text_t *FileName = "galice.root", Text_t *BkgGeantFileName = "")
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");
171 // Connect the Root Galice file containing Geometry, Kine, Hits
172 // and eventually RawClusters
173 TFile *file = (TFile*) gROOT->GetListOfFiles()->FindObject(FileName);
175 printf("\n Creating file %s\n", FileName);
176 file = new TFile(FileName);
178 else printf("\n File %s found in file list\n", FileName);
180 // Get AliRun object from file or create it if not on file
182 gAlice = (AliRun*) file->Get("gAlice");
183 if (gAlice) printf("AliRun object found on file\n");
185 printf("\n Create new gAlice object");
186 gAlice = new AliRun("gAlice","Alice test program");
191 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
192 AliMUONEventReconstructor *Reco = new AliMUONEventReconstructor();
194 Reco->SetRecGeantHits(RecGeantHits);
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;
205 // gObjectTable->Print();
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();
218 Reco->EventReconstruct();
219 // Dump current event
222 AliMUONEventRecNtupleFill(Reco, 0);
223 // gObjectTable->Print();
227 AliMUONEventRecNtupleFill(Reco, -1);