#include "PndFtsHoughTrackerTask.h" #include #include // FTS #include "PndGeoFtsPar.h" #include "PndFtsTube.h" #include "PndFtsMapCreator.h" #include "PndFtsHit.h" #include "FairHit.h" // magnetic field #include "FairField.h" // (Hough) tracking #include "PndFtsHoughTrackFinder.h" #include "PndFtsHoughTrackFinderQA.h" #include "PndFtsHoughSpace.h" #include "PndTrackCand.h" #include "PndTrack.h" #include "FairTrackParP.h" #include "PndFtsHoughTrackCand.h" // histogramming / plotting #include "TH1.h" #include "TH2.h" #include "TGraph.h" // peak finder #include "TSpectrum2.h" // root IO #include "FairRunAna.h" #include "FairRootManager.h" #include "FairRuntimeDb.h" #include "FairTask.h" #include "TString.h" // TODO this list can probably be shorter //#include "PndDetectorList.h" // Root includes #include "TROOT.h" #include "TString.h" #include "TClonesArray.h" #include "TParticlePDG.h" // framework includes #include "FairRootManager.h" #include "FairRun.h" #include "FairRuntimeDb.h" #include "FairRunAna.h" #include "TObjectTable.h" #include "PndFtsMapCreator.h" using std::cout; using std::endl; // ---- Default constructor ------------------------------------------- PndFtsHoughTrackerTask::PndFtsHoughTrackerTask(Int_t verbose, Bool_t persistence) : FairTask("PndFtsHoughTrackerTask", verbose), fLogger(FairLogger::GetLogger()), fPersistence(persistence), fFtsBranchId(0), fFtsHitArray(0), fFtsMcPoints(0), fFtsParameters(0), fFtsTubeArray(0), fField(0), fTracksArrayName("FTSTrkHough"), fTrackCands(0), fTracks(0), fSaveDebugInfo(kFALSE), fEventNr(0) // fOutFile(0), // fHoughTrackCands(0), { if(33) fLogger->Info(MESSAGE_ORIGIN,"Destructor of PndFtsHoughTrackerTask"); // TODO Is that correct?!? // delete fHoughTrackCands; delete fTrackCands; delete fTracks; // fOutFile->Close(); } // ---- Initialisation ---------------------------------------------- void PndFtsHoughTrackerTask::SetParContainers() { if(fVerbose>3) fLogger->Info(MESSAGE_ORIGIN,"SetParContainers of PndFtsHoughTrackerTask"); // FTS parameters FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb(); fFtsParameters=(PndGeoFtsPar*)(rtdb->getContainer("PndGeoFtsPar")); } // ---- Init ---------------------------------------------------------- InitStatus PndFtsHoughTrackerTask::Init() { if(fVerbose>3) Info("Init","Initilization of PndFtsHoughTrackerTask"); // Get a handle from the IO manager FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { fLogger->Fatal(MESSAGE_ORIGIN,"RootManager not instantiated, return!"); return kFATAL; } // Get a pointer to the previous already existing data level /* = (TClonesArray*) ioman->GetObject("InputDataLevelName"); if ( ! ) { fLogger->Error(MESSAGE_ORIGIN,"No InputDataLevelName array!\n PndFtsHoughTrackerTask will be inactive"); return kERROR; } */ // Create the TClonesArray for the output data and register // it in the IO manager /* = new TClonesArray("OutputDataLevelName", 100); ioman->Register("OutputDataLevelName","OutputDataLevelName",,kTRUE); */ // Do whatever else is needed at the initilization stage // Create histograms to be filled // initialize variables // FTS Hits fFtsHitArray= (TClonesArray *)ioman->GetObject("FTSHit"); if ( ! fFtsHitArray ) { fLogger->Info(MESSAGE_ORIGIN,"No FTSHit array!"); return kERROR; } fFtsMcPoints = dynamic_cast (ioman->GetObject("FTSPoint")); if ( ! fFtsMcPoints ) { fLogger->Info(MESSAGE_ORIGIN,"No McPoints array!"); return kERROR; } // FTS Branch fFtsBranchId = ioman->GetBranchId("FTSHit"); // FTS Tube Array PndFtsMapCreator mapperFts(fFtsParameters); fFtsTubeArray = mapperFts.FillTubeArray(); // B field if(fVerbose>3) Info("Init","Try to get B field."); fField = FairRunAna::Instance()->GetField(); if ( ! fField ) { if(fVerbose>3) fLogger->Info(MESSAGE_ORIGIN,"No fField array!"); return kERROR; } // Debugging // if (fSaveDebugInfo){ // InitOutFileForDebugging(); // } // FIXME this caused trouble, but I don't need it // fHoughTrackCands = new TClonesArray("PndFtsHoughTrackCand"); // ioman->Register("FTSTrkDebugCand", "HoughTrackCand", fHoughTrackCands, fSaveDebugInfo); //fHoughSpaces = new TClonesArray("PndFtsHoughSpace"); //ioman->Register("FTSTrkDebugHS", "HoughSpaces", fHoughSpaces, fSaveDebugInfo); // Output fTrackCands = new TClonesArray("PndTrackCand"); fTracks = new TClonesArray("PndTrack"); ioman->Register(fTracksArrayName,"FTSTrk", fTracks, fPersistence); // for PndTrack ioman->Register(fTracksArrayName+"Cand","FTSTrk", fTrackCands, fPersistence); // for PndTrackCand // TODO Is that correct, should it not be FTSTrkCand or something? if(3GetOutFile(); // if (0==fOutFile) // { // std::cout << "InitOutFileForDebugging: Cannot get outfile.\n"; // } // else // { // fOutFile->cd(); // fOutFile->mkdir("PndFtsHoughTrackerTask"); // std::cout << "InitOutFileForDebugging: Outfile initialised for debugging output.\n"; // } //} //void PndFtsHoughTrackerTask::AddNewEventToOutFileForDebugging(UInt_t eventNr){ // fOutFile = FairRootManager::Instance()->GetOutFile(); // if (0==fOutFile) // { // std::cout << "AddNewEventToOutFileForDebugging: Cannot get outfile.\n"; // } // else // { // fOutFile->cd(); // fOutFile->cd("PndFtsHoughTrackerTask"); // fOutFile->mkdir(""+eventNr); // } //} // ---- ReInit ------------------------------------------------------- InitStatus PndFtsHoughTrackerTask::ReInit() { InitStatus stat=kSUCCESS; if(3Info(MESSAGE_ORIGIN,"Re- Initilization of PndFtsHoughTrackerTask"); return stat; } const TVector3 PndFtsHoughTrackerTask::GetFtsHitPosErrors(const PndFtsHit *const ftsHit) const { const PndFtsTube *const tube = GetFtsTube(ftsHit); const Double_t sizeSigmaCoeff = 1.5; // TODO Check value const Double_t rhoError = tube->GetRadIn()/sizeSigmaCoeff; const Double_t zError = tube->GetHalfLength()/sizeSigmaCoeff; // TODO might need additional factor TVector3 hitPosErrors(rhoError,rhoError,zError); return hitPosErrors; } const TMatrixT PndFtsHoughTrackerTask::GetFtsHitCovMatrix(const PndFtsHit *const ftsHit) const { const PndFtsTube *const tube = GetFtsTube(ftsHit); const Double_t sizeSigmaCoeff = 1.5; // TODO Check value const Double_t rhoError = tube->GetRadIn()/sizeSigmaCoeff; const Double_t zError = tube->GetHalfLength()/sizeSigmaCoeff; // TODO might need additional factor TMatrixT rotationMatrix = tube->GetRotationMatrix(); TMatrixT unrotatedCovMatrix(3,3); // initialize with 0 for (Int_t firstIdx=0; firstIdx < 3; ++firstIdx){ for (Int_t secondIdx=0; secondIdx < 3; ++secondIdx){ unrotatedCovMatrix[firstIdx][secondIdx] = 0; } } unrotatedCovMatrix[0][0] = pow(rhoError, 2); unrotatedCovMatrix[1][1] = pow(rhoError, 2); unrotatedCovMatrix[2][2] = pow(zError, 2); TMatrixT rotatedCovMatrix = rotationMatrix*unrotatedCovMatrix; rotatedCovMatrix *= rotationMatrix.Transpose(rotationMatrix); return rotatedCovMatrix; } // ---- Exec ---------------------------------------------------------- void PndFtsHoughTrackerTask::Exec(Option_t* option) { if(1Delete(); fTracks->Delete(); // fHoughTrackCands->Delete(); //fHoughSpaces->Delete(); CheckForDuplicateFtsHits(); if(3Print(); std::cout << '\n'; } myCand->CalcTimeStamp(); // TODO Why is this needed? if (1GetTimeStamp() == 0){ myTrack->SetTimeStamp(0.0001 * (iFoundTrack+1)); myCand->SetTimeStamp(0.0001 * (iFoundTrack+1)); } else { myTrack->SetTimeStamp(myCand->GetTimeStamp()); myTrack->SetTimeStampError(myCand->GetTimeStampError()); } myTrack->SetLink(FairLink("FTSHoughTrackCand", iFoundTrack)); myTrack->SetTrackCandRef(myCand); if (1Print(); } } fTrackCands->Sort(); fTracks->Sort(); if(3Delete(); fTracks->Delete(); // fHoughTrackCands->Delete(); } // ---- Finish -------------------------------------------------------- void PndFtsHoughTrackerTask::Finish() { if(3Fatal(MESSAGE_ORIGIN,"RootManager not instantiated, return!"); } ioman->Write(); if(3GetEntriesFast()); } ClassImp(PndFtsHoughTrackerTask)