#include #include #include #include #include #include #include #include #include #include "IOARuntimeParameters.hxx" #include "IReconFGDHacked.hxx" #include "fgdUtils.hxx" /// Initialization. This method checks the DummyDatabase in /// order to decide which methods to use for matching and /// for FGD isolated reconstruction. IReconFGDHacked::IReconFGDHacked() : COMET::IAlgorithm("TFGDRecon") { matcher = new IFgdTpcNoMatcher(); // No matching // Choice of which iso-recon algorithm to use is controlled by // ReconFGD parameters file. fgdIsoRecon = 0; if ((bool)COMET::IOARuntimeParameters::Get().GetParameterI("oaAlignTools.FGDIsoReconP0DCluster")) { fgdIsoRecon = new IFgdIsoReconP0DCluster(); // P0D Cluster iso recon std::cout<<"Using P0D clustering..."<FinishUp(); } void AddTimeBinBoundary(COMET::IHandle Result, COMET::IHandle hits){ // Get the interval boundaries std::pair time_bin_boundary = fgdUtils::GetTimeBinBoundary(*hits); // Save boundaries using IRealDatum COMET::IRealDatum* binStartTime = new COMET::IRealDatum("binStartTime","binStartTime"); binStartTime->SetValue(time_bin_boundary.first); Result->AddDatum(binStartTime); COMET::IRealDatum* binEndTime = new COMET::IRealDatum("binEndTime","binEndTime"); binEndTime->SetValue(time_bin_boundary.second); Result->AddDatum(binEndTime); } /// This is the main FGD reconstruction program. /// It basically calls two distinct reconstruction steps. /// /// -> Step 1 involves the matching of TPC tracks to FGD hits. /// There are several ways this can be done (including /// not being done at all). /// -> Step 2 involves fitting the remaining FGD hits. /// Currently this is just implemented with a Hough transform /// pattern recognition. Call this "Iso" reconstruction. /// COMET::IHandle IReconFGDHacked::Process(const COMET::IAlgorithmResult& in){ COMET::ICOMETEvent& event = GetEvent(); COMET::IHandle fgd_raw = event.GetHitSelection("fgd"); if (!fgd_raw) return CreateResult(); // Return empty, but valid result. // time bin hits (binner does hit filtering too now!) TFGDHitBins bins = timeBinner->BinHits(fgd_raw); COMET::IHandle CumulativeResult(CreateResult()); // Add TPC tracks int nbin = 0; for (TFGDHitBins::iterator bin = bins.begin(); bin != bins.end(); bin++) { COMET::IAlgorithmResult input; input.AddHitSelection(new COMET::IHitSelection(**bin)); // Do the matching reconstruction COMET::IHandle MatcherResult = matcher->Process(input); if(!MatcherResult) continue; // Add the full set of hits to result, so that they can be used // in next step. (do we really need to do this?) MatcherResult->AddHitSelection(new COMET::IHitSelection(**bin)); // Do the fgd-iso reconstruction (this will always return a valid handle) COMET::IHandle ReconResult = fgdIsoRecon->Process(*MatcherResult); // Copy results of TPC/FGD matching and iso-recon into final container. COMET::IHandle FinalResult(CreateResult()); fgdUtils::MergeResults(FinalResult, MatcherResult); fgdUtils::MergeResults(FinalResult, ReconResult); // Now that we have lists of used hits from both the isorecon // and matcher, merge them into a total ReconFGD hit used // list. COMET::IHandle matchedHits = MatcherResult->GetHitSelection("matchedFgdHits"); COMET::IHandle isoreconedHits = ReconResult->GetHitSelection("usedFgdIsoreconHits"); COMET::IHitSelection *usedHits = fgdUtils::combineHitSelections(matchedHits, isoreconedHits); usedHits->SetName("used"); FinalResult->AddHitSelection(usedHits); // Make sure we have a container of unused hits, even if it's empty // This is a bit of a HACK COMET::IHandle unusedHits = FinalResult->GetHitSelection("unused"); if (!unusedHits) FinalResult->AddHitSelection(new COMET::IHitSelection("unused")); // Execute FGD iso-recon PID and save results if (pid) { COMET::IHandle PidResult = pid->Process(*FinalResult); if (PidResult) { COMET::IHandle fgdPid = PidResult->GetResultsContainer("FGDPids"); if (fgdPid) FinalResult->AddResultsContainer(new COMET::IReconObjectContainer(*fgdPid)); } } // Save the information about the boundaries of this time bin AddTimeBinBoundary(FinalResult, *bin); // Merge the results from this time bin into global result fgdUtils::MergeResults(CumulativeResult, FinalResult); // Save the results for this particular time bin as separate algorithm result char result_name[100]; sprintf(result_name,"ReconFGD_timebin%i",nbin); event.AddFit(FinalResult, result_name); nbin++; } return CumulativeResult; } /// This is the main FGD reconstruction program. /// It basically calls two distinct reconstruction steps. /// /// -> Step 1 involves the matching of TPC tracks to FGD hits. /// There are several ways this can be done (including /// not being done at all). /// -> Step 2 involves fitting the remaining FGD hits. /// Currently this is just implemented with a Hough transform /// pattern recognition. Call this "Iso" reconstruction. /// COMET::IHandle IReconFGDHacked::HackedProcess(COMET::IHandle fgd_raw){ COMET::ICOMETEvent& event = GetEvent(); if (!fgd_raw) return CreateResult(); // Return empty, but valid result. // time bin hits (binner does hit filtering too now!) TFGDHitBins bins = timeBinner->BinHits(fgd_raw); COMET::IHandle CumulativeResult(CreateResult()); // Add TPC tracks int nbin = 0; for (TFGDHitBins::iterator bin = bins.begin(); bin != bins.end(); bin++) { COMET::IAlgorithmResult input; input.AddHitSelection(new COMET::IHitSelection(**bin)); // Do the matching reconstruction COMET::IHandle MatcherResult = matcher->Process(input); if(!MatcherResult) continue; // Add the full set of hits to result, so that they can be used // in next step. (do we really need to do this?) MatcherResult->AddHitSelection(new COMET::IHitSelection(**bin)); // Do the fgd-iso reconstruction (this will always return a valid handle) COMET::IHandle ReconResult = fgdIsoRecon->Process(*MatcherResult); // Copy results of TPC/FGD matching and iso-recon into final container. COMET::IHandle FinalResult(CreateResult()); fgdUtils::MergeResults(FinalResult, MatcherResult); fgdUtils::MergeResults(FinalResult, ReconResult); // Now that we have lists of used hits from both the isorecon // and matcher, merge them into a total ReconFGD hit used // list. COMET::IHandle matchedHits = MatcherResult->GetHitSelection("matchedFgdHits"); COMET::IHandle isoreconedHits = ReconResult->GetHitSelection("usedFgdIsoreconHits"); COMET::IHitSelection *usedHits = fgdUtils::combineHitSelections(matchedHits, isoreconedHits); usedHits->SetName("used"); FinalResult->AddHitSelection(usedHits); // Make sure we have a container of unused hits, even if it's empty // This is a bit of a HACK COMET::IHandle unusedHits = FinalResult->GetHitSelection("unused"); if (!unusedHits) FinalResult->AddHitSelection(new COMET::IHitSelection("unused")); // Execute FGD iso-recon PID and save results if (pid) { COMET::IHandle PidResult = pid->Process(*FinalResult); if (PidResult) { COMET::IHandle fgdPid = PidResult->GetResultsContainer("FGDPids"); if (fgdPid) FinalResult->AddResultsContainer(new COMET::IReconObjectContainer(*fgdPid)); } } // Save the information about the boundaries of this time bin AddTimeBinBoundary(FinalResult, *bin); // Merge the results from this time bin into global result fgdUtils::MergeResults(CumulativeResult, FinalResult); // Save the results for this particular time bin as separate algorithm result char result_name[100]; sprintf(result_name,"ReconFGD_timebin%i",nbin); event.AddFit(FinalResult, result_name); nbin++; } return CumulativeResult; }