35#include "GaudiKernel/Bootstrap.h"
36#include "GaudiKernel/IDataProviderSvc.h"
37#include "GaudiKernel/ISvcLocator.h"
38#include "GaudiKernel/MsgStream.h"
39#include "GaudiKernel/PropertyMgr.h"
40#include "GaudiKernel/SmartDataPtr.h"
42#include "EventModel/Event.h"
43#include "EventModel/EventModel.h"
45#include "EventModel/EventHeader.h"
48#include "EmcRawEvent/EmcDigi.h"
49#include "EmcRecEventModel/RecEmcEventModel.h"
50#include "EmcRecGeoSvc/IEmcRecGeoSvc.h"
51#include "EvtRecEvent/EvtRecEvent.h"
52#include "EvtRecEvent/EvtRecTrack.h"
54#include "CLHEP/Geometry/Point3D.h"
55#include "CLHEP/Vector/ThreeVector.h"
56#ifndef ENABLE_BACKWARDS_COMPATIBILITY
59#include "CLHEP/Random/RandGauss.h"
63using CLHEP::Hep3Vector;
64using CLHEP::RandGauss;
68typedef std::vector<int>
Vint;
69typedef std::vector<HepLorentzVector>
Vp4;
76 : Algorithm( name, pSvcLocator )
79 , m_lowEnergyShowerCut( 0.1 )
80 , m_highEnergyShowerCut( 0.5 )
81 , m_matchThetaCut( 0.2 )
82 , m_matchPhiCut( 0.2 )
83 , m_highMomentumCut( 0.5 )
86 , m_minAngShEnergyCut( 0.2 )
91 , m_oneProngMomentumCut( 1.2 )
95 , m_ShEneThreshCut( 0.02 )
96 , m_ShEneLeptonCut( 1. )
97 , m_minNrXtalsShowerCut( 10 )
98 , m_maxNrXtalsShowerCut( 70 )
99 , m_phiDiffMinCut( 0.05 )
100 , m_phiDiffMaxCut( 0.2 )
101 , m_nrShThreshCut( 20 )
102 , m_thetaDiffCut( 0.04 )
106 m_showersAccepted( 0 )
109 m_writeMVToFile( true )
111 , m_inputFileDir(
"../InputData/" )
112 , m_fileDir(
"/home/besdata/public/liucx/Calib/" )
113 , m_selMethod(
"Ixtal" )
116 , m_beamEnergy( 1.843 )
125 declareProperty(
"Vr0cut", m_vr0cut = 1.0 );
126 declareProperty(
"Vz0cut", m_vz0cut = 5.0);
128 declareProperty(
"lowEnergyShowerCut", m_lowEnergyShowerCut );
129 declareProperty(
"highEnergyShowerCut", m_highEnergyShowerCut );
130 declareProperty(
"matchThetaCut", m_matchThetaCut );
131 declareProperty(
"matchPhiCut", m_matchPhiCut );
133 declareProperty(
"highMomentumCut", m_highMomentumCut );
134 declareProperty(
"EoPMaxCut", m_EoPMaxCut );
135 declareProperty(
"EoPMinCut", m_EoPMinCut );
136 declareProperty(
"minAngShEnergyCut", m_minAngShEnergyCut );
137 declareProperty(
"minAngCut", m_minAngCut );
138 declareProperty(
"acolliCut", m_acolliCut );
139 declareProperty(
"eNormCut", m_eNormCut );
140 declareProperty(
"pNormCut", m_pNormCut );
141 declareProperty(
"oneProngMomentumCut", m_oneProngMomentumCut );
145 declareProperty(
"digiRangeCut", m_digiRangeCut );
147 declareProperty(
"ShEneThreshCut", m_ShEneThreshCut );
148 declareProperty(
"ShEneLeptonCut", m_ShEneLeptonCut );
150 declareProperty(
"minNrXtalsShowerCut", m_minNrXtalsShowerCut );
151 declareProperty(
"maxNrXtalsShowerCut", m_maxNrXtalsShowerCut );
152 declareProperty(
"phiDiffMinCut", m_phiDiffMinCut );
153 declareProperty(
"phiDiffMaxCut", m_phiDiffMaxCut );
154 declareProperty(
"nrShThreshCut", m_nrShThreshCut );
155 declareProperty(
"thetaDiffCut", m_thetaDiffCut );
156 declareProperty(
"LATCut", m_LATCut );
159 declareProperty(
"writeMVToFile", m_writeMVToFile );
160 declareProperty(
"fileExt", m_fileExt );
161 declareProperty(
"fileDir", m_fileDir );
162 declareProperty(
"inputFileDir", m_inputFileDir );
163 declareProperty(
"selMethod", m_selMethod );
164 declareProperty(
"sigmaCut", m_sigmaCut );
165 declareProperty(
"ReadBeamEFromDB", m_ReadBeamEFromDB =
false );
167 declareProperty(
"beamEnergy", m_beamEnergy );
168 declareProperty(
"Dbeam", m_dbeam = 0.00 );
170 declareProperty(
"UseBeamDetectorEnergy", m_useBeamDetectorEnergy =
false );
172 declareProperty(
"elecSaturation", m_elecSaturation =
true );
174 declareProperty(
"MsgFlag", m_MsgFlag );
175 declareProperty(
"Num", m_Num );
176 declareProperty(
"fileNum", m_fileNum );
179 m_index =
new int*[56];
180 for ( j = 0; j < 56; j++ )
182 m_index[j] =
new int[120];
183 for (
int k = 0; k < 120; k++ ) { m_index[j][k] = -1; }
188 for (
int i = 0; i < 6240; i++ ) { m_inputConst[i] = 1.0; }
200 for (
int i = 0; i < 56; i++ )
delete[] m_index[i];
206 for (
int j = 0; j < 6240; j++ ) { m_measure[j] = -1; }
211 MsgStream log(
msgSvc(), name() );
212 log << MSG::INFO <<
"in initialize()" << endmsg;
215 m_showersAccepted = 0;
220 m_TwoProngMatched = 0;
222 m_TwoProngOneMatched = 0;
229 if ( m_writeMVToFile ) myCalibData =
new EmcBhaCalibData( m_nXtals, m_MsgFlag );
230 else myCalibData = 0;
234 ISvcLocator* svcLocator = Gaudi::svcLocator();
235 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc", m_iGeoSvc );
236 if ( sc != StatusCode::SUCCESS ) { cout <<
"Error: Can't get EmcRecGeoSvc" << endl; }
251 StatusCode scBeamEnergy;
252 scBeamEnergy = Gaudi::svcLocator()->service(
"BeamEnergySvc", m_BeamEnergySvc );
254 if ( scBeamEnergy != StatusCode::SUCCESS )
255 { log << MSG::ERROR <<
"can not use BeamEnergySvc" << endmsg; }
285 return StatusCode::SUCCESS;
291 MsgStream log(
msgSvc(), name() );
292 log << MSG::DEBUG <<
"in execute()" << endmsg;
298 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(),
"/Event/EventHeader" );
300 run = eventHeader->runNumber();
301 event = eventHeader->eventNumber();
309 if ( m_ReadBeamEFromDB && m_irun != run )
312 m_BeamEnergySvc->getBeamEnergyInfo();
313 if ( m_BeamEnergySvc->isRunValid() ) m_beamEnergy = m_BeamEnergySvc->getbeamE();
318 cout <<
"beamEnergy=" << m_beamEnergy << endl;
319 m_beamEnergy = m_beamEnergy - m_dbeam;
323 HepLorentzVector ptrk;
324 ptrk.setPx( m_beamEnergy *
sin( the ) *
cos( phi ) );
325 ptrk.setPy( m_beamEnergy *
sin( the ) *
sin( phi ) );
326 ptrk.setPz( m_beamEnergy *
cos( the ) );
327 ptrk.setE( m_beamEnergy );
329 ptrk = ptrk.boost( -0.011, 0, 0 );
331 cout <<
"beamEnergy=" << m_beamEnergy <<
" cms " << ptrk.e()
332 <<
" ratio=" << ( m_beamEnergy - ptrk.e() ) / ptrk.e() << endl;
333 m_beamEnergy = ptrk.e();
336 if ( m_useBeamDetectorEnergy )
341 scScan = Gaudi::svcLocator()->service(
"ScanEnergySvc", m_ScanEnergySvc );
342 if ( scScan != StatusCode::SUCCESS ) { cout <<
"can not use ScanEnergySvc" << endmsg; }
346 std::cout <<
"Test ScanEnergySvc getScanEnergy= " << m_ScanEnergySvc->
getScanEnergy()
348 m_beamEnergy = m_ScanEnergySvc->
getScanEnergy() / 2.0 / 1000.;
349 cout <<
"ScanbeamEnergy=" << m_beamEnergy << endl;
356 for (
int j = 0; j < 6240; j++ ) { m_measure[j] = -1; }
358 if ( m_elecSaturation ==
true )
362 SmartDataPtr<EmcDigiCol> emcDigiCol( eventSvc(),
"/Event/Digi/EmcDigiCol" );
365 log << MSG::FATAL <<
"Could not find EMC digi" << endmsg;
366 return ( StatusCode::FAILURE );
369 EmcDigiCol::iterator iter3;
370 for ( iter3 = emcDigiCol->begin(); iter3 != emcDigiCol->end(); iter3++ )
372 RecEmcID id( ( *( iter3 ) )->identify() );
375 unsigned int npart, ntheta, nphi;
380 unsigned int newthetaInd = -999;
381 if ( npart == 0 ) newthetaInd = ntheta;
382 if ( npart == 1 ) newthetaInd = ntheta + 6;
383 if ( npart == 2 ) newthetaInd = 55 - ntheta;
385 int ixtal =
index( newthetaInd, nphi );
386 m_measure[ixtal] = ( *iter3 )->getMeasure();
419 return StatusCode::SUCCESS;
425 MsgStream log(
msgSvc(), name() );
427 log << MSG::INFO <<
"in finalize()" << endmsg;
440 if ( m_writeMVToFile )
446 cout <<
"Event=" << m_events << endl;
448 cout <<
"m_Nothing =" << m_Nothing << endl;
449 cout <<
"m_OneProng=" << m_OneProng << endl;
451 cout <<
"m_TwoProngMatched=" << m_TwoProngMatched << endl;
453 cout <<
"m_TwoProngOneMatched=" << m_TwoProngOneMatched << endl;
455 cout <<
"m_showersAccepted=" << m_showersAccepted << endl;
457 return StatusCode::SUCCESS;
462double EmcSelBhaEvent::expectedEnergy(
long int ixtal ) {
467 unsigned int module, ntheta, nphi, ThetaIndex;
470 module = theEmcStruc->getPartId( ixtal );
471 ntheta = theEmcStruc->
getTheta( ixtal );
472 nphi = theEmcStruc->
getPhi( ixtal );
474 if ( module == 0 ) ThetaIndex = ntheta;
475 if ( module == 1 ) ThetaIndex = ntheta + 6;
476 if ( module == 2 ) ThetaIndex = 55 - ntheta;
482 double theta = SeedPos.theta();
483 double phi = SeedPos.phi();
484 HepLorentzVector ptrk;
485 ptrk.setPx( m_beamEnergy *
sin( theta ) *
cos( phi ) );
486 ptrk.setPy( m_beamEnergy *
sin( theta ) *
sin( phi ) );
487 ptrk.setPz( m_beamEnergy *
cos( theta ) );
488 ptrk.setE( m_beamEnergy );
490 ptrk = ptrk.boost( 0.011, 0, 0 );
492 double depoEne_lab = m_corFun[ThetaIndex] * ptrk.e();
501 MsgStream log(
msgSvc(), name() );
553 for (
int i = 0; i < evtRecEvent->totalTracks(); i++ )
556 if ( i >= evtRecTrkCol->size() )
break;
560 if ( ( *itTrk )->isEmcShowerValid() )
564 int TrkID = ( *itTrk )->
trackId();
565 double Shower5x5 = theShower->
e5x5();
590 if ( Shower5x5 > ( 0.6 * m_beamEnergy ) ) { iGam.push_back( TrkID ); }
593 int nGam = iGam.size();
601 m_selectedTrkID1 = iGam[0];
602 m_selectedTrkID2 = iGam[1];
611 MsgStream log(
msgSvc(), name() );
633 double ene, theta, phi, eseed;
634 double showerX, showerY, showerZ;
635 long int thetaIndex, phiIndex, numberOfDigis;
638 unsigned int showerModule;
640 HepPoint3D showerPosition( 0, 0, 0 );
642 if ( !m_showerList.empty() ) m_showerList.clear();
644 for (
int ish = 0; ish < 2; ish++ )
650 theShower = theShower1;
655 theShower = theShower2;
658 ene = theShower->
e5x5();
659 eseed = theShower->
eSeed();
685 showerPosition = theShower->
position();
686 theta = theShower->
theta();
687 phi = theShower->
phi();
688 showerX = theShower->
x();
689 showerY = theShower->
y();
690 showerZ = theShower->
z();
707 list<EmcShDigi> shDigiList;
710 double digiEne,
time, fraction, digiTheta, digiPhi;
711 double digiX, digiY, digiZ;
712 long int digiThetaIndex, digiPhiIndex;
713 HepPoint3D digiPos( 0, 0, 0 );
715 RecEmcFractionMap::const_iterator ciFractionMap;
717 if ( !shDigiList.empty() ) shDigiList.clear();
719 for ( ciFractionMap = fracMap5x5.begin(); ciFractionMap != fracMap5x5.end();
723 digiEne = ciFractionMap->second.getEnergy();
725 time = ciFractionMap->second.getTime();
726 fraction = ciFractionMap->second.getFraction();
728 cellId = ciFractionMap->second.getCellId();
730 digiPos = m_iGeoSvc->GetCFrontCenter( cellId );
731 digiTheta = digiPos.theta();
732 digiPhi = digiPos.phi();
737 module = EmcID::barrel_ec( cellId );
748 aShDigi->
setPhi( digiPhi );
755 aShDigi->
setY( digiX );
756 aShDigi->
setY( digiY );
757 aShDigi->
setZ( digiZ );
759 shDigiList.push_back( *aShDigi );
763 numberOfDigis = shDigiList.size();
765 maxima = *( --shDigiList.end() );
778 aShower->
setWhere( showerPosition );
779 aShower->
setX( showerX );
780 aShower->
setY( showerY );
781 aShower->
setZ( showerZ );
782 m_showerList.push_back( *aShower );
791 if ( m_showerList.size() == 2 )
794 list<EmcShower>::const_iterator iter_Sh;
796 for ( iter_Sh = m_showerList.begin(); iter_Sh != m_showerList.end(); iter_Sh++ )
802 double theta = iter_Sh->theta();
811 myBhaEvt->setPositron()->setShower( shower );
812 myBhaEvt->setPositron()->setTheta( shower.
theta() );
813 myBhaEvt->setPositron()->setPhi( shower.
phi() );
814 unsigned int newthetaInd = -999;
821 myBhaEvt->setPositron()->setThetaIndex( newthetaInd );
823 unsigned int newphiInd = shower.
phiIndex();
824 myBhaEvt->setPositron()->setPhiIndex( newphiInd );
825 myBhaEvt->setPositron()->setFound(
true );
827 log << MSG::INFO << name() <<
": Positron: theta,phi energy "
828 << myBhaEvt->positron()->theta() <<
"," << myBhaEvt->positron()->shower().phi()
829 <<
" " << myBhaEvt->positron()->shower().energy() << endmsg;
837 myBhaEvt->setElectron()->setShower( shower );
838 myBhaEvt->setElectron()->setTheta( shower.
theta() );
839 myBhaEvt->setElectron()->setPhi( shower.
phi() );
840 unsigned int newthetaInd = -999;
847 myBhaEvt->setElectron()->setThetaIndex( newthetaInd );
848 unsigned int newphiInd = shower.
phiIndex();
849 myBhaEvt->setElectron()->setPhiIndex( newphiInd );
850 myBhaEvt->setElectron()->setFound(
true );
852 log << MSG::INFO << name() <<
": Electron: theta,phi energy "
853 << myBhaEvt->electron()->theta() <<
"," << myBhaEvt->electron()->shower().phi()
854 <<
" " << myBhaEvt->electron()->shower().energy() << endmsg;
862 MsgStream log(
msgSvc(), name() );
865 if ( 0 != myBhaEvt->positron()->found() || 0 != myBhaEvt->electron()->found() )
870 double calibEnergy = 0.;
871 double energyError = 0.;
874 if ( myBhaEvt->electron()->found() )
882 unsigned int module, ntheta, nphi;
883 if ( myBhaEvt->electron()->thetaIndex() <= 5 )
886 ntheta = myBhaEvt->electron()->thetaIndex();
888 else if ( myBhaEvt->electron()->thetaIndex() >= 50 )
891 ntheta = 55 - myBhaEvt->electron()->thetaIndex();
896 ntheta = myBhaEvt->electron()->thetaIndex() - 6;
898 nphi = myBhaEvt->electron()->phiIndex();
901 HepPoint3D SeedPos( 0, 0, 0 );
902 SeedPos = m_iGeoSvc->GetCFrontCenter( shId );
912 calibEnergy = myBhaEvt->getDepoMCShowerEnergy_lab(
913 SeedPos.theta(), SeedPos.phi(), myBhaEvt->electron()->thetaIndex(),
914 myBhaEvt->electron()->phiIndex(), m_corFun[myBhaEvt->electron()->thetaIndex()],
917 if ( m_selMethod ==
"DataMCIxtal" )
919 calibEnergy = myBhaEvt->getDepoMCShowerEnergy_lab(
920 SeedPos.theta(), SeedPos.phi(), myBhaEvt->electron()->thetaIndex(),
921 myBhaEvt->electron()->phiIndex(),
922 m_eMeanMC[
index( myBhaEvt->electron()->thetaIndex(),
923 myBhaEvt->electron()->phiIndex() )],
934 if ( calibEnergy > 0 )
937 energyError = myBhaEvt->getErrorDepoMCShowerEnergy(
938 myBhaEvt->electron()->thetaIndex(), myBhaEvt->electron()->phiIndex(),
939 m_eSigma[myBhaEvt->electron()->thetaIndex()] * m_beamEnergy / 100. );
940 if ( m_selMethod ==
"DataMCIxtal" )
942 energyError = m_eRmsMC[
index( myBhaEvt->electron()->thetaIndex(),
943 myBhaEvt->electron()->phiIndex() )] *
948 log << MSG::WARNING <<
" Did not find MC deposited cluster energy "
949 <<
" for this cluster: thetaInd: " << myBhaEvt->electron()->thetaIndex()
950 <<
" phiInd: " << myBhaEvt->electron()->phiIndex() << endl
951 <<
"Will not use this cluster for the Emc "
952 <<
"Bhabha calibration !" << endmsg;
955 myBhaEvt->setElectron()->setErrorOnCalibEnergy( energyError );
956 myBhaEvt->setElectron()->setCalibEnergy( calibEnergy );
960 else log << MSG::INFO << name() <<
": Electron was not selected ! " << endmsg;
966 if ( myBhaEvt->positron()->found() )
974 unsigned int module, ntheta, nphi;
975 if ( myBhaEvt->positron()->thetaIndex() <= 5 )
978 ntheta = myBhaEvt->positron()->thetaIndex();
980 else if ( myBhaEvt->positron()->thetaIndex() >= 50 )
983 ntheta = 55 - myBhaEvt->positron()->thetaIndex();
988 ntheta = myBhaEvt->positron()->thetaIndex() - 6;
990 nphi = myBhaEvt->positron()->phiIndex();
993 HepPoint3D SeedPos( 0, 0, 0 );
994 SeedPos = m_iGeoSvc->GetCFrontCenter( shId );
1004 calibEnergy = myBhaEvt->getDepoMCShowerEnergy_lab(
1005 SeedPos.theta(), SeedPos.phi(), myBhaEvt->positron()->thetaIndex(),
1006 myBhaEvt->positron()->phiIndex(), m_corFun[myBhaEvt->positron()->thetaIndex()],
1009 if ( m_selMethod ==
"DataMCIxtal" )
1011 calibEnergy = myBhaEvt->getDepoMCShowerEnergy_lab(
1012 SeedPos.theta(), SeedPos.phi(), myBhaEvt->positron()->thetaIndex(),
1013 myBhaEvt->positron()->phiIndex(),
1014 m_eMeanMC[
index( myBhaEvt->positron()->thetaIndex(),
1015 myBhaEvt->positron()->phiIndex() )],
1027 if ( calibEnergy > 0. )
1030 energyError = myBhaEvt->getErrorDepoMCShowerEnergy(
1031 myBhaEvt->positron()->thetaIndex(), myBhaEvt->positron()->phiIndex(),
1032 m_eSigma[myBhaEvt->positron()->thetaIndex()] * m_beamEnergy / 100. );
1034 if ( m_selMethod ==
"DataMCIxtal" )
1036 energyError = m_eRmsMC[
index( myBhaEvt->electron()->thetaIndex(),
1037 myBhaEvt->electron()->phiIndex() )] *
1042 log << MSG::WARNING <<
" Did not find MC deposited cluster energy "
1043 <<
"for this cluster: thetaInd: " << myBhaEvt->positron()->thetaIndex()
1044 <<
" phiInd: " << myBhaEvt->positron()->phiIndex() << endl
1045 <<
"Will not use this cluster for the Emc "
1046 <<
"Bhabha calibration !" << endmsg;
1049 myBhaEvt->setPositron()->setErrorOnCalibEnergy( energyError );
1050 myBhaEvt->setPositron()->setCalibEnergy( calibEnergy );
1054 else log << MSG::INFO << name() <<
": Positron was not selected ! " << endmsg;
1060 else { log << MSG::WARNING <<
" No Bhabha data for calibration found in event !" << endmsg; }
1063void EmcSelBhaEvent::fillMatrix() {
1073 for (
int i = 1; i <= 2; i++ )
1076 if ( i == 2 ) _theBhabha = *( myBhaEvt->
electron() );
1077 else _theBhabha = *( myBhaEvt->
positron() );
1084 int _bhaThetaIndex = _theBhabha.
thetaIndex();
1085 int _bhaPhiIndex = _theBhabha.
phiIndex();
1088 double eraw = _bhaEne;
1092 HepLorentzVector ptrk;
1093 ptrk.setPx( eraw *
sin( the ) *
cos( phi ) );
1094 ptrk.setPy( eraw *
sin( the ) *
sin( phi ) );
1095 ptrk.setPz( eraw *
cos( the ) );
1098 ptrk = ptrk.boost( -0.011, 0, 0 );
1102 double SigCut = 0.0;
1104 SigCut = m_sigmaCut;
1106 int ixtalIndex =
index( _bhaThetaIndex, _bhaPhiIndex );
1107 double peakCutMin =0;
1108 double peakCutMax =999;
1111 if ( m_selMethod ==
"Ithe" )
1113 peakCutMin = m_eDepEne[_bhaThetaIndex] * m_beamEnergy -
1114 SigCut * m_eSigmaExp[_bhaThetaIndex] * m_beamEnergy / 100.;
1116 peakCutMax = m_eDepEne[_bhaThetaIndex] * m_beamEnergy +
1117 SigCut * m_eSigmaExp[_bhaThetaIndex] * m_beamEnergy / 100.;
1137 if ( m_selMethod ==
"Ixtal" )
1139 peakCutMin = m_eRawPeak[ixtalIndex] * m_beamEnergy -
1140 SigCut * m_eSigmaExp[_bhaThetaIndex] * m_beamEnergy / 100.;
1142 peakCutMax = m_eRawPeak[ixtalIndex] * m_beamEnergy +
1143 SigCut * m_eSigmaExp[_bhaThetaIndex] * m_beamEnergy / 100.;
1146 if ( m_selMethod ==
"DataMCIxtal" )
1148 peakCutMin = m_eMeanData[ixtalIndex] * m_beamEnergy -
1149 SigCut * m_eRmsData[ixtalIndex] * m_beamEnergy;
1152 peakCutMax = m_eMeanData[ixtalIndex] * m_beamEnergy +
1153 SigCut * m_eRmsData[ixtalIndex] * m_beamEnergy;
1194 if ( _theBhabha.
found() != 0 && _theBhabha.
calibEnergy() > 0. && _bhaEne >= peakCutMin &&
1195 _bhaEne <= peakCutMax && m_measure[ixtalIndex] != 3 )
1210 m_showersAccepted++;
1212 _sigmaBha = _theBhabha.
sigma2();
1215 _theShower = _theBhabha.
shower();
1220 _DigiMax = _theShower.
maxima();
1222 unsigned int newThetaIndMax = 999;
1232 int maximaIndex = 0;
1239 list<EmcShDigi> _DigiList = _theShower.
digiList();
1241 list<EmcShDigi>::const_iterator _Digi1, _Digi2;
1247 for ( _Digi1 = _DigiList.begin(); _Digi1 != _DigiList.end(); _Digi1++ )
1254 unsigned int newThetaInd1 = 999;
1255 if ( _Digi1->module() == 0 ) newThetaInd1 = _Digi1->thetaIndex();
1256 if ( _Digi1->module() == 1 ) newThetaInd1 = _Digi1->thetaIndex() + 6;
1257 if ( _Digi1->module() == 2 ) newThetaInd1 = 55 - _Digi1->thetaIndex();
1259 int Digi1Index =
index( newThetaInd1, _Digi1->phiIndex() );
1267 double dvec = ( (
static_cast<double>( _Digi1->energy() ) ) *
1271 if ( m_writeMVToFile ) ( myCalibData->vectorR( Digi1Index ) ) += dvec;
1274 if ( m_writeMVToFile ) ( myCalibData->xtalHits( Digi1Index ) )++;
1278 if ( Digi1Index == maximaIndex )
1280 if ( m_writeMVToFile ) { ( myCalibData->xtalHitsDir( Digi1Index ) )++; }
1284 for ( _Digi2 = _Digi1; _Digi2 != _DigiList.end(); _Digi2++ )
1287 unsigned int newThetaInd2 = 999;
1288 if ( _Digi2->module() == 0 ) newThetaInd2 = _Digi2->thetaIndex();
1289 if ( _Digi2->module() == 1 ) newThetaInd2 = _Digi2->thetaIndex() + 6;
1290 if ( _Digi2->module() == 2 ) newThetaInd2 = 55 - _Digi2->thetaIndex();
1292 int Digi2Index =
index( newThetaInd2, _Digi2->phiIndex() );
1295 double val =
static_cast<double>( ( ( ( _Digi1->energy() * _Digi2->energy() ) ) ) /
1298 if ( m_writeMVToFile ) myCalibData->matrixMEle( Digi1Index, Digi2Index ) += val;
1309 MsgStream log(
msgSvc(), name() );
1311 int numberOfXtalsRing;
1322 for (
int the = theEmcStruc->
startingTheta(); the < nrOfTheRings; the++ )
1325 numberOfXtalsRing = theEmcStruc->
crystalsInRing( (
unsigned int)the );
1327 for (
int phi = 0; phi < numberOfXtalsRing; phi++ )
1328 { m_index[the][phi] = theEmcStruc->
getIndex( (
unsigned int)the, (
unsigned int)phi ); }
1331 log << MSG::INFO <<
" Emc geometry for Bhabha calibration initialized !! " << endl
1332 <<
"Number of Xtals: " << m_nXtals << endmsg;
1338 MsgStream log(
msgSvc(), name() );
1341 if ( myCalibData != 0 )
1344 if ( m_writeMVToFile )
1349 if ( m_run < 0 ) {
count =
sprintf( cnum,
"MC%d_%i", -m_run, m_Num ); }
1350 if ( m_run >= 0 ) {
count =
sprintf( cnum,
"%d_%i", m_run, m_fileNum ); }
1352 std::string runnum =
"";
1353 runnum.append( cnum );
1355 ofstream runnumberOut;
1356 std::string runnumberFile = m_fileDir;
1357 runnumberFile += m_fileExt;
1358 runnumberFile +=
"runnumbers.dat";
1359 runnumberOut.open( runnumberFile.c_str(), ios::out | ios::app );
1361 ifstream runnumberIn;
1362 runnumberIn.open( runnumberFile.c_str() );
1363 bool status =
false;
1364 while ( !runnumberIn.eof() )
1369 if ( runnum ==
num )
1372 log << MSG::INFO <<
" the runnumber: " << runnum
1373 <<
" exists in the file runnumbers.dat" << endmsg;
1379 log << MSG::INFO <<
" the runnumber: " << runnum
1380 <<
" does not exist in the file runnumbers.dat" << endmsg;
1383 runnumberIn.close();
1386 std::string vectorFile = m_fileDir;
1387 vectorFile += m_fileExt;
1388 vectorFile += runnum;
1389 vectorFile +=
"CalibVector.dat";
1390 vectorOut.open( vectorFile.c_str() );
1393 std::string matrixFile = m_fileDir;
1394 matrixFile += m_fileExt;
1395 matrixFile += runnum;
1396 matrixFile +=
"CalibMatrix.dat";
1397 matrixOut.open( matrixFile.c_str() );
1399 if ( vectorOut.good() && matrixOut.good() && runnumberOut.good() )
1402 myCalibData->writeOut( matrixOut, vectorOut );
1404 log << MSG::INFO <<
" Wrote files " << ( vectorFile ) <<
" and " << ( matrixFile )
1409 runnumberOut << runnum <<
"\n";
1410 log << MSG::INFO <<
"Wrote files " << runnumberFile << endmsg;
1414 log << MSG::WARNING <<
" Could not open vector and/or matrix file !" << endl
1415 <<
"matrix file : " << matrixFile << endl
1416 <<
"vector file : " << vectorFile << endmsg;
1420 runnumberOut.close();
1428 while ( diff >
pi ) diff -= twopi;
1429 while ( diff < -
pi ) diff += twopi;
1437 std::string corFunFile = m_inputFileDir;
1438 corFunFile += m_fileExt;
1439 corFunFile +=
"cor.conf";
1440 corFunIn.open( corFunFile.c_str() );
1441 for (
int i = 0; i < 56; i++ )
1443 corFunIn >> m_corFun[i];
1445 cout <<
"energy corFun=" << m_corFun[i] << endl;
1453 std::string EsigmaFile = m_inputFileDir;
1454 EsigmaFile += m_fileExt;
1455 EsigmaFile +=
"sigma.conf";
1456 EsigmaIn.open( EsigmaFile.c_str() );
1457 for (
int i = 0; i < 56; i++ )
1459 EsigmaIn >> m_eSigma[i];
1461 cout <<
"Sigma=" << m_eSigma[i] << endl;
1469 std::string EDepEneFile = m_inputFileDir;
1470 EDepEneFile += m_fileExt;
1471 EDepEneFile +=
"peakI.conf";
1472 EDepEneIn.open( EDepEneFile.c_str() );
1473 for (
int i = 0; i < 56; i++ )
1475 EDepEneIn >> m_eDepEne[i];
1478 cout <<
"DepEne=" << m_eDepEne[i] << endl;
1484 ifstream ESigmaExpIn;
1485 std::string ESigmaExpFile = m_inputFileDir;
1486 ESigmaExpFile += m_fileExt;
1487 ESigmaExpFile +=
"sigmaI.conf";
1488 ESigmaExpIn.open( ESigmaExpFile.c_str() );
1489 for (
int i = 0; i < 56; i++ )
1491 ESigmaExpIn >> m_eSigmaExp[i];
1492 cout <<
"SigmaExp=" << m_eSigmaExp[i] << endl;
1494 ESigmaExpIn.close();
1500 std::string EFile = m_inputFileDir;
1502 EFile +=
"findpeak.conf";
1503 EIn.open( EFile.c_str() );
1507 for (
int i = 0; i < 6240; i++ )
1509 EIn >> ixtal >> Peak[i];
1510 m_eRawPeak[ixtal] = Peak[i];
1534 std::string EFile = m_inputFileDir;
1536 EFile +=
"X4680-meaNo3-e5x5cmsCut0.7-2mc.conf";
1537 EIn.open( EFile.c_str() );
1539 double MeanData[6240], MeanMC[6240];
1540 double RmsData[6240], RmsMC[6240];
1542 for (
int i = 0; i < 6240; i++ )
1544 EIn >> ixtal >> MeanData[i] >> MeanMC[i] >> RmsData[i] >> RmsMC[i];
1545 m_eMeanData[ixtal] = MeanData[i];
1546 m_eMeanMC[ixtal] = MeanMC[i];
1554 ifstream EIn1, EIn2, EIn3, EIn4;
1556 std::string EFile1 = m_inputFileDir;
1557 std::string EFile2 = m_inputFileDir;
1558 std::string EFile3 = m_inputFileDir;
1559 std::string EFile4 = m_inputFileDir;
1561 EFile1 +=
"findpeak-all-IV.conf";
1562 EFile2 +=
"findrms-all-IV.conf";
1563 EFile3 +=
"peakIxtalMC.conf";
1564 EFile4 +=
"findrms-all-MC.conf";
1566 EIn1.open( EFile1.c_str() );
1567 EIn2.open( EFile2.c_str() );
1568 EIn3.open( EFile3.c_str() );
1569 EIn4.open( EFile4.c_str() );
1573 int ixtal1, ixtal2, ixtal3, ixtal4;
1574 for (
int i = 0; i < 6240; i++ )
1576 EIn1 >> ixtal1 >> MeanData[i];
1577 EIn2 >> ixtal2 >> RmsData[i];
1578 EIn3 >> ixtal3 >> MeanMC[i];
1579 EIn4 >> ixtal4 >> RmsMC[i];
1581 m_eRmsData[ixtal2] = RmsData[i];
1583 m_eRmsMC[ixtal4] = RmsMC[i];
1596 double minDist = 999;
1604 HepLorentzVector theShowerVec( 1, 1, 1, 1 );
1605 theShowerVec.setTheta( theShower->
theta() );
1606 theShowerVec.setPhi( theShower->
phi() );
1607 theShowerVec.setRho( theShower->
energy() );
1608 theShowerVec.setE( theShower->
energy() );
1610 for (
int j = 0; j < evtRecEvent->totalTracks(); j++ )
1614 if ( !( *jtTrk )->isEmcShowerValid() )
continue;
1615 if ( ShowerID == ( *jtTrk )->trackId() )
continue;
1619 if ( aShower->
energy() > m_minAngShEnergyCut )
1622 HepLorentzVector aShowerVec( 1, 1, 1, 1 );
1623 aShowerVec.setTheta( aShower->
theta() );
1624 aShowerVec.setPhi( aShower->
phi() );
1625 aShowerVec.setRho( aShower->
energy() );
1626 aShowerVec.setE( aShower->
energy() );
1628 double dist = theShowerVec.angle( aShowerVec );
1630 if ( dist < minDist ) minDist = dist;
DECLARE_COMPONENT(BesBdkRc)
HepGeom::Point3D< double > HepPoint3D
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
map< RecEmcID, RecEmcFraction, less< RecEmcID > > RecEmcFractionMap
EvtRecTrackCol::iterator EvtRecTrackIterator
DOUBLE_PRECISION count[3]
std::vector< HepLorentzVector > Vp4
double sin(const BesAngle a)
double cos(const BesAngle a)
HepPoint3D position() const
EmcBhabha * positron() const
EmcBhabha * electron() const
const double & calibEnergy() const
const double & errorOnCalibEnergy() const
const unsigned int & thetaIndex() const
const unsigned int & phiIndex() 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)
double findPhiDiff(double phi1, double phi2)
void readDataAndMCIxtal()
EmcSelBhaEvent(const std::string &name, ISvcLocator *pSvcLocator)
int index(int theta, int phi) const
double Angle2ClosestShower(int ShowerID)
void setWhere(HepPoint3D where)
const unsigned int & thetaIndex() const
const unsigned int & phiIndex() const
void setTheta(double theta)
void setModule(unsigned int module)
void setEnergy(double energy)
void setFraction(double fraction)
void setTime(double time)
void setPhiIndex(unsigned int phiIndex)
void setThetaIndex(unsigned int thetaIndex)
const unsigned int & module() const
const unsigned int & thetaIndex() const
void setEnergy(double energy)
const double & theta() const
void setTheta(double theta)
const double & energy() const
void setDigiList(std::list< EmcShDigi > digiList)
void setPhiIndex(unsigned int phiIndex)
const double & phi() const
void setThetaIndex(unsigned int thetaIndex)
const EmcShDigi maxima() const
void setMaxima(EmcShDigi maxima)
const unsigned int & phiIndex() const
void setWhere(HepPoint3D where)
const std::list< EmcShDigi > digiList() const
void setNumberOfDigis(long int numberOfDigis)
const unsigned int & module() const
void setModule(unsigned int module)
long getIndex(unsigned int thetaIndex, unsigned int phiIndex) const
unsigned int getNumberOfTheRings()
unsigned int startingTheta()
unsigned int crystalsInRing(unsigned int theta) const
unsigned int getNumberOfXtals()
unsigned int getPhi(long Index) const
unsigned int getTheta(long Index) const
virtual HepPoint3D GetCFrontCenter(const Identifier &id) const =0
virtual double getScanEnergy() const =0
RecEmcFractionMap getFractionMap5x5() const
RecEmcID getShowerId() const
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol