1#include "EventAssembly/EventAssemblyAlg.h"
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"
13#include "EventModel/EventHeader.h"
14#include "EvtRecEvent/EvtRecObject.h"
15#include "EvtRecEvent/EvtRecTrack.h"
16#include "EvtRecEvent/EvtRecEvent.h"
17#include "EvTimeEvent/RecEsTime.h"
18#include "Identifier/Identifier.h"
19#include "Identifier/TofID.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;
398 int module_mrpc = (int)im/25;
400 if(module==1)
continue;
401 if(module==0 && (barrel_ec==5 || barrel_ec==6))
continue;
402 if(module==2 && (barrel_ec==3 || barrel_ec==4))
continue;
405 dphi =
abs(module_mrpc-nphi1_mrpc);
410 partid_dPhiMin=barrel_ec;
411 indexOfTofNearest = j;
433 if(indexOfTofNearest>=0) {
434 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
435 double matWindow = 0;
436 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
438 matWindow = 0.01277+0.004268/sqrt(eShower);
443 if(indexOfTofNearest>=0 && dPhiMin<=1) {
445 double eShower = (*(beginOfEmcTrackCol+i))->e5x5();
446 double matWindow = 0;
448 matWindow = 0.01277+0.004268/sqrt(eShower);
452 HepPoint3D tofPos(0,0.867,(*(beginOfTofTrackCol+indexOfTofNearest))->zrhit());
453 if(fabs(tofPos.theta()-emcPos.theta())<matWindow || module!=1) {
454 aNewEvtRecTrack->
addTofTrack(*(beginOfTofTrackCol+indexOfTofNearest));
455 TofMatched[indexOfTofNearest]=
true;
461 aNewEvtRecTrackCol->push_back(aNewEvtRecTrack);
468 if(myMsgFlag) cout<<
"Charged tracks: "<<numOfChargedTrks<<
" Ext track: "<<numOfExt <<
" Shower:"<<numOfShower<<
" Matched shower:"<<numOfMatchedShower<<endl;
471 DataObject *aDataObject1;
473 if ( aDataObject1 == NULL ) {
476 if ( sc.isFailure() ) {
477 log << MSG::FATAL <<
"Could not register EvtRecObject in TDS!" << endreq;
478 return StatusCode::FAILURE;
482 DataObject* aDataObject2;
484 if ( aDataObject2 == NULL ) {
486 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
490 if ( sc.isFailure() ) {
491 log << MSG::FATAL <<
"Could not register EvtRecEvent in TDS!" << endreq;
492 return( StatusCode::FAILURE);
497 aRecEvent->
setTotalTracks(numOfChargedTrks+numOfShower-numOfMatchedShower);
502 DataObject* aDataObject3;
504 if ( aDataObject3 != NULL ) {
506 SmartIF<IDataManagerSvc> dataMgrSvc(eventSvc());
512 if ( sc.isFailure() ) {
513 log << MSG::FATAL <<
"Could not register EvtRecTrackCol in TDS!" << endreq;
514 return( StatusCode::FAILURE);
521 log<<MSG::FATAL<<
"Could not find RecTrackListCol in TDS!"<<endreq;
524 EvtRecTrackCol::iterator itOfRecTrkListCol = evtRecTrackCol->begin();
526 for(
int i=0;itOfRecTrkListCol!=evtRecTrackCol->end();itOfRecTrkListCol++,i++)
528 cout<<
"******************** Track "<<i<<
": *********************"<<endl;
529 cout<<
"Track ID: "<<(*itOfRecTrkListCol)->trackId()<<endl;
530 if((*itOfRecTrkListCol)->isMdcTrackValid())
532 RecMdcTrack* mdcTrk = (*itOfRecTrkListCol)->mdcTrack();
533 double kappa = mdcTrk->
helix(2);
534 double tanl = mdcTrk->
helix(4);
535 cout<<
"Mdc kappa, tanl: "<<kappa<<
", "<<tanl<<endl;
537 if((*itOfRecTrkListCol)->isExtTrackValid())
539 RecExtTrack* extTrack = (*itOfRecTrkListCol)->extTrack();
541 cout<<
"Ext Emc pos:"<<emcPos.x()<<
","<<emcPos.y()<<
","<<emcPos.z()<<endl;
543 if((*itOfRecTrkListCol)->isEmcShowerValid())
545 RecEmcShower* emcTrack = (*itOfRecTrkListCol)->emcShower();
547 double x = emcPos.x();
548 double y = emcPos.y();
549 double z = emcPos.z();
550 cout<<
"Emc rec pos:"<<
x<<
","<<y<<
","<<z<<endl;
554 return StatusCode::SUCCESS;
560 MsgStream log(
msgSvc(), name());
561 log << MSG::INFO <<
"in finalize()" << endreq;
563 return StatusCode::SUCCESS;
569double EventAssemblyAlg::thetaCut(
double p,
double nSigma,
int parId)
572 if(parId<1||parId>3) parId=3;
573 if(nSigma<=0) nSigma = 5.;
574 double cut = myEmcThetaCut;
577 case 1:
cut = fabs(-0.00159)+(
exp(-3.566*p-4.14)+0.006804)*nSigma;
break;
578 case 2:
cut = fabs(-0.00145)+(
exp(-4.268*p-3.305)+0.01129)*nSigma;
break;
579 case 3:
cut = fabs(-0.00161)+(
exp(-5.955*p-3.052)+0.01751)*nSigma;
break;
586double EventAssemblyAlg::phiCut(
double p,
double nSigma,
int parId)
589 if(parId<1||parId>3) parId=3;
590 if(nSigma<=0) nSigma = 5.;
591 double cut = myEmcPhiCut;
594 case 1:
cut = fabs(
exp(-2.187*p-2.945)+0.03236)+(
exp(-2.977*p-3.558)+0.005566)*nSigma;
break;
595 case 2:
cut = fabs(
exp(-2.216*p-2.13)+0.03314)+(
exp(-2.436*p-3.392)+0.005049)*nSigma;
break;
596 case 3:
cut = fabs(
exp(-1.63*p-2.931)+0.03223)+(
exp(-3.192*p-2.756)+0.01533)*nSigma;
break;
ObjectVector< EvtRecTrack > EvtRecTrackCol
EvtComplex exp(const EvtComplex &c)
double abs(const EvtComplex &c)
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
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 int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static bool is_mymrpc(const Identifier &id)
static int layer(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