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>
30 #include "AliHeader.h"
34 #include "AliMUONEventReconstructor.h"
35 #include "AliMUONTrack.h"
36 #include "AliMUONTrackHit.h"
37 #include "AliMUONTrackParam.h"
39 // Classes for Ntuple ////////////////////////////////////////////////////
41 class AliMUONTrackRecNtuple : public TObject {
43 // for direct access to members
44 Int_t fCharge; // charge of reconstructed track (+/- 1)
45 Float_t fPxRec; // Px of reconstructed track at vertex (GeV/c)
46 Float_t fPyRec; // Py of reconstructed track at vertex (GeV/c)
47 Float_t fPzRec; // Pz of reconstructed track at vertex (GeV/c)
48 Float_t fZRec; // Z of reconstructed track at vertex (cm)
49 Float_t fZRec1; // Z of reconstructed track at first hit (cm)
50 Int_t fNHits; // number of hits
51 Float_t fChi2; // chi2 of fit
52 Float_t fPxGen; // Px of best compatible generated track at vertex (GeV/c)
53 Float_t fPyGen; // Py of best compatible generated track at vertex (GeV/c)
54 Float_t fPzGen; // Pz of best compatible generated track at vertex (GeV/c)
55 AliMUONTrackRecNtuple(){;} // Constructor
56 virtual ~AliMUONTrackRecNtuple(){;} // Destructor
59 ClassDef(AliMUONTrackRecNtuple, 1) // AliMUONTrackRecNtuple
62 class AliMUONHeaderRecNtuple : public TObject {
64 // for direct access to members
65 Int_t fEvent; // event number
66 AliMUONHeaderRecNtuple(){;} // Constructor
67 virtual ~AliMUONHeaderRecNtuple(){;} // Destructor
70 ClassDef(AliMUONHeaderRecNtuple, 1) // AliMUONHeaderRecNtuple
73 ClassImp(AliMUONTrackRecNtuple) // Class implementation in ROOT context
74 ClassImp(AliMUONHeaderRecNtuple) // Class implementation in ROOT context
76 //__________________________________________________________________________
77 void AliMUONEventRecNtupleFill(AliMUONEventReconstructor *Reco, Int_t FillWrite = 0)
79 // Fill Ntuple for reconstructed event pointed to by "Reco"
80 // if "FillWrite" different from -1.
81 // Ntuple is created automatically before filling first event.
82 // If "FillWrite" = -1, write and close the file
84 static Bool_t firstTime = kTRUE;
86 static AliMUONHeaderRecNtuple *header = new AliMUONHeaderRecNtuple();
87 static TClonesArray *recTracks = new TClonesArray("AliMUONTrackRecNtuple",5);
91 AliMUONTrackParam *trackParam;
92 AliMUONTrackRecNtuple *recTrackNt;
93 Double_t bendingSlope, nonBendingSlope, pYZ;
95 if (FillWrite == -1) {
96 printf(">>> Writing Ntuple of reconstructed tracks\n");
97 // better to create the file before the Ntuple ????
98 TFile *file = new TFile("MUONtrackReco.root","recreate");
106 // first call: create tree for Ntuple...
107 printf(">>> Creating Ntuple of reconstructed tracks\n");
108 ntuple = new TTree("MUONtrackReco", "MUONtrackReco");
109 ntuple->Branch("Header","AliMUONHeaderRecNtuple", &header);
110 ntuple->Branch("Tracks", &recTracks);
115 header->fEvent = gAlice->GetHeader()->GetEvent();
117 TClonesArray *recoTracksPtr = Reco->GetRecTracksPtr();
118 recoTracksPtr->Compress(); // for simple loop without "Next" since no hole
119 recTracks->Clear(); // to reset the TClonesArray of tracks to be put in the ntuple
120 // Loop over reconstructed tracks
121 for (trackIndex = 0; trackIndex < Reco->GetNRecTracks(); trackIndex++) {
122 track = (AliMUONTrack*) ((*recoTracksPtr)[trackIndex]);
123 recTrackNt = (AliMUONTrackRecNtuple*)
124 new ((*recTracks)[trackIndex]) AliMUONTrackRecNtuple();
125 // track parameters at Vertex
126 trackParam = track->GetTrackParamAtVertex();
127 recTrackNt->fCharge =
128 Int_t(TMath::Sign(1., trackParam->GetInverseBendingMomentum()));
129 bendingSlope = trackParam->GetBendingSlope();
130 nonBendingSlope = trackParam->GetNonBendingSlope();
131 pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
132 recTrackNt->fPzRec = pYZ / TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
133 recTrackNt->fPxRec = recTrackNt->fPzRec * nonBendingSlope;
134 recTrackNt->fPyRec = recTrackNt->fPzRec * bendingSlope;
135 recTrackNt->fZRec = trackParam->GetZ();
136 // track parameters at first hit
137 trackParam = ((AliMUONTrackHit*)
138 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
139 recTrackNt->fZRec1 = trackParam->GetZ();
141 recTrackNt->fChi2 = track->GetFitFMin();
143 recTrackNt->fNHits = track->GetNTrackHits();
144 // track parameters at vertex of best compatible generated track:
145 // in fact muon with the right charge
146 // for (int iPart = 0; iPart < gAlice->Particles()->GetEntriesFast(); iPart++) {
147 // TParticle *particle = (TParticle*) gAlice->Particles()->UncheckedAt(iPart);
148 // if ((particle->GetPdgCode() * recTrackNt->fCharge) == -13) {
149 // recTrackNt->fPxGen = particle->Px();
150 // recTrackNt->fPyGen = particle->Py();
151 // recTrackNt->fPzGen = particle->Pz();
152 // } // commented by Gines
154 } // for (trackIndex = 0;...
156 printf(">>> Filling Ntuple of reconstructed tracks\n");
162 void MUONrecoNtuple (Int_t FirstEvent = 0, Int_t LastEvent = 0, Int_t RecGeantHits = 0, Text_t *FileName = "galice.root", Text_t *BkgGeantFileName = "")
165 cout << "MUON_recoNtuple" << endl;
166 cout << "FirstEvent " << FirstEvent << endl;
167 cout << "LastEvent " << LastEvent << endl;
168 cout << "RecGeantHits " << RecGeantHits << endl;
169 cout << "FileName ``" << FileName << "''" << endl;
170 cout << "BkgGeantFileName ``" << BkgGeantFileName << "''" << endl;
171 // // Dynamically link some shared libs
172 // if (gClassTable->GetID("AliRun") < 0) {
173 // gROOT->LoadMacro("loadlibs.C");
178 // Creating Run Loader and openning file containing Hits, Digits and RecPoints
179 AliRunLoader * RunLoader = AliRunLoader::Open(FileName,"Event","UPDATE");
180 if (RunLoader ==0x0) {
181 printf(">>> Error : Error Opening %s file \n",FileName);
184 // Loading AliRun master
185 RunLoader->LoadgAlice();
186 gAlice = RunLoader->GetAliRun();
188 // Loading MUON subsystem
189 AliMUON * MUON = (AliMUON *) gAlice->GetDetector("MUON");
190 AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
191 MUONLoader->LoadHits("READ");
192 MUONLoader->LoadRecPoints("READ");
194 Int_t ievent, nevents;
195 nevents = RunLoader->GetNumberOfEvents();
198 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
199 MUON->SetTreeAddress();
200 AliMUONEventReconstructor *Reco = new AliMUONEventReconstructor();
202 Reco->SetRecGeantHits(RecGeantHits);
204 // The right place for changing AliMUONEventReconstructor parameters
205 // with respect to the default ones
206 // Reco->SetMaxSigma2Distance(100.0);
207 Reco->SetPrintLevel(20);
208 // Reco->SetPrintLevel(1);
209 // Reco->SetBendingResolution(0.0);
210 // Reco->SetNonBendingResolution(0.0);
211 cout << "AliMUONEventReconstructor: actual parameters" << endl;
213 // gObjectTable->Print();
215 for (Int_t event = FirstEvent; event < LastEvent; event++) {
216 cout << "Event: " << event << endl;
217 RunLoader->GetEvent(event);
218 // Int_t nparticles = gAlice->GetEvent(event);
219 // cout << "nparticles: " << nparticles << endl;
220 // prepare background file and/or event if necessary
221 if (RecGeantHits == 1) {
222 if (event == FirstEvent) Reco->SetBkgGeantFile(BkgGeantFileName);
223 if (Reco->GetBkgGeantFile())Reco->NextBkgGeantEvent();
225 Reco->EventReconstruct();
226 // Dump current event
229 AliMUONEventRecNtupleFill(Reco, 0);
230 // gObjectTable->Print();
231 MUON->ResetRawClusters();
234 AliMUONEventRecNtupleFill(Reco, -1);