86 MsgStream log(
msgSvc(), name() );
87 log << MSG::INFO <<
"in initialize()" << endmsg;
93 if ( nt1 ) m_tuple1 = nt1;
96 m_tuple1 =
ntupleSvc()->book(
"FILE1/ec", CLID_ColumnWiseTuple,
"ks N-Tuple example" );
99 status = m_tuple1->addItem(
"ef", m_ef );
100 status = m_tuple1->addItem(
"e5", m_e5 );
101 status = m_tuple1->addItem(
"ec", m_ec );
102 status = m_tuple1->addItem(
"ct", m_ct );
103 status = m_tuple1->addItem(
"cedge", m_cedge );
107 log << MSG::ERROR <<
" Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
108 return StatusCode::FAILURE;
113 m_index =
new int*[56];
114 for (
int j = 0; j < 56; j++ )
116 m_index[j] =
new int[120];
117 for (
int k = 0; k < 120; k++ ) { m_index[j][k] = -1; }
120 m_par =
new double*[22];
121 for (
int j = 0; j < 22; j++ )
123 m_par[j] =
new double[11];
124 for (
int k = 0; k < 11; k++ ) { m_par[j][k] = -99; }
127 m_parphi =
new double*[22];
128 for (
int j = 0; j < 22; j++ )
130 m_parphi[j] =
new double[5];
131 for (
int k = 0; k < 5; k++ ) { m_parphi[j][k] = -99; }
137 EnParInFile = getenv(
"ABSCORROOT" );
138 EnParInFile +=
"/share/para.dat";
139 EnParIn.open( EnParInFile.c_str() );
140 for (
int i = 0; i < 22; i++ )
143 EnParIn >> m_par[i][0] >> m_par[i][1] >> m_par[i][2] >> m_par[i][3] >> m_par[i][4] >>
144 m_par[i][5] >> m_par[i][6] >> m_par[i][7] >> m_par[i][8] >> m_par[i][9] >>
151 string EnParInFilephi = getenv(
"ABSCORROOT" );
152 EnParInFilephi +=
"/share/paraphi.dat";
153 EnParInphi.open( EnParInFilephi.c_str() );
154 for (
int i = 0; i < 22; i++ )
156 EnParInphi >> m_parphi[i][0] >> m_parphi[i][1] >> m_parphi[i][2] >> m_parphi[i][3] >>
181 string DataPathcbeam;
182 DataPathcbeam = getenv(
"ABSCORROOT" );
183 DataPathcbeam +=
"/share/cbeam.txt";
185 incbeam.exceptions( ifstream::failbit | ifstream::badbit );
186 incbeam.open( DataPathcbeam.c_str(), ios::in );
187 for (
int i = 0; i < 56; i++ )
189 double tid, peak, peake, sig, sige;
195 cbeam[i] = 1.0 / peak;
200 DataPathc3p = getenv("ABSCORROOT");
201 DataPathc3p += "/share/c3p.txt";
203 string DataPathc3ptof;
204 DataPathc3ptof = getenv("ABSCORROOT");
205 DataPathc3ptof += "/share/c3ptof.txt";
206 cout<<"mccor = "<<mccor<<endl;
207 //DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
211 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
212 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
213 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
214 for(int i=0; i<4; i++){
221 string paraPath = getenv(
"ABSCORROOT" );
222 if ( paraPath ==
"" ) {}
225 if ( MCuseTof == 1 ) { paraPath +=
"/share/evsetTof.txt"; }
226 if ( MCuseTof == 0 ) { paraPath +=
"/share/evset.txt"; }
229 in2.open( paraPath.c_str() );
231 double energy, thetaid, peak1, peakerr1, res, reserr;
232 dt =
new TGraph2DErrors();
233 dtErr =
new TGraph2DErrors();
235 for (
int i = 0; i < 1484; i++ )
243 dt->SetPoint( i,
energy, thetaid, peak1 );
244 dt->SetPointError( i, 0, 0, peakerr1 );
245 dtErr->SetPoint( i,
energy, thetaid, res );
246 dtErr->SetPointError( i, 0, 0, reserr );
247 if ( i < 28 ) e25min[int( thetaid )] =
energy;
248 if ( i >= 1484 - 28 ) e25max[int( thetaid )] =
energy;
256 for (
int ih = 0; ih < 10; ih++ )
263 int dumring, dumphi, dummod, dumid;
265 HotList = getenv(
"ABSCORROOT" );
266 HotList +=
"/share/hotcry.txt";
268 hotcrys.exceptions( ifstream::failbit | ifstream::badbit );
269 hotcrys.open( HotList.c_str(), ios::in );
270 for (
int il = 0; il < numhots; il++ )
272 hotcrys >> hrunstart[il];
273 hotcrys >> hrunend[il];
274 hotcrys >> hcell[il];
284 string CorFunparaPath;
286 CorFunparaPath = getenv("ABSCORROOT");
288 // Read energy correction Function parameters from PhotonCor/McCor
290 if (IYear==2009) CorFunparaPath += "/share/evsetTofCorFunctionPar2009Jpsi.txt";
291 if (IYear==2012) CorFunparaPath += "/share/evsetTofCorFunctionPar2012Jpsi.txt";
292 if (IYear==2018) CorFunparaPath += "/share/evsetTofCorFunctionPar2018Jpsi.txt";
293 if (IYear==2019) CorFunparaPath += "/share/evsetTofCorFunctionPar2019Jpsi.txt";
297 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
301 in2corfun.open(CorFunparaPath.c_str());
304 for(int i=0;i<28;i++){
305 in2corfun>>m_corFunPar[i][0];
306 in2corfun>>m_corFunPar[i][1];
307 in2corfun>>m_corFunPar[i][2];
308 in2corfun>>m_corFunPar[i][3];
309 in2corfun>>m_corFunPar[i][4];
310 in2corfun>>m_corFunPar[i][5];
318 ISvcLocator* svcLocator = Gaudi::svcLocator();
319 StatusCode sc = svcLocator->service(
"EmcShEnCalibSvc", m_EmcShEnCalibSvc );
321 if ( sc != StatusCode::SUCCESS )
322 { std::cout <<
"can not use EmcShEnCalibSvc in AbsCor" << endl; }
326 <<
"getPi0CalibFile() and getSingleGammaCalibFile() still are empty in initialize()"
328 std::cout <<
"will be assigned a value in execute()" << std::endl;
329 std::cout <<
"Test EmcShEnCalibSvc in AbsCor initialize getPi0CalibFile()= "
330 << m_EmcShEnCalibSvc->getPi0CalibFile()
331 <<
"Test EmcShEnCalibSvc in AbsCor getSingleGammaCalibFile()= "
332 << m_EmcShEnCalibSvc->getSingleGammaCalibFile() << std::endl;
335 log << MSG::INFO <<
"successfully return from initialize()" << endmsg;
336 return StatusCode::SUCCESS;
341 MsgStream log(
msgSvc(), name() );
342 log << MSG::INFO <<
"in execute()" << endmsg;
344 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(),
"/Event/EventHeader" );
345 int runNo = eventHeader->runNumber();
350 if ( runNum >= runFrom && runNum <= runTo ) { m_inFlag =
true; }
351 else { m_inFlag =
false; }
353 if ( m_inFlag ==
false )
356 runFrom = m_EmcShEnCalibSvc->getRunFrom();
357 runTo = m_EmcShEnCalibSvc->getRunTo();
362 cout <<
"current run=" <<
runNo << endl;
363 cout <<
"in AbsCor open getPi0CalibFile()= " << m_EmcShEnCalibSvc->getPi0CalibFile()
365 cout <<
"open getSingleGammaCalibFile()= " << m_EmcShEnCalibSvc->getSingleGammaCalibFile()
367 cout <<
"getRunFrom()=" << runFrom << endl;
368 cout <<
"getRunTo()=" << runTo << endl;
370 string CorFunparaPath;
373 if ( m_ifReadDB ) { CorFunparaPath = m_EmcShEnCalibSvc->getSingleGammaCalibFile(); }
376 CorFunparaPath = m_CorFunparaPath;
377 cout <<
"no read database, but using the set:" << CorFunparaPath << endl;
382 CorFunparaPath = getenv(
"ABSCORROOT" );
383 CorFunparaPath +=
"/share/evsetCorFunctionPar.txt";
387 in2corfun.open( CorFunparaPath.c_str() );
390 for (
int i = 0; i < 28; i++ )
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];
403 DataPathc3p = getenv(
"ABSCORROOT" );
404 DataPathc3p +=
"/share/c3p.txt";
406 string DataPathc3ptof;
407 if ( m_ifReadDB ) { DataPathc3ptof = m_EmcShEnCalibSvc->getPi0CalibFile(); }
410 DataPathc3ptof = m_DataPathc3ptof;
411 cout <<
"no read database, but using the set:" << DataPathc3ptof << endl;
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++ )
430 if ( evtRecEvent->totalTracks() > evtRecTrkCol->size() )
return StatusCode::SUCCESS;
431 if ( evtRecEvent->totalTracks() > 50 )
return StatusCode::SUCCESS;
434 ISvcLocator* svcLocator = Gaudi::svcLocator();
435 StatusCode sc = svcLocator->service(
"EmcRecGeoSvc", iGeoSvc );
436 if ( sc != StatusCode::SUCCESS ) { cout <<
"Error: Can't get EmcRecGeoSvc" << endl; }
438 for (
int i = 0; i < evtRecEvent->totalTracks(); i++ )
441 if ( !( *itTrk )->isEmcShowerValid() )
continue;
477 unsigned int module, ntheta, nphi;
478 module = EmcID::barrel_ec( id );
487 double e5x5 = emcTrk->
e5x5();
490 if ( usetof == 1 && ( *itTrk )->isTofTrackValid() )
492 SmartRefVector<RecTofTrack> recTofTrackVec = ( *itTrk )->tofTrack();
493 if ( !recTofTrackVec.empty() ) etof = recTofTrackVec[0]->energy();
494 if ( etof > 100. ) etof = 0;
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 );
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 ); }
513 if ( MCCorUseFunction == 1 ) { energyC = ECorrFunctionMC( e5x5, DthetaId ); }
514 else if ( MCCorUseFunction == 0 ) { energyC = ECorrMC( e5x5, DthetaId ); }
536 double lnE = std::log( energyC );
539 lnE = std::log( 1.0 );
540 if ( energyC < 0.05 )
541 lnE = std::log( 0.05 );
547 if (
runNo > 0 && dodatacor == 1 )
548 { lnEcor =
ai[0] +
ai[1] * lnE +
ai[2] * lnE * lnE +
ai[3] * lnE * lnE * lnE; }
550 if ( lnEcor < 0.5 )
continue;
554 HepPoint3D pos( emcTrk->
position() );
558 if ( hotcellmask == 1 )
560 for (
int ih = 0; ih < 10; ih++ )
562 if ( hrunstart[ih] == -1 || hrunend[ih] == -1 || hcell[ih] == -1 )
continue;
573 unsigned int theModule;
574 if ( thetaModule > 21 )
576 theModule = 43 - thetaModule;
578 pos.setZ( -pos.z() );
580 else { theModule = thetaModule; }
583 if ( theModule == 21 ) { IRShift = 0; }
584 else if ( theModule == 20 ) { IRShift = 2.5; }
585 else { IRShift = 5.; }
587 HepPoint3D IR( 0, 0, IRShift );
588 HepPoint3D center01, center23;
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 );
601 xIn = length *
tan( theta01 - ( pos - IR ).theta() ) - d / 2;
602 if ( xIn < ( -d / 2 ) && theModule != 21 )
605 theModule = theModule + 1;
608 if ( theModule == 21 ) { IRShift = 0; }
609 else if ( theModule == 20 ) { IRShift = 2.5; }
610 else { IRShift = 5.; }
611 HepPoint3D IR1( 0, 0, IRShift );
617 theta01 = ( center01 - IR ).theta();
618 theta23 = ( center23 - IR ).theta();
619 length = ( center01 - IR ).mag();
620 d = length *
tan( theta01 - theta23 );
622 xIn = length *
tan( theta01 - ( pos - IR ).theta() ) - d / 2;
624 else if ( xIn > ( d / 2 ) && theModule != 0 )
627 theModule = theModule - 1;
629 if ( theModule == 21 ) { IRShift = 0; }
630 else if ( theModule == 20 ) { IRShift = 2.5; }
631 else { IRShift = 5.; }
633 HepPoint3D IR1( 0, 0, IRShift );
639 theta01 = ( center01 - IR ).theta();
640 theta23 = ( center23 - IR ).theta();
641 length = ( center01 - IR ).mag();
642 d = length *
tan( theta01 - theta23 );
644 xIn = length *
tan( theta01 - ( pos - IR ).theta() ) - d / 2;
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;
654 if ( nphi == 0 && yIn > 100 ) yIn = yIn - 360;
655 if ( nphi == 119 && yIn < -100 ) yIn = yIn + 360;
657 if ( yIn < -1.5 - 0.15 )
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;
668 if ( yIn > 1.5 - 0.15 )
671 if ( nphi != 119 ) phiModule = phiModule + 1;
672 if ( nphi == 119 ) phiModule = 0;
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;
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
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;
696 double energyCC = energyC / ( lnEcor * enecor );
703 m_e5 = emcTrk->
e5x5();
711 SmartDataPtr<RecEmcShowerCol> recEmcShowerCol( eventSvc(),
713 if ( !recEmcShowerCol ) {
return ( StatusCode::SUCCESS ); }
714 SmartDataPtr<DstEmcShowerCol> dstEmcShowerCol( eventSvc(),
716 if ( !dstEmcShowerCol ) {
return ( StatusCode::SUCCESS ); }
719 if ( recEmcShowerCol->size() != dstEmcShowerCol->size() )
return StatusCode::SUCCESS;
720 for (
int i = 0; i < recEmcShowerCol->size(); i++ )
722 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin() + i;
723 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin() + i;
726 ( *iter_dst )->setEnergy( ( *iter_rec )->energy() );
727 ( *iter_dst )->setStatus( ( *iter_rec )->status() );
732 return ( StatusCode::SUCCESS );