NCPOTCounter Class Reference

Calculates POT contained in a set of uDSTs. More...

#include <NCPOTCounter.h>

List of all members.

Public Member Functions

 NCPOTCounter ()
void Config (const Registry &r, std::vector< BeamType::BeamType_t > beamIndex, std::vector< NC::RunUtil::ERunType > runsToUse)
void SetPOTValues (std::map< NCBeam::Info, double > &pot, Detector::Detector_t det, NCType::EFileType fileType, NCType::EDataMC dataMC)
double GetPOTValue (Detector::Detector_t det, NCType::EFileType fileType, NCType::EDataMC dataMC, BeamType::BeamType_t beamType, NC::RunUtil::ERunType run)
std::vector< TString > GetListOfFiles (NCBeam::Info info, NCType::EFileType fileType, Detector::Detector_t det, NCType::EDataMC dataMC) const
 List of stripped uDSTs under fDataMCPath for a particular run period.
void SetMCExposureForBeam (NCBeam::Info beam, double pot)

Private Types

typedef std::map< NCBeam::Info,
double > 
POTMap
typedef std::map< NCBeam::Info,
double > 
ScaleMap
typedef std::vector< int > POTKey
typedef std::map< POTKey, POTMapCache

Private Member Functions

int GetRunsInFile (TString fileName)
 Get the number of runs contained in fileName.
double GetPOTForSingleFile (TString fileName, NCType::EFileType fileType, Detector::Detector_t det, NCType::EDataMC dataMC, int bt, int nRunsOffset) const
 Get the POT for a file fileName and additional details.
TString FileDesignator (NCType::EFileType fileType, Detector::Detector_t det, NCType::EDataMC dataMC) const
 Can be "data", "blind", "tau", "electron", "mc".
TString HistName (NCType::EFileType fileType, NCType::EDataMC dataMC) const
 Can be "dataPOT" or "mcPOT".
double POTPerRun (int bt, Detector::Detector_t det, NCType::EFileType fileType) const
 POT per subrun for near detector, POT per run for far.
int MockFileSubRun (TString fileName) const

Private Attributes

TString fDataMCPath
TString fMockDataSet
bool fMockData
bool fMCAsData
int fRunLimits [3][2]
 [detector][dataMC]
std::vector< BeamType::BeamType_tfBeamIndex
std::vector
< NC::RunUtil::ERunType
fRunsToUse
std::map< NCBeam::Info, double > fFarMCExposures
 Allows different MC configurations to be scaled to different POT's.
int fMockDataSubRun

Static Private Attributes

static Cache fgCache

Detailed Description

Calculates POT contained in a set of uDSTs.

Definition at line 67 of file NCPOTCounter.h.


Member Typedef Documentation

typedef std::map<POTKey, POTMap> NCPOTCounter::Cache [private]

Definition at line 141 of file NCPOTCounter.h.

typedef std::vector<int> NCPOTCounter::POTKey [private]

Definition at line 139 of file NCPOTCounter.h.

typedef std::map<NCBeam::Info, double> NCPOTCounter::POTMap [private]

Definition at line 101 of file NCPOTCounter.h.

typedef std::map<NCBeam::Info, double> NCPOTCounter::ScaleMap [private]

Definition at line 102 of file NCPOTCounter.h.


Constructor & Destructor Documentation

NCPOTCounter::NCPOTCounter (  ) 

Definition at line 26 of file NCPOTCounter.cxx.

00027 {
00028 }


Member Function Documentation

void NCPOTCounter::Config ( const Registry r,
std::vector< BeamType::BeamType_t beamIndex,
std::vector< NC::RunUtil::ERunType runsToUse 
)
TString NCPOTCounter::FileDesignator ( NCType::EFileType  fileType,
Detector::Detector_t  det,
NCType::EDataMC  dataMC 
) const [private]

Can be "data", "blind", "tau", "electron", "mc".

Definition at line 351 of file NCPOTCounter.cxx.

References fMCAsData, fMockData, fMockDataSet, NCType::kData, NCType::kElectronFile, Detector::kFar, NCType::kMockFile, Detector::kNear, and NCType::kTauFile.

Referenced by GetListOfFiles(), and GetPOTForSingleFile().

00354 {
00355   if(fileType == NCType::kMockFile) return fMockDataSet;
00356 
00357   if(dataMC == NCType::kData && !(fMCAsData || fMockData)){
00358     if(det == Detector::kNear) return "data";
00359     else if(det == Detector::kFar) return "blind";
00360   }
00361 
00362   if(fileType == NCType::kTauFile) return "tau";
00363 
00364   if(fileType == NCType::kElectronFile) return "electron";
00365 
00366   return "mc";
00367 }

vector< TString > NCPOTCounter::GetListOfFiles ( NCBeam::Info  info,
NCType::EFileType  fileType,
Detector::Detector_t  det,
NCType::EDataMC  dataMC 
) const

List of stripped uDSTs under fDataMCPath for a particular run period.

with correct dataMC, beaminfo info and detector det,

Definition at line 221 of file NCPOTCounter.cxx.

References bfld::AsString(), fDataMCPath, FileDesignator(), files, NC::RunUtil::FindRunType(), fMockDataSubRun, Form(), NCBeam::Info::GetBeamType(), NCBeam::Info::GetRunType(), Detector::kFar, NCType::kMockFile, MockFileSubRun(), and runPeriod.

Referenced by NCExtrapolationModule::AddFilesToChain().

00225 {
00226 //   MSG("NCPOTCounter", Msg::kInfo) << "GetListOfFiles(" << bt << ", " << fileType
00227 //                                   << ", " << det << ", " << dataMC << endl;
00228   TDirectory* saveDir = gDirectory;
00229 
00230   vector<TString> ret;
00231 
00232   const TString fileDesignator = FileDesignator(fileType, det, dataMC);
00233   const TString beamType = BeamType::AsString(info.GetBeamType());
00234   const TString runPeriod= Form("run%d", (int)info.GetRunType());
00235   const TString detName = (det == Detector::kFar) ? "far" : "near";
00236 
00237   //have a path to the relevant uDST's.  each uDST has the
00238   //BeamType::AsString() for the beam in its name, also has near
00239   //or far in the name.
00240   //make a TSystemDirectory object to get a list of files in the
00241   //path for the data and mc
00242 
00243   //the files for different beam configurations are in uDST/LXXXzYYYi
00244   //directories.  that is directories named for the beam type
00245   TSystemDirectory dataDir(beamType, fDataMCPath+beamType+"/");
00246   TList* files = dataDir.GetListOfFiles();
00247   assert(files);
00248 
00249   for(int de = 0; de < files->GetEntries(); ++de){
00250     TString fileName = files->At(de)->GetName();
00251 
00252     //Do nothing for "." and ".." entries
00253     if(fileName == "." || fileName == "..") continue;
00254 
00255     //check that this file is the right kind
00256     if(fileName.Contains(beamType) &&
00257        fileName.Contains("strip") &&
00258        fileName.Contains(detName) &&
00259        fileName.Contains(fileDesignator)){
00260 
00261       // Check it's the right run type - this should work for both data and mc
00262       const NC::RunUtil::ERunType fileRunPeriod = NC::RunUtil::FindRunType(fileName);
00263       if(fileRunPeriod != info.GetRunType()) continue;
00264       if(fileType == NCType::kMockFile && fMockDataSubRun != -1){
00265         // For mock data, only add files with subrun requested
00266         int subRun = MockFileSubRun(fileName);
00267         // If it's not the one we want, don't add it to the chain.
00268         //
00269         // subRun==-1 if the file is the one-uDST-per-run type. In
00270         // that case, the fileDesignator check above is enough to tell
00271         // us that we want to use this file, so don't skip it
00272         if(subRun != -1 && subRun != fMockDataSubRun) continue;
00273       }
00274       ret.push_back(fileName);
00275     }//end if the right detector and beam and designator
00276   }//end loop over data files
00277 
00278   delete files;
00279 
00280   saveDir->cd();
00281 
00282   return ret;
00283 }

double NCPOTCounter::GetPOTForSingleFile ( TString  fileName,
NCType::EFileType  fileType,
Detector::Detector_t  det,
NCType::EDataMC  dataMC,
int  bt,
int  nRunsOffset 
) const [private]

Get the POT for a file fileName and additional details.

nRunsOffset is the number of runs that we've previously read from other files, which should be subtracted from the file limit to get the number of runs we should read from *this* file. This is needed to deal with the fact that we have multiple MC files in the near detector

Definition at line 303 of file NCPOTCounter.cxx.

References FileDesignator(), fRunLimits, HistName(), Msg::kInfo, NCType::kMockFile, MockFileSubRun(), MSG, and POTPerRun().

00309 {
00310   //  TDirectory* saveDir = gDirectory;
00311 
00312   TFile tf(fileName);
00313   assert(!tf.IsZombie());
00314   const TString histName = HistName(fileType, dataMC);
00315   const TString fileDesignator = FileDesignator(fileType, det, dataMC);
00316 
00317   TH1F* potHist = (TH1F*)(tf.Get(histName));
00318 
00319   if(fileType==NCType::kMockFile) {
00320     // The one-subrun-per-uDST files have the correct POT stored in
00321     // the dataPOT histogram. The one-run-per-uDST files have to use
00322     // the hardcoded value from POTPerRun
00323     if (MockFileSubRun(fileName) != -1)
00324       return potHist->Integral(0, potHist->GetNbinsX()+1)*1e12;
00325     else return POTPerRun(bt, det, fileType);
00326   }
00327 
00328   MSG("NCPOTCounter", Msg::kInfo) << "  Running on "
00329                                   << fileName << " with "
00330                                   << potHist->GetEntries()
00331                                   << " runs" << endl;
00332 
00333 
00334   //use all pot's for data
00335   if(fileDesignator == "data" || fileDesignator == "blind"){
00336     return potHist->Integral(0, potHist->GetNbinsX()+1)*1e12;
00337   }
00338 
00339   const double potPerRun = POTPerRun(bt, det, fileType);
00340 
00341   const int runLimit = fRunLimits[det][dataMC]-nRunsOffset;
00342   if(runLimit <= potHist->GetEntries()){
00343     return potPerRun*runLimit;
00344   }
00345   else{
00346     return potHist->Integral(0, potHist->GetNbinsX()+1)*1e12;
00347   }
00348 }

double NCPOTCounter::GetPOTValue ( Detector::Detector_t  det,
NCType::EFileType  fileType,
NCType::EDataMC  dataMC,
BeamType::BeamType_t  beamType,
NC::RunUtil::ERunType  run 
)

Definition at line 205 of file NCPOTCounter.cxx.

References SetPOTValues().

00210 {
00211   map<NCBeam::Info, double> pot;
00212 
00213   SetPOTValues(pot, det, fileType, dataMC);
00214 
00215   const NCBeam::Info beamInfo(beamType, run);
00216 
00217   return pot[beamInfo];
00218 }

int NCPOTCounter::GetRunsInFile ( TString  fileName  )  [private]

Get the number of runs contained in fileName.

as given by the pot histogram

Definition at line 285 of file NCPOTCounter.cxx.

00286 {
00287   TFile tf(fileName);
00288   assert(!tf.IsZombie());
00289   TH1F* potHist = (TH1F*)(tf.Get("mcPOT"));
00290   if(!potHist) potHist=(TH1F*)(tf.Get("dataPOT"));
00291   assert(potHist);
00292   // Hopefully this cast does what I want. Why does GetEntries() not return an int? Gah
00293   return int(potHist->GetEntries());
00294 }

TString NCPOTCounter::HistName ( NCType::EFileType  fileType,
NCType::EDataMC  dataMC 
) const [private]

Can be "dataPOT" or "mcPOT".

Definition at line 370 of file NCPOTCounter.cxx.

References fMCAsData, fMockData, NCType::kData, and NCType::kMockFile.

Referenced by GetPOTForSingleFile().

00372 {
00373   if(fileType == NCType::kMockFile ||
00374      (dataMC == NCType::kData && !(fMCAsData || fMockData))) return "dataPOT";
00375 
00376   return "mcPOT";
00377 }

int NCPOTCounter::MockFileSubRun ( TString  fileName  )  const [private]

The subrun number of a mock data file if it is of the one-subrun-per-uDST type, or -1 otherwise

Definition at line 402 of file NCPOTCounter.cxx.

Referenced by GetListOfFiles(), and GetPOTForSingleFile().

00403 {
00404   // Filenames look like:
00405   // "far_mock_L010z185i_F21910001_0000.uDST_strip.root"
00406   //
00407   // ROOT is useless and doesn't support character classes, or
00408   // specifying a number of times to match, so we get this RE
00409   // to find the subrun from the filename.
00410 
00411   TRegexp re("_[0-9][0-9][0-9][0-9]\\.uDST");
00412   int stupidROOT;
00413   int index = re.Index(fileName, &stupidROOT);
00414   if(index != kNPOS) {
00415     // We found a subrun string in the filename, so use that.
00416     TString subRunStr(fileName(index+1, 4));
00417     return subRunStr.Atoi();
00418   } else {
00419     // This will happen for one-uDST-per-run files
00420     return -1;
00421   }
00422 }

double NCPOTCounter::POTPerRun ( int  bt,
Detector::Detector_t  det,
NCType::EFileType  fileType 
) const [private]

POT per subrun for near detector, POT per run for far.

Definition at line 380 of file NCPOTCounter.cxx.

References fBeamIndex, Detector::kFar, NCType::kMockFile, and kPOTNear.

Referenced by GetPOTForSingleFile().

00382 {
00383   //really need to do something better than the next few lines
00384   //to account for changes in MC version
00385 
00386   if(det == Detector::kFar){
00387     if(fileType == NCType::kMockFile) {
00388       const double kPotFarMock = 2.5e20;
00389       return kPotFarMock;
00390     }
00391 
00392     // TODO: Is this a good name for it? If so should go in NCType
00393     const double kPotFarMC = 6.5e20;
00394     return kPotFarMC;
00395   }
00396 
00397   const double ret = kPOTNear[fBeamIndex[bt]];
00398   assert(ret >= 0);
00399   return ret;
00400 }

void NCPOTCounter::SetMCExposureForBeam ( NCBeam::Info  beam,
double  pot 
)

Definition at line 297 of file NCPOTCounter.cxx.

References fFarMCExposures.

Referenced by NCExtrapolationModule::SetMCExposureForBeam().

00298 {
00299   fFarMCExposures[beam] = pot;
00300 }

void NCPOTCounter::SetPOTValues ( std::map< NCBeam::Info, double > &  pot,
Detector::Detector_t  det,
NCType::EFileType  fileType,
NCType::EDataMC  dataMC 
)

pot returns a map of pot's as would otherwise be returned by GetPOTValue

Referenced by GetPOTValue(), NCExtrapolationModule::Run(), and NCDataQualityModule::SetPOTValues().


Member Data Documentation

Definition at line 153 of file NCPOTCounter.h.

Referenced by POTPerRun().

TString NCPOTCounter::fDataMCPath [private]

Definition at line 146 of file NCPOTCounter.h.

Referenced by GetListOfFiles().

std::map<NCBeam::Info, double> NCPOTCounter::fFarMCExposures [private]

Allows different MC configurations to be scaled to different POT's.

Definition at line 156 of file NCPOTCounter.h.

Referenced by SetMCExposureForBeam().

Definition at line 143 of file NCPOTCounter.h.

bool NCPOTCounter::fMCAsData [private]

Definition at line 149 of file NCPOTCounter.h.

Referenced by FileDesignator(), and HistName().

bool NCPOTCounter::fMockData [private]

Definition at line 148 of file NCPOTCounter.h.

Referenced by FileDesignator(), and HistName().

TString NCPOTCounter::fMockDataSet [private]

Definition at line 147 of file NCPOTCounter.h.

Referenced by FileDesignator().

Definition at line 157 of file NCPOTCounter.h.

Referenced by GetListOfFiles().

int NCPOTCounter::fRunLimits[3][2] [private]

[detector][dataMC]

Definition at line 152 of file NCPOTCounter.h.

Referenced by GetPOTForSingleFile().

Definition at line 154 of file NCPOTCounter.h.


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1