BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcTrackListCsmc.cxx
Go to the documentation of this file.
1//
2// $Id: MdcTrackListCsmc.cxx,v 1.7 2008/04/01 03:14:36 zhangy Exp $
3//
5#include <math.h>
6#include <iostream>
13#include "TrkBase/TrkHitList.h"
15#include "TrkBase/TrkRecoTrk.h"
16#include "TrkBase/TrkFit.h"
19#include "TrkBase/TrkErrCode.h"
21
22//yzhang hist cut
23#include "AIDA/IHistogram1D.h"
24//extern AIDA::IHistogram1D* g_tkChi2;
25//zhangy hist cut
26
27// IOS_USING_DECLARATION_MARKER - BaBar iostreams migration, do not touch this line!
28using std::cout;
29using std::endl;
30
31// End Implementation Dependencies -------------------------------------
32
33// *************************************************************************
35 MdcTrackListBase(tkPar) {
36// *************************************************************************
37 return;
38 }
39
40// *************************************************************************
42// *************************************************************************
43
44// *************************************************************************
46 const MdcDetector* gm,
47 TrkContext& context, double t0) {
48// *************************************************************************
49 // Forms tracks out of list of superlayer segments
50 int nTracks = 0;
51 // Create empty list of stereo segs (to save time)
52 MdcSegGrouperSt stereoSegs(gm,tkParam.lPrint);
53 // *** Create r-phi track
54
55 // Create list of axial segments, treated as on straight tracks
56 MdcSegGrouperCsmc straightSegs(gm, tkParam.lPrint);
57 straightSegs.fillWithSegs(segs);
58 //std::cout<< "after straight fill " << std::endl;
59 //segs->plot();//yzhang debug
60 MdcSeg *seed;
61 int goodOnly = 1;
62 MdcTrack* trialTrack = 0;
63 while (1) {
64 seed = segs->getSeed(0,goodOnly);
65 if (seed == 0 && goodOnly == 1) {
66 segs->resetSeed(gm);
67 goodOnly = 0;
68 continue;
69 }
70 else if (seed == 0 && goodOnly == 0) {
71 break;
72 }
73 delete trialTrack;
74 trialTrack = 0;
75 int success = straightSegs.combineSegs(trialTrack, seed,
76 context, t0, tkParam.maxSegChisqO);
77 if (!success) {
78 //std::cout<< " MdcTrackListCsmc::combineSegs not successed!" << std::endl;
79 continue;
80 }
81
82 if (tkParam.lPrint > 1) {
83 trialTrack->track().printAll(cout);
84 }
85 // *** End r-phi track-finding
86
87 // *** Add stereo to taste
88 stereoSegs.fillWithSegs(segs, trialTrack);
89
90 success = stereoSegs.combineSegs(trialTrack, 0, context, t0,
92 if (success) {
93 // Finish 3-d track;
94 success = finish3d(trialTrack->track());
95 // success = finish3d(trialTrack->track()); // GSciolla: try to repeat
96 }
97 if (!success) {
98 //std::cout<< " MdcTrackListCsmc::finish3d not successed!" << std::endl;
99 continue;
100 }
101
102 if (tkParam.lPrint > 1) {
103 trialTrack->track().printAll(cout);
104 }
105
106 nTracks++;
107 append(trialTrack); // Add to list of Tracks
108 trialTrack = 0;
109
110 } // end while(1)
111 delete trialTrack;
112
113
114 //cout << " Number of Tracks found= " << nTracks ;
115 //cout << " " << endl;
116 return nTracks;
117}
118
119// ************************************************************************
121// ************************************************************************
122 int success = 0;
123 int nParamFit = 0 ;
124
125 TrkErrCode fitResult;
126
127 // ------------------------
128 // 4 param fit (line)
129 // ------------------------
130 nParamFit = 4;
131 TrkLineMaker makeFit;
132 makeFit.changeFit(trk);
133 makeFit.setFlipAndDrop(trk, true, true);
134 //setCosmic(&trk); // set hot to cosmics OBSOLETE! REMOVE!
135 fitResult = trk.hits()->fit();
136 makeFit.setFlipAndDrop(trk, false, false);
137
138 // ---------------------------------------------------------------
139 // Are there some TDC that can be replaced with later measurements? ( beginning)
140 // ---------------------------------------------------------------
141 // Note to Sciolla: multiple hits commented out for now OK! I will put it back later...
142 /* if( _flags.useMultipleHits ) {
143 int NHITS = trk.nHit();
144
145 if (fitResult.success()) {
146 int ifirst = 0;
147 for (int ihot = 0; ihot < NHITS ; ihot++) {
148
149 MdcHitOnTrack* ahot = (MdcHitOnTrack*)trk.hitAList()[ihot];
150 double firstTime = ahot->mdcHit()->rawTime(0);
151
152 // Get the list of times for this Digi
153 const MdcDigi* tmpDigi = ahot->mdcHit()->digi() ;
154// int nTDChits = tmpDigi->getTdcTimeAList()->length() ;
155 int nTDChits = tmpDigi->tmdcits() ;
156
157 double newTime=0. ;
158
159 for( int il = 1; il<nTDChits ; il++){
160
161 // get the time corresponding to this doca ---> distance to time
162 newTime = tmpDigi->TdcTime(il);
163 double newDrift = ahot->layer()->timeToDistance(newTime);
164
165 double tmp_doca = ahot->dcaToWire();
166 double new_diff = fabs(fabs(tmp_doca)-fabs(newDrift));
167 double tmp_drift = ahot->drift();
168 double tmp_drift2 =
169 ahot->layer()->timeToDistance(tmpDigi->TdcTime(0));
170 double old_diff = fabs(fabs(tmp_doca)-fabs(tmp_drift2));
171
172 if( ((old_diff-new_diff)>0.1) // new time better then old of at least 1 mm
173 && (new_diff<=0.8) ) { // and newresid < 2 mm
174 // if(_flags.debug) {
175 if(1) {
176
177 if(ifirst==0) {
178 ifirst = 1 ;
179 cout <<" nHits | time1 |fittim | time2 | doca(mm) | drift1 "
180 <<" drift1(rec) | drift2 | layer | wire | isActive"
181 << " | chi2 | nactive" << endl;
182 }
183
184 int isAct = 1 ;
185 if (!ahot->isActive()) {
186 isAct = 0 ;
187 // cout<< " >> " ;
188 // cout << "This hit is not active " << endl ;
189 }
190
191 cout << " " << nTDChits
192 << " " << tmpDigi->TdcTime(0)
193 << " " << ahot->fitTime()
194 << " " << newTime
195 << " " << tmp_doca*10
196 << " " << tmp_drift*10
197 << " " << tmp_drift2*10
198 << " " << newDrift*10
199 << " " << ahot->layer()->layNum()
200 << " " << ahot->wire()
201 << " " << isAct
202 << " " << trk.chisq()
203 << " " << trk.nActive()
204 << endl;
205
206 cout << " old/new diff (mm) = " << old_diff*10
207 << " | " << new_diff*10
208 << endl ;
209 }
210
211 ahot->setTimeIndex(il) ;
212 // cout << "new rawtime ="
213 // << ahot->mdcHit()->rawTime(0)<< endl ; // check the new value
214
215
216 // store results in ntuple to see improvements ... before ...
217 HepTuple* tupleMultHits = _manager->ntuple("multiHits");
218
219 tupleMultHits->column("ch2Dof1", trk.chisq()/(trk.nActive() - 4));
220 tupleMultHits->column("nActiv1", trk.nActive());
221 tupleMultHits->column("resid1",ahot->resid());
222 tupleMultHits->column("doca1",ahot->resid()+ahot->drift());
223 tupleMultHits->column("time1", ahot->fitTime() );
224 tupleMultHits->column("rawtime1", ahot->mdcHit()->rawTime(il) );
225
226 // - make the hit active and usable
227 ahot->setActivity(true);
228
229 // now refit the track ...
230 fitResult = trk.fit();
231
232 // store results in ntuple to see improvements ... after ...
233 tupleMultHits->column("ch2Dof2", trk.chisq()/(trk.nActive() - 4));
234 tupleMultHits->column("nActiv2", trk.nActive());
235 tupleMultHits->column("resid2",ahot->resid());
236 tupleMultHits->column("doca2",ahot->resid()+ahot->drift());
237 tupleMultHits->column("time2", ahot->fitTime() );
238 tupleMultHits->column("rawtime2", ahot->mdcHit()->rawTime(il) );
239 tupleMultHits->dumpData();
240 }
241 }
242 }
243 }
244 } // Are there some TDC that can be replaced with later measurements? (end)
245 */
246
247 const TrkFit* tkFit = trk.fitResult();
248 double chisqperDOF = 0.;
249 if (fitResult.success()) {
250 int nDOF = tkFit->nActive() - nParamFit;
251 if (nDOF > nParamFit)
252 chisqperDOF = tkFit->chisq() / nDOF;
253 else
254 chisqperDOF = tkFit->chisq();
255 int goodMatch = 1;
256 if (chisqperDOF > tkParam.maxChisq) goodMatch = 0;
257 if (tkFit->nActive() < tkParam.minHits) goodMatch = 0;
258
259 if (goodMatch) success = 1;
260 }
261
262 return success;
263}
264
265
266////--------------------------------------------------------------------
267//void MdcTrackListCsmc::setCosmic(TrkRecoTrk *recoTrk ) {
268////--------------------------------------------------------------------
269//
270 //// get list of hot and set them to cosmics
271 ////----------------------------------------
272 //// int ihot ;
273 //TrkHitList* hitList = recoTrk->hits();
274 //assert (hitList != 0);
275 //for (int layer = 1; layer <= 16; layer++) {
276 //// Look for hits in this layer
277 //TrkHitList::hot_iterator end(hitList->end());
278 //for ( TrkHitList::hot_iterator ihot(hitList->begin()) ; ihot != end; ++ihot) {
279 //const MdcHitOnTrack* ahot = ihot->mdcHitOnTrack();
280//
281 //// GS: setCosmic and setPM are not useful anymore since this info
282 //// are now in MdcEnv and MdcHitOnTrack takes them from the MdcEnv
283 //// ahot->setCosmic(true); // set cosmic flag
284 //// ahot->setzPM(_flags.zPM); // set z Photo Multip. ProtoII
285//
286 //} // loop over hits
287 //}
288//}
289
290
291
292
void fillWithSegs(const MdcSegList *inSegs)
void fillWithSegs(const MdcSegList *inSegs, const MdcTrack *axialTrack)
int combineSegs(MdcTrack *&, MdcSeg *seed, TrkContext &, double trackT0, double maxSegChisqO, int combineByFitHits=0)
MdcSeg * getSeed(int iview, int goodOnly)
void resetSeed(const MdcDetector *gm)
MdcTrackParams tkParam
MdcTrackListCsmc(const MdcTrackParams &tkPar)
int createFromSegs(MdcSegList *segs, const MdcHitMap *, const MdcDetector *, TrkContext &, double trackT0)
int finish3d(TrkRecoTrk &trk)
TrkRecoTrk & track()
Definition MdcTrack.h:27
virtual double chisq() const =0
int success() const
Definition TrkErrCode.h:62
virtual int nActive() const =0
TrkErrCode fit()
TrkHitList * hits()
Definition TrkRecoTrk.h:107
virtual void printAll(std::ostream &) const
const TrkFit * fitResult() const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
virtual void changeFit(TrkRecoTrk &theTrack) const