3 /**************************************************************************
4 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
5 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
6 * full copyright notice. *
7 **************************************************************************/
9 // Macro to visualise trackRef in MUON spectrometer
10 // (both tracker and trigger).
12 // Use muon_trackRefs(Bool_t showSimClusters) in order to run it
14 // Needs that alieve_init() is already called
16 #if !defined(__CINT__) || defined(__MAKECINT__)
18 #include "AliMUONClusterStoreV2.h"
19 #include "AliMUONRawClusterV2.h"
20 #include "AliMUONVCluster.h"
21 #include "AliMUONConstants.h"
22 #include "AliMUONRecoParam.h"
23 #include "AliMUONCDB.h"
25 #include "AliRunLoader.h"
27 #include "AliTrackReference.h"
29 #include "EveBase/AliEveMagField.h"
30 #include "EveBase/AliEveTrack.h"
31 #include "EveBase/AliEveEventManager.h"
33 #include <TEveManager.h>
35 #include <TEveTrack.h>
36 #include <TEvePointSet.h>
37 #include <TEveVSDStructs.h>
38 #include <TEveTrackPropagator.h>
40 #include <TClonesArray.h>
42 #include <TParticle.h>
48 //______________________________________________________________________________
49 void muon_trackRef_propagator_setup(TEveTrackPropagator* trkProp, Bool_t showVertex)
52 trkProp->SetMagFieldObj(new AliEveMagField);
53 trkProp->SetStepper(TEveTrackPropagator::kRungeKutta);
55 // set propagation range
56 trkProp->SetMaxR(500.);
57 trkProp->SetMaxZ(-AliMUONConstants::DefaultChamberZ(13)+3.5);
59 // go through pathmarks
60 trkProp->SetFitDaughters(kFALSE);
61 trkProp->SetFitReferences(kTRUE);
62 trkProp->SetFitDecay(kTRUE);
63 trkProp->SetFitCluster2Ds(kFALSE);
65 // Render first vertex if required
68 trkProp->SetRnrFV(kTRUE);
69 trkProp->RefFVAtt().SetMarkerSize(0.5);
70 trkProp->RefFVAtt().SetMarkerColor(kRed);
74 //______________________________________________________________________________
75 Bool_t isReconstructible(Bool_t* chHit)
77 // load recoParam from OCDB
78 static AliMUONRecoParam* gRecoParam = 0x0;
79 static UInt_t gRequestedStationMask = 0;
80 static Bool_t gRequest2ChInSameSt45 = kFALSE;
83 gRecoParam = AliMUONCDB::LoadRecoParam();
84 if (!gRecoParam) exit(-1);
85 // compute the mask of requested stations
86 gRequestedStationMask = 0;
87 for (Int_t i = 0; i < 5; i++) if (gRecoParam->RequestStation(i)) gRequestedStationMask |= ( 1 << i );
88 // get whether a track need 2 chambers hit in the same station (4 or 5) or not to be reconstructible
89 gRequest2ChInSameSt45 = !gRecoParam->MakeMoreTrackCandidates();
92 // check which chambers are hit
93 UInt_t presentStationMask(0);
94 Int_t nChHitInSt4 = 0, nChHitInSt5 = 0;
95 for (Int_t ich=0; ich<10; ich++)
97 if (!chHit[ich]) continue;
99 presentStationMask |= ( 1 << ist );
100 if (ist == 3) nChHitInSt4++;
101 if (ist == 4) nChHitInSt5++;
104 // at least one cluster per requested station
105 if ((gRequestedStationMask & presentStationMask) != gRequestedStationMask) return kFALSE;
107 // 2 chambers hit in the same station (4 or 5)
108 if (gRequest2ChInSameSt45) return (nChHitInSt4 == 2 || nChHitInSt5 == 2);
109 // or 2 chambers hit in station 4 & 5 together
110 else return (nChHitInSt4+nChHitInSt5 >= 2);
113 //______________________________________________________________________________
114 void add_muon_trackRefs(AliStack* stack, TTree* treeTR, TEveTrackList* reco, TEveTrackList* other,
115 TEvePointSet* RecoClusters, TEvePointSet* OtherClusters)
117 TClonesArray* trackRefs = 0;
118 treeTR->SetBranchAddress("TrackReferences", &trackRefs);
119 Int_t nSimTracks = stack->GetNtrack();
120 AliMUONClusterStoreV2 clusters;
121 TClonesArray clustersTrigger("AliMUONRawClusterV2", 10);
123 // loop over simulated track
124 for (Int_t itr = 0; itr < nSimTracks; itr++)
126 treeTR->GetEntry(stack->TreeKEntry(itr));
127 Int_t nTrackRefs = trackRefs->GetEntriesFast();
128 if (nTrackRefs <= 0) continue;
130 TEveTrack* track = 0x0;
132 for (Int_t ich=0; ich<10; ich++) chHit[ich] = kFALSE;
134 // loop over simulated track hits
135 for (Int_t itrR = 0; itrR < nTrackRefs; ++itrR)
137 AliTrackReference* atr = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(itrR));
139 // skip trackRefs not in MUON
140 if (atr->DetectorId() != AliTrackReference::kMUON) continue;
142 // record chamber hit
143 Int_t detElemId = atr->UserId();
144 Int_t chamberId = detElemId / 100 - 1;
145 if (chamberId < 0) continue;
146 if (chamberId < 10) chHit[chamberId] = kTRUE;
148 // produce eve track if not already done
151 TParticle* p = stack->Particle(itr);
152 track = new AliEveTrack(p, itr, 0x0);
153 track->SetName(Form("%s [%d]", p->GetName(), itr));
154 track->SetStdTitle();
155 track->SetSourceObject(p);
158 clustersTrigger.Clear("C");
162 track->AddPathMark(TEvePathMark(TEvePathMark::kReference,
163 TEveVector(atr->X(), atr->Y(), atr->Z()),
164 TEveVector(atr->Px(), atr->Py(), atr->Pz()),
167 // produce clusters if required
168 if (RecoClusters || OtherClusters)
173 // produce a new cluster on that DE or update existing one
174 AliMUONVCluster* cl = 0x0;
176 do cl = clusters.FindObject(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, ++clNum));
177 while (cl && cl->GetNDigits() == 2);
179 cl->SetXYZ((cl->GetX() + atr->X()) / 2., (cl->GetY() + atr->Y()) / 2., (cl->GetZ() + atr->Z()) / 2.);
183 cl = clusters.Add(chamberId, detElemId, clNum);
184 cl->SetXYZ(atr->X(), atr->Y(), atr->Z());
186 cl->AddDigitId((UInt_t)itrR);
190 AliMUONVCluster* cl = new(clustersTrigger[clustersTrigger.GetLast()+1]) AliMUONRawClusterV2();
191 cl->SetXYZ(atr->X(), atr->Y(), atr->Z());
198 track->SortPathMarksByTime();
199 // stop track propagation at last path mark
200 track->RefPathMarks().back().fType = TEvePathMark::kDecay;
202 // add the track and trackRefs to proper lists
203 if (isReconstructible(chHit)) {
204 track->SetPropagator(reco->GetPropagator());
205 track->SetAttLineAttMarker(reco);
206 reco->AddElement(track);
212 TIter next(clusters.CreateIterator());
213 gROOT->ProcessLine(Form("add_muon_clusters((TIter*)%p, (TEvePointSet*)%p);",&next, RecoClusters));
215 TIter next2(clustersTrigger.MakeIterator());
216 gROOT->ProcessLine(Form("add_muon_clusters((TIter*)%p, (TEvePointSet*)%p);",&next2, RecoClusters));
220 track->SetPropagator(other->GetPropagator());
221 track->SetAttLineAttMarker(other);
222 other->AddElement(track);
228 TIter next(clusters.CreateIterator());
229 gROOT->ProcessLine(Form("add_muon_clusters((TIter*)%p, (TEvePointSet*)%p);",&next, OtherClusters));
231 TIter next2(clustersTrigger.MakeIterator());
232 gROOT->ProcessLine(Form("add_muon_clusters((TIter*)%p, (TEvePointSet*)%p);",&next2, OtherClusters));
240 //______________________________________________________________________________
241 void muon_trackRefs(Bool_t showSimClusters)
243 // load kinematics and trackRefs
244 AliRunLoader* rl = AliEveEventManager::AssertRunLoader();
245 rl->LoadKinematics();
246 AliStack* stack = rl->Stack();
249 TTree* treeTR = rl->TreeTR();
253 TEveElementList* trackCont = new TEveElementList("Sim MUON Tracks");
255 TEveTrackList* reco = new TEveTrackList("reconstructible");
256 reco->SetRnrPoints(kFALSE);
257 reco->SetRnrLine(kTRUE);
258 reco->SetLineColor(kRed);
259 reco->SetLineStyle(2);
260 muon_trackRef_propagator_setup(reco->GetPropagator(), kTRUE);
261 trackCont->AddElement(reco);
263 TEveTrackList* other = new TEveTrackList("others");
264 other->SetRnrPoints(kFALSE);
265 other->SetRnrLine(kTRUE);
266 other->SetLineColor(kWhite);
267 other->SetLineStyle(3);
268 muon_trackRef_propagator_setup(other->GetPropagator(), kFALSE);
269 trackCont->AddElement(other);
272 TEveElementList* clusterCont = 0x0;
273 TEvePointSet* RecoClusters = 0x0;
274 TEvePointSet* OtherClusters = 0x0;
277 clusterCont = new TEveElementList("Sim MUON Clusters");
279 RecoClusters = new TEvePointSet(1000);
280 RecoClusters->SetName("Reconstructibles");
281 RecoClusters->SetPickable(kFALSE);
282 RecoClusters->SetMarkerStyle(2);
283 RecoClusters->SetMarkerColor(kRed);
284 RecoClusters->SetMarkerSize(0.5);
285 clusterCont->AddElement(RecoClusters);
287 OtherClusters = new TEvePointSet(10000);
288 OtherClusters->SetName("Others");
289 OtherClusters->SetPickable(kFALSE);
290 OtherClusters->SetMarkerStyle(2);
291 OtherClusters->SetMarkerColor(kWhite);
292 OtherClusters->SetMarkerSize(0.5);
293 clusterCont->AddElement(OtherClusters);
295 TEveUtil::LoadMacro("muon_clusters.C+");
298 // add tracks to the proper list and propagate them. Add also clusters if required.
299 add_muon_trackRefs(stack, treeTR, reco, other, RecoClusters, OtherClusters);
302 trackCont->SetTitle(Form("N=%d", reco->NumChildren()+other->NumChildren()));
303 reco->SetTitle(Form("N=%d",reco->NumChildren()));
304 other->SetTitle(Form("N=%d",other->NumChildren()));
307 clusterCont->SetTitle(Form("N=%d",RecoClusters->GetLastPoint()+OtherClusters->GetLastPoint()+2));
308 RecoClusters->SetTitle(Form("N=%d",RecoClusters->GetLastPoint()+1));
309 OtherClusters->SetTitle(Form("N=%d",OtherClusters->GetLastPoint()+1));
312 // add graphic containers
313 gEve->DisableRedraw();
314 gEve->AddElement(trackCont);
315 if (clusterCont) gEve->AddElement(clusterCont);
316 gEve->EnableRedraw();