339 {
340 MsgStream log(
msgSvc(), name());
341 log << MSG::INFO << "in execute()" << endreq;
342
343 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
344 int runNo=eventHeader->runNumber();
345
346
349 if (runNum>=runFrom&&runNum<=runTo) {
350 m_inFlag=true;
351 } else {
352 m_inFlag=false;
353 }
354
355 if (m_inFlag==false){
356
357 runFrom=m_EmcShEnCalibSvc -> getRunFrom();
358 runTo=m_EmcShEnCalibSvc -> getRunTo();
359
360
361
362 cout <<
"current run=" <<
runNo<<endl;
363 cout << "in AbsCor open getPi0CalibFile()= " << m_EmcShEnCalibSvc -> getPi0CalibFile()<<endl;
364 cout << "open getSingleGammaCalibFile()= " << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()<<endl;
365 cout <<"getRunFrom()="<< runFrom<<endl;
366 cout <<"getRunTo()="<< runTo<<endl;
367
368
369 string CorFunparaPath;
370 if(MCuseTof==1){
371 if (m_ifReadDB){
372 CorFunparaPath = m_EmcShEnCalibSvc -> getSingleGammaCalibFile();
373 } else {
374 CorFunparaPath = m_CorFunparaPath;
375 cout<<"no read database, but using the set:"<<CorFunparaPath<<endl;
376 }
377 }
378 if(MCuseTof==0){
379 CorFunparaPath = getenv("ABSCORROOT");
380 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
381 }
382
384 in2corfun.open(CorFunparaPath.c_str());
385 assert(in2corfun);
386
387 for(int i=0;i<28;i++){
388 in2corfun>>m_corFunPar[i][0];
389 in2corfun>>m_corFunPar[i][1];
390 in2corfun>>m_corFunPar[i][2];
391 in2corfun>>m_corFunPar[i][3];
392 in2corfun>>m_corFunPar[i][4];
393 in2corfun>>m_corFunPar[i][5];
394 }
395 in2corfun.close();
396
397
398 string DataPathc3p;
399 DataPathc3p = getenv("ABSCORROOT");
400 DataPathc3p += "/share/c3p.txt";
401
402 string DataPathc3ptof;
403 if (m_ifReadDB){
404 DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
405 } else {
406 DataPathc3ptof = m_DataPathc3ptof;
407 cout<<"no read database, but using the set:"<<DataPathc3ptof<<endl;
408 }
409
411 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
412 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
413 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
414 for(int i=0; i<4; i++){
415 double am,ame;
416 inc3p>>am;
417 inc3p>>ame;
419 }
420 }
421
422
425 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())return SUCCESS;
426 if(evtRecEvent->totalTracks()>50)return SUCCESS;
427
429 ISvcLocator* svcLocator = Gaudi::svcLocator();
430 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
431 if(sc!=StatusCode::SUCCESS) {
432 cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
433 }
434
435 for(int i = 0; i< evtRecEvent->totalTracks(); i++) {
437 if(!(*itTrk)->isEmcShowerValid())continue;
439
440
441
442
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
474
475 unsigned int module, ntheta, nphi;
479
480
481
484
485
486 double e5x5=emcTrk->
e5x5();
487 double etof=0;
488
489 if(usetof==1 && (*itTrk)->isTofTrackValid()){
490 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
491 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
492 if(etof>100.)etof=0;
493 }
494
495 double energyC;
496
497 int thetaId;
498 if (module==0||module==2) thetaId = thetaModule;
499 if (module==1 && thetaModule<=21) thetaId = thetaModule + 6;
500 if (module==1 && thetaModule>21) thetaId = 43 - thetaModule + 6;
501 double DthetaId=double(thetaId);
502
503 if(MCuseTof==1){
504 if (thetaId<6) etof=0.0;
505 if (MCCorUseFunction==1){
506 energyC=ECorrFunctionMC(e5x5+etof,DthetaId);
507 } else if (MCCorUseFunction==0){
508 energyC=ECorrMC(e5x5+etof,DthetaId);
509 }
510 }
511 if (MCuseTof==0) {
512 if (MCCorUseFunction==1){
513 energyC=ECorrFunctionMC(e5x5,DthetaId);
514 } else if (MCCorUseFunction==0){
515 energyC=ECorrMC(e5x5,DthetaId);
516 }
517 }
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539 double lnE = std::log(energyC);
540
541 if (energyC>1.0) lnE=std::log(1.0);
542 if (energyC<0.05) lnE=std::log(0.05);
543
544 double lnEcor=1.0;
545 if(dopi0Cor==1){
546 if(
runNo>0 && dodatacor==1) {
547 lnEcor =
ai[0]+
ai[1]*lnE+
ai[2]*lnE*lnE+
ai[3]*lnE*lnE*lnE;
548 }
549 }
550 if(lnEcor<0.5)continue;
551
552
553
554
556
557
558 double enecor=1.;
559 if(hotcellmask==1){
560 for(int ih=0;ih<10;ih++){
561 if(hrunstart[ih]==-1||hrunend[ih]==-1||hcell[ih]==-1)continue;
564 }
565 }
566
567 if(edgecor==1){
568
569 if(module==1) {
570 unsigned int theModule;
571 if(thetaModule>21) {
572 theModule = 43 - thetaModule;
574 pos.setZ(-pos.z());
575 } else {
576 theModule = thetaModule;
577 }
578
579 double IRShift;
580 if(theModule==21) {
581 IRShift = 0;
582
583 } else if(theModule==20) {
584 IRShift = 2.5;
585
586 } else {
587 IRShift = 5.;
588
589 }
590
591
596
597 double theta01,theta23,length,d;
598 theta01 = (center01-IR).theta();
599 theta23 = (center23-IR).theta();
600 length = (center01-IR).mag();
601 d = length*
tan(theta01-theta23);
602
603 double xIn;
604 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
605 if (xIn < (-d/2) && theModule!=21){
606
607 theModule=theModule+1 ;
608
610 if(theModule==21) {
611 IRShift = 0;
612
613 } else if(theModule==20) {
614 IRShift = 2.5;
615
616 } else {
617 IRShift = 5.;
618
619 }
621 IR=IR1;
624 theta01 = (center01-IR).theta();
625 theta23 = (center23-IR).theta();
626 length = (center01-IR).mag();
627 d = length*
tan(theta01-theta23);
628
629 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
630
631 } else if (xIn > (d/2) && theModule!=0 ){
632
633 theModule=theModule-1 ;
635 if(theModule==21) {
636 IRShift = 0;
637
638 } else if(theModule==20) {
639 IRShift = 2.5;
640
641 } else {
642 IRShift = 5.;
643
644 }
645
647 IR=IR1;
650 theta01 = (center01-IR).theta();
651 theta23 = (center23-IR).theta();
652 length = (center01-IR).mag();
653 d = length*
tan(theta01-theta23);
654
655 xIn = length*
tan(theta01-(pos-IR).theta())-d/2;
656 }
657
658 double yIn;
659
660
661
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
665 if(nphi==0&&yIn>100) yIn=yIn-360;
666 if(nphi==119&&yIn<-100) yIn=yIn+360;
667
668 if(yIn<-1.5-0.15){
669
670 if(nphi!=0) phiModule=phiModule-1;
671 if(nphi==0) phiModule=119;
672 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
673 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
674 if(phiModule==0&&yIn>100) yIn=yIn-360;
675 if(phiModule==119&&yIn<-100) yIn=yIn+360;
676
677 }
678
679 if(yIn>1.5-0.15){
680
681
682 if(nphi!=119) phiModule=phiModule+1;
683 if(nphi==119) phiModule=0;
684
685 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
686 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
687 if(phiModule==0&&yIn>100) yIn=yIn-360;
688 if(phiModule==119&&yIn<-100) yIn=yIn+360;
689 }
690
691 enecor=m_par[theModule][0]
692 +m_par[theModule][1]*xIn
693 +m_par[theModule][2]*xIn*xIn
694 +m_par[theModule][3]*xIn*xIn*xIn
695 +m_par[theModule][4]*xIn*xIn*xIn*xIn
696 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
697 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
698
699
700 +m_par[theModule][7]*yIn
701 +m_par[theModule][8]*yIn*yIn
702 +m_par[theModule][9]*yIn*yIn*yIn
703 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
704
705 } else{
706 enecor=1;
707 }
708 }
709
710
711 double energyCC= energyC/(lnEcor*enecor);
712
714
715 if(ntOut==true){
716 m_ef=energyCC;
718 m_ec=energyC;
719 m_ct=lnEcor ;
720 m_cedge=enecor;
721 m_tuple1->write();
722 }
723
724
725 }
726
728 if(!recEmcShowerCol){
729 return( StatusCode::SUCCESS);
730 }
732 if(!dstEmcShowerCol){
733 return( StatusCode::SUCCESS);
734 }
735
736
737 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())return SUCCESS;
738 for(int i=0;i<recEmcShowerCol->size();i++){
739 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
740 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
741
742 (*iter_dst)->setEnergy((*iter_rec)->energy());
743 (*iter_dst)->setStatus((*iter_rec)->status());
744
745
746 }
747 return( StatusCode::SUCCESS);
748}
double tan(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
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 barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
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