#include "hrichcorrelatorsim.h"
#include "hrichcorrelatorpar.h"
#include "hrichgeometrypar.h"
#include "hrichutilfunc.h"
#include "hgeantkine.h"
#include "hgeantrich.h"
#include "hgeantmdc.h"
#include "hruntimedb.h"
#include "hevent.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hrichdetector.h"
#include "hmdcdetector.h"
#include "htofdetector.h"
#include "hshowerdetector.h"
#include "hshowertrack.h"
#include "hcategory.h"
#include "hiterator.h"
#include "hmatrixcatiter.h"
#include "hrichhit.h"
#include "hrichhitsim.h"
#include "hmdcseg.h"
#include "hmdcsegsim.h"
#include "htofhit.h"
#include "htofhitsim.h"
#include "hshowerhittof.h"
#include "tofdef.h"
#include "hmdcdef.h"
#include "showertofinodef.h"
#include "showerdef.h"
#include "hdebug.h"
#include "hades.h"
#include "richdef.h"
#include "hhitmatchsim.h"
#include "hhitmatchheadersim.h"
#include "hlinearcategory.h"
#include "kickdef.h"
#include <fstream>
#include "hgeantheader.h"
#include "hrecevent.h"
#include "hpartialevent.h"
ClassImp(HRichCorrelatorSim)
HRichCorrelatorSim::HRichCorrelatorSim(const Text_t *name,const Text_t *title) :
HRichCorrelator(name,title)
{
}
HRichCorrelatorSim::HRichCorrelatorSim(const Text_t *name,const Text_t *title,const Char_t* filename, Bool_t style) :
HRichCorrelator(name,title,filename,style)
{
pFileName = filename;
isComplex = style;
}
HRichCorrelatorSim::HRichCorrelatorSim()
{
}
HRichCorrelatorSim::~HRichCorrelatorSim(void)
{
}
Bool_t HRichCorrelatorSim::init() {
if (gHades) {
HEvent *event=gHades->getCurrentEvent();
HRuntimeDb *rtdb=gHades->getRuntimeDb();
HSpectrometer *spec=gHades->getSetup();
if (event && rtdb) {
HTofDetector *tof=(HTofDetector*)spec->getDetector("Tof");
HShowerDetector *shower = (HShowerDetector*)spec->getDetector("Shower");
HMdcDetector *mdc =(HMdcDetector*)(spec->getDetector("Mdc"));
HRichDetector *rich = (HRichDetector*)spec->getDetector("Rich");
HRichCorrelatorPar *pCorrPar =
(HRichCorrelatorPar*)rtdb->getContainer("RichCorrelatorParameters");
if (!pCorrPar)
{
pCorrPar = new HRichCorrelatorPar;
rtdb->addContainer(pCorrPar);
}
setCorrelationPar(pCorrPar);
if (!pCorrPar) return kFALSE;
fGeantKineCat =(HLinearCategory*) event->getCategory(catGeantKine);
if (!fGeantKineCat)
{
Error("HRichCorrelatorSim::init",
"no GEANT Kine category available");
}
iter_kine = (HIterator *)fGeantKineCat ->MakeIterator("native");
fGeantRichMirrorCat = (HMatrixCategory*)(gHades->getCurrentEvent()
->getCategory(catRichGeantRaw+2));
if (!fGeantRichMirrorCat)
{
Warning("HRichCorrelatorSim::init",
"no GEANT RICH MIRROR category available");
}
if (fGeantRichMirrorCat) iter_mirror = (HIterator *)fGeantRichMirrorCat->MakeIterator("native");
fGeantMdcCat = (HMatrixCategory*)(gHades->getCurrentEvent()
->getCategory(catMdcGeantRaw));
if (!fGeantMdcCat)
{
Warning("HRichCorrelatorSim::init",
"no GEANT MDC RAW category available");
}
if (fGeantMdcCat) iter_mdcgeant = (HIterator *)fGeantMdcCat->MakeIterator("native");
if (rich) {
fRichPID=gHades->getCurrentEvent()->getCategory(catRichHit);
if (!fRichPID) {
fRichPID=rich->buildMatrixCat("HRichHitSim",1);
if (!fRichPID) return kFALSE;
else gHades->getCurrentEvent()
->addCategory(catRichHit, fRichPID, "Rich");
}
fRichIter = (HIterator*) fRichPID->MakeIterator();
if(!fRichIter) Error("init","no RichHitSim iter defined");
pRichHitFitCat=gHades->getCurrentEvent()->getCategory(catRichHitFit);
if (!pRichHitFitCat){
Warning("init()","no Rich hit fit category in input");
}
if (pRichHitFitCat) pRichHitFitIter =
(HIterator*) pRichHitFitCat->MakeIterator();
pHitMatchCat=event->getCategory(catMatchHit);
if (!pHitMatchCat) {
pHitMatchCat=rich->buildLinearCat("HHitMatchSim");
if (!pHitMatchCat) {
Error("init","No HIT MATCH category defined");
return kFALSE;
}
else event->addCategory(catMatchHit, pHitMatchCat, "Rich");
}
pIterMatchHit = (HIterator*)getHitMatchCat()->MakeIterator("native");
pHitMatchHeaderCat=event->getCategory(catMatchHitHeader);
if (!pHitMatchHeaderCat) {
pHitMatchHeaderCat=rich->buildLinearCat("HHitMatchHeaderSim");
if (!pHitMatchHeaderCat) {
Error("init","No HIT MATCH HEADER SIM category defined");
return kFALSE;
}
else event->addCategory(catMatchHitHeader, pHitMatchHeaderCat
, "Rich");
}
pIterMatchHitHeader = (HIterator*)getHitMatchHeaderCat()
->MakeIterator("native");
}
if (mdc) {
fMdcSeg = gHades->getCurrentEvent()->getCategory(catMdcSeg);
if (!fMdcSeg){
fMdcSeg = mdc->buildMatrixCategory("HMdcSegSim",0.5F);
if (!fMdcSeg) {
Error("init","No MDC segment sim category defined");
return kFALSE;
}
}
else {
gHades->getCurrentEvent()
->addCategory(catMdcSeg,fMdcSeg,"Mdc");
fMdcSegIter=(HIterator *)fMdcSeg->MakeIterator();
}
}
if (tof) {
fTofHits=event->getCategory(catTofHit);
if (!fTofHits) {
fTofHits=tof->buildMatrixCategory("HTofHitSim",0.5F);
if (!fTofHits) {
Error("init","No TOF input");
return kFALSE;
}else{
gHades->getCurrentEvent()
->addCategory(catTofHit,fTofHits,"Tof");
}
}
fTofIter=(HIterator *)fTofHits->MakeIterator();
}
if (shower) {
fShowerTrack=gHades->getCurrentEvent()->getCategory(catShowerTrack);
if (!fShowerTrack) {
fShowerTrack=shower->buildCategory(catShowerTrack);
if (!fShowerTrack) return kFALSE;
else gHades->getCurrentEvent()
->addCategory(catShowerTrack, fShowerTrack, "Shower");
}
iter_showertrack = (HIterator*)fShowerTrack->MakeIterator();
fShowerTofHits=event->getCategory(catShowerHitTofTrack);
if (!fShowerTofHits)
{
fShowerTofHits = new HLinearCategory("HShowerHitTofTrack", 1000);
if (!fShowerTofHits) return kFALSE;
else gHades->getCurrentEvent()
->addCategory(catShowerHitTofTrack,fShowerTofHits, "Tofino");
}
fShowerTofIter = (HIterator *)fShowerTofHits->MakeIterator();
}
fKickTrackCat = gHades->getCurrentEvent()->getCategory(catKickTrack);
if (!fKickTrackCat) {
Error("init","KickTrack not found in input file");
return kFALSE;
}
iterTracks = (HIterator *)fKickTrackCat->MakeIterator("native");
} else {
Error ("init","! (event && rtdb)");
return kFALSE;
}
iniCounters();
pFileOut = new TFile(pFileName,"RECREATE");
return kTRUE;
} else {
Error ("init","! (gHades)");
return kFALSE;
}
}
void HRichCorrelatorSim::iniCounters(void)
{
HRichCorrelator::iniCounters();
ng_Part=ngGNb_RM=ngGNb_RT_S=ngGNb_MT_S=ngGNb_RMT_S=0;
ngGNbRMonly=ngGNbRTSonly=ngGNbMTSonly=ngGNbRMTSonly=0;
ngNb_RW=ngNb_MW=0;
fg_RW=fg_MW=0.;
ngNb_Fakes=0;
ngNb_ConfTracklet=0;
for(Int_t k=0;k<MAXPARIDS;k++) ng_ParId[k]=0;
}
Bool_t HRichCorrelatorSim::reinit()
{
HRichCorrelatorPar* pCorrPar = (HRichCorrelatorPar*)getCorrelationPar();
iniCuts();
iniSwitches();
pCorrPar -> printParam();
return kTRUE;
}
void HRichCorrelatorSim::diag(HHitMatchSim * pHM)
{
cout<<"*** HRichCorrelatorSim::diag *********************** "<<endl;
HMdcSegSim *m=0;
HRichHitSim *r=0;
HShowerHitTof *st=0;
HTofHitSim *t=0;
if(pHM->getMdcInd()>-1) m = ((HMdcSegSim*)getMdcSegCat()
->getObject(pHM->getMdcInd()));
if(pHM->getRichInd()>-1) r = ((HRichHitSim*)getRichHitCat()
->getObject(pHM->getRichInd()));
if(pHM->getShowInd()>-1) st = ((HShowerHitTof*)
getShowerTofHitCat()
->getObject(pHM->getShowInd()));
if(pHM->getTofInd()>-1) t = ((HTofHitSim*)getTofHitCat()
->getObject(pHM->getTofInd()));
if(r)
{
cout<<"RICH track/weight"<<endl;
cout<<r->track1<<"/"<<r->weigTrack1<<" ";
cout<<r->track2<<"/"<<r->weigTrack2<<" ";
cout<<r->track3<<"/"<<r->weigTrack3<<endl;
}
if(m)
{
Int_t nNbMdcSegTr=m->getNTracks();
cout<<"MDC track/weight"<<endl;
for (Int_t i=0;i<nNbMdcSegTr;i++)
{
cout<<m->getTrack(i)<<"/"<<(Int_t)m->getNTimes(i)<<" ";
}
cout<<endl;
}
if(st)
{
cout<<"SHOWER track/"<<endl;
for (Int_t i=0;i<SHOWERMAXTRACKS;i++)
{
cout<<showerTracks[i]<<"/"<<" ";
}
cout<<endl;
}
if(t)
{
cout<<"TOF track/"<<endl;
cout<<t->getNTrack1()<<"/"<<" ";
cout<<t->getNTrack2()<<"/"<<" ";
cout<<endl;
}
}
Int_t HRichCorrelatorSim::execute()
{
if (!HRichCorrelator::execute())
{
HHitMatchSim *pHitMatch=0;
pIterMatchHit->Reset();
while((pHitMatch = (HHitMatchSim *)pIterMatchHit->Next()))
{
(pHitMatch->getTrackInfoObj())->reset();
cleanTracks();
if(pHitMatch->getRichInd()>=0) assignRichTracks(pHitMatch->getRichInd());
if(pHitMatch->getMdcInd()>=0) assignMdcTracks(pHitMatch->getMdcInd());
if(pHitMatch->getShowInd()>=0) assignShowerTrack(pHitMatch->getShowInd());
if(pHitMatch->getTofInd()>=0) assignTofTracks(pHitMatch->getTofInd());
matchTracks(pHitMatch);
if ((richTracks[0] == -5 || richTracks[0] == -1) && richTracks[1] >0)
{
}
}
HHitMatchHeaderSim *pHMH = 0;
pIterMatchHitHeader->Reset();
while((pHMH = (HHitMatchHeaderSim *)pIterMatchHitHeader->Next()))
{
pHMH->resetSim();
HHitMatchSim *pHitMatch=0;
pIterMatchHit->Reset();
Int_t nMaxParticles=pHMH->getNbCorrObjs()*MAXPARTICLES;
Int_t *nDParticles=new Int_t[nMaxParticles];
for(Int_t i=0;i<nMaxParticles;i++) nDParticles[i]=-2;
Int_t nl_Part=0;
Int_t nl_RM=0;
Int_t nl_RT_S=0;
Int_t nl_MT_S=0;
Int_t nl_RMT_S=0;
Int_t nGNbRMonly=0;
Int_t nGNbRTSonly=0;
Int_t nGNbMTSonly=0;
Int_t nGNbRMTSonly=0;
Float_t fl_RW=0.;
Float_t fl_MW=0.;
Int_t nlNb_Fakes=0;
Int_t nlNb_ConfTracklet=0;
Int_t nl_ParId[MAXPARIDS];
for(Int_t k=0;k<MAXPARIDS;k++) nl_ParId[k]=0;
while((pHitMatch = (HHitMatchSim *)pIterMatchHit->Next()))
{
HTrackInfo *t = pHitMatch->getTrackInfoObj();
pHitMatch->resetSim();
pHitMatch->setGLepRing(isGRing(pHitMatch));
pHitMatch->setGCLepRing(isGCorrRing(t));
pHitMatch->setNbGPart(t->getPartNr());
Int_t nMatchedMirrorRingTrkNb = -3;
if (nMatchedMirrorRingTrkNb>-1) isLepOnMDC(pHitMatch,nMatchedMirrorRingTrkNb);
Int_t isFirstGeantNbInTracklet=1;
for(Int_t i=0;i<MAXPARTICLES;i++)
{
Int_t nTrkNb=t->getTrkNb(i);
if (nTrkNb>-1)
{
if(isFirstGeantNbInTracklet) nlNb_ConfTracklet++;
isFirstGeantNbInTracklet=0;
pHitMatch->setFakeFlag(0);
Int_t nParId=t->getParId(i);
if(!pHitMatch->isFake() && (nParId==2 || nParId==3) )
{
pHitMatch->setLeptonFlag(1);
}
Int_t index=fillUniqueIndex(nTrkNb,
nMaxParticles,
nDParticles);
if(index>0)
{
Float_t fRW=t->getRichWeight(i);
Float_t fMW=t->getMdcWeight(i);
Int_t nMatchRM=t->getMatchedRM(i);
Int_t nMatchRT_S=t->getMatchedRT_S(i);
Int_t nMatchMT_S=t->getMatchedMT_S(i);
Int_t nMatchRMT_S=t->getMatchedRMT_S(i);
nl_Part++;
if(nParId<MAXPARIDS) nl_ParId[nParId]+=1;
if(fRW>-1) fl_RW+=fRW;
if(fMW>-1) fl_MW+=fMW;
if(nMatchRM != -1) nl_RM++;
if(nMatchRT_S != -1) nl_RT_S++;
if(nMatchMT_S != -1) nl_MT_S++;
if(nMatchRMT_S != -1) nl_RMT_S++;
if(nMatchRM!=-1 && nMatchRT_S==-1 &&
nMatchMT_S==-1 && nMatchRMT_S==-1 ) nGNbRMonly++;
if(nMatchRM==-1 && nMatchRT_S!=-1 &&
nMatchMT_S==-1 && nMatchRMT_S==-1 ) nGNbRTSonly++;
if(nMatchRM==-1 && nMatchRT_S==-1 &&
nMatchMT_S!=-1 && nMatchRMT_S==-1 ) nGNbMTSonly++;
if(nMatchRM!=-1 && nMatchRT_S!=-1 &&
nMatchMT_S!=-1 && nMatchRMT_S!=-1 ) nGNbRMTSonly++;
}
}
}
if(pHitMatch->isFake()) nlNb_Fakes++;
}
delete nDParticles;
if(nl_Part>0)
{
fl_RW/=nl_Part;
fl_MW/=nl_Part;
}
pHMH->setNbPart(nl_Part);
ng_Part+=nl_Part;
ngNb_ConfTracklet+=nlNb_ConfTracklet;
pHMH->setNbConfTracklets(nlNb_ConfTracklet);
ngNb_Fakes+=nlNb_Fakes;
pHMH->setNbFakes(nlNb_Fakes);
pHMH->setAvrgRichWeight(fl_RW);
if(fl_RW>0.)
{
fg_RW+=fl_RW;
ngNb_RW++;
}
pHMH->setAvrgMdcWeight(fl_MW);
if(fl_MW>0.)
{
fg_MW+=fl_MW;
ngNb_MW++;
}
for(Int_t n=0;n<MAXPARIDS;n++)
{
ng_ParId[n]+=nl_ParId[n];
if(nl_ParId[n]>0) pHMH->setParId(n,nl_ParId[n]);
}
pHMH->setGeantNb_RM(nGNbRMonly);
ngGNbRMonly+=nGNbRMonly;
pHMH->setGeantNb_RT_S(nGNbRTSonly);
ngGNbRTSonly+=nGNbRTSonly;
pHMH->setGeantNb_MT_S(nGNbMTSonly);
ngGNbMTSonly+=nGNbMTSonly;
pHMH->setGeantNb_RMT_S(nGNbRMTSonly);
ngGNbRMTSonly+=nGNbRMTSonly;
HRecEvent* pGeantEvent = (HRecEvent*)(gHades->getCurrentEvent());
HPartialEvent* pPartialEvent = pGeantEvent->getPartialEvent(catSimul);
HGeantHeader* pGeantHeader = (HGeantHeader*)(pPartialEvent->getSubHeader());
pHMH->setImpactParam(pGeantHeader->getImpactParameter());
}
}
return 0;
}
void HRichCorrelatorSim::diagOut(HHitMatchSim* pHitMatch,HTrackInfo* t)
{
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
<<nCounterProcessedNbEvents<<endl;
pHitMatch->dumpToStdoutSim();
diag(pHitMatch);
for(Int_t i=0;i<MAXPARTICLES;i++)
{
if (t->getTrkNb(i)>-1)
{
HRichUtilFunc::dumpKine(HRichUtilFunc::
getKineObj(t->getTrkNb(i),
(HLinearCategory*)
getGeantKineCat()));
}
}
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "<<endl;
}
void HRichCorrelatorSim::cleanTracks()
{
for(Int_t i = 0;i<RICHMAXTRACKS;i++){
richTracks[i] = 0;
richWeights[i] = 0;
}
for(Int_t i = 0;i<MDCMAXTRACKS;i++){
mdcTracks[i] = 0;
mdcWeights[i] = 0;
}
for(Int_t i = 0;i<TOFMAXTRACKS;i++) tofTracks[i]=0;
for(Int_t i = 0;i<SHOWERMAXTRACKS;i++) showerTracks[i] = 0;
}
void HRichCorrelatorSim::assignRichTracks(Int_t richInd)
{
HRichHitSim *pRichHit = ((HRichHitSim*)getRichHitCat()
->getObject(richInd));
richTracks[0] = pRichHit->track1;
richWeights[0] = pRichHit->weigTrack1;
richTracks[1] = pRichHit->track2;
richWeights[1] = pRichHit->weigTrack2;
richTracks[2] = pRichHit->track3;
richWeights[2] = pRichHit->weigTrack3;
}
void HRichCorrelatorSim::assignMdcTracks(Int_t mdcInd)
{
HMdcSegSim *pMdcSeg = ((HMdcSegSim*)getMdcSegCat()
->getObject(mdcInd));
for(Int_t i =0;i<pMdcSeg->getNTracks();i++)
{
mdcTracks[i] = pMdcSeg->getTrack(i);
mdcWeights[i] = (Int_t)pMdcSeg->getNTimes(i);
}
}
void HRichCorrelatorSim::assignShowerTrack(Int_t showerInd)
{
HShowerTrack *pTrack=0;
iter_showertrack->Reset();
HShowerHitTof * pHit = ((HShowerHitTof*) getShowerTofHitCat()
->getObject(showerInd));
pTrack = (HShowerTrack *)iter_showertrack->Next();
do {
if (pTrack && pHit->getAddress()==pTrack->getAddress()) {
*showerTracks = pTrack->getTrack();
break;
}
}
while((pTrack = (HShowerTrack *)iter_showertrack->Next())) ;
Int_t i=0;
while((pTrack = (HShowerTrack *)iter_showertrack->Next())) {
if (i<SHOWERMAXTRACKS-1 && pHit->getAddress()==pTrack->getAddress()) {
showerTracks[i++] = pTrack->getTrack();
} else break;
}
}
void HRichCorrelatorSim::assignTofTracks(Int_t tofInd)
{
HTofHitSim *pTofHit = ((HTofHitSim*)getTofHitCat()
->getObject(tofInd));
tofTracks[0] = pTofHit ->getNTrack1();
tofTracks[1] = pTofHit ->getNTrack2();
}
void HRichCorrelatorSim::matchTracks(HHitMatchSim *pHitMatch)
{
Bool_t kRICH = kFALSE;
Bool_t kMDC = kFALSE;
Bool_t kTOF = kFALSE;
Bool_t kSHOWER = kFALSE;
for(Int_t i = 0;i<RICHMAXTRACKS;i++)
{
if (richTracks[i] > 0) {kRICH=kTRUE; break;}
}
for(Int_t i = 0;i<MDCMAXTRACKS;i++)
{
if (mdcTracks[i] > 0) {kMDC=kTRUE; break;}
}
for(Int_t i = 0;i<TOFMAXTRACKS;i++)
{
if (tofTracks[i] > 0) {kTOF=kTRUE; break;}
}
for(Int_t i = 0;i<SHOWERMAXTRACKS;i++)
{
if (showerTracks[i] > 0) {kSHOWER=kTRUE; break;}
}
if(kRICH && kMDC && !kSHOWER && !kTOF)
{
corrTracksRM(pHitMatch);
}
if(!kRICH && kMDC && (kSHOWER || kTOF) )
{
corrTracksMT_S(pHitMatch);
}
if(kRICH && !kMDC && (kSHOWER || kTOF) )
{
corrTracksRT_S(pHitMatch);
}
if(kRICH && kMDC && (kSHOWER || kTOF) )
{
corrTracksRM(pHitMatch);
corrTracksRT_S(pHitMatch);
corrTracksMT_S(pHitMatch);
evalBiCorrs(pHitMatch);
}
}
void HRichCorrelatorSim::evalBiCorrs(HHitMatchSim *pHitMatch)
{
HTrackInfo* t = pHitMatch->getTrackInfoObj();
for (Int_t i=0;i<MAXPARTICLES;i++)
{
Int_t nRM = t->getMatchedRM(i);
Int_t nRT_S = t->getMatchedRT_S(i);
Int_t nMT_S = t->getMatchedMT_S(i);
if (nRM==1 && nMT_S==1 && nRT_S==1) t->setMatchedRMT_S(i);
}
}
void HRichCorrelatorSim::corrTracksRT_S(HHitMatchSim *pHitMatch)
{
HTrackInfo* t = pHitMatch->getTrackInfoObj();
for (Int_t i=0;i<RICHMAXTRACKS;i++)
{
for (Int_t j=0;j<SHOWERMAXTRACKS;j++)
{
if(richTracks[i]>0 && richTracks[i] == showerTracks[j])
{
setGeantTrackInfoRT_S(i,t);
break;
}
}
for (Int_t j=0;j<TOFMAXTRACKS;j++)
{
if(richTracks[i]>0 && richTracks[i] == tofTracks[j])
{
setGeantTrackInfoRT_S(i,t);
break;
}
}
}
}
void HRichCorrelatorSim::corrTracksMT_S(HHitMatchSim *pHitMatch){
HTrackInfo* t = pHitMatch->getTrackInfoObj();
for (Int_t i=0;i<MDCMAXTRACKS;i++)
{
for (Int_t j=0;j<SHOWERMAXTRACKS;j++)
{
if(mdcTracks[i]>0 && mdcTracks[i] == showerTracks[j])
{
setGeantTrackInfoMT_S(i,t);
break;
}
}
for (Int_t j=0;j<TOFMAXTRACKS;j++)
{
if(mdcTracks[i]>0 && mdcTracks[i] == tofTracks[j])
{
setGeantTrackInfoMT_S(i,t);
break;
}
}
}
}
void HRichCorrelatorSim::corrTracksRM(HHitMatchSim* pHitMatch)
{
HTrackInfo* t = pHitMatch->getTrackInfoObj();
for (Int_t i=0;i<RICHMAXTRACKS;i++)
{
for (Int_t j=0;j<MDCMAXTRACKS;j++)
{
if(richTracks[i]>0 && richTracks[i] == mdcTracks[j])
{
setGeantTrackInfoRM(i,j,t);
break;
}
}
}
}
Float_t HRichCorrelatorSim::calcRichWeight(Int_t ind)
{
Float_t sumWeightsRich=0.;
for(Int_t i=0;i<RICHMAXTRACKS;i++) sumWeightsRich += richWeights[i];
Float_t f = (Float_t) richWeights[ind];
return f/sumWeightsRich;
}
Float_t HRichCorrelatorSim::calcMdcWeight(Int_t ind)
{
Float_t sumWeightsMdc=0.;
for(Int_t j =0;j<MDCMAXTRACKS;j++) sumWeightsMdc += mdcWeights[j];
Float_t f = (Float_t) mdcWeights[ind];
return f/sumWeightsMdc;
}
void HRichCorrelatorSim::setGeantTrackInfoRT_S(Int_t index,HTrackInfo *t)
{
Int_t trknb = richTracks[index];
if(trknb<=0) return;
Int_t newSlot=-1;
for (Int_t i=0;i<MAXPARTICLES;i++)
{
if(t->getTrkNb(i)<0)
{
newSlot=i;
break;
}
if(t->getTrkNb(i) == trknb)
{
t->setMatchedRT_S(i);
if(t->getRichWeight(i)==-1) t->setRichWeight(i,calcRichWeight(index));
newSlot=-1;
break;
}
}
if (newSlot>=0)
{
HGeantKine* kine=(HGeantKine*)HRichUtilFunc::getKineObj(trknb,(HLinearCategory*)getGeantKineCat());
if (kine==0)
{
Warning("setGeantTrackInfoRT_S","track number stored in rich hit not found in GEANT kine container");
cout<<"track number that creates problem: "<<trknb<<endl;
return;
}
Int_t aTrack, aID;
Int_t aPar, aMed, aMech;
Float_t ptot;
kine->getParticle(aTrack,aID);
kine->getCreator(aPar,aMed,aMech);
ptot=kine->getTotalMomentum();
if (aTrack!=trknb) Error("HRichCorrelatorSim::setGeantTrackInfoRT_S","track numbers not equal");
t->setTrkNb(newSlot,trknb);
t->setParId(newSlot,aID);
t->setMech(newSlot,aMech);
t->setCreatorId(newSlot,HRichUtilFunc::getParentParID(kine,(HLinearCategory*)getGeantKineCat()));
t->setCreatorTrkNb(newSlot,aPar);
t->setMed(newSlot,aMed);
Float_t xvert,yvert,zvert;
kine->getVertex(xvert,yvert,zvert);
t->setVertx(newSlot,xvert);
t->setVerty(newSlot,yvert);
t->setVertz(newSlot,zvert);
if (aID==2 || aID==3)
{
t->setPi0Dalitz(newSlot,isPi0Dalitz(trknb));
t->setConvLep(newSlot,isConvLep(trknb));
}
t->setTotMom(newSlot,ptot);
t->setRichWeight(newSlot,calcRichWeight(index));
t->setMatchedRT_S(newSlot);
}
}
void HRichCorrelatorSim::setGeantTrackInfoMT_S(Int_t index,HTrackInfo *t)
{
Int_t trknb = mdcTracks[index];
Int_t newSlot=-1;
for (Int_t i=0;i<MAXPARTICLES;i++)
{
if(t->getTrkNb(i)<0)
{
newSlot=i;
break;
}
if(t->getTrkNb(i) == trknb)
{
t->setMatchedMT_S(i);
if(t->getMdcWeight(i)==-1) t->setMdcWeight(i,calcMdcWeight(index));
newSlot=-1;
break;
}
}
if (newSlot>=0)
{
HGeantKine* kine=(HGeantKine*)HRichUtilFunc::getKineObj(trknb,(HLinearCategory*)getGeantKineCat());
Int_t aTrack, aID;
Int_t aPar, aMed, aMech;
Float_t ptot;
kine->getParticle(aTrack,aID);
kine->getCreator(aPar,aMed,aMech);
ptot=kine->getTotalMomentum();
if (aTrack!=trknb) Error("HRichCorrelatorSim::setGeantTrackInfoRT_S","track numbers not equal");
t->setTrkNb(newSlot,trknb);
t->setParId(newSlot,aID);
t->setMech(newSlot,aMech);
t->setCreatorId(newSlot,HRichUtilFunc::getParentParID(kine,(HLinearCategory*)getGeantKineCat()));
t->setCreatorTrkNb(newSlot,aPar);
Float_t xvert,yvert,zvert;
kine->getVertex(xvert,yvert,zvert);
t->setVertx(newSlot,xvert);
t->setVerty(newSlot,yvert);
t->setVertz(newSlot,zvert);
t->setMed(newSlot,aMed);
if (aID==2 || aID==3)
{
t->setPi0Dalitz(newSlot,isPi0Dalitz(trknb));
t->setConvLep(newSlot,isConvLep(trknb));
}
t->setTotMom(newSlot,ptot);
t->setMdcWeight(newSlot,calcMdcWeight(index));
t->setMatchedMT_S(newSlot);
}
}
void HRichCorrelatorSim::setGeantTrackInfoRM(Int_t richindex,Int_t mdcindex,
HTrackInfo *t)
{
Int_t trknb = richTracks[richindex];
if (trknb<0) return;
Int_t newSlot=-1;
for (Int_t i=0;i<MAXPARTICLES;i++)
{
if(t->getTrkNb(i)<0)
{
newSlot=i;
break;
}
if(t->getTrkNb(i) == trknb)
{
t->setMatchedRM(i);
if(t->getMdcWeight(i)==-1) t->setMdcWeight(i,calcMdcWeight(mdcindex));
if(t->getRichWeight(i)==-1) t->setRichWeight(i,calcRichWeight(richindex));
newSlot=-1;
break;
}
}
if (newSlot>=0)
{
HGeantKine* kine=(HGeantKine*)HRichUtilFunc::getKineObj(trknb,(HLinearCategory*)getGeantKineCat());
if (kine==0)
{
Warning("setGeantTrackInfoRT_S","track number stored in rich hit not found in GEANT kine container");
cout<<"track number that creates problem: "<<trknb<<endl;
return;
}
Int_t aTrack, aID;
Int_t aPar, aMed, aMech;
Float_t ptot;
kine->getParticle(aTrack,aID);
kine->getCreator(aPar,aMed,aMech);
ptot=kine->getTotalMomentum();
if (aTrack!=trknb) Error("HRichCorrelatorSim::setGeantTrackInfoRT_S","track numbers not equal");
t->setTrkNb(newSlot,trknb);
t->setParId(newSlot,aID);
t->setMech(newSlot,aMech);
t->setCreatorId(newSlot,HRichUtilFunc::getParentParID(kine,(HLinearCategory*)getGeantKineCat()));
t->setCreatorTrkNb(newSlot,aPar);
Float_t xvert,yvert,zvert;
kine->getVertex(xvert,yvert,zvert);
t->setVertx(newSlot,xvert);
t->setVerty(newSlot,yvert);
t->setVertz(newSlot,zvert);
t->setMed(newSlot,aMed);
if (aID==2 || aID==3)
{
t->setPi0Dalitz(newSlot,isPi0Dalitz(trknb));
t->setConvLep(newSlot,isConvLep(trknb));
}
t->setTotMom(newSlot,ptot);
t->setRichWeight(newSlot,calcRichWeight(richindex));
t->setMdcWeight(newSlot,calcMdcWeight(mdcindex));
t->setMatchedRM(newSlot);
}
}
Int_t HRichCorrelatorSim::isPi0Dalitz(Int_t trk)
{
HGeantKine * kine =0;
iter_kine->Reset();
while((kine=(HGeantKine *)iter_kine->Next())!=0)
{
Int_t aTrack, aID;
Int_t aPar, aMed, aMech;
Float_t ptot;
kine->getParticle(aTrack,aID);
kine->getCreator(aPar,aMed,aMech);
ptot=kine->getTotalMomentum();
if (aTrack==trk)
{
if ( aMech==5 && (aID == 2 || aID==3) && (aMed>=8 && aMed<=19))
{
HGeantKine *kine_parent1 = HRichUtilFunc::findParent(kine,(HLinearCategory*) getGeantKineCat());
if(kine_parent1){
Int_t aTrackp1, aIDp1;
kine_parent1->getParticle(aTrackp1,aIDp1);
if(aIDp1==7)
{
return 1;
}
else return 0;
}
}
}
}
return 0;
}
Int_t HRichCorrelatorSim::isConvLep(Int_t trk)
{
HGeantKine * kine =0;
iter_kine->Reset();
while((kine=(HGeantKine *)iter_kine->Next())!=0)
{
Int_t aTrack, aID;
Int_t aPar, aMed, aMech;
Float_t ptot;
kine->getParticle(aTrack,aID);
kine->getCreator(aPar,aMed,aMech);
ptot=kine->getTotalMomentum();
if (aTrack==trk)
{
if ( aMech==6 && (aID == 2 || aID==3) && (aMed>=8 && aMed<=19))
{
HGeantKine *kine_parent1 = HRichUtilFunc::findParent(kine,(HLinearCategory*) getGeantKineCat());
if(kine_parent1){
Int_t aTrackp1, aIDp1;
Int_t aParp1,aMedp1,aMechp1;
kine_parent1->getParticle(aTrackp1,aIDp1);
kine_parent1->getCreator(aParp1,aMedp1,aMechp1);
if(aIDp1==1 && aMechp1==5)
{
HGeantKine *kine_parent2 = HRichUtilFunc::findParent(kine_parent1,(HLinearCategory*) getGeantKineCat());
if(kine_parent2){
Int_t aTrackp2, aIDp2;
kine_parent2->getParticle(aTrackp2,aIDp2);
if(aIDp2==7)
{
return 1;
}
else return 0;
}
}
}
}
}
}
return 0;
}
Int_t HRichCorrelatorSim::isLepOnMirror(HHitMatchSim *h)
{
Int_t RingCanBeInCorrelation=-1;
HGeantRichMirror *mirr=0;
iter_mirror->Reset();
HRichGeometryPar* pGeo = (HRichGeometryPar*) getGeometryPar();
Float_t fYShift = pGeo->getSectorShift();
fYShift = fYShift/TMath::Cos(20./57.3);
HRichPadTab* pPadsTab = ((HRichGeometryPar*)pGeo)->getPadsPar();
HRichPad *pPad = 0;
HRichHitSim* r=0;
Int_t lep1Count = 0;
Int_t lep2Count = 0;
if(h->getRichInd()>-1) r = ((HRichHitSim*)getRichHitCat()
->getObject(h->getRichInd()));
else return -1;
if (r)
{
Int_t xRing=r->getRingCenterX();
Int_t yRing=r->getRingCenterY();
Int_t secRing=r->getSector();
Float_t weight1 =0.;
Float_t weight2 =0.;
Float_t weightTemp = 0.;
while((mirr=(HGeantRichMirror *)iter_mirror->Next())!=0)
{
Int_t aTrk,aID;
mirr->getTrack(aTrk,aID);
weightTemp = 0;
weightTemp = matchRingMirrtracks(r,aTrk,aID);
if(weightTemp>0){
Float_t x=mirr->getYRing()/10.;
Float_t y=mirr->getXRing()/10. + fYShift;
pPad=pPadsTab->getPad(x,
y );
if (!pPad) return -1;
Int_t sec=mirr->getSector();
Int_t xMirrPhotCM=pPad->getPadX();
Int_t yMirrPhotCM=pPad->getPadY();
Int_t phot=mirr->getNumPhot();
if ((TMath::Abs(xMirrPhotCM-xRing)<2 &&
TMath::Abs(yMirrPhotCM-yRing)<2 &&
sec==secRing) && lep1Count==0){
RingCanBeInCorrelation=aTrk;
h->setLeptonOnMirror(1);
h->setNumPhot1(phot);
weight1 = weightTemp;
lep1Count++;
HTrackInfo* t=(HTrackInfo*) h->getTrackInfoObj();
for (Int_t i=0;i<MAXPARTICLES;i++)
{
if( t->getTrkNb(i)>-1 && t->getTrkNb(i)==aTrk)
{
if (t->getMatchedRM(i)==1 || t->getMatchedRT_S(i)==1 ||
t->getMatchedRMT_S(i)==1)
{
if (t->getParId(i)==2 || t->getParId(i)==3)
{
t->setNumPhot(i,phot);
} else Error("HRichCorrelatorSim::isLepOnMirror(HHitMatchSim *h)","it's not a lepton !!");
}
} else break;
}
}
else{
if ((TMath::Abs(xMirrPhotCM-xRing)<4 &&
TMath::Abs(yMirrPhotCM-yRing)<4 &&
sec==secRing) && lep2Count==0){
h->setLeptonOnMirror(2);
h->setNumPhot2(phot);
weight2 = weightTemp;
lep2Count++;
}
}
}
}
if (lep1Count==0){
h->setLeptonOnMirror(0);
h->setNumPhot2(0);
}
else{
if(lep2Count>0){
h->setWeightRatio(weight1>weight2?weight1/weight2:weight2/weight1);
}
}
}else Error("HRichCorrelatorSim::isLepOnMirror(HHitMatchSim *h)","no valid Rich hit found");
return RingCanBeInCorrelation;
}
Int_t HRichCorrelatorSim::matchRingMirrtracks(HRichHitSim *pH,Int_t trackMirr,Int_t idMirr){
Int_t t1,t2,t3;
t1=t2=t3=-1;
t1=pH->track1;t2=pH->track2;t3=pH->track3;
Int_t p1,p2,p3;p1=p2=p3=-1;
if (t1>-1) p1=HRichUtilFunc::getParID(t1,(HLinearCategory*)
getGeantKineCat());
if (t2>-1) p2=HRichUtilFunc::getParID(t2,(HLinearCategory*)
getGeantKineCat());
if (t3>-1) p3=HRichUtilFunc::getParID(t3,(HLinearCategory*)
getGeantKineCat());
if (t1==trackMirr && idMirr==p1) return pH->weigTrack1;
if (t2==trackMirr && idMirr==p2) return pH->weigTrack2;
if (t3==trackMirr && idMirr==p3) return pH->weigTrack3;
return 0;
}
Int_t HRichCorrelatorSim::isLepOnMDC(HHitMatchSim* h,Int_t trknb)
{
Int_t ParticleSeenInMDC=-1;
if (h->getNumPhot1()>0)
{
HGeantMdc *gmdc = 0;
iter_mdcgeant->Reset();
while((gmdc=(HGeantMdc *)iter_mdcgeant->Next())!=0)
{
Int_t mod = (Int_t) gmdc->getModule();
Int_t lay = (Int_t) gmdc->getLayer();
if (gmdc->getTrack()==trknb && mod==0 && lay==0)
{
ParticleSeenInMDC=1;
h->setGLepInMDC(ParticleSeenInMDC);
HTrackInfo* t=(HTrackInfo*) h->getTrackInfoObj();
for (Int_t i=0;i<MAXPARTICLES;i++)
{
if( t->getTrkNb(i)>-1 && t->getTrkNb(i)==trknb)
{
if (t->getMatchedRM(i)==1 || t->getMatchedRT_S(i)==1 ||
t->getMatchedRMT_S(i)==1)
{
t->setGCLepInMDC(i,ParticleSeenInMDC);
break;
}
}
}
}
}
}
return ParticleSeenInMDC;
}
Bool_t HRichCorrelatorSim::finalize() {
HRichCorrelator::finalize();
TFile *f = (TFile*) gHades->getOutputFile();
TString filename("testfile.stat");
if (f){
cout<<((TFile*)f)->GetName()<<endl;
filename = ((TFile*)gHades->getOutputFile())->GetName();
}
filename.Remove(filename.Length()-5, filename.Length());
filename.Append(".stat");
std::ofstream statusOut(filename.Data(),ios::app);
cout<<"--- SIM INFO ---"<<endl;
cout<<"Nb of GEANT particles :"<<ng_Part<<endl;
cout<<"Particle ID/# ... ";
for(Int_t n=0;n<MAXPARIDS;n++)
{
if(ng_ParId[n]>0) cout<<n<<"/"<<ng_ParId[n]<<" ";
}
cout<<endl;
if(ngNb_RW>0.) cout<<"Avrg Rich Weight :"<<fg_RW/ngNb_RW<<endl;
if(ngNb_MW>0.) cout<<"Avrg Mdc Weight :"<<fg_MW/ngNb_MW<<endl;
cout<<"Nb of GEANT confirmed tracklets: "<<ngNb_ConfTracklet<<endl;
cout<<"Nb of fake tracklets: "<<ngNb_Fakes<<endl;
cout<<"Nb of Geant confirmed RM tracklets: "<<ngGNbRMonly<<endl;
cout<<"Nb of Geant confirmed R (T||S) tracklets: "<<ngGNbRTSonly<<endl;
cout<<"Nb of Geant confirmed M (T||S) tracklets: "<<ngGNbMTSonly<<endl;
cout<<"Nb of Geant confirmed RM(T||S) tracklets: "<<ngGNbRMTSonly<<endl;
statusOut<<"--- SIM INFO ---"<<endl;
statusOut<<"Nb of Geant particles :"<<ng_Part<<endl;
statusOut<<"Particle ID/# ... ";
for(Int_t n=0;n<MAXPARIDS;n++)
{
if(ng_ParId[n]>0) statusOut<<n<<"/"<<ng_ParId[n]<<" ";
}
statusOut<<endl;
if(ngNb_RW>0.) statusOut<<"Avrg Rich Weight :"<<fg_RW/ngNb_RW<<endl;
if(ngNb_MW>0.) statusOut<<"Avrg Mdc Weight :"<<fg_MW/ngNb_MW<<endl;
statusOut<<"Nb of GEANT confirmed tracklets: "<<ngNb_ConfTracklet<<endl;
statusOut<<"Nb of fake tracklets: "<<ngNb_Fakes<<endl;
statusOut<<"Nb of Geant confirmed RM tracklets: "<<ngGNbRMonly<<endl;
statusOut<<"Nb of Geant confirmed R (T||S) tracklets: "<<ngGNbRTSonly<<endl;
statusOut<<"Nb of Geant confirmed M (T||S) tracklets: "<<ngGNbMTSonly<<endl;
statusOut<<"Nb of Geant confirmed RM(T||S) tracklets: "<<ngGNbRMTSonly<<endl;
statusOut.close();
return kTRUE;
}
Int_t HRichCorrelatorSim::isGCorrRing(HTrackInfo *t)
{
Int_t n=0;
Bool_t isCorrRing=kFALSE;
for (Int_t i=0;i<MAXPARTICLES;i++)
{
if( t->getTrkNb(i)>-1 )
{
if (t->getMatchedRM(i)==1 || t->getMatchedRT_S(i)==1 ||
t->getMatchedRMT_S(i)==1)
{
if (t->getParId(i)==2 || t->getParId(i)==3) n++;
isCorrRing=kTRUE;
}
} else break;
}
if (isCorrRing) return n;
else return -1;
}
Int_t HRichCorrelatorSim::isGRing(HHitMatchSim *h)
{
Int_t n=0;
HRichHitSim* r=0;
if(h->getRichInd()>-1) r = ((HRichHitSim*)getRichHitCat()
->getObject(h->getRichInd()));
else return -1;
Int_t t1,t2,t3,w1,w2,w3;
t1=t2=t3=w1=w2=w3=-1;
if(r)
{
t1=r->track1;t2=r->track2;t3=r->track3;
w1=r->weigTrack1;w2=r->weigTrack2;w3=r->weigTrack3;
Int_t p1,p2,p3;p1=p2=p3=-1;
if (t1>-1) p1=HRichUtilFunc::getParID(t1,(HLinearCategory*)
getGeantKineCat());
if (t2>-1) p2=HRichUtilFunc::getParID(t2,(HLinearCategory*)
getGeantKineCat());
if (t3>-1) p3=HRichUtilFunc::getParID(t3,(HLinearCategory*)
getGeantKineCat());
if (p1==2 || p1==3) n++;
if (p2==2 || p2==3) n++;
if (p3==2 || p3==3) n++;
}
else Error("HRichCorrelatorSim::isGRing","no rich hit found");
return n;
}
Last change: Sat May 22 13:08:29 2010
Last generated: 2010-05-22 13:08
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.