CGEM BOSS 6.6.5.g
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"
44
45#include "KalFitAlg/lpav/Lpav.h"
46// Bfield:
52#include "KalFitAlg/KalFitAlg.h"
53#include "McTruth/McParticle.h"
54#include "McTruth/MdcMcHit.h"
58#include "MdcRawEvent/MdcDigi.h"
66
68
70#include "Identifier/MdcID.h"
71#include "GaudiKernel/IPartPropSvc.h"
72#include "GaudiKernel/INTupleSvc.h"
74#include "McTruth/CgemMcHit.h"
78
79using CLHEP::HepVector;
80using CLHEP::Hep3Vector;
81using CLHEP::HepMatrix;
82using CLHEP::HepSymMatrix;
83
84using namespace Event;
85//using 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 if(debug_==5||debug_==4)
330 {
331 cout<<"KalFitAlg:: nTotalTrks = "<<nTotalTrks<<endl;
332 cout<<" e: "<<nFailedTrks[0]<<" failed, "<<nTotalTrks-nFailedTrks[0]<<" successed"<<endl;
333 cout<<" mu: "<<nFailedTrks[1]<<" failed, "<<nTotalTrks-nFailedTrks[1]<<" successed"<<endl;
334 cout<<" pi: "<<nFailedTrks[2]<<" failed, "<<nTotalTrks-nFailedTrks[2]<<" successed"<<endl;
335 cout<<" K: "<<nFailedTrks[3]<<" failed, "<<nTotalTrks-nFailedTrks[3]<<" successed"<<endl;
336 cout<<" p: "<<nFailedTrks[4]<<" failed, "<<nTotalTrks-nFailedTrks[4]<<" successed"<<endl;
337 }
338 return StatusCode::SUCCESS;
339}
340
341// begin run setting
343{
344 MsgStream log(msgSvc(), name());
345 log << MSG::INFO << "in beginRun()" << endreq;
346 log << MSG::INFO << "Present Parameters: muls: " << muls_ <<" loss: "
347 << " activeonly "<< activeonly_ << endreq;
348
349 // initialize the MdcGeomSvc
351 // Wires, Layers and SuperLayers of Mdc :
352 set_Mdc();
353
354 IMagneticFieldSvc* IMFSvc;
355 StatusCode sc = service ("MagneticFieldSvc",IMFSvc);
356 if(sc!=StatusCode::SUCCESS) {
357 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
358 }
359
360 // Nominal magnetic field :
362 KalFitTrack::Bznom_ = (IMFSvc->getReferField())*10000; //unit is KGauss
364
365 if(4 == debug_){
366 std::cout<<" beginRun, referField from MagneticFieldSvc:"<< (IMFSvc->getReferField())*10000 <<std::endl;
367 std::cout<<" magnetic field: "<<KalFitTrack::Bznom_<<std::endl;
368 }
369 }
370
371 return StatusCode::SUCCESS;
372}
373
374
375
376
377// hist_def function
379{
380 if(ntuple_&1) {
381 NTuplePtr nt1(ntupleSvc(),"FILE104/n101");
382 StatusCode status;
383 if ( nt1 ) m_nt1 = nt1;
384 else {
385 m_nt1= ntupleSvc()->book("FILE104/n101",CLID_ColumnWiseTuple,"KalFit");
386 if ( m_nt1 ) {
387
388 status = m_nt1->addItem("trackid",m_trackid);
389 status = m_nt1->addItem("stat",5,2,m_stat);
390 status = m_nt1->addItem("ndf",5,2,m_ndf);
391 status = m_nt1->addItem("chisq",5,2,m_chisq);
392 status = m_nt1->addItem("length",5,m_length);
393 status = m_nt1->addItem("tof",5,m_tof);
394 status = m_nt1->addItem("nhits",5,m_nhits);
395 status = m_nt1->addItem("zhelix",5,m_zhelix);
396 status = m_nt1->addItem("zhelixe",5,m_zhelixe);
397 status = m_nt1->addItem("zhelixmu",5,m_zhelixmu);
398 status = m_nt1->addItem("zhelixk",5,m_zhelixk);
399 status = m_nt1->addItem("zhelixp",5,m_zhelixp);
400 status = m_nt1->addItem("zptot",m_zptot);
401 status = m_nt1->addItem("zptote",m_zptote);
402 status = m_nt1->addItem("zptotmu",m_zptotmu);
403 status = m_nt1->addItem("zptotk",m_zptotk);
404 status = m_nt1->addItem("zptotp",m_zptotp);
405
406 status = m_nt1->addItem("zpt",m_zpt);
407 status = m_nt1->addItem("zpte",m_zpte);
408 status = m_nt1->addItem("zptmu",m_zptmu);
409 status = m_nt1->addItem("zptk",m_zptk);
410 status = m_nt1->addItem("zptp",m_zptp);
411
412 status = m_nt1->addItem("fptot",m_fptot);
413 status = m_nt1->addItem("fptote",m_fptote);
414 status = m_nt1->addItem("fptotmu",m_fptotmu);
415 status = m_nt1->addItem("fptotk",m_fptotk);
416 status = m_nt1->addItem("fptotp",m_fptotp);
417 status = m_nt1->addItem("fpt",m_fpt);
418 status = m_nt1->addItem("fpte",m_fpte);
419 status = m_nt1->addItem("fptmu",m_fptmu);
420 status = m_nt1->addItem("fptk",m_fptk);
421 status = m_nt1->addItem("fptp",m_fptp);
422
423 status = m_nt1->addItem("lptot",m_lptot);
424 status = m_nt1->addItem("lptote",m_lptote);
425 status = m_nt1->addItem("lptotmu",m_lptotmu);
426 status = m_nt1->addItem("lptotk",m_lptotk);
427 status = m_nt1->addItem("lptotp",m_lptotp);
428 status = m_nt1->addItem("lpt",m_lpt);
429 status = m_nt1->addItem("lpte",m_lpte);
430 status = m_nt1->addItem("lptmu",m_lptmu);
431 status = m_nt1->addItem("lptk",m_lptk);
432 status = m_nt1->addItem("lptp",m_lptp);
433
434 status = m_nt1->addItem("zsigp",m_zsigp);
435 status = m_nt1->addItem("zsigpe",m_zsigpe);
436 status = m_nt1->addItem("zsigpmu",m_zsigpmu);
437 status = m_nt1->addItem("zsigpk",m_zsigpk);
438 status = m_nt1->addItem("zsigpp",m_zsigpp);
439 status = m_nt1->addItem("fhelix",5,m_fhelix);
440 status = m_nt1->addItem("fhelixe",5,m_fhelixe);
441 status = m_nt1->addItem("fhelixmu",5,m_fhelixmu);
442 status = m_nt1->addItem("fhelixk",5,m_fhelixk);
443 status = m_nt1->addItem("fhelixp",5,m_fhelixp);
444 status = m_nt1->addItem("lhelix",5,m_lhelix);
445 status = m_nt1->addItem("lhelixe",5,m_lhelixe);
446 status = m_nt1->addItem("lhelixmu",5,m_lhelixmu);
447 status = m_nt1->addItem("lhelixk",5,m_lhelixk);
448 status = m_nt1->addItem("lhelixp",5,m_lhelixp);
449 status = m_nt1->addItem("rGem",4,m_rGem);
450 status = m_nt1->addItem("chi2Gem",4,m_chi2Gem);
451 status = m_nt1->addItem("phiGemExp",4,m_phiGemExp);
452 status = m_nt1->addItem("phiGemHit",4,m_phiGemHit);
453 status = m_nt1->addItem("zGemExp",4,m_zGemExp);
454 status = m_nt1->addItem("zGemHit",4,m_zGemHit);
455 if(ntuple_&32) {
456 status = m_nt1->addItem("zerror",15,m_zerror);
457 status = m_nt1->addItem("zerrore",15,m_zerrore);
458 status = m_nt1->addItem("zerrormu",15,m_zerrormu);
459 status = m_nt1->addItem("zerrork",15,m_zerrork);
460 status = m_nt1->addItem("zerrorp",15,m_zerrorp);
461 status = m_nt1->addItem("ferror",15,m_ferror);
462 status = m_nt1->addItem("ferrore",15,m_ferrore);
463 status = m_nt1->addItem("ferrormu",15,m_ferrormu);
464 status = m_nt1->addItem("ferrork",15,m_ferrork);
465 status = m_nt1->addItem("ferrorp",15,m_ferrorp);
466 status = m_nt1->addItem("lerror",15,m_lerror);
467 status = m_nt1->addItem("lerrore",15,m_lerrore);
468 status = m_nt1->addItem("lerrormu",15,m_lerrormu);
469 status = m_nt1->addItem("lerrork",15,m_lerrork);
470 status = m_nt1->addItem("lerrorp",15,m_lerrorp);
471 }
472 if((ntuple_&16)&&(ntuple_&1)) {
473 status = m_nt1->addItem("evtid",m_evtid);
474 status = m_nt1->addItem("mchelix",5,m_mchelix);
475 status = m_nt1->addItem("mcptot",m_mcptot);
476 status = m_nt1->addItem("mcpid",m_mcpid);
477 }
478 if( status.isFailure() ) cout<<"Ntuple1 add item failed!"<<endl;
479 }
480 }
481 }
482
483 if(ntuple_&4) {
484 NTuplePtr nt2(ntupleSvc(),"FILE104/n102");
485 StatusCode status2;
486 if ( nt2 ) m_nt2 = nt2;
487 else {
488 m_nt2= ntupleSvc()->book("FILE104/n102",CLID_ColumnWiseTuple,"KalFitComp");
489 if ( m_nt2 ) {
490 status2 = m_nt2->addItem("delx",m_delx);
491 status2 = m_nt2->addItem("dely",m_dely);
492 status2 = m_nt2->addItem("delz",m_delz);
493 status2 = m_nt2->addItem("delthe",m_delthe);
494 status2 = m_nt2->addItem("delphi",m_delphi);
495 status2 = m_nt2->addItem("delp",m_delp);
496 status2 = m_nt2->addItem("delpx",m_delpx);
497 status2 = m_nt2->addItem("delpy",m_delpy);
498 status2 = m_nt2->addItem("delpz",m_delpz);
499
500 if( status2.isFailure() ) cout<<"Ntuple2 add item failed!"<<endl;
501 }
502 }
503 }
504
505 if(ntuple_&2) {
506 NTuplePtr nt3(ntupleSvc(),"FILE104/n103");
507 StatusCode status3;
508 if ( nt3 ) m_nt3 = nt3;
509 else {
510 m_nt3= ntupleSvc()->book("FILE104/n103",CLID_ColumnWiseTuple,"PatRec");
511 if ( m_nt3 ) {
512 status3 = m_nt3->addItem("trkhelix",5,m_trkhelix);
513 status3 = m_nt3->addItem("trkptot",m_trkptot);
514 if(ntuple_&32) {
515 status3 = m_nt3->addItem("trkerror",15,m_trkerror);
516 status3 = m_nt3->addItem("trksigp",m_trksigp);
517 }
518 status3 = m_nt3->addItem("trkndf",m_trkndf);
519 status3 = m_nt3->addItem("trkchisq",m_trkchisq);
520 if( status3.isFailure() ) cout<<"Ntuple3 add item failed!"<<endl;
521 }
522 }
523 }
524
525 if(ntuple_&4) {
526 NTuplePtr nt4(ntupleSvc(),"FILE104/n104");
527 StatusCode status4;
528 if ( nt4 ) m_nt4 = nt4;
529 else {
530 m_nt4= ntupleSvc()->book("FILE104/n104",CLID_ColumnWiseTuple,"PatRecComp");
531 if ( m_nt4 ) {
532 status4 = m_nt4->addItem("trkdelx",m_trkdelx);
533 status4 = m_nt4->addItem("trkdely",m_trkdely);
534 status4 = m_nt4->addItem("trkdelz",m_trkdelz);
535 status4 = m_nt4->addItem("trkdelthe",m_trkdelthe);
536 status4 = m_nt4->addItem("trkdelphi",m_trkdelphi);
537 status4 = m_nt4->addItem("trkdelp",m_trkdelp);
538 if( status4.isFailure() ) cout<<"Ntuple4 add item failed!"<<endl;
539 }
540 }
541 }
542 if(ntuple_&8) {
543 NTuplePtr nt5(ntupleSvc(), "FILE104/n105");
544 StatusCode status5;
545 if ( nt5 ) m_nt5 = nt5;
546 else {
547 m_nt5= ntupleSvc()->book("FILE104/n105",CLID_ColumnWiseTuple,"KalFitdChisq");
548 if ( m_nt5 ) {
549 status5 = m_nt5->addItem("dchi2",m_dchi2);
550 status5 = m_nt5->addItem("masshyp",m_masshyp);
551 status5 = m_nt5->addItem("residual_estim",m_residest);
552 status5 = m_nt5->addItem("residual",m_residnew);
553 status5 = m_nt5->addItem("layer",m_layer);
554 status5 = m_nt5->addItem("kaldr",m_anal_dr);
555 status5 = m_nt5->addItem("kalphi0",m_anal_phi0);
556 status5 = m_nt5->addItem("kalkappa",m_anal_kappa);
557 status5 = m_nt5->addItem("kaldz",m_anal_dz);
558 status5 = m_nt5->addItem("kaltanl",m_anal_tanl);
559 status5 = m_nt5->addItem("dr_ea",m_anal_ea_dr);
560 status5 = m_nt5->addItem("phi0_ea",m_anal_ea_phi0);
561 status5 = m_nt5->addItem("kappa_ea",m_anal_ea_kappa);
562 status5 = m_nt5->addItem("dz_ea",m_anal_ea_dz);
563 status5 = m_nt5->addItem("tanl_ea",m_anal_ea_tanl);
564 if( status5.isFailure() ) cout<<"Ntuple5 add item failed!"<<endl;
565 }
566 }
567 }
568
569 //For kalman fit failure
570 //cout<<"start to book ntuple!"<<endl;
571 NTuplePtr nt7(ntupleSvc(),"FILE104/n120");
572 StatusCode status7;
573 if(nt7) m_nt7 = nt7;
574 else{
575 m_nt7 = ntupleSvc()-> book("FILE104/n120",CLID_ColumnWiseTuple,"kalfit_failure");
576 if(m_nt7){
577 status7 = m_nt7 ->addItem("run_kal",m_run_kal);
578 status7 = m_nt7 ->addItem("event_kal",m_event_kal);
579 status7 = m_nt7 ->addItem("trkid_kal",m_trkid_kal);
580 status7 = m_nt7 ->addItem("dropedHits_kal_e",m_dropedHits_kal_e);
581 status7 = m_nt7 ->addItem("kappa2_kal_e",m_kappa2_kal_e);
582 status7 = m_nt7 ->addItem("trackNhits_kal_e",m_trackNhits_kal_e);
583 status7 = m_nt7 ->addItem("trackNster_kal_e",m_trackNster_kal_e);
584 status7 = m_nt7 ->addItem("trackNaxis_kal_e",m_trackNaxis_kal_e);
585 status7 = m_nt7 ->addItem("chi2_kal_e",m_chi2_kal_e);
586 status7 = m_nt7 ->addItem("Ea00_kal_e",m_Ea00_kal_e);
587 status7 = m_nt7 ->addItem("Ea11_kal_e",m_Ea11_kal_e);
588 status7 = m_nt7 ->addItem("Ea22_kal_e",m_Ea22_kal_e);
589 status7 = m_nt7 ->addItem("Ea33_kal_e",m_Ea33_kal_e);
590 status7 = m_nt7 ->addItem("Ea44_kal_e",m_Ea44_kal_e);
591 status7 = m_nt7 ->addItem("dropedHits_kal_mu",m_dropedHits_kal_mu);
592 status7 = m_nt7 ->addItem("kappa2_kal_mu",m_kappa2_kal_mu);
593 status7 = m_nt7 ->addItem("trackNhits_kal_mu",m_trackNhits_kal_mu);
594 status7 = m_nt7 ->addItem("trackNster_kal_mu",m_trackNster_kal_mu);
595 status7 = m_nt7 ->addItem("trackNaxis_kal_mu",m_trackNaxis_kal_mu);
596 status7 = m_nt7 ->addItem("chi2_kal_mu",m_chi2_kal_mu);
597 status7 = m_nt7 ->addItem("Ea00_kal_mu",m_Ea00_kal_mu);
598 status7 = m_nt7 ->addItem("Ea11_kal_mu",m_Ea11_kal_mu);
599 status7 = m_nt7 ->addItem("Ea22_kal_mu",m_Ea22_kal_mu);
600 status7 = m_nt7 ->addItem("Ea33_kal_mu",m_Ea33_kal_mu);
601 status7 = m_nt7 ->addItem("Ea44_kal_mu",m_Ea44_kal_mu);
602 status7 = m_nt7 ->addItem("iqual_front_kal_mu",m_iqual_front_kal_mu);
603 status7 = m_nt7 ->addItem("dropedHits_kal_pi",m_dropedHits_kal_pi);
604 status7 = m_nt7 ->addItem("kappa2_kal_pi",m_kappa2_kal_pi);
605 status7 = m_nt7 ->addItem("trackNhits_kal_pi",m_trackNhits_kal_pi);
606 status7 = m_nt7 ->addItem("trackNster_kal_pi",m_trackNster_kal_pi);
607 status7 = m_nt7 ->addItem("trackNaxis_kal_pi",m_trackNaxis_kal_pi);
608 status7 = m_nt7 ->addItem("chi2_kal_pi",m_chi2_kal_pi);
609 status7 = m_nt7 ->addItem("Ea00_kal_pi",m_Ea00_kal_pi);
610 status7 = m_nt7 ->addItem("Ea11_kal_pi",m_Ea11_kal_pi);
611 status7 = m_nt7 ->addItem("Ea22_kal_pi",m_Ea22_kal_pi);
612 status7 = m_nt7 ->addItem("Ea33_kal_pi",m_Ea33_kal_pi);
613 status7 = m_nt7 ->addItem("Ea44_kal_pi",m_Ea44_kal_pi);
614 status7 = m_nt7 ->addItem("dropedHits_kal_k",m_dropedHits_kal_k);
615 status7 = m_nt7 ->addItem("kappa2_kal_k",m_kappa2_kal_k);
616 status7 = m_nt7 ->addItem("trackNhits_kal_k",m_trackNhits_kal_k);
617 status7 = m_nt7 ->addItem("trackNster_kal_k",m_trackNster_kal_k);
618 status7 = m_nt7 ->addItem("trackNaxis_kal_k",m_trackNaxis_kal_k);
619 status7 = m_nt7 ->addItem("chi2_kal_k",m_chi2_kal_k);
620 status7 = m_nt7 ->addItem("Ea00_kal_k",m_Ea00_kal_k);
621 status7 = m_nt7 ->addItem("Ea11_kal_k",m_Ea11_kal_k);
622 status7 = m_nt7 ->addItem("Ea22_kal_k",m_Ea22_kal_k);
623 status7 = m_nt7 ->addItem("Ea33_kal_k",m_Ea33_kal_k);
624 status7 = m_nt7 ->addItem("Ea44_kal_k",m_Ea44_kal_k);
625 status7 = m_nt7 ->addItem("dropedHits_kal_p",m_dropedHits_kal_p);
626 status7 = m_nt7 ->addItem("kappa2_kal_p",m_kappa2_kal_p);
627 status7 = m_nt7 ->addItem("trackNhits_kal_p",m_trackNhits_kal_p);
628 status7 = m_nt7 ->addItem("trackNster_kal_p",m_trackNster_kal_p);
629 status7 = m_nt7 ->addItem("trackNaxis_kal_p",m_trackNaxis_kal_p);
630 status7 = m_nt7 ->addItem("chi2_kal_p",m_chi2_kal_p);
631 status7 = m_nt7 ->addItem("Ea00_kal_p",m_Ea00_kal_p);
632 status7 = m_nt7 ->addItem("Ea11_kal_p",m_Ea11_kal_p);
633 status7 = m_nt7 ->addItem("Ea22_kal_p",m_Ea22_kal_p);
634 status7 = m_nt7 ->addItem("Ea33_kal_p",m_Ea33_kal_p);
635 status7 = m_nt7 ->addItem("Ea44_kal_p",m_Ea44_kal_p);
636
637 status7 = m_nt7 ->addItem("hit_number",m_hit_no,0, 1000);
638 status7 = m_nt7 ->addItem("nCluster",m_nCluster,0, 1000);
639 status7 = m_nt7->addIndexedItem("dchi2_hit_e",m_hit_no,m_dchi2_hit_e);
640 status7 = m_nt7->addIndexedItem("residual_estim_hit_e",m_hit_no,m_residest_hit_e);
641 status7 = m_nt7->addIndexedItem("residual_hit_e",m_hit_no,m_residnew_hit_e);
642 status7 = m_nt7->addIndexedItem("layer_hit_e",m_hit_no,m_layer_hit_e);
643 status7 = m_nt7->addIndexedItem("kaldr_hit_e",m_hit_no,m_anal_dr_hit_e);
644 status7 = m_nt7->addIndexedItem("kalphi0_hit_e",m_hit_no,m_anal_phi0_hit_e);
645 status7 = m_nt7->addIndexedItem("kalkappa_hit_e",m_hit_no,m_anal_kappa_hit_e);
646 status7 = m_nt7->addIndexedItem("kaldz_hit_e",m_hit_no,m_anal_dz_hit_e);
647 status7 = m_nt7->addIndexedItem("kaltanl_hit_e",m_hit_no,m_anal_tanl_hit_e);
648 status7 = m_nt7->addIndexedItem("dr_ea_hit_e",m_hit_no,m_anal_ea_dr_hit_e);
649 status7 = m_nt7->addIndexedItem("phi0_ea_hit_e",m_hit_no,m_anal_ea_phi0_hit_e);
650 status7 = m_nt7->addIndexedItem("kappa_ea_hit_e",m_hit_no,m_anal_ea_kappa_hit_e);
651 status7 = m_nt7->addIndexedItem("dz_ea_hit_e",m_hit_no,m_anal_ea_dz_hit_e);
652 status7 = m_nt7->addIndexedItem("tanl_ea_hit_e",m_hit_no,m_anal_ea_tanl_hit_e);
653 status7 = m_nt7->addIndexedItem("dchi2_hit_mu",m_hit_no,m_dchi2_hit_mu);
654 status7 = m_nt7->addIndexedItem("residual_estim_hit_mu",m_hit_no,m_residest_hit_mu);
655 status7 = m_nt7->addIndexedItem("residual_hit_mu",m_hit_no,m_residnew_hit_mu);
656 status7 = m_nt7->addIndexedItem("layer_hit_mu",m_hit_no,m_layer_hit_mu);
657 status7 = m_nt7->addIndexedItem("kaldr_hit_mu",m_hit_no,m_anal_dr_hit_mu);
658 status7 = m_nt7->addIndexedItem("kalphi0_hit_mu",m_hit_no,m_anal_phi0_hit_mu);
659 status7 = m_nt7->addIndexedItem("kalkappa_hit_mu",m_hit_no,m_anal_kappa_hit_mu);
660 status7 = m_nt7->addIndexedItem("kaldz_hit_mu",m_hit_no,m_anal_dz_hit_mu);
661 status7 = m_nt7->addIndexedItem("kaltanl_hit_mu",m_hit_no,m_anal_tanl_hit_mu);
662 status7 = m_nt7->addIndexedItem("dr_ea_hit_mu",m_hit_no,m_anal_ea_dr_hit_mu);
663 status7 = m_nt7->addIndexedItem("phi0_ea_hit_mu",m_hit_no,m_anal_ea_phi0_hit_mu);
664 status7 = m_nt7->addIndexedItem("kappa_ea_hit_mu",m_hit_no,m_anal_ea_kappa_hit_mu);
665 status7 = m_nt7->addIndexedItem("dz_ea_hit_mu",m_hit_no,m_anal_ea_dz_hit_mu);
666 status7 = m_nt7->addIndexedItem("tanl_ea_hit_mu",m_hit_no,m_anal_ea_tanl_hit_mu);
667 status7 = m_nt7->addIndexedItem("dchi2_hit_pi",m_hit_no,m_dchi2_hit_pi);
668 status7 = m_nt7->addIndexedItem("residual_estim_hit_pi",m_hit_no,m_residest_hit_pi);
669 status7 = m_nt7->addIndexedItem("residual_hit_pi",m_hit_no,m_residnew_hit_pi);
670 status7 = m_nt7->addIndexedItem("layer_hit_pi",m_hit_no,m_layer_hit_pi);
671 status7 = m_nt7->addIndexedItem("kaldr_hit_pi",m_hit_no,m_anal_dr_hit_pi);
672 status7 = m_nt7->addIndexedItem("kalphi0_hit_pi",m_hit_no,m_anal_phi0_hit_pi);
673 status7 = m_nt7->addIndexedItem("kalkappa_hit_pi",m_hit_no,m_anal_kappa_hit_pi);
674 status7 = m_nt7->addIndexedItem("kaldz_hit_pi",m_hit_no,m_anal_dz_hit_pi);
675 status7 = m_nt7->addIndexedItem("kaltanl_hit_pi",m_hit_no,m_anal_tanl_hit_pi);
676 status7 = m_nt7->addIndexedItem("dr_ea_hit_pi",m_hit_no,m_anal_ea_dr_hit_pi);
677 status7 = m_nt7->addIndexedItem("phi0_ea_hit_pi",m_hit_no,m_anal_ea_phi0_hit_pi);
678 status7 = m_nt7->addIndexedItem("kappa_ea_hit_pi",m_hit_no,m_anal_ea_kappa_hit_pi);
679 status7 = m_nt7->addIndexedItem("dz_ea_hit_pi",m_hit_no,m_anal_ea_dz_hit_pi);
680 status7 = m_nt7->addIndexedItem("tanl_ea_hit_pi",m_hit_no,m_anal_ea_tanl_hit_pi);
681 status7 = m_nt7->addIndexedItem("dchi2_hit_k",m_hit_no,m_dchi2_hit_k);
682 status7 = m_nt7->addIndexedItem("residual_estim_hit_k",m_hit_no,m_residest_hit_k);
683 status7 = m_nt7->addIndexedItem("residual_hit_k",m_hit_no,m_residnew_hit_k);
684 status7 = m_nt7->addIndexedItem("layer_hit_k",m_hit_no,m_layer_hit_k);
685 status7 = m_nt7->addIndexedItem("kaldr_hit_k",m_hit_no,m_anal_dr_hit_k);
686 status7 = m_nt7->addIndexedItem("kalphi0_hit_k",m_hit_no,m_anal_phi0_hit_k);
687 status7 = m_nt7->addIndexedItem("kalkappa_hit_k",m_hit_no,m_anal_kappa_hit_k);
688 status7 = m_nt7->addIndexedItem("kaldz_hit_k",m_hit_no,m_anal_dz_hit_k);
689 status7 = m_nt7->addIndexedItem("kaltanl_hit_k",m_hit_no,m_anal_tanl_hit_k);
690 status7 = m_nt7->addIndexedItem("dr_ea_hit_k",m_hit_no,m_anal_ea_dr_hit_k);
691 status7 = m_nt7->addIndexedItem("phi0_ea_hit_k",m_hit_no,m_anal_ea_phi0_hit_k);
692 status7 = m_nt7->addIndexedItem("kappa_ea_hit_k",m_hit_no,m_anal_ea_kappa_hit_k);
693 status7 = m_nt7->addIndexedItem("dz_ea_hit_k",m_hit_no,m_anal_ea_dz_hit_k);
694 status7 = m_nt7->addIndexedItem("tanl_ea_hit_k",m_hit_no,m_anal_ea_tanl_hit_k);
695 status7 = m_nt7->addIndexedItem("dchi2_hit_p",m_hit_no,m_dchi2_hit_p);
696 status7 = m_nt7->addIndexedItem("residual_estim_hit_p",m_hit_no,m_residest_hit_p);
697 status7 = m_nt7->addIndexedItem("residual_hit_p",m_hit_no,m_residnew_hit_p);
698 status7 = m_nt7->addIndexedItem("layer_hit_p",m_hit_no,m_layer_hit_p);
699 status7 = m_nt7->addIndexedItem("kaldr_hit_p",m_hit_no,m_anal_dr_hit_p);
700 status7 = m_nt7->addIndexedItem("kalphi0_hit_p",m_hit_no,m_anal_phi0_hit_p);
701 status7 = m_nt7->addIndexedItem("kalkappa_hit_p",m_hit_no,m_anal_kappa_hit_p);
702 status7 = m_nt7->addIndexedItem("kaldz_hit_p",m_hit_no,m_anal_dz_hit_p);
703 status7 = m_nt7->addIndexedItem("kaltanl_hit_p",m_hit_no,m_anal_tanl_hit_p);
704 status7 = m_nt7->addIndexedItem("dr_ea_hit_p",m_hit_no,m_anal_ea_dr_hit_p);
705 status7 = m_nt7->addIndexedItem("phi0_ea_hit_p",m_hit_no,m_anal_ea_phi0_hit_p);
706 status7 = m_nt7->addIndexedItem("kappa_ea_hit_p",m_hit_no,m_anal_ea_kappa_hit_p);
707 status7 = m_nt7->addIndexedItem("dz_ea_hit_p",m_hit_no,m_anal_ea_dz_hit_p);
708 status7 = m_nt7->addIndexedItem("tanl_ea_hit_p",m_hit_no,m_anal_ea_tanl_hit_p);
709
710 if( status7.isFailure() ) cout<<"Ntuple7 add item failed!"<<endl;
711 }
712 }
713 //cout<<"book ntuple done!"<<endl;
714
715
716
717 NTuplePtr nt6(ntupleSvc(),"FILE104/n106");
718 StatusCode status6;
719 if ( nt6 ) m_nt6 = nt6;
720 else {
721 m_nt6= ntupleSvc()->book("FILE104/n106",CLID_ColumnWiseTuple,"kal seg");
722 if ( m_nt6 ) {
723 status6 = m_nt6->addItem("docaInc",m_docaInc);
724 status6 = m_nt6->addItem("docaExc",m_docaExc);
725 status6 = m_nt6->addItem("tdr",m_tdrift);
726 status6 = m_nt6->addItem("layerid", m_layerid);
727 status6 = m_nt6->addItem("event", m_eventNo);
728 status6 = m_nt6->addItem("residualInc",m_residualInc);
729 status6 = m_nt6->addItem("residualExc",m_residualExc);
730 status6 = m_nt6->addItem("lr",m_lr);
731 status6 = m_nt6->addItem("dd",m_dd);
732 status6 = m_nt6->addItem("y",m_yposition);
733
734 if( status6.isFailure() ) cout<<"Ntuple6 add item failed!"<<endl;
735 }
736 }
737
738 if(ifProdNt10) {
739 NTuplePtr nt10(ntupleSvc(),"FILE104/n110");
740 StatusCode status10;
741 if ( nt10 ) m_nt10 = nt10;
742 else {
743 m_nt10= ntupleSvc()->book("FILE104/n110",CLID_ColumnWiseTuple,"test");
744 if ( m_nt10 ) {
745 status10 = m_nt10->addItem("evt",m_evt3);
746 status10 = m_nt10->addItem("qua",m_qua);
747 status10 = m_nt10->addItem("nhit",m_nGemHits,0,4000000);
748 status10 = m_nt10->addIndexedItem("meas_r",m_nGemHits,m_meas_r);
749 status10 = m_nt10->addIndexedItem("meas_phi",m_nGemHits,m_meas_phi);
750 status10 = m_nt10->addIndexedItem("meas_z",m_nGemHits,m_meas_z);
751 status10 = m_nt10->addIndexedItem("esti1_r",m_nGemHits,m_esti1_r);
752 status10 = m_nt10->addIndexedItem("esti1_phi",m_nGemHits,m_esti1_phi);
753 status10 = m_nt10->addIndexedItem("esti1_z",m_nGemHits,m_esti1_z);
754 status10 = m_nt10->addIndexedItem("esti2_r",m_nGemHits,m_esti2_r);
755 status10 = m_nt10->addIndexedItem("esti2_phi",m_nGemHits,m_esti2_phi);
756 status10 = m_nt10->addIndexedItem("esti2_z",m_nGemHits,m_esti2_z);
757 status10 = m_nt10->addIndexedItem("diff1_phi",m_nGemHits,m_diff1_phi);
758 status10 = m_nt10->addIndexedItem("diff1_z",m_nGemHits,m_diff1_z);
759 status10 = m_nt10->addIndexedItem("diff2_phi",m_nGemHits,m_diff2_phi);
760 status10 = m_nt10->addIndexedItem("diff2_z",m_nGemHits,m_diff2_z);
761 status10 = m_nt10->addIndexedItem("layer",m_nGemHits,m_GemLayer);
762 status10 = m_nt10->addIndexedItem("mass",m_nGemHits,m_mass);
763 status10 = m_nt10->addIndexedItem("dchi2",m_nGemHits,m_Gchi2);
764 status10 = m_nt10->addIndexedItem("meas_phierr",m_nGemHits,m_meas_phierr);
765 status10 = m_nt10->addIndexedItem("meas_zerr",m_nGemHits,m_meas_zerr);
766 status10 = m_nt10->addIndexedItem("esti_phierr",m_nGemHits,m_esti_phierr);
767 status10 = m_nt10->addIndexedItem("esti_zerr",m_nGemHits,m_esti_zerr);
768 if( status10.isFailure() ) cout<<"Ntuple10 add item failed!"<<endl;
769 }
770 }
771 }
772
773 if(ifProdNt11) {
774 NTuplePtr nt11(ntupleSvc(),"FILE104/n111");
775 StatusCode status11;
776 if ( nt11 ) m_nt11 = nt11;
777 else {
778 m_nt11= ntupleSvc()->book("FILE104/n111",CLID_ColumnWiseTuple,"truth");
779 if ( m_nt11 ) {
780 status11 = m_nt11->addItem("evt",m_evt4);
781 status11 = m_nt11->addItem("ntruth",m_ntruth,0,400000);
782 status11 = m_nt11->addIndexedItem("phi",m_ntruth,m_dtphi);
783 status11 = m_nt11->addIndexedItem("z",m_ntruth,m_dtv);
784 status11 = m_nt11->addIndexedItem("postphi",m_ntruth,m_dtpostphi);
785 status11 = m_nt11->addIndexedItem("postz",m_ntruth,m_dtpostz);
786 status11 = m_nt11->addIndexedItem("layer",m_ntruth,m_tlayer);
787 if( status11.isFailure() ) cout<<"Ntuple11 add item failed!"<<endl;
788 }
789 }
790 }
791
792 if(ifProdNt12) {
793 NTuplePtr nt12(ntupleSvc(),"FILE104/n112");
794 StatusCode status12;
795 if ( nt12 ) m_nt12 = nt12;
796 else {
797 m_nt12= ntupleSvc()->book("FILE104/n112",CLID_ColumnWiseTuple,"PatRecComp");
798 if ( m_nt12 ) {
799 status12 = m_nt12->addItem("evt",m_evt);
800 status12 = m_nt12->addItem("track",m_track);
801 status12 = m_nt12->addItem("diff_dr",m_diff_dr);
802 status12 = m_nt12->addItem("diff_phi0",m_diff_phi0);
803 status12 = m_nt12->addItem("diff_kappa",m_diff_kappa);
804 status12 = m_nt12->addItem("diff_dz",m_diff_dz);
805 status12 = m_nt12->addItem("diff_tanl",m_diff_tanl);
806 status12 = m_nt12->addItem("diff_p",m_diff_p);
807 if( status12.isFailure() ) cout<<"Ntuple12 add item failed!"<<endl;
808 }
809 }
810 }
811}
812
813
814
816{
817 int layid = 0;
818
819 /// set dchi2cutf_anal
820 for(layid = 0; layid<2; layid++) {
822 }
825 for(layid = 4; layid<12; layid++) {
827 }
828 for(layid = 12; layid<20; layid++) {
830 }
831 for(layid = 20; layid<43; layid++) {
833 }
834
835
836 /// set dchi2cuts_anal
837 for(layid = 0; layid<2; layid++) {
839 }
840
843 for(layid = 4; layid<12; layid++) {
845 }
846 for(layid = 12; layid<20; layid++) {
848 }
849 for(layid = 20; layid<43; layid++) {
851 }
852
853 /// temporary
854 // for(layid = 0; layid<43; layid++) {
855 // KalFitTrack::dchi2cuts_anal[layid] = 10.0;
856 // }
857
858
859 /// set dchi2cutf_calib
860 for(layid = 0; layid<2; layid++) {
862 }
863
866
867 for(layid = 4; layid<12; layid++) {
869 }
870
871 for(layid = 12; layid<20; layid++) {
873 }
874
875 for(layid = 20; layid<43; layid++) {
877 }
878
879 /// temporary
880 if(usage_<2){
881 for(layid = 0; layid<43; layid++) {
882 KalFitTrack::dchi2cutf_calib[layid] = 10.0;
883 }
884 }
885
886
887 /// set dchi2cuts_calib
888 for(layid = 0; layid<2; layid++) {
890 }
891
894
895 for(layid = 4; layid<12; layid++) {
897 }
898
899 for(layid = 12; layid<20; layid++) {
901 }
902
903 for(layid = 20; layid<43; layid++) {
905 }
906
907 /// temporary
908 if(usage_<2){
909 for(layid = 0; layid<43; layid++) {
910 KalFitTrack::dchi2cuts_calib[layid] = 10.0;
911 }
912 }
913}
914
915
916
917// event function
919{
920 MsgStream log(msgSvc(), name());
921 log << MSG::INFO << "in execute()" << endreq;
922 if(testOutput) std::cout<<"begin to deal with EVENT ..."<<(++eventno)<<std::endl;
923 for(int i=0; i<5; i++) iqual_front_[i] = 1;
924 iqual_back_ = 1;
925
926
927 /*
928 MdcID mdcId;
929 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
930 SmartDataPtr<RecMdcKalHelixSegCol> recSegCol(eventSvc(),"/Event/Recon/RecMdcKalHelixSegCol");
931 if(recmdckaltrkCol) {
932 cout<<"------------------------ new event ---------------------"<<endl;
933 cout<<"recmdckaltrkCol->size()="<<recmdckaltrkCol->size()<<endl;
934 cout<<"recSegCol.size()="<<recSegCol->size()<<endl;
935 cout<<"--------------------------------------------------------"<<endl;
936 RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
937 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
938 int i_trk=0;
939 for(;KalTrk !=recmdckaltrkCol->end();KalTrk++){
940 cout<<"*** track "<<i_trk++<<" ***"<<endl;
941 HelixSegRefVec gothelixsegs = (*KalTrk)->getVecHelixSegs();
942 for(int i=0;i<5;i++) cout<<"pid "<<i<<" nSegs="<<((*KalTrk)->getVecHelixSegs(i)).size()<<endl;
943 HelixSegRefVec::iterator iter_hit = gothelixsegs.begin();
944 if(iter_hit == gothelixsegs.end())cout<<"iter_hit == gothelixsegs.end()"<<endl;
945 int nhitofthistrk=0;
946 for( ; iter_hit != gothelixsegs.end(); iter_hit++){
947 nhitofthistrk++;
948 //cout<<"layerId: "<<(*iter_hit)->getLayerId()<<endl;
949 //cout<<"Identifier: "<<(*iter_hit)->getMdcId()<<endl;
950 //cout<<"layerId: "<<mdcId.layer((*iter_hit)->getMdcId())<<endl;
951 //cout<<"getDT: "<<(*iter_hit)->getDT()<<endl;
952 }
953 iter_hit=gothelixsegs.begin();
954 //for(int m=0; m<nhitofthistrk/5;m++){
955 // identifier = (*iter_hit) -> getMdcId();
956 //}
957 cout<<"nhitofthistrk="<<nhitofthistrk<<endl;
958 }
959 }
960 else cout<<"did not find /Event/Recon/RecMdcKalTrackCol"<<endl;
961 */
962
963
964
965
966 ///
967 IMagneticFieldSvc* IMFSvc;
968 StatusCode sc = service ("MagneticFieldSvc",IMFSvc);
969 if(sc!=StatusCode::SUCCESS) {
970 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
971 }
972
973 // Nominal magnetic field :
975 KalFitTrack::Bznom_ = (IMFSvc->getReferField())*10000; //unit is KGauss
977
978 if(4 == debug_){
979 std::cout<<" execute, referField from MagneticFieldSvc: "<< (IMFSvc->getReferField())*10000 <<std::endl;
980 std::cout<<" magnetic field: "<<KalFitTrack::Bznom_<<std::endl;
981 }
982 }
983
985
986 IDataProviderSvc* evtSvc = NULL;
987 Gaudi::svcLocator()->service("EventDataSvc", evtSvc);
988 if (evtSvc) {
989 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
990 } else {
991 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
992 return StatusCode::SUCCESS;
993 }
994
995 StatusCode kalsc;
996 IDataManagerSvc *dataManSvc;
997 dataManSvc= dynamic_cast<IDataManagerSvc*>(evtSvc);
998 DataObject *aKalTrackCol;
999 evtSvc->findObject("/Event/Recon/RecMdcKalTrackCol",aKalTrackCol);
1000 if(aKalTrackCol != NULL) {
1001 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalTrackCol");
1002 evtSvc->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
1003 }
1004
1005 kalsc = evtSvc->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
1006 if( kalsc.isFailure() ) {
1007 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
1008 return StatusCode::SUCCESS;
1009 }
1010 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
1011
1012 DataObject *aKalHelixSegCol;
1013 evtSvc->findObject("/Event/Recon/RecMdcKalHelixSegCol", aKalHelixSegCol);
1014 if(aKalHelixSegCol != NULL){
1015 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalHelixSegCol");
1016 evtSvc->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
1017 }
1018 RecMdcKalHelixSegCol *helixsegcol = new RecMdcKalHelixSegCol;
1019 kalsc = evtSvc->registerObject("/Event/Recon/RecMdcKalHelixSegCol", helixsegcol);
1020 if( kalsc.isFailure()){
1021 log<< MSG::FATAL << "Could not register RecMdcKalHelixSeg" <<endreq;
1022 return StatusCode::SUCCESS;
1023 }
1024 log << MSG::INFO << "RecMdcKalHelixSegCol register successfully!" <<endreq;
1025
1026
1027 /*IMdcGeomSvc* geosvc;
1028 StatusCode sc = service("MdcGeomSvc", geosvc);
1029 if (sc == StatusCode::SUCCESS) {
1030 } else {
1031 return sc;
1032 }*/
1033
1034 ISvcLocator* svcLocator = Gaudi::svcLocator();
1035 ICgemGeomSvc* ISvc;
1036 StatusCode Cgem_sc=svcLocator->service("CgemGeomSvc", ISvc);
1037 m_CgemGeomSvc_=dynamic_cast<CgemGeomSvc *>(ISvc);
1038 if (!Cgem_sc.isSuccess()) log<< MSG::INFO << "KalFitAlg::execute(): Could not open CGEM geometry file" << endreq;
1039 //myNCgemLayers = myCgemGeomSvc->getNumberOfCgemLayer();
1040 //if(myPrintFlag) cout<<"CgemClusterCreate::initialize() "<<myNCgemLayers<<" Cgem layers"<<endl;
1041
1042 MdcGeomSvc* const geosvc = dynamic_cast<MdcGeomSvc*>(imdcGeomSvc_);
1043 if(!geosvc) {
1044 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitAlg::execute ...!!"<<std::endl;
1045 }
1046
1047 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
1048 if (!eventHeader) {
1049 log << MSG::WARNING << "Could not find Event Header" << endreq;
1050 return StatusCode::FAILURE;
1051 }
1052 int eventNo = eventHeader->eventNumber();
1054 int runNo = eventHeader->runNumber();
1055 if(runNo>0) wsag_=4;
1056 else wsag_=0;
1057
1058 if(testOutput) cout<<endl<<"$$$$$$$$$$$ run="<<runNo<<", evt="<<eventNo<<" $$$$$$$$$$$$$$$$$"<<endl<<endl;
1059
1060 double t0=0.;
1061 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
1062 if (estimeCol && estimeCol->size()) {
1063 RecEsTimeCol::iterator iter_evt = estimeCol->begin();
1064 t0 = (*iter_evt)->getTest();
1065 // t0Stat = (*iter_evt)->getStat();
1066 }else{
1067 log << MSG::WARNING << "Could not find EvTimeCol" << endreq;
1068 return StatusCode::SUCCESS;
1069 }
1070
1071
1072 if(debug_==4) {
1073 std::cout<<"in KalFitAlg , we get the event start time = "<<t0<<std::endl;
1074 }
1076
1077 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc,"/Event/Digi/MdcDigiCol");
1078 if (sc!=StatusCode::SUCCESS) {
1079 log << MSG::FATAL << "Could not find MdcDigiCol!" << endreq;
1080 return StatusCode::SUCCESS;
1081 }
1082 KalFitTrack::setMdcDigiCol(mdcDigiCol);
1083
1084 // register RecMdcTrack and MdcRecHit collection
1085
1086 if((ntuple_&16)&&(ntuple_&1)) {
1087 // McTruth infor,Retrieve MC track truth
1088 // bool mcstat = true;
1089 // more research needed ...
1090
1091 m_evtid = eventHeader->eventNumber();
1092 bool mcstat = true;
1093
1094 SmartDataPtr<McParticleCol> mcPartCol(eventSvc(),"/Event/MC/McParticleCol");
1095 if (!mcPartCol) {
1096 log << MSG::WARNING << "Could not find McParticle" << endreq;
1097 mcstat = false;
1098 }
1099
1100 if(mcstat) {
1101 McParticleCol::iterator i_mcTrk = mcPartCol->begin();
1102 for (;i_mcTrk != mcPartCol->end(); i_mcTrk++) {
1103 if(!(*i_mcTrk)->primaryParticle()) continue;
1104 const HepLorentzVector& mom((*i_mcTrk)->initialFourMomentum());
1105 const HepLorentzVector& pos = (*i_mcTrk)->initialPosition();
1106 log << MSG::DEBUG << "MCINFO:particleId=" << (*i_mcTrk)->particleProperty()
1107 << " theta=" << mom.theta() <<" phi="<< mom.phi()
1108 <<" px="<< mom.px() <<" py="<< mom.py() <<" pz="<< mom.pz()
1109 << endreq;
1110 double charge = 0.0;
1111 int pid = (*i_mcTrk)->particleProperty();
1112 int mother_id = ((*i_mcTrk)->mother()).particleProperty();
1113 if( pid >0 ) {
1114 charge = m_particleTable->particle( pid )->charge();
1115 } else if ( pid <0 ) {
1116 charge = m_particleTable->particle( -pid )->charge();
1117 charge *= -1;
1118 } else {
1119 log << MSG::WARNING << "wrong particle id, please check data" <<endreq;
1120 }
1121 HepPoint3D pos2(pos.x(),pos.y(),pos.z());
1122 Hep3Vector mom2(mom.px(),mom.py(),mom.pz());
1123
1124 KalmanFit::Helix mchelix(pos2, mom2, charge);
1125 log << MSG::DEBUG << "charge of the track " << charge << endreq;
1126 if( debug_ == 4) cout<< "helix: "<<mchelix.a()<<endl;
1127 mchelix.pivot( HepPoint3D(0,0,0) );
1128 for( int j =0; j<5; j++) {
1129 m_mchelix[j] = mchelix.a()[j];
1130 }
1131 m_mcpid = pid;
1132 m_mcptot = sqrt(1+pow(m_mchelix[4],2))/m_mchelix[2];
1133 if(testOutput)
1134 {
1135 cout<<"MC pid, mother_id = "<<pid<<", "<<mother_id<<endl;
1136 cout<<" p4 = "<<(*i_mcTrk)->initialFourMomentum()<<endl;
1137 cout<<" start from "<<(*i_mcTrk)->initialPosition()<<endl;
1138 cout<<" end at "<<(*i_mcTrk)->finalPosition()<<endl;
1139 cout<<" Helix: "<<mchelix.a()<<endl;
1140 cout<<"mc ptot, theta, phi, R = "<<m_mcptot<<", "<<mom2.theta()/acos(-1.)*180<<", "<<mom2.phi()/acos(-1.)*180<<", "<<mchelix.radius()<<endl;
1141 }
1142 }
1143 }
1144 }
1145
1146 Identifier mdcid;
1147
1148 //retrieve RecMdcTrackCol from TDS
1149 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
1150 if (!newtrkCol) {
1151 log << MSG::FATAL << "Could not find RecMdcTrackCol" << endreq;
1152 return( StatusCode::SUCCESS);
1153 }
1154 log << MSG::INFO << "Begin to make MdcRecTrkCol and MdcRecWirhitCol"<<endreq;
1155
1156 vector<MdcRec_trk>* mtrk_mgr = MdcRecTrkCol::getMdcRecTrkCol();
1157 mtrk_mgr->clear();
1158 // m_tracks_kal = mtrk_mgr ->size();
1159 vector<MdcRec_trk_add>* mtrkadd_mgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
1160 mtrkadd_mgr->clear();
1161 vector<MdcRec_wirhit>* mhit_mgr = MdcRecWirhitCol::getMdcRecWirhitCol();
1162 mhit_mgr->clear();
1163
1164 double trkx1,trkx2,trky1,trky2,trkz1,trkz2,trkthe1,trkthe2,trkphi1,trkphi2,trkp1,trkp2,trkr1,trkr2,trkkap1,trkkap2,trktanl1,trktanl2;
1165 Hep3Vector csmp3[2];
1166 double csmphi[2];
1167 int status_temp=0;
1168 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
1169 for(int kj = 1; iter_trk != newtrkCol->end(); iter_trk++,kj++) {
1170 if(kj<3){
1171 csmp3[kj-1]=(*iter_trk)->p3();
1172 csmphi[kj-1] = (*iter_trk)->phi();
1173 }
1174 if(ntuple_&2) {
1175 //check trackcol, track level
1176 for( int j = 0, ij = 0; j<5; j++) {
1177 m_trkhelix[j] = (*iter_trk)->helix()[j];
1178 if(ntuple_&32) {
1179 for(int k=0; k<=j; k++,ij++) {
1180 m_trkerror[ij] = (*iter_trk)->err()[j][k];
1181 }
1182 }
1183 }
1184 m_trkptot = sqrt(1+pow(m_trkhelix[4],2))/m_trkhelix[2];
1185 if(ntuple_&32){
1186 m_trksigp = sqrt(pow((m_trkptot/m_trkhelix[2]),2)*m_trkerror[5]+
1187 pow((m_trkhelix[4]/m_trkptot),2)*pow((1/m_trkhelix[2]),4)*m_trkerror[14]-
1188 2*m_trkhelix[4]*m_trkerror[12]*pow((1/m_trkhelix[2]),3));
1189 }
1190 m_trkndf = (*iter_trk)->ndof();
1191 m_trkchisq = (*iter_trk)->chi2();
1192
1193 if (debug_ == 4) cout<<"Ea from RecMdcTrackCol..." <<(*iter_trk)->err()<<endl;
1194
1195 StatusCode sc3 = m_nt3->write();
1196 if( sc3.isFailure() ) cout<<"Ntuple3 filling failed!"<<endl;
1197 }
1198 //end of track level check and prepare evt check
1199 if(ntuple_&4) {
1200 /*
1201 if(kj == 1) {
1202 trkphi1 = (*iter_trk)->getFi0();
1203 trkr1 = (*iter_trk)->getDr();
1204 trkz1 = (*iter_trk)->getDz();
1205 trkkap1 = (*iter_trk)->getCpa();
1206 trktanl1 = (*iter_trk)->getTanl();
1207 trkx1 = trkr1*cos(trkphi1);
1208 trky1 = trkr1*sin(trkphi1);
1209 trkp1 = sqrt(1+trktanl1*trktanl1)/trkkap1;
1210 trkthe1 = M_PI/2-atan(trktanl1);
1211 } else if(kj == 2) {
1212 trkphi2 = (*iter_trk)->getFi0();
1213 trkr2 = (*iter_trk)->getDr();
1214 trkz2 = (*iter_trk)->getDz();
1215 trkkap2 = (*iter_trk)->getCpa();
1216 trktanl2 = (*iter_trk)->getTanl();
1217 trkx2 = trkr2*cos(trkphi2);
1218 trky2 = trkr2*sin(trkphi2);
1219 trkp2 = sqrt(1+trktanl2*trktanl2)/trkkap1;
1220 trkthe2 = M_PI/2-atan(trktanl2);
1221 }
1222 */
1223 }
1224 //end prepare
1225
1226 log << MSG::DEBUG << "retrieved MDC tracks:"
1227 << " Nhits " <<(*iter_trk)->getNhits()
1228 << " Nster " <<(*iter_trk)->nster() <<endreq;
1229 // so ,use this to get the hits vector belong to this track ...
1230 HitRefVec gothits = (*iter_trk)->getVecHits();
1231
1232 MdcRec_trk* rectrk = new MdcRec_trk;
1233
1234 rectrk->id = (*iter_trk)->trackId();
1235 rectrk->chiSq = (*iter_trk)->chi2();
1236 rectrk->ndf = (*iter_trk)->ndof();
1237 rectrk->fiTerm = (*iter_trk)->getFiTerm();
1238 rectrk->nhits = (*iter_trk)->getNhits();
1239 rectrk->nster = (*iter_trk)->nster();
1240 rectrk->nclus = (*iter_trk)->getNcluster();
1241 rectrk->stat = (*iter_trk)->stat();
1242 status_temp = (*iter_trk)->stat();
1243 MdcRec_trk_add* trkadd = new MdcRec_trk_add;
1244 trkadd->id = (*iter_trk)->trackId();
1245 trkadd->quality = 0;
1246 trkadd->kind = 1;
1247 trkadd->decision = 0;
1248 trkadd->body = rectrk;
1249 rectrk->add = trkadd;
1250
1251 for ( int i=0; i<5; i++) {
1252 rectrk->helix[i] = (*iter_trk)->helix()[i];
1253 if( i<3 ) rectrk->pivot[i] = (*iter_trk)->getPivot()[i];
1254 for( int j = 1; j<i+2;j++) {
1255 rectrk->error[i*(i+1)/2+j-1] = (*iter_trk)->err()(i+1,j);
1256 }
1257 }
1258 std::sort(gothits.begin(), gothits.end(), order_rechits);
1259 HitRefVec::iterator it_gothit = gothits.begin();
1260 for( ; it_gothit != gothits.end(); it_gothit++) {
1261
1262 if( (*it_gothit)->getStat() != 1 ) {
1263 if(activeonly_) {
1264 log<<MSG::WARNING<<"this hit is not used in helix fitting!"<<endreq;
1265 continue;
1266 }
1267 }
1268
1269 log << MSG::DEBUG << "retrieved hits in MDC tracks:"
1270 << " hits DDL " <<(*it_gothit)->getDriftDistLeft()
1271 << " hits DDR " <<(*it_gothit)->getDriftDistRight()
1272 << " error DDL " <<(*it_gothit)->getErrDriftDistLeft()
1273 << " error DDR " <<(*it_gothit)->getErrDriftDistRight()
1274 << " id of hit "<<(*it_gothit)->getId()
1275 << " track id of hit "<<(*it_gothit)->getTrkId()
1276 << " hits ADC " <<(*it_gothit)->getAdc() << endreq;
1277
1278 MdcRec_wirhit* whit = new MdcRec_wirhit;
1279 whit->id = (*it_gothit)->getId();
1280 whit->ddl = (*it_gothit)->getDriftDistLeft();
1281 whit->ddr = (*it_gothit)->getDriftDistRight();
1282 whit->erddl = (*it_gothit)->getErrDriftDistLeft();
1283 whit->erddr = (*it_gothit)->getErrDriftDistRight();
1284 whit->pChiSq = (*it_gothit)->getChisqAdd();
1285 whit->lr = (*it_gothit)->getFlagLR();
1286 whit->stat = (*it_gothit)->getStat();
1287 mdcid = (*it_gothit)->getMdcId();
1288 int layid = MdcID::layer(mdcid);
1289 int localwid = MdcID::wire(mdcid);
1290 int w0id = geosvc->Layer(layid)->Wirst();
1291 int wid = w0id + localwid;
1292 log << MSG::INFO
1293 << "lr from PR: "<<whit->lr
1294 << " layerId = " << layid
1295 << " wireId = " << localwid
1296 << endreq;
1297
1298 const MdcGeoWire * const wirgeo = geosvc->Wire(wid);
1299
1300 //std::cout<<"the track id of *it_gothit... "<<(*it_gothit)->getTrackId()<<std::endl;
1301 whit->rechitptr = *it_gothit;
1302 whit->geo = wirgeo;
1303 whit->dat = 0;
1304 whit->trk = rectrk;
1305 whit->tdc = (*it_gothit)->getTdc();
1306 whit->adc= (*it_gothit)->getAdc();
1307 rectrk->hitcol.push_back(whit);
1308 mhit_mgr->push_back(*whit);
1309 }
1310 mtrk_mgr->push_back(*rectrk);
1311 mtrkadd_mgr->push_back(*trkadd);
1312
1313 delete rectrk;
1314 delete trkadd;
1315 }
1316
1317 // check trkcol: evt level
1318 if(ntuple_&4) {
1319 m_trkdelx = trkx1 - trkx2;
1320 m_trkdely = trky1 - trky2;
1321 m_trkdelz = trkz1 - trkz2;
1322 m_trkdelthe = trkthe1 + trkthe2;
1323 m_trkdelphi = trkphi1- trkphi2;
1324 m_trkdelp = trkp1 - trkp2;
1325 StatusCode sc4 = m_nt4->write();
1326 if( sc4.isFailure() ) cout<<"Ntuple4 filling failed!"<<endl;
1327 }
1328
1329 if(debug_ == 4) { std::cout<<"before refit,ntrk,nhits,nadd..."<<mtrk_mgr->size()
1330 <<"********"<<mhit_mgr->size()<<"****"<<mtrkadd_mgr->size()<<endl;
1331 }
1332
1333 if(useNCGem_>0) makeGemHitsCol();
1334
1335 // Actual fitter procedure :
1336 //cout << "m_trackid" << m_trackid << endl;
1337 //cout << "m_qua" << m_qua << endl;
1338 //cout << "m_esti" << m_esti1_r[0] << endl;
1339 if(usage_ == 0) kalman_fitting_anal();
1340 if(usage_ == 1) kalman_fitting_calib();
1341 double mdang = 180.0 - csmp3[0].angle(csmp3[1].unit())*180.0/M_PI;
1342 double mdphi = 180.0 - fabs(csmphi[0]-csmphi[1])*180.0/M_PI;
1343 //std::cout<<"before refit,ntrk,nhits,nadd..."<<mtrk_mgr->size()<<" , "<<mhit_mgr->size()<<" , "<<mtrkadd_mgr->size()<<endl;
1344 if(usage_ == 2 && (mtrk_mgr->size())==2 && fabs(mdang)<m_dangcut && fabs(mdphi)<m_dphicut) kalman_fitting_csmalign();
1345 if(usage_ == 3 && (mtrk_mgr->size())==1 && status_temp==-1) kalman_fitting_MdcxReco_Csmc_Sew();
1346
1347 log << MSG::DEBUG <<"after kalman_fitting(),but in execute...."<<endreq;
1348 clearTables();
1349
1350
1351 ///*
1352 // --- test for songxy
1353 MdcID mdcId;
1354 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
1355 //cout<<"------------------------ new event ---------------------"<<endl;
1356 //cout<<"recmdckaltrkCol->size()="<<recmdckaltrkCol->size()<<endl;
1357 //cout<<"--------------------------------------------------------"<<endl;
1359 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
1360 int i_trk=0;
1361 for(;KalTrk !=recmdckaltrkCol->end();KalTrk++){
1362 //cout<<"*** track "<<i_trk++<<" ***"<<endl;
1363 for(int hypo=0; hypo<5; hypo++)
1364 {
1365 if((*KalTrk)->getStat(0,hypo)==1) nFailedTrks[hypo]++;
1366 }
1367 //if(eventNo==1080) cout<<"mu_status = "<<(*KalTrk)->getStat(0,1)<<endl;
1368 HelixSegRefVec gothelixsegs = (*KalTrk)->getVecHelixSegs();
1369 HelixSegRefVec::iterator iter_hit = gothelixsegs.begin();
1370 //if(iter_hit == gothelixsegs.end())cout<<"iter_hit == gothelixsegs.end()"<<endl;
1371 int nhitofthistrk=0;
1372 for( ; iter_hit != gothelixsegs.end(); iter_hit++){
1373 nhitofthistrk++;
1374 //cout<<"layerId: "<<(*iter_hit)->getLayerId()<<endl;
1375 //cout<<"Identifier: "<<(*iter_hit)->getMdcId()<<endl;
1376 //cout<<"layerId: "<<mdcId.layer((*iter_hit)->getMdcId())<<endl;
1377 //cout<<"getDT: "<<(*iter_hit)->getDT()<<endl;
1378 }
1379 iter_hit=gothelixsegs.begin();
1380 //for(int m=0; m<nhitofthistrk/5;m++){
1381 // identifier = (*iter_hit) -> getMdcId();
1382 //}
1383 }
1384 // */
1385
1386 // --- test for getStat(2, pid)
1387 /*
1388 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
1389 SmartDataPtr<RecMdcTrackCol> mdcTrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
1390 //RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
1391 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
1392 int i_trk=0;
1393 for(RecMdcTrackCol::iterator mdcTrk = mdcTrkCol->begin(); KalTrk !=recmdckaltrkCol->end(); KalTrk++, mdcTrk++){
1394 cout<<"*** track "<<i_trk++<<" ***"<<endl;
1395 cout<<"trackId mdc: "<<(*mdcTrk)->trackId()<<endl;
1396 cout<<"trackId kal: "<<(*KalTrk)->trackId()<<endl;
1397 bool KalIsValid = true;
1398 for(int i_pid=0; i_pid<5; i_pid++) {
1399 cout<<"pid "<<i_pid<<" state 0 : "<<(*KalTrk)->getStat(0, i_pid)<<endl;
1400 cout<<"pid "<<i_pid<<" state 1 : "<<(*KalTrk)->getStat(1, i_pid)<<endl;
1401 if((*KalTrk)->getStat(0, i_pid)==1) {
1402 KalIsValid = false;
1403 switch(i_pid) {
1404 case 0: RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
1405 break;
1406 case 1: RecMdcKalTrack::setPidType(RecMdcKalTrack::muon);
1407 break;
1408 case 2: RecMdcKalTrack::setPidType(RecMdcKalTrack::pion);
1409 break;
1410 case 3: RecMdcKalTrack::setPidType(RecMdcKalTrack::kaon);
1411 break;
1412 case 4: RecMdcKalTrack::setPidType(RecMdcKalTrack::proton);
1413 break;
1414 }
1415 cout<<"Helix Kal: "<<(*KalTrk)->helix()<<endl;
1416 cout<<"Helix Kal err: "<<(*KalTrk)->err()<<endl;
1417 }
1418 }
1419 if(!KalIsValid) {
1420 cout<<"Helix Mdc: "<<(*mdcTrk)->helix()<<endl;
1421 cout<<"Helix Mdc err: "<<(*mdcTrk)->err()<<endl;
1422 }
1423 }
1424 */
1425 if(ifProdNt11)
1426 {
1427 SmartDataPtr<Event::CgemMcHitCol> cgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
1428 if (!cgemMcHitCol){
1429 log << MSG::WARNING << "Could not retrieve Cgem MC truth" << endreq;
1430 return StatusCode::FAILURE;
1431 }
1432 m_evt4=eventHeader->eventNumber();
1433 Event::CgemMcHitCol::iterator iter_truth = cgemMcHitCol->begin();
1434 int jj=0;
1435 double dprex,dprey,dprez,dpostx,dposty,dpostz;
1436 int layer;
1437 for(; iter_truth != cgemMcHitCol->end(); ++iter_truth){
1438 layer = (*iter_truth)->GetLayerID();
1439 dprex = (*iter_truth)->GetPositionXOfPrePoint();
1440 dprey = (*iter_truth)->GetPositionYOfPrePoint();
1441 dprez = (*iter_truth)->GetPositionZOfPrePoint();
1442 dpostx = (*iter_truth)->GetPositionXOfPostPoint();
1443 dposty = (*iter_truth)->GetPositionYOfPostPoint();
1444 dpostz = (*iter_truth)->GetPositionZOfPostPoint();
1445
1446 double midx=0;
1447 double midy=0;
1448 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(layer);
1449 double diR = CgemLayer->getInnerROfGapD();
1450 double dmR = CgemLayer->getMiddleROfGapD();
1451 double doR = CgemLayer->getOuterROfGapD();
1452 if((dprex >=0&&dprey>=0)||(dprex <0&&dprey>=0)){
1453 //m_dtphi[jj] = acos(dprex/dr_layer[layer]);
1454 m_dtphi[jj] = acos(dprex/diR);
1455 m_dtv[jj] = dprez;
1456 //m_dtpostphi[jj] = acos(dpostx/dor_layer[layer]);
1457 m_dtpostphi[jj] = acos(dpostx/doR);
1458 m_dtpostz[jj]= dpostz;
1459 }
1460 if((dprex <0&&dprey<0)||(dprex >=0&&dprey<0)){
1461 //m_dtphi[jj] = -acos(dprex/dr_layer[layer]);
1462 m_dtphi[jj] = -acos(dprex/diR);
1463 m_dtv[jj] = dprez;
1464 //m_dtpostphi[jj] = -acos(dpostx/dor_layer[layer]);
1465 m_dtpostphi[jj] = -acos(dpostx/doR);
1466 m_dtpostz[jj]= dpostz;
1467 }
1468 midx=(dprex+dpostx)/2;
1469 midy=(dprey+dposty)/2;
1470 if((midx>=0&&midy>=0)||(midx<0&&midy>=0)){
1471 //m_dtphi[jj]=acos(midx/dmr_layer[layer]);
1472 m_dtphi[jj]=acos(midx/dmR);
1473 }
1474 if((midx<0&&midy<0)||(midx>=0&&midy<0)){
1475 //m_dtphi[jj]=-acos(midx/dmr_layer[layer]);
1476 m_dtphi[jj]=-acos(midx/dmR);
1477 }
1478 m_dtv[jj] = (m_dtv[jj]+m_dtpostz[jj])/20;
1479 m_tlayer[jj] = layer;
1480 jj++;
1481 }
1482 m_ntruth = jj;
1483
1484 m_nt11->write();
1485 }
1486
1487
1488
1489 return StatusCode::SUCCESS;
1490}
1491
1492// fill TDS:
1494 RecMdcKalTrack* trk , int l_mass) {
1495
1496 HepPoint3D IP(0,0,0);
1497 track.pivot(IP);
1498 // Fit quality
1499 int iqual(1);
1500 int trasster = TrasanTRK.nster, trakster = track.nster(),
1501 trasax(TrasanTRK.nhits-trasster), trakax(track.nchits()-trakster);
1502
1503
1504 if(ntuple_&256){
1505 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
1506 if(!eventHeader){
1507 cout<<"Open event header file failed!"<<endl;
1508 }
1509 m_run_kal = eventHeader->runNumber();
1510 m_event_kal = eventHeader->eventNumber();
1511
1512 m_trkid_kal = track.trasan_id();
1513 if(l_mass==0){
1514 //m_dropedHits_kal_e = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1515 m_dropedHits_kal_e = TrasanTRK.ndf+5-track.nchits();
1516 m_kappa2_kal_e = TrasanTRK.helix[2]*track.a()[2];
1517 m_trackNhits_kal_e = track.nchits();
1518 m_trackNster_kal_e = track.nster();
1519 m_trackNaxis_kal_e = track.nchits()-track.nster();
1520 m_chi2_kal_e = track.chiSq();
1521 m_Ea00_kal_e = track.Ea()[0][0];
1522 m_Ea11_kal_e = track.Ea()[1][1];
1523 m_Ea22_kal_e = track.Ea()[2][2];
1524 m_Ea33_kal_e = track.Ea()[3][3];
1525 m_Ea44_kal_e = track.Ea()[4][4];
1526 }
1527 else if(l_mass==1){
1528 //m_dropedHits_kal_mu = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1529 m_dropedHits_kal_mu = TrasanTRK.ndf+5-track.nchits();
1530 m_kappa2_kal_mu = TrasanTRK.helix[2]*track.a()[2];
1531 m_trackNhits_kal_mu = track.nchits();
1532 m_trackNster_kal_mu = track.nster();
1533 m_trackNaxis_kal_mu = track.nchits()-track.nster();
1534 m_chi2_kal_mu = track.chiSq();
1535 m_Ea00_kal_mu = track.Ea()[0][0];
1536 m_Ea11_kal_mu = track.Ea()[1][1];
1537 m_Ea22_kal_mu = track.Ea()[2][2];
1538 m_Ea33_kal_mu = track.Ea()[3][3];
1539 m_Ea44_kal_mu = track.Ea()[4][4];
1540 //if(myEventNo==1080) cout<<"m_dropedHits_kal_mu = "<<m_dropedHits_kal_mu<<endl;
1541 }
1542 else if(l_mass==2){
1543 //m_dropedHits_kal_pi = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1544 m_dropedHits_kal_pi = TrasanTRK.ndf+5-track.nchits();
1545 m_kappa2_kal_pi = TrasanTRK.helix[2]*track.a()[2];
1546 m_trackNhits_kal_pi = track.nchits();
1547 m_trackNster_kal_pi = track.nster();
1548 m_trackNaxis_kal_pi = track.nchits()-track.nster();
1549 m_chi2_kal_pi = track.chiSq();
1550 m_Ea00_kal_pi = track.Ea()[0][0];
1551 m_Ea11_kal_pi = track.Ea()[1][1];
1552 m_Ea22_kal_pi = track.Ea()[2][2];
1553 m_Ea33_kal_pi = track.Ea()[3][3];
1554 m_Ea44_kal_pi = track.Ea()[4][4];
1555
1556 }
1557 else if(l_mass==3){
1558 //m_dropedHits_kal_k = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1559 m_dropedHits_kal_k = TrasanTRK.ndf+5-track.nchits();
1560 m_kappa2_kal_k = TrasanTRK.helix[2]*track.a()[2];
1561 m_trackNhits_kal_k = track.nchits();
1562 m_trackNster_kal_k = track.nster();
1563 m_trackNaxis_kal_k = track.nchits()-track.nster();
1564 m_chi2_kal_k = track.chiSq();
1565 m_Ea00_kal_k = track.Ea()[0][0];
1566 m_Ea11_kal_k = track.Ea()[1][1];
1567 m_Ea22_kal_k = track.Ea()[2][2];
1568 m_Ea33_kal_k = track.Ea()[3][3];
1569 m_Ea44_kal_k = track.Ea()[4][4];
1570
1571 }
1572 else if(l_mass==4){
1573 //m_dropedHits_kal_p = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1574 m_dropedHits_kal_p = TrasanTRK.ndf+5-track.nchits();
1575 m_kappa2_kal_p = TrasanTRK.helix[2]*track.a()[2];
1576 m_trackNhits_kal_p = track.nchits();
1577 m_trackNster_kal_p = track.nster();
1578 m_trackNaxis_kal_p = track.nchits()-track.nster();
1579 m_chi2_kal_p = track.chiSq();
1580 m_Ea00_kal_p = track.Ea()[0][0];
1581 m_Ea11_kal_p = track.Ea()[1][1];
1582 m_Ea22_kal_p = track.Ea()[2][2];
1583 m_Ea33_kal_p = track.Ea()[3][3];
1584 m_Ea44_kal_p = track.Ea()[4][4];
1585
1586 }
1587 }
1588
1589
1590 // if (TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits()>fitnocut_ ||
1591 if(TrasanTRK.ndf+5-track.nchits()>fitnocut_
1592 || TrasanTRK.helix[2]*track.a()[2]<0)
1593 iqual = 0;
1594
1595 if (debug_ == 4) {
1596 cout<< "trasster trakster trasax trakax TrasK trackK iqual"<<endl
1597 <<trasster<<" "<<trakster<<" "<<trasax<<" "<<trakax
1598 <<" "<<TrasanTRK.helix[2]<<" "<<track.a()[2]<<" "<<iqual<<endl;
1599 cout<<"FillTds> track.chiSq..."<<track.chiSq()<<" nchits "<<track.nchits()
1600 <<" nster "<<track.nster()<<" iqual "<<iqual<<" track.Ea "<< track.Ea()<<endl;
1601
1602 cout<<"fillTds>.....track.Ea[2][2] "<<track.Ea()[2][2]<<endl;
1603 cout << " TRASAN stereo = " << trasster
1604 << " and KalFitTrack = " << trakster << std::endl;
1605 cout << " TRASAN axial = " << trasax
1606 << " and KalFitTrack = " << trakax << std::endl;
1607
1608 if (!iqual) {
1609 cout << "...there is a problem during fit !! " << std::endl;
1610 if (trasster-trakster>5)
1611 cout << " because stereo " << trasster-trakster << std::endl;
1612 if (trasax-trakax >5)
1613 cout << " because axial " << std::endl;
1614 if (TrasanTRK.helix[2]*track.a()[2]<0)
1615 cout << " because kappa sign " << std::endl;
1616 }
1617 }
1618 // Protection : if any problem, we keep the original information !!!!
1619 if (track.nchits() > 5 && track.nster() > 1 &&
1620 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1621 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1622 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1623 track.Ea()[4][4] > 0 && iqual) {
1624 if(debug_ == 4) cout<<"fillTds>.....going on "<<endl;
1625 trk->setStat(0,0,l_mass);
1626 trk->setMass(track.mass(),l_mass);
1627
1628 // chisq & ndf
1629 trk->setChisq(track.chiSq(),0,l_mass);
1630 trk->setNdf(track.nchits()-5,0,l_mass);
1631 trk->setNhits(track.nchits(),l_mass);
1632
1633 trk->setFHelix(track.a(),l_mass);
1634 trk->setFError(track.Ea(),l_mass);
1635
1636 } else {
1637
1638 if(debug_==4) cout<<"ALARM: FillTds Not refit with KalFilter!!! lmass="<<l_mass<<endl;
1639 // NOT refit with Kalman filter :
1640 trk->setStat(1,0,l_mass);
1641 trk->setMass(KalFitTrack::mass(l_mass),l_mass);
1642 // chisq & ndf (0 : filter ; 1 : smoother;)
1643 trk->setChisq(TrasanTRK.chiSq,0,l_mass);
1644 //trk->setNdf(TrasanTRK.nhits-5,0,l_mass);
1645 trk->setNdf(TrasanTRK.ndf,0,l_mass);
1646 // nhits
1647 //trk->setNhits(TrasanTRK.nhits,l_mass);
1648 trk->setNhits(TrasanTRK.ndf+5,l_mass);
1649 double a_trasan[5], ea_trasan[15];
1650 for( int i =0 ; i <5; i++){
1651 a_trasan[i] = TrasanTRK.helix[i];
1652 }
1653 for( int j =0 ; j <15; j++){
1654 ea_trasan[j] = TrasanTRK.error[j];
1655 }
1656 trk->setFHelix(a_trasan, l_mass);
1657 trk->setFError(ea_trasan,l_mass);
1658 }
1659 //if(l_mass==1&&m_event_kal==1080) cout<<"mu_status_filled = "<<trk->getStat(0,l_mass)<<endl;
1660}
1661
1662// Fill Tds :
1664 RecMdcKalTrack* trk , int l_mass) {
1665
1666 HepPoint3D IP(0,0,0);
1667 track.pivot(IP);
1668 // Fit quality
1669 // int iqual(1);
1670 int trasster = TrasanTRK.nster, trakster = track.nster(),
1671 trasax(TrasanTRK.nhits-trasster), trakax(track.nchits()-trakster);
1672 //if (TrasanTRK.nhits-track.nchits()>fitnocut_ ||
1673 if(TrasanTRK.ndf+5-track.nchits()>fitnocut_ ||
1674 TrasanTRK.helix[2]*track.a()[2]<0)
1675 iqual_front_[l_mass] = 0;
1676 if (debug_ == 4) {
1677
1678 cout<<"Nhit from PR "<<TrasanTRK.nhits<<" nhit "<<track.nchits()<<endl;
1679 cout<< "trasster trakster trasax trakax TrasK trackK iqual"<<endl
1680 <<trasster<<" "<<trakster<<" "<<trasax<<" "<<trakax
1681 <<" "<<TrasanTRK.helix[2]<<" "<<track.a()[2]<<" "<<iqual_front_[l_mass]<<endl;
1682 cout<<"FillTds_lead> track.chiSq..."<<track.chiSq()<<" nchits "<<track.nchits()
1683 <<" nster "<<track.nster()<<" iqual_front_[l_mass] "<<iqual_front_[l_mass]<<" track.Ea "<<track.Ea()<<endl;
1684
1685 cout << " TRASAN stereo = " << trasster
1686 << " and KalFitTrack = " << trakster << std::endl;
1687 cout << " TRASAN axial = " << trasax
1688 << " and KalFitTrack = " << trakax << std::endl;
1689
1690 if (!iqual_front_[l_mass]) {
1691 cout << "...there is a problem during fit !! " << std::endl;
1692 if (trasster-trakster>5)
1693 cout << " because stereo " << trasster-trakster << std::endl;
1694 if (trasax-trakax >5)
1695 cout << " because axial " << std::endl;
1696 if (TrasanTRK.helix[2]*track.a()[2]<0)
1697 cout << " because kappa sign " << std::endl;
1698 }
1699 }
1700 // Protection : if any problem, we keep the original information !!!!
1701 if (track.nchits() > 5 && track.nster() > 1 &&
1702 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1703 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1704 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1705 track.Ea()[4][4] > 0 && iqual_front_[l_mass]) {
1706
1707 trk->setStat(0,0,l_mass);
1708 trk->setMass(track.mass(),l_mass);
1709 trk->setChisq(track.chiSq(),0,l_mass);
1710 trk->setNdf(track.nchits()-5,0,l_mass);
1711 trk->setNhits(track.nchits(),l_mass);
1712 //trkid
1713 trk->setTrackId(TrasanTRK.id);
1714
1715 if (debug_ == 4) cout<<" trasan id...1 "<<TrasanTRK.id<<endl;
1716
1717 trk->setFHelix(track.a(),l_mass);
1718 trk->setFError(track.Ea(),l_mass);
1719
1720 } else {
1721
1722 //cout<<"copy Mdc Helix in fillTds_lead()"<<endl;
1723
1724 if(debug_==4) cout<<"ALARM: FillTds_forMdc Not refit with KalFilter!!! lmass="<<l_mass<<endl;
1725 // NOT refit with Kalman filter :
1726 trk->setStat(1,0,l_mass);
1727 trk->setMass(KalFitTrack::mass(l_mass),l_mass);
1728
1729 // chisq & ndf
1730 trk->setChisq(TrasanTRK.chiSq,0,l_mass);
1731 //trk->setNdf(TrasanTRK.nhits-5,0,l_mass);
1732 trk->setNdf(TrasanTRK.ndf,0,l_mass);
1733 //trkid
1734 trk->setTrackId(TrasanTRK.id);
1735
1736 if (debug_ ==4) cout<<" trasan id...2 "<<TrasanTRK.id<<endl;
1737
1738 // nhits
1739 //trk->setNhits(TrasanTRK.nhits,l_mass);
1740 trk->setNhits(TrasanTRK.ndf+5,l_mass);
1741 double a_trasan[5], ea_trasan[15];
1742 for( int i =0 ; i <5; i++){
1743 a_trasan[i] = TrasanTRK.helix[i];
1744 }
1745 for( int j =0 ; j <15; j++){
1746 ea_trasan[j] = TrasanTRK.error[j];
1747 }
1748 trk->setFHelix(a_trasan,l_mass);
1749 trk->setFError(ea_trasan,l_mass);
1750 // trk->setFHelix(TrasanTRK.helix,l_mass);
1751 // trk->setFError(TrasanTRK.error,l_mass);
1752 }
1753}
1754
1755
1756
1757
1759 RecMdcKalTrack* trk, int l_mass)
1760{
1761 //cout<<"call fillTds_ip() done!"<<endl;
1762 HepPoint3D IP(0,0,0);
1763 track.pivot(IP);
1764
1765 if (debug_ == 4&& l_mass==lead_) {
1766 cout << "fillTds_IP>......"<<endl;
1767 cout << " dr = " << track.a()[0]
1768 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
1769 cout << " phi0 = " << track.a()[1]
1770 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
1771 cout << " PT = " << 1/track.a()[2]
1772 << ", Er_kappa =" << sqrt(track.Ea()[2][2]) << std::endl;
1773 cout << " dz = " << track.a()[3]
1774 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
1775 cout << " tanl = " << track.a()[4]
1776 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
1777 }
1778
1779
1780 //cout<<"start to get the event!"<<endl;
1781
1782
1783
1784
1785 //cout<<"get the event done!"<<endl;
1786
1787/*
1788 if(ntuple_&256){
1789
1790 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
1791 if(!eventHeader){
1792 cout<<"Open event header file failed!"<<endl;
1793 }
1794// cout<<__LINE__<<endl;
1795 int run = eventHeader->runNumber();
1796// cout<<__LINE__<<endl;
1797 //m_run_kal = eventHeader->runNumber();
1798 m_run_kal = run;
1799// cout<<__LINE__<<endl;
1800 m_event_kal = eventHeader->eventNumber();
1801// cout<<__LINE__<<endl;
1802
1803 if(l_mass==0){
1804// cout<<__LINE__<<endl;
1805 m_dropedHits_kal_e = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1806// cout<<__LINE__<<endl;
1807 m_kappa2_kal_e = TrasanTRK.helix[2]*track.a()[2];
1808// cout<<__LINE__<<endl;
1809 m_trackNhits_kal_e = track.nchits();
1810// cout<<__LINE__<<endl;
1811 m_trackNster_kal_e = track.nster();
1812// cout<<__LINE__<<endl;
1813 m_trackNaxis_kal_e = track.nchits()-track.nster();
1814// cout<<__LINE__<<endl;
1815 m_chi2_kal_e = track.chiSq();
1816// cout<<__LINE__<<endl;
1817 m_Ea00_kal_e = track.Ea()[0][0];
1818// cout<<__LINE__<<endl;
1819 m_Ea11_kal_e = track.Ea()[1][1];
1820// cout<<__LINE__<<endl;
1821 m_Ea22_kal_e = track.Ea()[2][2];
1822// cout<<__LINE__<<endl;
1823 m_Ea33_kal_e = track.Ea()[3][3];
1824// cout<<__LINE__<<endl;
1825 m_Ea44_kal_e = track.Ea()[4][4];
1826// cout<<__LINE__<<endl;
1827
1828 }
1829 else if(l_mass==1){
1830 m_dropedHits_kal_mu = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1831 m_kappa2_kal_mu = TrasanTRK.helix[2]*track.a()[2];
1832 m_trackNhits_kal_mu = track.nchits();
1833 m_trackNster_kal_mu = track.nster();
1834 m_trackNaxis_kal_mu = track.nchits()-track.nster();
1835 m_chi2_kal_mu = track.chiSq();
1836 m_Ea00_kal_mu = track.Ea()[0][0];
1837 m_Ea11_kal_mu = track.Ea()[1][1];
1838 m_Ea22_kal_mu = track.Ea()[2][2];
1839 m_Ea33_kal_mu = track.Ea()[3][3];
1840 m_Ea44_kal_mu = track.Ea()[4][4];
1841
1842
1843 }
1844 else if(l_mass==2){
1845 m_dropedHits_kal_pi = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1846 m_kappa2_kal_pi = TrasanTRK.helix[2]*track.a()[2];
1847 m_trackNhits_kal_pi = track.nchits();
1848 m_trackNster_kal_pi = track.nster();
1849 m_trackNaxis_kal_pi = track.nchits()-track.nster();
1850 m_chi2_kal_pi = track.chiSq();
1851 m_Ea00_kal_pi = track.Ea()[0][0];
1852 m_Ea11_kal_pi = track.Ea()[1][1];
1853 m_Ea22_kal_pi = track.Ea()[2][2];
1854 m_Ea33_kal_pi = track.Ea()[3][3];
1855 m_Ea44_kal_pi = track.Ea()[4][4];
1856
1857 }
1858 else if(l_mass==3){
1859 m_dropedHits_kal_k = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1860 m_kappa2_kal_k = TrasanTRK.helix[2]*track.a()[2];
1861 m_trackNhits_kal_k = track.nchits();
1862 m_trackNster_kal_k = track.nster();
1863 m_trackNaxis_kal_k = track.nchits()-track.nster();
1864 m_chi2_kal_k = track.chiSq();
1865 m_Ea00_kal_k = track.Ea()[0][0];
1866 m_Ea11_kal_k = track.Ea()[1][1];
1867 m_Ea22_kal_k = track.Ea()[2][2];
1868 m_Ea33_kal_k = track.Ea()[3][3];
1869 m_Ea44_kal_k = track.Ea()[4][4];
1870
1871 }
1872 else if(l_mass==4){
1873 m_dropedHits_kal_p = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1874 m_kappa2_kal_p = TrasanTRK.helix[2]*track.a()[2];
1875 m_trackNhits_kal_p = track.nchits();
1876 m_trackNster_kal_p = track.nster();
1877 m_trackNaxis_kal_p = track.nchits()-track.nster();
1878 m_chi2_kal_p = track.chiSq();
1879 m_Ea00_kal_p = track.Ea()[0][0];
1880 m_Ea11_kal_p = track.Ea()[1][1];
1881 m_Ea22_kal_p = track.Ea()[2][2];
1882 m_Ea33_kal_p = track.Ea()[3][3];
1883 m_Ea44_kal_p = track.Ea()[4][4];
1884
1885 }
1886
1887
1888
1889 //cout<<"fill the ntuple done!"<<endl;
1890
1891 //StatusCode sc7 = m_nt7 ->write();
1892
1893 //if(sc7.isFailure()) cout<<" Write Kalfit failure ntuple failed !"<<endl;
1894
1895 //cout<<"save the ntuple done!"<<endl;
1896 }
1897*/
1898
1899
1900 //if (TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits()>fitnocut_ ||
1901 if (TrasanTRK.ndf+5-track.nchits()>fitnocut_ ||
1902 TrasanTRK.helix[2]*track.a()[2]<0)
1903 iqual_front_[l_mass] = 0;
1904
1905
1906 if (track.nchits() > 5 && track.nster() > 1 &&
1907 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1908 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1909 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1910 track.Ea()[4][4] > 0 && iqual_front_[l_mass]) {
1911
1912 // fill track information
1913 double dr = track.a()[0];
1914 double phi0 = track.a()[1];
1915 double kappa = track.a()[2];
1916 double dz = track.a()[3];
1917 double tanl = track.a()[4];
1918
1919 // vertex of the track
1920 double vx = dr*cos(phi0);
1921 double vy = dr*sin(phi0);
1922 double vz = dz;
1923
1924 // see Belle note148 for the formulas
1925 // initial momentum of the track
1926 if(0==kappa) kappa = 10e-10;
1927 double px = -sin(phi0)/fabs(kappa);
1928 double py = cos(phi0)/fabs(kappa);
1929 double pz = tanl/fabs(kappa);
1930
1931 trk->setX(vx, l_mass);
1932 trk->setY(vy, l_mass);
1933 trk->setZ(vz, l_mass);
1934 trk->setPx(px, l_mass);
1935 trk->setPy(py, l_mass);
1936 trk->setPz(pz, l_mass);
1937
1938 const HepPoint3D poca(dr*cos(phi0),dr*sin(phi0),dz);
1939 trk->setPoca(poca,l_mass);
1940
1941 trk->setZHelix(track.a(),l_mass);
1942 trk->setZError(track.Ea(),l_mass);
1943
1944
1945 //set charge
1946 int charge=0;
1947 if (kappa > 0.0000000001)
1948 charge = 1;
1949 else if (kappa < -0.0000000001)
1950 charge = -1;
1951 trk->setCharge(charge,l_mass);
1952
1953 //set theta
1954 double ptot = sqrt(px*px+py*py+pz*pz);
1955 trk->setTheta(acos(pz/ptot),l_mass);
1956 }
1957
1958 else{
1959 //cout<<"copy Mdc Helix in fillTds_ip()"<<endl;
1960
1961 if(4==debug_) cout<<"track "<< track.trasan_id() <<", pid "<< l_mass <<" fails"<<endl;
1962
1963 // fill track information
1964 double dr = TrasanTRK.helix[0];
1965 double phi0 = TrasanTRK.helix[1];
1966 double kappa = TrasanTRK.helix[2];
1967 double dz = TrasanTRK.helix[3];
1968 double tanl = TrasanTRK.helix[4];
1969
1970 double vx = dr*cos(phi0);
1971 double vy = dr*sin(phi0);
1972 double vz = dz;
1973
1974 if(0==kappa) kappa = 10e-10;
1975 double px = -sin(phi0)/fabs(kappa);
1976 double py = cos(phi0)/fabs(kappa);
1977 double pz = tanl/fabs(kappa);
1978
1979 trk->setX(vx, l_mass);
1980 trk->setY(vy, l_mass);
1981 trk->setZ(vz, l_mass);
1982
1983 trk->setPx(px, l_mass);
1984 trk->setPy(py, l_mass);
1985 trk->setPz(pz, l_mass);
1986
1987 const HepPoint3D poca(dr*cos(phi0),dr*sin(phi0),dz);
1988
1989 trk->setPoca(poca,l_mass);
1990 //trk->setZHelix(TrasanTRK.helix,l_mass);
1991 //trk->setZError(TrasanTRK.error,l_mass);
1992 double a_trasan[5], ea_trasan[15];
1993 for( int i =0 ; i <5; i++){
1994 a_trasan[i] = TrasanTRK.helix[i];
1995 }
1996 for( int j =0 ; j <15; j++){
1997 ea_trasan[j] = TrasanTRK.error[j];
1998 }
1999 trk->setZHelix(a_trasan,l_mass);
2000 trk->setZError(ea_trasan,l_mass);
2001
2002 //set charge
2003 int charge=0;
2004 if (kappa > 0.0000000001)
2005 charge = 1;
2006 else if (kappa < -0.0000000001)
2007 charge = -1;
2008 trk->setCharge(charge,l_mass);
2009
2010 //set theta
2011 double ptot = sqrt(px*px+py*py+pz*pz);
2012 trk->setTheta(acos(pz/ptot),l_mass);
2013 }
2014
2015 if(4==debug_) {
2017 std::cout<<"px: "<<trk->px()<<" py: "<<trk->py()<<" pz: "<<trk->pz()<<std::endl;
2018 std::cout<<"vx: "<<trk->x()<<" vy: "<<trk->y()<<" vz: "<<trk->z()<<std::endl;
2019 }
2020}
2021
2022
2024 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass)
2025{
2026
2027 HepPoint3D IP(0,0,0);
2028 //track.pivot(IP);
2029
2030 // Fit quality
2031 int iqual(1);
2032
2033 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5) iqual = 0;
2034
2035 if(debug_ == 4) cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0] "<<trk->getNdf(0,2)<<endl;
2036 if(debug_ == 4) cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2037
2038 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2039 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2040 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2041 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2042 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2043 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX &&
2044 iqual) {
2045
2046 // chisq ( for backward filter)
2047
2048 trk->setStat(0,1,l_mass);
2049 trk->setChisq(track.chiSq_back(),1,l_mass);
2050 trk->setNdf(track.ndf_back()-5,1,l_mass);
2051 trk->setLength(track.pathip(),l_mass);
2052 if(debug_ == 4) cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2053 trk->setTof(track.tof(),l_mass);
2054
2056 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2057 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2058 }
2059
2060 // Path length in each MDC layer :
2061 if (pathl_)
2062 for (int i = 0; i<43; i++) {
2063 trk->setPathl(track.pathl()[i],i);
2064 }
2065
2066 trk->setLHelix(track.a(),l_mass);
2067 trk->setLError(track.Ea(),l_mass);
2068 trk->setLPivot(track.pivot(),l_mass);
2069
2070 trk->setLPoint(track.point_last(),l_mass);
2071 trk->setPathSM(track.getPathSM(),l_mass);
2072 trk->setTof(track.getTofSM(),l_mass);
2073 trk->setFiTerm(track.getFiTerm(),l_mass);
2074
2075 if(4 == debug_){
2076 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2077 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2078 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2079 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2080 }
2081
2082 } else {
2083 if(debug_==4) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2084 // NOT refit with Kalman filter :
2085 trk->setStat(1,1,l_mass);
2086 HepPoint3D piv(TrasanTRK.pivot[0],
2087 TrasanTRK.pivot[1],
2088 TrasanTRK.pivot[2]);
2089
2090 HepVector a(5);
2091 for(int i = 0; i < 5; i++)
2092 a[i] = TrasanTRK.helix[i];
2093
2094 HepSymMatrix ea(5);
2095 for(int i = 0, k = 0; i < 5; i++) {
2096 for(int j = 0; j <= i; j++) {
2097 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2098 ea[j][i] = ea[i][j];
2099 }
2100 }
2101
2102 KalFitTrack track_rep(piv, a, ea, lead_,
2103 TrasanTRK.chiSq, TrasanTRK.nhits);
2104 double fiTerm = TrasanTRK.fiTerm;
2105
2106 double fi0 = track_rep.phi0();
2107 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2108 track_rep.center() );
2109 double x = xc.x();
2110 double y = xc.y();
2111 double phi_x;
2112 if( fabs( x ) > 1.0e-10 ){
2113 phi_x = atan2( y, x );
2114 if( phi_x < 0 ) phi_x += 2*M_PI;
2115 } else {
2116 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2117 }
2118 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2119 double dphi = fabs( fiTerm + fi0 - phi_x );
2120 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2121 double tanl = track_rep.tanl();
2122 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2123 if(debug_ == 4) {
2124 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2125 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2126 }
2127 double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2128 double light_speed( 29.9792458 ); // light speed in cm/nsec
2129 double pt( 1.0 / track_rep.kappa() );
2130 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2131
2132 // chisq (2 : for backward filter)
2133 trk->setStat(1,1,l_mass);
2134 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2135 if(debug_ == 4) {
2136 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<endl;
2137 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<endl;
2138 }
2139 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2140 trk->setLength(track_len,l_mass);
2141 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2142 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2143 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2144
2145 track_rep.pivot(IP);
2146
2147 trk->setLHelix(track_rep.a(),l_mass);
2148 trk->setLError(track_rep.Ea(),l_mass);
2149 trk->setLPivot(track.pivot(),l_mass);
2150
2151 /// right???
2152 trk->setLPoint(track.point_last(),l_mass);
2153 trk->setPathSM(track.getPathSM(),l_mass);
2154 trk->setTof(track.getTofSM(),l_mass);
2155 trk->setFiTerm(track.getFiTerm(),l_mass);
2156 }
2157
2158 // test--------
2159 if(debug_ == 4) {
2160
2161 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2162 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2163 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2164
2165 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2166 cout << " dr = " << track.a()[0]
2167 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2168 cout<< " phi0 = " << track.a()[1]
2169 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2170 cout << " PT = " << 1/track.a()[2]
2171 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2172 cout << " dz = " << track.a()[3]
2173 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2174 cout << " tanl = " << track.a()[4]
2175 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2176 cout << " Ea = " << track.Ea() <<endl;
2177 }
2178 // test end ----------
2179}
2180
2182 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass,
2183 RecMdcKalHelixSegCol* segcol)
2184{
2185
2186 HepPoint3D IP(0,0,0);
2187
2188 // attention the pivot problem of the HelixSeg ... ???
2189 track.pivot(IP);
2190 // Fit quality
2191 //int iqual(1);
2192 //if ((trk->getNdf(0,2))-(track.ndf_back()-5)>5)
2193 // form getNdf(0,2) to getNdf(0,1) for muon hypothesis
2194
2195 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5){
2196 iqual_back_ = 0;
2197 }
2198 if(usage_>1){
2199 for(int i=0; i<5; i++) iqual_front_[i] = 1;
2200 iqual_back_ = 1;
2201 }
2202 if(debug_ == 4){
2203 std::cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0][l_mass] "<<trk->getNdf(0,l_mass)<<endl;
2204 std::cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2205 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;
2206 }
2207
2208 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2209 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2210 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2211 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2212 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2213 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX && iqual_front_[l_mass] && iqual_back_){
2214
2215 // chisq ( for backward filter)
2216 //std::cout<<"begin to fillTds_back track no. : "<<(++Tds_back_no)<<std::endl;
2217
2218
2219 HelixSegRefVec helixsegrefvec;
2220 for (vector<KalFitHelixSeg>::iterator it = track.HelixSegs().begin(); it!=track.HelixSegs().end();it ++)
2221 {
2222
2223 //std::cout<<" alpha of KalFitHelixSeg: "<<it->alpha()<<std::endl;
2224 //std::cout<<" doca1 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2225
2226 it->pivot(IP);
2227
2228 //std::cout<<" doca2 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2229
2230 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2231 helixseg->setResIncl(it->residual_include());
2232 helixseg->setResExcl(it->residual_exclude());
2233 if(debug_ == 4) {
2234 std::cout<<"helixseg->Res_inc ..."<<helixseg->getResIncl()<<std::endl;
2235 }
2236 helixseg->setDrIncl(it->a_include()[0]);
2237 helixseg->setFi0Incl(it->a_include()[1]);
2238 helixseg->setCpaIncl(it->a_include()[2]);
2239 helixseg->setDzIncl(it->a_include()[3]);
2240 helixseg->setTanlIncl(it->a_include()[4]);
2241
2242
2243 helixseg->setDrExcl(it->a_exclude()[0]);
2244 helixseg->setFi0Excl(it->a_exclude()[1]);
2245 helixseg->setCpaExcl(it->a_exclude()[2]);
2246 helixseg->setDzExcl(it->a_exclude()[3]);
2247 helixseg->setTanlExcl(it->a_exclude()[4]);
2248
2249 helixseg->setHelixIncl(it->a_include());
2250 helixseg->setErrorIncl(it->Ea_include());
2251
2252 //Helix temp(IP, it->a(), it->Ea());
2253
2254 //std::cout<<" doca3 of KalFitHelixSeg: "<<(temp.approach(*(it->HitMdc()),false))<<std::endl;
2255
2256 helixseg->setHelixExcl(it->a_exclude());
2257 helixseg->setErrorExcl(it->Ea_exclude());
2258 helixseg->setLayerId(it->layer());
2259
2260 if(debug_ == 4) {
2261 std::cout<<"KalFitHelixSeg track id .."<<it->HitMdc()->rechitptr()->getTrkId()<<std::endl;
2262 std::cout<<"helixseg a: "<<it->a()<<std::endl;
2263 std::cout<<"helixseg a_excl: "<<helixseg->getHelixExcl()<<std::endl;
2264 std::cout<<"helixseg a_incl: "<<helixseg->getHelixIncl()<<std::endl;
2265
2266 std::cout<<"helixseg Ea: "<<it->Ea()<<std::endl;
2267 std::cout<<"helixseg Ea_excl: "<<helixseg->getErrorExcl()<<std::endl;
2268 std::cout<<"helixseg Ea_incl: "<<helixseg->getErrorIncl()<<std::endl;
2269
2270 std::cout<<"helixseg layer: "<<it->layer()<<std::endl;
2271 }
2272
2273
2274 helixseg->setTrackId(it->HitMdc()->rechitptr()->getTrkId());
2275 helixseg->setMdcId(it->HitMdc()->rechitptr()->getMdcId());
2276 helixseg->setFlagLR(it->HitMdc()->LR());
2277 helixseg->setTdc(it->HitMdc()->rechitptr()->getTdc());
2278 helixseg->setAdc(it->HitMdc()->rechitptr()->getAdc());
2279 helixseg->setZhit(it->HitMdc()->rechitptr()->getZhit());
2280 helixseg->setTof(it->tof());
2281 helixseg->setDocaIncl(it->doca_include());
2282 helixseg->setDocaExcl(it->doca_exclude());
2283 helixseg->setDD(it->dd());
2284 helixseg->setEntra(it->HitMdc()->rechitptr()->getEntra());
2285 helixseg->setDT(it->dt());
2286 segcol->push_back(helixseg);
2287 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2288 helixsegrefvec.push_back(refhelixseg);
2289
2290 if(ntuple_&8){
2291 m_docaInc = helixseg -> getDocaIncl();
2292 m_docaExc = helixseg -> getDocaExcl();
2293 m_residualInc = helixseg -> getResIncl();
2294 m_residualExc = helixseg -> getResExcl();
2295 m_dd = helixseg -> getDD();
2296 m_lr = helixseg->getFlagLR();
2297 m_tdrift = helixseg -> getDT();
2298 m_layerid = helixseg -> getLayerId();
2299 m_yposition= it->HitMdc()->wire().fwd().y();
2300 m_eventNo = myEventNo;
2301 StatusCode sc6 = m_nt6->write();
2302 if( sc6.isFailure() ) cout<<"Ntuple6 helixseg filling failed!"<<endl;
2303
2304 }
2305 }
2306
2307 trk->setVecHelixSegs(helixsegrefvec, l_mass);
2308 if(debug_ == 4) {
2309 std::cout<<"trk->getVecHelixSegs size..."<<(trk->getVecHelixSegs()).size()<<std::endl;
2310 }
2311 trk->setStat(0,1,l_mass);
2312 trk->setChisq(track.chiSq_back(),1,l_mass);
2313 trk->setNdf(track.ndf_back()-5,1,l_mass);
2314 // add setNhits ,maybe some problem
2315 trk->setNhits(track.ndf_back(),l_mass);
2316 if(!(track.ndf_back()==track.HelixSegs().size())) {
2317 std::cout<<"THEY ARE NOT EQUALL!!!"<<std::endl;
2318 }
2319 trk->setLength(track.pathip(),l_mass);
2320 if(debug_ == 4) {
2321 std::cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2322 }
2323 trk->setTof(track.tof(),l_mass);
2325 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2326 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2327 }
2328 // Path length in each MDC layer :
2329 if (pathl_)
2330 for (int i = 0; i<43; i++) {
2331 trk->setPathl(track.pathl()[i],i);
2332 }
2333 trk->setLHelix(track.a(),l_mass);
2334 trk->setLError(track.Ea(),l_mass);
2335 trk->setLPivot(track.pivot(),l_mass);
2336
2337 trk->setLPoint(track.point_last(),l_mass);
2338 trk->setPathSM(track.getPathSM(),l_mass);
2339 trk->setTof(track.getTofSM(),l_mass);
2340 trk->setFiTerm(track.getFiTerm(),l_mass);
2341 double a_trasan[5], ea_trasan[15];
2342 for( int i =0 ; i <5; i++){
2343 a_trasan[i] = TrasanTRK.helix[i];
2344 }
2345 for( int j =0 ; j <15; j++){
2346 ea_trasan[j] = TrasanTRK.helix[j];
2347 }
2348 trk->setTHelix(a_trasan);
2349 trk->setTError(ea_trasan);
2350
2351 if(4 == debug_){
2352 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2353 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2354 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2355 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2356 }
2357
2358 } else {
2359
2360 if(debug_==4) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2361 // NOT refit with Kalman filter :
2362 trk->setStat(1,1,l_mass);
2363
2364 HepPoint3D piv(TrasanTRK.pivot[0],
2365 TrasanTRK.pivot[1],
2366 TrasanTRK.pivot[2]);
2367
2368 HepVector a(5);
2369 for(int i = 0; i < 5; i++)
2370 a[i] = TrasanTRK.helix[i];
2371
2372 HepSymMatrix ea(5);
2373 for(int i = 0, k = 0; i < 5; i++) {
2374 for(int j = 0; j <= i; j++) {
2375 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2376 ea[j][i] = ea[i][j];
2377 }
2378 }
2379
2380 KalFitTrack track_rep(piv, a, ea, lead_,
2381 TrasanTRK.chiSq, TrasanTRK.nhits);
2382 double fiTerm = TrasanTRK.fiTerm;
2383
2384 double fi0 = track_rep.phi0();
2385 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2386 track_rep.center() );
2387 double x = xc.x();
2388 double y = xc.y();
2389 double phi_x;
2390 if( fabs( x ) > 1.0e-10 ){
2391 phi_x = atan2( y, x );
2392 if( phi_x < 0 ) phi_x += 2*M_PI;
2393 } else {
2394 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2395 }
2396 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2397 double dphi = fabs( fiTerm + fi0 - phi_x );
2398 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2399 double tanl = track_rep.tanl();
2400 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2401 if(debug_ == 4) {
2402 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2403 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2404 }
2405 double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2406 double light_speed( 29.9792458 ); // light speed in cm/nsec
2407 double pt( 1.0 / track_rep.kappa() );
2408 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2409
2410
2411 // chisq (2 : for backward filter)
2412
2413 trk->setStat(1,1,l_mass);
2414 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2415 if(debug_ == 4) {
2416 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<std::endl;
2417 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<std::endl;
2418 }
2419 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2420 trk->setLength(track_len,l_mass);
2421 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2422 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2423 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2424
2425 track_rep.pivot(IP);
2426
2427 trk->setLHelix(track_rep.a(),l_mass);
2428 trk->setLError(track_rep.Ea(),l_mass);
2429 trk->setLPivot(track.pivot(),l_mass);
2430
2431 /// right???
2432 trk->setLPoint(track.point_last(),l_mass);
2433 trk->setPathSM(track.getPathSM(),l_mass);
2434 trk->setTof(track.getTofSM(),l_mass);
2435 trk->setFiTerm(track.getFiTerm(),l_mass);
2436 trk->setTHelix(track_rep.a());
2437 trk->setTError(track_rep.Ea());
2438
2439 }
2440
2441 // test--------
2442 if(debug_ == 4) {
2443 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2444 cout << " dr = " << track.a()[0]
2445 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2446 cout<< " phi0 = " << track.a()[1]
2447 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2448 cout << " PT = " << 1/track.a()[2]
2449 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2450 cout << " dz = " << track.a()[3]
2451 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2452 cout << " tanl = " << track.a()[4]
2453 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2454 cout << " Ea = " << track.Ea() <<endl;
2455 }
2456 // test end ----------
2457}
2458
2460 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass,
2461 RecMdcKalHelixSegCol* segcol, int smoothflag)
2462{
2463
2464 HepPoint3D IP(0,0,0);
2465
2466 // attention the pivot problem of the HelixSeg ... ???
2467 //track.pivot(IP);
2468 // Fit quality
2469 //int iqual(1);
2470 //if ((trk->getNdf(0,2))-(track.ndf_back()-5)>5)
2471 // form getNdf(0,2) to getNdf(0,1) for muon hypothesis
2472
2473 iqual_back_ = 1;
2474 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5){
2475 iqual_back_ = 0;
2476 }
2477
2478 if(debug_ == 4){
2479 std::cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0][l_mass] "<<trk->getNdf(0,l_mass)<<endl;
2480 std::cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2481 }
2482
2483
2484 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2485 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2486 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2487 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2488 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2489 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX && iqual_front_[l_mass] && iqual_back_){
2490
2491 // chisq ( for backward filter)
2492 //std::cout<<"begin to fillTds_back track no. : "<<(++Tds_back_no)<<std::endl;
2493
2494
2495 HelixSegRefVec helixsegrefvec;
2496 for (vector<KalFitHelixSeg>::iterator it = track.HelixSegs().begin(); it!=track.HelixSegs().end();it ++)
2497 {
2498
2499 //std::cout<<" alpha of KalFitHelixSeg: "<<it->alpha()<<std::endl;
2500 //std::cout<<" doca1 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2501
2502 it->pivot(IP);
2503
2504 //std::cout<<" doca2 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2505
2506 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2507 helixseg->setResIncl(it->residual_include());
2508 helixseg->setResExcl(it->residual_exclude());
2509 if(debug_ == 4) {
2510 std::cout<<"helixseg->Res_inc ..."<<helixseg->getResIncl()<<std::endl;
2511 }
2512 // helixseg->setDrIncl(it->a_include()[0]);
2513 // helixseg->setFi0Incl(it->a_include()[1]);
2514 // helixseg->setCpaIncl(it->a_include()[2]);
2515 // helixseg->setDzIncl(it->a_include()[3]);
2516 // helixseg->setTanlIncl(it->a_include()[4]);
2517 //
2518 //
2519 // helixseg->setDrExcl(it->a_exclude()[0]);
2520 // helixseg->setFi0Excl(it->a_exclude()[1]);
2521 // helixseg->setCpaExcl(it->a_exclude()[2]);
2522 // helixseg->setDzExcl(it->a_exclude()[3]);
2523 // helixseg->setTanlExcl(it->a_exclude()[4]);
2524
2525 helixseg->setHelixIncl(it->a_include());
2526 //helixseg->setErrorIncl(it->Ea_include());
2527
2528 //Helix temp(IP, it->a(), it->Ea());
2529
2530 //std::cout<<" doca3 of KalFitHelixSeg: "<<(temp.approach(*(it->HitMdc()),false))<<std::endl;
2531
2532 helixseg->setHelixExcl(it->a_exclude());
2533 //helixseg->setErrorExcl(it->Ea_exclude());
2534 //helixseg->setLayerId(it->layer());
2535
2536 if(debug_ == 4) {
2537 std::cout<<"KalFitHelixSeg track id .."<<it->HitMdc()->rechitptr()->getTrkId()<<std::endl;
2538 std::cout<<"helixseg a: "<<it->a()<<std::endl;
2539 std::cout<<"helixseg a_excl: "<<helixseg->getHelixExcl()<<std::endl;
2540 std::cout<<"helixseg a_incl: "<<helixseg->getHelixIncl()<<std::endl;
2541
2542 std::cout<<"helixseg Ea: "<<it->Ea()<<std::endl;
2543 std::cout<<"helixseg Ea_excl: "<<helixseg->getErrorExcl()<<std::endl;
2544 std::cout<<"helixseg Ea_incl: "<<helixseg->getErrorIncl()<<std::endl;
2545
2546 std::cout<<"helixseg layer: "<<it->layer()<<std::endl;
2547 }
2548
2549
2550 helixseg->setTrackId(it->HitMdc()->rechitptr()->getTrkId());
2551 helixseg->setMdcId(it->HitMdc()->rechitptr()->getMdcId());
2552 helixseg->setFlagLR(it->HitMdc()->LR());
2553 helixseg->setTdc(it->HitMdc()->rechitptr()->getTdc());
2554 helixseg->setAdc(it->HitMdc()->rechitptr()->getAdc());
2555 helixseg->setZhit(it->HitMdc()->rechitptr()->getZhit());
2556 helixseg->setTof(it->tof());
2557 helixseg->setDocaIncl(it->doca_include());
2558 helixseg->setDocaExcl(it->doca_exclude());
2559 helixseg->setDD(it->dd());
2560 helixseg->setEntra(it->HitMdc()->rechitptr()->getEntra());
2561 helixseg->setDT(it->dt());
2562 //cout<<"setDT( "<<it->dt()<<" )"<<endl;
2563 segcol->push_back(helixseg);
2564 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2565 helixsegrefvec.push_back(refhelixseg);
2566 if(ntuple_&8){
2567 m_docaInc = helixseg -> getDocaIncl();
2568 m_docaExc = helixseg -> getDocaExcl();
2569 m_residualInc = helixseg -> getResIncl();
2570 m_residualExc = helixseg -> getResExcl();
2571 m_dd = helixseg -> getDD();
2572 m_lr = helixseg->getFlagLR();
2573 m_tdrift = helixseg -> getDT();
2574 m_layerid = helixseg -> getLayerId();
2575 m_yposition= it->HitMdc()->wire().fwd().y();
2576 m_eventNo = myEventNo;
2577 StatusCode sc6 = m_nt6->write();
2578 if( sc6.isFailure() ) cout<<"Ntuple6 helixseg filling failed!"<<endl;
2579
2580 }
2581 }
2582
2583 trk->setVecHelixSegs(helixsegrefvec, l_mass);
2584 //cout<<"setVecHelixSegs with Kalman hits"<<endl;
2585 if(debug_ == 4) {
2586 std::cout<<"trk->getVecHelixSegs size..."<<(trk->getVecHelixSegs()).size()<<std::endl;
2587 }
2588 trk->setStat(0,1,l_mass);
2589 trk->setChisq(track.chiSq_back(),1,l_mass);
2590 trk->setNdf(track.ndf_back()-5,1,l_mass);
2591 // add setNhits ,maybe some problem
2592 trk->setNhits(track.ndf_back(),l_mass);
2593 if(!(track.ndf_back()==track.HelixSegs().size())) {
2594 std::cout<<"THEY ARE NOT EQUALL!!!"<<std::endl;
2595 }
2596 trk->setLength(track.pathip(),l_mass);
2597 if(debug_ == 4) {
2598 std::cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2599 }
2600 trk->setTof(track.tof(),l_mass);
2602 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2603 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2604 }
2605 // Path length in each MDC layer :
2606 if (pathl_)
2607 for (int i = 0; i<43; i++) {
2608 trk->setPathl(track.pathl()[i],i);
2609 }
2610 trk->setLHelix(track.a(),l_mass);
2611 trk->setLError(track.Ea(),l_mass);
2612 trk->setLPivot(track.pivot(),l_mass);
2613
2614 trk->setLPoint(track.point_last(),l_mass);
2615 trk->setPathSM(track.getPathSM(),l_mass);
2616 trk->setTof(track.getTofSM(),l_mass);
2617 trk->setFiTerm(track.getFiTerm(),l_mass);
2618 double a_trasan[5], ea_trasan[15];
2619 for( int i =0 ; i <5; i++){
2620 a_trasan[i] = TrasanTRK.helix[i];
2621 }
2622 for( int j =0 ; j <15; j++){
2623 ea_trasan[j] = TrasanTRK.helix[j];
2624 }
2625 trk->setTHelix(a_trasan);
2626 trk->setTError(ea_trasan);
2627
2628 if(4 == debug_){
2629 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2630 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2631 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2632 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2633 }
2634
2635 } else {
2636
2637 if(debug_==4) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2638 // NOT refit with Kalman filter :
2639 trk->setStat(1,1,l_mass);
2640
2641 HepPoint3D piv(TrasanTRK.pivot[0],
2642 TrasanTRK.pivot[1],
2643 TrasanTRK.pivot[2]);
2644
2645 HepVector a(5);
2646 for(int i = 0; i < 5; i++)
2647 a[i] = TrasanTRK.helix[i];
2648
2649 HepSymMatrix ea(5);
2650 for(int i = 0, k = 0; i < 5; i++) {
2651 for(int j = 0; j <= i; j++) {
2652 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2653 ea[j][i] = ea[i][j];
2654 }
2655 }
2656
2657 KalFitTrack track_rep(piv, a, ea, lead_,
2658 TrasanTRK.chiSq, TrasanTRK.nhits);
2659 double fiTerm = TrasanTRK.fiTerm;
2660
2661 double fi0 = track_rep.phi0();
2662 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2663 track_rep.center() );
2664 double x = xc.x();
2665 double y = xc.y();
2666 double phi_x;
2667 if( fabs( x ) > 1.0e-10 ){
2668 phi_x = atan2( y, x );
2669 if( phi_x < 0 ) phi_x += 2*M_PI;
2670 } else {
2671 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2672 }
2673 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2674 double dphi = fabs( fiTerm + fi0 - phi_x );
2675 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2676 double tanl = track_rep.tanl();
2677 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2678 if(debug_ == 4) {
2679 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2680 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2681 }
2682 //double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2683 double track_len(fabs( track_rep.radius() * fiTerm * cosl_inv )); // 2010-11-26 added by wangll
2684 //cout<<"track radius : "<<track_rep.radius()<<" "<<track.radius()<<endl;
2685 double light_speed( 29.9792458 ); // light speed in cm/nsec
2686 double pt( 1.0 / track_rep.kappa() );
2687 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2688
2689
2690 // chisq (2 : for backward filter)
2691
2692 trk->setStat(1,1,l_mass);
2693 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2694 if(debug_ == 4) {
2695 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<std::endl;
2696 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<std::endl;
2697 }
2698 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2699 trk->setLength(track_len,l_mass);
2700 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2701 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2702 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2703
2704 //track_rep.pivot(IP);
2705 HepPoint3D LPiovt = track_rep.x(fiTerm);
2706 track_rep.pivot(LPiovt);
2707
2708 trk->setLHelix(track_rep.a(),l_mass);
2709 trk->setLError(track_rep.Ea(),l_mass);
2710 //trk->setLPivot(track.pivot(),l_mass); // commented 2010-09-02
2711 //trk->setLPivot(IP, l_mass); // add 2010-09-02
2712 trk->setLPivot(LPiovt, l_mass); // add 2010-11-25
2713
2714 /// right???
2715 trk->setLPoint(track.point_last(),l_mass);
2716 //trk->setPathSM(track.getPathSM(),l_mass);// commented 2010-11-25 by wangll
2717 trk->setPathSM(track_len,l_mass);// added 2010-11-25 by wangll
2718 //trk->setTof(track.getTofSM(),l_mass);// commented 2010-11-25 by wangll
2719 // trk->setFiTerm(track.getFiTerm(),l_mass); // commented 2010-11-25 by wangll
2720 trk->setFiTerm(fiTerm,l_mass); // added by wangll 2010-11-25
2721 trk->setTHelix(track_rep.a());
2722 trk->setTError(track_rep.Ea());
2723
2724 /*
2725 // --- check track id by wangll 2010-08-15
2726 if(l_mass==lead_) {
2727 //cout<<" ----- bad smooth track -----"<<endl;
2728 //cout<<"l_mass = "<<l_mass<<endl;
2729 int trkId = trk->trackId();
2730 //
2731 // cout<<"track id = "<<trkId<<endl;
2732 // cout<<"THelix: "<<trk->getTHelix()<<endl;
2733 // cout<<"FHelix: "<<trk->getFHelix()<<endl;
2734 // cout<<"size of VecHelixSegs: "<<trk->getVecHelixSegs().size()<<endl;
2735 //
2736 SmartDataPtr<RecMdcTrackCol> mdcTrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
2737 //int nMdcTrk = mdcTrkCol.size();
2738 //cout<<"number of Mdc Tracks: "<<nMdcTrk<<endl;
2739 RecMdcTrackCol::iterator iter_mdcTrk = mdcTrkCol->begin();
2740 bool findMdcTrk = false;
2741 for(; iter_mdcTrk != mdcTrkCol->end(); iter_mdcTrk++) {
2742 if(trkId==(*iter_mdcTrk)->trackId()) {
2743 findMdcTrk = true;
2744 break;
2745 }
2746 }
2747 if(findMdcTrk) {
2748 HitRefVec mdcVecHits = (*iter_mdcTrk)->getVecHits();
2749 int nHits = mdcVecHits.size();
2750 //cout<<"number of Mdc Hits: "<<nHits<<endl;
2751 HelixSegRefVec helixsegrefvec;
2752 HitRefVec::iterator iter_mdcHit = mdcVecHits.begin();
2753 for(int iii=0; iter_mdcHit!=mdcVecHits.end(); iter_mdcHit++,iii++) {
2754 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2755 //cout<<"hit "<<iii<<endl;
2756 //cout<<"getMdcId: "<<(*iter_mdcHit)->getMdcId()<<endl;
2757 //cout<<"getAdc: "<<(*iter_mdcHit)->getAdc()<<endl;
2758 //cout<<"getTdc: "<<(*iter_mdcHit)->getTdc()<<endl;
2759 //cout<<"getDriftT: "<<(*iter_mdcHit)->getDriftT()<<endl;
2760 //cout<<"getZhit: "<<(*iter_mdcHit)->getZhit()<<endl;
2761 //cout<<"getFlagLR: "<<(*iter_mdcHit)->getFlagLR()<<endl;
2762 //cout<<"getDriftDistLeft: "<<(*iter_mdcHit)->getDriftDistLeft()<<endl;
2763 //cout<<"getDriftDistRight: "<<(*iter_mdcHit)->getDriftDistRight()<<endl;
2764 //cout<<"getDoca: "<<(*iter_mdcHit)->getDoca()<<endl;
2765 //cout<<"getEntra: "<<(*iter_mdcHit)->getEntra()<<endl;
2766 //
2767 helixseg->setMdcId((*iter_mdcHit)->getMdcId());
2768 helixseg->setAdc((*iter_mdcHit)->getAdc());
2769 helixseg->setTdc((*iter_mdcHit)->getTdc());
2770 helixseg->setZhit((*iter_mdcHit)->getZhit());
2771 helixseg->setFlagLR((*iter_mdcHit)->getFlagLR());
2772 if((*iter_mdcHit)->getFlagLR()==0) helixseg->setDD((*iter_mdcHit)->getDriftDistLeft());
2773 if((*iter_mdcHit)->getFlagLR()==1) helixseg->setDD((*iter_mdcHit)->getDriftDistRight());
2774 helixseg->setDocaIncl((*iter_mdcHit)->getDoca());
2775 helixseg->setEntra((*iter_mdcHit)->getEntra());
2776 helixseg->setDT((*iter_mdcHit)->getDriftT());
2777 segcol->push_back(helixseg);
2778 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2779 helixsegrefvec.push_back(refhelixseg);
2780 }
2781 trk->setVecHelixSegs(helixsegrefvec);
2782 cout<<"setVecHelixSegs with Mdc hits"<<endl;
2783 }
2784 else cout<<"not find the Mdc Track!";
2785 //cout<<"size of VecHelixSegs: "<<trk->getVecHelixSegs().size()<<endl;
2786 }
2787 */
2788
2789 }
2790
2791 // test--------
2792 if(debug_ == 4) {
2793 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2794 cout << " dr = " << track.a()[0]
2795 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2796 cout<< " phi0 = " << track.a()[1]
2797 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2798 cout << " PT = " << 1/track.a()[2]
2799 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2800 cout << " dz = " << track.a()[3]
2801 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2802 cout << " tanl = " << track.a()[4]
2803 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2804 cout << " Ea = " << track.Ea() <<endl;
2805 }
2806 // test end ----------
2807}
2808
2809//void KalFitAlg::FillTds_helixsegs(KalFitTrack& track,MdcRec_trk& rectrk )
2810
2811void KalFitAlg::sameas(RecMdcKalTrack* trk, int l_mass, int imain)
2812{
2813 // note: for this function,only imain==lead(2) considered
2814 //std::cout<<"BEGINNING THE sameas() function ..."<<std::endl;
2815 trk->setMass(trk->getMass(imain), l_mass);
2816 trk->setLength(trk->getLength(imain), l_mass);
2817 trk->setTof(trk->getTof(imain), l_mass);
2818 trk->setNhits(trk->getNhits(imain), l_mass);
2819
2820 for(int jj = 0; jj<2; jj++) {
2821 trk->setStat(trk->getStat(jj,imain), jj, l_mass);
2822 trk->setChisq(trk->getChisq(jj, l_mass), jj, l_mass);
2823 trk->setNdf(trk->getChisq(jj, l_mass), jj, l_mass);
2824 }
2825 trk->setLHelix(trk->getFHelix(),l_mass);
2826 trk->setLError(trk->getFError(),l_mass);
2827}
2828
2829
2831{
2832 // retrieve Mdc geometry information
2833 IMdcGeomSvc* igeomsvc;
2834 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
2835 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
2836 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
2837 if(!geomsvc){
2838 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
2839 }
2840
2841 HepPoint3D ip(0,0,0);
2842 if(m_usevtxdb==1){
2843 Hep3Vector xorigin(0,0,0);
2844 IVertexDbSvc* vtxsvc;
2845 Gaudi::svcLocator()->service("VertexDbSvc", vtxsvc);
2846 if(vtxsvc->isVertexValid()){
2847 double* dbv = vtxsvc->PrimaryVertex();
2848 double* vv = vtxsvc->SigmaPrimaryVertex();
2849 xorigin.setX(dbv[0]);
2850 xorigin.setY(dbv[1]);
2851 xorigin.setZ(dbv[2]);
2852 }
2853 ip[0] = xorigin[0];
2854 ip[1] = xorigin[1];
2855 ip[2] = xorigin[2];
2856 }
2857
2858 // Estimation of the path length from ip to 1st cylinder
2859
2860 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
2861 work.ignoreErrorMatrix();
2862 work.pivot(ip);
2863
2864
2865 double tanl = track.tanl();
2866 double phi_old = work.phi0();
2867 double phi = track.phi0();
2868
2869 if (fabs(phi - phi_old) > M_PI) {
2870 if (phi > phi_old) phi -= 2 * M_PI;
2871 else phi_old -= 2 * M_PI;
2872 }
2873
2874 double path_zero = fabs(track.radius() * (phi_old-phi)* sqrt(1 + tanl * tanl));
2875 // track.addPathSM(path_zero);
2876
2877
2878 HepSymMatrix Eakal(5,0);
2879 track.pivot(ip);
2880 /// be attention to this inital error matrix of smoother,
2881 /// how is track.Ea() in the next sentence when use it?
2882 Eakal = track.Ea()*matrixg_;
2883 track.Ea(Eakal);
2884
2885 // Mdc part :
2886 unsigned int nhit = track.HitsMdc().size();
2887 int layer_prev = -1;
2888
2889 HepVector pos_old(3,0);
2890 double r0kal_prec(0);
2891 int nhits_read(0);
2892 for( unsigned i=0 ; i < nhit; i++ ) {
2893 int ihit = (nhit-1)-i;
2894 KalFitHitMdc& HitMdc = track.HitMdc(ihit);
2895 const KalFitWire& Wire = HitMdc.wire();
2896
2897 int wireid = Wire.geoID();
2898 nhits_read++;
2899
2900 int layer = Wire.layer().layerId();
2901 if (pathl_ && layer != layer_prev) {
2902
2903 if (debug_ == 4) cout<<"in smoother,layerid "<<layer<<" layer_prev "
2904 <<layer_prev <<" pathl_ "<<pathl_<<endl;
2905
2906 // track.PathL(Wire.layer().layerId());
2907 layer_prev = layer;
2908 }
2909
2910 HepPoint3D fwd(Wire.fwd());
2911 HepPoint3D bck(Wire.bck());
2912 Hep3Vector wire = (CLHEP::Hep3Vector)fwd - (CLHEP::Hep3Vector)bck;
2913 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
2914 work.ignoreErrorMatrix();
2915 work.pivot((fwd + bck) * .5);
2916 HepPoint3D x0kal = (work.x(0).z() - bck.z()) / wire.z() * wire + bck;
2917
2918 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
2919 if (wsag_ == 4){
2920 Hep3Vector result;
2921 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
2922 double tension = geowire->Tension();
2923
2924 //std::cout<<" tension: "<<tension<<std::endl;
2925 double zinit(x0kal.z()), lzx(Wire.lzx());
2926
2927 // double A(Wire.Acoef());
2928 double A = 47.35E-6/tension;
2929 double Zp = (zinit - bck.z())*lzx/wire.z();
2930
2931 if(4 == debug_){
2932 std::cout<<" sag in smoother_anal: "<<std::endl;
2933 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
2934 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
2935 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
2936 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
2937 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
2938 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
2939 }
2940
2941 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
2942 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
2943 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
2944
2945 wire.setX(wire.x()/wire.z());
2946 wire.setY(result.z());
2947 wire.setZ(1);
2948
2949 x0kal.setX(result.x());
2950 x0kal.setY(result.y());
2951 }
2952
2953 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
2954
2955 // If x0kal is after the inner wall and x0kal_prec before :
2956 double r0kal = x0kal.perp();
2957 if (debug_ == 4) {
2958 cout<<"wire direction "<<wire<<endl;
2959 cout<<"x0kal "<<x0kal<<endl;
2960 cout<<"smoother::r0kal "<<r0kal<<" r0kal_prec "<<r0kal_prec <<endl;
2961 }
2962
2963 // change PIVOT :
2964 /*cout<<endl<<"before change pivot: "<<endl;//wangll
2965 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2966 cout<<"track.helix = "<<track.a()<<endl;//wangll
2967 */
2968 double pathl(0);
2969 track.pivot_numf(x0kal, pathl);
2970 track.addPathSM(pathl);
2971 /*cout<<endl<<"after change pivot: "<<endl;//wangll
2972 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2973 cout<<"track.helix = "<<track.a()<<endl;//wangll
2974 */
2975
2976 // calculate the tof time in this layer
2977 double pmag( sqrt( 1.0 + track.a()[4]*track.a()[4]) / track.a()[2]);
2978 double mass_over_p( track.mass()/ pmag );
2979 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2980 double tofest = pathl / ( 29.9792458 * beta );
2981 track.addTofSM(tofest);
2982
2983 // std::cout<<" in layer: "<<layer<<" pathl: "<<pathl<<" tof: "<<tofest<<std::endl;
2984
2985 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
2986 /*cout<<endl<<"after muls: "<<endl;//wangll
2987 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2988 cout<<"track.helix = "<<track.a()<<endl;//wangll
2989 */
2990 if(!(way<0&&fabs(track.kappa())>1000.0)) {
2991 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
2992 }
2993
2994
2995 // Add info hit wire :
2996 /*cout<<endl<<"after eloss: "<<endl;//wangll
2997 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2998 cout<<"track.helix = "<<track.a()<<endl;//wangll
2999 */
3000 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3001 HepVector Va(5,0);
3002 HepSymMatrix Ma(5,0);
3003 KalFitHelixSeg HelixSeg(&HitMdc,x0kal,Va,Ma);
3004
3005 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3006 double dchi2=-1;
3007 track.smoother_Mdc(HitMdc, meas, HelixSeg, dchi2, m_csmflag);
3008 if(dchi2>0.0) {
3009 track.HelixSegs().push_back(HelixSeg);
3010 }
3011 }
3012
3013 /// oh, to be the last hit
3014
3015 if(i == nhit-1){
3016
3017 /// calculate the lsat point in MDC
3018 HepPoint3D point;
3019 point.setX(x0kal.x() + track.a()[0]*cos(track.a()[1]));
3020 point.setY(x0kal.y() + track.a()[0]*sin(track.a()[1]));
3021 point.setZ(x0kal.z() + track.a()[3]);
3022 track.point_last(point);
3023
3024 /// calculate fiTerm
3025 double phi_old = track.a()[1];
3026 KalFitTrack temp(x0kal, track.a(), track.Ea(), 0, 0, 0);
3027 temp.pivot(ip);
3028 double phi_new = temp.a()[1];
3029 double fi = phi_new - phi_old;
3030 /// for protection purpose
3031 //if(fabs(fi) >= CLHEP::twopi) fi = fmod(fi+2*CLHEP::twopi,CLHEP::twopi);
3032
3033 if(fabs(fi) >= CLHEP::twopi) fi = fmod(fi+2*CLHEP::twopi,CLHEP::twopi);
3034
3035 track.fiTerm(fi);
3036 }
3037
3038 if (debug_==4) cout<<"track----7-----"<<track.a()<<endl;
3039 r0kal_prec = r0kal;
3040 }
3041}
3042
3043
3044
3046{
3047
3048 // retrieve Mdc geometry information
3049 IMdcGeomSvc* igeomsvc;
3050 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3051 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3052 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3053 if(!geomsvc){
3054 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3055 }
3056
3057 HepSymMatrix Eakal(5,0);
3058 // Estimation of the path length from ip to 1st cylinder
3059 HepPoint3D ip(0,0,0);
3060 track.pivot(ip);
3061 Eakal = track.getInitMatrix();
3062 if( debug_ == 4) {
3063 std::cout<<"the initial error matrix in smoothing is "<<Eakal<<std::endl;
3064 }
3065 track.Ea(Eakal);
3066
3067 // Mdc part :
3068 unsigned int nseg = track.HelixSegs().size();
3069 int layer_prev = -1;
3070
3071 HepVector pos_old(3,0);
3072 double r0kal_prec(0);
3073 int nsegs_read(0);
3074 for( unsigned i=0 ; i < nseg; i++ ) {
3075
3076 int flag=0;
3077 int iseg = (nseg-1)-i;
3078 KalFitHelixSeg& HelixSeg = track.HelixSeg(iseg);
3079 const KalFitWire& Wire = HelixSeg.HitMdc()->wire();
3080
3081 int wireid = Wire.geoID();
3082 nsegs_read++;
3083
3084 int layer = Wire.layer().layerId();
3085 if (pathl_ && layer != layer_prev) {
3086
3087 if (debug_ == 4) cout<<"in smoother,layerid "<<layer<<" layer_prev "
3088 <<layer_prev <<" pathl_ "<<pathl_<<endl;
3089
3090 // track.PathL(Wire.layer().layerId());
3091 layer_prev = layer;
3092 }
3093
3094 HepPoint3D fwd(Wire.fwd());
3095 HepPoint3D bck(Wire.bck());
3096 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3097 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
3098 work.ignoreErrorMatrix();
3099 work.pivot((fwd + bck) * .5);
3100 HepPoint3D x0kal = (work.x(0).z() - bck.z()) / wire.z() * wire + bck;
3101
3102
3103 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3104
3105 if (wsag_ == 4){
3106
3107 Hep3Vector result;
3108 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3109 double tension = geowire->Tension();
3110
3111 //std::cout<<" tension: "<<tension<<std::endl;
3112 double zinit(x0kal.z()), lzx(Wire.lzx());
3113
3114 // double A(Wire.Acoef());
3115
3116 double A = 47.35E-6/tension;
3117 double Zp = (zinit - bck.z())*lzx/wire.z();
3118
3119 if(4 == debug_){
3120
3121 std::cout<<" sag in smoother_calib: "<<std::endl;
3122 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3123 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3124 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3125 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3126 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3127 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3128 }
3129
3130 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3131 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3132 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3133
3134 wire.setX(wire.x()/wire.z());
3135 wire.setY(result.z());
3136 wire.setZ(1);
3137
3138 x0kal.setX(result.x());
3139 x0kal.setY(result.y());
3140 }
3141
3142 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3143
3144
3145 // If x0kal is after the inner wall and x0kal_prec before :
3146 double r0kal = x0kal.perp();
3147 if (debug_ == 4) {
3148 cout<<"wire direction "<<wire<<endl;
3149 cout<<"x0kal "<<x0kal<<endl;
3150 cout<<"smoother::r0kal "<<r0kal<<" r0kal_prec "<<r0kal_prec <<endl;
3151 }
3152
3153 // change PIVOT :
3154 double pathl(0);
3155 track.pivot_numf(x0kal, pathl);
3156
3157 if (debug_ == 4) cout<<"track----6-----"<<track.a()<<" ...path..."<<pathl
3158 <<"momentum"<<track.momentum(0)<<endl;
3159 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3160 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3161
3162 // Add info hit wire :
3163 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3164 // attention to this measure value ,what is the measurement value !!
3165 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3166
3167 if(usage_>1) track.smoother_Mdc_csmalign(HelixSeg, meas,flag, m_csmflag);
3168 else track.smoother_Mdc(HelixSeg, meas,flag, m_csmflag);
3169 // cout<<"layer, cell, track.a: "<<Wire.layer().layerId()<<" , "<<Wire.localId()<<" , "<<track.a()<<endl;
3170 }
3171
3172 if (debug_==4) cout<<"track----7-----"<<track.a()<<endl;
3173 r0kal_prec = r0kal;
3174 // can this kind of operation be right??
3175 if(flag == 0) {
3176 track.HelixSegs().erase(track.HelixSegs().begin()+iseg);
3177 }
3178 }
3179}
3180
3181
3182
3183void KalFitAlg::filter_fwd_anal(KalFitTrack& track, int l_mass, int way, HepSymMatrix& Eakal)
3184{
3185
3186 if(debug_==4) {
3187 cout<<"**********************"<<endl;//wangll
3188 cout<<"filter pid type "<<l_mass<<endl;//wangll
3189 }
3190
3191 // retrieve Mdc geometry information
3192 IMdcGeomSvc* igeomsvc;
3193 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3194 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3195 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3196 if(!geomsvc){
3197 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3198 }
3199
3200 //Hep3Vector x0inner(track.pivot());
3201 HepVector pos_old(3,0);
3202 double r0kal_prec(0);
3203 int nhits_read(0);
3204 int nhit = track.HitsMdc().size();
3205 if(debug_ == 4) cout<<"filter_fwd..........111 nhit="<<nhit<<endl;
3206 for( int i=0 ; i < nhit; i++ ) {
3207 KalFitHitMdc& HitMdc = track.HitMdc(i);
3208 // veto on some hits :
3209 if (HitMdc.chi2()<0) continue;
3210 const KalFitWire& Wire = HitMdc.wire();
3211 int layerf = Wire.layer().layerId();
3212
3213 //std::cout<<"in layer: "<<layerf<<std::endl;
3214
3215 int wireid = Wire.geoID();
3216 nhits_read++;
3217 HepPoint3D fwd(Wire.fwd());
3218 HepPoint3D bck(Wire.bck());
3219 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3220 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
3221 work.ignoreErrorMatrix();
3222 work.pivot((fwd + bck) * .5);
3223
3224 //std::cout<<" (fwd + bck) * .5: "<<(fwd + bck)*.5<<std::endl;
3225 //std::cout<<" track.x(0): "<<track.x(0)<<std::endl;
3226 //std::cout<<" work.x(0): "<<work.x(0)<<std::endl;
3227 //std::cout<<" bck: "<<bck<<std::endl;
3228
3229 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
3230
3231 if(4 == debug_) {
3232 std::cout<<" a="<<track.a()<<std::endl;
3233 std::cout<<" pivot="<<track.pivot()<<std::endl;
3234 std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3235 }
3236
3237 // Modification to take account of the wire sag :
3238 /*
3239 if (wsag_==1) {
3240 double A(1.2402E-6);
3241 if (nhits_read != 1 && r0kal_prec > RMW && x0kal.perp() < RMW)
3242 A = 8.5265E-7;
3243 HepPoint3D x0kal_up(x0kal);
3244 double length = sqrt(wire.x()*wire.x()+wire.z()*wire.z());
3245 double zp = (x0kal.z() - bck.z())*length/wire.z();
3246
3247 x0kal_up.setX(wire.x()*(x0kal.z()-bck.z())/wire.z()+bck.x());
3248 x0kal_up.setY((A*(zp-length)+wire.y()/length)*zp+bck.y());
3249 double slopex = wire.x()/wire.z();
3250 double slopey = (A*(2*zp-length)*length+wire.y())/wire.z();
3251
3252 x0kal = x0kal_up;
3253 wire.setX(slopex);
3254 wire.setY(slopey);
3255 wire.setZ(1);
3256
3257 } else if (wsag_ == 2 || wsag_ == 3){
3258 double slopex = wire.x()/wire.z();
3259 double slopey(0), zinit(x0kal.z());
3260 double pos[3], yb_sag(0), yf_sag(0);
3261 int wire_ID = Wire.geoID();
3262 if (wsag_ == 2)
3263 calcdc_sag2_(&wire_ID, &zinit, pos, &slopey, &yb_sag, &yf_sag);
3264
3265 else
3266 calcdc_sag3_(&wire_ID, &zinit, pos, &slopey, &yb_sag, &yf_sag);
3267
3268 wire.setX(slopex);
3269 wire.setY(slopey);
3270 wire.setZ(1);
3271 x0kal.setX(pos[0]);
3272 x0kal.setY(pos[1]);
3273 } else
3274 */
3275
3276 if (wsag_ == 4){
3277 Hep3Vector result;
3278 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3279 double tension = geowire->Tension();
3280 //std::cout<<" tension: "<<tension<<std::endl;
3281 double zinit(x0kal.z()), lzx(Wire.lzx());
3282 // double A(Wire.Acoef());
3283 double A = 47.35E-6/tension;
3284 double Zp = (zinit - bck.z())*lzx/wire.z();
3285
3286 if(4 == debug_){
3287 std::cout<<" sag in filter_fwd_anal: "<<std::endl;
3288 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3289 std::cout<<"zinit: "<<zinit<<" bck.z(): "<<bck.z()<<std::endl;
3290 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3291 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3292 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3293 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3294 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3295 }
3296
3297 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3298 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3299 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3300
3301 wire.setX(wire.x()/wire.z());
3302 wire.setY(result.z());
3303 wire.setZ(1);
3304 x0kal.setX(result.x());
3305 x0kal.setY(result.y());
3306 }
3307
3308
3309 // If x0kal is after the inner wall and x0kal_prec before :
3310 double r0kal = x0kal.perp();
3311
3312 // change PIVOT :
3313 double pathl(0);
3314
3315 if(i==0) track.pivot(x0kal);
3316 else track.pivot_numf(x0kal, pathl);
3317
3318
3319 if (nhits_read == 1) {
3320 track.Ea(Eakal);
3321 } else {
3322 //std::cout<<" Ea="<<track.Ea()<<std::endl;
3323 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3324 //std::cout<<" after muls Ea="<<track.Ea()<<std::endl;
3325 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3326 //std::cout<<" after eloss Ea="<<track.Ea()<<std::endl;
3327 }
3328
3329 if(4 == debug_) {
3330 std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3331 std::cout<<" a="<<track.a()<<std::endl;
3332 std::cout<<" Ea="<<track.Ea()<<std::endl;
3333 }
3334
3335 double dtracknew = 0.;
3336 double dtrack = 0.;
3337 double dtdc = 0.;
3338 // Add info hit wire :
3339 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3340 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3341 double diff_chi2 = track.chiSq();
3342 Hep3Vector IP(0,0,0);
3343 KalmanFit::Helix work_bef = *(KalmanFit::Helix*)&track;
3344 work_bef.ignoreErrorMatrix();
3345 work_bef.pivot(IP);
3346 int inext(-1);
3347 if (i+1<nhit)
3348 for( unsigned k=i+1 ; k < nhit; k++ )
3349 if (!(track.HitMdc(k).chi2()<0)) {
3350 inext = (signed) k;
3351 break;
3352 }
3353 double dchi2 = -1.0;
3354
3355 double chi2 = track.update_hits(HitMdc,inext,meas,way,dchi2,dtrack,dtracknew,dtdc,m_csmflag);
3356
3357 //cout << "dchi2=" << dchi2 << endl;
3358 /// get the doca from another other independent method
3359
3360 /*
3361 std::cout<<" step0: "<<std::endl;
3362 KalFitTrack temp2(track);
3363 std::cout<<" step1: "<<std::endl;
3364
3365 KalmanFit::Helix temp3(track.pivot(),track.a(),track.Ea());
3366 KalmanFit::Helix temp4(track.pivot(),track.a(),track.Ea());
3367
3368 std::cout<<" step2: "<<std::endl;
3369 double doca25 = temp2.approach(HitMdc, false);
3370 std::cout<<" step3: "<<std::endl;
3371
3372 temp2.pivot(IP);
3373 std::cout<<" a2: "<<temp2.a()<<std::endl;
3374
3375 std::cout<<" step4: "<<std::endl;
3376
3377 double doca26 = temp3.approach(HitMdc, false);
3378 std::cout<<" another doca2.6: "<<doca26<<std::endl;
3379
3380 temp3.pivot(IP);
3381 std::cout<<" a3: "<<temp3.a()<<std::endl;
3382
3383 temp4.bFieldZ(-10);
3384 temp4.pivot(IP);
3385 std::cout<<" a4: "<<temp4.a()<<std::endl;
3386
3387 std::cout<<" step5: "<<std::endl;
3388
3389 double doca1 = track.approach(HitMdc, false);
3390 double doca2 = temp2.approach(HitMdc, false);
3391 double doca3 = temp3.approach(HitMdc, false);
3392 double doca4 = temp4.approach(HitMdc, false);
3393
3394 std::cout<<" dtrack: "<<dtrack<<std::endl;
3395 std::cout<<" another doca1: "<<doca1<<std::endl;
3396 std::cout<<" another doca2: "<<doca2<<std::endl;
3397 std::cout<<" another doca2.5: "<<doca25<<std::endl;
3398 std::cout<<" another doca3: "<<doca3<<std::endl;
3399 std::cout<<" another doca4: "<<doca4<<std::endl;
3400 */
3401
3402
3403 //if( dchi2 <0 ) { std::cout<<" ... ERROR OF dchi2... "<<std::endl; }
3404
3405 if (ntuple_&8) {
3406 m_dchi2 = dchi2;
3407 m_masshyp = l_mass;
3408 m_residest = dtrack-dtdc;
3409 m_residnew = dtracknew -dtdc;
3410 m_layer = Wire.layer().layerId();
3411 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3412 m_anal_dr = worktemp.a()[0];
3413 m_anal_phi0 = worktemp.a()[1];
3414 m_anal_kappa = worktemp.a()[2];
3415 m_anal_dz = worktemp.a()[3];
3416 m_anal_tanl = worktemp.a()[4];
3417 m_anal_ea_dr = worktemp.Ea()[0][0];
3418 m_anal_ea_phi0 = worktemp.Ea()[1][1];
3419 m_anal_ea_kappa = worktemp.Ea()[2][2];
3420 m_anal_ea_dz = worktemp.Ea()[3][3];
3421 m_anal_ea_tanl = worktemp.Ea()[4][4];
3422 StatusCode sc5 = m_nt5->write();
3423 if( sc5.isFailure() ) cout<<"Ntuple5 filling failed!"<<endl;
3424 }
3425
3426 if (ntuple_&256) {
3427
3428 //cout<<"Mdc: "<<m_hit_no<<endl;
3429
3430 if(l_mass == 0){
3431 m_dchi2_hit_e[m_hit_no] = dchi2;
3432 m_residest_hit_e[m_hit_no] = dtrack-dtdc;
3433 m_residnew_hit_e[m_hit_no] = dtracknew -dtdc;
3434 m_layer_hit_e[m_hit_no] = Wire.layer().layerId();
3435 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3436 m_anal_dr_hit_e[m_hit_no] = worktemp.a()[0];
3437 m_anal_phi0_hit_e[m_hit_no] = worktemp.a()[1];
3438 m_anal_kappa_hit_e[m_hit_no] = worktemp.a()[2];
3439 m_anal_dz_hit_e[m_hit_no] = worktemp.a()[3];
3440 m_anal_tanl_hit_e[m_hit_no] = worktemp.a()[4];
3441 m_anal_ea_dr_hit_e[m_hit_no] = worktemp.Ea()[0][0];
3442 m_anal_ea_phi0_hit_e[m_hit_no] = worktemp.Ea()[1][1];
3443 m_anal_ea_kappa_hit_e[m_hit_no] = worktemp.Ea()[2][2];
3444 m_anal_ea_dz_hit_e[m_hit_no] = worktemp.Ea()[3][3];
3445 m_anal_ea_tanl_hit_e[m_hit_no] = worktemp.Ea()[4][4];
3446
3447 }
3448
3449 else if(l_mass == 1){
3450 m_dchi2_hit_mu[m_hit_no] = dchi2;
3451 m_residest_hit_mu[m_hit_no] = dtrack-dtdc;
3452 m_residnew_hit_mu[m_hit_no] = dtracknew -dtdc;
3453 m_layer_hit_mu[m_hit_no] = Wire.layer().layerId();
3454 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3455 m_anal_dr_hit_mu[m_hit_no] = worktemp.a()[0];
3456 m_anal_phi0_hit_mu[m_hit_no] = worktemp.a()[1];
3457 m_anal_kappa_hit_mu[m_hit_no] = worktemp.a()[2];
3458 m_anal_dz_hit_mu[m_hit_no] = worktemp.a()[3];
3459 m_anal_tanl_hit_mu[m_hit_no] = worktemp.a()[4];
3460 m_anal_ea_dr_hit_mu[m_hit_no] = worktemp.Ea()[0][0];
3461 m_anal_ea_phi0_hit_mu[m_hit_no] = worktemp.Ea()[1][1];
3462 m_anal_ea_kappa_hit_mu[m_hit_no] = worktemp.Ea()[2][2];
3463 m_anal_ea_dz_hit_mu[m_hit_no] = worktemp.Ea()[3][3];
3464 m_anal_ea_tanl_hit_mu[m_hit_no] = worktemp.Ea()[4][4];
3465
3466 }
3467
3468
3469 else if(l_mass == 2){
3470 m_dchi2_hit_pi[m_hit_no] = dchi2;
3471 m_residest_hit_pi[m_hit_no] = dtrack-dtdc;
3472 m_residnew_hit_pi[m_hit_no] = dtracknew -dtdc;
3473 m_layer_hit_pi[m_hit_no] = Wire.layer().layerId();
3474 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3475 m_anal_dr_hit_pi[m_hit_no] = worktemp.a()[0];
3476 m_anal_phi0_hit_pi[m_hit_no] = worktemp.a()[1];
3477 m_anal_kappa_hit_pi[m_hit_no] = worktemp.a()[2];
3478 m_anal_dz_hit_pi[m_hit_no] = worktemp.a()[3];
3479 m_anal_tanl_hit_pi[m_hit_no] = worktemp.a()[4];
3480 m_anal_ea_dr_hit_pi[m_hit_no] = worktemp.Ea()[0][0];
3481 m_anal_ea_phi0_hit_pi[m_hit_no] = worktemp.Ea()[1][1];
3482 m_anal_ea_kappa_hit_pi[m_hit_no] = worktemp.Ea()[2][2];
3483 m_anal_ea_dz_hit_pi[m_hit_no] = worktemp.Ea()[3][3];
3484 m_anal_ea_tanl_hit_pi[m_hit_no] = worktemp.Ea()[4][4];
3485
3486 }
3487
3488
3489 else if(l_mass == 3){
3490 m_dchi2_hit_k[m_hit_no] = dchi2;
3491 m_residest_hit_k[m_hit_no] = dtrack-dtdc;
3492 m_residnew_hit_k[m_hit_no] = dtracknew -dtdc;
3493 m_layer_hit_k[m_hit_no] = Wire.layer().layerId();
3494 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3495 m_anal_dr_hit_k[m_hit_no] = worktemp.a()[0];
3496 m_anal_phi0_hit_k[m_hit_no] = worktemp.a()[1];
3497 m_anal_kappa_hit_k[m_hit_no] = worktemp.a()[2];
3498 m_anal_dz_hit_k[m_hit_no] = worktemp.a()[3];
3499 m_anal_tanl_hit_k[m_hit_no] = worktemp.a()[4];
3500 m_anal_ea_dr_hit_k[m_hit_no] = worktemp.Ea()[0][0];
3501 m_anal_ea_phi0_hit_k[m_hit_no] = worktemp.Ea()[1][1];
3502 m_anal_ea_kappa_hit_k[m_hit_no] = worktemp.Ea()[2][2];
3503 m_anal_ea_dz_hit_k[m_hit_no] = worktemp.Ea()[3][3];
3504 m_anal_ea_tanl_hit_k[m_hit_no] = worktemp.Ea()[4][4];
3505
3506 }
3507
3508
3509 else if(l_mass == 4){
3510 m_dchi2_hit_p[m_hit_no] = dchi2;
3511 m_residest_hit_p[m_hit_no] = dtrack-dtdc;
3512 m_residnew_hit_p[m_hit_no] = dtracknew -dtdc;
3513 m_layer_hit_p[m_hit_no] = Wire.layer().layerId();
3514 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3515 m_anal_dr_hit_p[m_hit_no] = worktemp.a()[0];
3516 m_anal_phi0_hit_p[m_hit_no] = worktemp.a()[1];
3517 m_anal_kappa_hit_p[m_hit_no] = worktemp.a()[2];
3518 m_anal_dz_hit_p[m_hit_no] = worktemp.a()[3];
3519 m_anal_tanl_hit_p[m_hit_no] = worktemp.a()[4];
3520 m_anal_ea_dr_hit_p[m_hit_no] = worktemp.Ea()[0][0];
3521 m_anal_ea_phi0_hit_p[m_hit_no] = worktemp.Ea()[1][1];
3522 m_anal_ea_kappa_hit_p[m_hit_no] = worktemp.Ea()[2][2];
3523 m_anal_ea_dz_hit_p[m_hit_no] = worktemp.Ea()[3][3];
3524 m_anal_ea_tanl_hit_p[m_hit_no] = worktemp.Ea()[4][4];
3525
3526 }
3527
3528 m_hit_no++;
3529 }
3530
3531
3532 KalmanFit::Helix work_aft = *(KalmanFit::Helix*)&track;
3533 work_aft.ignoreErrorMatrix();
3534 work_aft.pivot(IP);
3535 diff_chi2 = chi2 - diff_chi2;
3536 HitMdc.chi2(diff_chi2);
3537 }
3538 r0kal_prec = r0kal;
3539 }
3540 //cout <<"filter end" << endl;
3541}
3542
3543
3544
3545void KalFitAlg::filter_fwd_calib(KalFitTrack& track, int l_mass, int way, HepSymMatrix& Eakal)
3546{
3547
3548 // retrieve Mdc geometry information
3549 IMdcGeomSvc* igeomsvc;
3550 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3551 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3552 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3553 if(!geomsvc){
3554 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3555 }
3556
3557 if(debug_ == 4) {
3558 std::cout<<"filter_fwd_calib starting ...the inital error Matirx is "<<track.Ea()<<std::endl;
3559 }
3560 Hep3Vector x0inner(track.pivot());
3561 HepVector pos_old(3,0);
3562 double r0kal_prec(0);
3563 int nhits_read(0);
3564
3565 unsigned int nhit = track.HitsMdc().size();
3566 if(debug_ == 4) cout<<"filter_fwd..........111 nhit="<<nhit<<endl;
3567 for( unsigned i=0 ; i < nhit; i++ ) {
3568
3569 KalFitHitMdc& HitMdc = track.HitMdc(i);
3570 if(debug_ == 4)
3571 cout<<"filter_fwd...........222 chi2="<<HitMdc.chi2()<<endl;
3572 // veto on some hits :
3573 if (HitMdc.chi2()<0) continue;
3574 const KalFitWire& Wire = HitMdc.wire();
3575
3576 int wireid = Wire.geoID();
3577 nhits_read++;
3578
3579 // if (nhits_read == 1) track.Ea(Eakal);
3580 HepPoint3D fwd(Wire.fwd());
3581 HepPoint3D bck(Wire.bck());
3582 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3583 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
3584 work.ignoreErrorMatrix();
3585 work.pivot((fwd + bck) * .5);
3586 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
3587
3588 if(4 == debug_)
3589 std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3590
3591 if (wsag_ == 4){
3592 Hep3Vector result;
3593 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3594 double tension = geowire->Tension();
3595 //std::cout<<" tension: "<<tension<<std::endl;
3596 double zinit(x0kal.z()), lzx(Wire.lzx());
3597 // double A(Wire.Acoef());
3598 double A = 47.35E-6/tension;
3599 double Zp = (zinit - bck.z())*lzx/wire.z();
3600
3601 if(4 == debug_){
3602
3603 std::cout<<" sag in filter_fwd_calib: "<<std::endl;
3604 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3605 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3606 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3607 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3608 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3609 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3610 }
3611
3612 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3613 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3614 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3615 wire.setX(wire.x()/wire.z());
3616 wire.setY(result.z());
3617 wire.setZ(1);
3618 x0kal.setX(result.x());
3619 x0kal.setY(result.y());
3620 }
3621
3622 if(4 == debug_)
3623 std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3624
3625 // If x0kal is after the inner wall and x0kal_prec before :
3626 double r0kal = x0kal.perp();
3627
3628 // change PIVOT :
3629 double pathl(0);
3630
3631 //std::cout<<" track a3: "<<track.a()<<std::endl;
3632 //std::cout<<" track p3: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3633
3634 if (debug_ == 4)
3635 cout << "*** move from " << track.pivot() << " ( Kappa = "
3636 << track.a()[2] << ")" << endl;
3637 track.pivot_numf(x0kal, pathl); //see the code , the error matrix has been changed in this function ..
3638
3639 //std::cout<<" track a4: "<<track.a()<<std::endl;
3640 //std::cout<<" track p4: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3641
3642
3643 if (debug_ == 4)
3644 cout << "*** to " << track.pivot() << " ( Kappa = "
3645 << track.a()[2] << ")" << std::endl;
3646
3647 if (nhits_read == 1) {
3648 track.Ea(Eakal);
3649 if(debug_==4) cout << "filter_fwd::Ea = " << track.Ea()<<endl;
3650
3651
3652 } else {
3653 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3654 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3655 }
3656
3657
3658 //std::cout<<" track a5: "<<track.a()<<std::endl;
3659 //std::cout<<" track p5: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3660
3661 // Add info hit wire :
3662 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3663 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3664
3665 double diff_chi2 = track.chiSq();
3666
3667 Hep3Vector IP(0,0,0);
3668 KalmanFit::Helix work_bef = *(KalmanFit::Helix*)&track;
3669 work_bef.ignoreErrorMatrix();
3670 work_bef.pivot(IP);
3671 int inext(-1);
3672 if (i+1<nhit)
3673 for( unsigned k=i+1 ; k < nhit; k++ )
3674 if (!(track.HitMdc(k).chi2()<0)) {
3675 inext = (signed) k;
3676 break;
3677 }
3678 double dchi2 = -1.0;
3679
3680 if (debug_ == 4) {
3681 std::cout<<"the value of x0kal is "<<x0kal<<std::endl;
3682 std::cout<<"the value of track.pivot() is "<<track.pivot()<<std::endl;
3683 }
3684
3685 HepVector Va(5,0);
3686 HepSymMatrix Ma(5,0);
3687 KalFitHelixSeg HelixSeg(&HitMdc,x0kal,Va,Ma);
3688
3689 if(debug_ == 4) {
3690 std::cout<<"HelixSeg.Ea_pre_fwd() ..."<<HelixSeg.Ea_pre_fwd()<<std::endl;
3691 std::cout<<"HelixSeg.a_pre_fwd() ..."<<HelixSeg.a_pre_fwd()<<std::endl;
3692 std::cout<<"HelixSeg.Ea_filt_fwd() ..."<<HelixSeg.Ea_filt_fwd()<<std::endl;
3693 }
3694
3695 //std::cout<<" track a1: "<<track.a()<<std::endl;
3696 //std::cout<<" track p1: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3697
3698 double chi2=0.;
3699 if(usage_>1) chi2=track.update_hits_csmalign(HelixSeg, inext, meas, way, dchi2, m_csmflag);
3700 else chi2 = track.update_hits(HelixSeg, inext, meas, way, dchi2, m_csmflag);
3701
3702 //std::cout<<" track a2: "<<track.a()<<std::endl;
3703 //std::cout<<" track p2: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3704
3705 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;
3706
3707 if(debug_ == 4) cout<< "****inext***"<<inext<<" !!!! dchi2= "<< dchi2
3708 << " chisq= "<< chi2<< endl;
3709
3710 if (ntuple_&8) {
3711 m_dchi2 = dchi2;
3712 m_masshyp = l_mass;
3713 StatusCode sc5 = m_nt5->write();
3714 if( sc5.isFailure() ) cout<<"Ntuple5 filling failed!"<<endl;
3715 }
3716
3717 KalmanFit::Helix work_aft = *(KalmanFit::Helix*)&track;
3718 work_aft.ignoreErrorMatrix();
3719 work_aft.pivot(IP);
3720 diff_chi2 = chi2 - diff_chi2;
3721 HitMdc.chi2(diff_chi2);
3722
3723 if(debug_ == 4) {
3724
3725 cout << " -> after include meas = " << meas
3726 << " at R = " << track.pivot().perp() << std::endl;
3727 cout << " chi2 = " << chi2 << ", diff_chi2 = "
3728 << diff_chi2 << ", LR = "
3729 << HitMdc.LR() << ", stereo = " << HitMdc.wire().stereo()
3730 << ", layer = " << HitMdc.wire().layer().layerId() << std::endl;
3731 cout<<"filter_fwd..........HitMdc.chi2... "<<HitMdc.chi2()<<endl;
3732 }
3733
3734 if(dchi2>0.0 && (way!=999)) {
3735 track.HelixSegs().push_back(HelixSeg);
3736 }
3737 }
3738 r0kal_prec = r0kal;
3739 }
3740}
3741
3742// Take account of the inner wall (forward filter) :
3743void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way){
3744
3745 if (debug_ ==4) cout<<"innerwall....."<<endl;
3746 for(int i = 0; i < _BesKalmanFitWalls.size(); i++) {
3747 _BesKalmanFitWalls[i].updateTrack(track, way);
3748 if (debug_ == 4) cout<<"Wall "<<i<<" update the track!(filter)"<<endl;
3749 }
3750}
3751
3752void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way,int begin,int end){
3753 if (debug_ ==4) cout<<"innerwall....."<<endl;
3754 for(int i = begin; i <= end; i++) {
3755 _BesKalmanFitWalls[i].updateTrack(track, way);
3756 if(debug_ == 4){cout << "wall" << i << endl;
3757 cout <<"track" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;}
3758 if (debug_ == 4) cout<<"Wall "<<i<<" update the track!(filter)"<<endl;
3759 }
3760}
3761
3762void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way, double r1, double r2, int& index){
3763 if (debug_ ==4) cout<<"innerwall....."<<endl;
3764 double ri=(r1<r2)?r1:r2;
3765 double ro=(r1<r2)?r2:r1;
3766 double Rmin,Rmax;
3767 int step;
3768 vector<KalFitCylinder>::iterator it;
3769 vector<KalFitCylinder>::iterator itStart;
3770 vector<KalFitCylinder>::iterator itStop;
3771 if(way<0){
3772 step=-1;
3773 itStart=_BesKalmanFitWalls.end()-index-1;
3774 itStop =_BesKalmanFitWalls.begin()-1;
3775 }
3776 else{
3777 step=1;
3778 itStart=_BesKalmanFitWalls.begin()+index;
3779 itStop =_BesKalmanFitWalls.end();
3780 }
3781 for(it=itStart; it != itStop; it=it+step) {
3782 if(ri < it->rmin() && it->radius() < ro) {
3783 it->updateTrack(track,way);
3784 Rmin=it->rmin();
3785 Rmax=it->radius();
3786 continue;
3787 }
3788 else if(it->rmin() <= ri && ri <= it->radius() && it->radius() < ro){
3789 it->updateTrack(track,way,ri,it->radius());
3790 Rmin=ri;
3791 Rmax=it->radius();
3792 if(way>0){
3793 //index = it - _BesKalmanFitWalls.begin();
3794 break;
3795 }
3796 else continue;
3797 }
3798 else if(ri < it->rmin() && it->rmin() <= ro && ro <= it->radius()){
3799 it->updateTrack(track,way,it->rmin(),ro);
3800 Rmin=it->rmin();
3801 Rmax=ro;
3802 if(way<0){
3803 //index = _BesKalmanFitWalls.end() - it;
3804 break;
3805 }
3806 else continue;
3807 }
3808 else if(it->radius()<ri || ro < it->rmin()){
3809 continue;
3810 }
3811 else {
3812 it->updateTrack(track,way,ri,ro);
3813 Rmin=ri;
3814 Rmax=ro;
3815 //index=it-_BesKalmanFitWalls.begin();
3816 break;
3817 }
3818 }
3819 if(way<0){
3820 //double phi=track.intersect_cylinder(Rmax);
3821 //HepPoint3D pivot=track.x(phi);
3822 //track.pivot_numf(pivot);
3823 track.pivot_numf(track.x(track.intersect_cylinder(Rmax)));
3824 index = _BesKalmanFitWalls.end() - it-1;
3825 }
3826 else{
3827 //double phi=track.intersect_cylinder(Rmin);
3828 //HepPoint3D pivot=track.x(phi);
3829 //track.pivot_numf(pivot);
3830 track.pivot_numf(track.x(track.intersect_cylinder(Rmin)));
3831 index = it - _BesKalmanFitWalls.begin();
3832 }
3833
3834}
3835
3836
3837//void KalFitAlg::set_Mdc(void)
3838
3839// Use the information of trasan and refit the best tracks
3840
3842{
3843
3844 //cout<<"kalman_fitting_anal deal with a new event"<<endl;//wangll
3845
3846 MsgStream log(msgSvc(), name());
3847 double Pt_threshold(0.3);
3848 Hep3Vector IP(0,0,0);
3849 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
3850 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
3851 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
3852
3853 // Table Manager
3854 if ( !&whMgr ) return;
3855
3856 // Get reduced chi**2 of Mdc track :
3857 int ntrk = mdcMgr->size();
3858 double* rPt = new double[ntrk];
3859 int* rOM = new int[ntrk];
3860 unsigned int* order = new unsigned int[ntrk];
3861 unsigned int* rCont = new unsigned int[ntrk];
3862 unsigned int* rGen = new unsigned int[ntrk];
3863
3864 if(testOutput) cout<<"nMdcTrk = "<<ntrk<<endl;
3865
3866 int index = 0;
3867 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
3868 end = mdcMgr->end(); it != end; it++) {
3869 // Pt
3870 rPt[index] = 0;
3871 if (it->helix[2])
3872 rPt[index] = 1 / fabs(it->helix[2]);
3873 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
3874 if(rPt[index] < 0) rPt[index] = DBL_MAX;
3875 // Outermost layer
3876 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
3877 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
3878 int outermost(-1);
3879 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3880 ii !=pt.begin()-1; ii--) {
3881 int lyr((*ii)->geo->Lyr()->Id());
3882 if (outermost < lyr) outermost = lyr;
3883 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
3884 }
3885 rOM[index] = outermost;
3886 order[index] = index;
3887 ++index;
3888 }
3889
3890 // Sort Mdc tracks by Pt
3891 for (int j, k = ntrk - 1; k >= 0; k = j){
3892 j = -1;
3893 for(int i = 1; i <= k; i++)
3894 if(rPt[i - 1] < rPt[i]){
3895 j = i - 1;
3896 std::swap(order[i], order[j]);
3897 std::swap(rPt[i], rPt[j]);
3898 std::swap(rOM[i], rOM[j]);
3899 std::swap(rCont[i], rCont[j]);
3900 std::swap(rGen[i], rGen[j]);
3901 }
3902 }
3903 delete [] rPt;
3904
3905 //
3906 int newcount(0);
3907 //check whether Recon already registered
3908 DataObject *aReconEvent;
3909 eventSvc()->findObject("/Event/Recon",aReconEvent);
3910 if(!aReconEvent) {
3911 // register ReconEvent Data Object to TDS;
3912 ReconEvent* recevt = new ReconEvent;
3913 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
3914 if(sc!=StatusCode::SUCCESS) {
3915 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
3916 return;
3917 }
3918 }
3919
3920 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
3922 //make RecMdcKalTrackCol
3923 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
3924 // Loop over tracks given by trasan :
3925 for(int l = 0; l < ntrk; l++) {
3926
3927 //cout<<"----------------"<<endl;//wangll
3928 //cout<<"track "<<l<<" : "<<endl;//wangll
3929 nTotalTrks++;
3930
3931 for(int i=0; i<5; i++) iqual_front_[i] = 1; // wangll 2010-11-01
3932
3933 // m_timer[3]->start();
3934 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[l]);
3935 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[l]);
3936
3937 // Reject the ones with quality != 0
3938 int trasqual = TrasanTRK_add.quality;
3939 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
3940 if (trasqual) continue;
3941
3942 newcount++;
3943 if (debug_ == 4)
3944 cout << "******* KalFit NUMBER : " << newcount << std::endl;
3945
3946 // What kind of KalFit ?
3947 int type(0);
3948 if ((TrasanTRK_add.decision & 32) == 32 ||
3949 (TrasanTRK_add.decision & 64) == 64) type = 1;
3950
3951 // Initialisation : (x, a, ea)
3952 HepPoint3D x(TrasanTRK.pivot[0],
3953 TrasanTRK.pivot[1],
3954 TrasanTRK.pivot[2]);
3955
3956 HepVector a(5);
3957 for(int i = 0; i < 5; i++)
3958 a[i] = TrasanTRK.helix[i];
3959
3960 HepSymMatrix ea(5);
3961 for(int i = 0, k = 0; i < 5; i++) {
3962 for(int j = 0; j <= i; j++) {
3963 ea[i][j] = matrixg_*TrasanTRK.error[k++];
3964 ea[j][i] = ea[i][j];
3965 }
3966 }
3967 double fiTerm = TrasanTRK.fiTerm;
3968 int way(1);
3969 // Prepare the track found :
3970 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
3971
3972 track_lead.bFieldZ(KalFitTrack::Bznom_);
3973 double pT_trk = fabs(track_lead.pt());
3974
3975 // Mdc Hits
3976 int inlyr(999), outlyr(-1);
3977 int* rStat = new int[43];
3978 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
3979 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
3980 int hit_in(0);
3981 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
3982 // Number of hits/layer
3983 int Num[43] = {0};
3984 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3985 ii != pt.begin()-1; ii--) {
3986 Num[(*ii)->geo->Lyr()->Id()]++;
3987 }
3988 int hit_asso(0);
3989 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3990 ii != pt.begin()-1; ii--) {
3991 hit_asso++;
3992
3993 if (pT_trk>0.12 && Num[(*ii)->geo->Lyr()->Id()]>3) {
3994 if (debug_==4 )
3995 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
3996 << " hits in the layer "
3997 << (*ii)->geo->Lyr()->Id() << std::endl;
3998 continue;
3999 }
4000 // comment out wangll 2020-05-22
4001
4002 // if(ii!=pt.end()-1){
4003 // int layer_before=(*(ii+1))->geo->Lyr()->Id();
4004 // if(layer_before == (*ii)->geo->Lyr()->Id()){
4005 // MdcRec_wirhit * rechit_before = *(ii+1);
4006 // if((*rechit_before).rechitptr->getDriftT()>450 || (**ii).rechitptr->getDriftT()>450.){
4007 // if((*rechit_before).tdc < (**ii).tdc) continue;
4008 // else if(track_lead.HitsMdc().size()>0 && rStat[layer_before]){
4009 // track_lead.HitsMdc().pop_back();
4010 // }
4011 // }
4012 // }
4013 // }
4014
4015 hit_in++;
4016 MdcRec_wirhit & rechit = **ii;
4017 double dist[2] = {rechit.ddl, rechit.ddr};
4018 double erdist[2] = {rechit.erddl, rechit.erddr};
4019 const MdcGeoWire* geo = rechit.geo;
4020
4021 int lr_decision(0);
4022 if (KalFitTrack::LR_ == 1){
4023 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
4024 // if (rechit.lr==0) lr_decision=-1;
4025 else if (rechit.lr==1) lr_decision=1;
4026 }
4027
4028 int ind(geo->Lyr()->Id());
4029
4030 // ATTENTION HERE!!!
4031 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
4032 lr_decision, rechit.tdc,
4033 dist, erdist,
4034 _wire+(geo->Id()), rechit.rechitptr));
4035 // inner/outer layer :
4036 rStat[ind]++;
4037 if (inlyr>ind) inlyr = ind;
4038 if (outlyr<ind) outlyr = ind;
4039 }
4040 if (debug_ == 4)
4041 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
4042
4043 // Empty layers :
4044 int empty_between(0), empty(0);
4045 for (int i= inlyr; i <= outlyr; i++)
4046 if (!rStat[i]) empty_between++;
4047 empty = empty_between+inlyr+(42-outlyr);
4048 delete [] rStat;
4049
4050 // RMK high momentum track under study, probably not neeeded...
4051 track_lead.order_wirhit(1);
4052 //track_lead.order_hits();
4053
4054 for(std::vector<KalFitHitMdc>::iterator it_hit = track_lead.HitsMdc().begin(); it_hit!=track_lead.HitsMdc().end(); it_hit++){
4055 //std::cout<<" the id of this hits after sorting in PatRec is "<<it_hit->id()<<std::endl;
4056 //std::cout<<" the layerid of the hit is "<<it_hit->wire().layer().layerId()<<std::endl;
4057 //std::cout<<" the cellid of this wire is "<<it_hit->wire().localId()<<std::endl;
4058 }
4059
4060 track_lead.type(type);
4061 track_lead.trasan_id(TrasanTRK.id);
4062 unsigned int nhit = track_lead.HitsMdc().size();
4063 if (!nhit && debug_ == 4) {
4064 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
4065 continue;
4066 }
4067
4068 // Initialisation :
4069 double KalFitst(0), KalFitax(0), KalFitschi2(0);
4070 // Move to the outer hit :
4071
4072 Hep3Vector outer_pivot(track_lead.x(fiTerm));
4073 track_lead.pivot(outer_pivot);
4074
4075 track_lead.bFieldZ(KalFitTrack::Bznom_);
4076 // attention best_chi2 reinitialize !!!
4077 if (nhit>=3 && !KalFitTrack::LR_)
4078 start_seed(track_lead, lead_, way, TrasanTRK);
4079 HepSymMatrix Eakal(5,0);
4080
4081 /// very low momentum and very big costheta angle, use special initial error matrix
4082 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
4083 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
4084 choice_ = 6;
4085 }
4086
4087 /// chose different initial error matrix
4088 init_matrix(choice_,TrasanTRK, Eakal);
4089
4090
4091 if (debug_ == 4){
4092 cout << "from Mdc Pattern Recognition: " << std::endl;
4093 HepPoint3D IP(0,0,0);
4094 KalmanFit::Helix work(track_lead.pivot(),
4095 track_lead.a(),
4096 track_lead.Ea());
4097 work.pivot(IP);
4098 cout << " dr = " << work.a()[0]
4099 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4100 cout << " phi0 = " << work.a()[1]
4101 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4102 cout << " PT = " << 1/work.a()[2]
4103 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4104 cout << " dz = " << work.a()[3]
4105 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4106 cout << " tanl = " << work.a()[4]
4107 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4108 }
4109
4110 if(testOutput) {
4111 cout<<"----------------------"<<endl;//660a
4112 cout<<"track "<<l<<", pid = "<<lead_<<": "<<endl;
4113 //int n_hits=(*itRecMdcTrack)->getNhits();
4114 //int n_hit_Axis=n_hits-(*itRecMdcTrack)->nster();
4115 //cout<<"nMdcHits,nMdcHitsAxis = "<<n_hits<<", "<<n_hit_Axis<<endl;//660a
4116 //cout<<"----------------------"<<endl;
4117 //cout<<"# old track par #"<<endl<<" pivot: "<<track.pivot()<<endl<<" helix: "<<track.a()<<endl<<" error: "<<track.Ea()<<endl;
4118 //cout<<"# true track par #"<<endl<<" helix: "<<mc_a<<endl;
4119 }
4120
4121
4122 filter_fwd_anal(track_lead, lead_, way, Eakal);
4123
4124 // std::cout<<" step3, track_lead.Ea: "<<track_lead.Ea()<<std::endl;
4125 track_lead.update_forMdc();
4126
4127 HepPoint3D IP(0,0,0);
4128 if (debug_ == 4) {
4129 cout << " Mdc FIRST KALMAN FIT " << std::endl;
4130 KalmanFit::Helix work(track_lead.pivot(),
4131 track_lead.a(),
4132 track_lead.Ea());
4133 work.pivot(IP);
4134 cout << " dr = " << work.a()[0]
4135 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4136 cout << " phi0 = " << work.a()[1]
4137 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4138 cout << " PT = " << 1/work.a()[2]
4139 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4140 cout << " dz = " << work.a()[3]
4141 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4142 cout << " tanl = " << work.a()[4]
4143 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4144 }
4145
4146 // fill TDS
4147 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
4148 kaltrk->setTrackId(TrasanTRK.id);
4149 // Complete the track (other mass assumption, backward) and
4150 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol,1);
4151 }// loop mdc tracks
4152
4153
4154 IDataProviderSvc* eventSvc = NULL;
4155 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
4156 if (eventSvc) {
4157 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
4158 } else {
4159 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
4160 return ;
4161 }
4162 StatusCode kalsc;
4163 IDataManagerSvc *dataManSvc;
4164 dataManSvc= dynamic_cast<IDataManagerSvc*>(eventSvc);
4165 DataObject *aKalTrackCol;
4166 eventSvc->findObject("/Event/Recon/RecMdcKalTrackCol",aKalTrackCol);
4167 if(aKalTrackCol != NULL) {
4168 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalTrackCol");
4169 eventSvc->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
4170 }
4171 kalsc = eventSvc->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
4172 if( kalsc.isFailure() ) {
4173 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
4174 return ;
4175 }
4176 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
4177 StatusCode segsc;
4178 //check whether the RecMdcKalHelixSegCol has been already registered
4179 DataObject *aRecKalSegEvent;
4180 eventSvc->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
4181 if(aRecKalSegEvent!=NULL) {
4182 //then unregister RecMdcKalHelixSegCol
4183 segsc = eventSvc->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
4184 if(segsc != StatusCode::SUCCESS) {
4185 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
4186 return;
4187 }
4188 }
4189 segsc = eventSvc->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
4190 if( segsc.isFailure() ) {
4191 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
4192 return;
4193 }
4194 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
4195
4196 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.);
4197 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0),tanl2(0.);
4198 double px1(0.),px2(0.),py1(0.),py2(0.),pz1(0.),pz2(0.),charge1(0.),charge2(0.);
4199
4200 //check the result:RecMdcKalTrackCol
4201 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc,"/Event/Recon/RecMdcKalTrackCol");
4202 if (!kaltrkCol) {
4203 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
4204 return;
4205 }
4206 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
4207 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
4208 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
4209 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
4210 << "Track Id: " << (*iter_trk)->getTrackId()
4211 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
4212 << " Length of the track: "<< (*iter_trk)->getLength(2)
4213 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
4214 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
4215 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
4216 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,2)
4217 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
4218 << "Kappa " << (*iter_trk)->getZHelix()[2]
4219 << endreq;
4220 for( int i = 0; i<43; i++) {
4221 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
4222 << (*iter_trk)->getPathl(i) <<endreq;
4223 }
4224 if(ntuple_&1) {
4225 m_trackid = (*iter_trk)->getTrackId();
4226
4227 for( int jj =0, iii=0; jj<5; jj++) {
4228
4229 m_length[jj] = (*iter_trk)->getLength(jj);
4230 m_tof[jj] = (*iter_trk)->getTof(jj);
4231 m_nhits[jj] = (*iter_trk)->getNhits(jj);
4232 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
4233 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
4234 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
4235 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
4236 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
4237 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
4238 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
4239 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
4240 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
4241 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
4242 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
4243 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
4244 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
4245 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
4246 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
4247
4248 if(ntuple_&32) {
4249 for(int kk=0; kk<=jj; kk++,iii++) {
4250 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
4251 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
4252 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
4253 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
4254 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
4255 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
4256 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
4257 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
4258 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
4259 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
4260 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
4261 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
4262 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
4263 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
4264 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
4265 }
4266 }
4267 }
4268
4269 // // the following logic may seem peculiar, but it IS the case(for BOSS5.0 and BOSS5.1)
4270 // m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4271 // m_chisq[0][1] = (*iter_trk)->getChisq(0,1);
4272 // m_chisq[1][0] = (*iter_trk)->getChisq(0,2);
4273 // m_chisq[1][1] = (*iter_trk)->getChisq(0,3);
4274 // m_chisq[2][0] = (*iter_trk)->getChisq(0,4);
4275 // m_chisq[2][1] = (*iter_trk)->getChisq(1,0);
4276 // m_chisq[3][0] = (*iter_trk)->getChisq(1,1);
4277 // m_chisq[3][1] = (*iter_trk)->getChisq(1,2);
4278 // m_chisq[4][0] = (*iter_trk)->getChisq(1,3);
4279 // m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4280
4281 // m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4282 // m_ndf[0][1] = (*iter_trk)->getNdf(0,1);
4283 // m_ndf[1][0] = (*iter_trk)->getNdf(0,2);
4284 // m_ndf[1][1] = (*iter_trk)->getNdf(0,3);
4285 // m_ndf[2][0] = (*iter_trk)->getNdf(0,4);
4286 // m_ndf[2][1] = (*iter_trk)->getNdf(1,0);
4287 // m_ndf[3][0] = (*iter_trk)->getNdf(1,1);
4288 // m_ndf[3][1] = (*iter_trk)->getNdf(1,2);
4289 // m_ndf[4][0] = (*iter_trk)->getNdf(1,3);
4290 // m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4291
4292 // m_stat[0][0] = (*iter_trk)->getStat(0,0);
4293 // m_stat[0][1] = (*iter_trk)->getStat(0,1);
4294 // m_stat[1][0] = (*iter_trk)->getStat(0,2);
4295 // m_stat[1][1] = (*iter_trk)->getStat(0,3);
4296 // m_stat[2][0] = (*iter_trk)->getStat(0,4);
4297 // m_stat[2][1] = (*iter_trk)->getStat(1,0);
4298 // m_stat[3][0] = (*iter_trk)->getStat(1,1);
4299 // m_stat[3][1] = (*iter_trk)->getStat(1,2);
4300 // m_stat[4][0] = (*iter_trk)->getStat(1,3);
4301 // m_stat[4][1] = (*iter_trk)->getStat(1,4);
4302
4303 // RootConversion changed in BOSS6.0, so use thefollowing:
4304 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4305 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
4306 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
4307 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
4308 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
4309 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
4310 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
4311 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
4312 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
4313 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4314
4315 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4316 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
4317 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
4318 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
4319 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
4320 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
4321 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
4322 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
4323 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
4324 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4325
4326 m_stat[0][0] = (*iter_trk)->getStat(0,0);
4327 m_stat[1][0] = (*iter_trk)->getStat(0,1);
4328 m_stat[2][0] = (*iter_trk)->getStat(0,2);
4329 m_stat[3][0] = (*iter_trk)->getStat(0,3);
4330 m_stat[4][0] = (*iter_trk)->getStat(0,4);
4331 m_stat[0][1] = (*iter_trk)->getStat(1,0);
4332 m_stat[1][1] = (*iter_trk)->getStat(1,1);
4333 m_stat[2][1] = (*iter_trk)->getStat(1,2);
4334 m_stat[3][1] = (*iter_trk)->getStat(1,3);
4335 m_stat[4][1] = (*iter_trk)->getStat(1,4);
4336
4337 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
4338 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
4339 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
4340 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
4341 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
4342
4343 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
4344 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
4345 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
4346 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
4347 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
4348
4349 m_lpt = 1/m_lhelix[2];
4350 m_lpte = 1/m_lhelixe[2];
4351 m_lptmu = 1/m_lhelixmu[2];
4352 m_lptk = 1/m_lhelixk[2];
4353 m_lptp = 1/m_lhelixp[2];
4354
4355 m_fpt = 1/m_fhelix[2];
4356 m_fpte = 1/m_fhelixe[2];
4357 m_fptmu = 1/m_fhelixmu[2];
4358 m_fptk = 1/m_fhelixk[2];
4359 m_fptp = 1/m_fhelixp[2];
4360
4361 if(debug_ >= 3){
4362 std::cout<<" "<<std::endl;
4363 std::cout<<"in file Kalman_fitting_anal ,the m_fpt is .."<<m_fpt<<std::endl;
4364 std::cout<<"in file Kalman_fitting_anal ,the m_fpte is .."<<m_fpte<<std::endl;
4365 std::cout<<"in file Kalman_fitting_anal ,the m_fptmu is .."<<m_fptmu<<std::endl;
4366 std::cout<<"in file Kalman_fitting_anal ,the m_fptk is .."<<m_fptk<<std::endl;
4367 std::cout<<"in file Kalman_fitting_anal ,the m_fptp is .."<<m_fptp<<std::endl;
4368 }
4369
4370 m_zpt = 1/m_zhelix[2];
4371 m_zpte = 1/m_zhelixe[2];
4372 m_zptmu = 1/m_zhelixmu[2];
4373 m_zptk = 1/m_zhelixk[2];
4374 m_zptp = 1/m_zhelixp[2];
4375
4376 if(debug_ >= 3) {
4377 std::cout<<"in file Kalman_fitting_anal ,the m_zpt is .."<<m_zpt<<std::endl;
4378 std::cout<<"in file Kalman_fitting_anal ,the m_zpte is .."<<m_zpte<<std::endl;
4379 std::cout<<"in file Kalman_fitting_anal ,the m_zptmu is .."<<m_zptmu<<std::endl;
4380 std::cout<<"in file Kalman_fitting_anal ,the m_zptk is .."<<m_zptk<<std::endl;
4381 std::cout<<"in file Kalman_fitting_anal ,the m_zptp is .."<<m_zptp<<std::endl;
4382 }
4383 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
4384 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
4385 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
4386 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
4387 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
4388
4389 if(debug_ >= 3) {
4390 std::cout<<"in file Kalman_fitting_anal ,the m_zptot is .."<<m_zptot<<std::endl;
4391 std::cout<<"in file Kalman_fitting_anal ,the m_zptote is .."<<m_zptote<<std::endl;
4392 std::cout<<"in file Kalman_fitting_anal ,the m_zptotmu is .."<<m_zptotmu<<std::endl;
4393 std::cout<<"in file Kalman_fitting_anal ,the m_zptotk is .."<<m_zptotk<<std::endl;
4394 std::cout<<"in file Kalman_fitting_anal ,the m_zptotp is .."<<m_zptotp<<std::endl;
4395 }
4396
4397 if(ntuple_&32) {
4398 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
4399 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
4400 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
4401 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
4402 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
4403 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
4404 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
4405 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
4406 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
4407 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
4408 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
4409 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
4410 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
4411 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
4412 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
4413 }
4414
4415 StatusCode sc1 = m_nt1->write();
4416 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
4417 }
4418
4419 if(ntuple_&4) {
4420 if(jj == 1) {
4421 phi1 = (*iter_trk)->getFFi0();
4422 r1 = (*iter_trk)->getFDr();
4423 z1 = (*iter_trk)->getFDz();
4424 kap1 = (*iter_trk)->getFCpa();
4425 tanl1 = (*iter_trk)->getFTanl();
4426 charge1 = kap1/fabs(kap1);
4427 x1 = r1*cos(phi1);
4428 y1 = r1*sin(phi1);
4429 p1 = sqrt(1+tanl1*tanl1)/kap1;
4430 the1 = M_PI/2-atan(tanl1);
4431 px1 = -sin(phi1)/fabs(kap1);
4432 py1 = cos(phi1)/fabs(kap1);
4433 pz1= tanl1/fabs(kap1);
4434
4435 } else if(jj == 2) {
4436 phi2 = (*iter_trk)->getFFi0();
4437 r2 = (*iter_trk)->getFDr();
4438 z2 = (*iter_trk)->getFDz();
4439 kap2 = (*iter_trk)->getFCpa();
4440 tanl2 = (*iter_trk)->getFTanl();
4441 charge2 = kap2/fabs(kap2);
4442 x2 = r1*cos(phi2);
4443 y2 = r1*sin(phi2);
4444 p2 = sqrt(1+tanl2*tanl2)/kap1;
4445 the2 = M_PI/2-atan(tanl2);
4446 px2 = -sin(phi2)/fabs(kap2);
4447 py2 = cos(phi2)/fabs(kap2);
4448 pz2= tanl2/fabs(kap2);
4449 }
4450 }
4451 }
4452 if(ntuple_&4) {
4453 m_delx = x1 - x2;
4454 m_dely = y1 - y2;
4455 m_delz = z1 - z2;
4456 m_delthe = the1 + the2;
4457 m_delphi = phi1- phi2;
4458 m_delp = p1 - p2;
4459 m_delpx = charge1*fabs(px1) + charge2*fabs(px2);
4460 m_delpy = charge1*fabs(py1) + charge2*fabs(py2);
4461 m_delpz = charge1*fabs(pz1) + charge2*fabs(pz2);
4462
4463 StatusCode sc2 = m_nt2->write();
4464 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
4465 }
4466
4467 delete [] order;
4468 delete [] rCont;
4469 delete [] rGen;
4470 delete [] rOM;
4471
4472 if (debug_ == 4)
4473 cout << "Kalfitting finished " << std::endl;
4474 //cout << "kalman fitting end" << endl;
4475}
4476
4478{
4479
4480 MsgStream log(msgSvc(), name());
4481 double Pt_threshold(0.3);
4482 Hep3Vector IP(0,0,0);
4483
4484 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
4485 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
4486 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
4487
4488 // Table Manager
4489 if ( !&whMgr ) return;
4490
4491 // Get reduced chi**2 of Mdc track :
4492 int ntrk = mdcMgr->size();
4493 double* rPt = new double[ntrk];
4494 int* rOM = new int[ntrk];
4495 unsigned int* order = new unsigned int[ntrk];
4496 unsigned int* rCont = new unsigned int[ntrk];
4497 unsigned int* rGen = new unsigned int[ntrk];
4498
4499 int index = 0;
4500 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
4501 end = mdcMgr->end(); it != end; it++) {
4502 // Pt
4503 rPt[index] = 0;
4504 if (it->helix[2])
4505 rPt[index] = 1 / fabs(it->helix[2]);
4506 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
4507 if(rPt[index] < 0) rPt[index] = DBL_MAX;
4508 // Outermost layer
4509 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
4510 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
4511 int outermost(-1);
4512 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4513 ii !=pt.begin()-1; ii--) {
4514 int lyr((*ii)->geo->Lyr()->Id());
4515 if (outermost < lyr) outermost = lyr;
4516 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
4517 }
4518 rOM[index] = outermost;
4519 order[index] = index;
4520 ++index;
4521 }
4522
4523 // Sort Mdc tracks by Pt
4524 for (int j, k = ntrk - 1; k >= 0; k = j){
4525 j = -1;
4526 for(int i = 1; i <= k; i++)
4527 if(rPt[i - 1] < rPt[i]){
4528 j = i - 1;
4529 std::swap(order[i], order[j]);
4530 std::swap(rPt[i], rPt[j]);
4531 std::swap(rOM[i], rOM[j]);
4532 std::swap(rCont[i], rCont[j]);
4533 std::swap(rGen[i], rGen[j]);
4534 }
4535 }
4536 delete [] rPt;
4537 //
4538 int newcount(0);
4539 //check whether Recon already registered
4540 DataObject *aReconEvent;
4541 eventSvc()->findObject("/Event/Recon",aReconEvent);
4542 if(!aReconEvent) {
4543 // register ReconEvent Data Object to TDS;
4544 ReconEvent* recevt = new ReconEvent;
4545 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
4546 if(sc!=StatusCode::SUCCESS) {
4547 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
4548 return;
4549 }
4550 }
4551
4552 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
4554 //make RecMdcKalTrackCol
4555 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
4556
4557 // Loop over tracks given by PatRecon :
4558 for(int l = 0; l < ntrk; l++) {
4559 // m_timer[3]->start();
4560 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[l]);
4561 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[l]);
4562
4563 // Reject the ones with quality != 0
4564 int trasqual = TrasanTRK_add.quality;
4565 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
4566 if (trasqual) continue;
4567
4568 newcount++;
4569 if (debug_ == 4)
4570 cout << "******* KalFit NUMBER : " << newcount << std::endl;
4571
4572 // What kind of KalFit ?
4573 int type(0);
4574 if ((TrasanTRK_add.decision & 32) == 32 ||
4575 (TrasanTRK_add.decision & 64) == 64) type = 1;
4576
4577 // Initialisation : (x, a, ea)
4578 HepPoint3D x(TrasanTRK.pivot[0],
4579 TrasanTRK.pivot[1],
4580 TrasanTRK.pivot[2]);
4581
4582 HepVector a(5);
4583 for(int i = 0; i < 5; i++)
4584 a[i] = TrasanTRK.helix[i];
4585
4586 HepSymMatrix ea(5);
4587 for(int i = 0, k = 0; i < 5; i++) {
4588 for(int j = 0; j <= i; j++) {
4589 ea[i][j] = matrixg_*TrasanTRK.error[k++];
4590 ea[j][i] = ea[i][j];
4591 }
4592 }
4593
4595
4596 double fiTerm = TrasanTRK.fiTerm;
4597 int way(1);
4598 // Prepare the track found :
4599 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
4600 track_lead.bFieldZ(KalFitTrack::Bznom_);
4601 // Mdc Hits
4602 int inlyr(999), outlyr(-1);
4603 int* rStat = new int[43];
4604 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
4605 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
4606 int hit_in(0);
4607 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
4608 // Number of hits/layer
4609 int Num[43] = {0};
4610 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4611 ii != pt.begin()-1; ii--) {
4612 Num[(*ii)->geo->Lyr()->Id()]++;
4613 }
4614
4615 int hit_asso(0);
4616 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4617 ii != pt.begin()-1; ii--) {
4618
4619 hit_asso++;
4620 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
4621 if (debug_ ==4)
4622 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
4623 << " hits in the layer "
4624 << (*ii)->geo->Lyr()->Id() << std::endl;
4625 continue;
4626 }
4627 // if(ii!=pt.end()-1){
4628 // if(42 == (*ii)->geo->Lyr()->Id() && 42 == (*(ii+1))->geo->Lyr()->Id()){
4629 // MdcRec_wirhit * rechit_before = *(ii+1);
4630 // if((*rechit_before).tdc < (**ii).tdc) continue;
4631 // else if(track_lead.HitsMdc().size()>0 && rStat[42]){
4632 // track_lead.HitsMdc().pop_back();
4633 // }
4634 // }
4635 // else{
4636 // int layer_before=(*(ii+1))->geo->Lyr()->Id();
4637 // if(layer_before == (*ii)->geo->Lyr()->Id()){
4638 // MdcRec_wirhit * rechit_before = *(ii+1);
4639 // if((*rechit_before).rechitptr->getDriftT()>450 || (**ii).rechitptr->getDriftT()>450.){
4640 // if((*rechit_before).tdc < (**ii).tdc) continue;
4641 // else if(track_lead.HitsMdc().size()>0 && rStat[layer_before]){
4642 // track_lead.HitsMdc().pop_back();
4643 // }
4644 // }
4645 // }
4646 // }
4647 // }
4648
4649 hit_in++;
4650 MdcRec_wirhit & rechit = **ii;
4651 double dist[2] = {rechit.ddl, rechit.ddr};
4652 double erdist[2] = {rechit.erddl, rechit.erddr};
4653 const MdcGeoWire* geo = rechit.geo;
4654
4655 int lr_decision(0);
4656 if (KalFitTrack::LR_ == 1){
4657 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
4658 // if (rechit.lr==0) lr_decision=-1;
4659 else if (rechit.lr==1) lr_decision=1;
4660 }
4661
4662 int ind(geo->Lyr()->Id());
4663 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
4664 lr_decision, rechit.tdc,
4665 dist, erdist,
4666 _wire+(geo->Id()), rechit.rechitptr));
4667 // inner/outer layer :
4668 rStat[ind]++;
4669 if (inlyr>ind) inlyr = ind;
4670 if (outlyr<ind) outlyr = ind;
4671 }
4672 if (debug_ == 4)
4673 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
4674
4675 // Empty layers :
4676 int empty_between(0), empty(0);
4677 for (int i= inlyr; i <= outlyr; i++)
4678 if (!rStat[i]) empty_between++;
4679 empty = empty_between+inlyr+(42-outlyr);
4680 delete [] rStat;
4681
4682 // RMK high momentum track under study, probably not neeeded...
4683 track_lead.order_wirhit(1);
4684 track_lead.type(type);
4685 unsigned int nhit = track_lead.HitsMdc().size();
4686 if (!nhit && debug_ == 4) {
4687 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
4688 continue;
4689 }
4690
4691 // Initialisation :
4692 double KalFitst(0), KalFitax(0), KalFitschi2(0);
4693 // Move to the outer most hit :
4694 Hep3Vector outer_pivot(track_lead.x(fiTerm));
4695
4696 if(debug_ == 4) {
4697 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
4698 }
4699 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
4700 track_lead.bFieldZ(KalFitTrack::Bznom_);
4701 // attention best_chi2 reinitialize !!!
4702 if (nhit>=3 && !KalFitTrack::LR_)
4703 start_seed(track_lead, lead_, way, TrasanTRK);
4704 HepSymMatrix Eakal(5,0);
4705
4706 //init_matrix(TrasanTRK, Eakal);
4707
4708 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
4709 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
4710 choice_ = 6;
4711 }
4712
4713 init_matrix(choice_,TrasanTRK, Eakal);
4714
4715 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
4716
4717 if (debug_ == 4){
4718 std::cout << "from Mdc Pattern Recognition: " << std::endl;
4719 HepPoint3D IP(0,0,0);
4720 KalmanFit::Helix work(track_lead.pivot(),
4721 track_lead.a(),
4722 track_lead.Ea());
4723 work.pivot(IP);
4724 std::cout << " dr = " << work.a()[0]
4725 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4726 std::cout << " phi0 = " << work.a()[1]
4727 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4728 std::cout << " PT = " << 1/work.a()[2]
4729 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4730 std::cout << " dz = " << work.a()[3]
4731 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4732 std::cout << " tanl = " << work.a()[4]
4733 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4734 }
4735
4736 filter_fwd_calib(track_lead, lead_, way, Eakal);
4737 track_lead.update_forMdc();
4738
4739 HepPoint3D IP(0,0,0);
4740 if (debug_ == 4) {
4741 cout << " Mdc FIRST KALMAN FIT " << std::endl;
4742 KalmanFit::Helix work(track_lead.pivot(),
4743 track_lead.a(),
4744 track_lead.Ea());
4745 work.pivot(IP);
4746 cout << " dr = " << work.a()[0]
4747 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4748 cout << " phi0 = " << work.a()[1]
4749 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4750 cout << " PT = " << 1/work.a()[2]
4751 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4752 cout << " dz = " << work.a()[3]
4753 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4754 cout << " tanl = " << work.a()[4]
4755 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4756 }
4757
4758 // fill TDS
4759 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
4760
4761 // Complete the track (other mass assumption, backward) and
4762 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
4763 }
4764
4765
4766 StatusCode kalsc;
4767 //check whether the RecMdcKalTrackCol has been already registered
4768 DataObject *aRecKalEvent;
4769 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
4770 if(aRecKalEvent!=NULL) {
4771 //then unregister RecMdcKalCol
4772 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
4773 if(kalsc != StatusCode::SUCCESS) {
4774 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
4775 return;
4776 }
4777 }
4778
4779 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
4780 if( kalsc.isFailure()) {
4781 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
4782 return;
4783 }
4784 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
4785
4786
4787
4788 StatusCode segsc;
4789 //check whether the RecMdcKalHelixSegCol has been already registered
4790 DataObject *aRecKalSegEvent;
4791 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
4792 if(aRecKalSegEvent!=NULL) {
4793 //then unregister RecMdcKalHelixSegCol
4794 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
4795 if(segsc != StatusCode::SUCCESS) {
4796 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
4797 return;
4798 }
4799 }
4800
4801 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
4802 if( segsc.isFailure() ) {
4803 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
4804 return;
4805 }
4806 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
4807
4808
4809 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.);
4810 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
4811 //check the result:RecMdcKalTrackCol
4812
4813 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
4814 if (!kaltrkCol) {
4815 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
4816 return;
4817 }
4818 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
4819 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
4820 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
4821 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
4822 << "Track Id: " << (*iter_trk)->getTrackId()
4823 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
4824 << " Length of the track: "<< (*iter_trk)->getLength(2)
4825 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
4826 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
4827 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
4828 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
4829 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
4830 << "Kappa " << (*iter_trk)->getZHelix()[2]
4831 << endreq;
4832
4833 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
4834 if(debug_ == 4) {
4835 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
4836 }
4837
4838 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
4839 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
4840 if(debug_ == 4) {
4841 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
4842 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
4843 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
4844 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
4845 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
4846 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
4847 }
4848 }
4849 for( int i = 0; i<43; i++) {
4850 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
4851 << (*iter_trk)->getPathl(i) <<endreq;
4852 }
4853
4854 if(ntuple_&1) {
4855 m_trackid = (*iter_trk)->getTrackId();
4856 for( int jj =0, iii=0; jj<5; jj++) {
4857 m_length[jj] = (*iter_trk)->getLength(jj);
4858 m_tof[jj] = (*iter_trk)->getTof(jj);
4859 m_nhits[jj] = (*iter_trk)->getNhits(jj);
4860 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
4861 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
4862 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
4863 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
4864 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
4865 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
4866 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
4867 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
4868 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
4869 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
4870 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
4871 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
4872 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
4873 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
4874 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
4875 if(ntuple_&32) {
4876 for(int kk=0; kk<=jj; kk++,iii++) {
4877 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
4878 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
4879 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
4880 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
4881 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
4882 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
4883 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
4884 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
4885 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
4886 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
4887 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
4888 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
4889 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
4890 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
4891 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
4892 }
4893
4894 }
4895 }
4896
4897 // // the following logic may seem peculiar, but it IS the case(for BOSS5.0 and BOSS5.1)
4898 // m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4899 // m_chisq[0][1] = (*iter_trk)->getChisq(0,1);
4900 // m_chisq[1][0] = (*iter_trk)->getChisq(0,2);
4901 // m_chisq[1][1] = (*iter_trk)->getChisq(0,3);
4902 // m_chisq[2][0] = (*iter_trk)->getChisq(0,4);
4903 // m_chisq[2][1] = (*iter_trk)->getChisq(1,0);
4904 // m_chisq[3][0] = (*iter_trk)->getChisq(1,1);
4905 // m_chisq[3][1] = (*iter_trk)->getChisq(1,2);
4906 // m_chisq[4][0] = (*iter_trk)->getChisq(1,3);
4907 // m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4908
4909 // m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4910 // m_ndf[0][1] = (*iter_trk)->getNdf(0,1);
4911 // m_ndf[1][0] = (*iter_trk)->getNdf(0,2);
4912 // m_ndf[1][1] = (*iter_trk)->getNdf(0,3);
4913 // m_ndf[2][0] = (*iter_trk)->getNdf(0,4);
4914 // m_ndf[2][1] = (*iter_trk)->getNdf(1,0);
4915 // m_ndf[3][0] = (*iter_trk)->getNdf(1,1);
4916 // m_ndf[3][1] = (*iter_trk)->getNdf(1,2);
4917 // m_ndf[4][0] = (*iter_trk)->getNdf(1,3);
4918 // m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4919
4920 // m_stat[0][0] = (*iter_trk)->getStat(0,0);
4921 // m_stat[0][1] = (*iter_trk)->getStat(0,1);
4922 // m_stat[1][0] = (*iter_trk)->getStat(0,2);
4923 // m_stat[1][1] = (*iter_trk)->getStat(0,3);
4924 // m_stat[2][0] = (*iter_trk)->getStat(0,4);
4925 // m_stat[2][1] = (*iter_trk)->getStat(1,0);
4926 // m_stat[3][0] = (*iter_trk)->getStat(1,1);
4927 // m_stat[3][1] = (*iter_trk)->getStat(1,2);
4928 // m_stat[4][0] = (*iter_trk)->getStat(1,3);
4929 // m_stat[4][1] = (*iter_trk)->getStat(1,4);
4930
4931 // RootConversion changed in BOSS6.0, so use thefollowing:
4932 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4933 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
4934 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
4935 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
4936 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
4937 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
4938 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
4939 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
4940 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
4941 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4942
4943 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4944 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
4945 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
4946 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
4947 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
4948 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
4949 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
4950 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
4951 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
4952 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4953
4954 m_stat[0][0] = (*iter_trk)->getStat(0,0);
4955 m_stat[1][0] = (*iter_trk)->getStat(0,1);
4956 m_stat[2][0] = (*iter_trk)->getStat(0,2);
4957 m_stat[3][0] = (*iter_trk)->getStat(0,3);
4958 m_stat[4][0] = (*iter_trk)->getStat(0,4);
4959 m_stat[0][1] = (*iter_trk)->getStat(1,0);
4960 m_stat[1][1] = (*iter_trk)->getStat(1,1);
4961 m_stat[2][1] = (*iter_trk)->getStat(1,2);
4962 m_stat[3][1] = (*iter_trk)->getStat(1,3);
4963 m_stat[4][1] = (*iter_trk)->getStat(1,4);
4964
4965 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
4966 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
4967 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
4968 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
4969 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
4970
4971 m_zpt = 1/m_zhelix[2];
4972 m_zpte = 1/m_zhelixe[2];
4973 m_zptmu = 1/m_zhelixmu[2];
4974 m_zptk = 1/m_zhelixk[2];
4975 m_zptp = 1/m_zhelixp[2];
4976
4977 m_fpt = 1/m_fhelix[2];
4978 m_fpte = 1/m_fhelixe[2];
4979 m_fptmu = 1/m_fhelixmu[2];
4980 m_fptk = 1/m_fhelixk[2];
4981 m_fptp = 1/m_fhelixp[2];
4982
4983 m_lpt = 1/m_lhelix[2];
4984 m_lpte = 1/m_lhelixe[2];
4985 m_lptmu = 1/m_lhelixmu[2];
4986 m_lptk = 1/m_lhelixk[2];
4987 m_lptp = 1/m_lhelixp[2];
4988
4989 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
4990 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
4991 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
4992 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
4993 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
4994
4995 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
4996 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
4997 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
4998 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
4999 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
5000 if(ntuple_&32) {
5001 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
5002 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
5003 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
5004 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
5005 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
5006 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
5007 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
5008 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
5009 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
5010 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
5011 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
5012 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
5013 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
5014 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
5015 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
5016 }
5017
5018 StatusCode sc1 = m_nt1->write();
5019 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
5020 }
5021
5022 if(ntuple_&4) {
5023 if(jj == 1) {
5024 phi1 = (*iter_trk)->getFFi0();
5025 r1 = (*iter_trk)->getFDr();
5026 z1 = (*iter_trk)->getFDz();
5027 kap1 = (*iter_trk)->getFCpa();
5028 tanl1 = (*iter_trk)->getFTanl();
5029 x1 = r1*cos(phi1);
5030 y1 = r1*sin(phi1);
5031 p1 = sqrt(1+tanl1*tanl1)/kap1;
5032 the1 = M_PI/2-atan(tanl1);
5033 } else if(jj == 2) {
5034 phi2 = (*iter_trk)->getFFi0();
5035 r2 = (*iter_trk)->getFDr();
5036 z2 = (*iter_trk)->getFDz();
5037 kap2 = (*iter_trk)->getFCpa();
5038 tanl2 = (*iter_trk)->getFTanl();
5039 x2 = r1*cos(phi2);
5040 y2 = r1*sin(phi2);
5041 p2 = sqrt(1+tanl2*tanl2)/kap1;
5042 the2 = M_PI/2-atan(tanl2);
5043 }
5044 }
5045 }
5046 if(ntuple_&4) {
5047 m_delx = x1 - x2;
5048 m_dely = y1 - y2;
5049 m_delz = z1 - z2;
5050 m_delthe = the1 + the2;
5051 m_delphi = phi1- phi2;
5052 m_delp = p1 - p2;
5053 StatusCode sc2 = m_nt2->write();
5054 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
5055 }
5056 delete [] order;
5057 delete [] rCont;
5058 delete [] rGen;
5059 delete [] rOM;
5060
5061 if (debug_ == 4)
5062 cout << "Kalfitting finished " << std::endl;
5063}
5064
5065//Mdc alignment by MdcxReco_Csmc_Sew
5067{
5068
5069 MsgStream log(msgSvc(), name());
5070 double Pt_threshold(0.3);
5071 Hep3Vector IP(0,0,0);
5072
5073 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
5074 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
5075 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
5076
5077 // Table Manager
5078 if ( !&whMgr ) return;
5079
5080 // Get reduced chi**2 of Mdc track :
5081 int ntrk = mdcMgr->size();
5082 // cout<<"ntrk: "<<ntrk<<endl;
5083
5084 int nhits = whMgr->size();
5085 //cout<<"nhits: "<<nhits<<endl;
5086
5087
5088 //check whether Recon already registered
5089 DataObject *aReconEvent;
5090 eventSvc()->findObject("/Event/Recon",aReconEvent);
5091 if(!aReconEvent) {
5092 // register ReconEvent Data Object to TDS;
5093 ReconEvent* recevt = new ReconEvent;
5094 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
5095 if(sc!=StatusCode::SUCCESS) {
5096 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
5097 return;
5098 }
5099 }
5100
5101 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
5103 //make RecMdcKalTrackCol
5104 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
5105
5106
5107 MdcRec_trk& TrasanTRK = *(mdcMgr->begin());
5108 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin());
5109 // Reject the ones with quality != 0
5110 // int trasqual = TrasanTRK_add.quality;
5111 // if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5112 // if (trasqual) continue;
5113
5114 // What kind of KalFit ?
5115 int type(0);
5116 if ((TrasanTRK_add.decision & 32) == 32 ||
5117 (TrasanTRK_add.decision & 64) == 64) type = 1;
5118
5119 // Initialisation : (x, a, ea)
5120 HepPoint3D x(TrasanTRK.pivot[0],
5121 TrasanTRK.pivot[1],
5122 TrasanTRK.pivot[2]);
5123
5124 HepVector a(5);
5125 for(int i = 0; i < 5; i++)
5126 a[i] = TrasanTRK.helix[i];
5127
5128 HepSymMatrix ea(5);
5129 for(int i = 0, k = 0; i < 5; i++) {
5130 for(int j = 0; j <= i; j++) {
5131 ea[i][j] = matrixg_*TrasanTRK.error[k++];
5132 ea[j][i] = ea[i][j];
5133 }
5134 }
5135
5137
5138 double fiTerm = TrasanTRK.fiTerm;
5139 int way(1);
5140 // Prepare the track found :
5141 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
5142 track_lead.bFieldZ(KalFitTrack::Bznom_);
5143
5144 int hit_asso(0);
5145 // Reject the ones with quality != 0
5146 int trasqual = TrasanTRK_add.quality;
5147 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5148 if (trasqual) return;
5149 // Mdc Hits
5150 int inlyr(999), outlyr(-1);
5151 int* rStat = new int[43];
5152 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
5153 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
5154 int hit_in(0);
5155 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
5156 // Number of hits/layer
5157 int Num[43] = {0};
5158 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5159 ii != pt.begin()-1; ii--) {
5160 Num[(*ii)->geo->Lyr()->Id()]++;
5161 }
5162
5163 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5164 ii != pt.begin()-1; ii--) {
5165
5166 hit_asso++;
5167 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
5168 if (debug_ ==4)
5169 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
5170 << " hits in the layer "
5171 << (*ii)->geo->Lyr()->Id() << std::endl;
5172 continue;
5173 }
5174
5175 hit_in++;
5176 MdcRec_wirhit & rechit = **ii;
5177 double dist[2] = {rechit.ddl, rechit.ddr};
5178 double erdist[2] = {rechit.erddl, rechit.erddr};
5179 const MdcGeoWire* geo = rechit.geo;
5180
5181 int lr_decision(0);
5182 if (KalFitTrack::LR_ == 1){
5183 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
5184 // if (rechit.lr==0) lr_decision=-1;
5185 else if (rechit.lr==1) lr_decision=1;
5186 }
5187
5188 int ind(geo->Lyr()->Id());
5189 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
5190 lr_decision, rechit.tdc,
5191 dist, erdist,
5192 _wire+(geo->Id()), rechit.rechitptr));
5193 // inner/outer layer :
5194 rStat[ind]++;
5195 if (inlyr>ind) inlyr = ind;
5196 if (outlyr<ind) outlyr = ind;
5197 }
5198 // Empty layers :
5199 int empty_between(0), empty(0);
5200 for (int i= inlyr; i <= outlyr; i++)
5201 if (!rStat[i]) empty_between++;
5202 empty = empty_between+inlyr+(42-outlyr);
5203 delete [] rStat;
5204
5205 if (debug_ == 4)
5206 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
5207
5208
5209 // RMK high momentum track under study, probably not neeeded...
5210 track_lead.order_wirhit(0);
5211 track_lead.type(type);
5212 unsigned int nhit = track_lead.HitsMdc().size();
5213 if (nhit<70) {
5214 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
5215 return;
5216 }
5217
5218 // Initialisation :
5219 double KalFitst(0), KalFitax(0), KalFitschi2(0);
5220 // Move to the outer most hit :
5221 Hep3Vector outer_pivot(track_lead.x(fiTerm));
5222
5223 if(debug_ == 4) {
5224 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
5225 }
5226 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
5227 track_lead.bFieldZ(KalFitTrack::Bznom_);
5228 // attention best_chi2 reinitialize !!!
5229 if (nhit>=3 && !KalFitTrack::LR_)
5230 start_seed(track_lead, lead_, way, TrasanTRK);
5231 HepSymMatrix Eakal(5,0);
5232
5233 //init_matrix(TrasanTRK, Eakal);
5234
5235 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
5236 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5237 choice_ = 6;
5238 }
5239
5240 init_matrix(choice_,TrasanTRK, Eakal);
5241
5242 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
5243
5244 if (debug_ == 4){
5245 std::cout << "from Mdc Pattern Recognition: " << std::endl;
5246 //HepPoint3D IP(0,0,0);
5247 KalmanFit::Helix work(track_lead.pivot(),
5248 track_lead.a(),
5249 track_lead.Ea());
5250 work.pivot(IP);
5251 std::cout << " dr = " << work.a()[0]
5252 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
5253 std::cout << " phi0 = " << work.a()[1]
5254 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
5255 std::cout << " PT = " << 1/work.a()[2]
5256 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
5257 std::cout << " dz = " << work.a()[3]
5258 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
5259 std::cout << " tanl = " << work.a()[4]
5260 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
5261 }
5262 filter_fwd_calib(track_lead, lead_, way, Eakal);
5263 track_lead.update_forMdc();
5264
5265 //HepPoint3D IP(0,0,0);
5266 if (debug_ == 4) {
5267 cout << " Mdc FIRST KALMAN FIT " << std::endl;
5268 KalmanFit::Helix work1(track_lead.pivot(),
5269 track_lead.a(),
5270 track_lead.Ea());
5271 work1.pivot(IP);
5272 cout << " dr = " << work1.a()[0]
5273 << ", Er_dr = " << sqrt(work1.Ea()[0][0]) << std::endl;
5274 cout << " phi0 = " << work1.a()[1]
5275 << ", Er_phi0 = " << sqrt(work1.Ea()[1][1]) << std::endl;
5276 cout << " PT = " << 1/work1.a()[2]
5277 << ", Er_kappa = " << sqrt(work1.Ea()[2][2]) << std::endl;
5278 cout << " dz = " << work1.a()[3]
5279 << ", Er_dz = " << sqrt(work1.Ea()[3][3]) << std::endl;
5280 cout << " tanl = " << work1.a()[4]
5281 << ", Er_tanl = " << sqrt(work1.Ea()[4][4]) << std::endl;
5282 }
5283
5284 // fill TDS
5285 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
5286
5287 // Complete the track (other mass assumption, backward) and
5288 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
5289
5290
5291 StatusCode kalsc;
5292 //check whether the RecMdcKalTrackCol has been already registered
5293 DataObject *aRecKalEvent;
5294 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
5295 if(aRecKalEvent!=NULL) {
5296 //then unregister RecMdcKalCol
5297 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
5298 if(kalsc != StatusCode::SUCCESS) {
5299 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
5300 return;
5301 }
5302 }
5303
5304 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
5305 if( kalsc.isFailure()) {
5306 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
5307 return;
5308 }
5309 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
5310
5311
5312
5313 StatusCode segsc;
5314 //check whether the RecMdcKalHelixSegCol has been already registered
5315 DataObject *aRecKalSegEvent;
5316 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
5317 if(aRecKalSegEvent!=NULL) {
5318 //then unregister RecMdcKalHelixSegCol
5319 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
5320 if(segsc != StatusCode::SUCCESS) {
5321 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
5322 return;
5323 }
5324 }
5325
5326 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
5327 if( segsc.isFailure() ) {
5328 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
5329 return;
5330 }
5331 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
5332
5333
5334 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.);
5335 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
5336 //check the result:RecMdcKalTrackCol
5337
5338 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
5339 if (!kaltrkCol) {
5340 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
5341 return;
5342 }
5343 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
5344 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
5345 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
5346 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
5347 << "Track Id: " << (*iter_trk)->getTrackId()
5348 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
5349 << " Length of the track: "<< (*iter_trk)->getLength(2)
5350 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
5351 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
5352 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
5353 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
5354 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
5355 << "Kappa " << (*iter_trk)->getZHelix()[2]
5356 << "zhelixmu "<<(*iter_trk)->getZHelixMu()
5357 << endreq;
5358
5359 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
5360 if(debug_ == 4) {
5361 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
5362 }
5363
5364 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
5365 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
5366 if(debug_ == 4) {
5367 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
5368 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
5369 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
5370 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
5371 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
5372 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
5373 }
5374 }
5375 for( int i = 0; i<43; i++) {
5376 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
5377 << (*iter_trk)->getPathl(i) <<endreq;
5378 }
5379
5380 if(ntuple_&1) {
5381 m_trackid = (*iter_trk)->getTrackId();
5382 for( int jj =0, iii=0; jj<5; jj++) {
5383 m_length[jj] = (*iter_trk)->getLength(jj);
5384 m_tof[jj] = (*iter_trk)->getTof(jj);
5385 m_nhits[jj] = (*iter_trk)->getNhits(jj);
5386 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
5387 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
5388 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
5389 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
5390 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
5391 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
5392 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
5393 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
5394 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
5395 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
5396 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
5397 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
5398 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
5399 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
5400 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
5401 if(ntuple_&32) {
5402 for(int kk=0; kk<=jj; kk++,iii++) {
5403 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
5404 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
5405 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
5406 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
5407 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
5408 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
5409 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
5410 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
5411 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
5412 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
5413 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
5414 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
5415 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
5416 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
5417 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
5418 }
5419
5420 }
5421 }
5422
5423 // RootConversion changed in BOSS6.0, so use thefollowing:
5424 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
5425 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
5426 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
5427 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
5428 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
5429 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
5430 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
5431 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
5432 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
5433 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
5434
5435 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
5436 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
5437 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
5438 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
5439 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
5440 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
5441 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
5442 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
5443 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
5444 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
5445
5446 m_stat[0][0] = (*iter_trk)->getStat(0,0);
5447 m_stat[1][0] = (*iter_trk)->getStat(0,1);
5448 m_stat[2][0] = (*iter_trk)->getStat(0,2);
5449 m_stat[3][0] = (*iter_trk)->getStat(0,3);
5450 m_stat[4][0] = (*iter_trk)->getStat(0,4);
5451 m_stat[0][1] = (*iter_trk)->getStat(1,0);
5452 m_stat[1][1] = (*iter_trk)->getStat(1,1);
5453 m_stat[2][1] = (*iter_trk)->getStat(1,2);
5454 m_stat[3][1] = (*iter_trk)->getStat(1,3);
5455 m_stat[4][1] = (*iter_trk)->getStat(1,4);
5456
5457 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
5458 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
5459 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
5460 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
5461 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
5462
5463 m_zpt = 1/m_zhelix[2];
5464 m_zpte = 1/m_zhelixe[2];
5465 m_zptmu = 1/m_zhelixmu[2];
5466 m_zptk = 1/m_zhelixk[2];
5467 m_zptp = 1/m_zhelixp[2];
5468
5469 m_fpt = 1/m_fhelix[2];
5470 m_fpte = 1/m_fhelixe[2];
5471 m_fptmu = 1/m_fhelixmu[2];
5472 m_fptk = 1/m_fhelixk[2];
5473 m_fptp = 1/m_fhelixp[2];
5474
5475 m_lpt = 1/m_lhelix[2];
5476 m_lpte = 1/m_lhelixe[2];
5477 m_lptmu = 1/m_lhelixmu[2];
5478 m_lptk = 1/m_lhelixk[2];
5479 m_lptp = 1/m_lhelixp[2];
5480
5481 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
5482 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
5483 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
5484 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
5485 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
5486
5487 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
5488 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
5489 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
5490 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
5491 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
5492 if(ntuple_&32) {
5493 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
5494 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
5495 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
5496 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
5497 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
5498 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
5499 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
5500 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
5501 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
5502 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
5503 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
5504 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
5505 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
5506 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
5507 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
5508 }
5509
5510 StatusCode sc1 = m_nt1->write();
5511 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
5512 }
5513
5514 if(ntuple_&4) {
5515 if(jj == 1) {
5516 phi1 = (*iter_trk)->getFFi0();
5517 r1 = (*iter_trk)->getFDr();
5518 z1 = (*iter_trk)->getFDz();
5519 kap1 = (*iter_trk)->getFCpa();
5520 tanl1 = (*iter_trk)->getFTanl();
5521 x1 = r1*cos(phi1);
5522 y1 = r1*sin(phi1);
5523 p1 = sqrt(1+tanl1*tanl1)/kap1;
5524 the1 = M_PI/2-atan(tanl1);
5525 } else if(jj == 2) {
5526 phi2 = (*iter_trk)->getFFi0();
5527 r2 = (*iter_trk)->getFDr();
5528 z2 = (*iter_trk)->getFDz();
5529 kap2 = (*iter_trk)->getFCpa();
5530 tanl2 = (*iter_trk)->getFTanl();
5531 x2 = r1*cos(phi2);
5532 y2 = r1*sin(phi2);
5533 p2 = sqrt(1+tanl2*tanl2)/kap1;
5534 the2 = M_PI/2-atan(tanl2);
5535 }
5536 }
5537 }
5538 if(ntuple_&4) {
5539 m_delx = x1 - x2;
5540 m_dely = y1 - y2;
5541 m_delz = z1 - z2;
5542 m_delthe = the1 + the2;
5543 m_delphi = phi1- phi2;
5544 m_delp = p1 - p2;
5545 StatusCode sc2 = m_nt2->write();
5546 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
5547 }
5548
5549 if (debug_ == 4)
5550 cout << "Kalfitting finished " << std::endl;
5551}
5552
5553
5554//Mdc alignment by conecting two cosmic segments for one track
5556{
5557
5558 MsgStream log(msgSvc(), name());
5559 double Pt_threshold(0.3);
5560 Hep3Vector IP(0,0,0);
5561
5562 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
5563 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
5564 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
5565
5566 // Table Manager
5567 if ( !&whMgr ) return;
5568
5569 // Get reduced chi**2 of Mdc track :
5570 int ntrk = mdcMgr->size();
5571 //cout<<"ntrk: "<<ntrk<<endl;
5572
5573 int nhits = whMgr->size();
5574 //cout<<"nhits: "<<nhits<<endl;
5575
5576
5577 double* rY = new double[ntrk];
5578 double* rfiTerm = new double[ntrk];
5579 double* rPt = new double[ntrk];
5580 int* rOM = new int[ntrk];
5581 unsigned int* order = new unsigned int[ntrk];
5582 unsigned int* rCont = new unsigned int[ntrk];
5583 unsigned int* rGen = new unsigned int[ntrk];
5584
5585 int index = 0;
5586 Hep3Vector csmp3[2];
5587 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
5588 end = mdcMgr->end(); it != end; it++) {
5589 //order by phi term
5590 rfiTerm[index]=it->fiTerm;
5591 //cout<<"fiTerm: "<<rfiTerm[index]<<endl;
5592 // Pt
5593 rPt[index] = 0;
5594 if (it->helix[2])
5595 rPt[index] = 1 / fabs(it->helix[2]);
5596 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
5597 if(rPt[index] < 0) rPt[index] = DBL_MAX;
5598 // Outermost layer
5599 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
5600 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
5601 int outermost(-1);
5602 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5603 ii !=pt.begin()-1; ii--) {
5604 int lyr((*ii)->geo->Lyr()->Id());
5605 if (outermost < lyr) {
5606 outermost = lyr;
5607 rY[index] = (*ii)->geo->Forward().y();
5608 }
5609 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
5610 }
5611 rOM[index] = outermost;
5612 order[index] = index;
5613 ++index;
5614 }
5615
5616 // Sort Mdc tracks by fiTerm
5617 for (int j, k = ntrk - 1; k >= 0; k = j){
5618 j = -1;
5619 for(int i = 1; i <= k; i++)
5620 if(rY[i - 1] < rY[i]){
5621 j = i - 1;
5622 std::swap(order[i], order[j]);
5623 std::swap(rY[i], rY[j]);
5624 std::swap(rOM[i], rOM[j]);
5625 std::swap(rCont[i], rCont[j]);
5626 std::swap(rGen[i], rGen[j]);
5627 }
5628 }
5629 delete [] rPt;
5630 delete [] rY;
5631 delete [] rfiTerm;
5632 //
5633 int newcount(0);
5634 //check whether Recon already registered
5635 DataObject *aReconEvent;
5636 eventSvc()->findObject("/Event/Recon",aReconEvent);
5637 if(!aReconEvent) {
5638 // register ReconEvent Data Object to TDS;
5639 ReconEvent* recevt = new ReconEvent;
5640 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
5641 if(sc!=StatusCode::SUCCESS) {
5642 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
5643 return;
5644 }
5645 }
5646
5647 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
5649 //make RecMdcKalTrackCol
5650 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
5651
5652 // m_timer[3]->start();
5653 // MdcRec_trk& TrasanTRK;
5654 // MdcRec_trk_add& TrasanTRK_add;
5655
5656 // for(int l = 0; l < ntrk; l++) {
5657 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[1]);
5658 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[1]);
5659 // Reject the ones with quality != 0
5660 // int trasqual = TrasanTRK_add.quality;
5661 // if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5662 // if (trasqual) continue;
5663
5664 newcount++;
5665 if (debug_ == 4)
5666 cout << "******* KalFit NUMBER : " << newcount << std::endl;
5667
5668 // What kind of KalFit ?
5669 int type(0);
5670 if ((TrasanTRK_add.decision & 32) == 32 ||
5671 (TrasanTRK_add.decision & 64) == 64) type = 1;
5672
5673 // Initialisation : (x, a, ea)
5674 HepPoint3D x(TrasanTRK.pivot[0],
5675 TrasanTRK.pivot[1],
5676 TrasanTRK.pivot[2]);
5677
5678 HepVector a(5);
5679 for(int i = 0; i < 5; i++)
5680 a[i] = TrasanTRK.helix[i];
5681
5682 HepSymMatrix ea(5);
5683 for(int i = 0, k = 0; i < 5; i++) {
5684 for(int j = 0; j <= i; j++) {
5685 ea[i][j] = matrixg_*TrasanTRK.error[k++];
5686 ea[j][i] = ea[i][j];
5687 }
5688 }
5689
5691
5692 double fiTerm = TrasanTRK.fiTerm;
5693 int way(1);
5694 // Prepare the track found :
5695 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
5696 track_lead.bFieldZ(KalFitTrack::Bznom_);
5697
5698 int hit_asso(0);
5699 for(int l = 0; l < ntrk; l++) {
5700 MdcRec_trk& TrasanTRK1 = *(mdcMgr->begin() + order[l]);
5701 MdcRec_trk_add& TrasanTRK_add1 = *(mdc_addMgr->begin()+order[l]);
5702 // Reject the ones with quality != 0
5703 int trasqual = TrasanTRK_add1.quality;
5704 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5705 if (trasqual) continue;
5706 // Mdc Hits
5707 int inlyr(999), outlyr(-1);
5708 int* rStat = new int[43];
5709 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
5710 std::vector<MdcRec_wirhit*> pt=TrasanTRK1.hitcol;
5711 int hit_in(0);
5712 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
5713 // Number of hits/layer
5714 int Num[43] = {0};
5715 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5716 ii != pt.begin()-1; ii--) {
5717 Num[(*ii)->geo->Lyr()->Id()]++;
5718 }
5719
5720 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5721 ii != pt.begin()-1; ii--) {
5722
5723 hit_asso++;
5724 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
5725 if (debug_ ==4)
5726 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
5727 << " hits in the layer "
5728 << (*ii)->geo->Lyr()->Id() << std::endl;
5729 continue;
5730 }
5731
5732 hit_in++;
5733 MdcRec_wirhit & rechit = **ii;
5734 double dist[2] = {rechit.ddl, rechit.ddr};
5735 double erdist[2] = {rechit.erddl, rechit.erddr};
5736 const MdcGeoWire* geo = rechit.geo;
5737
5738 int lr_decision(0);
5739 if (KalFitTrack::LR_ == 1){
5740 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
5741 // if (rechit.lr==0) lr_decision=-1;
5742 else if (rechit.lr==1) lr_decision=1;
5743 }
5744
5745 int ind(geo->Lyr()->Id());
5746 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
5747 lr_decision, rechit.tdc,
5748 dist, erdist,
5749 _wire+(geo->Id()), rechit.rechitptr));
5750 // inner/outer layer :
5751 rStat[ind]++;
5752 if (inlyr>ind) inlyr = ind;
5753 if (outlyr<ind) outlyr = ind;
5754 }
5755 // Empty layers :
5756 int empty_between(0), empty(0);
5757 for (int i= inlyr; i <= outlyr; i++)
5758 if (!rStat[i]) empty_between++;
5759 empty = empty_between+inlyr+(42-outlyr);
5760 delete [] rStat;
5761 }
5762 if (debug_ == 4)
5763 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
5764
5765
5766 // RMK high momentum track under study, probably not neeeded...
5767 track_lead.order_wirhit(0);
5768 track_lead.type(type);
5769 unsigned int nhit = track_lead.HitsMdc().size();
5770 if (nhit<70) {
5771 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
5772 return;
5773 }
5774
5775 // Initialisation :
5776 double KalFitst(0), KalFitax(0), KalFitschi2(0);
5777 // Move to the outer most hit :
5778 Hep3Vector outer_pivot(track_lead.x(fiTerm));
5779
5780 if(debug_ == 4) {
5781 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
5782 }
5783 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
5784 track_lead.bFieldZ(KalFitTrack::Bznom_);
5785 // attention best_chi2 reinitialize !!!
5786 if (nhit>=3 && !KalFitTrack::LR_)
5787 start_seed(track_lead, lead_, way, TrasanTRK);
5788 HepSymMatrix Eakal(5,0);
5789
5790 //init_matrix(TrasanTRK, Eakal);
5791
5792 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
5793 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5794 choice_ = 6;
5795 }
5796
5797 init_matrix(choice_,TrasanTRK, Eakal);
5798
5799 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
5800
5801 if (debug_ == 4){
5802 std::cout << "from Mdc Pattern Recognition: " << std::endl;
5803 //HepPoint3D IP(0,0,0);
5804 KalmanFit::Helix work(track_lead.pivot(),
5805 track_lead.a(),
5806 track_lead.Ea());
5807 work.pivot(IP);
5808 std::cout << " dr = " << work.a()[0]
5809 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
5810 std::cout << " phi0 = " << work.a()[1]
5811 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
5812 std::cout << " PT = " << 1/work.a()[2]
5813 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
5814 std::cout << " dz = " << work.a()[3]
5815 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
5816 std::cout << " tanl = " << work.a()[4]
5817 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
5818 }
5819 filter_fwd_calib(track_lead, lead_, way, Eakal);
5820 track_lead.update_forMdc();
5821
5822 //HepPoint3D IP(0,0,0);
5823 if (debug_ == 4) {
5824 cout << " Mdc FIRST KALMAN FIT " << std::endl;
5825 KalmanFit::Helix work1(track_lead.pivot(),
5826 track_lead.a(),
5827 track_lead.Ea());
5828 work1.pivot(IP);
5829 cout << " dr = " << work1.a()[0]
5830 << ", Er_dr = " << sqrt(work1.Ea()[0][0]) << std::endl;
5831 cout << " phi0 = " << work1.a()[1]
5832 << ", Er_phi0 = " << sqrt(work1.Ea()[1][1]) << std::endl;
5833 cout << " PT = " << 1/work1.a()[2]
5834 << ", Er_kappa = " << sqrt(work1.Ea()[2][2]) << std::endl;
5835 cout << " dz = " << work1.a()[3]
5836 << ", Er_dz = " << sqrt(work1.Ea()[3][3]) << std::endl;
5837 cout << " tanl = " << work1.a()[4]
5838 << ", Er_tanl = " << sqrt(work1.Ea()[4][4]) << std::endl;
5839 }
5840
5841 // fill TDS
5842 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
5843
5844 // Complete the track (other mass assumption, backward) and
5845 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
5846 // }
5847
5848
5849 StatusCode kalsc;
5850 //check whether the RecMdcKalTrackCol has been already registered
5851 DataObject *aRecKalEvent;
5852 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
5853 if(aRecKalEvent!=NULL) {
5854 //then unregister RecMdcKalCol
5855 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
5856 if(kalsc != StatusCode::SUCCESS) {
5857 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
5858 return;
5859 }
5860 }
5861
5862 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
5863 if( kalsc.isFailure()) {
5864 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
5865 return;
5866 }
5867 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
5868
5869
5870
5871 StatusCode segsc;
5872 //check whether the RecMdcKalHelixSegCol has been already registered
5873 DataObject *aRecKalSegEvent;
5874 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
5875 if(aRecKalSegEvent!=NULL) {
5876 //then unregister RecMdcKalHelixSegCol
5877 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
5878 if(segsc != StatusCode::SUCCESS) {
5879 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
5880 return;
5881 }
5882 }
5883
5884 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
5885 if( segsc.isFailure() ) {
5886 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
5887 return;
5888 }
5889 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
5890
5891
5892 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.);
5893 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
5894 //check the result:RecMdcKalTrackCol
5895
5896 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
5897 if (!kaltrkCol) {
5898 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
5899 return;
5900 }
5901 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
5902 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
5903 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
5904 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
5905 << "Track Id: " << (*iter_trk)->getTrackId()
5906 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
5907 << " Length of the track: "<< (*iter_trk)->getLength(2)
5908 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
5909 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
5910 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
5911 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
5912 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
5913 << "Kappa " << (*iter_trk)->getZHelix()[2]
5914 << "zhelixmu "<<(*iter_trk)->getZHelixMu()
5915 << endreq;
5916
5917 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
5918 if(debug_ == 4) {
5919 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
5920 }
5921
5922 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
5923 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
5924 if(debug_ == 4) {
5925 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
5926 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
5927 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
5928 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
5929 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
5930 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
5931 }
5932 }
5933 for( int i = 0; i<43; i++) {
5934 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
5935 << (*iter_trk)->getPathl(i) <<endreq;
5936 }
5937
5938 if(ntuple_&1) {
5939 m_trackid = (*iter_trk)->getTrackId();
5940 for( int jj =0, iii=0; jj<5; jj++) {
5941 m_length[jj] = (*iter_trk)->getLength(jj);
5942 m_tof[jj] = (*iter_trk)->getTof(jj);
5943 m_nhits[jj] = (*iter_trk)->getNhits(jj);
5944 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
5945 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
5946 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
5947 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
5948 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
5949 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
5950 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
5951 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
5952 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
5953 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
5954 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
5955 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
5956 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
5957 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
5958 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
5959 if(ntuple_&32) {
5960 for(int kk=0; kk<=jj; kk++,iii++) {
5961 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
5962 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
5963 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
5964 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
5965 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
5966 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
5967 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
5968 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
5969 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
5970 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
5971 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
5972 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
5973 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
5974 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
5975 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
5976 }
5977
5978 }
5979 }
5980
5981 // RootConversion changed in BOSS6.0, so use thefollowing:
5982 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
5983 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
5984 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
5985 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
5986 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
5987 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
5988 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
5989 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
5990 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
5991 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
5992
5993 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
5994 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
5995 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
5996 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
5997 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
5998 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
5999 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
6000 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
6001 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
6002 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
6003
6004 m_stat[0][0] = (*iter_trk)->getStat(0,0);
6005 m_stat[1][0] = (*iter_trk)->getStat(0,1);
6006 m_stat[2][0] = (*iter_trk)->getStat(0,2);
6007 m_stat[3][0] = (*iter_trk)->getStat(0,3);
6008 m_stat[4][0] = (*iter_trk)->getStat(0,4);
6009 m_stat[0][1] = (*iter_trk)->getStat(1,0);
6010 m_stat[1][1] = (*iter_trk)->getStat(1,1);
6011 m_stat[2][1] = (*iter_trk)->getStat(1,2);
6012 m_stat[3][1] = (*iter_trk)->getStat(1,3);
6013 m_stat[4][1] = (*iter_trk)->getStat(1,4);
6014
6015 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
6016 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
6017 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
6018 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
6019 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
6020
6021 m_zpt = 1/m_zhelix[2];
6022 m_zpte = 1/m_zhelixe[2];
6023 m_zptmu = 1/m_zhelixmu[2];
6024 m_zptk = 1/m_zhelixk[2];
6025 m_zptp = 1/m_zhelixp[2];
6026
6027 m_fpt = 1/m_fhelix[2];
6028 m_fpte = 1/m_fhelixe[2];
6029 m_fptmu = 1/m_fhelixmu[2];
6030 m_fptk = 1/m_fhelixk[2];
6031 m_fptp = 1/m_fhelixp[2];
6032
6033 m_lpt = 1/m_lhelix[2];
6034 m_lpte = 1/m_lhelixe[2];
6035 m_lptmu = 1/m_lhelixmu[2];
6036 m_lptk = 1/m_lhelixk[2];
6037 m_lptp = 1/m_lhelixp[2];
6038
6039 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
6040 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
6041 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
6042 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
6043 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
6044
6045 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
6046 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
6047 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
6048 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
6049 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
6050 if(ntuple_&32) {
6051 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
6052 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
6053 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
6054 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
6055 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
6056 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
6057 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
6058 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
6059 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
6060 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
6061 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
6062 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
6063 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
6064 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
6065 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
6066 }
6067
6068 StatusCode sc1 = m_nt1->write();
6069 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
6070 }
6071
6072 if(ntuple_&4) {
6073 if(jj == 1) {
6074 phi1 = (*iter_trk)->getFFi0();
6075 r1 = (*iter_trk)->getFDr();
6076 z1 = (*iter_trk)->getFDz();
6077 kap1 = (*iter_trk)->getFCpa();
6078 tanl1 = (*iter_trk)->getFTanl();
6079 x1 = r1*cos(phi1);
6080 y1 = r1*sin(phi1);
6081 p1 = sqrt(1+tanl1*tanl1)/kap1;
6082 the1 = M_PI/2-atan(tanl1);
6083 } else if(jj == 2) {
6084 phi2 = (*iter_trk)->getFFi0();
6085 r2 = (*iter_trk)->getFDr();
6086 z2 = (*iter_trk)->getFDz();
6087 kap2 = (*iter_trk)->getFCpa();
6088 tanl2 = (*iter_trk)->getFTanl();
6089 x2 = r1*cos(phi2);
6090 y2 = r1*sin(phi2);
6091 p2 = sqrt(1+tanl2*tanl2)/kap1;
6092 the2 = M_PI/2-atan(tanl2);
6093 }
6094 }
6095 }
6096 if(ntuple_&4) {
6097 m_delx = x1 - x2;
6098 m_dely = y1 - y2;
6099 m_delz = z1 - z2;
6100 m_delthe = the1 + the2;
6101 m_delphi = phi1- phi2;
6102 m_delp = p1 - p2;
6103 StatusCode sc2 = m_nt2->write();
6104 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
6105 }
6106 delete [] order;
6107 delete [] rCont;
6108 delete [] rGen;
6109 delete [] rOM;
6110
6111 if (debug_ == 4)
6112 cout << "Kalfitting finished " << std::endl;
6113}
6114
6115
6116
6118 MdcRec_trk_add& TrasanTRK_add,
6119 KalFitTrack& track_lead,
6120 RecMdcKalTrack* kaltrk,
6121 RecMdcKalTrackCol* kalcol,RecMdcKalHelixSegCol *segcol,int flagsmooth)
6122{
6123 static int nmass = KalFitTrack::nmass();
6124 int way(1);
6125 MsgStream log(msgSvc(), name());
6126 KalFitTrack track_first(track_lead);
6127 //fromFHitToInnerWall(track_lead, way);
6128 // cout << "m_esti" << m_esti1_r[0] << endl;
6129 //cout<<"fitGemHits for pion"<<endl;
6130 //if(useNCGem_>0) fitGemHits(track_lead, lead_, way);
6131 if(useNCGem_>0) track_first=Cgem_filter_anal(track_lead, lead_, way);
6132 KalFitTrack track_ip(track_lead);
6133 //cout<<"__FUNCTION__: track_lead.nLayerUsed = "<<track_lead.nLayerUsed()<<endl;
6134 //cout<<"__FUNCTION__: track_ip.nLayerUsed = "<<track_ip.nLayerUsed()<<endl;
6135 //innerwall(track_ip, lead_, way,95,99);
6136 // Fill Tds
6137 fillTds_ip(TrasanTRK, track_ip, kaltrk, lead_);
6138 // std::cout<<"track_first nster"<<track_first.nster()<<std::endl;
6139
6140 //fillTds_lead(TrasanTRK, track_first, kaltrk, lead_);
6141 fillTds(TrasanTRK, track_first, kaltrk, lead_);
6142 // Refit for different mass assumptions :
6143 double pp = track_lead.momentum().mag();
6144
6145 if(!(i_front_<0)){
6146 //cout << "!!!!i_front" << i_front_<< endl;
6147 for(int l_mass = 0, flg = 1; l_mass < nmass;
6148 l_mass++, flg <<= 1) {
6149
6150 if (!(mhyp_ & flg)) continue;
6151 if (l_mass == lead_) continue;
6152
6153 // Check the mom. to decide of the refit with this mass assumption
6154 if ((lead_ != 0 && l_mass==0 && pp > pe_cut_) ||
6155 (lead_ != 1 && l_mass==1 && pp > pmu_cut_) ||
6156 (lead_ != 2 && l_mass==2 && pp > ppi_cut_) ||
6157 (lead_ != 3 && l_mass==3 && pp > pk_cut_) ||
6158 (lead_ != 4 && l_mass==4 && pp > pp_cut_))
6159 continue;
6160 if(debug_ == 4) cout<<"complete_track..REFIT ASSUMPION " << l_mass << endl;
6161 // Initialisation :
6162 double chiSq = 0;
6163 int nhits = 0;
6164
6165 // Initialisation : (x, a, ea)
6166 HepPoint3D x_trasan(TrasanTRK.pivot[0],
6167 TrasanTRK.pivot[1],
6168 TrasanTRK.pivot[2]);
6169 HepVector a_trasan(5);
6170 for(int i = 0; i < 5; i++)
6171 a_trasan[i] = TrasanTRK.helix[i];
6172
6173 HepSymMatrix ea_trasan(5);
6174 for(int i = 0, k = 0; i < 5; i++) {
6175 for(int j = 0; j <= i; j++) {
6176 ea_trasan[i][j] = matrixg_*TrasanTRK.error[k++];
6177 ea_trasan[j][i] = ea_trasan[i][j];
6178 }
6179 }
6180
6181 KalFitTrack track(x_trasan,a_trasan, ea_trasan, l_mass, chiSq, nhits);
6182 track.HitsMdc(track_lead.HitsMdc());
6183 track.trasan_id(TrasanTRK.id);
6184 double fiTerm = TrasanTRK.fiTerm;
6185 track.pivot(track.x(fiTerm));
6186 HepSymMatrix Eakal(5,0);
6187
6188 double costheta = track.a()[4] / sqrt(1.0 + track.a()[4]*track.a()[4]);
6189 if( (1.0/fabs(track.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
6190 choice_ = 6;
6191 }
6192
6193 init_matrix(choice_,TrasanTRK, Eakal);
6194 if(ntuple_&256) {
6195 m_hit_no=0;
6196 m_nCluster=0;
6197 }
6198 filter_fwd_anal(track, l_mass, way, Eakal);
6199 KalFitTrack track_z(track);
6200 track_first=track;
6201 //fromFHitToInnerWall(track_z, way);
6202 //cout<<"fitGemHits for i="<<l_mass<<endl;
6203 //if(useNCGem_>0) fitGemHits(track_z, l_mass, way);
6204 if(useNCGem_>0) track_first=Cgem_filter_anal(track_z, l_mass, way);
6205 ///fill tds with results got at (0,0,0)
6206 //innerwall(track_z, l_mass, way,95,99);
6207 fillTds_ip(TrasanTRK, track_z, kaltrk, l_mass);
6208 // Fill tds with the result at the inner most hit
6209 fillTds(TrasanTRK, track_first, kaltrk, l_mass);
6210 if(ifProdNt12){
6211 if(l_mass==1)residual(track_z);
6212 }
6213 }
6214 } // end of //end of if (!(i_front<0))
6215
6216
6217 if(ntuple_&256) StatusCode sc7 = m_nt7 ->write();
6218 // Refit with an enhancement of the error matrix at Mdc level :
6219 if (enhance_) {
6220
6221 HepPoint3D x_first(0, 0, 0);
6222 HepVector a_first(kaltrk->getFHelix());
6223 HepSymMatrix ea_first(kaltrk->getFError());
6224 HepVector fac(5);
6225 fac[0]=fac_h1_; fac[1]=fac_h2_; fac[2]=fac_h3_; fac[3]=fac_h4_; fac[4]=fac_h5_;
6226 for(int i = 0; i < 5; i++)
6227 for(int j = 0; j <= i; j++)
6228 ea_first[i][j] = fac[i]*fac[j]*ea_first[i][j];
6229 KalFitTrack track(x_first, a_first, ea_first, 2, 0, 0);
6230 }
6231 //if(myEventNo==1080) cout<<"mu_status_filled2 = "<<kaltrk->getStat(0,1)<<endl;
6232
6233 // Backward filter :
6234 KalFitTrack track_back(track_lead);
6235 if (debug_ == 4) {
6236 cout << " Backward fitting flag:" << back_<< endl;
6237 cout << "track_back pivot " << track_back.pivot()
6238 << " track_lead kappa " << track_lead.a()[2]
6239 <<endl;
6240 }
6241
6242 if (back_ && track_lead.a()[2] != 0 &&
6243 1/fabs(track_lead.a()[2]) > pT_) {
6244 track_back.HitsMdc(track_lead.HitsMdc());
6245
6247 double p_kaon(0), p_proton(0);
6248 if (!(kaltrk->getStat(0,3))) {
6249 p_kaon = 1 / fabs(kaltrk->getZHelixK()[2]) *
6250 sqrt(1 + kaltrk->getZHelixK()[4]*kaltrk->getZHelixK()[4]);
6251 track_back.p_kaon(p_kaon);
6252 } else {
6253 p_kaon = 1 / fabs(track_back.a()[2]) *
6254 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6255 track_back.p_kaon(p_kaon);
6256 }
6257 if (!(kaltrk->getStat(0,4))) {
6258 p_proton = 1 / fabs(kaltrk->getZHelixP()[2]) *
6259 sqrt(1 + kaltrk->getZHelixP()[4]*kaltrk->getZHelixP()[4]);
6260 track_back.p_proton(p_proton);
6261 } else {
6262 p_proton = 1 / fabs(track_back.a()[2]) *
6263 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6264 track_back.p_proton(p_proton);
6265 }
6266 }
6267
6268 if (!(i_back_<0)) {
6269 //cout<<" *** in smoothing process ***"<<endl;
6270 for(int l_mass = 0; l_mass < nmass; l_mass++) {
6271 //cout<<" --- in hypothesis "<<l_mass<<" :"<<endl;
6272 KalFitTrack track_seed(track_back);
6273 track_seed.chgmass(l_mass);
6274 //cout<<"---------------"<<endl;//wangll
6275 //cout<<"smooth track "<<l_mass<<endl;//wangll
6276 //cout<<" pivot :"<<track_seed.pivot()<<endl;//wangll
6277 //cout<<" helix :"<<track_seed.a()<<endl;//wangll
6278
6279 if(useNCGem_>0) Cgem_filter_anal(track_seed, l_mass, -way);
6280 smoother_anal(track_seed, -way);
6281 // if( usage_ == 1) smoother_calib(track_seed, -way);
6282 //cout<<"fillTds_back 1"<<endl;
6283 // fill TDS for backward filter :
6284 fillTds_back(track_seed, kaltrk, TrasanTRK, l_mass, segcol, 1);
6285 //cout<<"nHits: "<<kaltrk->getVecHelixSegs().size()<<endl;
6286 }
6287 } else {
6288 if(useNCGem_>0) Cgem_filter_anal(track_back, lead_, -way);
6289 smoother_anal(track_back, -way);
6290 //smoother_calib(track_back, -way);
6291 // smoother(track_back, -way);
6292 // fill TDS for backward filter :
6293 //cout<<"fillTds_back 2"<<endl;
6294 fillTds_back(track_back, kaltrk, TrasanTRK, lead_, segcol, 1);
6295 }
6296 }
6297
6298 // Take care of the pointers (use lead. hyp results by default)
6299 //if(myEventNo==1080) cout<<"mu_status_filled3 = "<<kaltrk->getStat(0,1)<<endl;
6300 /*
6301 for(int pid = 0; pid < nmass;
6302 pid++) {
6303 if (pid == lead_) continue;
6304 if (kaltrk->getStat(1,pid))
6305 sameas(kaltrk, pid, lead_);
6306 }*/
6307
6308
6309 //check: before register into TDS
6310
6311 log << MSG::DEBUG << "registered MDC Kalmantrack:"
6312 << "Track Id: " << kaltrk->getTrackId()
6313 << " Mass of the fit: "<< kaltrk->getMass(2)<< endreq
6314 << "Length of the track: "<< kaltrk->getLength(2)
6315 << " Tof of the track: "<< kaltrk->getTof(2) << endreq
6316 << "Chisq of the fit: "<< kaltrk->getChisq(0,2)
6317 <<" "<< kaltrk->getChisq(1,2) << endreq
6318 << "Ndf of the fit: "<< kaltrk->getNdf(0,2)
6319 <<" "<< kaltrk->getNdf(1,2) << endreq
6320 << "Helix " << kaltrk->getZHelix()[2]
6321 <<endreq;
6322
6323 //if(myEventNo==1080) cout<<"mu_status_filled4 = "<<kaltrk->getStat(0,1)<<endl;
6324 kalcol->push_back(kaltrk);
6325 track_lead.HitsMdc().clear();
6326}
6327
6328
6330 MdcRec_trk_add& TrasanTRK_add,
6331 KalFitTrack& track_lead,
6332 RecMdcKalTrack* kaltrk,
6333 RecMdcKalTrackCol* kalcol,RecMdcKalHelixSegCol *segcol)
6334{
6335 static int nmass = KalFitTrack::nmass();
6336 int way(1);
6337 MsgStream log(msgSvc(), name());
6338 KalFitTrack track_first(track_lead);
6339 KalFitTrack track_ip(track_lead);
6340
6341 if (debug_ == 4){
6342 cout << "track_first pivot "<<track_first.pivot()<< " helix "<<track_first.a()<<endl;
6343 }
6344 if(usage_==1) innerwall(track_ip, lead_, way);
6345 // Fill Tds
6346 fillTds_ip(TrasanTRK, track_ip, kaltrk, lead_);
6347
6348 if (debug_ == 4) {
6349 cout << "after inner wall, track_ip pivot "<<track_first.pivot()<< " helix "<<track_first.a()<<endl;
6350 }
6351
6352 fillTds_lead(TrasanTRK, track_first, kaltrk, lead_);
6353
6354 // Refit for different mass assumptions :
6355 double pp = track_lead.momentum().mag();
6356
6357 //w if (!KalFitDSSD::cosmic_)
6358 if(!(i_front_<0)){
6359
6360 for(int l_mass = 0, flg = 1; l_mass < nmass;
6361 l_mass++, flg <<= 1) {
6362
6363 if (!(mhyp_ & flg)) continue;
6364 if (l_mass == lead_) continue;
6365
6366 // Check the mom. to decide of the refit with this mass assumption
6367 if ((lead_ != 0 && l_mass==0 && pp > pe_cut_) ||
6368 (lead_ != 1 && l_mass==1 && pp > pmu_cut_) ||
6369 (lead_ != 2 && l_mass==2 && pp > ppi_cut_) ||
6370 (lead_ != 3 && l_mass==3 && pp > pk_cut_) ||
6371 (lead_ != 4 && l_mass==4 && pp > pp_cut_))
6372 continue;
6373
6374 if(debug_ == 4) {
6375 cout<<"complete_track..REFIT ASSUMPION " << l_mass << endl;
6376 }
6377
6378 // Initialisation :
6379 double chiSq = 0;
6380 int nhits = 0;
6381
6382 // Initialisation : (x, a, ea)
6383 HepPoint3D x_trasan(TrasanTRK.pivot[0],
6384 TrasanTRK.pivot[1],
6385 TrasanTRK.pivot[2]);
6386
6387 HepVector a_trasan(5);
6388 for(int i = 0; i < 5; i++){
6389 a_trasan[i] = TrasanTRK.helix[i];
6390 }
6391
6392 HepSymMatrix ea_trasan(5);
6393 for(int i = 0, k = 0; i < 5; i++) {
6394 for(int j = 0; j <= i; j++) {
6395 ea_trasan[i][j] = matrixg_*TrasanTRK.error[k++];
6396 ea_trasan[j][i] = ea_trasan[i][j];
6397 }
6398 }
6399
6400 KalFitTrack track(x_trasan,a_trasan, ea_trasan, l_mass, chiSq, nhits);
6401 track.HitsMdc(track_lead.HitsMdc());
6402
6403 double fiTerm = TrasanTRK.fiTerm;
6404 track.pivot(track.x(fiTerm));
6405
6406 HepSymMatrix Eakal(5,0);
6407
6408 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
6409 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
6410 choice_ = 6;
6411 }
6412
6413 init_matrix(choice_, TrasanTRK, Eakal);
6414
6415 filter_fwd_calib(track, l_mass, way, Eakal);
6416
6417 KalFitTrack track_z(track);
6418 ///fill tds with results got at (0,0,0)
6419 innerwall(track_z, l_mass, way);
6420 fillTds_ip(TrasanTRK, track_z, kaltrk, l_mass);
6421 // Fill tds
6422 fillTds(TrasanTRK, track, kaltrk, l_mass);
6423 }
6424 } //end of if (!(i_front<0))
6425
6426 // Refit with an enhancement of the error matrix at Mdc level :
6427
6428 if (enhance_) {
6429 HepPoint3D x_first(0, 0, 0);
6430 HepVector a_first(kaltrk->getFHelix());
6431 HepSymMatrix ea_first(kaltrk->getFError());
6432 HepVector fac(5);
6433 fac[0]=fac_h1_; fac[1]=fac_h2_; fac[2]=fac_h3_; fac[3]=fac_h4_; fac[4]=fac_h5_;
6434
6435 for(int i = 0; i < 5; i++)
6436 for(int j = 0; j <= i; j++)
6437 ea_first[i][j] = fac[i]*fac[j]*ea_first[i][j];
6438 KalFitTrack track(x_first, a_first, ea_first, 2, 0, 0);
6439 }
6440
6441 // Backward filter
6442 // Attention, the initial error matrix of track_back is the error matrix
6443 // that after filter_fwd_calib(...) course of track_lead. So one thing need
6444 // more consideration that how to chose the inital error matrix of this smoother,
6445 // to put it by hand or use the error matrix after filter_fwd_calib. I think
6446 // it should be to refer R.G.Brown's book.
6447
6448 KalFitTrack track_back(track_lead);
6449
6450 //track_back(track);
6451
6452
6453 if (debug_ == 4) {
6454 cout << " Backward fitting flag:" << back_<< endl;
6455 cout << "track_back pivot " << track_back.pivot()
6456 << " track_lead kappa " << track_lead.a()[2]
6457 <<endl;
6458 }
6459
6460 if (back_ && track_lead.a()[2] != 0 &&
6461 1/fabs(track_lead.a()[2]) > pT_) {
6462 track_back.HitsMdc(track_lead.HitsMdc());
6463
6465
6466 double p_kaon(0), p_proton(0);
6467
6468 if (!(kaltrk->getStat(0,3))) {
6469 p_kaon = 1 / fabs(kaltrk->getZHelixK()[2]) *
6470 sqrt(1 + kaltrk->getZHelixK()[4]*kaltrk->getZHelixK()[4]);
6471 track_back.p_kaon(p_kaon);
6472 } else {
6473 p_kaon = 1 / fabs(track_back.a()[2]) *
6474 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6475 track_back.p_kaon(p_kaon);
6476 }
6477 if (!(kaltrk->getStat(0,4))) {
6478 p_proton = 1 / fabs(kaltrk->getZHelixP()[2]) *
6479 sqrt(1 + kaltrk->getZHelixP()[4]*kaltrk->getZHelixP()[4]);
6480 track_back.p_proton(p_proton);
6481 } else {
6482 p_proton = 1 / fabs(track_back.a()[2]) *
6483 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6484 track_back.p_proton(p_proton);
6485 }
6486
6487 }
6488
6489
6490 if (!(i_back_<0)) {
6491 for(int l_mass = 0; l_mass < nmass; l_mass++) {
6492 KalFitTrack track_seed(track_back);
6493 track_seed.chgmass(l_mass);
6494 smoother_calib(track_seed, -way);
6495 // fill TDS for backward filter :
6496 fillTds_back(track_seed, kaltrk, TrasanTRK, l_mass,segcol);
6497 }
6498 } else {
6499
6500 smoother_calib(track_back, -way);
6501 // fill TDS for backward filter , for leading particle hypothesis :
6502 fillTds_back(track_back, kaltrk, TrasanTRK, lead_,segcol);
6503 // fillTds_helixsegs(track_back,TrasanTRK);
6504 }
6505 }
6506
6507 /*
6508 // Take care of the pointers (use lead. hyp results by default)
6509 for(int pid = 0; pid < nmass;
6510 pid++) {
6511 if (pid == lead_) continue;
6512 if (kaltrk->getStat(1,pid))
6513 sameas(kaltrk, pid, lead_);
6514 }
6515 */
6516
6517 //check: before register into TDS
6518
6519 log << MSG::DEBUG << "registered MDC Kalmantrack:"
6520 << "Track Id: " << kaltrk->getTrackId()
6521 << " Mass of the fit: "<< kaltrk->getMass(2)<< endreq
6522 << "Length of the track: "<< kaltrk->getLength(2)
6523 << " Tof of the track: "<< kaltrk->getTof(2) << endreq
6524 << "Chisq of the fit: "<< kaltrk->getChisq(0,2)
6525 <<" "<< kaltrk->getChisq(1,2) << endreq
6526 << "Ndf of the fit: "<< kaltrk->getNdf(0,2)
6527 <<" "<< kaltrk->getNdf(1,2) << endreq
6528 << "Helix " << kaltrk->getZHelix()[2]
6529 <<endreq;
6530
6531 kalcol->push_back(kaltrk);
6532 track_lead.HitsMdc().clear();
6533 track_back.HelixSegs().clear();
6534 // ??ATTENTION!! should track_back.HelixSegs() be cleared ??
6535}
6536
6537
6538void KalFitAlg::init_matrix(MdcRec_trk& trk, HepSymMatrix& Eakal )
6539{
6540 for ( int i=0; i<5; i++) {
6541 for( int j = 1; j<i+2;j++) {
6542 Eakal(i+1,j) = matrixg_*(trk.error[i*(i+1)/2+j-1]);
6543 Eakal(j,i+1) = Eakal(i+1,j);
6544 }
6545 }
6546
6547 if (debug_ == 4) cout<<"initialised Ea.. "<<Eakal<<endl;
6548}
6549
6550
6551
6552void KalFitAlg::init_matrix(int k, MdcRec_trk& trk, HepSymMatrix& Eakal )
6553{
6554 if(0==k){
6555 for ( int i=0; i<5; i++) {
6556 for( int j = 1; j<i+2;j++) {
6557 Eakal(i+1,j) = matrixg_*(trk.error[i*(i+1)/2+j-1]);
6558 Eakal(j,i+1) = Eakal(i+1,j);
6559 }
6560 Eakal(1,1) = Eakal(1,1)* gain1_;
6561 Eakal(2,2) = Eakal(2,2)* gain2_;
6562 Eakal(3,3) = Eakal(3,3)* gain3_;
6563 Eakal(4,4) = Eakal(4,4)* gain4_;
6564 Eakal(5,5) = Eakal(5,5)* gain5_;
6565 }
6566 }
6567 // HepSymMatrix ea_temp(5);
6568 // for(int i = 0, k = 0; i < 5; i++) {
6569 // for(int j = 0; j <= i; j++) {
6570 // ea_temp[i][j] = matrixg_*trk.error[k++];
6571 // ea_temp[j][i] = ea_temp[i][j];
6572 // }
6573 // }
6574
6575 if(1==k){
6576 Eakal(1,1) = .2;
6577 Eakal(2,2) = .001;
6578 Eakal(3,3) = 1.0;
6579 Eakal(4,4) = 10.0;
6580 Eakal(5,5) = 0.002;
6581 }
6582
6583 if(2==k){
6584 Eakal(1,1) = .2;
6585 Eakal(2,2) = 0.1;
6586 Eakal(3,3) = 1.0;
6587 Eakal(4,4) = 25.0;
6588 Eakal(5,5) = 0.10;
6589 }
6590
6591
6592 if(3==k){
6593 Eakal(1,1) = .2;
6594 Eakal(2,2) = .001;
6595 Eakal(3,3) = 1.0;
6596 Eakal(4,4) = 25.0;
6597 Eakal(5,5) = 0.10;
6598 }
6599
6600 if(4==k){
6601 Eakal(1,1) = .2;
6602 Eakal(2,2) = .01;
6603 Eakal(3,3) = 0.01;
6604 Eakal(4,4) = 1.;
6605 Eakal(5,5) = .01;
6606 }
6607
6608 if(5==k) {
6609 Eakal(1,1) = 2.;
6610 Eakal(2,2) = 0.1;
6611 Eakal(3,3) = 1.;
6612 Eakal(4,4) = 20.;
6613 Eakal(5,5) = 0.1;
6614 }
6615
6616 if(6==k) {
6617 Eakal(1,1) = 0.01;
6618 Eakal(2,2) = 0.01;
6619 Eakal(3,3) = 0.01;
6620 Eakal(4,4) = 100.;
6621 Eakal(5,5) = 0.5;
6622 }
6623
6624 if(k!=0){
6625 Eakal(3,3) = 0.2;
6626 Eakal(1,1) = 1;
6627 Eakal(4,4) = 1;
6628 }
6629
6630 if (debug_ == 4) cout<<"initialised Eakal.. "<<Eakal<<endl;
6631}
6632
6633
6634
6635
6636void KalFitAlg::start_seed(KalFitTrack& track, int lead_, int way, MdcRec_trk& TrasanTRK)
6637{
6638 if (debug_ == 4)
6639 cout << "start_seed begin... " << std::endl;
6640 // keep initial helix parameters
6641 Hep3Vector x_init(track.pivot());
6642 HepSymMatrix Ea_init(5,0);
6643 Ea_init = track.Ea();
6644 HepVector a_init(5);
6645 a_init = track.a();
6646
6647 // LR assumption :
6648 unsigned int nhit_included(10);
6649 int LR[8][3] = {
6650 {1,1,1},
6651 {1,1,-1},
6652 {1,-1,1},
6653 {1,-1,-1},
6654 {-1,1,1},
6655 {-1,1,-1},
6656 {-1,-1,1},
6657 {-1,-1,-1}
6658 };
6659
6660 unsigned int nhit = track.HitsMdc().size();
6661 double chi2_min(DBL_MAX);
6662 int i_min(-1);
6663 for (int ktrial = 0; ktrial < 8; ktrial++) {
6664
6665 // Come back to trasan seed :
6666 track.pivot(x_init);
6667 track.a(a_init);
6668 track.Ea(Ea_init);
6669
6670 track.chiSq(0);
6671 track.chiSq_back(0);
6672 track.nchits(0);
6673 track.nster(0);
6674 track.ndf_back(0);
6675
6676 HepSymMatrix Eakal(5,0);
6677
6678 init_matrix(choice_,TrasanTRK, Eakal);
6679 // initialize the Mdc hits :
6680 for( unsigned i=0 ; i < nhit; i++ ){
6681 KalFitHitMdc& HitMdc = track.HitMdc(i);
6682 int lr_decision(0);
6683 if (i<3) lr_decision = LR[ktrial][i];
6684 HitMdc.LR(lr_decision);
6685 if (i<nhit_included)
6686 HitMdc.chi2(0);
6687 else
6688 HitMdc.chi2(-1);
6689 }
6690 // Mdc fit the ... first hits :
6691
6692 if(usage_==0) filter_fwd_anal(track, lead_, way, Eakal);
6693 way=999;
6694 if(usage_>0) filter_fwd_calib(track, lead_, way, Eakal);
6695
6696 // Check the chi2
6697 if (debug_ == 4)
6698 cout << "---- Result for " << ktrial << " case : chi2 = " << track.chiSq()
6699 << ", nhits included = " << track.nchits() << " for nhits available = "
6700 << nhit << std::endl;
6701
6702 if (track.chiSq() < chi2_min &&
6703 (track.nchits() == nhit_included || track.nchits() == nhit)){
6704 chi2_min = track.chiSq();
6705 i_min = ktrial;
6706 }
6707 }
6708
6709 // Initialize to the best solution :
6710 if (debug_ == 4)
6711 cout << "*** i_min = " << i_min << " with a chi2 = " << chi2_min << std::endl;
6712
6713 for( unsigned i=0 ; i < nhit; i++ ){
6714 KalFitHitMdc& HitMdc = track.HitMdc(i);
6715 int lr_decision(0);
6716 if (i_min >= 0 && i < 3)
6717 lr_decision = LR[i_min][i];
6718 HitMdc.LR(lr_decision);
6719 HitMdc.chi2(0);
6720 HitMdc.chi2_back(0);
6721 }
6722 track.pivot(x_init);
6723 track.a(a_init);
6724 track.Ea(Ea_init);
6725 track.chiSq(0);
6726 track.chiSq_back(0);
6727 track.nchits(0);
6728 track.nster(0);
6729 track.ndf_back(0);
6730
6731 // For debugging purpose :
6732 if (debug_ == 4) {
6733 for( unsigned i=0 ; i < 3; i++ ){
6734 KalFitHitMdc& HitMdc = track.HitMdc(i);
6735 cout << " LR(" << i << ") = " << HitMdc.LR()
6736 << ", stereo = " << HitMdc.wire().stereo()
6737 << ", layer = " << HitMdc.wire().layer().layerId() << std::endl;
6738 }
6739 }
6740}
6741
6742// this function is added to clear tables after processing each event
6743// to avoid memory leak,because of the usage of MdcTables etc.
6744// Apr. 2005
6746
6747 if(debug_ == 4) cout<<"Begining to clear Tables ...."<<endl;
6748 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
6749 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
6750 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
6751 vector<MdcRec_trk>::iterator tit=mdcMgr->begin();
6752 for( ; tit != mdcMgr->end(); tit++) {
6753 vector<MdcRec_wirhit*>::iterator vit= tit->hitcol.begin() ;
6754 for(; vit != tit->hitcol.end(); vit++) {
6755 delete (*vit);
6756 }
6757 }
6758
6759 mdcMgr->clear();
6760 mdc_addMgr->clear();
6761 whMgr->clear();
6762
6763 // delete mdcMgr;
6764 // delete mdc_addMgr;
6765 // delete whMgr;
6766 // mdcMgr = 0;
6767 // mdc_addMgr = 0;
6768 // whMgr = 0;
6769
6770}
6771
6772bool KalFitAlg::order_rechits(const SmartRef<RecMdcHit>& m1, const SmartRef<RecMdcHit>& m2) {
6773 return MdcID::layer(m1->getMdcId()) > MdcID::layer(m2->getMdcId());
6774}
6775
6776/*void KalFitAlg::makeGemHitsCol()
6777 {
6778 bool giveCout=true;
6779
6780 for(int i=0; i<4; i++) myGemHitCol[i].clear();
6781
6782 SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
6783 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
6784
6785 int nHits, nDigi;
6786 unsigned int stripIndx, isVStrip;
6787 int layer;
6788 double x, y, z, r, phi;
6789
6790 nHits = mdcMcHitCol->size();
6791 nDigi = mdcDigiCol->size();
6792
6793//cout<<__FUNCTION__<<":: nHits = "<<nHits<<endl;
6794
6795Rndm::Numbers gaussRPhi(randSvc(), Rndm::Gauss(0.,myRphiResGem));
6796Rndm::Numbers gaussZ(randSvc(), Rndm::Gauss(0.,myZResGem));
6797
6798MdcMcHitCol::const_iterator it = mdcMcHitCol->begin();
6799
6800if(giveCout) cout<<endl<<endl<<" ------------- Mdc MC hits: ------------"<<endl<<endl;
6801
6802for(;it!=mdcMcHitCol->end(); it++)
6803{
6804Identifier id= (*it)->identify();
6805layer = MdcID::layer(id);
6806//if(layer>(useNCGem_-1)) continue;
6807if(layer>4) continue;
6808stripIndx = (*it)->getDriftDistance();
6809isVStrip = (*it)->getPositionFlag();
6810x = ((*it)->getPositionX())*0.1; // mm->cm
6811y = ((*it)->getPositionY())*0.1; // mm->cm
6812z = ((*it)->getPositionZ())*0.1; // mm->cm
6813r=sqrt(x*x+y*y);
6814phi=atan2(y,x);
6815if(giveCout) {
6816cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isVStrip<<endl;
6817cout<<" true x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
6818}
6819if(layer<4&&myGemHitCol[layer].empty())
6820{
6821if(giveCout) cout<<"myGemHitCol["<<layer<<"] is empty"<<endl;
6822double phiResam = phi+gaussRPhi()/r;
6823while(phi>M_PI) phi-=2.0*M_PI;
6824while(phi<-M_PI) phi+=2.0*M_PI;
6825double zResam = z+gaussZ();
6826KalFitGemHit aKalFitGemHit(phiResam,zResam,r,myRphiResGem,myZResGem);
6827if(giveCout) {
6828cout<<" resam x, y, z, phi, r = "<<x<<", "<<y<<", "<<zResam<<", "<<phiResam<<", "<<r<<endl;
6829cout<<" Dphi, Dz = "<<phiResam-phi<<", "<<zResam-z<<endl;
6830cout<<" nSigPhi, nSigZ = "<<(phiResam-phi)*r/myRphiResGem<<", "<<(zResam-z)/myZResGem<<endl;
6831}
6832if(phi>M_PI||phi<-M_PI) cout<<__FUNCTION__<<": phi = "<<phi<<endl;
6833myGemHitCol[layer].push_back(aKalFitGemHit);
6834}
6835}
6836
6837//cout<<endl<<endl<<" ------------- Mdc digi: ------------"<<endl<<endl;
6838
6839MdcDigiCol::const_iterator it_digi = mdcDigiCol->begin();
6840for(;it_digi!=mdcDigiCol->end(); it_digi++)
6841{
6842Identifier id = (*it_digi)->identify();
6843layer = MdcID::layer(id);
6844if(layer>4) continue;
6845double stripId = RawDataUtil::MdcTime((*it_digi)->getTimeChannel());
6846double isV = RawDataUtil::MdcCharge((*it_digi)->getChargeChannel());
6847//cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripId<<", "<<isV<<endl;
6848stripIndx=stripId+0.5;
6849//cout<<" stripIndx = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isV<<endl;
6850}
6851
6852///
6853// --- print out GEM hits
6854if(giveCout) cout<<endl<<"------- GEM hits: --------"<<endl;
6855//for(int i=0; i<useNCGem_; i++)
6856for(int i=0; i<4; i++)
6857{
6858 if(giveCout) cout<<"### layer "<<i<<endl;
6859 //int nhits = myGemHitCol[i].size();
6860 KalFitGemHitCol::const_iterator it_GemHit = (myGemHitCol[i]).begin();
6861 for(int j=0; it_GemHit!=(myGemHitCol[i]).end(); it_GemHit++, j++)
6862 {
6863 if(giveCout) cout<<" hit "<<(j+1)<<": phi, z, r = "<<it_GemHit->getPhi()<<", "<<it_GemHit->getZ()<<", "<<it_GemHit->getR()<<endl;
6864 if(ntuple_&1) m_rGem[i] = it_GemHit->getR();
6865 }
6866}
6867///
6868}
6869*/
6870
6871
6873{
6874 double rMaxInnerWall=6.42005+0.00495;
6875 if(useNCGem_>1) { // GEM mode
6876 //rMaxInnerWall=m_CGEM.end()->radius();
6877 //rMaxInnerWall=16.7;
6878 rMaxInnerWall=m_innerWall[0].radius();
6879 }
6880 else { // MDC mode
6881 rMaxInnerWall=_BesKalmanFitWalls[0].radius();
6882 }
6883 double dPhiToInnerWall = track.intersect_cylinder(rMaxInnerWall);
6884 HepPoint3D posAtInnerWall = track.x(dPhiToInnerWall);
6885 double pathToInnerWall;
6886 track.pivot_numf(posAtInnerWall, pathToInnerWall);
6887 //cout<<"__FUNCTION__: rMaxInnerWall = "<<rMaxInnerWall<<endl;
6888 //cout<<"posAtInnerWall, pathToInnerWall = "<<posAtInnerWall<<", "<<pathToInnerWall<<endl;
6889 if(pathToInnerWall>0)
6890 {
6891 if(muls_) track.ms(pathToInnerWall, _BesKalmanFitMaterials[0], way);
6892 if(loss_) track.eloss(pathToInnerWall, _BesKalmanFitMaterials[0], way);
6893 }
6894 if(useNCGem_>0) m_innerWall[0].updateTrack(track, way);
6895
6896}
6897
6898
6899/*void KalFitAlg::fitGemHits(KalFitTrack& track, int hypo, int way)
6900 {
6901 bool printOut=false;
6902 if(printOut) {
6903 cout<<endl;
6904 cout<<"--------------------------------------"<<endl;
6905 cout<<"start GEM Kalman fit: hypo = "<<hypo<<endl;
6906 cout<<"--------------------------------------"<<endl;
6907 }
6908//int iLayer=useNCGem_-1;
6909int nLayer=4;
6910switch(useNCGem_)
6911{
6912case 0: nLayer=0; break;
6913case 1: nLayer=1; break;
6914case 2: nLayer=2; break;
6915case 3:
6916case 13:
6917nLayer=3; break;
6918case 4:
6919case 14:
6920nLayer=4; break;
6921}
6922int iLayer=nLayer-1;
6923//for(int iLayer=3; iLayer>=0; iLayer--)
6924int nGemLayers=m_CGEM.size();
6925double rGem, rmax, rmin;
6926for(int iGem=nGemLayers-1; iGem>=0; iGem--)
6927//for(int i=nGemLayers-1; i>=0; i--)
6928{
6929//if(way) iGem=i;
6930if(printOut) cout<<"rGem = "<<m_CGEM[iGem].radius()<<endl;
6931if(iLayer>=0) rGem=(myGemHitCol[iLayer].begin())->getR();
6932rmax = m_CGEM[iGem].radius();
6933rmin = m_CGEM[iGem].rmin();
6934if(iLayer>=0 && rGem<rmax && rGem>rmin)
6935{
6936if(myUseGemPos3D) {
6937if(printOut) {
6938cout<<"in GEM 3D coorinate fit "<<endl;
6939cout<<"iLayer = "<<iLayer<<endl;
6940cout<<"rGemLayerMax = "<<m_CGEM[iGem].radius()<<endl;
6941}
6942rmax=m_CGEM[iGem].radius();
6943double dPhiToGem = track.intersect_cylinder(rmax);
6944HepPoint3D posEstiAtGem = track.x(dPhiToGem);
6945track.pivot_numf(posEstiAtGem);
6946int nHits=myGemHitCol[iLayer].size();
6947if(nHits!=1) continue;
6948//rGem=(myGemHitCol[iLayer].begin())->getR();
6949double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
6950double zGem=(myGemHitCol[iLayer].begin())->getZ();
6951HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos3D();
6952if(printOut) cout<<"v_measu,rGem = "<<v_measu<<", "<<rGem<<endl;
6953dPhiToGem = track.intersect_cylinder(rGem);
6954posEstiAtGem = track.x(dPhiToGem);
6955double x0=posEstiAtGem.x();
6956double y0=posEstiAtGem.y();
6957double z0=posEstiAtGem.z();
6958double pathInGem;
6959track.pivot_numf(posEstiAtGem, pathInGem);
6960if(pathInGem>0)
6961{
6962if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
6963if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
6964}
6965double rGemEsti=posEstiAtGem.perp();
6966double phiGemEsti=posEstiAtGem.phi();
6967double zGemEsti=posEstiAtGem.z();
6968HepVector v_estim(3,0);
6969v_estim(1)=x0;
6970v_estim(2)=y0;
6971v_estim(3)=z0;
6972if(printOut) {
6973 cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
6974 cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
6975}
6976const HepSymMatrix& Ea = track.Ea();
6977HepVector v_a = track.a();
6978double phi0=v_a(2);
6979if(printOut) {
6980 cout<<"v_a = "<<v_a<<endl;
6981 cout<<"phi0 = "<<phi0<<endl;
6982}
6983// --- derivative matrix
6984HepMatrix H(3, 5, 0);
6985double c=1.0;
6986if(x0*y0>0.0) c=-1.0;
6987H(1,1)=cos(phi0);
6988H(2,1)=sin(phi0);
6989H(3,4)=1.0;
6990if(printOut) cout<<"H="<<H<<endl;
6991HepMatrix H_T=H.T();
6992if(printOut) cout<<"H_T="<<H_T<<endl;
6993// --- error matrix of Gem hit
6994HepSymMatrix V=(myGemHitCol[iLayer].begin())->getErrMat3D();
6995if(printOut) cout<<"V="<<V<<endl;
6996HepMatrix HEa=H*Ea;
6997HepMatrix HEaH_T=HEa*H_T;
6998if(printOut) cout<<"HEaH_T="<<HEaH_T<<endl;
6999int ierr=-1;
7000HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
7001if(printOut) cout<<"Vinv="<<Vinv<<endl;
7002if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
7003// --- gain matrix
7004HepMatrix K=Ea*H_T*Vinv;
7005if(printOut) cout<<"K="<<K<<endl;
7006// --- new error matrix
7007HepSymMatrix EaNew(5,0);
7008EaNew.assign(Ea-K*H*Ea);
7009// --- diff
7010HepVector v_diff=v_measu-v_estim;
7011//double delPhi=v_diff(1);
7012//while(delPhi> M_PI) delPhi-=2.0*M_PI;
7013//while(delPhi<-M_PI) delPhi+=2.0*M_PI;
7014//v_diff(1)=delPhi;
7015if(printOut) cout<<"v_diff = "<<v_diff<<endl;
7016// --- new parameters
7017HepVector aNew=v_a+K*v_diff;
7018// --- new v_estim
7019KalFitTrack track_test(posEstiAtGem,aNew,EaNew,track.mass(),0.0,track.nchits());
7020double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7021HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7022double phiGemEsti_new=posEstiAtGem_new.phi();
7023double zGemEsti_new=posEstiAtGem_new.z();
7024double x0_new = posEstiAtGem_new.x();
7025double y0_new = posEstiAtGem_new.y();
7026double z0_new = posEstiAtGem_new.z();
7027HepVector v_estim_new(3,0);
7028v_estim_new(1)=x0_new;
7029v_estim_new(2)=y0_new;
7030v_estim_new(3)=z0_new;
7031if(printOut) cout<<"v_estim_new = "<<v_estim_new<<endl;
7032// --- diff between measurement and updated estimation
7033v_diff=v_measu-v_estim_new;
7034if(printOut) cout<<"v_diff_new = "<<v_diff<<endl;
7035// --- new derivative matrix
7036track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7037HepVector v_a_new = track_test.a();
7038HepSymMatrix Ea_new = track_test.Ea();
7039double phi0_new = v_a_new(2);
7040HepMatrix H_new(3, 5, 0);
7041H_new(1,1)=cos(phi0_new);
7042H_new(2,1)=sin(phi0_new);
7043H_new(3,4)=1.0;
7044HepMatrix H_new_T=H_new.T();
7045// --- R mactrix
7046if(printOut) cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7047HepSymMatrix R(3,0);
7048R.assign(V-H_new*Ea_new*H_new_T);
7049// --- Chi^2 added
7050HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7051if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7052if(printOut) cout<<"v_dChi2 = "<<v_dChi2<<endl;
7053double dChi2=v_dChi2(1);
7054if(ntuple_&1 && hypo==1) {
7055 m_chi2Gem[iLayer]=dChi2;
7056 m_phiGemExp[iLayer]=phiGemEsti;
7057 m_phiGemHit[iLayer]=v_measu(1);
7058 m_zGemExp[iLayer]=zGemEsti;
7059 m_zGemHit[iLayer]=v_measu(2);
7060}
7061// --- comparison
7062//
7063if(printOut) {
7064 cout<<"pivot: "<<posEstiAtGem<<endl;
7065 cout<<"new pivot: "<<posEstiAtGem_new<<endl;
7066 cout<<"a: "<<v_a<<endl;
7067 cout<<"new a: "<<v_a_new<<endl;
7068 cout<<"Ea: "<<Ea<<endl;
7069 cout<<"new Ea: "<<Ea_new<<endl;
7070 cout<<"dchi2= "<<dChi2<<endl;
7071}
7072//
7073// --- update KalFitTrack
7074if(iLayer>=0) track.set(posEstiAtGem_new,v_a_new,Ea_new);
7075//track.a(aNew);
7076//track.Ea(EaNew);
7077iLayer--;
7078// --- move track to rmin of this layer
7079rmin = m_CGEM[iGem].rmin();
7080dPhiToGem = track.intersect_cylinder(rmin);
7081posEstiAtGem = track.x(dPhiToGem);
7082track.pivot_numf(posEstiAtGem, pathInGem);
7083if(pathInGem>0)
7084{
7085 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
7086 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
7087}
7088}
7089else {
7090 if(printOut) {
7091 cout<<"iLayer = "<<iLayer<<endl;
7092 cout<<"rGemLayerMax = "<<m_CGEM[iGem].radius()<<endl;
7093 }
7094 rmax=m_CGEM[iGem].radius();
7095 double dPhiToGem = track.intersect_cylinder(rmax);
7096 HepPoint3D posEstiAtGem = track.x(dPhiToGem);
7097 track.pivot_numf(posEstiAtGem);
7098 int nHits=myGemHitCol[iLayer].size();
7099 if(nHits!=1) continue;
7100 //rGem=(myGemHitCol[iLayer].begin())->getR();
7101 double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
7102 double zGem=(myGemHitCol[iLayer].begin())->getZ();
7103 HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos();
7104 if(printOut) cout<<"v_measu,rGem = "<<v_measu<<", "<<rGem<<endl;
7105 dPhiToGem = track.intersect_cylinder(rGem);
7106 posEstiAtGem = track.x(dPhiToGem);
7107 double x0=posEstiAtGem.x();
7108 double y0=posEstiAtGem.y();
7109 double z0=posEstiAtGem.z();
7110 double pathInGem;
7111 track.pivot_numf(posEstiAtGem, pathInGem);
7112 if(pathInGem>0)
7113 {
7114 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
7115 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
7116 }
7117 double rGemEsti=posEstiAtGem.perp();
7118 double phiGemEsti=posEstiAtGem.phi();
7119 double zGemEsti=posEstiAtGem.z();
7120 HepVector v_estim(2,0);
7121 v_estim(1)=phiGemEsti;
7122 v_estim(2)=zGemEsti;
7123 if(printOut) {
7124 cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
7125 cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
7126 }
7127 const HepSymMatrix& Ea = track.Ea();
7128 HepVector v_a = track.a();
7129 double phi0=v_a(2);
7130 if(printOut) {
7131 cout<<"v_a = "<<v_a<<endl;
7132 cout<<"phi0 = "<<phi0<<endl;
7133 }
7134 // --- derivative matrix
7135 HepMatrix H(2, 5, 0);
7136 double c=1.0;
7137 //if(x0*y0>0.0&&useNCGem_==3&&iLayer==1) c=-1.0;
7138 //if(x0*y0>0.0) c=-1.0;
7139 //H(1,1)=c*(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
7140 H(1,1)=(x0*sin(phi0)-y0*cos(phi0))/(x0*x0+y0*y0);
7141 H(2,4)=1.0;
7142 if(printOut) cout<<"H="<<H<<endl;
7143 HepMatrix H_T=H.T();
7144 if(printOut) cout<<"H_T="<<H_T<<endl;
7145 // --- error matrix of Gem hit
7146 HepSymMatrix V=(myGemHitCol[iLayer].begin())->getErrMat();
7147 if(printOut) cout<<"V="<<V<<endl;
7148 HepMatrix HEa=H*Ea;
7149 HepMatrix HEaH_T=HEa*H_T;
7150 if(printOut) cout<<"HEaH_T="<<HEaH_T<<endl;
7151 int ierr=-1;
7152 HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
7153 if(printOut) cout<<"Vinv="<<Vinv<<endl;
7154 if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
7155 // --- gain matrix
7156 HepMatrix K=Ea*H_T*Vinv;
7157 if(printOut) cout<<"K="<<K<<endl;
7158 // --- new error matrix
7159 HepSymMatrix EaNew(5,0);
7160 EaNew.assign(Ea-K*H*Ea);
7161 // --- diff
7162 HepVector v_diff=v_measu-v_estim;
7163 double delPhi=v_diff(1);
7164 while(delPhi> M_PI) delPhi-=2.0*M_PI;
7165 while(delPhi<-M_PI) delPhi+=2.0*M_PI;
7166 v_diff(1)=delPhi;
7167 if(printOut) cout<<"v_diff = "<<v_diff<<endl;
7168 // --- new parameters
7169 HepVector aNew=v_a+K*v_diff;
7170 // --- new v_estim
7171 KalFitTrack track_test(posEstiAtGem,aNew,EaNew,track.mass(),0.0,track.nchits());
7172 double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7173 HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7174 double phiGemEsti_new=posEstiAtGem_new.phi();
7175 double zGemEsti_new=posEstiAtGem_new.z();
7176 double x0_new = posEstiAtGem_new.x();
7177 double y0_new = posEstiAtGem_new.y();
7178 HepVector v_estim_new(2,0);
7179 v_estim_new(1)=phiGemEsti_new;
7180 v_estim_new(2)=zGemEsti_new;
7181 if(printOut) cout<<"v_estim_new = "<<v_estim_new<<endl;
7182 // --- diff between measurement and updated estimation
7183 v_diff=v_measu-v_estim_new;
7184 delPhi=v_diff(1);
7185 while(delPhi> M_PI) delPhi-=2.0*M_PI;
7186 while(delPhi<-M_PI) delPhi+=2.0*M_PI;
7187 if(printOut) cout<<"v_diff_new = "<<v_diff<<endl;
7188 // --- new derivative matrix
7189 track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7190 HepVector v_a_new = track_test.a();
7191 HepSymMatrix Ea_new = track_test.Ea();
7192 double phi0_new = v_a_new(2);
7193 HepMatrix H_new(2, 5, 0);
7194 c=1.0;
7195 //if(x0_new*y0_new>0.0&&useNCGem_==3&&iLayer==1) c=-1.0;
7196 if(x0_new*y0_new>0.0) c=-1.0;
7197 //H_new(1,1)=c*(x0_new*cos(phi0_new)-y0_new*sin(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7198 H_new(1,1)=(x0_new*sin(phi0_new)-y0_new*cos(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7199 H_new(2,4)=1.0;
7200 HepMatrix H_new_T=H_new.T();
7201 // --- R mactrix
7202 if(printOut) cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7203 HepSymMatrix R(2,0);
7204 R.assign(V-H_new*Ea_new*H_new_T);
7205 // --- Chi^2 added
7206 HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7207 if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7208 if(printOut) cout<<"v_dChi2 = "<<v_dChi2<<endl;
7209 double dChi2=v_dChi2(1);
7210 if(ntuple_&1 && hypo==1) {
7211 m_chi2Gem[iLayer]=dChi2;
7212 m_phiGemExp[iLayer]=phiGemEsti;
7213 m_phiGemHit[iLayer]=v_measu(1);
7214 m_zGemExp[iLayer]=zGemEsti;
7215 m_zGemHit[iLayer]=v_measu(2);
7216 }
7217 // --- comparison
7218 //
7219 if(printOut) {
7220 cout<<"pivot: "<<posEstiAtGem<<endl;
7221 cout<<"new pivot: "<<posEstiAtGem_new<<endl;
7222 cout<<"a: "<<v_a<<endl;
7223 cout<<"new a: "<<v_a_new<<endl;
7224 cout<<"Ea: "<<Ea<<endl;
7225 cout<<"new Ea: "<<Ea_new<<endl;
7226 cout<<"dchi2= "<<dChi2<<endl;
7227 }
7228 //
7229 // --- update KalFitTrack
7230 if(iLayer>=0) track.set(posEstiAtGem_new,v_a_new,Ea_new);
7231 //track.a(aNew);
7232 //track.Ea(EaNew);
7233 iLayer--;
7234 // --- move track to rmin of this layer
7235 rmin = m_CGEM[iGem].rmin();
7236 dPhiToGem = track.intersect_cylinder(rmin);
7237 posEstiAtGem = track.x(dPhiToGem);
7238 track.pivot_numf(posEstiAtGem, pathInGem);
7239 if(pathInGem>0)
7240 {
7241 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
7242 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
7243 }
7244}
7245}// if hit in this layer
7246else {
7247 m_CGEM[iGem].updateTrack(track, way);
7248}
7249}// loop GEM layers
7250// end of GEM Kalman fit
7251//cout<<"finish GEM part"<<endl;
7252
7253}*/
7255{
7256 for(int i=0; i<3; i++) myGemHitCol[i].clear();
7257
7258 /*SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
7259 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
7260
7261 int nHits, nDigi;
7262 unsigned int stripIndx, isVStrip;
7263 int layer;
7264 double x, y, z, r, phi;
7265
7266 nHits = mdcMcHitCol->size();
7267 nDigi = mdcDigiCol->size();
7268
7269 //cout<<__FUNCTION__<<":: nHits = "<<nHits<<endl;
7270
7271 Rndm::Numbers gaussRPhi(randSvc(), Rndm::Gauss(0.,0.023));
7272 Rndm::Numbers gaussZ(randSvc(), Rndm::Gauss(0.,0.05));
7273
7274 MdcMcHitCol::const_iterator it = mdcMcHitCol->begin();
7275
7276 cout<<endl<<endl<<" ------------- Mdc MC hits: ------------"<<endl<<endl;*/
7277
7278 SmartDataPtr<RecCgemClusterCol> cgemClusterCol(eventSvc(),"/Event/Recon/RecCgemClusterCol");
7279 int layer,sheet;
7280 double phi,v;
7281 RecCgemClusterCol::const_iterator it = cgemClusterCol->begin();
7282 for(;it!=cgemClusterCol->end();it++){
7283 //cout<<"cluster:"<<(*it)->getclusterid()<<" phi:"<<(*it)->getrecphi()<<" z:"<<(*it)->getRecZ()<<endl;
7284 if((*it)->getflag()==2){
7285 layer = (*it)->getlayerid();
7286 sheet = (*it)->getsheetid();
7287 phi = (*it)->getrecphi();
7288 v = (*it)->getrecv();
7289 KalFitGemHit aKalFitGemHit(phi,v,layer,sheet);
7290 myGemHitCol[layer].push_back(aKalFitGemHit);
7291 }
7292 }
7293 if(debug_==4){
7294 cout << "Gem information" << endl;
7295 cout << "first layer " << myGemHitCol[0].size() << endl;
7296 cout << "second layer" << myGemHitCol[1].size() << endl;
7297 cout << "third layer" << myGemHitCol[2].size() << endl;
7298 }
7299 /*
7300 for(;it!=mdcMcHitCol->end(); it++)
7301 {
7302 Identifier id= (*it)->identify();
7303 layer = MdcID::layer(id);
7304 if(layer>7) continue;
7305 stripIndx = (*it)->getDriftDistance();
7306 isVStrip = (*it)->getPositionFlag();
7307 x = ((*it)->getPositionX())*0.1; // mm->cm
7308 y = ((*it)->getPositionY())*0.1; // mm->cm
7309 z = ((*it)->getPositionZ())*0.1; // mm->cm
7310 r=sqrt(x*x+y*y);
7311 phi=atan2(y,x);
7312 cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isVStrip<<endl;
7313 //cout<<" true x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
7314 if(myGemHitCol[layer].empty())
7315 {
7316 //cout<<"myGemHitCol["<<layer<<"] is empty"<<endl;
7317 phi+=gaussRPhi()/r;
7318 while(phi>M_PI) phi-=M_PI2;
7319 while(phi<-M_PI) phi+=M_PI2;
7320 z+=gaussZ();
7321 KalFitGemHit aKalFitGemHit(phi,z,r);
7322 //cout<<" resam x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
7323 myGemHitCol[layer].push_back(aKalFitGemHit);
7324 }
7325 }
7326
7327 cout<<endl<<endl<<" ------------- Mdc digi: ------------"<<endl<<endl;
7328
7329 MdcDigiCol::const_iterator it_digi = mdcDigiCol->begin();
7330 for(;it_digi!=mdcDigiCol->end(); it_digi++)
7331 {
7332 Identifier id = (*it_digi)->identify();
7333 layer = MdcID::layer(id);
7334 if(layer>7) continue;
7335 double stripId = RawDataUtil::MdcTime((*it_digi)->getTimeChannel());
7336 double isV = RawDataUtil::MdcCharge((*it_digi)->getChargeChannel());
7337 cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripId<<", "<<isV<<endl;
7338 stripIndx=stripId+0.5;
7339 cout<<" stripIndx = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isV<<endl;
7340 }
7341 */
7342
7343 // --- print out GEM hits
7344 bool prtGemHits=false;
7345 //bool prtGemHits=true;
7346 if(prtGemHits) cout<<endl<<"------- GEM hits: --------"<<endl;
7347 for(int i=0; i<3; i++)
7348 {
7349 if(prtGemHits) cout<<"### layer "<<i<<endl;
7350 //int nhits = myGemHitCol[i].size();
7351 KalFitGemHitCol::const_iterator it_GemHit = (myGemHitCol[i]).begin();
7352 for(int j=0; it_GemHit!=(myGemHitCol[i]).end(); it_GemHit++, j++)
7353 {
7354 if(prtGemHits) cout<<" hit "<<(j+1)<<": phi, z, r = "<<it_GemHit->getPhi()<<", "<<it_GemHit->getZ()<<", "<<it_GemHit->getR()<<endl;
7355 }
7356 }
7357
7358}
7359void KalFitAlg::fitGemHits(KalFitTrack& track, int hypo, int way)
7360{
7361 {
7362 //cout<<endl;
7363 //cout<<"--------------------------------------"<<endl;
7364 //cout<<"start GEM Kalman fit: hypo = "<<hypo<<endl;
7365 //cout<<"--------------------------------------"<<endl;
7366 // std::vector<double> dchi2_all;
7367 // std::vector<HepPoint3D> posnew;
7368 // std::vector<HepSymMatrix> eanew;
7369 // std::vector<HepVector> anew;
7370 //std::map<int,double> dchi2;
7371 std::map<double,double> esti1_r;
7372 std::map<double,double> esti2_r;
7373 std::map<double,double> esti1_phi;
7374 std::map<double,double> esti2_phi;
7375 std::map<double,double> esti1_z;
7376 std::map<double,double> esti2_z;
7377 std::map<double,double> diff1_phi;
7378 std::map<double,double> diff1_z;
7379 std::map<double,double> diff2_phi;
7380 std::map<double,double> diff2_z;
7381 std::map<double,HepPoint3D> posnew;
7382 std::map<double,HepSymMatrix> eanew;
7383 std::map<double,HepVector> anew;
7384 std::map<double,double> meas_r;
7385 std::map<double,double> meas_phi;
7386 std::map<double,double> meas_z;
7387 std::map<double,double> meas_phierr;
7388 std::map<double,double> esti_phierr;
7389 std::map<double,double> meas_zerr;
7390 std::map<double,double> esti_zerr;
7391 int ii=0;
7392 if(debug_==4){ cout << "wall size" << _BesKalmanFitWalls.size() << endl;}
7393 for(int iLayer=2; iLayer>=0; iLayer--)
7394 {
7395 posnew.clear();
7396 eanew.clear();
7397 anew.clear();
7398 esti1_r.clear();
7399 esti2_r.clear();
7400 esti1_phi.clear();
7401 esti2_phi.clear();
7402 esti1_z.clear();
7403 esti2_z.clear();
7404 diff1_phi.clear();
7405 diff1_z.clear();
7406 diff2_phi.clear();
7407 diff2_z.clear();
7408 meas_r.clear();
7409 meas_phi.clear();
7410 meas_z.clear();
7411 meas_phierr.clear();
7412 meas_zerr.clear();
7413 esti_phierr.clear();
7414 esti_zerr.clear();
7415 //cout<<"iLayer = "<<iLayer<<endl;
7416 int nHits=myGemHitCol[iLayer].size();
7417 //cout << "nhits" << nHits << "in layer" << iLayer << endl;
7418
7419 if (nHits <= 0) continue;
7420 //if(nHits!=1) continue;
7421
7422 vector<KalFitGemHit>::iterator iter;
7423 int ihit=0;
7424 // int ii=0;
7425 //cout <<"track before" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;
7426 innerwall(track,hypo,way,64+iLayer*(-32),88+iLayer*(-32));
7427 KalFitTrack track_start(track);
7428 //cout << "now position" << track_start.pivot().perp() << ","<< track_start.pivot().phi() << "," << track_start.pivot().z() <<endl;
7429 for(iter=myGemHitCol[iLayer].begin();iter!=myGemHitCol[iLayer].end();iter++ )
7430 {
7431 //cout <<"track" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;
7432 track.set(track_start.pivot(),track_start.a(),track_start.Ea());
7433 //cout << "track start" << "pivot=" << track_start.pivot() << "a=" << track_start.a() << "ea=" << track_start.Ea() << endl;
7434 double rGem=(*iter).getR();
7435 double phiGem=(*iter).getPhi();
7436 double zGem=(*iter).getZ();
7437 HepVector v_measu=(*iter).getVecPos();
7438 //cout << "hit" << ihit << "r=" << rGem << "phi=" << phiGem << "z=" << zGem << endl;
7439 // cout << "v_measu= " << v_measu << endl;
7440 /*
7441 double rGem=(myGemHitCol[iLayer].begin())->getR();
7442 double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
7443 double zGem=(myGemHitCol[iLayer].begin())->getZ();
7444 HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos();
7445 cout<<"v_measu = "<<v_measu<<endl;
7446 */
7447 double dPhiToGem = track.intersect_cylinder(rGem);
7448 //cout << "dPhiToGem=" << dPhiToGem << endl;
7449 HepPoint3D posEstiAtGem = track.x(dPhiToGem);
7450 double x0=posEstiAtGem.x();
7451 double y0=posEstiAtGem.y();
7452 double pathInGem;
7453 //cout << "before move" << "pivot" <<track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7454 track.pivot_numf(posEstiAtGem, pathInGem);
7455 //cout << "posEstiAtGem=" << posEstiAtGem << endl;
7456 //cout << "pathInGem=" << pathInGem << endl;
7457 if(pathInGem>0)
7458 {
7459 if(muls_) track.ms(pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7460 if(loss_) track.eloss(pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7461 }
7462 //cout << "after move" << "pivot" <<track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7463 double rGemEsti=posEstiAtGem.perp();
7464 double phiGemEsti=posEstiAtGem.phi();
7465 double zGemEsti=posEstiAtGem.z();
7466 HepVector v_estim(2,0);
7467 v_estim(1)=phiGemEsti;
7468 v_estim(2)=zGemEsti;
7469 //cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
7470 //cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
7471 double dPhi=track.intersect_cylinder(rGem);
7472 //cout << "dPhi=" << dPhi << endl;
7473 HepPoint3D pos = track.x(dPhi);
7474 //cout<< "assumed esti phi,z" << pos.phi() << "," << pos.z() << endl;
7475 const HepSymMatrix& Ea = track.Ea();
7476 HepVector v_a = track.a();
7477 double drho=v_a(1);
7478 double phi0=v_a(2);
7479 double kappa=v_a(3);
7480 double tl=v_a(5);
7481 //cout<<"v_a = "<<v_a<<endl;
7482 //cout<<"phi0 = "<<phi0<<endl;
7483 // --- derivative matrix
7484 HepMatrix H(2, 5, 0);
7485 //H(1,2)=(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
7486 //H(2,4)=1.0;
7487 H(1,1)=-y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
7488 //H(1,1)=(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
7489 //H(1,2)=-y0/(y0*y0+x0*x0)*sin(phi0+dPhi)-x0/(x0*x0+y0*y0)*cos(phi0+dPhi);
7490 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)));
7491 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));
7492 H(2,3)=m_alpha/(kappa*kappa)*tl*dPhi;
7493 H(2,4)=1.0;
7494 H(2,5)=-1*(m_alpha/kappa)*dPhi;
7495 //cout<<"H="<<H<<endl;
7496 HepMatrix H_T=H.T();
7497 //cout<<"H_T="<<H_T<<endl;
7498 //cout << "H*v_a=" << H*v_a << endl;
7499 //cout << "H*v_a+estim=" <<H*v_a+v_estim << endl;
7500 // --- error matrix of Gem hit
7501 HepSymMatrix V=(*iter).getErrMat();
7502 //cout<<"V="<<V<<endl;
7503 HepMatrix HEa=H*Ea;
7504 HepMatrix HEaH_T=HEa*H_T;
7505 int ierr=-1;
7506 HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
7507 if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
7508 // --- gain matrix
7509 HepMatrix K=Ea*H_T*Vinv;
7510 // --- new error matrix
7511 HepSymMatrix EaNew(5,0);
7512 EaNew.assign(Ea-K*H*Ea);
7513 // --- diff
7514 HepVector v_diff=v_measu-v_estim;
7515 //cout << "v_diff before= " << v_diff << endl;
7516 double delPhi=v_diff(1);
7517 if(fabs(v_diff(1))>6.28) v_measu(1)=-1*v_measu(1);
7518 while(delPhi> M_PI) delPhi-=M_PI;
7519 while(delPhi<-M_PI) delPhi+=M_PI;
7520 v_diff(1)=delPhi;
7521 //v_diff=v_measu-(H*v_a+v_estim);
7522 //cout<<"v_diff = "<<v_diff<<endl;
7523 // --- new parameters
7524 HepVector aNew=v_a+K*v_diff;
7525 //cout << "matrix K=" << K << endl;
7526 //cout << "aNew=" << aNew << endl;
7527 // --- new v_estim
7528 KalFitTrack track_test(posEstiAtGem,aNew,EaNew,hypo,0.0,track.nchits());
7529 double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7530 HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7531 double phiGemEsti_new=posEstiAtGem_new.phi();
7532 double zGemEsti_new=posEstiAtGem_new.z();
7533 double x0_new = posEstiAtGem_new.x();
7534 double y0_new = posEstiAtGem_new.y();
7535 HepVector v_estim_new(2,0);
7536 v_estim_new(1)=phiGemEsti_new;
7537 v_estim_new(2)=zGemEsti_new;
7538 //cout<<"v_estim_new = "<<v_estim_new<<endl;
7539 //cout << "assumed v_estim_new =" << H*aNew+v_estim << endl;
7540 // --- diff between measurement and updated estimation
7541 v_diff=v_measu-v_estim_new;
7542 delPhi=v_diff(1);
7543 while(delPhi> M_PI) delPhi-=M_PI;
7544 while(delPhi<-M_PI) delPhi+=M_PI;
7545 //cout<<"v_diff_new = "<<v_diff<<endl;
7546 //cout << "H*aNew"<< H*aNew << endl;
7547 //cout << "test v_diff new" << v_measu-v_estim-H*aNew << endl;
7548 // --- new derivative matrix
7549 track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7550 HepVector v_a_new = track_test.a();
7551 //cout << "v_a_new=" << v_a_new << endl;
7552 HepSymMatrix Ea_new = track_test.Ea();
7553 //cout << "Ea_new =" << Ea_new << endl;
7554 double phi0_new = v_a_new(2);
7555 double kappa_new=v_a_new(3);
7556 HepMatrix H_new(2, 5, 0);
7557 //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);
7558 //H_new(2,4)=1.0;
7559 //H_new(1,1)=(x0_new*cos(phi0_new)-y0_new*sin(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7560
7561 /* 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);
7562 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);
7563 H_new(2,4)=1.0;
7564 H_new(2,5)=-(-333.564095)/kappa_new*dPhiToGem_New;*/
7565 HepMatrix H_new_T=H_new.T();
7566 // --- R mactrix
7567 //cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7568 //cout << "H*Ea_new*H_T=" << H*Ea_new*H_T << endl;
7569 //cout << "H*EaNew*H_T=" << H*EaNew*H_T<< endl;
7570 //cout << "H_new*Eanew*H_new_T = "<< H_new*EaNew*H_new_T << endl;
7571 //cout << "assumed R=" <<V-H*Ea_new*H_T << endl;
7572 HepSymMatrix R(2,0);
7573 //R.assign(V-H_new*Ea_new*H_new_T);
7574 R.assign(V-H*EaNew*H_T);
7575
7576 //cout << "test track" << "pivot" << track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7577 // --- Chi^2 added
7578 //cout << "v_diff_T=" << v_diff.T() <<endl;
7579 //cout << "v_diff=" << v_diff <<endl;
7580 //cout << "R="<<R << endl;
7581 //cout << "R inverse=" << R.inverse(ierr)<< endl;
7582 HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7583 if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7584 //cout<<"v_dChi2 = "<<v_dChi2<<endl;
7585 //cout<< "test dchi2=" << (H*v_a).T()*R.inverse(ierr)*(H*v_a) << endl;
7586 double dChi2=v_dChi2(1);
7587
7588 // --- comparison
7589 if(debug_==4){
7590 cout<<"pivot: "<<posEstiAtGem<<endl;
7591 cout<<"new pivot: "<<posEstiAtGem<<endl;
7592 cout<<"a: "<<v_a<<endl;
7593 cout<<"new a: "<<aNew<<endl;
7594 cout<<"Ea: "<<Ea<<endl;
7595 cout<<"new Ea: "<<EaNew<<endl;
7596 cout<<"dchi2= "<<dChi2<<endl;
7597 }
7598 /* if(ntuple_&1){
7599 m_diff[ii]=delPhi;
7600 cout << v_diff(2) << endl;
7601 m_diffz[ii]=v_diff(2);
7602 m_phi[ii]=phiGem;
7603 m_z[ii]=zGem;
7604 m_Gemdchi2[ii]=dChi2;
7605 m_Glayer[ii]=iLayer;
7606 m_hypo[ii]=hypo;
7607 m_meas_r[ii]=rGem;
7608 m_meas_phi[ii]=phiGem;
7609 m_meas_z[ii]=zGem;
7610 m_esti1_r[ii]=rGemEsti;
7611 m_esti1_phi[ii]=phiGemEsti;
7612 m_esti1_z[ii]=zGemEsti;
7613 m_esti2_r[ii]=rGem;
7614 m_esti2_phi[ii]=phiGemEsti_new;
7615 m_esti2_z[ii]=zGemEsti_new;
7616 m_diff1_phi[ii]=phiGem-phiGemEsti;
7617 m_diff1_z[ii]=zGem-zGemEsti;
7618 m_diff2_phi[ii]=phiGem-phiGemEsti_new;
7619 m_diff2_z[ii]=zGem-zGemEsti_new;
7620 m_Gchi2[ii]=dChi2;
7621 m_GemLayer[ii]=iLayer;
7622 m_mass[ii]=hypo;
7623 } */
7624 // --- update KalFitTrack
7625 //track.set(posEstiAtGem_new,v_a_new,Ea_new);
7626 //dchi2_all.push_back(dChi2);
7627 //posnew.push_back(posEstiAtGem_new);
7628 //anew.push_back(v_a_new);
7629 //eanew.push_back(Ea_new);
7630 //dchi2[ii]=dChi2;
7631 esti1_r[dChi2]=rGemEsti;
7632 esti1_phi[dChi2]=phiGemEsti;
7633 esti1_z[dChi2]=zGemEsti;
7634 esti2_r[dChi2]=rGem;
7635 esti2_phi[dChi2]=phiGemEsti_new;
7636 esti2_z[dChi2]=zGemEsti_new;
7637 diff1_phi[dChi2]=phiGem-phiGemEsti;
7638 diff1_z[dChi2]=zGem-zGemEsti;
7639 diff2_phi[dChi2]=phiGem-phiGemEsti_new;
7640 diff2_z[dChi2]=zGem-zGemEsti_new;
7641 posnew[dChi2]=posEstiAtGem;
7642 anew[dChi2]=aNew;
7643 eanew[dChi2]=EaNew;
7644 meas_r[dChi2]=rGem;
7645 meas_phi[dChi2]=phiGem;
7646 //cout << "meas_phi[dChi2]" << phiGem << endl;
7647 meas_z[dChi2]=zGem;
7648 meas_phierr[dChi2]=sqrt(V[0][0]);
7649 //cout << "meas_phierr[dChi2]" << meas_phierr[dChi2] << endl;
7650 meas_zerr[dChi2]=sqrt(V[1][1]);
7651 //cout << "meas_zerr[dChi2]" << meas_zerr[dChi2] << endl;
7652 esti_phierr[dChi2]=sqrt((H*(track_start.Ea())*H_T)[0][0]);
7653 //cout << "esti_phierr[dChi2]" << esti_phierr[dChi2] << endl;
7654 esti_zerr[dChi2]=sqrt((H*(track_start.Ea())*H_T)[1][1]);
7655 //cout << "esti_zerr[dChi2]" << esti_zerr[dChi2] << endl;
7656
7657 ihit++;
7658 // ii++;
7659 }
7660
7661 //m_Gemhits=ii;
7662 //m_nt7->write();
7663 track.set((posnew.begin())->second,(anew.begin())->second,(eanew.begin()->second));
7664
7665 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(iLayer);
7666 double new_dPhiToGem = track.intersect_cylinder((CgemLayer->getInnerROfGapD())/10);
7667 HepPoint3D new_posEstiAtGem = track.x(new_dPhiToGem);
7668 double new_pathInGem;
7669 //cout << "new_dPhiToGem" << new_dPhiToGem << endl;
7670 //cout << "before move2" << "pivot" <<track.pivot().perp() << "," << track.pivot().phi() << "," << track.pivot().z()<< "a" << track.a() << "ea" << track.Ea() << endl;
7671 track.pivot_numf(new_posEstiAtGem, new_pathInGem);
7672 //cout << "posEstiAtGem2=" << new_posEstiAtGem << endl;
7673 //cout << "pathInGem2=" << new_pathInGem << endl;
7674 if(new_pathInGem>0)
7675 {
7676 if(muls_) track.ms(new_pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7677 if(loss_) track.eloss(new_pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7678 }
7679 //cout << "after move2: " << "pivot" <<track.pivot().perp() << "," << track.pivot().phi() << "," << track.pivot().z() << "a" << track.a() << "ea" << track.Ea() << endl;
7680 if(iLayer>=1){
7681 innerwall(track,hypo,way,90+(-32)*iLayer,95+(-32)*iLayer);}
7682 else{
7683 innerwall(track,hypo,way,90+(-32)*iLayer,94+(-32)*iLayer);}
7684 //cout <<"!!!!ntuple" << ntuple_ << endl;
7685 //cout << "!!!(esti1_phi.begin())->second" << (esti1_phi.begin())->second << endl;
7686 //cout<<" Finish innerwall"<<endl;
7687 if(ntuple_&1)
7688 {
7689 //cout << "good!" << endl;
7690 //cout << "m_esti1_r[ii]0" << m_esti1_r[ii] << endl;
7691 m_esti1_r[ii]=(esti1_r.begin())->second;
7692 //cout << "m_esti1_r[ii]1" << m_esti1_r[ii] << endl;
7693 m_esti1_phi[ii]=(esti1_phi.begin())->second;
7694 m_esti1_z[ii]=(esti1_z.begin())->second;
7695 m_esti2_r[ii]=(esti2_r.begin())->second;
7696 m_esti2_phi[ii]=(esti2_phi.begin())->second;
7697 m_esti2_z[ii]=(esti2_z.begin())->second;
7698 m_diff1_phi[ii]=(diff1_phi.begin())->second;
7699 m_diff1_z[ii]=(diff1_z.begin())->second;
7700 m_diff2_phi[ii]=(diff2_phi.begin())->second;
7701 m_diff2_z[ii]=(diff2_z.begin())->second;
7702 m_Gchi2[ii]=(esti1_r.begin())->first;
7703 m_meas_r[ii]=(meas_r.begin())->second;
7704 m_meas_phi[ii]=(meas_phi.begin())->second;
7705 //cout << "m_meas_phi[ii]" << m_meas_phi[ii] << endl;
7706 m_meas_z[ii]=(meas_z.begin())->second;
7707 m_meas_phierr[ii]=(meas_phierr.begin())->second;
7708 m_meas_zerr[ii]=(meas_zerr.begin())->second;
7709 m_esti_phierr[ii]=(esti_phierr.begin())->second;
7710 m_esti_zerr[ii]=(esti_zerr.begin())->second;
7711 m_GemLayer[ii]=iLayer;
7712 m_mass[ii]=hypo;
7713 }
7714 //cout<<" end of ntuple_"<<endl;
7715 ii++;
7716 }// loop layers
7717 //cout<<"finish layer loop"<<endl;
7718
7719 //SmartDataPtr<Event::EventHeader> evtHeader(eventSvc(),"/Event/EventHeader");
7720 //m_evt3 = evtHeader->eventNumber();
7721 if(ifProdNt10) {
7722 //cout << "m_meas_phi[ii]" << m_meas_phi[0] << endl;
7723 if(m_meas_phi[0]>0 && m_meas_phi[0]<1.5707963) m_qua=0;
7724 if(m_meas_phi[0]>1.5707963 && m_meas_phi[0]<3.1415926) m_qua=1;
7725 if(m_meas_phi[0]>-3.1415926&& m_meas_phi[0]<-1.5707963) m_qua=2;
7726 if(m_meas_phi[0]>-1.5707963&& m_meas_phi[0]<0) m_qua=3;
7727 //cout << "m_qua=" << m_qua << endl;
7728 m_nGemHits=ii;
7729 }
7730 //m_Gemhits=ii;
7731 // m_nt7->write();
7732 // m_nt10->write();
7733 posnew.clear();
7734 eanew.clear();
7735 anew.clear();
7736 esti1_r.clear();
7737 esti2_r.clear();
7738 esti1_phi.clear();
7739 esti2_phi.clear();
7740 esti1_z.clear();
7741 esti2_z.clear();
7742 diff1_phi.clear();
7743 diff1_z.clear();
7744 diff2_phi.clear();
7745 diff2_z.clear();
7746 meas_r.clear();
7747 meas_phi.clear();
7748 meas_z.clear();
7749 meas_phierr.clear();
7750 meas_zerr.clear();
7751 esti_phierr.clear();
7752 esti_zerr.clear();
7753
7754 }// end of GEM Kalman fit
7755 //cout << "end of GEM Kalman fit" << endl;
7756 if(ifProdNt10) {
7757 SmartDataPtr<Event::EventHeader> evtHeader(eventSvc(),"/Event/EventHeader");
7758 //cout << "evtHeader" << m_evt3 << endl;
7759 m_evt3 = evtHeader->eventNumber();
7760 m_nt10->write();
7761 }
7762
7763}
7764
7765
7766
7768{
7769
7770 ///---readin clusters of this track
7771 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
7772 if (!eventHeader) {
7773 cout << "Could not find Event Header" << endl;
7774 }
7775 int eventNo = eventHeader->eventNumber();
7776 int runNo = eventHeader->runNumber();
7777 SmartDataPtr<RecMdcTrackCol> recMdcTrack(eventSvc(),"/Event/Recon/RecMdcTrackCol");
7778 if (!recMdcTrack) {
7779 cout << "Could not find RecMdcTrackCol" << endl;
7780 }
7781 RecMdcTrackCol::iterator itrk = recMdcTrack->begin();
7782 ClusterRefVec clusterRefVec;
7783 for(; itrk != recMdcTrack->end(); itrk++){
7784 if((*itrk)->trackId() == track.trasan_id() && (*itrk)->getNcluster() > 0) {
7785 clusterRefVec = (*itrk)->getVecClusters();
7786 break;
7787 }
7788 else {
7789 if(4 == debug_) cout<<"run:"<<runNo<<" , Event:"<<eventNo<<" , track:"<<track.trasan_id()<<" has no cluster!"<<endl;
7790 }
7791 }
7792
7793 if(debug_==4){ cout<<"wall size"<<_BesKalmanFitWalls.size()<<endl;}
7794
7795 ///---set the start and stop point of fit
7796 ClusterRefVec::iterator itCluster;
7797 ClusterRefVec::iterator itStartFlag;
7798 ClusterRefVec::iterator itStopFlag;
7799 int step;
7800 int index=0;
7801 double lastR;
7802 double R_o_cgem=_BesKalmanFitWalls[0].radius();
7803 if(way<0){
7804 itStartFlag = clusterRefVec.begin();
7805 itStopFlag = clusterRefVec.end();
7806 lastR=0;
7807 step = 1;
7808 }
7809 else {
7810 itStartFlag = clusterRefVec.end()-1;
7811 itStopFlag = clusterRefVec.begin()-1;
7812 lastR=R_o_cgem;
7813 step = -1;
7814 double pathl;
7815 track.pivot_numf(track.x(track.intersect_cylinder(R_o_cgem)),pathl);
7816 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
7817 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
7818 }
7819
7820 ///---update track
7821 for(itCluster = itStartFlag; itCluster !=itStopFlag; itCluster = itCluster + step){
7822 int layer = (*itCluster)->getlayerid();
7823 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(layer);
7824 double dmR = CgemLayer->getMiddleROfGapD()/10;
7825 innerwall(track,hypo,way,lastR,dmR,index);
7826 lastR=dmR;
7827 double dchi2(0);
7828 //track.update_hits(*itCluster, dmR, way, m_csmflag);
7829 dchi2 = track.update_hits(*itCluster, dmR, way, m_csmflag);
7830 if (ntuple_&256 && way>0) {
7831
7832 //cout<<"cgem: "<<m_hit_no<<endl;
7833 m_nCluster++;
7834 if(hypo == 0){
7835 m_dchi2_hit_e[m_hit_no] = dchi2;
7836 m_residest_hit_e[m_hit_no] = 0;
7837 m_residnew_hit_e[m_hit_no] = 0;
7838 m_layer_hit_e[m_hit_no] = layer;
7839 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7840 m_anal_dr_hit_e[m_hit_no] = worktemp.a()[0];
7841 m_anal_phi0_hit_e[m_hit_no] = worktemp.a()[1];
7842 m_anal_kappa_hit_e[m_hit_no] = worktemp.a()[2];
7843 m_anal_dz_hit_e[m_hit_no] = worktemp.a()[3];
7844 m_anal_tanl_hit_e[m_hit_no] = worktemp.a()[4];
7845 m_anal_ea_dr_hit_e[m_hit_no] = worktemp.Ea()[0][0];
7846 m_anal_ea_phi0_hit_e[m_hit_no] = worktemp.Ea()[1][1];
7847 m_anal_ea_kappa_hit_e[m_hit_no] = worktemp.Ea()[2][2];
7848 m_anal_ea_dz_hit_e[m_hit_no] = worktemp.Ea()[3][3];
7849 m_anal_ea_tanl_hit_e[m_hit_no] = worktemp.Ea()[4][4];
7850 }
7851
7852
7853 else if(hypo == 1){
7854 m_dchi2_hit_mu[m_hit_no] = dchi2;
7855 m_residest_hit_mu[m_hit_no] = 0;
7856 m_residnew_hit_mu[m_hit_no] = 0;
7857 m_layer_hit_mu[m_hit_no] = layer;
7858 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7859 m_anal_dr_hit_mu[m_hit_no] = worktemp.a()[0];
7860 m_anal_phi0_hit_mu[m_hit_no] = worktemp.a()[1];
7861 m_anal_kappa_hit_mu[m_hit_no] = worktemp.a()[2];
7862 m_anal_dz_hit_mu[m_hit_no] = worktemp.a()[3];
7863 m_anal_tanl_hit_mu[m_hit_no] = worktemp.a()[4];
7864 m_anal_ea_dr_hit_mu[m_hit_no] = worktemp.Ea()[0][0];
7865 m_anal_ea_phi0_hit_mu[m_hit_no] = worktemp.Ea()[1][1];
7866 m_anal_ea_kappa_hit_mu[m_hit_no] = worktemp.Ea()[2][2];
7867 m_anal_ea_dz_hit_mu[m_hit_no] = worktemp.Ea()[3][3];
7868 m_anal_ea_tanl_hit_mu[m_hit_no] = worktemp.Ea()[4][4];
7869 }
7870
7871
7872
7873 else if(hypo == 2){
7874 m_dchi2_hit_pi[m_hit_no] = dchi2;
7875 m_residest_hit_pi[m_hit_no] = 0;
7876 m_residnew_hit_pi[m_hit_no] = 0;
7877 m_layer_hit_pi[m_hit_no] = layer;
7878 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7879 m_anal_dr_hit_pi[m_hit_no] = worktemp.a()[0];
7880 m_anal_phi0_hit_pi[m_hit_no] = worktemp.a()[1];
7881 m_anal_kappa_hit_pi[m_hit_no] = worktemp.a()[2];
7882 m_anal_dz_hit_pi[m_hit_no] = worktemp.a()[3];
7883 m_anal_tanl_hit_pi[m_hit_no] = worktemp.a()[4];
7884 m_anal_ea_dr_hit_pi[m_hit_no] = worktemp.Ea()[0][0];
7885 m_anal_ea_phi0_hit_pi[m_hit_no] = worktemp.Ea()[1][1];
7886 m_anal_ea_kappa_hit_pi[m_hit_no] = worktemp.Ea()[2][2];
7887 m_anal_ea_dz_hit_pi[m_hit_no] = worktemp.Ea()[3][3];
7888 m_anal_ea_tanl_hit_pi[m_hit_no] = worktemp.Ea()[4][4];
7889 }
7890
7891
7892 else if(hypo == 3){
7893 m_dchi2_hit_k[m_hit_no] = dchi2;
7894 m_residest_hit_k[m_hit_no] = 0;
7895 m_residnew_hit_k[m_hit_no] = 0;
7896 m_layer_hit_k[m_hit_no] = layer;
7897 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7898 m_anal_dr_hit_k[m_hit_no] = worktemp.a()[0];
7899 m_anal_phi0_hit_k[m_hit_no] = worktemp.a()[1];
7900 m_anal_kappa_hit_k[m_hit_no] = worktemp.a()[2];
7901 m_anal_dz_hit_k[m_hit_no] = worktemp.a()[3];
7902 m_anal_tanl_hit_k[m_hit_no] = worktemp.a()[4];
7903 m_anal_ea_dr_hit_k[m_hit_no] = worktemp.Ea()[0][0];
7904 m_anal_ea_phi0_hit_k[m_hit_no] = worktemp.Ea()[1][1];
7905 m_anal_ea_kappa_hit_k[m_hit_no] = worktemp.Ea()[2][2];
7906 m_anal_ea_dz_hit_k[m_hit_no] = worktemp.Ea()[3][3];
7907 m_anal_ea_tanl_hit_k[m_hit_no] = worktemp.Ea()[4][4];
7908 }
7909
7910
7911 else if(hypo == 4){
7912 m_dchi2_hit_p[m_hit_no] = dchi2;
7913 m_residest_hit_p[m_hit_no] = 0;
7914 m_residnew_hit_p[m_hit_no] = 0;
7915 m_layer_hit_p[m_hit_no] = layer;
7916 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7917 m_anal_dr_hit_p[m_hit_no] = worktemp.a()[0];
7918 m_anal_phi0_hit_p[m_hit_no] = worktemp.a()[1];
7919 m_anal_kappa_hit_p[m_hit_no] = worktemp.a()[2];
7920 m_anal_dz_hit_p[m_hit_no] = worktemp.a()[3];
7921 m_anal_tanl_hit_p[m_hit_no] = worktemp.a()[4];
7922 m_anal_ea_dr_hit_p[m_hit_no] = worktemp.Ea()[0][0];
7923 m_anal_ea_phi0_hit_p[m_hit_no] = worktemp.Ea()[1][1];
7924 m_anal_ea_kappa_hit_p[m_hit_no] = worktemp.Ea()[2][2];
7925 m_anal_ea_dz_hit_p[m_hit_no] = worktemp.Ea()[3][3];
7926 m_anal_ea_tanl_hit_p[m_hit_no] = worktemp.Ea()[4][4];
7927 }
7928
7929 m_hit_no++;
7930 }
7931 }// loop clusters
7932 KalFitTrack track_first(track);
7933 if(way<0){
7934 innerwall(track,hypo,way,lastR,R_o_cgem,index);
7935 }
7936 else
7937 {
7938 innerwall(track,hypo,way,lastR,0,index);
7939 }
7940
7941 return track_first;
7942}
7943
7944
7945/*
7946void KalFitAlg::Cgem_filter_anal(KalFitTrack& track, int hypo, int way)
7947{
7948 const double a_stero[3] = {(45.94*3.1415926/180),(31.10*3.1415926/180),(32.99*3.1415926/180)};
7949 const double w_sheet[3] = {549.78,417.097,550.614};
7950 const double r_layer[3] = {87.5026,132.7686,175.2686};
7951 const double dmr_layer[3] = {79.838,125.104,167.604};
7952 const int l_layer[3] = {532,690,847};
7953 const int n_sheet[3] = {1,2,2};
7954 const double x_reso[3]={0.1372,0.1476,0.1412};
7955 const double v_reso[3]={0.1273,0.1326,0.1378};
7956 //KalFitTrack track(Track);
7957
7958 SmartDataPtr<RecMdcTrackCol> recMdcTrack(eventSvc(),"/Event/Recon/RecMdcTrackCol");
7959 if (!recMdcTrack) {
7960 //cout << MSG::FATAL << "Could not find RecMdcTrackCol" << endreq;
7961 cout << "Could not find RecMdcTrackCol" << endl;
7962 return;
7963 }
7964 RecMdcTrackCol::iterator itrk = recMdcTrack->begin();
7965 ClusterRefVec clusterRefVec;
7966 for(; itrk != recMdcTrack->end(); itrk++){
7967 if((*itrk)->trackId() == track.trasan_id() && (*itrk)->getNcluster() > 0) {
7968 clusterRefVec = (*itrk)->getVecClusters();
7969 break;
7970 }
7971 else{cout<<"track id:"<<(*itrk)->trackId()<<","<<track.trasan_id()<<" cluster:"<<(*itrk)->getNcluster()<<endl;return;}
7972 }
7973 if(debug_==4){ cout<<"wall size"<<_BesKalmanFitWalls.size()<<endl;}
7974
7975 ClusterRefVec::iterator itCluster;
7976 ClusterRefVec::iterator itStartFlag;
7977 ClusterRefVec::iterator itStopFlag;
7978 int step;
7979 int index=0;
7980 double lastR=_BesKalmanFitWalls[0].radius();
7981 if(way>0){
7982 itStartFlag = clusterRefVec.end()-1;
7983 itStopFlag = clusterRefVec.begin()-1;
7984 step = -1;
7985 }
7986 else if(way<0){
7987 itStartFlag = clusterRefVec.begin();
7988 itStopFlag = clusterRefVec.end();
7989 step = 1;
7990 }
7991 else{
7992 cout<<"way=0,no filter direction"<<endl;
7993 return;
7994 }
7995
7996
7997 for(itCluster = itStartFlag; itCluster !=itStopFlag; itCluster = itCluster + step){
7998 int layer = (*itCluster)->getlayerid();
7999 //double dmR = dmr_layer[layer]/10;
8000 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(iLayer);
8001 double dmR = CgemLayer->getMiddleROfGapD()/10;
8002 double recZ = (*itCluster)->getRecZ()/10;
8003 double recPhi = (*itCluster)->getrecphi();
8004 while(recPhi > M_PI) recPhi-=2*M_PI;
8005 while(recPhi <-M_PI) recPhi+=2*M_PI;
8006
8007 innerwall(track,hypo,way,lastR,dmR,index);
8008 lastR=dmR;
8009 HepVector v_measu(2,0);
8010 v_measu(1) = recPhi;
8011 v_measu(2) = recZ;
8012 //double Phi = track.intersect_cylinder(dmR);
8013 HepPoint3D x0kal = track.x(track.intersect_cylinder(dmR));
8014 track.pivot_numf(x0kal);
8015 double x0 = x0kal.x();
8016 double y0 = x0kal.y();
8017 double pathl(0);
8018 HepVector v_estim(2,0);
8019 v_estim(1) = x0kal.phi();
8020 v_estim(2) = x0kal.z();
8021 double dPhi=track.intersect_cylinder(dmR);
8022 const HepSymMatrix& Ea = track.Ea();
8023 HepVector v_a = track.a();
8024 double dr = v_a(1);
8025 double phi0 = v_a(2);
8026 double kappa = v_a(3);
8027 double tanl = v_a(5);
8028 // --- derivative matrix
8029 HepMatrix H(2, 5, 0);
8030 H(1,1) = -y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
8031 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)));
8032 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));
8033 H(2,3) = m_alpha/(kappa*kappa)*tanl*dPhi;
8034 H(2,4) = 1.0;
8035 H(2,5) = -1*(m_alpha/kappa)*dPhi;
8036 // --- error matrix of Cgem
8037 HepSymMatrix V(2,0);
8038 V(1,1) = pow(x_reso[layer]/r_layer[layer],2);
8039 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);
8040 // --- gain matrix
8041 int ierr=-1;
8042 HepMatrix K = Ea*H.T()*(V+H*Ea*H.T()).inverse(ierr);
8043 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
8044 // --- new error matrix
8045 HepSymMatrix EaNew(5,0);
8046 EaNew.assign(Ea-K*H*Ea);
8047 // --- diff
8048 HepVector v_diff = v_measu - v_estim;
8049 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
8050 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
8051 // --- new parameters
8052 HepVector aNew = v_a + K*v_diff;
8053 // --- new v_estim
8054 KalFitTrack track_new(x0kal,aNew,EaNew,hypo,0.0,track.nchits());
8055 HepPoint3D x0kal_new = track_new.x(track_new.intersect_cylinder(dmR));
8056 HepVector v_estim_new(2,0);
8057 v_estim_new(1) = x0kal_new.phi();
8058 v_estim_new(2) = x0kal_new.z();
8059 // --- difference between measurement and updated estimation
8060 v_diff = v_measu - v_estim_new;
8061 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
8062 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
8063 // --- new derivative matrix
8064 //track_new.pivot_numf(x0kal_new,pathl);
8065 //HepVector a_new = track_new.a();
8066 //HepVector Ea_new = track_new.Ea();
8067 // --- R matrix
8068 HepSymMatrix R(2,0);
8069 R.assign(V-H*EaNew*H.T());
8070 HepVector dChi2 = v_diff.T()*R.inverse(ierr)*v_diff;
8071 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
8072 if(way>0) track.chiSq(track.chiSq()+dChi2(1));
8073 if(way<0) track.chiSq_back(track.chiSq_back()+dChi2(1));
8074 //track.set(x0kal,aNew,EaNew);
8075 track.set(track.pivot(),aNew,EaNew);
8076 }
8077}
8078*/
8079
8080
8082{
8083
8084 //cout<<"R:"<<track.pivot().perp()<<endl;
8085 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
8086 if (!eventHeader) {
8087 cout << "Could not find Event Header" << endl;
8088 }
8089 int eventNo = eventHeader->eventNumber();
8090 int runNo = eventHeader->runNumber();
8091 m_evt=eventNo;
8092 //cout<<"Event::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"<<eventNo<<endl;
8093
8094 SmartDataPtr<McParticleCol> mcPartCol(eventSvc(),"/Event/MC/McParticleCol");
8095 if (!mcPartCol) {
8096 cout << "Could not find McParticle" << endl;
8097 }
8098
8099 HepVector mc_a(5,0);
8100 McParticleCol::iterator i_mcTrk = mcPartCol->begin();
8101 for (;i_mcTrk != mcPartCol->end(); i_mcTrk++) {
8102 if(!(*i_mcTrk)->primaryParticle()) continue;
8103 const HepLorentzVector& mom((*i_mcTrk)->initialFourMomentum());
8104 const HepLorentzVector& pos = (*i_mcTrk)->initialPosition();
8105 //cout<<"MCposition:"<<pos.x()<<" "<<pos.y()<<" "<<pos.z()<<" "<<endl;
8106 double charge = 0.0;
8107 int pid = (*i_mcTrk)->particleProperty();
8108 if( pid >0 ) {
8109 charge = m_particleTable->particle( pid )->charge();
8110 } else if ( pid <0 ) {
8111 charge = m_particleTable->particle( -pid )->charge();
8112 charge *= -1;
8113 } else {
8114 }
8115 HepPoint3D pos2(pos.x(),pos.y(),pos.z());
8116 Hep3Vector mom2(mom.px(),mom.py(),mom.pz());
8117
8118 KalmanFit::Helix mchelix(pos2, mom2, charge);
8119 //if( debug_ == 0) cout<< "helix: "<<mchelix.a()<<endl;
8120 mchelix.pivot( HepPoint3D(0,0,0) );
8121 for( int j =0; j<5; j++) {
8122 //m_mchelix[j] = mchelix.a()[j];
8123 mc_a[j] = mchelix.a()[j];
8124 }
8125 //m_mcpid = pid;
8126 //m_mcptot = sqrt(1+pow(m_mchelix[4],2))/m_mchelix[2];
8127 }
8128 HepPoint3D IP(0,0,0);
8129 KalmanFit::Helix MChelix(IP,mc_a);
8130 MChelix.pivot(track.pivot());
8131 m_diff_dr = track.a()[0]-MChelix.a()[0];
8132 m_diff_phi0 = track.a()[1]-MChelix.a()[1];
8133 m_diff_kappa = track.a()[2]-MChelix.a()[2];
8134 m_diff_dz = track.a()[3]-MChelix.a()[3];
8135 m_diff_tanl = track.a()[4]-MChelix.a()[4];
8136 if(track.a()[2] != 0 && MChelix.a()[2] != 0)
8137 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];
8138 else
8139 m_diff_p =9999;
8140 StatusCode sc12 = m_nt12->write();
8141 if( sc12.isFailure() ) cout<<"Ntuple12 filling failed!"<<endl;
8142 //cout<<"kalfit a:"<<track.a()<<endl<<"MCtruth a:"<<MChelix.a()<<endl<<endl;
8143 ///*
8144 // --- calculate the material quantity
8145 bool printwalls = false;
8146 if(printwalls){
8147 double material_quantity(0);
8148 int size = _BesKalmanFitWalls.size();
8149 for(int i=0;i<size;i++)
8150 {
8151 double ro = _BesKalmanFitWalls[i].radius();
8152 double ri = _BesKalmanFitWalls[i].rmin();
8153 double thick = ro-ri;
8154 KalFitMaterial material = _BesKalmanFitWalls[i].material();
8155 double X0 = material.X0();
8156 double rho = material.get_density();
8157 double Z = material.Z();
8158 //double X = X0/rho;
8159 material_quantity += 100*thick/X0;
8160 cout<<"----------------------------------------------------------------------------------------------------"<<endl;
8161 cout<<"wall"<<i+1<<" Z:"<<setw(12)<<Z<<endl;
8162 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;
8163 cout<<"----------------------------------------------------------------------------------------------------"<<endl;
8164 cout<<endl;
8165 //cout<<"wall"<<i+1<<" Z:"<<Z<<" Thick:"<<thick<<" Density:"<<rho <<" X0:"<<X0<<endl;
8166 //cout<<"radiation length="<<x<<" material quantity="<<thick/x<<endl;
8167
8168 }
8169 cout<<"============================================================"<<endl;
8170 cout<<"total material quantity="<<material_quantity<<endl;
8171 cout<<"============================================================"<<endl;
8172 }
8173 //*/
8174}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
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
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
HepGeom::Point3D< double > HepPoint3D
Definition: KalFitAlg.h:54
#define DBL_MAX
Definition: KalFitAlg.h:13
**********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
int eventNo
ObjectVector< RecMdcKalHelixSeg > RecMdcKalHelixSegCol
SmartRefVector< RecMdcKalHelixSeg > HelixSegRefVec
ObjectVector< RecMdcKalTrack > RecMdcKalTrackCol
SmartRefVector< RecCgemCluster > ClusterRefVec
Definition: RecMdcTrack.h:28
SmartRefVector< RecMdcHit > HitRefVec
Definition: RecMdcTrack.h:26
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
#define M_PI
Definition: TConstant.h:4
#define X0
double getMiddleROfGapD() const
Definition: CgemGeoLayer.h:105
double getOuterROfGapD() const
Definition: CgemGeoLayer.h:104
double getInnerROfGapD() const
Definition: CgemGeoLayer.h:103
CgemGeoLayer * getCgemLayer(int i) const
Definition: CgemGeomSvc.h:48
void setFHelix(const HepVector &fhelix, const int pid)
const double y() const
void setStat(int stat, int i, int pid)
void setY(const double y, const int pid)
void setPz(const double pz, const int pid)
void setChisq(double chisq, int i, int pid)
void setZError(const HepSymMatrix &error, const int pid)
void setX(const double x, const int pid)
void setPoca(const HepPoint3D &poca, const int pid)
void setPx(const double px, const int pid)
void setZ(const double z, const int pid)
void setTheta(const double theta, const int pid)
const double px() const
const double z() const
void setPy(const double py, const int pid)
void setFError(const HepSymMatrix &ferror, const int pid)
static void setPidType(PidType pidType)
void setTrackId(int trackId)
const double pz() const
void setZHelix(const HepVector &helix, const int pid)
const double py() const
void setCharge(const int charge, const int pid)
void setNdf(int ndf, int i, int pid)
const double x() const
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
Definition: KalFitAlg.h:201
int debug_kft_
Definition: KalFitAlg.h:227
double gain1_
Definition: KalFitAlg.h:212
void residual(KalFitTrack &track)
Definition: KalFitAlg.cxx:8081
double m_alpha
Definition: KalFitAlg.h:249
void filter_fwd_anal(KalFitTrack &trk, int l_mass, int way, HepSymMatrix &Eakal)
Kalman filter (forward) in Mdc.
Definition: KalFitAlg.cxx:3183
void filter_fwd_calib(KalFitTrack &trk, int l_mass, int way, HepSymMatrix &Eakal)
Definition: KalFitAlg.cxx:3545
double dchi2cut_mid1_
Definition: KalFitAlg.h:235
double fstrag_
factor of energy loss straggling for electron
Definition: KalFitAlg.h:238
double pmu_cut_
Definition: KalFitAlg.h:201
StatusCode beginRun()
Definition: KalFitAlg.cxx:342
double fac_h4_
Definition: KalFitAlg.h:210
double m_dangcut
Definition: KalFitAlg.h:248
int loss_
Definition: KalFitAlg.h:207
double theta_cut_
Definition: KalFitAlg.h:202
double pt_cut_
Definition: KalFitAlg.h:202
int back_
flag to perform smoothing
Definition: KalFitAlg.h:189
double gain3_
Definition: KalFitAlg.h:212
void fillTds_lead(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
Definition: KalFitAlg.cxx:1663
int iqual_front_[5]
Definition: KalFitAlg.h:241
int numfcor_
Definition: KalFitAlg.h:214
int outer_steps_
Definition: KalFitAlg.h:217
int eventno
Definition: KalFitAlg.h:191
~KalFitAlg(void)
destructor
Definition: KalFitAlg.cxx:182
int muls_
Definition: KalFitAlg.h:207
void fromFHitToInnerWall(KalFitTrack &track, int way)
Definition: KalFitAlg.cxx:6872
double gain5_
Definition: KalFitAlg.h:212
double dchi2cutf_
Definition: KalFitAlg.h:233
void clean(void)
Definition: KalFitAlg.cxx:190
int tof_hyp_
Definition: KalFitAlg.h:207
void kalman_fitting_MdcxReco_Csmc_Sew(void)
Definition: KalFitAlg.cxx:5066
double pp_cut_
Definition: KalFitAlg.h:201
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:2830
int iqual_back_
Definition: KalFitAlg.h:241
int i_back_
mass assumption for backward filter (if <0 means use leading mass)
Definition: KalFitAlg.h:224
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:6117
int wsag_
flag to take account the wire sag into account
Definition: KalFitAlg.h:187
double fac_h3_
Definition: KalFitAlg.h:210
double dchi2cut_mid2_
Definition: KalFitAlg.h:235
void kalman_fitting_calib(void)
Definition: KalFitAlg.cxx:4477
void sameas(RecMdcKalTrack *trk, int l_mass, int imain)
complete the RecMdcKalTrackCol
Definition: KalFitAlg.cxx:2811
void fillTds_ip(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
with results got at (0,0,0)
Definition: KalFitAlg.cxx:1758
void makeGemHitsCol()
Definition: KalFitAlg.cxx:7254
int tofflag_
Definition: KalFitAlg.h:207
int mhyp_
Definition: KalFitAlg.h:199
void fitGemHits(KalFitTrack &track, int hypo, int way)
Definition: KalFitAlg.cxx:7359
string matfile_
Definition: KalFitAlg.h:231
void fillTds(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
with results got at the inner Mdc hit
Definition: KalFitAlg.cxx:1493
void innerwall(KalFitTrack &trk, int l_mass, int way)
Take the inner walls (eloss and mult scat) into account.
Definition: KalFitAlg.cxx:3743
double fac_h1_
Definition: KalFitAlg.h:210
double m_dphicut
Definition: KalFitAlg.h:248
KalFitTrack Cgem_filter_anal(KalFitTrack &track, int hypo, int way)
Definition: KalFitAlg.cxx:7767
double fac_h2_
Definition: KalFitAlg.h:210
int fitnocut_
Definition: KalFitAlg.h:220
int debug_
Debug flag for the track finder part.
Definition: KalFitAlg.h:227
string cylfile_
Definition: KalFitAlg.h:231
int usage_
Definition: KalFitAlg.h:181
int pathl_
Definition: KalFitAlg.h:185
void start_seed(KalFitTrack &track, int lead_, int way, MdcRec_trk &trk)
Definition: KalFitAlg.cxx:6636
double dchi2cut_layid2_
Definition: KalFitAlg.h:235
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:3841
int i_front_
Definition: KalFitAlg.h:225
void setDchisqCut(void)
Definition: KalFitAlg.cxx:815
int m_usevtxdb
Definition: KalFitAlg.h:246
int tprop_
propagation correction
Definition: KalFitAlg.h:244
double dchi2cut_layid3_
Definition: KalFitAlg.h:235
double fac_h5_
Definition: KalFitAlg.h:210
int choice_
Definition: KalFitAlg.h:183
void set_Mdc(void)
Set up the wires, layers and superlayers...
Definition: KalFitAlg2.cxx:114
int drifttime_choice_
Definition: KalFitAlg.h:222
int m_csmflag
Definition: KalFitAlg.h:247
double dchi2cut_outer_
Definition: KalFitAlg.h:235
int enhance_
flag to enhance the error matrix at the inner hit of Mdc (cosmic)
Definition: KalFitAlg.h:209
int myEventNo
Definition: KalFitAlg.h:245
StatusCode execute()
event function
Definition: KalFitAlg.cxx:918
double gain2_
Definition: KalFitAlg.h:212
int inner_steps_
Definition: KalFitAlg.h:216
int lead_
leading mass assumption
Definition: KalFitAlg.h:197
int resolution_
Definition: KalFitAlg.h:240
double dchi2cuts_
Definition: KalFitAlg.h:233
void smoother_calib(KalFitTrack &trk, int way)
Definition: KalFitAlg.cxx:3045
void init_matrix(MdcRec_trk &trk, HepSymMatrix &Ea)
Definition: KalFitAlg.cxx:6538
int numf_
Definition: KalFitAlg.h:215
double pk_cut_
Definition: KalFitAlg.h:201
double pT_
value of the pT cut for backward filter
Definition: KalFitAlg.h:195
int steplev_
Definition: KalFitAlg.h:213
double matrixg_
Definition: KalFitAlg.h:210
StatusCode initialize()
initialize
Definition: KalFitAlg.cxx:204
StatusCode finalize()
Definition: KalFitAlg.cxx:320
void kalman_fitting_csmalign(void)
Definition: KalFitAlg.cxx:5555
double gain4_
Definition: KalFitAlg.h:212
int ntuple_
Fill ntuples of KalFit.
Definition: KalFitAlg.h:229
double ppi_cut_
Definition: KalFitAlg.h:201
void hist_def(void)
hist definition
Definition: KalFitAlg.cxx:378
void fillTds_back(KalFitTrack &track, RecMdcKalTrack *trk, MdcRec_trk &TrasanTRK, int l_mass)
with results got at the outer Mdc hit
Definition: KalFitAlg.cxx:2023
double dchi2cut_inner_
Definition: KalFitAlg.h:235
int activeonly_
Definition: KalFitAlg.h:207
void clearTables()
Definition: KalFitAlg.cxx:6745
static int muls(void)
static int loss(void)
CLHEP::HepVector a_pre_fwd(void)
CLHEP::HepSymMatrix Ea_filt_fwd(void)
CLHEP::HepSymMatrix & Ea_pre_fwd(void)
KalFitHitMdc * HitMdc(void)
Description of a Hit in Mdc.
Definition: KalFitHitMdc.h:17
double chi2_back(void) const
Definition: KalFitHitMdc.h:31
int LR(void) const
Definition: KalFitHitMdc.h:29
double chi2(void) const
Definition: KalFitHitMdc.h:30
const KalFitWire & wire(void) const
Definition: KalFitHitMdc.h:35
const int layerId(void) const
returns layer ID
double get_density(void) const
double X0(void) const
Extractor.
double Z(void) const
Description of a track class (<- Helix.cc)
Definition: KalFitTrack.h:36
double * pathl(void)
Definition: KalFitTrack.h:194
static void setMdcDigiCol(MdcDigiCol *digicol)
static int lead(void)
Magnetic field map.
static double chi2_hitf_
Cut chi2 for each hit.
Definition: KalFitTrack.h:289
static double dchi2cuts_anal[43]
Definition: KalFitTrack.h:297
int type(void) const
Definition: KalFitTrack.h:184
unsigned int nchits(void) const
Definition: KalFitTrack.h:203
static double dchi2cuts_calib[43]
Definition: KalFitTrack.h:301
double tof_proton(void) const
Definition: KalFitTrack.h:198
static int debug_
for debug
Definition: KalFitTrack.h:287
static int nmass(void)
double tof_kaon(void) const
Definition: KalFitTrack.h:197
static double Bznom_
Definition: KalFitTrack.h:306
static int back(void)
void order_wirhit(int index)
HepSymMatrix getInitMatrix(void) const
static void setInitMatrix(HepSymMatrix m)
double chiSq(void) const
Definition: KalFitTrack.h:188
int ndf_back(void) const
Definition: KalFitTrack.h:190
static int nmdc_hit2_
Cut chi2 for each hit.
Definition: KalFitTrack.h:319
static int tofall_
Definition: KalFitTrack.h:321
KalFitHelixSeg & HelixSeg(int i)
Definition: KalFitTrack.h:240
void addTofSM(double time)
static int steplev_
Definition: KalFitTrack.h:309
void chgmass(int i)
static double factor_strag_
factor of energy loss straggling for electron
Definition: KalFitTrack.h:317
int trasan_id(void) const
Definition: KalFitTrack.h:185
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.
Definition: KalFitTrack.h:312
void update_forMdc(void)
double intersect_cylinder(double r) const
Intersection with different geometry.
double chiSq_back(void) const
Definition: KalFitTrack.h:189
double getFiTerm(void)
Definition: KalFitTrack.h:169
void HitsMdc(vector< KalFitHitMdc > &lh)
double getPathSM(void)
Definition: KalFitTrack.h:163
double pathip(void) const
Definition: KalFitTrack.h:191
void fiTerm(double fi)
void point_last(const HepPoint3D &point)
set and give out the last point of the track
Definition: KalFitTrack.h:146
void HelixSegs(vector< KalFitHelixSeg > &vs)
static double chi2_hits_
Definition: KalFitTrack.h:289
static int numf_
Flag for treatment of non-uniform mag field.
Definition: KalFitTrack.h:291
unsigned int nster(void) const
Definition: KalFitTrack.h:204
static int inner_steps_
Definition: KalFitTrack.h:292
double mass(void) const
Definition: KalFitTrack.h:187
static int outer_steps_
Definition: KalFitTrack.h:293
double p_proton(void) const
Definition: KalFitTrack.h:200
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
Definition: KalFitTrack.h:328
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
Definition: KalFitTrack.h:284
void appendHitsMdc(KalFitHitMdc h)
Functions for Mdc hits list.
void addPathSM(double path)
static double dchi2cutf_calib[43]
Definition: KalFitTrack.h:299
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 *)
double getTofSM(void)
Definition: KalFitTrack.h:166
static int numfcor_
NUMF treatment improved.
Definition: KalFitTrack.h:304
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 double dchi2cutf_anal[43]
Definition: KalFitTrack.h:295
static int LR_
Use L/R decision from MdcRecHit information :
Definition: KalFitTrack.h:326
double p_kaon(void) const
Definition: KalFitTrack.h:199
KalFitHitMdc & HitMdc(int i)
Definition: KalFitTrack.h:235
static int strag_
Flag to take account of energy loss straggling :
Definition: KalFitTrack.h:315
Description of a Wire class.
Definition: KalFitWire.h:46
unsigned int geoID(void) const
Definition: KalFitWire.h:74
unsigned int localId(void) const
Extractor :
Definition: KalFitWire.h:69
HepPoint3D bck(void) const
Definition: KalFitWire.h:93
HepPoint3D fwd(void) const
Geometry :
Definition: KalFitWire.h:92
const KalFitLayer_Mdc & layer(void) const
Definition: KalFitWire.h:70
unsigned int stereo(void) const
Definition: KalFitWire.h:75
double lzx(void) const
Definition: KalFitWire.h:96
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.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
int Id(void) const
Definition: MdcGeoLayer.h:155
int Wirst(void) const
Definition: MdcGeoLayer.h:157
MdcGeoLayer * Lyr(void) const
Definition: MdcGeoWire.h:140
int Id(void) const
Definition: MdcGeoWire.h:127
double Tension(void) const
Definition: MdcGeoWire.h:136
const MdcGeoWire *const Wire(unsigned id)
Definition: MdcGeomSvc.cxx:770
const MdcGeoLayer *const Layer(unsigned id)
Definition: MdcGeomSvc.cxx:786
Definition: MdcID.h:9
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
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
MdcRec_trk * body
Definition: MdcTables.h:767
float helix[5]
Definition: MdcTables.h:403
float chiSq
Definition: MdcTables.h:406
float fiTerm
Definition: MdcTables.h:408
vector< MdcRec_wirhit * > hitcol
Definition: MdcTables.h:414
MdcRec_trk_add * add
Definition: MdcTables.h:415
float pivot[3]
Definition: MdcTables.h:404
float error[15]
Definition: MdcTables.h:405
float ndf
Definition: MdcTables.h:407
float pChiSq
Definition: MdcTables.h:332
MdcDat_wirhit * dat
Definition: MdcTables.h:336
RecMdcHit * rechitptr
Definition: MdcTables.h:338
const MdcGeoWire * geo
Definition: MdcTables.h:335
MdcRec_trk * trk
Definition: MdcTables.h:337
void setTrackId(int trackid)
void setResIncl(double res)
void setDocaExcl(double doca)
HepVector & getHelixExcl(void)
void setHelixIncl(const HepVector &helix)
void setLayerId(int layerId)
void setDT(double dt)
int getFlagLR(void) const
void setDrIncl(double dr)
HepVector & getHelixIncl(void)
void setTanlIncl(double tanl)
void setDzIncl(double dz)
void setAdc(double adc)
void setEntra(double entra)
void setDzExcl(double dz)
void setFi0Excl(double fi0)
void setFi0Incl(double fi0)
double getResIncl(void)
void setFlagLR(int flagLR)
HepSymMatrix & getErrorExcl(void)
void setCpaIncl(double cpa)
void setTdc(double tdc)
void setDD(double dd)
void setResExcl(double res)
void setCpaExcl(double cpa)
void setDrExcl(double dr)
void setHelixExcl(const HepVector &helix)
void setZhit(double zhit)
HepSymMatrix & getErrorIncl(void)
void setErrorExcl(const HepSymMatrix &error)
void setTanlExcl(double tanl)
void setMdcId(Identifier mdcid)
void setTof(double tof)
void setDocaIncl(double doca)
void setErrorIncl(const HepSymMatrix &error)
const HepVector & getZHelix() const
void setLHelix(const HepVector &helix, const int pid)
void setFiTerm(double fi, const int pid)
double getPathSM(int pid) const
void setPathSM(double length, int pid)
HepVector & getZHelixP()
const HepPoint3D & getLPoint() const
const double getFiTerm(const int pid) const
double getTof(int pid) const
const HepSymMatrix & getFError() const
double getChisq(int i, int pid) const
void setLength(double length, int pid)
HepVector & getZHelixK()
void setTError(const HepSymMatrix &error)
void setMass(double mass, int pid)
HelixSegRefVec getVecHelixSegs(int pid=-1) const
const HepVector & getFHelix() const
void setTHelix(const HepVector &helix)
void setPathl(double pathl, int i)
const HepPoint3D & getLPivot() const
int getTrackId(void) const
void setVecHelixSegs(const HelixSegRefVec &vechelixsegs, int pid=-1)
void setLError(const HepSymMatrix &error, const int pid)
int getNhits(int pid) const
double getMass(int pid) const
void setLPoint(const HepPoint3D &point, const int pid)
int getStat(int i, int pid) const
void setLPivot(const HepPoint3D &pivot, const int pid)
double getLength(int pid) const
void setTof(double tof, int pid)
int getNdf(int i, int pid) const
void setNhits(int nhits, int pid)
IMPLICIT REAL *A H
Definition: myXsection.h:1
Definition: Event.h:21