BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
AbsCor.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
7//#
9#include "EventModel/Event.h"
11
16
17
18#include "TMath.h"
19#include "GaudiKernel/INTupleSvc.h"
20#include "GaudiKernel/NTuple.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/IHistogramSvc.h"
23#include "CLHEP/Vector/ThreeVector.h"
24#include "CLHEP/Vector/LorentzVector.h"
25#include "CLHEP/Vector/TwoVector.h"
26using CLHEP::Hep3Vector;
27using CLHEP::Hep2Vector;
28using CLHEP::HepLorentzVector;
29#include "CLHEP/Geometry/Point3D.h"
30#ifndef ENABLE_BACKWARDS_COMPATIBILITY
32#endif
33
37#include "Identifier/TofID.h"
39
40#include "AbsCor/AbsCor.h"
42#include "TGraphErrors.h"
43#include "TGraph2D.h"
44#include "TGraph2DErrors.h"
45#include <vector>
46#include <string>
47#include <fstream>
48#include <strstream>
50
51/////////////////////////////////////////////////////////////////////////////
52//
53double cbeam[56];
54double ai[4];
55AbsCor::AbsCor(const std::string& name, ISvcLocator* pSvcLocator) :
56 Algorithm(name, pSvcLocator) {
57
58 //Declare the properties
59 ntOut = true;
60 declareProperty("NTupleOut",ntOut=false);
61 declareProperty("McCor", mccor=0);
62 declareProperty("EdgeCor", edgecor=0);
63 declareProperty("HotCellMask", hotcellmask=0);
64 declareProperty("UseTof", usetof=1);
65 declareProperty("DoDataCor", dodatacor = 1);
66 declareProperty("DoPi0Cor",dopi0Cor=1);
67 declareProperty("MCUseTof", MCuseTof=1);
68 declareProperty("MCCorUseFunction", MCCorUseFunction=1);
69 declareProperty("IYear",IYear=2009);
70 m_ReadFile=false;
71 runFrom0 = 0;
72 runTo0 = 0;
73}
74
75
76//TGraphErrors *dt = new TGraphErrors();
77// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
78StatusCode AbsCor::initialize(){
79 MsgStream log(msgSvc(), name());
80 log << MSG::INFO << "in initialize()" << endmsg;
81
82 StatusCode status;
83 if(ntOut == true){
84 NTuplePtr nt1(ntupleSvc(), "FILE1/ec");
85 if ( nt1 ) m_tuple1 = nt1;
86 else {
87 m_tuple1 = ntupleSvc()->book ("FILE1/ec", CLID_ColumnWiseTuple, "ks N-Tuple example");
88 if ( m_tuple1 ) {
89 status = m_tuple1->addItem ("ef", m_ef);
90 status = m_tuple1->addItem ("e5", m_e5);
91 status = m_tuple1->addItem ("ec", m_ec);
92 status = m_tuple1->addItem ("ct", m_ct);
93 status = m_tuple1->addItem ("cedge", m_cedge);
94 }
95 else {
96 log << MSG::ERROR << " Cannot book N-tuple:" << long(m_tuple1) << endmsg;
97 return StatusCode::FAILURE;
98 }
99 }
100 }
101
102 m_index = new int*[56];
103 for (int j=0;j<56;j++ ) {
104 m_index[j] = new int[120];
105 for ( int k=0; k<120; k++) {
106 m_index[j][k]=-1;
107 }
108 }
109
110 m_par = new double*[22];
111 for (int j=0;j<22;j++ ) {
112 m_par[j] = new double[11];
113 for ( int k=0; k<11; k++) {
114 m_par[j][k]=-99;
115 }
116 }
117
118 m_parphi = new double*[22];
119 for (int j=0;j<22;j++ ) {
120 m_parphi[j] = new double[5];
121 for ( int k=0; k<5; k++) {
122 m_parphi[j][k]=-99;
123 }
124 }
125
126 ifstream EnParIn;
127 //EnParIn.exceptions( ifstream::failbit | ifstream::badbit );
128 string EnParInFile;
129 EnParInFile = getenv("ABSCORROOT");
130 EnParInFile += "/share/para.dat";
131 EnParIn.open(EnParInFile.c_str());
132 for(int i=0;i<22;i++) {
133
134 EnParIn>>m_par[i][0]>>m_par[i][1]>>m_par[i][2]>>m_par[i][3]>>m_par[i][4]
135 >>m_par[i][5]>>m_par[i][6]>>m_par[i][7]>>m_par[i][8]>>m_par[i][9]
136 >>m_par[i][10];
137 }
138 EnParIn.close();
139
140 ifstream EnParInphi;
141 //EnParInphi.exceptions( ifstream::failbit | ifstream::badbit );
142 string EnParInFilephi = getenv("ABSCORROOT");
143 EnParInFilephi += "/share/paraphi.dat";
144 EnParInphi.open(EnParInFilephi.c_str());
145 for(int i=0;i<22;i++) {
146 EnParInphi>>m_parphi[i][0]>>m_parphi[i][1]>>m_parphi[i][2]>>m_parphi[i][3]>>m_parphi[i][4];
147
148 }
149 EnParInphi.close();
150
151
152 /* liucx
153 string DataPathevse;
154 DataPathevse = getenv("ABSCORROOT");
155 DataPathevse += "/share/barmccorevse10bin.txt";
156 ifstream inpi0;
157 inpi0.exceptions( ifstream::failbit | ifstream::badbit );
158 inpi0.open(DataPathevse.c_str(),ios::in);
159
160 double epoint[11],peak[11],peakerr[11];
161 for(Int_t i=0;i<11;i++){
162 inpi0>>epoint[i];
163 inpi0>>peak[i];
164 inpi0>>peakerr[i];
165 }
166 for(Int_t i=0;i<11;i++){
167 dt->SetPoint(i, epoint[i],peak[i]);
168 dt->SetPointError(i,0,peakerr[i]);
169 }
170 */
171
172 string DataPathcbeam;
173 DataPathcbeam = getenv("ABSCORROOT");
174 DataPathcbeam += "/share/cbeam.txt";
175 ifstream incbeam;
176 incbeam.exceptions( ifstream::failbit | ifstream::badbit );
177 incbeam.open(DataPathcbeam.c_str(),ios::in);
178 for(int i=0; i<56; i++){
179 double tid,peak,peake,sig,sige;
180 incbeam>>tid;
181 incbeam>>peak;
182 incbeam>>peake;
183 incbeam>>sig;
184 incbeam>>sige;
185 cbeam[i]=1.0/peak;
186 }
187 /* by liucx
188 /////////////////////////////
189 string DataPathc3p;
190 DataPathc3p = getenv("ABSCORROOT");
191 DataPathc3p += "/share/c3p.txt";
192
193 string DataPathc3ptof;
194 DataPathc3ptof = getenv("ABSCORROOT");
195 DataPathc3ptof += "/share/c3ptof.txt";
196 cout<<"mccor = "<<mccor<<endl;
197 //DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
198
199
200 ifstream inc3p;
201 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
202 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
203 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
204 for(int i=0; i<4; i++){
205 double am,ame;
206 inc3p>>am;
207 inc3p>>ame;
208 ai[i]=am;
209 }
210 */
211 string paraPath = getenv("ABSCORROOT");
212 if(paraPath==""){} //cout<<"AbsCor environment not set!";
213
214 // Read energy correction parameters from PhotonCor/McCor
215 if(MCuseTof==1){
216 paraPath += "/share/evsetTof.txt";
217 }
218 if(MCuseTof==0){
219 paraPath += "/share/evset.txt";
220 }
221
222 ifstream in2;
223 in2.open(paraPath.c_str());
224 assert(in2);
225 double energy,thetaid,peak1,peakerr1,res,reserr;
226 dt = new TGraph2DErrors();
227 dtErr = new TGraph2DErrors();
228 //for(int i=0;i<560;i++){
229 for(int i=0;i<1484;i++){ //53*28
230 in2>>energy;
231 in2>>thetaid;
232 in2>>peak1;
233 in2>>peakerr1;
234 in2>>res;
235 in2>>reserr;
236 dt->SetPoint(i,energy,thetaid,peak1);
237 dt->SetPointError(i,0,0,peakerr1);
238 dtErr->SetPoint(i,energy,thetaid,res);
239 dtErr->SetPointError(i,0,0,reserr);
240 if(i<28) e25min[int(thetaid)]=energy;
241 if(i>=1484-28) e25max[int(thetaid)]=energy;
242 // if(i>=560-28) e25max[int(thetaid)]=energy;
243 }
244 in2.close();
245
246 //-------------------------
247 // Suppression of hot crystals
248 // Reading the map from hotcry.txt (Hajime, Jul 2013)
249 for(int ih=0;ih<10;ih++){
250 hrunstart[ih]=-1;
251 hrunend[ih]=-1;
252 hcell[ih]=-1;
253 }
254 int numhots=4; // numbers of hot crystals
255 int dumring,dumphi,dummod,dumid;
256 string HotList;
257 HotList = getenv("ABSCORROOT");
258 HotList += "/share/hotcry.txt";
259 ifstream hotcrys;
260 hotcrys.exceptions( ifstream::failbit | ifstream::badbit );
261 hotcrys.open(HotList.c_str(),ios::in);
262 for(int il=0; il<numhots; il++){
263 hotcrys>>hrunstart[il];
264 hotcrys>>hrunend[il];
265 hotcrys>>hcell[il];
266 hotcrys>>dumring;
267 hotcrys>>dumphi;
268 hotcrys>>dummod;
269 hotcrys>>dumid;
270 }
271 hotcrys.close();
272 //-------------------------
273 /* by liucx
274 ////////////////////to read the parameters of energy correction function//////////
275 string CorFunparaPath;
276
277 CorFunparaPath = getenv("ABSCORROOT");
278
279 // Read energy correction Function parameters from PhotonCor/McCor
280 if(MCuseTof==1){
281 if (IYear==2009) CorFunparaPath += "/share/evsetTofCorFunctionPar2009Jpsi.txt";
282 if (IYear==2012) CorFunparaPath += "/share/evsetTofCorFunctionPar2012Jpsi.txt";
283 if (IYear==2018) CorFunparaPath += "/share/evsetTofCorFunctionPar2018Jpsi.txt";
284 if (IYear==2019) CorFunparaPath += "/share/evsetTofCorFunctionPar2019Jpsi.txt";
285
286 }
287 if(MCuseTof==0){
288 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
289 }
290
291 ifstream in2corfun;
292 in2corfun.open(CorFunparaPath.c_str());
293 assert(in2corfun);
294
295 for(int i=0;i<28;i++){
296 in2corfun>>m_corFunPar[i][0];
297 in2corfun>>m_corFunPar[i][1];
298 in2corfun>>m_corFunPar[i][2];
299 in2corfun>>m_corFunPar[i][3];
300 in2corfun>>m_corFunPar[i][4];
301 in2corfun>>m_corFunPar[i][5];
302 }
303 in2corfun.close();
304 ///////////////////////
305
306*/
307
308 //////// read the shower correction parameters from database////// by liucx
309 ISvcLocator* svcLocator = Gaudi::svcLocator();
310 StatusCode sc = svcLocator->service("EmcShEnCalibSvc", m_EmcShEnCalibSvc);
311
312 if( sc != StatusCode::SUCCESS){
313 std::cout << "can not use EmcShEnCalibSvc in AbsCor" << endl;
314 }
315 else {
316 std::cout<<"getPi0CalibFile() and getSingleGammaCalibFile() still are empty in initialize()"<< std::endl;
317 std::cout<<"will be assigned a value in execute()"<< std::endl;
318 std::cout << "Test EmcShEnCalibSvc in AbsCor initialize getPi0CalibFile()= "
319 << m_EmcShEnCalibSvc -> getPi0CalibFile()
320 << "Test EmcShEnCalibSvc in AbsCor getSingleGammaCalibFile()= "
321 << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()
322 << std::endl;
323 }
324
325
326
327 log << MSG::INFO << "successfully return from initialize()" <<endmsg;
328 return StatusCode::SUCCESS;
329
330}
331
332// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
333StatusCode AbsCor::execute() {
334 MsgStream log(msgSvc(), name());
335 log << MSG::INFO << "in execute()" << endreq;
336
337 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
338 int runNo=eventHeader->runNumber();
339
340 //// by liucx
341 int runNum = runNo;
342 if (runNo<0) runNum=-runNo; // for MC
343 unsigned int runFrom=m_EmcShEnCalibSvc -> getRunFrom();
344 unsigned int runTo=m_EmcShEnCalibSvc -> getRunTo();
345 if (!m_ReadFile) {
346 runFrom0 = runFrom;
347 runTo0 = runTo;
348 }
349
350 if (runNum>=runFrom0&&runNum<=runTo0&&m_ReadFile==true){
351
352 //for test
353 //cout<<"do not open the CorFunctionPar File repeatly"<<endl;
354 //cout<<"runNo,RunFrom,runTo="<<runNo<<","<<runFrom<<","<<runTo<<endl;
355 } else {
356 if (runFrom0!=runFrom) runFrom0 = runFrom;
357 if (runTo0!=runTo) runTo0 = runTo;
358 ////to read the parameters of energy correction parameters of single gamma and pi0 calibration//////////
359 // Read energy correction Function parameters
360 cout << "current run=" << runNo<<endl;
361 cout << "in AbsCor open getPi0CalibFile()= " << m_EmcShEnCalibSvc -> getPi0CalibFile()<<endl;
362 cout << "open getSingleGammaCalibFile()= " << m_EmcShEnCalibSvc -> getSingleGammaCalibFile()<<endl;
363 cout <<"getRunFrom()="<< runFrom<<endl;
364 cout <<"getRunTo()="<< runTo<<endl;
365
366
367 string CorFunparaPath;
368 if(MCuseTof==1){
369 CorFunparaPath = m_EmcShEnCalibSvc -> getSingleGammaCalibFile();
370 }
371 if(MCuseTof==0){
372 CorFunparaPath = getenv("ABSCORROOT");
373 CorFunparaPath += "/share/evsetCorFunctionPar.txt";
374 }
375
376 ifstream in2corfun;
377 in2corfun.open(CorFunparaPath.c_str());
378 assert(in2corfun);
379
380 for(int i=0;i<28;i++){
381 in2corfun>>m_corFunPar[i][0];
382 in2corfun>>m_corFunPar[i][1];
383 in2corfun>>m_corFunPar[i][2];
384 in2corfun>>m_corFunPar[i][3];
385 in2corfun>>m_corFunPar[i][4];
386 in2corfun>>m_corFunPar[i][5];
387 }
388 in2corfun.close();
389
390 ////////read the parameter of pi0 calibration for data
391 string DataPathc3p;
392 DataPathc3p = getenv("ABSCORROOT");
393 DataPathc3p += "/share/c3p.txt";
394
395 string DataPathc3ptof;
396 DataPathc3ptof = m_EmcShEnCalibSvc -> getPi0CalibFile();
397
398 ifstream inc3p;
399 inc3p.exceptions( ifstream::failbit | ifstream::badbit );
400 if(usetof==0)inc3p.open(DataPathc3p.c_str(),ios::in);
401 if(usetof==1)inc3p.open(DataPathc3ptof.c_str(),ios::in);
402 for(int i=0; i<4; i++){
403 double am,ame;
404 inc3p>>am;
405 inc3p>>ame;
406 ai[i]=am;
407 }
408
409 ///////////////////////
410 m_ReadFile=true;
411 cout<<"-----------read parameter file-------"<<endl;
412 }
413 ////////////////////////end of reading the correction parameters from Svc and file
414
415 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
416 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
417 if(evtRecEvent->totalTracks()>evtRecTrkCol->size())return SUCCESS;
418 if(evtRecEvent->totalTracks()>50)return SUCCESS;
419
420 IEmcRecGeoSvc* iGeoSvc;
421 ISvcLocator* svcLocator = Gaudi::svcLocator();
422 StatusCode sc = svcLocator->service("EmcRecGeoSvc",iGeoSvc);
423 if(sc!=StatusCode::SUCCESS) {
424 cout<<"Error: Can't get EmcRecGeoSvc"<<endl;
425 }
426
427 for(int i = 0; i< evtRecEvent->totalTracks(); i++) {
428 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
429 if(!(*itTrk)->isEmcShowerValid())continue;
430 RecEmcShower *emcTrk = (*itTrk)->emcShower();
431// if(emcTrk->energy()<0.0005)continue;
432
433 /* by liucx
434 //the correction is based on e5x5 energy from the version AbsCor-00-00-29.
435 //It's impossible to correct twice.
436 //So the code is commented out.
437
438 int st = emcTrk->status();
439 if(st>10000)continue;
440 emcTrk->setStatus(st+20000);
441 */
442
443
444
445// cout<<"REC after calib EMC status = "<<emcTrk->status()<<endl;
446
447 //if(emcTrk->e5x5()<0.015)continue;
448
449// if(emcTrk->getTime()<10||emcTrk->getTime()>30)continue;
450/*
451 if(emcTrk->e5x5()<0.02){
452 emcTrk->setEnergy(emcTrk->e5x5()*1.1);
453 continue;
454 }
455*/
456/*
457 int intid = emcTrk->cellId();
458 Identifier id=Identifier(intid);
459 int getthetaid = EmcID::theta_module(id);
460 int getmodule = EmcID::barrel_ec(id);
461 if(getmodule==1)getthetaid=getthetaid+6;
462 if(getmodule==2)getthetaid=55-getthetaid;
463*/
464
465 RecEmcID id = Identifier(emcTrk->cellId());
466
467 unsigned int module, ntheta, nphi;
468 module = EmcID::barrel_ec(id);
469 ntheta = EmcID::theta_module(id);
470 nphi = EmcID::phi_module(id);
471
472 // id=EmcID::crystal_id(module,ntheta,nphi);
473
474 unsigned int thetaModule = EmcID::theta_module(id);
475 unsigned int phiModule = EmcID::phi_module(id);
476
477
478 double e5x5=emcTrk->e5x5();
479 double etof=0;
480
481 if(usetof==1 && (*itTrk)->isTofTrackValid()){
482 SmartRefVector<RecTofTrack> recTofTrackVec=(*itTrk)->tofTrack();
483 if(!recTofTrackVec.empty())etof=recTofTrackVec[0]->energy();
484 if(etof>100.)etof=0;
485 }
486
487 double energyC;
488
489 int thetaId;
490 if (module==0||module==2) thetaId = thetaModule;
491 if (module==1 && thetaModule<=21) thetaId = thetaModule + 6;
492 if (module==1 && thetaModule>21) thetaId = 43 - thetaModule + 6;
493 double DthetaId=double(thetaId);
494
495 if(MCuseTof==1){
496 if (thetaId<6) etof=0.0; //in EMC endcap
497 if (MCCorUseFunction==1){
498 energyC=ECorrFunctionMC(e5x5+etof,DthetaId);
499 } else if (MCCorUseFunction==0){
500 energyC=ECorrMC(e5x5+etof,DthetaId);
501 }
502 }
503 if (MCuseTof==0) {
504 if (MCCorUseFunction==1){
505 energyC=ECorrFunctionMC(e5x5,DthetaId);
506 } else if (MCCorUseFunction==0){
507 energyC=ECorrMC(e5x5,DthetaId);
508 }
509 }
510
511
512 /*
513 if(usetof==1){
514 energyC=ECorrMC(e5x5+etof,thetaId);
515 }
516 if (usetof==0) {
517 energyC=emcTrk->energy();
518 }
519 */
520 // double energyC=emcTrk->energy()+etof;
521/*
522 if(energyC<=0||energyC>4.99)continue;
523 double cor = 1.0;
524 if(runNo>0)cor = dt->Eval(energyC);
525 if(cor<0.001)continue;
526// cout<<cor<<endl;
527 double energyCC= energyC/cor;
528 emcTrk->setEnergy(energyCC);
529*/
530
531 double lnE = std::log(energyC);
532
533 if (energyC>1.0) lnE=std::log(1.0); //gamma energy bin from 0.05 to 0.9GeV for pi0 calibration
534 if (energyC<0.05) lnE=std::log(0.05); //set the range(0.05-1.0GeV) of application for pi0 calibration function
535
536 double lnEcor=1.0;
537 if(dopi0Cor==1){
538 if(runNo>0 && dodatacor==1) {
539 lnEcor = ai[0]+ai[1]*lnE+ai[2]*lnE*lnE+ai[3]*lnE*lnE*lnE;
540 }
541 }
542 if(lnEcor<0.5)continue;
543// cout<<lnEcor<<" "<<etof<<endl;
544
545
546//////////////////////////////////////now no using in the following
547 HepPoint3D pos(emcTrk->position());
548
549 // If it is "hot", return "9999" (Hajime, Jul 2013)
550 double enecor=1.;
551 if(hotcellmask==1){
552 for(int ih=0;ih<10;ih++){
553 if(hrunstart[ih]==-1||hrunend[ih]==-1||hcell[ih]==-1)continue;
554 if(abs(runNo)<hrunstart[ih]||abs(runNo)>hrunend[ih])continue;
555 if ( emcTrk->cellId()==hcell[ih] ) {emcTrk->setStatus(9999);}
556 }
557 }
558
559 if(edgecor==1){
560
561 if(module==1) { //barrel
562 unsigned int theModule;
563 if(thetaModule>21) {
564 theModule = 43 - thetaModule;
565 id = EmcID::crystal_id(module,theModule,phiModule);
566 pos.setZ(-pos.z());
567 } else {
568 theModule = thetaModule;
569 }
570
571 double IRShift;
572 if(theModule==21) {
573 IRShift = 0;
574
575 } else if(theModule==20) {
576 IRShift = 2.5;
577
578 } else {
579 IRShift = 5.;
580
581 }
582
583
584 HepPoint3D IR(0,0,IRShift);
585 HepPoint3D center01, center23; //center of point0,1 and point2,3 in crystal
586 center01 = (iGeoSvc->GetCrystalPoint(id,0)+iGeoSvc->GetCrystalPoint(id,1))/2;
587 center23 = (iGeoSvc->GetCrystalPoint(id,2)+iGeoSvc->GetCrystalPoint(id,3))/2;
588
589 double theta01,theta23,length,d;
590 theta01 = (center01-IR).theta();
591 theta23 = (center23-IR).theta();
592 length = (center01-IR).mag();
593 d = length*tan(theta01-theta23); //length in x direction
594
595 double xIn;
596 xIn = length*tan(theta01-(pos-IR).theta())-d/2;
597 if (xIn < (-d/2) && theModule!=21){
598
599 theModule=theModule+1 ;
600
601 id = EmcID::crystal_id(module,theModule,phiModule);
602 if(theModule==21) {
603 IRShift = 0;
604
605 } else if(theModule==20) {
606 IRShift = 2.5;
607
608 } else {
609 IRShift = 5.;
610
611 }
612 HepPoint3D IR1(0,0,IRShift);
613 IR=IR1;
614 center01 = (iGeoSvc->GetCrystalPoint(id,0)+iGeoSvc->GetCrystalPoint(id,1))/2;
615 center23 = (iGeoSvc->GetCrystalPoint(id,2)+iGeoSvc->GetCrystalPoint(id,3))/2;
616 theta01 = (center01-IR).theta();
617 theta23 = (center23-IR).theta();
618 length = (center01-IR).mag();
619 d = length*tan(theta01-theta23); //length in x direction
620
621 xIn = length*tan(theta01-(pos-IR).theta())-d/2;
622
623 } else if (xIn > (d/2) && theModule!=0 ){
624
625 theModule=theModule-1 ;
626 id = EmcID::crystal_id(module,theModule,phiModule);
627 if(theModule==21) {
628 IRShift = 0;
629
630 } else if(theModule==20) {
631 IRShift = 2.5;
632
633 } else {
634 IRShift = 5.;
635
636 }
637
638 HepPoint3D IR1(0,0,IRShift);
639 IR=IR1;
640 center01 = (iGeoSvc->GetCrystalPoint(id,0)+iGeoSvc->GetCrystalPoint(id,1))/2;
641 center23 = (iGeoSvc->GetCrystalPoint(id,2)+iGeoSvc->GetCrystalPoint(id,3))/2;
642 theta01 = (center01-IR).theta();
643 theta23 = (center23-IR).theta();
644 length = (center01-IR).mag();
645 d = length*tan(theta01-theta23); //length in x direction
646
647 xIn = length*tan(theta01-(pos-IR).theta())-d/2;
648 }
649
650 double yIn;
651 // yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.1537
652 // : pos.phi()*180./CLHEP::pi-phiModule*3.-1.1537;
653
654 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
655 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
656
657 if(nphi==0&&yIn>100) yIn=yIn-360;
658 if(nphi==119&&yIn<-100) yIn=yIn+360;
659
660 if(yIn<-1.5-0.15){
661
662 if(nphi!=0) phiModule=phiModule-1;
663 if(nphi==0) phiModule=119;
664 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
665 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
666 if(phiModule==0&&yIn>100) yIn=yIn-360;
667 if(phiModule==119&&yIn<-100) yIn=yIn+360;
668
669 }
670
671 if(yIn>1.5-0.15){
672
673
674 if(nphi!=119) phiModule=phiModule+1;
675 if(nphi==119) phiModule=0;
676
677 yIn = pos.phi() < 0 ? pos.phi()*180./CLHEP::pi+360.-phiModule*3.-1.843
678 : pos.phi()*180./CLHEP::pi-phiModule*3.-1.843;
679 if(phiModule==0&&yIn>100) yIn=yIn-360;
680 if(phiModule==119&&yIn<-100) yIn=yIn+360;
681 }
682
683 enecor=m_par[theModule][0]
684 +m_par[theModule][1]*xIn
685 +m_par[theModule][2]*xIn*xIn
686 +m_par[theModule][3]*xIn*xIn*xIn
687 +m_par[theModule][4]*xIn*xIn*xIn*xIn
688 +m_par[theModule][5]*xIn*xIn*xIn*xIn*xIn
689 +m_par[theModule][6]*xIn*xIn*xIn*xIn*xIn*xIn
690 // +m_par[theModule][7]*xIn*xIn*xIn*xIn*xIn*xIn*xIn
691 // +m_par[theModule][8]*xIn*xIn*xIn*xIn*xIn*xIn*xIn*xIn
692 +m_par[theModule][7]*yIn
693 +m_par[theModule][8]*yIn*yIn
694 +m_par[theModule][9]*yIn*yIn*yIn
695 +m_par[theModule][10]*yIn*yIn*yIn*yIn;
696 //////////////////////
697 } else{
698 enecor=1;
699 }
700 }
701//////////////////////////////////////now no using in the above
702
703 double energyCC= energyC/(lnEcor*enecor);
704 // cout<<"Trk Level Corr. and Orig. "<<energyCC<<" "<<emcTrk->energy()<<endl;
705 emcTrk->setEnergy(energyCC);
706
707 if(ntOut==true){
708 m_ef=energyCC;
709 m_e5=emcTrk->e5x5();
710 m_ec=energyC;
711 m_ct=lnEcor ;
712 m_cedge=enecor;
713 m_tuple1->write();
714 }
715
716
717 }
718//==============Modify Dst===============================================================
719 SmartDataPtr<RecEmcShowerCol> recEmcShowerCol(eventSvc(), EventModel::Recon::RecEmcShowerCol);
720 if(!recEmcShowerCol){
721 return( StatusCode::SUCCESS);
722 }
723 SmartDataPtr<DstEmcShowerCol> dstEmcShowerCol(eventSvc(), EventModel::Dst::DstEmcShowerCol);
724 if(!dstEmcShowerCol){
725 return( StatusCode::SUCCESS);
726 }
727
728// cout<<"Rec and Dst Size "<<recEmcShowerCol->size()<<" "<<dstEmcShowerCol->size()<<endl;
729 if(recEmcShowerCol->size()!=dstEmcShowerCol->size())return SUCCESS;
730 for(int i=0;i<recEmcShowerCol->size();i++){
731 RecEmcShowerCol::iterator iter_rec = recEmcShowerCol->begin()+i;
732 DstEmcShowerCol::iterator iter_dst = dstEmcShowerCol->begin()+i;
733// cout<<"Rec and Dst energy "<<(*iter_rec)->energy()<<" "<<(*iter_dst)->energy()<<endl;
734 (*iter_dst)->setEnergy((*iter_rec)->energy());
735 (*iter_dst)->setStatus((*iter_rec)->status());
736// cout<<"DST after calib EMC status = "<<(*iter_dst)->status()<<endl;
737// cout<<"Rec == Dst? "<<(*iter_rec)->energy()<<" "<<(*iter_dst)->energy()<<endl;
738 }
739 return( StatusCode::SUCCESS);
740}
741
742// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
743StatusCode AbsCor::finalize() {
744
745 MsgStream log(msgSvc(), name());
746 log << MSG::INFO << "in finalize()" << endmsg;
747 return StatusCode::SUCCESS;
748}
749
750
751
752double AbsCor::E25min(int n) const
753{
754 return e25min[n];
755}
756double AbsCor::E25max(int n) const
757{
758 return e25max[n];
759}
760
761
762//The following function is copied from PhotonCor/McCor
763double AbsCor::ECorrMC(double eg, double theid) const
764{
765 double Energy5x5=eg;
766 if(eg<E25min(int(theid))) eg=E25min(int(theid));
767 if(eg>E25max(int(theid))) eg=E25max(int(theid))-0.001;
768
769 if(theid<=0)theid=0.001;
770 if(theid>=27)theid=26.999;
771 Float_t einter = eg + 0.00001;
772 Float_t tinter = theid+0.0001;
773 //cout<<"inter="<< einter<<" "<<tinter<<endl;
774 double ecor=dt->Interpolate(einter,tinter);
775 // cout<<"ecor="<<ecor<<endl;
776 if(!(ecor))return Energy5x5;
777 if(ecor<0.5)return Energy5x5;
778 double EnergyCor=Energy5x5/ecor;
779 return EnergyCor;
780}
781
782// Get energy error
783double AbsCor::ErrMC(double eg, double theid) const
784{
785
786 if(eg<E25min(int(theid))) eg=E25min(int(theid));
787 if(eg>E25max(int(theid))) eg=E25max(int(theid))-0.001;
788 if(theid<=0)theid=0.001;
789 if(theid>=27)theid=26.999;
790 Float_t einter = eg + 0.00001;
791 Float_t tinter = theid+0.0001;
792 double err=dtErr->Interpolate(einter,tinter);
793 return err;
794}
795
796
797
798double AbsCor::ECorrFunctionMC(double eg, double theid) const
799{
800 if(theid<0||theid>27){
801 cout<<"in AbsCor EcorrFunctionMC error::thetaId is out of the region [0,27]"<<endl;
802 }
803 double Energy5x5=eg;
804 double x=Energy5x5;
805 //if(Energy5x5>E25max(int(theid))) x=E25max(int(theid));
806
807 int ith=int(theid);
808 double ecor;
809 ecor = m_corFunPar[ith][0]/(m_corFunPar[ith][1]+exp(-x))
810 + m_corFunPar[ith][2]
811 + m_corFunPar[ith][3]*x
812 + m_corFunPar[ith][4]*x*x
813 + m_corFunPar[ith][5]*x*x*x;
814
815 double EnergyCor=Energy5x5/ecor;
816
817 return EnergyCor;
818
819}
820
HepGeom::Point3D< double > HepPoint3D
Definition: AbsCor.cxx:31
double ai[4]
Definition: AbsCor.cxx:54
double cbeam[56]
Definition: AbsCor.cxx:53
double tan(const BesAngle a)
Definition: BesAngle.h:216
int runNo
Definition: DQA_TO_DB.cxx:12
const Int_t n
Double_t x[10]
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
EvtRecTrackCol::iterator EvtRecTrackIterator
Definition: EvtRecTrack.h:111
************Class m_ypar INTEGER m_KeyWgt INTEGER m_KeyIHVP INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input READ never touch them !$ !debug facility $ !maximum weight $ !inverse alfaQED $ !minimum real photon energy
Definition: KK2f.h:50
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
StatusCode execute()
Definition: AbsCor.cxx:333
AbsCor(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AbsCor.cxx:55
StatusCode finalize()
Definition: AbsCor.cxx:743
StatusCode initialize()
Definition: AbsCor.cxx:78
int cellId() const
Definition: DstEmcShower.h:32
HepPoint3D position() const
Definition: DstEmcShower.h:34
double e5x5() const
Definition: DstEmcShower.h:49
void setStatus(int st)
Definition: DstEmcShower.h:59
void setEnergy(double e)
Definition: DstEmcShower.h:63
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition: EmcID.cxx:71
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
virtual HepPoint3D GetCrystalPoint(const Identifier &id, const int i) const =0
_EXTERN_ std::string DstEmcShowerCol
Definition: EventModel.h:134
_EXTERN_ std::string EvtRecEvent
Definition: EventModel.h:116
_EXTERN_ std::string EvtRecTrackCol
Definition: EventModel.h:117
_EXTERN_ std::string RecEmcShowerCol
Definition: EventModel.h:103