13 #include "CbmMuchHit.h"
18 #include "CbmStsTrackMatch.h"
20 #include "FairRootManager.h"
22 #include "TClonesArray.h"
24 #include "TLorentzVector.h"
39 : FairTask(name, iVerbose) {
51 (TClonesArray*) FairRootManager::Instance()->GetObject(
"MuchPoint");
52 fMuchHits = (TClonesArray*) FairRootManager::Instance()->GetObject(
"MuchHit");
54 (TClonesArray*) FairRootManager::Instance()->GetObject(
"StsTrack");
55 fMCTracks = (TClonesArray*) FairRootManager::Instance()->GetObject(
"MCTrack");
57 (TClonesArray*) FairRootManager::Instance()->GetObject(
"StsTrackMatch");
63 FairRootManager::Instance()->GetObject(
"PrimaryVertex."));
66 FairRootManager::Instance()->GetObject(
"PrimaryVertex"));
69 Error(
"CbmL1MuchFinder::ReInit",
"vertex not found!");
75 FairRootManager::Instance()->Register(
"MuchTrack",
78 IsOutputBranchPersistent(
"MuchTrack"));
88 const int MaxBranches = 50;
90 static bool first_call_murec = 1;
92 static int EventCounter = 0;
94 cout <<
" MuRec event " << EventCounter << endl;
98 if (first_call_murec) {
100 TDirectory* curdir = gDirectory;
101 histodir = gDirectory->mkdir(
"MuRec");
104 new TH1F(
"NBranches",
"N Branches", MaxBranches, 0, MaxBranches);
109 vector<CbmL1MuchHit> vMuchHits;
111 for (
int ih = 0; ih < NHits; ih++) {
112 CbmMuchHit*
h = (CbmMuchHit*)
fMuchHits->At(ih);
114 vMuchHits.push_back(
m);
117 vector<CbmL1MuchTrack> vTracks;
123 for (
int itr = 0; itr < NStsTracks; itr++) {
126 if (sts->GetNStsHits() + sts->GetNMvdHits() < 4)
continue;
132 Int_t mcTrackID =
m->GetMCTrackId();
133 if (mcTrackID < 0)
continue;
135 if (!mcTrack)
continue;
136 if (abs(mcTrack->
GetPdgCode()) != 13)
continue;
144 Branches[0].
StsID = itr;
145 Branches[0].
NHits = 0;
150 Branches[0].
vHits.clear();
152 for (
int ist = 0; ist < MuNStations; ist++) {
154 int NBranchesOld = NBranches;
156 for (
int ibr = 0; ibr < NBranchesOld; ibr++) {
163 if (1. < 0.5 *
fabs(tr.
T[4]))
176 for (
int ih = 0; ih < NHits; ih++) {
178 if (
h.iStation != ist)
continue;
181 sqrt(
h.FitPoint.x *
h.FitPoint.x +
h.FitPoint.y *
h.FitPoint.y
182 +
h.FitPoint.z *
h.FitPoint.z);
183 double hp = 1. /
fabs(tr.
T[4]);
185 hl *
sqrt(1. - 0.1057 * 0.1057 / (hp * hp)) / 29.9792458;
186 if (
h.time - texp > 1.0)
continue;
188 double dx = tr.
T[0] -
h.FitPoint.x;
189 double dy = tr.
T[1] -
h.FitPoint.y;
190 double c0 = tr.
C[0] +
h.FitPoint.V[0];
191 double c1 = tr.
C[1] +
h.FitPoint.V[1];
192 double c2 = tr.
C[2] +
h.FitPoint.V[2];
193 double chi2 = 0.5 * (dx * dx * c0 - 2 * dx * dy * c1 + dy * dy * c2)
194 / (c0 * c2 - c1 * c1);
195 if (chi2 <= 20.) NewHits.push_back(ih);
197 int nnew = NewHits.size();
198 for (
int ih = 1; ih < nnew; ih++) {
199 if (NBranches >= MaxBranches)
break;
212 double qp0 = tr.
T[4];
213 h.Filter(tr, 1, qp0);
219 for (
int ibr = 1; ibr < NBranches; ibr++) {
220 if ((Branches[ibr].NHits > Branches[bestbr].NHits)
221 || (Branches[ibr].
NHits == Branches[bestbr].
NHits)
222 && (Branches[ibr].chi2 < Branches[bestbr].chi2))
225 vTracks.push_back(Branches[bestbr]);
230 Int_t mcTrackID =
m->GetMCTrackId();
231 if (mcTrackID < 0)
continue;
233 if (!mcTrack)
continue;
238 int NTracks = vTracks.size();
239 cout <<
"NTracks=" << NTracks << endl;
242 vector<CbmL1MuchTrack*> vpTracks;
243 for (
int i = 0;
i < NTracks;
i++)
244 vpTracks.push_back(&(vTracks[
i]));
249 for (
int it = 0; it < NTracks; it++) {
256 for (
int ih = 0; ih < tr.
NHits; ih++)
257 if (tr.
vHits[ih]->busy) nbusy++;
258 if (0 && nbusy > 2) {
270 MuchTrack->SetMuchTrack(&tp);
271 MuchTrack->SetStsTrackID(tr.
StsID);
273 for (vector<CbmL1MuchHit*>::iterator
i = tr.
vHits.begin();
276 if (++nh > 30)
break;
277 MuchTrack->AddHitIndex((*i)->index);
279 MuchTrack->SetNMissedHits(tr.
NMissed);
282 for (
int ih = 0; ih < tr.
NHits; ih++)
283 tr.
vHits[ih]->busy = 1;
286 if (EventCounter < 100 && EventCounter % 10 == 0
287 || EventCounter >= 100 && EventCounter % 100 == 0)
294 TFile HistoFile(
"MuRec.root",
"RECREATE");
300 if (!obj->IsFolder())
303 TDirectory* cur = gDirectory;
304 TDirectory* sub = cur->mkdir(obj->GetName());
306 TList* listSub = ((TDirectory*) obj)->GetList();
308 while (TObject* obj1 = it())