//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of resCalc // Uses existing GFTracks as reference and calculates // residua in XY for CdcHits. // // Environment: // Software NOT developed for the PANDA Detector at FAIR. // // Author List: // Sverre Doerheim(adapting author) // // Physik Department E18, TUM // //----------------------------------------------------------- #include "TpcTrackCdcHitResCalc.h" #include "TClonesArray.h" #include "TpcCluster.h" #include "TpcResidual.h" #include "TpcRefResidualCollection.h" #include "TpcSPHit.h" #include "TpcAlignmentManager.h" #include "CdcSpacepoint.h" #include "CdcHit.h" #include "GFTools.h" #include "GFTrack.h" #include "GFException.h" #include "GFAbsTrackRep.h" #include "GFRecoHitFactory.h" #include "GFRecoHitProducer.h" #include "RKTrackRep.h" #include #include #include #include #include #include #include #include #include TpcTrackCdcHitResCalc::TpcTrackCdcHitResCalc() : fCdcGFTrackBranchName("CdcTrackPostFit"), fCdcGFHitBranchName("CdcSpacepoint"), fTpcGFTrackBranchName("TpcTrackPostFit"), fCdcHitBranchName("CdcHitBr"), fNRep(-1), fDetID(-1), fAlignedMatching(true), fUseCdcHits(false), fTpcPtCut(0.5), fCdcPtCut(0.5), fTrackdPhiCut(10), fOrigTransfName("tpc"), fAlMan(NULL), cutOnSameCharge(true), cutOnPtRes(true), ptResCut(0.100), fQA("TpcTrackCdcHitResCalcQA.root") { fNExpectedBranches = 3; } TpcTrackCdcHitResCalc::~TpcTrackCdcHitResCalc() { } bool TpcTrackCdcHitResCalc::init() { if(fBranchMap.size() != fNExpectedBranches) { std::cout<<"TpcTrackCdcHitResCalc::init(): "<GetClass()->GetName()); if(type.find(TpcGFTrackRefType)GetClass()->GetName()); if(type.find(CdcGFTrackRefType)GetClass()->GetName()); if(type.find(cdcSPhitType)GetClass()->GetName()); if(type.find(cdcHitType)GetEntriesFast(); // GF Referencetrackfit loop for(unsigned int irtr=0; irtr=0){ tpcRep = iTpcTrack->getTrackRep(fNRep); }else{ tpcRep = iTpcTrack->getCardinalRep(); } if(tpcRep->getStatusFlag()!=0){ continue; } double tpcCharge=tpcRep->getCharge(); TVector3 tpcMom=tpcRep->getMom(); TVector3 tpcPos=tpcRep->getPos(); fQA.fillBasicHists("tpc",tpcMom,tpcPos,tpcCharge); fQA.fillBasicHists("tpc",tpcMom,tpcPos,0); if(tpcMom.Perp()getLastPlane(); RKTrackRep* lastTpcRep=(RKTrackRep*)tpcRep->clone(); lastTpcRep->setData(lastTpcRep->getLastState(),tpcLastPl, &lastTpcRep->getLastCov(),lastTpcRep->getAuxInfo(lastTpcRep->getReferencePlane())); tpcMom=((GFAbsTrackRep*)lastTpcRep)->getMom(); tpcPos=((GFAbsTrackRep*)lastTpcRep)->getPos(); TMatrixD tpcCov=((GFAbsTrackRep*)lastTpcRep)->getCov(); if(tpcMom.Perp()extrapolateToCylinder(15,tpcPos,tpcMom); }catch(GFException& ex){ std::cout<<"TpcRefGFTrackResCalc::calc(): Error during TPC extrap to cylinder: \n" <<" "<GetEntriesFast(); for(unsigned int itr=0;itrgetCardinalRep(); double cdcCharge=cdcRep->getCharge(); TVector3 cdcMom, cdcPos; TMatrixDSym cdcCov_; cdcRep->getPosMomCov(cdcPos,cdcMom,cdcCov_); fQA.fillBasicHists("cdc",cdcMom,cdcPos,cdcCharge); fQA.fillBasicHists("cdc",cdcMom,cdcPos,0); //Only consider cases where tpc and cdc have the same charge if(cdcCharge*tpcCharge<0 and cutOnSameCharge){ continue; } if(cdcMom.Perp()getStatusFlag()!=0){ continue; } try{ cdcRep->extrapolateToCylinder(15,cdcPos,cdcMom); }catch(GFException& ex){ std::cout<<"TpcRefGFTrackResCalc::calc(): Error during extrap to cylinder mom: \n" <<" "<(this->fTrackdPhiCut/2)) or (fabs(CdcTpcMatchingQA::phiDifference(cdcMom.Phi(),tpcMom.Phi()))>this->fTrackdPhiCut)){ continue; } if((fabs(cdcMom.Perp()-tpcMom.Perp())>ptResCut) and cutOnPtRes){ continue; } fQA.fillMatchingHists(tpcMom,tpcPos,cdcMom,cdcPos,true,0); fQA.fillMatchingHists(tpcMom,tpcPos,cdcMom,cdcPos,true,cdcCharge); //loop over hits from matched track GFTrackCand cand=iCdcTrack->getCand(); unsigned int nHits = cand.getNHits(); for(int iHit=0;iHitAt(hitId); if(recoHit==NULL){ std::cout<<"nooooooooooooooooooooooooooooooooo "<GetEntries()< cov(3,3) ; if(fUseCdcHits){ int iCl=recoHit->getHitID(); CdcHit* cl= (CdcHit*) fCdcHitArray->At(iCl); if(cl==0){ std::cout<<"no cluster at id: "<GetEntriesFast()<GetEntriesFast()<GetHitPos(); TVector3 sigX = cl->GetXposErr(); TVector3 sigY = cl->GetYposErr(); TVector3 sigZ = cl->GetZposErr(); cov[0][0] = sigX.X()*sigX.X(); cov[1][1] = sigY.Y()*sigY.Y(); cov[2][2] = sigZ.Z()*sigZ.Z(); }else{ TVectorT rc = ((GFAbsRecoHit*)recoHit)->getRawHitCoord(); cov =((GFAbsRecoHit*)recoHit)->getRawHitCov(); hPos = TVector3(rc[0], rc[1], rc[2]); if(hPos.Perp()>30){ continue; } double tracklength=0; bool ok=true; TVector3 poca, norm; TVector3 pos1,mom1; TMatrixDSym cov6; try { tpcRep->extrapolateToCylinder(hPos.Perp(),poca,norm); //TVectorT dummy; GFDetPlane plane(poca,norm); tracklength=tpcRep->extrapolate(plane); tpcRep->getPosMomCov(pos1,mom1,cov6); } catch(GFException& ex) { std::cout<<"TpcRefGFTrackResCalc::calc(): Error during extrapolation: \n" <<" "<setResXYZ(poca-hPos); theRes->setRefPos(poca); theRes->setHitPos(hPos); theRes->setTrackDir(mom1.Unit()); //TODO, use correct assignment (cluster/SPHit) if(fUseCdcHits){ theRes->setHitIndex(recoHit->getHitID()); }else{ theRes->setHitIndex(hitId); } TMatrixDSym cov3=cov6.GetSub(0,2,0,2); //cov3.Print(); theRes->setHitCov(cov); theRes->setTrackCov(cov3); theRes->setTrackLength(tracklength); theRes->setCharge(cdcCharge); fResults.back()->addResidual(theRes); } } }//end Hit loop }//end GFTrack loop delete lastTpcRep; }//end refGFTrack loop } void TpcTrackCdcHitResCalc::writeHists(){ fQA.writeHists(); } // void TpcTrackCdcHitResCalc::fillRefHistos(TVector3 refMom,TVector3 refPos){ // histMap["histRefMom"]->Fill(refMom.Mag()); // histMap["histRefPT"]->Fill(refMom.Perp()); // } // void TpcTrackCdcHitResCalc::fillTrackHistos(TVector3 mom,TVector3 pos){ // histMap["histCdcMom"]->Fill(mom.Mag()); // histMap["histCdcPT"]->Fill(mom.Perp()); // } // void TpcTrackCdcHitResCalc::fillMatchingHistos(TVector3 refMom, TVector3 refPos, TVector3 mom, TVector3 pos){ // histMap["histMomRes"]->Fill(mom.Mag()-refMom.Mag()); // histMap["histMomResVMom"]->Fill(mom.Mag(),mom.Mag()-refMom.Mag()); // histMap["histPTRes"]->Fill(mom.Perp()-refMom.Perp()); // histMap["histPTResVPT"]->Fill(mom.Perp(),mom.Perp()-refMom.Perp()); // } ClassImp(TpcTrackCdcHitResCalc)