1 #include "SineSubtractCache.h" 3 #include "AnitaDataset.h" 6 #include "FilteredAnitaEvent.h" 7 #include "SineSubtractCache.h" 8 #include "FilterStrategy.h" 9 #include "RawAnitaHeader.h" 10 #include "TDirectory.h" 13 const TString ssrTreeName =
"sineSubResultTree";
16 return TString::Format(
"ssr_%d_%d", (
int)pol, ant);
19 TString UCorrelator::SineSubtractCache::fileName(
const char* specDir, UInt_t hash, Int_t run){
20 int av = AnitaVersion::get();
21 return TString::Format(
"%s/sineSubResults_%u_anita%d_run%d.root", specDir, hash, av, run);
25 void UCorrelator::SineSubtractCache::makeCache(
int run, SineSubtractFilter* ssf){
27 UCorrelator::SineSubtractFilter::setUseCache(
false);
30 const char* ssDesc = ssf->description();
32 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ <<
", can't cache or use cached results without SineSubtract description!" << std::endl;
35 UInt_t hash = TString(ssDesc).Hash();
37 const char* specDir = getenv(
"UCORRELATOR_SPECAVG_DIR");
39 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ <<
", can't cache or use cached results without UCORRELATOR_SPECAVG_DIR environment variable!" << std::endl;
43 std::cout <<
"Info in " << __PRETTY_FUNCTION__ <<
", will generate cached sine subtraction results!" << std::endl;
49 TFile* fOut =
new TFile(fileName(specDir, hash, run),
"recreate");
50 TTree* tOut =
new TTree(ssrTreeName, ssrTreeName);
51 UInt_t eventNumber = 0;
52 tOut->Branch(
"eventNumber", &eventNumber);
55 for(
int ant=0; ant < NUM_SEAVEYS; ant++){
56 tOut->Branch(branchName(pol, ant), &results[pol][ant]);
62 const double deltaPrint = double(n)/1000;
64 for(
int entry=0; entry < d.N(); entry++){
71 for(
int ant=0; ant < NUM_SEAVEYS; ant++){
74 results[pol][ant] = ssr;
78 eventNumber = d.header()->eventNumber;
80 if(entry >= nextPrint){
82 int m = nm*nextPrint/n;
83 fprintf(stderr,
"\r%4.2f %% complete", 100*nextPrint/n);
85 for(
int i=0; i < m; i++) std::cerr <<
"=";
86 for(
int i=m; i < nm; i++) std::cerr <<
" ";
88 nextPrint += deltaPrint;
89 if(nextPrint >= n){std::cerr << std::endl;}
93 tOut->BuildIndex(
"eventNumber");
115 : fDebug(false), fFile(NULL), fTree(NULL), fDescHash(0), fSpecDir(), fCurrentRun(-1), fLastAttemptedRun(-1), fLastEventNumber(0)
120 for(
int ant=0; ant < NUM_SEAVEYS; ant++){
121 results[pol][ant] = NULL;
126 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ <<
", can't cache or use cached results without SineSubtract description!" << std::endl;
129 fDescHash = TString(ssDesc).Hash();
131 const char* specDir = getenv(
"UCORRELATOR_SPECAVG_DIR");
133 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ <<
", can't cache or use cached results without UCORRELATOR_SPECAVG_DIR environment variable!" << std::endl;
143 UCorrelator::SineSubtractCache::~SineSubtractCache(){
159 if(eventNumber != fLastEventNumber){
161 if(run!=fLastAttemptedRun){
165 Int_t entry = fTree->GetEntryNumberWithIndex(eventNumber);
167 fTree->GetEntry(entry);
169 if(eventNumber != fLastEventNumber){
170 std::cerr <<
"Warning in " << __PRETTY_FUNCTION__ <<
", loaded sine subtract cache: run = " << fCurrentRun <<
", eventNumber requested = " 171 << eventNumber <<
", but eventNumber read = " << fLastEventNumber << std::endl;
175 static int numEntryWarnings = 0;
176 const int maxEntryWarnings = 20;
177 if(numEntryWarnings < maxEntryWarnings || fDebug){
178 std::cerr <<
"Warning " << (numEntryWarnings+1) <<
" of " << maxEntryWarnings <<
" in " << __PRETTY_FUNCTION__ <<
", can't find entry " 179 << entry <<
" in " << fTree->GetName() <<
" in file " << fFile->GetName()
180 <<
" for eventNumber " << eventNumber << std::endl;
187 static int numTreeWarnings = 0;
188 const int maxTreeWarnings = 20;
189 if(numTreeWarnings < maxTreeWarnings || fDebug){
190 std::cerr <<
"Warning " << (numTreeWarnings+1) <<
" of " << maxTreeWarnings <<
" in " << __PRETTY_FUNCTION__ <<
", can't find " 191 << ssrTreeName <<
" in file " << fFile->GetName() << std::endl;
197 return results[pol][ant];
202 void UCorrelator::SineSubtractCache::loadRun(Int_t run){
204 if(fSpecDir.Length() > 0 && fDescHash > 0){
211 const TString theRootPwd = gDirectory->GetPath();
212 TString fName = fileName(fSpecDir, fDescHash, run);
213 fFile = TFile::Open(fName,
"read");
215 fTree = (TTree*) fFile->Get(ssrTreeName);
217 fTree->SetBranchAddress(
"eventNumber", &fLastEventNumber);
220 for(
int ant=0; ant < NUM_SEAVEYS; ant++){
221 fTree->SetBranchAddress(branchName(pol, ant), &results[pol][ant]);
224 fTree->BuildIndex(
"eventNumber");
229 std::cerr <<
"Loaded first entry in run " << fCurrentRun <<
", which has eventNumber " << fLastEventNumber << std::endl;
231 gDirectory->cd(theRootPwd);
234 std::cerr <<
"Error in " << __PRETTY_FUNCTION__ <<
", couldn't open file " << fName << std::endl;
236 fLastAttemptedRun = run;
A filter strategy defines the sets of filters that are used and provides some introspection abilities...
SineSubtractCache(const char *descr)
This class is intended to store all the necessary data about an ANITA event for filtering and analysi...
enum AnitaPol::EAnitaPol AnitaPol_t
Polarisation enumeration.
static int getRunContainingEventNumber(UInt_t eventNumber)
Get the run that contains the eventNumber.
void addOperation(FilterOperation *f, bool enable_output=false)