MI60Spill Class Reference

#include <MI60Spill.h>

List of all members.

Public Member Functions

 MI60Spill ()
 ~MI60Spill ()
void getUnixTime ()
TH1D * getSpillHisto ()
TH1D * getSubtractedSpillHisto ()
TH1D * getShiftedSpillHisto ()
TH1D * getFakeSpillHisto ()
TH1D * getFakeSpill ()
double adcToVolts (int)
void Reset ()
void ReadFile (const char *)
void ReadHeader (std::ifstream &inFile)
void ReadRCWM (std::ifstream &inFile)
void ReadBackground (std::ifstream &inFile)
void findFirstBunch (std::ifstream &inFile)
void findNextBunch (std::ifstream &inFile)
void ReadD74 (std::ifstream &inFile)
void ReadD74return (std::ifstream &inFile)
TH1D * GetBunchHisto (std::ifstream &inFile, double searchStart, double searchEnd)
void GetBunchInfo (TH1D *hBunch, double &mean, double &RMS, double &tempBunchHeight, double &tempPeakPosition, double &background)
void SaveBunch (double mean, double RMS, double height, double peakPosition, double background)
void MoveStream (std::ifstream &inFile, double searchStart)
double GetBunchBackground (TH1D *h)
void FitBackgroundLinear ()
void FitBackgroundDoubleLinear ()
void FitBackgroundQuadratic ()
double GetChi2Linear (std::vector< double > &pars, double rangeMin=0, double rangeMax=1)
double GetChi2DoubleLinear (std::vector< double > &pars, double rangeMin=0, double rangeMax=1)
double GetChi2Quadratic (std::vector< double > &pars, double rangeMin=0, double rangeMax=1)
double BackgroundFunctionLinear (double tempTime, std::vector< double > &pars)
double BackgroundFunctionDoubleLinear (double tempTime, std::vector< double > &pars)
double BackgroundFunctionQuadratic (double tempTime, std::vector< double > &pars)
TH1D * GetBackgroundFunction ()

Public Attributes

Int_t unixTime
const char * infile
Int_t threshold
Int_t nSearches
Int_t nBunches
Double_t baseVoltage
Double_t spillLength
double time
double firstBunchPosition
std::vector< double > bunchHeight
std::vector< double > bunchPosition
std::vector< double > bunchPositionRMS
std::vector< double > peakPosition
std::vector< double > bunchBackground
std::vector< double > backgroundPars
double backgroundFitChi2
Double_t lastD74
Double_t returnD74
Double_t bin_d74
int nPoints
double timePerPoint
int yScale
int yOffset

Detailed Description

Definition at line 8 of file MI60Spill.h.


Constructor & Destructor Documentation

MI60Spill::MI60Spill (  ) 

Definition at line 11 of file MI60Spill.cxx.

References Reset().

00012   :nPoints(100000), timePerPoint(4e-10)
00013 {
00014   this->Reset();
00015 }

MI60Spill::~MI60Spill (  ) 

Definition at line 17 of file MI60Spill.cxx.

00018 {
00019 }


Member Function Documentation

double MI60Spill::adcToVolts ( int  adcCounts  ) 

Definition at line 295 of file MI60Spill.cxx.

References yOffset, and yScale.

Referenced by GetBunchHisto(), getShiftedSpillHisto(), getSpillHisto(), getSubtractedSpillHisto(), and ReadBackground().

00295                                          {
00296   double volts = adcCounts * (5/127.0)*this->yScale - this->yOffset;
00297   return volts;
00298 }

double MI60Spill::BackgroundFunctionDoubleLinear ( double  tempTime,
std::vector< double > &  pars 
)

Definition at line 545 of file MI60Spill.cxx.

References bunchPosition, and spillLength.

Referenced by GetBackgroundFunction(), GetChi2DoubleLinear(), and getSubtractedSpillHisto().

00545                                                                                         {
00546   if (pars.size()==4){
00547     double spillMidpoint = this->bunchPosition[0] + (0.5*this->spillLength);
00548     if (tempTime<spillMidpoint) return ( pars[0] + (pars[1]*tempTime) );
00549     else return ( pars[2] + (pars[3]*tempTime) ); 
00550   }
00551   else{
00552     std::cout<<"called background function with wrong number of parameters"
00553              <<std::endl;
00554     return -1;
00555   }
00556 }

double MI60Spill::BackgroundFunctionLinear ( double  tempTime,
std::vector< double > &  pars 
)

Definition at line 529 of file MI60Spill.cxx.

Referenced by GetChi2Linear().

00529                                                                                   {
00530   if (pars.size()==2) return (pars[0] + (pars[1]*tempTime));
00531   std::cout<<"called background function with wrong number of parameters"
00532            <<std::endl;
00533   return -1;
00534 }

double MI60Spill::BackgroundFunctionQuadratic ( double  tempTime,
std::vector< double > &  pars 
)

Definition at line 536 of file MI60Spill.cxx.

Referenced by GetChi2Quadratic().

00536                                                                                      {
00537   if (pars.size()==3) return (pars[0] + (pars[1]*tempTime)
00538                               + (pars[2]*pow(tempTime,2)));
00539 
00540   std::cout<<"called background function with wrong number of parameters"
00541            <<std::endl;
00542   return -1;
00543 }

void MI60Spill::findFirstBunch ( std::ifstream &  inFile  ) 

Definition at line 242 of file MI60Spill.cxx.

References baseVoltage, MuELoss::e, firstBunchPosition, GetBunchHisto(), GetBunchInfo(), MoveStream(), threshold, time, and timePerPoint.

Referenced by ReadRCWM().

00242                                                  {
00243   double RCWM = -999;
00244   double tempPeakPosition = -999;
00245   double tempBunchHeight = -999;
00246   double mean=-999;
00247   double RMS=-999;
00248   double background = -999;
00249 
00250   while (firstBunchPosition < 0 && time<1e-5 ){
00251     inFile >> RCWM;
00252     threshold = baseVoltage+20;
00253 
00254     if (RCWM>threshold){
00255       double searchStart = time;
00256       double searchEnd = searchStart+5e-9;
00257       TH1D* hBunch = this->GetBunchHisto(inFile,searchStart,searchEnd);
00258       this->GetBunchInfo(hBunch, mean, RMS,
00259                          tempBunchHeight, tempPeakPosition, background);
00260       firstBunchPosition = tempPeakPosition;
00261 
00262     }
00263     time += timePerPoint;
00264   }
00265 
00266   double nextSearchStart = (this->firstBunchPosition + 9.9e-9
00267                             - 3*18.83e-9);
00268   this->MoveStream(inFile,nextSearchStart);
00269 }

void MI60Spill::findNextBunch ( std::ifstream &  inFile  ) 

Definition at line 271 of file MI60Spill.cxx.

References MuELoss::e, firstBunchPosition, GetBunchHisto(), GetBunchInfo(), nBunches, nSearches, SaveBunch(), and time.

Referenced by ReadRCWM().

00271                                                 {
00272   double searchStart = time;
00273   double searchEnd = ((this->firstBunchPosition + 9.9e-9)
00274                       + (this->nSearches - 2)*18.83e-9);
00275 
00276   TH1D* hBunch = this->GetBunchHisto(inFile,searchStart,searchEnd);
00277   double tempPeakPosition = -999;  double tempBunchHeight = -999;
00278   double mean=-999;  double RMS=-999; double background = -999;
00279   this->GetBunchInfo(hBunch, mean, RMS,
00280                      tempBunchHeight, tempPeakPosition, background);
00281   delete hBunch; hBunch = 0;
00282 
00283   bool isBunch = tempBunchHeight>1 || (nBunches>50&&nBunches<500)  //in middle of spill//very big peak
00284     || (RMS < 4.6e-9 && tempPeakPosition - mean < 1e-9
00285         && tempPeakPosition - mean > -1e-9 && tempBunchHeight>0.2);
00286 
00287 
00288   if (isBunch) this->SaveBunch(mean, RMS, tempBunchHeight,
00289                                tempPeakPosition, background);
00290 
00291   nSearches++;
00292 }

void MI60Spill::FitBackgroundDoubleLinear (  ) 

Definition at line 390 of file MI60Spill.cxx.

References backgroundFitChi2, backgroundPars, and GetChi2DoubleLinear().

Referenced by ReadFile().

00390                                          {
00391   //Model background as 2 straight lines joined at middle of spill
00392 
00393   //2d fit for first line
00394   std::vector<double> pars;
00395   std::vector<double> endPars;
00396   std::vector<double> bestFitPars;
00397   double chi2 = 1000;
00398   double bestFitChi2 = 1000;
00399  
00400   //set initial values;
00401   double start0 = 0.0; double end0=0.5; double step0=(end0-start0)/50.0;
00402   double start1 = -25000;double end1=-5000;double step1=(end1-start1)/50.0;
00403   double start2 = 0.0; double end2=0.5; double step2=(end2-start2)/50.0;
00404   double start3 = -25000;double end3=-5000;double step3=(end3-start3)/50.0;
00405 
00406   pars.push_back(start0); // line 1 intercept
00407   pars.push_back(start1); // line 1 gradient
00408   pars.push_back(start2); // line 2 intercept
00409   pars.push_back(start3); // line 2 gradient
00410 
00411   while(pars[0]<end0){
00412     pars[0]+=step0;
00413     while(pars[1]<end1){
00414       pars[1]+=step1;
00415       chi2 = this->GetChi2DoubleLinear(pars);
00416       if (chi2<bestFitChi2){
00417         bestFitPars = pars;
00418         bestFitChi2 = chi2;
00419       }
00420     }
00421     pars[1] = start1;
00422   }
00423   backgroundPars.push_back(bestFitPars[0]);
00424   backgroundPars.push_back(bestFitPars[1]);
00425 
00426   bestFitChi2 = 1000;
00427   while(pars[2]<end2){
00428     pars[2]+=step2;
00429     while(pars[3]<end3){
00430       pars[3]+=step3;
00431       chi2 = this->GetChi2DoubleLinear(pars);
00432       if (chi2<bestFitChi2){
00433         bestFitPars = pars;
00434         bestFitChi2 = chi2;
00435       }
00436     }
00437     pars[3] = start3;
00438   }
00439   backgroundPars.push_back(bestFitPars[2]);
00440   backgroundPars.push_back(bestFitPars[3]);
00441   backgroundFitChi2 = bestFitChi2;
00442 }

void MI60Spill::FitBackgroundLinear (  ) 

Definition at line 356 of file MI60Spill.cxx.

References backgroundFitChi2, backgroundPars, and GetChi2Linear().

00356                                    {
00357   //fit a 1st order polynomial to the background during the spill
00358 
00359   std::vector<double> pars;
00360   std::vector<double> bestFitPars;
00361   double chi2 = 1000;
00362   double bestFitChi2 = 1000;
00363  
00364   //set initial values;
00365   double start0 = 0.15; double end0=0.25; double step0=(end0-start0)/10.0;
00366   double start1 = -15000;double end1=-10000;double step1=(end1-start1)/10.0;
00367 
00368   pars.push_back(start0);
00369   pars.push_back(start1);
00370 
00371   while(pars[0]<end0){
00372     pars[0]+=step0;
00373     while(pars[1]<end1){
00374       pars[1]+=step1;
00375       chi2 = this->GetChi2Linear(pars);
00376       //std::cout<<pars[0]<<" "<<pars[1]<<" "<<chi2<<std::endl;
00377       if (chi2<bestFitChi2){
00378         bestFitPars = pars;
00379         bestFitChi2 = chi2;
00380       }
00381     }
00382     pars[1] = start1;
00383   }
00384   //save best fit values
00385 
00386   backgroundPars = bestFitPars;
00387   backgroundFitChi2 = bestFitChi2;
00388 }

void MI60Spill::FitBackgroundQuadratic (  ) 

Definition at line 445 of file MI60Spill.cxx.

References backgroundFitChi2, backgroundPars, and GetChi2Quadratic().

00445                                       {
00446   //fit a 1st order polynomial to the background during the spill
00447 
00448   std::vector<double> pars;
00449   std::vector<double> bestFitPars;
00450   double chi2 = 1000;
00451   double bestFitChi2 = 1000;
00452 
00453   //set initial values;
00454   double start0 = 0.27; double end0=0.34; double step0=(end0-start0)/20.0;
00455   double start1 = -40000; double end1=-25000; double step1=(end1-start1)/20.0;
00456   double start2 = 5e8; double end2=12e8; double step2=(end2-start2)/20.0;
00457 
00458   pars.push_back(start0); pars.push_back(start1); pars.push_back(start2);
00459 
00460   while(pars[2]<end2){
00461     pars[2]+=step2;
00462     while(pars[0]<end0){
00463       pars[0]+=step0;
00464       while(pars[1]<end1){
00465         pars[1]+=step1;
00466         chi2 = this->GetChi2Quadratic(pars);
00467         //std::cout << pars[0] << " " << pars[1] << " " << pars[2]
00468         //   << " " << chi2 << std::endl;
00469         if (chi2<bestFitChi2){
00470           bestFitPars = pars;
00471           bestFitChi2 = chi2;
00472         }
00473       }
00474       pars[1] = start1;
00475     }
00476     pars[0] = start0;
00477   }
00478 
00479   //save best fit values
00480   backgroundPars = bestFitPars;
00481   backgroundFitChi2 = bestFitChi2;
00482 }

TH1D * MI60Spill::GetBackgroundFunction (  ) 

Definition at line 558 of file MI60Spill.cxx.

References BackgroundFunctionDoubleLinear(), backgroundPars, and timePerPoint.

00558                                       {
00559   TH1D* h = new TH1D("hBackground","hBackground",
00560                      50000, 0, 50000*timePerPoint);
00561   for (int i; i<50000; i++){
00562     double tempTime = i*timePerPoint;
00563     double bg = this->BackgroundFunctionDoubleLinear(tempTime, backgroundPars);
00564     h->SetBinContent(i, bg);
00565   }
00566   std::cout << backgroundPars[0] << " " << backgroundPars[1] << " "
00567             << backgroundPars[2] << " " << backgroundPars[3] << std::endl;
00568   return h;
00569 }

double MI60Spill::GetBunchBackground ( TH1D *  h  ) 

Definition at line 344 of file MI60Spill.cxx.

Referenced by GetBunchInfo().

00344                                            {
00345   h->GetXaxis()->SetRange(0,30);
00346   double leftInt = h->Integral();
00347   double leftBins = 31;
00348   h->GetXaxis()->SetRange(70,100);
00349   double rightInt = h->Integral();
00350   double rightBins = 31;
00351   double background = (leftInt+rightInt)/(leftBins+rightBins);
00352   h->GetXaxis()->SetRange();
00353   return background;
00354 }

TH1D * MI60Spill::GetBunchHisto ( std::ifstream &  inFile,
double  searchStart,
double  searchEnd 
)

Definition at line 300 of file MI60Spill.cxx.

References adcToVolts(), time, and timePerPoint.

Referenced by findFirstBunch(), and findNextBunch().

00300                                                                                       {
00301   double RCWM = 0;
00302   TH1D* h = new TH1D("","",100,searchStart,searchEnd);
00303   while(time<searchEnd){
00304     inFile>>RCWM;
00305     h->Fill(time,this->adcToVolts(RCWM));
00306     time += timePerPoint;
00307   }
00308   return h;
00309 }

void MI60Spill::GetBunchInfo ( TH1D *  hBunch,
double &  mean,
double &  RMS,
double &  tempBunchHeight,
double &  tempPeakPosition,
double &  background 
)

Definition at line 311 of file MI60Spill.cxx.

References GetBunchBackground().

Referenced by findFirstBunch(), and findNextBunch().

00313                                                      {
00314   mean = h->GetMean();
00315   RMS =h->GetRMS();
00316   tempBunchHeight = h->GetMaximum();
00317   tempPeakPosition = h->GetXaxis()->GetBinCenter(h->GetMaximumBin());
00318   bunchBackground = this->GetBunchBackground(h);
00319 }

double MI60Spill::GetChi2DoubleLinear ( std::vector< double > &  pars,
double  rangeMin = 0,
double  rangeMax = 1 
)

Definition at line 514 of file MI60Spill.cxx.

References BackgroundFunctionDoubleLinear(), bunchBackground, bunchPosition, and nBunches.

Referenced by FitBackgroundDoubleLinear().

00514                                                                                               {
00515   double tempTime = 0;
00516   double chi2 = 0;
00517   int i = 0;
00518   while(i<nBunches && tempTime<rangeMax){
00519     tempTime = bunchPosition[i];
00520     if (tempTime>=rangeMin){
00521       double func = this->BackgroundFunctionDoubleLinear(tempTime, pars);
00522       chi2 += pow(bunchBackground[i]-func, 2);
00523     }
00524     i++;
00525   }
00526   return chi2;
00527 }

double MI60Spill::GetChi2Linear ( std::vector< double > &  pars,
double  rangeMin = 0,
double  rangeMax = 1 
)

Definition at line 484 of file MI60Spill.cxx.

References BackgroundFunctionLinear(), bunchBackground, bunchPosition, and nBunches.

Referenced by FitBackgroundLinear().

00484                                                                                         {
00485   double tempTime = 0;
00486   double chi2 = 0;
00487   int i = 0;
00488   while(i<nBunches && tempTime<rangeMax){
00489     tempTime = bunchPosition[i];
00490     if (tempTime>=rangeMin){
00491       double func = this->BackgroundFunctionLinear(tempTime, pars);
00492       chi2 += pow(bunchBackground[i]-func, 2);
00493     }
00494     i++;
00495   }
00496   return chi2;
00497 }

double MI60Spill::GetChi2Quadratic ( std::vector< double > &  pars,
double  rangeMin = 0,
double  rangeMax = 1 
)

Definition at line 499 of file MI60Spill.cxx.

References BackgroundFunctionQuadratic(), bunchBackground, bunchPosition, and nBunches.

Referenced by FitBackgroundQuadratic().

00499                                                                                            {
00500   double tempTime = 0;
00501   double chi2 = 0;
00502   int i = 0;
00503   while(i<nBunches && tempTime<rangeMax){
00504     tempTime = bunchPosition[i];
00505     if (tempTime>=rangeMin){
00506       double func = this->BackgroundFunctionQuadratic(tempTime, pars);
00507       chi2 += pow(bunchBackground[i]-func, 2);
00508     }
00509     i++;
00510   }
00511   return chi2;
00512 }

TH1D * MI60Spill::getFakeSpill (  ) 

Definition at line 217 of file MI60Spill.cxx.

References base, bunchHeight, bunchPosition, nBunches, and timePerPoint.

00217                              {
00218   TH1D* hSpill = new TH1D("hFakeSpill","hFakeSpill", 50000, 0, 50000*timePerPoint);
00219   int base = 0;
00220   for (int i = 0; i<50000; i++){
00221     hSpill->SetBinContent(i,base);
00222   }
00223   for (int i = 0; i<nBunches; i++){
00224     hSpill->Fill(bunchPosition[i],bunchHeight[i]);
00225   }
00226   return hSpill;
00227 }

TH1D * MI60Spill::getFakeSpillHisto (  ) 

Definition at line 205 of file MI60Spill.cxx.

References base, bunchHeight, nBunches, peakPosition, and timePerPoint.

00205                                   {
00206   TH1D* hSpill = new TH1D("hFakeSpillHisto","hFakeSpillHisto", 50000, 0, 50000*timePerPoint);
00207   int base = 0;
00208   for (int i = 0; i<50000; i++){
00209    hSpill->SetBinContent(i,base);
00210   }
00211   for (int i = 0; i<nBunches; i++){
00212     hSpill->Fill(peakPosition[i],bunchHeight[i]);
00213   }
00214   return hSpill;
00215 }

TH1D * MI60Spill::getShiftedSpillHisto (  ) 

Definition at line 185 of file MI60Spill.cxx.

References adcToVolts(), bunchPosition, infile, nPoints, ReadHeader(), and timePerPoint.

00185                                      {
00186   double RCWM = 0;
00187   double tempTime = -bunchPosition[0];
00188   std::cout<<tempTime<<std::endl;
00189 
00190   TH1D* hSpill = new TH1D("hSpill","hSpill",
00191                           50000, -20000*timePerPoint, 30000*timePerPoint);
00192   std::ifstream inFile;
00193   inFile.open(infile); //reset input stream
00194   //want time =0 to coincide with the first bunch
00195   this->ReadHeader(inFile);
00196 
00197   for (int i=0; i<nPoints; i++){
00198     inFile >> RCWM;
00199     hSpill->Fill(tempTime, this->adcToVolts(RCWM) );
00200     tempTime += timePerPoint;
00201   }
00202   return hSpill;
00203 }

TH1D * MI60Spill::getSpillHisto (  ) 

Definition at line 145 of file MI60Spill.cxx.

References adcToVolts(), infile, nPoints, ReadHeader(), and timePerPoint.

00145                               {
00146   TH1D* hSpill = new TH1D("hSpill","hSpill", 50000, 0, 50000*timePerPoint);
00147   std::ifstream inFile;
00148   inFile.open(infile); //reset input stream
00149   double RCWM = 0;
00150   double tempTime = 0;
00151 
00152   this->ReadHeader(inFile);
00153 
00154   for (int i=0; i<nPoints; i++){
00155     inFile >> RCWM;
00156     double rawVoltage = this->adcToVolts(RCWM);
00157     //    double backgroundSubtractedVoltage = rawVoltage -
00158     //  this->BackgroundFunctionDoubleLinear(tempTime,backgroundPars);
00159     hSpill->Fill(tempTime, rawVoltage);
00160     tempTime += timePerPoint;
00161   }
00162   return hSpill;
00163 }

TH1D * MI60Spill::getSubtractedSpillHisto (  ) 

Definition at line 165 of file MI60Spill.cxx.

References adcToVolts(), BackgroundFunctionDoubleLinear(), backgroundPars, infile, nPoints, ReadHeader(), and timePerPoint.

00165                                         {
00166   TH1D* hSpill = new TH1D("hSubSpill","hSubSpill", 50000, 0, 50000*timePerPoint);
00167   std::ifstream inFile;
00168   inFile.open(infile); //reset input stream
00169   double RCWM = 0;
00170   double tempTime = 0;
00171 
00172   this->ReadHeader(inFile);
00173 
00174   for (int i=0; i<nPoints; i++){
00175     inFile >> RCWM;
00176     double rawVoltage = this->adcToVolts(RCWM);
00177     double backgroundSubtractedVoltage = rawVoltage -
00178       this->BackgroundFunctionDoubleLinear(tempTime,backgroundPars);
00179     hSpill->Fill(tempTime, backgroundSubtractedVoltage);
00180     tempTime += timePerPoint;
00181   }
00182   return hSpill;
00183 }

void MI60Spill::getUnixTime (  ) 

Definition at line 66 of file MI60Spill.cxx.

References infile, and unixTime.

Referenced by ReadFile().

00066                            {
00067   std::string file(infile); //casts file name to a std::string
00068   std::string sTime = file.substr(46,10); //FIXME: dodgy way to get time
00069   Int_t fileTime = atoi(sTime.c_str());
00070   this->unixTime = fileTime;
00071 }

void MI60Spill::MoveStream ( std::ifstream &  inFile,
double  searchStart 
)

Definition at line 332 of file MI60Spill.cxx.

References ReadHeader(), time, and timePerPoint.

Referenced by findFirstBunch(), and ReadRCWM().

00332                                                                      {
00333   inFile.clear();
00334   inFile.seekg(0, std::ios::beg);
00335   this->ReadHeader(inFile);
00336   time = 0;
00337   double dummy = 0;
00338   while (time<searchStartTime){
00339     inFile >> dummy;
00340     time += timePerPoint;
00341   }
00342 }

void MI60Spill::ReadBackground ( std::ifstream &  inFile  ) 

Definition at line 229 of file MI60Spill.cxx.

References adcToVolts(), baseVoltage, time, and timePerPoint.

Referenced by ReadRCWM().

00229                                                  {
00230   double RCWM = 0;
00231   double sumBase = 0;
00232 
00233   for (int i=0; i<1000; i++){
00234     inFile >> RCWM;
00235     sumBase += this->adcToVolts(RCWM);
00236     time += timePerPoint;
00237   }
00238 
00239   baseVoltage = sumBase/1000.0;
00240 }

void MI60Spill::ReadD74 ( std::ifstream &  inFile  ) 

Definition at line 96 of file MI60Spill.cxx.

References bin_d74, lastD74, time, and timePerPoint.

Referenced by ReadFile().

00096                                           {
00097   //FIXME: make sure ifstream is in right position
00098   double d74 = 0;
00099   time = 0;
00100   std::string dummyInput="";
00101 
00102   while(dummyInput.substr(0,5) != "Chann"){
00103     getline(inFile,dummyInput);
00104     //    std::cout<<dummyInput.substr(0,5)<<" getline"<<std::endl;
00105   }
00106 
00107   for (int i=0; i<100000; i++){
00108     //Get input
00109     inFile >> d74;
00110 
00111     //find leading edge
00112     if (d74>0){
00113       lastD74 = time;
00114       bin_d74 = i;
00115       break;
00116     }
00117 
00118     time += timePerPoint;
00119   }
00120 }

void MI60Spill::ReadD74return ( std::ifstream &  inFile  ) 

Definition at line 122 of file MI60Spill.cxx.

References returnD74, time, and timePerPoint.

Referenced by ReadFile().

00122                                                 {
00123   //FIXME: make sure ifstream is in right position
00124   double d74 = 0;
00125   time = 0;
00126   std::string dummyInput="";
00127 
00128   while(dummyInput.substr(0,1) != std::string("C")){
00129     getline(inFile,dummyInput);
00130     //    std::cout<<"getline"<<std::endl;
00131   }
00132 
00133   for (int i=0; i<100000; i++){
00134     //Get input
00135     inFile >> d74;
00136     //find leading edge
00137     if (d74>-50){
00138       returnD74 = time;
00139       break;
00140     }
00141     time += timePerPoint;
00142   }
00143 }

void MI60Spill::ReadFile ( const char *  inputFile  ) 

Definition at line 48 of file MI60Spill.cxx.

References FitBackgroundDoubleLinear(), getUnixTime(), infile, ReadD74(), ReadD74return(), ReadRCWM(), and Reset().

00049 {
00050   this->Reset();
00051   this->infile = inputFile;
00052   this->getUnixTime();
00053 
00054   //Open file
00055   std::ifstream inFile;
00056   inFile.open(infile);
00057 
00058   this->ReadRCWM(inFile);
00059   this->ReadD74(inFile);
00060   this->ReadD74return(inFile);
00061   //this->FitBackgroundLinear();
00062   this->FitBackgroundDoubleLinear();
00063   //this->FitBackgroundQuadratic();
00064 }

void MI60Spill::ReadHeader ( std::ifstream &  inFile  ) 

Definition at line 85 of file MI60Spill.cxx.

References nPoints, timePerPoint, yOffset, and yScale.

Referenced by getShiftedSpillHisto(), getSpillHisto(), getSubtractedSpillHisto(), MoveStream(), and ReadRCWM().

00085                                              {
00086   //should read number of points, time between points
00087   //and adc conversion factors into object
00088   std::string dummyInput;
00089   inFile >> dummyInput;
00090   inFile >> dummyInput;
00091   inFile >> dummyInput;
00092   inFile >> dummyInput >> dummyInput
00093          >> nPoints >> timePerPoint >> yScale >> yOffset;
00094 }

void MI60Spill::ReadRCWM ( std::ifstream &  inFile  ) 

Definition at line 73 of file MI60Spill.cxx.

References MuELoss::e, findFirstBunch(), findNextBunch(), MoveStream(), nBunches, nPoints, nSearches, peakPosition, ReadBackground(), ReadHeader(), spillLength, time, and timePerPoint.

Referenced by ReadFile().

00073                                            {
00074   this->ReadHeader(inFile);
00075   this->ReadBackground(inFile);
00076   this->findFirstBunch(inFile); //locates first large bunch,
00077   //then moves the stream back a few buckets to search more thoroughly
00078   while (nSearches<520&&time<18e-6) this->findNextBunch(inFile);
00079   if (nBunches == 0) spillLength = 0;
00080   else spillLength = peakPosition[nBunches-1] - peakPosition[0];
00081   this->MoveStream(inFile,nPoints*timePerPoint -1);
00082 }

void MI60Spill::Reset ( void   ) 

Definition at line 21 of file MI60Spill.cxx.

References backgroundFitChi2, backgroundPars, baseVoltage, bin_d74, bunchBackground, bunchHeight, bunchPosition, bunchPositionRMS, firstBunchPosition, lastD74, nBunches, nSearches, peakPosition, returnD74, spillLength, threshold, time, and unixTime.

Referenced by MI60Spill(), and ReadFile().

00022 {
00023   unixTime = -999;
00024 
00025   threshold = 0;
00026   nBunches = 0;
00027   nSearches = 0;
00028 
00029   baseVoltage = 0;
00030   spillLength = 0;
00031   time = 0;
00032 
00033   firstBunchPosition = -999;
00034   bunchHeight.clear();
00035   bunchPosition.clear();
00036   bunchPositionRMS.clear();
00037   peakPosition.clear();
00038 
00039   bunchBackground.clear();
00040   backgroundPars.clear();
00041   backgroundFitChi2 = -999;
00042 
00043   lastD74 = -999;
00044   returnD74 = -999;
00045   bin_d74 = -999;
00046 }

void MI60Spill::SaveBunch ( double  mean,
double  RMS,
double  height,
double  peakPosition,
double  background 
)

Definition at line 321 of file MI60Spill.cxx.

References bunchBackground, bunchHeight, bunchPosition, bunchPositionRMS, nBunches, and peakPosition.

Referenced by findNextBunch().

00322                                                                             {
00323   bunchPosition.push_back(mean);
00324   bunchPositionRMS.push_back(RMS);
00325   bunchHeight.push_back(height);
00326   peakPosition.push_back(peakTime);
00327   bunchBackground.push_back(background);
00328 
00329   nBunches++;
00330 }


Member Data Documentation

std::vector<double> MI60Spill::backgroundPars

Definition at line 22 of file MI60Spill.h.

Referenced by findFirstBunch(), ReadBackground(), and Reset().

Definition at line 38 of file MI60Spill.h.

Referenced by ReadD74(), and Reset().

std::vector<double> MI60Spill::bunchBackground

Definition at line 32 of file MI60Spill.h.

Referenced by GetChi2DoubleLinear(), GetChi2Linear(), GetChi2Quadratic(), Reset(), and SaveBunch().

std::vector<double> MI60Spill::bunchHeight

Definition at line 27 of file MI60Spill.h.

Referenced by getFakeSpill(), getFakeSpillHisto(), Reset(), and SaveBunch().

std::vector<double> MI60Spill::bunchPosition
std::vector<double> MI60Spill::bunchPositionRMS

Definition at line 29 of file MI60Spill.h.

Referenced by Reset(), and SaveBunch().

Definition at line 26 of file MI60Spill.h.

Referenced by findFirstBunch(), findNextBunch(), and Reset().

const char* MI60Spill::infile

Definition at line 36 of file MI60Spill.h.

Referenced by ReadD74(), and Reset().

Definition at line 19 of file MI60Spill.h.

Referenced by findNextBunch(), ReadRCWM(), and Reset().

std::vector<double> MI60Spill::peakPosition

Definition at line 30 of file MI60Spill.h.

Referenced by getFakeSpillHisto(), ReadRCWM(), Reset(), and SaveBunch().

Definition at line 37 of file MI60Spill.h.

Referenced by ReadD74return(), and Reset().

Definition at line 23 of file MI60Spill.h.

Referenced by BackgroundFunctionDoubleLinear(), ReadRCWM(), and Reset().

Definition at line 18 of file MI60Spill.h.

Referenced by findFirstBunch(), and Reset().

Definition at line 13 of file MI60Spill.h.

Referenced by getUnixTime(), and Reset().

Definition at line 86 of file MI60Spill.h.

Referenced by adcToVolts(), and ReadHeader().

Definition at line 85 of file MI60Spill.h.

Referenced by adcToVolts(), and ReadHeader().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1