1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
20 // Macro MUONrecoNtuple.C (TO BE COMPILED)
21 // for testing the C++ reconstruction code
22 // and producing an Ntuple with reconstructed tracks
23 // in output file "MUONtrackReco.root".
24 // An example for using the Ntuple is in the macro MUONmassPlot.C
27 // FirstEvent (default 0)
28 // LastEvent (default 0)
29 // RecGeantHits (1 to reconstruct GEANT hits) (default 0)
30 // FileName (for signal) (default "galice.root")
31 // BkgGeantFileName (for background),
32 // needed only if RecGeantHits = 1 and background to be added
34 // IMPORTANT NOTICE FOR USERS:
35 // under "root" or "root.exe", execute the following commands:
36 // 1. "gSystem->SetIncludePath("-I$ALICE_ROOT/MUON -I$ALICE_ROOT/STEER -I$ROOTSYS/include")" to get the right path at compilation time
37 // 2. ".x loadlibs.C" to load the shared libraries
38 // 3. ".x MUONrecoNtuple.C+()" with the right arguments, without forgetting the "+" which implies the compilation of the macro before its execution
42 #include <TClassTable.h>
43 #include <TClonesArray.h>
45 #include <TParticle.h>
49 #include "AliHeader.h"
53 #include "AliMUONEventReconstructor.h"
54 #include "AliMUONTrack.h"
55 #include "AliMUONTrackHit.h"
56 #include "AliMUONTrackParam.h"
58 // Classes for Ntuple ////////////////////////////////////////////////////
60 class AliMUONTrackRecNtuple : public TObject {
62 // for direct access to members
63 Int_t fCharge; // charge of reconstructed track (+/- 1)
64 Float_t fPxRec; // Px of reconstructed track at vertex (GeV/c)
65 Float_t fPyRec; // Py of reconstructed track at vertex (GeV/c)
66 Float_t fPzRec; // Pz of reconstructed track at vertex (GeV/c)
67 Float_t fZRec; // Z of reconstructed track at vertex (cm)
68 Float_t fZRec1; // Z of reconstructed track at first hit (cm)
69 Int_t fNHits; // number of hits
70 Float_t fChi2; // chi2 of fit
71 Float_t fPxGen; // Px of best compatible generated track at vertex (GeV/c)
72 Float_t fPyGen; // Py of best compatible generated track at vertex (GeV/c)
73 Float_t fPzGen; // Pz of best compatible generated track at vertex (GeV/c)
74 AliMUONTrackRecNtuple(){;} // Constructor
75 virtual ~AliMUONTrackRecNtuple(){;} // Destructor
78 ClassDef(AliMUONTrackRecNtuple, 1) // AliMUONTrackRecNtuple
81 class AliMUONHeaderRecNtuple : public TObject {
83 // for direct access to members
84 Int_t fEvent; // event number
85 AliMUONHeaderRecNtuple(){;} // Constructor
86 virtual ~AliMUONHeaderRecNtuple(){;} // Destructor
89 ClassDef(AliMUONHeaderRecNtuple, 1) // AliMUONHeaderRecNtuple
92 ClassImp(AliMUONTrackRecNtuple) // Class implementation in ROOT context
93 ClassImp(AliMUONHeaderRecNtuple) // Class implementation in ROOT context
95 //__________________________________________________________________________
96 void AliMUONEventRecNtupleFill(AliMUONEventReconstructor *Reco, Int_t FillWrite = 0)
98 // Fill Ntuple for reconstructed event pointed to by "Reco"
99 // if "FillWrite" different from -1.
100 // Ntuple is created automatically before filling first event.
101 // If "FillWrite" = -1, write and close the file
103 static Bool_t firstTime = kTRUE;
104 static TTree *ntuple;
105 static AliMUONHeaderRecNtuple *header = new AliMUONHeaderRecNtuple();
106 static TClonesArray *recTracks = new TClonesArray("AliMUONTrackRecNtuple",5);
110 AliMUONTrackParam *trackParam;
111 AliMUONTrackRecNtuple *recTrackNt;
112 Double_t bendingSlope, nonBendingSlope, pYZ;
114 if (FillWrite == -1) {
115 printf(">>> Writing Ntuple of reconstructed tracks\n");
116 // better to create the file before the Ntuple ????
117 TFile *file = new TFile("MUONtrackReco.root","recreate");
125 // first call: create tree for Ntuple...
126 printf(">>> Creating Ntuple of reconstructed tracks\n");
127 ntuple = new TTree("MUONtrackReco", "MUONtrackReco");
128 ntuple->Branch("Header","AliMUONHeaderRecNtuple", &header);
129 ntuple->Branch("Tracks", &recTracks);
134 header->fEvent = gAlice->GetHeader()->GetEvent();
136 TClonesArray *recoTracksPtr = Reco->GetRecTracksPtr();
137 recoTracksPtr->Compress(); // for simple loop without "Next" since no hole
138 recTracks->Clear(); // to reset the TClonesArray of tracks to be put in the ntuple
139 // Loop over reconstructed tracks
140 for (trackIndex = 0; trackIndex < Reco->GetNRecTracks(); trackIndex++) {
141 track = (AliMUONTrack*) ((*recoTracksPtr)[trackIndex]);
142 recTrackNt = (AliMUONTrackRecNtuple*)
143 new ((*recTracks)[trackIndex]) AliMUONTrackRecNtuple();
144 // track parameters at Vertex
145 trackParam = track->GetTrackParamAtVertex();
146 recTrackNt->fCharge =
147 Int_t(TMath::Sign(1., trackParam->GetInverseBendingMomentum()));
148 bendingSlope = trackParam->GetBendingSlope();
149 nonBendingSlope = trackParam->GetNonBendingSlope();
150 pYZ = 1/TMath::Abs(trackParam->GetInverseBendingMomentum());
151 recTrackNt->fPzRec = pYZ / TMath::Sqrt(1.0 + bendingSlope * bendingSlope);
152 recTrackNt->fPxRec = recTrackNt->fPzRec * nonBendingSlope;
153 recTrackNt->fPyRec = recTrackNt->fPzRec * bendingSlope;
154 recTrackNt->fZRec = trackParam->GetZ();
155 // track parameters at first hit
156 trackParam = ((AliMUONTrackHit*)
157 (track->GetTrackHitsPtr()->First()))->GetTrackParam();
158 recTrackNt->fZRec1 = trackParam->GetZ();
160 recTrackNt->fChi2 = track->GetFitFMin();
162 recTrackNt->fNHits = track->GetNTrackHits();
163 printf("test> Px %f Py %f Pz %f \n", recTrackNt->fPxRec, recTrackNt->fPyRec, recTrackNt->fPzRec);
164 // track parameters at vertex of best compatible generated track:
165 // in fact muon with the right charge
166 TTree* mtreeK=gAlice->TreeK();
167 TBranch *brparticle = mtreeK->GetBranch("Particles");
168 Int_t nPart = brparticle->GetEntries();
169 TParticle *particle = new TParticle();
170 mtreeK->SetBranchAddress("Particles",&particle);
171 for (Int_t iPart = 0; iPart < nPart; iPart++) {
172 brparticle->GetEntry(iPart);
173 //cout << "Code Particle: " << particle->GetPdgCode() << "\n";
174 if ((particle->GetPdgCode() * recTrackNt->fCharge) == -13) {
175 recTrackNt->fPxGen = particle->Px();
176 recTrackNt->fPyGen = particle->Py();
177 recTrackNt->fPzGen = particle->Pz();
178 printf("Gen: Px %f Py %f Pz %f \n", recTrackNt->fPxGen, recTrackNt->fPyGen, recTrackNt->fPzGen);
181 } // for (trackIndex = 0;...
183 printf(">>> Filling Ntuple of reconstructed tracks\n");
189 void MUONrecoNtuple (Int_t FirstEvent = 0, Int_t LastEvent = 0, Int_t RecGeantHits = 0, Text_t *FileName = "galice.root", Text_t *BkgGeantFileName = "")
192 cout << "MUON_recoNtuple" << endl;
193 cout << "FirstEvent " << FirstEvent << endl;
194 cout << "LastEvent " << LastEvent << endl;
195 cout << "RecGeantHits " << RecGeantHits << endl;
196 cout << "FileName ``" << FileName << "''" << endl;
197 cout << "BkgGeantFileName ``" << BkgGeantFileName << "''" << endl;
198 // // Dynamically link some shared libs
199 // if (gClassTable->GetID("AliRun") < 0) {
200 // gROOT->LoadMacro("loadlibs.C");
205 // Creating Run Loader and openning file containing Hits, Digits and RecPoints
206 AliRunLoader * RunLoader = AliRunLoader::Open(FileName,"Event","UPDATE");
207 if (RunLoader ==0x0) {
208 printf(">>> Error : Error Opening %s file \n",FileName);
211 // Loading AliRun master
212 RunLoader->LoadgAlice();
213 gAlice = RunLoader->GetAliRun();
214 RunLoader->LoadKinematics("READ");
216 // Loading MUON subsystem
217 AliMUON * MUON = (AliMUON *) gAlice->GetDetector("MUON");
218 AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
219 MUONLoader->LoadHits("READ");
220 MUONLoader->LoadRecPoints("READ");
222 Int_t ievent, nevents;
223 nevents = RunLoader->GetNumberOfEvents();
226 // AliMUON *MUON = (AliMUON*) gAlice->GetModule("MUON"); // necessary ????
227 MUON->SetTreeAddress();
228 AliMUONEventReconstructor *Reco = new AliMUONEventReconstructor();
230 Reco->SetRecGeantHits(RecGeantHits);
232 // The right place for changing AliMUONEventReconstructor parameters
233 // with respect to the default ones
234 // Reco->SetMaxSigma2Distance(100.0);
235 // Reco->SetPrintLevel(20);
236 Reco->SetPrintLevel(1);
237 // Reco->SetBendingResolution(0.0);
238 // Reco->SetNonBendingResolution(0.0);
239 cout << "AliMUONEventReconstructor: actual parameters" << endl;
241 // gObjectTable->Print();
243 if (LastEvent>nevents) LastEvent = nevents;
244 for (Int_t event = FirstEvent; event < LastEvent; event++) {
245 cout << "Event: " << event << endl;
246 RunLoader->GetEvent(event);
247 // Int_t nparticles = gAlice->GetEvent(event);
248 // cout << "nparticles: " << nparticles << endl;
249 // prepare background file and/or event if necessary
250 if (RecGeantHits == 1) {
251 if (event == FirstEvent) Reco->SetBkgGeantFile(BkgGeantFileName);
252 if (Reco->GetBkgGeantFile())Reco->NextBkgGeantEvent();
254 Reco->EventReconstruct();
255 // Dump current event
258 AliMUONEventRecNtupleFill(Reco, 0);
259 // gObjectTable->Print();
260 MUON->ResetRawClusters();
263 AliMUONEventRecNtupleFill(Reco, -1);