Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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,
POTMap
Cache

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::ERunTypefRunsToUse
std::map< NCBeam::Info, double > fFarMCExposures
 Allows different MC configurations to be scaled to different POT's.
int fMockDataSubRun

Static Private Attributes

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.

Referenced by SetPOTValues().

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
 

Definition at line 31 of file NCPOTCounter.cxx.

References fBeamIndex, fDataMCPath, fMCAsData, fMockData, fMockDataSet, fMockDataSubRun, fRunLimits, fRunsToUse, Registry::Get(), and gSystem().

Referenced by NCExtrapolationModule::Config(), and NCDataQualityModule::SetPOTValues().

00034 {
00035   const char* tmps;
00036   int tmpb, tmpi;
00037 
00038   // TODO - this code is copy-pasted from NCExtrapolationModule
00039   if(r.Get("DataMCPath", tmps)){
00040     //for some reason the TSystemDirectory constructor can't resolve
00041     //environmental variables, so just take care of it here
00042     TString temp = tmps;
00043     // Assume the form $ENVVAR/path
00044     if(temp.Contains("$")){
00045       int pos = temp.Index("/"); // find the first /
00046       temp.Resize(pos); // and truncate at it
00047       temp.Remove(TString::kLeading, '$'); // drop the $ off the front
00048       fDataMCPath = tmps; // Copy the original string
00049       // and then replace the part that we think is the environment variable
00050       fDataMCPath.Replace(0, pos, gSystem->Getenv(temp));
00051     }
00052     else fDataMCPath = temp;
00053     // Add a trailing slash so that concatenating the path later will work
00054     if(!fDataMCPath.EndsWith("/")) fDataMCPath += "/";
00055   }
00056 
00057   if(r.Get("MockDataSet", tmps)) fMockDataSet = tmps;
00058   if(r.Get("UseMCAsData", tmpb)) fMCAsData = tmpb;
00059   if(r.Get("UseMockData", tmpb)) fMockData = tmpb;
00060 
00061   if(r.Get("RunLimitNearData", tmpi))
00062     fRunLimits[Detector::kNear][NCType::kData] = tmpi;
00063   if(r.Get("RunLimitFarData", tmpi))
00064     fRunLimits[Detector::kFar][NCType::kData] = tmpi;
00065   if(r.Get("RunLimitNearMC", tmpi))
00066     fRunLimits[Detector::kNear][NCType::kMC] = tmpi;
00067   if(r.Get("RunLimitFarMC", tmpi))
00068     fRunLimits[Detector::kFar][NCType::kMC] = tmpi;
00069 
00070   if(r.Get("MockDataSubRun", tmpi)) fMockDataSubRun = tmpi;
00071 
00072   fBeamIndex = beamIndex;
00073   fRunsToUse = runsToUse;
00074 }

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 det, and fMCAsData.

Referenced by GetListOfFiles(), GetPOTForSingleFile(), and SetPOTValues().

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 BeamType::AsString(), det, fDataMCPath, FileDesignator(), files, NC::RunUtil::FindRunType(), fMockDataSubRun, Form(), NCBeam::Info::GetBeamType(), NCBeam::Info::GetRunType(), MockFileSubRun(), and runPeriod.

Referenced by NCExtrapolationModule::AddFilesToChain(), and SetPOTValues().

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 det, FileDesignator(), fRunLimits, HistName(), MockFileSubRun(), MSG, and POTPerRun().

Referenced by SetPOTValues().

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 det, run(), and 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.

Referenced by SetPOTValues().

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.

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 det, fBeamIndex, 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

Definition at line 77 of file NCPOTCounter.cxx.

References det, fBeamIndex, fDataMCPath, fFarMCExposures, fgCache, FileDesignator(), fRunLimits, fRunsToUse, GetListOfFiles(), GetPOTForSingleFile(), GetRunsInFile(), MSG, and POTKey.

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

00081 {
00082   POTKey key(3);
00083   key[0] = det;
00084   key[1] = fileType;
00085   key[2] = dataMC;
00086 
00087   Cache::iterator it = fgCache.find(key);
00088 
00089   if(it != fgCache.end()){
00090     pot = it->second;
00091     return;
00092   }
00093 
00094 
00095   pot.clear();
00096 
00097   MSG("NCPOTCounter", Msg::kInfo)
00098     << "NCPOTCounter::SetPOTValues:"
00099     << " fDataMCPath = " << fDataMCPath << endl;
00100 
00101 
00102   // Make POT map with an entry for each run/beam type
00103   // combination. If we actually have nonzero POTs for a particular
00104   // combination, it'll get added to the 'pot' map at the end.
00105   map<NCBeam::Info, double> POTtmp;
00106 
00107   for(int r = NC::RunUtil::kRunI; 
00108       r <= NC::RunUtil::kMaxRun; ++r){
00109     for(unsigned int j = 0; j < fBeamIndex.size(); ++j){
00110       NCBeam::Info info(fBeamIndex[j], NC::RunUtil::ERunType(r));
00111       POTtmp[info] = 0.;
00112     }
00113   }
00114 
00115   //loop over the beams/runperiods we're using and fill the pot values
00116   for(unsigned int bt = 0; bt < fBeamIndex.size(); ++bt){
00117     for(unsigned int runIdx = 0; runIdx<fRunsToUse.size(); ++runIdx){
00118       NCBeam::Info info(fBeamIndex[bt], fRunsToUse[runIdx]);
00119 
00120       // The total number of runs we've read from files,
00121       // so we can apply the file limits
00122       int nRunsRead = 0;
00123       
00124       const vector<TString> fileList = GetListOfFiles(info, fileType, det, dataMC);
00125 
00126       for(unsigned int nf = 0; nf < fileList.size(); ++nf){
00127         const TString fileName = fileList[nf];
00128         const double potToAdd = GetPOTForSingleFile(fileName, fileType,
00129                                                     det, dataMC, bt, nRunsRead);
00130         assert(potToAdd >= 0);
00131         
00132         //const int runType = NC::RunUtil::FindRunType(fileName);
00133 
00134         assert(POTtmp.find(info)!=POTtmp.end());
00135         POTtmp[info] += potToAdd;
00136         
00137         MSG("NCPOTCounter", Msg::kInfo) << "  Adding " << potToAdd << " POT to "
00138                                         << FileDesignator(fileType, det, dataMC)
00139                                         << endl;
00140 
00141         nRunsRead += GetRunsInFile(fileName);
00142         // If we've already hit the file limit, stop
00143         if(nRunsRead > fRunLimits[det][dataMC]) break;
00144 
00145       } // end for nf
00146 
00147       
00148       /*
00149         const TString beamType = BeamType::AsString(fBeamIndex[bt]);
00150         MSG("NCPOTCounter", Msg::kInfo) << "POT INFORMATION("
00151         << (det == Detector::kFar ? "far" : "near")
00152         << "): " << endl
00153         << FileDesignator(fileType, det, dataMC)
00154         << " run I POT[" << beamType << "] = "
00155         << POTtmp[0].at(bt)
00156         << " run II POT[" << beamType << "] = "
00157         << POTtmp[1].at(bt)
00158         << endl;
00159       */
00160 
00161       if(POTtmp[info] > 0){
00162         if(dataMC == NCType::kData && fMCAsData){
00163           assert(fFarMCExposures.find(info) != fFarMCExposures.end() &&
00164                  "Did you call set_mc_exposure_for_beam for this beam?");
00165           pot[info] = fFarMCExposures[info];
00166         }
00167         else{
00168           pot[info] = POTtmp[info];
00169         }
00170       }//end if pot > 0 for this combination of run type and beam      
00171      
00172     }//end loop over run types 
00173 
00174     // Now we've looped over all the run periods, add their total to
00175     // the RunAll NCBeam for this beamtype
00176 
00177     double totalPOT=0;
00178 
00179     for(unsigned int n = 0; n < fRunsToUse.size(); ++n){
00180       NCBeam::Info info(fBeamIndex[bt], fRunsToUse[n]);
00181       totalPOT+=pot[info];
00182     }
00183       
00184     const NCBeam::Info infoAll(fBeamIndex[bt], NC::RunUtil::kRunAll);
00185     pot[infoAll] = totalPOT;
00186       
00187   }//end loop over beam types
00188     
00189   for(map<NCBeam::Info, double>::const_iterator it = pot.begin();
00190       it != pot.end(); ++it){
00191     MSG("NCPOTCounter", Msg::kInfo) << "POT INFO: "
00192                                     << (det == Detector::kFar ? "Far" : "Near")
00193                                     << " "
00194                                     << (dataMC == NCType::kMC ? "MC" : "data")
00195                                     << " from \""
00196                                     << FileDesignator(fileType, det, dataMC)
00197                                     << "\" files " << it->first <<  " has "
00198                                     << it->second << " POT" << endl;
00199   }
00200     
00201   fgCache[key] = pot;
00202 }


Member Data Documentation

std::vector<BeamType::BeamType_t> NCPOTCounter::fBeamIndex [private]
 

Definition at line 153 of file NCPOTCounter.h.

Referenced by Config(), POTPerRun(), and SetPOTValues().

TString NCPOTCounter::fDataMCPath [private]
 

Definition at line 146 of file NCPOTCounter.h.

Referenced by Config(), GetListOfFiles(), and SetPOTValues().

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(), and SetPOTValues().

NCPOTCounter::Cache NCPOTCounter::fgCache [static, private]
 

Definition at line 24 of file NCPOTCounter.cxx.

Referenced by SetPOTValues().

bool NCPOTCounter::fMCAsData [private]
 

Definition at line 149 of file NCPOTCounter.h.

Referenced by Config(), FileDesignator(), and HistName().

bool NCPOTCounter::fMockData [private]
 

Definition at line 148 of file NCPOTCounter.h.

Referenced by Config().

TString NCPOTCounter::fMockDataSet [private]
 

Definition at line 147 of file NCPOTCounter.h.

Referenced by Config().

int NCPOTCounter::fMockDataSubRun [private]
 

Definition at line 157 of file NCPOTCounter.h.

Referenced by Config(), and GetListOfFiles().

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

[detector][dataMC]

Definition at line 152 of file NCPOTCounter.h.

Referenced by Config(), GetPOTForSingleFile(), and SetPOTValues().

std::vector<NC::RunUtil::ERunType> NCPOTCounter::fRunsToUse [private]
 

Definition at line 154 of file NCPOTCounter.h.

Referenced by Config(), and SetPOTValues().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:09:40 2010 for loon by  doxygen 1.3.9.1