to read the parameters of energy correction parameters of single gamma and pi0 calibration//////////
340 {
341 MsgStream log(
msgSvc(), name() );
342 log << MSG::INFO << "in execute()" << endmsg;
343
344 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
345 int runNo = eventHeader->runNumber();
346
347
350 if ( runNum >= runFrom && runNum <= runTo ) { m_inFlag = true; }
351 else { m_inFlag = false; }
352
353 if ( m_inFlag == false )
354 {
355
356 runFrom = m_EmcShEnCalibSvc->getRunFrom();
357 runTo = m_EmcShEnCalibSvc->getRunTo();
358
359
360
361
362 cout <<
"current run=" <<
runNo << endl;
363 cout << "in AbsCor open getPi0CalibFile()= " << m_EmcShEnCalibSvc->getPi0CalibFile()
364 << endl;
365 cout << "open getSingleGammaCalibFile()= " << m_EmcShEnCalibSvc->getSingleGammaCalibFile()
366 << endl;
367 cout << "getRunFrom()=" << runFrom << endl;
368 cout << "getRunTo()=" << runTo << endl;
369
370 string CorFunparaPath;
371 if ( MCuseTof == 1 )
372 {
373 if ( m_ifReadDB ) { CorFunparaPath = m_EmcShEnCalibSvc->getSingleGammaCalibFile(); }
374 else
375 {
376 CorFunparaPath = m_CorFunparaPath;
377 cout << "no read database, but using the set:" << CorFunparaPath << endl;
378 }
379 }
380 if ( MCuseTof == 0 )
381 {
382 CorFunparaPath = getenv( "ABSCORROOT" );
383 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
384 }
385
387 in2corfun.open( CorFunparaPath.c_str() );
388 assert( in2corfun );
389
390 for ( int i = 0; i < 28; i++ )
391 {
392 in2corfun >> m_corFunPar[i][0];
393 in2corfun >> m_corFunPar[i][1];
394 in2corfun >> m_corFunPar[i][2];
395 in2corfun >> m_corFunPar[i][3];
396 in2corfun >> m_corFunPar[i][4];
397 in2corfun >> m_corFunPar[i][5];
398 }
399 in2corfun.close();
400
401
402 string DataPathc3p;
403 DataPathc3p = getenv( "ABSCORROOT" );
404 DataPathc3p += "/share/c3p.txt";
405
406 string DataPathc3ptof;
407 if ( m_ifReadDB ) { DataPathc3ptof = m_EmcShEnCalibSvc->getPi0CalibFile(); }
408 else
409 {
410 DataPathc3ptof = m_DataPathc3ptof;
411 cout << "no read database, but using the set:" << DataPathc3ptof << endl;
412 }
413
415 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
416 if ( usetof == 0 ) inc3p.open( DataPathc3p.c_str(), ios::in );
417 if ( usetof == 1 ) inc3p.open( DataPathc3ptof.c_str(), ios::in );
418 for ( int i = 0; i < 4; i++ )
419 {
420 double am, ame;
421 inc3p >> am;
422 inc3p >> ame;
424 }
425 }
426
427
430 if ( evtRecEvent->totalTracks() > evtRecTrkCol->size() ) return StatusCode::SUCCESS;
431 if ( evtRecEvent->totalTracks() > 50 ) return StatusCode::SUCCESS;
432
433 IEmcRecGeoSvc* iGeoSvc;
434 ISvcLocator* svcLocator = Gaudi::svcLocator();
435 StatusCode sc = svcLocator->service( "EmcRecGeoSvc", iGeoSvc );
436 if ( sc != StatusCode::SUCCESS ) { cout << "Error: Can't get EmcRecGeoSvc" << endl; }
437
438 for ( int i = 0; i < evtRecEvent->totalTracks(); i++ )
439 {
441 if ( !( *itTrk )->isEmcShowerValid() ) continue;
442 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
476
477 unsigned int module, ntheta, nphi;
478 module = EmcID::barrel_ec( id );
481
482
483
486
487 double e5x5 = emcTrk->
e5x5();
488 double etof = 0;
489
490 if ( usetof == 1 && ( *itTrk )->isTofTrackValid() )
491 {
492 SmartRefVector<RecTofTrack> recTofTrackVec = ( *itTrk )->tofTrack();
493 if ( !recTofTrackVec.empty() ) etof = recTofTrackVec[0]->energy();
494 if ( etof > 100. ) etof = 0;
495 }
496
497 double energyC = 0;
498
499 int thetaId = -99;
500 if ( module == 0 || module == 2 ) thetaId = thetaModule;
501 if ( module == 1 && thetaModule <= 21 ) thetaId = thetaModule + 6;
502 if ( module == 1 && thetaModule > 21 ) thetaId = 43 - thetaModule + 6;
503 double DthetaId = double( thetaId );
504
505 if ( MCuseTof == 1 )
506 {
507 if ( thetaId < 6 ) etof = 0.0;
508 if ( MCCorUseFunction == 1 ) { energyC = ECorrFunctionMC( e5x5 + etof, DthetaId ); }
509 else if ( MCCorUseFunction == 0 ) { energyC = ECorrMC( e5x5 + etof, DthetaId ); }
510 }
511 if ( MCuseTof == 0 )
512 {
513 if ( MCCorUseFunction == 1 ) { energyC = ECorrFunctionMC( e5x5, DthetaId ); }
514 else if ( MCCorUseFunction == 0 ) { energyC = ECorrMC( e5x5, DthetaId ); }
515 }
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536 double lnE = std::log( energyC );
537
538 if ( energyC > 1.0 )
539 lnE = std::log( 1.0 );
540 if ( energyC < 0.05 )
541 lnE = std::log( 0.05 );
542
543
544 double lnEcor = 1.0;
545 if ( dopi0Cor == 1 )
546 {
547 if (
runNo > 0 && dodatacor == 1 )
548 { lnEcor =
ai[0] +
ai[1] * lnE +
ai[2] * lnE * lnE +
ai[3] * lnE * lnE * lnE; }
549 }
550 if ( lnEcor < 0.5 ) continue;
551
552
553
555
556
557 double enecor = 1.;
558 if ( hotcellmask == 1 )
559 {
560 for ( int ih = 0; ih < 10; ih++ )
561 {
562 if ( hrunstart[ih] == -1 || hrunend[ih] == -1 || hcell[ih] == -1 ) continue;
565 }
566 }
567
568 if ( edgecor == 1 )
569 {
570
571 if ( module == 1 )
572 {
573 unsigned int theModule;
574 if ( thetaModule > 21 )
575 {
576 theModule = 43 - thetaModule;
578 pos.setZ( -pos.z() );
579 }
580 else { theModule = thetaModule; }
581
582 double IRShift;
583 if ( theModule == 21 ) { IRShift = 0; }
584 else if ( theModule == 20 ) { IRShift = 2.5; }
585 else { IRShift = 5.; }
586
589 center01 =
591 center23 =
593
594 double theta01, theta23, length, d;
595 theta01 = ( center01 - IR ).theta();
596 theta23 = ( center23 - IR ).theta();
597 length = ( center01 - IR ).mag();
598 d = length *
tan( theta01 - theta23 );
599
600 double xIn;
601 xIn = length *
tan( theta01 - ( pos - IR ).theta() ) - d / 2;
602 if ( xIn < ( -d / 2 ) && theModule != 21 )
603 {
604
605 theModule = theModule + 1;
606
608 if ( theModule == 21 ) { IRShift = 0; }
609 else if ( theModule == 20 ) { IRShift = 2.5; }
610 else { IRShift = 5.; }
612 IR = IR1;
613 center01 =
615 center23 =
617 theta01 = ( center01 - IR ).theta();
618 theta23 = ( center23 - IR ).theta();
619 length = ( center01 - IR ).mag();
620 d = length *
tan( theta01 - theta23 );
621
622 xIn = length *
tan( theta01 - ( pos - IR ).theta() ) - d / 2;
623 }
624 else if ( xIn > ( d / 2 ) && theModule != 0 )
625 {
626
627 theModule = theModule - 1;
629 if ( theModule == 21 ) { IRShift = 0; }
630 else if ( theModule == 20 ) { IRShift = 2.5; }
631 else { IRShift = 5.; }
632
634 IR = IR1;
635 center01 =
637 center23 =
639 theta01 = ( center01 - IR ).theta();
640 theta23 = ( center23 - IR ).theta();
641 length = ( center01 - IR ).mag();
642 d = length *
tan( theta01 - theta23 );
643
644 xIn = length *
tan( theta01 - ( pos - IR ).theta() ) - d / 2;
645 }
646
647 double yIn;
648
649
650
651 yIn = pos.phi() < 0 ? pos.phi() * 180. / CLHEP::pi + 360. - phiModule * 3. - 1.843
652 : pos.phi() * 180. / CLHEP::pi - phiModule * 3. - 1.843;
653
654 if ( nphi == 0 && yIn > 100 ) yIn = yIn - 360;
655 if ( nphi == 119 && yIn < -100 ) yIn = yIn + 360;
656
657 if ( yIn < -1.5 - 0.15 )
658 {
659
660 if ( nphi != 0 ) phiModule = phiModule - 1;
661 if ( nphi == 0 ) phiModule = 119;
662 yIn = pos.phi() < 0 ? pos.phi() * 180. / CLHEP::pi + 360. - phiModule * 3. - 1.843
663 : pos.phi() * 180. / CLHEP::pi - phiModule * 3. - 1.843;
664 if ( phiModule == 0 && yIn > 100 ) yIn = yIn - 360;
665 if ( phiModule == 119 && yIn < -100 ) yIn = yIn + 360;
666 }
667
668 if ( yIn > 1.5 - 0.15 )
669 {
670
671 if ( nphi != 119 ) phiModule = phiModule + 1;
672 if ( nphi == 119 ) phiModule = 0;
673
674 yIn = pos.phi() < 0 ? pos.phi() * 180. / CLHEP::pi + 360. - phiModule * 3. - 1.843
675 : pos.phi() * 180. / CLHEP::pi - phiModule * 3. - 1.843;
676 if ( phiModule == 0 && yIn > 100 ) yIn = yIn - 360;
677 if ( phiModule == 119 && yIn < -100 ) yIn = yIn + 360;
678 }
679
680 enecor = m_par[theModule][0] + m_par[theModule][1] * xIn +
681 m_par[theModule][2] * xIn * xIn + m_par[theModule][3] * xIn * xIn * xIn +
682 m_par[theModule][4] * xIn * xIn * xIn * xIn +
683 m_par[theModule][5] * xIn * xIn * xIn * xIn * xIn +
684 m_par[theModule][6] * xIn * xIn * xIn * xIn * xIn * xIn
685
686
687 + m_par[theModule][7] * yIn + m_par[theModule][8] * yIn * yIn +
688 m_par[theModule][9] * yIn * yIn * yIn +
689 m_par[theModule][10] * yIn * yIn * yIn * yIn;
690
691 }
692 else { enecor = 1; }
693 }
694
695
696 double energyCC = energyC / ( lnEcor * enecor );
697
699
700 if ( ntOut == true )
701 {
702 m_ef = energyCC;
703 m_e5 = emcTrk->
e5x5();
704 m_ec = energyC;
705 m_ct = lnEcor;
706 m_cedge = enecor;
707 m_tuple1->write();
708 }
709 }
710
711 SmartDataPtr<RecEmcShowerCol> recEmcShowerCol( eventSvc(),
713 if ( !recEmcShowerCol ) { return ( StatusCode::SUCCESS ); }
714 SmartDataPtr<DstEmcShowerCol> dstEmcShowerCol( eventSvc(),
716 if ( !dstEmcShowerCol ) { return ( StatusCode::SUCCESS ); }
717
718
719 if ( recEmcShowerCol->size() != dstEmcShowerCol->size() ) return StatusCode::SUCCESS;
720 for ( int i = 0; i < recEmcShowerCol->size(); i++ )
721 {
722 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin() + i;
723 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin() + i;
724
725
726 ( *iter_dst )->setEnergy( ( *iter_rec )->energy() );
727 ( *iter_dst )->setStatus( ( *iter_rec )->status() );
728
729
730
731 }
732 return ( StatusCode::SUCCESS );
733}
HepGeom::Point3D< double > HepPoint3D
EvtRecTrackCol::iterator EvtRecTrackIterator
double tan(const BesAngle a)
HepPoint3D position() const
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
static unsigned int theta_module(const Identifier &id)
static unsigned int phi_module(const Identifier &id)
virtual HepPoint3D GetCrystalPoint(const Identifier &id, const int i) const =0
_EXTERN_ std::string DstEmcShowerCol
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol
_EXTERN_ std::string RecEmcShowerCol