297 lines
8.7 KiB
C++
297 lines
8.7 KiB
C++
#ifndef BeamTune_h
|
|
#define BeamTune_h
|
|
|
|
/*********************************************
|
|
* This is online analyzer for PID, ANL
|
|
*
|
|
* Created by Khushi @ 2024-09-03
|
|
*
|
|
* ******************************************/
|
|
#include "Analyser.h"
|
|
#include <cmath>
|
|
#include "math.h"
|
|
#include <algorithm>
|
|
//#include "TLine.h"
|
|
//#include <TMarker.h>
|
|
#include <vector>
|
|
#include <iostream>
|
|
class BeamTune : public Analyzer{
|
|
|
|
|
|
|
|
public:
|
|
BeamTune(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){
|
|
|
|
|
|
SetUpdateTimeInSec(2.0);
|
|
|
|
RedefineEventBuilder({0}); // only builder for the 0-th digitizer.
|
|
tick2ns = digi[0]->GetTick2ns();
|
|
|
|
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
|
|
evtbder = GetEventBuilder();
|
|
evtbder->SetTimeWindow(500);
|
|
|
|
//========== use the influx from the Analyzer
|
|
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
|
|
dataBaseName = "testing";
|
|
|
|
SetUpCanvas(); // see below
|
|
|
|
};
|
|
|
|
void SetUpCanvas();
|
|
|
|
public slots:
|
|
void UpdateHistograms();
|
|
|
|
|
|
private:
|
|
|
|
MultiBuilder *evtbder;
|
|
|
|
//Histogram2D * hPID;
|
|
|
|
Histogram2D * hFrame; // dE versus E : ch1 versus ch4
|
|
Histogram2D * hFrame1; // dE versus E : ch1 versus ch4
|
|
//Histogram2D * hdEtotE; // dE versus totE : ch1 versus (ch1+ch4)
|
|
|
|
int tick2ns;
|
|
|
|
float s0, s1, s2, s3;
|
|
unsigned long long s_t0, s_t1, s_t2, s_t3;
|
|
|
|
float e0, e1, e2, e3, dE1, dE2;
|
|
unsigned long long t0, t1, t2, t3, dE1_t, dE2_t;
|
|
|
|
float ch1, ch4, ch7;
|
|
//unsigned long long t1, t4, t7;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void BeamTune::SetUpCanvas(){
|
|
|
|
setGeometry(0, 0, 2000, 1000);
|
|
|
|
//============ histograms
|
|
|
|
//hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this);
|
|
//layout->addWidget(hPID, 2, 0);
|
|
|
|
hFrame = new Histogram2D("X Map", "X-axis", "Y-axis", 100, -10, 110, 100, -0.8, 0.8, this);
|
|
layout->addWidget(hFrame, 0, 0, 1, 2);
|
|
|
|
hFrame1 = new Histogram2D("X Map", "X-axis", "Y-axis", 100, -10, 110, 100, -0.8, 0.8, this);
|
|
layout->addWidget(hFrame1, 1, 1, 1, 2);
|
|
|
|
|
|
/*
|
|
hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this);
|
|
layout->addWidget(hdEdT, 1, 3);
|
|
|
|
hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 10000, this);
|
|
layout->addWidget(hdEtotE, 1, 0, 1, 2);
|
|
*/
|
|
}
|
|
|
|
inline void BeamTune::UpdateHistograms(){
|
|
|
|
if( this->isVisible() == false ) return;
|
|
|
|
BuildEvents(false); // call the event builder to build events
|
|
|
|
//============ Get events, and do analysis
|
|
long eventBuilt = evtbder->eventBuilt;
|
|
if( eventBuilt == 0 ) return;
|
|
|
|
//============ Get the cut list, if any
|
|
/*
|
|
QList<QPolygonF> cutList = hPID->GetCutList();
|
|
const int nCut = cutList.count();
|
|
unsigned long long tMin[nCut] = {0xFFFFFFFFFFFFFFFF}, tMax[nCut] = {0};
|
|
unsigned int count[nCut]={0};
|
|
|
|
QList<QPolygonF> cutList1 = hFrame->GetCutList();
|
|
const int nCut1 = cutList1.count();
|
|
unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0};
|
|
unsigned int count1[nCut1]={0};
|
|
*/
|
|
/*
|
|
QList<QPolygonF> cutList2 = hdEtotE->GetCutList();
|
|
const int nCut2 = cutList2.count();
|
|
unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0};
|
|
unsigned int count2[nCut2]={0};
|
|
*/
|
|
//============ Processing data and fill histograms
|
|
long eventIndex = evtbder->eventIndex;
|
|
long eventStart = eventIndex - eventBuilt + 1;
|
|
if(eventStart < 0 ) eventStart += MaxNEvent;
|
|
|
|
for( long i = eventStart ; i <= eventIndex; i ++ ){
|
|
std::vector<Hit> event = evtbder->events[i];
|
|
//printf("-------------- %ld\n", i);
|
|
|
|
if( event.size() == 0 ) return;
|
|
|
|
|
|
e0 = 0;
|
|
e1 = 0;
|
|
e2 = 0;
|
|
e3 = 0;
|
|
|
|
t0 = 0;
|
|
t1 = 0;
|
|
t2 = 0;
|
|
t3 = 0;
|
|
|
|
s0 = 0;
|
|
s1 = 0;
|
|
s2 = 0;
|
|
s3 = 0;
|
|
|
|
s_t0 = 0;
|
|
s_t1 = 0;
|
|
s_t2 = 0;
|
|
s_t3 = 0;
|
|
|
|
|
|
//std::vector<TLine*> lines; // Store lines to draw after the loop
|
|
//std::vector<TMarker*> markers; // Store markers to draw after the loop
|
|
//int lineCount = 0; // Counter to keep track of the number of lines
|
|
|
|
for( int k = 0; k < (int) event.size(); k++ ){
|
|
//event[k].Print();
|
|
|
|
if( event[k].ch == 2 ) {s0 = event[k].energy; s_t0 = event[k].timestamp;} //
|
|
if( event[k].ch == 3 ) {s1= event[k].energy; s_t1 = event[k].timestamp;} // The 4 output signals from the
|
|
if( event[k].ch == 4 ) {s2 = event[k].energy; s_t2 = event[k].timestamp;} // MCP detector
|
|
if( event[k].ch == 5 ) {s3= event[k].energy; s_t3 = event[k].timestamp;} //
|
|
|
|
if( event[k].ch == 10 ) {e0 = event[k].energy; t0 = event[k].timestamp;} //
|
|
if( event[k].ch == 11 ) {e1= event[k].energy; t1 = event[k].timestamp;} // The 4 output signals from the
|
|
if( event[k].ch == 12 ) {e2 = event[k].energy; t2 = event[k].timestamp;} // position sensitive E detector
|
|
if( event[k].ch == 13 ) {e3= event[k].energy; t3 = event[k].timestamp;} //
|
|
|
|
}
|
|
|
|
if (s0>10 && s1>10 && s2>10 && s3>10 && e0>10 && e1>10 && e2>10 && e3>10) {
|
|
float_t rotation_angle = 31.;
|
|
double_t Xr = (((s1+s2)/(s0+s1+s2+s3))-0.51)*cos(-rotation_angle*M_PI/180)-(((s2+s3)/(s0+s1+s2+s3))-0.51)*sin(-rotation_angle*M_PI/180);
|
|
double_t Yr = (((s1+s2)/(s0+s1+s2+s3))-0.51)*sin(-rotation_angle*M_PI/180)+(((s2+s3)/(s0+s1+s2+s3))-0.51)*cos(-rotation_angle*M_PI/180);
|
|
|
|
double_t X2 = ((e0-e1)/(e0+e1)); // PSD X position
|
|
double_t Y2 = ((e3-e2)/(e2+e3)); // PSD Y position
|
|
// printf("(E, dE) = (%f, %f)\n", E, dE);
|
|
|
|
|
|
// Create the line and store it in the vector
|
|
//TLine *line = new TLine(Xr, Yr, X2, Y2);
|
|
//line->SetLineColor(kBlack);
|
|
// Set line color based on Y2 value
|
|
/*
|
|
if (Y2 > 0) {
|
|
line->SetLineColor(kPink); // Pink color if Y2 > 0
|
|
} else {
|
|
line->SetLineColor(kBlack); // Black otherwise
|
|
}
|
|
*/
|
|
//lines.push_back(line);
|
|
//lineCount++; // Increment the counter
|
|
|
|
//Create markers at the start and end of the line
|
|
//TMarker *startMarker = new TMarker(Xr, Yr, kFullCircle);
|
|
//startMarker->SetMarkerColor(kRed);
|
|
//startMarker->SetMarkerSize(0.1);
|
|
//markers.push_back(startMarker);
|
|
|
|
//TMarker *endMarker = new TMarker(X2, Y2, kFullCircle);
|
|
//endMarker->SetMarkerColor(kGreen);
|
|
//endMarker->SetMarkerSize(0.2);
|
|
//markers.push_back(endMarker);
|
|
|
|
|
|
//hFrame->Fill(Xr,Yr, sX2,Y2);
|
|
//hFrame1->Fill(X2,Y2);
|
|
|
|
// Draw all the lines after the loop
|
|
|
|
//for (auto line : lines) {
|
|
// line->Draw();
|
|
//}
|
|
|
|
// Draw all the markers after the lines
|
|
//for (auto marker : markers) {
|
|
// marker->Draw();
|
|
//}
|
|
//gStyle->SetOptStat(0000000);
|
|
//hdEtotE->Fill(ch1*0.25*0.25 + ch4,ch1);
|
|
|
|
}
|
|
//check events inside any Graphical cut and extract the rate
|
|
/*
|
|
for(int p = 0; p < cutList.count(); p++ ){
|
|
if( cutList[p].isEmpty() ) continue;
|
|
if( cutList[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
|
|
if( t1 < tMin[p] ) tMin[p] = t1;
|
|
if( t1 > tMax[p] ) tMax[p] = t1;
|
|
count[p] ++;
|
|
//printf(".... %d \n", count[p]);
|
|
}
|
|
}
|
|
|
|
for(int p = 0; p < cutList1.count(); p++ ){
|
|
if( cutList1[p].isEmpty() ) continue;
|
|
if( cutList1[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){
|
|
if( t1 < tMin1[p] ) tMin1[p] = t1;
|
|
if( t1 > tMax1[p] ) tMax1[p] = t1;
|
|
count1[p] ++;
|
|
//printf("hdEE.... %d \n", count1[p]);
|
|
}
|
|
}
|
|
|
|
for(int p = 0; p < cutList2.count(); p++ ){
|
|
if( cutList2[p].isEmpty() ) continue;
|
|
if( cutList2[p].containsPoint(QPointF(ch1+ch4,ch1), Qt::OddEvenFill) ){
|
|
if( t1 < tMin2[p] ) tMin2[p] = t1;
|
|
if( t1 > tMax2[p] ) tMax2[p] = t1;
|
|
count2[p] ++;
|
|
//printf("hdEtotE.... %d \n", count2[p]);
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
/*
|
|
for(int p = 0; p < cutList2.count(); p++ ){
|
|
printf("hdEE.... %d %d \n", p, count1[p]);
|
|
}
|
|
*/
|
|
//hPID->UpdatePlot();
|
|
|
|
hFrame->UpdatePlot();
|
|
hFrame1->UpdatePlot();
|
|
//hdEtotE->UpdatePlot();
|
|
|
|
/*
|
|
//========== output to Influx
|
|
QList<QString> cutNameList = hPID->GetCutNameList();
|
|
for( int p = 0; p < cutList.count(); p ++){
|
|
if( cutList[p].isEmpty() ) continue;
|
|
double dT = (tMax[p]-tMin[p]) * tick2ns / 1e9; // tick to sec
|
|
double rate = count[p]*1.0/(dT);
|
|
//printf("%llu %llu, %f %d\n", tMin[p], tMax[p], dT, count[p]);
|
|
//printf("%10s | %d | %f Hz \n", cutNameList[p].toStdString().c_str(), count[p], rate);
|
|
|
|
influx->AddDataPoint("Cut,name=" + cutNameList[p].toStdString()+ " value=" + std::to_string(rate));
|
|
influx->WriteData(dataBaseName);
|
|
influx->ClearDataPointsBuffer();
|
|
}
|
|
*/
|
|
}
|
|
|
|
|
|
#endif
|