2024-09-05 16:04:35 -04:00
# ifndef Target_h
# define Target_h
/*********************************************
* This is online analyzer for PID , ANL
*
* Created by Khushi @ 2024 - 09 - 03
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "Analyser.h"
class Target : public Analyzer {
public :
Target ( 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 ) ;
2024-09-14 18:17:00 -04:00
SetDatabase ( " https://localhost:8086 " , " testing " , " zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A== " ) ;
2024-09-05 16:04:35 -04:00
SetUpCanvas ( ) ; // see below
} ;
void SetUpCanvas ( ) ;
public slots :
void UpdateHistograms ( ) ;
private :
MultiBuilder * evtbder ;
//Histogram2D * hPID;
Histogram1D * hdE ; // raw dE (ch=1): ch1
Histogram1D * hE ; // raw E (ch=4) : ch4
Histogram1D * hdT ; // raw dT (ch=7): ch7
Histogram1D * hTotE ; // total energy (dE+E): ch1+ch4
Histogram1D * hTWin ; // coincidence time window TWin: (t4-t1)*1e9
Histogram2D * hdEE ; // dE versus E : ch1 versus ch4
Histogram2D * hdEtotE ; // dE versus totE : ch1 versus (ch1+ch4)
Histogram2D * hdEdT ; // dE versus TOF: ch1 versus (t7-t1)*1e9
int tick2ns ;
float ch1 , ch4 , ch7 ;
unsigned long long t1 , t4 , t7 ;
} ;
inline void Target : : 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);
hdEE = new Histogram2D ( " dE vs E " , " E[ch] " , " dE[ch] " , 500 , - 100 , 10000 , 500 , - 100 , 10000 , this ) ;
layout - > addWidget ( hdEE , 0 , 0 , 1 , 2 ) ;
hdE = new Histogram1D ( " raw dE (ch=1) " , " dE [ch] " , 300 , 0 , 8000 , this ) ;
layout - > addWidget ( hdE , 0 , 2 ) ;
hdEdT = new Histogram2D ( " dE vs TOF " , " TOF [ns] " , " dE " , 100 , 0 , 500 , 100 , 0 , 4000 , this ) ;
layout - > addWidget ( hdEdT , 1 , 3 ) ;
hE = new Histogram1D ( " raw E (ch=4) " , " E [ch] " , 300 , 0 , 10000 , this ) ;
layout - > addWidget ( hE , 0 , 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 ) ;
hdT = new Histogram1D ( " raw dT (ch=7) " , " dT [ch] " , 300 , 0 , 1000 , this ) ;
layout - > addWidget ( hdT , 1 , 2 ) ;
hTotE = new Histogram1D ( " total energy (dE+E) " , " TotE [ch] " , 300 , 0 , 16000 , this ) ;
layout - > addWidget ( hTotE , 0 , 4 ) ;
hTWin = new Histogram1D ( " coincidence time window " , " TWin [ns] " , 300 , 0 , 500 , this ) ;
layout - > addWidget ( hTWin , 1 , 4 ) ;
}
inline void Target : : 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 = hdEE - > 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 ;
for ( int k = 0 ; k < ( int ) event . size ( ) ; k + + ) {
//event[k].Print();
2024-09-14 11:52:18 -04:00
if ( event [ k ] . ch = = 4 ) { ch1 = event [ k ] . energy ; t1 = event [ k ] . timestamp ; } // Reads channel 6 of the digitizer corresponding to dE
if ( event [ k ] . ch = = 6 ) { ch4 = event [ k ] . energy ; t4 = event [ k ] . timestamp ; } // Reads channel 7 of the digitizer corresponding to E
if ( event [ k ] . ch = = 7 ) { ch7 = event [ k ] . energy ; t7 = event [ k ] . timestamp ; }
2024-09-05 16:04:35 -04:00
}
// printf("(E, dE) = (%f, %f)\n", E, dE);
//hPID->Fill(ch4 , ch1); // x, y
//etotal = ch1*0.25*0.25 + ch4
hdE - > Fill ( ch1 ) ;
hE - > Fill ( ch4 ) ;
hdT - > Fill ( ch7 ) ;
2024-09-14 11:52:18 -04:00
hTotE - > Fill ( ch1 + ch4 ) ;
2024-09-05 16:04:35 -04:00
hdEE - > Fill ( ch4 , ch1 ) ;
2024-09-14 11:52:18 -04:00
hdEtotE - > Fill ( ch1 + ch4 , ch1 ) ;
2024-09-05 16:04:35 -04:00
hdEdT - > Fill ( ( t7 - t1 ) * 1e9 , ch1 ) ;
hTWin - > Fill ( ( t4 - t1 ) * 1e9 ) ;
//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();
hdE - > UpdatePlot ( ) ;
hE - > UpdatePlot ( ) ;
hdT - > UpdatePlot ( ) ;
hTotE - > UpdatePlot ( ) ;
hdEE - > UpdatePlot ( ) ;
hdEtotE - > UpdatePlot ( ) ;
hdEdT - > UpdatePlot ( ) ;
hTWin - > 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