3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/AlgFactory.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/IDataManagerSvc.h"
9#include "GaudiKernel/PropertyMgr.h"
26 declareProperty(
"MsgFlag",myMsgFlag=
false);
27 declareProperty(
"ActiveCutFlag",myActiveCutFlag=
true);
28 declareProperty(
"EmcThetaMatchCut",myEmcThetaCut=-1);
29 declareProperty(
"EmcPhiMatchCut",myEmcPhiCut=-1);
30 declareProperty(
"EmcThetaNSigmaCut",myEmcThetaNSigmaCut=5);
31 declareProperty(
"EmcPhiNSigmaCut",myEmcPhiNSigmaCut=5);
32 declareProperty(
"ParticleId",myParticleId);
33 declareProperty(
"Output", m_Output = 0);
39 MsgStream log(
msgSvc(), name());
40 log << MSG::INFO <<
"in initialize()" << endreq;
42 if(myEmcThetaCut<0) myEmcThetaCut = 0.1745;
43 if(myEmcPhiCut<0) myEmcPhiCut = 0.2618;
45 log << MSG::INFO <<
"EmcThetaCut,EmcPhiCut: "<<myEmcThetaCut<<
", "<<myEmcPhiCut<<endreq;
46 log << MSG::INFO <<
"emcThetaNSigmaCut, emcPhiNSigmaCut: "<<myEmcThetaNSigmaCut<<
", "<<myEmcPhiNSigmaCut<<endreq;
49 NTuplePtr nt1(
ntupleSvc(),
"FILE998/match");
50 if ( nt1 ) myNTuple1 = nt1;
52 myNTuple1 =
ntupleSvc()->book(
"FILE998/match", CLID_ColumnWiseTuple,
"match");
54 myNTuple1->addItem(
"exted",myExted);
55 myNTuple1->addItem(
"matched",myMatched);
56 myNTuple1->addItem(
"Ematched",myEnergyMatched);
59 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(myNTuple1) << endmsg;
64 return StatusCode::SUCCESS;
70 MsgStream log(
msgSvc(), name());
71 log << MSG::INFO <<
"in execute()" << endreq;
73 int numOfChargedTrks = 0;
79 int numOfMatchedShower = 0;
83 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
86 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
87 return( StatusCode::FAILURE);
89 log << MSG::INFO <<
": retrieved event: " << eventHeader->eventNumber() <<
" run: " << eventHeader->runNumber() << endreq;
93 RecMdcTrackCol::iterator beginOfMdcTrkCol = RecMdcTrackCol::iterator(
NULL);
96 log<<MSG::INFO<<
"Could not find RecMdcTrackCol!"<<endreq;
100 beginOfMdcTrkCol = recMdcTrackCol->begin();
101 numOfChargedTrks = recMdcTrackCol->size();
105 RecMdcKalTrackCol::iterator beginOfMdcKalTrackCol = RecMdcKalTrackCol::iterator(
NULL);
108 log<<MSG::INFO<<
"Could not find MdcKalTrackCol!"<<endreq;
112 numOfKalTrks = mdcKalTrackCol->size();
113 beginOfMdcKalTrackCol = mdcKalTrackCol->begin();
118 RecMdcDedxCol::iterator beginOfDedxCol = RecMdcDedxCol::iterator(
NULL);
121 log<<MSG::INFO<<
"Could not find MdcDedxCol!"<<endreq;
124 numOfDedx = mdcDedxCol->size();
125 beginOfDedxCol = mdcDedxCol->begin();
130 RecExtTrackCol::iterator beginOfExtTrackCol = RecExtTrackCol::iterator(
NULL);
133 log<<MSG::INFO<<
"Could not find RecExtTrackCol!"<<endreq;
137 beginOfExtTrackCol = extTrackCol->begin();
138 numOfExt = extTrackCol->size();
142 RecTofTrackCol::iterator beginOfTofTrackCol = RecTofTrackCol::iterator(
NULL);
145 log<<MSG::INFO<<
"Could not find RecTofTrackCol!"<<endreq;
149 beginOfTofTrackCol = TofTrackCol->begin();
150 numOfTof = TofTrackCol->size();
154 RecEmcShowerCol::iterator beginOfEmcTrackCol = RecEmcShowerCol::iterator(
NULL);
157 log<<MSG::INFO<<
"Could not find RecEmcShowerCol!"<<endreq;
161 beginOfEmcTrackCol = emcRecShowerCol->begin();
162 numOfShower = emcRecShowerCol->size();
166 RecMucTrackCol::iterator beginOfMucTrackCol = RecMucTrackCol::iterator(
NULL);
169 log<<MSG::INFO<<
"Could not find RecMucTrackCol!"<<endreq;
173 beginOfMucTrackCol = mucTrackCol->begin();
174 numOfMucTrks = mucTrackCol->size();
179 int MaxHit = numOfChargedTrks+numOfShower+numOfTof;
181 vector<bool> dEdxMatched;
182 vector<bool> kalTrkMatched;
183 vector<bool> extMatched;
184 vector<bool> TofMatched;
185 vector<bool> emcMatched;
186 vector<bool> mucMatched;
188 for(
int i=0;i<MaxHit;i++)
190 dEdxMatched.push_back(
false);
191 kalTrkMatched.push_back(
false);
192 extMatched.push_back(
false);
193 TofMatched.push_back(
false);
194 emcMatched.push_back(
false);
195 mucMatched.push_back(
false);
202 if(numOfChargedTrks+numOfShower)
204 for(
int i=0;i<numOfChargedTrks;i++)
207 int mdcTrkID = (*(beginOfMdcTrkCol+i))->
trackId();
209 aNewEvtRecTrack->
setMdcTrack(*(beginOfMdcTrkCol+i));
211 for(
int j=0;j<numOfKalTrks;j++)
212 if( !kalTrkMatched[j] && mdcTrkID==(*(beginOfMdcKalTrackCol+j))->trackId() )
216 kalTrkMatched[j]=
true;
219 for(
int j=0;j<numOfDedx;j++)
220 if( !dEdxMatched[j] && mdcTrkID==(*(beginOfDedxCol+j))->trackId() )
222 aNewEvtRecTrack->
setMdcDedx(*(beginOfDedxCol+j));
227 for(
int j=0;j<numOfExt;j++)
228 if( !extMatched[j] && mdcTrkID==(*(beginOfExtTrackCol+j))->trackId() )
230 aNewEvtRecTrack->
setExtTrack(*(beginOfExtTrackCol+j));
234 for(
int j=0;j<numOfTof;j++)
235 if( !TofMatched[j] && mdcTrkID==(*(beginOfTofTrackCol+j))->trackID() )
237 aNewEvtRecTrack->
addTofTrack(*(beginOfTofTrackCol+j));
241 for(
int j=0;j<numOfMucTrks;j++)
242 if( !mucMatched[j] && mdcTrkID==(*(beginOfMucTrackCol+j))->trackId() )
244 aNewEvtRecTrack->
setMucTrack(*(beginOfMucTrackCol+j));
252 myEnergyMatched = -1.;
256 if(m_Output==1)myExted = 1.;
258 Hep3Vector extPos = (aNewEvtRecTrack->
extTrack())->emcPosition();
259 double extTheta = extPos.theta();
260 double extPhi = extPos.phi();
262 double dAngleMin = 9999.;
263 int indexOfEmcNearest = -1;
265 for(
int j=0;j<numOfShower;j++)
269 HepPoint3D emcPot = (*(beginOfEmcTrackCol+j))->position();
270 Hep3Vector emcPos(emcPot.x(),emcPot.y(),emcPot.z());
271 double dAngle = extPos.angle(emcPos);
275 indexOfEmcNearest = j;
279 if(indexOfEmcNearest>=0)
281 HepPoint3D emcPot = (*(beginOfEmcTrackCol+indexOfEmcNearest))->position();
282 double theta = emcPot.theta();
283 double phi = emcPot.phi();
284 double deltaTheta = (extTheta-theta);
288 double tanLamda = (*(beginOfMdcTrkCol+i))->helix(4);
289 double kappa = (*(beginOfMdcTrkCol+i))->helix(2);
290 double p = sqrt(1+tanLamda*tanLamda)/fabs(kappa);
291 double aThetaCut = thetaCut(p,myEmcThetaNSigmaCut,myParticleId);
292 double aPhiCUt = phiCut(p,myEmcPhiNSigmaCut,myParticleId);
293 if(fabs(deltaTheta)<aThetaCut && fabs(deltaPhi)<aPhiCUt)
295 aNewEvtRecTrack->
setEmcShower(*(beginOfEmcTrackCol+indexOfEmcNearest));
297 emcMatched[indexOfEmcNearest]=
true;
298 numOfMatchedShower++;
299 if(m_Output==1)myMatched = 1.;
302 else if(fabs(deltaTheta)<myEmcThetaCut && fabs(deltaPhi)<myEmcPhiCut)
304 aNewEvtRecTrack->
setEmcShower(*(beginOfEmcTrackCol+indexOfEmcNearest));
306 emcMatched[indexOfEmcNearest]=
true;
307 numOfMatchedShower++;
308 if(m_Output==1)myMatched = 1.;
312 aNewEvtRecTrackCol->push_back(aNewEvtRecTrack);
314 myEnergyMatched = 0.;
320 for(
int i=0;i<numOfShower;i++)
325 aNewEvtRecTrack->
setTrackId(
id+numOfChargedTrks);
330 HepPoint3D emcPos((*(beginOfEmcTrackCol+i))->position());
331 double emcPhi = emcPos.phi();
332 emcPhi = emcPhi < 0 ? emcPhi+CLHEP::twopi : emcPhi;
334 int module=9999, nphi1=9999, nphi2=9999, nphi1_mrpc=9999;
335 module = (*(beginOfEmcTrackCol+i))->module();
337 nphi1 = (int)(emcPhi*88./CLHEP::twopi);
338 nphi2 = (int)(emcPhi*88./CLHEP::twopi+0.5);
341 nphi1 = (int)(emcPhi*48./CLHEP::twopi+0.5);
345 double fi_endtof_mrpc = atan2(emcPos.y(),emcPos.x())-3.141592654/2.;
346 if(fi_endtof_mrpc<0) fi_endtof_mrpc += 2*3.141592654;
347 nphi1_mrpc=((int)(fi_endtof_mrpc/(3.141593/18)))+1;
349 if(nphi1_mrpc%2==0){nphi1_mrpc=nphi1_mrpc/2;}
350 else {nphi1_mrpc=(nphi1_mrpc+1)/2;}
352 if(emcPos.z()>0) {(nphi1_mrpc -= 19); nphi1_mrpc=nphi1_mrpc*(-1);}
358 int partid_dPhiMin = 7;
359 bool mrpcmatch =
false;
361 int indexOfTofNearest = -1;
362 for(
int j=0;j<numOfTof;j++) {
363 if( !TofMatched[j] ) {
365 Identifier id((*(beginOfTofTrackCol+j))->tofID());
375 if(module!=barrel_ec)
continue;
379 dPhi =
abs(im - nphi1);
381 dPhi =
abs(im - nphi2);
384 dPhi = dPhi>=44 ? 88-dPhi : dPhi;
386 dPhi = dPhi>=24 ? 48-dPhi : dPhi;
391 indexOfTofNearest = j;
400 dphi =
abs(module_mrpc-nphi1_mrpc);
405 partid_dPhiMin=barrel_ec;
406 indexOfTofNearest = j;
428 if(indexOfTofNearest>=0) {
429 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
430 double matWindow = 0;
431 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
433 matWindow = 0.01277+0.004268/sqrt(eShower);
438 if(indexOfTofNearest>=0 && dPhiMin<=1) {
440 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
441 double matWindow = 0;
443 matWindow = 0.01277+0.004268/sqrt(eShower);
447 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
448 if(fabs(tofPos.theta()-emcPos.theta())<matWindow || module!=1) {
449 aNewEvtRecTrack->
addTofTrack(*(beginOfTofTrackCol+indexOfTofNearest));
450 TofMatched[indexOfTofNearest]=
true;
456 aNewEvtRecTrackCol->push_back(aNewEvtRecTrack);
463 if(myMsgFlag) cout<<
"Charged tracks: "<<numOfChargedTrks<<
" Ext track: "<<numOfExt <<
" Shower:"<<numOfShower<<
" Matched shower:"<<numOfMatchedShower<<endl;
466 DataObject *aDataObject1;
468 if ( aDataObject1 ==
NULL ) {
471 if ( sc.isFailure() ) {
472 log << MSG::FATAL <<
"Could not register EvtRecObject in TDS!" << endreq;
473 return StatusCode::FAILURE;
477 DataObject* aDataObject2;
479 if ( aDataObject2 ==
NULL ) {
481 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
485 if ( sc.isFailure() ) {
486 log << MSG::FATAL <<
"Could not register EvtRecEvent in TDS!" << endreq;
487 return( StatusCode::FAILURE);
492 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
497 DataObject* aDataObject3;
499 if ( aDataObject3 !=
NULL ) {
501 SmartIF<IDataManagerSvc> dataMgrSvc(eventSvc());
507 if ( sc.isFailure() ) {
508 log << MSG::FATAL <<
"Could not register EvtRecTrackCol in TDS!" << endreq;
509 return( StatusCode::FAILURE);
516 log<<MSG::FATAL<<
"Could not find RecTrackListCol in TDS!"<<endreq;
519 EvtRecTrackCol::iterator itOfRecTrkListCol = evtRecTrackCol->begin();
521 for(
int i=0;itOfRecTrkListCol!=evtRecTrackCol->end();itOfRecTrkListCol++,i++)
523 cout<<
"******************** Track "<<i<<
": *********************"<<endl;
524 cout<<
"Track ID: "<<(*itOfRecTrkListCol)->trackId()<<endl;
525 if((*itOfRecTrkListCol)->isMdcTrackValid())
527 RecMdcTrack* mdcTrk = (*itOfRecTrkListCol)->mdcTrack();
528 double kappa = mdcTrk->
helix(2);
529 double tanl = mdcTrk->
helix(4);
530 cout<<
"Mdc kappa, tanl: "<<kappa<<
", "<<tanl<<endl;
532 if((*itOfRecTrkListCol)->isExtTrackValid())
534 RecExtTrack* extTrack = (*itOfRecTrkListCol)->extTrack();
536 cout<<
"Ext Emc pos:"<<emcPos.x()<<
","<<emcPos.y()<<
","<<emcPos.z()<<endl;
538 if((*itOfRecTrkListCol)->isEmcShowerValid())
540 RecEmcShower* emcTrack = (*itOfRecTrkListCol)->emcShower();
542 double x = emcPos.x();
543 double y = emcPos.y();
544 double z = emcPos.z();
545 cout<<
"Emc rec pos:"<<
x<<
","<<
y<<
","<<z<<endl;
549 return StatusCode::SUCCESS;
555 MsgStream log(
msgSvc(), name());
556 log << MSG::INFO <<
"in finalize()" << endreq;
558 return StatusCode::SUCCESS;
564double EventAssemblyAlg::thetaCut(
double p,
double nSigma,
int parId)
567 if(parId<1||parId>3) parId=3;
568 if(nSigma<=0) nSigma = 5.;
569 double cut = myEmcThetaCut;
572 case 1:
cut = fabs(-0.00159)+(
exp(-3.566*p-4.14)+0.006804)*nSigma;
break;
573 case 2:
cut = fabs(-0.00145)+(
exp(-4.268*p-3.305)+0.01129)*nSigma;
break;
574 case 3:
cut = fabs(-0.00161)+(
exp(-5.955*p-3.052)+0.01751)*nSigma;
break;
581double EventAssemblyAlg::phiCut(
double p,
double nSigma,
int parId)
584 if(parId<1||parId>3) parId=3;
585 if(nSigma<=0) nSigma = 5.;
586 double cut = myEmcPhiCut;
589 case 1:
cut = fabs(
exp(-2.187*p-2.945)+0.03236)+(
exp(-2.977*p-3.558)+0.005566)*nSigma;
break;
590 case 2:
cut = fabs(
exp(-2.216*p-2.13)+0.03314)+(
exp(-2.436*p-3.392)+0.005049)*nSigma;
break;
591 case 3:
cut = fabs(
exp(-1.63*p-2.931)+0.03223)+(
exp(-3.192*p-2.756)+0.01533)*nSigma;
break;
EvtComplex exp(const EvtComplex &c)
ObjectVector< EvtRecTrack > EvtRecTrackCol
HepPoint3D position() const
const Hep3Vector emcPosition() const
const HepVector helix() const
......
EventAssemblyAlg(const std::string &name, ISvcLocator *pSvcLocator)
void setTotalTracks(const int tottks)
void setTotalNeutral(const int nneu)
void setTotalCharged(const int nchrg)
void setMucTrack(const RecMucTrack *trk)
void setMdcTrack(const RecMdcTrack *trk)
void setTrackId(const int trkId)
void setMdcKalTrack(const RecMdcKalTrack *trk)
void setMdcDedx(const RecMdcDedx *trk)
void setEmcShower(const RecEmcShower *shower)
void addTofTrack(const SmartRef< RecTofTrack > trk)
void setExtTrack(const RecExtTrack *trk)
static bool is_mrpc(const Identifier &id)
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static int layer(const Identifier &id)
static int module(const Identifier &id)
_EXTERN_ std::string Event
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol
_EXTERN_ std::string RecExtTrackCol
_EXTERN_ std::string RecMdcDedxCol
_EXTERN_ std::string RecTofTrackCol
_EXTERN_ std::string RecMdcTrackCol
_EXTERN_ std::string RecMdcKalTrackCol
_EXTERN_ std::string RecMucTrackCol
_EXTERN_ std::string RecEmcShowerCol