{ #include #include #include "/homes/wto/cfACodes/Common/Utilities.h" int64_t RANGEMAX = 2000; TH1D * caven = new TH1D("caven", "",2*RANGEMAX*10*200,0,2*RANGEMAX*200); // ifstream fin; // fin.open("data.txt"); fin.open("leftPosition.txt"); // fin.open("rightPosition.txt"); int64_t LowRange = 0; int64_t HighRange = RANGEMAX; TF1 * DampSineFit = new TF1("DampSineFit","[0]*sin([1]*x-[2])*exp([3]*x)+[4]",0,RANGEMAX); DampSineFit->SetParameter(0,4*25.4); DampSineFit->SetParameter(1,-0.01292); DampSineFit->SetParameter(2,1.5); DampSineFit->SetParameter(3,-0.000019); DampSineFit->SetParameter(4,4*25.4); int64_t time,prevtime; int64_t prevch,ch; int64_t TotCh0,TotCh1,TotCh2,TotCh3,TotCh4,TotCh5,TotCh6,TotCh7,TotCh8,TotCh9; int64_t NumCh0,NumCh1,NumCh2,NumCh3,NumCh4,NumCh5,NumCh6,NumCh7,NumCh8,NumCh9; bool reset=false; while(fin>>ch){ fin>>time; //cout< prevtime+500) reset = true; if(reset) { if(NumCh0 > 1) { double thisTime = TotCh0 / double(NumCh0); caven->SetBinContent(thisTime/100,0*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh0*1.0)); } if(NumCh1 > 1) { double thisTime = TotCh1 / double(NumCh1); caven->SetBinContent(thisTime/100,0.5*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh1*1.0)); } if(NumCh2 > 1) { double thisTime = TotCh2 / double(NumCh2); caven->SetBinContent(thisTime/100,2*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh2*1.0)); } if(NumCh3 > 1) { double thisTime = TotCh3 / double(NumCh3); caven->SetBinContent(thisTime/100,2.5*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh3*1.0)); } if(NumCh4 > 1) { double thisTime = TotCh4 / NumCh4; caven->SetBinContent(thisTime/100,4*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh4*1.0)); } if(NumCh5 > 1) { double thisTime = TotCh5 / double(NumCh5); caven->SetBinContent(thisTime/100,4.5*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh5*1.0)); } if(NumCh6 > 1) { double thisTime = TotCh6 / double(NumCh6); caven->SetBinContent(thisTime/100,6*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh6*1.0)); } if(NumCh7 > 1) { double thisTime = TotCh7 / double(NumCh7); caven->SetBinContent(thisTime/100,6.5*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh7*1.0)); } if(NumCh8 > 1) { double thisTime = TotCh8 / double(NumCh8); caven->SetBinContent(thisTime/100,8*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh8*1.0)); } if(NumCh9 > 1) { double thisTime = TotCh9 / double(NumCh9); caven->SetBinContent(thisTime/100,8.5*25.4); caven->SetBinError(thisTime/100,25.4/sqrt(NumCh9*1.0)); } TotCh0=0; NumCh0=0; TotCh1=0; NumCh1=0; TotCh2=0; NumCh2=0; TotCh3=0; NumCh3=0; TotCh4=0; NumCh4=0; TotCh5=0; NumCh5=0; TotCh6=0; NumCh6=0; TotCh7=0; NumCh7=0; TotCh8=0; NumCh8=0; TotCh9=0; NumCh9=0; } prevch = ch; prevtime = time; reset = false; if(ch == 0){ if(TotCh0+time > INT_MAX){ reset = true; } else{ TotCh0+=time; NumCh0++; } } if(ch == 1){ if(TotCh1+time > INT_MAX){ reset = true; } else{ TotCh1+=time; NumCh1++; } } if(ch == 2){ if(TotCh2+time > INT_MAX){ reset = true; } else{ TotCh2+=time; NumCh2++; } } if(ch == 3){ if(TotCh3+time > INT_MAX){ reset = true; } else{ TotCh3+=time; NumCh3++; } } if(ch == 4){ if(TotCh4+time > INT_MAX){ reset = true; } else{ TotCh4+=time; NumCh4++; } } if(ch == 5){ if(TotCh5+time > INT_MAX){ reset = true; } else{ TotCh5+=time; NumCh5++; } } if(ch == 6){ if(TotCh6+time > INT_MAX){ reset = true; } else{ TotCh6+=time; NumCh6++; } } if(ch == 7){ if(TotCh7+time > INT_MAX){ reset = true; } else{ TotCh7+=time; NumCh7++; } } if(ch == 8){ if(TotCh8+time > INT_MAX){ reset = true; } else{ TotCh8+=time; NumCh8++; } } if(ch == 9){ if(TotCh9+time > INT_MAX){ reset = true; } else{ TotCh9+=time; NumCh9++; } } } fin.close(); fin.open("rightPosition.txt"); int64_t LowRange = 0; int64_t HighRange = RANGEMAX; TF1 * DampSineFit2 = new TF1("DampSineFit2","[0]*sin([1]*x-[2])*exp([3]*x)+[4]",2000,2*RANGEMAX); DampSineFit2->SetParameter(0,4*25.4); DampSineFit2->SetParameter(1,-0.01292); DampSineFit2->SetParameter(2,1.5); DampSineFit2->SetParameter(3,-0.000019); DampSineFit2->SetParameter(4,4*25.4); reset=false; while(fin>>ch){ fin>>time; //cout< prevtime+500) reset = true; if(reset) { if(NumCh0 > 1) { double thisTime = TotCh0 / double(NumCh0); caven->SetBinContent(thisTime/100+22000,0*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh0*1.0)); } if(NumCh1 > 1) { double thisTime = TotCh1 / double(NumCh1); caven->SetBinContent(thisTime/100+22000,0.5*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh1*1.0)); } if(NumCh2 > 1) { double thisTime = TotCh2 / double(NumCh2); caven->SetBinContent(thisTime/100+22000,2*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh2*1.0)); } if(NumCh3 > 1) { double thisTime = TotCh3 / double(NumCh3); caven->SetBinContent(thisTime/100+22000,2.5*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh3*1.0)); } if(NumCh4 > 1) { double thisTime = TotCh4 / NumCh4; caven->SetBinContent(thisTime/100+22000,4*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh4*1.0)); } if(NumCh5 > 1) { double thisTime = TotCh5 / double(NumCh5); caven->SetBinContent(thisTime/100+22000,4.5*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh5*1.0)); } if(NumCh6 > 1) { double thisTime = TotCh6 / double(NumCh6); caven->SetBinContent(thisTime/100+22000,6*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh6*1.0)); } if(NumCh7 > 1) { double thisTime = TotCh7 / double(NumCh7); caven->SetBinContent(thisTime/100+22000,6.5*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh7*1.0)); } if(NumCh8 > 1) { double thisTime = TotCh8 / double(NumCh8); caven->SetBinContent(thisTime/100+22000,8*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh8*1.0)); } if(NumCh9 > 1) { double thisTime = TotCh9 / double(NumCh9); caven->SetBinContent(thisTime/100+22000,8.5*25.4); caven->SetBinError(thisTime/100+22000,25.4/sqrt(NumCh9*1.0)); } TotCh0=0; NumCh0=0; TotCh1=0; NumCh1=0; TotCh2=0; NumCh2=0; TotCh3=0; NumCh3=0; TotCh4=0; NumCh4=0; TotCh5=0; NumCh5=0; TotCh6=0; NumCh6=0; TotCh7=0; NumCh7=0; TotCh8=0; NumCh8=0; TotCh9=0; NumCh9=0; } prevch = ch; prevtime = time; reset = false; if(ch == 0){ if(TotCh0+time > INT_MAX){ reset = true; } else{ TotCh0+=time; NumCh0++; } } if(ch == 1){ if(TotCh1+time > INT_MAX){ reset = true; } else{ TotCh1+=time; NumCh1++; } } if(ch == 2){ if(TotCh2+time > INT_MAX){ reset = true; } else{ TotCh2+=time; NumCh2++; } } if(ch == 3){ if(TotCh3+time > INT_MAX){ reset = true; } else{ TotCh3+=time; NumCh3++; } } if(ch == 4){ if(TotCh4+time > INT_MAX){ reset = true; } else{ TotCh4+=time; NumCh4++; } } if(ch == 5){ if(TotCh5+time > INT_MAX){ reset = true; } else{ TotCh5+=time; NumCh5++; } } if(ch == 6){ if(TotCh6+time > INT_MAX){ reset = true; } else{ TotCh6+=time; NumCh6++; } } if(ch == 7){ if(TotCh7+time > INT_MAX){ reset = true; } else{ TotCh7+=time; NumCh7++; } } if(ch == 8){ if(TotCh8+time > INT_MAX){ reset = true; } else{ TotCh8+=time; NumCh8++; } } if(ch == 9){ if(TotCh9+time > INT_MAX){ reset = true; } else{ TotCh9+=time; NumCh9++; } } } fin.close(); //gStyle->SetOptFit(); gStyle->SetOptStat(0); gStyle->SetErrorX(0.050); caven->Draw(); c1->SetTopMargin(0.1); // Range for plus caven->GetXaxis()->SetRange(LowRange*10+100,HighRange*10*2+200); caven->Fit("DampSineFit","E","",100,2000); caven->Fit("DampSineFit","EM","",100,2000); cout<GetChisquare()<Fit("DampSineFit2","E","",2200,4000); caven->Fit("DampSineFit2","EM","",2200,4000); cout<GetChisquare()<Draw("same"); caven->GetXaxis()->SetTitle("Time (s)"); caven->GetYaxis()->SetTitleOffset(0.7); caven->GetYaxis()->SetTitle("Position (mm)"); TLatex * Title = MakeTextBox("Cavendish data 22Apr13 UCSB Physics",0.20,0.91,0.04); Title->Draw(); TLatex * Right = MakeTextBox("Left Position. Fit p4=90.3#pm0.3",0.16,0.84,0.04); Right->Draw(); TArrow RtArrow(1200,185,1200,160,0.06); RtArrow->Draw(); TLatex * Left = MakeTextBox("Right Position. Fit p4=124.0#pm0.4",0.55,0.21,0.04); Left->Draw(); TArrow LfArrow(3000,20,3000,60,0.06); LfArrow->Draw(); }