/* verifyCoin -------------------- Inputs: Input Counts Filename Input Timestamps Filename Produces a histogram of the disparity between a the summation of 4 and 5 fold coincidences for a given counts line and the number timestamps for the same time period. histStamps -------------------- Inputs: Interval Input Timestamps Filename Produces a histogram of the time disparity between two sucessive timestamps that don't exceed the interval number of seconds, as this number defines windows for which the detectors are operational. In addition, this histogram is fitted with an exponential curve and computed average time difference is printed out to the screen. Author: Jason Immerman, 2008 Stony Brook University Summer Physics REU Date:   Jul 23, 2008 */ #include "Riostream.h" #include "TTimeStamp.h" #include "TGraph.h" #include "TCanvas.h" #include "TAttAxis.h" #include "TFile.h" #include "TList.h" #include "TH1.h" #include "TROOT.h" #include "TAxis.h" #include #include #include #include using namespace std; void verifyCoin(string countfileName, string stampfileName) { ifstream count; count.open(countfileName.c_str()); ifstream stamp; stamp.open(stampfileName.c_str()); Char_t s1[100]; Char_t s2[100]; Int_t date1; Int_t date2; Double_t time1; Double_t time2; Int_t nlines1 = 0; Int_t nlines2 = 0; TTimeStamp da1; TTimeStamp da2; Int_t fract1; Int_t fract2; Int_t v[11]; Int_t countCoin; Int_t stampCoin=0; Int_t last; TH1D *dataDisparity; dataDisparity = (TH1D*)gDirectory->GetList()->FindObject("dataDisparity"); if(dataDisparity) delete dataDisparity; dataDisparity = new TH1D("dataDisparity","Difference between 4/5 Coincidences as Read by Timestamps and Counts",29,1,30); while(1) { //Read new count line and get total number of coincidences within that minute nlines1++; count.getline(s1,99); sscanf(s1,"%*6s,%d,%lf,%*d,%*d,%*d,%*d,%*d,%*d,%*d,%*d,%*d,%d,%d",&date1,&time1,&v[0],&v[1]); if (!count.good()) break; fract1 = modf(time1,&time1); da1.Set(date1,int(time1),int(fract1*1e9),kTRUE,0); countCoin = v[0] + v[1]; //Initialize timestamp time if(nlines1==1) { stamp.getline(s2,99); sscanf(s2,"%*6s,%d,%lf",&date2,&time2); if (!stamp.good()) break; fract2 = modf(time2,&time2); da2.Set(date2,int(time2),int(fract2*1e9),kTRUE,0); last = da1.AsDouble() - 60; //Assume that first counts line covers 60 seconds } //If timestamp time is within last span of count time, increase stampCoin, get new timestamp time //Continue until timestamp time is outside time counted by last count while(da2.AsDouble() <= da1.AsDouble() && da1.AsDouble() > last) { stampCoin++; nlines2++; stamp.getline(s2,99); sscanf(s2,"%*6s,%d,%lf",&date2,&time2); if (!stamp.good()) break; fract2 = modf(time2,&time2); da2.Set(date2,int(time2),int(fract2*1e9),kTRUE,0); } if(!(stampCoin==countCoin)) dataDisparity->Fill(countCoin-stampCoin); stampCoin = 0; if (!stamp.good()) break; last = da1.AsDouble(); } TCanvas *c1 = new TCanvas("c1"); c1->SetLogy(); dataDisparity->Draw(); count.close(); stamp.close(); } void histStamps(int interval,string stampsFileName) //Builds Histogram of Time Differences between successive 4/5 Coincidences within windows of operation { ifstream in; in.open(stampsFileName.c_str()); Char_t s[100]; Int_t date; Double_t time; Int_t nlines = 0; TTimeStamp start; TTimeStamp end; Double_t diff; Double_t total = 0; Int_t cnt = 0; Double_t fract; TH1D *timeDiff; timeDiff = (TH1D*)gDirectory->GetList()->FindObject("timeDiff"); if(timeDiff) delete timeDiff; timeDiff = new TH1D("timeDiff","Time Difference Between Successive 4/5 Coincidences",200,0,500); while(1) { nlines++; in.getline(s,99); sscanf(s,"%*6s,%d,%lf",&date,&time); if (!in.good()) break; fract = modf(time,&time); end.Set(date,int(time),int(fract*1e9),kTRUE,0); if(!(nlines == 1)) { diff=end.AsDouble() - start.AsDouble(); if(diff <= interval) { timeDiff->Fill(diff); total = total + diff; cnt++; } } start = end; } cout << "The computed average between timestamps is " << total / cnt << endl; TCanvas *c1 = new TCanvas("c1"); timeDiff->Fit("expo","Q"); timeDiff->Draw(); in.close(); }