165{
166 MsgStream log(
msgSvc(), name());
167 log << MSG::INFO << "in excute()" << endreq;
168
169 const double pi = 4.*atan(1);
170 n_layer = 3;
171
172
173
174
175
176
177
178
179 int vec_clusterid[3];
180 m_seg_map.clear();
181
182 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
183 if (!eventHeader) {
184 log << MSG::FATAL << "Could not find Event Header" << endreq;
185 return StatusCode::FAILURE;
186 }
187 cgem_evt = eventHeader->eventNumber();
188 cgem_run = eventHeader->runNumber();
189
190
191
192
193
194
195 SmartDataPtr<RecCgemSegmentCol> recCgemSegmentCol(eventSvc(), "/Event/Recon/RecCgemSegmentCol");
196 if (!recCgemSegmentCol){
197 log << MSG::WARNING << "Could not retrieve Cgem segment list" << endreq;
198 check_segNum++;
199
200 return StatusCode::SUCCESS;
201 }
202 RecCgemSegmentCol::iterator itSeg;
203
204
205
206
207
208
209
210
211
212
213
214
215 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(), "/Event/Recon/RecCgemClusterCol");
216 if (!recCgemClusterCol){
217 log << MSG::WARNING << "Could not retrieve Cgem cluster list" << endreq;
218 return StatusCode::FAILURE;
219 }
220
221 SmartDataPtr<Event::CgemMcHitCol> recCgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
222 if (!recCgemMcHitCol)
223 {
224 log << MSG::WARNING << "Could not find event" << endreq;
225 return StatusCode::FAILURE;
226 }
227
228 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
229 if (!mcParticleCol) {
230 log << MSG::ERROR<< "Could not find McParticle" << endreq;
231 }
232 else{
233
234 Hep3Vector truth_p;
HepPoint3D truth_position;
double mc_charge(0.);
235 McParticleCol::iterator iter_mc = mcParticleCol->begin();
236 for (;iter_mc != mcParticleCol->end(); ++iter_mc ) {
237 int pdg=(*iter_mc)->particleProperty();
238 if(fabs(pdg)!=13) continue;
239 if(truth_ntrack >=10)continue;
240 if(pdg<0)mc_charge = 1.;
241 else mc_charge =-1.;
242 double truth_x = (*iter_mc)->initialPosition().x();
243 double truth_y = (*iter_mc)->initialPosition().y();
244 double truth_z = (*iter_mc)->initialPosition().z();
245
246 double truth_px = (*iter_mc)->initialFourMomentum().px();
247 double truth_py = (*iter_mc)->initialFourMomentum().py();
248 double truth_pz = (*iter_mc)->initialFourMomentum().pz();
249 double truth_P = sqrt(truth_px*truth_px+truth_py*truth_py+truth_pz*truth_pz);
250 truth_CosTheta[truth_ntrack] = truth_pz/truth_P;
251
252 truth_position =
HepPoint3D(truth_x, truth_y, truth_z);
253 truth_p = Hep3Vector(truth_px, truth_py, truth_pz);
254
257 tmp_helix->
pivot(tmp_pivot);
258 truth_dr[truth_ntrack] = tmp_helix->
dr();
259 truth_dz[truth_ntrack] = tmp_helix->
dz();
260 truth_phi0[truth_ntrack] = tmp_helix->
phi0();
261 truth_kappa[truth_ntrack] = tmp_helix->
kappa();
262 truth_tanl[truth_ntrack] = tmp_helix->
tanl();
263 truth_charge[truth_ntrack] = mc_charge;
264 if(m_debug){
265 cout<<"Track Helix : "<<endl
266 <<
"dr = "<<tmp_helix->
dr()<<
"\tphi0 = "<<tmp_helix->
phi0()<<
"\tkappa = "<<tmp_helix->
kappa()
267 <<
"\ndz = "<<tmp_helix->
dz()<<
"\ttanl = "<<tmp_helix->
tanl()<<
"\tpt = "<<1./tmp_helix->
kappa()<<endl<<endl;
268 }
269
270 truth_ntrack++;
271 delete tmp_helix;
272 }
273 }
274 bool use_truth_hits = true;
275 if(use_truth_hits){
276 SmartDataPtr<Event::CgemMcHitCol> lv_CgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
277 if (!lv_CgemMcHitCol)
278 {
279 log << MSG::WARNING << "Could not find event" << endreq;
280 return StatusCode::FAILURE;
281 }
282 Event::CgemMcHitCol::iterator iter_truth = lv_CgemMcHitCol->begin();
283 for( ; iter_truth != lv_CgemMcHitCol->end(); ++iter_truth){
284 if(fabs((*iter_truth)->GetPDGCode())!=13) continue;
285 double tmp_x = ((*iter_truth)->GetPositionXOfPrePoint()+(*iter_truth)->GetPositionXOfPostPoint())/2;
286 double tmp_y = ((*iter_truth)->GetPositionYOfPrePoint()+(*iter_truth)->GetPositionYOfPostPoint())/2;
287 double tmp_z = ((*iter_truth)->GetPositionZOfPrePoint()+(*iter_truth)->GetPositionZOfPostPoint())/2;
288 double tmp_phi = atan2(tmp_y,tmp_x);
289 while(tmp_phi < 0) tmp_phi += 2*
pi;
290 mc_phi[(*iter_truth)->GetLayerID()] = tmp_phi;
292 mc_v[(*iter_truth)->GetLayerID()] = tmp_v;
293 CgemSegmentFun::vec_z[(*iter_truth)->GetLayerID()] = ((*iter_truth)->GetPositionZOfPostPoint()+(*iter_truth)->GetPositionZOfPrePoint())/2./10.;
295
296
297 }
298 double Ini_d0(0.), Ini_phi0(0.), Ini_kappa(0.), Ini_z0(0.), Ini_tanl(0.);
300 }
301
302 itSeg = recCgemSegmentCol->begin();
303 cgem_nsegment=0;
304 for(;itSeg != recCgemSegmentCol->end(); ++itSeg){
305 if(cgem_nsegment >= 1000){check_segOver++;continue;}
306 cgem_segmentid[cgem_nsegment] = (*itSeg)->getsegmentid();
307 vec_clusterid[0] = (*itSeg)->getclusterid_1();
308 vec_clusterid[1] = (*itSeg)->getclusterid_2();
309 vec_clusterid[2] = (*itSeg)->getclusterid_3();
310 int IsTruth = (*itSeg)->getmatch();
311
312
313 Int_t ierflg;
314 Double_t arglist[10];
315 m_failed = 0;
316
317 m_pMnTrk = new TMinuit(5);
318 m_pMnTrk -> SetPrintLevel(-1);
320 m_pMnTrk -> SetErrorDef(1.0);
321
322 m_pMnTrk -> mnparm(0, "dr" , 0, 0.1 , -10, 10, ierflg);
323 m_pMnTrk -> mnparm(1, "phi0" , 0, 0.16, 0, 6.3, ierflg);
324 m_pMnTrk -> mnparm(2, "kappa", 0, 0.4, -100, 100, ierflg);
325 m_pMnTrk -> mnparm(3, "dz" , 0, 0.5 , -50, 50, ierflg);
326 m_pMnTrk -> mnparm(4, "tanL" , 0, 0.005 , -10, 10, ierflg);
327
328
329
330
331
332 arglist[0] = 0;
333 m_pMnTrk -> mnexcm("Set NOW", arglist, 0, ierflg);
334
335
336 RecCgemClusterCol::iterator itTrk=recCgemClusterCol->begin();
337 for(; itTrk != recCgemClusterCol->end(); ++itTrk){
338 if((*itTrk)->getflag() == 0){
339 n_stripX[(*itTrk)->getlayerid()] = (*itTrk)->getclusterflage()-(*itTrk)->getclusterflagb()+1;
341 }
342 if((*itTrk)->getflag() == 1){
343 n_stripV[(*itTrk)->getlayerid()] = (*itTrk)->getclusterflage()-(*itTrk)->getclusterflagb()+1;
345 }
346 if((*itTrk)->getflag() != 2) continue;
347 if(!CheckClusterID((*itTrk)->getlayerid(), (*itTrk)->getclusterid(), vec_clusterid)) continue;
348
349 double tmp_phi = (*itTrk)->getrecphi();
350
353
354 rec_phi[(*itTrk)->getlayerid()] = (*itTrk)->getrecphi();
357
358
359
360
361 }
362
363 double Ini_d0(0.), Ini_phi0(0.), Ini_kappa(0.), Ini_z0(0.), Ini_tanl(0.);
364 double chisq(0.);
365
366 int charge = GetChargeOfTrack();
367 cgem_charge[cgem_nsegment] = charge;
369
370 double ErrMatrix[5][5] ;
371 double TrkPar[5] = {Ini_d0, Ini_phi0, Ini_kappa, Ini_z0, Ini_tanl};
372
373 double TrkParErr[5] ;
374 double helixErr[15];
375 int fit = mnTrkFit(TrkPar, TrkParErr, &ErrMatrix[0][0], chisq);
376 int fitAgain = 0; double kappa_err;
377 if(!fit){
378
379 m_failed = 1;
380 double tmp_recphi[3], tmp_kappa[8];
381 for(int ii = 0, mm = 0; ii < 2; ii++)
382 for(int jj = 0; jj < 2; jj++)
383 for(int kk = 0; kk < 2; kk++, mm++){
387 charge = GetChargeOfTrack(tmp_recphi);
389
390 }
391 double kappa_s = GetMin(tmp_kappa);
392 double kappa_l = GetMax(tmp_kappa);
393 kappa_err = (kappa_s - kappa_l)/2.;
394 double TrkPar[5] = {Ini_d0, Ini_phi0, (kappa_l+kappa_s)/2., Ini_z0, Ini_tanl};
395 TrkPar[2] = kappa_l;
396 fitAgain = mnTrkFit(TrkPar, TrkParErr, &ErrMatrix[0][0], chisq);
397
398 }
399
400
401
402
403
404
405
406
407
408
409
410 cgem_fitFlag[cgem_nsegment] = fit;
411 if(fit==1||fitAgain){
412 if(fit){
413 for (int ie = 0, k = 0 ; ie < 5 ; ie++){
414 for (int je = ie ; je < 5 ; je ++, k++) {
415 helixErr[k] = ErrMatrix[ie][je];
416 }
417 }
418 }
419
420 if(fitAgain){
421 for (int ie = 0, k = 0 ; ie < 5 ; ie++){
422 for (int je = ie ; je < 5 ; je ++, k++) {
423 if(ie==2&&je<2)helixErr[k] = ErrMatrix[ie+2][je];
424 else if(je<2&&ie>2) helixErr[k] = ErrMatrix[ie-1][je];
425 else if(je>2&&ie>2) helixErr[k] = ErrMatrix[ie-1][je-1];
426 else if(je==2) helixErr[k] = 0.;
427 else helixErr[k] = ErrMatrix[ie][je];
428
429 if(k==9)helixErr[k] = pow(kappa_err,2);
430
431 }
432 }
433 TrkParErr[0] = 0.8812/0.0677*TrkParErr[0];
434 TrkParErr[1] = 0.266/0.004*TrkParErr[1];
435 TrkParErr[2] = kappa_err;
436 helixErr[0] = 0.8812/0.0677*helixErr[0];
437 helixErr[5] = 0.266/0.004*helixErr[5];
438 }
439
440
441
442
443
444
445
446
447 (*itSeg)->sethelix(TrkPar);
448 (*itSeg)->sethelix_err(helixErr);
449 (*itSeg)->setmatch(IsTruth);
450 cgem_dr[cgem_nsegment] = TrkPar[0];
451 cgem_phi0[cgem_nsegment] = TrkPar[1];
452 cgem_kappa[cgem_nsegment] = TrkPar[2];
453 cgem_dz[cgem_nsegment] = TrkPar[3];
454 cgem_tanl[cgem_nsegment] = TrkPar[4];
455 cgem_chisq[cgem_nsegment] = chisq;
456 if(m_debug){
457 cout<< "fit success" << endl
458 <<"dr = " <<TrkPar[0]<<" +- "<<TrkParErr[0]<<"\t\t"
459 <<"phi0 = "<<TrkPar[1]<<" +- "<<TrkParErr[1]<<"\t\t"
460 <<"kappa= "<<TrkPar[2]<<" +- "<<TrkParErr[2]<<"\n"
461 <<"dz = " <<TrkPar[3]<<" +- "<<TrkParErr[3]<<"\t\t"
462 <<"tanl = "<<TrkPar[4]<<" +- "<<TrkParErr[4]<<"\n\n"
463 <<"kappa_err= "<<TrkParErr[2]<<endl;
464 cout<<"chisq = "<<chisq<<endl;
465 }
466 }
467 else{
468
469
470 double fail_helix[5], fail_helix_err[15] ;
471 for(int i = 0; i <15; i++){
472 if(i<5)fail_helix[i] = -999.;
473 fail_helix_err[i] = -999.;
474 }
475 (*itSeg)->sethelix(fail_helix);
476 (*itSeg)->sethelix_err(fail_helix_err);
477 (*itSeg)->setmatch(IsTruth);
478 cgem_dr[cgem_nsegment] = -999.;
479 cgem_phi0[cgem_nsegment] = -999.;
480 cgem_kappa[cgem_nsegment] = -999.;
481 cgem_dz[cgem_nsegment] = -999.;
482 cgem_tanl[cgem_nsegment] = -999.;
483 cgem_chisq[cgem_nsegment] = -999.;
484 }
485
486
487 cgem_nsegment++;
488
489
490 delete m_pMnTrk;
491
492 }
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534 helix_ntuple->write();
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550 return StatusCode::SUCCESS;
551}
double sin(const BesAngle a)
double cos(const BesAngle a)
HepGeom::Point3D< double > HepPoint3D
double dr(void) const
returns an element of parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
void GetHelixVarBeforeFit(int charge, double &d0, double &phi0, double &omega, double &z0, double &tanl)
double GetKappaAfterFit(int charge, double *rec_phi)
void fcnTrk(int &npar, double *gin, double &f, double *par, int iflag)