CGEM BOSS 6.6.5.h
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"
63#include "MdcGeomSvc/MdcGeomSvc.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 // --- just check nCgemXCluster, nCgemVCluster
1252 //cout<<"KalFitAlg::execute(): nCgemXCluster, nCgemVCluster = "<<(*iter_trk)->nCgemXCluster()<<", "<<(*iter_trk)->nCgemVCluster()<<endl;
1253
1254 for ( int i=0; i<5; i++) {
1255 rectrk->helix[i] = (*iter_trk)->helix()[i];
1256 if( i<3 ) rectrk->pivot[i] = (*iter_trk)->getPivot()[i];
1257 for( int j = 1; j<i+2;j++) {
1258 rectrk->error[i*(i+1)/2+j-1] = (*iter_trk)->err()(i+1,j);
1259 }
1260 }
1261 std::sort(gothits.begin(), gothits.end(), order_rechits);
1262 HitRefVec::iterator it_gothit = gothits.begin();
1263 for( ; it_gothit != gothits.end(); it_gothit++) {
1264
1265 if( (*it_gothit)->getStat() != 1 ) {
1266 if(activeonly_) {
1267 log<<MSG::WARNING<<"this hit is not used in helix fitting!"<<endreq;
1268 continue;
1269 }
1270 }
1271
1272 log << MSG::DEBUG << "retrieved hits in MDC tracks:"
1273 << " hits DDL " <<(*it_gothit)->getDriftDistLeft()
1274 << " hits DDR " <<(*it_gothit)->getDriftDistRight()
1275 << " error DDL " <<(*it_gothit)->getErrDriftDistLeft()
1276 << " error DDR " <<(*it_gothit)->getErrDriftDistRight()
1277 << " id of hit "<<(*it_gothit)->getId()
1278 << " track id of hit "<<(*it_gothit)->getTrkId()
1279 << " hits ADC " <<(*it_gothit)->getAdc() << endreq;
1280
1281 MdcRec_wirhit* whit = new MdcRec_wirhit;
1282 whit->id = (*it_gothit)->getId();
1283 whit->ddl = (*it_gothit)->getDriftDistLeft();
1284 whit->ddr = (*it_gothit)->getDriftDistRight();
1285 whit->erddl = (*it_gothit)->getErrDriftDistLeft();
1286 whit->erddr = (*it_gothit)->getErrDriftDistRight();
1287 whit->pChiSq = (*it_gothit)->getChisqAdd();
1288 whit->lr = (*it_gothit)->getFlagLR();
1289 whit->stat = (*it_gothit)->getStat();
1290 mdcid = (*it_gothit)->getMdcId();
1291 int layid = MdcID::layer(mdcid);
1292 int localwid = MdcID::wire(mdcid);
1293 int w0id = geosvc->Layer(layid)->Wirst();
1294 int wid = w0id + localwid;
1295 log << MSG::INFO
1296 << "lr from PR: "<<whit->lr
1297 << " layerId = " << layid
1298 << " wireId = " << localwid
1299 << endreq;
1300
1301 const MdcGeoWire * const wirgeo = geosvc->Wire(wid);
1302
1303 //std::cout<<"the track id of *it_gothit... "<<(*it_gothit)->getTrackId()<<std::endl;
1304 whit->rechitptr = *it_gothit;
1305 whit->geo = wirgeo;
1306 whit->dat = 0;
1307 whit->trk = rectrk;
1308 whit->tdc = (*it_gothit)->getTdc();
1309 whit->adc= (*it_gothit)->getAdc();
1310 rectrk->hitcol.push_back(whit);
1311 mhit_mgr->push_back(*whit);
1312 }
1313 mtrk_mgr->push_back(*rectrk);
1314 mtrkadd_mgr->push_back(*trkadd);
1315
1316 delete rectrk;
1317 delete trkadd;
1318 }
1319
1320 // check trkcol: evt level
1321 if(ntuple_&4) {
1322 m_trkdelx = trkx1 - trkx2;
1323 m_trkdely = trky1 - trky2;
1324 m_trkdelz = trkz1 - trkz2;
1325 m_trkdelthe = trkthe1 + trkthe2;
1326 m_trkdelphi = trkphi1- trkphi2;
1327 m_trkdelp = trkp1 - trkp2;
1328 StatusCode sc4 = m_nt4->write();
1329 if( sc4.isFailure() ) cout<<"Ntuple4 filling failed!"<<endl;
1330 }
1331
1332 if(debug_ == 4) { std::cout<<"before refit,ntrk,nhits,nadd..."<<mtrk_mgr->size()
1333 <<"********"<<mhit_mgr->size()<<"****"<<mtrkadd_mgr->size()<<endl;
1334 }
1335
1336 if(useNCGem_>0) makeGemHitsCol();
1337
1338 // Actual fitter procedure :
1339 //cout << "m_trackid" << m_trackid << endl;
1340 //cout << "m_qua" << m_qua << endl;
1341 //cout << "m_esti" << m_esti1_r[0] << endl;
1342 if(usage_ == 0) kalman_fitting_anal();
1343 if(usage_ == 1) kalman_fitting_calib();
1344 double mdang = 180.0 - csmp3[0].angle(csmp3[1].unit())*180.0/M_PI;
1345 double mdphi = 180.0 - fabs(csmphi[0]-csmphi[1])*180.0/M_PI;
1346 //std::cout<<"before refit,ntrk,nhits,nadd..."<<mtrk_mgr->size()<<" , "<<mhit_mgr->size()<<" , "<<mtrkadd_mgr->size()<<endl;
1347 if(usage_ == 2 && (mtrk_mgr->size())==2 && fabs(mdang)<m_dangcut && fabs(mdphi)<m_dphicut) kalman_fitting_csmalign();
1348 if(usage_ == 3 && (mtrk_mgr->size())==1 && status_temp==-1) kalman_fitting_MdcxReco_Csmc_Sew();
1349
1350 log << MSG::DEBUG <<"after kalman_fitting(),but in execute...."<<endreq;
1351 clearTables();
1352
1353
1354 ///*
1355 // --- test for songxy
1356 MdcID mdcId;
1357 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
1358 //cout<<"------------------------ new event ---------------------"<<endl;
1359 //cout<<"recmdckaltrkCol->size()="<<recmdckaltrkCol->size()<<endl;
1360 //cout<<"--------------------------------------------------------"<<endl;
1362 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
1363 int i_trk=0;
1364 for(;KalTrk !=recmdckaltrkCol->end();KalTrk++, i_trk++){
1365 //cout<<"*** track "<<i_trk++<<" ***"<<endl;
1366 bool trkFailed = false;
1367 for(int hypo=0; hypo<5; hypo++)
1368 {
1369 if((*KalTrk)->getStat(0,hypo)==1) {
1370 nFailedTrks[hypo]++;
1371 trkFailed=true;
1372 }
1373 }
1374 if(trkFailed) cout<<" Evt "<<myEventNo<<", track "<<i_trk<<": Kalman filter failed"<<endl;
1375 //if(eventNo==1080) cout<<"mu_status = "<<(*KalTrk)->getStat(0,1)<<endl;
1376 HelixSegRefVec gothelixsegs = (*KalTrk)->getVecHelixSegs();
1377 HelixSegRefVec::iterator iter_hit = gothelixsegs.begin();
1378 //if(iter_hit == gothelixsegs.end())cout<<"iter_hit == gothelixsegs.end()"<<endl;
1379 int nhitofthistrk=0;
1380 for( ; iter_hit != gothelixsegs.end(); iter_hit++){
1381 nhitofthistrk++;
1382 //cout<<"layerId: "<<(*iter_hit)->getLayerId()<<endl;
1383 //cout<<"Identifier: "<<(*iter_hit)->getMdcId()<<endl;
1384 //cout<<"layerId: "<<mdcId.layer((*iter_hit)->getMdcId())<<endl;
1385 //cout<<"getDT: "<<(*iter_hit)->getDT()<<endl;
1386 }
1387 iter_hit=gothelixsegs.begin();
1388 //for(int m=0; m<nhitofthistrk/5;m++){
1389 // identifier = (*iter_hit) -> getMdcId();
1390 //}
1391 }
1392 // */
1393
1394 // --- test for getStat(2, pid)
1395 /*
1396 SmartDataPtr<RecMdcKalTrackCol> recmdckaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
1397 SmartDataPtr<RecMdcTrackCol> mdcTrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
1398 //RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
1399 RecMdcKalTrackCol::iterator KalTrk= recmdckaltrkCol->begin();
1400 int i_trk=0;
1401 for(RecMdcTrackCol::iterator mdcTrk = mdcTrkCol->begin(); KalTrk !=recmdckaltrkCol->end(); KalTrk++, mdcTrk++){
1402 cout<<"*** track "<<i_trk++<<" ***"<<endl;
1403 cout<<"trackId mdc: "<<(*mdcTrk)->trackId()<<endl;
1404 cout<<"trackId kal: "<<(*KalTrk)->trackId()<<endl;
1405 bool KalIsValid = true;
1406 for(int i_pid=0; i_pid<5; i_pid++) {
1407 cout<<"pid "<<i_pid<<" state 0 : "<<(*KalTrk)->getStat(0, i_pid)<<endl;
1408 cout<<"pid "<<i_pid<<" state 1 : "<<(*KalTrk)->getStat(1, i_pid)<<endl;
1409 if((*KalTrk)->getStat(0, i_pid)==1) {
1410 KalIsValid = false;
1411 switch(i_pid) {
1412 case 0: RecMdcKalTrack::setPidType(RecMdcKalTrack::electron);
1413 break;
1414 case 1: RecMdcKalTrack::setPidType(RecMdcKalTrack::muon);
1415 break;
1416 case 2: RecMdcKalTrack::setPidType(RecMdcKalTrack::pion);
1417 break;
1418 case 3: RecMdcKalTrack::setPidType(RecMdcKalTrack::kaon);
1419 break;
1420 case 4: RecMdcKalTrack::setPidType(RecMdcKalTrack::proton);
1421 break;
1422 }
1423 cout<<"Helix Kal: "<<(*KalTrk)->helix()<<endl;
1424 cout<<"Helix Kal err: "<<(*KalTrk)->err()<<endl;
1425 }
1426 }
1427 if(!KalIsValid) {
1428 cout<<"Helix Mdc: "<<(*mdcTrk)->helix()<<endl;
1429 cout<<"Helix Mdc err: "<<(*mdcTrk)->err()<<endl;
1430 }
1431 }
1432 */
1433 if(ifProdNt11)
1434 {
1435 SmartDataPtr<Event::CgemMcHitCol> cgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
1436 if (!cgemMcHitCol){
1437 log << MSG::WARNING << "Could not retrieve Cgem MC truth" << endreq;
1438 return StatusCode::FAILURE;
1439 }
1440 m_evt4=eventHeader->eventNumber();
1441 Event::CgemMcHitCol::iterator iter_truth = cgemMcHitCol->begin();
1442 int jj=0;
1443 double dprex,dprey,dprez,dpostx,dposty,dpostz;
1444 int layer;
1445 for(; iter_truth != cgemMcHitCol->end(); ++iter_truth){
1446 layer = (*iter_truth)->GetLayerID();
1447 dprex = (*iter_truth)->GetPositionXOfPrePoint();
1448 dprey = (*iter_truth)->GetPositionYOfPrePoint();
1449 dprez = (*iter_truth)->GetPositionZOfPrePoint();
1450 dpostx = (*iter_truth)->GetPositionXOfPostPoint();
1451 dposty = (*iter_truth)->GetPositionYOfPostPoint();
1452 dpostz = (*iter_truth)->GetPositionZOfPostPoint();
1453
1454 double midx=0;
1455 double midy=0;
1456 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(layer);
1457 double diR = CgemLayer->getInnerROfGapD();
1458 double dmR = CgemLayer->getMiddleROfGapD();
1459 double doR = CgemLayer->getOuterROfGapD();
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 if((dprex <0&&dprey<0)||(dprex >=0&&dprey<0)){
1469 //m_dtphi[jj] = -acos(dprex/dr_layer[layer]);
1470 m_dtphi[jj] = -acos(dprex/diR);
1471 m_dtv[jj] = dprez;
1472 //m_dtpostphi[jj] = -acos(dpostx/dor_layer[layer]);
1473 m_dtpostphi[jj] = -acos(dpostx/doR);
1474 m_dtpostz[jj]= dpostz;
1475 }
1476 midx=(dprex+dpostx)/2;
1477 midy=(dprey+dposty)/2;
1478 if((midx>=0&&midy>=0)||(midx<0&&midy>=0)){
1479 //m_dtphi[jj]=acos(midx/dmr_layer[layer]);
1480 m_dtphi[jj]=acos(midx/dmR);
1481 }
1482 if((midx<0&&midy<0)||(midx>=0&&midy<0)){
1483 //m_dtphi[jj]=-acos(midx/dmr_layer[layer]);
1484 m_dtphi[jj]=-acos(midx/dmR);
1485 }
1486 m_dtv[jj] = (m_dtv[jj]+m_dtpostz[jj])/20;
1487 m_tlayer[jj] = layer;
1488 jj++;
1489 }
1490 m_ntruth = jj;
1491
1492 m_nt11->write();
1493 }
1494
1495
1496
1497 return StatusCode::SUCCESS;
1498}
1499
1500// fill TDS:
1502 RecMdcKalTrack* trk , int l_mass) {
1503
1504 HepPoint3D IP(0,0,0);
1505 track.pivot(IP);
1506 // Fit quality
1507 int iqual(1);
1508 int trasster = TrasanTRK.nster, trakster = track.nster(),
1509 trasax(TrasanTRK.nhits-trasster), trakax(track.nchits()-trakster);
1510
1511
1512 if(ntuple_&256){
1513 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
1514 if(!eventHeader){
1515 cout<<"Open event header file failed!"<<endl;
1516 }
1517 m_run_kal = eventHeader->runNumber();
1518 m_event_kal = eventHeader->eventNumber();
1519
1520 m_trkid_kal = track.trasan_id();
1521 if(l_mass==0){
1522 //m_dropedHits_kal_e = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1523 m_dropedHits_kal_e = TrasanTRK.ndf+5-track.nchits();
1524 m_kappa2_kal_e = TrasanTRK.helix[2]*track.a()[2];
1525 m_trackNhits_kal_e = track.nchits();
1526 m_trackNster_kal_e = track.nster();
1527 m_trackNaxis_kal_e = track.nchits()-track.nster();
1528 m_chi2_kal_e = track.chiSq();
1529 m_Ea00_kal_e = track.Ea()[0][0];
1530 m_Ea11_kal_e = track.Ea()[1][1];
1531 m_Ea22_kal_e = track.Ea()[2][2];
1532 m_Ea33_kal_e = track.Ea()[3][3];
1533 m_Ea44_kal_e = track.Ea()[4][4];
1534 }
1535 else if(l_mass==1){
1536 //m_dropedHits_kal_mu = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1537 m_dropedHits_kal_mu = TrasanTRK.ndf+5-track.nchits();
1538 m_kappa2_kal_mu = TrasanTRK.helix[2]*track.a()[2];
1539 m_trackNhits_kal_mu = track.nchits();
1540 m_trackNster_kal_mu = track.nster();
1541 m_trackNaxis_kal_mu = track.nchits()-track.nster();
1542 m_chi2_kal_mu = track.chiSq();
1543 m_Ea00_kal_mu = track.Ea()[0][0];
1544 m_Ea11_kal_mu = track.Ea()[1][1];
1545 m_Ea22_kal_mu = track.Ea()[2][2];
1546 m_Ea33_kal_mu = track.Ea()[3][3];
1547 m_Ea44_kal_mu = track.Ea()[4][4];
1548 //if(myEventNo==1080) cout<<"m_dropedHits_kal_mu = "<<m_dropedHits_kal_mu<<endl;
1549 }
1550 else if(l_mass==2){
1551 //m_dropedHits_kal_pi = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1552 m_dropedHits_kal_pi = TrasanTRK.ndf+5-track.nchits();
1553 m_kappa2_kal_pi = TrasanTRK.helix[2]*track.a()[2];
1554 m_trackNhits_kal_pi = track.nchits();
1555 m_trackNster_kal_pi = track.nster();
1556 m_trackNaxis_kal_pi = track.nchits()-track.nster();
1557 m_chi2_kal_pi = track.chiSq();
1558 m_Ea00_kal_pi = track.Ea()[0][0];
1559 m_Ea11_kal_pi = track.Ea()[1][1];
1560 m_Ea22_kal_pi = track.Ea()[2][2];
1561 m_Ea33_kal_pi = track.Ea()[3][3];
1562 m_Ea44_kal_pi = track.Ea()[4][4];
1563
1564 }
1565 else if(l_mass==3){
1566 //m_dropedHits_kal_k = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1567 m_dropedHits_kal_k = TrasanTRK.ndf+5-track.nchits();
1568 m_kappa2_kal_k = TrasanTRK.helix[2]*track.a()[2];
1569 m_trackNhits_kal_k = track.nchits();
1570 m_trackNster_kal_k = track.nster();
1571 m_trackNaxis_kal_k = track.nchits()-track.nster();
1572 m_chi2_kal_k = track.chiSq();
1573 m_Ea00_kal_k = track.Ea()[0][0];
1574 m_Ea11_kal_k = track.Ea()[1][1];
1575 m_Ea22_kal_k = track.Ea()[2][2];
1576 m_Ea33_kal_k = track.Ea()[3][3];
1577 m_Ea44_kal_k = track.Ea()[4][4];
1578
1579 }
1580 else if(l_mass==4){
1581 //m_dropedHits_kal_p = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1582 m_dropedHits_kal_p = TrasanTRK.ndf+5-track.nchits();
1583 m_kappa2_kal_p = TrasanTRK.helix[2]*track.a()[2];
1584 m_trackNhits_kal_p = track.nchits();
1585 m_trackNster_kal_p = track.nster();
1586 m_trackNaxis_kal_p = track.nchits()-track.nster();
1587 m_chi2_kal_p = track.chiSq();
1588 m_Ea00_kal_p = track.Ea()[0][0];
1589 m_Ea11_kal_p = track.Ea()[1][1];
1590 m_Ea22_kal_p = track.Ea()[2][2];
1591 m_Ea33_kal_p = track.Ea()[3][3];
1592 m_Ea44_kal_p = track.Ea()[4][4];
1593
1594 }
1595 }
1596
1597
1598 // if (TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits()>fitnocut_ ||
1599 if(TrasanTRK.ndf+5-track.nchits()>fitnocut_
1600 || TrasanTRK.helix[2]*track.a()[2]<0)
1601 iqual = 0;
1602
1603 if (debug_ == 4) {
1604 cout<< "trasster trakster trasax trakax TrasK trackK iqual"<<endl
1605 <<trasster<<" "<<trakster<<" "<<trasax<<" "<<trakax
1606 <<" "<<TrasanTRK.helix[2]<<" "<<track.a()[2]<<" "<<iqual<<endl;
1607 cout<<"FillTds> track.chiSq..."<<track.chiSq()<<" nchits "<<track.nchits()
1608 <<" nster "<<track.nster()<<" iqual "<<iqual<<" track.Ea "<< track.Ea()<<endl;
1609
1610 cout<<"fillTds>.....track.Ea[2][2] "<<track.Ea()[2][2]<<endl;
1611 cout << " TRASAN stereo = " << trasster
1612 << " and KalFitTrack = " << trakster << std::endl;
1613 cout << " TRASAN axial = " << trasax
1614 << " and KalFitTrack = " << trakax << std::endl;
1615
1616 if (!iqual) {
1617 cout << "...there is a problem during fit !! " << std::endl;
1618 if (trasster-trakster>5)
1619 cout << " because stereo " << trasster-trakster << std::endl;
1620 if (trasax-trakax >5)
1621 cout << " because axial " << std::endl;
1622 if (TrasanTRK.helix[2]*track.a()[2]<0)
1623 cout << " because kappa sign " << std::endl;
1624 }
1625 }
1626 // Protection : if any problem, we keep the original information !!!!
1627 if (track.nchits() > 5 && track.nster() > 1 &&
1628 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1629 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1630 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1631 track.Ea()[4][4] > 0 && iqual) {
1632 if(debug_ == 4) cout<<"fillTds>.....going on "<<endl;
1633 trk->setStat(0,0,l_mass);
1634 trk->setMass(track.mass(),l_mass);
1635
1636 // chisq & ndf
1637 trk->setChisq(track.chiSq(),0,l_mass);
1638 trk->setNdf(track.nchits()-5,0,l_mass);
1639 trk->setNhits(track.nchits(),l_mass);
1640
1641 trk->setFHelix(track.a(),l_mass);
1642 trk->setFError(track.Ea(),l_mass);
1643
1644 } else {
1645
1646 if(debug_==4) cout<<"ALARM: FillTds Not refit with KalFilter!!! lmass="<<l_mass<<endl;
1647 // NOT refit with Kalman filter :
1648 trk->setStat(1,0,l_mass);
1649 trk->setMass(KalFitTrack::mass(l_mass),l_mass);
1650 // chisq & ndf (0 : filter ; 1 : smoother;)
1651 trk->setChisq(TrasanTRK.chiSq,0,l_mass);
1652 //trk->setNdf(TrasanTRK.nhits-5,0,l_mass);
1653 trk->setNdf(TrasanTRK.ndf,0,l_mass);
1654 // nhits
1655 //trk->setNhits(TrasanTRK.nhits,l_mass);
1656 trk->setNhits(TrasanTRK.ndf+5,l_mass);
1657 double a_trasan[5], ea_trasan[15];
1658 for( int i =0 ; i <5; i++){
1659 a_trasan[i] = TrasanTRK.helix[i];
1660 }
1661 for( int j =0 ; j <15; j++){
1662 ea_trasan[j] = TrasanTRK.error[j];
1663 }
1664 trk->setFHelix(a_trasan, l_mass);
1665 trk->setFError(ea_trasan,l_mass);
1666 }
1667 //if(l_mass==1&&m_event_kal==1080) cout<<"mu_status_filled = "<<trk->getStat(0,l_mass)<<endl;
1668}
1669
1670// Fill Tds :
1672 RecMdcKalTrack* trk , int l_mass) {
1673
1674 HepPoint3D IP(0,0,0);
1675 track.pivot(IP);
1676 // Fit quality
1677 // int iqual(1);
1678 int trasster = TrasanTRK.nster, trakster = track.nster(),
1679 trasax(TrasanTRK.nhits-trasster), trakax(track.nchits()-trakster);
1680 //if (TrasanTRK.nhits-track.nchits()>fitnocut_ ||
1681 if(TrasanTRK.ndf+5-track.nchits()>fitnocut_ ||
1682 TrasanTRK.helix[2]*track.a()[2]<0)
1683 iqual_front_[l_mass] = 0;
1684 if (debug_ == 4) {
1685
1686 cout<<"Nhit from PR "<<TrasanTRK.nhits<<" nhit "<<track.nchits()<<endl;
1687 cout<< "trasster trakster trasax trakax TrasK trackK iqual"<<endl
1688 <<trasster<<" "<<trakster<<" "<<trasax<<" "<<trakax
1689 <<" "<<TrasanTRK.helix[2]<<" "<<track.a()[2]<<" "<<iqual_front_[l_mass]<<endl;
1690 cout<<"FillTds_lead> track.chiSq..."<<track.chiSq()<<" nchits "<<track.nchits()
1691 <<" nster "<<track.nster()<<" iqual_front_[l_mass] "<<iqual_front_[l_mass]<<" track.Ea "<<track.Ea()<<endl;
1692
1693 cout << " TRASAN stereo = " << trasster
1694 << " and KalFitTrack = " << trakster << std::endl;
1695 cout << " TRASAN axial = " << trasax
1696 << " and KalFitTrack = " << trakax << std::endl;
1697
1698 if (!iqual_front_[l_mass]) {
1699 cout << "...there is a problem during fit !! " << std::endl;
1700 if (trasster-trakster>5)
1701 cout << " because stereo " << trasster-trakster << std::endl;
1702 if (trasax-trakax >5)
1703 cout << " because axial " << std::endl;
1704 if (TrasanTRK.helix[2]*track.a()[2]<0)
1705 cout << " because kappa sign " << std::endl;
1706 }
1707 }
1708 // Protection : if any problem, we keep the original information !!!!
1709 if (track.nchits() > 5 && track.nster() > 1 &&
1710 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1711 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1712 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1713 track.Ea()[4][4] > 0 && iqual_front_[l_mass]) {
1714
1715 trk->setStat(0,0,l_mass);
1716 trk->setMass(track.mass(),l_mass);
1717 trk->setChisq(track.chiSq(),0,l_mass);
1718 trk->setNdf(track.nchits()-5,0,l_mass);
1719 trk->setNhits(track.nchits(),l_mass);
1720 //trkid
1721 trk->setTrackId(TrasanTRK.id);
1722
1723 if (debug_ == 4) cout<<" trasan id...1 "<<TrasanTRK.id<<endl;
1724
1725 trk->setFHelix(track.a(),l_mass);
1726 trk->setFError(track.Ea(),l_mass);
1727
1728 } else {
1729
1730 //cout<<"copy Mdc Helix in fillTds_lead()"<<endl;
1731
1732 if(debug_==4) cout<<"ALARM: FillTds_forMdc Not refit with KalFilter!!! lmass="<<l_mass<<endl;
1733 // NOT refit with Kalman filter :
1734 trk->setStat(1,0,l_mass);
1735 trk->setMass(KalFitTrack::mass(l_mass),l_mass);
1736
1737 // chisq & ndf
1738 trk->setChisq(TrasanTRK.chiSq,0,l_mass);
1739 //trk->setNdf(TrasanTRK.nhits-5,0,l_mass);
1740 trk->setNdf(TrasanTRK.ndf,0,l_mass);
1741 //trkid
1742 trk->setTrackId(TrasanTRK.id);
1743
1744 if (debug_ ==4) cout<<" trasan id...2 "<<TrasanTRK.id<<endl;
1745
1746 // nhits
1747 //trk->setNhits(TrasanTRK.nhits,l_mass);
1748 trk->setNhits(TrasanTRK.ndf+5,l_mass);
1749 double a_trasan[5], ea_trasan[15];
1750 for( int i =0 ; i <5; i++){
1751 a_trasan[i] = TrasanTRK.helix[i];
1752 }
1753 for( int j =0 ; j <15; j++){
1754 ea_trasan[j] = TrasanTRK.error[j];
1755 }
1756 trk->setFHelix(a_trasan,l_mass);
1757 trk->setFError(ea_trasan,l_mass);
1758 // trk->setFHelix(TrasanTRK.helix,l_mass);
1759 // trk->setFError(TrasanTRK.error,l_mass);
1760 }
1761}
1762
1763
1764
1765
1767 RecMdcKalTrack* trk, int l_mass)
1768{
1769 //cout<<"call fillTds_ip() done!"<<endl;
1770 HepPoint3D IP(0,0,0);
1771 track.pivot(IP);
1772
1773 if (debug_ == 4&& l_mass==lead_) {
1774 cout << "fillTds_IP>......"<<endl;
1775 cout << " dr = " << track.a()[0]
1776 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
1777 cout << " phi0 = " << track.a()[1]
1778 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
1779 cout << " PT = " << 1/track.a()[2]
1780 << ", Er_kappa =" << sqrt(track.Ea()[2][2]) << std::endl;
1781 cout << " dz = " << track.a()[3]
1782 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
1783 cout << " tanl = " << track.a()[4]
1784 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
1785 }
1786
1787
1788 //cout<<"start to get the event!"<<endl;
1789
1790
1791
1792
1793 //cout<<"get the event done!"<<endl;
1794
1795/*
1796 if(ntuple_&256){
1797
1798 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
1799 if(!eventHeader){
1800 cout<<"Open event header file failed!"<<endl;
1801 }
1802// cout<<__LINE__<<endl;
1803 int run = eventHeader->runNumber();
1804// cout<<__LINE__<<endl;
1805 //m_run_kal = eventHeader->runNumber();
1806 m_run_kal = run;
1807// cout<<__LINE__<<endl;
1808 m_event_kal = eventHeader->eventNumber();
1809// cout<<__LINE__<<endl;
1810
1811 if(l_mass==0){
1812// cout<<__LINE__<<endl;
1813 m_dropedHits_kal_e = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1814// cout<<__LINE__<<endl;
1815 m_kappa2_kal_e = TrasanTRK.helix[2]*track.a()[2];
1816// cout<<__LINE__<<endl;
1817 m_trackNhits_kal_e = track.nchits();
1818// cout<<__LINE__<<endl;
1819 m_trackNster_kal_e = track.nster();
1820// cout<<__LINE__<<endl;
1821 m_trackNaxis_kal_e = track.nchits()-track.nster();
1822// cout<<__LINE__<<endl;
1823 m_chi2_kal_e = track.chiSq();
1824// cout<<__LINE__<<endl;
1825 m_Ea00_kal_e = track.Ea()[0][0];
1826// cout<<__LINE__<<endl;
1827 m_Ea11_kal_e = track.Ea()[1][1];
1828// cout<<__LINE__<<endl;
1829 m_Ea22_kal_e = track.Ea()[2][2];
1830// cout<<__LINE__<<endl;
1831 m_Ea33_kal_e = track.Ea()[3][3];
1832// cout<<__LINE__<<endl;
1833 m_Ea44_kal_e = track.Ea()[4][4];
1834// cout<<__LINE__<<endl;
1835
1836 }
1837 else if(l_mass==1){
1838 m_dropedHits_kal_mu = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1839 m_kappa2_kal_mu = TrasanTRK.helix[2]*track.a()[2];
1840 m_trackNhits_kal_mu = track.nchits();
1841 m_trackNster_kal_mu = track.nster();
1842 m_trackNaxis_kal_mu = track.nchits()-track.nster();
1843 m_chi2_kal_mu = track.chiSq();
1844 m_Ea00_kal_mu = track.Ea()[0][0];
1845 m_Ea11_kal_mu = track.Ea()[1][1];
1846 m_Ea22_kal_mu = track.Ea()[2][2];
1847 m_Ea33_kal_mu = track.Ea()[3][3];
1848 m_Ea44_kal_mu = track.Ea()[4][4];
1849
1850
1851 }
1852 else if(l_mass==2){
1853 m_dropedHits_kal_pi = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1854 m_kappa2_kal_pi = TrasanTRK.helix[2]*track.a()[2];
1855 m_trackNhits_kal_pi = track.nchits();
1856 m_trackNster_kal_pi = track.nster();
1857 m_trackNaxis_kal_pi = track.nchits()-track.nster();
1858 m_chi2_kal_pi = track.chiSq();
1859 m_Ea00_kal_pi = track.Ea()[0][0];
1860 m_Ea11_kal_pi = track.Ea()[1][1];
1861 m_Ea22_kal_pi = track.Ea()[2][2];
1862 m_Ea33_kal_pi = track.Ea()[3][3];
1863 m_Ea44_kal_pi = track.Ea()[4][4];
1864
1865 }
1866 else if(l_mass==3){
1867 m_dropedHits_kal_k = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1868 m_kappa2_kal_k = TrasanTRK.helix[2]*track.a()[2];
1869 m_trackNhits_kal_k = track.nchits();
1870 m_trackNster_kal_k = track.nster();
1871 m_trackNaxis_kal_k = track.nchits()-track.nster();
1872 m_chi2_kal_k = track.chiSq();
1873 m_Ea00_kal_k = track.Ea()[0][0];
1874 m_Ea11_kal_k = track.Ea()[1][1];
1875 m_Ea22_kal_k = track.Ea()[2][2];
1876 m_Ea33_kal_k = track.Ea()[3][3];
1877 m_Ea44_kal_k = track.Ea()[4][4];
1878
1879 }
1880 else if(l_mass==4){
1881 m_dropedHits_kal_p = TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits();
1882 m_kappa2_kal_p = TrasanTRK.helix[2]*track.a()[2];
1883 m_trackNhits_kal_p = track.nchits();
1884 m_trackNster_kal_p = track.nster();
1885 m_trackNaxis_kal_p = track.nchits()-track.nster();
1886 m_chi2_kal_p = track.chiSq();
1887 m_Ea00_kal_p = track.Ea()[0][0];
1888 m_Ea11_kal_p = track.Ea()[1][1];
1889 m_Ea22_kal_p = track.Ea()[2][2];
1890 m_Ea33_kal_p = track.Ea()[3][3];
1891 m_Ea44_kal_p = track.Ea()[4][4];
1892
1893 }
1894
1895
1896
1897 //cout<<"fill the ntuple done!"<<endl;
1898
1899 //StatusCode sc7 = m_nt7 ->write();
1900
1901 //if(sc7.isFailure()) cout<<" Write Kalfit failure ntuple failed !"<<endl;
1902
1903 //cout<<"save the ntuple done!"<<endl;
1904 }
1905*/
1906
1907
1908 //if (TrasanTRK.nhits+TrasanTRK.nclus*2-track.nchits()>fitnocut_ ||
1909 if (TrasanTRK.ndf+5-track.nchits()>fitnocut_ ||
1910 TrasanTRK.helix[2]*track.a()[2]<0)
1911 iqual_front_[l_mass] = 0;
1912
1913
1914 if (track.nchits() > 5 && track.nster() > 1 &&
1915 track.nchits()-track.nster() > 2 && track.chiSq() > 0 &&
1916 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
1917 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
1918 track.Ea()[4][4] > 0 && iqual_front_[l_mass]) {
1919
1920 // fill track information
1921 double dr = track.a()[0];
1922 double phi0 = track.a()[1];
1923 double kappa = track.a()[2];
1924 double dz = track.a()[3];
1925 double tanl = track.a()[4];
1926
1927 // vertex of the track
1928 double vx = dr*cos(phi0);
1929 double vy = dr*sin(phi0);
1930 double vz = dz;
1931
1932 // see Belle note148 for the formulas
1933 // initial momentum of the track
1934 if(0==kappa) kappa = 10e-10;
1935 double px = -sin(phi0)/fabs(kappa);
1936 double py = cos(phi0)/fabs(kappa);
1937 double pz = tanl/fabs(kappa);
1938
1939 trk->setX(vx, l_mass);
1940 trk->setY(vy, l_mass);
1941 trk->setZ(vz, l_mass);
1942 trk->setPx(px, l_mass);
1943 trk->setPy(py, l_mass);
1944 trk->setPz(pz, l_mass);
1945
1946 const HepPoint3D poca(dr*cos(phi0),dr*sin(phi0),dz);
1947 trk->setPoca(poca,l_mass);
1948
1949 trk->setZHelix(track.a(),l_mass);
1950 trk->setZError(track.Ea(),l_mass);
1951
1952
1953 //set charge
1954 int charge=0;
1955 if (kappa > 0.0000000001)
1956 charge = 1;
1957 else if (kappa < -0.0000000001)
1958 charge = -1;
1959 trk->setCharge(charge,l_mass);
1960
1961 //set theta
1962 double ptot = sqrt(px*px+py*py+pz*pz);
1963 trk->setTheta(acos(pz/ptot),l_mass);
1964 }
1965
1966 else{
1967 //cout<<"copy Mdc Helix in fillTds_ip()"<<endl;
1968
1969 if(4==debug_) cout<<"track "<< track.trasan_id() <<", pid "<< l_mass <<" fails"<<endl;
1970
1971 // fill track information
1972 double dr = TrasanTRK.helix[0];
1973 double phi0 = TrasanTRK.helix[1];
1974 double kappa = TrasanTRK.helix[2];
1975 double dz = TrasanTRK.helix[3];
1976 double tanl = TrasanTRK.helix[4];
1977
1978 double vx = dr*cos(phi0);
1979 double vy = dr*sin(phi0);
1980 double vz = dz;
1981
1982 if(0==kappa) kappa = 10e-10;
1983 double px = -sin(phi0)/fabs(kappa);
1984 double py = cos(phi0)/fabs(kappa);
1985 double pz = tanl/fabs(kappa);
1986
1987 trk->setX(vx, l_mass);
1988 trk->setY(vy, l_mass);
1989 trk->setZ(vz, l_mass);
1990
1991 trk->setPx(px, l_mass);
1992 trk->setPy(py, l_mass);
1993 trk->setPz(pz, l_mass);
1994
1995 const HepPoint3D poca(dr*cos(phi0),dr*sin(phi0),dz);
1996
1997 trk->setPoca(poca,l_mass);
1998 //trk->setZHelix(TrasanTRK.helix,l_mass);
1999 //trk->setZError(TrasanTRK.error,l_mass);
2000 double a_trasan[5], ea_trasan[15];
2001 for( int i =0 ; i <5; i++){
2002 a_trasan[i] = TrasanTRK.helix[i];
2003 }
2004 for( int j =0 ; j <15; j++){
2005 ea_trasan[j] = TrasanTRK.error[j];
2006 }
2007 trk->setZHelix(a_trasan,l_mass);
2008 trk->setZError(ea_trasan,l_mass);
2009
2010 //set charge
2011 int charge=0;
2012 if (kappa > 0.0000000001)
2013 charge = 1;
2014 else if (kappa < -0.0000000001)
2015 charge = -1;
2016 trk->setCharge(charge,l_mass);
2017
2018 //set theta
2019 double ptot = sqrt(px*px+py*py+pz*pz);
2020 trk->setTheta(acos(pz/ptot),l_mass);
2021 }
2022
2023 if(4==debug_) {
2025 std::cout<<"px: "<<trk->px()<<" py: "<<trk->py()<<" pz: "<<trk->pz()<<std::endl;
2026 std::cout<<"vx: "<<trk->x()<<" vy: "<<trk->y()<<" vz: "<<trk->z()<<std::endl;
2027 }
2028}
2029
2030
2032 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass)
2033{
2034
2035 HepPoint3D IP(0,0,0);
2036 //track.pivot(IP);
2037
2038 // Fit quality
2039 int iqual(1);
2040
2041 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5) iqual = 0;
2042
2043 if(debug_ == 4) cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0] "<<trk->getNdf(0,2)<<endl;
2044 if(debug_ == 4) cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2045
2046 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2047 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2048 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2049 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2050 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2051 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX &&
2052 iqual) {
2053
2054 // chisq ( for backward filter)
2055
2056 trk->setStat(0,1,l_mass);
2057 trk->setChisq(track.chiSq_back(),1,l_mass);
2058 trk->setNdf(track.ndf_back()-5,1,l_mass);
2059 trk->setLength(track.pathip(),l_mass);
2060 if(debug_ == 4) cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2061 trk->setTof(track.tof(),l_mass);
2062
2064 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2065 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2066 }
2067
2068 // Path length in each MDC layer :
2069 if (pathl_)
2070 for (int i = 0; i<43; i++) {
2071 trk->setPathl(track.pathl()[i],i);
2072 }
2073
2074 trk->setLHelix(track.a(),l_mass);
2075 trk->setLError(track.Ea(),l_mass);
2076 trk->setLPivot(track.pivot(),l_mass);
2077
2078 trk->setLPoint(track.point_last(),l_mass);
2079 trk->setPathSM(track.getPathSM(),l_mass);
2080 trk->setTof(track.getTofSM(),l_mass);
2081 trk->setFiTerm(track.getFiTerm(),l_mass);
2082
2083 if(4 == debug_){
2084 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2085 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2086 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2087 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2088 }
2089
2090 } else {
2091 if(debug_==4) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2092 // NOT refit with Kalman filter :
2093 trk->setStat(1,1,l_mass);
2094 HepPoint3D piv(TrasanTRK.pivot[0],
2095 TrasanTRK.pivot[1],
2096 TrasanTRK.pivot[2]);
2097
2098 HepVector a(5);
2099 for(int i = 0; i < 5; i++)
2100 a[i] = TrasanTRK.helix[i];
2101
2102 HepSymMatrix ea(5);
2103 for(int i = 0, k = 0; i < 5; i++) {
2104 for(int j = 0; j <= i; j++) {
2105 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2106 ea[j][i] = ea[i][j];
2107 }
2108 }
2109
2110 KalFitTrack track_rep(piv, a, ea, lead_,
2111 TrasanTRK.chiSq, TrasanTRK.nhits);
2112 double fiTerm = TrasanTRK.fiTerm;
2113
2114 double fi0 = track_rep.phi0();
2115 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2116 track_rep.center() );
2117 double x = xc.x();
2118 double y = xc.y();
2119 double phi_x;
2120 if( fabs( x ) > 1.0e-10 ){
2121 phi_x = atan2( y, x );
2122 if( phi_x < 0 ) phi_x += 2*M_PI;
2123 } else {
2124 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2125 }
2126 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2127 double dphi = fabs( fiTerm + fi0 - phi_x );
2128 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2129 double tanl = track_rep.tanl();
2130 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2131 if(debug_ == 4) {
2132 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2133 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2134 }
2135 double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2136 double light_speed( 29.9792458 ); // light speed in cm/nsec
2137 double pt( 1.0 / track_rep.kappa() );
2138 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2139
2140 // chisq (2 : for backward filter)
2141 trk->setStat(1,1,l_mass);
2142 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2143 if(debug_ == 4) {
2144 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<endl;
2145 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<endl;
2146 }
2147 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2148 trk->setLength(track_len,l_mass);
2149 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2150 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2151 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2152
2153 track_rep.pivot(IP);
2154
2155 trk->setLHelix(track_rep.a(),l_mass);
2156 trk->setLError(track_rep.Ea(),l_mass);
2157 trk->setLPivot(track.pivot(),l_mass);
2158
2159 /// right???
2160 trk->setLPoint(track.point_last(),l_mass);
2161 trk->setPathSM(track.getPathSM(),l_mass);
2162 trk->setTof(track.getTofSM(),l_mass);
2163 trk->setFiTerm(track.getFiTerm(),l_mass);
2164 }
2165
2166 // test--------
2167 if(debug_ == 4) {
2168
2169 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2170 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2171 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2172
2173 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2174 cout << " dr = " << track.a()[0]
2175 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2176 cout<< " phi0 = " << track.a()[1]
2177 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2178 cout << " PT = " << 1/track.a()[2]
2179 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2180 cout << " dz = " << track.a()[3]
2181 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2182 cout << " tanl = " << track.a()[4]
2183 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2184 cout << " Ea = " << track.Ea() <<endl;
2185 }
2186 // test end ----------
2187}
2188
2190 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass,
2191 RecMdcKalHelixSegCol* segcol)
2192{
2193
2194 HepPoint3D IP(0,0,0);
2195
2196 // attention the pivot problem of the HelixSeg ... ???
2197 track.pivot(IP);
2198 // Fit quality
2199 //int iqual(1);
2200 //if ((trk->getNdf(0,2))-(track.ndf_back()-5)>5)
2201 // form getNdf(0,2) to getNdf(0,1) for muon hypothesis
2202
2203 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5){
2204 iqual_back_ = 0;
2205 }
2206 if(usage_>1){
2207 for(int i=0; i<5; i++) iqual_front_[i] = 1;
2208 iqual_back_ = 1;
2209 }
2210 if(debug_ == 4){
2211 std::cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0][l_mass] "<<trk->getNdf(0,l_mass)<<endl;
2212 std::cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2213 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;
2214 }
2215
2216 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2217 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2218 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2219 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2220 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2221 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX && iqual_front_[l_mass] && iqual_back_){
2222
2223 // chisq ( for backward filter)
2224 //std::cout<<"begin to fillTds_back track no. : "<<(++Tds_back_no)<<std::endl;
2225
2226
2227 HelixSegRefVec helixsegrefvec;
2228 for (vector<KalFitHelixSeg>::iterator it = track.HelixSegs().begin(); it!=track.HelixSegs().end();it ++)
2229 {
2230
2231 //std::cout<<" alpha of KalFitHelixSeg: "<<it->alpha()<<std::endl;
2232 //std::cout<<" doca1 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2233
2234 it->pivot(IP);
2235
2236 //std::cout<<" doca2 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2237
2238 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2239 helixseg->setResIncl(it->residual_include());
2240 helixseg->setResExcl(it->residual_exclude());
2241 if(debug_ == 4) {
2242 std::cout<<"helixseg->Res_inc ..."<<helixseg->getResIncl()<<std::endl;
2243 }
2244 helixseg->setDrIncl(it->a_include()[0]);
2245 helixseg->setFi0Incl(it->a_include()[1]);
2246 helixseg->setCpaIncl(it->a_include()[2]);
2247 helixseg->setDzIncl(it->a_include()[3]);
2248 helixseg->setTanlIncl(it->a_include()[4]);
2249
2250
2251 helixseg->setDrExcl(it->a_exclude()[0]);
2252 helixseg->setFi0Excl(it->a_exclude()[1]);
2253 helixseg->setCpaExcl(it->a_exclude()[2]);
2254 helixseg->setDzExcl(it->a_exclude()[3]);
2255 helixseg->setTanlExcl(it->a_exclude()[4]);
2256
2257 helixseg->setHelixIncl(it->a_include());
2258 helixseg->setErrorIncl(it->Ea_include());
2259
2260 //Helix temp(IP, it->a(), it->Ea());
2261
2262 //std::cout<<" doca3 of KalFitHelixSeg: "<<(temp.approach(*(it->HitMdc()),false))<<std::endl;
2263
2264 helixseg->setHelixExcl(it->a_exclude());
2265 helixseg->setErrorExcl(it->Ea_exclude());
2266 helixseg->setLayerId(it->layer());
2267
2268 if(debug_ == 4) {
2269 std::cout<<"KalFitHelixSeg track id .."<<it->HitMdc()->rechitptr()->getTrkId()<<std::endl;
2270 std::cout<<"helixseg a: "<<it->a()<<std::endl;
2271 std::cout<<"helixseg a_excl: "<<helixseg->getHelixExcl()<<std::endl;
2272 std::cout<<"helixseg a_incl: "<<helixseg->getHelixIncl()<<std::endl;
2273
2274 std::cout<<"helixseg Ea: "<<it->Ea()<<std::endl;
2275 std::cout<<"helixseg Ea_excl: "<<helixseg->getErrorExcl()<<std::endl;
2276 std::cout<<"helixseg Ea_incl: "<<helixseg->getErrorIncl()<<std::endl;
2277
2278 std::cout<<"helixseg layer: "<<it->layer()<<std::endl;
2279 }
2280
2281
2282 helixseg->setTrackId(it->HitMdc()->rechitptr()->getTrkId());
2283 helixseg->setMdcId(it->HitMdc()->rechitptr()->getMdcId());
2284 helixseg->setFlagLR(it->HitMdc()->LR());
2285 helixseg->setTdc(it->HitMdc()->rechitptr()->getTdc());
2286 helixseg->setAdc(it->HitMdc()->rechitptr()->getAdc());
2287 helixseg->setZhit(it->HitMdc()->rechitptr()->getZhit());
2288 helixseg->setTof(it->tof());
2289 helixseg->setDocaIncl(it->doca_include());
2290 helixseg->setDocaExcl(it->doca_exclude());
2291 helixseg->setDD(it->dd());
2292 helixseg->setEntra(it->HitMdc()->rechitptr()->getEntra());
2293 helixseg->setDT(it->dt());
2294 segcol->push_back(helixseg);
2295 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2296 helixsegrefvec.push_back(refhelixseg);
2297
2298 if(ntuple_&8){
2299 m_docaInc = helixseg -> getDocaIncl();
2300 m_docaExc = helixseg -> getDocaExcl();
2301 m_residualInc = helixseg -> getResIncl();
2302 m_residualExc = helixseg -> getResExcl();
2303 m_dd = helixseg -> getDD();
2304 m_lr = helixseg->getFlagLR();
2305 m_tdrift = helixseg -> getDT();
2306 m_layerid = helixseg -> getLayerId();
2307 m_yposition= it->HitMdc()->wire().fwd().y();
2308 m_eventNo = myEventNo;
2309 StatusCode sc6 = m_nt6->write();
2310 if( sc6.isFailure() ) cout<<"Ntuple6 helixseg filling failed!"<<endl;
2311
2312 }
2313 }
2314
2315 trk->setVecHelixSegs(helixsegrefvec, l_mass);
2316 if(debug_ == 4) {
2317 std::cout<<"trk->getVecHelixSegs size..."<<(trk->getVecHelixSegs()).size()<<std::endl;
2318 }
2319 trk->setStat(0,1,l_mass);
2320 trk->setChisq(track.chiSq_back(),1,l_mass);
2321 trk->setNdf(track.ndf_back()-5,1,l_mass);
2322 // add setNhits ,maybe some problem
2323 trk->setNhits(track.ndf_back(),l_mass);
2324 if(!(track.ndf_back()==track.HelixSegs().size())) {
2325 std::cout<<"THEY ARE NOT EQUALL!!!"<<std::endl;
2326 }
2327 trk->setLength(track.pathip(),l_mass);
2328 if(debug_ == 4) {
2329 std::cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2330 }
2331 trk->setTof(track.tof(),l_mass);
2333 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2334 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2335 }
2336 // Path length in each MDC layer :
2337 if (pathl_)
2338 for (int i = 0; i<43; i++) {
2339 trk->setPathl(track.pathl()[i],i);
2340 }
2341 trk->setLHelix(track.a(),l_mass);
2342 trk->setLError(track.Ea(),l_mass);
2343 trk->setLPivot(track.pivot(),l_mass);
2344
2345 trk->setLPoint(track.point_last(),l_mass);
2346 trk->setPathSM(track.getPathSM(),l_mass);
2347 trk->setTof(track.getTofSM(),l_mass);
2348 trk->setFiTerm(track.getFiTerm(),l_mass);
2349 double a_trasan[5], ea_trasan[15];
2350 for( int i =0 ; i <5; i++){
2351 a_trasan[i] = TrasanTRK.helix[i];
2352 }
2353 for( int j =0 ; j <15; j++){
2354 ea_trasan[j] = TrasanTRK.helix[j];
2355 }
2356 trk->setTHelix(a_trasan);
2357 trk->setTError(ea_trasan);
2358
2359 if(4 == debug_){
2360 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2361 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2362 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2363 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2364 }
2365
2366 } else {
2367
2368 if(debug_==4) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2369 // NOT refit with Kalman filter :
2370 trk->setStat(1,1,l_mass);
2371
2372 HepPoint3D piv(TrasanTRK.pivot[0],
2373 TrasanTRK.pivot[1],
2374 TrasanTRK.pivot[2]);
2375
2376 HepVector a(5);
2377 for(int i = 0; i < 5; i++)
2378 a[i] = TrasanTRK.helix[i];
2379
2380 HepSymMatrix ea(5);
2381 for(int i = 0, k = 0; i < 5; i++) {
2382 for(int j = 0; j <= i; j++) {
2383 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2384 ea[j][i] = ea[i][j];
2385 }
2386 }
2387
2388 KalFitTrack track_rep(piv, a, ea, lead_,
2389 TrasanTRK.chiSq, TrasanTRK.nhits);
2390 double fiTerm = TrasanTRK.fiTerm;
2391
2392 double fi0 = track_rep.phi0();
2393 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2394 track_rep.center() );
2395 double x = xc.x();
2396 double y = xc.y();
2397 double phi_x;
2398 if( fabs( x ) > 1.0e-10 ){
2399 phi_x = atan2( y, x );
2400 if( phi_x < 0 ) phi_x += 2*M_PI;
2401 } else {
2402 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2403 }
2404 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2405 double dphi = fabs( fiTerm + fi0 - phi_x );
2406 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2407 double tanl = track_rep.tanl();
2408 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2409 if(debug_ == 4) {
2410 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2411 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2412 }
2413 double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2414 double light_speed( 29.9792458 ); // light speed in cm/nsec
2415 double pt( 1.0 / track_rep.kappa() );
2416 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2417
2418
2419 // chisq (2 : for backward filter)
2420
2421 trk->setStat(1,1,l_mass);
2422 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2423 if(debug_ == 4) {
2424 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<std::endl;
2425 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<std::endl;
2426 }
2427 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2428 trk->setLength(track_len,l_mass);
2429 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2430 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2431 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2432
2433 track_rep.pivot(IP);
2434
2435 trk->setLHelix(track_rep.a(),l_mass);
2436 trk->setLError(track_rep.Ea(),l_mass);
2437 trk->setLPivot(track.pivot(),l_mass);
2438
2439 /// right???
2440 trk->setLPoint(track.point_last(),l_mass);
2441 trk->setPathSM(track.getPathSM(),l_mass);
2442 trk->setTof(track.getTofSM(),l_mass);
2443 trk->setFiTerm(track.getFiTerm(),l_mass);
2444 trk->setTHelix(track_rep.a());
2445 trk->setTError(track_rep.Ea());
2446
2447 }
2448
2449 // test--------
2450 if(debug_ == 4) {
2451 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2452 cout << " dr = " << track.a()[0]
2453 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2454 cout<< " phi0 = " << track.a()[1]
2455 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2456 cout << " PT = " << 1/track.a()[2]
2457 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2458 cout << " dz = " << track.a()[3]
2459 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2460 cout << " tanl = " << track.a()[4]
2461 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2462 cout << " Ea = " << track.Ea() <<endl;
2463 }
2464 // test end ----------
2465}
2466
2468 RecMdcKalTrack* trk, MdcRec_trk& TrasanTRK, int l_mass,
2469 RecMdcKalHelixSegCol* segcol, int smoothflag)
2470{
2471
2472 HepPoint3D IP(0,0,0);
2473
2474 // attention the pivot problem of the HelixSeg ... ???
2475 //track.pivot(IP);
2476 // Fit quality
2477 //int iqual(1);
2478 //if ((trk->getNdf(0,2))-(track.ndf_back()-5)>5)
2479 // form getNdf(0,2) to getNdf(0,1) for muon hypothesis
2480
2481 iqual_back_ = 1;
2482 if ((trk->getNdf(0,l_mass))-(track.ndf_back()-5)>5){
2483 iqual_back_ = 0;
2484 }
2485
2486 if(debug_ == 4){
2487 std::cout<< "fillTds_back> mass "<<trk->getMass(2)<<" ndf[0][l_mass] "<<trk->getNdf(0,l_mass)<<endl;
2488 std::cout<<"ndf_back "<< track.ndf_back() << " chi2_back " << track.chiSq_back()<<endl;
2489 }
2490
2491
2492 if (track.ndf_back() > 5 && track.chiSq_back() > 0 &&
2493 track.Ea()[0][0] > 0 && track.Ea()[1][1] > 0 &&
2494 track.Ea()[2][2] > 0 && track.Ea()[3][3] > 0 &&
2495 track.Ea()[4][4] > 0 && fabs(track.a()[0]) < DBL_MAX &&
2496 fabs(track.a()[1]) < DBL_MAX && fabs(track.a()[2]) < DBL_MAX &&
2497 fabs(track.a()[3]) < DBL_MAX && fabs(track.a()[4]) < DBL_MAX && iqual_front_[l_mass] && iqual_back_){
2498
2499 // chisq ( for backward filter)
2500 //std::cout<<"begin to fillTds_back track no. : "<<(++Tds_back_no)<<std::endl;
2501
2502
2503 HelixSegRefVec helixsegrefvec;
2504 for (vector<KalFitHelixSeg>::iterator it = track.HelixSegs().begin(); it!=track.HelixSegs().end();it ++)
2505 {
2506
2507 //std::cout<<" alpha of KalFitHelixSeg: "<<it->alpha()<<std::endl;
2508 //std::cout<<" doca1 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2509
2510 it->pivot(IP);
2511
2512 //std::cout<<" doca2 of KalFitHelixSeg: "<<(it->approach(*(it->HitMdc()),false))<<std::endl;
2513
2514 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2515 helixseg->setResIncl(it->residual_include());
2516 helixseg->setResExcl(it->residual_exclude());
2517 if(debug_ == 4) {
2518 std::cout<<"helixseg->Res_inc ..."<<helixseg->getResIncl()<<std::endl;
2519 }
2520 // helixseg->setDrIncl(it->a_include()[0]);
2521 // helixseg->setFi0Incl(it->a_include()[1]);
2522 // helixseg->setCpaIncl(it->a_include()[2]);
2523 // helixseg->setDzIncl(it->a_include()[3]);
2524 // helixseg->setTanlIncl(it->a_include()[4]);
2525 //
2526 //
2527 // helixseg->setDrExcl(it->a_exclude()[0]);
2528 // helixseg->setFi0Excl(it->a_exclude()[1]);
2529 // helixseg->setCpaExcl(it->a_exclude()[2]);
2530 // helixseg->setDzExcl(it->a_exclude()[3]);
2531 // helixseg->setTanlExcl(it->a_exclude()[4]);
2532
2533 helixseg->setHelixIncl(it->a_include());
2534 //helixseg->setErrorIncl(it->Ea_include());
2535
2536 //Helix temp(IP, it->a(), it->Ea());
2537
2538 //std::cout<<" doca3 of KalFitHelixSeg: "<<(temp.approach(*(it->HitMdc()),false))<<std::endl;
2539
2540 helixseg->setHelixExcl(it->a_exclude());
2541 //helixseg->setErrorExcl(it->Ea_exclude());
2542 //helixseg->setLayerId(it->layer());
2543
2544 if(debug_ == 4) {
2545 std::cout<<"KalFitHelixSeg track id .."<<it->HitMdc()->rechitptr()->getTrkId()<<std::endl;
2546 std::cout<<"helixseg a: "<<it->a()<<std::endl;
2547 std::cout<<"helixseg a_excl: "<<helixseg->getHelixExcl()<<std::endl;
2548 std::cout<<"helixseg a_incl: "<<helixseg->getHelixIncl()<<std::endl;
2549
2550 std::cout<<"helixseg Ea: "<<it->Ea()<<std::endl;
2551 std::cout<<"helixseg Ea_excl: "<<helixseg->getErrorExcl()<<std::endl;
2552 std::cout<<"helixseg Ea_incl: "<<helixseg->getErrorIncl()<<std::endl;
2553
2554 std::cout<<"helixseg layer: "<<it->layer()<<std::endl;
2555 }
2556
2557
2558 helixseg->setTrackId(it->HitMdc()->rechitptr()->getTrkId());
2559 helixseg->setMdcId(it->HitMdc()->rechitptr()->getMdcId());
2560 helixseg->setFlagLR(it->HitMdc()->LR());
2561 helixseg->setTdc(it->HitMdc()->rechitptr()->getTdc());
2562 helixseg->setAdc(it->HitMdc()->rechitptr()->getAdc());
2563 helixseg->setZhit(it->HitMdc()->rechitptr()->getZhit());
2564 helixseg->setTof(it->tof());
2565 helixseg->setDocaIncl(it->doca_include());
2566 helixseg->setDocaExcl(it->doca_exclude());
2567 helixseg->setDD(it->dd());
2568 helixseg->setEntra(it->HitMdc()->rechitptr()->getEntra());
2569 helixseg->setDT(it->dt());
2570 //cout<<"setDT( "<<it->dt()<<" )"<<endl;
2571 segcol->push_back(helixseg);
2572 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2573 helixsegrefvec.push_back(refhelixseg);
2574 if(ntuple_&8){
2575 m_docaInc = helixseg -> getDocaIncl();
2576 m_docaExc = helixseg -> getDocaExcl();
2577 m_residualInc = helixseg -> getResIncl();
2578 m_residualExc = helixseg -> getResExcl();
2579 m_dd = helixseg -> getDD();
2580 m_lr = helixseg->getFlagLR();
2581 m_tdrift = helixseg -> getDT();
2582 m_layerid = helixseg -> getLayerId();
2583 m_yposition= it->HitMdc()->wire().fwd().y();
2584 m_eventNo = myEventNo;
2585 StatusCode sc6 = m_nt6->write();
2586 if( sc6.isFailure() ) cout<<"Ntuple6 helixseg filling failed!"<<endl;
2587
2588 }
2589 }
2590
2591 trk->setVecHelixSegs(helixsegrefvec, l_mass);
2592 //cout<<"setVecHelixSegs with Kalman hits"<<endl;
2593 if(debug_ == 4) {
2594 std::cout<<"trk->getVecHelixSegs size..."<<(trk->getVecHelixSegs()).size()<<std::endl;
2595 }
2596 trk->setStat(0,1,l_mass);
2597 trk->setChisq(track.chiSq_back(),1,l_mass);
2598 trk->setNdf(track.ndf_back()-5,1,l_mass);
2599 // add setNhits ,maybe some problem
2600 trk->setNhits(track.ndf_back(),l_mass);
2601 if(!(track.ndf_back()==track.HelixSegs().size())) {
2602 std::cout<<"THEY ARE NOT EQUALL!!!"<<std::endl;
2603 }
2604 trk->setLength(track.pathip(),l_mass);
2605 if(debug_ == 4) {
2606 std::cout<<"l_mass "<<l_mass<<" path set as "<<track.pathip()<<endl;
2607 }
2608 trk->setTof(track.tof(),l_mass);
2610 if(l_mass == 3) trk->setTof(track.tof_kaon(),l_mass);
2611 if(l_mass == 4) trk->setTof(track.tof_proton(),l_mass);
2612 }
2613 // Path length in each MDC layer :
2614 if (pathl_)
2615 for (int i = 0; i<43; i++) {
2616 trk->setPathl(track.pathl()[i],i);
2617 }
2618 trk->setLHelix(track.a(),l_mass);
2619 trk->setLError(track.Ea(),l_mass);
2620 trk->setLPivot(track.pivot(),l_mass);
2621
2622 trk->setLPoint(track.point_last(),l_mass);
2623 trk->setPathSM(track.getPathSM(),l_mass);
2624 trk->setTof(track.getTofSM(),l_mass);
2625 trk->setFiTerm(track.getFiTerm(),l_mass);
2626 double a_trasan[5], ea_trasan[15];
2627 for( int i =0 ; i <5; i++){
2628 a_trasan[i] = TrasanTRK.helix[i];
2629 }
2630 for( int j =0 ; j <15; j++){
2631 ea_trasan[j] = TrasanTRK.helix[j];
2632 }
2633 trk->setTHelix(a_trasan);
2634 trk->setTError(ea_trasan);
2635
2636 if(4 == debug_){
2637 std::cout<<" last pivot: "<< trk->getLPivot(0)<<std::endl;
2638 std::cout<<" pathl in SM: "<< trk->getPathSM(0)<<std::endl;
2639 std::cout<<" fiTerm: "<< trk->getFiTerm(0)<<std::endl;
2640 std::cout<<" last point: "<< trk->getLPoint(0)<<std::endl;
2641 }
2642
2643 } else {
2644
2645 if(debug_==4) cout<<"ALARM: FillTds_back Not refit with KalFilter!!!"<<endl;
2646 // NOT refit with Kalman filter :
2647 trk->setStat(1,1,l_mass);
2648
2649 HepPoint3D piv(TrasanTRK.pivot[0],
2650 TrasanTRK.pivot[1],
2651 TrasanTRK.pivot[2]);
2652
2653 HepVector a(5);
2654 for(int i = 0; i < 5; i++)
2655 a[i] = TrasanTRK.helix[i];
2656
2657 HepSymMatrix ea(5);
2658 for(int i = 0, k = 0; i < 5; i++) {
2659 for(int j = 0; j <= i; j++) {
2660 ea[i][j] = matrixg_*TrasanTRK.error[k++];
2661 ea[j][i] = ea[i][j];
2662 }
2663 }
2664
2665 KalFitTrack track_rep(piv, a, ea, lead_,
2666 TrasanTRK.chiSq, TrasanTRK.nhits);
2667 double fiTerm = TrasanTRK.fiTerm;
2668
2669 double fi0 = track_rep.phi0();
2670 HepPoint3D xc(track_rep.kappa()/fabs(track_rep.kappa())*
2671 track_rep.center() );
2672 double x = xc.x();
2673 double y = xc.y();
2674 double phi_x;
2675 if( fabs( x ) > 1.0e-10 ){
2676 phi_x = atan2( y, x );
2677 if( phi_x < 0 ) phi_x += 2*M_PI;
2678 } else {
2679 phi_x = ( y > 0 ) ? M_PI_4: 3.0*M_PI_4;
2680 }
2681 if(debug_ == 4) cout<<"fiterm "<<fiTerm<<" fi0 "<<fi0<<" phi_x "<<phi_x<<endl;
2682 double dphi = fabs( fiTerm + fi0 - phi_x );
2683 if( dphi >= 2*M_PI ) dphi -= 2*M_PI;
2684 double tanl = track_rep.tanl();
2685 double cosl_inv = sqrt( tanl*tanl + 1.0 );
2686 if(debug_ == 4) {
2687 cout<<"tanl= "<<tanl<<" radius "<<track_rep.radius()<<" dphi "<<dphi<<endl;
2688 cout<<" cosl_inv "<<cosl_inv<<" radius_numf "<<track_rep.radius_numf()<<endl;
2689 }
2690 //double track_len(fabs( track_rep.radius() * dphi * cosl_inv ));
2691 double track_len(fabs( track_rep.radius() * fiTerm * cosl_inv )); // 2010-11-26 added by wangll
2692 //cout<<"track radius : "<<track_rep.radius()<<" "<<track.radius()<<endl;
2693 double light_speed( 29.9792458 ); // light speed in cm/nsec
2694 double pt( 1.0 / track_rep.kappa() );
2695 double p( pt * sqrt( 1.0 + tanl*tanl ) );
2696
2697
2698 // chisq (2 : for backward filter)
2699
2700 trk->setStat(1,1,l_mass);
2701 trk->setChisq(TrasanTRK.chiSq,1,l_mass);
2702 if(debug_ == 4) {
2703 std::cout<<".....fillTds_back...chiSq..."<< TrasanTRK.chiSq<<std::endl;
2704 std::cout<<"...track_len..."<<track_len<<" ndf[1] "<< trk->getNdf(0,l_mass)<<std::endl;
2705 }
2706 trk->setNdf(TrasanTRK.nhits-5,1,l_mass);
2707 trk->setLength(track_len,l_mass);
2708 double mass_over_p( KalFitTrack::mass(l_mass)/ p );
2709 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2710 trk->setTof(track_len / ( light_speed * beta ), l_mass) ;
2711
2712 //track_rep.pivot(IP);
2713 HepPoint3D LPiovt = track_rep.x(fiTerm);
2714 track_rep.pivot(LPiovt);
2715
2716 trk->setLHelix(track_rep.a(),l_mass);
2717 trk->setLError(track_rep.Ea(),l_mass);
2718 //trk->setLPivot(track.pivot(),l_mass); // commented 2010-09-02
2719 //trk->setLPivot(IP, l_mass); // add 2010-09-02
2720 trk->setLPivot(LPiovt, l_mass); // add 2010-11-25
2721
2722 /// right???
2723 trk->setLPoint(track.point_last(),l_mass);
2724 //trk->setPathSM(track.getPathSM(),l_mass);// commented 2010-11-25 by wangll
2725 trk->setPathSM(track_len,l_mass);// added 2010-11-25 by wangll
2726 //trk->setTof(track.getTofSM(),l_mass);// commented 2010-11-25 by wangll
2727 // trk->setFiTerm(track.getFiTerm(),l_mass); // commented 2010-11-25 by wangll
2728 trk->setFiTerm(fiTerm,l_mass); // added by wangll 2010-11-25
2729 trk->setTHelix(track_rep.a());
2730 trk->setTError(track_rep.Ea());
2731
2732 /*
2733 // --- check track id by wangll 2010-08-15
2734 if(l_mass==lead_) {
2735 //cout<<" ----- bad smooth track -----"<<endl;
2736 //cout<<"l_mass = "<<l_mass<<endl;
2737 int trkId = trk->trackId();
2738 //
2739 // cout<<"track id = "<<trkId<<endl;
2740 // cout<<"THelix: "<<trk->getTHelix()<<endl;
2741 // cout<<"FHelix: "<<trk->getFHelix()<<endl;
2742 // cout<<"size of VecHelixSegs: "<<trk->getVecHelixSegs().size()<<endl;
2743 //
2744 SmartDataPtr<RecMdcTrackCol> mdcTrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
2745 //int nMdcTrk = mdcTrkCol.size();
2746 //cout<<"number of Mdc Tracks: "<<nMdcTrk<<endl;
2747 RecMdcTrackCol::iterator iter_mdcTrk = mdcTrkCol->begin();
2748 bool findMdcTrk = false;
2749 for(; iter_mdcTrk != mdcTrkCol->end(); iter_mdcTrk++) {
2750 if(trkId==(*iter_mdcTrk)->trackId()) {
2751 findMdcTrk = true;
2752 break;
2753 }
2754 }
2755 if(findMdcTrk) {
2756 HitRefVec mdcVecHits = (*iter_mdcTrk)->getVecHits();
2757 int nHits = mdcVecHits.size();
2758 //cout<<"number of Mdc Hits: "<<nHits<<endl;
2759 HelixSegRefVec helixsegrefvec;
2760 HitRefVec::iterator iter_mdcHit = mdcVecHits.begin();
2761 for(int iii=0; iter_mdcHit!=mdcVecHits.end(); iter_mdcHit++,iii++) {
2762 RecMdcKalHelixSeg* helixseg = new RecMdcKalHelixSeg;
2763 //cout<<"hit "<<iii<<endl;
2764 //cout<<"getMdcId: "<<(*iter_mdcHit)->getMdcId()<<endl;
2765 //cout<<"getAdc: "<<(*iter_mdcHit)->getAdc()<<endl;
2766 //cout<<"getTdc: "<<(*iter_mdcHit)->getTdc()<<endl;
2767 //cout<<"getDriftT: "<<(*iter_mdcHit)->getDriftT()<<endl;
2768 //cout<<"getZhit: "<<(*iter_mdcHit)->getZhit()<<endl;
2769 //cout<<"getFlagLR: "<<(*iter_mdcHit)->getFlagLR()<<endl;
2770 //cout<<"getDriftDistLeft: "<<(*iter_mdcHit)->getDriftDistLeft()<<endl;
2771 //cout<<"getDriftDistRight: "<<(*iter_mdcHit)->getDriftDistRight()<<endl;
2772 //cout<<"getDoca: "<<(*iter_mdcHit)->getDoca()<<endl;
2773 //cout<<"getEntra: "<<(*iter_mdcHit)->getEntra()<<endl;
2774 //
2775 helixseg->setMdcId((*iter_mdcHit)->getMdcId());
2776 helixseg->setAdc((*iter_mdcHit)->getAdc());
2777 helixseg->setTdc((*iter_mdcHit)->getTdc());
2778 helixseg->setZhit((*iter_mdcHit)->getZhit());
2779 helixseg->setFlagLR((*iter_mdcHit)->getFlagLR());
2780 if((*iter_mdcHit)->getFlagLR()==0) helixseg->setDD((*iter_mdcHit)->getDriftDistLeft());
2781 if((*iter_mdcHit)->getFlagLR()==1) helixseg->setDD((*iter_mdcHit)->getDriftDistRight());
2782 helixseg->setDocaIncl((*iter_mdcHit)->getDoca());
2783 helixseg->setEntra((*iter_mdcHit)->getEntra());
2784 helixseg->setDT((*iter_mdcHit)->getDriftT());
2785 segcol->push_back(helixseg);
2786 SmartRef<RecMdcKalHelixSeg> refhelixseg(helixseg);
2787 helixsegrefvec.push_back(refhelixseg);
2788 }
2789 trk->setVecHelixSegs(helixsegrefvec);
2790 cout<<"setVecHelixSegs with Mdc hits"<<endl;
2791 }
2792 else cout<<"not find the Mdc Track!";
2793 //cout<<"size of VecHelixSegs: "<<trk->getVecHelixSegs().size()<<endl;
2794 }
2795 */
2796
2797 }
2798
2799 // test--------
2800 if(debug_ == 4) {
2801 cout<<"Now let us see results after smoothering at IP:........."<<endl;
2802 cout << " dr = " << track.a()[0]
2803 << ", Er_dr = " << sqrt(track.Ea()[0][0]) << std::endl;
2804 cout<< " phi0 = " << track.a()[1]
2805 << ", Er_phi0 = " << sqrt(track.Ea()[1][1]) << std::endl;
2806 cout << " PT = " << 1/track.a()[2]
2807 << ", Er_kappa = " << sqrt(track.Ea()[2][2]) << std::endl;
2808 cout << " dz = " << track.a()[3]
2809 << ", Er_dz = " << sqrt(track.Ea()[3][3]) << std::endl;
2810 cout << " tanl = " << track.a()[4]
2811 << ", Er_tanl = " << sqrt(track.Ea()[4][4]) << std::endl;
2812 cout << " Ea = " << track.Ea() <<endl;
2813 }
2814 // test end ----------
2815}
2816
2817//void KalFitAlg::FillTds_helixsegs(KalFitTrack& track,MdcRec_trk& rectrk )
2818
2819void KalFitAlg::sameas(RecMdcKalTrack* trk, int l_mass, int imain)
2820{
2821 // note: for this function,only imain==lead(2) considered
2822 //std::cout<<"BEGINNING THE sameas() function ..."<<std::endl;
2823 trk->setMass(trk->getMass(imain), l_mass);
2824 trk->setLength(trk->getLength(imain), l_mass);
2825 trk->setTof(trk->getTof(imain), l_mass);
2826 trk->setNhits(trk->getNhits(imain), l_mass);
2827
2828 for(int jj = 0; jj<2; jj++) {
2829 trk->setStat(trk->getStat(jj,imain), jj, l_mass);
2830 trk->setChisq(trk->getChisq(jj, l_mass), jj, l_mass);
2831 trk->setNdf(trk->getChisq(jj, l_mass), jj, l_mass);
2832 }
2833 trk->setLHelix(trk->getFHelix(),l_mass);
2834 trk->setLError(trk->getFError(),l_mass);
2835}
2836
2837
2839{
2840 // retrieve Mdc geometry information
2841 IMdcGeomSvc* igeomsvc;
2842 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
2843 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
2844 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
2845 if(!geomsvc){
2846 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
2847 }
2848
2849 HepPoint3D ip(0,0,0);
2850 if(m_usevtxdb==1){
2851 Hep3Vector xorigin(0,0,0);
2852 IVertexDbSvc* vtxsvc;
2853 Gaudi::svcLocator()->service("VertexDbSvc", vtxsvc);
2854 if(vtxsvc->isVertexValid()){
2855 double* dbv = vtxsvc->PrimaryVertex();
2856 double* vv = vtxsvc->SigmaPrimaryVertex();
2857 xorigin.setX(dbv[0]);
2858 xorigin.setY(dbv[1]);
2859 xorigin.setZ(dbv[2]);
2860 }
2861 ip[0] = xorigin[0];
2862 ip[1] = xorigin[1];
2863 ip[2] = xorigin[2];
2864 }
2865
2866 // Estimation of the path length from ip to 1st cylinder
2867
2868 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
2869 work.ignoreErrorMatrix();
2870 work.pivot(ip);
2871
2872
2873 double tanl = track.tanl();
2874 double phi_old = work.phi0();
2875 double phi = track.phi0();
2876
2877 if (fabs(phi - phi_old) > M_PI) {
2878 if (phi > phi_old) phi -= 2 * M_PI;
2879 else phi_old -= 2 * M_PI;
2880 }
2881
2882 double path_zero = fabs(track.radius() * (phi_old-phi)* sqrt(1 + tanl * tanl));
2883 // track.addPathSM(path_zero);
2884
2885
2886 HepSymMatrix Eakal(5,0);
2887 track.pivot(ip);
2888 /// be attention to this inital error matrix of smoother,
2889 /// how is track.Ea() in the next sentence when use it?
2890 Eakal = track.Ea()*matrixg_;
2891 track.Ea(Eakal);
2892
2893 // Mdc part :
2894 unsigned int nhit = track.HitsMdc().size();
2895 int layer_prev = -1;
2896
2897 HepVector pos_old(3,0);
2898 double r0kal_prec(0);
2899 int nhits_read(0);
2900 for( unsigned i=0 ; i < nhit; i++ ) {
2901 int ihit = (nhit-1)-i;
2902 KalFitHitMdc& HitMdc = track.HitMdc(ihit);
2903 const KalFitWire& Wire = HitMdc.wire();
2904
2905 int wireid = Wire.geoID();
2906 nhits_read++;
2907
2908 int layer = Wire.layer().layerId();
2909 if (pathl_ && layer != layer_prev) {
2910
2911 if (debug_ == 4) cout<<"in smoother,layerid "<<layer<<" layer_prev "
2912 <<layer_prev <<" pathl_ "<<pathl_<<endl;
2913
2914 // track.PathL(Wire.layer().layerId());
2915 layer_prev = layer;
2916 }
2917
2918 HepPoint3D fwd(Wire.fwd());
2919 HepPoint3D bck(Wire.bck());
2920 Hep3Vector wire = (CLHEP::Hep3Vector)fwd - (CLHEP::Hep3Vector)bck;
2921 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
2922 work.ignoreErrorMatrix();
2923 work.pivot((fwd + bck) * .5);
2924 HepPoint3D x0kal = (work.x(0).z() - bck.z()) / wire.z() * wire + bck;
2925
2926 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
2927 if (wsag_ == 4){
2928 Hep3Vector result;
2929 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
2930 double tension = geowire->Tension();
2931
2932 //std::cout<<" tension: "<<tension<<std::endl;
2933 double zinit(x0kal.z()), lzx(Wire.lzx());
2934
2935 // double A(Wire.Acoef());
2936 double A = 47.35E-6/tension;
2937 double Zp = (zinit - bck.z())*lzx/wire.z();
2938
2939 if(4 == debug_){
2940 std::cout<<" sag in smoother_anal: "<<std::endl;
2941 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
2942 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
2943 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
2944 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
2945 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
2946 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
2947 }
2948
2949 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
2950 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
2951 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
2952
2953 wire.setX(wire.x()/wire.z());
2954 wire.setY(result.z());
2955 wire.setZ(1);
2956
2957 x0kal.setX(result.x());
2958 x0kal.setY(result.y());
2959 }
2960
2961 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
2962
2963 // If x0kal is after the inner wall and x0kal_prec before :
2964 double r0kal = x0kal.perp();
2965 if (debug_ == 4) {
2966 cout<<"wire direction "<<wire<<endl;
2967 cout<<"x0kal "<<x0kal<<endl;
2968 cout<<"smoother::r0kal "<<r0kal<<" r0kal_prec "<<r0kal_prec <<endl;
2969 }
2970
2971 // change PIVOT :
2972 /*cout<<endl<<"before change pivot: "<<endl;//wangll
2973 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2974 cout<<"track.helix = "<<track.a()<<endl;//wangll
2975 */
2976 double pathl(0);
2977 track.pivot_numf(x0kal, pathl);
2978 track.addPathSM(pathl);
2979 /*cout<<endl<<"after change pivot: "<<endl;//wangll
2980 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2981 cout<<"track.helix = "<<track.a()<<endl;//wangll
2982 */
2983
2984 // calculate the tof time in this layer
2985 double pmag( sqrt( 1.0 + track.a()[4]*track.a()[4]) / track.a()[2]);
2986 double mass_over_p( track.mass()/ pmag );
2987 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2988 double tofest = pathl / ( 29.9792458 * beta );
2989 track.addTofSM(tofest);
2990
2991 // std::cout<<" in layer: "<<layer<<" pathl: "<<pathl<<" tof: "<<tofest<<std::endl;
2992
2993 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
2994 /*cout<<endl<<"after muls: "<<endl;//wangll
2995 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
2996 cout<<"track.helix = "<<track.a()<<endl;//wangll
2997 */
2998 if(!(way<0&&fabs(track.kappa())>1000.0)) {
2999 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3000 }
3001
3002
3003 // Add info hit wire :
3004 /*cout<<endl<<"after eloss: "<<endl;//wangll
3005 cout<<"track.pivot = "<<track.pivot()<<endl;//wangll
3006 cout<<"track.helix = "<<track.a()<<endl;//wangll
3007 */
3008 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3009 HepVector Va(5,0);
3010 HepSymMatrix Ma(5,0);
3011 KalFitHelixSeg HelixSeg(&HitMdc,x0kal,Va,Ma);
3012
3013 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3014 double dchi2=-1;
3015 track.smoother_Mdc(HitMdc, meas, HelixSeg, dchi2, m_csmflag);
3016 if(dchi2>0.0) {
3017 track.HelixSegs().push_back(HelixSeg);
3018 }
3019 }
3020
3021 /// oh, to be the last hit
3022
3023 if(i == nhit-1){
3024
3025 /// calculate the lsat point in MDC
3026 HepPoint3D point;
3027 point.setX(x0kal.x() + track.a()[0]*cos(track.a()[1]));
3028 point.setY(x0kal.y() + track.a()[0]*sin(track.a()[1]));
3029 point.setZ(x0kal.z() + track.a()[3]);
3030 track.point_last(point);
3031
3032 /// calculate fiTerm
3033 double phi_old = track.a()[1];
3034 KalFitTrack temp(x0kal, track.a(), track.Ea(), 0, 0, 0);
3035 temp.pivot(ip);
3036 double phi_new = temp.a()[1];
3037 double fi = phi_new - phi_old;
3038 /// for protection purpose
3039 //if(fabs(fi) >= CLHEP::twopi) fi = fmod(fi+2*CLHEP::twopi,CLHEP::twopi);
3040
3041 if(fabs(fi) >= CLHEP::twopi) fi = fmod(fi+2*CLHEP::twopi,CLHEP::twopi);
3042
3043 track.fiTerm(fi);
3044 }
3045
3046 if (debug_==4) cout<<"track----7-----"<<track.a()<<endl;
3047 r0kal_prec = r0kal;
3048 }
3049}
3050
3051
3052
3054{
3055
3056 // retrieve Mdc geometry information
3057 IMdcGeomSvc* igeomsvc;
3058 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3059 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3060 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3061 if(!geomsvc){
3062 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3063 }
3064
3065 HepSymMatrix Eakal(5,0);
3066 // Estimation of the path length from ip to 1st cylinder
3067 HepPoint3D ip(0,0,0);
3068 track.pivot(ip);
3069 Eakal = track.getInitMatrix();
3070 if( debug_ == 4) {
3071 std::cout<<"the initial error matrix in smoothing is "<<Eakal<<std::endl;
3072 }
3073 track.Ea(Eakal);
3074
3075 // Mdc part :
3076 unsigned int nseg = track.HelixSegs().size();
3077 int layer_prev = -1;
3078
3079 HepVector pos_old(3,0);
3080 double r0kal_prec(0);
3081 int nsegs_read(0);
3082 for( unsigned i=0 ; i < nseg; i++ ) {
3083
3084 int flag=0;
3085 int iseg = (nseg-1)-i;
3086 KalFitHelixSeg& HelixSeg = track.HelixSeg(iseg);
3087 const KalFitWire& Wire = HelixSeg.HitMdc()->wire();
3088
3089 int wireid = Wire.geoID();
3090 nsegs_read++;
3091
3092 int layer = Wire.layer().layerId();
3093 if (pathl_ && layer != layer_prev) {
3094
3095 if (debug_ == 4) cout<<"in smoother,layerid "<<layer<<" layer_prev "
3096 <<layer_prev <<" pathl_ "<<pathl_<<endl;
3097
3098 // track.PathL(Wire.layer().layerId());
3099 layer_prev = layer;
3100 }
3101
3102 HepPoint3D fwd(Wire.fwd());
3103 HepPoint3D bck(Wire.bck());
3104 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3105 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
3106 work.ignoreErrorMatrix();
3107 work.pivot((fwd + bck) * .5);
3108 HepPoint3D x0kal = (work.x(0).z() - bck.z()) / wire.z() * wire + bck;
3109
3110
3111 if(4 == debug_) std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3112
3113 if (wsag_ == 4){
3114
3115 Hep3Vector result;
3116 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3117 double tension = geowire->Tension();
3118
3119 //std::cout<<" tension: "<<tension<<std::endl;
3120 double zinit(x0kal.z()), lzx(Wire.lzx());
3121
3122 // double A(Wire.Acoef());
3123
3124 double A = 47.35E-6/tension;
3125 double Zp = (zinit - bck.z())*lzx/wire.z();
3126
3127 if(4 == debug_){
3128
3129 std::cout<<" sag in smoother_calib: "<<std::endl;
3130 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3131 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3132 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3133 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3134 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3135 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3136 }
3137
3138 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3139 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3140 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3141
3142 wire.setX(wire.x()/wire.z());
3143 wire.setY(result.z());
3144 wire.setZ(1);
3145
3146 x0kal.setX(result.x());
3147 x0kal.setY(result.y());
3148 }
3149
3150 if(4 == debug_) std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3151
3152
3153 // If x0kal is after the inner wall and x0kal_prec before :
3154 double r0kal = x0kal.perp();
3155 if (debug_ == 4) {
3156 cout<<"wire direction "<<wire<<endl;
3157 cout<<"x0kal "<<x0kal<<endl;
3158 cout<<"smoother::r0kal "<<r0kal<<" r0kal_prec "<<r0kal_prec <<endl;
3159 }
3160
3161 // change PIVOT :
3162 double pathl(0);
3163 track.pivot_numf(x0kal, pathl);
3164
3165 if (debug_ == 4) cout<<"track----6-----"<<track.a()<<" ...path..."<<pathl
3166 <<"momentum"<<track.momentum(0)<<endl;
3167 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3168 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3169
3170 // Add info hit wire :
3171 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3172 // attention to this measure value ,what is the measurement value !!
3173 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3174
3175 if(usage_>1) track.smoother_Mdc_csmalign(HelixSeg, meas,flag, m_csmflag);
3176 else track.smoother_Mdc(HelixSeg, meas,flag, m_csmflag);
3177 // cout<<"layer, cell, track.a: "<<Wire.layer().layerId()<<" , "<<Wire.localId()<<" , "<<track.a()<<endl;
3178 }
3179
3180 if (debug_==4) cout<<"track----7-----"<<track.a()<<endl;
3181 r0kal_prec = r0kal;
3182 // can this kind of operation be right??
3183 if(flag == 0) {
3184 track.HelixSegs().erase(track.HelixSegs().begin()+iseg);
3185 }
3186 }
3187}
3188
3189
3190
3191void KalFitAlg::filter_fwd_anal(KalFitTrack& track, int l_mass, int way, HepSymMatrix& Eakal)
3192{
3193
3194 if(debug_==4) {
3195 cout<<"**********************"<<endl;//wangll
3196 cout<<"filter pid type "<<l_mass<<endl;//wangll
3197 }
3198
3199 // retrieve Mdc geometry information
3200 IMdcGeomSvc* igeomsvc;
3201 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3202 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3203 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3204 if(!geomsvc){
3205 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3206 }
3207
3208 //Hep3Vector x0inner(track.pivot());
3209 HepVector pos_old(3,0);
3210 double r0kal_prec(0);
3211 int nhits_read(0);
3212 int nhit = track.HitsMdc().size();
3213 if(debug_ == 4) cout<<"filter_fwd..........111 nhit="<<nhit<<endl;
3214 for( int i=0 ; i < nhit; i++ ) {
3215 KalFitHitMdc& HitMdc = track.HitMdc(i);
3216 // veto on some hits :
3217 if (HitMdc.chi2()<0) continue;
3218 const KalFitWire& Wire = HitMdc.wire();
3219 int layerf = Wire.layer().layerId();
3220
3221 //std::cout<<"in layer: "<<layerf<<std::endl;
3222
3223 int wireid = Wire.geoID();
3224 nhits_read++;
3225 HepPoint3D fwd(Wire.fwd());
3226 HepPoint3D bck(Wire.bck());
3227 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3228 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
3229 work.ignoreErrorMatrix();
3230 work.pivot((fwd + bck) * .5);
3231
3232 //std::cout<<" (fwd + bck) * .5: "<<(fwd + bck)*.5<<std::endl;
3233 //std::cout<<" track.x(0): "<<track.x(0)<<std::endl;
3234 //std::cout<<" work.x(0): "<<work.x(0)<<std::endl;
3235 //std::cout<<" bck: "<<bck<<std::endl;
3236
3237 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
3238
3239 if(4 == debug_) {
3240 std::cout<<" a="<<track.a()<<std::endl;
3241 std::cout<<" pivot="<<track.pivot()<<std::endl;
3242 std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3243 }
3244
3245 // Modification to take account of the wire sag :
3246 /*
3247 if (wsag_==1) {
3248 double A(1.2402E-6);
3249 if (nhits_read != 1 && r0kal_prec > RMW && x0kal.perp() < RMW)
3250 A = 8.5265E-7;
3251 HepPoint3D x0kal_up(x0kal);
3252 double length = sqrt(wire.x()*wire.x()+wire.z()*wire.z());
3253 double zp = (x0kal.z() - bck.z())*length/wire.z();
3254
3255 x0kal_up.setX(wire.x()*(x0kal.z()-bck.z())/wire.z()+bck.x());
3256 x0kal_up.setY((A*(zp-length)+wire.y()/length)*zp+bck.y());
3257 double slopex = wire.x()/wire.z();
3258 double slopey = (A*(2*zp-length)*length+wire.y())/wire.z();
3259
3260 x0kal = x0kal_up;
3261 wire.setX(slopex);
3262 wire.setY(slopey);
3263 wire.setZ(1);
3264
3265 } else if (wsag_ == 2 || wsag_ == 3){
3266 double slopex = wire.x()/wire.z();
3267 double slopey(0), zinit(x0kal.z());
3268 double pos[3], yb_sag(0), yf_sag(0);
3269 int wire_ID = Wire.geoID();
3270 if (wsag_ == 2)
3271 calcdc_sag2_(&wire_ID, &zinit, pos, &slopey, &yb_sag, &yf_sag);
3272
3273 else
3274 calcdc_sag3_(&wire_ID, &zinit, pos, &slopey, &yb_sag, &yf_sag);
3275
3276 wire.setX(slopex);
3277 wire.setY(slopey);
3278 wire.setZ(1);
3279 x0kal.setX(pos[0]);
3280 x0kal.setY(pos[1]);
3281 } else
3282 */
3283
3284 if (wsag_ == 4){
3285 Hep3Vector result;
3286 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3287 double tension = geowire->Tension();
3288 //std::cout<<" tension: "<<tension<<std::endl;
3289 double zinit(x0kal.z()), lzx(Wire.lzx());
3290 // double A(Wire.Acoef());
3291 double A = 47.35E-6/tension;
3292 double Zp = (zinit - bck.z())*lzx/wire.z();
3293
3294 if(4 == debug_){
3295 std::cout<<" sag in filter_fwd_anal: "<<std::endl;
3296 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3297 std::cout<<"zinit: "<<zinit<<" bck.z(): "<<bck.z()<<std::endl;
3298 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3299 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3300 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3301 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3302 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3303 }
3304
3305 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3306 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3307 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3308
3309 wire.setX(wire.x()/wire.z());
3310 wire.setY(result.z());
3311 wire.setZ(1);
3312 x0kal.setX(result.x());
3313 x0kal.setY(result.y());
3314 }
3315
3316
3317 // If x0kal is after the inner wall and x0kal_prec before :
3318 double r0kal = x0kal.perp();
3319
3320 // change PIVOT :
3321 double pathl(0);
3322
3323 if(i==0) track.pivot(x0kal);
3324 else track.pivot_numf(x0kal, pathl);
3325
3326
3327 if (nhits_read == 1) {
3328 track.Ea(Eakal);
3329 } else {
3330 //std::cout<<" Ea="<<track.Ea()<<std::endl;
3331 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3332 //std::cout<<" after muls Ea="<<track.Ea()<<std::endl;
3333 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3334 //std::cout<<" after eloss Ea="<<track.Ea()<<std::endl;
3335 }
3336
3337 if(4 == debug_) {
3338 std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3339 std::cout<<" a="<<track.a()<<std::endl;
3340 std::cout<<" Ea="<<track.Ea()<<std::endl;
3341 }
3342
3343 double dtracknew = 0.;
3344 double dtrack = 0.;
3345 double dtdc = 0.;
3346 // Add info hit wire :
3347 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3348 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3349 double diff_chi2 = track.chiSq();
3350 Hep3Vector IP(0,0,0);
3351 KalmanFit::Helix work_bef = *(KalmanFit::Helix*)&track;
3352 work_bef.ignoreErrorMatrix();
3353 work_bef.pivot(IP);
3354 int inext(-1);
3355 if (i+1<nhit)
3356 for( unsigned k=i+1 ; k < nhit; k++ )
3357 if (!(track.HitMdc(k).chi2()<0)) {
3358 inext = (signed) k;
3359 break;
3360 }
3361 double dchi2 = -1.0;
3362
3363 double chi2 = track.update_hits(HitMdc,inext,meas,way,dchi2,dtrack,dtracknew,dtdc,m_csmflag);
3364
3365 //cout << "dchi2=" << dchi2 << endl;
3366 /// get the doca from another other independent method
3367
3368 /*
3369 std::cout<<" step0: "<<std::endl;
3370 KalFitTrack temp2(track);
3371 std::cout<<" step1: "<<std::endl;
3372
3373 KalmanFit::Helix temp3(track.pivot(),track.a(),track.Ea());
3374 KalmanFit::Helix temp4(track.pivot(),track.a(),track.Ea());
3375
3376 std::cout<<" step2: "<<std::endl;
3377 double doca25 = temp2.approach(HitMdc, false);
3378 std::cout<<" step3: "<<std::endl;
3379
3380 temp2.pivot(IP);
3381 std::cout<<" a2: "<<temp2.a()<<std::endl;
3382
3383 std::cout<<" step4: "<<std::endl;
3384
3385 double doca26 = temp3.approach(HitMdc, false);
3386 std::cout<<" another doca2.6: "<<doca26<<std::endl;
3387
3388 temp3.pivot(IP);
3389 std::cout<<" a3: "<<temp3.a()<<std::endl;
3390
3391 temp4.bFieldZ(-10);
3392 temp4.pivot(IP);
3393 std::cout<<" a4: "<<temp4.a()<<std::endl;
3394
3395 std::cout<<" step5: "<<std::endl;
3396
3397 double doca1 = track.approach(HitMdc, false);
3398 double doca2 = temp2.approach(HitMdc, false);
3399 double doca3 = temp3.approach(HitMdc, false);
3400 double doca4 = temp4.approach(HitMdc, false);
3401
3402 std::cout<<" dtrack: "<<dtrack<<std::endl;
3403 std::cout<<" another doca1: "<<doca1<<std::endl;
3404 std::cout<<" another doca2: "<<doca2<<std::endl;
3405 std::cout<<" another doca2.5: "<<doca25<<std::endl;
3406 std::cout<<" another doca3: "<<doca3<<std::endl;
3407 std::cout<<" another doca4: "<<doca4<<std::endl;
3408 */
3409
3410
3411 //if( dchi2 <0 ) { std::cout<<" ... ERROR OF dchi2... "<<std::endl; }
3412
3413 if (ntuple_&8) {
3414 m_dchi2 = dchi2;
3415 m_masshyp = l_mass;
3416 m_residest = dtrack-dtdc;
3417 m_residnew = dtracknew -dtdc;
3418 m_layer = Wire.layer().layerId();
3419 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3420 m_anal_dr = worktemp.a()[0];
3421 m_anal_phi0 = worktemp.a()[1];
3422 m_anal_kappa = worktemp.a()[2];
3423 m_anal_dz = worktemp.a()[3];
3424 m_anal_tanl = worktemp.a()[4];
3425 m_anal_ea_dr = worktemp.Ea()[0][0];
3426 m_anal_ea_phi0 = worktemp.Ea()[1][1];
3427 m_anal_ea_kappa = worktemp.Ea()[2][2];
3428 m_anal_ea_dz = worktemp.Ea()[3][3];
3429 m_anal_ea_tanl = worktemp.Ea()[4][4];
3430 StatusCode sc5 = m_nt5->write();
3431 if( sc5.isFailure() ) cout<<"Ntuple5 filling failed!"<<endl;
3432 }
3433
3434 if (ntuple_&256) {
3435
3436 //cout<<"Mdc: "<<m_hit_no<<endl;
3437
3438 if(l_mass == 0){
3439 m_dchi2_hit_e[m_hit_no] = dchi2;
3440 m_residest_hit_e[m_hit_no] = dtrack-dtdc;
3441 m_residnew_hit_e[m_hit_no] = dtracknew -dtdc;
3442 m_layer_hit_e[m_hit_no] = Wire.layer().layerId();
3443 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3444 m_anal_dr_hit_e[m_hit_no] = worktemp.a()[0];
3445 m_anal_phi0_hit_e[m_hit_no] = worktemp.a()[1];
3446 m_anal_kappa_hit_e[m_hit_no] = worktemp.a()[2];
3447 m_anal_dz_hit_e[m_hit_no] = worktemp.a()[3];
3448 m_anal_tanl_hit_e[m_hit_no] = worktemp.a()[4];
3449 m_anal_ea_dr_hit_e[m_hit_no] = worktemp.Ea()[0][0];
3450 m_anal_ea_phi0_hit_e[m_hit_no] = worktemp.Ea()[1][1];
3451 m_anal_ea_kappa_hit_e[m_hit_no] = worktemp.Ea()[2][2];
3452 m_anal_ea_dz_hit_e[m_hit_no] = worktemp.Ea()[3][3];
3453 m_anal_ea_tanl_hit_e[m_hit_no] = worktemp.Ea()[4][4];
3454
3455 }
3456
3457 else if(l_mass == 1){
3458 m_dchi2_hit_mu[m_hit_no] = dchi2;
3459 m_residest_hit_mu[m_hit_no] = dtrack-dtdc;
3460 m_residnew_hit_mu[m_hit_no] = dtracknew -dtdc;
3461 m_layer_hit_mu[m_hit_no] = Wire.layer().layerId();
3462 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3463 m_anal_dr_hit_mu[m_hit_no] = worktemp.a()[0];
3464 m_anal_phi0_hit_mu[m_hit_no] = worktemp.a()[1];
3465 m_anal_kappa_hit_mu[m_hit_no] = worktemp.a()[2];
3466 m_anal_dz_hit_mu[m_hit_no] = worktemp.a()[3];
3467 m_anal_tanl_hit_mu[m_hit_no] = worktemp.a()[4];
3468 m_anal_ea_dr_hit_mu[m_hit_no] = worktemp.Ea()[0][0];
3469 m_anal_ea_phi0_hit_mu[m_hit_no] = worktemp.Ea()[1][1];
3470 m_anal_ea_kappa_hit_mu[m_hit_no] = worktemp.Ea()[2][2];
3471 m_anal_ea_dz_hit_mu[m_hit_no] = worktemp.Ea()[3][3];
3472 m_anal_ea_tanl_hit_mu[m_hit_no] = worktemp.Ea()[4][4];
3473
3474 }
3475
3476
3477 else if(l_mass == 2){
3478 m_dchi2_hit_pi[m_hit_no] = dchi2;
3479 m_residest_hit_pi[m_hit_no] = dtrack-dtdc;
3480 m_residnew_hit_pi[m_hit_no] = dtracknew -dtdc;
3481 m_layer_hit_pi[m_hit_no] = Wire.layer().layerId();
3482 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3483 m_anal_dr_hit_pi[m_hit_no] = worktemp.a()[0];
3484 m_anal_phi0_hit_pi[m_hit_no] = worktemp.a()[1];
3485 m_anal_kappa_hit_pi[m_hit_no] = worktemp.a()[2];
3486 m_anal_dz_hit_pi[m_hit_no] = worktemp.a()[3];
3487 m_anal_tanl_hit_pi[m_hit_no] = worktemp.a()[4];
3488 m_anal_ea_dr_hit_pi[m_hit_no] = worktemp.Ea()[0][0];
3489 m_anal_ea_phi0_hit_pi[m_hit_no] = worktemp.Ea()[1][1];
3490 m_anal_ea_kappa_hit_pi[m_hit_no] = worktemp.Ea()[2][2];
3491 m_anal_ea_dz_hit_pi[m_hit_no] = worktemp.Ea()[3][3];
3492 m_anal_ea_tanl_hit_pi[m_hit_no] = worktemp.Ea()[4][4];
3493
3494 }
3495
3496
3497 else if(l_mass == 3){
3498 m_dchi2_hit_k[m_hit_no] = dchi2;
3499 m_residest_hit_k[m_hit_no] = dtrack-dtdc;
3500 m_residnew_hit_k[m_hit_no] = dtracknew -dtdc;
3501 m_layer_hit_k[m_hit_no] = Wire.layer().layerId();
3502 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3503 m_anal_dr_hit_k[m_hit_no] = worktemp.a()[0];
3504 m_anal_phi0_hit_k[m_hit_no] = worktemp.a()[1];
3505 m_anal_kappa_hit_k[m_hit_no] = worktemp.a()[2];
3506 m_anal_dz_hit_k[m_hit_no] = worktemp.a()[3];
3507 m_anal_tanl_hit_k[m_hit_no] = worktemp.a()[4];
3508 m_anal_ea_dr_hit_k[m_hit_no] = worktemp.Ea()[0][0];
3509 m_anal_ea_phi0_hit_k[m_hit_no] = worktemp.Ea()[1][1];
3510 m_anal_ea_kappa_hit_k[m_hit_no] = worktemp.Ea()[2][2];
3511 m_anal_ea_dz_hit_k[m_hit_no] = worktemp.Ea()[3][3];
3512 m_anal_ea_tanl_hit_k[m_hit_no] = worktemp.Ea()[4][4];
3513
3514 }
3515
3516
3517 else if(l_mass == 4){
3518 m_dchi2_hit_p[m_hit_no] = dchi2;
3519 m_residest_hit_p[m_hit_no] = dtrack-dtdc;
3520 m_residnew_hit_p[m_hit_no] = dtracknew -dtdc;
3521 m_layer_hit_p[m_hit_no] = Wire.layer().layerId();
3522 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
3523 m_anal_dr_hit_p[m_hit_no] = worktemp.a()[0];
3524 m_anal_phi0_hit_p[m_hit_no] = worktemp.a()[1];
3525 m_anal_kappa_hit_p[m_hit_no] = worktemp.a()[2];
3526 m_anal_dz_hit_p[m_hit_no] = worktemp.a()[3];
3527 m_anal_tanl_hit_p[m_hit_no] = worktemp.a()[4];
3528 m_anal_ea_dr_hit_p[m_hit_no] = worktemp.Ea()[0][0];
3529 m_anal_ea_phi0_hit_p[m_hit_no] = worktemp.Ea()[1][1];
3530 m_anal_ea_kappa_hit_p[m_hit_no] = worktemp.Ea()[2][2];
3531 m_anal_ea_dz_hit_p[m_hit_no] = worktemp.Ea()[3][3];
3532 m_anal_ea_tanl_hit_p[m_hit_no] = worktemp.Ea()[4][4];
3533
3534 }
3535
3536 m_hit_no++;
3537 }
3538
3539
3540 KalmanFit::Helix work_aft = *(KalmanFit::Helix*)&track;
3541 work_aft.ignoreErrorMatrix();
3542 work_aft.pivot(IP);
3543 diff_chi2 = chi2 - diff_chi2;
3544 HitMdc.chi2(diff_chi2);
3545 }
3546 r0kal_prec = r0kal;
3547 }
3548 //cout <<"filter end" << endl;
3549}
3550
3551
3552
3553void KalFitAlg::filter_fwd_calib(KalFitTrack& track, int l_mass, int way, HepSymMatrix& Eakal)
3554{
3555
3556 // retrieve Mdc geometry information
3557 IMdcGeomSvc* igeomsvc;
3558 StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", igeomsvc);
3559 if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
3560 MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(igeomsvc);
3561 if(!geomsvc){
3562 std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
3563 }
3564
3565 if(debug_ == 4) {
3566 std::cout<<"filter_fwd_calib starting ...the inital error Matirx is "<<track.Ea()<<std::endl;
3567 }
3568 Hep3Vector x0inner(track.pivot());
3569 HepVector pos_old(3,0);
3570 double r0kal_prec(0);
3571 int nhits_read(0);
3572
3573 unsigned int nhit = track.HitsMdc().size();
3574 if(debug_ == 4) cout<<"filter_fwd..........111 nhit="<<nhit<<endl;
3575 for( unsigned i=0 ; i < nhit; i++ ) {
3576
3577 KalFitHitMdc& HitMdc = track.HitMdc(i);
3578 if(debug_ == 4)
3579 cout<<"filter_fwd...........222 chi2="<<HitMdc.chi2()<<endl;
3580 // veto on some hits :
3581 if (HitMdc.chi2()<0) continue;
3582 const KalFitWire& Wire = HitMdc.wire();
3583
3584 int wireid = Wire.geoID();
3585 nhits_read++;
3586
3587 // if (nhits_read == 1) track.Ea(Eakal);
3588 HepPoint3D fwd(Wire.fwd());
3589 HepPoint3D bck(Wire.bck());
3590 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
3591 KalmanFit::Helix work = *(KalmanFit::Helix*)&track;
3592 work.ignoreErrorMatrix();
3593 work.pivot((fwd + bck) * .5);
3594 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
3595
3596 if(4 == debug_)
3597 std::cout<<" x0kal before sag: "<<x0kal<<std::endl;
3598
3599 if (wsag_ == 4){
3600 Hep3Vector result;
3601 const MdcGeoWire* geowire = geomsvc->Wire(wireid);
3602 double tension = geowire->Tension();
3603 //std::cout<<" tension: "<<tension<<std::endl;
3604 double zinit(x0kal.z()), lzx(Wire.lzx());
3605 // double A(Wire.Acoef());
3606 double A = 47.35E-6/tension;
3607 double Zp = (zinit - bck.z())*lzx/wire.z();
3608
3609 if(4 == debug_){
3610
3611 std::cout<<" sag in filter_fwd_calib: "<<std::endl;
3612 std::cout<<" x0kal.x(): "<<std::setprecision(10)<<x0kal.x()<<std::endl;
3613 std::cout<<" wire.x()*(zinit-bck.z())/wire.z(): "<<std::setprecision(10)
3614 <<(wire.x()*(zinit-bck.z())/wire.z())<<std::endl;
3615 std::cout<<"bck.x(): "<<std::setprecision(10)<<bck.x()<<std::endl;
3616 std::cout<<" wire.x()*(zinit-bck.z())/wire.z() + bck.x(): "<<std::setprecision(10)
3617 <<(wire.x()*(zinit-bck.z())/wire.z() + bck.x())<<std::endl;
3618 }
3619
3620 result.setX(wire.x()*(zinit-bck.z())/wire.z() + bck.x());
3621 result.setY((A*(Zp-lzx)+wire.y()/lzx)*Zp+bck.y());
3622 result.setZ((A*(2*Zp-lzx)*lzx+wire.y())/wire.z());
3623 wire.setX(wire.x()/wire.z());
3624 wire.setY(result.z());
3625 wire.setZ(1);
3626 x0kal.setX(result.x());
3627 x0kal.setY(result.y());
3628 }
3629
3630 if(4 == debug_)
3631 std::cout<<" x0kal after sag: "<<x0kal<<std::endl;
3632
3633 // If x0kal is after the inner wall and x0kal_prec before :
3634 double r0kal = x0kal.perp();
3635
3636 // change PIVOT :
3637 double pathl(0);
3638
3639 //std::cout<<" track a3: "<<track.a()<<std::endl;
3640 //std::cout<<" track p3: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3641
3642 if (debug_ == 4)
3643 cout << "*** move from " << track.pivot() << " ( Kappa = "
3644 << track.a()[2] << ")" << endl;
3645 track.pivot_numf(x0kal, pathl); //see the code , the error matrix has been changed in this function ..
3646
3647 //std::cout<<" track a4: "<<track.a()<<std::endl;
3648 //std::cout<<" track p4: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3649
3650
3651 if (debug_ == 4)
3652 cout << "*** to " << track.pivot() << " ( Kappa = "
3653 << track.a()[2] << ")" << std::endl;
3654
3655 if (nhits_read == 1) {
3656 track.Ea(Eakal);
3657 if(debug_==4) cout << "filter_fwd::Ea = " << track.Ea()<<endl;
3658
3659
3660 } else {
3661 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
3662 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
3663 }
3664
3665
3666 //std::cout<<" track a5: "<<track.a()<<std::endl;
3667 //std::cout<<" track p5: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3668
3669 // Add info hit wire :
3670 if(fabs(track.kappa())>0&&fabs(track.kappa())<1000.0&&fabs(track.tanl())<7.02) {
3671 Hep3Vector meas = track.momentum(0).cross(wire).unit();
3672
3673 double diff_chi2 = track.chiSq();
3674
3675 Hep3Vector IP(0,0,0);
3676 KalmanFit::Helix work_bef = *(KalmanFit::Helix*)&track;
3677 work_bef.ignoreErrorMatrix();
3678 work_bef.pivot(IP);
3679 int inext(-1);
3680 if (i+1<nhit)
3681 for( unsigned k=i+1 ; k < nhit; k++ )
3682 if (!(track.HitMdc(k).chi2()<0)) {
3683 inext = (signed) k;
3684 break;
3685 }
3686 double dchi2 = -1.0;
3687
3688 if (debug_ == 4) {
3689 std::cout<<"the value of x0kal is "<<x0kal<<std::endl;
3690 std::cout<<"the value of track.pivot() is "<<track.pivot()<<std::endl;
3691 }
3692
3693 HepVector Va(5,0);
3694 HepSymMatrix Ma(5,0);
3695 KalFitHelixSeg HelixSeg(&HitMdc,x0kal,Va,Ma);
3696
3697 if(debug_ == 4) {
3698 std::cout<<"HelixSeg.Ea_pre_fwd() ..."<<HelixSeg.Ea_pre_fwd()<<std::endl;
3699 std::cout<<"HelixSeg.a_pre_fwd() ..."<<HelixSeg.a_pre_fwd()<<std::endl;
3700 std::cout<<"HelixSeg.Ea_filt_fwd() ..."<<HelixSeg.Ea_filt_fwd()<<std::endl;
3701 }
3702
3703 //std::cout<<" track a1: "<<track.a()<<std::endl;
3704 //std::cout<<" track p1: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3705
3706 double chi2=0.;
3707 if(usage_>1) chi2=track.update_hits_csmalign(HelixSeg, inext, meas, way, dchi2, m_csmflag);
3708 else chi2 = track.update_hits(HelixSeg, inext, meas, way, dchi2, m_csmflag);
3709
3710 //std::cout<<" track a2: "<<track.a()<<std::endl;
3711 //std::cout<<" track p2: "<<sqrt(1.0+track.a()[4]*track.a()[4])/track.a()[2]<<std::endl;
3712
3713 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;
3714
3715 if(debug_ == 4) cout<< "****inext***"<<inext<<" !!!! dchi2= "<< dchi2
3716 << " chisq= "<< chi2<< endl;
3717
3718 if (ntuple_&8) {
3719 m_dchi2 = dchi2;
3720 m_masshyp = l_mass;
3721 StatusCode sc5 = m_nt5->write();
3722 if( sc5.isFailure() ) cout<<"Ntuple5 filling failed!"<<endl;
3723 }
3724
3725 KalmanFit::Helix work_aft = *(KalmanFit::Helix*)&track;
3726 work_aft.ignoreErrorMatrix();
3727 work_aft.pivot(IP);
3728 diff_chi2 = chi2 - diff_chi2;
3729 HitMdc.chi2(diff_chi2);
3730
3731 if(debug_ == 4) {
3732
3733 cout << " -> after include meas = " << meas
3734 << " at R = " << track.pivot().perp() << std::endl;
3735 cout << " chi2 = " << chi2 << ", diff_chi2 = "
3736 << diff_chi2 << ", LR = "
3737 << HitMdc.LR() << ", stereo = " << HitMdc.wire().stereo()
3738 << ", layer = " << HitMdc.wire().layer().layerId() << std::endl;
3739 cout<<"filter_fwd..........HitMdc.chi2... "<<HitMdc.chi2()<<endl;
3740 }
3741
3742 if(dchi2>0.0 && (way!=999)) {
3743 track.HelixSegs().push_back(HelixSeg);
3744 }
3745 }
3746 r0kal_prec = r0kal;
3747 }
3748}
3749
3750// Take account of the inner wall (forward filter) :
3751void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way){
3752
3753 if (debug_ ==4) cout<<"innerwall....."<<endl;
3754 for(int i = 0; i < _BesKalmanFitWalls.size(); i++) {
3755 _BesKalmanFitWalls[i].updateTrack(track, way);
3756 if (debug_ == 4) cout<<"Wall "<<i<<" update the track!(filter)"<<endl;
3757 }
3758}
3759
3760void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way,int begin,int end){
3761 if (debug_ ==4) cout<<"innerwall....."<<endl;
3762 for(int i = begin; i <= end; i++) {
3763 _BesKalmanFitWalls[i].updateTrack(track, way);
3764 if(debug_ == 4){cout << "wall" << i << endl;
3765 cout <<"track" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;}
3766 if (debug_ == 4) cout<<"Wall "<<i<<" update the track!(filter)"<<endl;
3767 }
3768}
3769
3770void KalFitAlg::innerwall(KalFitTrack& track, int l_mass, int way, double r1, double r2, int& index){
3771 if (debug_ ==4) cout<<"innerwall....."<<endl;
3772 double ri=(r1<r2)?r1:r2;
3773 double ro=(r1<r2)?r2:r1;
3774 double Rmin,Rmax;
3775 int step;
3776 vector<KalFitCylinder>::iterator it;
3777 vector<KalFitCylinder>::iterator itStart;
3778 vector<KalFitCylinder>::iterator itStop;
3779 if(way<0){
3780 step=-1;
3781 itStart=_BesKalmanFitWalls.end()-index-1;
3782 itStop =_BesKalmanFitWalls.begin()-1;
3783 }
3784 else{
3785 step=1;
3786 itStart=_BesKalmanFitWalls.begin()+index;
3787 itStop =_BesKalmanFitWalls.end();
3788 }
3789 for(it=itStart; it != itStop; it=it+step) {
3790 if(ri < it->rmin() && it->radius() < ro) {
3791 it->updateTrack(track,way);
3792 Rmin=it->rmin();
3793 Rmax=it->radius();
3794 continue;
3795 }
3796 else if(it->rmin() <= ri && ri <= it->radius() && it->radius() < ro){
3797 it->updateTrack(track,way,ri,it->radius());
3798 Rmin=ri;
3799 Rmax=it->radius();
3800 if(way>0){
3801 //index = it - _BesKalmanFitWalls.begin();
3802 break;
3803 }
3804 else continue;
3805 }
3806 else if(ri < it->rmin() && it->rmin() <= ro && ro <= it->radius()){
3807 it->updateTrack(track,way,it->rmin(),ro);
3808 Rmin=it->rmin();
3809 Rmax=ro;
3810 if(way<0){
3811 //index = _BesKalmanFitWalls.end() - it;
3812 break;
3813 }
3814 else continue;
3815 }
3816 else if(it->radius()<ri || ro < it->rmin()){
3817 continue;
3818 }
3819 else {
3820 it->updateTrack(track,way,ri,ro);
3821 Rmin=ri;
3822 Rmax=ro;
3823 //index=it-_BesKalmanFitWalls.begin();
3824 break;
3825 }
3826 }
3827 if(way<0){
3828 //double phi=track.intersect_cylinder(Rmax);
3829 //HepPoint3D pivot=track.x(phi);
3830 //track.pivot_numf(pivot);
3831 track.pivot_numf(track.x(track.intersect_cylinder(Rmax)));
3832 index = _BesKalmanFitWalls.end() - it-1;
3833 }
3834 else{
3835 //double phi=track.intersect_cylinder(Rmin);
3836 //HepPoint3D pivot=track.x(phi);
3837 //track.pivot_numf(pivot);
3838 track.pivot_numf(track.x(track.intersect_cylinder(Rmin)));
3839 index = it - _BesKalmanFitWalls.begin();
3840 }
3841
3842}
3843
3844
3845//void KalFitAlg::set_Mdc(void)
3846
3847// Use the information of trasan and refit the best tracks
3848
3850{
3851
3852 //cout<<"kalman_fitting_anal deal with a new event"<<endl;//wangll
3853
3854 MsgStream log(msgSvc(), name());
3855 double Pt_threshold(0.3);
3856 Hep3Vector IP(0,0,0);
3857 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
3858 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
3859 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
3860
3861 // Table Manager
3862 if ( !&whMgr ) return;
3863
3864 // Get reduced chi**2 of Mdc track :
3865 int ntrk = mdcMgr->size();
3866 double* rPt = new double[ntrk];
3867 int* rOM = new int[ntrk];
3868 unsigned int* order = new unsigned int[ntrk];
3869 unsigned int* rCont = new unsigned int[ntrk];
3870 unsigned int* rGen = new unsigned int[ntrk];
3871
3872 if(testOutput) cout<<"nMdcTrk = "<<ntrk<<endl;
3873
3874 int index = 0;
3875 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
3876 end = mdcMgr->end(); it != end; it++) {
3877 // Pt
3878 rPt[index] = 0;
3879 if (it->helix[2])
3880 rPt[index] = 1 / fabs(it->helix[2]);
3881 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
3882 if(rPt[index] < 0) rPt[index] = DBL_MAX;
3883 // Outermost layer
3884 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
3885 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
3886 int outermost(-1);
3887 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3888 ii !=pt.begin()-1; ii--) {
3889 int lyr((*ii)->geo->Lyr()->Id());
3890 if (outermost < lyr) outermost = lyr;
3891 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
3892 }
3893 rOM[index] = outermost;
3894 order[index] = index;
3895 ++index;
3896 }
3897
3898 // Sort Mdc tracks by Pt
3899 for (int j, k = ntrk - 1; k >= 0; k = j){
3900 j = -1;
3901 for(int i = 1; i <= k; i++)
3902 if(rPt[i - 1] < rPt[i]){
3903 j = i - 1;
3904 std::swap(order[i], order[j]);
3905 std::swap(rPt[i], rPt[j]);
3906 std::swap(rOM[i], rOM[j]);
3907 std::swap(rCont[i], rCont[j]);
3908 std::swap(rGen[i], rGen[j]);
3909 }
3910 }
3911 delete [] rPt;
3912
3913 //
3914 int newcount(0);
3915 //check whether Recon already registered
3916 DataObject *aReconEvent;
3917 eventSvc()->findObject("/Event/Recon",aReconEvent);
3918 if(!aReconEvent) {
3919 // register ReconEvent Data Object to TDS;
3920 ReconEvent* recevt = new ReconEvent;
3921 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
3922 if(sc!=StatusCode::SUCCESS) {
3923 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
3924 return;
3925 }
3926 }
3927
3928 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
3930 //make RecMdcKalTrackCol
3931 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
3932 // Loop over tracks given by trasan :
3933 for(int l = 0; l < ntrk; l++) {
3934
3935 //cout<<"----------------"<<endl;//wangll
3936 //cout<<"track "<<l<<" : "<<endl;//wangll
3937 nTotalTrks++;
3938
3939 for(int i=0; i<5; i++) iqual_front_[i] = 1; // wangll 2010-11-01
3940
3941 // m_timer[3]->start();
3942 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[l]);
3943 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[l]);
3944
3945 // Reject the ones with quality != 0
3946 int trasqual = TrasanTRK_add.quality;
3947 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
3948 if (trasqual) continue;
3949
3950 newcount++;
3951 if (debug_ == 4)
3952 cout << "******* KalFit NUMBER : " << newcount << std::endl;
3953
3954 // What kind of KalFit ?
3955 int type(0);
3956 if ((TrasanTRK_add.decision & 32) == 32 ||
3957 (TrasanTRK_add.decision & 64) == 64) type = 1;
3958
3959 // Initialisation : (x, a, ea)
3960 HepPoint3D x(TrasanTRK.pivot[0],
3961 TrasanTRK.pivot[1],
3962 TrasanTRK.pivot[2]);
3963
3964 HepVector a(5);
3965 for(int i = 0; i < 5; i++)
3966 a[i] = TrasanTRK.helix[i];
3967
3968 HepSymMatrix ea(5);
3969 for(int i = 0, k = 0; i < 5; i++) {
3970 for(int j = 0; j <= i; j++) {
3971 ea[i][j] = matrixg_*TrasanTRK.error[k++];
3972 ea[j][i] = ea[i][j];
3973 }
3974 }
3975 double fiTerm = TrasanTRK.fiTerm;
3976 int way(1);
3977 // Prepare the track found :
3978 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
3979
3980 track_lead.bFieldZ(KalFitTrack::Bznom_);
3981 double pT_trk = fabs(track_lead.pt());
3982
3983 // Mdc Hits
3984 int inlyr(999), outlyr(-1);
3985 int* rStat = new int[43];
3986 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
3987 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
3988 int hit_in(0);
3989 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
3990 // Number of hits/layer
3991 int Num[43] = {0};
3992 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3993 ii != pt.begin()-1; ii--) {
3994 Num[(*ii)->geo->Lyr()->Id()]++;
3995 }
3996 int hit_asso(0);
3997 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
3998 ii != pt.begin()-1; ii--) {
3999 hit_asso++;
4000
4001 if (pT_trk>0.12 && Num[(*ii)->geo->Lyr()->Id()]>3) {
4002 if (debug_==4 )
4003 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
4004 << " hits in the layer "
4005 << (*ii)->geo->Lyr()->Id() << std::endl;
4006 continue;
4007 }
4008 // comment out wangll 2020-05-22
4009
4010 // if(ii!=pt.end()-1){
4011 // int layer_before=(*(ii+1))->geo->Lyr()->Id();
4012 // if(layer_before == (*ii)->geo->Lyr()->Id()){
4013 // MdcRec_wirhit * rechit_before = *(ii+1);
4014 // if((*rechit_before).rechitptr->getDriftT()>450 || (**ii).rechitptr->getDriftT()>450.){
4015 // if((*rechit_before).tdc < (**ii).tdc) continue;
4016 // else if(track_lead.HitsMdc().size()>0 && rStat[layer_before]){
4017 // track_lead.HitsMdc().pop_back();
4018 // }
4019 // }
4020 // }
4021 // }
4022
4023 hit_in++;
4024 MdcRec_wirhit & rechit = **ii;
4025 double dist[2] = {rechit.ddl, rechit.ddr};
4026 double erdist[2] = {rechit.erddl, rechit.erddr};
4027 const MdcGeoWire* geo = rechit.geo;
4028
4029 int lr_decision(0);
4030 if (KalFitTrack::LR_ == 1){
4031 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
4032 // if (rechit.lr==0) lr_decision=-1;
4033 else if (rechit.lr==1) lr_decision=1;
4034 }
4035
4036 int ind(geo->Lyr()->Id());
4037
4038 // ATTENTION HERE!!!
4039 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
4040 lr_decision, rechit.tdc,
4041 dist, erdist,
4042 _wire+(geo->Id()), rechit.rechitptr));
4043 // inner/outer layer :
4044 rStat[ind]++;
4045 if (inlyr>ind) inlyr = ind;
4046 if (outlyr<ind) outlyr = ind;
4047 }
4048 if (debug_ == 4)
4049 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
4050
4051 // Empty layers :
4052 int empty_between(0), empty(0);
4053 for (int i= inlyr; i <= outlyr; i++)
4054 if (!rStat[i]) empty_between++;
4055 empty = empty_between+inlyr+(42-outlyr);
4056 delete [] rStat;
4057
4058 // RMK high momentum track under study, probably not neeeded...
4059 track_lead.order_wirhit(1);
4060 //track_lead.order_hits();
4061
4062 for(std::vector<KalFitHitMdc>::iterator it_hit = track_lead.HitsMdc().begin(); it_hit!=track_lead.HitsMdc().end(); it_hit++){
4063 //std::cout<<" the id of this hits after sorting in PatRec is "<<it_hit->id()<<std::endl;
4064 //std::cout<<" the layerid of the hit is "<<it_hit->wire().layer().layerId()<<std::endl;
4065 //std::cout<<" the cellid of this wire is "<<it_hit->wire().localId()<<std::endl;
4066 }
4067
4068 track_lead.type(type);
4069 track_lead.trasan_id(TrasanTRK.id);
4070 unsigned int nhit = track_lead.HitsMdc().size();
4071 if (!nhit && debug_ == 4) {
4072 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
4073 continue;
4074 }
4075
4076 // Initialisation :
4077 double KalFitst(0), KalFitax(0), KalFitschi2(0);
4078 // Move to the outer hit :
4079
4080 Hep3Vector outer_pivot(track_lead.x(fiTerm));
4081 track_lead.pivot(outer_pivot);
4082
4083 track_lead.bFieldZ(KalFitTrack::Bznom_);
4084 // attention best_chi2 reinitialize !!!
4085 if (nhit>=3 && !KalFitTrack::LR_)
4086 start_seed(track_lead, lead_, way, TrasanTRK);
4087 HepSymMatrix Eakal(5,0);
4088
4089 /// very low momentum and very big costheta angle, use special initial error matrix
4090 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
4091 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
4092 choice_ = 6;
4093 }
4094
4095 /// chose different initial error matrix
4096 init_matrix(choice_,TrasanTRK, Eakal);
4097
4098
4099 if (debug_ == 4){
4100 cout << "from Mdc Pattern Recognition: " << std::endl;
4101 HepPoint3D IP(0,0,0);
4102 KalmanFit::Helix work(track_lead.pivot(),
4103 track_lead.a(),
4104 track_lead.Ea());
4105 work.pivot(IP);
4106 cout << " dr = " << work.a()[0]
4107 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4108 cout << " phi0 = " << work.a()[1]
4109 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4110 cout << " PT = " << 1/work.a()[2]
4111 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4112 cout << " dz = " << work.a()[3]
4113 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4114 cout << " tanl = " << work.a()[4]
4115 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4116 }
4117
4118 if(testOutput) {
4119 cout<<"----------------------"<<endl;//660a
4120 cout<<"track "<<l<<", pid = "<<lead_<<": "<<endl;
4121 //int n_hits=(*itRecMdcTrack)->getNhits();
4122 //int n_hit_Axis=n_hits-(*itRecMdcTrack)->nster();
4123 //cout<<"nMdcHits,nMdcHitsAxis = "<<n_hits<<", "<<n_hit_Axis<<endl;//660a
4124 //cout<<"----------------------"<<endl;
4125 //cout<<"# old track par #"<<endl<<" pivot: "<<track.pivot()<<endl<<" helix: "<<track.a()<<endl<<" error: "<<track.Ea()<<endl;
4126 //cout<<"# true track par #"<<endl<<" helix: "<<mc_a<<endl;
4127 }
4128
4129
4130 filter_fwd_anal(track_lead, lead_, way, Eakal);
4131
4132 // std::cout<<" step3, track_lead.Ea: "<<track_lead.Ea()<<std::endl;
4133 track_lead.update_forMdc();
4134
4135 HepPoint3D IP(0,0,0);
4136 if (debug_ == 4) {
4137 cout << " Mdc FIRST KALMAN FIT " << std::endl;
4138 KalmanFit::Helix work(track_lead.pivot(),
4139 track_lead.a(),
4140 track_lead.Ea());
4141 work.pivot(IP);
4142 cout << " dr = " << work.a()[0]
4143 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4144 cout << " phi0 = " << work.a()[1]
4145 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4146 cout << " PT = " << 1/work.a()[2]
4147 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4148 cout << " dz = " << work.a()[3]
4149 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4150 cout << " tanl = " << work.a()[4]
4151 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4152 }
4153
4154 // fill TDS
4155 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
4156 kaltrk->setTrackId(TrasanTRK.id);
4157 // Complete the track (other mass assumption, backward) and
4158 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol,1);
4159 }// loop mdc tracks
4160
4161
4162 IDataProviderSvc* eventSvc = NULL;
4163 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
4164 if (eventSvc) {
4165 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
4166 } else {
4167 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
4168 return ;
4169 }
4170 StatusCode kalsc;
4171 IDataManagerSvc *dataManSvc;
4172 dataManSvc= dynamic_cast<IDataManagerSvc*>(eventSvc);
4173 DataObject *aKalTrackCol;
4174 eventSvc->findObject("/Event/Recon/RecMdcKalTrackCol",aKalTrackCol);
4175 if(aKalTrackCol != NULL) {
4176 dataManSvc->clearSubTree("/Event/Recon/RecMdcKalTrackCol");
4177 eventSvc->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
4178 }
4179 kalsc = eventSvc->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
4180 if( kalsc.isFailure() ) {
4181 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
4182 return ;
4183 }
4184 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
4185 StatusCode segsc;
4186 //check whether the RecMdcKalHelixSegCol has been already registered
4187 DataObject *aRecKalSegEvent;
4188 eventSvc->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
4189 if(aRecKalSegEvent!=NULL) {
4190 //then unregister RecMdcKalHelixSegCol
4191 segsc = eventSvc->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
4192 if(segsc != StatusCode::SUCCESS) {
4193 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
4194 return;
4195 }
4196 }
4197 segsc = eventSvc->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
4198 if( segsc.isFailure() ) {
4199 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
4200 return;
4201 }
4202 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
4203
4204 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.);
4205 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0),tanl2(0.);
4206 double px1(0.),px2(0.),py1(0.),py2(0.),pz1(0.),pz2(0.),charge1(0.),charge2(0.);
4207
4208 //check the result:RecMdcKalTrackCol
4209 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc,"/Event/Recon/RecMdcKalTrackCol");
4210 if (!kaltrkCol) {
4211 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
4212 return;
4213 }
4214 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
4215 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
4216 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
4217 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
4218 << "Track Id: " << (*iter_trk)->getTrackId()
4219 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
4220 << " Length of the track: "<< (*iter_trk)->getLength(2)
4221 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
4222 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
4223 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
4224 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,2)
4225 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
4226 << "Kappa " << (*iter_trk)->getZHelix()[2]
4227 << endreq;
4228 for( int i = 0; i<43; i++) {
4229 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
4230 << (*iter_trk)->getPathl(i) <<endreq;
4231 }
4232 if(ntuple_&1) {
4233 m_trackid = (*iter_trk)->getTrackId();
4234
4235 for( int jj =0, iii=0; jj<5; jj++) {
4236
4237 m_length[jj] = (*iter_trk)->getLength(jj);
4238 m_tof[jj] = (*iter_trk)->getTof(jj);
4239 m_nhits[jj] = (*iter_trk)->getNhits(jj);
4240 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
4241 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
4242 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
4243 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
4244 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
4245 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
4246 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
4247 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
4248 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
4249 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
4250 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
4251 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
4252 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
4253 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
4254 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
4255
4256 if(ntuple_&32) {
4257 for(int kk=0; kk<=jj; kk++,iii++) {
4258 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
4259 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
4260 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
4261 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
4262 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
4263 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
4264 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
4265 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
4266 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
4267 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
4268 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
4269 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
4270 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
4271 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
4272 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
4273 }
4274 }
4275 }
4276
4277 // // the following logic may seem peculiar, but it IS the case(for BOSS5.0 and BOSS5.1)
4278 // m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4279 // m_chisq[0][1] = (*iter_trk)->getChisq(0,1);
4280 // m_chisq[1][0] = (*iter_trk)->getChisq(0,2);
4281 // m_chisq[1][1] = (*iter_trk)->getChisq(0,3);
4282 // m_chisq[2][0] = (*iter_trk)->getChisq(0,4);
4283 // m_chisq[2][1] = (*iter_trk)->getChisq(1,0);
4284 // m_chisq[3][0] = (*iter_trk)->getChisq(1,1);
4285 // m_chisq[3][1] = (*iter_trk)->getChisq(1,2);
4286 // m_chisq[4][0] = (*iter_trk)->getChisq(1,3);
4287 // m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4288
4289 // m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4290 // m_ndf[0][1] = (*iter_trk)->getNdf(0,1);
4291 // m_ndf[1][0] = (*iter_trk)->getNdf(0,2);
4292 // m_ndf[1][1] = (*iter_trk)->getNdf(0,3);
4293 // m_ndf[2][0] = (*iter_trk)->getNdf(0,4);
4294 // m_ndf[2][1] = (*iter_trk)->getNdf(1,0);
4295 // m_ndf[3][0] = (*iter_trk)->getNdf(1,1);
4296 // m_ndf[3][1] = (*iter_trk)->getNdf(1,2);
4297 // m_ndf[4][0] = (*iter_trk)->getNdf(1,3);
4298 // m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4299
4300 // m_stat[0][0] = (*iter_trk)->getStat(0,0);
4301 // m_stat[0][1] = (*iter_trk)->getStat(0,1);
4302 // m_stat[1][0] = (*iter_trk)->getStat(0,2);
4303 // m_stat[1][1] = (*iter_trk)->getStat(0,3);
4304 // m_stat[2][0] = (*iter_trk)->getStat(0,4);
4305 // m_stat[2][1] = (*iter_trk)->getStat(1,0);
4306 // m_stat[3][0] = (*iter_trk)->getStat(1,1);
4307 // m_stat[3][1] = (*iter_trk)->getStat(1,2);
4308 // m_stat[4][0] = (*iter_trk)->getStat(1,3);
4309 // m_stat[4][1] = (*iter_trk)->getStat(1,4);
4310
4311 // RootConversion changed in BOSS6.0, so use thefollowing:
4312 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4313 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
4314 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
4315 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
4316 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
4317 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
4318 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
4319 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
4320 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
4321 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4322
4323 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4324 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
4325 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
4326 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
4327 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
4328 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
4329 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
4330 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
4331 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
4332 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4333
4334 m_stat[0][0] = (*iter_trk)->getStat(0,0);
4335 m_stat[1][0] = (*iter_trk)->getStat(0,1);
4336 m_stat[2][0] = (*iter_trk)->getStat(0,2);
4337 m_stat[3][0] = (*iter_trk)->getStat(0,3);
4338 m_stat[4][0] = (*iter_trk)->getStat(0,4);
4339 m_stat[0][1] = (*iter_trk)->getStat(1,0);
4340 m_stat[1][1] = (*iter_trk)->getStat(1,1);
4341 m_stat[2][1] = (*iter_trk)->getStat(1,2);
4342 m_stat[3][1] = (*iter_trk)->getStat(1,3);
4343 m_stat[4][1] = (*iter_trk)->getStat(1,4);
4344
4345 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
4346 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
4347 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
4348 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
4349 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
4350
4351 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
4352 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
4353 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
4354 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
4355 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
4356
4357 m_lpt = 1/m_lhelix[2];
4358 m_lpte = 1/m_lhelixe[2];
4359 m_lptmu = 1/m_lhelixmu[2];
4360 m_lptk = 1/m_lhelixk[2];
4361 m_lptp = 1/m_lhelixp[2];
4362
4363 m_fpt = 1/m_fhelix[2];
4364 m_fpte = 1/m_fhelixe[2];
4365 m_fptmu = 1/m_fhelixmu[2];
4366 m_fptk = 1/m_fhelixk[2];
4367 m_fptp = 1/m_fhelixp[2];
4368
4369 if(debug_ >= 3){
4370 std::cout<<" "<<std::endl;
4371 std::cout<<"in file Kalman_fitting_anal ,the m_fpt is .."<<m_fpt<<std::endl;
4372 std::cout<<"in file Kalman_fitting_anal ,the m_fpte is .."<<m_fpte<<std::endl;
4373 std::cout<<"in file Kalman_fitting_anal ,the m_fptmu is .."<<m_fptmu<<std::endl;
4374 std::cout<<"in file Kalman_fitting_anal ,the m_fptk is .."<<m_fptk<<std::endl;
4375 std::cout<<"in file Kalman_fitting_anal ,the m_fptp is .."<<m_fptp<<std::endl;
4376 }
4377
4378 m_zpt = 1/m_zhelix[2];
4379 m_zpte = 1/m_zhelixe[2];
4380 m_zptmu = 1/m_zhelixmu[2];
4381 m_zptk = 1/m_zhelixk[2];
4382 m_zptp = 1/m_zhelixp[2];
4383
4384 if(debug_ >= 3) {
4385 std::cout<<"in file Kalman_fitting_anal ,the m_zpt is .."<<m_zpt<<std::endl;
4386 std::cout<<"in file Kalman_fitting_anal ,the m_zpte is .."<<m_zpte<<std::endl;
4387 std::cout<<"in file Kalman_fitting_anal ,the m_zptmu is .."<<m_zptmu<<std::endl;
4388 std::cout<<"in file Kalman_fitting_anal ,the m_zptk is .."<<m_zptk<<std::endl;
4389 std::cout<<"in file Kalman_fitting_anal ,the m_zptp is .."<<m_zptp<<std::endl;
4390 }
4391 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
4392 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
4393 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
4394 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
4395 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
4396
4397 if(debug_ >= 3) {
4398 std::cout<<"in file Kalman_fitting_anal ,the m_zptot is .."<<m_zptot<<std::endl;
4399 std::cout<<"in file Kalman_fitting_anal ,the m_zptote is .."<<m_zptote<<std::endl;
4400 std::cout<<"in file Kalman_fitting_anal ,the m_zptotmu is .."<<m_zptotmu<<std::endl;
4401 std::cout<<"in file Kalman_fitting_anal ,the m_zptotk is .."<<m_zptotk<<std::endl;
4402 std::cout<<"in file Kalman_fitting_anal ,the m_zptotp is .."<<m_zptotp<<std::endl;
4403 }
4404
4405 if(ntuple_&32) {
4406 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
4407 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
4408 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
4409 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
4410 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
4411 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
4412 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
4413 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
4414 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
4415 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
4416 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
4417 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
4418 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
4419 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
4420 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
4421 }
4422
4423 StatusCode sc1 = m_nt1->write();
4424 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
4425 }
4426
4427 if(ntuple_&4) {
4428 if(jj == 1) {
4429 phi1 = (*iter_trk)->getFFi0();
4430 r1 = (*iter_trk)->getFDr();
4431 z1 = (*iter_trk)->getFDz();
4432 kap1 = (*iter_trk)->getFCpa();
4433 tanl1 = (*iter_trk)->getFTanl();
4434 charge1 = kap1/fabs(kap1);
4435 x1 = r1*cos(phi1);
4436 y1 = r1*sin(phi1);
4437 p1 = sqrt(1+tanl1*tanl1)/kap1;
4438 the1 = M_PI/2-atan(tanl1);
4439 px1 = -sin(phi1)/fabs(kap1);
4440 py1 = cos(phi1)/fabs(kap1);
4441 pz1= tanl1/fabs(kap1);
4442
4443 } else if(jj == 2) {
4444 phi2 = (*iter_trk)->getFFi0();
4445 r2 = (*iter_trk)->getFDr();
4446 z2 = (*iter_trk)->getFDz();
4447 kap2 = (*iter_trk)->getFCpa();
4448 tanl2 = (*iter_trk)->getFTanl();
4449 charge2 = kap2/fabs(kap2);
4450 x2 = r1*cos(phi2);
4451 y2 = r1*sin(phi2);
4452 p2 = sqrt(1+tanl2*tanl2)/kap1;
4453 the2 = M_PI/2-atan(tanl2);
4454 px2 = -sin(phi2)/fabs(kap2);
4455 py2 = cos(phi2)/fabs(kap2);
4456 pz2= tanl2/fabs(kap2);
4457 }
4458 }
4459 }
4460 if(ntuple_&4) {
4461 m_delx = x1 - x2;
4462 m_dely = y1 - y2;
4463 m_delz = z1 - z2;
4464 m_delthe = the1 + the2;
4465 m_delphi = phi1- phi2;
4466 m_delp = p1 - p2;
4467 m_delpx = charge1*fabs(px1) + charge2*fabs(px2);
4468 m_delpy = charge1*fabs(py1) + charge2*fabs(py2);
4469 m_delpz = charge1*fabs(pz1) + charge2*fabs(pz2);
4470
4471 StatusCode sc2 = m_nt2->write();
4472 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
4473 }
4474
4475 delete [] order;
4476 delete [] rCont;
4477 delete [] rGen;
4478 delete [] rOM;
4479
4480 if (debug_ == 4)
4481 cout << "Kalfitting finished " << std::endl;
4482 //cout << "kalman fitting end" << endl;
4483}
4484
4486{
4487
4488 MsgStream log(msgSvc(), name());
4489 double Pt_threshold(0.3);
4490 Hep3Vector IP(0,0,0);
4491
4492 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
4493 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
4494 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
4495
4496 // Table Manager
4497 if ( !&whMgr ) return;
4498
4499 // Get reduced chi**2 of Mdc track :
4500 int ntrk = mdcMgr->size();
4501 double* rPt = new double[ntrk];
4502 int* rOM = new int[ntrk];
4503 unsigned int* order = new unsigned int[ntrk];
4504 unsigned int* rCont = new unsigned int[ntrk];
4505 unsigned int* rGen = new unsigned int[ntrk];
4506
4507 int index = 0;
4508 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
4509 end = mdcMgr->end(); it != end; it++) {
4510 // Pt
4511 rPt[index] = 0;
4512 if (it->helix[2])
4513 rPt[index] = 1 / fabs(it->helix[2]);
4514 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
4515 if(rPt[index] < 0) rPt[index] = DBL_MAX;
4516 // Outermost layer
4517 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
4518 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
4519 int outermost(-1);
4520 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4521 ii !=pt.begin()-1; ii--) {
4522 int lyr((*ii)->geo->Lyr()->Id());
4523 if (outermost < lyr) outermost = lyr;
4524 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
4525 }
4526 rOM[index] = outermost;
4527 order[index] = index;
4528 ++index;
4529 }
4530
4531 // Sort Mdc tracks by Pt
4532 for (int j, k = ntrk - 1; k >= 0; k = j){
4533 j = -1;
4534 for(int i = 1; i <= k; i++)
4535 if(rPt[i - 1] < rPt[i]){
4536 j = i - 1;
4537 std::swap(order[i], order[j]);
4538 std::swap(rPt[i], rPt[j]);
4539 std::swap(rOM[i], rOM[j]);
4540 std::swap(rCont[i], rCont[j]);
4541 std::swap(rGen[i], rGen[j]);
4542 }
4543 }
4544 delete [] rPt;
4545 //
4546 int newcount(0);
4547 //check whether Recon already registered
4548 DataObject *aReconEvent;
4549 eventSvc()->findObject("/Event/Recon",aReconEvent);
4550 if(!aReconEvent) {
4551 // register ReconEvent Data Object to TDS;
4552 ReconEvent* recevt = new ReconEvent;
4553 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
4554 if(sc!=StatusCode::SUCCESS) {
4555 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
4556 return;
4557 }
4558 }
4559
4560 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
4562 //make RecMdcKalTrackCol
4563 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
4564
4565 // Loop over tracks given by PatRecon :
4566 for(int l = 0; l < ntrk; l++) {
4567 // m_timer[3]->start();
4568 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[l]);
4569 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[l]);
4570
4571 // Reject the ones with quality != 0
4572 int trasqual = TrasanTRK_add.quality;
4573 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
4574 if (trasqual) continue;
4575
4576 newcount++;
4577 if (debug_ == 4)
4578 cout << "******* KalFit NUMBER : " << newcount << std::endl;
4579
4580 // What kind of KalFit ?
4581 int type(0);
4582 if ((TrasanTRK_add.decision & 32) == 32 ||
4583 (TrasanTRK_add.decision & 64) == 64) type = 1;
4584
4585 // Initialisation : (x, a, ea)
4586 HepPoint3D x(TrasanTRK.pivot[0],
4587 TrasanTRK.pivot[1],
4588 TrasanTRK.pivot[2]);
4589
4590 HepVector a(5);
4591 for(int i = 0; i < 5; i++)
4592 a[i] = TrasanTRK.helix[i];
4593
4594 HepSymMatrix ea(5);
4595 for(int i = 0, k = 0; i < 5; i++) {
4596 for(int j = 0; j <= i; j++) {
4597 ea[i][j] = matrixg_*TrasanTRK.error[k++];
4598 ea[j][i] = ea[i][j];
4599 }
4600 }
4601
4603
4604 double fiTerm = TrasanTRK.fiTerm;
4605 int way(1);
4606 // Prepare the track found :
4607 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
4608 track_lead.bFieldZ(KalFitTrack::Bznom_);
4609 // Mdc Hits
4610 int inlyr(999), outlyr(-1);
4611 int* rStat = new int[43];
4612 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
4613 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
4614 int hit_in(0);
4615 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
4616 // Number of hits/layer
4617 int Num[43] = {0};
4618 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4619 ii != pt.begin()-1; ii--) {
4620 Num[(*ii)->geo->Lyr()->Id()]++;
4621 }
4622
4623 int hit_asso(0);
4624 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
4625 ii != pt.begin()-1; ii--) {
4626
4627 hit_asso++;
4628 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
4629 if (debug_ ==4)
4630 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
4631 << " hits in the layer "
4632 << (*ii)->geo->Lyr()->Id() << std::endl;
4633 continue;
4634 }
4635 // if(ii!=pt.end()-1){
4636 // if(42 == (*ii)->geo->Lyr()->Id() && 42 == (*(ii+1))->geo->Lyr()->Id()){
4637 // MdcRec_wirhit * rechit_before = *(ii+1);
4638 // if((*rechit_before).tdc < (**ii).tdc) continue;
4639 // else if(track_lead.HitsMdc().size()>0 && rStat[42]){
4640 // track_lead.HitsMdc().pop_back();
4641 // }
4642 // }
4643 // else{
4644 // int layer_before=(*(ii+1))->geo->Lyr()->Id();
4645 // if(layer_before == (*ii)->geo->Lyr()->Id()){
4646 // MdcRec_wirhit * rechit_before = *(ii+1);
4647 // if((*rechit_before).rechitptr->getDriftT()>450 || (**ii).rechitptr->getDriftT()>450.){
4648 // if((*rechit_before).tdc < (**ii).tdc) continue;
4649 // else if(track_lead.HitsMdc().size()>0 && rStat[layer_before]){
4650 // track_lead.HitsMdc().pop_back();
4651 // }
4652 // }
4653 // }
4654 // }
4655 // }
4656
4657 hit_in++;
4658 MdcRec_wirhit & rechit = **ii;
4659 double dist[2] = {rechit.ddl, rechit.ddr};
4660 double erdist[2] = {rechit.erddl, rechit.erddr};
4661 const MdcGeoWire* geo = rechit.geo;
4662
4663 int lr_decision(0);
4664 if (KalFitTrack::LR_ == 1){
4665 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
4666 // if (rechit.lr==0) lr_decision=-1;
4667 else if (rechit.lr==1) lr_decision=1;
4668 }
4669
4670 int ind(geo->Lyr()->Id());
4671 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
4672 lr_decision, rechit.tdc,
4673 dist, erdist,
4674 _wire+(geo->Id()), rechit.rechitptr));
4675 // inner/outer layer :
4676 rStat[ind]++;
4677 if (inlyr>ind) inlyr = ind;
4678 if (outlyr<ind) outlyr = ind;
4679 }
4680 if (debug_ == 4)
4681 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
4682
4683 // Empty layers :
4684 int empty_between(0), empty(0);
4685 for (int i= inlyr; i <= outlyr; i++)
4686 if (!rStat[i]) empty_between++;
4687 empty = empty_between+inlyr+(42-outlyr);
4688 delete [] rStat;
4689
4690 // RMK high momentum track under study, probably not neeeded...
4691 track_lead.order_wirhit(1);
4692 track_lead.type(type);
4693 unsigned int nhit = track_lead.HitsMdc().size();
4694 if (!nhit && debug_ == 4) {
4695 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
4696 continue;
4697 }
4698
4699 // Initialisation :
4700 double KalFitst(0), KalFitax(0), KalFitschi2(0);
4701 // Move to the outer most hit :
4702 Hep3Vector outer_pivot(track_lead.x(fiTerm));
4703
4704 if(debug_ == 4) {
4705 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
4706 }
4707 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
4708 track_lead.bFieldZ(KalFitTrack::Bznom_);
4709 // attention best_chi2 reinitialize !!!
4710 if (nhit>=3 && !KalFitTrack::LR_)
4711 start_seed(track_lead, lead_, way, TrasanTRK);
4712 HepSymMatrix Eakal(5,0);
4713
4714 //init_matrix(TrasanTRK, Eakal);
4715
4716 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
4717 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
4718 choice_ = 6;
4719 }
4720
4721 init_matrix(choice_,TrasanTRK, Eakal);
4722
4723 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
4724
4725 if (debug_ == 4){
4726 std::cout << "from Mdc Pattern Recognition: " << std::endl;
4727 HepPoint3D IP(0,0,0);
4728 KalmanFit::Helix work(track_lead.pivot(),
4729 track_lead.a(),
4730 track_lead.Ea());
4731 work.pivot(IP);
4732 std::cout << " dr = " << work.a()[0]
4733 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4734 std::cout << " phi0 = " << work.a()[1]
4735 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4736 std::cout << " PT = " << 1/work.a()[2]
4737 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4738 std::cout << " dz = " << work.a()[3]
4739 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4740 std::cout << " tanl = " << work.a()[4]
4741 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4742 }
4743
4744 filter_fwd_calib(track_lead, lead_, way, Eakal);
4745 track_lead.update_forMdc();
4746
4747 HepPoint3D IP(0,0,0);
4748 if (debug_ == 4) {
4749 cout << " Mdc FIRST KALMAN FIT " << std::endl;
4750 KalmanFit::Helix work(track_lead.pivot(),
4751 track_lead.a(),
4752 track_lead.Ea());
4753 work.pivot(IP);
4754 cout << " dr = " << work.a()[0]
4755 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
4756 cout << " phi0 = " << work.a()[1]
4757 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
4758 cout << " PT = " << 1/work.a()[2]
4759 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
4760 cout << " dz = " << work.a()[3]
4761 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
4762 cout << " tanl = " << work.a()[4]
4763 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
4764 }
4765
4766 // fill TDS
4767 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
4768
4769 // Complete the track (other mass assumption, backward) and
4770 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
4771 }
4772
4773
4774 StatusCode kalsc;
4775 //check whether the RecMdcKalTrackCol has been already registered
4776 DataObject *aRecKalEvent;
4777 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
4778 if(aRecKalEvent!=NULL) {
4779 //then unregister RecMdcKalCol
4780 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
4781 if(kalsc != StatusCode::SUCCESS) {
4782 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
4783 return;
4784 }
4785 }
4786
4787 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
4788 if( kalsc.isFailure()) {
4789 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
4790 return;
4791 }
4792 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
4793
4794
4795
4796 StatusCode segsc;
4797 //check whether the RecMdcKalHelixSegCol has been already registered
4798 DataObject *aRecKalSegEvent;
4799 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
4800 if(aRecKalSegEvent!=NULL) {
4801 //then unregister RecMdcKalHelixSegCol
4802 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
4803 if(segsc != StatusCode::SUCCESS) {
4804 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
4805 return;
4806 }
4807 }
4808
4809 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
4810 if( segsc.isFailure() ) {
4811 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
4812 return;
4813 }
4814 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
4815
4816
4817 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.);
4818 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
4819 //check the result:RecMdcKalTrackCol
4820
4821 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
4822 if (!kaltrkCol) {
4823 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
4824 return;
4825 }
4826 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
4827 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
4828 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
4829 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
4830 << "Track Id: " << (*iter_trk)->getTrackId()
4831 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
4832 << " Length of the track: "<< (*iter_trk)->getLength(2)
4833 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
4834 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
4835 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
4836 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
4837 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
4838 << "Kappa " << (*iter_trk)->getZHelix()[2]
4839 << endreq;
4840
4841 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
4842 if(debug_ == 4) {
4843 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
4844 }
4845
4846 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
4847 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
4848 if(debug_ == 4) {
4849 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
4850 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
4851 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
4852 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
4853 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
4854 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
4855 }
4856 }
4857 for( int i = 0; i<43; i++) {
4858 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
4859 << (*iter_trk)->getPathl(i) <<endreq;
4860 }
4861
4862 if(ntuple_&1) {
4863 m_trackid = (*iter_trk)->getTrackId();
4864 for( int jj =0, iii=0; jj<5; jj++) {
4865 m_length[jj] = (*iter_trk)->getLength(jj);
4866 m_tof[jj] = (*iter_trk)->getTof(jj);
4867 m_nhits[jj] = (*iter_trk)->getNhits(jj);
4868 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
4869 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
4870 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
4871 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
4872 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
4873 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
4874 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
4875 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
4876 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
4877 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
4878 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
4879 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
4880 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
4881 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
4882 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
4883 if(ntuple_&32) {
4884 for(int kk=0; kk<=jj; kk++,iii++) {
4885 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
4886 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
4887 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
4888 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
4889 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
4890 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
4891 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
4892 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
4893 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
4894 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
4895 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
4896 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
4897 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
4898 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
4899 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
4900 }
4901
4902 }
4903 }
4904
4905 // // the following logic may seem peculiar, but it IS the case(for BOSS5.0 and BOSS5.1)
4906 // m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4907 // m_chisq[0][1] = (*iter_trk)->getChisq(0,1);
4908 // m_chisq[1][0] = (*iter_trk)->getChisq(0,2);
4909 // m_chisq[1][1] = (*iter_trk)->getChisq(0,3);
4910 // m_chisq[2][0] = (*iter_trk)->getChisq(0,4);
4911 // m_chisq[2][1] = (*iter_trk)->getChisq(1,0);
4912 // m_chisq[3][0] = (*iter_trk)->getChisq(1,1);
4913 // m_chisq[3][1] = (*iter_trk)->getChisq(1,2);
4914 // m_chisq[4][0] = (*iter_trk)->getChisq(1,3);
4915 // m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4916
4917 // m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4918 // m_ndf[0][1] = (*iter_trk)->getNdf(0,1);
4919 // m_ndf[1][0] = (*iter_trk)->getNdf(0,2);
4920 // m_ndf[1][1] = (*iter_trk)->getNdf(0,3);
4921 // m_ndf[2][0] = (*iter_trk)->getNdf(0,4);
4922 // m_ndf[2][1] = (*iter_trk)->getNdf(1,0);
4923 // m_ndf[3][0] = (*iter_trk)->getNdf(1,1);
4924 // m_ndf[3][1] = (*iter_trk)->getNdf(1,2);
4925 // m_ndf[4][0] = (*iter_trk)->getNdf(1,3);
4926 // m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4927
4928 // m_stat[0][0] = (*iter_trk)->getStat(0,0);
4929 // m_stat[0][1] = (*iter_trk)->getStat(0,1);
4930 // m_stat[1][0] = (*iter_trk)->getStat(0,2);
4931 // m_stat[1][1] = (*iter_trk)->getStat(0,3);
4932 // m_stat[2][0] = (*iter_trk)->getStat(0,4);
4933 // m_stat[2][1] = (*iter_trk)->getStat(1,0);
4934 // m_stat[3][0] = (*iter_trk)->getStat(1,1);
4935 // m_stat[3][1] = (*iter_trk)->getStat(1,2);
4936 // m_stat[4][0] = (*iter_trk)->getStat(1,3);
4937 // m_stat[4][1] = (*iter_trk)->getStat(1,4);
4938
4939 // RootConversion changed in BOSS6.0, so use thefollowing:
4940 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
4941 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
4942 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
4943 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
4944 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
4945 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
4946 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
4947 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
4948 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
4949 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
4950
4951 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
4952 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
4953 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
4954 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
4955 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
4956 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
4957 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
4958 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
4959 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
4960 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
4961
4962 m_stat[0][0] = (*iter_trk)->getStat(0,0);
4963 m_stat[1][0] = (*iter_trk)->getStat(0,1);
4964 m_stat[2][0] = (*iter_trk)->getStat(0,2);
4965 m_stat[3][0] = (*iter_trk)->getStat(0,3);
4966 m_stat[4][0] = (*iter_trk)->getStat(0,4);
4967 m_stat[0][1] = (*iter_trk)->getStat(1,0);
4968 m_stat[1][1] = (*iter_trk)->getStat(1,1);
4969 m_stat[2][1] = (*iter_trk)->getStat(1,2);
4970 m_stat[3][1] = (*iter_trk)->getStat(1,3);
4971 m_stat[4][1] = (*iter_trk)->getStat(1,4);
4972
4973 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
4974 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
4975 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
4976 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
4977 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
4978
4979 m_zpt = 1/m_zhelix[2];
4980 m_zpte = 1/m_zhelixe[2];
4981 m_zptmu = 1/m_zhelixmu[2];
4982 m_zptk = 1/m_zhelixk[2];
4983 m_zptp = 1/m_zhelixp[2];
4984
4985 m_fpt = 1/m_fhelix[2];
4986 m_fpte = 1/m_fhelixe[2];
4987 m_fptmu = 1/m_fhelixmu[2];
4988 m_fptk = 1/m_fhelixk[2];
4989 m_fptp = 1/m_fhelixp[2];
4990
4991 m_lpt = 1/m_lhelix[2];
4992 m_lpte = 1/m_lhelixe[2];
4993 m_lptmu = 1/m_lhelixmu[2];
4994 m_lptk = 1/m_lhelixk[2];
4995 m_lptp = 1/m_lhelixp[2];
4996
4997 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
4998 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
4999 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
5000 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
5001 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
5002
5003 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
5004 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
5005 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
5006 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
5007 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
5008 if(ntuple_&32) {
5009 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
5010 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
5011 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
5012 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
5013 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
5014 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
5015 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
5016 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
5017 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
5018 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
5019 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
5020 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
5021 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
5022 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
5023 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
5024 }
5025
5026 StatusCode sc1 = m_nt1->write();
5027 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
5028 }
5029
5030 if(ntuple_&4) {
5031 if(jj == 1) {
5032 phi1 = (*iter_trk)->getFFi0();
5033 r1 = (*iter_trk)->getFDr();
5034 z1 = (*iter_trk)->getFDz();
5035 kap1 = (*iter_trk)->getFCpa();
5036 tanl1 = (*iter_trk)->getFTanl();
5037 x1 = r1*cos(phi1);
5038 y1 = r1*sin(phi1);
5039 p1 = sqrt(1+tanl1*tanl1)/kap1;
5040 the1 = M_PI/2-atan(tanl1);
5041 } else if(jj == 2) {
5042 phi2 = (*iter_trk)->getFFi0();
5043 r2 = (*iter_trk)->getFDr();
5044 z2 = (*iter_trk)->getFDz();
5045 kap2 = (*iter_trk)->getFCpa();
5046 tanl2 = (*iter_trk)->getFTanl();
5047 x2 = r1*cos(phi2);
5048 y2 = r1*sin(phi2);
5049 p2 = sqrt(1+tanl2*tanl2)/kap1;
5050 the2 = M_PI/2-atan(tanl2);
5051 }
5052 }
5053 }
5054 if(ntuple_&4) {
5055 m_delx = x1 - x2;
5056 m_dely = y1 - y2;
5057 m_delz = z1 - z2;
5058 m_delthe = the1 + the2;
5059 m_delphi = phi1- phi2;
5060 m_delp = p1 - p2;
5061 StatusCode sc2 = m_nt2->write();
5062 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
5063 }
5064 delete [] order;
5065 delete [] rCont;
5066 delete [] rGen;
5067 delete [] rOM;
5068
5069 if (debug_ == 4)
5070 cout << "Kalfitting finished " << std::endl;
5071}
5072
5073//Mdc alignment by MdcxReco_Csmc_Sew
5075{
5076
5077 MsgStream log(msgSvc(), name());
5078 double Pt_threshold(0.3);
5079 Hep3Vector IP(0,0,0);
5080
5081 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
5082 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
5083 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
5084
5085 // Table Manager
5086 if ( !&whMgr ) return;
5087
5088 // Get reduced chi**2 of Mdc track :
5089 int ntrk = mdcMgr->size();
5090 // cout<<"ntrk: "<<ntrk<<endl;
5091
5092 int nhits = whMgr->size();
5093 //cout<<"nhits: "<<nhits<<endl;
5094
5095
5096 //check whether Recon already registered
5097 DataObject *aReconEvent;
5098 eventSvc()->findObject("/Event/Recon",aReconEvent);
5099 if(!aReconEvent) {
5100 // register ReconEvent Data Object to TDS;
5101 ReconEvent* recevt = new ReconEvent;
5102 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
5103 if(sc!=StatusCode::SUCCESS) {
5104 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
5105 return;
5106 }
5107 }
5108
5109 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
5111 //make RecMdcKalTrackCol
5112 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
5113
5114
5115 MdcRec_trk& TrasanTRK = *(mdcMgr->begin());
5116 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin());
5117 // Reject the ones with quality != 0
5118 // int trasqual = TrasanTRK_add.quality;
5119 // if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5120 // if (trasqual) continue;
5121
5122 // What kind of KalFit ?
5123 int type(0);
5124 if ((TrasanTRK_add.decision & 32) == 32 ||
5125 (TrasanTRK_add.decision & 64) == 64) type = 1;
5126
5127 // Initialisation : (x, a, ea)
5128 HepPoint3D x(TrasanTRK.pivot[0],
5129 TrasanTRK.pivot[1],
5130 TrasanTRK.pivot[2]);
5131
5132 HepVector a(5);
5133 for(int i = 0; i < 5; i++)
5134 a[i] = TrasanTRK.helix[i];
5135
5136 HepSymMatrix ea(5);
5137 for(int i = 0, k = 0; i < 5; i++) {
5138 for(int j = 0; j <= i; j++) {
5139 ea[i][j] = matrixg_*TrasanTRK.error[k++];
5140 ea[j][i] = ea[i][j];
5141 }
5142 }
5143
5145
5146 double fiTerm = TrasanTRK.fiTerm;
5147 int way(1);
5148 // Prepare the track found :
5149 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
5150 track_lead.bFieldZ(KalFitTrack::Bznom_);
5151
5152 int hit_asso(0);
5153 // Reject the ones with quality != 0
5154 int trasqual = TrasanTRK_add.quality;
5155 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5156 if (trasqual) return;
5157 // Mdc Hits
5158 int inlyr(999), outlyr(-1);
5159 int* rStat = new int[43];
5160 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
5161 std::vector<MdcRec_wirhit*> pt=TrasanTRK.hitcol;
5162 int hit_in(0);
5163 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
5164 // Number of hits/layer
5165 int Num[43] = {0};
5166 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5167 ii != pt.begin()-1; ii--) {
5168 Num[(*ii)->geo->Lyr()->Id()]++;
5169 }
5170
5171 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5172 ii != pt.begin()-1; ii--) {
5173
5174 hit_asso++;
5175 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
5176 if (debug_ ==4)
5177 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
5178 << " hits in the layer "
5179 << (*ii)->geo->Lyr()->Id() << std::endl;
5180 continue;
5181 }
5182
5183 hit_in++;
5184 MdcRec_wirhit & rechit = **ii;
5185 double dist[2] = {rechit.ddl, rechit.ddr};
5186 double erdist[2] = {rechit.erddl, rechit.erddr};
5187 const MdcGeoWire* geo = rechit.geo;
5188
5189 int lr_decision(0);
5190 if (KalFitTrack::LR_ == 1){
5191 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
5192 // if (rechit.lr==0) lr_decision=-1;
5193 else if (rechit.lr==1) lr_decision=1;
5194 }
5195
5196 int ind(geo->Lyr()->Id());
5197 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
5198 lr_decision, rechit.tdc,
5199 dist, erdist,
5200 _wire+(geo->Id()), rechit.rechitptr));
5201 // inner/outer layer :
5202 rStat[ind]++;
5203 if (inlyr>ind) inlyr = ind;
5204 if (outlyr<ind) outlyr = ind;
5205 }
5206 // Empty layers :
5207 int empty_between(0), empty(0);
5208 for (int i= inlyr; i <= outlyr; i++)
5209 if (!rStat[i]) empty_between++;
5210 empty = empty_between+inlyr+(42-outlyr);
5211 delete [] rStat;
5212
5213 if (debug_ == 4)
5214 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
5215
5216
5217 // RMK high momentum track under study, probably not neeeded...
5218 track_lead.order_wirhit(0);
5219 track_lead.type(type);
5220 unsigned int nhit = track_lead.HitsMdc().size();
5221 if (nhit<70) {
5222 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
5223 return;
5224 }
5225
5226 // Initialisation :
5227 double KalFitst(0), KalFitax(0), KalFitschi2(0);
5228 // Move to the outer most hit :
5229 Hep3Vector outer_pivot(track_lead.x(fiTerm));
5230
5231 if(debug_ == 4) {
5232 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
5233 }
5234 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
5235 track_lead.bFieldZ(KalFitTrack::Bznom_);
5236 // attention best_chi2 reinitialize !!!
5237 if (nhit>=3 && !KalFitTrack::LR_)
5238 start_seed(track_lead, lead_, way, TrasanTRK);
5239 HepSymMatrix Eakal(5,0);
5240
5241 //init_matrix(TrasanTRK, Eakal);
5242
5243 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
5244 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5245 choice_ = 6;
5246 }
5247
5248 init_matrix(choice_,TrasanTRK, Eakal);
5249
5250 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
5251
5252 if (debug_ == 4){
5253 std::cout << "from Mdc Pattern Recognition: " << std::endl;
5254 //HepPoint3D IP(0,0,0);
5255 KalmanFit::Helix work(track_lead.pivot(),
5256 track_lead.a(),
5257 track_lead.Ea());
5258 work.pivot(IP);
5259 std::cout << " dr = " << work.a()[0]
5260 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
5261 std::cout << " phi0 = " << work.a()[1]
5262 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
5263 std::cout << " PT = " << 1/work.a()[2]
5264 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
5265 std::cout << " dz = " << work.a()[3]
5266 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
5267 std::cout << " tanl = " << work.a()[4]
5268 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
5269 }
5270 filter_fwd_calib(track_lead, lead_, way, Eakal);
5271 track_lead.update_forMdc();
5272
5273 //HepPoint3D IP(0,0,0);
5274 if (debug_ == 4) {
5275 cout << " Mdc FIRST KALMAN FIT " << std::endl;
5276 KalmanFit::Helix work1(track_lead.pivot(),
5277 track_lead.a(),
5278 track_lead.Ea());
5279 work1.pivot(IP);
5280 cout << " dr = " << work1.a()[0]
5281 << ", Er_dr = " << sqrt(work1.Ea()[0][0]) << std::endl;
5282 cout << " phi0 = " << work1.a()[1]
5283 << ", Er_phi0 = " << sqrt(work1.Ea()[1][1]) << std::endl;
5284 cout << " PT = " << 1/work1.a()[2]
5285 << ", Er_kappa = " << sqrt(work1.Ea()[2][2]) << std::endl;
5286 cout << " dz = " << work1.a()[3]
5287 << ", Er_dz = " << sqrt(work1.Ea()[3][3]) << std::endl;
5288 cout << " tanl = " << work1.a()[4]
5289 << ", Er_tanl = " << sqrt(work1.Ea()[4][4]) << std::endl;
5290 }
5291
5292 // fill TDS
5293 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
5294
5295 // Complete the track (other mass assumption, backward) and
5296 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
5297
5298
5299 StatusCode kalsc;
5300 //check whether the RecMdcKalTrackCol has been already registered
5301 DataObject *aRecKalEvent;
5302 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
5303 if(aRecKalEvent!=NULL) {
5304 //then unregister RecMdcKalCol
5305 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
5306 if(kalsc != StatusCode::SUCCESS) {
5307 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
5308 return;
5309 }
5310 }
5311
5312 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
5313 if( kalsc.isFailure()) {
5314 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
5315 return;
5316 }
5317 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
5318
5319
5320
5321 StatusCode segsc;
5322 //check whether the RecMdcKalHelixSegCol has been already registered
5323 DataObject *aRecKalSegEvent;
5324 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
5325 if(aRecKalSegEvent!=NULL) {
5326 //then unregister RecMdcKalHelixSegCol
5327 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
5328 if(segsc != StatusCode::SUCCESS) {
5329 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
5330 return;
5331 }
5332 }
5333
5334 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
5335 if( segsc.isFailure() ) {
5336 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
5337 return;
5338 }
5339 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
5340
5341
5342 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.);
5343 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
5344 //check the result:RecMdcKalTrackCol
5345
5346 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
5347 if (!kaltrkCol) {
5348 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
5349 return;
5350 }
5351 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
5352 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
5353 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
5354 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
5355 << "Track Id: " << (*iter_trk)->getTrackId()
5356 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
5357 << " Length of the track: "<< (*iter_trk)->getLength(2)
5358 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
5359 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
5360 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
5361 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
5362 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
5363 << "Kappa " << (*iter_trk)->getZHelix()[2]
5364 << "zhelixmu "<<(*iter_trk)->getZHelixMu()
5365 << endreq;
5366
5367 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
5368 if(debug_ == 4) {
5369 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
5370 }
5371
5372 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
5373 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
5374 if(debug_ == 4) {
5375 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
5376 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
5377 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
5378 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
5379 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
5380 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
5381 }
5382 }
5383 for( int i = 0; i<43; i++) {
5384 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
5385 << (*iter_trk)->getPathl(i) <<endreq;
5386 }
5387
5388 if(ntuple_&1) {
5389 m_trackid = (*iter_trk)->getTrackId();
5390 for( int jj =0, iii=0; jj<5; jj++) {
5391 m_length[jj] = (*iter_trk)->getLength(jj);
5392 m_tof[jj] = (*iter_trk)->getTof(jj);
5393 m_nhits[jj] = (*iter_trk)->getNhits(jj);
5394 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
5395 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
5396 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
5397 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
5398 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
5399 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
5400 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
5401 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
5402 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
5403 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
5404 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
5405 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
5406 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
5407 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
5408 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
5409 if(ntuple_&32) {
5410 for(int kk=0; kk<=jj; kk++,iii++) {
5411 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
5412 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
5413 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
5414 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
5415 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
5416 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
5417 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
5418 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
5419 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
5420 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
5421 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
5422 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
5423 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
5424 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
5425 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
5426 }
5427
5428 }
5429 }
5430
5431 // RootConversion changed in BOSS6.0, so use thefollowing:
5432 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
5433 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
5434 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
5435 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
5436 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
5437 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
5438 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
5439 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
5440 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
5441 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
5442
5443 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
5444 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
5445 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
5446 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
5447 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
5448 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
5449 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
5450 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
5451 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
5452 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
5453
5454 m_stat[0][0] = (*iter_trk)->getStat(0,0);
5455 m_stat[1][0] = (*iter_trk)->getStat(0,1);
5456 m_stat[2][0] = (*iter_trk)->getStat(0,2);
5457 m_stat[3][0] = (*iter_trk)->getStat(0,3);
5458 m_stat[4][0] = (*iter_trk)->getStat(0,4);
5459 m_stat[0][1] = (*iter_trk)->getStat(1,0);
5460 m_stat[1][1] = (*iter_trk)->getStat(1,1);
5461 m_stat[2][1] = (*iter_trk)->getStat(1,2);
5462 m_stat[3][1] = (*iter_trk)->getStat(1,3);
5463 m_stat[4][1] = (*iter_trk)->getStat(1,4);
5464
5465 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
5466 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
5467 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
5468 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
5469 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
5470
5471 m_zpt = 1/m_zhelix[2];
5472 m_zpte = 1/m_zhelixe[2];
5473 m_zptmu = 1/m_zhelixmu[2];
5474 m_zptk = 1/m_zhelixk[2];
5475 m_zptp = 1/m_zhelixp[2];
5476
5477 m_fpt = 1/m_fhelix[2];
5478 m_fpte = 1/m_fhelixe[2];
5479 m_fptmu = 1/m_fhelixmu[2];
5480 m_fptk = 1/m_fhelixk[2];
5481 m_fptp = 1/m_fhelixp[2];
5482
5483 m_lpt = 1/m_lhelix[2];
5484 m_lpte = 1/m_lhelixe[2];
5485 m_lptmu = 1/m_lhelixmu[2];
5486 m_lptk = 1/m_lhelixk[2];
5487 m_lptp = 1/m_lhelixp[2];
5488
5489 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
5490 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
5491 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
5492 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
5493 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
5494
5495 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
5496 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
5497 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
5498 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
5499 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
5500 if(ntuple_&32) {
5501 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
5502 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
5503 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
5504 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
5505 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
5506 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
5507 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
5508 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
5509 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
5510 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
5511 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
5512 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
5513 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
5514 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
5515 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
5516 }
5517
5518 StatusCode sc1 = m_nt1->write();
5519 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
5520 }
5521
5522 if(ntuple_&4) {
5523 if(jj == 1) {
5524 phi1 = (*iter_trk)->getFFi0();
5525 r1 = (*iter_trk)->getFDr();
5526 z1 = (*iter_trk)->getFDz();
5527 kap1 = (*iter_trk)->getFCpa();
5528 tanl1 = (*iter_trk)->getFTanl();
5529 x1 = r1*cos(phi1);
5530 y1 = r1*sin(phi1);
5531 p1 = sqrt(1+tanl1*tanl1)/kap1;
5532 the1 = M_PI/2-atan(tanl1);
5533 } else if(jj == 2) {
5534 phi2 = (*iter_trk)->getFFi0();
5535 r2 = (*iter_trk)->getFDr();
5536 z2 = (*iter_trk)->getFDz();
5537 kap2 = (*iter_trk)->getFCpa();
5538 tanl2 = (*iter_trk)->getFTanl();
5539 x2 = r1*cos(phi2);
5540 y2 = r1*sin(phi2);
5541 p2 = sqrt(1+tanl2*tanl2)/kap1;
5542 the2 = M_PI/2-atan(tanl2);
5543 }
5544 }
5545 }
5546 if(ntuple_&4) {
5547 m_delx = x1 - x2;
5548 m_dely = y1 - y2;
5549 m_delz = z1 - z2;
5550 m_delthe = the1 + the2;
5551 m_delphi = phi1- phi2;
5552 m_delp = p1 - p2;
5553 StatusCode sc2 = m_nt2->write();
5554 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
5555 }
5556
5557 if (debug_ == 4)
5558 cout << "Kalfitting finished " << std::endl;
5559}
5560
5561
5562//Mdc alignment by conecting two cosmic segments for one track
5564{
5565
5566 MsgStream log(msgSvc(), name());
5567 double Pt_threshold(0.3);
5568 Hep3Vector IP(0,0,0);
5569
5570 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
5571 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
5572 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
5573
5574 // Table Manager
5575 if ( !&whMgr ) return;
5576
5577 // Get reduced chi**2 of Mdc track :
5578 int ntrk = mdcMgr->size();
5579 //cout<<"ntrk: "<<ntrk<<endl;
5580
5581 int nhits = whMgr->size();
5582 //cout<<"nhits: "<<nhits<<endl;
5583
5584
5585 double* rY = new double[ntrk];
5586 double* rfiTerm = new double[ntrk];
5587 double* rPt = new double[ntrk];
5588 int* rOM = new int[ntrk];
5589 unsigned int* order = new unsigned int[ntrk];
5590 unsigned int* rCont = new unsigned int[ntrk];
5591 unsigned int* rGen = new unsigned int[ntrk];
5592
5593 int index = 0;
5594 Hep3Vector csmp3[2];
5595 for(vector<MdcRec_trk>::iterator it = mdcMgr->begin(),
5596 end = mdcMgr->end(); it != end; it++) {
5597 //order by phi term
5598 rfiTerm[index]=it->fiTerm;
5599 //cout<<"fiTerm: "<<rfiTerm[index]<<endl;
5600 // Pt
5601 rPt[index] = 0;
5602 if (it->helix[2])
5603 rPt[index] = 1 / fabs(it->helix[2]);
5604 if(debug_ == 4) cout<<"rPt...[ "<<index<<" ]...."<< rPt[index] <<endl;
5605 if(rPt[index] < 0) rPt[index] = DBL_MAX;
5606 // Outermost layer
5607 std::vector<MdcRec_wirhit*> pt = it->hitcol ;
5608 if(debug_ == 4) cout<<"ppt size: "<< pt.size()<<endl;
5609 int outermost(-1);
5610 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5611 ii !=pt.begin()-1; ii--) {
5612 int lyr((*ii)->geo->Lyr()->Id());
5613 if (outermost < lyr) {
5614 outermost = lyr;
5615 rY[index] = (*ii)->geo->Forward().y();
5616 }
5617 if(debug_ == 4) cout<<"outmost: "<<outermost<<" lyr: "<<lyr<<endl;
5618 }
5619 rOM[index] = outermost;
5620 order[index] = index;
5621 ++index;
5622 }
5623
5624 // Sort Mdc tracks by fiTerm
5625 for (int j, k = ntrk - 1; k >= 0; k = j){
5626 j = -1;
5627 for(int i = 1; i <= k; i++)
5628 if(rY[i - 1] < rY[i]){
5629 j = i - 1;
5630 std::swap(order[i], order[j]);
5631 std::swap(rY[i], rY[j]);
5632 std::swap(rOM[i], rOM[j]);
5633 std::swap(rCont[i], rCont[j]);
5634 std::swap(rGen[i], rGen[j]);
5635 }
5636 }
5637 delete [] rPt;
5638 delete [] rY;
5639 delete [] rfiTerm;
5640 //
5641 int newcount(0);
5642 //check whether Recon already registered
5643 DataObject *aReconEvent;
5644 eventSvc()->findObject("/Event/Recon",aReconEvent);
5645 if(!aReconEvent) {
5646 // register ReconEvent Data Object to TDS;
5647 ReconEvent* recevt = new ReconEvent;
5648 StatusCode sc = eventSvc()->registerObject("/Event/Recon",recevt );
5649 if(sc!=StatusCode::SUCCESS) {
5650 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
5651 return;
5652 }
5653 }
5654
5655 RecMdcKalTrackCol* kalcol = new RecMdcKalTrackCol;
5657 //make RecMdcKalTrackCol
5658 log << MSG::INFO << "beginning to make RecMdcKalTrackCol" <<endreq;
5659
5660 // m_timer[3]->start();
5661 // MdcRec_trk& TrasanTRK;
5662 // MdcRec_trk_add& TrasanTRK_add;
5663
5664 // for(int l = 0; l < ntrk; l++) {
5665 MdcRec_trk& TrasanTRK = *(mdcMgr->begin() + order[1]);
5666 MdcRec_trk_add& TrasanTRK_add = *(mdc_addMgr->begin()+order[1]);
5667 // Reject the ones with quality != 0
5668 // int trasqual = TrasanTRK_add.quality;
5669 // if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5670 // if (trasqual) continue;
5671
5672 newcount++;
5673 if (debug_ == 4)
5674 cout << "******* KalFit NUMBER : " << newcount << std::endl;
5675
5676 // What kind of KalFit ?
5677 int type(0);
5678 if ((TrasanTRK_add.decision & 32) == 32 ||
5679 (TrasanTRK_add.decision & 64) == 64) type = 1;
5680
5681 // Initialisation : (x, a, ea)
5682 HepPoint3D x(TrasanTRK.pivot[0],
5683 TrasanTRK.pivot[1],
5684 TrasanTRK.pivot[2]);
5685
5686 HepVector a(5);
5687 for(int i = 0; i < 5; i++)
5688 a[i] = TrasanTRK.helix[i];
5689
5690 HepSymMatrix ea(5);
5691 for(int i = 0, k = 0; i < 5; i++) {
5692 for(int j = 0; j <= i; j++) {
5693 ea[i][j] = matrixg_*TrasanTRK.error[k++];
5694 ea[j][i] = ea[i][j];
5695 }
5696 }
5697
5699
5700 double fiTerm = TrasanTRK.fiTerm;
5701 int way(1);
5702 // Prepare the track found :
5703 KalFitTrack track_lead = KalFitTrack(x, a, ea, lead_, 0, 0);
5704 track_lead.bFieldZ(KalFitTrack::Bznom_);
5705
5706 int hit_asso(0);
5707 for(int l = 0; l < ntrk; l++) {
5708 MdcRec_trk& TrasanTRK1 = *(mdcMgr->begin() + order[l]);
5709 MdcRec_trk_add& TrasanTRK_add1 = *(mdc_addMgr->begin()+order[l]);
5710 // Reject the ones with quality != 0
5711 int trasqual = TrasanTRK_add1.quality;
5712 if(debug_ == 4) cout<<"kalman_fitting>trasqual... "<<trasqual<<endl;
5713 if (trasqual) continue;
5714 // Mdc Hits
5715 int inlyr(999), outlyr(-1);
5716 int* rStat = new int[43];
5717 for(int irStat=0;irStat<43;++irStat)rStat[irStat]=0;
5718 std::vector<MdcRec_wirhit*> pt=TrasanTRK1.hitcol;
5719 int hit_in(0);
5720 if(debug_ == 4) cout<<"*********Pt size****"<< pt.size()<<endl;
5721 // Number of hits/layer
5722 int Num[43] = {0};
5723 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5724 ii != pt.begin()-1; ii--) {
5725 Num[(*ii)->geo->Lyr()->Id()]++;
5726 }
5727
5728 for (vector<MdcRec_wirhit*>::iterator ii = pt.end()-1;
5729 ii != pt.begin()-1; ii--) {
5730
5731 hit_asso++;
5732 if (Num[(*ii)->geo->Lyr()->Id()]>3) {
5733 if (debug_ ==4)
5734 cout << "WARNING: I found " << Num[(*ii)->geo->Lyr()->Id()]
5735 << " hits in the layer "
5736 << (*ii)->geo->Lyr()->Id() << std::endl;
5737 continue;
5738 }
5739
5740 hit_in++;
5741 MdcRec_wirhit & rechit = **ii;
5742 double dist[2] = {rechit.ddl, rechit.ddr};
5743 double erdist[2] = {rechit.erddl, rechit.erddr};
5744 const MdcGeoWire* geo = rechit.geo;
5745
5746 int lr_decision(0);
5747 if (KalFitTrack::LR_ == 1){
5748 if (rechit.lr==2 || rechit.lr==0) lr_decision=-1;
5749 // if (rechit.lr==0) lr_decision=-1;
5750 else if (rechit.lr==1) lr_decision=1;
5751 }
5752
5753 int ind(geo->Lyr()->Id());
5754 track_lead.appendHitsMdc( KalFitHitMdc(rechit.id,
5755 lr_decision, rechit.tdc,
5756 dist, erdist,
5757 _wire+(geo->Id()), rechit.rechitptr));
5758 // inner/outer layer :
5759 rStat[ind]++;
5760 if (inlyr>ind) inlyr = ind;
5761 if (outlyr<ind) outlyr = ind;
5762 }
5763 // Empty layers :
5764 int empty_between(0), empty(0);
5765 for (int i= inlyr; i <= outlyr; i++)
5766 if (!rStat[i]) empty_between++;
5767 empty = empty_between+inlyr+(42-outlyr);
5768 delete [] rStat;
5769 }
5770 if (debug_ == 4)
5771 cout << "**** NUMBER OF Mdc HITS (TRASAN) = " << hit_asso << std::endl;
5772
5773
5774 // RMK high momentum track under study, probably not neeeded...
5775 track_lead.order_wirhit(0);
5776 track_lead.type(type);
5777 unsigned int nhit = track_lead.HitsMdc().size();
5778 if (nhit<70) {
5779 cout << " ATTENTION TRACK WITH ONLY HITS " << nhit << std::endl;
5780 return;
5781 }
5782
5783 // Initialisation :
5784 double KalFitst(0), KalFitax(0), KalFitschi2(0);
5785 // Move to the outer most hit :
5786 Hep3Vector outer_pivot(track_lead.x(fiTerm));
5787
5788 if(debug_ == 4) {
5789 std::cout<<"before track_lead.pivot(outer_pivot) ,the error matrix of track_lead is .."<<track_lead.Ea()<<std::endl;
5790 }
5791 track_lead.pivot(outer_pivot); // hi gay, the error matrix is changed in this function!!
5792 track_lead.bFieldZ(KalFitTrack::Bznom_);
5793 // attention best_chi2 reinitialize !!!
5794 if (nhit>=3 && !KalFitTrack::LR_)
5795 start_seed(track_lead, lead_, way, TrasanTRK);
5796 HepSymMatrix Eakal(5,0);
5797
5798 //init_matrix(TrasanTRK, Eakal);
5799
5800 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
5801 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
5802 choice_ = 6;
5803 }
5804
5805 init_matrix(choice_,TrasanTRK, Eakal);
5806
5807 //std::cout<<" Eakal be here: "<<Eakal<<std::endl;
5808
5809 if (debug_ == 4){
5810 std::cout << "from Mdc Pattern Recognition: " << std::endl;
5811 //HepPoint3D IP(0,0,0);
5812 KalmanFit::Helix work(track_lead.pivot(),
5813 track_lead.a(),
5814 track_lead.Ea());
5815 work.pivot(IP);
5816 std::cout << " dr = " << work.a()[0]
5817 << ", Er_dr = " << sqrt(work.Ea()[0][0]) << std::endl;
5818 std::cout << " phi0 = " << work.a()[1]
5819 << ", Er_phi0 = " << sqrt(work.Ea()[1][1]) << std::endl;
5820 std::cout << " PT = " << 1/work.a()[2]
5821 << ", Er_kappa = " << sqrt(work.Ea()[2][2]) << std::endl;
5822 std::cout << " dz = " << work.a()[3]
5823 << ", Er_dz = " << sqrt(work.Ea()[3][3]) << std::endl;
5824 std::cout << " tanl = " << work.a()[4]
5825 << ", Er_tanl = " << sqrt(work.Ea()[4][4]) << std::endl;
5826 }
5827 filter_fwd_calib(track_lead, lead_, way, Eakal);
5828 track_lead.update_forMdc();
5829
5830 //HepPoint3D IP(0,0,0);
5831 if (debug_ == 4) {
5832 cout << " Mdc FIRST KALMAN FIT " << std::endl;
5833 KalmanFit::Helix work1(track_lead.pivot(),
5834 track_lead.a(),
5835 track_lead.Ea());
5836 work1.pivot(IP);
5837 cout << " dr = " << work1.a()[0]
5838 << ", Er_dr = " << sqrt(work1.Ea()[0][0]) << std::endl;
5839 cout << " phi0 = " << work1.a()[1]
5840 << ", Er_phi0 = " << sqrt(work1.Ea()[1][1]) << std::endl;
5841 cout << " PT = " << 1/work1.a()[2]
5842 << ", Er_kappa = " << sqrt(work1.Ea()[2][2]) << std::endl;
5843 cout << " dz = " << work1.a()[3]
5844 << ", Er_dz = " << sqrt(work1.Ea()[3][3]) << std::endl;
5845 cout << " tanl = " << work1.a()[4]
5846 << ", Er_tanl = " << sqrt(work1.Ea()[4][4]) << std::endl;
5847 }
5848
5849 // fill TDS
5850 RecMdcKalTrack* kaltrk = new RecMdcKalTrack;
5851
5852 // Complete the track (other mass assumption, backward) and
5853 complete_track(TrasanTRK, TrasanTRK_add, track_lead, kaltrk,kalcol,segcol);
5854 // }
5855
5856
5857 StatusCode kalsc;
5858 //check whether the RecMdcKalTrackCol has been already registered
5859 DataObject *aRecKalEvent;
5860 eventSvc()->findObject("/Event/Recon/RecMdcKalTrackCol", aRecKalEvent);
5861 if(aRecKalEvent!=NULL) {
5862 //then unregister RecMdcKalCol
5863 kalsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalTrackCol");
5864 if(kalsc != StatusCode::SUCCESS) {
5865 log << MSG::FATAL << "Could not unregister RecMdcKalTrack collection" << endreq;
5866 return;
5867 }
5868 }
5869
5870 kalsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalTrackCol", kalcol);
5871 if( kalsc.isFailure()) {
5872 log << MSG::FATAL << "Could not register RecMdcKalTrack" << endreq;
5873 return;
5874 }
5875 log << MSG::INFO << "RecMdcKalTrackCol registered successfully!" <<endreq;
5876
5877
5878
5879 StatusCode segsc;
5880 //check whether the RecMdcKalHelixSegCol has been already registered
5881 DataObject *aRecKalSegEvent;
5882 eventSvc()->findObject("/Event/Recon/RecMdcKalHelixSegCol", aRecKalSegEvent);
5883 if(aRecKalSegEvent!=NULL) {
5884 //then unregister RecMdcKalHelixSegCol
5885 segsc = eventSvc()->unregisterObject("/Event/Recon/RecMdcKalHelixSegCol");
5886 if(segsc != StatusCode::SUCCESS) {
5887 log << MSG::FATAL << "Could not unregister RecMdcKalHelixSegCol collection" << endreq;
5888 return;
5889 }
5890 }
5891
5892 segsc = eventSvc()->registerObject("/Event/Recon/RecMdcKalHelixSegCol", segcol);
5893 if( segsc.isFailure() ) {
5894 log << MSG::FATAL << "Could not register RecMdcKalHelixSeg" << endreq;
5895 return;
5896 }
5897 log << MSG::INFO << "RecMdcKalHelixSegCol registered successfully!" <<endreq;
5898
5899
5900 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.);
5901 double r1(0.),r2(0.),kap1(999.),kap2(999.),tanl1(0.),tanl2(0.);
5902 //check the result:RecMdcKalTrackCol
5903
5904 SmartDataPtr<RecMdcKalTrackCol> kaltrkCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
5905 if (!kaltrkCol) {
5906 log << MSG::FATAL << "Could not find RecMdcKalTrackCol" << endreq;
5907 return;
5908 }
5909 log << MSG::INFO << "Begin to check RecMdcKalTrackCol"<<endreq;
5910 RecMdcKalTrackCol::iterator iter_trk = kaltrkCol->begin();
5911 for( int jj=1; iter_trk != kaltrkCol->end(); iter_trk++,jj++) {
5912 log << MSG::DEBUG << "retrieved MDC Kalmantrack:"
5913 << "Track Id: " << (*iter_trk)->getTrackId()
5914 << " Mass of the fit: "<< (*iter_trk)->getMass(2)<< endreq
5915 << " Length of the track: "<< (*iter_trk)->getLength(2)
5916 << " Tof of the track: "<< (*iter_trk)->getTof(2) << endreq
5917 << " Chisq of the fit: "<< (*iter_trk)->getChisq(0,2)
5918 <<" "<< (*iter_trk)->getChisq(1,2) << endreq
5919 << "Ndf of the fit: "<< (*iter_trk)->getNdf(0,1)
5920 <<" "<< (*iter_trk)->getNdf(1,2) << endreq
5921 << "Kappa " << (*iter_trk)->getZHelix()[2]
5922 << "zhelixmu "<<(*iter_trk)->getZHelixMu()
5923 << endreq;
5924
5925 HelixSegRefVec gothelixsegs = (*iter_trk)->getVecHelixSegs();
5926 if(debug_ == 4) {
5927 std::cout<<"the size of gothelixsegs ..."<<gothelixsegs.size()<<std::endl;
5928 }
5929
5930 HelixSegRefVec::iterator it_gothelixseg = gothelixsegs.begin();
5931 for( ; it_gothelixseg != gothelixsegs.end(); it_gothelixseg++) {
5932 if(debug_ == 4) {
5933 std::cout<<"the layerId of this helixseg is ..."<<(*it_gothelixseg)->getLayerId()<<std::endl;
5934 std::cout<<"the residual of this helixseg exclude the meas hit"<<(*it_gothelixseg)->getResExcl()<<std::endl;
5935 std::cout<<"the residual of this helixseg include the meas hit"<<(*it_gothelixseg)->getResIncl()<<std::endl;
5936 std::cout<<"the track id of the helixseg is ..."<<(*it_gothelixseg)->getTrackId() <<std::endl;
5937 std::cout<<"the tof of the helixseg is ..."<<(*it_gothelixseg)->getTof()<<std::endl;
5938 std::cout<<"the Zhit of the helixseg is ..."<<(*it_gothelixseg)->getZhit()<<std::endl;
5939 }
5940 }
5941 for( int i = 0; i<43; i++) {
5942 log << MSG::DEBUG << "retrieved pathl["<<i<<"]= "
5943 << (*iter_trk)->getPathl(i) <<endreq;
5944 }
5945
5946 if(ntuple_&1) {
5947 m_trackid = (*iter_trk)->getTrackId();
5948 for( int jj =0, iii=0; jj<5; jj++) {
5949 m_length[jj] = (*iter_trk)->getLength(jj);
5950 m_tof[jj] = (*iter_trk)->getTof(jj);
5951 m_nhits[jj] = (*iter_trk)->getNhits(jj);
5952 m_zhelix[jj] = (*iter_trk)->getZHelix()[jj];
5953 m_zhelixe[jj] = (*iter_trk)->getZHelixE()[jj];
5954 m_zhelixmu[jj] = (*iter_trk)->getZHelixMu()[jj];
5955 m_zhelixk[jj] = (*iter_trk)->getZHelixK()[jj];
5956 m_zhelixp[jj] = (*iter_trk)->getZHelixP()[jj];
5957 m_fhelix[jj] = (*iter_trk)->getFHelix()[jj];
5958 m_fhelixe[jj] = (*iter_trk)->getFHelixE()[jj];
5959 m_fhelixmu[jj] = (*iter_trk)->getFHelixMu()[jj];
5960 m_fhelixk[jj] = (*iter_trk)->getFHelixK()[jj];
5961 m_fhelixp[jj] = (*iter_trk)->getFHelixP()[jj];
5962 m_lhelix[jj] = (*iter_trk)->getLHelix()[jj];
5963 m_lhelixe[jj] = (*iter_trk)->getLHelixE()[jj];
5964 m_lhelixmu[jj] = (*iter_trk)->getLHelixMu()[jj];
5965 m_lhelixk[jj] = (*iter_trk)->getLHelixK()[jj];
5966 m_lhelixp[jj] = (*iter_trk)->getLHelixP()[jj];
5967 if(ntuple_&32) {
5968 for(int kk=0; kk<=jj; kk++,iii++) {
5969 m_zerror[iii] = (*iter_trk)->getZError()[jj][kk];
5970 m_zerrore[iii] = (*iter_trk)->getZErrorE()[jj][kk];
5971 m_zerrormu[iii] = (*iter_trk)->getZErrorMu()[jj][kk];
5972 m_zerrork[iii] = (*iter_trk)->getZErrorK()[jj][kk];
5973 m_zerrorp[iii] = (*iter_trk)->getZErrorP()[jj][kk];
5974 m_ferror[iii] = (*iter_trk)->getFError()[jj][kk];
5975 m_ferrore[iii] = (*iter_trk)->getFErrorE()[jj][kk];
5976 m_ferrormu[iii] = (*iter_trk)->getFErrorMu()[jj][kk];
5977 m_ferrork[iii] = (*iter_trk)->getFErrorK()[jj][kk];
5978 m_ferrorp[iii] = (*iter_trk)->getFErrorP()[jj][kk];
5979 m_lerror[iii] = (*iter_trk)->getLError()[jj][kk];
5980 m_lerrore[iii] = (*iter_trk)->getLErrorE()[jj][kk];
5981 m_lerrormu[iii] = (*iter_trk)->getLErrorMu()[jj][kk];
5982 m_lerrork[iii] = (*iter_trk)->getLErrorK()[jj][kk];
5983 m_lerrorp[iii] = (*iter_trk)->getLErrorP()[jj][kk];
5984 }
5985
5986 }
5987 }
5988
5989 // RootConversion changed in BOSS6.0, so use thefollowing:
5990 m_chisq[0][0] = (*iter_trk)->getChisq(0,0);
5991 m_chisq[1][0] = (*iter_trk)->getChisq(0,1);
5992 m_chisq[2][0] = (*iter_trk)->getChisq(0,2);
5993 m_chisq[3][0] = (*iter_trk)->getChisq(0,3);
5994 m_chisq[4][0] = (*iter_trk)->getChisq(0,4);
5995 m_chisq[0][1] = (*iter_trk)->getChisq(1,0);
5996 m_chisq[1][1] = (*iter_trk)->getChisq(1,1);
5997 m_chisq[2][1] = (*iter_trk)->getChisq(1,2);
5998 m_chisq[3][1] = (*iter_trk)->getChisq(1,3);
5999 m_chisq[4][1] = (*iter_trk)->getChisq(1,4);
6000
6001 m_ndf[0][0] = (*iter_trk)->getNdf(0,0);
6002 m_ndf[1][0] = (*iter_trk)->getNdf(0,1);
6003 m_ndf[2][0] = (*iter_trk)->getNdf(0,2);
6004 m_ndf[3][0] = (*iter_trk)->getNdf(0,3);
6005 m_ndf[4][0] = (*iter_trk)->getNdf(0,4);
6006 m_ndf[0][1] = (*iter_trk)->getNdf(1,0);
6007 m_ndf[1][1] = (*iter_trk)->getNdf(1,1);
6008 m_ndf[2][1] = (*iter_trk)->getNdf(1,2);
6009 m_ndf[3][1] = (*iter_trk)->getNdf(1,3);
6010 m_ndf[4][1] = (*iter_trk)->getNdf(1,4);
6011
6012 m_stat[0][0] = (*iter_trk)->getStat(0,0);
6013 m_stat[1][0] = (*iter_trk)->getStat(0,1);
6014 m_stat[2][0] = (*iter_trk)->getStat(0,2);
6015 m_stat[3][0] = (*iter_trk)->getStat(0,3);
6016 m_stat[4][0] = (*iter_trk)->getStat(0,4);
6017 m_stat[0][1] = (*iter_trk)->getStat(1,0);
6018 m_stat[1][1] = (*iter_trk)->getStat(1,1);
6019 m_stat[2][1] = (*iter_trk)->getStat(1,2);
6020 m_stat[3][1] = (*iter_trk)->getStat(1,3);
6021 m_stat[4][1] = (*iter_trk)->getStat(1,4);
6022
6023 m_fptot = sqrt(1+pow(m_fhelix[4],2))/m_fhelix[2];
6024 m_fptote = sqrt(1+pow(m_fhelixe[4],2))/m_fhelixe[2];
6025 m_fptotmu = sqrt(1+pow(m_fhelixmu[4],2))/m_fhelixmu[2];
6026 m_fptotk = sqrt(1+pow(m_fhelixk[4],2))/m_fhelixk[2];
6027 m_fptotp = sqrt(1+pow(m_fhelixp[4],2))/m_fhelixp[2];
6028
6029 m_zpt = 1/m_zhelix[2];
6030 m_zpte = 1/m_zhelixe[2];
6031 m_zptmu = 1/m_zhelixmu[2];
6032 m_zptk = 1/m_zhelixk[2];
6033 m_zptp = 1/m_zhelixp[2];
6034
6035 m_fpt = 1/m_fhelix[2];
6036 m_fpte = 1/m_fhelixe[2];
6037 m_fptmu = 1/m_fhelixmu[2];
6038 m_fptk = 1/m_fhelixk[2];
6039 m_fptp = 1/m_fhelixp[2];
6040
6041 m_lpt = 1/m_lhelix[2];
6042 m_lpte = 1/m_lhelixe[2];
6043 m_lptmu = 1/m_lhelixmu[2];
6044 m_lptk = 1/m_lhelixk[2];
6045 m_lptp = 1/m_lhelixp[2];
6046
6047 m_lptot = sqrt(1+pow(m_lhelix[4],2))/m_lhelix[2];
6048 m_lptote = sqrt(1+pow(m_lhelixe[4],2))/m_lhelixe[2];
6049 m_lptotmu = sqrt(1+pow(m_lhelixmu[4],2))/m_lhelixmu[2];
6050 m_lptotk = sqrt(1+pow(m_lhelixk[4],2))/m_lhelixk[2];
6051 m_lptotp = sqrt(1+pow(m_lhelixp[4],2))/m_lhelixp[2];
6052
6053 m_zptot = sqrt(1+pow(m_zhelix[4],2))/m_zhelix[2];
6054 m_zptote = sqrt(1+pow(m_zhelixe[4],2))/m_zhelixe[2];
6055 m_zptotmu = sqrt(1+pow(m_zhelixmu[4],2))/m_zhelixmu[2];
6056 m_zptotk = sqrt(1+pow(m_zhelixk[4],2))/m_zhelixk[2];
6057 m_zptotp = sqrt(1+pow(m_zhelixp[4],2))/m_zhelixp[2];
6058 if(ntuple_&32) {
6059 m_zsigp = sqrt(pow((m_zptot/m_zhelix[2]),2)*m_zerror[5]+
6060 pow((m_zhelix[4]/m_zptot),2)*pow((1/m_zhelix[2]),4)*m_zerror[14]-
6061 2*m_zhelix[4]*m_zerror[12]*pow((1/m_zhelix[2]),3));
6062 m_zsigpe = sqrt(pow((m_zptote/m_zhelixe[2]),2)*m_zerrore[5]+
6063 pow((m_zhelixe[4]/m_zptote),2)*pow((1/m_zhelixe[2]),4)*m_zerrore[14]-
6064 2*m_zhelixe[4]*m_zerrore[12]*pow((1/m_zhelixe[2]),3));
6065 m_zsigpmu = sqrt(pow((m_zptotmu/m_zhelixmu[2]),2)*m_zerrormu[5]+
6066 pow((m_zhelixmu[4]/m_zptotmu),2)*pow((1/m_zhelixmu[2]),4)*m_zerrormu[14]-
6067 2*m_zhelixmu[4]*m_zerrormu[12]*pow((1/m_zhelixmu[2]),3));
6068 m_zsigpk = sqrt(pow((m_zptotk/m_zhelixk[2]),2)*m_zerrork[5]+
6069 pow((m_zhelixk[4]/m_zptotk),2)*pow((1/m_zhelixk[2]),4)*m_zerrork[14]-
6070 2*m_zhelixk[4]*m_zerrork[12]*pow((1/m_zhelixk[2]),3));
6071 m_zsigpp = sqrt(pow((m_zptotp/m_zhelixp[2]),2)*m_zerrorp[5]+
6072 pow((m_zhelixp[4]/m_zptotp),2)*pow((1/m_zhelixp[2]),4)*m_zerrorp[14]-
6073 2*m_zhelixp[4]*m_zerrorp[12]*pow((1/m_zhelixp[2]),3));
6074 }
6075
6076 StatusCode sc1 = m_nt1->write();
6077 if( sc1.isFailure() ) cout<<"Ntuple1 filling failed!"<<endl;
6078 }
6079
6080 if(ntuple_&4) {
6081 if(jj == 1) {
6082 phi1 = (*iter_trk)->getFFi0();
6083 r1 = (*iter_trk)->getFDr();
6084 z1 = (*iter_trk)->getFDz();
6085 kap1 = (*iter_trk)->getFCpa();
6086 tanl1 = (*iter_trk)->getFTanl();
6087 x1 = r1*cos(phi1);
6088 y1 = r1*sin(phi1);
6089 p1 = sqrt(1+tanl1*tanl1)/kap1;
6090 the1 = M_PI/2-atan(tanl1);
6091 } else if(jj == 2) {
6092 phi2 = (*iter_trk)->getFFi0();
6093 r2 = (*iter_trk)->getFDr();
6094 z2 = (*iter_trk)->getFDz();
6095 kap2 = (*iter_trk)->getFCpa();
6096 tanl2 = (*iter_trk)->getFTanl();
6097 x2 = r1*cos(phi2);
6098 y2 = r1*sin(phi2);
6099 p2 = sqrt(1+tanl2*tanl2)/kap1;
6100 the2 = M_PI/2-atan(tanl2);
6101 }
6102 }
6103 }
6104 if(ntuple_&4) {
6105 m_delx = x1 - x2;
6106 m_dely = y1 - y2;
6107 m_delz = z1 - z2;
6108 m_delthe = the1 + the2;
6109 m_delphi = phi1- phi2;
6110 m_delp = p1 - p2;
6111 StatusCode sc2 = m_nt2->write();
6112 if( sc2.isFailure() ) cout<<"Ntuple2 filling failed!"<<endl;
6113 }
6114 delete [] order;
6115 delete [] rCont;
6116 delete [] rGen;
6117 delete [] rOM;
6118
6119 if (debug_ == 4)
6120 cout << "Kalfitting finished " << std::endl;
6121}
6122
6123
6124
6126 MdcRec_trk_add& TrasanTRK_add,
6127 KalFitTrack& track_lead,
6128 RecMdcKalTrack* kaltrk,
6129 RecMdcKalTrackCol* kalcol,RecMdcKalHelixSegCol *segcol,int flagsmooth)
6130{
6131 static int nmass = KalFitTrack::nmass();
6132 int way(1);
6133 MsgStream log(msgSvc(), name());
6134 KalFitTrack track_ip(track_lead);
6135 //fromFHitToInnerWall(track_lead, way);
6136 // cout << "m_esti" << m_esti1_r[0] << endl;
6137 //cout<<"fitGemHits for pion"<<endl;
6138 //if(useNCGem_>0) fitGemHits(track_lead, lead_, way);
6139 if(useNCGem_>0) track_lead=Cgem_filter_anal(track_ip, lead_, way);
6140 else if(useNCGem_==0) innerwall(track_ip, lead_, way);
6141 KalFitTrack track_first(track_lead);
6142 //cout<<"__FUNCTION__: track_lead.nLayerUsed = "<<track_lead.nLayerUsed()<<endl;
6143 //cout<<"__FUNCTION__: track_ip.nLayerUsed = "<<track_ip.nLayerUsed()<<endl;
6144 //innerwall(track_ip, lead_, way,95,99);
6145 // Fill Tds
6146 fillTds_ip(TrasanTRK, track_ip, kaltrk, lead_);
6147 // std::cout<<"track_first nster"<<track_first.nster()<<std::endl;
6148
6149 //fillTds_lead(TrasanTRK, track_first, kaltrk, lead_);
6150 fillTds(TrasanTRK, track_first, kaltrk, lead_);
6151 // Refit for different mass assumptions :
6152 double pp = track_lead.momentum().mag();
6153
6154 if(!(i_front_<0)){
6155 //cout << "!!!!i_front" << i_front_<< endl;
6156 for(int l_mass = 0, flg = 1; l_mass < nmass;
6157 l_mass++, flg <<= 1) {
6158
6159 if (!(mhyp_ & flg)) continue;
6160 if (l_mass == lead_) continue;
6161
6162 // Check the mom. to decide of the refit with this mass assumption
6163 if ((lead_ != 0 && l_mass==0 && pp > pe_cut_) ||
6164 (lead_ != 1 && l_mass==1 && pp > pmu_cut_) ||
6165 (lead_ != 2 && l_mass==2 && pp > ppi_cut_) ||
6166 (lead_ != 3 && l_mass==3 && pp > pk_cut_) ||
6167 (lead_ != 4 && l_mass==4 && pp > pp_cut_))
6168 continue;
6169 if(debug_ == 4) cout<<"complete_track..REFIT ASSUMPION " << l_mass << endl;
6170 // Initialisation :
6171 double chiSq = 0;
6172 int nhits = 0;
6173
6174 // Initialisation : (x, a, ea)
6175 HepPoint3D x_trasan(TrasanTRK.pivot[0],
6176 TrasanTRK.pivot[1],
6177 TrasanTRK.pivot[2]);
6178 HepVector a_trasan(5);
6179 for(int i = 0; i < 5; i++)
6180 a_trasan[i] = TrasanTRK.helix[i];
6181
6182 HepSymMatrix ea_trasan(5);
6183 for(int i = 0, k = 0; i < 5; i++) {
6184 for(int j = 0; j <= i; j++) {
6185 ea_trasan[i][j] = matrixg_*TrasanTRK.error[k++];
6186 ea_trasan[j][i] = ea_trasan[i][j];
6187 }
6188 }
6189
6190 KalFitTrack track(x_trasan,a_trasan, ea_trasan, l_mass, chiSq, nhits);
6191 track.HitsMdc(track_lead.HitsMdc());
6192 track.trasan_id(TrasanTRK.id);
6193 double fiTerm = TrasanTRK.fiTerm;
6194 track.pivot(track.x(fiTerm));
6195 HepSymMatrix Eakal(5,0);
6196
6197 double costheta = track.a()[4] / sqrt(1.0 + track.a()[4]*track.a()[4]);
6198 if( (1.0/fabs(track.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
6199 choice_ = 6;
6200 }
6201
6202 init_matrix(choice_,TrasanTRK, Eakal);
6203 if(ntuple_&256) {
6204 m_hit_no=0;
6205 m_nCluster=0;
6206 }
6207 filter_fwd_anal(track, l_mass, way, Eakal);
6208 KalFitTrack track_z(track);
6209 track_first=track;
6210 //fromFHitToInnerWall(track_z, way);
6211 //cout<<"fitGemHits for i="<<l_mass<<endl;
6212 //if(useNCGem_>0) fitGemHits(track_z, l_mass, way);
6213 if(useNCGem_>0) track_first=Cgem_filter_anal(track_z, l_mass, way);
6214 else if(useNCGem_==0) innerwall(track_z, lead_, way);
6215 ///fill tds with results got at (0,0,0)
6216 //innerwall(track_z, l_mass, way,95,99);
6217 fillTds_ip(TrasanTRK, track_z, kaltrk, l_mass);
6218 // Fill tds with the result at the inner most hit
6219 fillTds(TrasanTRK, track_first, kaltrk, l_mass);
6220 if(ifProdNt12){
6221 if(l_mass==1)residual(track_z);
6222 }
6223 }
6224 } // end of //end of if (!(i_front<0))
6225
6226
6227 if(ntuple_&256) StatusCode sc7 = m_nt7 ->write();
6228 // Refit with an enhancement of the error matrix at Mdc level :
6229 if (enhance_) {
6230
6231 HepPoint3D x_first(0, 0, 0);
6232 HepVector a_first(kaltrk->getFHelix());
6233 HepSymMatrix ea_first(kaltrk->getFError());
6234 HepVector fac(5);
6235 fac[0]=fac_h1_; fac[1]=fac_h2_; fac[2]=fac_h3_; fac[3]=fac_h4_; fac[4]=fac_h5_;
6236 for(int i = 0; i < 5; i++)
6237 for(int j = 0; j <= i; j++)
6238 ea_first[i][j] = fac[i]*fac[j]*ea_first[i][j];
6239 KalFitTrack track(x_first, a_first, ea_first, 2, 0, 0);
6240 }
6241 //if(myEventNo==1080) cout<<"mu_status_filled2 = "<<kaltrk->getStat(0,1)<<endl;
6242
6243 // Backward filter :
6244 KalFitTrack track_back(track_lead);
6245 if (debug_ == 4) {
6246 cout << " Backward fitting flag:" << back_<< endl;
6247 cout << "track_back pivot " << track_back.pivot()
6248 << " track_lead kappa " << track_lead.a()[2]
6249 <<endl;
6250 }
6251
6252 if (back_ && track_lead.a()[2] != 0 &&
6253 1/fabs(track_lead.a()[2]) > pT_) {
6254 track_back.HitsMdc(track_lead.HitsMdc());
6255
6257 double p_kaon(0), p_proton(0);
6258 if (!(kaltrk->getStat(0,3))) {
6259 p_kaon = 1 / fabs(kaltrk->getZHelixK()[2]) *
6260 sqrt(1 + kaltrk->getZHelixK()[4]*kaltrk->getZHelixK()[4]);
6261 track_back.p_kaon(p_kaon);
6262 } else {
6263 p_kaon = 1 / fabs(track_back.a()[2]) *
6264 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6265 track_back.p_kaon(p_kaon);
6266 }
6267 if (!(kaltrk->getStat(0,4))) {
6268 p_proton = 1 / fabs(kaltrk->getZHelixP()[2]) *
6269 sqrt(1 + kaltrk->getZHelixP()[4]*kaltrk->getZHelixP()[4]);
6270 track_back.p_proton(p_proton);
6271 } else {
6272 p_proton = 1 / fabs(track_back.a()[2]) *
6273 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6274 track_back.p_proton(p_proton);
6275 }
6276 }
6277
6278 if (!(i_back_<0)) {
6279 //cout<<" *** in smoothing process ***"<<endl;
6280 for(int l_mass = 0; l_mass < nmass; l_mass++) {
6281 //cout<<" --- in hypothesis "<<l_mass<<" :"<<endl;
6282 KalFitTrack track_seed(track_back);
6283 track_seed.chgmass(l_mass);
6284 //cout<<"---------------"<<endl;//wangll
6285 //cout<<"smooth track "<<l_mass<<endl;//wangll
6286 //cout<<" pivot :"<<track_seed.pivot()<<endl;//wangll
6287 //cout<<" helix :"<<track_seed.a()<<endl;//wangll
6288
6289 if(useNCGem_>0) Cgem_filter_anal(track_seed, l_mass, -way);
6290 smoother_anal(track_seed, -way);
6291 // if( usage_ == 1) smoother_calib(track_seed, -way);
6292 //cout<<"fillTds_back 1"<<endl;
6293 // fill TDS for backward filter :
6294 fillTds_back(track_seed, kaltrk, TrasanTRK, l_mass, segcol, 1);
6295 //cout<<"nHits: "<<kaltrk->getVecHelixSegs().size()<<endl;
6296 }
6297 } else {
6298 if(useNCGem_>0) Cgem_filter_anal(track_back, lead_, -way);
6299 smoother_anal(track_back, -way);
6300 //smoother_calib(track_back, -way);
6301 // smoother(track_back, -way);
6302 // fill TDS for backward filter :
6303 //cout<<"fillTds_back 2"<<endl;
6304 fillTds_back(track_back, kaltrk, TrasanTRK, lead_, segcol, 1);
6305 }
6306 }
6307
6308 // Take care of the pointers (use lead. hyp results by default)
6309 //if(myEventNo==1080) cout<<"mu_status_filled3 = "<<kaltrk->getStat(0,1)<<endl;
6310 /*
6311 for(int pid = 0; pid < nmass;
6312 pid++) {
6313 if (pid == lead_) continue;
6314 if (kaltrk->getStat(1,pid))
6315 sameas(kaltrk, pid, lead_);
6316 }*/
6317
6318
6319 //check: before register into TDS
6320
6321 log << MSG::DEBUG << "registered MDC Kalmantrack:"
6322 << "Track Id: " << kaltrk->getTrackId()
6323 << " Mass of the fit: "<< kaltrk->getMass(2)<< endreq
6324 << "Length of the track: "<< kaltrk->getLength(2)
6325 << " Tof of the track: "<< kaltrk->getTof(2) << endreq
6326 << "Chisq of the fit: "<< kaltrk->getChisq(0,2)
6327 <<" "<< kaltrk->getChisq(1,2) << endreq
6328 << "Ndf of the fit: "<< kaltrk->getNdf(0,2)
6329 <<" "<< kaltrk->getNdf(1,2) << endreq
6330 << "Helix " << kaltrk->getZHelix()[2]
6331 <<endreq;
6332
6333 //if(myEventNo==1080) cout<<"mu_status_filled4 = "<<kaltrk->getStat(0,1)<<endl;
6334 kalcol->push_back(kaltrk);
6335 track_lead.HitsMdc().clear();
6336}
6337
6338
6340 MdcRec_trk_add& TrasanTRK_add,
6341 KalFitTrack& track_lead,
6342 RecMdcKalTrack* kaltrk,
6343 RecMdcKalTrackCol* kalcol,RecMdcKalHelixSegCol *segcol)
6344{
6345 static int nmass = KalFitTrack::nmass();
6346 int way(1);
6347 MsgStream log(msgSvc(), name());
6348 KalFitTrack track_first(track_lead);
6349 KalFitTrack track_ip(track_lead);
6350
6351 if (debug_ == 4){
6352 cout << "track_first pivot "<<track_first.pivot()<< " helix "<<track_first.a()<<endl;
6353 }
6354 if(usage_==1) innerwall(track_ip, lead_, way);
6355 // Fill Tds
6356 fillTds_ip(TrasanTRK, track_ip, kaltrk, lead_);
6357
6358 if (debug_ == 4) {
6359 cout << "after inner wall, track_ip pivot "<<track_first.pivot()<< " helix "<<track_first.a()<<endl;
6360 }
6361
6362 fillTds_lead(TrasanTRK, track_first, kaltrk, lead_);
6363
6364 // Refit for different mass assumptions :
6365 double pp = track_lead.momentum().mag();
6366
6367 //w if (!KalFitDSSD::cosmic_)
6368 if(!(i_front_<0)){
6369
6370 for(int l_mass = 0, flg = 1; l_mass < nmass;
6371 l_mass++, flg <<= 1) {
6372
6373 if (!(mhyp_ & flg)) continue;
6374 if (l_mass == lead_) continue;
6375
6376 // Check the mom. to decide of the refit with this mass assumption
6377 if ((lead_ != 0 && l_mass==0 && pp > pe_cut_) ||
6378 (lead_ != 1 && l_mass==1 && pp > pmu_cut_) ||
6379 (lead_ != 2 && l_mass==2 && pp > ppi_cut_) ||
6380 (lead_ != 3 && l_mass==3 && pp > pk_cut_) ||
6381 (lead_ != 4 && l_mass==4 && pp > pp_cut_))
6382 continue;
6383
6384 if(debug_ == 4) {
6385 cout<<"complete_track..REFIT ASSUMPION " << l_mass << endl;
6386 }
6387
6388 // Initialisation :
6389 double chiSq = 0;
6390 int nhits = 0;
6391
6392 // Initialisation : (x, a, ea)
6393 HepPoint3D x_trasan(TrasanTRK.pivot[0],
6394 TrasanTRK.pivot[1],
6395 TrasanTRK.pivot[2]);
6396
6397 HepVector a_trasan(5);
6398 for(int i = 0; i < 5; i++){
6399 a_trasan[i] = TrasanTRK.helix[i];
6400 }
6401
6402 HepSymMatrix ea_trasan(5);
6403 for(int i = 0, k = 0; i < 5; i++) {
6404 for(int j = 0; j <= i; j++) {
6405 ea_trasan[i][j] = matrixg_*TrasanTRK.error[k++];
6406 ea_trasan[j][i] = ea_trasan[i][j];
6407 }
6408 }
6409
6410 KalFitTrack track(x_trasan,a_trasan, ea_trasan, l_mass, chiSq, nhits);
6411 track.HitsMdc(track_lead.HitsMdc());
6412
6413 double fiTerm = TrasanTRK.fiTerm;
6414 track.pivot(track.x(fiTerm));
6415
6416 HepSymMatrix Eakal(5,0);
6417
6418 double costheta = track_lead.a()[4] / sqrt(1.0 + track_lead.a()[4]*track_lead.a()[4]);
6419 if( (1.0/fabs(track_lead.a()[2]) < pt_cut_ ) && (fabs(costheta)> theta_cut_) ) {
6420 choice_ = 6;
6421 }
6422
6423 init_matrix(choice_, TrasanTRK, Eakal);
6424
6425 filter_fwd_calib(track, l_mass, way, Eakal);
6426
6427 KalFitTrack track_z(track);
6428 ///fill tds with results got at (0,0,0)
6429 innerwall(track_z, l_mass, way);
6430 fillTds_ip(TrasanTRK, track_z, kaltrk, l_mass);
6431 // Fill tds
6432 fillTds(TrasanTRK, track, kaltrk, l_mass);
6433 }
6434 } //end of if (!(i_front<0))
6435
6436 // Refit with an enhancement of the error matrix at Mdc level :
6437
6438 if (enhance_) {
6439 HepPoint3D x_first(0, 0, 0);
6440 HepVector a_first(kaltrk->getFHelix());
6441 HepSymMatrix ea_first(kaltrk->getFError());
6442 HepVector fac(5);
6443 fac[0]=fac_h1_; fac[1]=fac_h2_; fac[2]=fac_h3_; fac[3]=fac_h4_; fac[4]=fac_h5_;
6444
6445 for(int i = 0; i < 5; i++)
6446 for(int j = 0; j <= i; j++)
6447 ea_first[i][j] = fac[i]*fac[j]*ea_first[i][j];
6448 KalFitTrack track(x_first, a_first, ea_first, 2, 0, 0);
6449 }
6450
6451 // Backward filter
6452 // Attention, the initial error matrix of track_back is the error matrix
6453 // that after filter_fwd_calib(...) course of track_lead. So one thing need
6454 // more consideration that how to chose the inital error matrix of this smoother,
6455 // to put it by hand or use the error matrix after filter_fwd_calib. I think
6456 // it should be to refer R.G.Brown's book.
6457
6458 KalFitTrack track_back(track_lead);
6459
6460 //track_back(track);
6461
6462
6463 if (debug_ == 4) {
6464 cout << " Backward fitting flag:" << back_<< endl;
6465 cout << "track_back pivot " << track_back.pivot()
6466 << " track_lead kappa " << track_lead.a()[2]
6467 <<endl;
6468 }
6469
6470 if (back_ && track_lead.a()[2] != 0 &&
6471 1/fabs(track_lead.a()[2]) > pT_) {
6472 track_back.HitsMdc(track_lead.HitsMdc());
6473
6475
6476 double p_kaon(0), p_proton(0);
6477
6478 if (!(kaltrk->getStat(0,3))) {
6479 p_kaon = 1 / fabs(kaltrk->getZHelixK()[2]) *
6480 sqrt(1 + kaltrk->getZHelixK()[4]*kaltrk->getZHelixK()[4]);
6481 track_back.p_kaon(p_kaon);
6482 } else {
6483 p_kaon = 1 / fabs(track_back.a()[2]) *
6484 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6485 track_back.p_kaon(p_kaon);
6486 }
6487 if (!(kaltrk->getStat(0,4))) {
6488 p_proton = 1 / fabs(kaltrk->getZHelixP()[2]) *
6489 sqrt(1 + kaltrk->getZHelixP()[4]*kaltrk->getZHelixP()[4]);
6490 track_back.p_proton(p_proton);
6491 } else {
6492 p_proton = 1 / fabs(track_back.a()[2]) *
6493 sqrt(1 + track_back.a()[4]*track_back.a()[4]);
6494 track_back.p_proton(p_proton);
6495 }
6496
6497 }
6498
6499
6500 if (!(i_back_<0)) {
6501 for(int l_mass = 0; l_mass < nmass; l_mass++) {
6502 KalFitTrack track_seed(track_back);
6503 track_seed.chgmass(l_mass);
6504 smoother_calib(track_seed, -way);
6505 // fill TDS for backward filter :
6506 fillTds_back(track_seed, kaltrk, TrasanTRK, l_mass,segcol);
6507 }
6508 } else {
6509
6510 smoother_calib(track_back, -way);
6511 // fill TDS for backward filter , for leading particle hypothesis :
6512 fillTds_back(track_back, kaltrk, TrasanTRK, lead_,segcol);
6513 // fillTds_helixsegs(track_back,TrasanTRK);
6514 }
6515 }
6516
6517 /*
6518 // Take care of the pointers (use lead. hyp results by default)
6519 for(int pid = 0; pid < nmass;
6520 pid++) {
6521 if (pid == lead_) continue;
6522 if (kaltrk->getStat(1,pid))
6523 sameas(kaltrk, pid, lead_);
6524 }
6525 */
6526
6527 //check: before register into TDS
6528
6529 log << MSG::DEBUG << "registered MDC Kalmantrack:"
6530 << "Track Id: " << kaltrk->getTrackId()
6531 << " Mass of the fit: "<< kaltrk->getMass(2)<< endreq
6532 << "Length of the track: "<< kaltrk->getLength(2)
6533 << " Tof of the track: "<< kaltrk->getTof(2) << endreq
6534 << "Chisq of the fit: "<< kaltrk->getChisq(0,2)
6535 <<" "<< kaltrk->getChisq(1,2) << endreq
6536 << "Ndf of the fit: "<< kaltrk->getNdf(0,2)
6537 <<" "<< kaltrk->getNdf(1,2) << endreq
6538 << "Helix " << kaltrk->getZHelix()[2]
6539 <<endreq;
6540
6541 kalcol->push_back(kaltrk);
6542 track_lead.HitsMdc().clear();
6543 track_back.HelixSegs().clear();
6544 // ??ATTENTION!! should track_back.HelixSegs() be cleared ??
6545}
6546
6547
6548void KalFitAlg::init_matrix(MdcRec_trk& trk, HepSymMatrix& Eakal )
6549{
6550 for ( int i=0; i<5; i++) {
6551 for( int j = 1; j<i+2;j++) {
6552 Eakal(i+1,j) = matrixg_*(trk.error[i*(i+1)/2+j-1]);
6553 Eakal(j,i+1) = Eakal(i+1,j);
6554 }
6555 }
6556
6557 if (debug_ == 4) cout<<"initialised Ea.. "<<Eakal<<endl;
6558}
6559
6560
6561
6562void KalFitAlg::init_matrix(int k, MdcRec_trk& trk, HepSymMatrix& Eakal )
6563{
6564 if(0==k){
6565 for ( int i=0; i<5; i++) {
6566 for( int j = 1; j<i+2;j++) {
6567 Eakal(i+1,j) = matrixg_*(trk.error[i*(i+1)/2+j-1]);
6568 Eakal(j,i+1) = Eakal(i+1,j);
6569 }
6570 Eakal(1,1) = Eakal(1,1)* gain1_;
6571 Eakal(2,2) = Eakal(2,2)* gain2_;
6572 Eakal(3,3) = Eakal(3,3)* gain3_;
6573 Eakal(4,4) = Eakal(4,4)* gain4_;
6574 Eakal(5,5) = Eakal(5,5)* gain5_;
6575 }
6576 }
6577 // HepSymMatrix ea_temp(5);
6578 // for(int i = 0, k = 0; i < 5; i++) {
6579 // for(int j = 0; j <= i; j++) {
6580 // ea_temp[i][j] = matrixg_*trk.error[k++];
6581 // ea_temp[j][i] = ea_temp[i][j];
6582 // }
6583 // }
6584
6585 if(1==k){
6586 Eakal(1,1) = .2;
6587 Eakal(2,2) = .001;
6588 Eakal(3,3) = 1.0;
6589 Eakal(4,4) = 10.0;
6590 Eakal(5,5) = 0.002;
6591 }
6592
6593 if(2==k){
6594 Eakal(1,1) = .2;
6595 Eakal(2,2) = 0.1;
6596 Eakal(3,3) = 1.0;
6597 Eakal(4,4) = 25.0;
6598 Eakal(5,5) = 0.10;
6599 }
6600
6601
6602 if(3==k){
6603 Eakal(1,1) = .2;
6604 Eakal(2,2) = .001;
6605 Eakal(3,3) = 1.0;
6606 Eakal(4,4) = 25.0;
6607 Eakal(5,5) = 0.10;
6608 }
6609
6610 if(4==k){
6611 Eakal(1,1) = .2;
6612 Eakal(2,2) = .01;
6613 Eakal(3,3) = 0.01;
6614 Eakal(4,4) = 1.;
6615 Eakal(5,5) = .01;
6616 }
6617
6618 if(5==k) {
6619 Eakal(1,1) = 2.;
6620 Eakal(2,2) = 0.1;
6621 Eakal(3,3) = 1.;
6622 Eakal(4,4) = 20.;
6623 Eakal(5,5) = 0.1;
6624 }
6625
6626 if(6==k) {
6627 Eakal(1,1) = 0.01;
6628 Eakal(2,2) = 0.01;
6629 Eakal(3,3) = 0.01;
6630 Eakal(4,4) = 100.;
6631 Eakal(5,5) = 0.5;
6632 }
6633
6634 if(k!=0){
6635 Eakal(3,3) = 0.2;
6636 Eakal(1,1) = 1;
6637 Eakal(4,4) = 1;
6638 }
6639
6640 if (debug_ == 4) cout<<"initialised Eakal.. "<<Eakal<<endl;
6641}
6642
6643
6644
6645
6646void KalFitAlg::start_seed(KalFitTrack& track, int lead_, int way, MdcRec_trk& TrasanTRK)
6647{
6648 if (debug_ == 4)
6649 cout << "start_seed begin... " << std::endl;
6650 // keep initial helix parameters
6651 Hep3Vector x_init(track.pivot());
6652 HepSymMatrix Ea_init(5,0);
6653 Ea_init = track.Ea();
6654 HepVector a_init(5);
6655 a_init = track.a();
6656
6657 // LR assumption :
6658 unsigned int nhit_included(10);
6659 int LR[8][3] = {
6660 {1,1,1},
6661 {1,1,-1},
6662 {1,-1,1},
6663 {1,-1,-1},
6664 {-1,1,1},
6665 {-1,1,-1},
6666 {-1,-1,1},
6667 {-1,-1,-1}
6668 };
6669
6670 unsigned int nhit = track.HitsMdc().size();
6671 double chi2_min(DBL_MAX);
6672 int i_min(-1);
6673 for (int ktrial = 0; ktrial < 8; ktrial++) {
6674
6675 // Come back to trasan seed :
6676 track.pivot(x_init);
6677 track.a(a_init);
6678 track.Ea(Ea_init);
6679
6680 track.chiSq(0);
6681 track.chiSq_back(0);
6682 track.nchits(0);
6683 track.nster(0);
6684 track.ndf_back(0);
6685
6686 HepSymMatrix Eakal(5,0);
6687
6688 init_matrix(choice_,TrasanTRK, Eakal);
6689 // initialize the Mdc hits :
6690 for( unsigned i=0 ; i < nhit; i++ ){
6691 KalFitHitMdc& HitMdc = track.HitMdc(i);
6692 int lr_decision(0);
6693 if (i<3) lr_decision = LR[ktrial][i];
6694 HitMdc.LR(lr_decision);
6695 if (i<nhit_included)
6696 HitMdc.chi2(0);
6697 else
6698 HitMdc.chi2(-1);
6699 }
6700 // Mdc fit the ... first hits :
6701
6702 if(usage_==0) filter_fwd_anal(track, lead_, way, Eakal);
6703 way=999;
6704 if(usage_>0) filter_fwd_calib(track, lead_, way, Eakal);
6705
6706 // Check the chi2
6707 if (debug_ == 4)
6708 cout << "---- Result for " << ktrial << " case : chi2 = " << track.chiSq()
6709 << ", nhits included = " << track.nchits() << " for nhits available = "
6710 << nhit << std::endl;
6711
6712 if (track.chiSq() < chi2_min &&
6713 (track.nchits() == nhit_included || track.nchits() == nhit)){
6714 chi2_min = track.chiSq();
6715 i_min = ktrial;
6716 }
6717 }
6718
6719 // Initialize to the best solution :
6720 if (debug_ == 4)
6721 cout << "*** i_min = " << i_min << " with a chi2 = " << chi2_min << std::endl;
6722
6723 for( unsigned i=0 ; i < nhit; i++ ){
6724 KalFitHitMdc& HitMdc = track.HitMdc(i);
6725 int lr_decision(0);
6726 if (i_min >= 0 && i < 3)
6727 lr_decision = LR[i_min][i];
6728 HitMdc.LR(lr_decision);
6729 HitMdc.chi2(0);
6730 HitMdc.chi2_back(0);
6731 }
6732 track.pivot(x_init);
6733 track.a(a_init);
6734 track.Ea(Ea_init);
6735 track.chiSq(0);
6736 track.chiSq_back(0);
6737 track.nchits(0);
6738 track.nster(0);
6739 track.ndf_back(0);
6740
6741 // For debugging purpose :
6742 if (debug_ == 4) {
6743 for( unsigned i=0 ; i < 3; i++ ){
6744 KalFitHitMdc& HitMdc = track.HitMdc(i);
6745 cout << " LR(" << i << ") = " << HitMdc.LR()
6746 << ", stereo = " << HitMdc.wire().stereo()
6747 << ", layer = " << HitMdc.wire().layer().layerId() << std::endl;
6748 }
6749 }
6750}
6751
6752// this function is added to clear tables after processing each event
6753// to avoid memory leak,because of the usage of MdcTables etc.
6754// Apr. 2005
6756
6757 if(debug_ == 4) cout<<"Begining to clear Tables ...."<<endl;
6758 vector<MdcRec_trk>* mdcMgr = MdcRecTrkCol::getMdcRecTrkCol();
6759 vector<MdcRec_trk_add>* mdc_addMgr = MdcRecTrkAddCol::getMdcRecTrkAddCol();
6760 vector<MdcRec_wirhit>* whMgr = MdcRecWirhitCol::getMdcRecWirhitCol();
6761 vector<MdcRec_trk>::iterator tit=mdcMgr->begin();
6762 for( ; tit != mdcMgr->end(); tit++) {
6763 vector<MdcRec_wirhit*>::iterator vit= tit->hitcol.begin() ;
6764 for(; vit != tit->hitcol.end(); vit++) {
6765 delete (*vit);
6766 }
6767 }
6768
6769 mdcMgr->clear();
6770 mdc_addMgr->clear();
6771 whMgr->clear();
6772
6773 // delete mdcMgr;
6774 // delete mdc_addMgr;
6775 // delete whMgr;
6776 // mdcMgr = 0;
6777 // mdc_addMgr = 0;
6778 // whMgr = 0;
6779
6780}
6781
6782bool KalFitAlg::order_rechits(const SmartRef<RecMdcHit>& m1, const SmartRef<RecMdcHit>& m2) {
6783 return MdcID::layer(m1->getMdcId()) > MdcID::layer(m2->getMdcId());
6784}
6785
6786/*void KalFitAlg::makeGemHitsCol()
6787 {
6788 bool giveCout=true;
6789
6790 for(int i=0; i<4; i++) myGemHitCol[i].clear();
6791
6792 SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
6793 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
6794
6795 int nHits, nDigi;
6796 unsigned int stripIndx, isVStrip;
6797 int layer;
6798 double x, y, z, r, phi;
6799
6800 nHits = mdcMcHitCol->size();
6801 nDigi = mdcDigiCol->size();
6802
6803//cout<<__FUNCTION__<<":: nHits = "<<nHits<<endl;
6804
6805Rndm::Numbers gaussRPhi(randSvc(), Rndm::Gauss(0.,myRphiResGem));
6806Rndm::Numbers gaussZ(randSvc(), Rndm::Gauss(0.,myZResGem));
6807
6808MdcMcHitCol::const_iterator it = mdcMcHitCol->begin();
6809
6810if(giveCout) cout<<endl<<endl<<" ------------- Mdc MC hits: ------------"<<endl<<endl;
6811
6812for(;it!=mdcMcHitCol->end(); it++)
6813{
6814Identifier id= (*it)->identify();
6815layer = MdcID::layer(id);
6816//if(layer>(useNCGem_-1)) continue;
6817if(layer>4) continue;
6818stripIndx = (*it)->getDriftDistance();
6819isVStrip = (*it)->getPositionFlag();
6820x = ((*it)->getPositionX())*0.1; // mm->cm
6821y = ((*it)->getPositionY())*0.1; // mm->cm
6822z = ((*it)->getPositionZ())*0.1; // mm->cm
6823r=sqrt(x*x+y*y);
6824phi=atan2(y,x);
6825if(giveCout) {
6826cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isVStrip<<endl;
6827cout<<" true x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
6828}
6829if(layer<4&&myGemHitCol[layer].empty())
6830{
6831if(giveCout) cout<<"myGemHitCol["<<layer<<"] is empty"<<endl;
6832double phiResam = phi+gaussRPhi()/r;
6833while(phi>M_PI) phi-=2.0*M_PI;
6834while(phi<-M_PI) phi+=2.0*M_PI;
6835double zResam = z+gaussZ();
6836KalFitGemHit aKalFitGemHit(phiResam,zResam,r,myRphiResGem,myZResGem);
6837if(giveCout) {
6838cout<<" resam x, y, z, phi, r = "<<x<<", "<<y<<", "<<zResam<<", "<<phiResam<<", "<<r<<endl;
6839cout<<" Dphi, Dz = "<<phiResam-phi<<", "<<zResam-z<<endl;
6840cout<<" nSigPhi, nSigZ = "<<(phiResam-phi)*r/myRphiResGem<<", "<<(zResam-z)/myZResGem<<endl;
6841}
6842if(phi>M_PI||phi<-M_PI) cout<<__FUNCTION__<<": phi = "<<phi<<endl;
6843myGemHitCol[layer].push_back(aKalFitGemHit);
6844}
6845}
6846
6847//cout<<endl<<endl<<" ------------- Mdc digi: ------------"<<endl<<endl;
6848
6849MdcDigiCol::const_iterator it_digi = mdcDigiCol->begin();
6850for(;it_digi!=mdcDigiCol->end(); it_digi++)
6851{
6852Identifier id = (*it_digi)->identify();
6853layer = MdcID::layer(id);
6854if(layer>4) continue;
6855double stripId = RawDataUtil::MdcTime((*it_digi)->getTimeChannel());
6856double isV = RawDataUtil::MdcCharge((*it_digi)->getChargeChannel());
6857//cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripId<<", "<<isV<<endl;
6858stripIndx=stripId+0.5;
6859//cout<<" stripIndx = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isV<<endl;
6860}
6861
6862///
6863// --- print out GEM hits
6864if(giveCout) cout<<endl<<"------- GEM hits: --------"<<endl;
6865//for(int i=0; i<useNCGem_; i++)
6866for(int i=0; i<4; i++)
6867{
6868 if(giveCout) cout<<"### layer "<<i<<endl;
6869 //int nhits = myGemHitCol[i].size();
6870 KalFitGemHitCol::const_iterator it_GemHit = (myGemHitCol[i]).begin();
6871 for(int j=0; it_GemHit!=(myGemHitCol[i]).end(); it_GemHit++, j++)
6872 {
6873 if(giveCout) cout<<" hit "<<(j+1)<<": phi, z, r = "<<it_GemHit->getPhi()<<", "<<it_GemHit->getZ()<<", "<<it_GemHit->getR()<<endl;
6874 if(ntuple_&1) m_rGem[i] = it_GemHit->getR();
6875 }
6876}
6877///
6878}
6879*/
6880
6881
6883{
6884 double rMaxInnerWall=6.42005+0.00495;
6885 if(useNCGem_>1) { // GEM mode
6886 //rMaxInnerWall=m_CGEM.end()->radius();
6887 //rMaxInnerWall=16.7;
6888 rMaxInnerWall=m_innerWall[0].radius();
6889 }
6890 else { // MDC mode
6891 rMaxInnerWall=_BesKalmanFitWalls[0].radius();
6892 }
6893 double dPhiToInnerWall = track.intersect_cylinder(rMaxInnerWall);
6894 HepPoint3D posAtInnerWall = track.x(dPhiToInnerWall);
6895 double pathToInnerWall;
6896 track.pivot_numf(posAtInnerWall, pathToInnerWall);
6897 //cout<<"__FUNCTION__: rMaxInnerWall = "<<rMaxInnerWall<<endl;
6898 //cout<<"posAtInnerWall, pathToInnerWall = "<<posAtInnerWall<<", "<<pathToInnerWall<<endl;
6899 if(pathToInnerWall>0)
6900 {
6901 if(muls_) track.ms(pathToInnerWall, _BesKalmanFitMaterials[0], way);
6902 if(loss_) track.eloss(pathToInnerWall, _BesKalmanFitMaterials[0], way);
6903 }
6904 if(useNCGem_>0) m_innerWall[0].updateTrack(track, way);
6905
6906}
6907
6908
6909/*void KalFitAlg::fitGemHits(KalFitTrack& track, int hypo, int way)
6910 {
6911 bool printOut=false;
6912 if(printOut) {
6913 cout<<endl;
6914 cout<<"--------------------------------------"<<endl;
6915 cout<<"start GEM Kalman fit: hypo = "<<hypo<<endl;
6916 cout<<"--------------------------------------"<<endl;
6917 }
6918//int iLayer=useNCGem_-1;
6919int nLayer=4;
6920switch(useNCGem_)
6921{
6922case 0: nLayer=0; break;
6923case 1: nLayer=1; break;
6924case 2: nLayer=2; break;
6925case 3:
6926case 13:
6927nLayer=3; break;
6928case 4:
6929case 14:
6930nLayer=4; break;
6931}
6932int iLayer=nLayer-1;
6933//for(int iLayer=3; iLayer>=0; iLayer--)
6934int nGemLayers=m_CGEM.size();
6935double rGem, rmax, rmin;
6936for(int iGem=nGemLayers-1; iGem>=0; iGem--)
6937//for(int i=nGemLayers-1; i>=0; i--)
6938{
6939//if(way) iGem=i;
6940if(printOut) cout<<"rGem = "<<m_CGEM[iGem].radius()<<endl;
6941if(iLayer>=0) rGem=(myGemHitCol[iLayer].begin())->getR();
6942rmax = m_CGEM[iGem].radius();
6943rmin = m_CGEM[iGem].rmin();
6944if(iLayer>=0 && rGem<rmax && rGem>rmin)
6945{
6946if(myUseGemPos3D) {
6947if(printOut) {
6948cout<<"in GEM 3D coorinate fit "<<endl;
6949cout<<"iLayer = "<<iLayer<<endl;
6950cout<<"rGemLayerMax = "<<m_CGEM[iGem].radius()<<endl;
6951}
6952rmax=m_CGEM[iGem].radius();
6953double dPhiToGem = track.intersect_cylinder(rmax);
6954HepPoint3D posEstiAtGem = track.x(dPhiToGem);
6955track.pivot_numf(posEstiAtGem);
6956int nHits=myGemHitCol[iLayer].size();
6957if(nHits!=1) continue;
6958//rGem=(myGemHitCol[iLayer].begin())->getR();
6959double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
6960double zGem=(myGemHitCol[iLayer].begin())->getZ();
6961HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos3D();
6962if(printOut) cout<<"v_measu,rGem = "<<v_measu<<", "<<rGem<<endl;
6963dPhiToGem = track.intersect_cylinder(rGem);
6964posEstiAtGem = track.x(dPhiToGem);
6965double x0=posEstiAtGem.x();
6966double y0=posEstiAtGem.y();
6967double z0=posEstiAtGem.z();
6968double pathInGem;
6969track.pivot_numf(posEstiAtGem, pathInGem);
6970if(pathInGem>0)
6971{
6972if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
6973if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
6974}
6975double rGemEsti=posEstiAtGem.perp();
6976double phiGemEsti=posEstiAtGem.phi();
6977double zGemEsti=posEstiAtGem.z();
6978HepVector v_estim(3,0);
6979v_estim(1)=x0;
6980v_estim(2)=y0;
6981v_estim(3)=z0;
6982if(printOut) {
6983 cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
6984 cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
6985}
6986const HepSymMatrix& Ea = track.Ea();
6987HepVector v_a = track.a();
6988double phi0=v_a(2);
6989if(printOut) {
6990 cout<<"v_a = "<<v_a<<endl;
6991 cout<<"phi0 = "<<phi0<<endl;
6992}
6993// --- derivative matrix
6994HepMatrix H(3, 5, 0);
6995double c=1.0;
6996if(x0*y0>0.0) c=-1.0;
6997H(1,1)=cos(phi0);
6998H(2,1)=sin(phi0);
6999H(3,4)=1.0;
7000if(printOut) cout<<"H="<<H<<endl;
7001HepMatrix H_T=H.T();
7002if(printOut) cout<<"H_T="<<H_T<<endl;
7003// --- error matrix of Gem hit
7004HepSymMatrix V=(myGemHitCol[iLayer].begin())->getErrMat3D();
7005if(printOut) cout<<"V="<<V<<endl;
7006HepMatrix HEa=H*Ea;
7007HepMatrix HEaH_T=HEa*H_T;
7008if(printOut) cout<<"HEaH_T="<<HEaH_T<<endl;
7009int ierr=-1;
7010HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
7011if(printOut) cout<<"Vinv="<<Vinv<<endl;
7012if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
7013// --- gain matrix
7014HepMatrix K=Ea*H_T*Vinv;
7015if(printOut) cout<<"K="<<K<<endl;
7016// --- new error matrix
7017HepSymMatrix EaNew(5,0);
7018EaNew.assign(Ea-K*H*Ea);
7019// --- diff
7020HepVector v_diff=v_measu-v_estim;
7021//double delPhi=v_diff(1);
7022//while(delPhi> M_PI) delPhi-=2.0*M_PI;
7023//while(delPhi<-M_PI) delPhi+=2.0*M_PI;
7024//v_diff(1)=delPhi;
7025if(printOut) cout<<"v_diff = "<<v_diff<<endl;
7026// --- new parameters
7027HepVector aNew=v_a+K*v_diff;
7028// --- new v_estim
7029KalFitTrack track_test(posEstiAtGem,aNew,EaNew,track.mass(),0.0,track.nchits());
7030double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7031HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7032double phiGemEsti_new=posEstiAtGem_new.phi();
7033double zGemEsti_new=posEstiAtGem_new.z();
7034double x0_new = posEstiAtGem_new.x();
7035double y0_new = posEstiAtGem_new.y();
7036double z0_new = posEstiAtGem_new.z();
7037HepVector v_estim_new(3,0);
7038v_estim_new(1)=x0_new;
7039v_estim_new(2)=y0_new;
7040v_estim_new(3)=z0_new;
7041if(printOut) cout<<"v_estim_new = "<<v_estim_new<<endl;
7042// --- diff between measurement and updated estimation
7043v_diff=v_measu-v_estim_new;
7044if(printOut) cout<<"v_diff_new = "<<v_diff<<endl;
7045// --- new derivative matrix
7046track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7047HepVector v_a_new = track_test.a();
7048HepSymMatrix Ea_new = track_test.Ea();
7049double phi0_new = v_a_new(2);
7050HepMatrix H_new(3, 5, 0);
7051H_new(1,1)=cos(phi0_new);
7052H_new(2,1)=sin(phi0_new);
7053H_new(3,4)=1.0;
7054HepMatrix H_new_T=H_new.T();
7055// --- R mactrix
7056if(printOut) cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7057HepSymMatrix R(3,0);
7058R.assign(V-H_new*Ea_new*H_new_T);
7059// --- Chi^2 added
7060HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7061if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7062if(printOut) cout<<"v_dChi2 = "<<v_dChi2<<endl;
7063double dChi2=v_dChi2(1);
7064if(ntuple_&1 && hypo==1) {
7065 m_chi2Gem[iLayer]=dChi2;
7066 m_phiGemExp[iLayer]=phiGemEsti;
7067 m_phiGemHit[iLayer]=v_measu(1);
7068 m_zGemExp[iLayer]=zGemEsti;
7069 m_zGemHit[iLayer]=v_measu(2);
7070}
7071// --- comparison
7072//
7073if(printOut) {
7074 cout<<"pivot: "<<posEstiAtGem<<endl;
7075 cout<<"new pivot: "<<posEstiAtGem_new<<endl;
7076 cout<<"a: "<<v_a<<endl;
7077 cout<<"new a: "<<v_a_new<<endl;
7078 cout<<"Ea: "<<Ea<<endl;
7079 cout<<"new Ea: "<<Ea_new<<endl;
7080 cout<<"dchi2= "<<dChi2<<endl;
7081}
7082//
7083// --- update KalFitTrack
7084if(iLayer>=0) track.set(posEstiAtGem_new,v_a_new,Ea_new);
7085//track.a(aNew);
7086//track.Ea(EaNew);
7087iLayer--;
7088// --- move track to rmin of this layer
7089rmin = m_CGEM[iGem].rmin();
7090dPhiToGem = track.intersect_cylinder(rmin);
7091posEstiAtGem = track.x(dPhiToGem);
7092track.pivot_numf(posEstiAtGem, pathInGem);
7093if(pathInGem>0)
7094{
7095 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
7096 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
7097}
7098}
7099else {
7100 if(printOut) {
7101 cout<<"iLayer = "<<iLayer<<endl;
7102 cout<<"rGemLayerMax = "<<m_CGEM[iGem].radius()<<endl;
7103 }
7104 rmax=m_CGEM[iGem].radius();
7105 double dPhiToGem = track.intersect_cylinder(rmax);
7106 HepPoint3D posEstiAtGem = track.x(dPhiToGem);
7107 track.pivot_numf(posEstiAtGem);
7108 int nHits=myGemHitCol[iLayer].size();
7109 if(nHits!=1) continue;
7110 //rGem=(myGemHitCol[iLayer].begin())->getR();
7111 double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
7112 double zGem=(myGemHitCol[iLayer].begin())->getZ();
7113 HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos();
7114 if(printOut) cout<<"v_measu,rGem = "<<v_measu<<", "<<rGem<<endl;
7115 dPhiToGem = track.intersect_cylinder(rGem);
7116 posEstiAtGem = track.x(dPhiToGem);
7117 double x0=posEstiAtGem.x();
7118 double y0=posEstiAtGem.y();
7119 double z0=posEstiAtGem.z();
7120 double pathInGem;
7121 track.pivot_numf(posEstiAtGem, pathInGem);
7122 if(pathInGem>0)
7123 {
7124 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
7125 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
7126 }
7127 double rGemEsti=posEstiAtGem.perp();
7128 double phiGemEsti=posEstiAtGem.phi();
7129 double zGemEsti=posEstiAtGem.z();
7130 HepVector v_estim(2,0);
7131 v_estim(1)=phiGemEsti;
7132 v_estim(2)=zGemEsti;
7133 if(printOut) {
7134 cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
7135 cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
7136 }
7137 const HepSymMatrix& Ea = track.Ea();
7138 HepVector v_a = track.a();
7139 double phi0=v_a(2);
7140 if(printOut) {
7141 cout<<"v_a = "<<v_a<<endl;
7142 cout<<"phi0 = "<<phi0<<endl;
7143 }
7144 // --- derivative matrix
7145 HepMatrix H(2, 5, 0);
7146 double c=1.0;
7147 //if(x0*y0>0.0&&useNCGem_==3&&iLayer==1) c=-1.0;
7148 //if(x0*y0>0.0) c=-1.0;
7149 //H(1,1)=c*(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
7150 H(1,1)=(x0*sin(phi0)-y0*cos(phi0))/(x0*x0+y0*y0);
7151 H(2,4)=1.0;
7152 if(printOut) cout<<"H="<<H<<endl;
7153 HepMatrix H_T=H.T();
7154 if(printOut) cout<<"H_T="<<H_T<<endl;
7155 // --- error matrix of Gem hit
7156 HepSymMatrix V=(myGemHitCol[iLayer].begin())->getErrMat();
7157 if(printOut) cout<<"V="<<V<<endl;
7158 HepMatrix HEa=H*Ea;
7159 HepMatrix HEaH_T=HEa*H_T;
7160 if(printOut) cout<<"HEaH_T="<<HEaH_T<<endl;
7161 int ierr=-1;
7162 HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
7163 if(printOut) cout<<"Vinv="<<Vinv<<endl;
7164 if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
7165 // --- gain matrix
7166 HepMatrix K=Ea*H_T*Vinv;
7167 if(printOut) cout<<"K="<<K<<endl;
7168 // --- new error matrix
7169 HepSymMatrix EaNew(5,0);
7170 EaNew.assign(Ea-K*H*Ea);
7171 // --- diff
7172 HepVector v_diff=v_measu-v_estim;
7173 double delPhi=v_diff(1);
7174 while(delPhi> M_PI) delPhi-=2.0*M_PI;
7175 while(delPhi<-M_PI) delPhi+=2.0*M_PI;
7176 v_diff(1)=delPhi;
7177 if(printOut) cout<<"v_diff = "<<v_diff<<endl;
7178 // --- new parameters
7179 HepVector aNew=v_a+K*v_diff;
7180 // --- new v_estim
7181 KalFitTrack track_test(posEstiAtGem,aNew,EaNew,track.mass(),0.0,track.nchits());
7182 double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7183 HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7184 double phiGemEsti_new=posEstiAtGem_new.phi();
7185 double zGemEsti_new=posEstiAtGem_new.z();
7186 double x0_new = posEstiAtGem_new.x();
7187 double y0_new = posEstiAtGem_new.y();
7188 HepVector v_estim_new(2,0);
7189 v_estim_new(1)=phiGemEsti_new;
7190 v_estim_new(2)=zGemEsti_new;
7191 if(printOut) cout<<"v_estim_new = "<<v_estim_new<<endl;
7192 // --- diff between measurement and updated estimation
7193 v_diff=v_measu-v_estim_new;
7194 delPhi=v_diff(1);
7195 while(delPhi> M_PI) delPhi-=2.0*M_PI;
7196 while(delPhi<-M_PI) delPhi+=2.0*M_PI;
7197 if(printOut) cout<<"v_diff_new = "<<v_diff<<endl;
7198 // --- new derivative matrix
7199 track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7200 HepVector v_a_new = track_test.a();
7201 HepSymMatrix Ea_new = track_test.Ea();
7202 double phi0_new = v_a_new(2);
7203 HepMatrix H_new(2, 5, 0);
7204 c=1.0;
7205 //if(x0_new*y0_new>0.0&&useNCGem_==3&&iLayer==1) c=-1.0;
7206 if(x0_new*y0_new>0.0) c=-1.0;
7207 //H_new(1,1)=c*(x0_new*cos(phi0_new)-y0_new*sin(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7208 H_new(1,1)=(x0_new*sin(phi0_new)-y0_new*cos(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7209 H_new(2,4)=1.0;
7210 HepMatrix H_new_T=H_new.T();
7211 // --- R mactrix
7212 if(printOut) cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7213 HepSymMatrix R(2,0);
7214 R.assign(V-H_new*Ea_new*H_new_T);
7215 // --- Chi^2 added
7216 HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7217 if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7218 if(printOut) cout<<"v_dChi2 = "<<v_dChi2<<endl;
7219 double dChi2=v_dChi2(1);
7220 if(ntuple_&1 && hypo==1) {
7221 m_chi2Gem[iLayer]=dChi2;
7222 m_phiGemExp[iLayer]=phiGemEsti;
7223 m_phiGemHit[iLayer]=v_measu(1);
7224 m_zGemExp[iLayer]=zGemEsti;
7225 m_zGemHit[iLayer]=v_measu(2);
7226 }
7227 // --- comparison
7228 //
7229 if(printOut) {
7230 cout<<"pivot: "<<posEstiAtGem<<endl;
7231 cout<<"new pivot: "<<posEstiAtGem_new<<endl;
7232 cout<<"a: "<<v_a<<endl;
7233 cout<<"new a: "<<v_a_new<<endl;
7234 cout<<"Ea: "<<Ea<<endl;
7235 cout<<"new Ea: "<<Ea_new<<endl;
7236 cout<<"dchi2= "<<dChi2<<endl;
7237 }
7238 //
7239 // --- update KalFitTrack
7240 if(iLayer>=0) track.set(posEstiAtGem_new,v_a_new,Ea_new);
7241 //track.a(aNew);
7242 //track.Ea(EaNew);
7243 iLayer--;
7244 // --- move track to rmin of this layer
7245 rmin = m_CGEM[iGem].rmin();
7246 dPhiToGem = track.intersect_cylinder(rmin);
7247 posEstiAtGem = track.x(dPhiToGem);
7248 track.pivot_numf(posEstiAtGem, pathInGem);
7249 if(pathInGem>0)
7250 {
7251 if(muls_) track.ms(pathInGem, m_CGEM[iGem].material(), way);
7252 if(loss_) track.eloss(pathInGem, m_CGEM[iGem].material(), way);
7253 }
7254}
7255}// if hit in this layer
7256else {
7257 m_CGEM[iGem].updateTrack(track, way);
7258}
7259}// loop GEM layers
7260// end of GEM Kalman fit
7261//cout<<"finish GEM part"<<endl;
7262
7263}*/
7265{
7266 for(int i=0; i<3; i++) myGemHitCol[i].clear();
7267
7268 /*SmartDataPtr<Event::MdcMcHitCol> mdcMcHitCol(eventSvc(), "/Event/MC/MdcMcHitCol");
7269 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
7270
7271 int nHits, nDigi;
7272 unsigned int stripIndx, isVStrip;
7273 int layer;
7274 double x, y, z, r, phi;
7275
7276 nHits = mdcMcHitCol->size();
7277 nDigi = mdcDigiCol->size();
7278
7279 //cout<<__FUNCTION__<<":: nHits = "<<nHits<<endl;
7280
7281 Rndm::Numbers gaussRPhi(randSvc(), Rndm::Gauss(0.,0.023));
7282 Rndm::Numbers gaussZ(randSvc(), Rndm::Gauss(0.,0.05));
7283
7284 MdcMcHitCol::const_iterator it = mdcMcHitCol->begin();
7285
7286 cout<<endl<<endl<<" ------------- Mdc MC hits: ------------"<<endl<<endl;*/
7287
7288 SmartDataPtr<RecCgemClusterCol> cgemClusterCol(eventSvc(),"/Event/Recon/RecCgemClusterCol");
7289 int layer,sheet;
7290 double phi,v;
7291 RecCgemClusterCol::const_iterator it = cgemClusterCol->begin();
7292 for(;it!=cgemClusterCol->end();it++){
7293 //cout<<"cluster:"<<(*it)->getclusterid()<<" phi:"<<(*it)->getrecphi()<<" z:"<<(*it)->getRecZ()<<endl;
7294 if((*it)->getflag()==2){
7295 layer = (*it)->getlayerid();
7296 sheet = (*it)->getsheetid();
7297 phi = (*it)->getrecphi();
7298 v = (*it)->getrecv();
7299 KalFitGemHit aKalFitGemHit(phi,v,layer,sheet);
7300 myGemHitCol[layer].push_back(aKalFitGemHit);
7301 }
7302 }
7303 if(debug_==4){
7304 cout << "Gem information" << endl;
7305 cout << "first layer " << myGemHitCol[0].size() << endl;
7306 cout << "second layer" << myGemHitCol[1].size() << endl;
7307 cout << "third layer" << myGemHitCol[2].size() << endl;
7308 }
7309 /*
7310 for(;it!=mdcMcHitCol->end(); it++)
7311 {
7312 Identifier id= (*it)->identify();
7313 layer = MdcID::layer(id);
7314 if(layer>7) continue;
7315 stripIndx = (*it)->getDriftDistance();
7316 isVStrip = (*it)->getPositionFlag();
7317 x = ((*it)->getPositionX())*0.1; // mm->cm
7318 y = ((*it)->getPositionY())*0.1; // mm->cm
7319 z = ((*it)->getPositionZ())*0.1; // mm->cm
7320 r=sqrt(x*x+y*y);
7321 phi=atan2(y,x);
7322 cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isVStrip<<endl;
7323 //cout<<" true x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
7324 if(myGemHitCol[layer].empty())
7325 {
7326 //cout<<"myGemHitCol["<<layer<<"] is empty"<<endl;
7327 phi+=gaussRPhi()/r;
7328 while(phi>M_PI) phi-=M_PI2;
7329 while(phi<-M_PI) phi+=M_PI2;
7330 z+=gaussZ();
7331 KalFitGemHit aKalFitGemHit(phi,z,r);
7332 //cout<<" resam x, y, z, phi, r = "<<x<<", "<<y<<", "<<z<<", "<<phi<<", "<<r<<endl;
7333 myGemHitCol[layer].push_back(aKalFitGemHit);
7334 }
7335 }
7336
7337 cout<<endl<<endl<<" ------------- Mdc digi: ------------"<<endl<<endl;
7338
7339 MdcDigiCol::const_iterator it_digi = mdcDigiCol->begin();
7340 for(;it_digi!=mdcDigiCol->end(); it_digi++)
7341 {
7342 Identifier id = (*it_digi)->identify();
7343 layer = MdcID::layer(id);
7344 if(layer>7) continue;
7345 double stripId = RawDataUtil::MdcTime((*it_digi)->getTimeChannel());
7346 double isV = RawDataUtil::MdcCharge((*it_digi)->getChargeChannel());
7347 cout<<"id, layer , stripIndx, isVSTrip = "<<id<<", "<<layer<<", "<<stripId<<", "<<isV<<endl;
7348 stripIndx=stripId+0.5;
7349 cout<<" stripIndx = "<<id<<", "<<layer<<", "<<stripIndx<<", "<<isV<<endl;
7350 }
7351 */
7352
7353 // --- print out GEM hits
7354 bool prtGemHits=false;
7355 //bool prtGemHits=true;
7356 if(prtGemHits) cout<<endl<<"------- GEM hits: --------"<<endl;
7357 for(int i=0; i<3; i++)
7358 {
7359 if(prtGemHits) cout<<"### layer "<<i<<endl;
7360 //int nhits = myGemHitCol[i].size();
7361 KalFitGemHitCol::const_iterator it_GemHit = (myGemHitCol[i]).begin();
7362 for(int j=0; it_GemHit!=(myGemHitCol[i]).end(); it_GemHit++, j++)
7363 {
7364 if(prtGemHits) cout<<" hit "<<(j+1)<<": phi, z, r = "<<it_GemHit->getPhi()<<", "<<it_GemHit->getZ()<<", "<<it_GemHit->getR()<<endl;
7365 }
7366 }
7367
7368}
7369void KalFitAlg::fitGemHits(KalFitTrack& track, int hypo, int way)
7370{
7371 {
7372 //cout<<endl;
7373 //cout<<"--------------------------------------"<<endl;
7374 //cout<<"start GEM Kalman fit: hypo = "<<hypo<<endl;
7375 //cout<<"--------------------------------------"<<endl;
7376 // std::vector<double> dchi2_all;
7377 // std::vector<HepPoint3D> posnew;
7378 // std::vector<HepSymMatrix> eanew;
7379 // std::vector<HepVector> anew;
7380 //std::map<int,double> dchi2;
7381 std::map<double,double> esti1_r;
7382 std::map<double,double> esti2_r;
7383 std::map<double,double> esti1_phi;
7384 std::map<double,double> esti2_phi;
7385 std::map<double,double> esti1_z;
7386 std::map<double,double> esti2_z;
7387 std::map<double,double> diff1_phi;
7388 std::map<double,double> diff1_z;
7389 std::map<double,double> diff2_phi;
7390 std::map<double,double> diff2_z;
7391 std::map<double,HepPoint3D> posnew;
7392 std::map<double,HepSymMatrix> eanew;
7393 std::map<double,HepVector> anew;
7394 std::map<double,double> meas_r;
7395 std::map<double,double> meas_phi;
7396 std::map<double,double> meas_z;
7397 std::map<double,double> meas_phierr;
7398 std::map<double,double> esti_phierr;
7399 std::map<double,double> meas_zerr;
7400 std::map<double,double> esti_zerr;
7401 int ii=0;
7402 if(debug_==4){ cout << "wall size" << _BesKalmanFitWalls.size() << endl;}
7403 for(int iLayer=2; iLayer>=0; iLayer--)
7404 {
7405 posnew.clear();
7406 eanew.clear();
7407 anew.clear();
7408 esti1_r.clear();
7409 esti2_r.clear();
7410 esti1_phi.clear();
7411 esti2_phi.clear();
7412 esti1_z.clear();
7413 esti2_z.clear();
7414 diff1_phi.clear();
7415 diff1_z.clear();
7416 diff2_phi.clear();
7417 diff2_z.clear();
7418 meas_r.clear();
7419 meas_phi.clear();
7420 meas_z.clear();
7421 meas_phierr.clear();
7422 meas_zerr.clear();
7423 esti_phierr.clear();
7424 esti_zerr.clear();
7425 //cout<<"iLayer = "<<iLayer<<endl;
7426 int nHits=myGemHitCol[iLayer].size();
7427 //cout << "nhits" << nHits << "in layer" << iLayer << endl;
7428
7429 if (nHits <= 0) continue;
7430 //if(nHits!=1) continue;
7431
7432 vector<KalFitGemHit>::iterator iter;
7433 int ihit=0;
7434 // int ii=0;
7435 //cout <<"track before" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;
7436 innerwall(track,hypo,way,64+iLayer*(-32),88+iLayer*(-32));
7437 KalFitTrack track_start(track);
7438 //cout << "now position" << track_start.pivot().perp() << ","<< track_start.pivot().phi() << "," << track_start.pivot().z() <<endl;
7439 for(iter=myGemHitCol[iLayer].begin();iter!=myGemHitCol[iLayer].end();iter++ )
7440 {
7441 //cout <<"track" << "pivot=" << track.pivot() << "a=" << track.a() << "ea=" <<track.Ea() << endl;
7442 track.set(track_start.pivot(),track_start.a(),track_start.Ea());
7443 //cout << "track start" << "pivot=" << track_start.pivot() << "a=" << track_start.a() << "ea=" << track_start.Ea() << endl;
7444 double rGem=(*iter).getR();
7445 double phiGem=(*iter).getPhi();
7446 double zGem=(*iter).getZ();
7447 HepVector v_measu=(*iter).getVecPos();
7448 //cout << "hit" << ihit << "r=" << rGem << "phi=" << phiGem << "z=" << zGem << endl;
7449 // cout << "v_measu= " << v_measu << endl;
7450 /*
7451 double rGem=(myGemHitCol[iLayer].begin())->getR();
7452 double phiGem=(myGemHitCol[iLayer].begin())->getPhi();
7453 double zGem=(myGemHitCol[iLayer].begin())->getZ();
7454 HepVector v_measu=(myGemHitCol[iLayer].begin())->getVecPos();
7455 cout<<"v_measu = "<<v_measu<<endl;
7456 */
7457 double dPhiToGem = track.intersect_cylinder(rGem);
7458 //cout << "dPhiToGem=" << dPhiToGem << endl;
7459 HepPoint3D posEstiAtGem = track.x(dPhiToGem);
7460 double x0=posEstiAtGem.x();
7461 double y0=posEstiAtGem.y();
7462 double pathInGem;
7463 //cout << "before move" << "pivot" <<track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7464 track.pivot_numf(posEstiAtGem, pathInGem);
7465 //cout << "posEstiAtGem=" << posEstiAtGem << endl;
7466 //cout << "pathInGem=" << pathInGem << endl;
7467 if(pathInGem>0)
7468 {
7469 if(muls_) track.ms(pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7470 if(loss_) track.eloss(pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7471 }
7472 //cout << "after move" << "pivot" <<track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7473 double rGemEsti=posEstiAtGem.perp();
7474 double phiGemEsti=posEstiAtGem.phi();
7475 double zGemEsti=posEstiAtGem.z();
7476 HepVector v_estim(2,0);
7477 v_estim(1)=phiGemEsti;
7478 v_estim(2)=zGemEsti;
7479 //cout<<"GEM layer "<<iLayer+1<<" : MC r,phi,z="<<rGem<<", "<<phiGem<<", "<<zGem<<endl;
7480 //cout<<" esti r,phi,z="<<rGemEsti<<", "<<phiGemEsti<<", "<<zGemEsti<<endl;
7481 double dPhi=track.intersect_cylinder(rGem);
7482 //cout << "dPhi=" << dPhi << endl;
7483 HepPoint3D pos = track.x(dPhi);
7484 //cout<< "assumed esti phi,z" << pos.phi() << "," << pos.z() << endl;
7485 const HepSymMatrix& Ea = track.Ea();
7486 HepVector v_a = track.a();
7487 double drho=v_a(1);
7488 double phi0=v_a(2);
7489 double kappa=v_a(3);
7490 double tl=v_a(5);
7491 //cout<<"v_a = "<<v_a<<endl;
7492 //cout<<"phi0 = "<<phi0<<endl;
7493 // --- derivative matrix
7494 HepMatrix H(2, 5, 0);
7495 //H(1,2)=(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
7496 //H(2,4)=1.0;
7497 H(1,1)=-y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
7498 //H(1,1)=(x0*cos(phi0)-y0*sin(phi0))/(x0*x0+y0*y0);
7499 //H(1,2)=-y0/(y0*y0+x0*x0)*sin(phi0+dPhi)-x0/(x0*x0+y0*y0)*cos(phi0+dPhi);
7500 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)));
7501 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));
7502 H(2,3)=m_alpha/(kappa*kappa)*tl*dPhi;
7503 H(2,4)=1.0;
7504 H(2,5)=-1*(m_alpha/kappa)*dPhi;
7505 //cout<<"H="<<H<<endl;
7506 HepMatrix H_T=H.T();
7507 //cout<<"H_T="<<H_T<<endl;
7508 //cout << "H*v_a=" << H*v_a << endl;
7509 //cout << "H*v_a+estim=" <<H*v_a+v_estim << endl;
7510 // --- error matrix of Gem hit
7511 HepSymMatrix V=(*iter).getErrMat();
7512 //cout<<"V="<<V<<endl;
7513 HepMatrix HEa=H*Ea;
7514 HepMatrix HEaH_T=HEa*H_T;
7515 int ierr=-1;
7516 HepMatrix Vinv=(V+HEaH_T).inverse(ierr);
7517 if(ierr!=0) cout<<"error in HEaH_T.inverse()!"<<endl;
7518 // --- gain matrix
7519 HepMatrix K=Ea*H_T*Vinv;
7520 // --- new error matrix
7521 HepSymMatrix EaNew(5,0);
7522 EaNew.assign(Ea-K*H*Ea);
7523 // --- diff
7524 HepVector v_diff=v_measu-v_estim;
7525 //cout << "v_diff before= " << v_diff << endl;
7526 double delPhi=v_diff(1);
7527 if(fabs(v_diff(1))>6.28) v_measu(1)=-1*v_measu(1);
7528 while(delPhi> M_PI) delPhi-=M_PI;
7529 while(delPhi<-M_PI) delPhi+=M_PI;
7530 v_diff(1)=delPhi;
7531 //v_diff=v_measu-(H*v_a+v_estim);
7532 //cout<<"v_diff = "<<v_diff<<endl;
7533 // --- new parameters
7534 HepVector aNew=v_a+K*v_diff;
7535 //cout << "matrix K=" << K << endl;
7536 //cout << "aNew=" << aNew << endl;
7537 // --- new v_estim
7538 KalFitTrack track_test(posEstiAtGem,aNew,EaNew,hypo,0.0,track.nchits());
7539 double dPhiToGem_New = track_test.intersect_cylinder(rGem);
7540 HepPoint3D posEstiAtGem_new = track_test.x(dPhiToGem_New);
7541 double phiGemEsti_new=posEstiAtGem_new.phi();
7542 double zGemEsti_new=posEstiAtGem_new.z();
7543 double x0_new = posEstiAtGem_new.x();
7544 double y0_new = posEstiAtGem_new.y();
7545 HepVector v_estim_new(2,0);
7546 v_estim_new(1)=phiGemEsti_new;
7547 v_estim_new(2)=zGemEsti_new;
7548 //cout<<"v_estim_new = "<<v_estim_new<<endl;
7549 //cout << "assumed v_estim_new =" << H*aNew+v_estim << endl;
7550 // --- diff between measurement and updated estimation
7551 v_diff=v_measu-v_estim_new;
7552 delPhi=v_diff(1);
7553 while(delPhi> M_PI) delPhi-=M_PI;
7554 while(delPhi<-M_PI) delPhi+=M_PI;
7555 //cout<<"v_diff_new = "<<v_diff<<endl;
7556 //cout << "H*aNew"<< H*aNew << endl;
7557 //cout << "test v_diff new" << v_measu-v_estim-H*aNew << endl;
7558 // --- new derivative matrix
7559 track_test.pivot_numf(posEstiAtGem_new, pathInGem);
7560 HepVector v_a_new = track_test.a();
7561 //cout << "v_a_new=" << v_a_new << endl;
7562 HepSymMatrix Ea_new = track_test.Ea();
7563 //cout << "Ea_new =" << Ea_new << endl;
7564 double phi0_new = v_a_new(2);
7565 double kappa_new=v_a_new(3);
7566 HepMatrix H_new(2, 5, 0);
7567 //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);
7568 //H_new(2,4)=1.0;
7569 //H_new(1,1)=(x0_new*cos(phi0_new)-y0_new*sin(phi0_new))/(x0_new*x0_new+y0_new*y0_new);
7570
7571 /* 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);
7572 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);
7573 H_new(2,4)=1.0;
7574 H_new(2,5)=-(-333.564095)/kappa_new*dPhiToGem_New;*/
7575 HepMatrix H_new_T=H_new.T();
7576 // --- R mactrix
7577 //cout<<"H_new*Ea_new*H_new_T = "<<H_new*Ea_new*H_new_T<<endl;
7578 //cout << "H*Ea_new*H_T=" << H*Ea_new*H_T << endl;
7579 //cout << "H*EaNew*H_T=" << H*EaNew*H_T<< endl;
7580 //cout << "H_new*Eanew*H_new_T = "<< H_new*EaNew*H_new_T << endl;
7581 //cout << "assumed R=" <<V-H*Ea_new*H_T << endl;
7582 HepSymMatrix R(2,0);
7583 //R.assign(V-H_new*Ea_new*H_new_T);
7584 R.assign(V-H*EaNew*H_T);
7585
7586 //cout << "test track" << "pivot" << track.pivot() << "a" << track.a() << "ea" << track.Ea() << endl;
7587 // --- Chi^2 added
7588 //cout << "v_diff_T=" << v_diff.T() <<endl;
7589 //cout << "v_diff=" << v_diff <<endl;
7590 //cout << "R="<<R << endl;
7591 //cout << "R inverse=" << R.inverse(ierr)<< endl;
7592 HepVector v_dChi2=v_diff.T()*R.inverse(ierr)*v_diff;
7593 if(ierr!=0) cout<<"error in R.inverse()!"<<endl;
7594 //cout<<"v_dChi2 = "<<v_dChi2<<endl;
7595 //cout<< "test dchi2=" << (H*v_a).T()*R.inverse(ierr)*(H*v_a) << endl;
7596 double dChi2=v_dChi2(1);
7597
7598 // --- comparison
7599 if(debug_==4){
7600 cout<<"pivot: "<<posEstiAtGem<<endl;
7601 cout<<"new pivot: "<<posEstiAtGem<<endl;
7602 cout<<"a: "<<v_a<<endl;
7603 cout<<"new a: "<<aNew<<endl;
7604 cout<<"Ea: "<<Ea<<endl;
7605 cout<<"new Ea: "<<EaNew<<endl;
7606 cout<<"dchi2= "<<dChi2<<endl;
7607 }
7608 /* if(ntuple_&1){
7609 m_diff[ii]=delPhi;
7610 cout << v_diff(2) << endl;
7611 m_diffz[ii]=v_diff(2);
7612 m_phi[ii]=phiGem;
7613 m_z[ii]=zGem;
7614 m_Gemdchi2[ii]=dChi2;
7615 m_Glayer[ii]=iLayer;
7616 m_hypo[ii]=hypo;
7617 m_meas_r[ii]=rGem;
7618 m_meas_phi[ii]=phiGem;
7619 m_meas_z[ii]=zGem;
7620 m_esti1_r[ii]=rGemEsti;
7621 m_esti1_phi[ii]=phiGemEsti;
7622 m_esti1_z[ii]=zGemEsti;
7623 m_esti2_r[ii]=rGem;
7624 m_esti2_phi[ii]=phiGemEsti_new;
7625 m_esti2_z[ii]=zGemEsti_new;
7626 m_diff1_phi[ii]=phiGem-phiGemEsti;
7627 m_diff1_z[ii]=zGem-zGemEsti;
7628 m_diff2_phi[ii]=phiGem-phiGemEsti_new;
7629 m_diff2_z[ii]=zGem-zGemEsti_new;
7630 m_Gchi2[ii]=dChi2;
7631 m_GemLayer[ii]=iLayer;
7632 m_mass[ii]=hypo;
7633 } */
7634 // --- update KalFitTrack
7635 //track.set(posEstiAtGem_new,v_a_new,Ea_new);
7636 //dchi2_all.push_back(dChi2);
7637 //posnew.push_back(posEstiAtGem_new);
7638 //anew.push_back(v_a_new);
7639 //eanew.push_back(Ea_new);
7640 //dchi2[ii]=dChi2;
7641 esti1_r[dChi2]=rGemEsti;
7642 esti1_phi[dChi2]=phiGemEsti;
7643 esti1_z[dChi2]=zGemEsti;
7644 esti2_r[dChi2]=rGem;
7645 esti2_phi[dChi2]=phiGemEsti_new;
7646 esti2_z[dChi2]=zGemEsti_new;
7647 diff1_phi[dChi2]=phiGem-phiGemEsti;
7648 diff1_z[dChi2]=zGem-zGemEsti;
7649 diff2_phi[dChi2]=phiGem-phiGemEsti_new;
7650 diff2_z[dChi2]=zGem-zGemEsti_new;
7651 posnew[dChi2]=posEstiAtGem;
7652 anew[dChi2]=aNew;
7653 eanew[dChi2]=EaNew;
7654 meas_r[dChi2]=rGem;
7655 meas_phi[dChi2]=phiGem;
7656 //cout << "meas_phi[dChi2]" << phiGem << endl;
7657 meas_z[dChi2]=zGem;
7658 meas_phierr[dChi2]=sqrt(V[0][0]);
7659 //cout << "meas_phierr[dChi2]" << meas_phierr[dChi2] << endl;
7660 meas_zerr[dChi2]=sqrt(V[1][1]);
7661 //cout << "meas_zerr[dChi2]" << meas_zerr[dChi2] << endl;
7662 esti_phierr[dChi2]=sqrt((H*(track_start.Ea())*H_T)[0][0]);
7663 //cout << "esti_phierr[dChi2]" << esti_phierr[dChi2] << endl;
7664 esti_zerr[dChi2]=sqrt((H*(track_start.Ea())*H_T)[1][1]);
7665 //cout << "esti_zerr[dChi2]" << esti_zerr[dChi2] << endl;
7666
7667 ihit++;
7668 // ii++;
7669 }
7670
7671 //m_Gemhits=ii;
7672 //m_nt7->write();
7673 track.set((posnew.begin())->second,(anew.begin())->second,(eanew.begin()->second));
7674
7675 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(iLayer);
7676 double new_dPhiToGem = track.intersect_cylinder((CgemLayer->getInnerROfGapD())/10);
7677 HepPoint3D new_posEstiAtGem = track.x(new_dPhiToGem);
7678 double new_pathInGem;
7679 //cout << "new_dPhiToGem" << new_dPhiToGem << endl;
7680 //cout << "before move2" << "pivot" <<track.pivot().perp() << "," << track.pivot().phi() << "," << track.pivot().z()<< "a" << track.a() << "ea" << track.Ea() << endl;
7681 track.pivot_numf(new_posEstiAtGem, new_pathInGem);
7682 //cout << "posEstiAtGem2=" << new_posEstiAtGem << endl;
7683 //cout << "pathInGem2=" << new_pathInGem << endl;
7684 if(new_pathInGem>0)
7685 {
7686 if(muls_) track.ms(new_pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7687 if(loss_) track.eloss(new_pathInGem, _BesKalmanFitMaterials[26+32*iLayer], way);
7688 }
7689 //cout << "after move2: " << "pivot" <<track.pivot().perp() << "," << track.pivot().phi() << "," << track.pivot().z() << "a" << track.a() << "ea" << track.Ea() << endl;
7690 if(iLayer>=1){
7691 innerwall(track,hypo,way,90+(-32)*iLayer,95+(-32)*iLayer);}
7692 else{
7693 innerwall(track,hypo,way,90+(-32)*iLayer,94+(-32)*iLayer);}
7694 //cout <<"!!!!ntuple" << ntuple_ << endl;
7695 //cout << "!!!(esti1_phi.begin())->second" << (esti1_phi.begin())->second << endl;
7696 //cout<<" Finish innerwall"<<endl;
7697 if(ntuple_&1)
7698 {
7699 //cout << "good!" << endl;
7700 //cout << "m_esti1_r[ii]0" << m_esti1_r[ii] << endl;
7701 m_esti1_r[ii]=(esti1_r.begin())->second;
7702 //cout << "m_esti1_r[ii]1" << m_esti1_r[ii] << endl;
7703 m_esti1_phi[ii]=(esti1_phi.begin())->second;
7704 m_esti1_z[ii]=(esti1_z.begin())->second;
7705 m_esti2_r[ii]=(esti2_r.begin())->second;
7706 m_esti2_phi[ii]=(esti2_phi.begin())->second;
7707 m_esti2_z[ii]=(esti2_z.begin())->second;
7708 m_diff1_phi[ii]=(diff1_phi.begin())->second;
7709 m_diff1_z[ii]=(diff1_z.begin())->second;
7710 m_diff2_phi[ii]=(diff2_phi.begin())->second;
7711 m_diff2_z[ii]=(diff2_z.begin())->second;
7712 m_Gchi2[ii]=(esti1_r.begin())->first;
7713 m_meas_r[ii]=(meas_r.begin())->second;
7714 m_meas_phi[ii]=(meas_phi.begin())->second;
7715 //cout << "m_meas_phi[ii]" << m_meas_phi[ii] << endl;
7716 m_meas_z[ii]=(meas_z.begin())->second;
7717 m_meas_phierr[ii]=(meas_phierr.begin())->second;
7718 m_meas_zerr[ii]=(meas_zerr.begin())->second;
7719 m_esti_phierr[ii]=(esti_phierr.begin())->second;
7720 m_esti_zerr[ii]=(esti_zerr.begin())->second;
7721 m_GemLayer[ii]=iLayer;
7722 m_mass[ii]=hypo;
7723 }
7724 //cout<<" end of ntuple_"<<endl;
7725 ii++;
7726 }// loop layers
7727 //cout<<"finish layer loop"<<endl;
7728
7729 //SmartDataPtr<Event::EventHeader> evtHeader(eventSvc(),"/Event/EventHeader");
7730 //m_evt3 = evtHeader->eventNumber();
7731 if(ifProdNt10) {
7732 //cout << "m_meas_phi[ii]" << m_meas_phi[0] << endl;
7733 if(m_meas_phi[0]>0 && m_meas_phi[0]<1.5707963) m_qua=0;
7734 if(m_meas_phi[0]>1.5707963 && m_meas_phi[0]<3.1415926) m_qua=1;
7735 if(m_meas_phi[0]>-3.1415926&& m_meas_phi[0]<-1.5707963) m_qua=2;
7736 if(m_meas_phi[0]>-1.5707963&& m_meas_phi[0]<0) m_qua=3;
7737 //cout << "m_qua=" << m_qua << endl;
7738 m_nGemHits=ii;
7739 }
7740 //m_Gemhits=ii;
7741 // m_nt7->write();
7742 // m_nt10->write();
7743 posnew.clear();
7744 eanew.clear();
7745 anew.clear();
7746 esti1_r.clear();
7747 esti2_r.clear();
7748 esti1_phi.clear();
7749 esti2_phi.clear();
7750 esti1_z.clear();
7751 esti2_z.clear();
7752 diff1_phi.clear();
7753 diff1_z.clear();
7754 diff2_phi.clear();
7755 diff2_z.clear();
7756 meas_r.clear();
7757 meas_phi.clear();
7758 meas_z.clear();
7759 meas_phierr.clear();
7760 meas_zerr.clear();
7761 esti_phierr.clear();
7762 esti_zerr.clear();
7763
7764 }// end of GEM Kalman fit
7765 //cout << "end of GEM Kalman fit" << endl;
7766 if(ifProdNt10) {
7767 SmartDataPtr<Event::EventHeader> evtHeader(eventSvc(),"/Event/EventHeader");
7768 //cout << "evtHeader" << m_evt3 << endl;
7769 m_evt3 = evtHeader->eventNumber();
7770 m_nt10->write();
7771 }
7772
7773}
7774
7775
7776
7778{
7779
7780 ///---readin clusters of this track
7781 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
7782 if (!eventHeader) {
7783 cout << "Could not find Event Header" << endl;
7784 }
7785 int eventNo = eventHeader->eventNumber();
7786 int runNo = eventHeader->runNumber();
7787 SmartDataPtr<RecMdcTrackCol> recMdcTrack(eventSvc(),"/Event/Recon/RecMdcTrackCol");
7788 if (!recMdcTrack) {
7789 cout << "Could not find RecMdcTrackCol" << endl;
7790 }
7791 RecMdcTrackCol::iterator itrk = recMdcTrack->begin();
7792 ClusterRefVec clusterRefVec;
7793 for(; itrk != recMdcTrack->end(); itrk++){
7794 if((*itrk)->trackId() == track.trasan_id() && (*itrk)->getNcluster() > 0) {
7795 clusterRefVec = (*itrk)->getVecClusters();
7796 break;
7797 }
7798 else {
7799 if(4 == debug_) cout<<"run:"<<runNo<<" , Event:"<<eventNo<<" , track:"<<track.trasan_id()<<" has no cluster!"<<endl;
7800 }
7801 }
7802
7803 if(debug_==4){ cout<<"wall size"<<_BesKalmanFitWalls.size()<<endl;}
7804
7805 ///---set the start and stop point of fit
7806 ClusterRefVec::iterator itCluster;
7807 ClusterRefVec::iterator itStartFlag;
7808 ClusterRefVec::iterator itStopFlag;
7809 int step;
7810 int index=0;
7811 double lastR;
7812 double R_o_cgem=_BesKalmanFitWalls[0].radius();
7813 if(way<0){
7814 itStartFlag = clusterRefVec.begin();
7815 itStopFlag = clusterRefVec.end();
7816 lastR=0;
7817 step = 1;
7818 }
7819 else {
7820 itStartFlag = clusterRefVec.end()-1;
7821 itStopFlag = clusterRefVec.begin()-1;
7822 lastR=R_o_cgem;
7823 step = -1;
7824 double pathl;
7825 track.pivot_numf(track.x(track.intersect_cylinder(R_o_cgem)),pathl);
7826 if(KalFitElement::muls()) track.msgasmdc(pathl, way);
7827 if(KalFitElement::loss()) track.eloss(pathl, _BesKalmanFitMaterials[0], way);
7828 }
7829
7830 ///---update track
7831 for(itCluster = itStartFlag; itCluster !=itStopFlag; itCluster = itCluster + step){
7832 int layer = (*itCluster)->getlayerid();
7833 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(layer);
7834 double dmR = CgemLayer->getMiddleROfGapD()/10;
7835 innerwall(track,hypo,way,lastR,dmR,index);
7836 lastR=dmR;
7837 double dchi2(0);
7838 //track.update_hits(*itCluster, dmR, way, m_csmflag);
7839 dchi2 = track.update_hits(*itCluster, dmR, way, m_csmflag);
7840 if (ntuple_&256 && way>0) {
7841
7842 //cout<<"cgem: "<<m_hit_no<<endl;
7843 m_nCluster++;
7844 if(hypo == 0){
7845 m_dchi2_hit_e[m_hit_no] = dchi2;
7846 m_residest_hit_e[m_hit_no] = 0;
7847 m_residnew_hit_e[m_hit_no] = 0;
7848 m_layer_hit_e[m_hit_no] = layer;
7849 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7850 m_anal_dr_hit_e[m_hit_no] = worktemp.a()[0];
7851 m_anal_phi0_hit_e[m_hit_no] = worktemp.a()[1];
7852 m_anal_kappa_hit_e[m_hit_no] = worktemp.a()[2];
7853 m_anal_dz_hit_e[m_hit_no] = worktemp.a()[3];
7854 m_anal_tanl_hit_e[m_hit_no] = worktemp.a()[4];
7855 m_anal_ea_dr_hit_e[m_hit_no] = worktemp.Ea()[0][0];
7856 m_anal_ea_phi0_hit_e[m_hit_no] = worktemp.Ea()[1][1];
7857 m_anal_ea_kappa_hit_e[m_hit_no] = worktemp.Ea()[2][2];
7858 m_anal_ea_dz_hit_e[m_hit_no] = worktemp.Ea()[3][3];
7859 m_anal_ea_tanl_hit_e[m_hit_no] = worktemp.Ea()[4][4];
7860 }
7861
7862
7863 else if(hypo == 1){
7864 m_dchi2_hit_mu[m_hit_no] = dchi2;
7865 m_residest_hit_mu[m_hit_no] = 0;
7866 m_residnew_hit_mu[m_hit_no] = 0;
7867 m_layer_hit_mu[m_hit_no] = layer;
7868 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7869 m_anal_dr_hit_mu[m_hit_no] = worktemp.a()[0];
7870 m_anal_phi0_hit_mu[m_hit_no] = worktemp.a()[1];
7871 m_anal_kappa_hit_mu[m_hit_no] = worktemp.a()[2];
7872 m_anal_dz_hit_mu[m_hit_no] = worktemp.a()[3];
7873 m_anal_tanl_hit_mu[m_hit_no] = worktemp.a()[4];
7874 m_anal_ea_dr_hit_mu[m_hit_no] = worktemp.Ea()[0][0];
7875 m_anal_ea_phi0_hit_mu[m_hit_no] = worktemp.Ea()[1][1];
7876 m_anal_ea_kappa_hit_mu[m_hit_no] = worktemp.Ea()[2][2];
7877 m_anal_ea_dz_hit_mu[m_hit_no] = worktemp.Ea()[3][3];
7878 m_anal_ea_tanl_hit_mu[m_hit_no] = worktemp.Ea()[4][4];
7879 }
7880
7881
7882
7883 else if(hypo == 2){
7884 m_dchi2_hit_pi[m_hit_no] = dchi2;
7885 m_residest_hit_pi[m_hit_no] = 0;
7886 m_residnew_hit_pi[m_hit_no] = 0;
7887 m_layer_hit_pi[m_hit_no] = layer;
7888 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7889 m_anal_dr_hit_pi[m_hit_no] = worktemp.a()[0];
7890 m_anal_phi0_hit_pi[m_hit_no] = worktemp.a()[1];
7891 m_anal_kappa_hit_pi[m_hit_no] = worktemp.a()[2];
7892 m_anal_dz_hit_pi[m_hit_no] = worktemp.a()[3];
7893 m_anal_tanl_hit_pi[m_hit_no] = worktemp.a()[4];
7894 m_anal_ea_dr_hit_pi[m_hit_no] = worktemp.Ea()[0][0];
7895 m_anal_ea_phi0_hit_pi[m_hit_no] = worktemp.Ea()[1][1];
7896 m_anal_ea_kappa_hit_pi[m_hit_no] = worktemp.Ea()[2][2];
7897 m_anal_ea_dz_hit_pi[m_hit_no] = worktemp.Ea()[3][3];
7898 m_anal_ea_tanl_hit_pi[m_hit_no] = worktemp.Ea()[4][4];
7899 }
7900
7901
7902 else if(hypo == 3){
7903 m_dchi2_hit_k[m_hit_no] = dchi2;
7904 m_residest_hit_k[m_hit_no] = 0;
7905 m_residnew_hit_k[m_hit_no] = 0;
7906 m_layer_hit_k[m_hit_no] = layer;
7907 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7908 m_anal_dr_hit_k[m_hit_no] = worktemp.a()[0];
7909 m_anal_phi0_hit_k[m_hit_no] = worktemp.a()[1];
7910 m_anal_kappa_hit_k[m_hit_no] = worktemp.a()[2];
7911 m_anal_dz_hit_k[m_hit_no] = worktemp.a()[3];
7912 m_anal_tanl_hit_k[m_hit_no] = worktemp.a()[4];
7913 m_anal_ea_dr_hit_k[m_hit_no] = worktemp.Ea()[0][0];
7914 m_anal_ea_phi0_hit_k[m_hit_no] = worktemp.Ea()[1][1];
7915 m_anal_ea_kappa_hit_k[m_hit_no] = worktemp.Ea()[2][2];
7916 m_anal_ea_dz_hit_k[m_hit_no] = worktemp.Ea()[3][3];
7917 m_anal_ea_tanl_hit_k[m_hit_no] = worktemp.Ea()[4][4];
7918 }
7919
7920
7921 else if(hypo == 4){
7922 m_dchi2_hit_p[m_hit_no] = dchi2;
7923 m_residest_hit_p[m_hit_no] = 0;
7924 m_residnew_hit_p[m_hit_no] = 0;
7925 m_layer_hit_p[m_hit_no] = layer;
7926 KalmanFit::Helix worktemp = *(KalmanFit::Helix*)&track;
7927 m_anal_dr_hit_p[m_hit_no] = worktemp.a()[0];
7928 m_anal_phi0_hit_p[m_hit_no] = worktemp.a()[1];
7929 m_anal_kappa_hit_p[m_hit_no] = worktemp.a()[2];
7930 m_anal_dz_hit_p[m_hit_no] = worktemp.a()[3];
7931 m_anal_tanl_hit_p[m_hit_no] = worktemp.a()[4];
7932 m_anal_ea_dr_hit_p[m_hit_no] = worktemp.Ea()[0][0];
7933 m_anal_ea_phi0_hit_p[m_hit_no] = worktemp.Ea()[1][1];
7934 m_anal_ea_kappa_hit_p[m_hit_no] = worktemp.Ea()[2][2];
7935 m_anal_ea_dz_hit_p[m_hit_no] = worktemp.Ea()[3][3];
7936 m_anal_ea_tanl_hit_p[m_hit_no] = worktemp.Ea()[4][4];
7937 }
7938
7939 m_hit_no++;
7940 }
7941 }// loop clusters
7942 KalFitTrack track_first(track);
7943 if(way<0){
7944 innerwall(track,hypo,way,lastR,R_o_cgem,index);
7945 }
7946 else
7947 {
7948 innerwall(track,hypo,way,lastR,0,index);
7949 }
7950
7951 return track_first;
7952}
7953
7954
7955/*
7956void KalFitAlg::Cgem_filter_anal(KalFitTrack& track, int hypo, int way)
7957{
7958 const double a_stero[3] = {(45.94*3.1415926/180),(31.10*3.1415926/180),(32.99*3.1415926/180)};
7959 const double w_sheet[3] = {549.78,417.097,550.614};
7960 const double r_layer[3] = {87.5026,132.7686,175.2686};
7961 const double dmr_layer[3] = {79.838,125.104,167.604};
7962 const int l_layer[3] = {532,690,847};
7963 const int n_sheet[3] = {1,2,2};
7964 const double x_reso[3]={0.1372,0.1476,0.1412};
7965 const double v_reso[3]={0.1273,0.1326,0.1378};
7966 //KalFitTrack track(Track);
7967
7968 SmartDataPtr<RecMdcTrackCol> recMdcTrack(eventSvc(),"/Event/Recon/RecMdcTrackCol");
7969 if (!recMdcTrack) {
7970 //cout << MSG::FATAL << "Could not find RecMdcTrackCol" << endreq;
7971 cout << "Could not find RecMdcTrackCol" << endl;
7972 return;
7973 }
7974 RecMdcTrackCol::iterator itrk = recMdcTrack->begin();
7975 ClusterRefVec clusterRefVec;
7976 for(; itrk != recMdcTrack->end(); itrk++){
7977 if((*itrk)->trackId() == track.trasan_id() && (*itrk)->getNcluster() > 0) {
7978 clusterRefVec = (*itrk)->getVecClusters();
7979 break;
7980 }
7981 else{cout<<"track id:"<<(*itrk)->trackId()<<","<<track.trasan_id()<<" cluster:"<<(*itrk)->getNcluster()<<endl;return;}
7982 }
7983 if(debug_==4){ cout<<"wall size"<<_BesKalmanFitWalls.size()<<endl;}
7984
7985 ClusterRefVec::iterator itCluster;
7986 ClusterRefVec::iterator itStartFlag;
7987 ClusterRefVec::iterator itStopFlag;
7988 int step;
7989 int index=0;
7990 double lastR=_BesKalmanFitWalls[0].radius();
7991 if(way>0){
7992 itStartFlag = clusterRefVec.end()-1;
7993 itStopFlag = clusterRefVec.begin()-1;
7994 step = -1;
7995 }
7996 else if(way<0){
7997 itStartFlag = clusterRefVec.begin();
7998 itStopFlag = clusterRefVec.end();
7999 step = 1;
8000 }
8001 else{
8002 cout<<"way=0,no filter direction"<<endl;
8003 return;
8004 }
8005
8006
8007 for(itCluster = itStartFlag; itCluster !=itStopFlag; itCluster = itCluster + step){
8008 int layer = (*itCluster)->getlayerid();
8009 //double dmR = dmr_layer[layer]/10;
8010 CgemGeoLayer* CgemLayer = m_CgemGeomSvc_->getCgemLayer(iLayer);
8011 double dmR = CgemLayer->getMiddleROfGapD()/10;
8012 double recZ = (*itCluster)->getRecZ()/10;
8013 double recPhi = (*itCluster)->getrecphi();
8014 while(recPhi > M_PI) recPhi-=2*M_PI;
8015 while(recPhi <-M_PI) recPhi+=2*M_PI;
8016
8017 innerwall(track,hypo,way,lastR,dmR,index);
8018 lastR=dmR;
8019 HepVector v_measu(2,0);
8020 v_measu(1) = recPhi;
8021 v_measu(2) = recZ;
8022 //double Phi = track.intersect_cylinder(dmR);
8023 HepPoint3D x0kal = track.x(track.intersect_cylinder(dmR));
8024 track.pivot_numf(x0kal);
8025 double x0 = x0kal.x();
8026 double y0 = x0kal.y();
8027 double pathl(0);
8028 HepVector v_estim(2,0);
8029 v_estim(1) = x0kal.phi();
8030 v_estim(2) = x0kal.z();
8031 double dPhi=track.intersect_cylinder(dmR);
8032 const HepSymMatrix& Ea = track.Ea();
8033 HepVector v_a = track.a();
8034 double dr = v_a(1);
8035 double phi0 = v_a(2);
8036 double kappa = v_a(3);
8037 double tanl = v_a(5);
8038 // --- derivative matrix
8039 HepMatrix H(2, 5, 0);
8040 H(1,1) = -y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
8041 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)));
8042 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));
8043 H(2,3) = m_alpha/(kappa*kappa)*tanl*dPhi;
8044 H(2,4) = 1.0;
8045 H(2,5) = -1*(m_alpha/kappa)*dPhi;
8046 // --- error matrix of Cgem
8047 HepSymMatrix V(2,0);
8048 V(1,1) = pow(x_reso[layer]/r_layer[layer],2);
8049 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);
8050 // --- gain matrix
8051 int ierr=-1;
8052 HepMatrix K = Ea*H.T()*(V+H*Ea*H.T()).inverse(ierr);
8053 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
8054 // --- new error matrix
8055 HepSymMatrix EaNew(5,0);
8056 EaNew.assign(Ea-K*H*Ea);
8057 // --- diff
8058 HepVector v_diff = v_measu - v_estim;
8059 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
8060 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
8061 // --- new parameters
8062 HepVector aNew = v_a + K*v_diff;
8063 // --- new v_estim
8064 KalFitTrack track_new(x0kal,aNew,EaNew,hypo,0.0,track.nchits());
8065 HepPoint3D x0kal_new = track_new.x(track_new.intersect_cylinder(dmR));
8066 HepVector v_estim_new(2,0);
8067 v_estim_new(1) = x0kal_new.phi();
8068 v_estim_new(2) = x0kal_new.z();
8069 // --- difference between measurement and updated estimation
8070 v_diff = v_measu - v_estim_new;
8071 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
8072 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
8073 // --- new derivative matrix
8074 //track_new.pivot_numf(x0kal_new,pathl);
8075 //HepVector a_new = track_new.a();
8076 //HepVector Ea_new = track_new.Ea();
8077 // --- R matrix
8078 HepSymMatrix R(2,0);
8079 R.assign(V-H*EaNew*H.T());
8080 HepVector dChi2 = v_diff.T()*R.inverse(ierr)*v_diff;
8081 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
8082 if(way>0) track.chiSq(track.chiSq()+dChi2(1));
8083 if(way<0) track.chiSq_back(track.chiSq_back()+dChi2(1));
8084 //track.set(x0kal,aNew,EaNew);
8085 track.set(track.pivot(),aNew,EaNew);
8086 }
8087}
8088*/
8089
8090
8092{
8093
8094 //cout<<"R:"<<track.pivot().perp()<<endl;
8095 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
8096 if (!eventHeader) {
8097 cout << "Could not find Event Header" << endl;
8098 }
8099 int eventNo = eventHeader->eventNumber();
8100 int runNo = eventHeader->runNumber();
8101 m_evt=eventNo;
8102 //cout<<"Event::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"<<eventNo<<endl;
8103
8104 SmartDataPtr<McParticleCol> mcPartCol(eventSvc(),"/Event/MC/McParticleCol");
8105 if (!mcPartCol) {
8106 cout << "Could not find McParticle" << endl;
8107 }
8108
8109 HepVector mc_a(5,0);
8110 McParticleCol::iterator i_mcTrk = mcPartCol->begin();
8111 for (;i_mcTrk != mcPartCol->end(); i_mcTrk++) {
8112 if(!(*i_mcTrk)->primaryParticle()) continue;
8113 const HepLorentzVector& mom((*i_mcTrk)->initialFourMomentum());
8114 const HepLorentzVector& pos = (*i_mcTrk)->initialPosition();
8115 //cout<<"MCposition:"<<pos.x()<<" "<<pos.y()<<" "<<pos.z()<<" "<<endl;
8116 double charge = 0.0;
8117 int pid = (*i_mcTrk)->particleProperty();
8118 if( pid >0 ) {
8119 charge = m_particleTable->particle( pid )->charge();
8120 } else if ( pid <0 ) {
8121 charge = m_particleTable->particle( -pid )->charge();
8122 charge *= -1;
8123 } else {
8124 }
8125 HepPoint3D pos2(pos.x(),pos.y(),pos.z());
8126 Hep3Vector mom2(mom.px(),mom.py(),mom.pz());
8127
8128 KalmanFit::Helix mchelix(pos2, mom2, charge);
8129 //if( debug_ == 0) cout<< "helix: "<<mchelix.a()<<endl;
8130 mchelix.pivot( HepPoint3D(0,0,0) );
8131 for( int j =0; j<5; j++) {
8132 //m_mchelix[j] = mchelix.a()[j];
8133 mc_a[j] = mchelix.a()[j];
8134 }
8135 //m_mcpid = pid;
8136 //m_mcptot = sqrt(1+pow(m_mchelix[4],2))/m_mchelix[2];
8137 }
8138 HepPoint3D IP(0,0,0);
8139 KalmanFit::Helix MChelix(IP,mc_a);
8140 MChelix.pivot(track.pivot());
8141 m_diff_dr = track.a()[0]-MChelix.a()[0];
8142 m_diff_phi0 = track.a()[1]-MChelix.a()[1];
8143 m_diff_kappa = track.a()[2]-MChelix.a()[2];
8144 m_diff_dz = track.a()[3]-MChelix.a()[3];
8145 m_diff_tanl = track.a()[4]-MChelix.a()[4];
8146 if(track.a()[2] != 0 && MChelix.a()[2] != 0)
8147 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];
8148 else
8149 m_diff_p =9999;
8150 StatusCode sc12 = m_nt12->write();
8151 if( sc12.isFailure() ) cout<<"Ntuple12 filling failed!"<<endl;
8152 //cout<<"kalfit a:"<<track.a()<<endl<<"MCtruth a:"<<MChelix.a()<<endl<<endl;
8153 ///*
8154 // --- calculate the material quantity
8155 bool printwalls = false;
8156 if(printwalls){
8157 double material_quantity(0);
8158 int size = _BesKalmanFitWalls.size();
8159 for(int i=0;i<size;i++)
8160 {
8161 double ro = _BesKalmanFitWalls[i].radius();
8162 double ri = _BesKalmanFitWalls[i].rmin();
8163 double thick = ro-ri;
8164 KalFitMaterial material = _BesKalmanFitWalls[i].material();
8165 double X0 = material.X0();
8166 double rho = material.get_density();
8167 double Z = material.Z();
8168 //double X = X0/rho;
8169 material_quantity += 100*thick/X0;
8170 cout<<"----------------------------------------------------------------------------------------------------"<<endl;
8171 cout<<"wall"<<i+1<<" Z:"<<setw(12)<<Z<<endl;
8172 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;
8173 cout<<"----------------------------------------------------------------------------------------------------"<<endl;
8174 cout<<endl;
8175 //cout<<"wall"<<i+1<<" Z:"<<Z<<" Thick:"<<thick<<" Density:"<<rho <<" X0:"<<X0<<endl;
8176 //cout<<"radiation length="<<x<<" material quantity="<<thick/x<<endl;
8177
8178 }
8179 cout<<"============================================================"<<endl;
8180 cout<<"total material quantity="<<material_quantity<<endl;
8181 cout<<"============================================================"<<endl;
8182 }
8183 //*/
8184}
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
double getOuterROfGapD() const
double getInnerROfGapD() const
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)
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.
void filter_fwd_calib(KalFitTrack &trk, int l_mass, int way, HepSymMatrix &Eakal)
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()
double fac_h4_
Definition KalFitAlg.h:210
double m_dangcut
Definition KalFitAlg.h:248
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)
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
void fromFHitToInnerWall(KalFitTrack &track, int way)
double gain5_
Definition KalFitAlg.h:212
double dchi2cutf_
Definition KalFitAlg.h:233
void clean(void)
int tof_hyp_
Definition KalFitAlg.h:207
void kalman_fitting_MdcxReco_Csmc_Sew(void)
double pp_cut_
Definition KalFitAlg.h:201
void setCalibSvc_init(void)
initialize for the services
void smoother_anal(KalFitTrack &trk, int way)
Kalman filter (smoothing or backward part)
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)
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)
void sameas(RecMdcKalTrack *trk, int l_mass, int imain)
complete the RecMdcKalTrackCol
void fillTds_ip(MdcRec_trk &TrasanTRK, KalFitTrack &track, RecMdcKalTrack *trk, int l_mass)
with results got at (0,0,0)
void makeGemHitsCol()
int tofflag_
Definition KalFitAlg.h:207
void fitGemHits(KalFitTrack &track, int hypo, int way)
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
void innerwall(KalFitTrack &trk, int l_mass, int way)
Take the inner walls (eloss and mult scat) into account.
double fac_h1_
Definition KalFitAlg.h:210
double m_dphicut
Definition KalFitAlg.h:248
KalFitTrack Cgem_filter_anal(KalFitTrack &track, int hypo, int way)
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
void start_seed(KalFitTrack &track, int lead_, int way, MdcRec_trk &trk)
double dchi2cut_layid2_
Definition KalFitAlg.h:235
void setBesFromGdml(void)
void setGeomSvc_init(void)
KalFitAlg(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition KalFitAlg.cxx:99
void kalman_fitting_anal(void)
int i_front_
Definition KalFitAlg.h:225
void setDchisqCut(void)
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...
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
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)
void init_matrix(MdcRec_trk &trk, HepSymMatrix &Ea)
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
StatusCode finalize()
void kalman_fitting_csmalign(void)
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
void fillTds_back(KalFitTrack &track, RecMdcKalTrack *trk, MdcRec_trk &TrasanTRK, int l_mass)
with results got at the outer Mdc hit
double dchi2cut_inner_
Definition KalFitAlg.h:235
int activeonly_
Definition KalFitAlg.h:207
void clearTables()
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.
double chi2_back(void) const
int LR(void) const
double chi2(void) const
const KalFitWire & wire(void) const
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)
static void setMdcDigiCol(MdcDigiCol *digicol)
static int lead(void)
Magnetic field map.
static double chi2_hitf_
Cut chi2 for each hit.
static double dchi2cuts_anal[43]
Definition KalFitTrack.h:58
int type(void) const
unsigned int nchits(void) const
static double dchi2cuts_calib[43]
Definition KalFitTrack.h:60
double tof_proton(void) const
static int debug_
for debug
static int nmass(void)
double tof_kaon(void) const
static double Bznom_
static int back(void)
void order_wirhit(int index)
HepSymMatrix getInitMatrix(void) const
static void setInitMatrix(HepSymMatrix m)
double chiSq(void) const
int ndf_back(void) const
static int nmdc_hit2_
Cut chi2 for each hit.
static int tofall_
KalFitHelixSeg & HelixSeg(int i)
void addTofSM(double time)
static int steplev_
void chgmass(int i)
static double factor_strag_
factor of energy loss straggling for electron
int trasan_id(void) const
const HepPoint3D & pivot_numf(const HepPoint3D &newPivot)
Sets pivot position in a given mag field.
void ms(double path, const KalFitMaterial &m, int index)
static int Tof_correc_
Flag for TOF correction.
void update_forMdc(void)
double intersect_cylinder(double r) const
Intersection with different geometry.
double chiSq_back(void) const
double getFiTerm(void)
void HitsMdc(vector< KalFitHitMdc > &lh)
double getPathSM(void)
double pathip(void) const
void fiTerm(double fi)
void point_last(const HepPoint3D &point)
set and give out the last point of the track
void HelixSegs(vector< KalFitHelixSeg > &vs)
static double chi2_hits_
static int numf_
Flag for treatment of non-uniform mag field.
unsigned int nster(void) const
static int inner_steps_
double mass(void) const
static int outer_steps_
double p_proton(void) const
double update_hits_csmalign(KalFitHelixSeg &HelixSeg, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, int csmflag)
void tof(double path)
Update the tof estimation.
static int drifttime_choice_
the drifttime choice
double smoother_Mdc(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
Kalman smoother for Mdc.
void msgasmdc(double path, int index)
Calculate multiple scattering angle.
static int tprop_
for signal propagation correction
void appendHitsMdc(KalFitHitMdc h)
Functions for Mdc hits list.
void addPathSM(double path)
static double dchi2cutf_calib[43]
Definition KalFitTrack.h:59
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)
static int numfcor_
NUMF treatment improved.
double radius_numf(void) const
Estimation of the radius in a given mag field.
double smoother_Mdc_csmalign(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
double update_hits(KalFitHitMdc &HitMdc, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, double &dtrack, double &dtracknew, double &dtdc, int csmflag)
Include the Mdc wire hits.
static double dchi2cutf_anal[43]
Definition KalFitTrack.h:57
static int LR_
Use L/R decision from MdcRecHit information :
double p_kaon(void) const
KalFitHitMdc & HitMdc(int i)
static int strag_
Flag to take account of energy loss straggling :
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.
const MdcGeoWire *const Wire(unsigned id)
const MdcGeoLayer *const Layer(unsigned id)
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)
static vector< MdcRec_trk > * getMdcRecTrkCol(void)
static vector< MdcRec_wirhit > * getMdcRecWirhitCol(void)
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
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