2024-01-27 00:57:57 -05:00
# define Analyzer_cxx
# include "Analyzer.h"
2025-01-27 15:11:27 -05:00
# include "Armory/ClassSX3.h"
# include "Armory/ClassPW.h"
2024-10-25 15:02:59 -04:00
# include <TH2.h>
# include <TStyle.h>
2025-01-17 11:18:07 -05:00
# include <TCanvas.h>
# include <TMath.h>
2025-01-27 15:11:27 -05:00
# include "TVector3.h"
2025-01-17 11:18:07 -05:00
2025-01-27 15:11:27 -05:00
# include <fstream>
# include <iostream>
# include <sstream>
# include <map>
2024-10-25 15:02:59 -04:00
# include <utility>
2025-01-17 11:18:07 -05:00
# include <algorithm>
2024-04-15 13:29:57 -04:00
2024-10-25 15:02:59 -04:00
TH2F * hsx3IndexVE ;
TH2F * hqqqIndexVE ;
TH2F * hpcIndexVE ;
2025-01-27 15:11:27 -05:00
TH2F * hpcIndexVE_GM ;
2024-10-25 15:02:59 -04:00
TH2F * hsx3Coin ;
TH2F * hqqqCoin ;
TH2F * hpcCoin ;
TH2F * hqqqPolar ;
TH2F * hsx3VpcIndex ;
TH2F * hqqqVpcIndex ;
TH2F * hqqqVpcE ;
TH2F * hsx3VpcE ;
TH2F * hanVScatsum ;
2025-01-27 09:51:25 -05:00
TH2F * hanVScatsum_a [ 24 ] ;
2025-01-27 16:34:39 -05:00
TH1F * hPC_E [ 48 ] ;
2025-01-27 09:51:25 -05:00
TH1F * hAnodeMultiplicity ;
2024-01-29 19:10:12 -05:00
int padID = 0 ;
2024-04-15 13:29:57 -04:00
SX3 sx3_contr ;
PW pw_contr ;
2025-01-17 11:18:07 -05:00
PW pwinstance ;
2024-04-15 13:29:57 -04:00
TVector3 hitPos ;
2025-01-27 15:11:27 -05:00
std : : map < int , std : : pair < double , double > > slopeInterceptMap ;
2024-04-15 13:29:57 -04:00
bool HitNonZero ;
2024-10-25 15:02:59 -04:00
TH1F * hZProj ;
2025-01-31 09:25:37 -05:00
TH1F * hPCZProj ;
2024-01-27 00:57:57 -05:00
2025-01-17 11:18:07 -05:00
void Analyzer : : Begin ( TTree * /*tree*/ )
{
2024-01-29 19:10:12 -05:00
TString option = GetOption ( ) ;
2024-10-25 15:02:59 -04:00
hsx3IndexVE = new TH2F ( " hsx3IndexVE " , " SX3 index vs Energy; sx3 index ; Energy " , 24 * 12 , 0 , 24 * 12 , 400 , 0 , 5000 ) ;
hsx3IndexVE - > SetNdivisions ( - 612 , " x " ) ;
hqqqIndexVE = new TH2F ( " hqqqIndexVE " , " QQQ index vs Energy; QQQ index ; Energy " , 4 * 2 * 16 , 0 , 4 * 2 * 16 , 400 , 0 , 5000 ) ;
hqqqIndexVE - > SetNdivisions ( - 1204 , " x " ) ;
2025-01-27 15:11:27 -05:00
hpcIndexVE = new TH2F ( " hpcIndexVE " , " PC index vs Energy; PC index ; Energy " , 2 * 24 , 0 , 2 * 24 , 400 , 0 , 16000 ) ;
2024-10-25 15:02:59 -04:00
hpcIndexVE - > SetNdivisions ( - 1204 , " x " ) ;
2025-01-27 15:11:27 -05:00
hpcIndexVE_GM = new TH2F ( " hpcIndexVE_GM " , " PC index vs Energy; PC index ; Energy " , 2 * 24 , 0 , 2 * 24 , 400 , 0 , 16000 ) ;
hpcIndexVE_GM - > SetNdivisions ( - 1204 , " x " ) ;
2024-10-25 15:02:59 -04:00
hsx3Coin = new TH2F ( " hsx3Coin " , " SX3 Coincident " , 24 * 12 , 0 , 24 * 12 , 24 * 12 , 0 , 24 * 12 ) ;
hqqqCoin = new TH2F ( " hqqqCoin " , " QQQ Coincident " , 4 * 2 * 16 , 0 , 4 * 2 * 16 , 4 * 2 * 16 , 0 , 4 * 2 * 16 ) ;
hpcCoin = new TH2F ( " hpcCoin " , " PC Coincident " , 2 * 24 , 0 , 2 * 24 , 2 * 24 , 0 , 2 * 24 ) ;
hqqqPolar = new TH2F ( " hqqqPolar " , " QQQ Polar ID " , 16 * 4 , - TMath : : Pi ( ) , TMath : : Pi ( ) , 16 , 10 , 50 ) ;
hsx3VpcIndex = new TH2F ( " hsx3Vpcindex " , " sx3 vs pc; sx3 index; pc index " , 24 * 12 , 0 , 24 * 12 , 48 , 0 , 48 ) ;
hsx3VpcIndex - > SetNdivisions ( - 612 , " x " ) ;
hsx3VpcIndex - > SetNdivisions ( - 12 , " y " ) ;
hqqqVpcIndex = new TH2F ( " hqqqVpcindex " , " qqq vs pc; qqq index; pc index " , 4 * 2 * 16 , 0 , 4 * 2 * 16 , 48 , 0 , 48 ) ;
hqqqVpcIndex - > SetNdivisions ( - 612 , " x " ) ;
hqqqVpcIndex - > SetNdivisions ( - 12 , " y " ) ;
2025-01-17 11:18:07 -05:00
hqqqVpcE = new TH2F ( " hqqqVpcEnergy " , " qqq vs pc; qqq energy; pc energy " , 400 , 0 , 5000 , 800 , 0 , 16000 ) ;
2024-10-25 15:02:59 -04:00
hqqqVpcE - > SetNdivisions ( - 612 , " x " ) ;
hqqqVpcE - > SetNdivisions ( - 12 , " y " ) ;
2025-01-17 11:18:07 -05:00
hsx3VpcE = new TH2F ( " hsx3VpcEnergy " , " sx3 vs pc; sx3 energy; pc energy " , 400 , 0 , 5000 , 800 , 0 , 16000 ) ;
2024-10-25 15:02:59 -04:00
hsx3VpcE - > SetNdivisions ( - 612 , " x " ) ;
hsx3VpcE - > SetNdivisions ( - 12 , " y " ) ;
2025-01-17 11:18:07 -05:00
hZProj = new TH1F ( " hZProj " , " Z Projection " , 200 , - 600 , 600 ) ;
2025-01-31 09:25:37 -05:00
hPCZProj = new TH1F ( " hPCZProj " , " PC Z Projection " , 200 , - 600 , 600 ) ;
2024-04-15 13:29:57 -04:00
2025-01-28 10:19:14 -05:00
hanVScatsum = new TH2F ( " hanVScatsum " , " Anode vs Cathode Sum; Anode E; Cathode E " , 400 , 0 , 16000 , 400 , 0 , 20000 ) ;
2025-01-27 09:51:25 -05:00
hAnodeMultiplicity = new TH1F ( " hAnodeMultiplicity " , " Number of Anodes/Event " , 40 , 0 , 40 ) ;
for ( int i = 0 ; i < 24 ; i + + )
{
TString histName = Form ( " hAnodeVsCathode_%d " , i ) ;
TString histTitle = Form ( " Anode %d vs Cathode Sum; Anode E; Cathode Sum E " , i ) ;
2025-01-28 10:19:14 -05:00
hanVScatsum_a [ i ] = new TH2F ( histName , histTitle , 400 , 0 , 16000 , 400 , 0 , 20000 ) ;
2025-01-27 09:51:25 -05:00
}
2025-01-27 16:34:39 -05:00
for ( int i = 0 ; i < 48 ; i + + )
{
TString histName = Form ( " hCathode_%d " , i ) ;
TString histTitle = Form ( " Cathode_E_%d; " , i ) ;
hPC_E [ i ] = new TH1F ( histName , histTitle , 3200 , 0 , 32000 ) ;
}
2024-04-15 13:29:57 -04:00
sx3_contr . ConstructGeo ( ) ;
pw_contr . ConstructGeo ( ) ;
2025-01-27 15:11:27 -05:00
std : : ifstream inputFile ( " slope_intercept_results.txt " ) ;
if ( inputFile . is_open ( ) )
{
std : : string line ;
int index ;
double slope , intercept ;
while ( std : : getline ( inputFile , line ) )
{
std : : stringstream ss ( line ) ;
ss > > index > > slope > > intercept ;
2025-01-27 16:34:39 -05:00
// wires 37, 39, 44 have fit data that is incorrect or not present, they have thus been set to 1,0 (slope, intercept) for convenience
// wire 19 the 4th point was genereated using the slope of the line produced uising the other 3 points from the wire 1 vs wire 19 plot
2025-01-27 15:11:27 -05:00
if ( index > = 0 & & index < = 47 )
{
slopeInterceptMap [ index ] = std : : make_pair ( slope , intercept ) ;
}
}
inputFile . close ( ) ;
}
else
{
std : : cerr < < " Error opening slope_intercept.txt " < < std : : endl ;
}
2024-01-27 00:57:57 -05:00
}
2025-01-17 11:18:07 -05:00
Bool_t Analyzer : : Process ( Long64_t entry )
{
2024-01-27 00:57:57 -05:00
2024-04-15 13:29:57 -04:00
// if ( entry > 100 ) return kTRUE;
hitPos . Clear ( ) ;
HitNonZero = false ;
2024-01-29 19:10:12 -05:00
// if( entry > 1) return kTRUE;
// printf("################### ev : %llu \n", entry);
b_sx3Multi - > GetEntry ( entry ) ;
b_sx3ID - > GetEntry ( entry ) ;
b_sx3Ch - > GetEntry ( entry ) ;
b_sx3E - > GetEntry ( entry ) ;
b_sx3T - > GetEntry ( entry ) ;
b_qqqMulti - > GetEntry ( entry ) ;
b_qqqID - > GetEntry ( entry ) ;
b_qqqCh - > GetEntry ( entry ) ;
b_qqqE - > GetEntry ( entry ) ;
b_qqqT - > GetEntry ( entry ) ;
b_pcMulti - > GetEntry ( entry ) ;
b_pcID - > GetEntry ( entry ) ;
b_pcCh - > GetEntry ( entry ) ;
b_pcE - > GetEntry ( entry ) ;
b_pcT - > GetEntry ( entry ) ;
sx3 . CalIndex ( ) ;
qqq . CalIndex ( ) ;
pc . CalIndex ( ) ;
// sx3.Print();
2024-10-25 15:02:59 -04:00
// ########################################################### Raw data
// //======================= SX3
2024-04-15 13:29:57 -04:00
std : : vector < std : : pair < int , int > > ID ; // first = id, 2nd = index
2025-01-17 11:18:07 -05:00
for ( int i = 0 ; i < sx3 . multi ; i + + )
{
ID . push_back ( std : : pair < int , int > ( sx3 . id [ i ] , i ) ) ;
2024-01-29 19:10:12 -05:00
2025-01-17 11:18:07 -05:00
hsx3IndexVE - > Fill ( sx3 . index [ i ] , sx3 . e [ i ] ) ;
2024-01-29 19:10:12 -05:00
2025-01-17 11:18:07 -05:00
for ( int j = i + 1 ; j < sx3 . multi ; j + + )
{
hsx3Coin - > Fill ( sx3 . index [ i ] , sx3 . index [ j ] ) ;
}
2024-01-29 19:10:12 -05:00
2025-01-17 11:18:07 -05:00
for ( int j = 0 ; j < pc . multi ; j + + )
{
hsx3VpcIndex - > Fill ( sx3 . index [ i ] , pc . index [ j ] ) ;
2024-04-15 13:29:57 -04:00
// if( sx3.ch[index] > 8 ){
// hsx3VpcE->Fill( sx3.e[i], pc.e[j] );
// }
2024-01-29 19:10:12 -05:00
}
}
2025-01-17 11:18:07 -05:00
if ( ID . size ( ) > 0 )
{
std : : sort ( ID . begin ( ) , ID . end ( ) , [ ] ( const std : : pair < int , int > & a , const std : : pair < int , int > & b )
{ return a . first < b . first ; } ) ;
2024-04-15 13:29:57 -04:00
// printf("##############################\n");
// for( size_t i = 0; i < ID.size(); i++) printf("%zu | %d %d \n", i, ID[i].first, ID[i].second );
2024-10-25 15:02:59 -04:00
std : : vector < std : : pair < int , int > > sx3ID ;
2024-04-15 13:29:57 -04:00
sx3ID . push_back ( ID [ 0 ] ) ;
bool found = false ;
2025-01-17 11:18:07 -05:00
for ( size_t i = 1 ; i < ID . size ( ) ; i + + )
{
if ( ID [ i ] . first = = sx3ID . back ( ) . first )
{
2024-04-15 13:29:57 -04:00
sx3ID . push_back ( ID [ i ] ) ;
2025-01-17 11:18:07 -05:00
if ( sx3ID . size ( ) > = 3 )
{
2024-04-15 13:29:57 -04:00
found = true ;
2024-10-25 15:02:59 -04:00
}
2025-01-17 11:18:07 -05:00
}
else
{
if ( ! found )
{
2024-04-15 13:29:57 -04:00
sx3ID . clear ( ) ;
sx3ID . push_back ( ID [ i ] ) ;
}
}
}
// printf("---------- sx3ID Multi : %zu \n", sx3ID.size());
2025-01-17 11:18:07 -05:00
if ( found )
{
2024-04-15 13:29:57 -04:00
int sx3ChUp , sx3ChDn , sx3ChBk ;
float sx3EUp , sx3EDn ;
// printf("------ sx3 ID : %d, multi: %zu\n", sx3ID[0].first, sx3ID.size());
2025-01-17 11:18:07 -05:00
for ( size_t i = 0 ; i < sx3ID . size ( ) ; i + + )
{
2024-04-15 13:29:57 -04:00
int index = sx3ID [ i ] . second ;
// printf(" %zu | index %d | ch : %d, energy : %d \n", i, index, sx3.ch[index], sx3.e[index]);
2025-01-17 11:18:07 -05:00
if ( sx3 . ch [ index ] < 8 )
{
if ( sx3 . ch [ index ] % 2 = = 0 )
{
2024-04-15 13:29:57 -04:00
sx3ChDn = sx3 . ch [ index ] ;
sx3EDn = sx3 . e [ index ] ;
2025-01-17 11:18:07 -05:00
}
else
{
2024-04-15 13:29:57 -04:00
sx3ChUp = sx3 . ch [ index ] ;
sx3EUp = sx3 . e [ index ] ;
}
2025-01-17 11:18:07 -05:00
}
else
{
2024-04-15 13:29:57 -04:00
sx3ChBk = sx3 . ch [ index ] ;
}
2025-01-17 11:18:07 -05:00
for ( int j = 0 ; j < pc . multi ; j + + )
{
2024-10-25 15:02:59 -04:00
// hsx3VpcIndex->Fill( sx3.index[i], pc.index[j] );
2025-01-17 11:18:07 -05:00
if ( sx3 . ch [ index ] > 8 )
{
2024-10-25 15:02:59 -04:00
hsx3VpcE - > Fill ( sx3 . e [ i ] , pc . e [ j ] ) ;
// hpcIndexVE->Fill( pc.index[i], pc.e[i] );
2024-04-15 13:29:57 -04:00
}
2024-10-25 15:02:59 -04:00
}
2024-04-15 13:29:57 -04:00
}
sx3_contr . CalSX3Pos ( sx3ID [ 0 ] . first , sx3ChUp , sx3ChDn , sx3ChBk , sx3EUp , sx3EDn ) ;
hitPos = sx3_contr . GetHitPos ( ) ;
HitNonZero = true ;
// hitPos.Print();
}
}
2024-01-29 19:10:12 -05:00
// //======================= QQQ
2025-01-17 11:18:07 -05:00
for ( int i = 0 ; i < qqq . multi ; i + + )
{
// for( int j = 0; j < pc.multi; j++){
// if(pc.index[j]==4){
hqqqIndexVE - > Fill ( qqq . index [ i ] , qqq . e [ i ] ) ;
// }
// }
for ( int j = 0 ; j < qqq . multi ; j + + )
{
if ( j = = i )
continue ;
hqqqCoin - > Fill ( qqq . index [ i ] , qqq . index [ j ] ) ;
}
2024-10-25 15:02:59 -04:00
2025-01-17 11:18:07 -05:00
for ( int j = i + 1 ; j < qqq . multi ; j + + )
{
for ( int k = 0 ; k < pc . multi ; k + + )
{
if ( pc . index [ k ] < 24 & & pc . e [ k ] > 50 )
{
hqqqVpcE - > Fill ( qqq . e [ i ] , pc . e [ k ] ) ;
2024-11-05 08:48:21 -05:00
// hpcIndexVE->Fill( pc.index[i], pc.e[i] );
hqqqVpcIndex - > Fill ( qqq . index [ i ] , pc . index [ j ] ) ;
2024-01-29 19:10:12 -05:00
}
2025-01-17 11:18:07 -05:00
// }
2024-11-05 08:48:21 -05:00
}
// if( qqq.used[i] == true ) continue;
2024-01-29 19:10:12 -05:00
2025-01-17 11:18:07 -05:00
// if( qqq.id[i] == qqq.id[j] && (16 - qqq.ch[i]) * (16 - qqq.ch[j]) < 0 ){ // must be same detector and wedge and ring
if ( qqq . id [ i ] = = qqq . id [ j ] )
{ // must be same detector
int chWedge = - 1 ;
int chRing = - 1 ;
if ( qqq . ch [ i ] < qqq . ch [ j ] )
{
chRing = qqq . ch [ j ] - 16 ;
chWedge = qqq . ch [ i ] ;
}
else
{
chRing = qqq . ch [ i ] ;
chWedge = qqq . ch [ j ] - 16 ;
2024-04-15 13:29:57 -04:00
}
2025-01-17 11:18:07 -05:00
// printf(" ID : %d , chWedge : %d, chRing : %d \n", qqq.id[i], chWedge, chRing);
double theta = - TMath : : Pi ( ) / 2 + 2 * TMath : : Pi ( ) / 16 / 4. * ( qqq . id [ i ] * 16 + chWedge + 0.5 ) ;
double rho = 10. + 40. / 16. * ( chRing + 0.5 ) ;
// if(qqq.e[i]>50){
hqqqPolar - > Fill ( theta , rho ) ;
// }
// qqq.used[i] = true;
// qqq.used[j] = true;
if ( ! HitNonZero )
{
double x = rho * TMath : : Cos ( theta ) ;
double y = rho * TMath : : Sin ( theta ) ;
hitPos . SetXYZ ( x , y , 23 + 75 + 30 ) ;
HitNonZero = true ;
2024-08-26 10:31:09 -04:00
}
2024-10-25 15:02:59 -04:00
}
}
2024-08-26 10:34:13 -04:00
}
2025-01-17 11:18:07 -05:00
// //======================= PC
2024-10-25 15:02:59 -04:00
2025-01-17 11:18:07 -05:00
ID . clear ( ) ;
int counter = 0 ;
std : : vector < std : : pair < int , double > > E ;
E . clear ( ) ;
for ( int i = 0 ; i < pc . multi ; i + + )
{
2024-10-25 15:02:59 -04:00
2025-01-17 11:18:07 -05:00
if ( pc . e [ i ] > 100 )
2025-01-27 16:34:39 -05:00
{
2025-01-17 11:18:07 -05:00
ID . push_back ( std : : pair < int , int > ( pc . id [ i ] , i ) ) ;
2025-01-27 16:34:39 -05:00
if ( pc . index [ i ] > = 0 & & pc . index [ i ] < 48 & & hPC_E [ pc . index [ i ] ] ! = nullptr )
{
// if (pc.index[i] >= 24 && pc.index[i] < 48) {
hPC_E [ pc . index [ i ] ] - > Fill ( pc . e [ i ] ) ;
}
// }
else
{
printf ( " Warning: Invalid index %d or null pointer detected! \n " , pc . index [ i ] ) ;
}
}
2025-01-17 11:18:07 -05:00
if ( pc . e [ i ] > 100 )
E . push_back ( std : : pair < int , double > ( pc . index [ i ] , pc . e [ i ] ) ) ;
2024-04-15 13:29:57 -04:00
2025-01-17 11:18:07 -05:00
hpcIndexVE - > Fill ( pc . index [ i ] , pc . e [ i ] ) ;
2024-10-04 12:43:24 -04:00
2025-01-17 11:18:07 -05:00
for ( int j = i + 1 ; j < pc . multi ; j + + )
{
hpcCoin - > Fill ( pc . index [ i ] , pc . index [ j ] ) ;
2024-04-15 13:29:57 -04:00
}
2025-01-27 15:11:27 -05:00
// Gain Matching of PC wires
if ( pc . index [ i ] > = 0 & & pc . index [ i ] < 48 )
{
// printf("index: %d, Old cathode energy: %d \n", pc.index[i],pc.e[i]);
auto it = slopeInterceptMap . find ( pc . index [ i ] ) ;
if ( it ! = slopeInterceptMap . end ( ) )
{
double slope = it - > second . first ;
double intercept = it - > second . second ;
// printf("slope: %f, intercept:%f\n" ,slope, intercept);
pc . e [ i ] = slope * pc . e [ i ] + intercept ;
// printf("index: %d, New cathode energy: %d \n",pc.index[i], pc.e[i]);
}
hpcIndexVE_GM - > Fill ( pc . index [ i ] , pc . e [ i ] ) ;
}
2025-01-17 11:18:07 -05:00
}
2025-01-27 09:51:25 -05:00
// Calculate the crossover points and put them into an array
2025-01-17 11:18:07 -05:00
pwinstance . ConstructGeo ( ) ;
2025-01-27 09:51:25 -05:00
Coord Crossover [ 24 ] [ 24 ] [ 2 ] ;
2025-01-17 11:18:07 -05:00
TVector3 a , c , diff ;
double a2 , ac , c2 , adiff , cdiff , denom , alpha , beta ;
int index = 0 ;
for ( int i = 0 ; i < pwinstance . An . size ( ) ; i + + )
{
a = pwinstance . An [ i ] . first - pwinstance . An [ i ] . second ;
for ( int j = 0 ; j < pwinstance . Ca . size ( ) ; j + + )
{
2025-01-27 09:51:25 -05:00
// Ok so this method uses what is essentially th solution of 2 equations to find the point of intersection between the anode and cathode wires
// here a and c are the vectors of the anode and cathode wires respectively
// diff is the perpendicular vector between the anode and cathode wires
// The idea behind this is to then find the scalars alpha and beta that give a ratio between 0 and -1,
2025-01-17 11:18:07 -05:00
c = pwinstance . Ca [ j ] . first - pwinstance . Ca [ j ] . second ;
diff = pwinstance . An [ i ] . first - pwinstance . Ca [ j ] . first ;
a2 = a . Dot ( a ) ;
ac = a . Dot ( c ) ;
c2 = c . Dot ( c ) ;
adiff = a . Dot ( diff ) ;
cdiff = c . Dot ( diff ) ;
denom = a2 * c2 - ac * ac ;
alpha = ( ac * cdiff - c2 * adiff ) / denom ;
beta = ( a2 * cdiff - ac * adiff ) / denom ;
2025-01-27 10:55:22 -05:00
Crossover [ i ] [ j ] [ 0 ] . x = pwinstance . An [ i ] . first . X ( ) + alpha * a . X ( ) ;
Crossover [ i ] [ j ] [ 0 ] . y = pwinstance . An [ i ] . first . Y ( ) + alpha * a . Y ( ) ;
Crossover [ i ] [ j ] [ 0 ] . z = pwinstance . An [ i ] . first . Z ( ) + alpha * a . Z ( ) ;
// placeholder variable Crossover[i][j][2].x has nothing to do with the geometry of the crossover and is being used to store the alpha value-
//-so that it can be used to sort "good" hits later
Crossover [ i ] [ j ] [ 1 ] . x = alpha ;
2025-01-27 15:11:27 -05:00
// if (i == 16)
// {
// for (int k = 0; k < 5; k++)
// {
// if ((i + 24 + k) % 24 == j)
// {
// // if (alpha < 0 && alpha >= -1)
// // {
// printf("Anode and cathode indices and coord : %d %d %f %f %f %f\n", i, j, pwinstance.Ca[j].first.X(), pwinstance.Ca[j].first.Y(), pwinstance.Ca[j].first.Z(), alpha);
// printf("Crossover wires, points and alpha are : %f %f %f %f \n", Crossover[i][j][1].x, Crossover[i][j][1].y, Crossover[i][j][1].z, Crossover[i][j][2].x /*this is alpha*/);
// // }
// }
// }
// }
2025-01-27 09:51:25 -05:00
}
}
std : : vector < std : : pair < int , double > > anodeHits = { } ;
std : : vector < std : : pair < int , double > > cathodeHits = { } ;
2025-01-28 10:19:14 -05:00
std : : vector < std : : pair < int , double > > corrcatMax = { } ;
std : : vector < std : : pair < int , double > > corrcatnextMax = { } ;
2025-01-31 09:25:37 -05:00
std : : vector < std : : pair < int , double > > commcat = { } ;
2025-01-27 09:51:25 -05:00
int aID = 0 ;
int cID = 0 ;
float aE = 0 ;
float cE = 0 ;
2025-01-28 10:19:14 -05:00
float aESum = 0 ;
float cESum = 0 ;
float aEMax = 0 ;
float cEMax = 0 ;
float aEnextMax = 0 ;
float cEnextMax = 0 ;
int aIDMax = 0 ;
int cIDMax = 0 ;
int aIDnextMax = 0 ;
int cIDnextMax = 0 ;
2025-01-27 09:51:25 -05:00
// Define the excluded SX3 and QQQ channels
// std::unordered_set<int> excludeSX3 = {34, 35, 36, 37, 61, 62, 67, 73, 74, 75, 76, 77, 78, 79, 80, 93, 97, 100, 103, 108, 109, 110, 111, 112};
// std::unordered_set<int> excludeQQQ = {0, 17, 109, 110, 111, 112, 113, 119, 127, 128};
// inCuth=false;
// inCutl=false;
// inPCCut=false;
for ( int i = 0 ; i < pc . multi ; i + + )
{
if ( pc . e [ i ] > 50 & & pc . multi < 7 )
{
2025-01-27 10:55:22 -05:00
// creating a vector of pairs of anode and cathode hits that is sorted in order of decreasing energy
2025-01-27 09:51:25 -05:00
if ( pc . index [ i ] < 24 )
{
anodeHits . push_back ( std : : pair < int , double > ( pc . index [ i ] , pc . e [ i ] ) ) ;
std : : sort ( anodeHits . begin ( ) , anodeHits . end ( ) , [ ] ( const std : : pair < int , double > & a , const std : : pair < int , double > & b )
{ return a . second > b . second ; } ) ;
}
else if ( pc . index [ i ] > = 24 )
{
cathodeHits . push_back ( std : : pair < int , double > ( pc . index [ i ] , pc . e [ i ] ) ) ;
2025-01-27 10:55:22 -05:00
std : : sort ( cathodeHits . begin ( ) , cathodeHits . end ( ) , [ ] ( const std : : pair < int , double > & a , const std : : pair < int , double > & b )
2025-01-27 09:51:25 -05:00
{ return a . second > b . second ; } ) ;
}
for ( int j = i + 1 ; j < pc . multi ; j + + )
2025-01-17 11:18:07 -05:00
{
2025-01-27 09:51:25 -05:00
// if(PCCoinc_cut1->IsInside(pc.index[i], pc.index[j]) || PCCoinc_cut2->IsInside(pc.index[i], pc.index[j])){
// // hpcCoin->Fill(pc.index[i], pc.index[j]);
// inPCCut = true;
// }
hpcCoin - > Fill ( pc . index [ i ] , pc . index [ j ] ) ;
}
if ( anodeHits . size ( ) > = 1 & & cathodeHits . size ( ) > = 1 )
{
for ( const auto & anode : anodeHits )
2025-01-17 11:18:07 -05:00
{
2025-01-27 09:51:25 -05:00
aID = anode . first ;
aE = anode . second ;
aESum + = aE ;
if ( aE > aEMax )
{
2025-01-27 10:55:22 -05:00
aIDnextMax = aIDMax ;
aEnextMax = aEMax ;
2025-01-27 09:51:25 -05:00
aEMax = aE ;
aIDMax = aID ;
}
if ( aE > aEnextMax & & aE < aEMax )
2025-01-17 11:18:07 -05:00
{
2025-01-27 09:51:25 -05:00
aEnextMax = aE ;
aIDnextMax = aID ;
2025-01-17 11:18:07 -05:00
}
2025-01-27 09:51:25 -05:00
// printf("aID : %d, aE : %f\n", aID, aE);
2025-01-17 11:18:07 -05:00
}
2025-01-27 09:51:25 -05:00
// printf("aID : %d, aE : %f, cE : %f\n", aID, aE, cE);
for ( const auto & cathode : cathodeHits )
{
cID = cathode . first ;
cE = cathode . second ;
if ( cE > cEMax )
{
2025-01-27 10:55:22 -05:00
cIDnextMax = cIDMax ;
cEnextMax = cEMax ;
2025-01-27 09:51:25 -05:00
cEMax = cE ;
cIDMax = cID ;
}
if ( cE > cEnextMax & & cE < cEMax )
{
cEnextMax = cE ;
cIDnextMax = cID ;
}
cESum + = cE ;
2025-01-31 09:25:37 -05:00
// This section of code is used to find the cathodes are correlated with the max and next max anodes, as well as to figure out if there are any common cathodes
2025-01-28 10:19:14 -05:00
for ( int j = 0 ; j < 5 ; j + + )
2025-01-17 11:18:07 -05:00
{
2025-01-28 10:19:14 -05:00
if ( ( aIDMax + 24 + j ) % 24 = = cathode . first )
2025-01-17 11:18:07 -05:00
{
2025-01-28 10:19:14 -05:00
corrcatMax . push_back ( std : : pair < int , double > ( cathode . first , cathode . second ) ) ;
2025-01-31 09:25:37 -05:00
std : : sort ( corrcatMax . begin ( ) , corrcatMax . end ( ) , [ ] ( const std : : pair < int , double > & a , const std : : pair < int , double > & b )
{ return a . second > b . second ; } ) ;
2025-01-17 11:18:07 -05:00
}
2025-01-31 09:25:37 -05:00
if ( ( aIDnextMax + 24 + j ) % 24 = = cathode . first )
2025-01-17 11:18:07 -05:00
{
2025-01-28 10:19:14 -05:00
corrcatnextMax . push_back ( std : : pair < int , double > ( cathode . first , cathode . second ) ) ;
2025-01-31 09:25:37 -05:00
std : : sort ( corrcatMax . begin ( ) , corrcatMax . end ( ) , [ ] ( const std : : pair < int , double > & a , const std : : pair < int , double > & b )
{ return a . second > b . second ; } ) ;
}
for ( int k = 0 ; k < 5 ; k + + )
{
if ( ( aIDMax + 24 + j ) % 24 = = ( aIDnextMax + 24 + k ) % 24 )
{
commcat . push_back ( std : : pair < int , double > ( cathode . first , cathode . second ) ) ;
}
2025-01-17 11:18:07 -05:00
}
}
2025-01-31 09:25:37 -05:00
}
TVector3 anodeIntersection ;
// Implementing a method for PC reconstruction using a single Anode event
if ( anodeHits . size ( ) = = 1 )
{
for ( const auto & corr : corrcatMax )
2025-01-28 10:19:14 -05:00
{
2025-01-31 09:25:37 -05:00
anodeIntersection + = TVector3 ( ( corr . second ) / cESum * Crossover [ aIDMax ] [ corr . first ] [ 0 ] . x , ( corr . second ) / cESum * Crossover [ aIDMax ] [ corr . first ] [ 0 ] . y ,
( corr . second ) / cESum * Crossover [ aIDMax ] [ corr . first ] [ 0 ] . z ) ;
2025-01-28 10:19:14 -05:00
}
2025-01-31 09:25:37 -05:00
}
//Filling the PC Z projection histogram
hPCZProj - > Fill ( anodeIntersection . Z ( ) ) ;
// }
// inCuth = false;
// inCutl = false;
// inPCCut = false;
// for(int j=i+1;j<pc.multi;j++){
// if(PCCoinc_cut1->IsInside(pc.index[i], pc.index[j]) || PCCoinc_cut2->IsInside(pc.index[i], pc.index[j])){
// // hpcCoin->Fill(pc.index[i], pc.index[j]);
// inPCCut = true;
// }
// hpcCoin->Fill(pc.index[i], pc.index[j]);
// }
2025-01-28 10:19:14 -05:00
2025-01-31 09:25:37 -05:00
// Check if the accumulated energies are within the defined ranges
// if (AnCatSum_high && AnCatSum_high->IsInside(aESum, cESum)) {
// inCuth = true;
// }
// if (AnCatSum_low && AnCatSum_low->IsInside(aESum, cESum)) {
// inCutl = true;
// }
// Fill histograms based on the cut conditions
// if (inCuth && inPCCut) {
// hanVScatsum_hcut->Fill(aESum, cESum);
// }
// if (inCutl && inPCCut) {
// hanVScatsum_lcut->Fill(aESum, cESum);
// }
// for(auto anode : anodeHits){
// float aE = anode.second;
// aESum += aE;
// if(inPCCut){
hanVScatsum - > Fill ( aEMax , cESum ) ;
// }
if ( aID < 24 & & aE > 50 )
{
hanVScatsum_a [ aID ] - > Fill ( aE , cESum ) ;
2024-11-05 08:48:21 -05:00
}
2025-01-31 09:25:37 -05:00
// }
// Fill histograms for the `pc` data
hpcIndexVE - > Fill ( pc . index [ i ] , pc . e [ i ] ) ;
// if(inPCCut){
hAnodeMultiplicity - > Fill ( anodeHits . size ( ) ) ;
// }
2024-10-30 09:28:01 -04:00
}
2024-10-25 15:02:59 -04:00
}
2025-01-17 11:18:07 -05:00
if ( HitNonZero )
{
pw_contr . CalTrack ( hitPos , aID , cID ) ;
hZProj - > Fill ( pw_contr . GetZ0 ( ) ) ;
}
2024-10-25 15:02:59 -04:00
}
2024-01-29 19:10:12 -05:00
2024-10-25 15:02:59 -04:00
// ########################################################### Track constrcution
2024-01-31 15:24:03 -05:00
2024-10-25 15:02:59 -04:00
// ############################## DO THE KINEMATICS
2024-01-29 19:10:12 -05:00
return kTRUE ;
2024-01-27 00:57:57 -05:00
}
2025-01-17 11:18:07 -05:00
void Analyzer : : Terminate ( )
{
2024-01-27 00:57:57 -05:00
2024-01-29 19:10:12 -05:00
gStyle - > SetOptStat ( " neiou " ) ;
2024-10-30 09:28:01 -04:00
TCanvas * canvas = new TCanvas ( " cANASEN " , " ANASEN " , 2000 , 2000 ) ;
canvas - > Divide ( 3 , 3 ) ;
2024-01-29 19:10:12 -05:00
2025-01-17 11:18:07 -05:00
// hsx3VpcIndex->Draw("colz");
//=============================================== pad-1
2024-10-30 09:28:01 -04:00
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
hsx3IndexVE - > Draw ( " colz " ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-2
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
hqqqIndexVE - > Draw ( " colz " ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-3
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
hpcIndexVE - > Draw ( " colz " ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-4
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
hsx3Coin - > Draw ( " colz " ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-5
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
canvas - > cd ( padID ) - > SetLogz ( true ) ;
2024-04-15 13:29:57 -04:00
2024-10-30 09:28:01 -04:00
hqqqCoin - > Draw ( " colz " ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-6
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
hpcCoin - > Draw ( " colz " ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-7
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-01-29 19:10:12 -05:00
2024-10-30 09:28:01 -04:00
// hsx3VpcIndex ->Draw("colz");
hsx3VpcE - > Draw ( " colz " ) ;
2024-04-15 13:29:57 -04:00
2024-10-30 09:28:01 -04:00
//=============================================== pad-8
padID + + ;
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
2024-04-15 13:29:57 -04:00
2024-10-30 09:28:01 -04:00
// hqqqVpcIndex ->Draw("colz");
2024-04-15 13:29:57 -04:00
2024-10-30 09:28:01 -04:00
hqqqVpcE - > Draw ( " colz " ) ;
//=============================================== pad-9
padID + + ;
2024-04-15 13:29:57 -04:00
2024-10-30 09:28:01 -04:00
// canvas->cd(padID)->DrawFrame(-50, -50, 50, 50);
// hqqqPolar->Draw("same colz pol");
2024-03-22 18:45:13 -04:00
2024-10-30 09:28:01 -04:00
canvas - > cd ( padID ) ;
canvas - > cd ( padID ) - > SetGrid ( 1 ) ;
// hZProj->Draw();
hanVScatsum - > Draw ( " colz " ) ;
2025-01-27 16:34:39 -05:00
TFile * outRoot = new TFile ( " Histograms.root " , " RECREATE " ) ;
if ( ! outRoot - > IsOpen ( ) )
{
std : : cerr < < " Error opening file for writing! " < < std : : endl ;
return ;
}
// Loop through histograms and write them to the ROOT file
for ( int i = 0 ; i < 48 ; i + + )
{
if ( hPC_E [ i ] ! = nullptr )
{
hPC_E [ i ] - > Write ( ) ; // Write histogram to file
}
}
outRoot - > Close ( ) ;
2024-01-27 00:57:57 -05:00
}