MI60pdf Class Reference

#include <MI60pdf.h>

List of all members.

Public Types

enum  dataType_t { TXT, BIN, NONE }

Public Member Functions

 MI60pdf ()
virtual ~MI60pdf ()
void CreatePDF (const TString &filename, double smearing)
void SetMI60dir (const char *dir)
void ReadFile (const char *filename)
void MakeSmearedPDF (double smearing)
TH1D * GetPDFhisto ()
std::vector< double > GetPDF ()
double RoundTripDelay ()
void LoadMI60Data (const TString &filename)
void LoadRAFdelayFile (const TString &s)
void makeRAFPDF ()
void conv (TH1D *h1, TH1D *h2, TH1D *hResult)
TH1D * BunchPlot ()

Public Attributes

std::ifstream inStream
std::ifstream fileReader
std::vector< double > vRWCM
TH1D * hRWCM
std::vector< double > vPDF
TH1D * hPDF
TH1D * hCorr
TH1D * hDelay
TString infile
TString dataDir
int lastSpillTime
int timestamp
TString date
int nSecondsIntoDay
std::vector< std::string > vNames
dataType_t dataType
int nPoints
double timePerPoint
double voltageScale
double voltageOffset
Double_t baseVoltageStart
Double_t baseVoltageEnd
double firstBunchPosition
double firstPeakPosition
Int_t nSearches
Int_t nBunches
Double_t spillLength
TProfile * backgroundProfile
std::vector< double > bunchPeak
std::vector< double > bunchBackground
Double_t lastD74
Double_t returnD74
bool fileFound

Private Member Functions

void LoadFile (const char *filename)
TString GetDate (int timestamp)
std::string FindFile (int spillTime)
double adcToVolts (int adcCounts)
double GetTime (int index)
int GetIndex (double time)
void Reset ()
void ReadHeader ()
void ReadRWCM ()
void ReadD74 ()
void ReadD74return ()
void ReadTextRWCM ()
void ReadBinaryRWCM ()
void ReadTextD74 ()
void ReadBinaryD74 ()
void ReadTextD74return ()
void ReadBinaryD74return ()
void AnalyzeSpill ()
void ReadBackgroundStart ()
void ReadBackgroundEnd ()
void FindFirstBunch ()
void SampleBackground ()
void ProfileBackground ()
double InterpolateBackground (double time)
void CorrectBackground ()
void SquelchNoise ()
void SmearPDF (double smearing)
double SmearBin (int nBin, double sigmaInBins)
void ReflectPDF ()
void NormalisePDF ()
TH1D * ReturnHisto (std::vector< double > vSpill, const char *name)
int to_int (std::string s)
int GetTimestamp (const TString &filename)

Detailed Description

Definition at line 21 of file MI60pdf.h.


Member Enumeration Documentation

Enumerator:
TXT 
BIN 
NONE 

Definition at line 48 of file MI60pdf.h.

00048 {TXT, BIN, NONE};


Constructor & Destructor Documentation

MI60pdf::MI60pdf (  ) 

Definition at line 24 of file MI60pdf.cxx.

References backgroundProfile, baseVoltageEnd, baseVoltageStart, dataDir, dataType, MuELoss::e, fileFound, firstBunchPosition, firstPeakPosition, hCorr, hDelay, hPDF, hRWCM, infile, lastD74, lastSpillTime, nBunches, NONE, nPoints, nSearches, returnD74, spillLength, timePerPoint, timestamp, voltageOffset, and voltageScale.

00025 {
00026         dataType = NONE;
00027         infile = "";
00028         dataDir = "/minos/data/tof_data/MI60/";
00029         lastSpillTime = -999;
00030         timestamp = -999;
00031 
00032         nPoints=100000;
00033         timePerPoint=4e-10;
00034         voltageScale = 0;
00035         voltageOffset = 0;
00036 
00037         baseVoltageStart = 0;
00038         baseVoltageEnd = 0;
00039 
00040         firstBunchPosition = -999;
00041         firstPeakPosition = -999;
00042         nSearches = 0;
00043         nBunches = 0;
00044         spillLength = 0;
00045 
00046         lastD74 = -999;
00047         returnD74 = -999;
00048 
00049         hRWCM = 0;
00050         hPDF = 0;
00051         hCorr = 0;
00052         backgroundProfile = 0;
00053         hDelay = 0;
00054 
00055         fileFound = false;
00056 }

MI60pdf::~MI60pdf (  )  [virtual]

Definition at line 58 of file MI60pdf.cxx.

References backgroundProfile, hCorr, hPDF, and hRWCM.

00059 {
00060   //std::cout<<"destroying"<<std::endl;
00061   if (hRWCM) {
00062     //std::cout<<"deleting hRWCM from location" << hRWCM << std::endl;
00063     delete hRWCM; hRWCM = 0;
00064   }
00065   if (hPDF)  {
00066     //std::cout<<"deleting hPDF"<<std::endl;
00067     delete hPDF;   hPDF = 0;
00068   }
00069   if (hCorr) {
00070     //std::cout<<"deleting hCorr"<<std::endl;
00071     delete hCorr; hCorr = 0;
00072   }
00073   if (backgroundProfile) {
00074     //std::cout<<"deleting backgroundProfile"<<std::endl;
00075     delete backgroundProfile; backgroundProfile = 0;}
00076 }


Member Function Documentation

double MI60pdf::adcToVolts ( int  adcCounts  )  [private]

Definition at line 655 of file MI60pdf.cxx.

References voltageOffset, and voltageScale.

Referenced by ReadBinaryRWCM(), and ReadTextRWCM().

00656 {
00657   double volts = adcCounts * (5/127.0)*this->voltageScale - this->voltageOffset;
00658   return volts;
00659 }

void MI60pdf::AnalyzeSpill (  )  [private]
TH1D * MI60pdf::BunchPlot (  ) 

Definition at line 718 of file MI60pdf.cxx.

References MuELoss::e, GetTime(), and vRWCM.

00719 {
00720   double bunchLength = 18.83e-9;
00721   TH1D* hBunch = new TH1D("hBunch","hBunch", 100, 0, bunchLength);
00722   double tempIntPart = 0;   double arbitraryOffset = -5e-9;
00723   for(unsigned int i = 0; i<vRWCM.size()-1000; i++){
00724     double bunchPhase = bunchLength * modf( (GetTime(i)+arbitraryOffset)/bunchLength, &tempIntPart );
00725     hBunch->Fill(bunchPhase, vRWCM.at(i));
00726   }
00727   return hBunch;
00728 }

void MI60pdf::conv ( TH1D *  h1,
TH1D *  h2,
TH1D *  hResult 
)

Definition at line 730 of file MI60pdf.cxx.

References MuELoss::a.

Referenced by makeRAFPDF().

00731 {
00732   int numPoints1 = h1->GetNbinsX();
00733   int numPoints2 = h2->GetNbinsX();
00734   for (int i = 100; i<numPoints1; i++){
00735     double t = h1->GetBinCenter(i); 
00736     double smearedBinValue = 0;
00737     double aSum = 0;
00738     for(int j=0; j<numPoints2; j++){
00739 
00740       double d = h2->GetBinCenter(j);
00741       double a = h2->Interpolate(d);
00742       double b = h1->Interpolate(t-d);//near detector distribution term
00743       if (b!=0 && a!=0) {
00744         smearedBinValue += a * b; //integral
00745       }
00746       aSum +=a;
00747     }
00748     hResult->SetBinContent(i, smearedBinValue);
00749     //std::cout<<smearedBinValue<<" "<<aSum<<std::endl;
00750   }
00751 }

void MI60pdf::CorrectBackground (  )  [private]

Definition at line 567 of file MI60pdf.cxx.

References GetTime(), InterpolateBackground(), and vPDF.

Referenced by MakeSmearedPDF().

00568 {
00570   //remove voltage baseline from PDF
00571   int numPoints = vPDF.size();
00572   for (int i=0; i<numPoints; i++){
00573     double tempTime = this->GetTime(i);
00574     vPDF[i] -= this->InterpolateBackground(tempTime);
00575   }
00576 }

void MI60pdf::CreatePDF ( const TString &  filename,
double  smearing 
)

Definition at line 83 of file MI60pdf.cxx.

References dataDir, date, fileFound, GetDate(), GetTimestamp(), infile, MakeSmearedPDF(), ReadFile(), Reset(), and timestamp.

Referenced by Phase2Fitter::EventLikelihood(), Phase2Fitter::EventLikelihoodGPS(), and Phase2Fitter::EventLikelihoodRAF().

00084 {
00085   this->Reset();
00086   
00087   if (filename==TString("")){
00088     fileFound = false;
00089     return;
00090   }
00091   
00092   timestamp = GetTimestamp(filename);
00093   this->date = GetDate(timestamp);
00094   infile = dataDir+date+"/"+filename;
00095   this->ReadFile(infile.Data());
00096   if (fileFound){
00097     this->MakeSmearedPDF(smearing);
00098   }
00099   else std::cout<<"File "<<infile<<" not found."<<std::endl;
00100 }

std::string MI60pdf::FindFile ( int  spillTime  )  [private]
void MI60pdf::FindFirstBunch (  )  [private]

Definition at line 443 of file MI60pdf.cxx.

References firstBunchPosition, firstPeakPosition, GetTime(), and vRWCM.

Referenced by ReadRWCM().

00444 {
00445   int peakBin=0;
00446   int i = 0;
00447   //find start of bunch
00448   while (vRWCM.at(i)<1.0 && i<25000){
00449     i++;
00450   }
00451   double peakVoltage = 0;
00452   //find peak of bunch
00453   for (int j = i; j < i+10; ++j) {
00454     if (vRWCM.at(j)>peakVoltage){
00455       peakVoltage = vRWCM.at(i);
00456       peakBin = i;
00457       firstPeakPosition = this->GetTime(j);
00458     }
00459   }
00460   //use this peak position to get the voltage-weighted mean
00461   //look in 18.83 ns window around peak
00462   int startBin = peakBin-4;  int endBin = peakBin+5;
00463   double sum1 = 0; double sum2 = 0;
00464   for (int index = startBin; index<=endBin; index++){
00465     sum1+=vRWCM.at(index)*GetTime(index);
00466     sum2+=vRWCM.at(index);
00467   }
00468   firstBunchPosition = sum1/sum2;
00469 }

TString MI60pdf::GetDate ( int  timestamp  )  [private]

Definition at line 170 of file MI60pdf.cxx.

References Munits::day, Form(), Munits::hour, Munits::minute, month, nSecondsIntoDay, Munits::second, and Munits::year.

Referenced by CreatePDF(), and LoadMI60Data().

00171 {
00172   //convert spilltime (unix time) to a date.
00173   //this gives you the correct folder
00174   time_t start = timestamp;
00175   struct tm* ptm;
00176   ptm = gmtime(&start);
00177   //Need to check whether we want this to be CDT or UTC
00178   //i.e. are files reset at 00:00:00 CDT or UTC?
00179   
00180   int year = (ptm->tm_year)+1900; int month = ptm->tm_mon+1;
00181   int day = (ptm->tm_mday); int hour = ptm->tm_hour;
00182   int minute = ptm->tm_min; int second = ptm->tm_sec;
00183   
00184   nSecondsIntoDay = hour*3600 + minute*60 + second;
00185   
00186   TString newDate = Form("%d-%02d-%02d", year, month, day);
00187   return newDate;
00188 }

int MI60pdf::GetIndex ( double  time  )  [private]

Definition at line 661 of file MI60pdf.cxx.

References timePerPoint.

Referenced by SampleBackground(), and SmearPDF().

00662 {
00663   return time / timePerPoint;
00664 }

std::vector< double > MI60pdf::GetPDF (  ) 

Definition at line 671 of file MI60pdf.cxx.

References vPDF.

00672 {
00673   return vPDF;
00674 }

TH1D* MI60pdf::GetPDFhisto (  )  [inline]

Definition at line 74 of file MI60pdf.h.

References hPDF.

Referenced by Phase2Fitter::EventLikelihood(), Phase2Fitter::EventLikelihoodGPS(), and Phase2Fitter::EventLikelihoodRAF().

00074 {return hPDF;}

double MI60pdf::GetTime ( int  index  )  [private]

Definition at line 666 of file MI60pdf.cxx.

References timePerPoint.

Referenced by BunchPlot(), CorrectBackground(), FindFirstBunch(), ReadBinaryD74(), ReadBinaryD74return(), ReadTextD74(), ReadTextD74return(), and ReturnHisto().

00667 {
00668   return index * timePerPoint;
00669 }

int MI60pdf::GetTimestamp ( const TString &  filename  )  [private]

Definition at line 708 of file MI60pdf.cxx.

Referenced by CreatePDF(), and LoadMI60Data().

00709 {
00710   if (filename.Length()>5){
00711     const char* c = filename(9,10).Data();
00712     int i = atoi(c);
00713     return i;
00714   }
00715   else return -999;
00716 }

double MI60pdf::InterpolateBackground ( double  time  )  [private]

Definition at line 538 of file MI60pdf.cxx.

References backgroundProfile, baseVoltageEnd, baseVoltageStart, and bunchPeak.

Referenced by CorrectBackground().

00539 {
00540   //if in range, interpolate
00541   if (t<bunchPeak[0]) return baseVoltageStart;
00542   if (t>bunchPeak[bunchPeak.size()-1]) return baseVoltageEnd;
00543   else return backgroundProfile->Interpolate(t);
00544 }

void MI60pdf::LoadFile ( const char *  filename  )  [private]

Definition at line 202 of file MI60pdf.cxx.

References fileFound, and inStream.

Referenced by ReadFile().

00203 {
00204   if (inStream.is_open()) inStream.close();
00205   inStream.open(filename);
00206   if (inStream.is_open()) fileFound = true;
00207   else std::cout<<"couldn't open stream for "<<filename<<std::endl;
00208   inStream.seekg(0, ios::beg);
00209 }

void MI60pdf::LoadMI60Data ( const TString &  filename  ) 

Definition at line 102 of file MI60pdf.cxx.

References dataDir, date, fileFound, GetDate(), GetTimestamp(), infile, ReadFile(), Reset(), and timestamp.

00103 {
00104   this->Reset();
00105   timestamp = GetTimestamp(filename);
00106   this->date = GetDate(timestamp);
00107   infile = dataDir+date+"/"+filename;
00108   this->ReadFile(infile.Data());
00109   if (!fileFound) std::cout<<"File "<<infile<<" not found."<<std::endl;
00110 }

void MI60pdf::LoadRAFdelayFile ( const TString &  s  ) 

Definition at line 762 of file MI60pdf.cxx.

References hDelay.

Referenced by Phase2Fitter::LoadRAFdelayFile().

00763 {
00764   TFile* fDelay = new TFile(s);
00765   hDelay = (TH1D*)fDelay->Get("hDelay");
00766   std::cout<<"got rafdelay file"<<std::endl;
00767   std::cout<<hDelay<<std::endl;
00768 }

void MI60pdf::makeRAFPDF (  ) 

Definition at line 753 of file MI60pdf.cxx.

References conv(), fileFound, hDelay, and hPDF.

Referenced by Phase2Fitter::EventLikelihoodRAF().

00754 {
00755   if (!fileFound) return;
00756   TH1D* h = (TH1D*)hPDF->Clone("h");
00757   conv(hPDF,hDelay,h);
00758   delete hPDF;
00759   hPDF = h;
00760 }

void MI60pdf::MakeSmearedPDF ( double  smearing  ) 

Definition at line 546 of file MI60pdf.cxx.

References CorrectBackground(), hCorr, hPDF, NormalisePDF(), ReturnHisto(), SmearPDF(), SquelchNoise(), vPDF, and vRWCM.

Referenced by CreatePDF(), Phase2Fitter::EventLikelihood(), Phase2Fitter::EventLikelihoodGPS(), and Phase2Fitter::EventLikelihoodRAF().

00547 {
00548   //clean up raw data into a usable spill PDF
00549   vPDF = vRWCM;
00550   if (hPDF) {
00552     delete hPDF;   hPDF = 0;
00553   }
00554   if (hCorr) {
00556     delete hCorr; hCorr = 0;
00557   }
00558   this->CorrectBackground();
00559   hCorr = this->ReturnHisto(vPDF, "hCorr");
00560   this->SquelchNoise();
00561   this->SmearPDF(smearing);
00562   //    this->ReflectPDF();
00563   this->NormalisePDF();
00564   hPDF = this->ReturnHisto(vPDF,"hPDF");
00565 }

void MI60pdf::NormalisePDF (  )  [private]

Definition at line 641 of file MI60pdf.cxx.

References vPDF.

Referenced by MakeSmearedPDF().

00642 {
00643   int numPoints = vPDF.size();
00644   double integral = 0;
00645   for (int i=0; i<numPoints; i++){
00646     integral += vPDF.at(i);
00647   }
00648   std::vector<double> v;
00649   for (int i=0; i<numPoints; i++){
00650     v.push_back(vPDF.at(i)/integral);
00651   }
00652   vPDF = v;
00653 }

void MI60pdf::ProfileBackground (  )  [private]

Definition at line 527 of file MI60pdf.cxx.

References backgroundProfile, bunchBackground, and bunchPeak.

Referenced by ReadRWCM().

00528 {
00530   int nBins = 20;
00531   backgroundProfile = new TProfile("bg","bg",
00532                                    nBins, bunchPeak[0], bunchPeak[bunchPeak.size()-1]);
00533   for (unsigned int i = 0; i<bunchPeak.size(); i++){
00534     backgroundProfile->Fill(bunchPeak[i],bunchBackground[i]);
00535   }
00536 }

void MI60pdf::ReadBackgroundEnd (  )  [private]

Definition at line 485 of file MI60pdf.cxx.

References baseVoltageEnd, and vRWCM.

Referenced by ReadRWCM().

00486 {
00487   double RWCM = 0;
00488   double sumBase = 0;
00489   double range=1000;
00490   int lastPoint = vRWCM.size();
00491   
00492   for (int i=lastPoint-1000; i<lastPoint; i++){
00493     RWCM = vRWCM.at(i);
00494     sumBase += RWCM;
00495   }
00496   
00497   baseVoltageEnd = sumBase/range;
00498 }

void MI60pdf::ReadBackgroundStart (  )  [private]

Definition at line 471 of file MI60pdf.cxx.

References baseVoltageStart, and vRWCM.

Referenced by ReadRWCM().

00472 {
00473   double RWCM = 0;
00474   double sumBase = 0;
00475   double range=1000;
00476   
00477   for (int i=0; i<range; i++){
00478     RWCM = vRWCM.at(i);
00479     sumBase += RWCM;
00480   }
00481   
00482   baseVoltageStart = sumBase/range;
00483 }

void MI60pdf::ReadBinaryD74 (  )  [private]

Definition at line 339 of file MI60pdf.cxx.

References GetTime(), inStream, lastD74, and nPoints.

Referenced by ReadD74().

00339                            {
00340   //std::cout<<"Reading $74"<<std::endl;
00341   int d74 = 0;
00342   char c;
00343   std::string dummyInput;
00344   
00345   getline(inStream, dummyInput);
00346   getline(inStream, dummyInput);
00347   
00348   double threshold = 0;
00349   double d74mean = 0;
00350   double d74noise = -999;
00351 
00352   for (int i=0; i<nPoints; i++){
00353     //Get input
00354     inStream.get(c);
00355     d74 = (int) c;
00356 
00357     if (i>=900&&i<1000){
00358       d74mean += d74/100.0;
00359       if (d74>d74noise)d74noise=d74;
00360     }
00361     if (i==1000) threshold = 2*d74noise - d74mean;
00362     //find leading edge
00363     if (d74>threshold){
00364       lastD74 = this->GetTime(i);
00365       //printf("\n$74 at %i, %f\n", i, this->GetTime(i));
00366       break;
00367     }
00368   }
00369   getline(inStream, dummyInput); //moves stream to end of d74 data
00370   //    std::cout<<"threshold $74 = "<<threshold<<std::endl;
00371 }

void MI60pdf::ReadBinaryD74return (  )  [private]

Definition at line 407 of file MI60pdf.cxx.

References GetTime(), inStream, nPoints, and returnD74.

Referenced by ReadD74return().

00407                                  {
00408   //std::cout<<"Reading $74 return"<<std::endl;
00409   int d74 = 0;
00410   char c;
00411   std::string dummyInput;
00412   
00413   getline(inStream, dummyInput);
00414   
00415   inStream.get(c);
00416   
00417   double threshold = 0;
00418   double d74mean = 0;
00419   double d74noise = -999;
00420 
00421   for (int i=0; i<nPoints; i++){
00422     //Get input
00423     inStream.get(c);
00424     d74 = (int) c;
00425     
00426     if (i>=900&&i<1000){
00427       d74mean += d74/100.0;
00428       if (d74>d74noise)d74noise=d74;
00429     }
00430 
00431     if (i==1000) threshold = 2*d74noise - d74mean;
00432 
00433     //find leading edge    
00434     if (d74>threshold){
00435       returnD74 = this->GetTime(i);
00436       //  printf("\n$74 return at %i, %f\n", i, this->GetTime(i));
00437       break;
00438     }
00439   }
00440   //    std::cout<<"threshold $74 return = "<<threshold<<std::endl;
00441 }

void MI60pdf::ReadBinaryRWCM (  )  [private]

Definition at line 273 of file MI60pdf.cxx.

References adcToVolts(), inStream, nPoints, and vRWCM.

Referenced by ReadRWCM().

00274 {
00275   //std::cout<<"Reading binary data file"<<std::endl;
00276   //assumes that provided inStream is pointing at the first line
00277   vRWCM.clear();
00278   //FIXME: ensure that the stream is pointing to the right place
00279   int RWCM = 0;
00280   char c;
00281   inStream.get(c); //eat extra header byte
00282   
00283   //    std::cout<<"First 10 data points:"<<std::endl;
00284   for (int i=0; i<nPoints; i++){
00285     inStream.get(c);
00286     RWCM = (int) c;
00287     //if (i<10) std::cout<<RWCM<<std::endl;
00288     
00289     vRWCM.push_back(this->adcToVolts(RWCM));
00290   }
00292 }

void MI60pdf::ReadD74 (  )  [private]

Definition at line 294 of file MI60pdf.cxx.

References BIN, dataType, ReadBinaryD74(), ReadTextD74(), and TXT.

Referenced by ReadFile().

00295 {
00296   if (dataType==TXT) this->ReadTextD74();
00297   else if (dataType==BIN) this->ReadBinaryD74();
00298   else std::cout<<"bad file"<<std::endl;
00299 }

void MI60pdf::ReadD74return (  )  [private]

Definition at line 301 of file MI60pdf.cxx.

References BIN, dataType, ReadBinaryD74return(), ReadTextD74return(), and TXT.

Referenced by ReadFile().

00302 {
00303   if (dataType==TXT) this->ReadTextD74return();
00304   else if (dataType==BIN) this->ReadBinaryD74return();
00305   else std::cout<<"bad file"<<std::endl;
00306 }

void MI60pdf::ReadFile ( const char *  filename  ) 

Definition at line 190 of file MI60pdf.cxx.

References fileFound, LoadFile(), ReadD74(), ReadD74return(), and ReadRWCM().

Referenced by CreatePDF(), and LoadMI60Data().

00191 {
00192   //std::cout<<"Reading file"<<std::endl;
00193   this->LoadFile(filename);
00194   if (fileFound){
00195     this->ReadRWCM();
00196     this->ReadD74();
00197     this->ReadD74return();
00198   }
00199   //std::cout<<"File has been read."<<std::endl;
00200 }

void MI60pdf::ReadHeader (  )  [private]

Definition at line 234 of file MI60pdf.cxx.

References BIN, dataType, inStream, nPoints, timePerPoint, TXT, voltageOffset, and voltageScale.

Referenced by ReadRWCM().

00235 {
00236   //std::cout<<"Reading file header"<<std::endl;
00237   //should read number of points, time between points
00238   //and adc conversion factors into object
00239   std::string dummyInput="";
00240   std::string fileType="";
00241   
00242   inStream.seekg(std::ios::beg);
00244   inStream >> dummyInput; 
00245   inStream >> fileType; 
00246   inStream >> dummyInput; 
00247   inStream >> dummyInput >> dummyInput
00248            >> nPoints >> timePerPoint >> voltageScale >> voltageOffset;
00249   
00250   if (fileType == "1.0"){
00251     dataType = TXT; //std::cout<<"TXT file"<<std::endl;
00252   }
00253   else if (fileType == "2.0"){
00254     dataType = BIN; //std::cout<<"BIN file"<<std::endl;
00255     inStream >> dummyInput;
00256   }
00257   else std::cout<<"couldn't work out file type "<<fileType<<std::endl;
00258 }

void MI60pdf::ReadRWCM (  )  [private]

Definition at line 211 of file MI60pdf.cxx.

References BIN, dataType, FindFirstBunch(), hRWCM, ProfileBackground(), ReadBackgroundEnd(), ReadBackgroundStart(), ReadBinaryRWCM(), ReadHeader(), ReadTextRWCM(), ReturnHisto(), SampleBackground(), TXT, and vRWCM.

Referenced by ReadFile().

00212 {
00213   //std::cout<<"Reading MI60 data"<<std::endl;
00214   this->ReadHeader(); //reads in some key information including the data type
00215   
00216   if (dataType == BIN) ReadBinaryRWCM(); //puts the spill data into an array
00217   if (dataType == TXT) ReadTextRWCM(); //puts the spill data into an array
00218   
00219   hRWCM = this->ReturnHisto(vRWCM, "raw");
00220   //std::cout<<"1"<<std::endl;
00221   this->ReadBackgroundStart();
00222   //std::cout<<"2"<<std::endl;
00223   this->ReadBackgroundEnd();
00224   // std::cout<<"3"<<std::endl;
00225   this->FindFirstBunch();
00226   //std::cout<<"4"<<std::endl;
00227   this->SampleBackground();
00228   //std::cout<<"5"<<std::endl;
00229   this->ProfileBackground();
00230   //std::cout<<"Loaded MI60 file "<<infile<<" into memory."<<std::endl;
00231   //std::cout<<"Has "<<vRWCM.size()<<" points."<<std::endl;
00232 }

void MI60pdf::ReadTextD74 (  )  [private]

Definition at line 309 of file MI60pdf.cxx.

References GetTime(), inStream, lastD74, and nPoints.

Referenced by ReadD74().

00309                          {
00310   //    std::cout<<"Reading $74"<<std::endl;
00311   int d74 = 0;
00312   std::string dummyInput="";
00313   
00314   while(dummyInput.substr(0,1) != std::string("C")){
00315     getline(inStream,dummyInput);
00316   }
00317   
00318   double threshold = 0;
00319   double d74mean = 0;
00320   double d74noise = -999;
00321 
00322   for (int i=0; i<nPoints; i++){
00323     //Get input
00324     inStream >> d74;
00325     if (i>=900&&i<1000){
00326       d74mean += d74/100.0;
00327       if (d74>d74noise) d74noise=d74;
00328     }
00329     if (i==1000) threshold = 2*d74noise - d74mean;
00330     //find leading edge
00331     if (d74>threshold){
00332       lastD74 = this->GetTime(i);
00333       break;
00334     }
00335   }
00336   //    std::cout<<"threshold $74 = "<<threshold<<std::endl;
00337 }

void MI60pdf::ReadTextD74return (  )  [private]

Definition at line 373 of file MI60pdf.cxx.

References GetTime(), inStream, nPoints, and returnD74.

Referenced by ReadD74return().

00373                                {
00374   //std::cout<<"Reading $74 return"<<std::endl;
00375   int d74 = 0;
00376   std::string dummyInput="";
00377   
00378   while(dummyInput.substr(0,1) != std::string("C")){
00379     getline(inStream,dummyInput);
00380   }
00381   
00382   double threshold = 0;
00383   double d74mean = 0;
00384   double d74noise = -999;
00385 
00386   for (int i=0; i<nPoints; i++){
00387     //Get input
00388     inStream >> d74;
00389     
00390     if (i>=900&&i<1000){
00391       d74mean += d74/100.0;
00392       if (d74>d74noise)d74noise=d74;
00393     }
00394     if (i==1000) threshold = 2*d74noise - d74mean;
00395 
00396     //find leading edge
00397     if (d74>threshold){
00398       returnD74 = this->GetTime(i);
00399       //printf("\n$74 return at %f\n",this->GetTime(i));
00400       break;
00401     }
00402   }
00403   //    std::cout<<"threshold $74 return= "<<threshold<<std::endl;
00404 }

void MI60pdf::ReadTextRWCM (  )  [private]

Definition at line 260 of file MI60pdf.cxx.

References adcToVolts(), inStream, nPoints, and vRWCM.

Referenced by ReadRWCM().

00261 {
00262   //std::cout<<"Reading text data file"<<std::endl;
00263   //assumes that provided inStream is pointing at the first line
00264   double RWCM = 0;
00265   vRWCM.clear();
00266   for (int i=0; i<nPoints; i++){
00267     inStream >> RWCM;
00268     double voltage = this->adcToVolts(RWCM);
00269     vRWCM.push_back(voltage);
00270   }
00271 }

void MI60pdf::ReflectPDF (  )  [private]

Definition at line 631 of file MI60pdf.cxx.

References vPDF.

00632 {
00633   std::vector<double> v;
00634   int numPoints = vPDF.size();
00635   for (int i=numPoints-1; i>=0; i--){
00636     v.push_back(vPDF.at(i));
00637   }
00638   vPDF = v;
00639 }

void MI60pdf::Reset ( void   )  [private]

Definition at line 114 of file MI60pdf.cxx.

References backgroundProfile, baseVoltageEnd, baseVoltageStart, bunchBackground, bunchPeak, dataType, fileFound, firstBunchPosition, firstPeakPosition, hCorr, hPDF, hRWCM, infile, inStream, lastD74, lastSpillTime, nBunches, NONE, nPoints, Munits::ns, nSearches, returnD74, spillLength, timePerPoint, timestamp, voltageOffset, voltageScale, vPDF, and vRWCM.

Referenced by CreatePDF(), and LoadMI60Data().

00115 {
00116   if (hRWCM) {
00118     delete hRWCM; hRWCM = 0;
00119   }
00120   if (hPDF) {
00122     delete hPDF;   hPDF = 0;
00123   }
00124   if (hCorr) {
00126     delete hCorr; hCorr = 0;
00127   }
00128   if (backgroundProfile) {
00130     delete backgroundProfile; backgroundProfile = 0;
00131   }
00132   
00133   vRWCM.clear();
00134   inStream.close();
00135   vPDF.clear();
00136   
00137   dataType = NONE;
00138   bunchPeak.clear();
00139   bunchBackground.clear();
00140   
00141   infile = "";
00142   lastSpillTime = -999;
00143   timestamp = -999;
00144   
00145   nPoints=100000;
00146   timePerPoint=0.4*Munits::ns;
00147   voltageScale = 0;
00148   voltageOffset = 0;
00149   
00150   baseVoltageStart = 0;
00151   baseVoltageEnd = 0;
00152   
00153   firstBunchPosition = -999;
00154   firstPeakPosition = -999;
00155   nSearches = 0;
00156   nBunches = 0;
00157   spillLength = 0;
00158   
00159   lastD74 = -999;
00160   returnD74 = -999;
00161         
00162   hRWCM = 0;
00163   hPDF = 0;
00164   hCorr = 0;
00165   backgroundProfile = 0;
00166 
00167   fileFound = false;
00168 }

TH1D * MI60pdf::ReturnHisto ( std::vector< double >  vSpill,
const char *  name 
) [private]

Definition at line 676 of file MI60pdf.cxx.

References GetTime(), and timePerPoint.

Referenced by MakeSmearedPDF(), and ReadRWCM().

00677 {
00679   int nBins = vSpill.size();
00680   double halfBin = timePerPoint*0.5;
00681   
00682   TH1D* h = new TH1D(name,name,nBins,
00683                      this->GetTime(0)-halfBin,this->GetTime(nBins-1)-halfBin);
00684   
00685   for (int i = 0; i<nBins; i++){
00686     h->SetBinContent(i, vSpill.at(i));
00687   }
00688   
00689   return h;
00690 }

double MI60pdf::RoundTripDelay (  ) 

Definition at line 692 of file MI60pdf.cxx.

References lastD74, and returnD74.

00693 {
00694   return this->returnD74 - this->lastD74;
00695 }

void MI60pdf::SampleBackground (  )  [private]

Definition at line 500 of file MI60pdf.cxx.

References bunchBackground, bunchPeak, firstBunchPosition, GetIndex(), Munits::ns, and vRWCM.

Referenced by ReadRWCM().

00501 {
00503   //sample the voltage in between bunches
00504   //want to sample between 5 and 10 ns before each peak
00505   double bucket = 18.83*Munits::ns;
00506   for(double aBunchPosition = firstBunchPosition - 10*bucket;
00507       bunchPeak.size()<540; aBunchPosition+=bucket)
00508     {
00509       bunchPeak.push_back(aBunchPosition);
00510     }
00511   
00512   //now know where each bunch should be
00513   for (unsigned int i = 0; i<bunchPeak.size();i++){
00514     int binMin = this->GetIndex(bunchPeak[i]) - 24;
00515     int binMax = binMin+12;
00516     int nBins = binMax-binMin;
00517     double sum = 0;
00518     
00519     for (int j = binMin; j<binMax; j++){
00520       sum += vRWCM[j];
00521     }
00522     double bg = sum/nBins;
00523     bunchBackground.push_back(bg);
00524   }
00525 }

void MI60pdf::SetMI60dir ( const char *  dir  ) 

Definition at line 78 of file MI60pdf.cxx.

References dataDir.

Referenced by Phase2Fitter::SetMI60dir().

00079 {
00080   dataDir=dir;
00081 }

Double_t MI60pdf::SmearBin ( int  nBin,
double  sigmaInBins 
) [private]

Definition at line 608 of file MI60pdf.cxx.

References MuELoss::a, and vPDF.

Referenced by SmearPDF().

00609 {
00610   //approximate convolution with a gaussian
00611   double smearedBinValue=0;
00612   double dt=1;
00613   int numPoints = vPDF.size();
00614   
00615   //cut off gaussian tails at however many std. deviations is deemed necessary
00616   double cutOff = 4*sigmaInBins;
00617   int limLow = nBin-cutOff;     if (limLow<0) limLow = 0;
00618   int limHigh = nBin+cutOff;    if (limHigh>=numPoints) limHigh = numPoints-1;
00619   
00620   for(int t=limLow; t<limHigh; t++){
00621     double a = pow(nBin-(t+0.5*dt), 2) / (2*pow(sigmaInBins,2));//gaussian term
00622     double b = vPDF.at(t);//near detector distribution term
00623     if (b!=0) {
00624       smearedBinValue += dt * exp(-a) * b; //integral
00625     }
00626   }
00627   smearedBinValue /= sigmaInBins * sqrt(2*3.14159265);
00628   return smearedBinValue;
00629 }

void MI60pdf::SmearPDF ( double  smearing  )  [private]

Definition at line 587 of file MI60pdf.cxx.

References firstBunchPosition, GetIndex(), Munits::ns, SmearBin(), timePerPoint, and vPDF.

Referenced by MakeSmearedPDF().

00588 {
00589   //convolve PDF with gaussian, sigma = smearing
00591   
00592   std::vector<double> v;
00593   double smearingInBins = smearing / timePerPoint; //convert units for the convolution
00594   
00595   //let's only smear the area where there's actually signal...
00596   int lowBin = this->GetIndex(firstBunchPosition - 100*Munits::ns);
00597   int highBin = lowBin + 25000;
00598   for (int i=0; i<lowBin; i++){
00599     v.push_back(0);
00600   }
00601   for (int i=lowBin; i<highBin; i++){
00602     v.push_back(this->SmearBin(i, smearingInBins));
00603   }
00604   //now replace vPDF by new, smeared PDF
00605   vPDF = v;
00606 }

void MI60pdf::SquelchNoise (  )  [private]

Definition at line 578 of file MI60pdf.cxx.

References vPDF.

Referenced by MakeSmearedPDF().

00579 {
00580   //cuts off any low-level signal in PDF
00581   int numPoints = vPDF.size();
00582   for (int i=0; i<numPoints; i++){
00583     if (vPDF.at(i)<0.2) vPDF[i]=0;
00584   }
00585 }

int MI60pdf::to_int ( std::string  s  )  [private]

Definition at line 697 of file MI60pdf.cxx.

00698 {
00699   stringstream ss(s);  
00700   int i;
00701   
00702   if( (ss >> i).fail() ){
00703       //std::cout<<"conversion error"<<std::endl;
00704     }
00705   return i;
00706 }


Member Data Documentation

Definition at line 65 of file MI60pdf.h.

Referenced by InterpolateBackground(), MI60pdf(), ProfileBackground(), Reset(), and ~MI60pdf().

Definition at line 57 of file MI60pdf.h.

Referenced by InterpolateBackground(), MI60pdf(), ReadBackgroundEnd(), and Reset().

Definition at line 56 of file MI60pdf.h.

Referenced by InterpolateBackground(), MI60pdf(), ReadBackgroundStart(), and Reset().

std::vector<double> MI60pdf::bunchBackground

Definition at line 67 of file MI60pdf.h.

Referenced by ProfileBackground(), Reset(), and SampleBackground().

std::vector<double> MI60pdf::bunchPeak

Definition at line 66 of file MI60pdf.h.

Referenced by InterpolateBackground(), ProfileBackground(), Reset(), and SampleBackground().

Definition at line 41 of file MI60pdf.h.

Referenced by CreatePDF(), LoadMI60Data(), MI60pdf(), and SetMI60dir().

Definition at line 49 of file MI60pdf.h.

Referenced by MI60pdf(), ReadD74(), ReadD74return(), ReadHeader(), ReadRWCM(), and Reset().

TString MI60pdf::date

Definition at line 44 of file MI60pdf.h.

Referenced by CreatePDF(), and LoadMI60Data().

std::ifstream MI60pdf::fileReader

Definition at line 29 of file MI60pdf.h.

Definition at line 59 of file MI60pdf.h.

Referenced by FindFirstBunch(), MI60pdf(), Reset(), SampleBackground(), and SmearPDF().

Definition at line 60 of file MI60pdf.h.

Referenced by FindFirstBunch(), MI60pdf(), and Reset().

Definition at line 37 of file MI60pdf.h.

Referenced by MakeSmearedPDF(), MI60pdf(), Reset(), and ~MI60pdf().

Definition at line 38 of file MI60pdf.h.

Referenced by LoadRAFdelayFile(), makeRAFPDF(), and MI60pdf().

Definition at line 36 of file MI60pdf.h.

Referenced by GetPDFhisto(), makeRAFPDF(), MakeSmearedPDF(), MI60pdf(), Reset(), and ~MI60pdf().

Definition at line 34 of file MI60pdf.h.

Referenced by MI60pdf(), ReadRWCM(), Reset(), and ~MI60pdf().

TString MI60pdf::infile

Definition at line 40 of file MI60pdf.h.

Referenced by CreatePDF(), LoadMI60Data(), MI60pdf(), and Reset().

std::ifstream MI60pdf::inStream
Double_t MI60pdf::lastD74

Definition at line 42 of file MI60pdf.h.

Referenced by MI60pdf(), and Reset().

Definition at line 62 of file MI60pdf.h.

Referenced by MI60pdf(), and Reset().

Definition at line 61 of file MI60pdf.h.

Referenced by MI60pdf(), and Reset().

Definition at line 45 of file MI60pdf.h.

Referenced by GetDate().

Definition at line 70 of file MI60pdf.h.

Referenced by MI60pdf(), ReadBinaryD74return(), ReadTextD74return(), Reset(), and RoundTripDelay().

Definition at line 63 of file MI60pdf.h.

Referenced by MI60pdf(), and Reset().

Definition at line 52 of file MI60pdf.h.

Referenced by GetIndex(), GetTime(), MI60pdf(), ReadHeader(), Reset(), ReturnHisto(), and SmearPDF().

Definition at line 43 of file MI60pdf.h.

Referenced by CreatePDF(), LoadMI60Data(), MI60pdf(), and Reset().

std::vector<std::string> MI60pdf::vNames

Definition at line 46 of file MI60pdf.h.

Definition at line 54 of file MI60pdf.h.

Referenced by adcToVolts(), MI60pdf(), ReadHeader(), and Reset().

Definition at line 53 of file MI60pdf.h.

Referenced by adcToVolts(), MI60pdf(), ReadHeader(), and Reset().

std::vector<double> MI60pdf::vPDF
std::vector<double> MI60pdf::vRWCM

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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1