CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitAlg.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// Description : Main file of the module KalFit in charge of :
3// 1/ Refit of the Mdc tracks using Kalman filter
4// 2/ Backward filter (smoothing)
5// 3/ and also several mass hypothesis, multiple scattering, energy loss,
6// non unif mag field treatment, wire sag effect...
7//------------------------------------------------------------------------
8// Modif :
9//------------------------------------------------------------------------
10#include <cstdio>
11#include <fstream>
12#include <string.h>
13#include <map>
14#include <vector>
15#include <algorithm>
16#include "CLHEP/Geometry/Vector3D.h"
17#include "CLHEP/Geometry/Point3D.h"
18#ifndef ENABLE_BACKWARDS_COMPATIBILITY
20#endif
21#include "CLHEP/Matrix/Vector.h"
22#include "CLHEP/Matrix/SymMatrix.h"
23#include "CLHEP/Matrix/Matrix.h"
24#include "GaudiKernel/MsgStream.h"
25#include "GaudiKernel/AlgFactory.h"
26#include "GaudiKernel/ISvcLocator.h"
27#include "GaudiKernel/IDataProviderSvc.h"
28#include "GaudiKernel/PropertyMgr.h"
29#include "GaudiKernel/IMessageSvc.h"
30#include "GaudiKernel/IDataManagerSvc.h"
31#include "GaudiKernel/SmartDataPtr.h"
32#include "GaudiKernel/PropertyMgr.h"
33#include "GaudiKernel/IJobOptionsSvc.h"
34#include "GaudiKernel/Bootstrap.h"
35#include "GaudiKernel/StatusCode.h"
36#include "GaudiKernel/ContainedObject.h"
37#include "GaudiKernel/SmartRef.h"
38#include "GaudiKernel/SmartRefVector.h"
39#include "GaudiKernel/ObjectVector.h"
40#include "GaudiKernel/RndmGenerators.h"
41
42//#include "TrackUtil/Helix.h"
43#include "KalFitAlg/helix/Helix.h"
44
45#include "KalFitAlg/lpav/Lpav.h"
46// Bfield:
47#include "KalFitAlg/coil/Bfield.h"
48#include "KalFitAlg/KalFitTrack.h"
49#include "KalFitAlg/KalFitHitMdc.h"
50#include "KalFitAlg/KalFitHelixSeg.h"
51#include "KalFitAlg/KalFitElement.h"
52#include "KalFitAlg/KalFitAlg.h"
53#include "McTruth/McParticle.h"
54#include "McTruth/MdcMcHit.h"
55#include "EventModel/EventHeader.h"
56#include "EvTimeEvent/RecEsTime.h"
57#include "ReconEvent/ReconEvent.h"
58#include "MdcRawEvent/MdcDigi.h"
59#include "MdcRecEvent/RecMdcHit.h"
60#include "MdcRecEvent/RecMdcTrack.h"
61#include "MdcRecEvent/RecMdcKalHelixSeg.h"
62#include "MdcRecEvent/RecMdcKalTrack.h"
63#include "MdcGeomSvc/MdcGeomSvc.h"
64#include "MagneticField/IMagneticFieldSvc.h"
65#include "MagneticField/MagneticFieldSvc.h"
66
67#include "VertexFit/IVertexDbSvc.h"
68
69#include "Identifier/Identifier.h"
70#include "Identifier/MdcID.h"
71#include "GaudiKernel/IPartPropSvc.h"
72#include "GaudiKernel/INTupleSvc.h"
73#include "RawEvent/RawDataUtil.h"
74#include "McTruth/CgemMcHit.h"
75#include "CgemRecEvent/RecCgemCluster.h"
76#include "CgemGeomSvc/ICgemGeomSvc.h"
77#include "CgemGeomSvc/CgemGeomSvc.h"
78
79using CLHEP::HepVector;
80using CLHEP::Hep3Vector;
81using CLHEP::HepMatrix;
82using CLHEP::HepSymMatrix;
83
84using namespace Event;
85using namespace KalmanFit;
86const double newr[3]={7.8338,12.3604,16.6104};
87const double dmr_layer[3] = {79.838,125.104,167.604};
88const double dor_layer[3] = {81.338,126.604,169.104};
89const double dr_layer[3] = {78.338,123.604,166.104};
90
91
92
93// Radius of the inner wall of mdc
94const double KalFitAlg::RIW = 6.35;
95
96bool testOutput=false;
97
98/// Constructor
99KalFitAlg::KalFitAlg(const std::string& name, ISvcLocator* pSvcLocator):
100 Algorithm(name, pSvcLocator), m_mdcCalibFunSvc_(0),m_MFSvc_(0),
101 _wire(0), _layer(0), _superLayer(0),
102 pathl_(1), wsag_(4), back_(1), pT_(0.0), lead_(2), mhyp_(31),
103 pe_cut_(2.0), pmu_cut_(2.0), ppi_cut_(2.0), pk_cut_(2.0), pp_cut_(2.0),
104 muls_(1), loss_(1), enhance_(0),drifttime_choice_(0),choice_(0),
105 fac_h1_(1),fac_h2_(1),fac_h3_(1),fac_h4_(1),fac_h5_(1),
106 i_back_(-1), debug_kft_(0), debug_(0), ntuple_(0),eventno(-1),
107 Tds_back_no(0),m_nt1(0),m_nt2(0),m_nt3(0),m_nt4(0),m_nt5(0),
108 iqual_back_(1),tprop_(1),
109 dchi2cut_inner_(0),dchi2cut_outer_(0),
110 dchi2cut_mid1_(0),dchi2cut_mid2_(0),
111 dchi2cut_layid2_(0),dchi2cut_layid3_(0),m_usevtxdb(0),m_dangcut(10),m_dphicut(10),
112 nTotalTrks(0)
113{
114 declareProperty("dchi2cut_layid2",dchi2cut_layid2_ = 10);
115 declareProperty("dchi2cut_layid3",dchi2cut_layid3_ = 10);
116 declareProperty("dchi2cut_inner",dchi2cut_inner_ = 10);
117 declareProperty("dchi2cut_mid1",dchi2cut_mid1_ = 10);
118 declareProperty("dchi2cut_mid2",dchi2cut_mid2_ = 10);
119 declareProperty("dchi2cut_outer",dchi2cut_outer_ = 10);
120 declareProperty("gain1",gain1_ = 1.);
121 declareProperty("gain2",gain2_ = 1.);
122 declareProperty("gain3",gain3_ = 1.);
123 declareProperty("gain4",gain4_ = 1.);
124 declareProperty("gain5",gain5_ = 1.);
125 declareProperty("fitnocut",fitnocut_ = 5);
126 declareProperty("inner_steps",inner_steps_ = 3);
127 declareProperty("outer_steps",outer_steps_ = 3);
128 declareProperty("choice",choice_ = 0);
129 declareProperty("numfcor",numfcor_ = 0);
130 declareProperty("numf",numf_ = 0);
131 declareProperty("steplev",steplev_ = 2);
132 declareProperty("usage",usage_=0);
133 declareProperty("i_front",i_front_=1);
134 declareProperty("lead",lead_=2);
135 declareProperty("muls",muls_=1);
136 declareProperty("loss",loss_=1);
137 declareProperty("matrixg",matrixg_=100.0);
138 declareProperty("lr",lr_=1);
139 declareProperty("debug_kft",debug_kft_=0);
140 declareProperty("debug",debug_=0);
141 declareProperty("ntuple",ntuple_=0);
142 declareProperty("activeonly",activeonly_=0);
143 declareProperty("matfile",matfile_="geomdc_material.dat");
144 declareProperty("cylfile",cylfile_="geomdc_cylinder.dat");
145 declareProperty("dchi2cutf",dchi2cutf_=1000.0);
146 declareProperty("dchi2cuts",dchi2cuts_=1000.0);
147 declareProperty("pt",pT_=0.0);
148 declareProperty("pe_cut",pe_cut_=2.0);
149 declareProperty("pmu_cut",pmu_cut_=2.0);
150 declareProperty("ppi_cut",ppi_cut_=2.0);
151 declareProperty("pk_cut",pk_cut_=2.0);
152 declareProperty("pp_cut",pp_cut_=2.0);
153 declareProperty("wsag",wsag_=4);
154 declareProperty("back",back_=1);
155 declareProperty("i_back",i_back_=1);
156 declareProperty("tofflag",tofflag_=1);
157 declareProperty("tof_hyp",tof_hyp_=1);
158 declareProperty("resolution",resolution_=1);
159 declareProperty("fstrag",fstrag_=0.9);
160 declareProperty("drifttime_choice",drifttime_choice_=0);
161 declareProperty("tprop",tprop_=1);
162 declareProperty("pt_cut",pt_cut_= 0.2);
163 declareProperty("theta_cut",theta_cut_= 0.8);
164 declareProperty("usevtxdb",m_usevtxdb= 0);
165 declareProperty("cosmicflag",m_csmflag= 0);
166 declareProperty("dangcut",m_dangcut=10.);
167 declareProperty("dphicut",m_dphicut=10.);
168 declareProperty("useNCGem",useNCGem_=0);
169 declareProperty("nInnerCFiber",nInnerCFiber_=0);
170 declareProperty("SigRphiGem",myRphiResGem=0.033);
171 declareProperty("SigZGem", myZResGem=0.04);
172 declareProperty("UseGemPos3D", myUseGemPos3D=false);
173 declareProperty("testCDC", testCDC=0);
174 declareProperty("ifProdNt10", ifProdNt10=false);
175 declareProperty("ifProdNt11", ifProdNt11=false);
176 declareProperty("ifProdNt12", ifProdNt12=false);
177
178 for(int i=0; i<5; i++) nFailedTrks[i]=0;
179}
180
181// destructor
183{
184 MsgStream log(msgSvc(), name());
185 log << MSG::INFO <<" Start cleaning, delete Mdc geometry objects" << endreq;
186 clean();
187 log << MSG::INFO << "End cleaning " << endreq;
188}
189
191{
192 // delete all Mdc objects :
193 _BesKalmanFitWalls.clear();
194 _BesKalmanFitMaterials.clear();
195 m_innerWall.clear();
196 m_CGEM.clear();
197 m_CGEMMaterials.clear();
198 if(_wire)free(_wire);
199 if(_layer)free(_layer);
200 if(_superLayer)free(_superLayer);
201}
202
203// initialization
205{
206 MsgStream log(msgSvc(), name());
207 log << MSG::INFO << "in initize()"
208 << "KalFit> Initialization for current run " << endreq;
209 log << MSG::INFO << "Present Parameters: muls: " << muls_ <<" loss: "
210 << loss_ <<" matrixg "<< matrixg_ <<" lr "<< lr_
211 << " debug " << debug_ << " ntuple " << ntuple_
212 << " activeonly "<< activeonly_ << endreq;
213
228
229 setDchisqCut();
230 // Delete properly the geometry objects if already existing
231 clean();
232 log << MSG::INFO << ".....building Mdc " << endreq;
233
234 // Set objects and material properties for Mdc detector :
235 //setMaterial_Mdc();
236 //setCylinder_Mdc();
237
239 // initialize the MdcCalibFunSvc
241 //
242 // // initialize the MdcGeomSvc
243 // setGeomSvc_init();
244 //getEventStarTime();
245 // // Wires, Layers and SuperLayers of Mdc :
246 // set_Mdc();
247 // define histograms and Ntuples
248 hist_def();
249
250
251 IMagneticFieldSvc* IMFSvc;
252 StatusCode sc = service ("MagneticFieldSvc",IMFSvc);
253 if(sc!=StatusCode::SUCCESS) {
254 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
255 }
257
258 // Nominal magnetic field :
260 KalFitTrack::Bznom_ = (IMFSvc->getReferField())*10000; //unit is KGauss
262
263 if(4 == debug_){
264 std::cout<<" initialize, referField from MagneticFieldSvc: "<< (IMFSvc->getReferField())*10000 <<std::endl;
265 std::cout<<" magnetic field: "<<KalFitTrack::Bznom_<<std::endl;
266 }
267
268 }
269
270 // Print out of the status of the flags :
271 if (ntuple_)
272 log << MSG::INFO <<" ntuple out, the option is "<< ntuple_ <<endreq;
273 if (debug_ >0 ) {
274 cout << "KalFitAlg> DEBUG open,Here is the important Parameters :\n";
275 cout << " Leading particule with mass hyp = " << lead_ << std::endl;
276 cout << " mhyp = " << mhyp_ << std::endl;
277 cout << "===== Effects taking into account : " << std::endl;
278 cout << " - multiple scattering = " << muls_ << std::endl;
279 cout << " - energy loss = " << loss_ << std::endl;
281 cout << " - straggling for the energy loss " << std::endl;
282 cout << " - nominal Bz value = " << KalFitTrack::Bznom_ << std::endl;
283
284 if (KalFitTrack::numf_ > 19)
285 cout << " - non uniform magnetic field treatment "
286 << KalFitTrack::numf_ << std::endl;
287 cout << " - wire sag correction = " << wsag_ << std::endl;
288 cout << " - Tof correction = " << KalFitTrack::Tof_correc_ << std::endl;
289 cout << " - chi2 cut for each hit = " << KalFitTrack::chi2_hitf_
290 << std::endl << " is applied after " << KalFitTrack::nmdc_hit2_
291 << " hits included " << std::endl;
292
293 if (back_){
294 cout << " Backward filter is on with a pT cut value = " << pT_ << endl;
295 }
296 if(debug_ == 4) cout << " pathl = " << pathl_ << std::endl;
297
298 if (KalFitTrack::LR_==1)
299 cout << " Decision L/R from MdcRecHit " << std::endl;
300 }
301
307 // Get the Particle Properties Service
308 IPartPropSvc* p_PartPropSvc;
309 static const bool CREATEIFNOTTHERE(true);
310 StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
311 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
312 log << MSG::WARNING << " Could not initialize Particle Properties Service" << endreq;
313 return StatusCode::SUCCESS;
314 }
315 m_particleTable = p_PartPropSvc->PDT();
316
317 return StatusCode::SUCCESS;
318}
319
321{
322 MsgStream log(msgSvc(), name());
323 log << MSG::DEBUG<<"KalFitAlg:: nTotalTrks = "<<nTotalTrks<<endreq;
324 log << MSG::DEBUG<<" e: "<<nFailedTrks[0]<<" failed, "<<nTotalTrks-nFailedTrks[0]<<" successed"<<endreq;
325 log << MSG::DEBUG<<" mu: "<<nFailedTrks[1]<<" failed, "<<nTotalTrks-nFailedTrks[1]<<" successed"<<endreq;
326 log << MSG::DEBUG<<" pi: "<<nFailedTrks[2]<<" failed, "<<nTotalTrks-nFailedTrks[2]<<" successed"<<endreq;
327 log << MSG::DEBUG<<" K: "<<nFailedTrks[3]<<" failed, "<<nTotalTrks-nFailedTrks[3]<<" successed"<<endreq;
328 log << MSG::DEBUG<<" p: "<<nFailedTrks[4]<<" failed, "<<nTotalTrks-nFailedTrks[4]<<" successed"<<endreq;
329 return StatusCode::SUCCESS;
330}
331
332// begin run setting
334{
335 MsgStream log(msgSvc(), name());
336 log << MSG::INFO << "in beginRun()" << endreq;
337 log << MSG::INFO << "Present Parameters: muls: " << muls_ <<" loss: "
338 << " activeonly "<< activeonly_ << endreq;
339
340 // initialize the MdcGeomSvc
342 // Wires, Layers and SuperLayers of Mdc :
343 set_Mdc();
344
345 IMagneticFieldSvc* IMFSvc;
346 StatusCode sc = service ("MagneticFieldSvc",IMFSvc);
347 if(sc!=StatusCode::SUCCESS) {
348 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
349 }
350
351 // Nominal magnetic field :
353 KalFitTrack::Bznom_ = (IMFSvc->getReferField())*10000; //unit is KGauss
355
356 if(4 == debug_){
357 std::cout<<" beginRun, referField from MagneticFieldSvc:"<< (IMFSvc->getReferField())*10000 <<std::endl;
358 std::cout<<" magnetic field: "<<KalFitTrack::Bznom_<<std::endl;
359 }
360 }
361
362 return StatusCode::SUCCESS;
363}
364
365
366
367
368// hist_def function
370{
371 if(ntuple_&1) {
372 NTuplePtr nt1(ntupleSvc(),"FILE104/n101");
373 StatusCode status;
374 if ( nt1 ) m_nt1 = nt1;
375 else {
376 m_nt1= ntupleSvc()->book("FILE104/n101",CLID_ColumnWiseTuple,"KalFit");
377 if ( m_nt1 ) {
378
379 status = m_nt1->addItem("trackid",m_trackid);
380 status = m_nt1->addItem("stat",5,2,m_stat);
381 status = m_nt1->addItem("ndf",5,2,m_ndf);
382 status = m_nt1->addItem("chisq",5,2,m_chisq);
383 status = m_nt1->addItem("length",5,m_length);
384 status = m_nt1->addItem("tof",5,m_tof);
385 status = m_nt1->addItem("nhits",5,m_nhits);
386 status = m_nt1->addItem("zhelix",5,m_zhelix);
387 status = m_nt1->addItem("zhelixe",5,m_zhelixe);
388 status = m_nt1->addItem("zhelixmu",5,m_zhelixmu);
389 status = m_nt1->addItem("zhelixk",5,m_zhelixk);
390 status = m_nt1->addItem("zhelixp",5,m_zhelixp);
391 status = m_nt1->addItem("zptot",m_zptot);
392 status = m_nt1->addItem("zptote",m_zptote);
393 status = m_nt1->addItem("zptotmu",m_zptotmu);
394 status = m_nt1->addItem("zptotk",m_zptotk);
395 status = m_nt1->addItem("zptotp",m_zptotp);
396
397 status = m_nt1->addItem("zpt",m_zpt);
398 status = m_nt1->addItem("zpte",m_zpte);
399 status = m_nt1->addItem("zptmu",m_zptmu);
400 status = m_nt1->addItem("zptk",m_zptk);
401 status = m_nt1->addItem("zptp",m_zptp);
402
403 status = m_nt1->addItem("fptot",m_fptot);
404 status = m_nt1->addItem("fptote",m_fptote);
405 status = m_nt1->addItem("fptotmu",m_fptotmu);
406 status = m_nt1->addItem("fptotk",m_fptotk);
407 status = m_nt1->addItem("fptotp",m_fptotp);
408 status = m_nt1->addItem("fpt",m_fpt);
409 status = m_nt1->addItem("fpte",m_fpte);
410 status = m_nt1->addItem("fptmu",m_fptmu);
411 status = m_nt1->addItem("fptk",m_fptk);
412 status = m_nt1->addItem("fptp",m_fptp);
413
414 status = m_nt1->addItem("lptot",m_lptot);
415 status = m_nt1->addItem("lptote",m_lptote);
416 status = m_nt1->addItem("lptotmu",m_lptotmu);
417 status = m_nt1->addItem("lptotk",m_lptotk);
418 status = m_nt1->addItem("lptotp",m_lptotp);
419 status = m_nt1->addItem("lpt",m_lpt);
420 status = m_nt1->addItem("lpte",m_lpte);
421 status = m_nt1->addItem("lptmu",m_lptmu);
422 status = m_nt1->addItem("lptk",m_lptk);
423 status = m_nt1->addItem("lptp",m_lptp);
424
425 status = m_nt1->addItem("zsigp",m_zsigp);
426 status = m_nt1->addItem("zsigpe",m_zsigpe);
427 status = m_nt1->addItem("zsigpmu",m_zsigpmu);
428 status = m_nt1->addItem("zsigpk",m_zsigpk);
429 status = m_nt1->addItem("zsigpp",m_zsigpp);
430 status = m_nt1->addItem("fhelix",5,m_fhelix);
431 status = m_nt1->addItem("fhelixe",5,m_fhelixe);
432 status = m_nt1->addItem("fhelixmu",5,m_fhelixmu);
433 status = m_nt1->addItem("fhelixk",5,m_fhelixk);
434 status = m_nt1->addItem("fhelixp",5,m_fhelixp);
435 status = m_nt1->addItem("lhelix",5,m_lhelix);
436 status = m_nt1->addItem("lhelixe",5,m_lhelixe);
437 status = m_nt1->addItem("lhelixmu",5,m_lhelixmu);
438 status = m_nt1->addItem("lhelixk",5,m_lhelixk);
439 status = m_nt1->addItem("lhelixp",5,m_lhelixp);
440 status = m_nt1->addItem("rGem",4,m_rGem);
441 status = m_nt1->addItem("chi2Gem",4,m_chi2Gem);
442 status = m_nt1->addItem("phiGemExp",4,m_phiGemExp);
443 status = m_nt1->addItem("phiGemHit",4,m_phiGemHit);
444 status = m_nt1->addItem("zGemExp",4,m_zGemExp);
445 status = m_nt1->addItem("zGemHit",4,m_zGemHit);
446 if(ntuple_&32) {
447 status = m_nt1->addItem("zerror",15,m_zerror);
448 status = m_nt1->addItem("zerrore",15,m_zerrore);
449 status = m_nt1->addItem("zerrormu",15,m_zerrormu);
450 status = m_nt1->addItem("zerrork",15,m_zerrork);
451 status = m_nt1->addItem("zerrorp",15,m_zerrorp);
452 status = m_nt1->addItem("ferror",15,m_ferror);
453 status = m_nt1->addItem("ferrore",15,m_ferrore);
454 status = m_nt1->addItem("ferrormu",15,m_ferrormu);
455 status = m_nt1->addItem("ferrork",15,m_ferrork);
456 status = m_nt1->addItem("ferrorp",15,m_ferrorp);
457 status = m_nt1->addItem("lerror",15,m_lerror);
458 status = m_nt1->addItem("lerrore",15,m_lerrore);
459 status = m_nt1->addItem("lerrormu",15,m_lerrormu);
460 status = m_nt1->addItem("lerrork",15,m_lerrork);
461 status = m_nt1->addItem("lerrorp",15,m_lerrorp);
462 }
463 if((ntuple_&16)&&(ntuple_&1)) {
464 status = m_nt1->addItem("evtid",m_evtid);
465 status = m_nt1->addItem("mchelix",5,m_mchelix);
466 status = m_nt1->addItem("mcptot",m_mcptot);
467 status = m_nt1->addItem("mcpid",m_mcpid);
468 }
469 if( status.isFailure() ) cout<<"Ntuple1 add item failed!"<<endl;
470 }
471 }
472 }
473
474 if(ntuple_&4) {
475 NTuplePtr nt2(ntupleSvc(),"FILE104/n102");
476 StatusCode status2;
477 if ( nt2 ) m_nt2 = nt2;
478 else {
479 m_nt2= ntupleSvc()->book("FILE104/n102",CLID_ColumnWiseTuple,"KalFitComp");
480 if ( m_nt2 ) {
481 status2 = m_nt2->addItem("delx",m_delx);
482 status2 = m_nt2->addItem("dely",m_dely);
483 status2 = m_nt2->addItem("delz",m_delz);
484 status2 = m_nt2->addItem("delthe",m_delthe);
485 status2 = m_nt2->addItem("delphi",m_delphi);
486 status2 = m_nt2->addItem("delp",m_delp);
487 status2 = m_nt2->addItem("delpx",m_delpx);
488 status2 = m_nt2->addItem("delpy",m_delpy);
489 status2 = m_nt2->addItem("delpz",m_delpz);
490
491 if( status2.isFailure() ) cout<<"Ntuple2 add item failed!"<<endl;
492 }
493 }
494 }
495
496 if(ntuple_&2) {
497 NTuplePtr nt3(ntupleSvc(),"FILE104/n103");
498 StatusCode status3;
499 if ( nt3 ) m_nt3 = nt3;
500 else {
501 m_nt3= ntupleSvc()->book("FILE104/n103",CLID_ColumnWiseTuple,"PatRec");
502 if ( m_nt3 ) {
503 status3 = m_nt3->addItem("trkhelix",5,m_trkhelix);
504 status3 = m_nt3->addItem("trkptot",m_trkptot);
505 if(ntuple_&32) {
506 status3 = m_nt3->addItem("trkerror",15,m_trkerror);
507 status3 = m_nt3->addItem("trksigp",m_trksigp);
508 }
509 status3 = m_nt3->addItem("trkndf",m_trkndf);
510 status3 = m_nt3->addItem("trkchisq",m_trkchisq);
511 if( status3.isFailure() ) cout<<"Ntuple3 add item failed!"<<endl;
512 }
513 }
514 }
515
516 if(ntuple_&4) {
517 NTuplePtr nt4(ntupleSvc(),"FILE104/n104");
518 StatusCode status4;
519 if ( nt4 ) m_nt4 = nt4;
520 else {
521 m_nt4= ntupleSvc()->book("FILE104/n104",CLID_ColumnWiseTuple,"PatRecComp");
522 if ( m_nt4 ) {
523 status4 = m_nt4->addItem("trkdelx",m_trkdelx);
524 status4 = m_nt4->addItem("trkdely",m_trkdely);
525 status4 = m_nt4->addItem("trkdelz",m_trkdelz);
526 status4 = m_nt4->addItem("trkdelthe",m_trkdelthe);
527 status4 = m_nt4->addItem("trkdelphi",m_trkdelphi);
528 status4 = m_nt4->addItem("trkdelp",m_trkdelp);
529 if( status4.isFailure() ) cout<<"Ntuple4 add item failed!"<<endl;
530 }
531 }
532 }
533 if(ntuple_&8) {
534 NTuplePtr nt5(ntupleSvc(), "FILE104/n105");
535 StatusCode status5;
536 if ( nt5 ) m_nt5 = nt5;
537 else {
538 m_nt5= ntupleSvc()->book("FILE104/n105",CLID_ColumnWiseTuple,"KalFitdChisq");
539 if ( m_nt5 ) {
540 status5 = m_nt5->addItem("dchi2",m_dchi2);
541 status5 = m_nt5->addItem("masshyp",m_masshyp);
542 status5 = m_nt5->addItem("residual_estim",m_residest);
543 status5 = m_nt5->addItem("residual",m_residnew);
544 status5 = m_nt5->addItem("layer",m_layer);
545 status5 = m_nt5->addItem("kaldr",m_anal_dr);
546 status5 = m_nt5->addItem("kalphi0",m_anal_phi0);
547 status5 = m_nt5->addItem("kalkappa",m_anal_kappa);
548 status5 = m_nt5->addItem("kaldz",m_anal_dz);
549 status5 = m_nt5->addItem("kaltanl",m_anal_tanl);
550 status5 = m_nt5->addItem("dr_ea",m_anal_ea_dr);
551 status5 = m_nt5->addItem("phi0_ea",m_anal_ea_phi0);
552 status5 = m_nt5->addItem("kappa_ea",m_anal_ea_kappa);
553 status5 = m_nt5->addItem("dz_ea",m_anal_ea_dz);
554 status5 = m_nt5->addItem("tanl_ea",m_anal_ea_tanl);
555 if( status5.isFailure() ) cout<<"Ntuple5 add item failed!"<<endl;
556 }
557 }
558 }
559
560 NTuplePtr nt6(ntupleSvc(),"FILE104/n106");
561 StatusCode status6;
562 if ( nt6 ) m_nt6 = nt6;
563 else {
564 m_nt6= ntupleSvc()->book("FILE104/n106",CLID_ColumnWiseTuple,"kal seg");
565 if ( m_nt6 ) {
566 status6 = m_nt6->addItem("docaInc",m_docaInc);
567 status6 = m_nt6->addItem("docaExc",m_docaExc);
568 status6 = m_nt6->addItem("tdr",m_tdrift);
569 status6 = m_nt6->addItem("layerid", m_layerid);
570 status6 = m_nt6->addItem("event", m_eventNo);
571 status6 = m_nt6->addItem("residualInc",m_residualInc);
572 status6 = m_nt6->addItem("residualExc",m_residualExc);
573 status6 = m_nt6->addItem("lr",m_lr);
574 status6 = m_nt6->addItem("dd",m_dd);
575 status6 = m_nt6->addItem("y",m_yposition);
576
577 if( status6.isFailure() ) cout<<"Ntuple6 add item failed!"<<endl;
578 }
579 }
580
581 if(ifProdNt10) {
582 NTuplePtr nt10(ntupleSvc(),"FILE104/n110");
583 StatusCode status10;
584 if ( nt10 ) m_nt10 = nt10;
585 else {
586 m_nt10= ntupleSvc()->book("FILE104/n110",CLID_ColumnWiseTuple,"test");
587 if ( m_nt10 ) {
588 status10 = m_nt10->addItem("evt",m_evt3);
589 status10 = m_nt10->addItem("qua",m_qua);
590 status10 = m_nt10->addItem("nhit",m_nGemHits,0,4000000);
591 status10 = m_nt10->addIndexedItem("meas_r",m_nGemHits,m_meas_r);
592 status10 = m_nt10->addIndexedItem("meas_phi",m_nGemHits,m_meas_phi);
593 status10 = m_nt10->addIndexedItem("meas_z",m_nGemHits,m_meas_z);
594 status10 = m_nt10->addIndexedItem("esti1_r",m_nGemHits,m_esti1_r);
595 status10 = m_nt10->addIndexedItem("esti1_phi",m_nGemHits,m_esti1_phi);
596 status10 = m_nt10->addIndexedItem("esti1_z",m_nGemHits,m_esti1_z);
597 status10 = m_nt10->addIndexedItem("esti2_r",m_nGemHits,m_esti2_r);
598 status10 = m_nt10->addIndexedItem("esti2_phi",m_nGemHits,m_esti2_phi);
599 status10 = m_nt10->addIndexedItem("esti2_z",m_nGemHits,m_esti2_z);
600 status10 = m_nt10->addIndexedItem("diff1_phi",m_nGemHits,m_diff1_phi);
601 status10 = m_nt10->addIndexedItem("diff1_z",m_nGemHits,m_diff1_z);
602 status10 = m_nt10->addIndexedItem("diff2_phi",m_nGemHits,m_diff2_phi);
603 status10 = m_nt10->addIndexedItem("diff2_z",m_nGemHits,m_diff2_z);
604 status10 = m_nt10->addIndexedItem("layer",m_nGemHits,m_GemLayer);
605 status10 = m_nt10->addIndexedItem("mass",m_nGemHits,m_mass);
606 status10 = m_nt10->addIndexedItem("dchi2",m_nGemHits,m_Gchi2);
607 status10 = m_nt10->addIndexedItem("meas_phierr",m_nGemHits,m_meas_phierr);
608 status10 = m_nt10->addIndexedItem("meas_zerr",m_nGemHits,m_meas_zerr);
609 status10 = m_nt10->addIndexedItem("esti_phierr",m_nGemHits,m_esti_phierr);
610 status10 = m_nt10->addIndexedItem("esti_zerr",m_nGemHits,m_esti_zerr);
611 if( status10.isFailure() ) cout<<"Ntuple10 add item failed!"<<endl;
612 }
613 }
614 }
615
616 if(ifProdNt11) {
617 NTuplePtr nt11(ntupleSvc(),"FILE104/n111");
618 StatusCode status11;
619 if ( nt11 ) m_nt11 = nt11;
620 else {
621 m_nt11= ntupleSvc()->book("FILE104/n111",CLID_ColumnWiseTuple,"truth");
622 if ( m_nt11 ) {
623 status11 = m_nt11->addItem("evt",m_evt4);
624 status11 = m_nt11->addItem("ntruth",m_ntruth,0,400000);
625 status11 = m_nt11->addIndexedItem("phi",m_ntruth,m_dtphi);
626 status11 = m_nt11->addIndexedItem("z",m_ntruth,m_dtv);
627 status11 = m_nt11->addIndexedItem("postphi",m_ntruth,m_dtpostphi);
628 status11 = m_nt11->addIndexedItem("postz",m_ntruth,m_dtpostz);
629 status11 = m_nt11->addIndexedItem("layer",m_ntruth,m_tlayer);
630 if( status11.isFailure() ) cout<<"Ntuple11 add item failed!"<<endl;
631 }
632 }
633 }
634
635 if(ifProdNt12) {
636 NTuplePtr nt12(ntupleSvc(),"FILE104/n112");
637 StatusCode status12;
638 if ( nt12 ) m_nt12 = nt12;
639 else {
640 m_nt12= ntupleSvc()->book("FILE104/n112",CLID_ColumnWiseTuple,"PatRecComp");
641 if ( m_nt12 ) {
642 status12 = m_nt12->addItem("evt",m_evt);
643 status12 = m_nt12->addItem("track",m_track);
644 status12 = m_nt12->addItem("diff_dr",m_diff_dr);
645 status12 = m_nt12->addItem("diff_phi0",m_diff_phi0);
646 status12 = m_nt12->addItem("diff_kappa",m_diff_kappa);
647 status12 = m_nt12->addItem("diff_dz",m_diff_dz);
648 status12 = m_nt12->addItem("diff_tanl",m_diff_tanl);
649 status12 = m_nt12->addItem("diff_p",m_diff_p);
650 if( status12.isFailure() ) cout<<"Ntuple12 add item failed!"<<endl;
651 }
652 }
653 }
654}
655
656
657
659{
660 int layid = 0;
661
662 /// set dchi2cutf_anal
663 for(layid = 0; layid<2; layid++) {
665 }
668 for(layid = 4; layid<12; layid++) {
670 }
671 for(layid = 12; layid<20; layid++) {
673 }
674 for(layid = 20; layid<43; layid++) {
676 }
677
678
679 /// set dchi2cuts_anal
680 for(layid = 0; layid<2; layid++) {
682 }
683
686 for(layid = 4; layid<12; layid++) {
688 }
689 for(layid = 12; layid<20; layid++) {
691 }
692 for(layid = 20; layid<43; layid++) {
694 }
695
696 /// temporary
697 // for(layid = 0; layid<43; layid++) {
698 // KalFitTrack::dchi2cuts_anal[layid] = 10.0;
699 // }
700
701
702 /// set dchi2cutf_calib
703 for(layid = 0; layid<2; layid++) {
705 }
706
709
710 for(layid = 4; layid<12; layid++) {
712 }
713
714 for(layid = 12; layid<20; layid++) {
716 }
717
718 for(layid = 20; layid<43; layid++) {
720 }
721
722 /// temporary
723 if(usage_<2){
724 for(layid = 0; layid<43; layid++) {
725 KalFitTrack::dchi2cutf_calib[layid] = 10.0;
726 }
727 }
728
729
730 /// set dchi2cuts_calib
731 for(layid = 0; layid<2; layid++) {
733 }
734
737
738 for(layid = 4; layid<12; layid++) {
740 }
741
742 for(layid = 12; layid<20; layid++) {
744 }
745
746 for(layid = 20; layid<43; layid++) {
748 }
749
750 /// temporary
751 if(usage_<2){
752 for(layid = 0; layid<43; layid++) {
753 KalFitTrack::dchi2cuts_calib[layid] = 10.0;
754 }
755 }
756}
757
758
759
760// event function
762{
763 MsgStream log(msgSvc(), name());
764 log << MSG::INFO << "in execute()" << endreq;
765 if(testOutput) std::cout<<"begin to deal with EVENT ..."<<(++eventno)<<std::endl;
766 for(int i=0; i<5; i++) iqual_front_[i] = 1;
767 iqual_back_ = 1;
768
769
770 /*
771 MdcID mdcId;
772 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
773 SmartDataPtr<RecMdcKalHelixSegCol> recSegCol(eventSvc(),"/Event/Recon/RecMdcKalHelixSegCol");
774 if(recmdckaltrkCol) {
775 cout<<"------------------------ new event ---------------------"<<endl;
776 cout<<"recmdckaltrkCol->size()="<<recmdckaltrkCol->size()<<endl;
777 cout<<"recSegCol.size()="<<recSegCol->size()<<endl;
778 cout<<"--------------------------------------------------------"<<endl;
779 RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
780 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
781 int i_trk=0;
782 for(;KalTrk !=recmdckaltrkCol->end();KalTrk++){
783 cout<<"*** track "<<i_trk++<<" ***"<<endl;
784 HelixSegRefVec gothelixsegs = (*KalTrk)->getVecHelixSegs();
785 for(int i=0;i<5;i++) cout<<"pid "<<i<<" nSegs="<<((*KalTrk)->getVecHelixSegs(i)).size()<<endl;
786 HelixSegRefVec::iterator iter_hit = gothelixsegs.begin();
787 if(iter_hit == gothelixsegs.end())cout<<"iter_hit == gothelixsegs.end()"<<endl;
788 int nhitofthistrk=0;
789 for( ; iter_hit != gothelixsegs.end(); iter_hit++){
790 nhitofthistrk++;
791 //cout<<"layerId: "<<(*iter_hit)->getLayerId()<<endl;
792 //cout<<"Identifier: "<<(*iter_hit)->getMdcId()<<endl;
793 //cout<<"layerId: "<<mdcId.layer((*iter_hit)->getMdcId())<<endl;
794 //cout<<"getDT: "<<(*iter_hit)->getDT()<<endl;
795 }
796 iter_hit=gothelixsegs.begin();
797 //for(int m=0; m<nhitofthistrk/5;m++){
798 // identifier = (*iter_hit) -> getMdcId();
799 //}
800 cout<<"nhitofthistrk="<<nhitofthistrk<<endl;
801 }
802 }
803 else cout<<"did not find /Event/Recon/RecMdcKalTrackCol"<<endl;
804 */
805
806
807
808
809 ///
810 IMagneticFieldSvc* IMFSvc;
811 StatusCode sc = service ("MagneticFieldSvc",IMFSvc);
812 if(sc!=StatusCode::SUCCESS) {
813 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
814 }
815
816 // Nominal magnetic field :
818 KalFitTrack::Bznom_ = (IMFSvc->getReferField())*10000; //unit is KGauss
820
821 if(4 == debug_){
822 std::cout<<" execute, referField from MagneticFieldSvc: "<< (IMFSvc->getReferField())*10000 <<std::endl;
823 std::cout<<" magnetic field: "<<KalFitTrack::Bznom_<<std::endl;
824 }
825 }
826
828
829 IDataProviderSvc* evtSvc = NULL;
830 Gaudi::svcLocator()->service("EventDataSvc", evtSvc);
831 if (evtSvc) {
832 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
833 } else {
834 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
835 return StatusCode::SUCCESS;
836 }
837
838 StatusCode kalsc;
839 IDataManagerSvc *dataManSvc;
840 dataManSvc= dynamic_cast<IDataManagerSvc*>(evtSvc);
841 DataObject *aKalTrackCol;
842 evtSvc->findObject("/Event/Recon/RecMdcKalTrackCol",aKalTrackCol);
843 if(aKalTrackCol != NULL) {
844 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalTrackCol");
845 evtSvc->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
846 }
847
848 kalsc = evtSvc->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
849 if( kalsc.isFailure() ) {
850 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
851 return StatusCode::SUCCESS;
852 }
853 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
854
855 DataObject *aKalHelixSegCol;
856 evtSvc->findObject("/Event/Recon/RecMdcKalHelixSegCol", aKalHelixSegCol);
857 if(aKalHelixSegCol != NULL){
858 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalHelixSegCol");
859 evtSvc->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
860 }
861 RecMdcKalHelixSegCol *helixsegcol = new RecMdcKalHelixSegCol;
862 kalsc = evtSvc->registerObject("/Event/Recon/RecMdcKalHelixSegCol", helixsegcol);
863 if( kalsc.isFailure()){
864 log<< MSG::FATAL << "Could not register RecMdcKalHelixSeg" <<endreq;
865 return StatusCode::SUCCESS;
866 }
867 log << MSG::INFO << "RecMdcKalHelixSegCol register successfully!" <<endreq;
868
869
870 /*IMdcGeomSvc* geosvc;
871 StatusCode sc = service("MdcGeomSvc", geosvc);
872 if (sc == StatusCode::SUCCESS) {
873 } else {
874 return sc;
875 }*/
876
877 ISvcLocator* svcLocator = Gaudi::svcLocator();
878 ICgemGeomSvc* ISvc;
879 StatusCode Cgem_sc=svcLocator->service("CgemGeomSvc", ISvc);
880 m_CgemGeomSvc_=dynamic_cast<CgemGeomSvc *>(ISvc);
881 if (!Cgem_sc.isSuccess()) log<< MSG::INFO << "KalFitAlg::execute(): Could not open CGEM geometry file" << endreq;
882 //myNCgemLayers = myCgemGeomSvc->getNumberOfCgemLayer();
883 //if(myPrintFlag) cout<<"CgemClusterCreate::initialize() "<<myNCgemLayers<<" Cgem layers"<<endl;
884
885 MdcGeomSvc* const geosvc = dynamic_cast<MdcGeomSvc*>(imdcGeomSvc_);
886 if(!geosvc) {
887 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitAlg::execute ...!!"<<std::endl;
888 }
889
890 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
891 if (!eventHeader) {
892 log << MSG::WARNING << "Could not find Event Header" << endreq;
893 return StatusCode::FAILURE;
894 }
895 int eventNo = eventHeader->eventNumber();
896 int runNo = eventHeader->runNumber();
897 if(runNo>0) wsag_=4;
898 else wsag_=0;
899
900 if(testOutput) cout<<endl<<"$$$$$$$$$$$ run="<<runNo<<", evt="<<eventNo<<" $$$$$$$$$$$$$$$$$"<<endl<<endl;
901
902 double t0=0.;
903 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
904 if (estimeCol && estimeCol->size()) {
905 RecEsTimeCol::iterator iter_evt = estimeCol->begin();
906 t0 = (*iter_evt)->getTest();
907 // t0Stat = (*iter_evt)->getStat();
908 }else{
909 log << MSG::WARNING << "Could not find EvTimeCol" << endreq;
910 return StatusCode::SUCCESS;
911 }
912
913
914 if(debug_==4) {
915 std::cout<<"in KalFitAlg , we get the event start time = "<<t0<<std::endl;
916 }
918
919 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc,"/Event/Digi/MdcDigiCol");
920 if (sc!=StatusCode::SUCCESS) {
921 log << MSG::FATAL << "Could not find MdcDigiCol!" << endreq;
922 return StatusCode::SUCCESS;
923 }
924 KalFitTrack::setMdcDigiCol(mdcDigiCol);
925
926 // register RecMdcTrack and MdcRecHit collection
927
928 if((ntuple_&16)&&(ntuple_&1)) {
929 // McTruth infor,Retrieve MC track truth
930 // bool mcstat = true;
931 // more research needed ...
932
933 m_evtid = eventHeader->eventNumber();
934 bool mcstat = true;
935
936 SmartDataPtr<McParticleCol> mcPartCol(eventSvc(),"/Event/MC/McParticleCol");
937 if (!mcPartCol) {
938 log << MSG::WARNING << "Could not find McParticle" << endreq;
939 mcstat = false;
940 }
941
942 if(mcstat) {
943 McParticleCol::iterator i_mcTrk = mcPartCol->begin();
944 for (;i_mcTrk != mcPartCol->end(); i_mcTrk++) {
945 if(!(*i_mcTrk)->primaryParticle()) continue;
946 const HepLorentzVector& mom((*i_mcTrk)->initialFourMomentum());
947 const HepLorentzVector& pos = (*i_mcTrk)->initialPosition();
948 log << MSG::DEBUG << "MCINFO:particleId=" << (*i_mcTrk)->particleProperty()
949 << " theta=" << mom.theta() <<" phi="<< mom.phi()
950 <<" px="<< mom.px() <<" py="<< mom.py() <<" pz="<< mom.pz()
951 << endreq;
952 double charge = 0.0;
953 int pid = (*i_mcTrk)->particleProperty();
954 int mother_id = ((*i_mcTrk)->mother()).particleProperty();
955 if( pid >0 ) {
956 charge = m_particleTable->particle( pid )->charge();
957 } else if ( pid <0 ) {
958 charge = m_particleTable->particle( -pid )->charge();
959 charge *= -1;
960 } else {
961 log << MSG::WARNING << "wrong particle id, please check data" <<endreq;
962 }
963 HepPoint3D pos2(pos.x(),pos.y(),pos.z());
964 Hep3Vector mom2(mom.px(),mom.py(),mom.pz());
965
966 Helix mchelix(pos2, mom2, charge);
967 log << MSG::DEBUG << "charge of the track " << charge << endreq;
968 if( debug_ == 4) cout<< "helix: "<<mchelix.a()<<endl;
969 mchelix.pivot( HepPoint3D(0,0,0) );
970 for( int j =0; j<5; j++) {
971 m_mchelix[j] = mchelix.a()[j];
972 }
973 m_mcpid = pid;
974 m_mcptot = sqrt(1+pow(m_mchelix[4],2))/m_mchelix[2];
975 if(testOutput)
976 {
977 cout<<"MC pid, mother_id = "<<pid<<", "<<mother_id<<endl;
978 cout<<" p4 = "<<(*i_mcTrk)->initialFourMomentum()<<endl;
979 cout<<" start from "<<(*i_mcTrk)->initialPosition()<<endl;
980 cout<<" end at "<<(*i_mcTrk)->finalPosition()<<endl;
981 cout<<" Helix: "<<mchelix.a()<<endl;
982 cout<<"mc ptot, theta, phi, R = "<<m_mcptot<<", "<<mom2.theta()/acos(-1.)*180<<", "<<mom2.phi()/acos(-1.)*180<<", "<<mchelix.radius()<<endl;
983 }
984 }
985 }
986 }
987
988 Identifier mdcid;
989
990 //retrieve RecMdcTrackCol from TDS
991 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
992 if (!newtrkCol) {
993 log << MSG::FATAL << "Could not find RecMdcTrackCol" << endreq;
994 return( StatusCode::SUCCESS);
995 }
996 log << MSG::INFO << "Begin to make MdcRecTrkCol and MdcRecWirhitCol"<<endreq;
997
998 vector<MdcRec_trk>* mtrk_mgr = MdcRecTrkCol::getMdcRecTrkCol();
999 mtrk_mgr->clear();
1000 vector<MdcRec_trk_add>* mtrkadd_mgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
1001 mtrkadd_mgr->clear();
1002 vector<MdcRec_wirhit>* mhit_mgr = MdcRecWirhitCol::getMdcRecWirhitCol();
1003 mhit_mgr->clear();
1004
1005 double trkx1,trkx2,trky1,trky2,trkz1,trkz2,trkthe1,trkthe2,trkphi1,trkphi2,trkp1,trkp2,trkr1,trkr2,trkkap1,trkkap2,trktanl1,trktanl2;
1006 Hep3Vector csmp3[2];
1007 double csmphi[2];
1008 int status_temp=0;
1009 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
1010 for(int kj = 1; iter_trk != newtrkCol->end(); iter_trk++,kj++) {
1011 if(kj<3){
1012 csmp3[kj-1]=(*iter_trk)->p3();
1013 csmphi[kj-1] = (*iter_trk)->phi();
1014 }
1015 if(ntuple_&2) {
1016 //check trackcol, track level
1017 for( int j = 0, ij = 0; j<5; j++) {
1018 m_trkhelix[j] = (*iter_trk)->helix()[j];
1019 if(ntuple_&32) {
1020 for(int k=0; k<=j; k++,ij++) {
1021 m_trkerror[ij] = (*iter_trk)->err()[j][k];
1022 }
1023 }
1024 }
1025 m_trkptot = sqrt(1+pow(m_trkhelix[4],2))/m_trkhelix[2];
1026 if(ntuple_&32){
1027 m_trksigp = sqrt(pow((m_trkptot/m_trkhelix[2]),2)*m_trkerror[5]+
1028 pow((m_trkhelix[4]/m_trkptot),2)*pow((1/m_trkhelix[2]),4)*m_trkerror[14]-
1029 2*m_trkhelix[4]*m_trkerror[12]*pow((1/m_trkhelix[2]),3));
1030 }
1031 m_trkndf = (*iter_trk)->ndof();
1032 m_trkchisq = (*iter_trk)->chi2();
1033
1034 if (debug_ == 4) cout<<"Ea from RecMdcTrackCol..." <<(*iter_trk)->err()<<endl;
1035
1036 StatusCode sc3 = m_nt3->write();
1037 if( sc3.isFailure() ) cout<<"Ntuple3 filling failed!"<<endl;
1038 }
1039 //end of track level check and prepare evt check
1040 if(ntuple_&4) {
1041 /*
1042 if(kj == 1) {
1043 trkphi1 = (*iter_trk)->getFi0();
1044 trkr1 = (*iter_trk)->getDr();
1045 trkz1 = (*iter_trk)->getDz();
1046 trkkap1 = (*iter_trk)->getCpa();
1047 trktanl1 = (*iter_trk)->getTanl();
1048 trkx1 = trkr1*cos(trkphi1);
1049 trky1 = trkr1*sin(trkphi1);
1050 trkp1 = sqrt(1+trktanl1*trktanl1)/trkkap1;
1051 trkthe1 = M_PI/2-atan(trktanl1);
1052 } else if(kj == 2) {
1053 trkphi2 = (*iter_trk)->getFi0();
1054 trkr2 = (*iter_trk)->getDr();
1055 trkz2 = (*iter_trk)->getDz();
1056 trkkap2 = (*iter_trk)->getCpa();
1057 trktanl2 = (*iter_trk)->getTanl();
1058 trkx2 = trkr2*cos(trkphi2);
1059 trky2 = trkr2*sin(trkphi2);
1060 trkp2 = sqrt(1+trktanl2*trktanl2)/trkkap1;
1061 trkthe2 = M_PI/2-atan(trktanl2);
1062 }
1063 */
1064 }
1065 //end prepare
1066
1067 log << MSG::DEBUG << "retrieved MDC tracks:"
1068 << " Nhits " <<(*iter_trk)->getNhits()
1069 << " Nster " <<(*iter_trk)->nster() <<endreq;
1070 // so ,use this to get the hits vector belong to this track ...
1071 HitRefVec gothits = (*iter_trk)->getVecHits();
1072
1073 MdcRec_trk* rectrk = new MdcRec_trk;
1074
1075 rectrk->id = (*iter_trk)->trackId();
1076 rectrk->chiSq = (*iter_trk)->chi2();
1077 rectrk->ndf = (*iter_trk)->ndof();
1078 rectrk->fiTerm = (*iter_trk)->getFiTerm();
1079 rectrk->nhits = (*iter_trk)->getNhits();
1080 rectrk->nster = (*iter_trk)->nster();
1081 rectrk->nclus = 0;
1082 rectrk->stat = (*iter_trk)->stat();
1083 status_temp = (*iter_trk)->stat();
1084 MdcRec_trk_add* trkadd = new MdcRec_trk_add;
1085 trkadd->id = (*iter_trk)->trackId();
1086 trkadd->quality = 0;
1087 trkadd->kind = 1;
1088 trkadd->decision = 0;
1089 trkadd->body = rectrk;
1090 rectrk->add = trkadd;
1091
1092 for ( int i=0; i<5; i++) {
1093 rectrk->helix[i] = (*iter_trk)->helix()[i];
1094 if( i<3 ) rectrk->pivot[i] = (*iter_trk)->getPivot()[i];
1095 for( int j = 1; j<i+2;j++) {
1096 rectrk->error[i*(i+1)/2+j-1] = (*iter_trk)->err()(i+1,j);
1097 }
1098 }
1099 std::sort(gothits.begin(), gothits.end(), order_rechits);
1100 HitRefVec::iterator it_gothit = gothits.begin();
1101 for( ; it_gothit != gothits.end(); it_gothit++) {
1102
1103 if( (*it_gothit)->getStat() != 1 ) {
1104 if(activeonly_) {
1105 log<<MSG::WARNING<<"this hit is not used in helix fitting!"<<endreq;
1106 continue;
1107 }
1108 }
1109
1110 log << MSG::DEBUG << "retrieved hits in MDC tracks:"
1111 << " hits DDL " <<(*it_gothit)->getDriftDistLeft()
1112 << " hits DDR " <<(*it_gothit)->getDriftDistRight()
1113 << " error DDL " <<(*it_gothit)->getErrDriftDistLeft()
1114 << " error DDR " <<(*it_gothit)->getErrDriftDistRight()
1115 << " id of hit "<<(*it_gothit)->getId()
1116 << " track id of hit "<<(*it_gothit)->getTrkId()
1117 << " hits ADC " <<(*it_gothit)->getAdc() << endreq;
1118
1119 MdcRec_wirhit* whit = new MdcRec_wirhit;
1120 whit->id = (*it_gothit)->getId();
1121 whit->ddl = (*it_gothit)->getDriftDistLeft();
1122 whit->ddr = (*it_gothit)->getDriftDistRight();
1123 whit->erddl = (*it_gothit)->getErrDriftDistLeft();
1124 whit->erddr = (*it_gothit)->getErrDriftDistRight();
1125 whit->pChiSq = (*it_gothit)->getChisqAdd();
1126 whit->lr = (*it_gothit)->getFlagLR();
1127 whit->stat = (*it_gothit)->getStat();
1128 mdcid = (*it_gothit)->getMdcId();
1129 int layid = MdcID::layer(mdcid);
1130 int localwid = MdcID::wire(mdcid);
1131 int w0id = geosvc->Layer(layid)->Wirst();
1132 int wid = w0id + localwid;
1133 log << MSG::INFO
1134 << "lr from PR: "<<whit->lr
1135 << " layerId = " << layid
1136 << " wireId = " << localwid
1137 << endreq;
1138
1139 const MdcGeoWire * const wirgeo = geosvc->Wire(wid);
1140
1141 //std::cout<<"the track id of *it_gothit... "<<(*it_gothit)->getTrackId()<<std::endl;
1142 whit->rechitptr = *it_gothit;
1143 whit->geo = wirgeo;
1144 whit->dat = 0;
1145 whit->trk = rectrk;
1146 whit->tdc = (*it_gothit)->getTdc();
1147 whit->adc= (*it_gothit)->getAdc();
1148 rectrk->hitcol.push_back(whit);
1149 mhit_mgr->push_back(*whit);
1150 }
1151 mtrk_mgr->push_back(*rectrk);
1152 mtrkadd_mgr->push_back(*trkadd);
1153
1154 delete rectrk;
1155 delete trkadd;
1156 }
1157
1158 // check trkcol: evt level
1159 if(ntuple_&4) {
1160 m_trkdelx = trkx1 - trkx2;
1161 m_trkdely = trky1 - trky2;
1162 m_trkdelz = trkz1 - trkz2;
1163 m_trkdelthe = trkthe1 + trkthe2;
1164 m_trkdelphi = trkphi1- trkphi2;
1165 m_trkdelp = trkp1 - trkp2;
1166 StatusCode sc4 = m_nt4->write();
1167 if( sc4.isFailure() ) cout<<"Ntuple4 filling failed!"<<endl;
1168 }
1169
1170 if(debug_ == 4) { std::cout<<"before refit,ntrk,nhits,nadd..."<<mtrk_mgr->size()
1171 <<"********"<<mhit_mgr->size()<<"****"<<mtrkadd_mgr->size()<<endl;
1172 }
1173
1174 if(useNCGem_>0) makeGemHitsCol();
1175
1176 // Actual fitter procedure :
1177 //cout << "m_trackid" << m_trackid << endl;
1178 //cout << "m_qua" << m_qua << endl;
1179 //cout << "m_esti" << m_esti1_r[0] << endl;
1180 if(usage_ == 0) kalman_fitting_anal();
1181 if(usage_ == 1) kalman_fitting_calib();
1182 double mdang = 180.0 - csmp3[0].angle(csmp3[1].unit())*180.0/M_PI;
1183 double mdphi = 180.0 - fabs(csmphi[0]-csmphi[1])*180.0/M_PI;
1184 //std::cout<<"before refit,ntrk,nhits,nadd..."<<mtrk_mgr->size()<<" , "<<mhit_mgr->size()<<" , "<<mtrkadd_mgr->size()<<endl;
1185 if(usage_ == 2 && (mtrk_mgr->size())==2 && fabs(mdang)<m_dangcut && fabs(mdphi)<m_dphicut) kalman_fitting_csmalign();
1186 if(usage_ == 3 && (mtrk_mgr->size())==1 && status_temp==-1) kalman_fitting_MdcxReco_Csmc_Sew();
1187
1188 log << MSG::DEBUG <<"after kalman_fitting(),but in execute...."<<endreq;
1189 clearTables();
1190
1191
1192 ///*
1193 // --- test for songxy
1194 MdcID mdcId;
1195 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
1196 //cout<<"------------------------ new event ---------------------"<<endl;
1197 //cout<<"recmdckaltrkCol->size()="<<recmdckaltrkCol->size()<<endl;
1198 //cout<<"--------------------------------------------------------"<<endl;
1200 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
1201 int i_trk=0;
1202 for(;KalTrk !=recmdckaltrkCol->end();KalTrk++){
1203 //cout<<"*** track "<<i_trk++<<" ***"<<endl;
1204 for(int hypo=0; hypo<5; hypo++)
1205 {
1206 if((*KalTrk)->getStat(0,hypo)==1) nFailedTrks[hypo]++;
1207 }
1208 HelixSegRefVec gothelixsegs = (*KalTrk)->getVecHelixSegs();
1209 HelixSegRefVec::iterator iter_hit = gothelixsegs.begin();
1210 //if(iter_hit == gothelixsegs.end())cout<<"iter_hit == gothelixsegs.end()"<<endl;
1211 int nhitofthistrk=0;
1212 for( ; iter_hit != gothelixsegs.end(); iter_hit++){
1213 nhitofthistrk++;
1214 //cout<<"layerId: "<<(*iter_hit)->getLayerId()<<endl;
1215 //cout<<"Identifier: "<<(*iter_hit)->getMdcId()<<endl;
1216 //cout<<"layerId: "<<mdcId.layer((*iter_hit)->getMdcId())<<endl;
1217 //cout<<"getDT: "<<(*iter_hit)->getDT()<<endl;
1218 }
1219 iter_hit=gothelixsegs.begin();
1220 //for(int m=0; m<nhitofthistrk/5;m++){
1221 // identifier = (*iter_hit) -> getMdcId();
1222 //}
1223 }
1224 // */
1225
1226 // --- test for getStat(2, pid)
1227 /*
1228 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
1229 SmartDataPtr<RecMdcTrackCol> mdcTrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
1230 //RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
1231 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
1232 int i_trk=0;
1233 for(RecMdcTrackCol::iterator mdcTrk = mdcTrkCol->begin(); KalTrk !=recmdckaltrkCol->end(); KalTrk++, mdcTrk++){
1234 cout<<"*** track "<<i_trk++<<" ***"<<endl;
1235 cout<<"trackId mdc: "<<(*mdcTrk)->trackId()<<endl;
1236 cout<<"trackId kal: "<<(*KalTrk)->trackId()<<endl;
1237 bool KalIsValid = true;
1238 for(int i_pid=0; i_pid<5; i_pid++) {
1239 cout<<"pid "<<i_pid<<" state 0 : "<<(*KalTrk)->getStat(0, i_pid)<<endl;
1240 cout<<"pid "<<i_pid<<" state 1 : "<<(*KalTrk)->getStat(1, i_pid)<<endl;
1241 if((*KalTrk)->getStat(0, i_pid)==1) {
1242 KalIsValid = false;
1243 switch(i_pid) {
1244 case 0: RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
1245 break;
1246 case 1: RecMdcKalTrack::setPidType(RecMdcKalTrack::muon);
1247 break;
1248 case 2: RecMdcKalTrack::setPidType(RecMdcKalTrack::pion);
1249 break;
1250 case 3: RecMdcKalTrack::setPidType(RecMdcKalTrack::kaon);
1251 break;
1252 case 4: RecMdcKalTrack::setPidType(RecMdcKalTrack::proton);
1253 break;
1254 }
1255 cout<<"Helix Kal: "<<(*KalTrk)->helix()<<endl;
1256 cout<<"Helix Kal err: "<<(*KalTrk)->err()<<endl;
1257 }
1258 }
1259 if(!KalIsValid) {
1260 cout<<"Helix Mdc: "<<(*mdcTrk)->helix()<<endl;
1261 cout<<"Helix Mdc err: "<<(*mdcTrk)->err()<<endl;
1262 }
1263 }
1264 */
1265 if(ifProdNt11)
1266 {
1267 SmartDataPtr<Event::CgemMcHitCol> cgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
1268 if (!cgemMcHitCol){
1269 log << MSG::WARNING << "Could not retrieve Cgem MC truth" << endreq;
1270 return StatusCode::FAILURE;
1271 }
1272 m_evt4=eventHeader->eventNumber();
1273 Event::CgemMcHitCol::iterator iter_truth = cgemMcHitCol->begin();
1274 int jj=0;
1275 double dprex,dprey,dprez,dpostx,dposty,dpostz;
1276 int layer;
1277 for(; iter_truth != cgemMcHitCol->end(); ++iter_truth){
1278 layer = (*iter_truth)->GetLayerID();
1279 dprex = (*iter_truth)->GetPositionXOfPrePoint();
1280 dprey = (*iter_truth)->GetPositionYOfPrePoint();
1281 dprez = (*iter_truth)->GetPositionZOfPrePoint();
1282 dpostx = (*iter_truth)->GetPositionXOfPostPoint();
1283 dposty = (*iter_truth)->GetPositionYOfPostPoint();
1284 dpostz = (*iter_truth)->GetPositionZOfPostPoint();
1285
1286 double midx=0;
1287 double midy=0;
1288 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(layer);
1289 double diR = CgemLayer->getInnerROfGapD();
1290 double dmR = CgemLayer->getMiddleROfGapD();
1291 double doR = CgemLayer->getOuterROfGapD();
1292 if((dprex >=0&&dprey>=0)||(dprex <0&&dprey>=0)){
1293 //m_dtphi[jj] = acos(dprex/dr_layer[layer]);
1294 m_dtphi[jj] = acos(dprex/diR);
1295 m_dtv[jj] = dprez;
1296 //m_dtpostphi[jj] = acos(dpostx/dor_layer[layer]);
1297 m_dtpostphi[jj] = acos(dpostx/doR);
1298 m_dtpostz[jj]= dpostz;
1299 }
1300 if((dprex <0&&dprey<0)||(dprex >=0&&dprey<0)){
1301 //m_dtphi[jj] = -acos(dprex/dr_layer[layer]);
1302 m_dtphi[jj] = -acos(dprex/diR);
1303 m_dtv[jj] = dprez;
1304 //m_dtpostphi[jj] = -acos(dpostx/dor_layer[layer]);
1305 m_dtpostphi[jj] = -acos(dpostx/doR);
1306 m_dtpostz[jj]= dpostz;
1307 }
1308 midx=(dprex+dpostx)/2;
1309 midy=(dprey+dposty)/2;
1310 if((midx>=0&&midy>=0)||(midx<0&&midy>=0)){
1311 //m_dtphi[jj]=acos(midx/dmr_layer[layer]);
1312 m_dtphi[jj]=acos(midx/dmR);
1313 }
1314 if((midx<0&&midy<0)||(midx>=0&&midy<0)){
1315 //m_dtphi[jj]=-acos(midx/dmr_layer[layer]);
1316 m_dtphi[jj]=-acos(midx/dmR);
1317 }
1318 m_dtv[jj] = (m_dtv[jj]+m_dtpostz[jj])/20;
1319 m_tlayer[jj] = layer;
1320 jj++;
1321 }
1322 m_ntruth = jj;
1323
1324 m_nt11->write();
1325 }
1326
1327
1328
1329 return StatusCode::SUCCESS;
1330}
1331
1332// Fill TDS:
1334 RecMdcKalTrack* trk , int l_mass) {
1335
1336 HepPoint3D IP(0,0,0);
1337 track.pivot(IP);
1338 // Fit quality
1339 int iqual(1);
1340 int trasster = TrasanTRK.nster, trakster = track.nster(),
1341 trasax(TrasanTRK.nhits-trasster), trakax(track.nchits()-trakster);
1342 if (TrasanTRK.nhits-track.nchits()>fitnocut_ ||
1343 TrasanTRK.helix[2]*track.a()[2]<0)
1344 iqual = 0;
1345
1346 if (debug_ == 4) {
1347 cout<< "trasster trakster trasax trakax TrasK trackK iqual"<<endl
1348 <<trasster<<" "<<trakster<<" "<<trasax<<" "<<trakax
1349 <<" "<<TrasanTRK.helix[2]<<" "<<track.a()[2]<<" "<<iqual<<endl;
1350 cout<<"FillTds> track.chiSq..."<<track.chiSq()<<" nchits "<<track.nchits()
1351 <<" nster "<<track.nster()<<" iqual "<<iqual<<" track.Ea "<< track.Ea()<<endl;
1352
1353 cout<<"fillTds>.....track.Ea[2][2] "<<track.Ea()[2][2]<<endl;
1354 cout << " TRASAN stereo = " << trasster
1355 << " and KalFitTrack = " << trakster << std::endl;
1356 cout << " TRASAN axial = " << trasax
1357 << " and KalFitTrack = " << trakax << std::endl;
1358
1359 if (!iqual) {
1360 cout << "...there is a problem during fit !! " << std::endl;
1361 if (trasster-trakster>5)
1362 cout << " because stereo " << trasster-trakster << std::endl;
1363 if (trasax-trakax >5)
1364 cout << " because axial " << std::endl;
1365 if (TrasanTRK.helix[2]*track.a()[2]<0)
1366 cout << " because kappa sign " << std::endl;
1367 }
1368 }
1369 // Protection : if any problem, we keep the original information !!!!
1370 if (track.nchits() > 5 && track.nster() > 1 &&
1371 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1372 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1373 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1374 track.Ea()[4][4] > 0 && iqual) {
1375 if(debug_ == 4) cout<<"fillTds>.....going on "<<endl;
1376 trk->setStat(0,0,l_mass);
1377 trk->setMass(track.mass(),l_mass);
1378
1379 // chisq & ndf
1380 trk->setChisq(track.chiSq(),0,l_mass);
1381 trk->setNdf(track.nchits()-5,0,l_mass);
1382 trk->setNhits(track.nchits(),l_mass);
1383
1384 trk->setFHelix(track.a(),l_mass);
1385 trk->setFError(track.Ea(),l_mass);
1386
1387 } else {
1388
1389 if(debug_) cout<<"ALARM: FillTds Not refit with KalFilter!!!"<<endl;
1390 // NOT refit with Kalman filter :
1391 trk->setStat(1,0,l_mass);
1392 trk->setMass(KalFitTrack::mass(l_mass),l_mass);
1393 // chisq & ndf (0 : filter ; 1 : smoother;)
1394 trk->setChisq(TrasanTRK.chiSq,0,l_mass);
1395 trk->setNdf(TrasanTRK.nhits-5,0,l_mass);
1396 // nhits
1397 trk->setNhits(TrasanTRK.nhits,l_mass);
1398 double a_trasan[5], ea_trasan[15];
1399 for( int i =0 ; i <5; i++){
1400 a_trasan[i] = TrasanTRK.helix[i];
1401 }
1402 for( int j =0 ; j <15; j++){
1403 ea_trasan[j] = TrasanTRK.error[j];
1404 }
1405 trk->setFHelix(a_trasan, l_mass);
1406 trk->setFError(ea_trasan,l_mass);
1407 }
1408}
1409
1410// Fill Tds :
1412 RecMdcKalTrack* trk , int l_mass) {
1413
1414 HepPoint3D IP(0,0,0);
1415 track.pivot(IP);
1416 // Fit quality
1417 // int iqual(1);
1418 int trasster = TrasanTRK.nster, trakster = track.nster(),
1419 trasax(TrasanTRK.nhits-trasster), trakax(track.nchits()-trakster);
1420 if (TrasanTRK.nhits-track.nchits()>fitnocut_ ||
1421 TrasanTRK.helix[2]*track.a()[2]<0)
1422 iqual_front_[l_mass] = 0;
1423 if (debug_ == 4) {
1424
1425 cout<<"Nhit from PR "<<TrasanTRK.nhits<<" nhit "<<track.nchits()<<endl;
1426 cout<< "trasster trakster trasax trakax TrasK trackK iqual"<<endl
1427 <<trasster<<" "<<trakster<<" "<<trasax<<" "<<trakax
1428 <<" "<<TrasanTRK.helix[2]<<" "<<track.a()[2]<<" "<<iqual_front_[l_mass]<<endl;
1429 cout<<"FillTds_lead> track.chiSq..."<<track.chiSq()<<" nchits "<<track.nchits()
1430 <<" nster "<<track.nster()<<" iqual_front_[l_mass] "<<iqual_front_[l_mass]<<" track.Ea "<<track.Ea()<<endl;
1431
1432 cout << " TRASAN stereo = " << trasster
1433 << " and KalFitTrack = " << trakster << std::endl;
1434 cout << " TRASAN axial = " << trasax
1435 << " and KalFitTrack = " << trakax << std::endl;
1436
1437 if (!iqual_front_[l_mass]) {
1438 cout << "...there is a problem during fit !! " << std::endl;
1439 if (trasster-trakster>5)
1440 cout << " because stereo " << trasster-trakster << std::endl;
1441 if (trasax-trakax >5)
1442 cout << " because axial " << std::endl;
1443 if (TrasanTRK.helix[2]*track.a()[2]<0)
1444 cout << " because kappa sign " << std::endl;
1445 }
1446 }
1447 // Protection : if any problem, we keep the original information !!!!
1448 if (track.nchits() > 5 && track.nster() > 1 &&
1449 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1450 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1451 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1452 track.Ea()[4][4] > 0 && iqual_front_[l_mass]) {
1453
1454 trk->setStat(0,0,l_mass);
1455 trk->setMass(track.mass(),l_mass);
1456 trk->setChisq(track.chiSq(),0,l_mass);
1457 trk->setNdf(track.nchits()-5,0,l_mass);
1458 trk->setNhits(track.nchits(),l_mass);
1459 //trkid
1460 trk->setTrackId(TrasanTRK.id);
1461
1462 if (debug_ == 4) cout<<" trasan id...1 "<<TrasanTRK.id<<endl;
1463
1464 trk->setFHelix(track.a(),l_mass);
1465 trk->setFError(track.Ea(),l_mass);
1466
1467 } else {
1468
1469 //cout<<"copy Mdc Helix in fillTds_lead()"<<endl;
1470
1471 if(debug_) cout<<"ALARM: FillTds_forMdc Not refit with KalFilter!!!"<<endl;
1472 // NOT refit with Kalman filter :
1473 trk->setStat(1,0,l_mass);
1474 trk->setMass(KalFitTrack::mass(l_mass),l_mass);
1475
1476 // chisq & ndf
1477 trk->setChisq(TrasanTRK.chiSq,0,l_mass);
1478 trk->setNdf(TrasanTRK.nhits-5,0,l_mass);
1479 //trkid
1480 trk->setTrackId(TrasanTRK.id);
1481
1482 if (debug_ ==4) cout<<" trasan id...2 "<<TrasanTRK.id<<endl;
1483
1484 // nhits
1485 trk->setNhits(TrasanTRK.nhits,l_mass);
1486 double a_trasan[5], ea_trasan[15];
1487 for( int i =0 ; i <5; i++){
1488 a_trasan[i] = TrasanTRK.helix[i];
1489 }
1490 for( int j =0 ; j <15; j++){
1491 ea_trasan[j] = TrasanTRK.error[j];
1492 }
1493 trk->setFHelix(a_trasan,l_mass);
1494 trk->setFError(ea_trasan,l_mass);
1495 // trk->setFHelix(TrasanTRK.helix,l_mass);
1496 // trk->setFError(TrasanTRK.error,l_mass);
1497 }
1498}
1499
1500
1501
1502
1504 RecMdcKalTrack* trk, int l_mass)
1505{
1506 HepPoint3D IP(0,0,0);
1507 track.pivot(IP);
1508
1509 if (debug_ == 4&& l_mass==lead_) {
1510 cout << "fillTds_IP>......"<<endl;
1511 cout << " dr = " << track.a()[0]
1512 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
1513 cout << " phi0 = " << track.a()[1]
1514 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
1515 cout << " PT = " << 1/track.a()[2]
1516 << ", Er_kappa =" << sqrt(track.Ea()[2][2]) << std::endl;
1517 cout << " dz = " << track.a()[3]
1518 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
1519 cout << " tanl = " << track.a()[4]
1520 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
1521 }
1522
1523 if (TrasanTRK.nhits-track.nchits()>fitnocut_ ||
1524 TrasanTRK.helix[2]*track.a()[2]<0)
1525 iqual_front_[l_mass] = 0;
1526
1527
1528 if (track.nchits() > 5 && track.nster() > 1 &&
1529 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1530 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1531 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1532 track.Ea()[4][4] > 0 && iqual_front_[l_mass]) {
1533
1534 // fill track information
1535 double dr = track.a()[0];
1536 double phi0 = track.a()[1];
1537 double kappa = track.a()[2];
1538 double dz = track.a()[3];
1539 double tanl = track.a()[4];
1540
1541 // vertex of the track
1542 double vx = dr*cos(phi0);
1543 double vy = dr*sin(phi0);
1544 double vz = dz;
1545
1546 // see Belle note148 for the formulas
1547 // initial momentum of the track
1548 if(0==kappa) kappa = 10e-10;
1549 double px = -sin(phi0)/fabs(kappa);
1550 double py = cos(phi0)/fabs(kappa);
1551 double pz = tanl/fabs(kappa);
1552
1553 trk->setX(vx, l_mass);
1554 trk->setY(vy, l_mass);
1555 trk->setZ(vz, l_mass);
1556 trk->setPx(px, l_mass);
1557 trk->setPy(py, l_mass);
1558 trk->setPz(pz, l_mass);
1559
1560 const HepPoint3D poca(dr*cos(phi0),dr*sin(phi0),dz);
1561 trk->setPoca(poca,l_mass);
1562
1563 trk->setZHelix(track.a(),l_mass);
1564 trk->setZError(track.Ea(),l_mass);
1565
1566
1567 //set charge
1568 int charge=0;
1569 if (kappa > 0.0000000001)
1570 charge = 1;
1571 else if (kappa < -0.0000000001)
1572 charge = -1;
1573 trk->setCharge(charge,l_mass);
1574
1575 //set theta
1576 double ptot = sqrt(px*px+py*py+pz*pz);
1577 trk->setTheta(acos(pz/ptot),l_mass);
1578 }
1579
1580 else{
1581 //cout<<"copy Mdc Helix in fillTds_ip()"<<endl;
1582
1583 // fill track information
1584 double dr = TrasanTRK.helix[0];
1585 double phi0 = TrasanTRK.helix[1];
1586 double kappa = TrasanTRK.helix[2];
1587 double dz = TrasanTRK.helix[3];
1588 double tanl = TrasanTRK.helix[4];
1589
1590 double vx = dr*cos(phi0);
1591 double vy = dr*sin(phi0);
1592 double vz = dz;
1593
1594 if(0==kappa) kappa = 10e-10;
1595 double px = -sin(phi0)/fabs(kappa);
1596 double py = cos(phi0)/fabs(kappa);
1597 double pz = tanl/fabs(kappa);
1598
1599 trk->setX(vx, l_mass);
1600 trk->setY(vy, l_mass);
1601 trk->setZ(vz, l_mass);
1602
1603 trk->setPx(px, l_mass);
1604 trk->setPy(py, l_mass);
1605 trk->setPz(pz, l_mass);
1606
1607 const HepPoint3D poca(dr*cos(phi0),dr*sin(phi0),dz);
1608
1609 trk->setPoca(poca,l_mass);
1610 //trk->setZHelix(TrasanTRK.helix,l_mass);
1611 //trk->setZError(TrasanTRK.error,l_mass);
1612 double a_trasan[5], ea_trasan[15];
1613 for( int i =0 ; i <5; i++){
1614 a_trasan[i] = TrasanTRK.helix[i];
1615 }
1616 for( int j =0 ; j <15; j++){
1617 ea_trasan[j] = TrasanTRK.error[j];
1618 }
1619 trk->setZHelix(a_trasan,l_mass);
1620 trk->setZError(ea_trasan,l_mass);
1621
1622 //set charge
1623 int charge=0;
1624 if (kappa > 0.0000000001)
1625 charge = 1;
1626 else if (kappa < -0.0000000001)
1627 charge = -1;
1628 trk->setCharge(charge,l_mass);
1629
1630 //set theta
1631 double ptot = sqrt(px*px+py*py+pz*pz);
1632 trk->setTheta(acos(pz/ptot),l_mass);
1633 }
1634
1635 if(4==debug_) {
1637 std::cout<<"px: "<<trk->px()<<" py: "<<trk->py()<<" pz: "<<trk->pz()<<std::endl;
1638 std::cout<<"vx: "<<trk->x()<<" vy: "<<trk->y()<<" vz: "<<trk->z()<<std::endl;
1639 }
1640}
1641
1642
1644 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass)
1645{
1646
1647 HepPoint3D IP(0,0,0);
1648 //track.pivot(IP);
1649
1650 // Fit quality
1651 int iqual(1);
1652
1653 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5) iqual = 0;
1654
1655 if(debug_ == 4) cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0] "<<trk->getNdf(0,2)<<endl;
1656 if(debug_ == 4) cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
1657
1658 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
1659 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1660 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1661 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
1662 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
1663 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX &&
1664 iqual) {
1665
1666 // chisq ( for backward filter)
1667
1668 trk->setStat(0,1,l_mass);
1669 trk->setChisq(track.chiSq_back(),1,l_mass);
1670 trk->setNdf(track.ndf_back()-5,1,l_mass);
1671 trk->setLength(track.pathip(),l_mass);
1672 if(debug_ == 4) cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
1673 trk->setTof(track.tof(),l_mass);
1674
1676 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
1677 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
1678 }
1679
1680 // Path length in each MDC layer :
1681 if (pathl_)
1682 for (int i = 0; i<43; i++) {
1683 trk->setPathl(track.pathl()[i],i);
1684 }
1685
1686 trk->setLHelix(track.a(),l_mass);
1687 trk->setLError(track.Ea(),l_mass);
1688 trk->setLPivot(track.pivot(),l_mass);
1689
1690 trk->setLPoint(track.point_last(),l_mass);
1691 trk->setPathSM(track.getPathSM(),l_mass);
1692 trk->setTof(track.getTofSM(),l_mass);
1693 trk->setFiTerm(track.getFiTerm(),l_mass);
1694
1695 if(4 == debug_){
1696 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
1697 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
1698 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
1699 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
1700 }
1701
1702 } else {
1703 if(debug_) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
1704 // NOT refit with Kalman filter :
1705 trk->setStat(1,1,l_mass);
1706 HepPoint3D piv(TrasanTRK.pivot[0],
1707 TrasanTRK.pivot[1],
1708 TrasanTRK.pivot[2]);
1709
1710 HepVector a(5);
1711 for(int i = 0; i < 5; i++)
1712 a[i] = TrasanTRK.helix[i];
1713
1714 HepSymMatrix ea(5);
1715 for(int i = 0, k = 0; i < 5; i++) {
1716 for(int j = 0; j <= i; j++) {
1717 ea[i][j] = matrixg_*TrasanTRK.error[k++];
1718 ea[j][i] = ea[i][j];
1719 }
1720 }
1721
1722 KalFitTrack track_rep(piv, a, ea, lead_,
1723 TrasanTRK.chiSq, TrasanTRK.nhits);
1724 double fiTerm = TrasanTRK.fiTerm;
1725
1726 double fi0 = track_rep.phi0();
1727 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
1728 track_rep.center() );
1729 double x = xc.x();
1730 double y = xc.y();
1731 double phi_x;
1732 if( fabs( x ) > 1.0e-10 ){
1733 phi_x = atan2( y, x );
1734 if( phi_x < 0 ) phi_x += 2*M_PI;
1735 } else {
1736 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
1737 }
1738 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
1739 double dphi = fabs( fiTerm + fi0 - phi_x );
1740 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
1741 double tanl = track_rep.tanl();
1742 double cosl_inv = sqrt( tanl*tanl + 1.0 );
1743 if(debug_ == 4) {
1744 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
1745 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
1746 }
1747 double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
1748 double light_speed( 29.9792458 ); // light speed in cm/nsec
1749 double pt( 1.0 / track_rep.kappa() );
1750 double p( pt * sqrt( 1.0 + tanl*tanl ) );
1751
1752 // chisq (2 : for backward filter)
1753 trk->setStat(1,1,l_mass);
1754 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
1755 if(debug_ == 4) {
1756 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<endl;
1757 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<endl;
1758 }
1759 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
1760 trk->setLength(track_len,l_mass);
1761 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
1762 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1763 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
1764
1765 track_rep.pivot(IP);
1766
1767 trk->setLHelix(track_rep.a(),l_mass);
1768 trk->setLError(track_rep.Ea(),l_mass);
1769 trk->setLPivot(track.pivot(),l_mass);
1770
1771 /// right???
1772 trk->setLPoint(track.point_last(),l_mass);
1773 trk->setPathSM(track.getPathSM(),l_mass);
1774 trk->setTof(track.getTofSM(),l_mass);
1775 trk->setFiTerm(track.getFiTerm(),l_mass);
1776 }
1777
1778 // test--------
1779 if(debug_ == 4) {
1780
1781 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
1782 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
1783 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
1784
1785 cout<<"Now let us see results after smoothering at IP:........."<<endl;
1786 cout << " dr = " << track.a()[0]
1787 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
1788 cout<< " phi0 = " << track.a()[1]
1789 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
1790 cout << " PT = " << 1/track.a()[2]
1791 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
1792 cout << " dz = " << track.a()[3]
1793 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
1794 cout << " tanl = " << track.a()[4]
1795 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
1796 cout << " Ea = " << track.Ea() <<endl;
1797 }
1798 // test end ----------
1799}
1800
1802 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass,
1803 RecMdcKalHelixSegCol* segcol)
1804{
1805
1806 HepPoint3D IP(0,0,0);
1807
1808 // attention the pivot problem of the HelixSeg ... ???
1809 track.pivot(IP);
1810 // Fit quality
1811 //int iqual(1);
1812 //if ((trk->getNdf(0,2))-(track.ndf_back()-5)>5)
1813 // form getNdf(0,2) to getNdf(0,1) for muon hypothesis
1814
1815 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5){
1816 iqual_back_ = 0;
1817 }
1818 if(usage_>1){
1819 for(int i=0; i<5; i++) iqual_front_[i] = 1;
1820 iqual_back_ = 1;
1821 }
1822 if(debug_ == 4){
1823 std::cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0][l_mass] "<<trk->getNdf(0,l_mass)<<endl;
1824 std::cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
1825 std::cout<<"track.ndf_back(), track.chiSq_back(), track.Ea()[5][5], track.a()[5], iqual_front_, iqual_back_: "<<track.ndf_back()<<" , "<<track.chiSq_back()<<" , "<<track.Ea()<<" , "<<track.a()<<" , "<<iqual_front_[l_mass]<<" , "<<iqual_back_<<std::endl;
1826 }
1827
1828 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
1829 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1830 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1831 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
1832 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
1833 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX && iqual_front_[l_mass] && iqual_back_){
1834
1835 // chisq ( for backward filter)
1836 //std::cout<<"begin to fillTds_back track no. : "<<(++Tds_back_no)<<std::endl;
1837
1838
1839 HelixSegRefVec helixsegrefvec;
1840 for (vector<KalFitHelixSeg>::iterator it = track.HelixSegs().begin(); it!=track.HelixSegs().end();it ++)
1841 {
1842
1843 //std::cout<<" alpha of KalFitHelixSeg: "<<it->alpha()<<std::endl;
1844 //std::cout<<" doca1 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
1845
1846 it->pivot(IP);
1847
1848 //std::cout<<" doca2 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
1849
1850 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
1851 helixseg->setResIncl(it->residual_include());
1852 helixseg->setResExcl(it->residual_exclude());
1853 if(debug_ == 4) {
1854 std::cout<<"helixseg->Res_inc ..."<<helixseg->getResIncl()<<std::endl;
1855 }
1856 helixseg->setDrIncl(it->a_include()[0]);
1857 helixseg->setFi0Incl(it->a_include()[1]);
1858 helixseg->setCpaIncl(it->a_include()[2]);
1859 helixseg->setDzIncl(it->a_include()[3]);
1860 helixseg->setTanlIncl(it->a_include()[4]);
1861
1862
1863 helixseg->setDrExcl(it->a_exclude()[0]);
1864 helixseg->setFi0Excl(it->a_exclude()[1]);
1865 helixseg->setCpaExcl(it->a_exclude()[2]);
1866 helixseg->setDzExcl(it->a_exclude()[3]);
1867 helixseg->setTanlExcl(it->a_exclude()[4]);
1868
1869 helixseg->setHelixIncl(it->a_include());
1870 helixseg->setErrorIncl(it->Ea_include());
1871
1872 //Helix temp(IP, it->a(), it->Ea());
1873
1874 //std::cout<<" doca3 of KalFitHelixSeg: "<<(temp.approach(*(it->HitMdc()),false))<<std::endl;
1875
1876 helixseg->setHelixExcl(it->a_exclude());
1877 helixseg->setErrorExcl(it->Ea_exclude());
1878 helixseg->setLayerId(it->layer());
1879
1880 if(debug_ == 4) {
1881 std::cout<<"KalFitHelixSeg track id .."<<it->HitMdc()->rechitptr()->getTrkId()<<std::endl;
1882 std::cout<<"helixseg a: "<<it->a()<<std::endl;
1883 std::cout<<"helixseg a_excl: "<<helixseg->getHelixExcl()<<std::endl;
1884 std::cout<<"helixseg a_incl: "<<helixseg->getHelixIncl()<<std::endl;
1885
1886 std::cout<<"helixseg Ea: "<<it->Ea()<<std::endl;
1887 std::cout<<"helixseg Ea_excl: "<<helixseg->getErrorExcl()<<std::endl;
1888 std::cout<<"helixseg Ea_incl: "<<helixseg->getErrorIncl()<<std::endl;
1889
1890 std::cout<<"helixseg layer: "<<it->layer()<<std::endl;
1891 }
1892
1893
1894 helixseg->setTrackId(it->HitMdc()->rechitptr()->getTrkId());
1895 helixseg->setMdcId(it->HitMdc()->rechitptr()->getMdcId());
1896 helixseg->setFlagLR(it->HitMdc()->LR());
1897 helixseg->setTdc(it->HitMdc()->rechitptr()->getTdc());
1898 helixseg->setAdc(it->HitMdc()->rechitptr()->getAdc());
1899 helixseg->setZhit(it->HitMdc()->rechitptr()->getZhit());
1900 helixseg->setTof(it->tof());
1901 helixseg->setDocaIncl(it->doca_include());
1902 helixseg->setDocaExcl(it->doca_exclude());
1903 helixseg->setDD(it->dd());
1904 helixseg->setEntra(it->HitMdc()->rechitptr()->getEntra());
1905 helixseg->setDT(it->dt());
1906 segcol->push_back(helixseg);
1907 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
1908 helixsegrefvec.push_back(refhelixseg);
1909
1910 if(ntuple_&8){
1911 m_docaInc = helixseg -> getDocaIncl();
1912 m_docaExc = helixseg -> getDocaExcl();
1913 m_residualInc = helixseg -> getResIncl();
1914 m_residualExc = helixseg -> getResExcl();
1915 m_dd = helixseg -> getDD();
1916 m_lr = helixseg->getFlagLR();
1917 m_tdrift = helixseg -> getDT();
1918 m_layerid = helixseg -> getLayerId();
1919 m_yposition= it->HitMdc()->wire().fwd().y();
1920 m_eventNo = eventNo;
1921 StatusCode sc6 = m_nt6->write();
1922 if( sc6.isFailure() ) cout<<"Ntuple6 helixseg filling failed!"<<endl;
1923
1924 }
1925 }
1926
1927 trk->setVecHelixSegs(helixsegrefvec, l_mass);
1928 if(debug_ == 4) {
1929 std::cout<<"trk->getVecHelixSegs size..."<<(trk->getVecHelixSegs()).size()<<std::endl;
1930 }
1931 trk->setStat(0,1,l_mass);
1932 trk->setChisq(track.chiSq_back(),1,l_mass);
1933 trk->setNdf(track.ndf_back()-5,1,l_mass);
1934 // add setNhits ,maybe some problem
1935 trk->setNhits(track.ndf_back(),l_mass);
1936 if(!(track.ndf_back()==track.HelixSegs().size())) {
1937 std::cout<<"THEY ARE NOT EQUALL!!!"<<std::endl;
1938 }
1939 trk->setLength(track.pathip(),l_mass);
1940 if(debug_ == 4) {
1941 std::cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
1942 }
1943 trk->setTof(track.tof(),l_mass);
1945 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
1946 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
1947 }
1948 // Path length in each MDC layer :
1949 if (pathl_)
1950 for (int i = 0; i<43; i++) {
1951 trk->setPathl(track.pathl()[i],i);
1952 }
1953 trk->setLHelix(track.a(),l_mass);
1954 trk->setLError(track.Ea(),l_mass);
1955 trk->setLPivot(track.pivot(),l_mass);
1956
1957 trk->setLPoint(track.point_last(),l_mass);
1958 trk->setPathSM(track.getPathSM(),l_mass);
1959 trk->setTof(track.getTofSM(),l_mass);
1960 trk->setFiTerm(track.getFiTerm(),l_mass);
1961 double a_trasan[5], ea_trasan[15];
1962 for( int i =0 ; i <5; i++){
1963 a_trasan[i] = TrasanTRK.helix[i];
1964 }
1965 for( int j =0 ; j <15; j++){
1966 ea_trasan[j] = TrasanTRK.helix[j];
1967 }
1968 trk->setTHelix(a_trasan);
1969 trk->setTError(ea_trasan);
1970
1971 if(4 == debug_){
1972 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
1973 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
1974 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
1975 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
1976 }
1977
1978 } else {
1979
1980 if(debug_) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
1981 // NOT refit with Kalman filter :
1982 trk->setStat(1,1,l_mass);
1983
1984 HepPoint3D piv(TrasanTRK.pivot[0],
1985 TrasanTRK.pivot[1],
1986 TrasanTRK.pivot[2]);
1987
1988 HepVector a(5);
1989 for(int i = 0; i < 5; i++)
1990 a[i] = TrasanTRK.helix[i];
1991
1992 HepSymMatrix ea(5);
1993 for(int i = 0, k = 0; i < 5; i++) {
1994 for(int j = 0; j <= i; j++) {
1995 ea[i][j] = matrixg_*TrasanTRK.error[k++];
1996 ea[j][i] = ea[i][j];
1997 }
1998 }
1999
2000 KalFitTrack track_rep(piv, a, ea, lead_,
2001 TrasanTRK.chiSq, TrasanTRK.nhits);
2002 double fiTerm = TrasanTRK.fiTerm;
2003
2004 double fi0 = track_rep.phi0();
2005 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2006 track_rep.center() );
2007 double x = xc.x();
2008 double y = xc.y();
2009 double phi_x;
2010 if( fabs( x ) > 1.0e-10 ){
2011 phi_x = atan2( y, x );
2012 if( phi_x < 0 ) phi_x += 2*M_PI;
2013 } else {
2014 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2015 }
2016 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2017 double dphi = fabs( fiTerm + fi0 - phi_x );
2018 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2019 double tanl = track_rep.tanl();
2020 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2021 if(debug_ == 4) {
2022 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2023 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2024 }
2025 double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2026 double light_speed( 29.9792458 ); // light speed in cm/nsec
2027 double pt( 1.0 / track_rep.kappa() );
2028 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2029
2030
2031 // chisq (2 : for backward filter)
2032
2033 trk->setStat(1,1,l_mass);
2034 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2035 if(debug_ == 4) {
2036 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<std::endl;
2037 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<std::endl;
2038 }
2039 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2040 trk->setLength(track_len,l_mass);
2041 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2042 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2043 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2044
2045 track_rep.pivot(IP);
2046
2047 trk->setLHelix(track_rep.a(),l_mass);
2048 trk->setLError(track_rep.Ea(),l_mass);
2049 trk->setLPivot(track.pivot(),l_mass);
2050
2051 /// right???
2052 trk->setLPoint(track.point_last(),l_mass);
2053 trk->setPathSM(track.getPathSM(),l_mass);
2054 trk->setTof(track.getTofSM(),l_mass);
2055 trk->setFiTerm(track.getFiTerm(),l_mass);
2056 trk->setTHelix(track_rep.a());
2057 trk->setTError(track_rep.Ea());
2058
2059 }
2060
2061 // test--------
2062 if(debug_ == 4) {
2063 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2064 cout << " dr = " << track.a()[0]
2065 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2066 cout<< " phi0 = " << track.a()[1]
2067 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2068 cout << " PT = " << 1/track.a()[2]
2069 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2070 cout << " dz = " << track.a()[3]
2071 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2072 cout << " tanl = " << track.a()[4]
2073 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2074 cout << " Ea = " << track.Ea() <<endl;
2075 }
2076 // test end ----------
2077}
2078
2080 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass,
2081 RecMdcKalHelixSegCol* segcol, int smoothflag)
2082{
2083
2084 HepPoint3D IP(0,0,0);
2085
2086 // attention the pivot problem of the HelixSeg ... ???
2087 //track.pivot(IP);
2088 // Fit quality
2089 //int iqual(1);
2090 //if ((trk->getNdf(0,2))-(track.ndf_back()-5)>5)
2091 // form getNdf(0,2) to getNdf(0,1) for muon hypothesis
2092
2093 iqual_back_ = 1;
2094 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5){
2095 iqual_back_ = 0;
2096 }
2097
2098 if(debug_ == 4){
2099 std::cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0][l_mass] "<<trk->getNdf(0,l_mass)<<endl;
2100 std::cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2101 }
2102
2103
2104 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2105 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2106 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2107 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2108 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2109 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX && iqual_front_[l_mass] && iqual_back_){
2110
2111 // chisq ( for backward filter)
2112 //std::cout<<"begin to fillTds_back track no. : "<<(++Tds_back_no)<<std::endl;
2113
2114
2115 HelixSegRefVec helixsegrefvec;
2116 for (vector<KalFitHelixSeg>::iterator it = track.HelixSegs().begin(); it!=track.HelixSegs().end();it ++)
2117 {
2118
2119 //std::cout<<" alpha of KalFitHelixSeg: "<<it->alpha()<<std::endl;
2120 //std::cout<<" doca1 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2121
2122 it->pivot(IP);
2123
2124 //std::cout<<" doca2 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2125
2126 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2127 helixseg->setResIncl(it->residual_include());
2128 helixseg->setResExcl(it->residual_exclude());
2129 if(debug_ == 4) {
2130 std::cout<<"helixseg->Res_inc ..."<<helixseg->getResIncl()<<std::endl;
2131 }
2132 // helixseg->setDrIncl(it->a_include()[0]);
2133 // helixseg->setFi0Incl(it->a_include()[1]);
2134 // helixseg->setCpaIncl(it->a_include()[2]);
2135 // helixseg->setDzIncl(it->a_include()[3]);
2136 // helixseg->setTanlIncl(it->a_include()[4]);
2137 //
2138 //
2139 // helixseg->setDrExcl(it->a_exclude()[0]);
2140 // helixseg->setFi0Excl(it->a_exclude()[1]);
2141 // helixseg->setCpaExcl(it->a_exclude()[2]);
2142 // helixseg->setDzExcl(it->a_exclude()[3]);
2143 // helixseg->setTanlExcl(it->a_exclude()[4]);
2144
2145 helixseg->setHelixIncl(it->a_include());
2146 //helixseg->setErrorIncl(it->Ea_include());
2147
2148 //Helix temp(IP, it->a(), it->Ea());
2149
2150 //std::cout<<" doca3 of KalFitHelixSeg: "<<(temp.approach(*(it->HitMdc()),false))<<std::endl;
2151
2152 helixseg->setHelixExcl(it->a_exclude());
2153 //helixseg->setErrorExcl(it->Ea_exclude());
2154 //helixseg->setLayerId(it->layer());
2155
2156 if(debug_ == 4) {
2157 std::cout<<"KalFitHelixSeg track id .."<<it->HitMdc()->rechitptr()->getTrkId()<<std::endl;
2158 std::cout<<"helixseg a: "<<it->a()<<std::endl;
2159 std::cout<<"helixseg a_excl: "<<helixseg->getHelixExcl()<<std::endl;
2160 std::cout<<"helixseg a_incl: "<<helixseg->getHelixIncl()<<std::endl;
2161
2162 std::cout<<"helixseg Ea: "<<it->Ea()<<std::endl;
2163 std::cout<<"helixseg Ea_excl: "<<helixseg->getErrorExcl()<<std::endl;
2164 std::cout<<"helixseg Ea_incl: "<<helixseg->getErrorIncl()<<std::endl;
2165
2166 std::cout<<"helixseg layer: "<<it->layer()<<std::endl;
2167 }
2168
2169
2170 helixseg->setTrackId(it->HitMdc()->rechitptr()->getTrkId());
2171 helixseg->setMdcId(it->HitMdc()->rechitptr()->getMdcId());
2172 helixseg->setFlagLR(it->HitMdc()->LR());
2173 helixseg->setTdc(it->HitMdc()->rechitptr()->getTdc());
2174 helixseg->setAdc(it->HitMdc()->rechitptr()->getAdc());
2175 helixseg->setZhit(it->HitMdc()->rechitptr()->getZhit());
2176 helixseg->setTof(it->tof());
2177 helixseg->setDocaIncl(it->doca_include());
2178 helixseg->setDocaExcl(it->doca_exclude());
2179 helixseg->setDD(it->dd());
2180 helixseg->setEntra(it->HitMdc()->rechitptr()->getEntra());
2181 helixseg->setDT(it->dt());
2182 //cout<<"setDT( "<<it->dt()<<" )"<<endl;
2183 segcol->push_back(helixseg);
2184 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2185 helixsegrefvec.push_back(refhelixseg);
2186 if(ntuple_&8){
2187 m_docaInc = helixseg -> getDocaIncl();
2188 m_docaExc = helixseg -> getDocaExcl();
2189 m_residualInc = helixseg -> getResIncl();
2190 m_residualExc = helixseg -> getResExcl();
2191 m_dd = helixseg -> getDD();
2192 m_lr = helixseg->getFlagLR();
2193 m_tdrift = helixseg -> getDT();
2194 m_layerid = helixseg -> getLayerId();
2195 m_yposition= it->HitMdc()->wire().fwd().y();
2196 m_eventNo = eventNo;
2197 StatusCode sc6 = m_nt6->write();
2198 if( sc6.isFailure() ) cout<<"Ntuple6 helixseg filling failed!"<<endl;
2199
2200 }
2201 }
2202
2203 trk->setVecHelixSegs(helixsegrefvec, l_mass);
2204 //cout<<"setVecHelixSegs with Kalman hits"<<endl;
2205 if(debug_ == 4) {
2206 std::cout<<"trk->getVecHelixSegs size..."<<(trk->getVecHelixSegs()).size()<<std::endl;
2207 }
2208 trk->setStat(0,1,l_mass);
2209 trk->setChisq(track.chiSq_back(),1,l_mass);
2210 trk->setNdf(track.ndf_back()-5,1,l_mass);
2211 // add setNhits ,maybe some problem
2212 trk->setNhits(track.ndf_back(),l_mass);
2213 if(!(track.ndf_back()==track.HelixSegs().size())) {
2214 std::cout<<"THEY ARE NOT EQUALL!!!"<<std::endl;
2215 }
2216 trk->setLength(track.pathip(),l_mass);
2217 if(debug_ == 4) {
2218 std::cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2219 }
2220 trk->setTof(track.tof(),l_mass);
2222 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2223 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2224 }
2225 // Path length in each MDC layer :
2226 if (pathl_)
2227 for (int i = 0; i<43; i++) {
2228 trk->setPathl(track.pathl()[i],i);
2229 }
2230 trk->setLHelix(track.a(),l_mass);
2231 trk->setLError(track.Ea(),l_mass);
2232 trk->setLPivot(track.pivot(),l_mass);
2233
2234 trk->setLPoint(track.point_last(),l_mass);
2235 trk->setPathSM(track.getPathSM(),l_mass);
2236 trk->setTof(track.getTofSM(),l_mass);
2237 trk->setFiTerm(track.getFiTerm(),l_mass);
2238 double a_trasan[5], ea_trasan[15];
2239 for( int i =0 ; i <5; i++){
2240 a_trasan[i] = TrasanTRK.helix[i];
2241 }
2242 for( int j =0 ; j <15; j++){
2243 ea_trasan[j] = TrasanTRK.helix[j];
2244 }
2245 trk->setTHelix(a_trasan);
2246 trk->setTError(ea_trasan);
2247
2248 if(4 == debug_){
2249 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2250 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2251 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2252 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2253 }
2254
2255 } else {
2256
2257 if(debug_) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2258 // NOT refit with Kalman filter :
2259 trk->setStat(1,1,l_mass);
2260
2261 HepPoint3D piv(TrasanTRK.pivot[0],
2262 TrasanTRK.pivot[1],
2263 TrasanTRK.pivot[2]);
2264
2265 HepVector a(5);
2266 for(int i = 0; i < 5; i++)
2267 a[i] = TrasanTRK.helix[i];
2268
2269 HepSymMatrix ea(5);
2270 for(int i = 0, k = 0; i < 5; i++) {
2271 for(int j = 0; j <= i; j++) {
2272 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2273 ea[j][i] = ea[i][j];
2274 }
2275 }
2276
2277 KalFitTrack track_rep(piv, a, ea, lead_,
2278 TrasanTRK.chiSq, TrasanTRK.nhits);
2279 double fiTerm = TrasanTRK.fiTerm;
2280
2281 double fi0 = track_rep.phi0();
2282 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2283 track_rep.center() );
2284 double x = xc.x();
2285 double y = xc.y();
2286 double phi_x;
2287 if( fabs( x ) > 1.0e-10 ){
2288 phi_x = atan2( y, x );
2289 if( phi_x < 0 ) phi_x += 2*M_PI;
2290 } else {
2291 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2292 }
2293 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2294 double dphi = fabs( fiTerm + fi0 - phi_x );
2295 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2296 double tanl = track_rep.tanl();
2297 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2298 if(debug_ == 4) {
2299 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2300 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2301 }
2302 //double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2303 double track_len(fabs( track_rep.radius() * fiTerm * cosl_inv )); // 2010-11-26 added by wangll
2304 //cout<<"track radius : "<<track_rep.radius()<<" "<<track.radius()<<endl;
2305 double light_speed( 29.9792458 ); // light speed in cm/nsec
2306 double pt( 1.0 / track_rep.kappa() );
2307 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2308
2309
2310 // chisq (2 : for backward filter)
2311
2312 trk->setStat(1,1,l_mass);
2313 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2314 if(debug_ == 4) {
2315 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<std::endl;
2316 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<std::endl;
2317 }
2318 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2319 trk->setLength(track_len,l_mass);
2320 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2321 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2322 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2323
2324 //track_rep.pivot(IP);
2325 HepPoint3D LPiovt = track_rep.x(fiTerm);
2326 track_rep.pivot(LPiovt);
2327
2328 trk->setLHelix(track_rep.a(),l_mass);
2329 trk->setLError(track_rep.Ea(),l_mass);
2330 //trk->setLPivot(track.pivot(),l_mass); // commented 2010-09-02
2331 //trk->setLPivot(IP, l_mass); // add 2010-09-02
2332 trk->setLPivot(LPiovt, l_mass); // add 2010-11-25
2333
2334 /// right???
2335 trk->setLPoint(track.point_last(),l_mass);
2336 //trk->setPathSM(track.getPathSM(),l_mass);// commented 2010-11-25 by wangll
2337 trk->setPathSM(track_len,l_mass);// added 2010-11-25 by wangll
2338 //trk->setTof(track.getTofSM(),l_mass);// commented 2010-11-25 by wangll
2339 // trk->setFiTerm(track.getFiTerm(),l_mass); // commented 2010-11-25 by wangll
2340 trk->setFiTerm(fiTerm,l_mass); // added by wangll 2010-11-25
2341 trk->setTHelix(track_rep.a());
2342 trk->setTError(track_rep.Ea());
2343
2344 /*
2345 // --- check track id by wangll 2010-08-15
2346 if(l_mass==lead_) {
2347 //cout<<" ----- bad smooth track -----"<<endl;
2348 //cout<<"l_mass = "<<l_mass<<endl;
2349 int trkId = trk->trackId();
2350 //
2351 // cout<<"track id = "<<trkId<<endl;
2352 // cout<<"THelix: "<<trk->getTHelix()<<endl;
2353 // cout<<"FHelix: "<<trk->getFHelix()<<endl;
2354 // cout<<"size of VecHelixSegs: "<<trk->getVecHelixSegs().size()<<endl;
2355 //
2356 SmartDataPtr<RecMdcTrackCol> mdcTrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
2357 //int nMdcTrk = mdcTrkCol.size();
2358 //cout<<"number of Mdc Tracks: "<<nMdcTrk<<endl;
2359 RecMdcTrackCol::iterator iter_mdcTrk = mdcTrkCol->begin();
2360 bool findMdcTrk = false;
2361 for(; iter_mdcTrk != mdcTrkCol->end(); iter_mdcTrk++) {
2362 if(trkId==(*iter_mdcTrk)->trackId()) {
2363 findMdcTrk = true;
2364 break;
2365 }
2366 }
2367 if(findMdcTrk) {
2368 HitRefVec mdcVecHits = (*iter_mdcTrk)->getVecHits();
2369 int nHits = mdcVecHits.size();
2370 //cout<<"number of Mdc Hits: "<<nHits<<endl;
2371 HelixSegRefVec helixsegrefvec;
2372 HitRefVec::iterator iter_mdcHit = mdcVecHits.begin();
2373 for(int iii=0; iter_mdcHit!=mdcVecHits.end(); iter_mdcHit++,iii++) {
2374 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2375 //cout<<"hit "<<iii<<endl;
2376 //cout<<"getMdcId: "<<(*iter_mdcHit)->getMdcId()<<endl;
2377 //cout<<"getAdc: "<<(*iter_mdcHit)->getAdc()<<endl;
2378 //cout<<"getTdc: "<<(*iter_mdcHit)->getTdc()<<endl;
2379 //cout<<"getDriftT: "<<(*iter_mdcHit)->getDriftT()<<endl;
2380 //cout<<"getZhit: "<<(*iter_mdcHit)->getZhit()<<endl;
2381 //cout<<"getFlagLR: "<<(*iter_mdcHit)->getFlagLR()<<endl;
2382 //cout<<"getDriftDistLeft: "<<(*iter_mdcHit)->getDriftDistLeft()<<endl;
2383 //cout<<"getDriftDistRight: "<<(*iter_mdcHit)->getDriftDistRight()<<endl;
2384 //cout<<"getDoca: "<<(*iter_mdcHit)->getDoca()<<endl;
2385 //cout<<"getEntra: "<<(*iter_mdcHit)->getEntra()<<endl;
2386 //
2387 helixseg->setMdcId((*iter_mdcHit)->getMdcId());
2388 helixseg->setAdc((*iter_mdcHit)->getAdc());
2389 helixseg->setTdc((*iter_mdcHit)->getTdc());
2390 helixseg->setZhit((*iter_mdcHit)->getZhit());
2391 helixseg->setFlagLR((*iter_mdcHit)->getFlagLR());
2392 if((*iter_mdcHit)->getFlagLR()==0) helixseg->setDD((*iter_mdcHit)->getDriftDistLeft());
2393 if((*iter_mdcHit)->getFlagLR()==1) helixseg->setDD((*iter_mdcHit)->getDriftDistRight());
2394 helixseg->setDocaIncl((*iter_mdcHit)->getDoca());
2395 helixseg->setEntra((*iter_mdcHit)->getEntra());
2396 helixseg->setDT((*iter_mdcHit)->getDriftT());
2397 segcol->push_back(helixseg);
2398 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2399 helixsegrefvec.push_back(refhelixseg);
2400 }
2401 trk->setVecHelixSegs(helixsegrefvec);
2402 cout<<"setVecHelixSegs with Mdc hits"<<endl;
2403 }
2404 else cout<<"not find the Mdc Track!";
2405 //cout<<"size of VecHelixSegs: "<<trk->getVecHelixSegs().size()<<endl;
2406 }
2407 */
2408
2409 }
2410
2411 // test--------
2412 if(debug_ == 4) {
2413 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2414 cout << " dr = " << track.a()[0]
2415 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2416 cout<< " phi0 = " << track.a()[1]
2417 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2418 cout << " PT = " << 1/track.a()[2]
2419 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2420 cout << " dz = " << track.a()[3]
2421 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2422 cout << " tanl = " << track.a()[4]
2423 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2424 cout << " Ea = " << track.Ea() <<endl;
2425 }
2426 // test end ----------
2427}
2428
2429//void KalFitAlg::FillTds_helixsegs(KalFitTrack& track,MdcRec_trk& rectrk )
2430
2431void KalFitAlg::sameas(RecMdcKalTrack* trk, int l_mass, int imain)
2432{
2433 // note: for this function,only imain==lead(2) considered
2434 //std::cout<<"BEGINNING THE sameas() function ..."<<std::endl;
2435 trk->setMass(trk->getMass(imain), l_mass);
2436 trk->setLength(trk->getLength(imain), l_mass);
2437 trk->setTof(trk->getTof(imain), l_mass);
2438 trk->setNhits(trk->getNhits(imain), l_mass);
2439
2440 for(int jj = 0; jj<2; jj++) {
2441 trk->setStat(trk->getStat(jj,imain), jj, l_mass);
2442 trk->setChisq(trk->getChisq(jj, l_mass), jj, l_mass);
2443 trk->setNdf(trk->getChisq(jj, l_mass), jj, l_mass);
2444 }
2445 trk->setLHelix(trk->getFHelix(),l_mass);
2446 trk->setLError(trk->getFError(),l_mass);
2447}
2448
2449
2451{
2452 // retrieve Mdc geometry information
2453 IMdcGeomSvc* igeomsvc;
2454 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
2455 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
2456 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
2457 if(!geomsvc){
2458 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
2459 }
2460
2461 HepPoint3D ip(0,0,0);
2462 if(m_usevtxdb==1){
2463 Hep3Vector xorigin(0,0,0);
2464 IVertexDbSvc* vtxsvc;
2465 Gaudi::svcLocator()->service("VertexDbSvc", vtxsvc);
2466 if(vtxsvc->isVertexValid()){
2467 double* dbv = vtxsvc->PrimaryVertex();
2468 double* vv = vtxsvc->SigmaPrimaryVertex();
2469 xorigin.setX(dbv[0]);
2470 xorigin.setY(dbv[1]);
2471 xorigin.setZ(dbv[2]);
2472 }
2473 ip[0] = xorigin[0];
2474 ip[1] = xorigin[1];
2475 ip[2] = xorigin[2];
2476 }
2477
2478 // Estimation of the path length from ip to 1st cylinder
2479
2480 Helix work = *(Helix*)&track;
2481 work.ignoreErrorMatrix();
2482 work.pivot(ip);
2483
2484
2485 double tanl = track.tanl();
2486 double phi_old = work.phi0();
2487 double phi = track.phi0();
2488
2489 if (fabs(phi - phi_old) > M_PI) {
2490 if (phi > phi_old) phi -= 2 * M_PI;
2491 else phi_old -= 2 * M_PI;
2492 }
2493
2494 double path_zero = fabs(track.radius() * (phi_old-phi)* sqrt(1 + tanl * tanl));
2495 // track.addPathSM(path_zero);
2496
2497
2498 HepSymMatrix Eakal(5,0);
2499 track.pivot(ip);
2500 /// be attention to this inital error matrix of smoother,
2501 /// how is track.Ea() in the next sentence when use it?
2502 Eakal = track.Ea()*matrixg_;
2503 track.Ea(Eakal);
2504
2505 // Mdc part :
2506 unsigned int nhit = track.HitsMdc().size();
2507 int layer_prev = -1;
2508
2509 HepVector pos_old(3,0);
2510 double r0kal_prec(0);
2511 int nhits_read(0);
2512 for( unsigned i=0 ; i < nhit; i++ ) {
2513 int ihit = (nhit-1)-i;
2514 KalFitHitMdc& HitMdc = track.HitMdc(ihit);
2515 const KalFitWire& Wire = HitMdc.wire();
2516
2517 int wireid = Wire.geoID();
2518 nhits_read++;
2519
2520 int layer = Wire.layer().layerId();
2521 if (pathl_ && layer != layer_prev) {
2522
2523 if (debug_ == 4) cout<<"in smoother,layerid "<<layer<<" layer_prev "
2524 <<layer_prev <<" pathl_ "<<pathl_<<endl;
2525
2526 // track.PathL(Wire.layer().layerId());
2527 layer_prev = layer;
2528 }
2529
2530 HepPoint3D fwd(Wire.fwd());
2531 HepPoint3D bck(Wire.bck());
2532 Hep3Vector wire = (CLHEP::Hep3Vector)fwd - (CLHEP::Hep3Vector)bck;
2533 Helix work = *(Helix*)&track;
2534 work.ignoreErrorMatrix();
2535 work.pivot((fwd + bck) * .5);
2536 HepPoint3D x0kal = (work.x(0).z() - bck.z()) / wire.z() * wire + bck;
2537
2538 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
2539 if (wsag_ == 4){
2540 Hep3Vector result;
2541 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
2542 double tension = geowire->Tension();
2543
2544 //std::cout<<" tension: "<<tension<<std::endl;
2545 double zinit(x0kal.z()), lzx(Wire.lzx());
2546
2547 // double A(Wire.Acoef());
2548 double A = 47.35E-6/tension;
2549 double Zp = (zinit - bck.z())*lzx/wire.z();
2550
2551 if(4 == debug_){
2552 std::cout<<" sag in smoother_anal: "<<std::endl;
2553 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
2554 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
2555 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
2556 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
2557 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
2558 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
2559 }
2560
2561 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
2562 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
2563 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
2564
2565 wire.setX(wire.x()/wire.z());
2566 wire.setY(result.z());
2567 wire.setZ(1);
2568
2569 x0kal.setX(result.x());
2570 x0kal.setY(result.y());
2571 }
2572
2573 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
2574
2575 // If x0kal is after the inner wall and x0kal_prec before :
2576 double r0kal = x0kal.perp();
2577 if (debug_ == 4) {
2578 cout<<"wire direction "<<wire<<endl;
2579 cout<<"x0kal "<<x0kal<<endl;
2580 cout<<"smoother::r0kal "<<r0kal<<" r0kal_prec "<<r0kal_prec <<endl;
2581 }
2582
2583 // change PIVOT :
2584 /*cout<<endl<<"before change pivot: "<<endl;//wangll
2585 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2586 cout<<"track.helix = "<<track.a()<<endl;//wangll
2587 */
2588 double pathl(0);
2589 track.pivot_numf(x0kal, pathl);
2590 track.addPathSM(pathl);
2591 /*cout<<endl<<"after change pivot: "<<endl;//wangll
2592 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2593 cout<<"track.helix = "<<track.a()<<endl;//wangll
2594 */
2595
2596 // calculate the tof time in this layer
2597 double pmag( sqrt( 1.0 + track.a()[4]*track.a()[4]) / track.a()[2]);
2598 double mass_over_p( track.mass()/ pmag );
2599 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2600 double tofest = pathl / ( 29.9792458 * beta );
2601 track.addTofSM(tofest);
2602
2603 // std::cout<<" in layer: "<<layer<<" pathl: "<<pathl<<" tof: "<<tofest<<std::endl;
2604
2605 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
2606 /*cout<<endl<<"after muls: "<<endl;//wangll
2607 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2608 cout<<"track.helix = "<<track.a()<<endl;//wangll
2609 */
2610 if(!(way<0&&fabs(track.kappa())>1000.0)) {
2611 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
2612 }
2613
2614
2615 // Add info hit wire :
2616 /*cout<<endl<<"after eloss: "<<endl;//wangll
2617 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2618 cout<<"track.helix = "<<track.a()<<endl;//wangll
2619 */
2620 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
2621 HepVector Va(5,0);
2622 HepSymMatrix Ma(5,0);
2623 KalFitHelixSeg HelixSeg(&HitMdc,x0kal,Va,Ma);
2624
2625 Hep3Vector meas = track.momentum(0).cross(wire).unit();
2626 double dchi2=-1;
2627 track.smoother_Mdc(HitMdc, meas, HelixSeg, dchi2, m_csmflag);
2628 if(dchi2>0.0) {
2629 track.HelixSegs().push_back(HelixSeg);
2630 }
2631 }
2632
2633 /// oh, to be the last hit
2634
2635 if(i == nhit-1){
2636
2637 /// calculate the lsat point in MDC
2638 HepPoint3D point;
2639 point.setX(x0kal.x() + track.a()[0]*cos(track.a()[1]));
2640 point.setY(x0kal.y() + track.a()[0]*sin(track.a()[1]));
2641 point.setZ(x0kal.z() + track.a()[3]);
2642 track.point_last(point);
2643
2644 /// calculate fiTerm
2645 double phi_old = track.a()[1];
2646 KalFitTrack temp(x0kal, track.a(), track.Ea(), 0, 0, 0);
2647 temp.pivot(ip);
2648 double phi_new = temp.a()[1];
2649 double fi = phi_new - phi_old;
2650 /// for protection purpose
2651 //if(fabs(fi) >= CLHEP::twopi) fi = fmod(fi+2*CLHEP::twopi,CLHEP::twopi);
2652
2653 if(fabs(fi) >= CLHEP::twopi) fi = fmod(fi+2*CLHEP::twopi,CLHEP::twopi);
2654
2655 track.fiTerm(fi);
2656 }
2657
2658 if (debug_) cout<<"track----7-----"<<track.a()<<endl;
2659 r0kal_prec = r0kal;
2660 }
2661}
2662
2663
2664
2666{
2667
2668 // retrieve Mdc geometry information
2669 IMdcGeomSvc* igeomsvc;
2670 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
2671 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
2672 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
2673 if(!geomsvc){
2674 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
2675 }
2676
2677 HepSymMatrix Eakal(5,0);
2678 // Estimation of the path length from ip to 1st cylinder
2679 HepPoint3D ip(0,0,0);
2680 track.pivot(ip);
2681 Eakal = track.getInitMatrix();
2682 if( debug_ == 4) {
2683 std::cout<<"the initial error matrix in smoothing is "<<Eakal<<std::endl;
2684 }
2685 track.Ea(Eakal);
2686
2687 // Mdc part :
2688 unsigned int nseg = track.HelixSegs().size();
2689 int layer_prev = -1;
2690
2691 HepVector pos_old(3,0);
2692 double r0kal_prec(0);
2693 int nsegs_read(0);
2694 for( unsigned i=0 ; i < nseg; i++ ) {
2695
2696 int flag=0;
2697 int iseg = (nseg-1)-i;
2698 KalFitHelixSeg& HelixSeg = track.HelixSeg(iseg);
2699 const KalFitWire& Wire = HelixSeg.HitMdc()->wire();
2700
2701 int wireid = Wire.geoID();
2702 nsegs_read++;
2703
2704 int layer = Wire.layer().layerId();
2705 if (pathl_ && layer != layer_prev) {
2706
2707 if (debug_ == 4) cout<<"in smoother,layerid "<<layer<<" layer_prev "
2708 <<layer_prev <<" pathl_ "<<pathl_<<endl;
2709
2710 // track.PathL(Wire.layer().layerId());
2711 layer_prev = layer;
2712 }
2713
2714 HepPoint3D fwd(Wire.fwd());
2715 HepPoint3D bck(Wire.bck());
2716 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
2717 Helix work = *(Helix*)&track;
2718 work.ignoreErrorMatrix();
2719 work.pivot((fwd + bck) * .5);
2720 HepPoint3D x0kal = (work.x(0).z() - bck.z()) / wire.z() * wire + bck;
2721
2722
2723 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
2724
2725 if (wsag_ == 4){
2726
2727 Hep3Vector result;
2728 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
2729 double tension = geowire->Tension();
2730
2731 //std::cout<<" tension: "<<tension<<std::endl;
2732 double zinit(x0kal.z()), lzx(Wire.lzx());
2733
2734 // double A(Wire.Acoef());
2735
2736 double A = 47.35E-6/tension;
2737 double Zp = (zinit - bck.z())*lzx/wire.z();
2738
2739 if(4 == debug_){
2740
2741 std::cout<<" sag in smoother_calib: "<<std::endl;
2742 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
2743 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
2744 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
2745 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
2746 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
2747 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
2748 }
2749
2750 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
2751 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
2752 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
2753
2754 wire.setX(wire.x()/wire.z());
2755 wire.setY(result.z());
2756 wire.setZ(1);
2757
2758 x0kal.setX(result.x());
2759 x0kal.setY(result.y());
2760 }
2761
2762 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
2763
2764
2765 // If x0kal is after the inner wall and x0kal_prec before :
2766 double r0kal = x0kal.perp();
2767 if (debug_ == 4) {
2768 cout<<"wire direction "<<wire<<endl;
2769 cout<<"x0kal "<<x0kal<<endl;
2770 cout<<"smoother::r0kal "<<r0kal<<" r0kal_prec "<<r0kal_prec <<endl;
2771 }
2772
2773 // change PIVOT :
2774 double pathl(0);
2775 track.pivot_numf(x0kal, pathl);
2776
2777 if (debug_ == 4) cout<<"track----6-----"<<track.a()<<" ...path..."<<pathl
2778 <<"momentum"<<track.momentum(0)<<endl;
2779 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
2780 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
2781
2782 // Add info hit wire :
2783 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
2784 // attention to this measure value ,what is the measurement value !!
2785 Hep3Vector meas = track.momentum(0).cross(wire).unit();
2786
2787 if(usage_>1) track.smoother_Mdc_csmalign(HelixSeg, meas,flag, m_csmflag);
2788 else track.smoother_Mdc(HelixSeg, meas,flag, m_csmflag);
2789 // cout<<"layer, cell, track.a: "<<Wire.layer().layerId()<<" , "<<Wire.localId()<<" , "<<track.a()<<endl;
2790 }
2791
2792 if (debug_) cout<<"track----7-----"<<track.a()<<endl;
2793 r0kal_prec = r0kal;
2794 // can this kind of operation be right??
2795 if(flag == 0) {
2796 track.HelixSegs().erase(track.HelixSegs().begin()+iseg);
2797 }
2798 }
2799}
2800
2801
2802
2803void KalFitAlg::filter_fwd_anal(KalFitTrack& track, int l_mass, int way, HepSymMatrix& Eakal)
2804{
2805
2806 //cout<<"**********************"<<endl;//wangll
2807 //cout<<"filter pid type "<<l_mass<<endl;//wangll
2808 // retrieve Mdc geometry information
2809
2810 IMdcGeomSvc* igeomsvc;
2811 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
2812 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
2813 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
2814 if(!geomsvc){
2815 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
2816 }
2817
2818 Hep3Vector x0inner(track.pivot());
2819 HepVector pos_old(3,0);
2820 double r0kal_prec(0);
2821 int nhits_read(0);
2822 int nhit = track.HitsMdc().size();
2823 if(debug_ == 4) cout<<"filter_fwd..........111 nhit="<<nhit<<endl;
2824 for( int i=0 ; i < nhit; i++ ) {
2825 KalFitHitMdc& HitMdc = track.HitMdc(i);
2826 // veto on some hits :
2827 if (HitMdc.chi2()<0) continue;
2828 const KalFitWire& Wire = HitMdc.wire();
2829 int layerf = Wire.layer().layerId();
2830
2831 //std::cout<<"in layer: "<<layerf<<std::endl;
2832
2833 int wireid = Wire.geoID();
2834 nhits_read++;
2835 HepPoint3D fwd(Wire.fwd());
2836 HepPoint3D bck(Wire.bck());
2837 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
2838 Helix work = *(Helix*)&track;
2839 work.ignoreErrorMatrix();
2840 work.pivot((fwd + bck) * .5);
2841
2842 //std::cout<<" (fwd + bck) * .5: "<<(fwd + bck)*.5<<std::endl;
2843 //std::cout<<" track.x(0): "<<track.x(0)<<std::endl;
2844 //std::cout<<" work.x(0): "<<work.x(0)<<std::endl;
2845 //std::cout<<" bck: "<<bck<<std::endl;
2846
2847 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
2848
2849 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
2850
2851 // Modification to take account of the wire sag :
2852 /*
2853 if (wsag_==1) {
2854 double A(1.2402E-6);
2855 if (nhits_read != 1 && r0kal_prec > RMW && x0kal.perp() < RMW)
2856 A = 8.5265E-7;
2857 HepPoint3D x0kal_up(x0kal);
2858 double length = sqrt(wire.x()*wire.x()+wire.z()*wire.z());
2859 double zp = (x0kal.z() - bck.z())*length/wire.z();
2860
2861 x0kal_up.setX(wire.x()*(x0kal.z()-bck.z())/wire.z()+bck.x());
2862 x0kal_up.setY((A*(zp-length)+wire.y()/length)*zp+bck.y());
2863 double slopex = wire.x()/wire.z();
2864 double slopey = (A*(2*zp-length)*length+wire.y())/wire.z();
2865
2866 x0kal = x0kal_up;
2867 wire.setX(slopex);
2868 wire.setY(slopey);
2869 wire.setZ(1);
2870
2871 } else if (wsag_ == 2 || wsag_ == 3){
2872 double slopex = wire.x()/wire.z();
2873 double slopey(0), zinit(x0kal.z());
2874 double pos[3], yb_sag(0), yf_sag(0);
2875 int wire_ID = Wire.geoID();
2876 if (wsag_ == 2)
2877 calcdc_sag2_(&wire_ID, &zinit, pos, &slopey, &yb_sag, &yf_sag);
2878
2879 else
2880 calcdc_sag3_(&wire_ID, &zinit, pos, &slopey, &yb_sag, &yf_sag);
2881
2882 wire.setX(slopex);
2883 wire.setY(slopey);
2884 wire.setZ(1);
2885 x0kal.setX(pos[0]);
2886 x0kal.setY(pos[1]);
2887 } else
2888 */
2889
2890 if (wsag_ == 4){
2891 Hep3Vector result;
2892 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
2893 double tension = geowire->Tension();
2894 //std::cout<<" tension: "<<tension<<std::endl;
2895 double zinit(x0kal.z()), lzx(Wire.lzx());
2896 // double A(Wire.Acoef());
2897 double A = 47.35E-6/tension;
2898 double Zp = (zinit - bck.z())*lzx/wire.z();
2899
2900 if(4 == debug_){
2901 std::cout<<" sag in filter_fwd_anal: "<<std::endl;
2902 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
2903 std::cout<<"zinit: "<<zinit<<" bck.z(): "<<bck.z()<<std::endl;
2904 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
2905 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
2906 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
2907 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
2908 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
2909 }
2910
2911 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
2912 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
2913 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
2914
2915 wire.setX(wire.x()/wire.z());
2916 wire.setY(result.z());
2917 wire.setZ(1);
2918 x0kal.setX(result.x());
2919 x0kal.setY(result.y());
2920 }
2921
2922 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
2923
2924 // If x0kal is after the inner wall and x0kal_prec before :
2925 double r0kal = x0kal.perp();
2926
2927 // change PIVOT :
2928 double pathl(0);
2929
2930 track.pivot_numf(x0kal, pathl);
2931
2932 if (nhits_read == 1) {
2933 track.Ea(Eakal);
2934 } else {
2935 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
2936 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
2937 }
2938
2939 double dtracknew = 0.;
2940 double dtrack = 0.;
2941 double dtdc = 0.;
2942 // Add info hit wire :
2943 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
2944 Hep3Vector meas = track.momentum(0).cross(wire).unit();
2945 double diff_chi2 = track.chiSq();
2946 Hep3Vector IP(0,0,0);
2947 Helix work_bef = *(Helix*)&track;
2948 work_bef.ignoreErrorMatrix();
2949 work_bef.pivot(IP);
2950 int inext(-1);
2951 if (i+1<nhit)
2952 for( unsigned k=i+1 ; k < nhit; k++ )
2953 if (!(track.HitMdc(k).chi2()<0)) {
2954 inext = (signed) k;
2955 break;
2956 }
2957 double dchi2 = -1.0;
2958
2959 double chi2 = track.update_hits(HitMdc,inext,meas,way,dchi2,dtrack,dtracknew,dtdc,m_csmflag);
2960
2961 //cout << "dchi2=" << dchi2 << endl;
2962 /// get the doca from another other independent method
2963
2964 /*
2965 std::cout<<" step0: "<<std::endl;
2966 KalFitTrack temp2(track);
2967 std::cout<<" step1: "<<std::endl;
2968
2969 Helix temp3(track.pivot(),track.a(),track.Ea());
2970 Helix temp4(track.pivot(),track.a(),track.Ea());
2971
2972 std::cout<<" step2: "<<std::endl;
2973 double doca25 = temp2.approach(HitMdc, false);
2974 std::cout<<" step3: "<<std::endl;
2975
2976 temp2.pivot(IP);
2977 std::cout<<" a2: "<<temp2.a()<<std::endl;
2978
2979 std::cout<<" step4: "<<std::endl;
2980
2981 double doca26 = temp3.approach(HitMdc, false);
2982 std::cout<<" another doca2.6: "<<doca26<<std::endl;
2983
2984 temp3.pivot(IP);
2985 std::cout<<" a3: "<<temp3.a()<<std::endl;
2986
2987 temp4.bFieldZ(-10);
2988 temp4.pivot(IP);
2989 std::cout<<" a4: "<<temp4.a()<<std::endl;
2990
2991 std::cout<<" step5: "<<std::endl;
2992
2993 double doca1 = track.approach(HitMdc, false);
2994 double doca2 = temp2.approach(HitMdc, false);
2995 double doca3 = temp3.approach(HitMdc, false);
2996 double doca4 = temp4.approach(HitMdc, false);
2997
2998 std::cout<<" dtrack: "<<dtrack<<std::endl;
2999 std::cout<<" another doca1: "<<doca1<<std::endl;
3000 std::cout<<" another doca2: "<<doca2<<std::endl;
3001 std::cout<<" another doca2.5: "<<doca25<<std::endl;
3002 std::cout<<" another doca3: "<<doca3<<std::endl;
3003 std::cout<<" another doca4: "<<doca4<<std::endl;
3004 */
3005
3006
3007 if( dchi2 <0 ) {
3008 std::cout<<" ... ERROR OF dchi2... "<<std::endl;
3009 }
3010
3011 if (ntuple_&8) {
3012 m_dchi2 = dchi2;
3013 m_masshyp = l_mass;
3014 m_residest = dtrack-dtdc;
3015 m_residnew = dtracknew -dtdc;
3016 m_layer = Wire.layer().layerId();
3017 Helix worktemp = *(Helix*)&track;
3018 m_anal_dr = worktemp.a()[0];
3019 m_anal_phi0 = worktemp.a()[1];
3020 m_anal_kappa = worktemp.a()[2];
3021 m_anal_dz = worktemp.a()[3];
3022 m_anal_tanl = worktemp.a()[4];
3023 m_anal_ea_dr = worktemp.Ea()[0][0];
3024 m_anal_ea_phi0 = worktemp.Ea()[1][1];
3025 m_anal_ea_kappa = worktemp.Ea()[2][2];
3026 m_anal_ea_dz = worktemp.Ea()[3][3];
3027 m_anal_ea_tanl = worktemp.Ea()[4][4];
3028 StatusCode sc5 = m_nt5->write();
3029 if( sc5.isFailure() ) cout<<"Ntuple5 filling failed!"<<endl;
3030 }
3031 Helix work_aft = *(Helix*)&track;
3032 work_aft.ignoreErrorMatrix();
3033 work_aft.pivot(IP);
3034 diff_chi2 = chi2 - diff_chi2;
3035 HitMdc.chi2(diff_chi2);
3036 }
3037 r0kal_prec = r0kal;
3038 }
3039 //cout <<"filter end" << endl;
3040}
3041
3042
3043
3044void KalFitAlg::filter_fwd_calib(KalFitTrack& track, int l_mass, int way, HepSymMatrix& Eakal)
3045{
3046
3047 // retrieve Mdc geometry information
3048 IMdcGeomSvc* igeomsvc;
3049 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3050 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3051 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3052 if(!geomsvc){
3053 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3054 }
3055
3056 if(debug_ == 4) {
3057 std::cout<<"filter_fwd_calib starting ...the inital error Matirx is "<<track.Ea()<<std::endl;
3058 }
3059 Hep3Vector x0inner(track.pivot());
3060 HepVector pos_old(3,0);
3061 double r0kal_prec(0);
3062 int nhits_read(0);
3063
3064 unsigned int nhit = track.HitsMdc().size();
3065 if(debug_ == 4) cout<<"filter_fwd..........111 nhit="<<nhit<<endl;
3066 for( unsigned i=0 ; i < nhit; i++ ) {
3067
3068 KalFitHitMdc& HitMdc = track.HitMdc(i);
3069 if(debug_ == 4)
3070 cout<<"filter_fwd...........222 chi2="<<HitMdc.chi2()<<endl;
3071 // veto on some hits :
3072 if (HitMdc.chi2()<0) continue;
3073 const KalFitWire& Wire = HitMdc.wire();
3074
3075 int wireid = Wire.geoID();
3076 nhits_read++;
3077
3078 // if (nhits_read == 1) track.Ea(Eakal);
3079 HepPoint3D fwd(Wire.fwd());
3080 HepPoint3D bck(Wire.bck());
3081 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3082 Helix work = *(Helix*)&track;
3083 work.ignoreErrorMatrix();
3084 work.pivot((fwd + bck) * .5);
3085 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
3086
3087 if(4 == debug_)
3088 std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3089
3090 if (wsag_ == 4){
3091 Hep3Vector result;
3092 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3093 double tension = geowire->Tension();
3094 //std::cout<<" tension: "<<tension<<std::endl;
3095 double zinit(x0kal.z()), lzx(Wire.lzx());
3096 // double A(Wire.Acoef());
3097 double A = 47.35E-6/tension;
3098 double Zp = (zinit - bck.z())*lzx/wire.z();
3099
3100 if(4 == debug_){
3101
3102 std::cout<<" sag in filter_fwd_calib: "<<std::endl;
3103 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3104 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3105 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3106 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3107 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3108 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3109 }
3110
3111 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3112 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3113 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3114 wire.setX(wire.x()/wire.z());
3115 wire.setY(result.z());
3116 wire.setZ(1);
3117 x0kal.setX(result.x());
3118 x0kal.setY(result.y());
3119 }
3120
3121 if(4 == debug_)
3122 std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3123
3124 // If x0kal is after the inner wall and x0kal_prec before :
3125 double r0kal = x0kal.perp();
3126
3127 // change PIVOT :
3128 double pathl(0);
3129
3130 //std::cout<<" track a3: "<<track.a()<<std::endl;
3131 //std::cout<<" track p3: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3132
3133 if (debug_ == 4)
3134 cout << "*** move from " << track.pivot() << " ( Kappa = "
3135 << track.a()[2] << ")" << endl;
3136 track.pivot_numf(x0kal, pathl); //see the code , the error matrix has been changed in this function ..
3137
3138 //std::cout<<" track a4: "<<track.a()<<std::endl;
3139 //std::cout<<" track p4: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3140
3141
3142 if (debug_ == 4)
3143 cout << "*** to " << track.pivot() << " ( Kappa = "
3144 << track.a()[2] << ")" << std::endl;
3145
3146 if (nhits_read == 1) {
3147 track.Ea(Eakal);
3148 if(debug_==4) cout << "filter_fwd::Ea = " << track.Ea()<<endl;
3149
3150
3151 } else {
3152 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3153 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3154 }
3155
3156
3157 //std::cout<<" track a5: "<<track.a()<<std::endl;
3158 //std::cout<<" track p5: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3159
3160 // Add info hit wire :
3161 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3162 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3163
3164 double diff_chi2 = track.chiSq();
3165
3166 Hep3Vector IP(0,0,0);
3167 Helix work_bef = *(Helix*)&track;
3168 work_bef.ignoreErrorMatrix();
3169 work_bef.pivot(IP);
3170 int inext(-1);
3171 if (i+1<nhit)
3172 for( unsigned k=i+1 ; k < nhit; k++ )
3173 if (!(track.HitMdc(k).chi2()<0)) {
3174 inext = (signed) k;
3175 break;
3176 }
3177 double dchi2 = -1.0;
3178
3179 if (debug_ == 4) {
3180 std::cout<<"the value of x0kal is "<<x0kal<<std::endl;
3181 std::cout<<"the value of track.pivot() is "<<track.pivot()<<std::endl;
3182 }
3183
3184 HepVector Va(5,0);
3185 HepSymMatrix Ma(5,0);
3186 KalFitHelixSeg HelixSeg(&HitMdc,x0kal,Va,Ma);
3187
3188 if(debug_ == 4) {
3189 std::cout<<"HelixSeg.Ea_pre_fwd() ..."<<HelixSeg.Ea_pre_fwd()<<std::endl;
3190 std::cout<<"HelixSeg.a_pre_fwd() ..."<<HelixSeg.a_pre_fwd()<<std::endl;
3191 std::cout<<"HelixSeg.Ea_filt_fwd() ..."<<HelixSeg.Ea_filt_fwd()<<std::endl;
3192 }
3193
3194 //std::cout<<" track a1: "<<track.a()<<std::endl;
3195 //std::cout<<" track p1: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3196
3197 double chi2=0.;
3198 if(usage_>1) chi2=track.update_hits_csmalign(HelixSeg, inext, meas, way, dchi2, m_csmflag);
3199 else chi2 = track.update_hits(HelixSeg, inext, meas, way, dchi2, m_csmflag);
3200
3201 //std::cout<<" track a2: "<<track.a()<<std::endl;
3202 //std::cout<<" track p2: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3203
3204 if(debug_ ==4 ) cout<<"layer, cell, dchi2,chi2, a, p: "<<HitMdc.wire().layer().layerId()<<" , "<<HitMdc.wire().localId()<<" , "<<dchi2<<" , "<<chi2<<" , "<<track.a()<<" , "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<endl;
3205
3206 if(debug_ == 4) cout<< "****inext***"<<inext<<" !!!! dchi2= "<< dchi2
3207 << " chisq= "<< chi2<< endl;
3208
3209 if (ntuple_&8) {
3210 m_dchi2 = dchi2;
3211 m_masshyp = l_mass;
3212 StatusCode sc5 = m_nt5->write();
3213 if( sc5.isFailure() ) cout<<"Ntuple5 filling failed!"<<endl;
3214 }
3215
3216 Helix work_aft = *(Helix*)&track;
3217 work_aft.ignoreErrorMatrix();
3218 work_aft.pivot(IP);
3219 diff_chi2 = chi2 - diff_chi2;
3220 HitMdc.chi2(diff_chi2);
3221
3222 if(debug_ == 4) {
3223
3224 cout << " -> after include meas = " << meas
3225 << " at R = " << track.pivot().perp() << std::endl;
3226 cout << " chi2 = " << chi2 << ", diff_chi2 = "
3227 << diff_chi2 << ", LR = "
3228 << HitMdc.LR() << ", stereo = " << HitMdc.wire().stereo()
3229 << ", layer = " << HitMdc.wire().layer().layerId() << std::endl;
3230 cout<<"filter_fwd..........HitMdc.chi2... "<<HitMdc.chi2()<<endl;
3231 }
3232
3233 if(dchi2>0.0 && (way!=999)) {
3234 track.HelixSegs().push_back(HelixSeg);
3235 }
3236 }
3237 r0kal_prec = r0kal;
3238 }
3239}
3240
3241// Take account of the inner wall (forward filter) :
3242void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way){
3243
3244 if (debug_ ==4) cout<<"innerwall....."<<endl;
3245 for(int i = 0; i < _BesKalmanFitWalls.size(); i++) {
3246 _BesKalmanFitWalls[i].updateTrack(track, way);
3247 if (debug_ == 4) cout<<"Wall "<<i<<" update the track!(filter)"<<endl;
3248 }
3249}
3250
3251void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way,int begin,int end){
3252 if (debug_ ==4) cout<<"innerwall....."<<endl;
3253 for(int i = begin; i <= end; i++) {
3254 _BesKalmanFitWalls[i].updateTrack(track, way);
3255 if(debug_ == 4){cout << "wall" << i << endl;
3256 cout <<"track" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;}
3257 if (debug_ == 4) cout<<"Wall "<<i<<" update the track!(filter)"<<endl;
3258 }
3259}
3260
3261void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way, double r1, double r2, int& index){
3262 if (debug_ ==4) cout<<"innerwall....."<<endl;
3263 double ri=(r1<r2)?r1:r2;
3264 double ro=(r1<r2)?r2:r1;
3265 double Rmin,Rmax;
3266 int step;
3267 vector<KalFitCylinder>::iterator it;
3268 vector<KalFitCylinder>::iterator itStart;
3269 vector<KalFitCylinder>::iterator itStop;
3270 if(way<0){
3271 step=-1;
3272 itStart=_BesKalmanFitWalls.end()-index-1;
3273 itStop =_BesKalmanFitWalls.begin()-1;
3274 }
3275 else{
3276 step=1;
3277 itStart=_BesKalmanFitWalls.begin()+index;
3278 itStop =_BesKalmanFitWalls.end();
3279 }
3280 for(it=itStart; it != itStop; it=it+step) {
3281 if(ri < it->rmin() && it->radius() < ro) {
3282 it->updateTrack(track,way);
3283 Rmin=it->rmin();
3284 Rmax=it->radius();
3285 continue;
3286 }
3287 else if(it->rmin() <= ri && ri <= it->radius() && it->radius() < ro){
3288 it->updateTrack(track,way,ri,it->radius());
3289 Rmin=ri;
3290 Rmax=it->radius();
3291 if(way>0){
3292 //index = it - _BesKalmanFitWalls.begin();
3293 break;
3294 }
3295 else continue;
3296 }
3297 else if(ri < it->rmin() && it->rmin() <= ro && ro <= it->radius()){
3298 it->updateTrack(track,way,it->rmin(),ro);
3299 Rmin=it->rmin();
3300 Rmax=ro;
3301 if(way<0){
3302 //index = _BesKalmanFitWalls.end() - it;
3303 break;
3304 }
3305 else continue;
3306 }
3307 else if(it->radius()<ri || ro < it->rmin()){
3308 continue;
3309 }
3310 else {
3311 it->updateTrack(track,way,ri,ro);
3312 Rmin=ri;
3313 Rmax=ro;
3314 //index=it-_BesKalmanFitWalls.begin();
3315 break;
3316 }
3317 }
3318 if(way<0){
3319 //double phi=track.intersect_cylinder(Rmax);
3320 //HepPoint3D pivot=track.x(phi);
3321 //track.pivot_numf(pivot);
3322 track.pivot_numf(track.x(track.intersect_cylinder(Rmax)));
3323 index = _BesKalmanFitWalls.end() - it-1;
3324 }
3325 else{
3326 //double phi=track.intersect_cylinder(Rmin);
3327 //HepPoint3D pivot=track.x(phi);
3328 //track.pivot_numf(pivot);
3329 track.pivot_numf(track.x(track.intersect_cylinder(Rmin)));
3330 index = it - _BesKalmanFitWalls.begin();
3331 }
3332
3333}
3334
3335
3336//void KalFitAlg::set_Mdc(void)
3337
3338// Use the information of trasan and refit the best tracks
3339
3341{
3342
3343 //cout<<"kalman_fitting_anal deal with a new event"<<endl;//wangll
3344
3345 MsgStream log(msgSvc(), name());
3346 double Pt_threshold(0.3);
3347 Hep3Vector IP(0,0,0);
3348 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
3349 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
3350 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
3351
3352 // Table Manager
3353 if ( !&whMgr ) return;
3354
3355 // Get reduced chi**2 of Mdc track :
3356 int ntrk = mdcMgr->size();
3357 double* rPt = new double[ntrk];
3358 int* rOM = new int[ntrk];
3359 unsigned int* order = new unsigned int[ntrk];
3360 unsigned int* rCont = new unsigned int[ntrk];
3361 unsigned int* rGen = new unsigned int[ntrk];
3362
3363 if(testOutput) cout<<"nMdcTrk = "<<ntrk<<endl;
3364
3365 int index = 0;
3366 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
3367 end = mdcMgr->end(); it != end; it++) {
3368 // Pt
3369 rPt[index] = 0;
3370 if (it->helix[2])
3371 rPt[index] = 1 / fabs(it->helix[2]);
3372 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
3373 if(rPt[index] < 0) rPt[index] = DBL_MAX;
3374 // Outermost layer
3375 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
3376 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
3377 int outermost(-1);
3378 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3379 ii !=pt.begin()-1; ii--) {
3380 int lyr((*ii)->geo->Lyr()->Id());
3381 if (outermost < lyr) outermost = lyr;
3382 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
3383 }
3384 rOM[index] = outermost;
3385 order[index] = index;
3386 ++index;
3387 }
3388
3389 // Sort Mdc tracks by Pt
3390 for (int j, k = ntrk - 1; k >= 0; k = j){
3391 j = -1;
3392 for(int i = 1; i <= k; i++)
3393 if(rPt[i - 1] < rPt[i]){
3394 j = i - 1;
3395 std::swap(order[i], order[j]);
3396 std::swap(rPt[i], rPt[j]);
3397 std::swap(rOM[i], rOM[j]);
3398 std::swap(rCont[i], rCont[j]);
3399 std::swap(rGen[i], rGen[j]);
3400 }
3401 }
3402 delete [] rPt;
3403
3404 //
3405 int newcount(0);
3406 //check whether Recon already registered
3407 DataObject *aReconEvent;
3408 eventSvc()->findObject("/Event/Recon",aReconEvent);
3409 if(!aReconEvent) {
3410 // register ReconEvent Data Object to TDS;
3411 ReconEvent* recevt = new ReconEvent;
3412 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
3413 if(sc!=StatusCode::SUCCESS) {
3414 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
3415 return;
3416 }
3417 }
3418
3419 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
3421 //make RecMdcKalTrackCol
3422 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
3423 // Loop over tracks given by trasan :
3424 for(int l = 0; l < ntrk; l++) {
3425
3426 //cout<<"----------------"<<endl;//wangll
3427 //cout<<"track "<<l<<" : "<<endl;//wangll
3428 nTotalTrks++;
3429
3430 for(int i=0; i<5; i++) iqual_front_[i] = 1; // wangll 2010-11-01
3431
3432 // m_timer[3]->start();
3433 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[l]);
3434 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[l]);
3435
3436 // Reject the ones with quality != 0
3437 int trasqual = TrasanTRK_add.quality;
3438 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
3439 if (trasqual) continue;
3440
3441 newcount++;
3442 if (debug_ == 4)
3443 cout << "******* KalFit NUMBER : " << newcount << std::endl;
3444
3445 // What kind of KalFit ?
3446 int type(0);
3447 if ((TrasanTRK_add.decision & 32) == 32 ||
3448 (TrasanTRK_add.decision & 64) == 64) type = 1;
3449
3450 // Initialisation : (x, a, ea)
3451 HepPoint3D x(TrasanTRK.pivot[0],
3452 TrasanTRK.pivot[1],
3453 TrasanTRK.pivot[2]);
3454
3455 HepVector a(5);
3456 for(int i = 0; i < 5; i++)
3457 a[i] = TrasanTRK.helix[i];
3458
3459 HepSymMatrix ea(5);
3460 for(int i = 0, k = 0; i < 5; i++) {
3461 for(int j = 0; j <= i; j++) {
3462 ea[i][j] = matrixg_*TrasanTRK.error[k++];
3463 ea[j][i] = ea[i][j];
3464 }
3465 }
3466 double fiTerm = TrasanTRK.fiTerm;
3467 int way(1);
3468 // Prepare the track found :
3469 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
3470
3471 track_lead.bFieldZ(KalFitTrack::Bznom_);
3472
3473 // Mdc Hits
3474 int inlyr(999), outlyr(-1);
3475 int* rStat = new int[43];
3476 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
3477 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
3478 int hit_in(0);
3479 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
3480 // Number of hits/layer
3481 int Num[43] = {0};
3482 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3483 ii != pt.begin()-1; ii--) {
3484 Num[(*ii)->geo->Lyr()->Id()]++;
3485 }
3486 int hit_asso(0);
3487 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3488 ii != pt.begin()-1; ii--) {
3489 hit_asso++;
3490 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
3491 if (debug_ >0)
3492 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
3493 << " hits in the layer "
3494 << (*ii)->geo->Lyr()->Id() << std::endl;
3495 continue;
3496 }
3497 // if(ii!=pt.end()-1){
3498 // int layer_before=(*(ii+1))->geo->Lyr()->Id();
3499 // if(layer_before == (*ii)->geo->Lyr()->Id()){
3500 // MdcRec_wirhit * rechit_before = *(ii+1);
3501 // if((*rechit_before).rechitptr->getDriftT()>450 || (**ii).rechitptr->getDriftT()>450.){
3502 // if((*rechit_before).tdc < (**ii).tdc) continue;
3503 // else if(track_lead.HitsMdc().size()>0 && rStat[layer_before]){
3504 // track_lead.HitsMdc().pop_back();
3505 // }
3506 // }
3507 // }
3508 // }
3509
3510 hit_in++;
3511 MdcRec_wirhit & rechit = **ii;
3512 double dist[2] = {rechit.ddl, rechit.ddr};
3513 double erdist[2] = {rechit.erddl, rechit.erddr};
3514 const MdcGeoWire* geo = rechit.geo;
3515
3516 int lr_decision(0);
3517 if (KalFitTrack::LR_ == 1){
3518 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
3519 // if (rechit.lr==0) lr_decision=-1;
3520 else if (rechit.lr==1) lr_decision=1;
3521 }
3522
3523 int ind(geo->Lyr()->Id());
3524
3525 // ATTENTION HERE!!!
3526 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
3527 lr_decision, rechit.tdc,
3528 dist, erdist,
3529 _wire+(geo->Id()), rechit.rechitptr));
3530 // inner/outer layer :
3531 rStat[ind]++;
3532 if (inlyr>ind) inlyr = ind;
3533 if (outlyr<ind) outlyr = ind;
3534 }
3535 if (debug_ == 4)
3536 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
3537
3538 // Empty layers :
3539 int empty_between(0), empty(0);
3540 for (int i= inlyr; i <= outlyr; i++)
3541 if (!rStat[i]) empty_between++;
3542 empty = empty_between+inlyr+(42-outlyr);
3543 delete [] rStat;
3544
3545 // RMK high momentum track under study, probably not neeeded...
3546 track_lead.order_wirhit(1);
3547 //track_lead.order_hits();
3548
3549 for(std::vector<KalFitHitMdc>::iterator it_hit = track_lead.HitsMdc().begin(); it_hit!=track_lead.HitsMdc().end(); it_hit++){
3550 //std::cout<<" the id of this hits after sorting in PatRec is "<<it_hit->id()<<std::endl;
3551 //std::cout<<" the layerid of the hit is "<<it_hit->wire().layer().layerId()<<std::endl;
3552 //std::cout<<" the cellid of this wire is "<<it_hit->wire().localId()<<std::endl;
3553 }
3554
3555 track_lead.type(type);
3556 track_lead.trasan_id(TrasanTRK.id);
3557 unsigned int nhit = track_lead.HitsMdc().size();
3558 if (!nhit && debug_ == 4) {
3559 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
3560 continue;
3561 }
3562
3563 // Initialisation :
3564 double KalFitst(0), KalFitax(0), KalFitschi2(0);
3565 // Move to the outer hit :
3566
3567 Hep3Vector outer_pivot(track_lead.x(fiTerm));
3568
3569 track_lead.pivot(outer_pivot);
3570
3571 track_lead.bFieldZ(KalFitTrack::Bznom_);
3572 // attention best_chi2 reinitialize !!!
3573 if (nhit>=3 && !KalFitTrack::LR_)
3574 start_seed(track_lead, lead_, way, TrasanTRK);
3575 HepSymMatrix Eakal(5,0);
3576
3577 /// very low momentum and very big costheta angle, use special initial error matrix
3578 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
3579 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
3580 choice_ = 6;
3581 }
3582
3583 /// chose different initial error matrix
3584 init_matrix(choice_,TrasanTRK, Eakal);
3585
3586
3587 if (debug_ == 4){
3588 cout << "from Mdc Pattern Recognition: " << std::endl;
3589 HepPoint3D IP(0,0,0);
3590 Helix work(track_lead.pivot(),
3591 track_lead.a(),
3592 track_lead.Ea());
3593 work.pivot(IP);
3594 cout << " dr = " << work.a()[0]
3595 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
3596 cout << " phi0 = " << work.a()[1]
3597 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
3598 cout << " PT = " << 1/work.a()[2]
3599 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
3600 cout << " dz = " << work.a()[3]
3601 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
3602 cout << " tanl = " << work.a()[4]
3603 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
3604 }
3605
3606 if(testOutput) {
3607 cout<<"----------------------"<<endl;//660a
3608 cout<<"track "<<l<<", pid = "<<lead_<<": "<<endl;
3609 //int n_hits=(*itRecMdcTrack)->getNhits();
3610 //int n_hit_Axis=n_hits-(*itRecMdcTrack)->nster();
3611 //cout<<"nMdcHits,nMdcHitsAxis = "<<n_hits<<", "<<n_hit_Axis<<endl;//660a
3612 //cout<<"----------------------"<<endl;
3613 //cout<<"# old track par #"<<endl<<" pivot: "<<track.pivot()<<endl<<" helix: "<<track.a()<<endl<<" error: "<<track.Ea()<<endl;
3614 //cout<<"# true track par #"<<endl<<" helix: "<<mc_a<<endl;
3615 }
3616
3617
3618 filter_fwd_anal(track_lead, lead_, way, Eakal);
3619
3620 // std::cout<<" step3, track_lead.Ea: "<<track_lead.Ea()<<std::endl;
3621 track_lead.update_forMdc();
3622
3623 HepPoint3D IP(0,0,0);
3624 if (debug_ == 4) {
3625 cout << " Mdc FIRST KALMAN FIT " << std::endl;
3626 Helix work(track_lead.pivot(),
3627 track_lead.a(),
3628 track_lead.Ea());
3629 work.pivot(IP);
3630 cout << " dr = " << work.a()[0]
3631 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
3632 cout << " phi0 = " << work.a()[1]
3633 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
3634 cout << " PT = " << 1/work.a()[2]
3635 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
3636 cout << " dz = " << work.a()[3]
3637 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
3638 cout << " tanl = " << work.a()[4]
3639 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
3640 }
3641
3642 // fill TDS
3643 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
3644 // Complete the track (other mass assumption, backward) and
3645 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol,1);
3646 }
3647
3648
3649 IDataProviderSvc* eventSvc = NULL;
3650 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
3651 if (eventSvc) {
3652 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
3653 } else {
3654 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
3655 return ;
3656 }
3657 StatusCode kalsc;
3658 IDataManagerSvc *dataManSvc;
3659 dataManSvc= dynamic_cast<IDataManagerSvc*>(eventSvc);
3660 DataObject *aKalTrackCol;
3661 eventSvc->findObject("/Event/Recon/RecMdcKalTrackCol",aKalTrackCol);
3662 if(aKalTrackCol != NULL) {
3663 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalTrackCol");
3664 eventSvc->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
3665 }
3666 kalsc = eventSvc->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
3667 if( kalsc.isFailure() ) {
3668 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
3669 return ;
3670 }
3671 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
3672 StatusCode segsc;
3673 //check whether the RecMdcKalHelixSegCol has been already registered
3674 DataObject *aRecKalSegEvent;
3675 eventSvc->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
3676 if(aRecKalSegEvent!=NULL) {
3677 //then unregister RecMdcKalHelixSegCol
3678 segsc = eventSvc->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
3679 if(segsc != StatusCode::SUCCESS) {
3680 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
3681 return;
3682 }
3683 }
3684 segsc = eventSvc->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
3685 if( segsc.isFailure() ) {
3686 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
3687 return;
3688 }
3689 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
3690
3691 double x1(0.),x2(0.),y1(0.),y2(0.),z1(0.),z2(0.),the1(0.),the2(0.),phi1(0.),phi2(0.),p1(0.),p2(0.);
3692 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0),tanl2(0.);
3693 double px1(0.),px2(0.),py1(0.),py2(0.),pz1(0.),pz2(0.),charge1(0.),charge2(0.);
3694
3695 //check the result:RecMdcKalTrackCol
3696 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc,"/Event/Recon/RecMdcKalTrackCol");
3697 if (!kaltrkCol) {
3698 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
3699 return;
3700 }
3701 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
3702 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
3703 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
3704 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
3705 << "Track Id: " << (*iter_trk)->getTrackId()
3706 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
3707 << " Length of the track: "<< (*iter_trk)->getLength(2)
3708 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
3709 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
3710 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
3711 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,2)
3712 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
3713 << "Kappa " << (*iter_trk)->getZHelix()[2]
3714 << endreq;
3715 for( int i = 0; i<43; i++) {
3716 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
3717 << (*iter_trk)->getPathl(i) <<endreq;
3718 }
3719 if(ntuple_&1) {
3720 m_trackid = (*iter_trk)->getTrackId();
3721
3722 for( int jj =0, iii=0; jj<5; jj++) {
3723
3724 m_length[jj] = (*iter_trk)->getLength(jj);
3725 m_tof[jj] = (*iter_trk)->getTof(jj);
3726 m_nhits[jj] = (*iter_trk)->getNhits(jj);
3727 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
3728 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
3729 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
3730 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
3731 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
3732 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
3733 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
3734 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
3735 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
3736 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
3737 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
3738 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
3739 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
3740 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
3741 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
3742
3743 if(ntuple_&32) {
3744 for(int kk=0; kk<=jj; kk++,iii++) {
3745 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
3746 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
3747 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
3748 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
3749 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
3750 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
3751 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
3752 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
3753 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
3754 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
3755 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
3756 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
3757 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
3758 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
3759 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
3760 }
3761 }
3762 }
3763
3764 // // the following logic may seem peculiar, but it IS the case(for BOSS5.0 and BOSS5.1)
3765 // m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
3766 // m_chisq[0][1] = (*iter_trk)->getChisq(0,1);
3767 // m_chisq[1][0] = (*iter_trk)->getChisq(0,2);
3768 // m_chisq[1][1] = (*iter_trk)->getChisq(0,3);
3769 // m_chisq[2][0] = (*iter_trk)->getChisq(0,4);
3770 // m_chisq[2][1] = (*iter_trk)->getChisq(1,0);
3771 // m_chisq[3][0] = (*iter_trk)->getChisq(1,1);
3772 // m_chisq[3][1] = (*iter_trk)->getChisq(1,2);
3773 // m_chisq[4][0] = (*iter_trk)->getChisq(1,3);
3774 // m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
3775
3776 // m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
3777 // m_ndf[0][1] = (*iter_trk)->getNdf(0,1);
3778 // m_ndf[1][0] = (*iter_trk)->getNdf(0,2);
3779 // m_ndf[1][1] = (*iter_trk)->getNdf(0,3);
3780 // m_ndf[2][0] = (*iter_trk)->getNdf(0,4);
3781 // m_ndf[2][1] = (*iter_trk)->getNdf(1,0);
3782 // m_ndf[3][0] = (*iter_trk)->getNdf(1,1);
3783 // m_ndf[3][1] = (*iter_trk)->getNdf(1,2);
3784 // m_ndf[4][0] = (*iter_trk)->getNdf(1,3);
3785 // m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
3786
3787 // m_stat[0][0] = (*iter_trk)->getStat(0,0);
3788 // m_stat[0][1] = (*iter_trk)->getStat(0,1);
3789 // m_stat[1][0] = (*iter_trk)->getStat(0,2);
3790 // m_stat[1][1] = (*iter_trk)->getStat(0,3);
3791 // m_stat[2][0] = (*iter_trk)->getStat(0,4);
3792 // m_stat[2][1] = (*iter_trk)->getStat(1,0);
3793 // m_stat[3][0] = (*iter_trk)->getStat(1,1);
3794 // m_stat[3][1] = (*iter_trk)->getStat(1,2);
3795 // m_stat[4][0] = (*iter_trk)->getStat(1,3);
3796 // m_stat[4][1] = (*iter_trk)->getStat(1,4);
3797
3798 // RootConversion changed in BOSS6.0, so use thefollowing:
3799 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
3800 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
3801 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
3802 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
3803 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
3804 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
3805 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
3806 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
3807 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
3808 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
3809
3810 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
3811 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
3812 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
3813 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
3814 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
3815 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
3816 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
3817 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
3818 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
3819 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
3820
3821 m_stat[0][0] = (*iter_trk)->getStat(0,0);
3822 m_stat[1][0] = (*iter_trk)->getStat(0,1);
3823 m_stat[2][0] = (*iter_trk)->getStat(0,2);
3824 m_stat[3][0] = (*iter_trk)->getStat(0,3);
3825 m_stat[4][0] = (*iter_trk)->getStat(0,4);
3826 m_stat[0][1] = (*iter_trk)->getStat(1,0);
3827 m_stat[1][1] = (*iter_trk)->getStat(1,1);
3828 m_stat[2][1] = (*iter_trk)->getStat(1,2);
3829 m_stat[3][1] = (*iter_trk)->getStat(1,3);
3830 m_stat[4][1] = (*iter_trk)->getStat(1,4);
3831
3832 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
3833 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
3834 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
3835 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
3836 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
3837
3838 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
3839 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
3840 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
3841 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
3842 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
3843
3844 m_lpt = 1/m_lhelix[2];
3845 m_lpte = 1/m_lhelixe[2];
3846 m_lptmu = 1/m_lhelixmu[2];
3847 m_lptk = 1/m_lhelixk[2];
3848 m_lptp = 1/m_lhelixp[2];
3849
3850 m_fpt = 1/m_fhelix[2];
3851 m_fpte = 1/m_fhelixe[2];
3852 m_fptmu = 1/m_fhelixmu[2];
3853 m_fptk = 1/m_fhelixk[2];
3854 m_fptp = 1/m_fhelixp[2];
3855
3856 if(debug_ >= 3){
3857 std::cout<<" "<<std::endl;
3858 std::cout<<"in file Kalman_fitting_anal ,the m_fpt is .."<<m_fpt<<std::endl;
3859 std::cout<<"in file Kalman_fitting_anal ,the m_fpte is .."<<m_fpte<<std::endl;
3860 std::cout<<"in file Kalman_fitting_anal ,the m_fptmu is .."<<m_fptmu<<std::endl;
3861 std::cout<<"in file Kalman_fitting_anal ,the m_fptk is .."<<m_fptk<<std::endl;
3862 std::cout<<"in file Kalman_fitting_anal ,the m_fptp is .."<<m_fptp<<std::endl;
3863 }
3864
3865 m_zpt = 1/m_zhelix[2];
3866 m_zpte = 1/m_zhelixe[2];
3867 m_zptmu = 1/m_zhelixmu[2];
3868 m_zptk = 1/m_zhelixk[2];
3869 m_zptp = 1/m_zhelixp[2];
3870
3871 if(debug_ >= 3) {
3872 std::cout<<"in file Kalman_fitting_anal ,the m_zpt is .."<<m_zpt<<std::endl;
3873 std::cout<<"in file Kalman_fitting_anal ,the m_zpte is .."<<m_zpte<<std::endl;
3874 std::cout<<"in file Kalman_fitting_anal ,the m_zptmu is .."<<m_zptmu<<std::endl;
3875 std::cout<<"in file Kalman_fitting_anal ,the m_zptk is .."<<m_zptk<<std::endl;
3876 std::cout<<"in file Kalman_fitting_anal ,the m_zptp is .."<<m_zptp<<std::endl;
3877 }
3878 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
3879 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
3880 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
3881 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
3882 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
3883
3884 if(debug_ >= 3) {
3885 std::cout<<"in file Kalman_fitting_anal ,the m_zptot is .."<<m_zptot<<std::endl;
3886 std::cout<<"in file Kalman_fitting_anal ,the m_zptote is .."<<m_zptote<<std::endl;
3887 std::cout<<"in file Kalman_fitting_anal ,the m_zptotmu is .."<<m_zptotmu<<std::endl;
3888 std::cout<<"in file Kalman_fitting_anal ,the m_zptotk is .."<<m_zptotk<<std::endl;
3889 std::cout<<"in file Kalman_fitting_anal ,the m_zptotp is .."<<m_zptotp<<std::endl;
3890 }
3891
3892 if(ntuple_&32) {
3893 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
3894 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
3895 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
3896 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
3897 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
3898 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
3899 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
3900 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
3901 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
3902 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
3903 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
3904 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
3905 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
3906 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
3907 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
3908 }
3909
3910 StatusCode sc1 = m_nt1->write();
3911 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
3912 }
3913
3914 if(ntuple_&4) {
3915 if(jj == 1) {
3916 phi1 = (*iter_trk)->getFFi0();
3917 r1 = (*iter_trk)->getFDr();
3918 z1 = (*iter_trk)->getFDz();
3919 kap1 = (*iter_trk)->getFCpa();
3920 tanl1 = (*iter_trk)->getFTanl();
3921 charge1 = kap1/fabs(kap1);
3922 x1 = r1*cos(phi1);
3923 y1 = r1*sin(phi1);
3924 p1 = sqrt(1+tanl1*tanl1)/kap1;
3925 the1 = M_PI/2-atan(tanl1);
3926 px1 = -sin(phi1)/fabs(kap1);
3927 py1 = cos(phi1)/fabs(kap1);
3928 pz1= tanl1/fabs(kap1);
3929
3930 } else if(jj == 2) {
3931 phi2 = (*iter_trk)->getFFi0();
3932 r2 = (*iter_trk)->getFDr();
3933 z2 = (*iter_trk)->getFDz();
3934 kap2 = (*iter_trk)->getFCpa();
3935 tanl2 = (*iter_trk)->getFTanl();
3936 charge2 = kap2/fabs(kap2);
3937 x2 = r1*cos(phi2);
3938 y2 = r1*sin(phi2);
3939 p2 = sqrt(1+tanl2*tanl2)/kap1;
3940 the2 = M_PI/2-atan(tanl2);
3941 px2 = -sin(phi2)/fabs(kap2);
3942 py2 = cos(phi2)/fabs(kap2);
3943 pz2= tanl2/fabs(kap2);
3944 }
3945 }
3946 }
3947 if(ntuple_&4) {
3948 m_delx = x1 - x2;
3949 m_dely = y1 - y2;
3950 m_delz = z1 - z2;
3951 m_delthe = the1 + the2;
3952 m_delphi = phi1- phi2;
3953 m_delp = p1 - p2;
3954 m_delpx = charge1*fabs(px1) + charge2*fabs(px2);
3955 m_delpy = charge1*fabs(py1) + charge2*fabs(py2);
3956 m_delpz = charge1*fabs(pz1) + charge2*fabs(pz2);
3957
3958 StatusCode sc2 = m_nt2->write();
3959 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
3960 }
3961
3962 delete [] order;
3963 delete [] rCont;
3964 delete [] rGen;
3965 delete [] rOM;
3966
3967 if (debug_ == 4)
3968 cout << "Kalfitting finished " << std::endl;
3969 //cout << "kalman fitting end" << endl;
3970}
3971
3973{
3974
3975 MsgStream log(msgSvc(), name());
3976 double Pt_threshold(0.3);
3977 Hep3Vector IP(0,0,0);
3978
3979 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
3980 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
3981 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
3982
3983 // Table Manager
3984 if ( !&whMgr ) return;
3985
3986 // Get reduced chi**2 of Mdc track :
3987 int ntrk = mdcMgr->size();
3988 double* rPt = new double[ntrk];
3989 int* rOM = new int[ntrk];
3990 unsigned int* order = new unsigned int[ntrk];
3991 unsigned int* rCont = new unsigned int[ntrk];
3992 unsigned int* rGen = new unsigned int[ntrk];
3993
3994 int index = 0;
3995 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
3996 end = mdcMgr->end(); it != end; it++) {
3997 // Pt
3998 rPt[index] = 0;
3999 if (it->helix[2])
4000 rPt[index] = 1 / fabs(it->helix[2]);
4001 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
4002 if(rPt[index] < 0) rPt[index] = DBL_MAX;
4003 // Outermost layer
4004 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
4005 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
4006 int outermost(-1);
4007 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4008 ii !=pt.begin()-1; ii--) {
4009 int lyr((*ii)->geo->Lyr()->Id());
4010 if (outermost < lyr) outermost = lyr;
4011 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
4012 }
4013 rOM[index] = outermost;
4014 order[index] = index;
4015 ++index;
4016 }
4017
4018 // Sort Mdc tracks by Pt
4019 for (int j, k = ntrk - 1; k >= 0; k = j){
4020 j = -1;
4021 for(int i = 1; i <= k; i++)
4022 if(rPt[i - 1] < rPt[i]){
4023 j = i - 1;
4024 std::swap(order[i], order[j]);
4025 std::swap(rPt[i], rPt[j]);
4026 std::swap(rOM[i], rOM[j]);
4027 std::swap(rCont[i], rCont[j]);
4028 std::swap(rGen[i], rGen[j]);
4029 }
4030 }
4031 delete [] rPt;
4032 //
4033 int newcount(0);
4034 //check whether Recon already registered
4035 DataObject *aReconEvent;
4036 eventSvc()->findObject("/Event/Recon",aReconEvent);
4037 if(!aReconEvent) {
4038 // register ReconEvent Data Object to TDS;
4039 ReconEvent* recevt = new ReconEvent;
4040 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
4041 if(sc!=StatusCode::SUCCESS) {
4042 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
4043 return;
4044 }
4045 }
4046
4047 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
4049 //make RecMdcKalTrackCol
4050 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
4051
4052 // Loop over tracks given by PatRecon :
4053 for(int l = 0; l < ntrk; l++) {
4054 // m_timer[3]->start();
4055 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[l]);
4056 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[l]);
4057
4058 // Reject the ones with quality != 0
4059 int trasqual = TrasanTRK_add.quality;
4060 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
4061 if (trasqual) continue;
4062
4063 newcount++;
4064 if (debug_ == 4)
4065 cout << "******* KalFit NUMBER : " << newcount << std::endl;
4066
4067 // What kind of KalFit ?
4068 int type(0);
4069 if ((TrasanTRK_add.decision & 32) == 32 ||
4070 (TrasanTRK_add.decision & 64) == 64) type = 1;
4071
4072 // Initialisation : (x, a, ea)
4073 HepPoint3D x(TrasanTRK.pivot[0],
4074 TrasanTRK.pivot[1],
4075 TrasanTRK.pivot[2]);
4076
4077 HepVector a(5);
4078 for(int i = 0; i < 5; i++)
4079 a[i] = TrasanTRK.helix[i];
4080
4081 HepSymMatrix ea(5);
4082 for(int i = 0, k = 0; i < 5; i++) {
4083 for(int j = 0; j <= i; j++) {
4084 ea[i][j] = matrixg_*TrasanTRK.error[k++];
4085 ea[j][i] = ea[i][j];
4086 }
4087 }
4088
4090
4091 double fiTerm = TrasanTRK.fiTerm;
4092 int way(1);
4093 // Prepare the track found :
4094 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
4095 track_lead.bFieldZ(KalFitTrack::Bznom_);
4096 // Mdc Hits
4097 int inlyr(999), outlyr(-1);
4098 int* rStat = new int[43];
4099 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
4100 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
4101 int hit_in(0);
4102 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
4103 // Number of hits/layer
4104 int Num[43] = {0};
4105 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4106 ii != pt.begin()-1; ii--) {
4107 Num[(*ii)->geo->Lyr()->Id()]++;
4108 }
4109
4110 int hit_asso(0);
4111 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4112 ii != pt.begin()-1; ii--) {
4113
4114 hit_asso++;
4115 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
4116 if (debug_ >0)
4117 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
4118 << " hits in the layer "
4119 << (*ii)->geo->Lyr()->Id() << std::endl;
4120 continue;
4121 }
4122 // if(ii!=pt.end()-1){
4123 // if(42 == (*ii)->geo->Lyr()->Id() && 42 == (*(ii+1))->geo->Lyr()->Id()){
4124 // MdcRec_wirhit * rechit_before = *(ii+1);
4125 // if((*rechit_before).tdc < (**ii).tdc) continue;
4126 // else if(track_lead.HitsMdc().size()>0 && rStat[42]){
4127 // track_lead.HitsMdc().pop_back();
4128 // }
4129 // }
4130 // else{
4131 // int layer_before=(*(ii+1))->geo->Lyr()->Id();
4132 // if(layer_before == (*ii)->geo->Lyr()->Id()){
4133 // MdcRec_wirhit * rechit_before = *(ii+1);
4134 // if((*rechit_before).rechitptr->getDriftT()>450 || (**ii).rechitptr->getDriftT()>450.){
4135 // if((*rechit_before).tdc < (**ii).tdc) continue;
4136 // else if(track_lead.HitsMdc().size()>0 && rStat[layer_before]){
4137 // track_lead.HitsMdc().pop_back();
4138 // }
4139 // }
4140 // }
4141 // }
4142 // }
4143
4144 hit_in++;
4145 MdcRec_wirhit & rechit = **ii;
4146 double dist[2] = {rechit.ddl, rechit.ddr};
4147 double erdist[2] = {rechit.erddl, rechit.erddr};
4148 const MdcGeoWire* geo = rechit.geo;
4149
4150 int lr_decision(0);
4151 if (KalFitTrack::LR_ == 1){
4152 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
4153 // if (rechit.lr==0) lr_decision=-1;
4154 else if (rechit.lr==1) lr_decision=1;
4155 }
4156
4157 int ind(geo->Lyr()->Id());
4158 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
4159 lr_decision, rechit.tdc,
4160 dist, erdist,
4161 _wire+(geo->Id()), rechit.rechitptr));
4162 // inner/outer layer :
4163 rStat[ind]++;
4164 if (inlyr>ind) inlyr = ind;
4165 if (outlyr<ind) outlyr = ind;
4166 }
4167 if (debug_ == 4)
4168 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
4169
4170 // Empty layers :
4171 int empty_between(0), empty(0);
4172 for (int i= inlyr; i <= outlyr; i++)
4173 if (!rStat[i]) empty_between++;
4174 empty = empty_between+inlyr+(42-outlyr);
4175 delete [] rStat;
4176
4177 // RMK high momentum track under study, probably not neeeded...
4178 track_lead.order_wirhit(1);
4179 track_lead.type(type);
4180 unsigned int nhit = track_lead.HitsMdc().size();
4181 if (!nhit && debug_ == 4) {
4182 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
4183 continue;
4184 }
4185
4186 // Initialisation :
4187 double KalFitst(0), KalFitax(0), KalFitschi2(0);
4188 // Move to the outer most hit :
4189 Hep3Vector outer_pivot(track_lead.x(fiTerm));
4190
4191 if(debug_ == 4) {
4192 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
4193 }
4194 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
4195 track_lead.bFieldZ(KalFitTrack::Bznom_);
4196 // attention best_chi2 reinitialize !!!
4197 if (nhit>=3 && !KalFitTrack::LR_)
4198 start_seed(track_lead, lead_, way, TrasanTRK);
4199 HepSymMatrix Eakal(5,0);
4200
4201 //init_matrix(TrasanTRK, Eakal);
4202
4203 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
4204 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
4205 choice_ = 6;
4206 }
4207
4208 init_matrix(choice_,TrasanTRK, Eakal);
4209
4210 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
4211
4212 if (debug_ == 4){
4213 std::cout << "from Mdc Pattern Recognition: " << std::endl;
4214 HepPoint3D IP(0,0,0);
4215 Helix work(track_lead.pivot(),
4216 track_lead.a(),
4217 track_lead.Ea());
4218 work.pivot(IP);
4219 std::cout << " dr = " << work.a()[0]
4220 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4221 std::cout << " phi0 = " << work.a()[1]
4222 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4223 std::cout << " PT = " << 1/work.a()[2]
4224 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4225 std::cout << " dz = " << work.a()[3]
4226 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4227 std::cout << " tanl = " << work.a()[4]
4228 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4229 }
4230
4231 filter_fwd_calib(track_lead, lead_, way, Eakal);
4232 track_lead.update_forMdc();
4233
4234 HepPoint3D IP(0,0,0);
4235 if (debug_ == 4) {
4236 cout << " Mdc FIRST KALMAN FIT " << std::endl;
4237 Helix work(track_lead.pivot(),
4238 track_lead.a(),
4239 track_lead.Ea());
4240 work.pivot(IP);
4241 cout << " dr = " << work.a()[0]
4242 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4243 cout << " phi0 = " << work.a()[1]
4244 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4245 cout << " PT = " << 1/work.a()[2]
4246 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4247 cout << " dz = " << work.a()[3]
4248 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4249 cout << " tanl = " << work.a()[4]
4250 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4251 }
4252
4253 // fill TDS
4254 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
4255
4256 // Complete the track (other mass assumption, backward) and
4257 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
4258 }
4259
4260
4261 StatusCode kalsc;
4262 //check whether the RecMdcKalTrackCol has been already registered
4263 DataObject *aRecKalEvent;
4264 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
4265 if(aRecKalEvent!=NULL) {
4266 //then unregister RecMdcKalCol
4267 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
4268 if(kalsc != StatusCode::SUCCESS) {
4269 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
4270 return;
4271 }
4272 }
4273
4274 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
4275 if( kalsc.isFailure()) {
4276 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
4277 return;
4278 }
4279 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
4280
4281
4282
4283 StatusCode segsc;
4284 //check whether the RecMdcKalHelixSegCol has been already registered
4285 DataObject *aRecKalSegEvent;
4286 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
4287 if(aRecKalSegEvent!=NULL) {
4288 //then unregister RecMdcKalHelixSegCol
4289 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
4290 if(segsc != StatusCode::SUCCESS) {
4291 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
4292 return;
4293 }
4294 }
4295
4296 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
4297 if( segsc.isFailure() ) {
4298 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
4299 return;
4300 }
4301 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
4302
4303
4304 double x1(0.),x2(0.),y1(0.),y2(0.),z1(0.),z2(0.),the1(0.),the2(0.),phi1(0.),phi2(0.),p1(0.),p2(0.);
4305 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
4306 //check the result:RecMdcKalTrackCol
4307
4308 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
4309 if (!kaltrkCol) {
4310 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
4311 return;
4312 }
4313 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
4314 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
4315 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
4316 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
4317 << "Track Id: " << (*iter_trk)->getTrackId()
4318 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
4319 << " Length of the track: "<< (*iter_trk)->getLength(2)
4320 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
4321 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
4322 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
4323 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
4324 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
4325 << "Kappa " << (*iter_trk)->getZHelix()[2]
4326 << endreq;
4327
4328 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
4329 if(debug_ == 4) {
4330 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
4331 }
4332
4333 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
4334 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
4335 if(debug_ == 4) {
4336 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
4337 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
4338 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
4339 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
4340 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
4341 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
4342 }
4343 }
4344 for( int i = 0; i<43; i++) {
4345 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
4346 << (*iter_trk)->getPathl(i) <<endreq;
4347 }
4348
4349 if(ntuple_&1) {
4350 m_trackid = (*iter_trk)->getTrackId();
4351 for( int jj =0, iii=0; jj<5; jj++) {
4352 m_length[jj] = (*iter_trk)->getLength(jj);
4353 m_tof[jj] = (*iter_trk)->getTof(jj);
4354 m_nhits[jj] = (*iter_trk)->getNhits(jj);
4355 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
4356 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
4357 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
4358 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
4359 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
4360 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
4361 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
4362 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
4363 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
4364 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
4365 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
4366 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
4367 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
4368 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
4369 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
4370 if(ntuple_&32) {
4371 for(int kk=0; kk<=jj; kk++,iii++) {
4372 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
4373 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
4374 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
4375 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
4376 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
4377 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
4378 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
4379 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
4380 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
4381 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
4382 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
4383 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
4384 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
4385 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
4386 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
4387 }
4388
4389 }
4390 }
4391
4392 // // the following logic may seem peculiar, but it IS the case(for BOSS5.0 and BOSS5.1)
4393 // m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4394 // m_chisq[0][1] = (*iter_trk)->getChisq(0,1);
4395 // m_chisq[1][0] = (*iter_trk)->getChisq(0,2);
4396 // m_chisq[1][1] = (*iter_trk)->getChisq(0,3);
4397 // m_chisq[2][0] = (*iter_trk)->getChisq(0,4);
4398 // m_chisq[2][1] = (*iter_trk)->getChisq(1,0);
4399 // m_chisq[3][0] = (*iter_trk)->getChisq(1,1);
4400 // m_chisq[3][1] = (*iter_trk)->getChisq(1,2);
4401 // m_chisq[4][0] = (*iter_trk)->getChisq(1,3);
4402 // m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4403
4404 // m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4405 // m_ndf[0][1] = (*iter_trk)->getNdf(0,1);
4406 // m_ndf[1][0] = (*iter_trk)->getNdf(0,2);
4407 // m_ndf[1][1] = (*iter_trk)->getNdf(0,3);
4408 // m_ndf[2][0] = (*iter_trk)->getNdf(0,4);
4409 // m_ndf[2][1] = (*iter_trk)->getNdf(1,0);
4410 // m_ndf[3][0] = (*iter_trk)->getNdf(1,1);
4411 // m_ndf[3][1] = (*iter_trk)->getNdf(1,2);
4412 // m_ndf[4][0] = (*iter_trk)->getNdf(1,3);
4413 // m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4414
4415 // m_stat[0][0] = (*iter_trk)->getStat(0,0);
4416 // m_stat[0][1] = (*iter_trk)->getStat(0,1);
4417 // m_stat[1][0] = (*iter_trk)->getStat(0,2);
4418 // m_stat[1][1] = (*iter_trk)->getStat(0,3);
4419 // m_stat[2][0] = (*iter_trk)->getStat(0,4);
4420 // m_stat[2][1] = (*iter_trk)->getStat(1,0);
4421 // m_stat[3][0] = (*iter_trk)->getStat(1,1);
4422 // m_stat[3][1] = (*iter_trk)->getStat(1,2);
4423 // m_stat[4][0] = (*iter_trk)->getStat(1,3);
4424 // m_stat[4][1] = (*iter_trk)->getStat(1,4);
4425
4426 // RootConversion changed in BOSS6.0, so use thefollowing:
4427 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4428 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
4429 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
4430 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
4431 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
4432 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
4433 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
4434 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
4435 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
4436 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4437
4438 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4439 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
4440 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
4441 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
4442 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
4443 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
4444 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
4445 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
4446 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
4447 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4448
4449 m_stat[0][0] = (*iter_trk)->getStat(0,0);
4450 m_stat[1][0] = (*iter_trk)->getStat(0,1);
4451 m_stat[2][0] = (*iter_trk)->getStat(0,2);
4452 m_stat[3][0] = (*iter_trk)->getStat(0,3);
4453 m_stat[4][0] = (*iter_trk)->getStat(0,4);
4454 m_stat[0][1] = (*iter_trk)->getStat(1,0);
4455 m_stat[1][1] = (*iter_trk)->getStat(1,1);
4456 m_stat[2][1] = (*iter_trk)->getStat(1,2);
4457 m_stat[3][1] = (*iter_trk)->getStat(1,3);
4458 m_stat[4][1] = (*iter_trk)->getStat(1,4);
4459
4460 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
4461 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
4462 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
4463 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
4464 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
4465
4466 m_zpt = 1/m_zhelix[2];
4467 m_zpte = 1/m_zhelixe[2];
4468 m_zptmu = 1/m_zhelixmu[2];
4469 m_zptk = 1/m_zhelixk[2];
4470 m_zptp = 1/m_zhelixp[2];
4471
4472 m_fpt = 1/m_fhelix[2];
4473 m_fpte = 1/m_fhelixe[2];
4474 m_fptmu = 1/m_fhelixmu[2];
4475 m_fptk = 1/m_fhelixk[2];
4476 m_fptp = 1/m_fhelixp[2];
4477
4478 m_lpt = 1/m_lhelix[2];
4479 m_lpte = 1/m_lhelixe[2];
4480 m_lptmu = 1/m_lhelixmu[2];
4481 m_lptk = 1/m_lhelixk[2];
4482 m_lptp = 1/m_lhelixp[2];
4483
4484 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
4485 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
4486 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
4487 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
4488 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
4489
4490 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
4491 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
4492 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
4493 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
4494 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
4495 if(ntuple_&32) {
4496 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
4497 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
4498 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
4499 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
4500 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
4501 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
4502 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
4503 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
4504 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
4505 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
4506 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
4507 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
4508 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
4509 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
4510 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
4511 }
4512
4513 StatusCode sc1 = m_nt1->write();
4514 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
4515 }
4516
4517 if(ntuple_&4) {
4518 if(jj == 1) {
4519 phi1 = (*iter_trk)->getFFi0();
4520 r1 = (*iter_trk)->getFDr();
4521 z1 = (*iter_trk)->getFDz();
4522 kap1 = (*iter_trk)->getFCpa();
4523 tanl1 = (*iter_trk)->getFTanl();
4524 x1 = r1*cos(phi1);
4525 y1 = r1*sin(phi1);
4526 p1 = sqrt(1+tanl1*tanl1)/kap1;
4527 the1 = M_PI/2-atan(tanl1);
4528 } else if(jj == 2) {
4529 phi2 = (*iter_trk)->getFFi0();
4530 r2 = (*iter_trk)->getFDr();
4531 z2 = (*iter_trk)->getFDz();
4532 kap2 = (*iter_trk)->getFCpa();
4533 tanl2 = (*iter_trk)->getFTanl();
4534 x2 = r1*cos(phi2);
4535 y2 = r1*sin(phi2);
4536 p2 = sqrt(1+tanl2*tanl2)/kap1;
4537 the2 = M_PI/2-atan(tanl2);
4538 }
4539 }
4540 }
4541 if(ntuple_&4) {
4542 m_delx = x1 - x2;
4543 m_dely = y1 - y2;
4544 m_delz = z1 - z2;
4545 m_delthe = the1 + the2;
4546 m_delphi = phi1- phi2;
4547 m_delp = p1 - p2;
4548 StatusCode sc2 = m_nt2->write();
4549 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
4550 }
4551 delete [] order;
4552 delete [] rCont;
4553 delete [] rGen;
4554 delete [] rOM;
4555
4556 if (debug_ == 4)
4557 cout << "Kalfitting finished " << std::endl;
4558}
4559
4560//Mdc alignment by MdcxReco_Csmc_Sew
4562{
4563
4564 MsgStream log(msgSvc(), name());
4565 double Pt_threshold(0.3);
4566 Hep3Vector IP(0,0,0);
4567
4568 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
4569 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
4570 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
4571
4572 // Table Manager
4573 if ( !&whMgr ) return;
4574
4575 // Get reduced chi**2 of Mdc track :
4576 int ntrk = mdcMgr->size();
4577 // cout<<"ntrk: "<<ntrk<<endl;
4578
4579 int nhits = whMgr->size();
4580 //cout<<"nhits: "<<nhits<<endl;
4581
4582
4583 //check whether Recon already registered
4584 DataObject *aReconEvent;
4585 eventSvc()->findObject("/Event/Recon",aReconEvent);
4586 if(!aReconEvent) {
4587 // register ReconEvent Data Object to TDS;
4588 ReconEvent* recevt = new ReconEvent;
4589 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
4590 if(sc!=StatusCode::SUCCESS) {
4591 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
4592 return;
4593 }
4594 }
4595
4596 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
4598 //make RecMdcKalTrackCol
4599 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
4600
4601
4602 MdcRec_trk& TrasanTRK = *(mdcMgr->begin());
4603 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin());
4604 // Reject the ones with quality != 0
4605 // int trasqual = TrasanTRK_add.quality;
4606 // if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
4607 // if (trasqual) continue;
4608
4609 // What kind of KalFit ?
4610 int type(0);
4611 if ((TrasanTRK_add.decision & 32) == 32 ||
4612 (TrasanTRK_add.decision & 64) == 64) type = 1;
4613
4614 // Initialisation : (x, a, ea)
4615 HepPoint3D x(TrasanTRK.pivot[0],
4616 TrasanTRK.pivot[1],
4617 TrasanTRK.pivot[2]);
4618
4619 HepVector a(5);
4620 for(int i = 0; i < 5; i++)
4621 a[i] = TrasanTRK.helix[i];
4622
4623 HepSymMatrix ea(5);
4624 for(int i = 0, k = 0; i < 5; i++) {
4625 for(int j = 0; j <= i; j++) {
4626 ea[i][j] = matrixg_*TrasanTRK.error[k++];
4627 ea[j][i] = ea[i][j];
4628 }
4629 }
4630
4632
4633 double fiTerm = TrasanTRK.fiTerm;
4634 int way(1);
4635 // Prepare the track found :
4636 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
4637 track_lead.bFieldZ(KalFitTrack::Bznom_);
4638
4639 int hit_asso(0);
4640 // Reject the ones with quality != 0
4641 int trasqual = TrasanTRK_add.quality;
4642 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
4643 if (trasqual) return;
4644 // Mdc Hits
4645 int inlyr(999), outlyr(-1);
4646 int* rStat = new int[43];
4647 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
4648 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
4649 int hit_in(0);
4650 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
4651 // Number of hits/layer
4652 int Num[43] = {0};
4653 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4654 ii != pt.begin()-1; ii--) {
4655 Num[(*ii)->geo->Lyr()->Id()]++;
4656 }
4657
4658 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4659 ii != pt.begin()-1; ii--) {
4660
4661 hit_asso++;
4662 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
4663 if (debug_ >0)
4664 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
4665 << " hits in the layer "
4666 << (*ii)->geo->Lyr()->Id() << std::endl;
4667 continue;
4668 }
4669
4670 hit_in++;
4671 MdcRec_wirhit & rechit = **ii;
4672 double dist[2] = {rechit.ddl, rechit.ddr};
4673 double erdist[2] = {rechit.erddl, rechit.erddr};
4674 const MdcGeoWire* geo = rechit.geo;
4675
4676 int lr_decision(0);
4677 if (KalFitTrack::LR_ == 1){
4678 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
4679 // if (rechit.lr==0) lr_decision=-1;
4680 else if (rechit.lr==1) lr_decision=1;
4681 }
4682
4683 int ind(geo->Lyr()->Id());
4684 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
4685 lr_decision, rechit.tdc,
4686 dist, erdist,
4687 _wire+(geo->Id()), rechit.rechitptr));
4688 // inner/outer layer :
4689 rStat[ind]++;
4690 if (inlyr>ind) inlyr = ind;
4691 if (outlyr<ind) outlyr = ind;
4692 }
4693 // Empty layers :
4694 int empty_between(0), empty(0);
4695 for (int i= inlyr; i <= outlyr; i++)
4696 if (!rStat[i]) empty_between++;
4697 empty = empty_between+inlyr+(42-outlyr);
4698 delete [] rStat;
4699
4700 if (debug_ == 4)
4701 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
4702
4703
4704 // RMK high momentum track under study, probably not neeeded...
4705 track_lead.order_wirhit(0);
4706 track_lead.type(type);
4707 unsigned int nhit = track_lead.HitsMdc().size();
4708 if (nhit<70) {
4709 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
4710 return;
4711 }
4712
4713 // Initialisation :
4714 double KalFitst(0), KalFitax(0), KalFitschi2(0);
4715 // Move to the outer most hit :
4716 Hep3Vector outer_pivot(track_lead.x(fiTerm));
4717
4718 if(debug_ == 4) {
4719 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
4720 }
4721 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
4722 track_lead.bFieldZ(KalFitTrack::Bznom_);
4723 // attention best_chi2 reinitialize !!!
4724 if (nhit>=3 && !KalFitTrack::LR_)
4725 start_seed(track_lead, lead_, way, TrasanTRK);
4726 HepSymMatrix Eakal(5,0);
4727
4728 //init_matrix(TrasanTRK, Eakal);
4729
4730 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
4731 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
4732 choice_ = 6;
4733 }
4734
4735 init_matrix(choice_,TrasanTRK, Eakal);
4736
4737 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
4738
4739 if (debug_ == 4){
4740 std::cout << "from Mdc Pattern Recognition: " << std::endl;
4741 //HepPoint3D IP(0,0,0);
4742 Helix work(track_lead.pivot(),
4743 track_lead.a(),
4744 track_lead.Ea());
4745 work.pivot(IP);
4746 std::cout << " dr = " << work.a()[0]
4747 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4748 std::cout << " phi0 = " << work.a()[1]
4749 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4750 std::cout << " PT = " << 1/work.a()[2]
4751 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4752 std::cout << " dz = " << work.a()[3]
4753 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4754 std::cout << " tanl = " << work.a()[4]
4755 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4756 }
4757 filter_fwd_calib(track_lead, lead_, way, Eakal);
4758 track_lead.update_forMdc();
4759
4760 //HepPoint3D IP(0,0,0);
4761 if (debug_ == 4) {
4762 cout << " Mdc FIRST KALMAN FIT " << std::endl;
4763 Helix work1(track_lead.pivot(),
4764 track_lead.a(),
4765 track_lead.Ea());
4766 work1.pivot(IP);
4767 cout << " dr = " << work1.a()[0]
4768 << ", Er_dr = " << sqrt(work1.Ea()[0][0]) << std::endl;
4769 cout << " phi0 = " << work1.a()[1]
4770 << ", Er_phi0 = " << sqrt(work1.Ea()[1][1]) << std::endl;
4771 cout << " PT = " << 1/work1.a()[2]
4772 << ", Er_kappa = " << sqrt(work1.Ea()[2][2]) << std::endl;
4773 cout << " dz = " << work1.a()[3]
4774 << ", Er_dz = " << sqrt(work1.Ea()[3][3]) << std::endl;
4775 cout << " tanl = " << work1.a()[4]
4776 << ", Er_tanl = " << sqrt(work1.Ea()[4][4]) << std::endl;
4777 }
4778
4779 // fill TDS
4780 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
4781
4782 // Complete the track (other mass assumption, backward) and
4783 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
4784
4785
4786 StatusCode kalsc;
4787 //check whether the RecMdcKalTrackCol has been already registered
4788 DataObject *aRecKalEvent;
4789 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
4790 if(aRecKalEvent!=NULL) {
4791 //then unregister RecMdcKalCol
4792 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
4793 if(kalsc != StatusCode::SUCCESS) {
4794 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
4795 return;
4796 }
4797 }
4798
4799 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
4800 if( kalsc.isFailure()) {
4801 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
4802 return;
4803 }
4804 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
4805
4806
4807
4808 StatusCode segsc;
4809 //check whether the RecMdcKalHelixSegCol has been already registered
4810 DataObject *aRecKalSegEvent;
4811 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
4812 if(aRecKalSegEvent!=NULL) {
4813 //then unregister RecMdcKalHelixSegCol
4814 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
4815 if(segsc != StatusCode::SUCCESS) {
4816 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
4817 return;
4818 }
4819 }
4820
4821 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
4822 if( segsc.isFailure() ) {
4823 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
4824 return;
4825 }
4826 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
4827
4828
4829 double x1(0.),x2(0.),y1(0.),y2(0.),z1(0.),z2(0.),the1(0.),the2(0.),phi1(0.),phi2(0.),p1(0.),p2(0.);
4830 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
4831 //check the result:RecMdcKalTrackCol
4832
4833 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
4834 if (!kaltrkCol) {
4835 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
4836 return;
4837 }
4838 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
4839 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
4840 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
4841 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
4842 << "Track Id: " << (*iter_trk)->getTrackId()
4843 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
4844 << " Length of the track: "<< (*iter_trk)->getLength(2)
4845 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
4846 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
4847 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
4848 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
4849 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
4850 << "Kappa " << (*iter_trk)->getZHelix()[2]
4851 << "zhelixmu "<<(*iter_trk)->getZHelixMu()
4852 << endreq;
4853
4854 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
4855 if(debug_ == 4) {
4856 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
4857 }
4858
4859 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
4860 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
4861 if(debug_ == 4) {
4862 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
4863 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
4864 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
4865 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
4866 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
4867 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
4868 }
4869 }
4870 for( int i = 0; i<43; i++) {
4871 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
4872 << (*iter_trk)->getPathl(i) <<endreq;
4873 }
4874
4875 if(ntuple_&1) {
4876 m_trackid = (*iter_trk)->getTrackId();
4877 for( int jj =0, iii=0; jj<5; jj++) {
4878 m_length[jj] = (*iter_trk)->getLength(jj);
4879 m_tof[jj] = (*iter_trk)->getTof(jj);
4880 m_nhits[jj] = (*iter_trk)->getNhits(jj);
4881 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
4882 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
4883 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
4884 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
4885 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
4886 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
4887 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
4888 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
4889 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
4890 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
4891 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
4892 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
4893 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
4894 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
4895 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
4896 if(ntuple_&32) {
4897 for(int kk=0; kk<=jj; kk++,iii++) {
4898 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
4899 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
4900 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
4901 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
4902 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
4903 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
4904 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
4905 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
4906 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
4907 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
4908 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
4909 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
4910 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
4911 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
4912 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
4913 }
4914
4915 }
4916 }
4917
4918 // RootConversion changed in BOSS6.0, so use thefollowing:
4919 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4920 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
4921 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
4922 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
4923 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
4924 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
4925 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
4926 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
4927 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
4928 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4929
4930 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4931 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
4932 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
4933 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
4934 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
4935 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
4936 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
4937 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
4938 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
4939 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4940
4941 m_stat[0][0] = (*iter_trk)->getStat(0,0);
4942 m_stat[1][0] = (*iter_trk)->getStat(0,1);
4943 m_stat[2][0] = (*iter_trk)->getStat(0,2);
4944 m_stat[3][0] = (*iter_trk)->getStat(0,3);
4945 m_stat[4][0] = (*iter_trk)->getStat(0,4);
4946 m_stat[0][1] = (*iter_trk)->getStat(1,0);
4947 m_stat[1][1] = (*iter_trk)->getStat(1,1);
4948 m_stat[2][1] = (*iter_trk)->getStat(1,2);
4949 m_stat[3][1] = (*iter_trk)->getStat(1,3);
4950 m_stat[4][1] = (*iter_trk)->getStat(1,4);
4951
4952 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
4953 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
4954 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
4955 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
4956 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
4957
4958 m_zpt = 1/m_zhelix[2];
4959 m_zpte = 1/m_zhelixe[2];
4960 m_zptmu = 1/m_zhelixmu[2];
4961 m_zptk = 1/m_zhelixk[2];
4962 m_zptp = 1/m_zhelixp[2];
4963
4964 m_fpt = 1/m_fhelix[2];
4965 m_fpte = 1/m_fhelixe[2];
4966 m_fptmu = 1/m_fhelixmu[2];
4967 m_fptk = 1/m_fhelixk[2];
4968 m_fptp = 1/m_fhelixp[2];
4969
4970 m_lpt = 1/m_lhelix[2];
4971 m_lpte = 1/m_lhelixe[2];
4972 m_lptmu = 1/m_lhelixmu[2];
4973 m_lptk = 1/m_lhelixk[2];
4974 m_lptp = 1/m_lhelixp[2];
4975
4976 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
4977 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
4978 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
4979 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
4980 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
4981
4982 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
4983 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
4984 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
4985 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
4986 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
4987 if(ntuple_&32) {
4988 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
4989 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
4990 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
4991 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
4992 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
4993 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
4994 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
4995 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
4996 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
4997 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
4998 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
4999 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
5000 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
5001 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
5002 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
5003 }
5004
5005 StatusCode sc1 = m_nt1->write();
5006 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
5007 }
5008
5009 if(ntuple_&4) {
5010 if(jj == 1) {
5011 phi1 = (*iter_trk)->getFFi0();
5012 r1 = (*iter_trk)->getFDr();
5013 z1 = (*iter_trk)->getFDz();
5014 kap1 = (*iter_trk)->getFCpa();
5015 tanl1 = (*iter_trk)->getFTanl();
5016 x1 = r1*cos(phi1);
5017 y1 = r1*sin(phi1);
5018 p1 = sqrt(1+tanl1*tanl1)/kap1;
5019 the1 = M_PI/2-atan(tanl1);
5020 } else if(jj == 2) {
5021 phi2 = (*iter_trk)->getFFi0();
5022 r2 = (*iter_trk)->getFDr();
5023 z2 = (*iter_trk)->getFDz();
5024 kap2 = (*iter_trk)->getFCpa();
5025 tanl2 = (*iter_trk)->getFTanl();
5026 x2 = r1*cos(phi2);
5027 y2 = r1*sin(phi2);
5028 p2 = sqrt(1+tanl2*tanl2)/kap1;
5029 the2 = M_PI/2-atan(tanl2);
5030 }
5031 }
5032 }
5033 if(ntuple_&4) {
5034 m_delx = x1 - x2;
5035 m_dely = y1 - y2;
5036 m_delz = z1 - z2;
5037 m_delthe = the1 + the2;
5038 m_delphi = phi1- phi2;
5039 m_delp = p1 - p2;
5040 StatusCode sc2 = m_nt2->write();
5041 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
5042 }
5043
5044 if (debug_ == 4)
5045 cout << "Kalfitting finished " << std::endl;
5046}
5047
5048
5049//Mdc alignment by conecting two cosmic segments for one track
5051{
5052
5053 MsgStream log(msgSvc(), name());
5054 double Pt_threshold(0.3);
5055 Hep3Vector IP(0,0,0);
5056
5057 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
5058 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
5059 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
5060
5061 // Table Manager
5062 if ( !&whMgr ) return;
5063
5064 // Get reduced chi**2 of Mdc track :
5065 int ntrk = mdcMgr->size();
5066 //cout<<"ntrk: "<<ntrk<<endl;
5067
5068 int nhits = whMgr->size();
5069 //cout<<"nhits: "<<nhits<<endl;
5070
5071
5072 double* rY = new double[ntrk];
5073 double* rfiTerm = new double[ntrk];
5074 double* rPt = new double[ntrk];
5075 int* rOM = new int[ntrk];
5076 unsigned int* order = new unsigned int[ntrk];
5077 unsigned int* rCont = new unsigned int[ntrk];
5078 unsigned int* rGen = new unsigned int[ntrk];
5079
5080 int index = 0;
5081 Hep3Vector csmp3[2];
5082 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
5083 end = mdcMgr->end(); it != end; it++) {
5084 //order by phi term
5085 rfiTerm[index]=it->fiTerm;
5086 //cout<<"fiTerm: "<<rfiTerm[index]<<endl;
5087 // Pt
5088 rPt[index] = 0;
5089 if (it->helix[2])
5090 rPt[index] = 1 / fabs(it->helix[2]);
5091 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
5092 if(rPt[index] < 0) rPt[index] = DBL_MAX;
5093 // Outermost layer
5094 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
5095 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
5096 int outermost(-1);
5097 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5098 ii !=pt.begin()-1; ii--) {
5099 int lyr((*ii)->geo->Lyr()->Id());
5100 if (outermost < lyr) {
5101 outermost = lyr;
5102 rY[index] = (*ii)->geo->Forward().y();
5103 }
5104 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
5105 }
5106 rOM[index] = outermost;
5107 order[index] = index;
5108 ++index;
5109 }
5110
5111 // Sort Mdc tracks by fiTerm
5112 for (int j, k = ntrk - 1; k >= 0; k = j){
5113 j = -1;
5114 for(int i = 1; i <= k; i++)
5115 if(rY[i - 1] < rY[i]){
5116 j = i - 1;
5117 std::swap(order[i], order[j]);
5118 std::swap(rY[i], rY[j]);
5119 std::swap(rOM[i], rOM[j]);
5120 std::swap(rCont[i], rCont[j]);
5121 std::swap(rGen[i], rGen[j]);
5122 }
5123 }
5124 delete [] rPt;
5125 delete [] rY;
5126 delete [] rfiTerm;
5127 //
5128 int newcount(0);
5129 //check whether Recon already registered
5130 DataObject *aReconEvent;
5131 eventSvc()->findObject("/Event/Recon",aReconEvent);
5132 if(!aReconEvent) {
5133 // register ReconEvent Data Object to TDS;
5134 ReconEvent* recevt = new ReconEvent;
5135 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
5136 if(sc!=StatusCode::SUCCESS) {
5137 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
5138 return;
5139 }
5140 }
5141
5142 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
5144 //make RecMdcKalTrackCol
5145 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
5146
5147 // m_timer[3]->start();
5148 // MdcRec_trk& TrasanTRK;
5149 // MdcRec_trk_add& TrasanTRK_add;
5150
5151 // for(int l = 0; l < ntrk; l++) {
5152 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[1]);
5153 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[1]);
5154 // Reject the ones with quality != 0
5155 // int trasqual = TrasanTRK_add.quality;
5156 // if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5157 // if (trasqual) continue;
5158
5159 newcount++;
5160 if (debug_ == 4)
5161 cout << "******* KalFit NUMBER : " << newcount << std::endl;
5162
5163 // What kind of KalFit ?
5164 int type(0);
5165 if ((TrasanTRK_add.decision & 32) == 32 ||
5166 (TrasanTRK_add.decision & 64) == 64) type = 1;
5167
5168 // Initialisation : (x, a, ea)
5169 HepPoint3D x(TrasanTRK.pivot[0],
5170 TrasanTRK.pivot[1],
5171 TrasanTRK.pivot[2]);
5172
5173 HepVector a(5);
5174 for(int i = 0; i < 5; i++)
5175 a[i] = TrasanTRK.helix[i];
5176
5177 HepSymMatrix ea(5);
5178 for(int i = 0, k = 0; i < 5; i++) {
5179 for(int j = 0; j <= i; j++) {
5180 ea[i][j] = matrixg_*TrasanTRK.error[k++];
5181 ea[j][i] = ea[i][j];
5182 }
5183 }
5184
5186
5187 double fiTerm = TrasanTRK.fiTerm;
5188 int way(1);
5189 // Prepare the track found :
5190 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
5191 track_lead.bFieldZ(KalFitTrack::Bznom_);
5192
5193 int hit_asso(0);
5194 for(int l = 0; l < ntrk; l++) {
5195 MdcRec_trk& TrasanTRK1 = *(mdcMgr->begin() + order[l]);
5196 MdcRec_trk_add& TrasanTRK_add1 = *(mdc_addMgr->begin()+order[l]);
5197 // Reject the ones with quality != 0
5198 int trasqual = TrasanTRK_add1.quality;
5199 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5200 if (trasqual) continue;
5201 // Mdc Hits
5202 int inlyr(999), outlyr(-1);
5203 int* rStat = new int[43];
5204 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
5205 std::vector<MdcRec_wirhit*> pt=TrasanTRK1.hitcol;
5206 int hit_in(0);
5207 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
5208 // Number of hits/layer
5209 int Num[43] = {0};
5210 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5211 ii != pt.begin()-1; ii--) {
5212 Num[(*ii)->geo->Lyr()->Id()]++;
5213 }
5214
5215 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5216 ii != pt.begin()-1; ii--) {
5217
5218 hit_asso++;
5219 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
5220 if (debug_ >0)
5221 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
5222 << " hits in the layer "
5223 << (*ii)->geo->Lyr()->Id() << std::endl;
5224 continue;
5225 }
5226
5227 hit_in++;
5228 MdcRec_wirhit & rechit = **ii;
5229 double dist[2] = {rechit.ddl, rechit.ddr};
5230 double erdist[2] = {rechit.erddl, rechit.erddr};
5231 const MdcGeoWire* geo = rechit.geo;
5232
5233 int lr_decision(0);
5234 if (KalFitTrack::LR_ == 1){
5235 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
5236 // if (rechit.lr==0) lr_decision=-1;
5237 else if (rechit.lr==1) lr_decision=1;
5238 }
5239
5240 int ind(geo->Lyr()->Id());
5241 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
5242 lr_decision, rechit.tdc,
5243 dist, erdist,
5244 _wire+(geo->Id()), rechit.rechitptr));
5245 // inner/outer layer :
5246 rStat[ind]++;
5247 if (inlyr>ind) inlyr = ind;
5248 if (outlyr<ind) outlyr = ind;
5249 }
5250 // Empty layers :
5251 int empty_between(0), empty(0);
5252 for (int i= inlyr; i <= outlyr; i++)
5253 if (!rStat[i]) empty_between++;
5254 empty = empty_between+inlyr+(42-outlyr);
5255 delete [] rStat;
5256 }
5257 if (debug_ == 4)
5258 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
5259
5260
5261 // RMK high momentum track under study, probably not neeeded...
5262 track_lead.order_wirhit(0);
5263 track_lead.type(type);
5264 unsigned int nhit = track_lead.HitsMdc().size();
5265 if (nhit<70) {
5266 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
5267 return;
5268 }
5269
5270 // Initialisation :
5271 double KalFitst(0), KalFitax(0), KalFitschi2(0);
5272 // Move to the outer most hit :
5273 Hep3Vector outer_pivot(track_lead.x(fiTerm));
5274
5275 if(debug_ == 4) {
5276 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
5277 }
5278 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
5279 track_lead.bFieldZ(KalFitTrack::Bznom_);
5280 // attention best_chi2 reinitialize !!!
5281 if (nhit>=3 && !KalFitTrack::LR_)
5282 start_seed(track_lead, lead_, way, TrasanTRK);
5283 HepSymMatrix Eakal(5,0);
5284
5285 //init_matrix(TrasanTRK, Eakal);
5286
5287 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
5288 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5289 choice_ = 6;
5290 }
5291
5292 init_matrix(choice_,TrasanTRK, Eakal);
5293
5294 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
5295
5296 if (debug_ == 4){
5297 std::cout << "from Mdc Pattern Recognition: " << std::endl;
5298 //HepPoint3D IP(0,0,0);
5299 Helix work(track_lead.pivot(),
5300 track_lead.a(),
5301 track_lead.Ea());
5302 work.pivot(IP);
5303 std::cout << " dr = " << work.a()[0]
5304 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
5305 std::cout << " phi0 = " << work.a()[1]
5306 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
5307 std::cout << " PT = " << 1/work.a()[2]
5308 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
5309 std::cout << " dz = " << work.a()[3]
5310 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
5311 std::cout << " tanl = " << work.a()[4]
5312 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
5313 }
5314 filter_fwd_calib(track_lead, lead_, way, Eakal);
5315 track_lead.update_forMdc();
5316
5317 //HepPoint3D IP(0,0,0);
5318 if (debug_ == 4) {
5319 cout << " Mdc FIRST KALMAN FIT " << std::endl;
5320 Helix work1(track_lead.pivot(),
5321 track_lead.a(),
5322 track_lead.Ea());
5323 work1.pivot(IP);
5324 cout << " dr = " << work1.a()[0]
5325 << ", Er_dr = " << sqrt(work1.Ea()[0][0]) << std::endl;
5326 cout << " phi0 = " << work1.a()[1]
5327 << ", Er_phi0 = " << sqrt(work1.Ea()[1][1]) << std::endl;
5328 cout << " PT = " << 1/work1.a()[2]
5329 << ", Er_kappa = " << sqrt(work1.Ea()[2][2]) << std::endl;
5330 cout << " dz = " << work1.a()[3]
5331 << ", Er_dz = " << sqrt(work1.Ea()[3][3]) << std::endl;
5332 cout << " tanl = " << work1.a()[4]
5333 << ", Er_tanl = " << sqrt(work1.Ea()[4][4]) << std::endl;
5334 }
5335
5336 // fill TDS
5337 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
5338
5339 // Complete the track (other mass assumption, backward) and
5340 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
5341 // }
5342
5343
5344 StatusCode kalsc;
5345 //check whether the RecMdcKalTrackCol has been already registered
5346 DataObject *aRecKalEvent;
5347 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
5348 if(aRecKalEvent!=NULL) {
5349 //then unregister RecMdcKalCol
5350 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
5351 if(kalsc != StatusCode::SUCCESS) {
5352 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
5353 return;
5354 }
5355 }
5356
5357 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
5358 if( kalsc.isFailure()) {
5359 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
5360 return;
5361 }
5362 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
5363
5364
5365
5366 StatusCode segsc;
5367 //check whether the RecMdcKalHelixSegCol has been already registered
5368 DataObject *aRecKalSegEvent;
5369 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
5370 if(aRecKalSegEvent!=NULL) {
5371 //then unregister RecMdcKalHelixSegCol
5372 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
5373 if(segsc != StatusCode::SUCCESS) {
5374 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
5375 return;
5376 }
5377 }
5378
5379 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
5380 if( segsc.isFailure() ) {
5381 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
5382 return;
5383 }
5384 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
5385
5386
5387 double x1(0.),x2(0.),y1(0.),y2(0.),z1(0.),z2(0.),the1(0.),the2(0.),phi1(0.),phi2(0.),p1(0.),p2(0.);
5388 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
5389 //check the result:RecMdcKalTrackCol
5390
5391 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
5392 if (!kaltrkCol) {
5393 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
5394 return;
5395 }
5396 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
5397 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
5398 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
5399 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
5400 << "Track Id: " << (*iter_trk)->getTrackId()
5401 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
5402 << " Length of the track: "<< (*iter_trk)->getLength(2)
5403 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
5404 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
5405 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
5406 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
5407 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
5408 << "Kappa " << (*iter_trk)->getZHelix()[2]
5409 << "zhelixmu "<<(*iter_trk)->getZHelixMu()
5410 << endreq;
5411
5412 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
5413 if(debug_ == 4) {
5414 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
5415 }
5416
5417 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
5418 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
5419 if(debug_ == 4) {
5420 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
5421 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
5422 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
5423 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
5424 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
5425 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
5426 }
5427 }
5428 for( int i = 0; i<43; i++) {
5429 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
5430 << (*iter_trk)->getPathl(i) <<endreq;
5431 }
5432
5433 if(ntuple_&1) {
5434 m_trackid = (*iter_trk)->getTrackId();
5435 for( int jj =0, iii=0; jj<5; jj++) {
5436 m_length[jj] = (*iter_trk)->getLength(jj);
5437 m_tof[jj] = (*iter_trk)->getTof(jj);
5438 m_nhits[jj] = (*iter_trk)->getNhits(jj);
5439 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
5440 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
5441 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
5442 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
5443 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
5444 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
5445 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
5446 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
5447 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
5448 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
5449 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
5450 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
5451 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
5452 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
5453 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
5454 if(ntuple_&32) {
5455 for(int kk=0; kk<=jj; kk++,iii++) {
5456 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
5457 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
5458 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
5459 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
5460 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
5461 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
5462 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
5463 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
5464 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
5465 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
5466 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
5467 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
5468 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
5469 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
5470 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
5471 }
5472
5473 }
5474 }
5475
5476 // RootConversion changed in BOSS6.0, so use thefollowing:
5477 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
5478 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
5479 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
5480 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
5481 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
5482 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
5483 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
5484 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
5485 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
5486 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
5487
5488 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
5489 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
5490 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
5491 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
5492 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
5493 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
5494 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
5495 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
5496 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
5497 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
5498
5499 m_stat[0][0] = (*iter_trk)->getStat(0,0);
5500 m_stat[1][0] = (*iter_trk)->getStat(0,1);
5501 m_stat[2][0] = (*iter_trk)->getStat(0,2);
5502 m_stat[3][0] = (*iter_trk)->getStat(0,3);
5503 m_stat[4][0] = (*iter_trk)->getStat(0,4);
5504 m_stat[0][1] = (*iter_trk)->getStat(1,0);
5505 m_stat[1][1] = (*iter_trk)->getStat(1,1);
5506 m_stat[2][1] = (*iter_trk)->getStat(1,2);
5507 m_stat[3][1] = (*iter_trk)->getStat(1,3);
5508 m_stat[4][1] = (*iter_trk)->getStat(1,4);
5509
5510 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
5511 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
5512 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
5513 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
5514 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
5515
5516 m_zpt = 1/m_zhelix[2];
5517 m_zpte = 1/m_zhelixe[2];
5518 m_zptmu = 1/m_zhelixmu[2];
5519 m_zptk = 1/m_zhelixk[2];
5520 m_zptp = 1/m_zhelixp[2];
5521
5522 m_fpt = 1/m_fhelix[2];
5523 m_fpte = 1/m_fhelixe[2];
5524 m_fptmu = 1/m_fhelixmu[2];
5525 m_fptk = 1/m_fhelixk[2];
5526 m_fptp = 1/m_fhelixp[2];
5527
5528 m_lpt = 1/m_lhelix[2];
5529 m_lpte = 1/m_lhelixe[2];
5530 m_lptmu = 1/m_lhelixmu[2];
5531 m_lptk = 1/m_lhelixk[2];
5532 m_lptp = 1/m_lhelixp[2];
5533
5534 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
5535 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
5536 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
5537 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
5538 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
5539
5540 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
5541 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
5542 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
5543 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
5544 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
5545 if(ntuple_&32) {
5546 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
5547 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
5548 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
5549 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
5550 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
5551 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
5552 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
5553 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
5554 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
5555 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
5556 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
5557 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
5558 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
5559 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
5560 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
5561 }
5562
5563 StatusCode sc1 = m_nt1->write();
5564 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
5565 }
5566
5567 if(ntuple_&4) {
5568 if(jj == 1) {
5569 phi1 = (*iter_trk)->getFFi0();
5570 r1 = (*iter_trk)->getFDr();
5571 z1 = (*iter_trk)->getFDz();
5572 kap1 = (*iter_trk)->getFCpa();
5573 tanl1 = (*iter_trk)->getFTanl();
5574 x1 = r1*cos(phi1);
5575 y1 = r1*sin(phi1);
5576 p1 = sqrt(1+tanl1*tanl1)/kap1;
5577 the1 = M_PI/2-atan(tanl1);
5578 } else if(jj == 2) {
5579 phi2 = (*iter_trk)->getFFi0();
5580 r2 = (*iter_trk)->getFDr();
5581 z2 = (*iter_trk)->getFDz();
5582 kap2 = (*iter_trk)->getFCpa();
5583 tanl2 = (*iter_trk)->getFTanl();
5584 x2 = r1*cos(phi2);
5585 y2 = r1*sin(phi2);
5586 p2 = sqrt(1+tanl2*tanl2)/kap1;
5587 the2 = M_PI/2-atan(tanl2);
5588 }
5589 }
5590 }
5591 if(ntuple_&4) {
5592 m_delx = x1 - x2;
5593 m_dely = y1 - y2;
5594 m_delz = z1 - z2;
5595 m_delthe = the1 + the2;
5596 m_delphi = phi1- phi2;
5597 m_delp = p1 - p2;
5598 StatusCode sc2 = m_nt2->write();
5599 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
5600 }
5601 delete [] order;
5602 delete [] rCont;
5603 delete [] rGen;
5604 delete [] rOM;
5605
5606 if (debug_ == 4)
5607 cout << "Kalfitting finished " << std::endl;
5608}
5609
5610
5611
5613 MdcRec_trk_add& TrasanTRK_add,
5614 KalFitTrack& track_lead,
5615 RecMdcKalTrack* kaltrk,
5616 RecMdcKalTrackCol* kalcol,RecMdcKalHelixSegCol *segcol,int flagsmooth)
5617{
5618 static int nmass = KalFitTrack::nmass();
5619 int way(1);
5620 MsgStream log(msgSvc(), name());
5621 KalFitTrack track_first(track_lead);
5622 //fromFHitToInnerWall(track_lead, way);
5623 // cout << "m_esti" << m_esti1_r[0] << endl;
5624 //cout<<"fitGemHits for pion"<<endl;
5625 //if(useNCGem_>0) fitGemHits(track_lead, lead_, way);
5626 if(useNCGem_>0)track_first=Cgem_filter_anal(track_lead, lead_, way);
5627 KalFitTrack track_ip(track_lead);
5628 //cout<<"__FUNCTION__: track_lead.nLayerUsed = "<<track_lead.nLayerUsed()<<endl;
5629 //cout<<"__FUNCTION__: track_ip.nLayerUsed = "<<track_ip.nLayerUsed()<<endl;
5630 //innerwall(track_ip, lead_, way,95,99);
5631 // Fill Tds
5632 fillTds_ip(TrasanTRK, track_ip, kaltrk, lead_);
5633 // std::cout<<"track_first nster"<<track_first.nster()<<std::endl;
5634
5635 fillTds_lead(TrasanTRK, track_first, kaltrk, lead_);
5636 // Refit for different mass assumptions :
5637 double pp = track_lead.momentum().mag();
5638
5639 if(!(i_front_<0)){
5640 //cout << "!!!!i_front" << i_front_<< endl;
5641 for(int l_mass = 0, flg = 1; l_mass < nmass;
5642 l_mass++, flg <<= 1) {
5643
5644 if (!(mhyp_ & flg)) continue;
5645 if (l_mass == lead_) continue;
5646
5647 // Check the mom. to decide of the refit with this mass assumption
5648 if ((lead_ != 0 && l_mass==0 && pp > pe_cut_) ||
5649 (lead_ != 1 && l_mass==1 && pp > pmu_cut_) ||
5650 (lead_ != 2 && l_mass==2 && pp > ppi_cut_) ||
5651 (lead_ != 3 && l_mass==3 && pp > pk_cut_) ||
5652 (lead_ != 4 && l_mass==4 && pp > pp_cut_))
5653 continue;
5654 if(debug_ == 4) cout<<"complete_track..REFIT ASSUMPION " << l_mass << endl;
5655 // Initialisation :
5656 double chiSq = 0;
5657 int nhits = 0;
5658
5659 // Initialisation : (x, a, ea)
5660 HepPoint3D x_trasan(TrasanTRK.pivot[0],
5661 TrasanTRK.pivot[1],
5662 TrasanTRK.pivot[2]);
5663 HepVector a_trasan(5);
5664 for(int i = 0; i < 5; i++)
5665 a_trasan[i] = TrasanTRK.helix[i];
5666
5667 HepSymMatrix ea_trasan(5);
5668 for(int i = 0, k = 0; i < 5; i++) {
5669 for(int j = 0; j <= i; j++) {
5670 ea_trasan[i][j] = matrixg_*TrasanTRK.error[k++];
5671 ea_trasan[j][i] = ea_trasan[i][j];
5672 }
5673 }
5674
5675 KalFitTrack track(x_trasan,a_trasan, ea_trasan, l_mass, chiSq, nhits);
5676 track.HitsMdc(track_lead.HitsMdc());
5677 track.trasan_id(TrasanTRK.id);
5678 double fiTerm = TrasanTRK.fiTerm;
5679 track.pivot(track.x(fiTerm));
5680 HepSymMatrix Eakal(5,0);
5681
5682 double costheta = track.a()[4] / sqrt(1.0 + track.a()[4]*track.a()[4]);
5683 if( (1.0/fabs(track.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5684 choice_ = 6;
5685 }
5686
5687 init_matrix(choice_,TrasanTRK, Eakal);
5688 filter_fwd_anal(track, l_mass, way, Eakal);
5689 KalFitTrack track_z(track);
5690 //fromFHitToInnerWall(track_z, way);
5691 //cout<<"fitGemHits for i="<<l_mass<<endl;
5692 //if(useNCGem_>0) fitGemHits(track_z, l_mass, way);
5693 if(useNCGem_>0) Cgem_filter_anal(track_z, l_mass, way);
5694 ///fill tds with results got at (0,0,0)
5695 //innerwall(track_z, l_mass, way,95,99);
5696 fillTds_ip(TrasanTRK, track_z, kaltrk, l_mass);
5697 // Fill tds
5698 fillTds(TrasanTRK, track, kaltrk, l_mass);
5699 if(ifProdNt12){
5700 if(l_mass==1)residual(track_z);
5701 }
5702 }
5703 } // end of //end of if (!(i_front<0))
5704
5705
5706 // Refit with an enhancement of the error matrix at Mdc level :
5707 if (enhance_) {
5708
5709 HepPoint3D x_first(0, 0, 0);
5710 HepVector a_first(kaltrk->getFHelix());
5711 HepSymMatrix ea_first(kaltrk->getFError());
5712 HepVector fac(5);
5713 fac[0]=fac_h1_; fac[1]=fac_h2_; fac[2]=fac_h3_; fac[3]=fac_h4_; fac[4]=fac_h5_;
5714 for(int i = 0; i < 5; i++)
5715 for(int j = 0; j <= i; j++)
5716 ea_first[i][j] = fac[i]*fac[j]*ea_first[i][j];
5717 KalFitTrack track(x_first, a_first, ea_first, 2, 0, 0);
5718 }
5719
5720 // Backward filter :
5721 KalFitTrack track_back(track_lead);
5722 if (debug_ == 4) {
5723 cout << " Backward fitting flag:" << back_<< endl;
5724 cout << "track_back pivot " << track_back.pivot()
5725 << " track_lead kappa " << track_lead.a()[2]
5726 <<endl;
5727 }
5728
5729 if (back_ && track_lead.a()[2] != 0 &&
5730 1/fabs(track_lead.a()[2]) > pT_) {
5731 track_back.HitsMdc(track_lead.HitsMdc());
5732
5734 double p_kaon(0), p_proton(0);
5735 if (!(kaltrk->getStat(0,3))) {
5736 p_kaon = 1 / fabs(kaltrk->getZHelixK()[2]) *
5737 sqrt(1 + kaltrk->getZHelixK()[4]*kaltrk->getZHelixK()[4]);
5738 track_back.p_kaon(p_kaon);
5739 } else {
5740 p_kaon = 1 / fabs(track_back.a()[2]) *
5741 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
5742 track_back.p_kaon(p_kaon);
5743 }
5744 if (!(kaltrk->getStat(0,4))) {
5745 p_proton = 1 / fabs(kaltrk->getZHelixP()[2]) *
5746 sqrt(1 + kaltrk->getZHelixP()[4]*kaltrk->getZHelixP()[4]);
5747 track_back.p_proton(p_proton);
5748 } else {
5749 p_proton = 1 / fabs(track_back.a()[2]) *
5750 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
5751 track_back.p_proton(p_proton);
5752 }
5753 }
5754
5755 if (!(i_back_<0)) {
5756 //cout<<" *** in smoothing process ***"<<endl;
5757 for(int l_mass = 0; l_mass < nmass; l_mass++) {
5758 //cout<<" --- in hypothesis "<<l_mass<<" :"<<endl;
5759 KalFitTrack track_seed(track_back);
5760 track_seed.chgmass(l_mass);
5761 //cout<<"---------------"<<endl;//wangll
5762 //cout<<"smooth track "<<l_mass<<endl;//wangll
5763 //cout<<" pivot :"<<track_seed.pivot()<<endl;//wangll
5764 //cout<<" helix :"<<track_seed.a()<<endl;//wangll
5765
5766 if(useNCGem_>0) Cgem_filter_anal(track_seed, l_mass, -way);
5767 smoother_anal(track_seed, -way);
5768 // if( usage_ == 1) smoother_calib(track_seed, -way);
5769 //cout<<"fillTds_back 1"<<endl;
5770 // fill TDS for backward filter :
5771 fillTds_back(track_seed, kaltrk, TrasanTRK, l_mass, segcol, 1);
5772 //cout<<"nHits: "<<kaltrk->getVecHelixSegs().size()<<endl;
5773 }
5774 } else {
5775 if(useNCGem_>0) Cgem_filter_anal(track_back, lead_, -way);
5776 smoother_anal(track_back, -way);
5777 //smoother_calib(track_back, -way);
5778 // smoother(track_back, -way);
5779 // fill TDS for backward filter :
5780 //cout<<"fillTds_back 2"<<endl;
5781 fillTds_back(track_back, kaltrk, TrasanTRK, lead_, segcol, 1);
5782 }
5783 }
5784
5785 // Take care of the pointers (use lead. hyp results by default)
5786 for(int pid = 0; pid < nmass;
5787 pid++) {
5788 if (pid == lead_) continue;
5789 if (kaltrk->getStat(1,pid))
5790 sameas(kaltrk, pid, lead_);
5791 }
5792
5793
5794 //check: before register into TDS
5795
5796 log << MSG::DEBUG << "registered MDC Kalmantrack:"
5797 << "Track Id: " << kaltrk->getTrackId()
5798 << " Mass of the fit: "<< kaltrk->getMass(2)<< endreq
5799 << "Length of the track: "<< kaltrk->getLength(2)
5800 << " Tof of the track: "<< kaltrk->getTof(2) << endreq
5801 << "Chisq of the fit: "<< kaltrk->getChisq(0,2)
5802 <<" "<< kaltrk->getChisq(1,2) << endreq
5803 << "Ndf of the fit: "<< kaltrk->getNdf(0,2)
5804 <<" "<< kaltrk->getNdf(1,2) << endreq
5805 << "Helix " << kaltrk->getZHelix()[2]
5806 <<endreq;
5807
5808 kalcol->push_back(kaltrk);
5809 track_lead.HitsMdc().clear();
5810}
5811
5812
5814 MdcRec_trk_add& TrasanTRK_add,
5815 KalFitTrack& track_lead,
5816 RecMdcKalTrack* kaltrk,
5817 RecMdcKalTrackCol* kalcol,RecMdcKalHelixSegCol *segcol)
5818{
5819 static int nmass = KalFitTrack::nmass();
5820 int way(1);
5821 MsgStream log(msgSvc(), name());
5822 KalFitTrack track_first(track_lead);
5823 KalFitTrack track_ip(track_lead);
5824
5825 if (debug_ == 4){
5826 cout << "track_first pivot "<<track_first.pivot()<< " helix "<<track_first.a()<<endl;
5827 }
5828 if(usage_==1) innerwall(track_ip, lead_, way);
5829 // Fill Tds
5830 fillTds_ip(TrasanTRK, track_ip, kaltrk, lead_);
5831
5832 if (debug_ == 4) {
5833 cout << "after inner wall, track_ip pivot "<<track_first.pivot()<< " helix "<<track_first.a()<<endl;
5834 }
5835
5836 fillTds_lead(TrasanTRK, track_first, kaltrk, lead_);
5837
5838 // Refit for different mass assumptions :
5839 double pp = track_lead.momentum().mag();
5840
5841 //w if (!KalFitDSSD::cosmic_)
5842 if(!(i_front_<0)){
5843
5844 for(int l_mass = 0, flg = 1; l_mass < nmass;
5845 l_mass++, flg <<= 1) {
5846
5847 if (!(mhyp_ & flg)) continue;
5848 if (l_mass == lead_) continue;
5849
5850 // Check the mom. to decide of the refit with this mass assumption
5851 if ((lead_ != 0 && l_mass==0 && pp > pe_cut_) ||
5852 (lead_ != 1 && l_mass==1 && pp > pmu_cut_) ||
5853 (lead_ != 2 && l_mass==2 && pp > ppi_cut_) ||
5854 (lead_ != 3 && l_mass==3 && pp > pk_cut_) ||
5855 (lead_ != 4 && l_mass==4 && pp > pp_cut_))
5856 continue;
5857
5858 if(debug_ == 4) {
5859 cout<<"complete_track..REFIT ASSUMPION " << l_mass << endl;
5860 }
5861
5862 // Initialisation :
5863 double chiSq = 0;
5864 int nhits = 0;
5865
5866 // Initialisation : (x, a, ea)
5867 HepPoint3D x_trasan(TrasanTRK.pivot[0],
5868 TrasanTRK.pivot[1],
5869 TrasanTRK.pivot[2]);
5870
5871 HepVector a_trasan(5);
5872 for(int i = 0; i < 5; i++){
5873 a_trasan[i] = TrasanTRK.helix[i];
5874 }
5875
5876 HepSymMatrix ea_trasan(5);
5877 for(int i = 0, k = 0; i < 5; i++) {
5878 for(int j = 0; j <= i; j++) {
5879 ea_trasan[i][j] = matrixg_*TrasanTRK.error[k++];
5880 ea_trasan[j][i] = ea_trasan[i][j];
5881 }
5882 }
5883
5884 KalFitTrack track(x_trasan,a_trasan, ea_trasan, l_mass, chiSq, nhits);
5885 track.HitsMdc(track_lead.HitsMdc());
5886
5887 double fiTerm = TrasanTRK.fiTerm;
5888 track.pivot(track.x(fiTerm));
5889
5890 HepSymMatrix Eakal(5,0);
5891
5892 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
5893 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5894 choice_ = 6;
5895 }
5896
5897 init_matrix(choice_, TrasanTRK, Eakal);
5898
5899 filter_fwd_calib(track, l_mass, way, Eakal);
5900
5901 KalFitTrack track_z(track);
5902 ///fill tds with results got at (0,0,0)
5903 innerwall(track_z, l_mass, way);
5904 fillTds_ip(TrasanTRK, track_z, kaltrk, l_mass);
5905 // Fill tds
5906 fillTds(TrasanTRK, track, kaltrk, l_mass);
5907 }
5908 } //end of if (!(i_front<0))
5909
5910 // Refit with an enhancement of the error matrix at Mdc level :
5911
5912 if (enhance_) {
5913 HepPoint3D x_first(0, 0, 0);
5914 HepVector a_first(kaltrk->getFHelix());
5915 HepSymMatrix ea_first(kaltrk->getFError());
5916 HepVector fac(5);
5917 fac[0]=fac_h1_; fac[1]=fac_h2_; fac[2]=fac_h3_; fac[3]=fac_h4_; fac[4]=fac_h5_;
5918
5919 for(int i = 0; i < 5; i++)
5920 for(int j = 0; j <= i; j++)
5921 ea_first[i][j] = fac[i]*fac[j]*ea_first[i][j];
5922 KalFitTrack track(x_first, a_first, ea_first, 2, 0, 0);
5923 }
5924
5925 // Backward filter
5926 // Attention, the initial error matrix of track_back is the error matrix
5927 // that after filter_fwd_calib(...) course of track_lead. So one thing need
5928 // more consideration that how to chose the inital error matrix of this smoother,
5929 // to put it by hand or use the error matrix after filter_fwd_calib. I think
5930 // it should be to refer R.G.Brown's book.
5931
5932 KalFitTrack track_back(track_lead);
5933
5934 //track_back(track);
5935
5936
5937 if (debug_ == 4) {
5938 cout << " Backward fitting flag:" << back_<< endl;
5939 cout << "track_back pivot " << track_back.pivot()
5940 << " track_lead kappa " << track_lead.a()[2]
5941 <<endl;
5942 }
5943
5944 if (back_ && track_lead.a()[2] != 0 &&
5945 1/fabs(track_lead.a()[2]) > pT_) {
5946 track_back.HitsMdc(track_lead.HitsMdc());
5947
5949
5950 double p_kaon(0), p_proton(0);
5951
5952 if (!(kaltrk->getStat(0,3))) {
5953 p_kaon = 1 / fabs(kaltrk->getZHelixK()[2]) *
5954 sqrt(1 + kaltrk->getZHelixK()[4]*kaltrk->getZHelixK()[4]);
5955 track_back.p_kaon(p_kaon);
5956 } else {
5957 p_kaon = 1 / fabs(track_back.a()[2]) *
5958 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
5959 track_back.p_kaon(p_kaon);
5960 }
5961 if (!(kaltrk->getStat(0,4))) {
5962 p_proton = 1 / fabs(kaltrk->getZHelixP()[2]) *
5963 sqrt(1 + kaltrk->getZHelixP()[4]*kaltrk->getZHelixP()[4]);
5964 track_back.p_proton(p_proton);
5965 } else {
5966 p_proton = 1 / fabs(track_back.a()[2]) *
5967 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
5968 track_back.p_proton(p_proton);
5969 }
5970
5971 }
5972
5973
5974 if (!(i_back_<0)) {
5975 for(int l_mass = 0; l_mass < nmass; l_mass++) {
5976 KalFitTrack track_seed(track_back);
5977 track_seed.chgmass(l_mass);
5978 smoother_calib(track_seed, -way);
5979 // fill TDS for backward filter :
5980 fillTds_back(track_seed, kaltrk, TrasanTRK, l_mass,segcol);
5981 }
5982 } else {
5983
5984 smoother_calib(track_back, -way);
5985 // fill TDS for backward filter , for leading particle hypothesis :
5986 fillTds_back(track_back, kaltrk, TrasanTRK, lead_,segcol);
5987 // fillTds_helixsegs(track_back,TrasanTRK);
5988 }
5989 }
5990
5991 /*
5992 // Take care of the pointers (use lead. hyp results by default)
5993 for(int pid = 0; pid < nmass;
5994 pid++) {
5995 if (pid == lead_) continue;
5996 if (kaltrk->getStat(1,pid))
5997 sameas(kaltrk, pid, lead_);
5998 }
5999 */
6000
6001 //check: before register into TDS
6002
6003 log << MSG::DEBUG << "registered MDC Kalmantrack:"
6004 << "Track Id: " << kaltrk->getTrackId()
6005 << " Mass of the fit: "<< kaltrk->getMass(2)<< endreq
6006 << "Length of the track: "<< kaltrk->getLength(2)
6007 << " Tof of the track: "<< kaltrk->getTof(2) << endreq
6008 << "Chisq of the fit: "<< kaltrk->getChisq(0,2)
6009 <<" "<< kaltrk->getChisq(1,2) << endreq
6010 << "Ndf of the fit: "<< kaltrk->getNdf(0,2)
6011 <<" "<< kaltrk->getNdf(1,2) << endreq
6012 << "Helix " << kaltrk->getZHelix()[2]
6013 <<endreq;
6014
6015 kalcol->push_back(kaltrk);
6016 track_lead.HitsMdc().clear();
6017 track_back.HelixSegs().clear();
6018 // ??ATTENTION!! should track_back.HelixSegs() be cleared ??
6019}
6020
6021
6022void KalFitAlg::init_matrix(MdcRec_trk& trk, HepSymMatrix& Eakal )
6023{
6024 for ( int i=0; i<5; i++) {
6025 for( int j = 1; j<i+2;j++) {
6026 Eakal(i+1,j) = matrixg_*(trk.error[i*(i+1)/2+j-1]);
6027 Eakal(j,i+1) = Eakal(i+1,j);
6028 }
6029 }
6030
6031 if (debug_ == 4) cout<<"initialised Ea.. "<<Eakal<<endl;
6032}
6033
6034
6035
6036void KalFitAlg::init_matrix(int k, MdcRec_trk& trk, HepSymMatrix& Eakal )
6037{
6038 if(0==k){
6039 for ( int i=0; i<5; i++) {
6040 for( int j = 1; j<i+2;j++) {
6041 Eakal(i+1,j) = matrixg_*(trk.error[i*(i+1)/2+j-1]);
6042 Eakal(j,i+1) = Eakal(i+1,j);
6043 }
6044 Eakal(1,1) = Eakal(1,1)* gain1_;
6045 Eakal(2,2) = Eakal(2,2)* gain2_;
6046 Eakal(3,3) = Eakal(3,3)* gain3_;
6047 Eakal(4,4) = Eakal(4,4)* gain4_;
6048 Eakal(5,5) = Eakal(5,5)* gain5_;
6049 }
6050 }
6051 // HepSymMatrix ea_temp(5);
6052 // for(int i = 0, k = 0; i < 5; i++) {
6053 // for(int j = 0; j <= i; j++) {
6054 // ea_temp[i][j] = matrixg_*trk.error[k++];
6055 // ea_temp[j][i] = ea_temp[i][j];
6056 // }
6057 // }
6058
6059 if(1==k){
6060 Eakal(1,1) = .2;
6061 Eakal(2,2) = .001;
6062 Eakal(3,3) = 1.0;
6063 Eakal(4,4) = 10.0;
6064 Eakal(5,5) = 0.002;
6065 }
6066
6067 if(2==k){
6068 Eakal(1,1) = .2;
6069 Eakal(2,2) = 0.1;
6070 Eakal(3,3) = 1.0;
6071 Eakal(4,4) = 25.0;
6072 Eakal(5,5) = 0.10;
6073 }
6074
6075
6076 if(3==k){
6077 Eakal(1,1) = .2;
6078 Eakal(2,2) = .001;
6079 Eakal(3,3) = 1.0;
6080 Eakal(4,4) = 25.0;
6081 Eakal(5,5) = 0.10;
6082 }
6083
6084 if(4==k){
6085 Eakal(1,1) = .2;
6086 Eakal(2,2) = .01;
6087 Eakal(3,3) = 0.01;
6088 Eakal(4,4) = 1.;
6089 Eakal(5,5) = .01;
6090 }
6091
6092 if(5==k) {
6093 Eakal(1,1) = 2.;
6094 Eakal(2,2) = 0.1;
6095 Eakal(3,3) = 1.;
6096 Eakal(4,4) = 20.;
6097 Eakal(5,5) = 0.1;
6098 }
6099
6100 if(6==k) {
6101 Eakal(1,1) = 0.01;
6102 Eakal(2,2) = 0.01;
6103 Eakal(3,3) = 0.01;
6104 Eakal(4,4) = 100.;
6105 Eakal(5,5) = 0.5;
6106 }
6107
6108 if(k!=0){
6109 Eakal(3,3) = 0.2;
6110 Eakal(1,1) = 1;
6111 Eakal(4,4) = 1;
6112 }
6113
6114 if (debug_ == 4) cout<<"initialised Eakal.. "<<Eakal<<endl;
6115}
6116
6117
6118
6119
6120void KalFitAlg::start_seed(KalFitTrack& track, int lead_, int way, MdcRec_trk& TrasanTRK)
6121{
6122 if (debug_ == 4)
6123 cout << "start_seed begin... " << std::endl;
6124 // keep initial helix parameters
6125 Hep3Vector x_init(track.pivot());
6126 HepSymMatrix Ea_init(5,0);
6127 Ea_init = track.Ea();
6128 HepVector a_init(5);
6129 a_init = track.a();
6130
6131 // LR assumption :
6132 unsigned int nhit_included(10);
6133 int LR[8][3] = {
6134 {1,1,1},
6135 {1,1,-1},
6136 {1,-1,1},
6137 {1,-1,-1},
6138 {-1,1,1},
6139 {-1,1,-1},
6140 {-1,-1,1},
6141 {-1,-1,-1}
6142 };
6143
6144 unsigned int nhit = track.HitsMdc().size();
6145 double chi2_min(DBL_MAX);
6146 int i_min(-1);
6147 for (int ktrial = 0; ktrial < 8; ktrial++) {
6148
6149 // Come back to trasan seed :
6150 track.pivot(x_init);
6151 track.a(a_init);
6152 track.Ea(Ea_init);
6153
6154 track.chiSq(0);
6155 track.chiSq_back(0);
6156 track.nchits(0);
6157 track.nster(0);
6158 track.ndf_back(0);
6159
6160 HepSymMatrix Eakal(5,0);
6161
6162 init_matrix(choice_,TrasanTRK, Eakal);
6163 // initialize the Mdc hits :
6164 for( unsigned i=0 ; i < nhit; i++ ){
6165 KalFitHitMdc& HitMdc = track.HitMdc(i);
6166 int lr_decision(0);
6167 if (i<3) lr_decision = LR[ktrial][i];
6168 HitMdc.LR(lr_decision);
6169 if (i<nhit_included)
6170 HitMdc.chi2(0);
6171 else
6172 HitMdc.chi2(-1);
6173 }
6174 // Mdc fit the ... first hits :
6175
6176 if(usage_==0) filter_fwd_anal(track, lead_, way, Eakal);
6177 way=999;
6178 if(usage_>0) filter_fwd_calib(track, lead_, way, Eakal);
6179
6180 // Check the chi2
6181 if (debug_ == 4)
6182 cout << "---- Result for " << ktrial << " case : chi2 = " << track.chiSq()
6183 << ", nhits included = " << track.nchits() << " for nhits available = "
6184 << nhit << std::endl;
6185
6186 if (track.chiSq() < chi2_min &&
6187 (track.nchits() == nhit_included || track.nchits() == nhit)){
6188 chi2_min = track.chiSq();
6189 i_min = ktrial;
6190 }
6191 }
6192
6193 // Initialize to the best solution :
6194 if (debug_ == 4)
6195 cout << "*** i_min = " << i_min << " with a chi2 = " << chi2_min << std::endl;
6196
6197 for( unsigned i=0 ; i < nhit; i++ ){
6198 KalFitHitMdc& HitMdc = track.HitMdc(i);
6199 int lr_decision(0);
6200 if (i_min >= 0 && i < 3)
6201 lr_decision = LR[i_min][i];
6202 HitMdc.LR(lr_decision);
6203 HitMdc.chi2(0);
6204 HitMdc.chi2_back(0);
6205 }
6206 track.pivot(x_init);
6207 track.a(a_init);
6208 track.Ea(Ea_init);
6209 track.chiSq(0);
6210 track.chiSq_back(0);
6211 track.nchits(0);
6212 track.nster(0);
6213 track.ndf_back(0);
6214
6215 // For debugging purpose :
6216 if (debug_ == 4) {
6217 for( unsigned i=0 ; i < 3; i++ ){
6218 KalFitHitMdc& HitMdc = track.HitMdc(i);
6219 cout << " LR(" << i << ") = " << HitMdc.LR()
6220 << ", stereo = " << HitMdc.wire().stereo()
6221 << ", layer = " << HitMdc.wire().layer().layerId() << std::endl;
6222 }
6223 }
6224}
6225
6226// this function is added to clear tables after processing each event
6227// to avoid memory leak,because of the usage of MdcTables etc.
6228// Apr. 2005
6230
6231 if(debug_ == 4) cout<<"Begining to clear Tables ...."<<endl;
6232 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
6233 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
6234 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
6235 vector<MdcRec_trk>::iterator tit=mdcMgr->begin();
6236 for( ; tit != mdcMgr->end(); tit++) {
6237 vector<MdcRec_wirhit*>::iterator vit= tit->hitcol.begin() ;
6238 for(; vit != tit->hitcol.end(); vit++) {
6239 delete (*vit);
6240 }
6241 }
6242
6243 mdcMgr->clear();
6244 mdc_addMgr->clear();
6245 whMgr->clear();
6246
6247 // delete mdcMgr;
6248 // delete mdc_addMgr;
6249 // delete whMgr;
6250 // mdcMgr = 0;
6251 // mdc_addMgr = 0;
6252 // whMgr = 0;
6253
6254}
6255
6256bool KalFitAlg::order_rechits(const SmartRef<RecMdcHit>& m1, const SmartRef<RecMdcHit>& m2) {
6257 return MdcID::layer(m1->getMdcId()) > MdcID::layer(m2->getMdcId());
6258}
6259
6260/*void KalFitAlg::makeGemHitsCol()
6261 {
6262 bool giveCout=true;
6263
6264 for(int i=0; i<4; i++) myGemHitCol[i].clear();
6265
6266 SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
6267 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
6268
6269 int nHits, nDigi;
6270 unsigned int stripIndx, isVStrip;
6271 int layer;
6272 double x, y, z, r, phi;
6273
6274 nHits = mdcMcHitCol->size();
6275 nDigi = mdcDigiCol->size();
6276
6277//cout<<__FUNCTION__<<":: nHits = "<<nHits<<endl;
6278
6279Rndm::Numbers gaussRPhi(randSvc(), Rndm::Gauss(0.,myRphiResGem));
6280Rndm::Numbers gaussZ(randSvc(), Rndm::Gauss(0.,myZResGem));
6281
6282MdcMcHitCol::const_iterator it = mdcMcHitCol->begin();
6283
6284if(giveCout) cout<<endl<<endl<<" ------------- Mdc MC hits: ------------"<<endl<<endl;
6285
6286for(;it!=mdcMcHitCol->end(); it++)
6287{
6288Identifier id= (*it)->identify();
6289layer = MdcID::layer(id);
6290//if(layer>(useNCGem_-1)) continue;
6291if(layer>4) continue;
6292stripIndx = (*it)->getDriftDistance();
6293isVStrip = (*it)->getPositionFlag();
6294x = ((*it)->getPositionX())*0.1; // mm->cm
6295y = ((*it)->getPositionY())*0.1; // mm->cm
6296z = ((*it)->getPositionZ())*0.1; // mm->cm
6297r=sqrt(x*x+y*y);
6298phi=atan2(y,x);
6299if(giveCout) {
6300cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isVStrip<<endl;
6301cout<<" true x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
6302}
6303if(layer<4&&myGemHitCol[layer].empty())
6304{
6305if(giveCout) cout<<"myGemHitCol["<<layer<<"] is empty"<<endl;
6306double phiResam = phi+gaussRPhi()/r;
6307while(phi>M_PI) phi-=2.0*M_PI;
6308while(phi<-M_PI) phi+=2.0*M_PI;
6309double zResam = z+gaussZ();
6310KalFitGemHit aKalFitGemHit(phiResam,zResam,r,myRphiResGem,myZResGem);
6311if(giveCout) {
6312cout<<" resam x, y, z, phi, r = "<<x<<", "<<y<<", "<<zResam<<", "<<phiResam<<", "<<r<<endl;
6313cout<<" Dphi, Dz = "<<phiResam-phi<<", "<<zResam-z<<endl;
6314cout<<" nSigPhi, nSigZ = "<<(phiResam-phi)*r/myRphiResGem<<", "<<(zResam-z)/myZResGem<<endl;
6315}
6316if(phi>M_PI||phi<-M_PI) cout<<__FUNCTION__<<": phi = "<<phi<<endl;
6317myGemHitCol[layer].push_back(aKalFitGemHit);
6318}
6319}
6320
6321//cout<<endl<<endl<<" ------------- Mdc digi: ------------"<<endl<<endl;
6322
6323MdcDigiCol::const_iterator it_digi = mdcDigiCol->begin();
6324for(;it_digi!=mdcDigiCol->end(); it_digi++)
6325{
6326Identifier id = (*it_digi)->identify();
6327layer = MdcID::layer(id);
6328if(layer>4) continue;
6329double stripId = RawDataUtil::MdcTime((*it_digi)->getTimeChannel());
6330double isV = RawDataUtil::MdcCharge((*it_digi)->getChargeChannel());
6331//cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripId<<", "<<isV<<endl;
6332stripIndx=stripId+0.5;
6333//cout<<" stripIndx = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isV<<endl;
6334}
6335
6336///
6337// --- print out GEM hits
6338if(giveCout) cout<<endl<<"------- GEM hits: --------"<<endl;
6339//for(int i=0; i<useNCGem_; i++)
6340for(int i=0; i<4; i++)
6341{
6342 if(giveCout) cout<<"### layer "<<i<<endl;
6343 //int nhits = myGemHitCol[i].size();
6344 KalFitGemHitCol::const_iterator it_GemHit = (myGemHitCol[i]).begin();
6345 for(int j=0; it_GemHit!=(myGemHitCol[i]).end(); it_GemHit++, j++)
6346 {
6347 if(giveCout) cout<<" hit "<<(j+1)<<": phi, z, r = "<<it_GemHit->getPhi()<<", "<<it_GemHit->getZ()<<", "<<it_GemHit->getR()<<endl;
6348 if(ntuple_&1) m_rGem[i] = it_GemHit->getR();
6349 }
6350}
6351///
6352}
6353*/
6354
6355
6357{
6358 double rMaxInnerWall=6.42005+0.00495;
6359 if(useNCGem_>1) { // GEM mode
6360 //rMaxInnerWall=m_CGEM.end()->radius();
6361 //rMaxInnerWall=16.7;
6362 rMaxInnerWall=m_innerWall[0].radius();
6363 }
6364 else { // MDC mode
6365 rMaxInnerWall=_BesKalmanFitWalls[0].radius();
6366 }
6367 double dPhiToInnerWall = track.intersect_cylinder(rMaxInnerWall);
6368 HepPoint3D posAtInnerWall = track.x(dPhiToInnerWall);
6369 double pathToInnerWall;
6370 track.pivot_numf(posAtInnerWall, pathToInnerWall);
6371 //cout<<"__FUNCTION__: rMaxInnerWall = "<<rMaxInnerWall<<endl;
6372 //cout<<"posAtInnerWall, pathToInnerWall = "<<posAtInnerWall<<", "<<pathToInnerWall<<endl;
6373 if(pathToInnerWall>0)
6374 {
6375 if(muls_) track.ms(pathToInnerWall, _BesKalmanFitMaterials[0], way);
6376 if(loss_) track.eloss(pathToInnerWall, _BesKalmanFitMaterials[0], way);
6377 }
6378 if(useNCGem_>0) m_innerWall[0].updateTrack(track, way);
6379
6380}
6381
6382
6383/*void KalFitAlg::fitGemHits(KalFitTrack& track, int hypo, int way)
6384 {
6385 bool printOut=false;
6386 if(printOut) {
6387 cout<<endl;
6388 cout<<"--------------------------------------"<<endl;
6389 cout<<"start GEM Kalman fit: hypo = "<<hypo<<endl;
6390 cout<<"--------------------------------------"<<endl;
6391 }
6392//int iLayer=useNCGem_-1;
6393int nLayer=4;
6394switch(useNCGem_)
6395{
6396case 0: nLayer=0; break;
6397case 1: nLayer=1; break;
6398case 2: nLayer=2; break;
6399case 3:
6400case 13:
6401nLayer=3; break;
6402case 4:
6403case 14:
6404nLayer=4; break;
6405}
6406int iLayer=nLayer-1;
6407//for(int iLayer=3; iLayer>=0; iLayer--)
6408int nGemLayers=m_CGEM.size();
6409double rGem, rmax, rmin;
6410for(int iGem=nGemLayers-1; iGem>=0; iGem--)
6411//for(int i=nGemLayers-1; i>=0; i--)
6412{
6413//if(way) iGem=i;
6414if(printOut) cout<<"rGem = "<<m_CGEM[iGem].radius()<<endl;
6415if(iLayer>=0) rGem=(myGemHitCol[iLayer].begin())->getR();
6416rmax = m_CGEM[iGem].radius();
6417rmin = m_CGEM[iGem].rmin();
6418if(iLayer>=0 && rGem<rmax && rGem>rmin)
6419{
6420if(myUseGemPos3D) {
6421if(printOut) {
6422cout<<"in GEM 3D coorinate fit "<<endl;
6423cout<<"iLayer = "<<iLayer<<endl;
6424cout<<"rGemLayerMax = "<<m_CGEM[iGem].radius()<<endl;
6425}
6426rmax=m_CGEM[iGem].radius();
6427double dPhiToGem = track.intersect_cylinder(rmax);
6428HepPoint3D posEstiAtGem = track.x(dPhiToGem);
6429track.pivot_numf(posEstiAtGem);
6430int nHits=myGemHitCol[iLayer].size();
6431if(nHits!=1) continue;
6432//rGem=(myGemHitCol[iLayer].begin())->getR();
6433double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
6434double zGem=(myGemHitCol[iLayer].begin())->getZ();
6435HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos3D();
6436if(printOut) cout<<"v_measu,rGem = "<<v_measu<<", "<<rGem<<endl;
6437dPhiToGem = track.intersect_cylinder(rGem);
6438posEstiAtGem = track.x(dPhiToGem);
6439double x0=posEstiAtGem.x();
6440double y0=posEstiAtGem.y();
6441double z0=posEstiAtGem.z();
6442double pathInGem;
6443track.pivot_numf(posEstiAtGem, pathInGem);
6444if(pathInGem>0)
6445{
6446if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
6447if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
6448}
6449double rGemEsti=posEstiAtGem.perp();
6450double phiGemEsti=posEstiAtGem.phi();
6451double zGemEsti=posEstiAtGem.z();
6452HepVector v_estim(3,0);
6453v_estim(1)=x0;
6454v_estim(2)=y0;
6455v_estim(3)=z0;
6456if(printOut) {
6457 cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
6458 cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
6459}
6460const HepSymMatrix& Ea = track.Ea();
6461HepVector v_a = track.a();
6462double phi0=v_a(2);
6463if(printOut) {
6464 cout<<"v_a = "<<v_a<<endl;
6465 cout<<"phi0 = "<<phi0<<endl;
6466}
6467// --- derivative matrix
6468HepMatrix H(3, 5, 0);
6469double c=1.0;
6470if(x0*y0>0.0) c=-1.0;
6471H(1,1)=cos(phi0);
6472H(2,1)=sin(phi0);
6473H(3,4)=1.0;
6474if(printOut) cout<<"H="<<H<<endl;
6475HepMatrix H_T=H.T();
6476if(printOut) cout<<"H_T="<<H_T<<endl;
6477// --- error matrix of Gem hit
6478HepSymMatrix V=(myGemHitCol[iLayer].begin())->getErrMat3D();
6479if(printOut) cout<<"V="<<V<<endl;
6480HepMatrix HEa=H*Ea;
6481HepMatrix HEaH_T=HEa*H_T;
6482if(printOut) cout<<"HEaH_T="<<HEaH_T<<endl;
6483int ierr=-1;
6484HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
6485if(printOut) cout<<"Vinv="<<Vinv<<endl;
6486if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
6487// --- gain matrix
6488HepMatrix K=Ea*H_T*Vinv;
6489if(printOut) cout<<"K="<<K<<endl;
6490// --- new error matrix
6491HepSymMatrix EaNew(5,0);
6492EaNew.assign(Ea-K*H*Ea);
6493// --- diff
6494HepVector v_diff=v_measu-v_estim;
6495//double delPhi=v_diff(1);
6496//while(delPhi> M_PI) delPhi-=2.0*M_PI;
6497//while(delPhi<-M_PI) delPhi+=2.0*M_PI;
6498//v_diff(1)=delPhi;
6499if(printOut) cout<<"v_diff = "<<v_diff<<endl;
6500// --- new parameters
6501HepVector aNew=v_a+K*v_diff;
6502// --- new v_estim
6503KalFitTrack track_test(posEstiAtGem,aNew,EaNew,track.mass(),0.0,track.nchits());
6504double dPhiToGem_New = track_test.intersect_cylinder(rGem);
6505HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
6506double phiGemEsti_new=posEstiAtGem_new.phi();
6507double zGemEsti_new=posEstiAtGem_new.z();
6508double x0_new = posEstiAtGem_new.x();
6509double y0_new = posEstiAtGem_new.y();
6510double z0_new = posEstiAtGem_new.z();
6511HepVector v_estim_new(3,0);
6512v_estim_new(1)=x0_new;
6513v_estim_new(2)=y0_new;
6514v_estim_new(3)=z0_new;
6515if(printOut) cout<<"v_estim_new = "<<v_estim_new<<endl;
6516// --- diff between measurement and updated estimation
6517v_diff=v_measu-v_estim_new;
6518if(printOut) cout<<"v_diff_new = "<<v_diff<<endl;
6519// --- new derivative matrix
6520track_test.pivot_numf(posEstiAtGem_new, pathInGem);
6521HepVector v_a_new = track_test.a();
6522HepSymMatrix Ea_new = track_test.Ea();
6523double phi0_new = v_a_new(2);
6524HepMatrix H_new(3, 5, 0);
6525H_new(1,1)=cos(phi0_new);
6526H_new(2,1)=sin(phi0_new);
6527H_new(3,4)=1.0;
6528HepMatrix H_new_T=H_new.T();
6529// --- R mactrix
6530if(printOut) cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
6531HepSymMatrix R(3,0);
6532R.assign(V-H_new*Ea_new*H_new_T);
6533// --- Chi^2 added
6534HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
6535if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
6536if(printOut) cout<<"v_dChi2 = "<<v_dChi2<<endl;
6537double dChi2=v_dChi2(1);
6538if(ntuple_&1 && hypo==1) {
6539 m_chi2Gem[iLayer]=dChi2;
6540 m_phiGemExp[iLayer]=phiGemEsti;
6541 m_phiGemHit[iLayer]=v_measu(1);
6542 m_zGemExp[iLayer]=zGemEsti;
6543 m_zGemHit[iLayer]=v_measu(2);
6544}
6545// --- comparison
6546//
6547if(printOut) {
6548 cout<<"pivot: "<<posEstiAtGem<<endl;
6549 cout<<"new pivot: "<<posEstiAtGem_new<<endl;
6550 cout<<"a: "<<v_a<<endl;
6551 cout<<"new a: "<<v_a_new<<endl;
6552 cout<<"Ea: "<<Ea<<endl;
6553 cout<<"new Ea: "<<Ea_new<<endl;
6554 cout<<"dchi2= "<<dChi2<<endl;
6555}
6556//
6557// --- update KalFitTrack
6558if(iLayer>=0) track.set(posEstiAtGem_new,v_a_new,Ea_new);
6559//track.a(aNew);
6560//track.Ea(EaNew);
6561iLayer--;
6562// --- move track to rmin of this layer
6563rmin = m_CGEM[iGem].rmin();
6564dPhiToGem = track.intersect_cylinder(rmin);
6565posEstiAtGem = track.x(dPhiToGem);
6566track.pivot_numf(posEstiAtGem, pathInGem);
6567if(pathInGem>0)
6568{
6569 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
6570 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
6571}
6572}
6573else {
6574 if(printOut) {
6575 cout<<"iLayer = "<<iLayer<<endl;
6576 cout<<"rGemLayerMax = "<<m_CGEM[iGem].radius()<<endl;
6577 }
6578 rmax=m_CGEM[iGem].radius();
6579 double dPhiToGem = track.intersect_cylinder(rmax);
6580 HepPoint3D posEstiAtGem = track.x(dPhiToGem);
6581 track.pivot_numf(posEstiAtGem);
6582 int nHits=myGemHitCol[iLayer].size();
6583 if(nHits!=1) continue;
6584 //rGem=(myGemHitCol[iLayer].begin())->getR();
6585 double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
6586 double zGem=(myGemHitCol[iLayer].begin())->getZ();
6587 HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos();
6588 if(printOut) cout<<"v_measu,rGem = "<<v_measu<<", "<<rGem<<endl;
6589 dPhiToGem = track.intersect_cylinder(rGem);
6590 posEstiAtGem = track.x(dPhiToGem);
6591 double x0=posEstiAtGem.x();
6592 double y0=posEstiAtGem.y();
6593 double z0=posEstiAtGem.z();
6594 double pathInGem;
6595 track.pivot_numf(posEstiAtGem, pathInGem);
6596 if(pathInGem>0)
6597 {
6598 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
6599 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
6600 }
6601 double rGemEsti=posEstiAtGem.perp();
6602 double phiGemEsti=posEstiAtGem.phi();
6603 double zGemEsti=posEstiAtGem.z();
6604 HepVector v_estim(2,0);
6605 v_estim(1)=phiGemEsti;
6606 v_estim(2)=zGemEsti;
6607 if(printOut) {
6608 cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
6609 cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
6610 }
6611 const HepSymMatrix& Ea = track.Ea();
6612 HepVector v_a = track.a();
6613 double phi0=v_a(2);
6614 if(printOut) {
6615 cout<<"v_a = "<<v_a<<endl;
6616 cout<<"phi0 = "<<phi0<<endl;
6617 }
6618 // --- derivative matrix
6619 HepMatrix H(2, 5, 0);
6620 double c=1.0;
6621 //if(x0*y0>0.0&&useNCGem_==3&&iLayer==1) c=-1.0;
6622 //if(x0*y0>0.0) c=-1.0;
6623 //H(1,1)=c*(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
6624 H(1,1)=(x0*sin(phi0)-y0*cos(phi0))/(x0*x0+y0*y0);
6625 H(2,4)=1.0;
6626 if(printOut) cout<<"H="<<H<<endl;
6627 HepMatrix H_T=H.T();
6628 if(printOut) cout<<"H_T="<<H_T<<endl;
6629 // --- error matrix of Gem hit
6630 HepSymMatrix V=(myGemHitCol[iLayer].begin())->getErrMat();
6631 if(printOut) cout<<"V="<<V<<endl;
6632 HepMatrix HEa=H*Ea;
6633 HepMatrix HEaH_T=HEa*H_T;
6634 if(printOut) cout<<"HEaH_T="<<HEaH_T<<endl;
6635 int ierr=-1;
6636 HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
6637 if(printOut) cout<<"Vinv="<<Vinv<<endl;
6638 if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
6639 // --- gain matrix
6640 HepMatrix K=Ea*H_T*Vinv;
6641 if(printOut) cout<<"K="<<K<<endl;
6642 // --- new error matrix
6643 HepSymMatrix EaNew(5,0);
6644 EaNew.assign(Ea-K*H*Ea);
6645 // --- diff
6646 HepVector v_diff=v_measu-v_estim;
6647 double delPhi=v_diff(1);
6648 while(delPhi> M_PI) delPhi-=2.0*M_PI;
6649 while(delPhi<-M_PI) delPhi+=2.0*M_PI;
6650 v_diff(1)=delPhi;
6651 if(printOut) cout<<"v_diff = "<<v_diff<<endl;
6652 // --- new parameters
6653 HepVector aNew=v_a+K*v_diff;
6654 // --- new v_estim
6655 KalFitTrack track_test(posEstiAtGem,aNew,EaNew,track.mass(),0.0,track.nchits());
6656 double dPhiToGem_New = track_test.intersect_cylinder(rGem);
6657 HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
6658 double phiGemEsti_new=posEstiAtGem_new.phi();
6659 double zGemEsti_new=posEstiAtGem_new.z();
6660 double x0_new = posEstiAtGem_new.x();
6661 double y0_new = posEstiAtGem_new.y();
6662 HepVector v_estim_new(2,0);
6663 v_estim_new(1)=phiGemEsti_new;
6664 v_estim_new(2)=zGemEsti_new;
6665 if(printOut) cout<<"v_estim_new = "<<v_estim_new<<endl;
6666 // --- diff between measurement and updated estimation
6667 v_diff=v_measu-v_estim_new;
6668 delPhi=v_diff(1);
6669 while(delPhi> M_PI) delPhi-=2.0*M_PI;
6670 while(delPhi<-M_PI) delPhi+=2.0*M_PI;
6671 if(printOut) cout<<"v_diff_new = "<<v_diff<<endl;
6672 // --- new derivative matrix
6673 track_test.pivot_numf(posEstiAtGem_new, pathInGem);
6674 HepVector v_a_new = track_test.a();
6675 HepSymMatrix Ea_new = track_test.Ea();
6676 double phi0_new = v_a_new(2);
6677 HepMatrix H_new(2, 5, 0);
6678 c=1.0;
6679 //if(x0_new*y0_new>0.0&&useNCGem_==3&&iLayer==1) c=-1.0;
6680 if(x0_new*y0_new>0.0) c=-1.0;
6681 //H_new(1,1)=c*(x0_new*cos(phi0_new)-y0_new*sin(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
6682 H_new(1,1)=(x0_new*sin(phi0_new)-y0_new*cos(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
6683 H_new(2,4)=1.0;
6684 HepMatrix H_new_T=H_new.T();
6685 // --- R mactrix
6686 if(printOut) cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
6687 HepSymMatrix R(2,0);
6688 R.assign(V-H_new*Ea_new*H_new_T);
6689 // --- Chi^2 added
6690 HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
6691 if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
6692 if(printOut) cout<<"v_dChi2 = "<<v_dChi2<<endl;
6693 double dChi2=v_dChi2(1);
6694 if(ntuple_&1 && hypo==1) {
6695 m_chi2Gem[iLayer]=dChi2;
6696 m_phiGemExp[iLayer]=phiGemEsti;
6697 m_phiGemHit[iLayer]=v_measu(1);
6698 m_zGemExp[iLayer]=zGemEsti;
6699 m_zGemHit[iLayer]=v_measu(2);
6700 }
6701 // --- comparison
6702 //
6703 if(printOut) {
6704 cout<<"pivot: "<<posEstiAtGem<<endl;
6705 cout<<"new pivot: "<<posEstiAtGem_new<<endl;
6706 cout<<"a: "<<v_a<<endl;
6707 cout<<"new a: "<<v_a_new<<endl;
6708 cout<<"Ea: "<<Ea<<endl;
6709 cout<<"new Ea: "<<Ea_new<<endl;
6710 cout<<"dchi2= "<<dChi2<<endl;
6711 }
6712 //
6713 // --- update KalFitTrack
6714 if(iLayer>=0) track.set(posEstiAtGem_new,v_a_new,Ea_new);
6715 //track.a(aNew);
6716 //track.Ea(EaNew);
6717 iLayer--;
6718 // --- move track to rmin of this layer
6719 rmin = m_CGEM[iGem].rmin();
6720 dPhiToGem = track.intersect_cylinder(rmin);
6721 posEstiAtGem = track.x(dPhiToGem);
6722 track.pivot_numf(posEstiAtGem, pathInGem);
6723 if(pathInGem>0)
6724 {
6725 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
6726 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
6727 }
6728}
6729}// if hit in this layer
6730else {
6731 m_CGEM[iGem].updateTrack(track, way);
6732}
6733}// loop GEM layers
6734// end of GEM Kalman fit
6735//cout<<"finish GEM part"<<endl;
6736
6737}*/
6739{
6740 for(int i=0; i<3; i++) myGemHitCol[i].clear();
6741
6742 /*SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
6743 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
6744
6745 int nHits, nDigi;
6746 unsigned int stripIndx, isVStrip;
6747 int layer;
6748 double x, y, z, r, phi;
6749
6750 nHits = mdcMcHitCol->size();
6751 nDigi = mdcDigiCol->size();
6752
6753 //cout<<__FUNCTION__<<":: nHits = "<<nHits<<endl;
6754
6755 Rndm::Numbers gaussRPhi(randSvc(), Rndm::Gauss(0.,0.023));
6756 Rndm::Numbers gaussZ(randSvc(), Rndm::Gauss(0.,0.05));
6757
6758 MdcMcHitCol::const_iterator it = mdcMcHitCol->begin();
6759
6760 cout<<endl<<endl<<" ------------- Mdc MC hits: ------------"<<endl<<endl;*/
6761
6762 SmartDataPtr<RecCgemClusterCol> cgemClusterCol(eventSvc(),"/Event/Recon/RecCgemClusterCol");
6763 int layer,sheet;
6764 double phi,v;
6765 RecCgemClusterCol::const_iterator it = cgemClusterCol->begin();
6766 for(;it!=cgemClusterCol->end();it++){
6767 //cout<<"cluster:"<<(*it)->getclusterid()<<" phi:"<<(*it)->getrecphi()<<" z:"<<(*it)->getRecZ()<<endl;
6768 if((*it)->getflag()==2){
6769 layer = (*it)->getlayerid();
6770 sheet = (*it)->getsheetid();
6771 phi = (*it)->getrecphi();
6772 v = (*it)->getrecv();
6773 KalFitGemHit aKalFitGemHit(phi,v,layer,sheet);
6774 myGemHitCol[layer].push_back(aKalFitGemHit);
6775 }
6776 }
6777 if(debug_==4){
6778 cout << "Gem information" << endl;
6779 cout << "first layer " << myGemHitCol[0].size() << endl;
6780 cout << "second layer" << myGemHitCol[1].size() << endl;
6781 cout << "third layer" << myGemHitCol[2].size() << endl;
6782 }
6783 /*
6784 for(;it!=mdcMcHitCol->end(); it++)
6785 {
6786 Identifier id= (*it)->identify();
6787 layer = MdcID::layer(id);
6788 if(layer>7) continue;
6789 stripIndx = (*it)->getDriftDistance();
6790 isVStrip = (*it)->getPositionFlag();
6791 x = ((*it)->getPositionX())*0.1; // mm->cm
6792 y = ((*it)->getPositionY())*0.1; // mm->cm
6793 z = ((*it)->getPositionZ())*0.1; // mm->cm
6794 r=sqrt(x*x+y*y);
6795 phi=atan2(y,x);
6796 cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isVStrip<<endl;
6797 //cout<<" true x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
6798 if(myGemHitCol[layer].empty())
6799 {
6800 //cout<<"myGemHitCol["<<layer<<"] is empty"<<endl;
6801 phi+=gaussRPhi()/r;
6802 while(phi>M_PI) phi-=M_PI2;
6803 while(phi<-M_PI) phi+=M_PI2;
6804 z+=gaussZ();
6805 KalFitGemHit aKalFitGemHit(phi,z,r);
6806 //cout<<" resam x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
6807 myGemHitCol[layer].push_back(aKalFitGemHit);
6808 }
6809 }
6810
6811 cout<<endl<<endl<<" ------------- Mdc digi: ------------"<<endl<<endl;
6812
6813 MdcDigiCol::const_iterator it_digi = mdcDigiCol->begin();
6814 for(;it_digi!=mdcDigiCol->end(); it_digi++)
6815 {
6816 Identifier id = (*it_digi)->identify();
6817 layer = MdcID::layer(id);
6818 if(layer>7) continue;
6819 double stripId = RawDataUtil::MdcTime((*it_digi)->getTimeChannel());
6820 double isV = RawDataUtil::MdcCharge((*it_digi)->getChargeChannel());
6821 cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripId<<", "<<isV<<endl;
6822 stripIndx=stripId+0.5;
6823 cout<<" stripIndx = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isV<<endl;
6824 }
6825 */
6826
6827 // --- print out GEM hits
6828 bool prtGemHits=false;
6829 //bool prtGemHits=true;
6830 if(prtGemHits) cout<<endl<<"------- GEM hits: --------"<<endl;
6831 for(int i=0; i<3; i++)
6832 {
6833 if(prtGemHits) cout<<"### layer "<<i<<endl;
6834 //int nhits = myGemHitCol[i].size();
6835 KalFitGemHitCol::const_iterator it_GemHit = (myGemHitCol[i]).begin();
6836 for(int j=0; it_GemHit!=(myGemHitCol[i]).end(); it_GemHit++, j++)
6837 {
6838 if(prtGemHits) cout<<" hit "<<(j+1)<<": phi, z, r = "<<it_GemHit->getPhi()<<", "<<it_GemHit->getZ()<<", "<<it_GemHit->getR()<<endl;
6839 }
6840 }
6841
6842}
6843void KalFitAlg::fitGemHits(KalFitTrack& track, int hypo, int way)
6844{
6845 {
6846 //cout<<endl;
6847 //cout<<"--------------------------------------"<<endl;
6848 //cout<<"start GEM Kalman fit: hypo = "<<hypo<<endl;
6849 //cout<<"--------------------------------------"<<endl;
6850 // std::vector<double> dchi2_all;
6851 // std::vector<HepPoint3D> posnew;
6852 // std::vector<HepSymMatrix> eanew;
6853 // std::vector<HepVector> anew;
6854 //std::map<int,double> dchi2;
6855 std::map<double,double> esti1_r;
6856 std::map<double,double> esti2_r;
6857 std::map<double,double> esti1_phi;
6858 std::map<double,double> esti2_phi;
6859 std::map<double,double> esti1_z;
6860 std::map<double,double> esti2_z;
6861 std::map<double,double> diff1_phi;
6862 std::map<double,double> diff1_z;
6863 std::map<double,double> diff2_phi;
6864 std::map<double,double> diff2_z;
6865 std::map<double,HepPoint3D> posnew;
6866 std::map<double,HepSymMatrix> eanew;
6867 std::map<double,HepVector> anew;
6868 std::map<double,double> meas_r;
6869 std::map<double,double> meas_phi;
6870 std::map<double,double> meas_z;
6871 std::map<double,double> meas_phierr;
6872 std::map<double,double> esti_phierr;
6873 std::map<double,double> meas_zerr;
6874 std::map<double,double> esti_zerr;
6875 int ii=0;
6876 if(debug_==4){ cout << "wall size" << _BesKalmanFitWalls.size() << endl;}
6877 for(int iLayer=2; iLayer>=0; iLayer--)
6878 {
6879 posnew.clear();
6880 eanew.clear();
6881 anew.clear();
6882 esti1_r.clear();
6883 esti2_r.clear();
6884 esti1_phi.clear();
6885 esti2_phi.clear();
6886 esti1_z.clear();
6887 esti2_z.clear();
6888 diff1_phi.clear();
6889 diff1_z.clear();
6890 diff2_phi.clear();
6891 diff2_z.clear();
6892 meas_r.clear();
6893 meas_phi.clear();
6894 meas_z.clear();
6895 meas_phierr.clear();
6896 meas_zerr.clear();
6897 esti_phierr.clear();
6898 esti_zerr.clear();
6899 //cout<<"iLayer = "<<iLayer<<endl;
6900 int nHits=myGemHitCol[iLayer].size();
6901 //cout << "nhits" << nHits << "in layer" << iLayer << endl;
6902
6903 if (nHits <= 0) continue;
6904 //if(nHits!=1) continue;
6905
6906 vector<KalFitGemHit>::iterator iter;
6907 int ihit=0;
6908 // int ii=0;
6909 //cout <<"track before" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;
6910 innerwall(track,hypo,way,64+iLayer*(-32),88+iLayer*(-32));
6911 KalFitTrack track_start(track);
6912 //cout << "now position" << track_start.pivot().perp() << ","<< track_start.pivot().phi() << "," << track_start.pivot().z() <<endl;
6913 for(iter=myGemHitCol[iLayer].begin();iter!=myGemHitCol[iLayer].end();iter++ )
6914 {
6915 //cout <<"track" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;
6916 track.set(track_start.pivot(),track_start.a(),track_start.Ea());
6917 //cout << "track start" << "pivot=" << track_start.pivot() << "a=" << track_start.a() << "ea=" << track_start.Ea() << endl;
6918 double rGem=(*iter).getR();
6919 double phiGem=(*iter).getPhi();
6920 double zGem=(*iter).getZ();
6921 HepVector v_measu=(*iter).getVecPos();
6922 //cout << "hit" << ihit << "r=" << rGem << "phi=" << phiGem << "z=" << zGem << endl;
6923 // cout << "v_measu= " << v_measu << endl;
6924 /*
6925 double rGem=(myGemHitCol[iLayer].begin())->getR();
6926 double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
6927 double zGem=(myGemHitCol[iLayer].begin())->getZ();
6928 HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos();
6929 cout<<"v_measu = "<<v_measu<<endl;
6930 */
6931 double dPhiToGem = track.intersect_cylinder(rGem);
6932 //cout << "dPhiToGem=" << dPhiToGem << endl;
6933 HepPoint3D posEstiAtGem = track.x(dPhiToGem);
6934 double x0=posEstiAtGem.x();
6935 double y0=posEstiAtGem.y();
6936 double pathInGem;
6937 //cout << "before move" << "pivot" <<track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
6938 track.pivot_numf(posEstiAtGem, pathInGem);
6939 //cout << "posEstiAtGem=" << posEstiAtGem << endl;
6940 //cout << "pathInGem=" << pathInGem << endl;
6941 if(pathInGem>0)
6942 {
6943 if(muls_) track.ms(pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
6944 if(loss_) track.eloss(pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
6945 }
6946 //cout << "after move" << "pivot" <<track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
6947 double rGemEsti=posEstiAtGem.perp();
6948 double phiGemEsti=posEstiAtGem.phi();
6949 double zGemEsti=posEstiAtGem.z();
6950 HepVector v_estim(2,0);
6951 v_estim(1)=phiGemEsti;
6952 v_estim(2)=zGemEsti;
6953 //cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
6954 //cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
6955 double dPhi=track.intersect_cylinder(rGem);
6956 //cout << "dPhi=" << dPhi << endl;
6957 HepPoint3D pos = track.x(dPhi);
6958 //cout<< "assumed esti phi,z" << pos.phi() << "," << pos.z() << endl;
6959 const HepSymMatrix& Ea = track.Ea();
6960 HepVector v_a = track.a();
6961 double drho=v_a(1);
6962 double phi0=v_a(2);
6963 double kappa=v_a(3);
6964 double tl=v_a(5);
6965 //cout<<"v_a = "<<v_a<<endl;
6966 //cout<<"phi0 = "<<phi0<<endl;
6967 // --- derivative matrix
6968 HepMatrix H(2, 5, 0);
6969 //H(1,2)=(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
6970 //H(2,4)=1.0;
6971 H(1,1)=-y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
6972 //H(1,1)=(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
6973 //H(1,2)=-y0/(y0*y0+x0*x0)*sin(phi0+dPhi)-x0/(x0*x0+y0*y0)*cos(phi0+dPhi);
6974 H(1,2)=-y0/(y0*y0+x0*x0)*((-1)*drho*sin(phi0)+m_alpha/kappa*(sin(phi0+dPhi)-sin(phi0)))+x0/(x0*x0+y0*y0)*(drho*cos(phi0)+m_alpha/kappa*(cos(phi0)-cos(phi0+dPhi)));
6975 H(1,3)=-y0/(y0*y0+x0*x0)*(-1)*m_alpha/(kappa*kappa)*(cos(phi0)-cos(phi0+dPhi))+x0/(x0*x0+y0*y0)*(-1)*m_alpha/(kappa*kappa)*(sin(phi0)-sin(phi0+dPhi));
6976 H(2,3)=m_alpha/(kappa*kappa)*tl*dPhi;
6977 H(2,4)=1.0;
6978 H(2,5)=-1*(m_alpha/kappa)*dPhi;
6979 //cout<<"H="<<H<<endl;
6980 HepMatrix H_T=H.T();
6981 //cout<<"H_T="<<H_T<<endl;
6982 //cout << "H*v_a=" << H*v_a << endl;
6983 //cout << "H*v_a+estim=" <<H*v_a+v_estim << endl;
6984 // --- error matrix of Gem hit
6985 HepSymMatrix V=(*iter).getErrMat();
6986 //cout<<"V="<<V<<endl;
6987 HepMatrix HEa=H*Ea;
6988 HepMatrix HEaH_T=HEa*H_T;
6989 int ierr=-1;
6990 HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
6991 if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
6992 // --- gain matrix
6993 HepMatrix K=Ea*H_T*Vinv;
6994 // --- new error matrix
6995 HepSymMatrix EaNew(5,0);
6996 EaNew.assign(Ea-K*H*Ea);
6997 // --- diff
6998 HepVector v_diff=v_measu-v_estim;
6999 //cout << "v_diff before= " << v_diff << endl;
7000 double delPhi=v_diff(1);
7001 if(fabs(v_diff(1))>6.28) v_measu(1)=-1*v_measu(1);
7002 while(delPhi> M_PI) delPhi-=M_PI;
7003 while(delPhi<-M_PI) delPhi+=M_PI;
7004 v_diff(1)=delPhi;
7005 //v_diff=v_measu-(H*v_a+v_estim);
7006 //cout<<"v_diff = "<<v_diff<<endl;
7007 // --- new parameters
7008 HepVector aNew=v_a+K*v_diff;
7009 //cout << "matrix K=" << K << endl;
7010 //cout << "aNew=" << aNew << endl;
7011 // --- new v_estim
7012 KalFitTrack track_test(posEstiAtGem,aNew,EaNew,hypo,0.0,track.nchits());
7013 double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7014 HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7015 double phiGemEsti_new=posEstiAtGem_new.phi();
7016 double zGemEsti_new=posEstiAtGem_new.z();
7017 double x0_new = posEstiAtGem_new.x();
7018 double y0_new = posEstiAtGem_new.y();
7019 HepVector v_estim_new(2,0);
7020 v_estim_new(1)=phiGemEsti_new;
7021 v_estim_new(2)=zGemEsti_new;
7022 //cout<<"v_estim_new = "<<v_estim_new<<endl;
7023 //cout << "assumed v_estim_new =" << H*aNew+v_estim << endl;
7024 // --- diff between measurement and updated estimation
7025 v_diff=v_measu-v_estim_new;
7026 delPhi=v_diff(1);
7027 while(delPhi> M_PI) delPhi-=M_PI;
7028 while(delPhi<-M_PI) delPhi+=M_PI;
7029 //cout<<"v_diff_new = "<<v_diff<<endl;
7030 //cout << "H*aNew"<< H*aNew << endl;
7031 //cout << "test v_diff new" << v_measu-v_estim-H*aNew << endl;
7032 // --- new derivative matrix
7033 track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7034 HepVector v_a_new = track_test.a();
7035 //cout << "v_a_new=" << v_a_new << endl;
7036 HepSymMatrix Ea_new = track_test.Ea();
7037 //cout << "Ea_new =" << Ea_new << endl;
7038 double phi0_new = v_a_new(2);
7039 double kappa_new=v_a_new(3);
7040 HepMatrix H_new(2, 5, 0);
7041 //H_new(1,1)=-y0_new/(x0_new*x0_new+y0_new*y0_new)*cos(phi0_new)+x0_new/(x0_new*x0_new+y0_new*y0_new)*sin(phi0_new);
7042 //H_new(2,4)=1.0;
7043 //H_new(1,1)=(x0_new*cos(phi0_new)-y0_new*sin(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7044
7045 /* H_new(1,1)=-y0_new/(1+x0_new*x0_new)*cos(phi0_new)+x0_new/(x0_new*x0_new+y0_new*y0_new)*sin(phi0_new);
7046 H_new(1,2)=-y0_new/(1+x0_new*x0_new)*sin(phi0_new+dPhiToGem_New)-x0_new/(x0_new*x0_new+y0_new*y0_new)*cos(phi0_new+dPhiToGem_New);
7047 H_new(2,4)=1.0;
7048 H_new(2,5)=-(-333.564095)/kappa_new*dPhiToGem_New;*/
7049 HepMatrix H_new_T=H_new.T();
7050 // --- R mactrix
7051 //cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7052 //cout << "H*Ea_new*H_T=" << H*Ea_new*H_T << endl;
7053 //cout << "H*EaNew*H_T=" << H*EaNew*H_T<< endl;
7054 //cout << "H_new*Eanew*H_new_T = "<< H_new*EaNew*H_new_T << endl;
7055 //cout << "assumed R=" <<V-H*Ea_new*H_T << endl;
7056 HepSymMatrix R(2,0);
7057 //R.assign(V-H_new*Ea_new*H_new_T);
7058 R.assign(V-H*EaNew*H_T);
7059
7060 //cout << "test track" << "pivot" << track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7061 // --- Chi^2 added
7062 //cout << "v_diff_T=" << v_diff.T() <<endl;
7063 //cout << "v_diff=" << v_diff <<endl;
7064 //cout << "R="<<R << endl;
7065 //cout << "R inverse=" << R.inverse(ierr)<< endl;
7066 HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7067 if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7068 //cout<<"v_dChi2 = "<<v_dChi2<<endl;
7069 //cout<< "test dchi2=" << (H*v_a).T()*R.inverse(ierr)*(H*v_a) << endl;
7070 double dChi2=v_dChi2(1);
7071
7072 // --- comparison
7073 if(debug_==4){
7074 cout<<"pivot: "<<posEstiAtGem<<endl;
7075 cout<<"new pivot: "<<posEstiAtGem<<endl;
7076 cout<<"a: "<<v_a<<endl;
7077 cout<<"new a: "<<aNew<<endl;
7078 cout<<"Ea: "<<Ea<<endl;
7079 cout<<"new Ea: "<<EaNew<<endl;
7080 cout<<"dchi2= "<<dChi2<<endl;
7081 }
7082 /* if(ntuple_&1){
7083 m_diff[ii]=delPhi;
7084 cout << v_diff(2) << endl;
7085 m_diffz[ii]=v_diff(2);
7086 m_phi[ii]=phiGem;
7087 m_z[ii]=zGem;
7088 m_Gemdchi2[ii]=dChi2;
7089 m_Glayer[ii]=iLayer;
7090 m_hypo[ii]=hypo;
7091 m_meas_r[ii]=rGem;
7092 m_meas_phi[ii]=phiGem;
7093 m_meas_z[ii]=zGem;
7094 m_esti1_r[ii]=rGemEsti;
7095 m_esti1_phi[ii]=phiGemEsti;
7096 m_esti1_z[ii]=zGemEsti;
7097 m_esti2_r[ii]=rGem;
7098 m_esti2_phi[ii]=phiGemEsti_new;
7099 m_esti2_z[ii]=zGemEsti_new;
7100 m_diff1_phi[ii]=phiGem-phiGemEsti;
7101 m_diff1_z[ii]=zGem-zGemEsti;
7102 m_diff2_phi[ii]=phiGem-phiGemEsti_new;
7103 m_diff2_z[ii]=zGem-zGemEsti_new;
7104 m_Gchi2[ii]=dChi2;
7105 m_GemLayer[ii]=iLayer;
7106 m_mass[ii]=hypo;
7107 } */
7108 // --- update KalFitTrack
7109 //track.set(posEstiAtGem_new,v_a_new,Ea_new);
7110 //dchi2_all.push_back(dChi2);
7111 //posnew.push_back(posEstiAtGem_new);
7112 //anew.push_back(v_a_new);
7113 //eanew.push_back(Ea_new);
7114 //dchi2[ii]=dChi2;
7115 esti1_r[dChi2]=rGemEsti;
7116 esti1_phi[dChi2]=phiGemEsti;
7117 esti1_z[dChi2]=zGemEsti;
7118 esti2_r[dChi2]=rGem;
7119 esti2_phi[dChi2]=phiGemEsti_new;
7120 esti2_z[dChi2]=zGemEsti_new;
7121 diff1_phi[dChi2]=phiGem-phiGemEsti;
7122 diff1_z[dChi2]=zGem-zGemEsti;
7123 diff2_phi[dChi2]=phiGem-phiGemEsti_new;
7124 diff2_z[dChi2]=zGem-zGemEsti_new;
7125 posnew[dChi2]=posEstiAtGem;
7126 anew[dChi2]=aNew;
7127 eanew[dChi2]=EaNew;
7128 meas_r[dChi2]=rGem;
7129 meas_phi[dChi2]=phiGem;
7130 //cout << "meas_phi[dChi2]" << phiGem << endl;
7131 meas_z[dChi2]=zGem;
7132 meas_phierr[dChi2]=sqrt(V[0][0]);
7133 //cout << "meas_phierr[dChi2]" << meas_phierr[dChi2] << endl;
7134 meas_zerr[dChi2]=sqrt(V[1][1]);
7135 //cout << "meas_zerr[dChi2]" << meas_zerr[dChi2] << endl;
7136 esti_phierr[dChi2]=sqrt((H*(track_start.Ea())*H_T)[0][0]);
7137 //cout << "esti_phierr[dChi2]" << esti_phierr[dChi2] << endl;
7138 esti_zerr[dChi2]=sqrt((H*(track_start.Ea())*H_T)[1][1]);
7139 //cout << "esti_zerr[dChi2]" << esti_zerr[dChi2] << endl;
7140
7141 ihit++;
7142 // ii++;
7143 }
7144
7145 //m_Gemhits=ii;
7146 //m_nt7->write();
7147 track.set((posnew.begin())->second,(anew.begin())->second,(eanew.begin()->second));
7148
7149 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(iLayer);
7150 double new_dPhiToGem = track.intersect_cylinder((CgemLayer->getInnerROfGapD())/10);
7151 HepPoint3D new_posEstiAtGem = track.x(new_dPhiToGem);
7152 double new_pathInGem;
7153 //cout << "new_dPhiToGem" << new_dPhiToGem << endl;
7154 //cout << "before move2" << "pivot" <<track.pivot().perp() << "," << track.pivot().phi() << "," << track.pivot().z()<< "a" << track.a() << "ea" << track.Ea() << endl;
7155 track.pivot_numf(new_posEstiAtGem, new_pathInGem);
7156 //cout << "posEstiAtGem2=" << new_posEstiAtGem << endl;
7157 //cout << "pathInGem2=" << new_pathInGem << endl;
7158 if(new_pathInGem>0)
7159 {
7160 if(muls_) track.ms(new_pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7161 if(loss_) track.eloss(new_pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7162 }
7163 //cout << "after move2: " << "pivot" <<track.pivot().perp() << "," << track.pivot().phi() << "," << track.pivot().z() << "a" << track.a() << "ea" << track.Ea() << endl;
7164 if(iLayer>=1){
7165 innerwall(track,hypo,way,90+(-32)*iLayer,95+(-32)*iLayer);}
7166 else{
7167 innerwall(track,hypo,way,90+(-32)*iLayer,94+(-32)*iLayer);}
7168 //cout <<"!!!!ntuple" << ntuple_ << endl;
7169 //cout << "!!!(esti1_phi.begin())->second" << (esti1_phi.begin())->second << endl;
7170 //cout<<" Finish innerwall"<<endl;
7171 if(ntuple_&1)
7172 {
7173 //cout << "good!" << endl;
7174 //cout << "m_esti1_r[ii]0" << m_esti1_r[ii] << endl;
7175 m_esti1_r[ii]=(esti1_r.begin())->second;
7176 //cout << "m_esti1_r[ii]1" << m_esti1_r[ii] << endl;
7177 m_esti1_phi[ii]=(esti1_phi.begin())->second;
7178 m_esti1_z[ii]=(esti1_z.begin())->second;
7179 m_esti2_r[ii]=(esti2_r.begin())->second;
7180 m_esti2_phi[ii]=(esti2_phi.begin())->second;
7181 m_esti2_z[ii]=(esti2_z.begin())->second;
7182 m_diff1_phi[ii]=(diff1_phi.begin())->second;
7183 m_diff1_z[ii]=(diff1_z.begin())->second;
7184 m_diff2_phi[ii]=(diff2_phi.begin())->second;
7185 m_diff2_z[ii]=(diff2_z.begin())->second;
7186 m_Gchi2[ii]=(esti1_r.begin())->first;
7187 m_meas_r[ii]=(meas_r.begin())->second;
7188 m_meas_phi[ii]=(meas_phi.begin())->second;
7189 //cout << "m_meas_phi[ii]" << m_meas_phi[ii] << endl;
7190 m_meas_z[ii]=(meas_z.begin())->second;
7191 m_meas_phierr[ii]=(meas_phierr.begin())->second;
7192 m_meas_zerr[ii]=(meas_zerr.begin())->second;
7193 m_esti_phierr[ii]=(esti_phierr.begin())->second;
7194 m_esti_zerr[ii]=(esti_zerr.begin())->second;
7195 m_GemLayer[ii]=iLayer;
7196 m_mass[ii]=hypo;
7197 }
7198 //cout<<" end of ntuple_"<<endl;
7199 ii++;
7200 }// loop layers
7201 //cout<<"finish layer loop"<<endl;
7202
7203 //SmartDataPtr<Event::EventHeader> evtHeader(eventSvc(),"/Event/EventHeader");
7204 //m_evt3 = evtHeader->eventNumber();
7205 if(ifProdNt10) {
7206 //cout << "m_meas_phi[ii]" << m_meas_phi[0] << endl;
7207 if(m_meas_phi[0]>0 && m_meas_phi[0]<1.5707963) m_qua=0;
7208 if(m_meas_phi[0]>1.5707963 && m_meas_phi[0]<3.1415926) m_qua=1;
7209 if(m_meas_phi[0]>-3.1415926&& m_meas_phi[0]<-1.5707963) m_qua=2;
7210 if(m_meas_phi[0]>-1.5707963&& m_meas_phi[0]<0) m_qua=3;
7211 //cout << "m_qua=" << m_qua << endl;
7212 m_nGemHits=ii;
7213 }
7214 //m_Gemhits=ii;
7215 // m_nt7->write();
7216 // m_nt10->write();
7217 posnew.clear();
7218 eanew.clear();
7219 anew.clear();
7220 esti1_r.clear();
7221 esti2_r.clear();
7222 esti1_phi.clear();
7223 esti2_phi.clear();
7224 esti1_z.clear();
7225 esti2_z.clear();
7226 diff1_phi.clear();
7227 diff1_z.clear();
7228 diff2_phi.clear();
7229 diff2_z.clear();
7230 meas_r.clear();
7231 meas_phi.clear();
7232 meas_z.clear();
7233 meas_phierr.clear();
7234 meas_zerr.clear();
7235 esti_phierr.clear();
7236 esti_zerr.clear();
7237
7238 }// end of GEM Kalman fit
7239 //cout << "end of GEM Kalman fit" << endl;
7240 if(ifProdNt10) {
7241 SmartDataPtr<Event::EventHeader> evtHeader(eventSvc(),"/Event/EventHeader");
7242 //cout << "evtHeader" << m_evt3 << endl;
7243 m_evt3 = evtHeader->eventNumber();
7244 m_nt10->write();
7245 }
7246
7247}
7248
7249
7250
7252{
7253
7254 ///---readin clusters of this track
7255 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
7256 if (!eventHeader) {
7257 cout << "Could not find Event Header" << endl;
7258 }
7259 int eventNo = eventHeader->eventNumber();
7260 int runNo = eventHeader->runNumber();
7261 SmartDataPtr<RecMdcTrackCol> recMdcTrack(eventSvc(),"/Event/Recon/RecMdcTrackCol");
7262 if (!recMdcTrack) {
7263 cout << "Could not find RecMdcTrackCol" << endl;
7264 }
7265 RecMdcTrackCol::iterator itrk = recMdcTrack->begin();
7266 ClusterRefVec clusterRefVec;
7267 for(; itrk != recMdcTrack->end(); itrk++){
7268 if((*itrk)->trackId() == track.trasan_id() && (*itrk)->getNcluster() > 0) {
7269 clusterRefVec = (*itrk)->getVecClusters();
7270 break;
7271 }
7272 else {
7273 if(4 == debug_) cout<<"run:"<<runNo<<" , Event:"<<eventNo<<" , track:"<<track.trasan_id()<<" has no cluster!"<<endl;
7274 }
7275 }
7276
7277 if(debug_==4){ cout<<"wall size"<<_BesKalmanFitWalls.size()<<endl;}
7278
7279 ///---set the start and stop point of fit
7280 ClusterRefVec::iterator itCluster;
7281 ClusterRefVec::iterator itStartFlag;
7282 ClusterRefVec::iterator itStopFlag;
7283 int step;
7284 int index=0;
7285 double lastR;
7286 double R_o_cgem=_BesKalmanFitWalls[0].radius();
7287 if(way<0){
7288 itStartFlag = clusterRefVec.begin();
7289 itStopFlag = clusterRefVec.end();
7290 lastR=0;
7291 step = 1;
7292 }
7293 else {
7294 itStartFlag = clusterRefVec.end()-1;
7295 itStopFlag = clusterRefVec.begin()-1;
7296 lastR=R_o_cgem;
7297 step = -1;
7298 double pathl;
7299 track.pivot_numf(track.x(track.intersect_cylinder(R_o_cgem)),pathl);
7300 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
7301 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
7302 }
7303
7304 ///---update track
7305 for(itCluster = itStartFlag; itCluster !=itStopFlag; itCluster = itCluster + step){
7306 int layer = (*itCluster)->getlayerid();
7307 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(layer);
7308 double dmR = CgemLayer->getMiddleROfGapD()/10;
7309 innerwall(track,hypo,way,lastR,dmR,index);
7310 lastR=dmR;
7311 track.update_hits(*itCluster, dmR, way, m_csmflag);
7312 }
7313 KalFitTrack track_first(track);
7314 if(way<0){
7315 innerwall(track,hypo,way,lastR,R_o_cgem,index);
7316 }
7317 else
7318 {
7319 innerwall(track,hypo,way,lastR,0,index);
7320 }
7321
7322 return track_first;
7323}
7324
7325
7326/*
7327void KalFitAlg::Cgem_filter_anal(KalFitTrack& track, int hypo, int way)
7328{
7329 const double a_stero[3] = {(45.94*3.1415926/180),(31.10*3.1415926/180),(32.99*3.1415926/180)};
7330 const double w_sheet[3] = {549.78,417.097,550.614};
7331 const double r_layer[3] = {87.5026,132.7686,175.2686};
7332 const double dmr_layer[3] = {79.838,125.104,167.604};
7333 const int l_layer[3] = {532,690,847};
7334 const int n_sheet[3] = {1,2,2};
7335 const double x_reso[3]={0.1372,0.1476,0.1412};
7336 const double v_reso[3]={0.1273,0.1326,0.1378};
7337 //KalFitTrack track(Track);
7338
7339 SmartDataPtr<RecMdcTrackCol> recMdcTrack(eventSvc(),"/Event/Recon/RecMdcTrackCol");
7340 if (!recMdcTrack) {
7341 //cout << MSG::FATAL << "Could not find RecMdcTrackCol" << endreq;
7342 cout << "Could not find RecMdcTrackCol" << endl;
7343 return;
7344 }
7345 RecMdcTrackCol::iterator itrk = recMdcTrack->begin();
7346 ClusterRefVec clusterRefVec;
7347 for(; itrk != recMdcTrack->end(); itrk++){
7348 if((*itrk)->trackId() == track.trasan_id() && (*itrk)->getNcluster() > 0) {
7349 clusterRefVec = (*itrk)->getVecClusters();
7350 break;
7351 }
7352 else{cout<<"track id:"<<(*itrk)->trackId()<<","<<track.trasan_id()<<" cluster:"<<(*itrk)->getNcluster()<<endl;return;}
7353 }
7354 if(debug_==4){ cout<<"wall size"<<_BesKalmanFitWalls.size()<<endl;}
7355
7356 ClusterRefVec::iterator itCluster;
7357 ClusterRefVec::iterator itStartFlag;
7358 ClusterRefVec::iterator itStopFlag;
7359 int step;
7360 int index=0;
7361 double lastR=_BesKalmanFitWalls[0].radius();
7362 if(way>0){
7363 itStartFlag = clusterRefVec.end()-1;
7364 itStopFlag = clusterRefVec.begin()-1;
7365 step = -1;
7366 }
7367 else if(way<0){
7368 itStartFlag = clusterRefVec.begin();
7369 itStopFlag = clusterRefVec.end();
7370 step = 1;
7371 }
7372 else{
7373 cout<<"way=0,no filter direction"<<endl;
7374 return;
7375 }
7376
7377
7378 for(itCluster = itStartFlag; itCluster !=itStopFlag; itCluster = itCluster + step){
7379 int layer = (*itCluster)->getlayerid();
7380 //double dmR = dmr_layer[layer]/10;
7381 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(iLayer);
7382 double dmR = CgemLayer->getMiddleROfGapD()/10;
7383 double recZ = (*itCluster)->getRecZ()/10;
7384 double recPhi = (*itCluster)->getrecphi();
7385 while(recPhi > M_PI) recPhi-=2*M_PI;
7386 while(recPhi <-M_PI) recPhi+=2*M_PI;
7387
7388 innerwall(track,hypo,way,lastR,dmR,index);
7389 lastR=dmR;
7390 HepVector v_measu(2,0);
7391 v_measu(1) = recPhi;
7392 v_measu(2) = recZ;
7393 //double Phi = track.intersect_cylinder(dmR);
7394 HepPoint3D x0kal = track.x(track.intersect_cylinder(dmR));
7395 track.pivot_numf(x0kal);
7396 double x0 = x0kal.x();
7397 double y0 = x0kal.y();
7398 double pathl(0);
7399 HepVector v_estim(2,0);
7400 v_estim(1) = x0kal.phi();
7401 v_estim(2) = x0kal.z();
7402 double dPhi=track.intersect_cylinder(dmR);
7403 const HepSymMatrix& Ea = track.Ea();
7404 HepVector v_a = track.a();
7405 double dr = v_a(1);
7406 double phi0 = v_a(2);
7407 double kappa = v_a(3);
7408 double tanl = v_a(5);
7409 // --- derivative matrix
7410 HepMatrix H(2, 5, 0);
7411 H(1,1) = -y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
7412 H(1,2) = -y0/(y0*y0+x0*x0)*((-1)*dr*sin(phi0)+m_alpha/kappa*(sin(phi0+dPhi)-sin(phi0)))+x0/(x0*x0+y0*y0)*(dr*cos(phi0)+m_alpha/kappa*(cos(phi0)-cos(phi0+dPhi)));
7413 H(1,3) = -y0/(y0*y0+x0*x0)*(-1)*m_alpha/(kappa*kappa)*(cos(phi0)-cos(phi0+dPhi))+x0/(x0*x0+y0*y0)*(-1)*m_alpha/(kappa*kappa)*(sin(phi0)-sin(phi0+dPhi));
7414 H(2,3) = m_alpha/(kappa*kappa)*tanl*dPhi;
7415 H(2,4) = 1.0;
7416 H(2,5) = -1*(m_alpha/kappa)*dPhi;
7417 // --- error matrix of Cgem
7418 HepSymMatrix V(2,0);
7419 V(1,1) = pow(x_reso[layer]/r_layer[layer],2);
7420 V(2,2) = pow(sqrt(0.01*v_reso[layer]*v_reso[layer]/(sin(a_stero[layer])*sin(a_stero[layer]))+0.01*x_reso[layer]*x_reso[layer]/(tan(a_stero[layer])*tan(a_stero[layer]))),2);
7421 // --- gain matrix
7422 int ierr=-1;
7423 HepMatrix K = Ea*H.T()*(V+H*Ea*H.T()).inverse(ierr);
7424 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
7425 // --- new error matrix
7426 HepSymMatrix EaNew(5,0);
7427 EaNew.assign(Ea-K*H*Ea);
7428 // --- diff
7429 HepVector v_diff = v_measu - v_estim;
7430 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
7431 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
7432 // --- new parameters
7433 HepVector aNew = v_a + K*v_diff;
7434 // --- new v_estim
7435 KalFitTrack track_new(x0kal,aNew,EaNew,hypo,0.0,track.nchits());
7436 HepPoint3D x0kal_new = track_new.x(track_new.intersect_cylinder(dmR));
7437 HepVector v_estim_new(2,0);
7438 v_estim_new(1) = x0kal_new.phi();
7439 v_estim_new(2) = x0kal_new.z();
7440 // --- difference between measurement and updated estimation
7441 v_diff = v_measu - v_estim_new;
7442 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
7443 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
7444 // --- new derivative matrix
7445 //track_new.pivot_numf(x0kal_new,pathl);
7446 //HepVector a_new = track_new.a();
7447 //HepVector Ea_new = track_new.Ea();
7448 // --- R matrix
7449 HepSymMatrix R(2,0);
7450 R.assign(V-H*EaNew*H.T());
7451 HepVector dChi2 = v_diff.T()*R.inverse(ierr)*v_diff;
7452 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
7453 if(way>0) track.chiSq(track.chiSq()+dChi2(1));
7454 if(way<0) track.chiSq_back(track.chiSq_back()+dChi2(1));
7455 //track.set(x0kal,aNew,EaNew);
7456 track.set(track.pivot(),aNew,EaNew);
7457 }
7458}
7459*/
7460
7461
7463{
7464
7465 //cout<<"R:"<<track.pivot().perp()<<endl;
7466 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
7467 if (!eventHeader) {
7468 cout << "Could not find Event Header" << endl;
7469 }
7470 int eventNo = eventHeader->eventNumber();
7471 int runNo = eventHeader->runNumber();
7472 m_evt=eventNo;
7473 //cout<<"Event::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"<<eventNo<<endl;
7474
7475 SmartDataPtr<McParticleCol> mcPartCol(eventSvc(),"/Event/MC/McParticleCol");
7476 if (!mcPartCol) {
7477 cout << "Could not find McParticle" << endl;
7478 }
7479
7480 HepVector mc_a(5,0);
7481 McParticleCol::iterator i_mcTrk = mcPartCol->begin();
7482 for (;i_mcTrk != mcPartCol->end(); i_mcTrk++) {
7483 if(!(*i_mcTrk)->primaryParticle()) continue;
7484 const HepLorentzVector& mom((*i_mcTrk)->initialFourMomentum());
7485 const HepLorentzVector& pos = (*i_mcTrk)->initialPosition();
7486 //cout<<"MCposition:"<<pos.x()<<" "<<pos.y()<<" "<<pos.z()<<" "<<endl;
7487 double charge = 0.0;
7488 int pid = (*i_mcTrk)->particleProperty();
7489 if( pid >0 ) {
7490 charge = m_particleTable->particle( pid )->charge();
7491 } else if ( pid <0 ) {
7492 charge = m_particleTable->particle( -pid )->charge();
7493 charge *= -1;
7494 } else {
7495 }
7496 HepPoint3D pos2(pos.x(),pos.y(),pos.z());
7497 Hep3Vector mom2(mom.px(),mom.py(),mom.pz());
7498
7499 Helix mchelix(pos2, mom2, charge);
7500 //if( debug_ == 0) cout<< "helix: "<<mchelix.a()<<endl;
7501 mchelix.pivot( HepPoint3D(0,0,0) );
7502 for( int j =0; j<5; j++) {
7503 //m_mchelix[j] = mchelix.a()[j];
7504 mc_a[j] = mchelix.a()[j];
7505 }
7506 //m_mcpid = pid;
7507 //m_mcptot = sqrt(1+pow(m_mchelix[4],2))/m_mchelix[2];
7508 }
7509 HepPoint3D IP(0,0,0);
7510 Helix MChelix(IP,mc_a);
7511 MChelix.pivot(track.pivot());
7512 m_diff_dr = track.a()[0]-MChelix.a()[0];
7513 m_diff_phi0 = track.a()[1]-MChelix.a()[1];
7514 m_diff_kappa = track.a()[2]-MChelix.a()[2];
7515 m_diff_dz = track.a()[3]-MChelix.a()[3];
7516 m_diff_tanl = track.a()[4]-MChelix.a()[4];
7517 if(track.a()[2] != 0 && MChelix.a()[2] != 0)
7518 m_diff_p = sqrt(1+track.a()[4]*track.a()[4])/track.a()[2] - sqrt(1+MChelix.a()[4]*MChelix.a()[4])/MChelix.a()[2];
7519 else
7520 m_diff_p =9999;
7521 StatusCode sc12 = m_nt12->write();
7522 if( sc12.isFailure() ) cout<<"Ntuple12 filling failed!"<<endl;
7523 //cout<<"kalfit a:"<<track.a()<<endl<<"MCtruth a:"<<MChelix.a()<<endl<<endl;
7524///*
7525 // --- calculate the material quantity
7526 bool printwalls = false;
7527 if(printwalls){
7528 double material_quantity(0);
7529 int size = _BesKalmanFitWalls.size();
7530 for(int i=0;i<size;i++)
7531 {
7532 double ro = _BesKalmanFitWalls[i].radius();
7533 double ri = _BesKalmanFitWalls[i].rmin();
7534 double thick = ro-ri;
7535 KalFitMaterial material = _BesKalmanFitWalls[i].material();
7536 double X0 = material.X0();
7537 double rho = material.get_density();
7538 double Z = material.Z();
7539 //double X = X0/rho;
7540 material_quantity += 100*thick/X0;
7541 cout<<"----------------------------------------------------------------------------------------------------"<<endl;
7542 cout<<"wall"<<i+1<<" Z:"<<setw(12)<<Z<<endl;
7543 cout<<"Ri(cm):"<<setw(12)<<ri<<"Ro(cm):"<<setw(12)<<ro<<"T(cm):"<<setw(12)<<thick<<"X0(cm):"<<setw(12)<<X0<<"T/X0(%)="<<setw(12)<<100*thick/X0<<"accumulation(%):"<<setw(12)<<material_quantity<<endl;
7544 cout<<"----------------------------------------------------------------------------------------------------"<<endl;
7545 cout<<endl;
7546 //cout<<"wall"<<i+1<<" Z:"<<Z<<" Thick:"<<thick<<" Density:"<<rho <<" X0:"<<X0<<endl;
7547 //cout<<"radiation length="<<x<<" material quantity="<<thick/x<<endl;
7548
7549 }
7550 cout<<"============================================================"<<endl;
7551 cout<<"total material quantity="<<material_quantity<<endl;
7552 cout<<"============================================================"<<endl;
7553 }
7554//*/
7555}
Double_t phi2
Double_t x[10]
Double_t phi1
int runNo
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in !Latex Output unit
Definition: FoamA.h:90
double sin(const BesAngle a)
double cos(const BesAngle a)
ObjectVector< RecMdcKalHelixSeg > RecMdcKalHelixSegCol
SmartRefVector< RecMdcKalHelixSeg > HelixSegRefVec
ObjectVector< RecMdcKalTrack > RecMdcKalTrackCol
SmartRefVector< RecCgemCluster > ClusterRefVec
SmartRefVector< RecMdcHit > HitRefVec
HepGeom::Point3D< double > HepPoint3D
Definition: KalFitAlg.cxx:19
bool testOutput
Definition: KalFitAlg.cxx:96
const double dr_layer[3]
Definition: KalFitAlg.cxx:89
const double dor_layer[3]
Definition: KalFitAlg.cxx:88
const double dmr_layer[3]
Definition: KalFitAlg.cxx:87
const double newr[3]
Definition: KalFitAlg.cxx:86
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
#define M_PI
Definition: TConstant.h:4
#define X0
void setFHelix(const HepVector &fhelix, const int pid)
void setZError(const HepSymMatrix &error, const int pid)
void setPoca(const HepPoint3D &poca, const int pid)
void setTheta(const double theta, const int pid)
void setFError(const HepSymMatrix &ferror, const int pid)
void setZHelix(const HepVector &helix, const int pid)
void setCharge(const int charge, const int pid)
virtual double getReferField()=0
virtual bool isVertexValid()=0
virtual double * SigmaPrimaryVertex()=0
virtual double * PrimaryVertex()=0
double pe_cut_
value of the momentum cut to decide refit
void residual(KalFitTrack &track)
Definition: KalFitAlg.cxx:7462
void filter_fwd_anal(KalFitTrack &trk, int l_mass, int way, HepSymMatrix &Eakal)
Kalman filter (forward) in Mdc.
Definition: KalFitAlg.cxx:2803
void filter_fwd_calib(KalFitTrack &trk, int l_mass, int way, HepSymMatrix &Eakal)
Definition: KalFitAlg.cxx:3044
double fstrag_
factor of energy loss straggling for electron
StatusCode beginRun()
Definition: KalFitAlg.cxx:333
void fillTds_lead(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
Definition: KalFitAlg.cxx:1411
~KalFitAlg(void)
destructor
Definition: KalFitAlg.cxx:182
void fromFHitToInnerWall(KalFitTrack &track, int way)
Definition: KalFitAlg.cxx:6356
void clean(void)
Definition: KalFitAlg.cxx:190
void kalman_fitting_MdcxReco_Csmc_Sew(void)
Definition: KalFitAlg.cxx:4561
void setCalibSvc_init(void)
initialize for the services
Definition: KalFitAlg2.cxx:247
void smoother_anal(KalFitTrack &trk, int way)
Kalman filter (smoothing or backward part)
Definition: KalFitAlg.cxx:2450
int i_back_
mass assumption for backward filter (if <0 means use leading mass)
void complete_track(MdcRec_trk &TrasanTRK, MdcRec_trk_add &TrasanTRK_add, KalFitTrack &track_lead, RecMdcKalTrack *kaltrk, RecMdcKalTrackCol *kalcol, RecMdcKalHelixSegCol *segcol, int flagsmooth)
Definition: KalFitAlg.cxx:5612
int wsag_
flag to take account the wire sag into account
void kalman_fitting_calib(void)
Definition: KalFitAlg.cxx:3972
void sameas(RecMdcKalTrack *trk, int l_mass, int imain)
complete the RecMdcKalTrackCol
Definition: KalFitAlg.cxx:2431
void fillTds_ip(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
with results got at (0,0,0)
Definition: KalFitAlg.cxx:1503
void makeGemHitsCol()
Definition: KalFitAlg.cxx:6738
void fitGemHits(KalFitTrack &track, int hypo, int way)
Definition: KalFitAlg.cxx:6843
void fillTds(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
with results got at the inner Mdc hit
Definition: KalFitAlg.cxx:1333
void innerwall(KalFitTrack &trk, int l_mass, int way)
Take the inner walls (eloss and mult scat) into account.
Definition: KalFitAlg.cxx:3242
KalFitTrack Cgem_filter_anal(KalFitTrack &track, int hypo, int way)
Definition: KalFitAlg.cxx:7251
int debug_
Debug flag for the track finder part.
void start_seed(KalFitTrack &track, int lead_, int way, MdcRec_trk &trk)
Definition: KalFitAlg.cxx:6120
void setBesFromGdml(void)
void setGeomSvc_init(void)
Definition: KalFitAlg2.cxx:259
KalFitAlg(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition: KalFitAlg.cxx:99
void kalman_fitting_anal(void)
Definition: KalFitAlg.cxx:3340
void setDchisqCut(void)
Definition: KalFitAlg.cxx:658
void set_Mdc(void)
Set up the wires, layers and superlayers...
Definition: KalFitAlg2.cxx:114
int enhance_
flag to enhance the error matrix at the inner hit of Mdc (cosmic)
StatusCode execute()
event function
Definition: KalFitAlg.cxx:761
void smoother_calib(KalFitTrack &trk, int way)
Definition: KalFitAlg.cxx:2665
void init_matrix(MdcRec_trk &trk, HepSymMatrix &Ea)
Definition: KalFitAlg.cxx:6022
double pT_
value of the pT cut for backward filter
StatusCode initialize()
initialize
Definition: KalFitAlg.cxx:204
StatusCode finalize()
Definition: KalFitAlg.cxx:320
void kalman_fitting_csmalign(void)
Definition: KalFitAlg.cxx:5050
void hist_def(void)
hist definition
Definition: KalFitAlg.cxx:369
void fillTds_back(KalFitTrack &track, RecMdcKalTrack *trk, MdcRec_trk &TrasanTRK, int l_mass)
with results got at the outer Mdc hit
Definition: KalFitAlg.cxx:1643
void clearTables()
Definition: KalFitAlg.cxx:6229
static int muls(void)
static int loss(void)
const int layerId(void) const
returns layer ID
Description of a track class (<- Helix.cc)
static void setMdcDigiCol(MdcDigiCol *digicol)
static int lead(void)
Magnetic field map.
static double chi2_hitf_
Cut chi2 for each hit.
static int nmass(void)
static int back(void)
void order_wirhit(int index)
HepSymMatrix getInitMatrix(void) const
static void setInitMatrix(HepSymMatrix m)
static int nmdc_hit2_
Cut chi2 for each hit.
void addTofSM(double time)
void chgmass(int i)
static double factor_strag_
factor of energy loss straggling for electron
const HepPoint3D & pivot_numf(const HepPoint3D &newPivot)
Sets pivot position in a given mag field.
void ms(double path, const KalFitMaterial &m, int index)
static int Tof_correc_
Flag for TOF correction.
void update_forMdc(void)
double intersect_cylinder(double r) const
Intersection with different geometry.
void HitsMdc(vector< KalFitHitMdc > &lh)
void fiTerm(double fi)
void point_last(const HepPoint3D &point)
set and give out the last point of the track
void HelixSegs(vector< KalFitHelixSeg > &vs)
static int numf_
Flag for treatment of non-uniform mag field.
double update_hits_csmalign(KalFitHelixSeg &HelixSeg, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, int csmflag)
void tof(double path)
Update the tof estimation.
static int drifttime_choice_
the drifttime choice
double smoother_Mdc(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
Kalman smoother for Mdc.
void msgasmdc(double path, int index)
Calculate multiple scattering angle.
static int tprop_
for signal propagation correction
void appendHitsMdc(KalFitHitMdc h)
Functions for Mdc hits list.
void addPathSM(double path)
static int resol(void)
void eloss(double path, const KalFitMaterial &m, int index)
Calculate total energy lost in material.
static void LR(int x)
static int numf(void)
static void setT0(double t0)
static void setMagneticFieldSvc(IMagneticFieldSvc *)
static int numfcor_
NUMF treatment improved.
double radius_numf(void) const
Estimation of the radius in a given mag field.
double smoother_Mdc_csmalign(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
double update_hits(KalFitHitMdc &HitMdc, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, double &dtrack, double &dtracknew, double &dtdc, int csmflag)
Include the Mdc wire hits.
static int LR_
Use L/R decision from MdcRecHit information :
static int strag_
Flag to take account of energy loss straggling :
unsigned int localId(void) const
Extractor :
HepPoint3D fwd(void) const
Geometry :
const KalFitLayer_Mdc & layer(void) const
double bFieldZ(double)
sets/returns z componet of the magnetic field.
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
void set(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
sets helix pivot position, parameters, and error matrix.
void ignoreErrorMatrix(void)
unsets error matrix. Error calculations will be ignored after this function call until an error matri...
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
const MdcGeoWire *const Wire(unsigned id)
Definition: MdcGeomSvc.cxx:770
const MdcGeoLayer *const Layer(unsigned id)
Definition: MdcGeomSvc.cxx:786
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
static vector< MdcRec_trk_add > * getMdcRecTrkAddCol(void)
Definition: MdcTables.cxx:356
static vector< MdcRec_trk > * getMdcRecTrkCol(void)
Definition: MdcTables.cxx:185
static vector< MdcRec_wirhit > * getMdcRecWirhitCol(void)
Definition: MdcTables.cxx:169
void setLHelix(const HepVector &helix, const int pid)
HelixSegRefVec getVecHelixSegs(int pid=-1) const
void setVecHelixSegs(const HelixSegRefVec &vechelixsegs, int pid=-1)
void setLError(const HepSymMatrix &error, const int pid)
void setLPoint(const HepPoint3D &point, const int pid)
void setLPivot(const HepPoint3D &pivot, const int pid)
IMPLICIT REAL *A H
Definition: myXsection.h:1